EDIT: There's now a semi-official repository for crystal on raspbian, check it out here: http://public.portalier.com/raspbian
Crystal doesn't build Debian packages for ARM, and you're correct in that you'll need to build from source.
However, the Crystal compiler is written in Crystal. This presents the obvious problem of how to get a compiler to build the compiler. The answer is cross-compilation: building an arm binary on a x86 desktop computer and copying it across.
Here's a quick step-by-step based on my memory of last time I cross-compiled:
- Install Crystal on a x86 desktop PC, and check it works.
- Install all required libraries on the desktop and Raspberry Pi. You'll need the same LLVM version on the Raspberry Pi and desktop. This is probably the hardest and longest step. You can install llvm 3.9 from debian testing for ARM, see this stackoverflow post for how to install only LLVM from debian testing.
- Check out the sources from git on both computers, and run
make deps
.
- Cross-compile the compiler by running this command in the root of the git repository:
./bin/crystal build src/compiler/crystal.cr --cross-compile --target arm-unknown-linux-gnueabihf --release -s -D without_openssl -D without_zlib
This command will create a crystal.o
file in your current directory, and also output a linker command (cc crystal.o -o crystal ...
).
- Copy
crystal.o
to the raspberry pi, and run the linker command. Be sure to edit the absolute path to llvm_ext.o
so that it points to the Crystal checkout on your Raspberry Pi, not the checkout on your desktop. Also make sure that all references to llvm-config
in the command are for the correct LLVM version. For example, changing /usr/local/bin/llvm-config
to llvm-config-3.9
on Raspbian.
- Run the crystal executable in your current directory (
./crystal -v
) and make sure it works.
- Ensure to set
CRYSTAL_PATH
environment variable is set to lib:/path/to/crystal/source/checkout/src
so that the compiler can find the standard library when compiling applications.
llvm_ext.so
is. Where am I editing that path at? – Comfy