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

unable to use anchor on arm #95

Closed
tac0turtle opened this issue Feb 27, 2021 · 36 comments
Closed

unable to use anchor on arm #95

tac0turtle opened this issue Feb 27, 2021 · 36 comments

Comments

@tac0turtle
Copy link
Contributor

tac0turtle commented Feb 27, 2021

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.

@armaniferrante
Copy link
Member

The issue is suspected to be in the idl parsing at the moment, since cargo build-bpf succeeds but anchor idl parse fails.

anchor idl parse -f src/lib.rs
[1]    4298 illegal hardware instruction  anchor idl parse -f src/lib.rs

@armaniferrante armaniferrante added priority:1 help wanted Extra attention is needed labels Feb 27, 2021
@armaniferrante
Copy link
Member

Related solana-labs/solana#16072

@armaniferrante armaniferrante added blocked and removed help wanted Extra attention is needed labels Apr 20, 2021
@armaniferrante
Copy link
Member

Labeling as blocked. Solana toolchain binaries don't run on M1 according to the linked issue above.

@armaniferrante
Copy link
Member

Recently addressed on the solana end solana-labs/solana#16346.

@mschneider
Copy link
Contributor

Most of the solana toolchain seems to be working now quite well on a m1. I managed to compile examples with anchor and deploy them to a local-test-validator using anchor launch. I couldn't get anchor test to run though.

@armaniferrante
Copy link
Member

Note that I don't own an M1 and so don't plan on directly addressing this myself--though I'm happy to closely work with and help anyone that decides to take on this issue.

@0xtristan
Copy link

@mschneider Solana v1.7 fixes most (if not all) of the M1 compatibility issues in my testing. If you want to get anchor to work on M1 you can manually update the cargo dependencies to 1.7 and build it from source. So far it's been working a treat for me the last few days. Happy to help if you have any issues.

@mschneider
Copy link
Contributor

mschneider commented Jun 8, 2021 via email

@armaniferrante
Copy link
Member

@mschneider you can try using anchor git dependencies in your Cargo.toml pointing at this branch #368. And install the 1.7.1 solana cli.

Once I confirm the 1.7 toolchain is ready for mainnet, I'll merge that PR and publish a release.

@0xtristan
Copy link

@mschneider pretty much what @armaniferrante said, just update the package dependencies in the respective Cargo.toml files and you can install the latest solana-cli using sh -c "$(curl -sSfL https://release.solana.com/v1.7.1/install)"

@mschneider
Copy link
Contributor

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

@mschneider
Copy link
Contributor

mschneider commented Jun 9, 2021

Next I installed solana and the anchor-cli locally:

sh -c "$(curl -sSfL https://release.solana.com/v1.7.1/install)"
cargo install --git https://github.com/project-serum/anchor --branch armani/sol anchor-cli --locked

I also used yarn link to setup a link between the currently checked out anchor/ts package and the basic-0 example. anchor launch did deploy the contract on my test-validator. But I still can't run the tests:

basic-0 max$ anchor test
BPF SDK: /Users/max/.local/share/solana/install/releases/1.7.1/solana-release/bin/sdk/bpf
Running: rustup toolchain list -v
Running: cargo +bpf build --target bpfel-unknown-unknown --release
    Finished release [optimized] target(s) in 0.18s

To deploy this program:
  $ solana program deploy /Users/max/Code/anchor/examples/tutorial/basic-0/target/deploy/basic_0.so


  basic-0
Transaction simulation failed: Attempt to load a program that does not exist 
    
Translating error Error: failed to send transaction: Transaction simulation failed: Attempt to load a program that does not exist
    at Connection.sendEncodedTransaction (/Users/max/Code/anchor/ts/node_modules/@solana/web3.js/lib/index.cjs.js:4520:13)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Connection.sendRawTransaction (/Users/max/Code/anchor/ts/node_modules/@solana/web3.js/lib/index.cjs.js:4481:20)
    at async Object.sendAndConfirmRawTransaction (/Users/max/Code/anchor/ts/node_modules/@solana/web3.js/lib/index.cjs.js:6263:21)
    at async Provider.send (/Users/max/Code/anchor/ts/dist/cjs/provider.js:81:22)
    at async Object.rpc [as initialize] (/Users/max/Code/anchor/ts/dist/cjs/program/namespace/rpc.js:11:31)
    at async Context.<anonymous> (/Users/max/Code/anchor/examples/tutorial/basic-0/tests/basic-0.js:13:5)
    1) Uses the workspace to invoke the initialize instruction


  0 passing (80ms)
  1 failing

  1) basic-0
       Uses the workspace to invoke the initialize instruction:
     Error: Promise rejected with no or falsy reason
      at processTicksAndRejections (internal/process/task_queues.js:95:5)


