Skip to content

when cross-compiling, look for RUSTFLAGS_HOST for rustc flags of build scripts #4428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 5 additions & 4 deletions src/cargo/ops/cargo_rustc/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,15 +1066,16 @@ fn env_args(config: &Config,
let compiling_with_target = build_config.requested_target.is_some();
let is_target_kind = kind == Kind::Target;

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

// First try RUSTFLAGS from the environment
if let Ok(a) = env::var(name) {
if let Ok(a) = env::var(&name[..]) {
let args = a.split(' ')
.map(str::trim)
.filter(|s| !s.is_empty())
Expand Down
17 changes: 9 additions & 8 deletions tests/cross-compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,31 +611,32 @@ fn build_script_needed_for_host_and_target() {
pub fn d2() { d1::d1(); }
");

assert_that(p.cargo_process("build").arg("--target").arg(&target).arg("-v"),
assert_that(p.cargo_process("build").arg("--target").arg(&target).arg("-v")
.env("RUSTFLAGS", "--cap-lints=forbid").env("RUSTFLAGS_HOST", "--cap-lints=warn"),
execs().with_status(0)
.with_stderr_contains(&format!("\
[COMPILING] d1 v0.0.0 ({url}/d1)", url = p.url()))
.with_stderr_contains(&format!("\
[RUNNING] `rustc [..] d1[/]build.rs [..] --out-dir {dir}[/]target[/]debug[/]build[/]d1-[..]`",
dir = p.root().display()))
[RUNNING] `rustc [..] d1[/]build.rs [..] --out-dir {dir}[/]target[/]debug[/]build[/]d1-[..] \
--cap-lints=warn`", dir = p.root().display()))
.with_stderr_contains(&format!("\
[RUNNING] `{dir}[/]target[/]debug[/]build[/]d1-[..][/]build-script-build`",
dir = p.root().display()))
dir = p.root().display()))
.with_stderr_contains("\
[RUNNING] `rustc [..] d1[/]src[/]lib.rs [..]`")
[RUNNING] `rustc [..] d1[/]src[/]lib.rs [..] --cap-lints=warn [..]`")
.with_stderr_contains(&format!("\
[COMPILING] d2 v0.0.0 ({url}/d2)", url = p.url()))
.with_stderr_contains(&format!("\
[RUNNING] `rustc [..] d2[/]src[/]lib.rs [..] \
[RUNNING] `rustc [..] d2[/]src[/]lib.rs [..] --cap-lints=warn \
-L /path/to/{host}`", host = host))
.with_stderr_contains(&format!("\
[COMPILING] foo v0.0.0 ({url})", url = p.url()))
.with_stderr_contains(&format!("\
[RUNNING] `rustc [..] build.rs [..] --out-dir {dir}[/]target[/]debug[/]build[/]foo-[..] \
-L /path/to/{host}`", dir = p.root().display(), host = host))
--cap-lints=warn -L /path/to/{host}`", dir = p.root().display(), host = host))
.with_stderr_contains(&format!("\
[RUNNING] `rustc [..] src[/]main.rs [..] --target {target} [..] \
-L /path/to/{target}`", target = target)));
--cap-lints=forbid -L /path/to/{target}`", target = target)));
}

#[test]
Expand Down