Skip to content

Commit

Permalink
fix: ignore forge-std artifacts in build --sizes (#7414)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Mar 18, 2024
1 parent db8ea58 commit a08a7da
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/common/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions crates/forge/tests/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
});

0 comments on commit a08a7da

Please sign in to comment.