Skip to content

Commit

Permalink
feat/forge: add extra output types to config and CompilerArgs on build (
Browse files Browse the repository at this point in the history
gakonst#644)

* add extra output types to config and CompilerArgs

* change default output selection instead of building one

* lint

* fix help on --extra-output

* bump ethers
  • Loading branch information
joshieDo authored Jan 31, 2022
1 parent 568534d commit 16b20da
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions cli/src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ impl Provider for BuildArgs {
dict.insert("optimizer".to_string(), self.compiler.optimize.into());
}

if let Some(extra) = &self.compiler.extra_output {
dict.insert("extra_output".to_string(), extra.clone().into());
}

Ok(Map::from([(Config::selected_profile(), dict)]))
}
}
7 changes: 7 additions & 0 deletions cli/src/opts/forge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ pub struct CompilerArgs {
#[clap(help = "optimizer parameter runs", long)]
#[serde(skip_serializing_if = "Option::is_none")]
pub optimize_runs: Option<usize>,

#[clap(
help = "extra output types [evm.assembly, ewasm, ir, irOptimized] eg: `--extra-output evm.assembly`",
long
)]
#[serde(skip_serializing_if = "Option::is_none")]
pub extra_output: Option<Vec<String>>,
}

/// Represents the common dapp argument pattern for `<path>:<contractname>` where `<path>:` is
Expand Down
24 changes: 23 additions & 1 deletion config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! foundry configuration.
use std::{
borrow::Cow,
collections::BTreeMap,
path::{Path, PathBuf},
};

Expand Down Expand Up @@ -140,6 +141,8 @@ pub struct Config {
pub block_difficulty: u64,
/// the `block.gaslimit` value during EVM execution
pub block_gas_limit: Option<u64>,
/// Pass extra output types
pub extra_output: Option<Vec<String>>,
/// Settings to pass to the `solc` compiler input
// TODO consider making this more structured https://stackoverflow.com/questions/48998034/does-toml-support-nested-arrays-of-objects-tables
// TODO this needs to work as extension to the defaults:
Expand Down Expand Up @@ -384,19 +387,37 @@ impl Config {
Optimizer { enabled: Some(self.optimizer), runs: Some(self.optimizer_runs) }
}

pub fn output_selection(&self) -> BTreeMap<String, BTreeMap<String, Vec<String>>> {
let mut output_selection = Settings::default_output_selection();

if let Some(extras) = &self.extra_output {
output_selection.entry("*".to_string()).and_modify(|e1| {
e1.entry("*".to_string()).and_modify(|e2| {
e2.extend_from_slice(extras.as_slice());
});
});
}

output_selection
}

/// Returns the configured `solc` `Settings` that includes:
/// - all libraries
/// - the optimizer
/// - evm version
pub fn solc_settings(&self) -> Result<Settings, SolcError> {
let libraries = parse_libraries(&self.libraries)?;
let optimizer = self.optimizer();
Ok(Settings {
let output_selection = self.output_selection();

Ok((Settings {
optimizer,
evm_version: Some(self.evm_version),
libraries,
output_selection,
..Default::default()
})
.with_ast())
}

/// Returns the default figment
Expand Down Expand Up @@ -645,6 +666,7 @@ impl Default for Config {
auto_detect_solc: true,
optimizer: true,
optimizer_runs: 200,
extra_output: None,
solc_settings: None,
fuzz_runs: 256,
ffi: false,
Expand Down

0 comments on commit 16b20da

Please sign in to comment.