From 8dc663ea1895309d910e008cbf5076910b6e9dc6 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Thu, 26 Jun 2025 15:54:58 -0700 Subject: [PATCH] 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. --- .../compilers/llvm/common/clang/default.nix | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkgs/development/compilers/llvm/common/clang/default.nix b/pkgs/development/compilers/llvm/common/clang/default.nix index 03e8aaec9b54..f671bf370aa5 100644 --- a/pkgs/development/compilers/llvm/common/clang/default.nix +++ b/pkgs/development/compilers/llvm/common/clang/default.nix @@ -158,6 +158,9 @@ stdenv.mkDerivation ( (lib.cmakeFeature "LLVM_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/llvm-tblgen") (lib.cmakeFeature "CLANG_TABLEGEN" "${buildLlvmTools.tblgen}/bin/clang-tblgen") ] + ++ lib.optionals (lib.versionAtLeast release_version "21") [ + (lib.cmakeFeature "CLANG_RESOURCE_DIR" "${placeholder "lib"}/lib/clang/${lib.versions.major release_version}") + ] ++ lib.optionals (lib.versionAtLeast release_version "17") [ (lib.cmakeBool "LLVM_INCLUDE_TESTS" false) ] @@ -211,9 +214,12 @@ stdenv.mkDerivation ( mkdir -p $lib/lib/clang mv $lib/lib/17 $lib/lib/clang/17 '') - + (lib.optionalString (lib.versionAtLeast release_version "19") '' - mv $out/lib/clang $lib/lib/clang - '') + + (lib.optionalString + ((lib.versionAtLeast release_version "19") && !(lib.versionAtLeast release_version "21")) + '' + mv $out/lib/clang $lib/lib/clang + '' + ) + '' # Move libclang to 'lib' output