Skip to content

Commit

Permalink
Enable lto for sysroot build to fix missing bitcode error (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-opp committed May 11, 2020
1 parent 10287ff commit 5eb0bc2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 9 additions & 5 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<'t> {
table: &'t Value,
pub struct Profile {
table: Value,
}

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

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

0 comments on commit 5eb0bc2

Please sign in to comment.