From a65abb57b2ee63470a9cf7c4fc98faeaaee8db53 Mon Sep 17 00:00:00 2001 From: Colin Roberts Date: Tue, 19 Sep 2023 12:01:38 +0200 Subject: [PATCH 1/3] add current serde version to binding dependencies --- ethers-contract/ethers-contract-abigen/src/multi.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ethers-contract/ethers-contract-abigen/src/multi.rs b/ethers-contract/ethers-contract-abigen/src/multi.rs index 08722463f..0b8be08f0 100644 --- a/ethers-contract/ethers-contract-abigen/src/multi.rs +++ b/ethers-contract/ethers-contract-abigen/src/multi.rs @@ -333,7 +333,12 @@ impl MultiExpansionResult { None }; - MultiBindingsInner { root, bindings, shared_types } + MultiBindingsInner { + root, + bindings, + shared_types, + dependencies: vec![String::from(r#"serde = "1.0.188""#)], + } } } @@ -581,6 +586,8 @@ struct MultiBindingsInner { bindings: BTreeMap, /// contains the content of the shared types if any shared_types: Option, + /// Dependencies other than `ethers-rs` to add to the `Cargo.toml` for bindings generated as a crate. + dependencies: Vec, } // deref allows for inspection without modification @@ -611,6 +618,9 @@ impl MultiBindingsInner { writeln!(toml)?; writeln!(toml, "[dependencies]")?; writeln!(toml, r#"{crate_version}"#)?; + for dependency in self.dependencies.clone() { + writeln!(toml, "{}", dependency)?; + } Ok(toml) } From af0321e7725ea1a2925d89fa2fb3e18551709767 Mon Sep 17 00:00:00 2001 From: Colin Roberts Date: Wed, 20 Sep 2023 15:59:37 -0600 Subject: [PATCH 2/3] feat: `MultiBindings::dependencies()` --- .../ethers-contract-abigen/src/multi.rs | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/ethers-contract/ethers-contract-abigen/src/multi.rs b/ethers-contract/ethers-contract-abigen/src/multi.rs index 0b8be08f0..0150661ad 100644 --- a/ethers-contract/ethers-contract-abigen/src/multi.rs +++ b/ethers-contract/ethers-contract-abigen/src/multi.rs @@ -144,7 +144,11 @@ impl MultiAbigen { /// Build the contract bindings and prepare for writing pub fn build(self) -> Result { let format = self.abigens.iter().any(|gen| gen.format); - Ok(MultiBindings { expansion: MultiExpansion::from_abigen(self.abigens)?.expand(), format }) + Ok(MultiBindings { + expansion: MultiExpansion::from_abigen(self.abigens)?.expand(), + format, + dependencies: vec![], + }) } } @@ -299,7 +303,12 @@ impl MultiExpansionResult { } /// Converts this result into [`MultiBindingsInner`] - fn into_bindings(mut self, single_file: bool, format: bool) -> MultiBindingsInner { + fn into_bindings( + mut self, + single_file: bool, + format: bool, + dependencies: Vec, + ) -> MultiBindingsInner { self.set_shared_import_path(single_file); let Self { contracts, shared_types, root, .. } = self; let bindings = contracts @@ -333,12 +342,7 @@ impl MultiExpansionResult { None }; - MultiBindingsInner { - root, - bindings, - shared_types, - dependencies: vec![String::from(r#"serde = "1.0.188""#)], - } + MultiBindingsInner { root, bindings, shared_types, dependencies } } } @@ -371,6 +375,7 @@ impl MultiExpansionResult { pub struct MultiBindings { expansion: MultiExpansionResult, format: bool, + dependencies: Vec, } impl MultiBindings { @@ -401,8 +406,19 @@ impl MultiBindings { self } + /// Specify a set of dependencies to use for the generated crate. + /// + /// By default, this is empty and only the `ethers` dependency is added. + pub fn dependencies( + mut self, + dependencies: impl IntoIterator>, + ) -> Self { + self.dependencies = dependencies.into_iter().map(|dep| dep.into()).collect(); + self + } + fn into_inner(self, single_file: bool) -> MultiBindingsInner { - self.expansion.into_bindings(single_file, self.format) + self.expansion.into_bindings(single_file, self.format, self.dependencies) } /// Generates all the bindings and writes them to the given module From fee65fd2c65dddbbd5178fa51b95e56a18e5bcee Mon Sep 17 00:00:00 2001 From: Colin Roberts Date: Wed, 4 Oct 2023 12:01:20 -0600 Subject: [PATCH 3/3] fix: fmt --- ethers-contract/ethers-contract-abigen/src/multi.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ethers-contract/ethers-contract-abigen/src/multi.rs b/ethers-contract/ethers-contract-abigen/src/multi.rs index 0150661ad..9b89b12b1 100644 --- a/ethers-contract/ethers-contract-abigen/src/multi.rs +++ b/ethers-contract/ethers-contract-abigen/src/multi.rs @@ -602,7 +602,8 @@ struct MultiBindingsInner { bindings: BTreeMap, /// contains the content of the shared types if any shared_types: Option, - /// Dependencies other than `ethers-rs` to add to the `Cargo.toml` for bindings generated as a crate. + /// Dependencies other than `ethers-rs` to add to the `Cargo.toml` for bindings generated as a + /// crate. dependencies: Vec, }