From 4468df28ac0a2a3feb3557856267861eb9fb2bf7 Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Tue, 9 Jun 2020 14:03:02 -0700 Subject: [PATCH] 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. --- src/lib.rs | 7 +++++++ tests/test.rs | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 9abcc4915..53bf1486a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1171,6 +1171,13 @@ impl Build { if !msvc || !is_asm || !is_arm { cmd.arg("-c"); } + if compiler.family == (ToolFamily::Msvc { clang_cl: true }) { + // #513: For `clang-cl`, separate flags/options from the input file. + // When cross-compiling macOS -> Windows, this avoids interpreting + // common `/Users/...` paths as the `/U` flag and triggering + // `-Wslash-u-filename` warning. + cmd.arg("--"); + } cmd.arg(&obj.src); run(&mut cmd, &name)?; diff --git a/tests/test.rs b/tests/test.rs index 3c9b4dc49..35ef87577 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -343,6 +343,14 @@ fn gnu_static() { test.cmd(0).must_have("-static").must_not_have("-shared"); } +#[test] +fn gnu_no_dash_dash() { + let test = Test::gnu(); + test.gcc().file("foo.c").compile("foo"); + + test.cmd(0).must_not_have("--"); +} + #[test] fn msvc_smoke() { reset_env(); @@ -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("--"); +}