Skip to content

Commit 5a62c4d

Browse files
committed
when cross-compiling, look for RUSTFLAGS_HOST for rustc flags of build scripts
1 parent a1489e8 commit 5a62c4d

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/cargo/ops/cargo_rustc/context.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1066,15 +1066,16 @@ fn env_args(config: &Config,
10661066
let compiling_with_target = build_config.requested_target.is_some();
10671067
let is_target_kind = kind == Kind::Target;
10681068

1069+
let mut name = name.to_owned();
10691070
if compiling_with_target && !is_target_kind {
10701071
// This is probably a build script or plugin and we're
1071-
// compiling with --target. In this scenario there are
1072-
// no rustflags we can apply.
1073-
return Ok(Vec::new());
1072+
// compiling with --target. In this scenario we apply the _HOST
1073+
// version of the flags.
1074+
name.push_str("_HOST");
10741075
}
10751076

10761077
// First try RUSTFLAGS from the environment
1077-
if let Ok(a) = env::var(name) {
1078+
if let Ok(a) = env::var(&name[..]) {
10781079
let args = a.split(' ')
10791080
.map(str::trim)
10801081
.filter(|s| !s.is_empty())

tests/cross-compile.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -611,31 +611,32 @@ fn build_script_needed_for_host_and_target() {
611611
pub fn d2() { d1::d1(); }
612612
");
613613

614-
assert_that(p.cargo_process("build").arg("--target").arg(&target).arg("-v"),
614+
assert_that(p.cargo_process("build").arg("--target").arg(&target).arg("-v")
615+
.env("RUSTFLAGS", "--cap-lints=forbid").env("RUSTFLAGS_HOST", "--cap-lints=warn"),
615616
execs().with_status(0)
616617
.with_stderr_contains(&format!("\
617618
[COMPILING] d1 v0.0.0 ({url}/d1)", url = p.url()))
618619
.with_stderr_contains(&format!("\
619-
[RUNNING] `rustc [..] d1[/]build.rs [..] --out-dir {dir}[/]target[/]debug[/]build[/]d1-[..]`",
620-
dir = p.root().display()))
620+
[RUNNING] `rustc [..] d1[/]build.rs [..] --out-dir {dir}[/]target[/]debug[/]build[/]d1-[..] \
621+
--cap-lints=warn`", dir = p.root().display()))
621622
.with_stderr_contains(&format!("\
622623
[RUNNING] `{dir}[/]target[/]debug[/]build[/]d1-[..][/]build-script-build`",
623-
dir = p.root().display()))
624+
dir = p.root().display()))
624625
.with_stderr_contains("\
625-
[RUNNING] `rustc [..] d1[/]src[/]lib.rs [..]`")
626+
[RUNNING] `rustc [..] d1[/]src[/]lib.rs [..] --cap-lints=warn [..]`")
626627
.with_stderr_contains(&format!("\
627628
[COMPILING] d2 v0.0.0 ({url}/d2)", url = p.url()))
628629
.with_stderr_contains(&format!("\
629-
[RUNNING] `rustc [..] d2[/]src[/]lib.rs [..] \
630+
[RUNNING] `rustc [..] d2[/]src[/]lib.rs [..] --cap-lints=warn \
630631
-L /path/to/{host}`", host = host))
631632
.with_stderr_contains(&format!("\
632633
[COMPILING] foo v0.0.0 ({url})", url = p.url()))
633634
.with_stderr_contains(&format!("\
634635
[RUNNING] `rustc [..] build.rs [..] --out-dir {dir}[/]target[/]debug[/]build[/]foo-[..] \
635-
-L /path/to/{host}`", dir = p.root().display(), host = host))
636+
--cap-lints=warn -L /path/to/{host}`", dir = p.root().display(), host = host))
636637
.with_stderr_contains(&format!("\
637638
[RUNNING] `rustc [..] src[/]main.rs [..] --target {target} [..] \
638-
-L /path/to/{target}`", target = target)));
639+
--cap-lints=forbid -L /path/to/{target}`", target = target)));
639640
}
640641

641642
#[test]

0 commit comments

Comments
 (0)