Skip to content

Commit

Permalink
Merge pull request #71 from rust-osdev/embed-bitcode
Browse files Browse the repository at this point in the history
Set `-Clinker-plugin-lto` for the sysroot build
  • Loading branch information
phil-opp committed May 12, 2020
2 parents 379de94 + 26b945f commit d88322b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
14 changes: 5 additions & 9 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ pub fn config() -> Result<Option<Config>> {
}
}

pub struct Profile {
table: Value,
pub struct Profile<'t> {
table: &'t Value,
}

impl Profile {
impl<'t> Profile<'t> {
pub fn hash<H>(&self, hasher: &mut H)
where
H: Hasher,
Expand All @@ -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(), {
Expand All @@ -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 })
}
}

Expand Down
7 changes: 2 additions & 5 deletions src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -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");

Expand Down

0 comments on commit d88322b

Please sign in to comment.