[clang-tools-extra] [clangd] support the zig c++ compiler wrapper (PR #100759)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 26 08:11:54 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-tools-extra

Author: Duncan Ogilvie (mrexodia)

<details>
<summary>Changes</summary>

When using `zig c++` for cross-compiling `clangd` removes the zig command from the command line. Because of this the system include extraction fails. This change detects that the driver executable is named `zig` and adds `cc` or `c++` 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.

---
Full diff: https://github.com/llvm/llvm-project/pull/100759.diff


1 Files Affected:

- (modified) clang-tools-extra/clangd/SystemIncludeExtractor.cpp (+11-1) 


``````````diff
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("-");

``````````

</details>


https://github.com/llvm/llvm-project/pull/100759


More information about the cfe-commits mailing list