Dart 2.6 brings native compilation to the desktop

A new extension to the Dart compiler set allows you to create self-contained executables for Linux, MacOS, and Windows

Dart 2.6 brings native compilation to the desktop
Getty Images

As part of the recent rollout of Dart 2.6, the Google engineers behind the language introduced dart2native, an extension to the Dart compiler set that extends native compilation to the Linux, MacOS, and Windows desktop platforms.

This extension offers the ability to compile Dart programs to self-contained executables. These executables contain ahead-of-time compiled machine code. Because dart2native extends native compilation support to traditional desktop OSes running Linux, MacOS, and Windows, it allows native applications to be built in Dart for these platforms. 

Compiled with Dart’s AOT compiler, executables can run on machines without the Dart SDK installed. They also start running in a matter of milliseconds. Previously, native compilation to machine code was limited to the iOS and Android mobile platforms. Users had asked for AOT compilation for desktop OSes.

The dart2native extension enables building and deploying of apps for the command line. These apps use libraries such as dart.io for IO; package:httpcode for networking, and package:args for parsing arguments. The extension also is compatible with dart:ffi, a mechanism for C language interoperability that was launched in preview in Dart 2.5. A new version is offered in Dart 2.6.

The dart2native compiler also can be used for small services such as a back-end supporting a front-end app using the Flutter toolkit. But dart2native does have some initial limitations, such as no cross-compilation support. The compiler supports creating machine code only for the OS it is running on, so would need to be run three times to create executables for MacOS, Linux, and Windows. Executables produced also cannot be signed.

Also featured in Dart 2.6 is a preview of static extension methods, a language feature that could solve an issue with introducing new functionality to existing types.

Where to download Dart 2.6 and dart2native

You can get Dart 2.6 and the dart2native compiler by downloading the Dart SDK. Instructions for installing the SDK can be found at dart.dev.