diff --git a/CHANGELOG.md b/CHANGELOG.md index c0b1022..0521398 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +- Set `-Clinker-plugin-lto` for the sysroot build ([#71](https://github.com/rust-osdev/cargo-xbuild/pull/71)) + - Second try to fix missing bitcode error for LTO builds (see [#69](https://github.com/rust-osdev/cargo-xbuild/issues/69)) + - Reverts "Enable lto for sysroot build to fix missing bitcode error ([#70](https://github.com/rust-osdev/cargo-xbuild/pull/70))" + ## 0.5.30 - 2020-05-11 - Enable lto for sysroot build to fix missing bitcode error ([#70](https://github.com/rust-osdev/cargo-xbuild/pull/70)) diff --git a/src/cargo.rs b/src/cargo.rs index 0d7be14..5a6b6e0 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -194,11 +194,11 @@ pub fn config() -> Result> { } } -pub struct Profile { - table: Value, +pub struct Profile<'t> { + table: &'t Value, } -impl Profile { +impl<'t> Profile<'t> { pub fn hash(&self, hasher: &mut H) where H: Hasher, @@ -218,13 +218,9 @@ impl Profile { v.to_string().hash(hasher); } - - pub fn set_lto(&mut self) { - self.table.as_table_mut().expect("[profile.release] not a table").insert("lto".into(), Value::Boolean(true)); - } } -impl fmt::Display for Profile { +impl<'t> fmt::Display for Profile<'t> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut map = toml::map::Map::new(); map.insert("profile".to_owned(), { @@ -247,7 +243,7 @@ impl Toml { self.table .get("profile") .and_then(|v| v.get("release")) - .map(|t| Profile { table: t.clone() }) + .map(|t| Profile { table: t }) } } diff --git a/src/sysroot.rs b/src/sysroot.rs index 02f7b94..24786dc 100644 --- a/src/sysroot.rs +++ b/src/sysroot.rs @@ -74,11 +74,8 @@ fn build_crate( let target_dir = td.join("target"); - if let Some(mut profile) = ctoml.profile() { - profile.set_lto(); + if let Some(profile) = ctoml.profile() { stoml.push_str(&profile.to_string()) - } else { - stoml.push_str("[profile.release]\nlto = true"); } util::write(&td.join("Cargo.toml"), &stoml)?; @@ -87,7 +84,7 @@ fn build_crate( let cargo = std::env::var("CARGO").unwrap_or("cargo".to_string()); let mut cmd = Command::new(cargo); - cmd.env_remove("RUSTFLAGS"); + cmd.env("RUSTFLAGS", "-Clinker-plugin-lto"); cmd.env("CARGO_TARGET_DIR", &target_dir); cmd.env("__CARGO_DEFAULT_LIB_METADATA", "XARGO");