diff --git a/crates/compiler/src/revive_resolc.rs b/crates/compiler/src/revive_resolc.rs index fc8adca..5fc2b61 100644 --- a/crates/compiler/src/revive_resolc.rs +++ b/crates/compiler/src/revive_resolc.rs @@ -42,6 +42,10 @@ struct ResolcInner { solc: Solc, /// Path to the `resolc` executable resolc_path: PathBuf, + /// The PVM heap size in bytes. + pvm_heap_size: u32, + /// The PVM stack size in bytes. + pvm_stack_size: u32, } impl Resolc { @@ -68,26 +72,32 @@ impl Resolc { Self(Arc::new(ResolcInner { solc, resolc_path: resolc_configuration.path.clone(), + pvm_heap_size: resolc_configuration + .heap_size + .unwrap_or(PolkaVMDefaultHeapMemorySize), + pvm_stack_size: resolc_configuration + .stack_size + .unwrap_or(PolkaVMDefaultStackMemorySize), })) }) .clone()) } - fn polkavm_settings() -> SolcStandardJsonInputSettingsPolkaVM { + fn polkavm_settings(&self) -> SolcStandardJsonInputSettingsPolkaVM { SolcStandardJsonInputSettingsPolkaVM::new( Some(SolcStandardJsonInputSettingsPolkaVMMemory::new( - Some(PolkaVMDefaultHeapMemorySize), - Some(PolkaVMDefaultStackMemorySize), + Some(self.0.pvm_heap_size), + Some(self.0.pvm_stack_size), )), false, ) } - fn inject_polkavm_settings(input: &SolcStandardJsonInput) -> Result { - let mut input_value = serde_json::to_value(&input) + fn inject_polkavm_settings(&self, input: &SolcStandardJsonInput) -> Result { + let mut input_value = serde_json::to_value(input) .context("Failed to serialize Standard JSON input for resolc")?; if let Some(settings) = input_value.get_mut("settings") { - settings["polkavm"] = serde_json::to_value(&Self::polkavm_settings()).unwrap(); + settings["polkavm"] = serde_json::to_value(self.polkavm_settings()).unwrap(); } Ok(input_value) } @@ -171,13 +181,13 @@ impl SolidityCompiler for Resolc { Optimizer::default_mode(), Details::disabled(&Version::new(0, 0, 0)), ), - polkavm: Self::polkavm_settings(), + polkavm: self.polkavm_settings(), metadata: SolcStandardJsonInputSettingsMetadata::default(), detect_missing_libraries: false, }, }; // Manually inject polkavm settings since it's marked skip_serializing in the upstream crate - let std_input_json = Self::inject_polkavm_settings(&input)?; + let std_input_json = self.inject_polkavm_settings(&input)?; Span::current().record( "json_in", diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index be8838c..a1e40b0 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -800,6 +800,17 @@ pub struct ResolcConfiguration { /// provided in the user's $PATH. #[clap(id = "resolc.path", long = "resolc.path", default_value = "resolc")] pub path: PathBuf, + + /// Specifies the PVM heap size in bytes. + /// + /// If unspecified, the revive compiler default is used + #[clap(id = "resolc.heap-size", long = "resolc.heap-size")] + pub heap_size: Option, + /// Specifies the PVM stack size in bytes. + /// + /// If unspecified, the revive compiler default is used + #[clap(id = "resolc.stack-size", long = "resolc.stack-size")] + pub stack_size: Option, } /// A set of configuration parameters for Polkadot Parachain.