Dart 2.6 supports creating self-contained executables
The newest update for Google’s programming language Dart has arrived. The key feature in this update is the new compiler, dart2native. With dart2native, programmers can use the command to compile a Dart program ahead-of-time to native x64 machine code. Dart 2.6 also includes two feature previews and a demo for a console code editor.
Dart 2.6 was announced on November 5, 2019. Version 2.6 arrives with
dart2native, an extension for the compiler set.
With the new update, Dart can product self-contained, native executables.
Have you checked out the language since the implementation of v2.x? Dart 2 fully rebooted the language with a full redesign. It added a more streamlined type system, syntax, and rebuilt dev tool chain. All of these improvements lead to optimized web and mobile development. 2.6 builds upon this 2.x reboot.
With Dart 2.6 onwards, the new
dart2native compiler is available in the Dart SDK.
Programmers can use the command to compile a Dart program ahead-of-time to native x64 machine code. The result is a self-contained executable compiled from the Dart file or an ahead-of-time snapshot that does not include the Dart runtime.
Read more about the compiler and how to create a standalone executable and/or AOT snapshot in the documentation. The feature derives from this issue on GitHub requesting the feature for desktop devices.
According to the release blog, “the executables start running in just a few milliseconds”. The provided sample starts, prints to stdout, and exists in 49 milliseconds.
A few caveats remain. Currently, there is no cross-compilation support for different operating systems. Nor is there signaling support for the executables, or support for
dart:developer . However, these limitations may all be resolved in a future update, based upon developer need.
💥Stable release of Dart 2.6 SDK!
Dart2native AOT-compiles Dart programs to self-contained executables for macOS, Windows, or Linux.
Create tools for the command line that your users can run even if they don’t have the Dart SDK.
— Dart Language (@dart_lang) November 5, 2019
Code editor demo
The dart_console package comes bundled with a demo for kilo, a small code editor written in roughly 500 lines of code.
It clocks in at only 7MB. With it, you can create console apps.
Check out the source code on GitHub.
Feature preview: Extension methods
Test out extension methods as the feature continues active development. Extension methods will call static functions and be able to define extension members for instance, methods, operators, setters, and getters.
Read about the design plans and considerations.
C# and Kotlin already use static extension methods. If timing goes well, extension methods will be included in the next SDK version.
Feature preview graduates to beta:
The new version of Foreign Function Interface in 2.6 introduces a number of breaking API changes. It makes APIs easier to use and provides easier access to memory.
From the changelog, here are the breaking changes this introduces:
- Breaking change: The API now makes use of static extension members. Static extension members enable the
dart:ffiAPI to be more precise with types, and provide convenient access to memory through extension getters and setters. The extension members on
.value =for accessing the value in native memory and
=for indexed access. The method
asExternalTypedDatahas been replaced with
asTypedListextension methods. And finally,
Structsdo no longer have a type argument and are accessed using the extension member
Pointer. These changes makes the code using
dart:ffimuch more concise.
- Breaking change: The memory management has been removed (
Pointer.free). Instead, memory management is available in package:ffi.
- Breaking change:
Pointer.offsetBywas removed, use
- Faster memory load and stores.
- The dartanalyzer (commandline and IDEs) now reports
- Callbacks are now supported in AOT (ahead-of-time) compiled code.
Miscellaneous changes include:
- Linter updated to 0.1.101
- dart:io library: Added