anchor: unable to use anchor on arm
Description
When trying to use anchor on a m1 based mac I get the below error:
❯ anchor
[1] 97137 illegal hardware instruction anchor
Not sure if this is because of a dependency but its odd because rust is emulated to use x86 instructions.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 36 (16 by maintainers)
The problem is that when I run:
solana-test-validator
,Also getting an error at this point, running M1 Mac in Rosetta terminal, Solana CLI version
1.7.11
Update:
Following the instructions here, but not running
solana-install init
worked for me:https://docs.solana.com/cli/install-solana-cli-tools#build-from-source
Then go to
sdk/cargo-build-bpf
from the project root. From there, run the following:This will install the
cargo-build-bpf
program to~/.cargo/bin
. Next in~/.cargo/bin
create a symlink to the sdk folder in the project’s bin folder, like this:Replace $PROJECT_ROOT with your Solana project folder.
Figured it out, my issue was very dumb. It’s depending on
greadlink
but didn’t give me any error message that it’s not installed.brew install coreutils
to get the gnu versionsTo fix the SSL error, symlink it manually:
Was beating my head against a wall trying to build from source, ended up running into the same problem as @dvcrn. This comment in the cargo-install-all.sh needs to be emphasised:
I have switched to solana v1.7.1. The installation is valid as I can run basic commands like
solana --version
. The problem is that when I run:solana-test-validator
, I get this error:like you mentioned you had gotten.
@dabit3 how did you build it from source on m1? I’m not having any luck here, on neither 1.7.1 nor 1.7.11
Managed to make it work. #368 + custom solana-test-validator build from 1.7.1 solana branch
#368 has been working great for me on M1. Appreciate it!
A few caveats: 1.7.1’s solana-test-validator crashes for me on launch
Here is what I did instead to bring one up:
git checkout v1.7
./install/install-help.sh .
but did not add to the PATH./bin/solana-test-validator
Slight elaboration and change on instructional provided by @dabit3 (which is how I figured this out, so thank you very much for posting this):
installed on ARM64 terminal. To verify this type “arch” in the terminal. If it says i386 it’s Rosetta Build from source allows you functionality for both solana-test-validator and allows one to utilize the anchor environment to build and test. You can use cargo build and cargo test but that will not populate the target/idl with the proper artifacts needed.
In the below instructions,
build-source
refers to the Source code (tar.gz) file you download to follow the instructions to build from source in order to install the Solana CLI tools found here: https://docs.solana.com/cli/install-solana-cli-tools#build-from-sourceGo to sdk/cargo-build-bpf from the
build-source
project root. From there, run the following:$ cargo install --path .
Verify the path created by opening a separate terminal and navigating to ~/.cargo/bin. List the contents of bin with:
$ ln -l.
You will either see SDK or cargo-build-bpf. On my Mac M1 chip running Monterey, I found the path to end with the latter.
So, On an apple M1 chip the cargo-build-bpf program is installed to the path ~/.cargo/bin/cargo-build-bpf. This will allow you to run commands like $ anchor build successfully in your local project root once you create a symlink from it to the path in your Solana source code/bin/sdk folder.
In a separate terminal navigate to ~/.cargo/bin and create a symlink to the sdk folder in the
build-source
project’s bin folder, like this:$ ln -s solana-1.9.2/bin/sdk ~/.cargo/bin/cargo-build-bpf
Replace
solana-1.9.2
with thebuild-source
code you downloaded earlier.That makes sense. Sorry I’ve been really confused after trying to get the validator to run. Will try that now. Thanks for your quick response and help @dabit3 ! Much appreciated!
Labeling as blocked. Solana toolchain binaries don’t run on M1 according to the linked issue above.