Skip to content

Commit

Permalink
Fix LTO regressions in nightly toolchain (#52)
Browse files Browse the repository at this point in the history
* Upgrade cargo-xbuild to include LTO fix

* Bump version

* Update CHANGELOG

* Disable lto for metadata generation, enable for contract build

* Fmt

* Update changelog
  • Loading branch information
ascjones authored May 12, 2020
1 parent 25b7234 commit 285a049
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Version 0.6.1 (2020-05-12)

- Fix LTO regressions in nightly toolchain [#52](https://github.com/paritytech/cargo-contract/pull/52)

# Version 0.6.0 (2020-03-25)

- First release to crates.io
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-contract"
version = "0.6.0"
version = "0.6.1"
authors = ["Parity Technologies <admin@parity.io>"]
build = "build.rs"
edition = "2018"
Expand Down Expand Up @@ -29,7 +29,7 @@ codec = { package = "parity-scale-codec", version = "1.2" }
which = "3.1.0"
colored = "1.9"
toml = "0.5.4"
cargo-xbuild = "0.5.26"
cargo-xbuild = "0.5.31"
rustc_version = "0.2.3"
serde_json = "1.0"
tempfile = "3.1.0"
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ fn build_cargo_project(crate_metadata: &CrateMetadata, verbosity: Option<Verbosi

Workspace::new(&crate_metadata.cargo_meta, &crate_metadata.root_package.id)?
.with_root_package_manifest(|manifest| {
manifest.with_removed_crate_type("rlib")?;
manifest
.with_removed_crate_type("rlib")?
.with_profile_release_lto(true)?;
Ok(())
})?
.using_temp(xbuild)?;
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ pub(crate) fn execute_generate_metadata(

Workspace::new(&metadata, &root_package_id)?
.with_root_package_manifest(|manifest| {
manifest.with_added_crate_type("rlib")?;
manifest
.with_added_crate_type("rlib")?
.with_profile_release_lto(false)?;
Ok(())
})?
.using_temp(generate_metadata)?;
Expand Down
20 changes: 20 additions & 0 deletions src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,26 @@ impl Manifest {
Ok(self)
}

/// Set `[profile.release]` lto flag
pub fn with_profile_release_lto(&mut self, enabled: bool) -> Result<&mut Self> {
let profile = self
.toml
.entry("profile")
.or_insert(value::Value::Table(Default::default()));
let release = profile
.as_table_mut()
.ok_or(anyhow::anyhow!("profile should be a table"))?
.entry("release")
.or_insert(value::Value::Table(Default::default()));
let lto = release
.as_table_mut()
.ok_or(anyhow::anyhow!("release should be a table"))?
.entry("lto")
.or_insert(enabled.into());
*lto = enabled.into();
Ok(self)
}

/// Remove a value from the `[lib] crate-types = []` section
///
/// If the value does not exist, does nothing.
Expand Down

0 comments on commit 285a049

Please sign in to comment.