dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.57k forks source link

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

Open dcharkes opened 2 months ago

dcharkes commented 2 months ago

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 https://github.com/dart-lang/native/issues/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 https://github.com/dart-lang/native/issues/1419.

Originally posted by @blaugold in https://github.com/flutter/flutter/pull/153054#pullrequestreview-2233514300

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 commented 2 months ago

@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 https://github.com/dart-lang/native/issues/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.