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

Add support for Apple Silicon #525

Closed
pmuens opened this issue Jan 20, 2022 · 16 comments
Closed

Add support for Apple Silicon #525

pmuens opened this issue Jan 20, 2022 · 16 comments

Comments

@pmuens
Copy link

pmuens commented Jan 20, 2022

First of all: Thanks everyone involved for creating foundry.

This might not be the correct repository but I thought that I'd post it regardless in case others stumble upon the same issue.

When I clone, compile and run foundry on an M1 Mac I get the following error message when running foundry build in the example scaffold that is generated via foundry init:

[1] philipp@MacBook-Pro-14> forge build
compiling...
Error: 
   0: "/Users/philipp/.svm/0.8.11/solc-0.8.11": Bad CPU type in executable (os error 86)

Location:
   cli/src/cmd/mod.rs:49

Overall it looks like svm doesn't support Apple Silicon binaries as of yet. I found the following issue in the svm-rs repo that might be related to the problem: alloy-rs/svm-rs#12

@onbjerg
Copy link
Member

onbjerg commented Jan 20, 2022

Do you get the same issue if you use foundryup?

@transmissions11
Copy link
Contributor

can you ru the compilation of the foundry in a rosetta terminal? im on an m1 as well and it works fine for me in alacritty run in rosetta mode

@devanoneth
Copy link
Contributor

Hm, that's weird, I have compiled, installed and used the forge binaries fine on an M1 Mac. No need for rosetta either.

I just checked and Activity Monitor also says it's running under "Apple" architecture.

@gakonst
Copy link
Member

gakonst commented Jan 21, 2022

Same for me, I'm on M1 w/o Rosetta and it works. @pmuens can you try nuking the ~/.svm directory and trying again? cc @roynalnaruto

@pmuens
Copy link
Author

pmuens commented Jan 21, 2022

Thanks everyone for jumping in!

Same for me, I'm on M1 w/o Rosetta and it works. @pmuens can you try nuking the ~/.svm directory and trying again?

Just ran an rm -r ~/.svm and forge build without any luck, unfortunately. It seems like the same binary is downloaded again:

-rwxrwxrwx  1 philipp  staff  38493496 Jan 21 08:08 /Users/philipp/.svm/0.8.11/solc-0.8.11

Do you get the same issue if you use foundryup?

I wrote a script inspired by foundryup which takes just the parts to build Foundry directly via a clone / pull from this git repo.

My directory structure is the following (the script posted below is the foundry.sh one). You'd run the script via ./scripts/foundry.sh from the project's root directory.

|__contracts
    |__lib
    |__src
        |__test
|__scripts
     |__foundry.sh
|__frontend
#!/usr/bin/env bash
set -e

# NOTE: This script is an adaption of https://tinyurl.com/yxefjez5

echo Installing Foundry...

# Adaption of https://stackoverflow.com/a/246128
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

ROOT_DIR="$SCRIPT_DIR/../contracts"
TMP_DIR="$ROOT_DIR/tmp"
BIN_DIR="$ROOT_DIR/bin"

mkdir -p $TMP_DIR
mkdir -p $BIN_DIR

while [[ $1 ]]; do
  case $1 in
    --)               shift; break;;
    -r|--repo)        shift; REPO=$1;;
    -b|--branch)      shift; BRANCH=$1;;
    -v|--version)     shift; VERSION=$1;;
    *) printf "internal error: %q\\n" "$1"; exit 1
  esac; shift
done

REPO=${REPO-gakonst/foundry}
BRANCH=${BRANCH-master}
VERSION=${VERSION-nightly}

if ! command -v cargo &> /dev/null ; then
  echo Cargo is not installed...
  exit 1
fi

REPO_PATH="${TMP_DIR}/${REPO}"

if [ -d $REPO_PATH ]; then
  cd $REPO_PATH
  git pull
  git checkout ${BRANCH}
  git pull
else
  IFS="/" read -ra AUTHOR <<< "$REPO"
  mkdir -p "$TMP_DIR/$AUTHOR"
  cd "$TMP_DIR/$AUTHOR"
  git clone https://github.com/${REPO}
  cd $REPO_PATH
  git checkout ${BRANCH}
fi

echo "nightly" > "$REPO_PATH/rust-toolchain"

cargo build --release --locked

cp "$REPO_PATH/target/release/forge" "$BIN_DIR/forge"
cp "$REPO_PATH/target/release/cast" "$BIN_DIR/cast"

chmod +x "$BIN_DIR/forge"
chmod +x "$BIN_DIR/cast"

echo Successfully installed Foundry...

I re-ran the script in an empty project structure again this morning. Unfortunately I get the same result.

I'm using this script to have forge and cast accessible in a project directory w/o installing it globally just yet (I'd love to install Foundry binaries via Nix eventually as I'm using Nix as my main package manager).

Ideally I'd also love to run Foundry "natively" without Rosetta 😬

Thanks again everyone for providing help here!


Edit: I also pulled the recent foundry_nightly_darwin_arm64.tar.gz release from https://github.com/gakonst/foundry/releases/tag/nightly and re-ran forge build via the forge binary from this nightly release. Still getting the same error (I also removed ~/.svm before running it) 🤔

Edit 2: The interesting part is that svm-rs seems to be lacking support for darwin-arm as per this enum

@gakonst
Copy link
Member

gakonst commented Jan 21, 2022

I'm using this script to have forge and cast accessible in a project directory w/o installing it globally just yet.

Curious as to why you don't want to do a global install?

