From 8552492bb3212af840809745343b3deedcd7a036 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Mon, 29 Jan 2024 16:20:22 +0300 Subject: [PATCH 01/11] Update Flatten impl --- Cargo.lock | 3 +-- Cargo.toml | 2 ++ crates/forge/bin/cmd/flatten.rs | 26 ++++++++++++++++++++++---- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ed06ee544396..e5760121a38c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3107,8 +3107,7 @@ dependencies = [ [[package]] name = "foundry-compilers" version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5106d26aa9a9955c852bed6f9d8994d7229a177969ae5a813008022b022f31ae" +source = "git+https://github.com/foundry-rs/compilers?branch=klkvr/new-flattener#730cb39f2493bf434b356cbeb68b943d3221c7d3" dependencies = [ "alloy-json-abi", "alloy-primitives", diff --git a/Cargo.toml b/Cargo.toml index d379d9ceadcb..b710ab71510b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -223,3 +223,5 @@ revm-interpreter = { git = "https://github.com/bluealloy/revm", branch = "reth_f revm-precompile = { git = "https://github.com/bluealloy/revm", branch = "reth_freeze" } revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors" } + +foundry-compilers = { git = "https://github.com/foundry-rs/compilers", branch = "klkvr/new-flattener"} \ No newline at end of file diff --git a/crates/forge/bin/cmd/flatten.rs b/crates/forge/bin/cmd/flatten.rs index 0716af47267a..7e2d88503ad9 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::{artifacts::Source, error::SolcError, flatten::Flattener, Graph}; use std::path::PathBuf; /// CLI arguments for `forge flatten`. @@ -38,10 +39,27 @@ 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}"))?; + + // We need to provide Flattener with compiled output of target and all of it's imports. + let project = config.ephemeral_no_artifacts_project()?; + let sources = Source::read_all(vec![target_path.clone()])?; + let (sources, _) = Graph::resolve_sources(&project.paths, sources)?.into_sources(); + + let compiler_output = ProjectCompiler::new().files(sources.into_keys()).compile(&project); + + let flattened = match compiler_output { + Ok(compiler_output) => { + Ok(Flattener::new(&project, &compiler_output, &target_path)?.flatten()) + } + Err(_) => { + // Fallback to the old flattening compilation if we couldn't compile the target + // successfully. This would be the case if the target has invalid + // syntax. (e.g. Solang) + Ok(project.paths.flatten(&target_path)?) + } + } + .map_err(|err: SolcError| eyre::eyre!("Failed to flatten: {err}"))?; match output { Some(output) => { From 36eec0b9e6654e94b7aa7aad51e2560a7e5a2fee Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Mon, 29 Jan 2024 19:32:26 +0300 Subject: [PATCH 02/11] Bump foundry-compilers --- Cargo.lock | 5 +++-- Cargo.toml | 6 ++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e5760121a38c..6bd437832b2b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3106,8 +3106,9 @@ dependencies = [ [[package]] name = "foundry-compilers" -version = "0.2.4" -source = "git+https://github.com/foundry-rs/compilers?branch=klkvr/new-flattener#730cb39f2493bf434b356cbeb68b943d3221c7d3" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c279e42a2206bbc273038a68508cd37d1605be4a81b3f76c083426d546e1e8d4" dependencies = [ "alloy-json-abi", "alloy-primitives", diff --git a/Cargo.toml b/Cargo.toml index b710ab71510b..a8889bc8f2c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -125,7 +125,7 @@ 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-compilers = { version = "0.2.5", default-features = false } ## revm # no default features to avoid c-kzg @@ -222,6 +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" } - -foundry-compilers = { git = "https://github.com/foundry-rs/compilers", branch = "klkvr/new-flattener"} \ No newline at end of file +revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors" } \ No newline at end of file From dd54c19c5e4ab4679f64ec70b652e650ded25308 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Mon, 29 Jan 2024 19:55:25 +0300 Subject: [PATCH 03/11] fix error handling --- crates/forge/bin/cmd/flatten.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/forge/bin/cmd/flatten.rs b/crates/forge/bin/cmd/flatten.rs index 7e2d88503ad9..30816a94dbaa 100644 --- a/crates/forge/bin/cmd/flatten.rs +++ b/crates/forge/bin/cmd/flatten.rs @@ -49,14 +49,15 @@ impl FlattenArgs { let compiler_output = ProjectCompiler::new().files(sources.into_keys()).compile(&project); let flattened = match compiler_output { - Ok(compiler_output) => { - Ok(Flattener::new(&project, &compiler_output, &target_path)?.flatten()) - } + Ok(compiler_output) => match Flattener::new(&project, &compiler_output, &target_path) { + Ok(flattener) => Ok(flattener.flatten()), + Err(err) => Err(err), + }, Err(_) => { // Fallback to the old flattening compilation if we couldn't compile the target // successfully. This would be the case if the target has invalid // syntax. (e.g. Solang) - Ok(project.paths.flatten(&target_path)?) + project.paths.flatten(&target_path) } } .map_err(|err: SolcError| eyre::eyre!("Failed to flatten: {err}"))?; From a929ad15506ce96768d430eebec23ac4304b56a0 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Mon, 29 Jan 2024 23:28:55 +0300 Subject: [PATCH 04/11] Update crates/forge/bin/cmd/flatten.rs Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com> --- crates/forge/bin/cmd/flatten.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/forge/bin/cmd/flatten.rs b/crates/forge/bin/cmd/flatten.rs index 30816a94dbaa..1eb992222820 100644 --- a/crates/forge/bin/cmd/flatten.rs +++ b/crates/forge/bin/cmd/flatten.rs @@ -41,7 +41,7 @@ impl FlattenArgs { let target_path = dunce::canonicalize(target_path)?; - // We need to provide Flattener with compiled output of target and all of it's imports. + // We need to provide Flattener with compiled output of target and all of its imports. let project = config.ephemeral_no_artifacts_project()?; let sources = Source::read_all(vec![target_path.clone()])?; let (sources, _) = Graph::resolve_sources(&project.paths, sources)?.into_sources(); From 7fde3ac405b83a9b271c0ff12e52a1980c63f627 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Mon, 29 Jan 2024 23:30:20 +0300 Subject: [PATCH 05/11] error handling --- crates/forge/bin/cmd/flatten.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/forge/bin/cmd/flatten.rs b/crates/forge/bin/cmd/flatten.rs index 1eb992222820..e065a3c3eaad 100644 --- a/crates/forge/bin/cmd/flatten.rs +++ b/crates/forge/bin/cmd/flatten.rs @@ -49,10 +49,9 @@ impl FlattenArgs { let compiler_output = ProjectCompiler::new().files(sources.into_keys()).compile(&project); let flattened = match compiler_output { - Ok(compiler_output) => match Flattener::new(&project, &compiler_output, &target_path) { - Ok(flattener) => Ok(flattener.flatten()), - Err(err) => Err(err), - }, + Ok(compiler_output) => { + Flattener::new(&project, &compiler_output, &target_path).map(|f| f.flatten()) + } Err(_) => { // Fallback to the old flattening compilation if we couldn't compile the target // successfully. This would be the case if the target has invalid From ff14ffa702b7a1932c03cbd49ae1d48a872f5a26 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Wed, 31 Jan 2024 20:31:19 +0300 Subject: [PATCH 06/11] Bump compilers and block-explorers --- Cargo.lock | 12 ++++-------- Cargo.toml | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6bd437832b2b..3e629ba62b35 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.5" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c279e42a2206bbc273038a68508cd37d1605be4a81b3f76c083426d546e1e8d4" +checksum = "c2d74d76d3129b4f821b24787193d8619ba07b9ebec60ce3f33e40f8ec190667" 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 a8889bc8f2c2..e23027048565 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.5", default-features = false } +foundry-block-explorers = { version = "0.2.3", default-features = false } +foundry-compilers = { version = "0.3.0", default-features = false } ## revm # no default features to avoid c-kzg From 8e8c493d5ef85181db97fdf9c5149a2b2a106ed6 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Wed, 31 Jan 2024 21:36:30 +0300 Subject: [PATCH 07/11] Simplify compilation --- crates/forge/bin/cmd/flatten.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/forge/bin/cmd/flatten.rs b/crates/forge/bin/cmd/flatten.rs index e065a3c3eaad..be976abaa321 100644 --- a/crates/forge/bin/cmd/flatten.rs +++ b/crates/forge/bin/cmd/flatten.rs @@ -5,7 +5,7 @@ use foundry_cli::{ utils::LoadConfig, }; use foundry_common::{compile::ProjectCompiler, fs}; -use foundry_compilers::{artifacts::Source, error::SolcError, flatten::Flattener, Graph}; +use foundry_compilers::{error::SolcError, flatten::Flattener}; use std::path::PathBuf; /// CLI arguments for `forge flatten`. @@ -41,12 +41,10 @@ impl FlattenArgs { let target_path = dunce::canonicalize(target_path)?; - // We need to provide Flattener with compiled output of target and all of its imports. let project = config.ephemeral_no_artifacts_project()?; - let sources = Source::read_all(vec![target_path.clone()])?; - let (sources, _) = Graph::resolve_sources(&project.paths, sources)?.into_sources(); - let compiler_output = ProjectCompiler::new().files(sources.into_keys()).compile(&project); + let compiler_output = + ProjectCompiler::new().files([target_path.clone()]).compile(&project); let flattened = match compiler_output { Ok(compiler_output) => { From 5a92e568d7e857ba4517378e09110de3adcae734 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Wed, 31 Jan 2024 21:38:20 +0300 Subject: [PATCH 08/11] fmt --- crates/forge/bin/cmd/flatten.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/forge/bin/cmd/flatten.rs b/crates/forge/bin/cmd/flatten.rs index be976abaa321..e2ac9d08b32f 100644 --- a/crates/forge/bin/cmd/flatten.rs +++ b/crates/forge/bin/cmd/flatten.rs @@ -43,8 +43,7 @@ impl FlattenArgs { let project = config.ephemeral_no_artifacts_project()?; - let compiler_output = - ProjectCompiler::new().files([target_path.clone()]).compile(&project); + let compiler_output = ProjectCompiler::new().files([target_path.clone()]).compile(&project); let flattened = match compiler_output { Ok(compiler_output) => { From f2ed450cd9dc0023c04a6f24205313f27338fcb3 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Wed, 31 Jan 2024 21:44:23 +0300 Subject: [PATCH 09/11] fix doc --- crates/forge/bin/cmd/flatten.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/forge/bin/cmd/flatten.rs b/crates/forge/bin/cmd/flatten.rs index e2ac9d08b32f..9831e17cecce 100644 --- a/crates/forge/bin/cmd/flatten.rs +++ b/crates/forge/bin/cmd/flatten.rs @@ -50,7 +50,7 @@ impl FlattenArgs { Flattener::new(&project, &compiler_output, &target_path).map(|f| f.flatten()) } Err(_) => { - // Fallback to the old flattening compilation if we couldn't compile the target + // 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) From 8f07698dacfc03a39f1dc4d920919744e05b7da5 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Thu, 1 Feb 2024 22:00:51 +0300 Subject: [PATCH 10/11] use patch --- Cargo.lock | 3 +-- Cargo.toml | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3e629ba62b35..80c8758e7ef3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3107,8 +3107,7 @@ dependencies = [ [[package]] name = "foundry-compilers" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2d74d76d3129b4f821b24787193d8619ba07b9ebec60ce3f33e40f8ec190667" +source = "git+https://github.com/klkvr/compilers?branch=klkvr/flatten-fix#bf346c5076b14912159639b779433d0272b381d8" dependencies = [ "alloy-json-abi", "alloy-primitives", diff --git a/Cargo.toml b/Cargo.toml index e23027048565..60fa82954292 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -222,4 +222,6 @@ 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" } \ No newline at end of file +revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors" } + +foundry-compilers = { git = "https://github.com/klkvr/compilers", branch = "klkvr/flatten-fix" } \ No newline at end of file From 94c139e2dc5b741ca5bfdac9ba644fbdfa0696b4 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Fri, 2 Feb 2024 15:08:24 +0300 Subject: [PATCH 11/11] bump compilers --- Cargo.lock | 5 +++-- Cargo.toml | 6 ++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 80c8758e7ef3..120b69e993ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3106,8 +3106,9 @@ dependencies = [ [[package]] name = "foundry-compilers" -version = "0.3.0" -source = "git+https://github.com/klkvr/compilers?branch=klkvr/flatten-fix#bf346c5076b14912159639b779433d0272b381d8" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fd693c0870b3817b215417ff0f2f0df02cddf296dc5524c330f99186a42cf29" dependencies = [ "alloy-json-abi", "alloy-primitives", diff --git a/Cargo.toml b/Cargo.toml index 60fa82954292..4fc87a5d2611 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -125,7 +125,7 @@ foundry-test-utils = { path = "crates/test-utils" } # solc & compilation utilities foundry-block-explorers = { version = "0.2.3", default-features = false } -foundry-compilers = { version = "0.3.0", default-features = false } +foundry-compilers = { version = "0.3.1", default-features = false } ## revm # no default features to avoid c-kzg @@ -222,6 +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" } - -foundry-compilers = { git = "https://github.com/klkvr/compilers", branch = "klkvr/flatten-fix" } \ No newline at end of file +revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors" } \ No newline at end of file