Skip to content

Commit cb11d37

Browse files
authored
Fix the resolc config option propagation (#135)
1 parent 0675b25 commit cb11d37

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub struct CompilerOpts {
5959
pub extra_output_files: Vec<ContractOutputSelection>,
6060

6161
/// Compiler settings for resolc.
62-
#[clap(flatten)]
62+
#[command(flatten)]
6363
#[serde(skip)]
6464
pub resolc_opts: ResolcOpts,
6565
}

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use serde::Serialize;
55
#[clap(next_help_heading = "Resolc configuration")]
66
/// Compiler options for resolc
77
pub struct ResolcOpts {
8-
#[clap(
8+
#[arg(
99
value_name = "RESOLC_COMPILE",
1010
help = "Enable compiling with resolc",
1111
long = "resolc-compile",
1212
visible_alias = "resolc",
13-
action = clap::ArgAction::SetTrue,
13+
action = clap::ArgAction::SetTrue
1414
)]
1515
pub resolc_compile: Option<bool>,
1616

@@ -29,7 +29,7 @@ pub struct ResolcOpts {
2929

3030
/// Set the LLVM optimization parameter `-O[0 | 1 | 2 | 3 | s | z]`.
3131
/// Use `3` for best performance and `z` for minimal size.
32-
#[clap(
32+
#[arg(
3333
short = 'O',
3434
long = "resolc-optimizer-mode",
3535
help = "Set the resolc optimization mode `-O[0 | 1 | 2 | 3 | s | z]`",
@@ -40,12 +40,12 @@ pub struct ResolcOpts {
4040
pub optimizer_mode: Option<String>,
4141

4242
/// The emulated EVM linear heap memory static buffer size in bytes.
43-
#[clap(long = "heap-size", help = "Set the contracts heap size in bytes", value_name = "SIZE")]
43+
#[arg(long = "heap-size", help = "Set the contracts heap size in bytes", value_name = "SIZE")]
4444
#[serde(skip_serializing_if = "Option::is_none")]
4545
pub heap_size: Option<u32>,
4646

4747
/// The contracts total stack size in bytes.
48-
#[clap(
48+
#[arg(
4949
long = "stack-size",
5050
help = "Set the contracts total stack size in bytes",
5151
value_name = "SIZE"
@@ -64,12 +64,14 @@ impl ResolcOpts {
6464
};
6565
}
6666

67+
set_if_some!(
68+
self.resolc_compile.and_then(|v| if v { Some(true) } else { None }),
69+
resolc.resolc_compile
70+
);
6771
set_if_some!(
6872
self.use_resolc.as_ref().map(|v| SolcReq::from(v.trim_start_matches("resolc:"))),
6973
resolc.resolc
7074
);
71-
72-
set_if_some!(self.resolc_compile, resolc.resolc_compile);
7375
set_if_some!(
7476
self.optimizer_mode.as_ref().and_then(|mode| mode.parse::<char>().ok()),
7577
resolc.optimizer_mode

crates/forge/tests/cli/revive_config.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,33 @@ Error: `resolc` this/resolc/does/not/exist does not exist
4646
4747
"#]]);
4848
});
49+
50+
// checks that we can set various config values
51+
forgetest_init!(can_set_resolc_config_values, |prj, _cmd| {
52+
let config = prj.config_from_output(["--resolc", "--resolc-optimization", "z"]);
53+
assert!(config.resolc.resolc_compile);
54+
assert_eq!(config.resolc.optimizer_mode, Some('z'));
55+
});
56+
57+
// tests that resolc can be explicitly enabled
58+
forgetest!(enable_resolc_explicitly, |prj, cmd| {
59+
prj.add_source(
60+
"Foo",
61+
r"
62+
pragma solidity *;
63+
contract Greeter {}
64+
",
65+
)
66+
.unwrap();
67+
68+
prj.update_config(|config| {
69+
config.resolc.resolc_compile = true;
70+
});
71+
72+
cmd.arg("build").assert_success().stdout_eq(str![[r#"
73+
[COMPILING_FILES] with [RESOLC_VERSION]
74+
[RESOLC_VERSION] [ELAPSED]
75+
Compiler run successful!
76+
77+
"#]]);
78+
});

0 commit comments

Comments
 (0)