dart2native: support creating self-contained binary executables

Feature request originally split from the related and now solved issue #34343 (comment).

Thanks to Dart 2.3 AOT mode compiling is now supported through the dart2aot utility.
For easier deployment and usability creating a single binary executable file would be a great feature to have.

Author: Fantashit

17 thoughts on “dart2native: support creating self-contained binary executables

  1. Just want to say: i really like flutter and Dart; every time i look into some introductions, i am waiting for AOT single binary to use it as main programming language overall 💯

    So, this maybe thoughts of many people, which are interested in flutter and / or Dart itself, but waiting for AOT the last years.

    Very happy if it´s available 🥇

  2. I also second the request for single (self-contained) binary output – this would be a welcome step in enabling e.g. multistage builds in Docker where we can throw out most of the dart run-time and get the container sizes down to something more manageable for FaaS and microservice deployments.

  3. Can we get some update? How long will we stay here? There is nothing upcoming in changelog till now…

    Thanks 👍

  4. Well, this is one of the best features after a long time. Do we have any language which is compiled and typed as well as high level and pretty much CONCISE + Supports OOP?
    There is OCaml which has some weird syntax(double semicolons required for line breaks, etc. Not concise also datatypes are weird, they use 1bit from every data type for garbage collection). Also there is Pascal but really who wants to add BEGIN and END blocks every where, such a time waste. So we are down to C++ which is actually quite complex and not concise and clean.

    At last we got Swift, but you know Apple right? they open sourced swift(that too a limited one with less libraries supported) to gain devs, so let’s skip apple.
    Now Go is pretty good, but does it support OOP? No. And Rust is quite low level and I didn’t really like it because it complicates simple tasks, its like java. BuildHorse(CoverWithSkin(AttachBones(CreateSkeleton())), Horse.Sane, Horse.Trained ……., Horse.ShouldBePolite, Horse.Alive);

    Dart is the only concise, simple, compiled language which you can count on.
    I can understand that JIT is far better for dynamic languages as it can intelligently check whether the type is changing.
    But anyone who says that a JIT is better for a typed language than ahead of time compilation, slap The C language on his face. What optimizations would a JIT do in typed language? There is very few to none, which is actually detrimental once you add the cost for JITing.

  5. Performance comparison between AOT and JIT is very nuanced and highly dependant on a particular workload. In general Dart AOT can’t necessarily devirtualize all the same calls that JIT can e.g. just declaring a variable as List<int> v does not actually give enough information to compiler to produce the best code for v[i] or similarly declaring a variable as int x; int y does not tell compiler anything (it can be null, or maybe smi, or maybe boxed 64-bit integer), so compiler can’t necessarily compile x + y into the best possible instruction sequence. JIT compiler compensates for the lack of information by collecting dynamic type profile and by performing speculative optimisations based on that type profile. AOT compensates for the lack of information by trying to do some global analyses. Sometimes one approach is more powerful, sometimes another.

    In any case – discussion of JIT vs AOT performance characteristics does not necessarily belong to this issue and should better be taken on other mediums (e.g. on Dart mailing list).

  6. @javaddict sorry, i downvoted you (#36915 (comment)) because this is a discussion about getting a tool to create a single binary out of the code. There is no discussion to compare against Java nor Kotlin, nor to replace native android programming.

    The only discussion background here is to create a single binary out of the box, because with Dart we have a language which is:

    • cross-platform, web
    • android, iOS, Windows, Mac OS, Linux, JS
    • front-end and back-end

    which means we are able to write mobile apps, web-apps and desktop-apps (which all will have their compiled format) and we are able to compile the whole server backend to a / several binaries.

    This is: to have a language which suites much needs and to have compiled binarys instead of naked code files, which is simply more safe and usable. In my intention this is not about AOT vs. JIT, vs. Kotlin, whatever.

    Simply: it is about generating single binaries.

    So, i would really like to have this feature 👍

  7. Strongly typed languages with garbage collection still need runtime systems, even when executing AOT-compiled machine code. This runtime system is responsible for performing dynamic type checks, and for freeing memory no longer used.

    Can we get a single binary that contains both runtime and machine code? I want to distribute a single file like golang without install dart runtime on other devices. @mit-mit

  8. Hey looks cool, Dart VM version: 2.6.0-dev.3.0 on “linux_x64” is working fine.
    dart2native helloworld.dart
    Generated: /home/xxx/helloworld.dart.exe

    Are you going to or can we have the option to name the generated executable,
    so the following is possible?
    dart2native helloworld.dart helloworld
    Generated: /home/xxx/helloworld

    Anyway on my i5 nuc – NUC6i5SYH
    time ./helloworld.dart.exe
    hello world!

    real 0m0.011s
    user 0m0.001s
    sys 0m0.011s

    time dart helloworld.dart
    hello world!

    real 0m0.129s
    user 0m0.172s
    sys 0m0.063s

  9. I can confirm success with dart2native – I’m able to reduce my container size from ~250MB to 25MB, which is a great improvement, especially as we begin to use Dart for cloud functions in OpenFaaS. An option for static linking so that we can toss out more of the runtime environment would be nice, and would likely bring this down to ~10MB, in line wither other languages (e.g. Golang).

  10. As asarnaak and sebe i have done some tests against startup time compared to C and Go, where Dart is ~20 times slower, but, all in all, this is a very big enhancement, and i would like to use Dart now whenever possible. For me, this issue is a game changer to all. Pretty cool!

  11. Just wanted to say thanks, i wanted to use dart for a command line application about a month ago and found I couldn’t package a single binary for my customer, so I had to skip it and write it in NodeS instead (it will likely need to be embedded into an interface at some point). Would have loved to use this – and now that its available I will definitely be using this in the future.

    IMO this is the final piece of the dart puzzle to go almost exclusively dart.

    So once again, a big thanks for listening to the community and prioritising a needed feature.

Comments are closed.