-
Notifications
You must be signed in to change notification settings - Fork 24
Add default values to compiler arguments #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
1eafd43
2fc4142
c52b86e
684cf2a
44bf48b
facccaa
8d21c30
5973fe4
2fca5a7
7a5997b
4a40b69
2ab6cee
390bc31
b91666c
ef17928
c0ee80f
ea4ba87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,10 +4,13 @@ | |
| use std::path::Path; | ||
| use std::path::PathBuf; | ||
|
|
||
| use clap::Parser; | ||
| use clap::{command, parser::ValueSource, ArgMatches, CommandFactory, Parser}; | ||
|
Check failure on line 7 in crates/resolc/src/resolc/arguments.rs
|
||
| use path_slash::PathExt; | ||
| use resolc::SolcCompiler; | ||
|
Check failure on line 9 in crates/resolc/src/resolc/arguments.rs
|
||
| use revive_common::MetadataHash; | ||
| use revive_solc_json_interface::SolcStandardJsonOutputError; | ||
| use revive_solc_json_interface::{ | ||
| PolkaVMDefaultHeapMemorySize, PolkaVMDefaultStackMemorySize, SolcStandardJsonOutputError, | ||
| }; | ||
|
|
||
| /// Compiles the provided Solidity input files (or use the standard input if no files | ||
| /// are given or "-" is specified as a file name). Outputs the components based on the | ||
|
|
@@ -57,8 +60,8 @@ | |
|
|
||
| /// Set the optimization parameter -O[0 | 1 | 2 | 3 | s | z]. | ||
| /// Use `3` for best performance and `z` for minimal size. | ||
| #[arg(short = 'O', long = "optimization")] | ||
| pub optimization: Option<char>, | ||
| #[arg(short = 'O', long = "optimization", default_value = "z")] | ||
| pub optimization: char, | ||
|
|
||
| /// Disable the `solc` optimizer. | ||
| /// Use it if your project uses the `MSIZE` instruction, or in other cases. | ||
|
|
@@ -69,8 +72,8 @@ | |
| /// Specify the path to the `solc` executable. By default, the one in `${PATH}` is used. | ||
| /// Yul mode: `solc` is used for source code validation, as `resolc` itself assumes that the input Yul is valid. | ||
| /// LLVM IR mode: `solc` is unused. | ||
| #[arg(long = "solc")] | ||
| pub solc: Option<String>, | ||
| #[arg(long = "solc", default_value = SolcCompiler::DEFAULT_EXECUTABLE_NAME)] | ||
| pub solc: String, | ||
|
|
||
| /// The EVM target version to generate IR for. | ||
| /// See https://github.com/paritytech/revive/blob/main/crates/common/src/evm_version.rs for reference. | ||
|
|
@@ -116,9 +119,8 @@ | |
|
|
||
| /// Set the metadata hash type. | ||
| /// Available types: `none`, `ipfs`, `keccak256`. | ||
| /// The default is `keccak256`. | ||
| #[arg(long)] | ||
| pub metadata_hash: Option<String>, | ||
| #[arg(long, default_value_t = MetadataHash::Keccak256)] | ||
| pub metadata_hash: MetadataHash, | ||
|
|
||
| /// Output PolkaVM assembly of the contracts. | ||
| #[arg(long = "asm")] | ||
|
|
@@ -185,9 +187,9 @@ | |
| /// You are incentiviced to keep this value as small as possible: | ||
| /// 1.Increasing the heap size will increase startup costs. | ||
| /// 2.The heap size contributes to the total memory size a contract can use, | ||
| /// which includes the contracts code size | ||
| #[arg(long = "heap-size")] | ||
| pub heap_size: Option<u32>, | ||
| /// which includes the contracts code size. | ||
| #[arg(long = "heap-size", default_value_t = PolkaVMDefaultHeapMemorySize)] | ||
| pub heap_size: u32, | ||
|
|
||
| /// The contracts total stack size in bytes. | ||
| /// | ||
|
|
@@ -198,16 +200,17 @@ | |
| /// eventually revert execution at runtime! | ||
| /// | ||
| /// You are incentiviced to keep this value as small as possible: | ||
| /// 1.Increasing the heap size will increase startup costs. | ||
| /// 1.Increasing the stack size will increase startup costs. | ||
| /// 2.The stack size contributes to the total memory size a contract can use, | ||
| /// which includes the contracts code size | ||
| #[arg(long = "stack-size")] | ||
| pub stack_size: Option<u32>, | ||
| /// which includes the contracts code size. | ||
| #[arg(long = "stack-size", default_value_t = PolkaVMDefaultStackMemorySize)] | ||
| pub stack_size: u32, | ||
| } | ||
|
|
||
| impl Arguments { | ||
| /// Validates the arguments. | ||
| pub fn validate(&self) -> Vec<SolcStandardJsonOutputError> { | ||
| let argument_matches = Arguments::command().get_matches(); | ||
| let mut messages = Vec::new(); | ||
|
|
||
| if self.version && std::env::args().count() > 2 { | ||
|
|
@@ -226,9 +229,13 @@ | |
| )); | ||
| } | ||
|
|
||
| if self.metadata_hash == Some(MetadataHash::IPFS.to_string()) { | ||
| if self.metadata_hash == MetadataHash::IPFS { | ||
| messages.push(SolcStandardJsonOutputError::new_error( | ||
| "`IPFS` metadata hash type is not supported. Please use `keccak256` instead.", | ||
| format!( | ||
| "`{}` metadata hash type is not supported. Please use `{}` instead.", | ||
| MetadataHash::IPFS, | ||
| MetadataHash::Keccak256, | ||
| ), | ||
| None, | ||
| None, | ||
| )); | ||
|
|
@@ -350,34 +357,34 @@ | |
| } | ||
| if self.disable_solc_optimizer { | ||
| messages.push(SolcStandardJsonOutputError::new_error( | ||
| "Disabling the solc optimizer must specified in standard JSON input settings.", | ||
| "Disabling the solc optimizer must be specified in standard JSON input settings.", | ||
| None, | ||
| None, | ||
| )); | ||
| } | ||
| if self.optimization.is_some() { | ||
| if !Self::came_from_default_value("optimization", &argument_matches) { | ||
| messages.push(SolcStandardJsonOutputError::new_error( | ||
| "LLVM optimizations must specified in standard JSON input settings.", | ||
| "LLVM optimizations must be specified in standard JSON input settings.", | ||
| None, | ||
| None, | ||
| )); | ||
| } | ||
| if self.metadata_hash.is_some() { | ||
| if !Self::came_from_default_value("metadata_hash", &argument_matches) { | ||
| messages.push(SolcStandardJsonOutputError::new_error( | ||
| "Metadata hash mode must specified in standard JSON input settings.", | ||
| "Metadata hash mode must be specified in standard JSON input settings.", | ||
| None, | ||
| None, | ||
| )); | ||
| } | ||
|
|
||
| if self.heap_size.is_some() { | ||
| if !Self::came_from_default_value("heap_size", &argument_matches) { | ||
| messages.push(SolcStandardJsonOutputError::new_error( | ||
| "Heap size must be specified in standard JSON input polkavm memory settings.", | ||
| None, | ||
| None, | ||
| )); | ||
| } | ||
| if self.stack_size.is_some() { | ||
| if !Self::came_from_default_value("stack_size", &argument_matches) { | ||
| messages.push(SolcStandardJsonOutputError::new_error( | ||
| "Stack size must be specified in standard JSON input polkavm memory settings.", | ||
| None, | ||
|
|
@@ -403,6 +410,19 @@ | |
| messages | ||
| } | ||
|
|
||
| /// Checks whether the value from the argument with the given `argument_id` | ||
| /// came from the preconfigured default value. | ||
| /// | ||
| /// This can be used for determining if a user has explicitly set a value for | ||
elle-j marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// an argument, even if it is the same value as the default one. | ||
| /// | ||
| /// Panics if the `id` is not a valid argument id. | ||
| fn came_from_default_value(argument_id: &str, argument_matches: &ArgMatches) -> bool { | ||
elle-j marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| argument_matches | ||
| .value_source(argument_id) | ||
| .is_some_and(|source| source == ValueSource::DefaultValue) | ||
| } | ||
|
||
|
|
||
| /// Returns remappings from input paths. | ||
| pub fn split_input_files_and_remappings( | ||
| &self, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.