Skip to content

Commit

Permalink
Added workspace section to override parent workspace (#378)
Browse files Browse the repository at this point in the history
* Added `workspace` section to override parent `workspace`

* Apply suggestions from code review

Co-authored-by: Andrew Jones <ascjones@hey.com>

Co-authored-by: Andrew Jones <ascjones@hey.com>
  • Loading branch information
xgreenx and ascjones authored Nov 29, 2021
1 parent d4a1181 commit c2a513c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)?;
Expand Down
11 changes: 11 additions & 0 deletions src/workspace/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c2a513c

Please sign in to comment.