Skip to content

Commit

Permalink
Use -- delimiter for any clang-like compiler
Browse files Browse the repository at this point in the history
to disambiguous path from arguments.

Signed-off-by: Jiahao XU <[email protected]>
  • Loading branch information
NobodyXu committed Jan 6, 2025
1 parent 3fe0e09 commit 2e917e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,10 @@ impl Build {
},
);

if compiler.supports_path_delimiter() {
cmd.arg("--");
}

cmd.arg(&src);

// On MSVC skip the CRT by setting the entry point to `main`.
Expand Down Expand Up @@ -1795,14 +1799,16 @@ impl Build {
if is_asm {
cmd.args(self.asm_flags.iter().map(std::ops::Deref::deref));
}
if compiler.family == (ToolFamily::Msvc { clang_cl: true }) && !is_assembler_msvc {

if compiler.supports_path_delimiter() && !is_assembler_msvc {
// #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);

if cfg!(target_os = "macos") {
self.fix_env_for_apple_os(&mut cmd)?;
}
Expand Down
8 changes: 8 additions & 0 deletions src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,14 @@ impl Tool {
pub fn is_like_msvc(&self) -> bool {
matches!(self.family, ToolFamily::Msvc { .. })
}

/// Supports using `--` delimiter to separate arguments and path to source files.
pub(crate) fn supports_path_delimiter(&self) -> bool {
matches!(
self.family,
ToolFamily::Clang { .. } | ToolFamily::Msvc { clang_cl: true }
)
}
}

/// Represents the family of tools this tool belongs to.
Expand Down

0 comments on commit 2e917e7

Please sign in to comment.