Skip to content

Commit 2e917e7

Browse files
committed
Use -- delimiter for any clang-like compiler
to disambiguous path from arguments. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
1 parent 3fe0e09 commit 2e917e7

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,10 @@ impl Build {
725725
},
726726
);
727727

728+
if compiler.supports_path_delimiter() {
729+
cmd.arg("--");
730+
}
731+
728732
cmd.arg(&src);
729733

730734
// On MSVC skip the CRT by setting the entry point to `main`.
@@ -1795,14 +1799,16 @@ impl Build {
17951799
if is_asm {
17961800
cmd.args(self.asm_flags.iter().map(std::ops::Deref::deref));
17971801
}
1798-
if compiler.family == (ToolFamily::Msvc { clang_cl: true }) && !is_assembler_msvc {
1802+
1803+
if compiler.supports_path_delimiter() && !is_assembler_msvc {
17991804
// #513: For `clang-cl`, separate flags/options from the input file.
18001805
// When cross-compiling macOS -> Windows, this avoids interpreting
18011806
// common `/Users/...` paths as the `/U` flag and triggering
18021807
// `-Wslash-u-filename` warning.
18031808
cmd.arg("--");
18041809
}
18051810
cmd.arg(&obj.src);
1811+
18061812
if cfg!(target_os = "macos") {
18071813
self.fix_env_for_apple_os(&mut cmd)?;
18081814
}

src/tool.rs

+8
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,14 @@ impl Tool {
420420
pub fn is_like_msvc(&self) -> bool {
421421
matches!(self.family, ToolFamily::Msvc { .. })
422422
}
423+
424+
/// Supports using `--` delimiter to separate arguments and path to source files.
425+
pub(crate) fn supports_path_delimiter(&self) -> bool {
426+
matches!(
427+
self.family,
428+
ToolFamily::Clang { .. } | ToolFamily::Msvc { clang_cl: true }
429+
)
430+
}
423431
}
424432

425433
/// Represents the family of tools this tool belongs to.

0 commit comments

Comments
 (0)