pub
pub copied to clipboard
Support globally activating packages using `dart compile exe`
The "pub global activate" command currently creates a bash script that executes a "pub global run". Instead, pub could use the dart2native tool and place the binary directly in .pub-cache/bin.
This also applies for local executables that you run with pub run. I believe that today pub creates a snapshot and runs it in an isolate, but it could just launch the native executable in a process with inherit stdio mode. This is basically the equivalent of the explicit pub global run which probably also spawns an isolate today.
Note that this would likely need to be opt in for the author of the binary. Native compilation adds some restrictions (on things like Isolates or mirrors) and so could break some binaries if we do it everywhere.
Native compilation adds some restrictions (on things like Isolates or mirrors) and so could break some binaries if we do it everywhere.
Exactly, what's the motivation for using this for pub [global] run?
It'll probably improve startup performance a little.
Also programs compiled with dart2native are AOT compiled, meaning they don't get JIT optimizations.
It might be the better choice for users wanting slightly faster startup or for short-lived programs. I agree it should be opt-in though.
Should we consider adding a new tag for it, e.g. ?
name: helloworld
executables:
helloworld:
runtime: aot
Would that also work for a future flutter-desktop world?
Does that make pub sort of a build system. I'm not saying we shouldn't, just that maybe we should think about all the things that will follow and do something more fully conceived.
Obviously, the next thing will be embedded resources.
Pub doesn't need to be a general purpose build system, but it would be nice to provide ways to speed up start-up time by using the existing tools in the Dart SDK (either dart2native or app-jit snapshots). The kernel snapshots are leaving a couple hundred ms on the table, which might be longer than the actual program's execution time.
The startup time is especially noticeable when using the bash completion package.
I think annotating the type of compilation in the executables section of pubspec.yaml is a nice idea...
We could have three values:
aot(compile to binary, dart compile exe)snapshotapp-jit-snapshot(pre-warmed up with a first run during compilation, takes arguments to do the trial run...)