Skip to content

Commit 4468df2

Browse files
committed
For clang-cl, separate flags/options from input file to avoid -Wslash-u-filename. (#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`. Not all compilers recognize `--` so this is limited to `clang-cl`. 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 4468df2

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,13 @@ impl Build {
11711171
if !msvc || !is_asm || !is_arm {
11721172
cmd.arg("-c");
11731173
}
1174+
if compiler.family == (ToolFamily::Msvc { clang_cl: true }) {
1175+
// #513: For `clang-cl`, separate flags/options from the input file.
1176+
// When cross-compiling macOS -> Windows, this avoids interpreting
1177+
// common `/Users/...` paths as the `/U` flag and triggering
1178+
// `-Wslash-u-filename` warning.
1179+
cmd.arg("--");
1180+
}
11741181
cmd.arg(&obj.src);
11751182

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

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_no_dash_dash() {
348+
let test = Test::gnu();
349+
test.gcc().file("foo.c").compile("foo");
350+
351+
test.cmd(0).must_not_have("--");
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)