A tutorial/template to build a vibed web application on a raspberryPi board.
The board can be used as a REST server to use the Pi IO with the dgpio
dub package.
NOTE: The project has been tested on ArchLinuxARM on a RaspberryPi3 board compiled from an Ubuntu 18.04 x86-64 environment.
One can use the flask-python stack to use the the Pi as a REST IOT server. But D is really FAST on the pi board. No jokes.
Set the variables in the ldc-pi
script.
Remember that the path directories must be absolute and not relative in order to avoid weird situations within dub
.
Then:
chmod +x ./ldc-pi
dub --compiler=./ldc-pi
ldc-pi is a shell script to set the local variables. This is necessary to propagate the build settings to every project dependency.
The important flags used are the same for the LDC Runtime cross-building:
ldc2 -mtriple=arm-linux-gnueabihf -gcc=arm-linux-gnueabihf-gcc
Make sure to have installed the cross compiler arm-linux-gnueabihf-gcc
.
Open a terminal and digit:
sudo apt-get install gcc-arm-linux-gnueabihf
Follow the instructions here: Building_LDC_runtime_libraries. Again: make sure to have the dependencies required
sudo apt-get install gcc-arm-linux-gnueabihf ninja-build cmake
Be sure to have the last LDC2 installed on the system.
You can find them here: LDC2_Releases.
Download the one that fits the host machine. For example if you are compiling the project on a Intel processor you need to download the linux-x86_64
one.
After that:
export LDC2_DIR=/path/to/ldc2
export CC=arm-linux-gnueabihf-gcc
$LDC2_DIR/bin/ldc-build-runtime --ninja --dFlags="-w;-mtriple=arm-linux-gnueabihf"
This will build the ldc-build-runtime.tmp
folder you can link at after at build time.
Vibe.d has two external dependencies that need a manual cross compilation (or a properly setted cross-gcc toolchain):
git clone https://github.com/openssl/openssl
As done for LDC Runtime let's cross-compile the openssl library.
Enter the directory and set the ./Configure
script variables.
export INSTALL-DIR=/path/to/openssl/install/dir
./Configure linux-generic32 shared \
--prefix=$INSTALL_DIR --openssldir=$INSTALL_DIR/openssl \
--cross-compile-prefix=arm-linux-gnueabihf-
Note: look at the cross compile prefix variabile. It will append gcc
automatically. It must use the same compiler used for the ldc runtime.
Then finally:
make
make install
The folder user for the INSTALL-DIR
now contains the libraries cross-compiled. You can see an example in the lib
folder.
Finally let's cross compile the ZLIB library. Download it from the ZLIB_Website. As done for the open-ssl:
export CC=arm-linux-gnueabihf-gcc
export INSTALL-DIR=/path/to/zlib/install/dir
make
make install
And we are done.