Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[native assets] Add dynamic linking integration test for dart #56459

Open
dcharkes opened this issue Aug 13, 2024 · 1 comment
Open

[native assets] Add dynamic linking integration test for dart #56459

dcharkes opened this issue Aug 13, 2024 · 1 comment
Labels
area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. area-native-interop Used for native interop related issues, including FFI.

Comments

@dcharkes
Copy link
Contributor

We want to support dylibs being dynamically linked to other dylibs in native assets:

We have a working PR for Flutter:

But it's not working in Dart standalone out of the box either.

Using the same builder hook setup as with Flutter but with standalone Dart, the linked library can never be found. I've tested dart run, dart test and dart build, always with the same result. I'm going to work on dart-lang/native#1419, but I would prefer landing this PR first and coming back later to update the tests.

@dcharkes If you have any idea what differences between embedders could cause loading the linked library to fail with standalone Dart, that would be very helpful for dart-lang/native#1419.

Originally posted by @blaugold in flutter/flutter#153054 (review)

We should add a similar integration test as in the Flutter PR with dylibs being dynamically linked to each other in pkg/dartdev/test/native_assets/build_test.dart and friends. (We could have the integration test project itself live on dart-lang/native instead of checking it in to the Dart SDK like we do with many other tests in pkg/dartdev/test/native_assets/.)

@dcharkes dcharkes added area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. area-native-interop Used for native interop related issues, including FFI. labels Aug 13, 2024
@dcharkes
Copy link
Contributor Author

@dcharkes If you have any idea what differences between embedders could cause loading the linked library to fail with standalone Dart, that would be very helpful for dart-lang/native#1419.

A Flutter app has it's include path / rpath set. A Dart .exe from dart build exe might not have that set yet. (Users using FFI have simply been using dlopen calls with full paths until now. And that's what native assets use under the hood as well currently.)

When doing dart run and dart test the executable is dart.exe in the Dart SDK. So that also doesn't have an include path / rpath. Maybe we can somehow provide that as an environment variable? Or maybe ensuring we run from the right working directory might help. This one might be slightly more tricky to get right than for dart build exe.

blaugold added a commit to blaugold/dart-sdk that referenced this issue Aug 20, 2024
The same bundling that is used for `dart build` is now also used for `dart test` and `dart run`, except that the output directory is `.dart_tool/native_assets`. This way all native code assets are placed next to each other in the `lib` directory, and loaded from there instead of loading them in place from where the build/link hooks placed them. By standardizing on this layout the different modes of running dart code that support native assets can use the same mechanisms to support dynamic linking between native code assets.

Also, on macOS install names of dylibs are rewritten to support dynamic linking, similar to the changes in flutter/flutter#153054.

Tests are added to verify that dynamic linking works as expected.

Related: dart-lang/native#190
Fixes: dart-lang#56459
@dcharkes dcharkes added this to the Native Assets v1.0 milestone Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. area-native-interop Used for native interop related issues, including FFI.
Projects
None yet
Development

No branches or pull requests

1 participant