@NorbertBodziony
Copy link
Contributor

@mschneider does solana-test-validator works for you ? I am getting
solana-test-validator dyld: Library not loaded: /usr/local/opt/openssl@1.1/lib/libssl.1.1.dylib
Maybe thats why it fails ?

@mschneider
Copy link
Contributor

mschneider commented Jun 9, 2021 via email

@0xtristan
Copy link

@NorbertBodziony I had that error too, running brew install openssl will fix it.

@tomlinton
Copy link
Contributor

#368 has been working great for me on M1. Appreciate it!

@NorbertBodziony
Copy link
Contributor

Managed to make it work. #368 + custom solana-test-validator build from 1.7.1 solana branch

@armaniferrante
Copy link
Member

Addressed by #368. Please re-open if there are still problems.

@mmdhrumil
Copy link

@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?

@NorbertBodziony
Copy link
Contributor

@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.

@mmdhrumil
Copy link

mmdhrumil commented Aug 8, 2021

@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
Copy link

dabit3 commented Sep 5, 2021

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.

@mmdhrumil
Copy link

@dabit3 Nice. I ended up switching to my Linux machine and found no issues there.

@dvcrn
Copy link

dvcrn commented Sep 8, 2021

@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

@dvcrn
Copy link

dvcrn commented Sep 8, 2021

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

@Findiglay
Copy link

Findiglay commented Sep 16, 2021

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

@sandrocan
Copy link

I was able to build from source and start a local test validator, thanks to @dabit3, but I can't run the example hello world program ( https://github.com/solana-labs/example-helloworld/blob/master/README.md )

When I run:
npm install

I get this error:
npm ERR! enoent ENOENT: no such file or directory, open '/Users/alessandro/solana/solana-1.7.12/package.json'
Seems that I'm missing the package.json file. Anybody had any similiar issues?

@dabit3
Copy link

dabit3 commented Sep 26, 2021

@sandrocan which directory are you running npm install from?

@sandrocan
Copy link

sandrocan commented Sep 26, 2021

@dabit3 /Users/alessandro/solana/solana-1.7.12 which is where the whole project is located

@dabit3
Copy link

dabit3 commented Sep 26, 2021

You should be running npm install from the hello-world folder, which has a package.json, not the main Solana codebase.

So

git clone git@github.com:solana-labs/example-helloworld.git

cd example-helloworld

npm install

@sandrocan
Copy link

sandrocan commented Sep 26, 2021

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!

@AngelLozan
Copy link

AngelLozan commented Jan 6, 2022

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.

@mmdhrumil
Copy link

mmdhrumil commented May 4, 2022

Hey @ScottLozano

Followed the same steps as you mentioned for installing it on my Macbook air m1 chip. Getting this error when I run anchor build

Can you please help? :)

My setup:

rustc/cargo - v 1.60.0
Anchor CLI: v 0.24.2
Solana: 1.9.19 mainnet-beta release

Followed the exact method you mentioned, including the symlink creation

Screen Shot 2022-05-04 at 5 13 42 PM

@AngelLozan
Copy link

@mdhrumil

  1. Did you install this on Rosetta terminal or ARM? I installed on ARM. Will clarify in my solution above.
  2. Did you install the symlink?
  3. I installed a different version and also, I installed the anchor-cli 0.19.0 & cargo 1.57.0 (b2e52d7ca 2021-10-21)
  4. Did you initialize Anchor in the project?

If you did the first two, possibly it's that you need to link a different path in the symlink? I see yours is through Documents. Mine is installed at root user, so: /Users/scott/.cargo/bin/

I can then see ($ls -l) this symlink which I created:

cargo-build-bpf -> solana-1.9.2/bin/sdk

and I have the solana-1.9.2 on my Desktop

Let me know if that helps.

@mmdhrumil
Copy link

Hey @ScottLozano

I tried this again and somehow it worked. Have tried it multiple times before but used to get stuck due to some or the other issues mentioned in this thread. Glad it worked this time.

Screen Shot 2022-05-04 at 7 46 39 PM

@AngelLozan
Copy link

AngelLozan commented May 4, 2022 via email

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