-
Notifications
You must be signed in to change notification settings - Fork 1.7k
FR: Bundle a dart library/snapshot + VM as an executable #27596
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
Comments
Would that be a |
We're already doing tree-shaking and a few optimizations as IR-to-IR transformations. I don't see the need for dart2dart in this setup, but maybe I'm missing something. |
I'm very excited about this general idea. It would make deploying Dart applications to non-Dart users extremely attractive.
What does the
Ideally, I'd like to control both the target OS and the target architecture, even if that means downloading a new Dart binary. I'd expect to be able to generate executables for the same targets that Dart itself is distributed for: Linux, Windows, and OS X both ia32 and x64.
Isn't this just a snapshot like we have today?
If you just mean a JavaScript entrypoint that can be run using |
I would prefer a
I realize that the IR/Kernel means dart2dart might not make any sense. My question is that if I have in my bin/hello_world.dart script: void main() {
print('Hello World');
}
void intentionallyUnusedFunction() {
print('Will somebody use me?');
} And I create a VM snapshot, will
I realize you could just assume the package based on
It is, but the difference here is I'd like it to a simple single file you run, i.e. $ wget https://some.site/http_server.dar
$ chmod +x http_server.dar
$ ./http_server.dart --port 8080
> Running server at 0.0.0.0:8080... (There is no abstraction leak that this is even a Dart binary, in this case)
I imagine it's not a lot of work, but it's the bundling and making it easy/first-class that I'm interested in here. i.e., deploy your package to Google cloud function with a simple script with little or no manual work. (Plus it's important to use DDC because it maps dart:io to NodeJs correctly) |
So the difference between this and a snapshot is that this looks up the Dart VM on the path? How do you handle version skew between the snapshot and the VM? Historically, each VM version only supports its own snapshot version.
I didn't realize DDC had a |
Good point. Depends how clever we want it to be then, I guess you could deploy as a
I think the Node support was an experimental 20% by @ochafik - not sure though. |
It looks like it is defined here: https://github.com/dart-lang/sdk/blob/master/pkg/dev_compiler/tool/input_sdk/patch/io_patch.dart -- looks like just stubs though. |
Oh, I see—that's about the same level of support as dart2js. |
Cool, then yes dart2js might be a fine target. |
@matanlurey: There's a separate IR-to-IR transformation that you can apply before you generate a snapshot: https://github.com/dart-lang/kernel/blob/master/lib/transformations/treeshaker.dart. After running the separate tree shaker on the IR input, the output IR will not contain |
@kasperl Nice! OK, then sounds at least part of this FR already exists 😅 Does the rest of this sound reasonable? |
What's the status of this FR? Is it included into dart? |
No I don't believe so, hence why it isn't closed. |
+1 and kudos for a self-contained approach, that would make dart deployment much easier. |
Adds: - dart2aot, a script similar to dart2js which compiles my.dart to my.dart.aot. - dartaotruntime, a minimal Dart runtime that only runs AOT blobs. - some extra tooling like gen_kernel and gen_snapshot used by the above. - build rules for all of the above, including adding it to the full SDK builds. Bug:#27596 Change-Id: Ic35f832b2b86be959212b8d21cfc5a082da5ced4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97627 Reviewed-by: Alexander Thomas <[email protected]> Reviewed-by: Vyacheslav Egorov <[email protected]> Commit-Queue: Clement Skau <[email protected]>
Doesn't |
Yes, I'm going to close the current issue. Initial support for native execution landed some months back and is documented here: https://dart.dev/tutorials/server/get-started#8-compile-for-production Support for single executable is tracked in #36915 |
Uh oh!
There was an error while loading. Please reload this page.
Strawman
Builds a
.dar
, orDart archive
using the programdar
, bundled as part of the SDK.Assume the following program structure:
We can run
dar build
to bundle a package + an entrypoint:Example use (on BASH compatible OS):
Cross platform support
For (non-bash) windows support, it would be nice to support
--output-exe
:Future optimizations and ideas
"Native" compilation
Like used in Flutter, perhaps we could pre-JIT a snapshot for a platform:
In the future future if we support pure
dart2native
AOT, this could start emitting native code.Without bundling the VM
For platforms where the Dart VM already exists (certain OSs, but also on a managed VM, etc), we could omit bundling the VM/SDK, and just bundle the Dart files. That would make the "executable" significantly smaller for these systems if we can trust the version.
Tree-shaking and optimizations
Once the Kernel is complete and we have extra cycles - revive dart2dart?
NodeJS support
Similar to work done by @srawlins and @kevmoo - being able to bundle as a NodeJS executable means we could run natively on google cloud functions and other platforms that take NodeJS. This would require use of the dart dev compiler today, maybe dart2js in the future.
Potential stakeholders
.sar
like output for Bazel using this scheme?/cc @anders-sandholm @a-siva @floitschG @kevmoo
The text was updated successfully, but these errors were encountered: