Posts: 6079
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Dart Native on Raspberry Pi

Fri Nov 08, 2019 6:39 pm

I happened to venture across this -

https://www.theregister.co.uk/2019/11/0 ... dart_build
Google software engineers have delivered Dart 2.6, an update to the open source programming language that provides the ability to create self-contained, native executables for the major desktop operating systems.

That capability comes from an extension to the Dart compiler set called dart2native, which makes it possible to turn Dart files into self-contained executables holding ahead-of-time compiled machine code. In other words, these executables will run on machines that don't have the Dart SDK installed.

Dart 2.6 also includes an improved version of dart:ffi, which provides C interoperability, and a new language feature called extension methods.
And support for that includes the Pi. For ARMv7 upwards it is an easy enough process with a downloadable Dart SDK for ARM provided. For ARMv6 ( Pi Zero, Zero W, A, B, A+ and B+ you will need to build the SDK yourself.

Code: Select all

cd ~
wget https://storage.googleapis.com/dart-archive/channels/stable/release/2.6.0/sdk/dartsdk-linux-arm-release.zip
unzip dartsdk-linux-arm-release.zip
./dart-sdk/bin/dart --version
Compilation isn't exactly fast but it does seem to work, generating a native ARM executable, albeit a quite large one and with a .exe extension by default.


Code: Select all

int Fibonacci(int n) {
  if (n <= 1) { return n; }
  else        { return Fibonacci(n-1) + Fibonacci(n-2); };

main() {
On my Pi 3B (non-plus) ...

Code: Select all

[email protected]:~ $ time ./dart-sdk/bin/dart fibo.dart

real    0m4.323s
user    0m5.529s
sys     0m0.241s

Code: Select all

[email protected]:~ $ time ./dart-sdk/bin/dart2native fibo.dart
Generated: /home/pi/fibo.exe

real    0m35.183s
user    0m41.626s
sys     0m1.839s

Code: Select all

[email protected]:~ $ time ./fibo.exe

real    0m0.059s
user    0m0.058s
sys     0m0.002s

Code: Select all

[email protected]:~ $ ls -l fibo.exe
-rwxr-xr-x 1 pi pi 6284048 Nov  8 18:24 fibo.exe

Code: Select all

[email protected]:~ $ file fibo.exe
fibo.exe: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32, stripped

Return to “Other programming languages”