Install Crystal on Mac M1

I extracted crystal-1.0.0-1-darwin-x86_64.tar.gz into ~/crystal-prebuilt, and I have:

LICENSES	
embedded	
license-cache	
src
bin		
etc		
samples

I extracted a second time, just to make sure. And I checked against 1.1.1, too, to see if it had the Makefile, but it is missing from that version, too.

Looks like the tar file referenced in the blog post doesn’t contain the Makefile, but the “source code” (https://github.com/crystal-lang/crystal/archive/refs/tags/1.1.0.tar.gz) tar does. I’ll give that a shot, and report back if that works.

Not sure how long it takes to build, but I’ve been running make overnight and it’s still running…

You also need to actually check out the current crystal source code, a step that appears to be missing in the blog post, probably for the same reason a fish might forget to start their instructions with “first, are you in water”…

This should do it:

git clone https://github.com/crystal-lang/crystal.git

…then cd crystal, and. that’s where you want to run make.

You might also run into a problem with LLVM: the homebrew version has updated to 12 in the meantime, and the patch to update crystal to it hasn’t been merged yet. So, either merge these changes into your local sources, or brew install llvm@11 / ibrew install llvm@11 followed by adjusting all the LLVM environment variables.

And it works! After trying those “Omnibus” scripts, which may well win the hardcoded-paths Award at the Friends of Historical Ruby Releases’ annual gala, this was surprisingly straightforward, thank you!

1 Like

Ahh yes, sorry about that! @KarlKemp is absolutely correct. The blog post is to be run in the context of the Crystal compiler source code, not the compiled release distributions. Will update the post to make that more clear.

(Though I believe a universal macOS release build ticks ever closer…)

1 Like

Hi @KarlKemp, out of curiosity, how long does it took you to compile?

It’s rather quick. I didn’t quite catch when it was done, but <10 min.If it hasn’t moved for hours, there’s probably some spurious punctuation or something and it’s waiting for input. Check top, activity monitor, or ps ax to see what it’s doing.

I tried to extract the sequence of commands from my shell history, but it’s too much of a mess, I believe.

This is checking out the source and patching it for LLVM 12 (EDIT: no longer necessary, since the PR was merged earlier today):

git clone https://github.com/crystal-lang/crystal.git
cd crystal
# git remote add llvm https://github.com/maxfierke/crystal.git
# git pull llvm
# git merge llvm/mf-llvm_12

If it’s any help, here’s the end result: iCloud sharing: crystal

r ~ % ./crystal -v
Crystal 1.1.1 (2021-07-26)

LLVM: 11.1.0
Default target: aarch64-apple-darwin21.0.0

(That binary was actually compiled with homebrew, which was relatively straightforward once there’s an existing, working aarch64 binary. )

1 Like

The blog post from my earlier post has been updated to reference LLVM 11 specifically and address the initial cloning of the source code. I would caution against building with LLVM 12 at this time, as Beta reminded me in another post it does not contain a vital patch that Homebrew’s LLVM 11 has that ensures release mode builds still function correctly. The patch only exists in LLVM master (and will likely be included in LLVM 13) but is not applied to LLVM 12 in Homebrew or elsewhere, as far as I know.

3 Likes

Let me clarify something. The patch is needed for x86 boxes only. For consistency, since we mostly have x86 architectures, we can only claim support for LLVM 10, as this is what we know it works. But that doesn’t mean it won’t work with 11 or 12. In fact, it’s OK if you go one step ahead of us and tell us if you find issues with these versions, so we can anticipate them prior to the 13 :smiley:

1 Like

Crystal 1.2.2 works with M1, you can install it with asdf

asdf plugin add crystal
asdf install crystal latest
asdf global crystal latest

2 Likes