-
Notifications
You must be signed in to change notification settings - Fork 11.7k
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
[clangd] support the zig c++ compiler wrapper #100759
base: main
Are you sure you want to change the base?
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clangd @llvm/pr-subscribers-clang-tools-extra Author: Duncan Ogilvie (mrexodia) ChangesWhen using I don't think there is infrastructure to test this (since it would involve executing the Full diff: https://github.com/llvm/llvm-project/pull/100759.diff 1 Files Affected:
diff --git a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
index d4b9b173d149d..c01dbea9c0c12 100644
--- a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
+++ b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
@@ -389,7 +389,17 @@ extractSystemIncludesAndTarget(const DriverArgs &InputArgs,
return std::nullopt;
}
- llvm::SmallVector<llvm::StringRef> Args = {Driver, "-E", "-v"};
+ llvm::SmallVector<llvm::StringRef> Args = {Driver};
+ // Support the zig compiler wrapper
+ auto DriverExecutable = llvm::sys::path::stem(Driver);
+ if (DriverExecutable == "zig") {
+ if (InputArgs.Lang == "c") {
+ Args.push_back("cc");
+ } else {
+ Args.push_back("c++");
+ }
+ }
+ Args.append({"-E", "-v"});
Args.append(InputArgs.render());
// Input needs to go after Lang flags.
Args.push_back("-");
|
This is a simple and nice change. Improving the developer experience and having things "just work" is always good. |
@kazutakahirata @kadircet @sam-mccall it looks like you were recently touching this file, any chance for a review? |
Ping! |
When using
zig c++
for cross-compilingclangd
removes the zig command (c++
/cc
) from the command line. Because of this the system include extraction fails. This change detects that the driver executable is namedzig
and addscc
orc++
back into the command line.I don't think there is infrastructure to test this (since it would involve executing the
zig
executable), so I did not add any tests. Screenshot of the feature working on Visual Studio Code on Windows:Trivial example project that sets up the cross compilation with CMake and generates
compile_commands.json
: https://github.com/mrexodia/zig-cross. You also need to use--query-driver=**/zig.exe
.