@pmuens
Copy link
Author

pmuens commented Jan 21, 2022

Curious as to why you don't want to do a global install?

A couple of years ago I switched from Homebrew to Nix for macOS package management. It definitely comes with a steep learning curve and a lot of times you have to fiddle around with the system yourself but I just love how everything is in /nix and installing new packages doesn't "pollute" the system (except for the dotfiles the packages create themselves in ~).

I looked through foundryup which is a great script to install Foundry but ideally I'd love to have Nix manage this for me (I want to build my own little package for this but haven't found the time to do that yet).

The other beautiful thing about the binaries is that they're "portable" so you can just move them around on your filesystem.

@onbjerg
Copy link
Member

onbjerg commented Jan 22, 2022

So it seems like this is not a Foundry issue, nor an svm-rs issue, but a Solidity issue. There are no released binaries for Silicon. So in order to fix this (without asking people to use Rosetta), we would need to:

@bretth18
Copy link

not sure what happened but i'm also having the same issue here after updating foundry. previously I was able to run things fine with the --no-auto-detect flag. tried updating w/ foundryup, removed /.svm but it's still downloading it. no rosetta, on a m1.

@gakonst
Copy link
Member

gakonst commented Jan 24, 2022

@bretth18 I think that the --no-auto-detect flag may no longer be respected for some reason, so this seems unrelated to apple silicon binaries during the autodetection step?

@pmuens
Copy link
Author

pmuens commented Jan 29, 2022

For those of you who got foundry up- and running natively on an M1 (without rosetta), how did you do it?

Did you just pull the binary release via https://github.com/gakonst/foundry/releases? Did you use foundryup? Or maybe built it yourself?

I did another attempt at installing foundry on my MacBook today and ran into the same issue I described above. My plan right now is to build solc and then use the --no-auto-detect flag in combination with $PATH to point foundry to the arm build of solc.

If anybody has another workaround, I would really appreciate it if you could chime in. Thanks again for looking into this.

@bretth18
Copy link

For those of you who got foundry up- and running natively on an M1 (without rosetta), how did you do it?

Did you just pull the binary release via https://github.com/gakonst/foundry/releases? Did you use foundryup? Or maybe built it yourself?

I did another attempt at installing foundry on my MacBook today and ran into the same issue I described above. My plan right now is to build solc and then use the --no-auto-detect flag in combination with $PATH to point foundry to the arm build of solc.

If anybody has another workaround, I would really appreciate it if you could chime in. Thanks again for looking into this.

hey, i was able to get everything working after realizing i wasn't using a foundry.toml config file. setting auto_detect_solc = false and have setup my SOLC_PATH to my arm build of solc. i've been using foundryup w/o problems. hope this helps!

@pmuens
Copy link
Author

pmuens commented Jan 30, 2022

hey, i was able to get everything working after realizing i wasn't using a foundry.toml config file. setting auto_detect_solc = false and have setup my SOLC_PATH to my arm build of solc. i've been using foundryup w/o problems. hope this helps!

That's great. Thanks for getting back and providing useful insights here 👍

Just out of curiosity: which solc arm build are you using? I tried to compile solc myself yesterday but ran into a bunch of compiler errors 🤔

@bretth18
Copy link

hey, i was able to get everything working after realizing i wasn't using a foundry.toml config file. setting auto_detect_solc = false and have setup my SOLC_PATH to my arm build of solc. i've been using foundryup w/o problems. hope this helps!

That's great. Thanks for getting back and providing useful insights here 👍

Just out of curiosity: which solc arm build are you using? I tried to compile solc myself yesterday but ran into a bunch of compiler errors 🤔

i've been using homebrew without problems: https://formulae.brew.sh/formula/solidity

@jrhe
Copy link
Contributor

jrhe commented Feb 8, 2022

Everything worked as expected for me on a fresh M1 mac using Homebrew's solidity bottle and foundryup. i.e.

brew install solidity
curl -L https://foundry.paradigm.xyz | bash
source ~/.zshrc
foundryup

@pmuens brew is using 0.8.11 - commit d7f03943. Managed to get it to build with the following:

cmake . -DCMAKE_INSTALL_PREFIX=testbin -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_BUILD_TYPE=Release -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_VERBOSE_MAKEFILE=ON -Wno-dev -DBUILD_TESTING=OFF -DCMAKE_OSX_SYSROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -DTESTS=OFF -DSTRICT_Z3_VERSION=OFFls
make
make install

Already had the dependencies installed from brew - needs boost and z3.

@gakonst gakonst closed this as completed in 2fecfa9 Feb 9, 2022
gakonst added a commit that referenced this issue Feb 9, 2022
bumps svm-rs.
fixes #525
fixes #684

driveby: re-enable geb integration test (fixed in gakonst/ethers-rs#866)
fixes #561
gakonst added a commit that referenced this issue Feb 9, 2022
bumps svm-rs.
fixes #525
fixes #684

driveby: re-enable geb integration test (fixed in gakonst/ethers-rs#866)
fixes #561
gakonst added a commit that referenced this issue Feb 9, 2022
bumps svm-rs.
fixes #525
fixes #684
@pmuens
Copy link
Author

pmuens commented Jun 22, 2022

FYI can confirm that the latest version works like a charm. Thanks a lot for fixing this 👌

charisma98 added a commit to charisma98/foundry that referenced this issue Mar 4, 2023
0129general added a commit to 0129general/FoundryProject that referenced this issue May 8, 2024
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

7 participants