nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1This code injects an LLVM modulemap for glibc and libstdc++ by overriding
2specific VFS paths. In order to do that, it needs to know the actual locations
3of glibc and libstdc++, but it only searches `-sysroot` and fails. Here we
4patch it to also consider `-idirafter` and `-isystem` as added by cc-wrapper.
5
6--- a/lib/ClangImporter/ClangIncludePaths.cpp
7+++ b/lib/ClangImporter/ClangIncludePaths.cpp
8@@ -142,6 +142,7 @@
9 /// \return a path without dots (`../`, './').
10 static llvm::Optional<Path> findFirstIncludeDir(
11 const llvm::opt::InputArgList &args,
12+ const llvm::opt::ArgList &DriverArgs,
13 const ArrayRef<const char *> expectedFileNames,
14 const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs) {
15 // C++ stdlib paths are added as `-internal-isystem`.
16@@ -151,6 +152,14 @@
17 llvm::append_range(includeDirs,
18 args.getAllArgValues(
19 clang::driver::options::OPT_internal_externc_isystem));
20+ // Nix adds the C stdlib include path using `-idirafter`.
21+ llvm::append_range(includeDirs,
22+ DriverArgs.getAllArgValues(
23+ clang::driver::options::OPT_idirafter));
24+ // Nix adds the C++ stdlib include path using `-isystem`.
25+ llvm::append_range(includeDirs,
26+ DriverArgs.getAllArgValues(
27+ clang::driver::options::OPT_isystem));
28
29 for (const auto &includeDir : includeDirs) {
30 Path dir(includeDir);
31@@ -218,7 +227,7 @@
32 // modulemap are present.
33 Path glibcDir;
34 if (auto dir = findFirstIncludeDir(
35- parsedIncludeArgs, {"inttypes.h", "unistd.h", "stdint.h"}, vfs)) {
36+ parsedIncludeArgs, clangDriverArgs, {"inttypes.h", "unistd.h", "stdint.h"}, vfs)) {
37 glibcDir = dir.value();
38 } else {
39 ctx.Diags.diagnose(SourceLoc(), diag::glibc_not_found, triple.str());
40@@ -276,7 +285,7 @@
41 auto parsedStdlibArgs = parseClangDriverArgs(clangDriver, stdlibArgStrings);
42
43 Path cxxStdlibDir;
44- if (auto dir = findFirstIncludeDir(parsedStdlibArgs,
45+ if (auto dir = findFirstIncludeDir(parsedStdlibArgs, clangDriverArgs,
46 {"cstdlib", "string", "vector"}, vfs)) {
47 cxxStdlibDir = dir.value();
48 } else {