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

Macos with m1 chip: Bad CPU type in executable #487

Open
matthewmaclay opened this issue May 29, 2022 · 1 comment
Open

Macos with m1 chip: Bad CPU type in executable #487

matthewmaclay opened this issue May 29, 2022 · 1 comment

Comments

@matthewmaclay
Copy link

matthewmaclay commented May 29, 2022

Prerequisites:
Macos Monterey 12.2.1
CPU: Apple M1

Run npm run build:program-rust
And get output

cargo build-bpf --manifest-path=./src/program-rust/Cargo.toml --bpf-out-dir=dist/program

BPF SDK: /Users/matthew/.local/share/solana/install/releases/stable-b0377bf77ca56ca3db7a339f69f8e8ccb1433904/solana-release/bin/sdk/bpf
cargo-build-bpf child: rustup toolchain list -v
cargo-build-bpf child: cargo +bpf build --target bpfel-unknown-unknown --release
error: command failed: 'cargo': Bad CPU type in executable (os error 86)
@YutaFujii0
Copy link

I had the same error and I managed to pass npm run build:program-rust step using docker.

# At your repository root
touch Dockerfile
docker build -t builder - < Dockerfile

docker run --platform linux/amd64 --mount type=bind,src=$(pwd),dst=/app builder
# This took several minutes to finish in my case. The last few lines of the output is like:

...

+ exit 0
cargo-build-bpf child: /root/.local/share/solana/install/releases/1.10.26/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/llvm-readelf --dyn-symbols /app/dist/program/helloworld.so

To deploy this program:
  $ solana program deploy /app/dist/program/helloworld.so
The program address will default to this keypair (override with --program-id):
  /app/dist/program/helloworld-keypair.json

Here's what Dockerfile looks like:

FROM --platform=linux/amd64 rust:1-buster

WORKDIR /app

# install solana since `cargo build-bpf` custom cargo command (cargo-build-bpf) is generated here
RUN sh -c "$(curl -sSfL https://release.solana.com/v1.10.26/install)"

# export additioan path
ENV PATH="/root/.local/share/solana/install/active_release/bin:${PATH}"

# execute what `npm run build:program-rust` does
CMD cargo build-bpf --manifest-path=./src/program-rust/Cargo.toml --bpf-out-dir=dist/program

NOTE: I only use docker for this npm run build:program-rust step to get helloworld-kaypair.json and helloworld.so files in dist/program/ directory. For other steps, instructed commands run without failure on M1 mac for my case.

Hope this helps.

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

No branches or pull requests

3 participants
@matthewmaclay @YutaFujii0 and others