How do I install crystal-lang on rapsberry pi?
Asked Answered
C

1

18

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.

Comfy answered 14/3, 2017 at 20:40 Comment(0)
T
19

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.
Travis answered 14/3, 2017 at 21:12 Comment(11)
Thanks a lot. Do I still need to install the garbage collector on my raspberry pi since I'm compiling crystal on my mac? I'm not sure where llvm_ext.so is. Where am I editing that path at?Comfy
The difficulty is to have a working LLVM 3.9 installed on the Raspberry Pi —previous releases have bugs for the ARM targets. Compiling on the Pi would take forever, and cross compilation of LLVM is... hard.Dacca
Yeah I feel like I've followed all the instructions and I have llvm 3.9.1 installed from packages.debian.org/stretch/llvm-3.9. I've posted this over on the most related github thread with more error details. github.com/crystal-lang/crystal/pull/3424Comfy
I think I've finally got it. Thanks again.Comfy
Have people had trouble using shards alongside the Raspian build? I'm seeing variations of, "undefined symbol: GC_get_push_other_roots" when using crystal deps or shards install.Pickaxe
@Pickaxe happened to me too installing crystallang on a pi-zero.Boddie
Would this have something to do with SSL. I've seen a few people around the place compiling --without-ssl . I cant help thinking that would break https for shards?Rewrite
Nope ., thats not it. More answers here Re that bug @Pickaxe github.com/crystal-lang/crystal/issues/2896Rewrite
Thanks, @Shayne. Unfortunately, I once spent the better part of a day chasing after the solutions listed in that thread and, IIRC, I borked my system as a result.Pickaxe
Hello, I made note about compiling crystal 0.26 on raspbian — constxife.ru/blog/2018/10/16/rpi-crystal.html. It's on russian, but you can read shell commands.Chorus
Google translate seems to do a respectable job with your page. Good work, @Chorus translate.google.com/…Rewrite

© 2022 - 2024 — McMap. All rights reserved.