DESK-MX6UL-AN-0005: Using DART for embedded applications

From DAVE Developer's Wiki
Revision as of 22:36, 25 March 2024 by U0007 (talk | contribs) (Preparing the building environment)

Jump to: navigation, search
Info Box


200px-Emblem-important.svg.png

This application note has been validated using the kit version in the History table.

History[edit | edit source]

Version Date Development Kit version
1.0.0 Oct 2022 DESK-MX6UL-L 3.0.0

Introduction[edit | edit source]

Dart is an open-source, scalable programming language, with robust libraries and runtimes, for building web, server, and mobile apps. Dart is a client-optimized language for fast apps on any platform. As described in the Dart github repository, Dart is:

  • Optimized for UI: Develop with a programming language specialized around the needs of user interface creation.
  • Productive: Make changes iteratively: use hot reload to see the result instantly in your running app.
  • Fast on all platforms: Compile to ARM & x64 machine code for mobile, desktop, and backend. Or compile to JavaScript for the web.

Dart's flexible compiler technology lets you run Dart code in different ways, depending on your target platform and goals:

  • Dart Native: For programs targeting devices (mobile, desktop, server, and more), Dart Native includes both a Dart VM with JIT (just-in-time) compilation and an AOT (ahead-of-time) compiler for producing machine code
  • Dart Web: For programs targeting the web, Dart Web includes both a development time compiler (dartdevc) and a production time compiler (dart2js)

Dart-platforms.png

Creating the SDK[edit | edit source]

It is possible to build the Dart VM and/or SDK using the instruction listed in the Building Dart SDK for ARM github page.

The following steps have been performed using the Ubuntu 20.04 DESK-MX6-UL-3.0.0 Virtual Machine provided along the DESK-MX6UL-L DAVE's Embedded systems developing environment for the i.MX6UL AXEL ULite SOM and SBC Lynx products.

Preparing the building environment[edit | edit source]

  • Ubuntu cross-toolchain for ARM has to be installed, using apt-get
sudo apt-get install git python3 curl xz-utils
sudo apt-get install gcc-arm-linux-gnueabihf g++-9-arm-linux-gnueabihf gcc-multilib 
sudo apt-get install g++-arm-linux-gnueabihf g++-multilib

Building the SDK[edit | edit source]

The git repository from Google source can be cloned

dvdk@vagrant:~/dart$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
Cloning into 'depot_tools'...
remote: Sending approximately 37.04 MiB ...
remote: Total 51219 (delta 37978), reused 51219 (delta 37978)
Receiving objects: 100% (51219/51219), 37.00 MiB | 3.71 MiB/s, done.
Resolving deltas: 100% (37978/37978), done.
dvdk@vagrant:~/dart$ export PATH="$PATH:$PWD/depot_tools"
dvdk@vagrant:~/dart$ 

and the proper sources fetched in the build directory

mkdir dart-sdk
cd dart-sdk
fetch dart
  • now it is possible to checkout the master branch
git checkout master
  • then, the linux target can be selected and synced
dvdk@vagrant:~/dart/dart-sdk$ echo "target_os = ['linux']" >> .gclient
dvdk@vagrant:~/dart/dart-sdk$ gclient sync
Updating depot_tools...
Syncing projects: 100% (99/99), done.                                                                    
Running hooks: 100% (10/10), done.              
dvdk@vagrant:~/dart/dart-sdk$ 
  • for building the SDK, a dedicated Python script can be used
cd sdk
./tools/build.py
  • running the script, it produces the Dart SDK:
