For a DIY project I’m working on I need to run a Dart project on my Raspberry Pi board, precisely in his Raspbian OS. The Dart team has done a good job publishing a wiki page with all the information to build the SDK. Here I’m summarizing the necessary steps in a handy list, or, if you prefer, at the end of the post you can find a zip file with the SDK already built.
I suggest you run the entire process in a virtual machine in order to have a clean environment and the best compatibility with the provided scripts.
- Download the Ubuntu server 12.04.5 64-bit ISO.
- Install your virtualization software, I’ve used VirtualBox.
- Create a new Virtual Machine. In VirtualBox using the wizard, select Linux OS and Ubuntu 64 bit. Here’s my VM configuration:
- 4 GB ram
- 23 GB HD, the used space after the entire process is about 11 GB
- 2 processors (the core available in my hosting machine)
- TCP ssh port forwarding (My host OS is a Linux with sshd active)
- Install Ubuntu server through the downloaded ISO. During the configuration, in the package selection phase, select the OpenSSH Server, we will use scp to copy the produced SDK.
READY TO START
Login in Ubuntu and create a working directory. All the following commands are relative to the created working folder.
Download and run the script that installs all the necessary dependencies.
$ wget http://src.chromium.org/svn/trunk/src/build/install-build-deps.sh
$ chmod u+x install-build-deps.sh
$ ./install-build-deps.sh --no-chromeos-fonts --arm
$ sudo apt-get install libc6-dev-i386 g++-multilib
DEPOT TOOLS INSTALLATION
Download and setup the source code management tools provided for chromium.
$ svn co http://src.chromium.org/svn/trunk/tools/depot_tools
$ export PATH=$PATH:`pwd`//depot_tools
SOURCE CODE DOWNLOAD
Download the Dart 1.7 source code (if you want the latest developed version use this url: http://dart.googlecode.com/svn/branches/bleeding_edge/deps/all.deps)
$ gclient config http://dart.googlecode.com/svn/branches/1.7/deps/all.deps
$ gclient sync
TOOL CHAIN DOWNLOAD
We are going to cross compile the code so we need the tool chain provided by Raspberry Pi.
$ git clone https://github.com/raspberrypi/tools.git
Finally we are ready to compile. In the meanwhile you can go to take a coffee.
$ cd dart
$ ./tools/build.py -m release -a arm --toolchain=../tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf create_sdk
Copy the dart-sdk folder under the dart/out/ReleaseXARM folder to your Raspberry Pi machine (using scp or your folder explorer).
If you like to make the Dart commands available in the command line edit your .bashrc file in your Raspbian installation and add these lines (modify the dart-sdk path based on your installation path):
READY TO RUN
You can check if the dart installation is working by simply running it. You should see this output:
pi@raspberrypi ~ $ dart
Usage: dart [<vm-flags>] <dart-script-file> [<dart-options>]
Executes the Dart script passed as <dart-script-file>.
--checked or -c
Insert runtime type checks and enable assertions (checked mode).
--help or -h
Display this message (add -v or --verbose for information about
all VM options).
--package-root=<path> or -p<path>
Where to find packages, that is, "package:..." imports.
Print the VM version.
LET’S RUN HELLO WORLD
As final step let’s run a simple Hello World project. We can create such simple project quickly using the new Stagehand tool. First we need to install it:
pi@raspberrypi ~/dart/projects $ pub global activate stagehand
We are now ready to create the project:
pi@raspberrypi ~/dart/projects $ mkdir HelloWorld
pi@raspberrypi ~/dart/projects $ cd HelloWorld/
pi@raspberrypi ~/dart/projects/HelloWorld $ stagehand consoleapp
The project is ready, let’s get hits dependencies and run it:
pi@raspberrypi ~/dart/projects/HelloWorld $ pub get
pi@raspberrypi ~/dart/projects/HelloWorld $ dart bin/main.dart
Hello world: 42!
THE FAST WAY
If all these steps scares you, then you can download the zipped folder with the Dart SDK that I’ve prepared. You’re downloading it and using it at your own risk.