Skip to content
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

fix: clang-cl detect warning on MacOS #1446

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

LinusChen-yf
Copy link

src/tool.rs Outdated
@@ -199,21 +199,12 @@ impl Tool {
compiler_detect_output.warnings = compiler_detect_output.debug;

let stdout = run_output(
Command::new(path).arg("-E").arg(tmp.path()),
Command::new(path).arg("-E").arg("--").arg(tmp.path()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I remember that there are some compiler that doesn't work with --

I think it's better to detect the clang-cl and use -- for it?

cc @madsmtm

Copy link
Collaborator

Choose a reason for hiding this comment

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

I recall that too, see also discussion in #1328.

I feel like we're shooting ourselves in the foot here by not having better CI for this sort of stuff? At the very least, I'd expect a test to be added that doesn't work before the PR, and works after.

Comment on lines +204 to +206
let is_clang_cl = path
.file_name()
.map_or(false, |name| name.to_string_lossy().contains("clang-cl"));
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants