Crystal on M1 Mac, Big Sur

Hi, trying to install Crystal:

$ brew install crystal
Error: crystal: no bottle available!
You can try to install from source with:
  brew install --build-from-source crystal
Please note building from source is unsupported. You will encounter build
failures with some formulae. If you experience any issues please create pull
requests instead of asking for help on Homebrew's GitHub, Twitter or any other
official channels.

$ brew install --build-from-source crystal
==> Downloading https://github.com/crystal-lang/shards/archive/v0.14.1.tar.gz
Already downloaded: /Users/valbaca/Library/Caches/Homebrew/downloads/243054e745fb64c2a2090ee74bd8f5492a73dce467d6eb2121c1de7362522dc3--shards-0.14.1.tar.gz
==> Downloading https://github.com/crystal-lang/crystal/releases/download/0.36.1
Already downloaded: /Users/valbaca/Library/Caches/Homebrew/downloads/21e69d67c3cd1545fe57b82418810e1e827581282b268d1daedf66006865f539--crystal-0.36.1-1-darwin-x86_64.tar.gz
==> Downloading https://github.com/crystal-lang/crystal/archive/1.0.0.tar.gz
Already downloaded: /Users/valbaca/Library/Caches/Homebrew/downloads/5e5007f36d96da96dc6b272be7532e052641f5b09706dbeb100477bde10d2944--crystal-1.0.0.tar.gz
==> make deps
==> make crystal release=true FLAGS=--no-debug CRYSTAL_CONFIG_LIBRARY_PATH=
Last 15 lines from /Users/valbaca/Library/Logs/Homebrew/crystal/02.make:
2021-07-08 10:24:43 -0700

make
crystal
release=true
FLAGS=--no-debug
CRYSTAL_CONFIG_LIBRARY_PATH=

Using /opt/homebrew/opt/llvm@11/bin/llvm-config [version=11.1.0]
CRYSTAL_CONFIG_LIBRARY_PATH="" CRYSTAL_CONFIG_BUILD_COMMIT="" SOURCE_DATE_EPOCH="1616422021" ./bin/crystal build --no-debug --release  -o .build/crystal src/compiler/crystal.cr -D without_openssl -D without_zlib
ld: in '/opt/homebrew/opt/llvm@11/lib/libunwind.dylib', building for macOS-x86_64 but attempting to link with file built for macOS-arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of command failed with code: 1: `clang "${@}" -o /private/tmp/crystal-20210708-46787-11la4vt/crystal-1.0.0/.brew_home/.cache/crystal/private-tmp-crystal-20210708-46787-11la4vt-crystal-1.0.0-src-ecr-process.cr/macro_run  -rdynamic -L/opt/homebrew/opt/bdw-gc/lib -L/opt/homebrew/opt/openssl@1.1/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/sqlite/lib -L/opt/homebrew/opt/llvm@11/lib -L/opt/homebrew/lib -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries -L/private/tmp/crystal-20210708-46787-11la4vt/crystal-1.0.0/boot/embedded/lib -lpcre -lgc -lpthread /private/tmp/crystal-20210708-46787-11la4vt/crystal-1.0.0/src/ext/libcrystal.a -L/opt/homebrew/Cellar/libevent/2.1.12/lib -levent -liconv -ldl`
make: *** [.build/crystal] Error 1

Do not report this issue to Homebrew/brew or Homebrew/core!

Here’s my relevant flags, not sure if they matter:

env | grep FLAG
XPC_FLAGS=0x0
NVM_CD_FLAGS=-q

Looks like this is known:

My arm/M1 brew is installed here:

$ which brew
/opt/homebrew/bin/brew

Step 1. Install x86_64 brew under /usr/local/bin/brew

arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Step 2. Create an alias for the x86_64 brew

I added this to my ~/.zshrc

# brew hack for x86
alias ibrew='arch -x86_64 /usr/local/bin/brew'

Step 3. ibrew install crystal

Step 4. Yay!

$ crystal --version
Crystal 1.0.0 (2021-03-22)

LLVM: 11.1.0
Default target: x86_64-apple-macosx

1 Like

I am not sure if you mean just installing the Crystal on M1 Mac or you want some specific environments.

If you just mean to install it and able to run the crystal on your terminal, you should check the pkg file.
You can find the pkg file here: Release 1.0.0 · crystal-lang/crystal · GitHub
(It is actually installed onto the Rosetta 2)

And here is a known discussion: