Skip to content

Commit 8dc663e

Browse files
pccalyssais
authored andcommitted
llvmPackages.clang: embed resource directory in Clang libraries
When Clang is statically linked against other programs they are unable to find the headers in Clang's resource directory. Typically the resource directory is found by searching a path relative to argv[0] but this would only really work for Clang itself due to each binary having a separate prefix (and not in Nix because of the full resource directory being split between multiple derivations and assembled in the wrapper). Because users of Clang as a library typically only need include in order for parsing to succeed, let's set that as the resource directory. The LLVM patch to make this work was sent upstream in llvm/llvm-project#145996, I intend to land it upstream and drop it from this PR.
1 parent c4b9e31 commit 8dc663e

File tree

1 file changed

+9
-3
lines changed
  • pkgs/development/compilers/llvm/common/clang

1 file changed

+9
-3
lines changed

pkgs/development/compilers/llvm/common/clang/default.nix

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ stdenv.mkDerivation (
158158
(lib.cmakeFeature "LLVM_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/llvm-tblgen")
159159
(lib.cmakeFeature "CLANG_TABLEGEN" "${buildLlvmTools.tblgen}/bin/clang-tblgen")
160160
]
161+
++ lib.optionals (lib.versionAtLeast release_version "21") [
162+
(lib.cmakeFeature "CLANG_RESOURCE_DIR" "${placeholder "lib"}/lib/clang/${lib.versions.major release_version}")
163+
]
161164
++ lib.optionals (lib.versionAtLeast release_version "17") [
162165
(lib.cmakeBool "LLVM_INCLUDE_TESTS" false)
163166
]
@@ -211,9 +214,12 @@ stdenv.mkDerivation (
211214
mkdir -p $lib/lib/clang
212215
mv $lib/lib/17 $lib/lib/clang/17
213216
'')
214-
+ (lib.optionalString (lib.versionAtLeast release_version "19") ''
215-
mv $out/lib/clang $lib/lib/clang
216-
'')
217+
+ (lib.optionalString
218+
((lib.versionAtLeast release_version "19") && !(lib.versionAtLeast release_version "21"))
219+
''
220+
mv $out/lib/clang $lib/lib/clang
221+
''
222+
)
217223
+ ''
218224
219225
# Move libclang to 'lib' output

0 commit comments

Comments
 (0)