Skip to content

Commit f1ae9f8

Browse files
committed
Fix PR comments
1 parent 8b744a0 commit f1ae9f8

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

src/cargo/ops/cargo_compile.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,12 @@ fn scrape_target_config(config: &Config, triple: &str)
709709
let list = value.list(&k)?;
710710
output.cfgs.extend(list.iter().map(|v| v.0.clone()));
711711
}
712+
"rustc-env" => {
713+
for (name, val) in value.table(&k)?.0 {
714+
let val = val.string(name)?.0;
715+
output.env.push((name.clone(), val.to_string()));
716+
}
717+
}
712718
"warning" | "rerun-if-changed" => {
713719
bail!("`{}` is not supported in build script overrides", k);
714720
}

src/cargo/ops/cargo_rustc/mod.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -428,17 +428,12 @@ fn rustc(cx: &mut Context, unit: &Unit, exec: Arc<Executor>) -> CargoResult<Work
428428
// been put there by one of the `build_scripts`) to the command provided.
429429
fn add_custom_env(rustc: &mut ProcessBuilder,
430430
build_state: &BuildMap,
431-
build_scripts: &BuildScripts,
431+
_: &BuildScripts,
432432
current_id: &PackageId) -> CargoResult<()> {
433-
for key in build_scripts.to_link.iter() {
434-
let output = build_state.get(key).chain_error(|| {
435-
internal(format!("couldn't find build state for {}/{:?}",
436-
key.0, key.1))
437-
})?;
438-
if key.0 == *current_id {
439-
for &(ref name, ref value) in output.env.iter() {
440-
rustc.env(name, value);
441-
}
433+
let key = (current_id.clone(), Kind::Host);
434+
if let Some(output) = build_state.get(&key) {
435+
for &(ref name, ref value) in output.env.iter() {
436+
rustc.env(name, value);
442437
}
443438
}
444439
Ok(())

tests/build-script.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,9 @@ fn env_build() {
15871587
"#)
15881588
.file("src/main.rs", r#"
15891589
const FOO: &'static str = env!("FOO");
1590-
fn main() {}
1590+
fn main() {
1591+
println!("{}", FOO);
1592+
}
15911593
"#)
15921594
.file("build.rs", r#"
15931595
fn main() {
@@ -1596,6 +1598,8 @@ fn env_build() {
15961598
"#);
15971599
assert_that(build.cargo_process("build").arg("-v"),
15981600
execs().with_status(0));
1601+
assert_that(build.cargo("run").arg("-v"),
1602+
execs().with_status(0).with_stdout("foo\n"));
15991603
}
16001604

16011605
#[test]

0 commit comments

Comments
 (0)