From 940b97b615cfd21eae6ba9ba492c835c9846960a Mon Sep 17 00:00:00 2001 From: xgreenx Date: Mon, 29 Nov 2021 14:24:16 +0200 Subject: [PATCH 1/2] Added `workspace` section to override parent `workspace` --- src/cmd/build.rs | 5 ++++- src/workspace/manifest.rs | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 0d32be54c..b173b9467 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -234,6 +234,8 @@ impl CheckCommand { /// Preferred default `[profile.release]` settings will be added if they are missing, existing /// user-defined settings will be preserved. /// +/// The `[workspace]` will be added if it is missing to ignore `workspace` from parent `Cargo.toml`. +/// /// To disable this and use the original `Cargo.toml` as is then pass the `-Z original_manifest` flag. fn exec_cargo_for_wasm_target( crate_metadata: &CrateMetadata, @@ -289,7 +291,8 @@ fn exec_cargo_for_wasm_target( .with_root_package_manifest(|manifest| { manifest .with_removed_crate_type("rlib")? - .with_profile_release_defaults(Profile::default_contract_release())?; + .with_profile_release_defaults(Profile::default_contract_release())? + .with_workspace()?; Ok(()) })? .using_temp(cargo_build)?; diff --git a/src/workspace/manifest.rs b/src/workspace/manifest.rs index 24f47c036..52a960898 100644 --- a/src/workspace/manifest.rs +++ b/src/workspace/manifest.rs @@ -283,6 +283,17 @@ impl Manifest { Ok(self) } + /// Set empty `[workspace]` section if it is not exist + /// + /// It allows ignore `workspace` from parent `Cargo.toml`. + /// It can reduce the size of the contract in some cases. + pub fn with_workspace(&mut self) -> Result<&mut Self> { + if let toml::map::Entry::Vacant(value) = self.toml.entry("workspace") { + value.insert(value::Value::Table(Default::default())); + } + Ok(self) + } + /// Get mutable reference to `[profile.release]` section fn get_profile_release_table_mut(&mut self) -> Result<&mut value::Table> { let profile = self From cd5a944b47d8b5a4cf3abad0d3b24020f1f49cb7 Mon Sep 17 00:00:00 2001 From: GreenBaneling | Supercolony Date: Mon, 29 Nov 2021 15:27:26 +0200 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Andrew Jones --- src/workspace/manifest.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/workspace/manifest.rs b/src/workspace/manifest.rs index 52a960898..ad0f02ca9 100644 --- a/src/workspace/manifest.rs +++ b/src/workspace/manifest.rs @@ -283,10 +283,10 @@ impl Manifest { Ok(self) } - /// Set empty `[workspace]` section if it is not exist + /// Set empty `[workspace]` section if it does not exist. /// - /// It allows ignore `workspace` from parent `Cargo.toml`. - /// It can reduce the size of the contract in some cases. + /// Ignores the `workspace` from the parent `Cargo.toml`. + /// This can reduce the size of the contract in some cases. pub fn with_workspace(&mut self) -> Result<&mut Self> { if let toml::map::Entry::Vacant(value) = self.toml.entry("workspace") { value.insert(value::Value::Table(Default::default()));