Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't install on Apple M1 Silicon #10237

Closed
ukd1 opened this issue Jan 11, 2021 · 19 comments
Closed

Can't install on Apple M1 Silicon #10237

ukd1 opened this issue Jan 11, 2021 · 19 comments

Comments

@ukd1
Copy link

ukd1 commented Jan 11, 2021

os: BigSur 11.0.1
cpu: Apple M1

expected result; be able to install Crystal

result:

% brew up
Updated 1 tap (homebrew/cask).
==> Updated Casks
unnaturalscrollwheels                                                                wakeonlan
russ@Russells-MBP ruby-install % brew install crystal
llvm@9: The x86_64 architecture is required for this software.
Error: An unsatisfied requirement failed this build.
@ukd1 ukd1 changed the title Can't install on Apple Silicon Can't install on Apple M1 Silicon Jan 11, 2021
@Blacksmoke16
Copy link
Member

Duplicate of #10066?

@straight-shoota
Copy link
Member

Duplicate of #10066

@straight-shoota straight-shoota marked this as a duplicate of #10066 Jan 11, 2021
@pannous
Copy link

pannous commented Feb 16, 2021

while #10066 addressed the technical issue, this issue could be reopened until the end user can use brew install crystal on new macs.

@straight-shoota
Copy link
Member

brew isn't the scope of this issue tracker, that's at https://github.com/homebrew/brew.

After #10348 the next step is probably to set up CI for arm64-apple-darwin and then provide binaries.

@jhass
Copy link
Member

jhass commented Feb 16, 2021

If somebody working on CI wants a temporary playground on our ARM build server, I think we can arrange for that :)

@ukd1
Copy link
Author

ukd1 commented Feb 19, 2021

I'm probably being dumb, but I can't get it to compile after #10348; probably as the instructions are for cross compiling, which I don't need on an M1. Anyone managed to get this to compile? If so, how?

@jhass
Copy link
Member

jhass commented Feb 19, 2021

You still do need to cross compile because there is no official binary to bootstrap from. It's just that you can do it with a single machine due to rosetta. So you cross compile the ARM compiler using the x86 compiler under rosetta and then link the result outside. I guess the instructions might use the ARM linker directly, I didn't take a close look.

@ukd1
Copy link
Author

ukd1 commented Feb 25, 2021

You still do need to cross compile because there is no official binary to bootstrap from. It's just that you can do it with a single machine due to rosetta. So you cross compile the ARM compiler using the x86 compiler under rosetta and then link the result outside. I guess the instructions might use the ARM linker directly, I didn't take a close look.

when I try this with brew for intel, I still get stuck on the first step - any ideas?

% LLVM_CONFIG="$INTEL_LLVM_CONFIG" \
   LDFLAGS="-L$INTEL_LLVM_ROOT/lib" \
   CPPFLAGS="-I$INTEL_LLVM_ROOT/include" \
   CC="$INTEL_LLVM_ROOT/bin/clang" \
   AR="$INTEL_LLVM_ROOT/bin/llvm-ar" \
   arch -x86_64 make     
Using /usr/local/opt/llvm/bin/llvm-config [version=11.1.0]
c++ -c  -o src/llvm/ext/llvm_ext.o src/llvm/ext/llvm_ext.cc -I/usr/local/Cellar/llvm/11.1.0/include -std=c++14 -stdlib=libc++   -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
/usr/local/opt/llvm/bin/clang -fPIC  -I/usr/local/opt/llvm/include  -c -o src/ext/sigfault.o src/ext/sigfault.c
/usr/local/opt/llvm/bin/llvm-ar -rcs src/ext/libcrystal.a src/ext/sigfault.o
CRYSTAL_CONFIG_LIBRARY_PATH="" CRYSTAL_CONFIG_BUILD_COMMIT="171cfbe6c" SOURCE_DATE_EPOCH="1614257218" ./bin/crystal build --link-flags="-L/usr/local/opt/llvm/lib"  -o .build/crystal src/compiler/crystal.cr -D without_openssl -D without_zlib
./bin/crystal: line 156: crystal: command not found
You need to have a crystal executable in your path! or set CRYSTAL env variable
make: *** [.build/crystal] Error 1

@maxfierke
Copy link
Contributor

maxfierke commented Feb 26, 2021

./bin/crystal: line 156: crystal: command not found
You need to have a crystal executable in your path! or set CRYSTAL env variable
make: *** [.build/crystal] Error 1

@ukd1 You'll need to make sure crystal is installed and linked for Intel Homebrew. If you have the ibrew alias setup, it would be ibrew install crystal, which should link by default. Otherwise, you can link with ibrew link crystal

(ibrew is just arch -x86_64 /usr/local/bin/brew)

Let me know if that unblocks you. I think I provided enough of the environment variables needed for getting the cross-compilation to work fairly smoothly, but it's possible I missed some things.

This will hopefully become a little easier once there's an official release w/ the M1 Support merged in, because at least then it shouldn't require Intel Homebrew at all, just an x86_64 release binary.

@sdogruyol
Copy link
Member

Is there any update on this? Just bought a new M1 Mac and I'm hitting the same issue 😢

@maxfierke
Copy link
Contributor

maxfierke commented Apr 1, 2021

I tried cross-compiling with the official x86_64 build of Crystal 1.0.0 to aarch64/arm64 and unfortunately it seems maybe the release build didn't ship with an llvm that can target aarch64/arm64 on macOS (I think it requires LLVM 11 and the release build probably used 9) so we may need to wait for the LLVM 11 issues to be sorted and for official builds to use LLVM 11.

Cross-compiling from source via the instructions in the darwin/aarch64 PR should still work, but is somewhat difficult.

EDIT: cross-compiling from source with an x86_64 compiler via Rosetta 2 is documented here: https://maxfierke.com/blog/posts/so-you-want-to-compile-crystal-on-arm64-macos

@ukd1
Copy link
Author

ukd1 commented Apr 6, 2021

@sdogruyol tbh I gave up for now. Until it works with brew natively, I don't want to maintain a hand-rolled setup. Try installing it x86?

@valbaca
Copy link

valbaca commented Jul 8, 2021

Listing the steps that helped me:

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!

$ which crystal
/usr/local/bin/crystal
$ crystal --version
Crystal 1.0.0 (2021-03-22)

LLVM: 11.1.0
Default target: x86_64-apple-macosx

@ukd1
Copy link
Author

ukd1 commented Jul 20, 2021

@valbaca whilst I'm sure this works, it's not really solving the issue of native arm64 installation - which is possible, but a pain.

@straight-shoota
Copy link
Member

I suppose we should be able to publish a distribution package for aarch64 macos now.

There's no CI infrastructure for Apple Silicon, yet. So it would need to be manually built. Once a package is available, it can serve as boot release for homebrew.

@maxfierke
Copy link
Contributor

Attached a test universal distribution build here: crystal-lang/distribution-scripts#104 (comment) if folks want to try it out on their M1 hardware

Only issue I've noticed is an LLVM assertion failing in debug mode for the program I tested it on, but release mode seems to work fine. the LLVM assertion failure seems maybe specific to my program or the version of LLVM, because I can reproduce it on x86_64 too

@pouyakary
Copy link

@maxfierke can you please repost the build you have?

@maxfierke
Copy link
Contributor

maxfierke commented Nov 18, 2021

@pouyakary official universal builds are now provided, see here for the latest: https://github.com/crystal-lang/crystal/releases/download/1.2.2/crystal-1.2.2-1-darwin-universal.tar.gz

You can also install via Homebrew on macOS ARM64 now.

@pouyakary
Copy link

@maxfierke thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants