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] Support dart pub global run #56044

Open
Tracked by #50565
lindeer opened this issue Jun 19, 2024 · 6 comments
Open
Tracked by #50565

[native_assets] Support dart pub global run #56044

lindeer opened this issue Jun 19, 2024 · 6 comments
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

@lindeer
Copy link

lindeer commented Jun 19, 2024

now my package contains a mylib-exe.dart in bin directory and in my pubspec.yaml:

environment:
  sdk: ^3.3.0

executables:
  mylib-exe:

dependencies:

but after I install dart pub global activate mylib both --source git or --source path, and run mylib-exe in cmd, report error:

Invalid argument(s): Couldn't resolve native function 'mylib_open' in 'package:mylib/src/lib_mylib.dart' : No asset with id 'package:mylib/src/lib_mylib.dart' found. No available native assets. Attempted to fallback to process lookup. /opt/programs/flutter/bin/cache/dart-sdk/bin/dart: undefined symbol: mylib_open.

seems build script not triggered and .so file not generated, I edit mylib-exe in ~/.pub-cache/bin/mylib-exe:

--- /home/wesley/.pub-cache/bin/mylib	2024-06-19 16:19:36.250444945 +0800
+++ mylib	2024-06-19 16:19:25.571916616 +0800
@@ -12,7 +12,7 @@
   if [ $exit_code != 253 ]; then
     exit $exit_code
   fi
-  dart pub global run mylib:mylib "$@"
+  dart pub global run --enable-experiment=native-assets mylib:mylib "$@"
 else
-  dart pub global run mylib:mylib "$@"
+  dart pub global run --enable-experiment=native-assets mylib:mylib "$@"
 fi

still not work. How should I fix it, thanks~

@dcharkes
Copy link
Contributor

dcharkes commented Jun 19, 2024

Thanks for the report @lindeer!

We don't have support yet for pub global run.

I would have expected the error message to complain that the experiment is required instead of run as if there are no native assets.

Just to double check, everything works fine when doing dart run --enable-experiment=native-assets mylib:mylib?

(Also, transferring this to the Dart SDK repo, as it should be implemented there.)

@dcharkes dcharkes transferred this issue from dart-lang/native Jun 19, 2024
@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 Jun 19, 2024
@dcharkes dcharkes changed the title How to correctly run executable with 'native-assets' [native_assets] Support dart pub global run Jun 19, 2024
@dcharkes
Copy link
Contributor

FYI @jonasfj @sigurdm

@dcharkes
Copy link
Contributor

dcharkes commented Jun 19, 2024

@jonasfj @sigurdm What would be a good way to save the binaries for pub global activated packages produced by the build hook.

And I'm thinking, it's probably cleanest to already invoke the build hook to produce the native assets during dart pub global activate and not during dart pub global run. (But we don't precompile the Dart code on activate judging from shell script in bin/.)

@lindeer
Copy link
Author

lindeer commented Jun 19, 2024

Just to double check, everything works fine when doing dart run --enable-experiment=native-assets mylib:mylib?

yeah, everything is OK when I run dart run.

@sigurdm
Copy link
Contributor

sigurdm commented Jun 20, 2024

And I'm thinking, it's probably cleanest to already invoke the build hook to produce the native assets during dart pub global activate and not during dart pub global run. (But we don't precompile the Dart code on activate judging from shell script in bin/.)

We do precompile - except for when the package is global activated from path.

We also support recompilation if the snapshot was compiled with a different VM.

@dcharkes
Copy link
Contributor

dcharkes commented Jun 20, 2024

After some offline discussion with @jonasfj and @sigurdm, this should probably be addressed by dart pub (package:pub) no longer manually compiling Dart to jit snapshots, but by dart pub invoking dart build exe (package:dartdev) so that dartdev is responsible for building dart code and bundling native assets. dart-lang/pub#4313

(Instead of trying to patch what pub is currently doing.)

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

3 participants