diff --git a/pkgs/development/compilers/llvm/common/default.nix b/pkgs/development/compilers/llvm/common/default.nix index 227f8db5f652..c56a8fee1476 100644 --- a/pkgs/development/compilers/llvm/common/default.nix +++ b/pkgs/development/compilers/llvm/common/default.nix @@ -515,7 +515,17 @@ let # we need to reintroduce `outputSpecified` to get the expected behavior e.g. of lib.get* llvm = tools.libllvm; - tblgen = callPackage ./tblgen.nix { }; + tblgen = callPackage ./tblgen.nix { + patches = builtins.filter + # Crude method to drop polly patches if present, they're not needed for tblgen. + (p: (!lib.hasInfix "-polly" p)) tools.libllvm.patches; + clangPatches = [ + # Would take tools.libclang.patches, but this introduces a cycle due + # to replacements depending on the llvm outpath (e.g. the LLVMgold patch). + # So take the only patch known to be necessary. + (metadata.getVersionFile "clang/gnu-install-dirs.patch") + ]; + }; libclang = callPackage ./clang { patches = diff --git a/pkgs/development/compilers/llvm/common/tblgen.nix b/pkgs/development/compilers/llvm/common/tblgen.nix index fe213e00b847..49cbcb0af2ca 100644 --- a/pkgs/development/compilers/llvm/common/tblgen.nix +++ b/pkgs/development/compilers/llvm/common/tblgen.nix @@ -12,6 +12,7 @@ src ? null, stdenv, version, + clangPatches, }: let @@ -60,6 +61,17 @@ let src = src'; sourceRoot = "${src.name}/llvm"; + postPatch = '' + ( + cd ../clang + chmod u+rwX -R . + for p in ${toString clangPatches} + do + patch -p1 < $p + done + ) + ''; + nativeBuildInputs = [ cmake ninja @@ -69,12 +81,16 @@ let cmakeFlags = [ # Projects with tablegen-like tools. "-DLLVM_ENABLE_PROJECTS=${ - lib.concatStringsSep ";" [ - "llvm" - "clang" - "clang-tools-extra" - "mlir" - ] + lib.concatStringsSep ";" ( + [ + "llvm" + "clang" + "clang-tools-extra" + ] + ++ lib.optionals (lib.versionAtLeast release_version "16") [ + "mlir" + ] + ) }" ] ++ devExtraCmakeFlags; @@ -82,13 +98,19 @@ let ninjaFlags = [ "clang-tblgen" - "clang-tidy-confusable-chars-gen" "llvm-tblgen" + ] + ++ lib.optionals (lib.versionAtLeast release_version "15") [ + "clang-tidy-confusable-chars-gen" + ] + ++ lib.optionals (lib.versionAtLeast release_version "16") [ "mlir-tblgen" ] - ++ lib.optionals (lib.versionOlder release_version "20") [ - "clang-pseudo-gen" # Removed in LLVM 20 @ ed8f78827895050442f544edef2933a60d4a7935. - ]; + ++ + lib.optionals ((lib.versionAtLeast release_version "15") && (lib.versionOlder release_version "20")) + [ + "clang-pseudo-gen" # Removed in LLVM 20 @ ed8f78827895050442f544edef2933a60d4a7935. + ]; installPhase = '' mkdir -p $out