Skip to content

Commit

Permalink
For non-MSVC, separate flags/options from the input file. (#513)
Browse files Browse the repository at this point in the history
This avoids a `clang-cl` issue common when cross-compiling from macOS
to Windows: the `-Wslash-u-filename` where a `/Users/...` path is
interpreted as the `cl.exe` flag `/U`.

In general it's somewhere between harmless and good form to separate
flags/options from input files, so `--` is used for all compilers save
MSVC.

There are no existing tests mocking out `clang-cl` and surface efforts
didn't succeed, so that will have to wait for follow-up.
  • Loading branch information
ncalexan committed Jun 9, 2020
1 parent 7859697 commit 73cfc8b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib.rs
Expand Up @@ -1171,6 +1171,9 @@ impl Build {
if !msvc || !is_asm || !is_arm {
cmd.arg("-c");
}
if !msvc || compiler.family == (ToolFamily::Msvc { clang_cl: true }) {
cmd.arg("--"); // #513: For non-MSVC, separate flags/options from the input file.
}
cmd.arg(&obj.src);

run(&mut cmd, &name)?;
Expand Down
9 changes: 9 additions & 0 deletions tests/support/mod.rs
Expand Up @@ -151,6 +151,15 @@ impl Execution {
};
self
}

pub fn must_end_with<P: AsRef<OsStr>>(&self, p: &[P]) -> &Execution {
let expected = p.iter().map(|x| x.as_ref()).collect::<Vec<_>>();
if !self.args.iter().map(|x| OsStr::new(x)).collect::<Vec<_>>().as_slice().ends_with(expected.as_slice()) {
panic!("did not end with {:?}", expected);
} else {
self
}
}
}

/// Hard link an executable or copy it if that fails.
Expand Down
16 changes: 16 additions & 0 deletions tests/test.rs
Expand Up @@ -343,6 +343,14 @@ fn gnu_static() {
test.cmd(0).must_have("-static").must_not_have("-shared");
}

#[test]
fn gnu_dash_dash() {
let test = Test::gnu();
test.gcc().file("foo.c").compile("foo");

test.cmd(0).must_end_with(&["--", "foo.c"]);
}

#[test]
fn msvc_smoke() {
reset_env();
Expand Down Expand Up @@ -411,3 +419,11 @@ fn msvc_no_static_crt() {

test.cmd(0).must_have("-MD");
}

#[test]
fn msvc_no_dash_dash() {
let test = Test::msvc();
test.gcc().file("foo.c").compile("foo");

test.cmd(0).must_not_have("--");
}

0 comments on commit 73cfc8b

Please sign in to comment.