Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I install crystal-lang on rapsberry pi?

When I try to add it to sources as per debian install instructions I get this error. I'm guessing this means that there are no arm packages for it.

Failed to fetch https://dist.crystal-lang.org/apt/dists/crystal/InRelease Unable to find expected entry 'main/binary-armhf/Packages' in Release file (Wrong sources.list entry or malformed file)

I'm guessing I probably need to install it from source. How would I go about doing that with an arm cpu? When I check it out and run make I get the error:

You need to have a crystal executable in your path! Makefile:113: recipe for target '.build/crystal' failed make: *** [.build/crystal] Error 1

Any suggestions would be greatly appreciated.

like image 828
isaacsloan Avatar asked Mar 14 '17 20:03

isaacsloan


1 Answers

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:

  1. Install Crystal on a x86 desktop PC, and check it works.
  2. 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.
  3. Check out the sources from git on both computers, and run make deps.
  4. 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 ...).
  5. 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.
  6. Run the crystal executable in your current directory (./crystal -v) and make sure it works.
  7. 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.
like image 74
Stephie Avatar answered Nov 06 '22 17:11

Stephie