Skip to content

Commit b455c5b

Browse files
grandizzyDaniPopes
andauthored
feat(forge): optimize compilation through preprocessing and caching (#10010)
* feat(forge): optimize compilation through preprocessing and caching * Add various test scenarios * Changes after review: rename cache_tests, add build option * Update solar and compilers revs * Update refs, add test with constructor args without name * Bump compilers rev * add test for named args, bump solar and compilers * feat(forge): add vm.deployCode cheats with msg.value and salt * Bump compilers, ctor test with value and salt, ignore win panic * Bump compilers with fix for win panic * Bump compilers * Update crates/common/src/compile.rs Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com> * bump * bump solar * bump solar 2 * bump compilers * ename config dynamic_test_linking, bump compilers * Dynamic test linking default enabled * More test fixes * chore: move preprocessor from compilers * bump * Ensure no cached artifacts in projects * Disable by default * Handle constructor expectRevert * Collect deps from call args too * Bump solar, use upstream fix for call args deps * Bump solar, compilers and block explorers --------- Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
1 parent e867a6c commit b455c5b

File tree

18 files changed

+2182
-55
lines changed

18 files changed

+2182
-55
lines changed

Cargo.lock

Lines changed: 74 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,12 @@ foundry-wallets = { path = "crates/wallets" }
188188
foundry-linking = { path = "crates/linking" }
189189

190190
# solc & compilation utilities
191-
foundry-block-explorers = { version = "0.11.0", default-features = false }
192-
foundry-compilers = { version = "0.13.5", default-features = false }
191+
foundry-block-explorers = { version = "0.13.0", default-features = false }
192+
foundry-compilers = { version = "0.14.0", default-features = false }
193193
foundry-fork-db = "0.12"
194194
solang-parser = "=0.3.3"
195-
solar-parse = { version = "=0.1.1", default-features = false }
195+
solar-parse = { version = "=0.1.2", default-features = false }
196+
solar-sema = { version = "=0.1.2", default-features = false }
196197

197198
## revm
198199
revm = { version = "19.4.0", default-features = false }
@@ -309,6 +310,7 @@ tracing-subscriber = "0.3"
309310
url = "2"
310311
vergen = { version = "8", default-features = false }
311312
yansi = { version = "1.0", features = ["detect-tty", "detect-env"] }
313+
path-slash = "0.2"
312314

313315
[patch.crates-io]
314316
## alloy-core

crates/cheatcodes/src/fs.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -371,19 +371,22 @@ fn deploy_code(
371371
revm::primitives::CreateScheme::Create
372372
};
373373

374-
let address = executor
375-
.exec_create(
376-
CreateInputs {
377-
caller: ccx.caller,
378-
scheme,
379-
value: value.unwrap_or(U256::ZERO),
380-
init_code: bytecode.into(),
381-
gas_limit: ccx.gas_limit,
382-
},
383-
ccx,
384-
)?
385-
.address
386-
.ok_or_else(|| fmt_err!("contract creation failed"))?;
374+
let outcome = executor.exec_create(
375+
CreateInputs {
376+
caller: ccx.caller,
377+
scheme,
378+
value: value.unwrap_or(U256::ZERO),
379+
init_code: bytecode.into(),
380+
gas_limit: ccx.gas_limit,
381+
},
382+
ccx,
383+
)?;
384+
385+
if !outcome.result.result.is_ok() {
386+
return Err(crate::Error::from(outcome.result.output))
387+
}
388+
389+
let address = outcome.address.ok_or_else(|| fmt_err!("contract creation failed"))?;
387390

388391
Ok(address.abi_encode())
389392
}

crates/cli/src/opts/build/core.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ pub struct BuildOpts {
3434
#[serde(skip)]
3535
pub no_cache: bool,
3636

37+
/// Enable dynamic test linking.
38+
#[arg(long, conflicts_with = "no_cache")]
39+
#[serde(skip)]
40+
pub dynamic_test_linking: bool,
41+
3742
/// Set pre-linked libraries.
3843
#[arg(long, help_heading = "Linker options", env = "DAPP_LIBRARIES")]
3944
#[serde(skip_serializing_if = "Vec::is_empty")]
@@ -245,6 +250,10 @@ impl Provider for BuildOpts {
245250
dict.insert("cache".to_string(), false.into());
246251
}
247252

253+
if self.dynamic_test_linking {
254+
dict.insert("dynamic_test_linking".to_string(), true.into());
255+
}
256+
248257
if self.build_info {
249258
dict.insert("build_info".to_string(), self.build_info.into());
250259
}

crates/common/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ alloy-transport.workspace = true
4545
alloy-consensus = { workspace = true, features = ["k256"] }
4646
alloy-network.workspace = true
4747

48+
solar-parse.workspace = true
49+
solar-sema.workspace = true
50+
4851
tower.workspace = true
4952

5053
async-trait.workspace = true
@@ -64,6 +67,7 @@ tracing.workspace = true
6467
url.workspace = true
6568
walkdir.workspace = true
6669
yansi.workspace = true
70+
path-slash.workspace = true
6771

6872
anstream.workspace = true
6973
anstyle.workspace = true

0 commit comments

Comments
 (0)