Changes

Jump to: navigation, search
Created page with "{{InfoBoxTop}} {{AppliesTo ORCA AN}} {{AppliesTo MITO 8M Mini AN}} {{InfoBoxBottom}} {{ImportantMessage|text=This application note has been validated using the '''kit version..."
{{InfoBoxTop}}
{{AppliesTo ORCA AN}}
{{AppliesTo MITO 8M Mini AN}}
{{InfoBoxBottom}}

{{ImportantMessage|text=This application note has been validated using the '''kit version''' in the History table.}}

==History==

{| class="wikitable" border="1"
!Version
!Date
!Development Kit version
|-
| 1.0.0
| Mar 2024
|[[DESK-MX8M-L/General/Release_Notes#DESK-MX8M-L_4.0.0|DESK-MX8M-L 4.0.0]]
|-
|}

== Introduction ==
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 [https://github.com/dart-lang 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 (<code>dartdevc</code>) and a production time compiler (<code>dart2js</code>)
[[File:Dart-platforms.png]]
== Creating the SDK ==
It is possible to build the Dart VM and/or SDK using the instruction listed in the [https://github.com/dart-lang/sdk/wiki/Building-Dart-SDK-for-ARM-or-RISC-V Building Dart SDK for ARM] github page.

The following steps have been performed using the Ubuntu 20.04 [[DESK-MX8M-L |DESK-MX8M-L 4.0.0]] Virtual Machine provided along the DESK-MX8M-L DAVE's Embedded systems developing environment for the i.MX8M Plus [[ORCA_SOM | ORCA]] and [[MITO 8M Mini SOM | MITO 8M Mini]] products.

=== Preparing the building environment ===
* Ubuntu cross-toolchain for ARM has to be installed, using <code>apt-get</code>
sudo apt-get install curl
sudo apt-get install g++-aarch64-linux-gnu

=== Building the SDK ===
The git repository from Google sources can be cloned
<pre class="workstation-terminal">
dvdk@vagrant:~/dart$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
Cloning into 'depot_tools'...
remote: Sending approximately 46.89 MiB ...
remote: Counting objects: 3, done
remote: Finding sources: 100% (3/3)
remote: Total 58236 (delta 42064), reused 58234 (delta 42064)
Receiving objects: 100% (58236/58236), 46.90 MiB | 11.64 MiB/s, done.
Resolving deltas: 100% (42064/42064), done.
dvdk@vagrant:~/dart$ export PATH="$PATH:$PWD/depot_tools"
dvdk@vagrant:~/dart$
</pre>
Then, the proper <code>dart</code> sources fetched in the build directory
<pre class="workstation-terminal">
dvdk@vagrant:~/dart$ mkdir dart-sdk
dvdk@vagrant:~/dart$ cd dart-sdk
dvdk@vagrant:~/dart/dart-sdk$ fetch dart
Running: gclient root
WARNING: Your metrics.cfg file was invalid or nonexistent. A new one will be created.
Running: gclient config --spec 'solutions = [
{
"name": "sdk",
"url": "https://dart.googlesource.com/sdk.git",
"deps_file": "DEPS",
"managed": False,
"custom_deps": {},
},
]
'
Running: gclient sync
________ running 'git -c core.deltaBaseCacheLimit=2g clone --no-checkout --progress https://dart.googlesource.com/sdk.git /home/dvdk/dart/dart-sdk/_gclient_sdk_5ci28x8d' in '/home/dvdk/dart/dart-sdk'
Cloning into '/home/dvdk/dart/dart-sdk/_gclient_sdk_5ci28x8d'...
remote: Sending approximately 1.11 GiB ...
remote: Counting objects: 11597, done
remote: Finding sources: 100% (78/78)
remote: Total 1525300 (delta 1276749), reused 1525289 (delta 1276749)
Receiving objects: 100% (1525300/1525300), 1.10 GiB | 11.50 MiB/s, done.
Resolving deltas: 100% (1276749/1276749), done.
Syncing projects: 100% (105/105), done.
Running: git config --add remote.origin.fetch '+refs/tags/*:refs/tags/*'
Running: git config diff.ignoreSubmodules dirty
dvdk@vagrant:~/dart/dart-sdk$
</pre>

* The <code>linux</code> target has be selected and synced
<pre class="workstation-terminal">
dvdk@vagrant:~/dart/dart-sdk$ echo "target_os = ['linux']" >> .gclient
dvdk@vagrant:~/dart/dart-sdk$
dvdk@vagrant:~/dart/dart-sdk$ gclient sync
Syncing projects: 100% (105/105), done.
dvdk@vagrant:~/dart/dart-sdk$
</pre>
* ''for building'' the SDK, a dedicated Python script can be used. Running the script, it produces the Dart SDK:
<pre class="workstation-terminal">
dvdk@vagrant:~/dart/dart-sdk/sdk$ ./tools/build.py --no-goma --no-clang --mode release --arch arm64 create_sdk
...
...
[2610/2610] STAMP obj/create_sdk.stamp
The build took 1540.750 seconds
dvdk@vagrant:~/dart/dart-sdk/sdk$ cd out/ReleaseXARM64/dart-sdk/
dvdk@vagrant:~/dart/dart-sdk/sdk/out/ReleaseXARM64/dart-sdk$ ls -la
total 40
drwxrwxr-x 5 dvdk dvdk 4096 Mar 26 10:37 .
drwxrwxr-x 9 dvdk dvdk 4096 Mar 26 11:34 ..
drwxrwxr-x 5 dvdk dvdk 4096 Mar 26 11:34 bin
-rw-rw-r-- 1 dvdk dvdk 1768 Mar 26 10:37 dartdoc_options.yaml
drwxrwxr-x 3 dvdk dvdk 4096 Mar 26 10:34 include
drwxrwxr-x 29 dvdk dvdk 4096 Mar 26 10:37 lib
-rw-rw-r-- 2 dvdk dvdk 1502 Mar 26 10:23 LICENSE
-rw-rw-r-- 2 dvdk dvdk 1271 Mar 26 10:23 README
-rw-rw-r-- 1 dvdk dvdk 41 Mar 26 10:37 revision
-rw-rw-r-- 1 dvdk dvdk 52 Mar 26 10:37 version
dvdk@vagrant:~/dart/dart-sdk/sdk/out/ReleaseXARM64/dart-sdk$
</pre>
* as reported [https://github.com/dart-lang/sdk/wiki/Building-Dart-SDK-for-ARM-or-RISC-V 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 ==
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''):
<pre class="workstation-terminal">
dvdk@vagrant:~/dart/dart-sdk/sdk/out/ReleaseXARM64/dart-sdk$ sudo tar zcpf ../../../../../dart-sdk-arm64.tar.gz *
dvdk@vagrant:~/dart/dart-sdk/sdk/out/ReleaseXARM64/dart-sdk$ cd ../../../../..
dvdk@vagrant:~/dart$ ls -la
total 133484
drwxrwxr-x 4 dvdk dvdk 4096 Mar 26 12:05 ./
drwxr-xr-x 20 dvdk dvdk 4096 Mar 26 10:34 ../
drwxrwxr-x 4 dvdk dvdk 4096 Mar 26 10:33 dart-sdk/
-rw-r--r-- 1 root root 136658509 Mar 26 12:05 dart-sdk-arm64.tar.gz
drwxrwxr-x 21 dvdk dvdk 12288 Mar 26 10:21 depot_tools/
dvdk@vagrant:~/dart$
</pre>

Then remote copy the SDK tarball into the target:
<pre class="workstation-terminal">
dvdk@vagrant:~/dart$ scp dart-sdk-arm64.tar.gz root@192.168.0.90:/home/root
The authenticity of host '192.168.0.90 (192.168.0.90)' can't be established.
ECDSA key fingerprint is SHA256:QEN8INGUdOrzVfwhRgoa1Wqxmg/DZUXcTBe9f/PaPAM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.0.90' (ECDSA) to the list of known hosts.
dart-sdk-arm64.tar.gz 100% 130MB 53.3MB/s 00:02
dvdk@vagrant:~/dart$
</pre>
and extract the archive in the <code>/usr/bin</code> target directory:
<pre class="board-terminal">
root@desk-mx8mp:~# mkdir /usr/bin/dart-sdk
root@desk-mx8mp:~# cd /usr/bin/dart-sdk
root@desk-mx8mp:/usr/bin/dart-sdk# tar zxpf /home/root/dart-sdk-arm64.tar.gz
root@desk-mx8mp:/usr/bin/dart-sdk# export PATH=$PATH:/usr/bin/dart-sdk/bin
root@desk-mx8mp:/usr/bin/dart-sdk#
</pre>

It runs and shows the version
<pre class="board-terminal">
root@desk-mx8mp:~# dart --version
Dart SDK version: 3.4.0-edge.93d2d44b26040fb3e0f4dc03b85e87aa008f9909 (main) (Tue Mar 26 06:57:47 2024 +0000) on "linux_arm64"
root@desk-mx8mp:~#
</pre>

== Running the ''Hello world'' example ==
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:
<pre>
void main(){
print("Hello World");
}
</pre>
corresponding to the created <code>hello_world.dart</code> text file. It produces on the target:
<pre class="board-terminal">
root@desk-mx8mp:~# dart hello_world.dart
Hello World
root@desk-mx8mp:~#
</pre>
The compiled version can be created for faster execution:
dart compile exe hello_world.dart
which produce a fast executable version:
<pre class="board-terminal">
root@desk-mx8mp:~# time ./hello_world.exe
Hello World

real 0m0.016s
user 0m0.015s
sys 0m0.005s
root@desk-mx8mp:~#
</pre>
versus the VM one:
<pre class="board-terminal">
root@desk-mx8mp:~# time dart hello_world.dart
Hello World

real 0m4.575s
user 0m5.400s
sys 0m0.322s
root@desk-mx8mp:~#
</pre>
== More information ==
* [https://dart.dev/overview Dart overview]
* [https://dart.dev/packages Dart packages] - ''The Dart ecosystem uses packages to manage shared software such as libraries and tools''
* [https://dart.dev/tools/pub/pubspec The pubspec file]
8,154
edits

Navigation menu