days
-3
-6
hours
-2
-3
minutes
-2
0
seconds
-1
-6
search
Dart hits the spot

Dart 2.6 supports creating self-contained executables

Sarah Schlothauer
dart
© Shutterstock / Olivier Le Moal

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.

dart2native

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:mirrors and dart:developer . However, these limitations may all be resolved in a future update, based upon developer need.

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.

SEE ALSO: How to supercharge innovation with a Dev Day

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: dart:ffi 

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.

SEE ALSO: Flutter developers survey: Documentation is key to Flutter’s success

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:ffi API to be more precise with types, and provide convenient access to memory through extension getters and setters. The extension members on Pointer provide .value and .value = for accessing the value in native memory and [] and []= for indexed access. The method asExternalTypedData has been replaced with asTypedList extension methods. And finally, Structs do no longer have a type argument and are accessed using the extension member .ref on Pointer. These changes makes the code using dart:ffi much more concise.
  • Breaking change: The memory management has been removed (Pointer.allocate and Pointer.free). Instead, memory management is available in package:ffi.
  • Breaking changePointer.offsetBy was removed, use cast and elementAt instead.
  • Faster memory load and stores.
  • The dartanalyzer (commandline and IDEs) now reports dart:ffi static errors.
  • Callbacks are now supported in AOT (ahead-of-time) compiled code.

Other changes

Miscellaneous changes include:

  • Linter updated to 0.1.101
  • Removed Pointer.offsetBy 
  • dart:io library: Added IOOverrides.serverSocketBind
Author
Sarah Schlothauer

Sarah Schlothauer

All Posts by Sarah Schlothauer

Sarah Schlothauer is an assistant editor for JAXenter.com. She received her Bachelor's degree from Monmouth University and is currently enrolled at Goethe University in Frankfurt, Germany where she is working on her Masters. She lives in Frankfurt with her husband and cat.

Leave a Reply

Be the First to Comment!

avatar
400
  Subscribe  
Notify of