Compiling Crystal on ARM
Compiling Crystal on ARM is not very common. This is how I did it in order to compile and test CNF Conformance on ARM.
Compiling Crystal on ARM is not very common. This is how I did it in order to compile and test CNF Conformance on ARM.
I was recently tasked to get crystal compiled on ARM for testing CNF Conformance which is an open source test suite to demonstrate conformance and implementation of Cloud Native Network Functions for vendors running Kubernetes.
I don't consider myself a code developer but am familiar with the basic development tools and building packages from source.
These are the steps outlined on Ubuntu Linux 18.04 LTS I got Crystal compiled in order to run crystal builds on ARM.
Install Development Package Dependencies and Other Pre-Req's
apt install gcc llvm-7 graphviz libevent-dev g++ libpcre3-dev libpcre++-dev libgc-dev libyaml-dev libxml2-dev libcrypto++-dev libssl-dev
gcc -dumpmachine
aarch64-linux-gnu
, your output may differ but take note of this as we have to cross compile on x86 in the next steps.git clone https://github.com/crystal-lang/crystal.git
cd crystal; git checkout 0.33.0
Compile on x86 First
apt install gcc llvm-7 graphviz libevent-dev g++ libpcre3-dev libpcre++-dev libgc-dev libyaml-dev libxml2-dev libcrypto++-dev libssl-dev
git clone https://github.com/crystal-lang/crystal.git
cd crystal; git checkout 0.33.0
make crystal
or it will complain about missing files on our compile.--target
in the command:./bin/crystal build src/compiler/crystal.cr --cross-compile --target=aarch64-linux-gnu -D without_openssl -D without_zlib --release
./bin/crystal
which uses the crystal source code wrapper script. If you already have crystal installed, using the installed crystal command will fail.crystal.o
file now you can copy to your target ARM host and take note of the command it provides for you to run next to build crystal. We'll use this command on our ARM host compile.Compile on ARM
crystal.o
file, do the following on your ARM host.
crystal.o
file into your checked out crystal repo where you already checked out the 0.33.0 version to compile.cc 'crystal.o' -o 'crystal' -rdynamic ./crystal/src/llvm/ext/llvm_ext.o '/usr/bin/llvm-config-7 --libs --system-libs --ldflags 2> /dev/null' -lstdc++ -lpcre -lm /usr/local/depot/crystal-0.33.0-1/bin/../lib/crystal/lib/libgc.a -lpthread /home/user/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/local/depot/crystal-0.33.0-1/bin/../lib/crystal/lib -L/usr/lib -L/usr/local/lib
crystal
binary in your checked out repo ./crystal
directory but you're not finished, you'll have to use the wrapper that's located in ./crystal/bin/
and it automatically looks in .build
so do the following steps:mkdir .build; mv crystal .build
pwd
is your ./crystal
checked out repo location:export OLDPATH=$PATH; export PATH=$PATH:$(pwd)/bin
crystal version
make
to build would not compile on our ARM host.
git clone https://github.com/crystal-lang/shards.git
cd shards
git checkout v0.8.1
crystal build src/shards.cr -o /usr/lib/crystal/bin/shards --release
shards
binary in your repo checkout. We created a ./shards/bin
directory to move the binary into and added that to our path as well where pwd
is ./shards
of your shards git repo checkout location.export OLDPATH=$PATH; export PATH=$PATH;$(pwd)/bin
And there you have it, a working crystal build environment on ARM.
And to give credit where due, a few sources used to get this going for me were found at https://danilafe.com/blog/crystal_on_arm/ and this Russian post for some of the shards build at http://constxife.ru/blog/2018/10/16/rpi-crystal.html (which you may need to run through Google Translate) which were both great resources to complete this task.