Skip to content

Commit

Permalink
Fix CARGO_CFG_ vars for configs defined both with and without value
Browse files Browse the repository at this point in the history
When a rustc cfg is defined both with and without value, the
environment variable should provide all the values. Before this change,
it ended up being empty.

Fixes: #11789
  • Loading branch information
vadorovsky committed Mar 2, 2023
1 parent c61b0f0 commit 566a2c5
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,11 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
for cfg in bcx.target_data.cfg(unit.kind) {
match *cfg {
Cfg::Name(ref n) => {
cfg_map.insert(n.clone(), None);
cfg_map.insert(n.clone(), Vec::new());
}
Cfg::KeyPair(ref k, ref v) => {
if let Some(ref mut values) =
*cfg_map.entry(k.clone()).or_insert_with(|| Some(Vec::new()))
{
values.push(v.clone())
}
let values = cfg_map.entry(k.clone()).or_insert_with(|| Vec::new());
values.push(v.clone());
}
}
}
Expand All @@ -249,14 +246,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
continue;
}
let k = format!("CARGO_CFG_{}", super::envify(&k));
match v {
Some(list) => {
cmd.env(&k, list.join(","));
}
None => {
cmd.env(&k, "");
}
}
cmd.env(&k, v.join(","));
}

// Also inform the build script of the rustc compiler context.
Expand Down

0 comments on commit 566a2c5

Please sign in to comment.