Skip to content

Commit 73cfc8b

Browse files
committed
For non-MSVC, separate flags/options from the input file. (#513)
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.
1 parent 7859697 commit 73cfc8b

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,9 @@ impl Build {
11711171
if !msvc || !is_asm || !is_arm {
11721172
cmd.arg("-c");
11731173
}
1174+
if !msvc || compiler.family == (ToolFamily::Msvc { clang_cl: true }) {
1175+
cmd.arg("--"); // #513: For non-MSVC, separate flags/options from the input file.
1176+
}
11741177
cmd.arg(&obj.src);
11751178

11761179
run(&mut cmd, &name)?;

tests/support/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ impl Execution {
151151
};
152152
self
153153
}
154+
155+
pub fn must_end_with<P: AsRef<OsStr>>(&self, p: &[P]) -> &Execution {
156+
let expected = p.iter().map(|x| x.as_ref()).collect::<Vec<_>>();
157+
if !self.args.iter().map(|x| OsStr::new(x)).collect::<Vec<_>>().as_slice().ends_with(expected.as_slice()) {
158+
panic!("did not end with {:?}", expected);
159+
} else {
160+
self
161+
}
162+
}
154163
}
155164

156165
/// Hard link an executable or copy it if that fails.

tests/test.rs

+16
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,14 @@ fn gnu_static() {
343343
test.cmd(0).must_have("-static").must_not_have("-shared");
344344
}
345345

346+
#[test]
347+
fn gnu_dash_dash() {
348+
let test = Test::gnu();
349+
test.gcc().file("foo.c").compile("foo");
350+
351+
test.cmd(0).must_end_with(&["--", "foo.c"]);
352+
}
353+
346354
#[test]
347355
fn msvc_smoke() {
348356
reset_env();
@@ -411,3 +419,11 @@ fn msvc_no_static_crt() {
411419

412420
test.cmd(0).must_have("-MD");
413421
}
422+
423+
#[test]
424+
fn msvc_no_dash_dash() {
425+
let test = Test::msvc();
426+
test.gcc().file("foo.c").compile("foo");
427+
428+
test.cmd(0).must_not_have("--");
429+
}

0 commit comments

Comments
 (0)