Skip to content

fix: clang-cl detect warning on MacOS #1446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,22 @@ impl Tool {
let mut compiler_detect_output = cargo_output.clone();
compiler_detect_output.warnings = compiler_detect_output.debug;

let stdout = run_output(
Command::new(path).arg("-E").arg(tmp.path()),
&compiler_detect_output,
)?;
let stdout = String::from_utf8_lossy(&stdout);

if stdout.contains("-Wslash-u-filename") {
let stdout = run_output(
Command::new(path).arg("-E").arg("--").arg(tmp.path()),
&compiler_detect_output,
)?;
let stdout = String::from_utf8_lossy(&stdout);
guess_family_from_stdout(&stdout, path, args, cargo_output)
let mut detect_cmd = Command::new(path);
// If it is clang-cl, use -- to separate the path
// to prevent confusion between the path and the parameter.
let is_clang_cl = path
.file_name()
.map_or(false, |name| name.to_string_lossy().contains("clang-cl"));
Comment on lines +204 to +206
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this will work for many cases, checking filename isn't very robust...

@madsmtm does clang-cl --version offer anything special that we can check here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# On Windows
> clang-cl --version
clang version 20.1.2
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Users\crash\scoop\apps\llvm\20.1.2\bin

# On MacOS
> clang-cl --version
Homebrew clang version 19.1.7
Target: arm64-pc-windows-msvc
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/llvm/19.1.7_1/bin

# On Linux
> clang-cl --version
clang version 19.1.7
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: /usr/bin

It seems that the output of clang-cl --version is not a very reliable way to determine whether it is clang-cl?

Because I saw the logic of using the file name to judge clang-cl in the original code, I referred to this part of the code.

cc-rs/src/tool.rs

Lines 242 to 244 in 5f55b01

match path.file_name().map(OsStr::to_string_lossy) {
Some(fname) if fname.contains("clang-cl") => ToolFamily::Msvc { clang_cl: true },
Some(fname) if fname.ends_with("cl") || fname == "cl.exe" => {

Or maybe it would be safer to use full characters to match clang-cl or clang-cl.exe?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, in that case I think it might be the only solution, cc @madsmtm wdyt

if is_clang_cl {
detect_cmd.arg("-E").arg("--").arg(tmp.path());
} else {
guess_family_from_stdout(&stdout, path, args, cargo_output)
detect_cmd.arg("-E").arg(tmp.path());
}

let stdout = run_output(&mut detect_cmd, &compiler_detect_output)?;
let stdout = String::from_utf8_lossy(&stdout);

guess_family_from_stdout(&stdout, path, args, cargo_output)
}
let detect_family = |path: &Path, args: &[String]| -> Result<ToolFamily, Error> {
let cache_key = [path.as_os_str()]
Expand Down
Loading