Skip to content

Commit

Permalink
Added support for Macs with Apple Silicon (#90)
Browse files Browse the repository at this point in the history
Added support for Macs with Apple Silicon:

selecting proper zksync compiler
information on where to get the most recent solidity
  • Loading branch information
mm-zk authored May 26, 2023
1 parent 71945f6 commit 9f225d2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -645,3 +645,12 @@ Make sure that:
If you get errors like `(code: -32601, message: Method not found, data: None)` - you are probably using a `send` method instead of `zksend`.
### 'Could not get solc: Unknown version provided', 'checksum not found'
These errors might show up on the Mac with ARM chip (M1, M2) - due to the fact that most recent solc compilers are not auto-downloaded there.
There are 2 workarounds:
- use the older compiler - by adding `--use 0.8.17` flag to your zk-build command
- download the compiler manually - and then use `--offline` mode (you can download the compiler into ~/.svm/VERSION/solc-VERSION -- for example ~/.svm/0.8.20/solc-0.8.20 )
You can get the lastest compiler version for MacOs AARCH here: https://github.com/ethers-rs/solc-builds/tree/master/macosx/aarch64
2 changes: 1 addition & 1 deletion cli/src/cmd/forge/zk_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl ZkBuildArgs {
}

if !zksolc_manager.exists() {
println!("Downloading zksolc compiler");
println!("Downloading zksolc compiler from {:?}", zksolc_manager.get_full_download_url().unwrap().to_string());
zksolc_manager
.download()
.map_err(|err| eyre::eyre!("Failed to download the file: {}", err))?;
Expand Down
26 changes: 13 additions & 13 deletions cli/src/cmd/forge/zksolc_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/// This module abstracts the details of managing the zksolc compiler, making it easier for developers to use
/// different versions of the compiler without dealing with the details of downloading, setting up, and switching
/// between versions. It is part of a larger framework for managing and interacting with zkSync contracts.
use anyhow::{anyhow, Error, Result};
use anyhow::{anyhow, Error, Result, Context};
use dirs;
use reqwest::blocking::Client;
use serde::Serialize;
Expand Down Expand Up @@ -94,7 +94,8 @@ impl ZkSolcVersion {
#[derive(Debug, Clone, Serialize)]
enum ZkSolcOS {
Linux,
Mac,
MacAMD,
MacARM
}

/// `get_operating_system` identifies the current operating system and returns the corresponding `ZkSolcOS` variant.
Expand All @@ -109,8 +110,11 @@ enum ZkSolcOS {
fn get_operating_system() -> Result<ZkSolcOS> {
match std::env::consts::OS {
"linux" => Ok(ZkSolcOS::Linux),
"macos" | "darwin" => Ok(ZkSolcOS::Mac),
_ => Err(Error::msg("Unsupported operating system")),
"macos" | "darwin" => match std::env::consts::ARCH {
"aarch64" => Ok(ZkSolcOS::MacARM),
_ => Ok(ZkSolcOS::MacAMD),
},
_ => Err(Error::msg(format!("Unsupported operating system {}", std::env::consts::OS))),
}
}

Expand All @@ -127,7 +131,8 @@ impl ZkSolcOS {
fn get_compiler(&self) -> &str {
match self {
ZkSolcOS::Linux => "zksolc-linux-amd64-musl-",
ZkSolcOS::Mac => "zksolc-macosx-amd64-",
ZkSolcOS::MacAMD => "zksolc-macosx-amd64-",
ZkSolcOS::MacARM => "zksolc-macosx-arm64-",
}
}

Expand All @@ -143,7 +148,8 @@ impl ZkSolcOS {
fn get_download_uri(&self) -> &str {
match self {
ZkSolcOS::Linux => "linux-amd64",
ZkSolcOS::Mac => "macosx-amd64",
ZkSolcOS::MacAMD => "macosx-amd64",
ZkSolcOS::MacARM => "macosx-arm64",
}
}
}
Expand Down Expand Up @@ -233,12 +239,7 @@ impl ZkSolcManagerBuilder {
///
/// This function can return an `Err` if the operating system cannot be determined using `get_operating_system`.
fn get_compiler(self) -> Result<String> {
if let Ok(zk_solc_os) = get_operating_system() {
let compiler = zk_solc_os.get_compiler().to_string();
Ok(compiler)
} else {
Err(Error::msg("Could not determine compiler"))
}
get_operating_system().with_context(|| "Failed to determine OS for compiler").map(|it| it.get_compiler().to_string())
}

/// `build` constructs and returns a `ZkSolcManager` instance based on the provided configuration options.
Expand Down Expand Up @@ -406,7 +407,6 @@ impl ZkSolcManager {
///
/// This function can return an `Err` if the full download URL cannot be parsed into a valid `Url`.
pub fn get_full_download_url(&self) -> Result<Url> {
// TODO: this is an example, of how you can 'propagate' the error from below, and add some local context information.
let zk_solc_os = get_operating_system()
.map_err(|err| anyhow!("Failed to determine OS to select the binary: {}", err))?;

Expand Down

0 comments on commit 9f225d2

Please sign in to comment.