From 5eb0bc255af54b7cb48d43d68e7e4c7f86cf6f59 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 11 May 2020 19:40:07 +0200 Subject: [PATCH] Enable lto for sysroot build to fix missing bitcode error (#70) --- src/cargo.rs | 14 +++++++++----- src/sysroot.rs | 5 ++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/cargo.rs b/src/cargo.rs index 5a6b6e0..0d7be14 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -194,11 +194,11 @@ pub fn config() -> Result> { } } -pub struct Profile<'t> { - table: &'t Value, +pub struct Profile { + table: Value, } -impl<'t> Profile<'t> { +impl Profile { pub fn hash(&self, hasher: &mut H) where H: Hasher, @@ -218,9 +218,13 @@ impl<'t> Profile<'t> { 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<'t> fmt::Display for Profile<'t> { +impl fmt::Display for Profile { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut map = toml::map::Map::new(); map.insert("profile".to_owned(), { @@ -243,7 +247,7 @@ impl Toml { self.table .get("profile") .and_then(|v| v.get("release")) - .map(|t| Profile { table: t }) + .map(|t| Profile { table: t.clone() }) } } diff --git a/src/sysroot.rs b/src/sysroot.rs index e33c628..02f7b94 100644 --- a/src/sysroot.rs +++ b/src/sysroot.rs @@ -74,8 +74,11 @@ fn build_crate( let target_dir = td.join("target"); - if let Some(profile) = ctoml.profile() { + if let Some(mut profile) = ctoml.profile() { + profile.set_lto(); stoml.push_str(&profile.to_string()) + } else { + stoml.push_str("[profile.release]\nlto = true"); } util::write(&td.join("Cargo.toml"), &stoml)?;