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)

Most upvoted comments

The problem is that when I run: solana-test-validator,

I get this error:

Also getting an error at this point, running M1 Mac in Rosetta terminal, Solana CLI version 1.7.11

[1]    17452 illegal hardware instruction  solana-test-validator

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:

$ cargo install --path .

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:

$ ln -s $PROJECT_ROOT/bin/sdk ~/.cargo/bin/sdk

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 versions

To fix the SSL error, symlink it manually:

ln -sfn /usr/local/Cellar/openssl@1.1/1.1.1k /usr/local/opt/openssl@1.1

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:

if [[ $OSTYPE == darwin* ]]; then
  # Mac OS X's version of `readlink` does not support the -f option,
  # But `greadlink` does, which you can get with `brew install coreutils`
  readlink_cmd="greadlink"
fi

@NorbertBodziony I’m facing the same issue with Solana v1.7.9. Not sure how to use #368 for solving the issue. Can you please help?

I would stick to 1.7.1 at least it works for me.

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:

dyld: Library not loaded: /usr/local/opt/openssl@1.1/lib/libssl.1.1.dylib
  Referenced from: /Users/dhrumil/.local/share/solana/install/active_release/bin/solana-test-validator
  Reason: image not found
zsh: abort      solana-test-validator

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

Ledger location: test-ledger
Log: test-ledger/validator.log
⠙ Initializing...
Illegal instruction: 4

Here is what I did instead to bring one up:

  1. Open a Rosetta2 Terminal
  2. git clone solana
  3. git checkout v1.7
  4. ran ./install/install-help.sh . but did not add to the PATH
  5. launch ./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.

  • Note: You will need to run the command solana-test-validator from within your project directory once the symlink to the path is set. So if you’re project is hello-world, you run the test-validator from there, not the Solana source files.

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-source

Go 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 the build-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.