about summary refs log tree commit diff
path: root/pkgs/development/compilers/swift/compiler/patches/swift-linux-fix-libc-paths.patch
blob: 02cdeb368bb7af16dcd3565e16c7889a090133eb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
This code injects an LLVM modulemap for glibc and libstdc++ by overriding
specific VFS paths. In order to do that, it needs to know the actual locations
of glibc and libstdc++, but it only searches `-sysroot` and fails. Here we
patch it to also consider `-idirafter` and `-isystem` as added by cc-wrapper.

--- a/lib/ClangImporter/ClangIncludePaths.cpp
+++ b/lib/ClangImporter/ClangIncludePaths.cpp
@@ -120,6 +120,7 @@ static clang::driver::Driver createClangDriver(const ASTContext &ctx) {
 /// \return a path without dots (`../`, './').
 static llvm::Optional<Path>
 findFirstIncludeDir(const llvm::opt::InputArgList &args,
+                    const llvm::opt::ArgList &DriverArgs,
                     const ArrayRef<const char *> expectedFileNames) {
   // C++ stdlib paths are added as `-internal-isystem`.
   std::vector<std::string> includeDirs =
@@ -128,6 +129,14 @@ findFirstIncludeDir(const llvm::opt::InputArgList &args,
   llvm::append_range(includeDirs,
                      args.getAllArgValues(
                          clang::driver::options::OPT_internal_externc_isystem));
+  // Nix adds the C stdlib include path using `-idirafter`.
+  llvm::append_range(includeDirs,
+                     DriverArgs.getAllArgValues(
+                         clang::driver::options::OPT_idirafter));
+  // Nix adds the C++ stdlib include path using `-isystem`.
+  llvm::append_range(includeDirs,
+                     DriverArgs.getAllArgValues(
+                         clang::driver::options::OPT_isystem));
 
   for (const auto &includeDir : includeDirs) {
     Path dir(includeDir);
@@ -193,7 +202,7 @@ getGlibcFileMapping(ASTContext &ctx) {
   // Ideally we would check that all of the headers referenced from the
   // modulemap are present.
   Path glibcDir;
-  if (auto dir = findFirstIncludeDir(parsedIncludeArgs,
+  if (auto dir = findFirstIncludeDir(parsedIncludeArgs, clangDriverArgs,
                                      {"inttypes.h", "unistd.h", "stdint.h"})) {
     glibcDir = dir.value();
   } else {
@@ -251,7 +260,7 @@ getLibStdCxxFileMapping(ASTContext &ctx) {
   auto parsedStdlibArgs = parseClangDriverArgs(clangDriver, stdlibArgStrings);
 
   Path cxxStdlibDir;
-  if (auto dir = findFirstIncludeDir(parsedStdlibArgs,
+  if (auto dir = findFirstIncludeDir(parsedStdlibArgs, clangDriverArgs,
                                      {"cstdlib", "string", "vector"})) {
     cxxStdlibDir = dir.value();
   } else {