diff --git a/Cargo.lock b/Cargo.lock index ed06ee544396..120b69e993ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2953,9 +2953,9 @@ dependencies = [ [[package]] name = "foundry-block-explorers" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebeafdc703baf5bb879b276653735cddb2e0244e5e59c24f3aeab5686d801006" +checksum = "5a056d4aa33a639c0aa1e9e473c25b9b191be30cbea94b31445fac5c272418ae" dependencies = [ "alloy-chains", "alloy-json-abi", @@ -3106,23 +3106,20 @@ dependencies = [ [[package]] name = "foundry-compilers" -version = "0.2.4" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5106d26aa9a9955c852bed6f9d8994d7229a177969ae5a813008022b022f31ae" +checksum = "7fd693c0870b3817b215417ff0f2f0df02cddf296dc5524c330f99186a42cf29" dependencies = [ "alloy-json-abi", "alloy-primitives", "cfg-if", - "const-hex", "dirs 5.0.1", "dunce", "fs_extra", "futures-util", - "glob", "home", "md-5 0.10.6", "memmap2 0.9.4", - "num_cpus", "once_cell", "path-slash", "rand 0.8.5", @@ -3137,7 +3134,6 @@ dependencies = [ "svm-rs-builds 0.3.5", "tempfile", "thiserror", - "tiny-keccak", "tokio", "tracing", "walkdir", diff --git a/Cargo.toml b/Cargo.toml index d379d9ceadcb..4fc87a5d2611 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -124,8 +124,8 @@ foundry-macros = { path = "crates/macros" } foundry-test-utils = { path = "crates/test-utils" } # solc & compilation utilities -foundry-block-explorers = { version = "0.2.0", default-features = false } -foundry-compilers = { version = "0.2.4", default-features = false } +foundry-block-explorers = { version = "0.2.3", default-features = false } +foundry-compilers = { version = "0.3.1", default-features = false } ## revm # no default features to avoid c-kzg @@ -222,4 +222,4 @@ revm-primitives = { git = "https://github.com/bluealloy/revm", branch = "reth_fr revm-interpreter = { git = "https://github.com/bluealloy/revm", branch = "reth_freeze" } revm-precompile = { git = "https://github.com/bluealloy/revm", branch = "reth_freeze" } -revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors" } +revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors" } \ No newline at end of file diff --git a/crates/forge/bin/cmd/flatten.rs b/crates/forge/bin/cmd/flatten.rs index 0716af47267a..9831e17cecce 100644 --- a/crates/forge/bin/cmd/flatten.rs +++ b/crates/forge/bin/cmd/flatten.rs @@ -4,7 +4,8 @@ use foundry_cli::{ opts::{CoreBuildArgs, ProjectPathsArgs}, utils::LoadConfig, }; -use foundry_common::fs; +use foundry_common::{compile::ProjectCompiler, fs}; +use foundry_compilers::{error::SolcError, flatten::Flattener}; use std::path::PathBuf; /// CLI arguments for `forge flatten`. @@ -38,10 +39,24 @@ impl FlattenArgs { let config = build_args.try_load_config_emit_warnings()?; - let paths = config.project_paths(); let target_path = dunce::canonicalize(target_path)?; - let flattened = - paths.flatten(&target_path).map_err(|err| eyre::eyre!("Failed to flatten: {err}"))?; + + let project = config.ephemeral_no_artifacts_project()?; + + let compiler_output = ProjectCompiler::new().files([target_path.clone()]).compile(&project); + + let flattened = match compiler_output { + Ok(compiler_output) => { + Flattener::new(&project, &compiler_output, &target_path).map(|f| f.flatten()) + } + Err(_) => { + // Fallback to the old flattening implementation if we couldn't compile the target + // successfully. This would be the case if the target has invalid + // syntax. (e.g. Solang) + project.paths.flatten(&target_path) + } + } + .map_err(|err: SolcError| eyre::eyre!("Failed to flatten: {err}"))?; match output { Some(output) => {