Skip to content

Commit 641132f

Browse files
authored
feat(forge): allow passing value to --optimize (#9071)
feat(forge): allow passing value to --optimize
1 parent ad86979 commit 641132f

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ impl Provider for CoreBuildArgs {
266266
dict.insert("ast".to_string(), true.into());
267267
}
268268

269-
if self.compiler.optimize {
270-
dict.insert("optimizer".to_string(), self.compiler.optimize.into());
269+
if let Some(optimize) = self.compiler.optimize {
270+
dict.insert("optimizer".to_string(), optimize.into());
271271
}
272272

273273
if !self.compiler.extra_output.is_empty() {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ pub struct CompilerArgs {
2626
pub evm_version: Option<EvmVersion>,
2727

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

3333
/// The number of runs specifies roughly how often each opcode of the deployed code will be
3434
/// executed across the life-time of the contract. This means it is a trade-off parameter

crates/forge/bin/cmd/create.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,11 @@ impl CreateArgs {
335335

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

338-
let num_of_optimizations =
339-
if self.opts.compiler.optimize { self.opts.compiler.optimizer_runs } else { None };
338+
let num_of_optimizations = if self.opts.compiler.optimize.unwrap_or_default() {
339+
self.opts.compiler.optimizer_runs
340+
} else {
341+
None
342+
};
340343
let verify = forge_verify::VerifyArgs {
341344
address,
342345
contract: Some(self.contract),

crates/forge/bin/cmd/inspect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl InspectArgs {
5252

5353
// Run Optimized?
5454
let optimized = if field == ContractArtifactField::AssemblyOptimized {
55-
true
55+
Some(true)
5656
} else {
5757
build.compiler.optimize
5858
};

0 commit comments

Comments
 (0)