Skip to content

Commit

Permalink
feat(forge): allow passing value to --optimize (#9071)
Browse files Browse the repository at this point in the history
feat(forge): allow passing value to --optimize
  • Loading branch information
klkvr authored Oct 9, 2024
1 parent ad86979 commit 641132f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions crates/cli/src/opts/build/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ impl Provider for CoreBuildArgs {
dict.insert("ast".to_string(), true.into());
}

if self.compiler.optimize {
dict.insert("optimizer".to_string(), self.compiler.optimize.into());
if let Some(optimize) = self.compiler.optimize {
dict.insert("optimizer".to_string(), optimize.into());
}

if !self.compiler.extra_output.is_empty() {
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/opts/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ pub struct CompilerArgs {
pub evm_version: Option<EvmVersion>,

/// Activate the Solidity optimizer.
#[arg(long)]
#[arg(long, default_missing_value="true", num_args = 0..=1)]
#[serde(skip)]
pub optimize: bool,
pub optimize: Option<bool>,

/// The number of runs specifies roughly how often each opcode of the deployed code will be
/// executed across the life-time of the contract. This means it is a trade-off parameter
Expand Down
7 changes: 5 additions & 2 deletions crates/forge/bin/cmd/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,11 @@ impl CreateArgs {

println!("Starting contract verification...");

let num_of_optimizations =
if self.opts.compiler.optimize { self.opts.compiler.optimizer_runs } else { None };
let num_of_optimizations = if self.opts.compiler.optimize.unwrap_or_default() {
self.opts.compiler.optimizer_runs
} else {
None
};
let verify = forge_verify::VerifyArgs {
address,
contract: Some(self.contract),
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl InspectArgs {

// Run Optimized?
let optimized = if field == ContractArtifactField::AssemblyOptimized {
true
Some(true)
} else {
build.compiler.optimize
};
Expand Down

0 comments on commit 641132f

Please sign in to comment.