Skip to content

Commit a5f0c87

Browse files
committed
Add PVM heap-size and stack-size configuration for resolc
1 parent 89ccd72 commit a5f0c87

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

crates/compiler/src/revive_resolc.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ struct ResolcInner {
4242
solc: Solc,
4343
/// Path to the `resolc` executable
4444
resolc_path: PathBuf,
45+
/// The PVM heap size in bytes.
46+
pvm_heap_size: u32,
47+
/// The PVM stack size in bytes.
48+
pvm_stack_size: u32,
4549
}
4650

4751
impl Resolc {
@@ -68,26 +72,32 @@ impl Resolc {
6872
Self(Arc::new(ResolcInner {
6973
solc,
7074
resolc_path: resolc_configuration.path.clone(),
75+
pvm_heap_size: resolc_configuration
76+
.heap_size
77+
.unwrap_or(PolkaVMDefaultHeapMemorySize),
78+
pvm_stack_size: resolc_configuration
79+
.stack_size
80+
.unwrap_or(PolkaVMDefaultStackMemorySize),
7181
}))
7282
})
7383
.clone())
7484
}
7585

76-
fn polkavm_settings() -> SolcStandardJsonInputSettingsPolkaVM {
86+
fn polkavm_settings(&self) -> SolcStandardJsonInputSettingsPolkaVM {
7787
SolcStandardJsonInputSettingsPolkaVM::new(
7888
Some(SolcStandardJsonInputSettingsPolkaVMMemory::new(
79-
Some(PolkaVMDefaultHeapMemorySize),
80-
Some(PolkaVMDefaultStackMemorySize),
89+
Some(self.0.pvm_heap_size),
90+
Some(self.0.pvm_stack_size),
8191
)),
8292
false,
8393
)
8494
}
8595

86-
fn inject_polkavm_settings(input: &SolcStandardJsonInput) -> Result<serde_json::Value> {
87-
let mut input_value = serde_json::to_value(&input)
96+
fn inject_polkavm_settings(&self, input: &SolcStandardJsonInput) -> Result<serde_json::Value> {
97+
let mut input_value = serde_json::to_value(input)
8898
.context("Failed to serialize Standard JSON input for resolc")?;
8999
if let Some(settings) = input_value.get_mut("settings") {
90-
settings["polkavm"] = serde_json::to_value(&Self::polkavm_settings()).unwrap();
100+
settings["polkavm"] = serde_json::to_value(self.polkavm_settings()).unwrap();
91101
}
92102
Ok(input_value)
93103
}
@@ -171,13 +181,13 @@ impl SolidityCompiler for Resolc {
171181
Optimizer::default_mode(),
172182
Details::disabled(&Version::new(0, 0, 0)),
173183
),
174-
polkavm: Self::polkavm_settings(),
184+
polkavm: self.polkavm_settings(),
175185
metadata: SolcStandardJsonInputSettingsMetadata::default(),
176186
detect_missing_libraries: false,
177187
},
178188
};
179189
// Manually inject polkavm settings since it's marked skip_serializing in the upstream crate
180-
let std_input_json = Self::inject_polkavm_settings(&input)?;
190+
let std_input_json = self.inject_polkavm_settings(&input)?;
181191

182192
Span::current().record(
183193
"json_in",

crates/config/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,17 @@ pub struct ResolcConfiguration {
800800
/// provided in the user's $PATH.
801801
#[clap(id = "resolc.path", long = "resolc.path", default_value = "resolc")]
802802
pub path: PathBuf,
803+
804+
/// Specifies the PVM heap size in bytes.
805+
///
806+
/// If unspecified, the revive compiler default is used
807+
#[clap(id = "resolc.heap-size", long = "resolc.heap-size")]
808+
pub heap_size: Option<u32>,
809+
/// Specifies the PVM stack size in bytes.
810+
///
811+
/// If unspecified, the revive compiler default is used
812+
#[clap(id = "resolc.stack-size", long = "resolc.stack-size")]
813+
pub stack_size: Option<u32>,
803814
}
804815

805816
/// A set of configuration parameters for Polkadot Parachain.

0 commit comments

Comments
 (0)