Skip to content

Commit

Permalink
calling the logic that ensures a default
Browse files Browse the repository at this point in the history
  • Loading branch information
MBerguer committed Jan 27, 2025
1 parent ed2c1e0 commit 3db5b6a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
39 changes: 22 additions & 17 deletions crates/config/src/zksync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ impl ZkSyncConfig {
libraries: Libraries,
evm_version: EvmVersion,
via_ir: bool,
offline: bool,
) -> ZkSolcSettings {
let optimizer = Optimizer {
enabled: Some(self.optimizer),
Expand Down Expand Up @@ -146,17 +147,15 @@ impl ZkSyncConfig {
suppressed_errors: self.suppressed_errors.clone(),
};

let zksolc_version = self.zksolc.as_ref().map(|req| match req {
SolcReq::Version(version) => version.clone(),
SolcReq::Local(path) => ZkSolc::get_version_for_path(path)
.unwrap_or_else(|_| panic!("Could not find zksolc version for this path")),
});
let zksolc_path = get_zksolc_compiler(self.zksolc.as_ref(), offline)
.unwrap_or_else(|e| panic!("Could not find zksolc compiler: {e}"));

// `cli_settings` get set from `Project` values when building `ZkSolcVersionedInput`
ZkSolcSettings {
settings: zk_settings,
cli_settings: CliSettings::default(),
zksolc_version,
zksolc_version: ZkSolc::get_version_for_path(zksolc_path.as_ref())
.unwrap_or_else(|_| panic!("Could not find zksolc version for this path")),
}
}
}
Expand All @@ -173,19 +172,14 @@ pub fn config_zksolc_settings(config: &Config) -> Result<ZkSolcSettings, SolcErr
Err(e) => return Err(SolcError::msg(format!("Failed to parse libraries: {e}"))),
};

Ok(config.zksync.settings(libraries, config.evm_version, config.via_ir))
Ok(config.zksync.settings(libraries, config.evm_version, config.via_ir, config.offline))
}

/// Return the configured `zksolc` compiler
///
/// If not `offline`, will install the default version automatically
/// Will fallback to `zksolc` present in the environment
pub fn config_zksolc_compiler(config: &Config) -> Result<ZkSolcCompiler, SolcError> {
let zksolc = if let Some(zksolc) =
config_ensure_zksolc(config.zksync.zksolc.as_ref(), config.offline)?
{
/// get the configured `zksolc` compiler
pub fn get_zksolc_compiler(zksolc: Option<&SolcReq>, offline: bool) -> Result<PathBuf, SolcError> {
let zksolc = if let Some(zksolc) = config_ensure_zksolc(zksolc, offline)? {
zksolc
} else if !config.offline {
} else if !offline {
let default_version = semver::Version::new(1, 5, 10);
let mut zksolc = ZkSolc::find_installed_version(&default_version)?;
if zksolc.is_none() {
Expand All @@ -197,7 +191,18 @@ pub fn config_zksolc_compiler(config: &Config) -> Result<ZkSolcCompiler, SolcErr
"zksolc".into()
};

Ok(ZkSolcCompiler { zksolc, solc: config_solc_compiler(config)? })
Ok(zksolc)
}

/// Return the configured `zksolc` compiler
///
/// If not `offline`, will install the default version automatically
/// Will fallback to `zksolc` present in the environment
pub fn config_zksolc_compiler(config: &Config) -> Result<ZkSolcCompiler, SolcError> {
Ok(ZkSolcCompiler {
zksolc: get_zksolc_compiler(config.zksync.zksolc.as_ref(), config.offline)?,
solc: config_solc_compiler(config)?,
})
}

/// Create a new ZKsync project
Expand Down
18 changes: 15 additions & 3 deletions crates/zksync/compilers/src/compilers/zksolc/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use std::{
path::{Path, PathBuf},
str::FromStr,
};

use super::{ZkSolc, ZkSolcCompiler};
///
/// The Solidity compiler codegen.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
Expand Down Expand Up @@ -90,7 +92,7 @@ pub struct ZkSettings {
}

/// Analogous to SolcSettings for zksolc compiler
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ZkSolcSettings {
/// JSON settings expected by Solc
Expand All @@ -100,8 +102,18 @@ pub struct ZkSolcSettings {
#[serde(flatten)]
pub cli_settings: solc::CliSettings,
/// The version of the zksolc compiler to use.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub zksolc_version: Option<Version>,
pub zksolc_version: Version,
}

impl Default for ZkSolcSettings {
fn default() -> Self {
Self {
settings: Default::default(),
cli_settings: Default::default(),
zksolc_version: ZkSolc::get_version_for_path(ZkSolcCompiler::default().zksolc.as_ref())
.expect("Failed to get zksolc version"),
}
}
}

impl ZkSettings {
Expand Down

0 comments on commit 3db5b6a

Please sign in to comment.