diff --git a/crates/common/src/compile.rs b/crates/common/src/compile.rs index 3f159f069b0f..8272dece32ac 100644 --- a/crates/common/src/compile.rs +++ b/crates/common/src/compile.rs @@ -245,7 +245,16 @@ impl ProjectCompiler { } let mut size_report = SizeReport { contracts: BTreeMap::new() }; - let artifacts: BTreeMap<_, _> = output.artifacts().collect(); + + let artifacts: BTreeMap<_, _> = output + .artifact_ids() + .filter(|(id, _)| { + // filter out forge-std specific contracts + !id.source.to_string_lossy().contains("/forge-std/src/") + }) + .map(|(id, artifact)| (id.name, artifact)) + .collect(); + for (name, artifact) in artifacts { let size = deployed_contract_size(artifact).unwrap_or_default(); @@ -381,6 +390,7 @@ impl Display for SizeReport { Cell::new("Margin (kB)").add_attribute(Attribute::Bold).fg(Color::Blue), ]); + // filters out non dev contracts (Test or Script) let contracts = self.contracts.iter().filter(|(_, c)| !c.is_dev_contract && c.size > 0); for (name, contract) in contracts { let margin = CONTRACT_SIZE_LIMIT as isize - contract.size as isize; diff --git a/crates/forge/tests/cli/build.rs b/crates/forge/tests/cli/build.rs index 0002ec14529d..668e4be5e1de 100644 --- a/crates/forge/tests/cli/build.rs +++ b/crates/forge/tests/cli/build.rs @@ -31,3 +31,12 @@ forgetest_init!(exact_build_output, |prj, cmd| { let stdout = cmd.stdout_lossy(); assert!(stdout.contains("Compiling"), "\n{stdout}"); }); + +// tests build output is as expected +forgetest_init!(build_sizes_no_forge_std, |prj, cmd| { + cmd.args(["build", "--sizes"]); + let stdout = cmd.stdout_lossy(); + assert!(!stdout.contains("console"), "\n{stdout}"); + assert!(!stdout.contains("std"), "\n{stdout}"); + assert!(stdout.contains("Counter"), "\n{stdout}"); +});