Skip to content

Commit

Permalink
Added libraries arg for linking external contract libraries (gakonst#313
Browse files Browse the repository at this point in the history
)

* added libraries arg for linking external contract libraries

* typo in error; more concise nested map building and add support for collisions on f

* more descriptive var names

* added libraries arg for linking external contract libraries

* typo in error; more concise nested map building and add support for collisions on f

* chore: cargo fmt / clippy

* chore: bump ethers

Co-authored-by: Georgios Konstantopoulos <[email protected]>
  • Loading branch information
hexonaut and gakonst authored Dec 26, 2021
1 parent 1560b71 commit 23ca482
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
25 changes: 13 additions & 12 deletions Cargo.lock

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

22 changes: 20 additions & 2 deletions cli/src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use ethers::{
types::Address,
};
use std::{
collections::BTreeMap,
path::{Path, PathBuf},
str::FromStr,
};
Expand Down Expand Up @@ -77,6 +78,9 @@ pub struct BuildArgs {
alias = "hh"
)]
pub hardhat: bool,

#[structopt(help = "add linked libraries", long)]
pub libraries: Vec<String>,
}

impl Cmd for BuildArgs {
Expand Down Expand Up @@ -217,9 +221,23 @@ impl BuildArgs {
let optimizer =
Optimizer { enabled: Some(self.optimize), runs: Some(self.optimize_runs as usize) };

// unflatten the libraries
let mut libraries = BTreeMap::default();
for l in self.libraries.iter() {
let mut items = l.split(':');
let file = String::from(items.next().expect("could not parse libraries"));
let lib = String::from(items.next().expect("could not parse libraries"));
let addr = String::from(items.next().expect("could not parse libraries"));
libraries.entry(file).or_insert_with(BTreeMap::default).insert(lib, addr);
}

// build the project w/ allowed paths = root and all the libs
let solc_settings =
Settings { optimizer, evm_version: Some(self.evm_version), ..Default::default() };
let solc_settings = Settings {
optimizer,
evm_version: Some(self.evm_version),
libraries,
..Default::default()
};
let mut builder = Project::builder()
.paths(paths)
.allowed_path(&root)
Expand Down

0 comments on commit 23ca482

Please sign in to comment.