-
Notifications
You must be signed in to change notification settings - Fork 504
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
base: main
Are you sure you want to change the base?
Conversation
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()), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
let is_clang_cl = path | ||
.file_name() | ||
.map_or(false, |name| name.to_string_lossy().contains("clang-cl")); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With clang-cl the same warning about -Wslash-u-filename
is still generated. The difference with normal clang is that the warning is output to stderr and the exit code is set to 1. Both things can be captured and checked for, allowing for a check without relying on the filename.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using clang-cl, you only need to add the parameter "--" before Path to avoid generating warnings, which is also the recommended way to deal with warnings.
In addition, is the reason why this PR has no follow-up now because there are not enough test cases in CI to ensure the safety of its code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, detecting clang-cl via filename isn't very robust
#1445