dvdk@vagrant:~/dart/dart-sdk/sdk$ ./tools/build.py --no-goma -m release --arch=arm create_sdk
Done. Made 351 targets from 90 files in 1075ms
buildtools/ninja/ninja -C out/ReleaseXARM create_sdk
ninja: Entering directory `out/ReleaseXARM'
[4167/4167] STAMP obj/create_sdk.stamp
The build took 3665.992 seconds
dvdk@vagrant:~/dart/dart-sdk/sdk$ ls -la out/ReleaseXARM/dart-sdk/
total 44
drwxrwxr-x  6 dvdk dvdk 4096 Oct 14 15:45 .
drwxrwxr-x  9 dvdk dvdk 4096 Oct 14 15:45 ..
drwxrwxr-x  5 dvdk dvdk 4096 Oct 14 15:45 bin
-rw-rw-r--  1 dvdk dvdk  928 Oct 14 14:54 dartdoc_options.yaml
drwxrwxr-x  3 dvdk dvdk 4096 Oct 14 14:45 include
drwxrwxr-x 27 dvdk dvdk 4096 Oct 14 15:31 lib
-rw-rw-r--  2 dvdk dvdk 1502 Oct 14 11:28 LICENSE
-rw-rw-r--  2 dvdk dvdk 1338 Oct 14 11:28 README
-rw-rw-r--  1 dvdk dvdk   41 Oct 14 14:54 revision
drwxrwxr-x  2 dvdk dvdk 4096 Oct 14 15:45 snapshots
-rw-rw-r--  1 dvdk dvdk   53 Oct 14 14:54 version
dvdk@vagrant:~/dart/dart-sdk/sdk$ 

As reported here:

You can also produce only a Dart VM runtime, no SDK, by replacing create_sdk with runtime. This process involves also building a VM that targets ia32/x64, which is used to generate a few parts of the SDK

Installing the SDK in the target[edit | edit source]

Once the SDK image has been created, it is possible to create an archive and copy it in the target (for example using scp or ftp):

dvdk@vagrant:~/dart/dart-sdk/sdk/out/ReleaseXARM/dart-sdk$ ls -la
total 44
drwxrwxr-x  6 dvdk dvdk 4096 Oct 14 15:45 ./
drwxrwxr-x  9 dvdk dvdk 4096 Oct 14 15:45 ../
drwxrwxr-x  5 dvdk dvdk 4096 Oct 14 15:45 bin/
-rw-rw-r--  1 dvdk dvdk  928 Oct 14 14:54 dartdoc_options.yaml
drwxrwxr-x  3 dvdk dvdk 4096 Oct 14 14:45 include/
drwxrwxr-x 27 dvdk dvdk 4096 Oct 14 15:31 lib/
-rw-rw-r--  2 dvdk dvdk 1502 Oct 14 11:28 LICENSE
-rw-rw-r--  2 dvdk dvdk 1338 Oct 14 11:28 README
-rw-rw-r--  1 dvdk dvdk   41 Oct 14 14:54 revision
drwxrwxr-x  2 dvdk dvdk 4096 Oct 14 15:45 snapshots/
-rw-rw-r--  1 dvdk dvdk   53 Oct 14 14:54 version
dvdk@vagrant:~/dart/dart-sdk/sdk/out/ReleaseXARM/dart-sdk$ sudo tar zcpf ../dart-sdk-arm.tar.gz *
dvdk@vagrant:~/dart/dart-sdk/sdk/out/ReleaseXARM/dart-sdk$ 

and then extract the archive in the /usr/bin target directory:

root@desk-mx6ul-lynx:/usr/bin# mkdir dart-sdk
root@desk-mx6ul-lynx:/usr/bin# cd dart-sdk
root@desk-mx6ul-lynx:/usr/bin/dart-sdk# scp user@192.168.0.23:/tmp/dart* .
user@192.168.0.23's password:
dart-sdk-arm.tar.gz                                                                                                                  100%  114MB   2.2MB/s   00:52
root@desk-mx6ul-lynx:/usr/bin/dart-sdk# tar zxpf dart-sdk-arm.tar.gz
root@desk-mx6ul-lynx:/usr/bin/dart-sdk# 

It runs and shows the version

root@desk-mx6ul-lynx:/usr/bin/dart-sdk# ./bin/dart --version
Dart SDK version: 2.19.0-edge.5501c7f9787b77897b9ac6fdd22103f273663d0d (be) (Fri Oct 14 03:13:52 2022 +0000) on "linux_arm"
root@desk-mx6ul-lynx:/usr/bin/dart-sdk#

Running the Hello world example[edit | edit source]

Before running a Hello World in Dart the Dart SDK has to be installed on the target, i.e. the previous steps have to be already accomplished.

The simpler example written in Dart can be the following one:

void main(){
   print("Hello World");
}

corresponding to the created hello_world.dart text file. It produces in the target:

root@desk-mx6ul-lynx:~# dart hello_world.dart
Hello World
root@desk-mx6ul-lynx:~#

The compiled version can be created for faster execution:

dart compile exe hello_world.dart

which produce a fast executable version:

root@desk-mx6ul-lynx:~# time ./hello_world.exe
Hello World

real    0m1.072s
user    0m0.032s
sys     0m0.036s
root@desk-mx6ul-lynx:~#

versus the VM one:

root@desk-mx6ul-lynx:~# time dart hello_world.dart
Hello World

real    0m24.370s
user    0m20.781s
sys     0m1.479s
root@desk-mx6ul-lynx:~#

More information[edit | edit source]