Skip to content

Commit

Permalink
Merge pull request #82 from eggyal/propagate-cargo-features
Browse files Browse the repository at this point in the history
Propagate `cargo-features` from project's Cargo.toml
  • Loading branch information
phil-opp authored Jun 9, 2020
2 parents a779803 + d395043 commit 09a0071
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,19 @@ impl<'t> fmt::Display for Profile<'t> {
}
}

pub struct Features<'a> {
array: &'a Value,
}

impl<'a> fmt::Display for Features<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut map = toml::map::Map::new();
map.insert("cargo-features".to_owned(), self.array.clone());

fmt::Display::fmt(&Value::Table(map), f)
}
}

pub struct Toml {
table: Value,
}
Expand All @@ -245,6 +258,12 @@ impl Toml {
.and_then(|v| v.get("release"))
.map(|t| Profile { table: t })
}

pub fn features(&self) -> Option<Features> {
self.table
.get("cargo-features")
.map(|a| Features { array: a })
}
}

pub fn toml(root: &Path) -> Result<Toml> {
Expand Down
4 changes: 4 additions & 0 deletions src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ fn build_crate(

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

if let Some(features) = ctoml.features() {
stoml.insert_str(0, &features.to_string())
}

if let Some(profile) = ctoml.profile() {
stoml.push_str(&profile.to_string())
}
Expand Down

0 comments on commit 09a0071

Please sign in to comment.