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

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.

>From cc96b54798cb83de488076599e5e9df4ac64b94f Mon Sep 17 00:00:00 2001
From: Duncan Ogilvie <mr.exodia.tp...@gmail.com>
Date: Fri, 26 Jul 2024 17:05:45 +0200
Subject: [PATCH] [clangd] support the zig c++ compiler wrapper

---
 clang-tools-extra/clangd/SystemIncludeExtractor.cpp | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

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

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to