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

bump compilers #8011

Merged
merged 18 commits into from
Jun 3, 2024
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ foundry-wallets = { path = "crates/wallets" }
foundry-linking = { path = "crates/linking" }

# solc & compilation utilities
foundry-block-explorers = { version = "0.2.8", default-features = false }
foundry-compilers = { version = "0.5.2", default-features = false }
foundry-block-explorers = { version = "0.3.0", default-features = false }
foundry-compilers = { version = "0.6.0", default-features = false }

## revm
# no default features to avoid c-kzg
Expand Down
28 changes: 16 additions & 12 deletions crates/cast/bin/cmd/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ use foundry_common::{
};
use foundry_compilers::{
artifacts::StorageLayout,
compilers::{solc::SolcVersionManager, CompilerVersionManager},
Artifact, CompilerConfig, ConfigurableContractArtifact, Project,
compilers::{solc::SolcCompiler, Compiler, CompilerSettings},
Artifact, ConfigurableContractArtifact, Project, Solc,
};
use foundry_config::{
figment::{self, value::Dict, Metadata, Profile},
impl_figment_convert_cast, Config,
};
use semver::Version;
use std::{str::FromStr, sync::Arc};
use std::str::FromStr;

/// The minimum Solc version for outputting storage layouts.
///
Expand Down Expand Up @@ -142,11 +142,10 @@ impl StorageArgs {
let mut project = etherscan_project(metadata, root_path)?;
add_storage_layout_output(&mut project);

let vm = SolcVersionManager::default();
project.compiler_config = if auto_detect {
CompilerConfig::AutoDetect(Arc::new(vm))
project.compiler = if auto_detect {
SolcCompiler::AutoDetect
} else {
CompilerConfig::Specific(vm.get_or_install(&version)?)
SolcCompiler::Specific(Solc::find_or_install(&version)?)
};

// Compile
Expand All @@ -160,8 +159,8 @@ impl StorageArgs {
if is_storage_layout_empty(&artifact.storage_layout) && auto_detect {
// try recompiling with the minimum version
eprintln!("The requested contract was compiled with {version} while the minimum version for storage layouts is {MIN_SOLC} and as a result the output may be empty.");
let solc = SolcVersionManager::default().get_or_install(&MIN_SOLC)?;
project.compiler_config = CompilerConfig::Specific(solc);
let solc = Solc::find_or_install(&MIN_SOLC)?;
project.compiler = SolcCompiler::Specific(solc);
if let Ok(output) = ProjectCompiler::new().quiet(true).compile(&project) {
out = output;
let (_, new_artifact) = out
Expand Down Expand Up @@ -284,10 +283,15 @@ fn print_storage(layout: StorageLayout, values: Vec<StorageValue>, pretty: bool)
Ok(())
}

fn add_storage_layout_output(project: &mut Project) {
fn add_storage_layout_output<C: Compiler>(project: &mut Project<C>) {
project.artifacts.additional_values.storage_layout = true;
let output_selection = project.artifacts.output_selection();
project.settings.push_all(output_selection);
project.settings.update_output_selection(|selection| {
selection.0.values_mut().for_each(|contract_selection| {
contract_selection
.values_mut()
.for_each(|selection| selection.push("storageLayout".to_string()))
});
})
}

fn is_storage_layout_empty(storage_layout: &Option<StorageLayout>) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion crates/cheatcodes/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ fn get_artifact_code(state: &Cheatcodes, path: &str, deployed: bool) -> Result<B
let mut version = None;

let path_or_name = parts.next().unwrap();
if path_or_name.ends_with(".sol") {
if path_or_name.contains('.') {
file = Some(PathBuf::from(path_or_name));
if let Some(name_or_version) = parts.next() {
if name_or_version.contains('.') {
Expand Down
8 changes: 2 additions & 6 deletions crates/chisel/benches/session_source.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use chisel::session_source::{SessionSource, SessionSourceConfig};
use criterion::{criterion_group, Criterion};
use foundry_compilers::{
compilers::{solc::SolcVersionManager, CompilerVersionManager},
Solc,
};
use foundry_compilers::Solc;
use once_cell::sync::Lazy;
use semver::Version;
use std::hint::black_box;
use tokio::runtime::Runtime;

static SOLC: Lazy<Solc> =
Lazy::new(|| SolcVersionManager::default().get_or_install(&Version::new(0, 8, 19)).unwrap());
static SOLC: Lazy<Solc> = Lazy::new(|| Solc::find_or_install(&Version::new(0, 8, 19)).unwrap());

/// Benchmark for the `clone_with_new_line` function in [SessionSource]
fn clone_with_new_line(c: &mut Criterion) {
Expand Down
13 changes: 3 additions & 10 deletions crates/chisel/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1401,11 +1401,7 @@ impl<'a> Iterator for InstructionIter<'a> {
#[cfg(test)]
mod tests {
use super::*;
use foundry_compilers::{
compilers::{solc::SolcVersionManager, CompilerVersionManager},
error::SolcError,
Solc,
};
use foundry_compilers::{error::SolcError, Solc};
use semver::Version;
use std::sync::Mutex;

Expand Down Expand Up @@ -1690,8 +1686,7 @@ mod tests {
for _ in 0..3 {
let mut is_preinstalled = PRE_INSTALL_SOLC_LOCK.lock().unwrap();
if !*is_preinstalled {
let solc = SolcVersionManager::default()
.get_or_install(&version.parse().unwrap())
let solc = Solc::find_or_install(&version.parse().unwrap())
.map(|solc| (solc.version.clone(), solc));
match solc {
Ok((v, solc)) => {
Expand All @@ -1712,9 +1707,7 @@ mod tests {
}
}

let solc = SolcVersionManager::default()
.get_or_install(&Version::new(0, 8, 19))
.expect("could not install solc");
let solc = Solc::find_or_install(&Version::new(0, 8, 19)).expect("could not install solc");
SessionSource::new(solc, Default::default())
}

Expand Down
25 changes: 12 additions & 13 deletions crates/chisel/src/session_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use eyre::Result;
use forge_fmt::solang_ext::SafeUnwrap;
use foundry_compilers::{
artifacts::{Settings, Source, Sources},
compilers::{solc::SolcVersionManager, CompilerInput, CompilerVersionManager},
CompilerOutput, Solc, SolcInput,
};
use foundry_config::{Config, SolcReq};
Expand Down Expand Up @@ -104,8 +103,6 @@ impl SessionSourceConfig {
SolcReq::Version(Version::new(0, 8, 19))
};

let vm = SolcVersionManager::default();

match solc_req {
SolcReq::Version(version) => {
// Validate that the requested evm version is supported by the solc version
Expand All @@ -118,15 +115,16 @@ impl SessionSourceConfig {
}
}

let solc = if let Ok(solc) = vm.get_installed(&version) {
solc
} else {
if self.foundry_config.offline {
eyre::bail!("can't install missing solc {version} in offline mode")
}
println!("{}", format!("Installing solidity version {version}...").green());
vm.install(&version)?
};
let solc =
if let Some(solc) = Solc::find_svm_installed_version(version.to_string())? {
solc
} else {
if self.foundry_config.offline {
eyre::bail!("can't install missing solc {version} in offline mode")
}
println!("{}", format!("Installing solidity version {version}...").green());
Solc::blocking_install(&version)?
};
Ok(solc)
}
SolcReq::Local(solc) => {
Expand Down Expand Up @@ -329,9 +327,10 @@ impl SessionSource {
};

// we only care about the solidity source, so we can safely unwrap
SolcInput::build(sources, settings, &self.solc.version)
SolcInput::resolve_and_build(sources, settings)
.into_iter()
.next()
.map(|i| i.sanitized(&self.solc.version))
.expect("Solidity source not found")
}

Expand Down
5 changes: 3 additions & 2 deletions crates/cli/src/opts/build/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use crate::{opts::CompilerArgs, utils::LoadConfig};
use clap::{Parser, ValueHint};
use eyre::Result;
use foundry_compilers::{
artifacts::RevertStrings, remappings::Remapping, utils::canonicalized, Project,
artifacts::RevertStrings, compilers::multi::MultiCompiler, remappings::Remapping,
utils::canonicalized, Project,
};
use foundry_config::{
figment,
Expand Down Expand Up @@ -132,7 +133,7 @@ impl CoreBuildArgs {
/// This loads the `foundry_config::Config` for the current workspace (see
/// [`utils::find_project_root_path`] and merges the cli `BuildArgs` into it before returning
/// [`foundry_config::Config::project()`]
pub fn project(&self) -> Result<Project> {
pub fn project(&self) -> Result<Project<MultiCompiler>> {
let config = self.try_load_config_emit_warnings()?;
Ok(config.project()?)
}
Expand Down
40 changes: 11 additions & 29 deletions crates/common/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ use eyre::{Context, Result};
use foundry_block_explorers::contract::Metadata;
use foundry_compilers::{
artifacts::{BytecodeObject, ContractBytecodeSome, Libraries},
compilers::{
solc::SolcVersionManager, vyper::parser::VyperParsedSource, Compiler,
CompilerVersionManager,
},
compilers::{solc::SolcCompiler, Compiler},
remappings::Remapping,
report::{BasicStdoutReporter, NoReporter, Report},
resolver::{parse::SolData, GraphEdges},
Artifact, ArtifactId, CompilerConfig, FileFilter, Project, ProjectCompileOutput,
ProjectPathsConfig, SolcConfig, SolcSparseFileFilter, SparseOutputFileFilter,
Artifact, ArtifactId, FileFilter, Project, ProjectBuilder, ProjectCompileOutput,
ProjectPathsConfig, Solc, SolcConfig, SparseOutputFileFilter,
};
use foundry_linking::Linker;
use num_format::{Locale, ToFormattedString};
Expand Down Expand Up @@ -521,7 +517,10 @@ pub async fn compile_from_source(
}

/// Creates a [Project] from an Etherscan source.
pub fn etherscan_project(metadata: &Metadata, target_path: impl AsRef<Path>) -> Result<Project> {
pub fn etherscan_project(
metadata: &Metadata,
target_path: impl AsRef<Path>,
) -> Result<Project<SolcCompiler>> {
let target_path = dunce::canonicalize(target_path.as_ref())?;
let sources_path = target_path.join(&metadata.contract_name);
metadata.source_tree().write_to(&target_path)?;
Expand Down Expand Up @@ -553,17 +552,16 @@ pub fn etherscan_project(metadata: &Metadata, target_path: impl AsRef<Path>) ->
.build_with_root(sources_path);

let v = metadata.compiler_version()?;
let vm = SolcVersionManager::default();
let solc = vm.get_or_install(&v)?;
let solc = Solc::find_or_install(&v)?;

let compiler_config = CompilerConfig::Specific(solc);
let compiler = SolcCompiler::Specific(solc);

Ok(Project::builder()
Ok(ProjectBuilder::<SolcCompiler>::default()
.settings(SolcConfig::builder().settings(settings).build().settings)
.paths(paths)
.ephemeral()
.no_artifacts()
.build(compiler_config)?)
.build(compiler)?)
}

/// Bundles multiple `SkipBuildFilter` into a single `FileFilter`
Expand Down Expand Up @@ -595,22 +593,6 @@ impl FileFilter for &SkipBuildFilters {
}
}

impl SparseOutputFileFilter<SolData> for SkipBuildFilters {
fn sparse_sources(&self, file: &Path, graph: &GraphEdges<SolData>) -> Vec<PathBuf> {
SolcSparseFileFilter::new(self).sparse_sources(file, graph)
}
}

impl SparseOutputFileFilter<VyperParsedSource> for SkipBuildFilters {
fn sparse_sources(&self, file: &Path, _graph: &GraphEdges<VyperParsedSource>) -> Vec<PathBuf> {
if self.is_match(file) {
vec![file.to_path_buf()]
} else {
vec![]
}
}
}

impl SkipBuildFilters {
/// Creates a new `SkipBuildFilters` from multiple `SkipBuildFilter`.
pub fn new(
Expand Down
Loading
Loading