Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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