From c2a513c8772fcd8729fc25128cee21401aedb6cd Mon Sep 17 00:00:00 2001 From: GreenBaneling | Supercolony Date: Mon, 29 Nov 2021 17:25:53 +0200 Subject: [PATCH] Added `workspace` section to override parent `workspace` (#378) * Added `workspace` section to override parent `workspace` * Apply suggestions from code review Co-authored-by: Andrew Jones Co-authored-by: Andrew Jones --- 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..ad0f02ca9 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 does not exist. + /// + /// 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())); + } + Ok(self) + } + /// Get mutable reference to `[profile.release]` section fn get_profile_release_table_mut(&mut self) -> Result<&mut value::Table> { let profile = self