Skip to content

Commit d88322b

Browse files
authored
Merge pull request #71 from rust-osdev/embed-bitcode
Set `-Clinker-plugin-lto` for the sysroot build
2 parents 379de94 + 26b945f commit d88322b

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## Unreleased
77

8+
- Set `-Clinker-plugin-lto` for the sysroot build ([#71](https://github.com/rust-osdev/cargo-xbuild/pull/71))
9+
- Second try to fix missing bitcode error for LTO builds (see [#69](https://github.com/rust-osdev/cargo-xbuild/issues/69))
10+
- Reverts "Enable lto for sysroot build to fix missing bitcode error ([#70](https://github.com/rust-osdev/cargo-xbuild/pull/70))"
11+
812
## 0.5.30 - 2020-05-11
913

1014
- Enable lto for sysroot build to fix missing bitcode error ([#70](https://github.com/rust-osdev/cargo-xbuild/pull/70))

src/cargo.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ pub fn config() -> Result<Option<Config>> {
194194
}
195195
}
196196

197-
pub struct Profile {
198-
table: Value,
197+
pub struct Profile<'t> {
198+
table: &'t Value,
199199
}
200200

201-
impl Profile {
201+
impl<'t> Profile<'t> {
202202
pub fn hash<H>(&self, hasher: &mut H)
203203
where
204204
H: Hasher,
@@ -218,13 +218,9 @@ impl Profile {
218218

219219
v.to_string().hash(hasher);
220220
}
221-
222-
pub fn set_lto(&mut self) {
223-
self.table.as_table_mut().expect("[profile.release] not a table").insert("lto".into(), Value::Boolean(true));
224-
}
225221
}
226222

227-
impl fmt::Display for Profile {
223+
impl<'t> fmt::Display for Profile<'t> {
228224
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
229225
let mut map = toml::map::Map::new();
230226
map.insert("profile".to_owned(), {
@@ -247,7 +243,7 @@ impl Toml {
247243
self.table
248244
.get("profile")
249245
.and_then(|v| v.get("release"))
250-
.map(|t| Profile { table: t.clone() })
246+
.map(|t| Profile { table: t })
251247
}
252248
}
253249

src/sysroot.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,8 @@ fn build_crate(
7474

7575
let target_dir = td.join("target");
7676

77-
if let Some(mut profile) = ctoml.profile() {
78-
profile.set_lto();
77+
if let Some(profile) = ctoml.profile() {
7978
stoml.push_str(&profile.to_string())
80-
} else {
81-
stoml.push_str("[profile.release]\nlto = true");
8279
}
8380

8481
util::write(&td.join("Cargo.toml"), &stoml)?;
@@ -87,7 +84,7 @@ fn build_crate(
8784

8885
let cargo = std::env::var("CARGO").unwrap_or("cargo".to_string());
8986
let mut cmd = Command::new(cargo);
90-
cmd.env_remove("RUSTFLAGS");
87+
cmd.env("RUSTFLAGS", "-Clinker-plugin-lto");
9188
cmd.env("CARGO_TARGET_DIR", &target_dir);
9289
cmd.env("__CARGO_DEFAULT_LIB_METADATA", "XARGO");
9390

0 commit comments

Comments
 (0)