diff --git a/flake.nix b/flake.nix index a4d84b97..7b7198d9 100644 --- a/flake.nix +++ b/flake.nix @@ -5,15 +5,8 @@ outputs = { self, nixpkgs }: let - # We can't use overlays because llvm dependencies are handled internally in llvmPackages_xx - pkgs-orig = import nixpkgs { system = "x86_64-linux"; }; - nixpkgs-patched = pkgs-orig.applyPatches { - name = "nixpkgs"; - src = nixpkgs; - patches = [ ./llvm-future-riscv-abi.diff ./llvm-restrict-targets.diff ./llvm-mingw-crosscompile.diff ./llvm-unbreak-static-cross.diff ]; - }; - pkgs = import nixpkgs-patched { system = "x86_64-linux"; }; - pkgs-mingw = import nixpkgs-patched { system = "x86_64-linux"; crossSystem = { config = "x86_64-w64-mingw32"; libc = "msvcrt"; }; }; + pkgs = import nixpkgs { system = "x86_64-linux"; }; + pkgs-mingw = import nixpkgs { system = "x86_64-linux"; crossSystem = { config = "x86_64-w64-mingw32"; libc = "msvcrt"; }; }; cargoSha256 = "sha256-otKLhr58HYMjVXAof6AdObNpggPnvK6qOl7I+4LWIP8="; msys2-python-tar = pkgs.fetchurl { url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-python-3.9.7-4-any.pkg.tar.zst"; @@ -46,16 +39,15 @@ ''; }; in rec { - inherit nixpkgs-patched; - - packages.x86_64-linux = { + packages.x86_64-linux = rec { + llvm-nac3 = pkgs.callPackage "${self}/llvm" {}; nac3artiq = pkgs.python3Packages.toPythonModule ( pkgs.rustPlatform.buildRustPackage { name = "nac3artiq"; src = self; inherit cargoSha256; - nativeBuildInputs = [ pkgs.python3 pkgs.llvm_12 ]; - buildInputs = [ pkgs.python3 pkgs.libffi pkgs.libxml2 pkgs.llvm_12 ]; + nativeBuildInputs = [ pkgs.python3 llvm-nac3 ]; + buildInputs = [ pkgs.python3 pkgs.libffi pkgs.libxml2 llvm-nac3 ]; cargoBuildFlags = [ "--package" "nac3artiq" ]; cargoTestFlags = [ "--package" "nac3ast" "--package" "nac3parser" "--package" "nac3core" "--package" "nac3artiq" ]; installPhase = @@ -68,7 +60,8 @@ ); }; - packages.x86_64-w64-mingw32 = { + packages.x86_64-w64-mingw32 = rec { + llvm-nac3 = pkgs-mingw.callPackage "${self}/llvm" { inherit (pkgs) llvmPackages_12; }; nac3artiq = pkgs-mingw.python3Packages.toPythonModule ( pkgs-mingw.rustPlatform.buildRustPackage { name = "nac3artiq"; @@ -85,7 +78,7 @@ #!${pkgs.bash}/bin/bash set -e # Gross hack to work around llvm-config asking for the wrong system libraries. - exec ${pkgs-mingw.llvm_12.dev}/bin/llvm-config-native \$@ | ${pkgs.gnused}/bin/sed s/-lrt\ -ldl\ -lpthread\ -lm// + exec ${llvm-nac3.dev}/bin/llvm-config-native \$@ | ${pkgs.gnused}/bin/sed s/-lrt\ -ldl\ -lpthread\ -lm// EOF chmod +x llvm-cfg/llvm-config export PATH=$PATH:`pwd`/llvm-cfg @@ -110,7 +103,7 @@ devShell.x86_64-linux = pkgs.mkShell { name = "nac3-dev-shell"; buildInputs = with pkgs; [ - llvm_12 + packages.x86_64-linux.llvm-nac3 clang_12 lld_12 cargo diff --git a/llvm-future-riscv-abi.diff b/llvm-future-riscv-abi.diff deleted file mode 100644 index ffe9ecb2..00000000 --- a/llvm-future-riscv-abi.diff +++ /dev/null @@ -1,61 +0,0 @@ -commit 6e2dea56207b4e52ade9d1eee6a4f198336dd0a6 -Author: Sebastien Bourdeauducq -Date: Thu Nov 11 23:32:13 2021 +0800 - - llvm: switch RISC-V ABI when FPU is present - -diff --git a/pkgs/development/compilers/llvm/12/llvm/default.nix b/pkgs/development/compilers/llvm/12/llvm/default.nix -index 30a1a7a16df..41b7211b2a5 100644 ---- a/pkgs/development/compilers/llvm/12/llvm/default.nix -+++ b/pkgs/development/compilers/llvm/12/llvm/default.nix -@@ -66,6 +66,7 @@ in stdenv.mkDerivation (rec { - sha256 = "sha256:12s8vr6ibri8b48h2z38f3afhwam10arfiqfy4yg37bmc054p5hi"; - stripLen = 1; - }) -+ ./llvm-future-riscv-abi.diff - ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; - - postPatch = optionalString stdenv.isDarwin '' -@@ -183,7 +184,7 @@ in stdenv.mkDerivation (rec { - cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native - ''; - -- doCheck = stdenv.isLinux && (!stdenv.isx86_32) && (!stdenv.hostPlatform.isMusl); -+ doCheck = false; # the ABI change breaks RISC-V FP tests - - checkTarget = "check-all"; - -diff --git a/pkgs/development/compilers/llvm/12/llvm/llvm-future-riscv-abi.diff b/pkgs/development/compilers/llvm/12/llvm/llvm-future-riscv-abi.diff -new file mode 100644 -index 00000000000..2427ed0e02c ---- /dev/null -+++ b/pkgs/development/compilers/llvm/12/llvm/llvm-future-riscv-abi.diff -@@ -0,0 +1,28 @@ -+diff --git a/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp b/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp -+index 0aba18b20..9bb75e7f4 100644 -+--- a/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp -++++ b/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp -+@@ -33,6 +33,8 @@ ABI computeTargetABI(const Triple &TT, FeatureBitset FeatureBits, -+ auto TargetABI = getTargetABI(ABIName); -+ bool IsRV64 = TT.isArch64Bit(); -+ bool IsRV32E = FeatureBits[RISCV::FeatureRV32E]; -++ bool IsRV32D = FeatureBits[RISCV::FeatureStdExtD]; -++ bool IsRV32F = FeatureBits[RISCV::FeatureStdExtF]; -+ -+ if (!ABIName.empty() && TargetABI == ABI_Unknown) { -+ errs() -+@@ -56,10 +58,10 @@ ABI computeTargetABI(const Triple &TT, FeatureBitset FeatureBits, -+ if (TargetABI != ABI_Unknown) -+ return TargetABI; -+ -+- // For now, default to the ilp32/ilp32e/lp64 ABI if no explicit ABI is given -+- // or an invalid/unrecognised string is given. In the future, it might be -+- // worth changing this to default to ilp32f/lp64f and ilp32d/lp64d when -+- // hardware support for floating point is present. -++ if (IsRV32D) -++ return ABI_ILP32D; -++ if (IsRV32F) -++ return ABI_ILP32F; -+ if (IsRV32E) -+ return ABI_ILP32E; -+ if (IsRV64) diff --git a/llvm-mingw-crosscompile.diff b/llvm-mingw-crosscompile.diff deleted file mode 100644 index 09fc6599..00000000 --- a/llvm-mingw-crosscompile.diff +++ /dev/null @@ -1,35 +0,0 @@ -diff --git a/pkgs/development/compilers/llvm/12/llvm/default.nix b/pkgs/development/compilers/llvm/12/llvm/default.nix -index 30a1a7a16df..4f9435d1819 100644 ---- a/pkgs/development/compilers/llvm/12/llvm/default.nix -+++ b/pkgs/development/compilers/llvm/12/llvm/default.nix -@@ -15,10 +15,11 @@ - , buildLlvmTools - , debugVersion ? false - , enableManpages ? false --, enableSharedLibraries ? !stdenv.hostPlatform.isStatic -+, enableSharedLibraries ? (!stdenv.hostPlatform.isStatic && !stdenv.targetPlatform.isMinGW) - , enablePFM ? !(stdenv.isDarwin - || stdenv.isAarch64 # broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 - || stdenv.isAarch32 # broken for the armv7l builder -+ || stdenv.targetPlatform.isMinGW - ) - , enablePolly ? false - }: -@@ -120,7 +121,7 @@ in stdenv.mkDerivation (rec { - "-DLLVM_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake/llvm/" - "-DCMAKE_BUILD_TYPE=${if debugVersion then "Debug" else "Release"}" - "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc -- "-DLLVM_BUILD_TESTS=ON" -+ "-DLLVM_BUILD_TESTS=${if stdenv.targetPlatform.isMinGW then "OFF" else "ON"}" - "-DLLVM_ENABLE_FFI=ON" - "-DLLVM_ENABLE_RTTI=ON" - "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" -@@ -134,7 +135,7 @@ in stdenv.mkDerivation (rec { - "-DSPHINX_OUTPUT_MAN=ON" - "-DSPHINX_OUTPUT_HTML=OFF" - "-DSPHINX_WARNINGS_AS_ERRORS=OFF" -- ] ++ optionals (!isDarwin) [ -+ ] ++ optionals (!isDarwin && !stdenv.targetPlatform.isMinGW) [ - "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" - ] ++ optionals isDarwin [ - "-DLLVM_ENABLE_LIBCXX=ON" diff --git a/llvm-restrict-targets.diff b/llvm-restrict-targets.diff deleted file mode 100644 index 6500c9c5..00000000 --- a/llvm-restrict-targets.diff +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/pkgs/development/compilers/llvm/12/llvm/default.nix b/pkgs/development/compilers/llvm/12/llvm/default.nix -index 41b7211b2a5..dfc707f034d 100644 ---- a/pkgs/development/compilers/llvm/12/llvm/default.nix -+++ b/pkgs/development/compilers/llvm/12/llvm/default.nix -@@ -127,6 +127,7 @@ in stdenv.mkDerivation (rec { - "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" - "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" - "-DLLVM_ENABLE_DUMP=ON" -+ "-DLLVM_TARGETS_TO_BUILD=X86;ARM;RISCV" - ] ++ optionals enableSharedLibraries [ - "-DLLVM_LINK_LLVM_DYLIB=ON" - ] ++ optionals enableManpages [ diff --git a/llvm-unbreak-static-cross.diff b/llvm-unbreak-static-cross.diff deleted file mode 100644 index 6ab65020..00000000 --- a/llvm-unbreak-static-cross.diff +++ /dev/null @@ -1,471 +0,0 @@ -diff --git a/pkgs/development/compilers/llvm/10/llvm/default.nix b/pkgs/development/compilers/llvm/10/llvm/default.nix -index 4e590dba4337d..413de2f868a3e 100644 ---- a/pkgs/development/compilers/llvm/10/llvm/default.nix -+++ b/pkgs/development/compilers/llvm/10/llvm/default.nix -@@ -81,7 +81,7 @@ in stdenv.mkDerivation (rec { - --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" - '' - # Patch llvm-config to return correct library path based on --link-{shared,static}. -- + optionalString (enableSharedLibraries) '' -+ + '' - substitute '${./outputs.patch}' ./outputs.patch --subst-var lib - patch -p1 < ./outputs.patch - '' + '' -diff --git a/pkgs/development/compilers/llvm/10/llvm/outputs.patch b/pkgs/development/compilers/llvm/10/llvm/outputs.patch -index 40096fa3497fd..878460e05b8af 100644 ---- a/pkgs/development/compilers/llvm/10/llvm/outputs.patch -+++ b/pkgs/development/compilers/llvm/10/llvm/outputs.patch -@@ -2,23 +2,13 @@ diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.c - index 94d426b..37f7794 100644 - --- a/tools/llvm-config/llvm-config.cpp - +++ b/tools/llvm-config/llvm-config.cpp --@@ -333,6 +333,21 @@ int main(int argc, char **argv) { -+@@ -333,6 +333,11 @@ int main(int argc, char **argv) { - ActiveIncludeOption = "-I" + ActiveIncludeDir; - } - --+ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared -++ /// Nix-specific multiple-output handling: override ActiveLibDir - + if (!IsInDevelopmentTree) { --+ bool WantShared = true; --+ for (int i = 1; i < argc; ++i) { --+ StringRef Arg = argv[i]; --+ if (Arg == "--link-shared") --+ WantShared = true; --+ else if (Arg == "--link-static") --+ WantShared = false; // the last one wins --+ } --+ --+ if (WantShared) --+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; -++ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; - + } - + - /// We only use `shared library` mode in cases where the static library form -diff --git a/pkgs/development/compilers/llvm/11/llvm/default.nix b/pkgs/development/compilers/llvm/11/llvm/default.nix -index f0148850dbe8a..32981b9d4dde8 100644 ---- a/pkgs/development/compilers/llvm/11/llvm/default.nix -+++ b/pkgs/development/compilers/llvm/11/llvm/default.nix -@@ -73,7 +73,7 @@ in stdenv.mkDerivation (rec { - --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" - '' - # Patch llvm-config to return correct library path based on --link-{shared,static}. -- + optionalString (enableSharedLibraries) '' -+ + '' - substitute '${./outputs.patch}' ./outputs.patch --subst-var lib - patch -p1 < ./outputs.patch - '' + '' -diff --git a/pkgs/development/compilers/llvm/11/llvm/outputs.patch b/pkgs/development/compilers/llvm/11/llvm/outputs.patch -index 40096fa3497fd..878460e05b8af 100644 ---- a/pkgs/development/compilers/llvm/11/llvm/outputs.patch -+++ b/pkgs/development/compilers/llvm/11/llvm/outputs.patch -@@ -2,23 +2,13 @@ diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.c - index 94d426b..37f7794 100644 - --- a/tools/llvm-config/llvm-config.cpp - +++ b/tools/llvm-config/llvm-config.cpp --@@ -333,6 +333,21 @@ int main(int argc, char **argv) { -+@@ -333,6 +333,11 @@ int main(int argc, char **argv) { - ActiveIncludeOption = "-I" + ActiveIncludeDir; - } - --+ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared -++ /// Nix-specific multiple-output handling: override ActiveLibDir - + if (!IsInDevelopmentTree) { --+ bool WantShared = true; --+ for (int i = 1; i < argc; ++i) { --+ StringRef Arg = argv[i]; --+ if (Arg == "--link-shared") --+ WantShared = true; --+ else if (Arg == "--link-static") --+ WantShared = false; // the last one wins --+ } --+ --+ if (WantShared) --+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; -++ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; - + } - + - /// We only use `shared library` mode in cases where the static library form -diff --git a/pkgs/development/compilers/llvm/12/llvm/default.nix b/pkgs/development/compilers/llvm/12/llvm/default.nix -index 30a1a7a16df83..bb5676b9d48e4 100644 ---- a/pkgs/development/compilers/llvm/12/llvm/default.nix -+++ b/pkgs/development/compilers/llvm/12/llvm/default.nix -@@ -74,7 +74,7 @@ in stdenv.mkDerivation (rec { - --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" - '' - # Patch llvm-config to return correct library path based on --link-{shared,static}. -- + optionalString (enableSharedLibraries) '' -+ + '' - substitute '${./outputs.patch}' ./outputs.patch --subst-var lib - patch -p1 < ./outputs.patch - '' + '' -diff --git a/pkgs/development/compilers/llvm/12/llvm/outputs.patch b/pkgs/development/compilers/llvm/12/llvm/outputs.patch -index 40096fa3497fd..878460e05b8af 100644 ---- a/pkgs/development/compilers/llvm/12/llvm/outputs.patch -+++ b/pkgs/development/compilers/llvm/12/llvm/outputs.patch -@@ -2,23 +2,13 @@ diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.c - index 94d426b..37f7794 100644 - --- a/tools/llvm-config/llvm-config.cpp - +++ b/tools/llvm-config/llvm-config.cpp --@@ -333,6 +333,21 @@ int main(int argc, char **argv) { -+@@ -333,6 +333,11 @@ int main(int argc, char **argv) { - ActiveIncludeOption = "-I" + ActiveIncludeDir; - } - --+ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared -++ /// Nix-specific multiple-output handling: override ActiveLibDir - + if (!IsInDevelopmentTree) { --+ bool WantShared = true; --+ for (int i = 1; i < argc; ++i) { --+ StringRef Arg = argv[i]; --+ if (Arg == "--link-shared") --+ WantShared = true; --+ else if (Arg == "--link-static") --+ WantShared = false; // the last one wins --+ } --+ --+ if (WantShared) --+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; -++ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; - + } - + - /// We only use `shared library` mode in cases where the static library form -diff --git a/pkgs/development/compilers/llvm/13/llvm/default.nix b/pkgs/development/compilers/llvm/13/llvm/default.nix -index 957f29e44994a..115b56396e8d8 100644 ---- a/pkgs/development/compilers/llvm/13/llvm/default.nix -+++ b/pkgs/development/compilers/llvm/13/llvm/default.nix -@@ -68,7 +68,7 @@ in stdenv.mkDerivation (rec { - --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" - '' - # Patch llvm-config to return correct library path based on --link-{shared,static}. -- + optionalString (enableSharedLibraries) '' -+ + '' - substitute '${./outputs.patch}' ./outputs.patch --subst-var lib - patch -p1 < ./outputs.patch - '' + '' -diff --git a/pkgs/development/compilers/llvm/13/llvm/outputs.patch b/pkgs/development/compilers/llvm/13/llvm/outputs.patch -index 40096fa3497fd..878460e05b8af 100644 ---- a/pkgs/development/compilers/llvm/13/llvm/outputs.patch -+++ b/pkgs/development/compilers/llvm/13/llvm/outputs.patch -@@ -2,23 +2,13 @@ diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.c - index 94d426b..37f7794 100644 - --- a/tools/llvm-config/llvm-config.cpp - +++ b/tools/llvm-config/llvm-config.cpp --@@ -333,6 +333,21 @@ int main(int argc, char **argv) { -+@@ -333,6 +333,11 @@ int main(int argc, char **argv) { - ActiveIncludeOption = "-I" + ActiveIncludeDir; - } - --+ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared -++ /// Nix-specific multiple-output handling: override ActiveLibDir - + if (!IsInDevelopmentTree) { --+ bool WantShared = true; --+ for (int i = 1; i < argc; ++i) { --+ StringRef Arg = argv[i]; --+ if (Arg == "--link-shared") --+ WantShared = true; --+ else if (Arg == "--link-static") --+ WantShared = false; // the last one wins --+ } --+ --+ if (WantShared) --+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; -++ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; - + } - + - /// We only use `shared library` mode in cases where the static library form -diff --git a/pkgs/development/compilers/llvm/5/llvm/default.nix b/pkgs/development/compilers/llvm/5/llvm/default.nix -index 6388cd65fbf47..a4d2fec36193d 100644 ---- a/pkgs/development/compilers/llvm/5/llvm/default.nix -+++ b/pkgs/development/compilers/llvm/5/llvm/default.nix -@@ -74,7 +74,7 @@ stdenv.mkDerivation ({ - --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}" ''${extra_libdir})' "" - '' - # Patch llvm-config to return correct library path based on --link-{shared,static}. -- + optionalString (enableSharedLibraries) '' -+ + '' - substitute '${./outputs.patch}' ./outputs.patch --subst-var lib - patch -p1 < ./outputs.patch - '' + '' -diff --git a/pkgs/development/compilers/llvm/5/llvm/outputs.patch b/pkgs/development/compilers/llvm/5/llvm/outputs.patch -index 40096fa3497fd..878460e05b8af 100644 ---- a/pkgs/development/compilers/llvm/5/llvm/outputs.patch -+++ b/pkgs/development/compilers/llvm/5/llvm/outputs.patch -@@ -2,23 +2,13 @@ diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.c - index 94d426b..37f7794 100644 - --- a/tools/llvm-config/llvm-config.cpp - +++ b/tools/llvm-config/llvm-config.cpp --@@ -333,6 +333,21 @@ int main(int argc, char **argv) { -+@@ -333,6 +333,11 @@ int main(int argc, char **argv) { - ActiveIncludeOption = "-I" + ActiveIncludeDir; - } - --+ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared -++ /// Nix-specific multiple-output handling: override ActiveLibDir - + if (!IsInDevelopmentTree) { --+ bool WantShared = true; --+ for (int i = 1; i < argc; ++i) { --+ StringRef Arg = argv[i]; --+ if (Arg == "--link-shared") --+ WantShared = true; --+ else if (Arg == "--link-static") --+ WantShared = false; // the last one wins --+ } --+ --+ if (WantShared) --+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; -++ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; - + } - + - /// We only use `shared library` mode in cases where the static library form -diff --git a/pkgs/development/compilers/llvm/6/llvm/default.nix b/pkgs/development/compilers/llvm/6/llvm/default.nix -index 0907c89561717..1c010980048cd 100644 ---- a/pkgs/development/compilers/llvm/6/llvm/default.nix -+++ b/pkgs/development/compilers/llvm/6/llvm/default.nix -@@ -72,7 +72,7 @@ stdenv.mkDerivation ({ - --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}" ''${extra_libdir})' "" - '' - # Patch llvm-config to return correct library path based on --link-{shared,static}. -- + optionalString (enableSharedLibraries) '' -+ + '' - substitute '${./outputs.patch}' ./outputs.patch --subst-var lib - patch -p1 < ./outputs.patch - '' + '' -diff --git a/pkgs/development/compilers/llvm/6/llvm/outputs.patch b/pkgs/development/compilers/llvm/6/llvm/outputs.patch -index 40096fa3497fd..878460e05b8af 100644 ---- a/pkgs/development/compilers/llvm/6/llvm/outputs.patch -+++ b/pkgs/development/compilers/llvm/6/llvm/outputs.patch -@@ -2,23 +2,13 @@ diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.c - index 94d426b..37f7794 100644 - --- a/tools/llvm-config/llvm-config.cpp - +++ b/tools/llvm-config/llvm-config.cpp --@@ -333,6 +333,21 @@ int main(int argc, char **argv) { -+@@ -333,6 +333,11 @@ int main(int argc, char **argv) { - ActiveIncludeOption = "-I" + ActiveIncludeDir; - } - --+ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared -++ /// Nix-specific multiple-output handling: override ActiveLibDir - + if (!IsInDevelopmentTree) { --+ bool WantShared = true; --+ for (int i = 1; i < argc; ++i) { --+ StringRef Arg = argv[i]; --+ if (Arg == "--link-shared") --+ WantShared = true; --+ else if (Arg == "--link-static") --+ WantShared = false; // the last one wins --+ } --+ --+ if (WantShared) --+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; -++ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; - + } - + - /// We only use `shared library` mode in cases where the static library form -diff --git a/pkgs/development/compilers/llvm/7/llvm/default.nix b/pkgs/development/compilers/llvm/7/llvm/default.nix -index 4a9b4f5182056..ac6efaccb865e 100644 ---- a/pkgs/development/compilers/llvm/7/llvm/default.nix -+++ b/pkgs/development/compilers/llvm/7/llvm/default.nix -@@ -76,7 +76,7 @@ in stdenv.mkDerivation ({ - --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}" ''${extra_libdir})' "" - '' - # Patch llvm-config to return correct library path based on --link-{shared,static}. -- + optionalString (enableSharedLibraries) '' -+ + '' - substitute '${./outputs.patch}' ./outputs.patch --subst-var lib - patch -p1 < ./outputs.patch - '' + '' -diff --git a/pkgs/development/compilers/llvm/7/llvm/outputs.patch b/pkgs/development/compilers/llvm/7/llvm/outputs.patch -index 40096fa3497fd..878460e05b8af 100644 ---- a/pkgs/development/compilers/llvm/7/llvm/outputs.patch -+++ b/pkgs/development/compilers/llvm/7/llvm/outputs.patch -@@ -2,23 +2,13 @@ diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.c - index 94d426b..37f7794 100644 - --- a/tools/llvm-config/llvm-config.cpp - +++ b/tools/llvm-config/llvm-config.cpp --@@ -333,6 +333,21 @@ int main(int argc, char **argv) { -+@@ -333,6 +333,11 @@ int main(int argc, char **argv) { - ActiveIncludeOption = "-I" + ActiveIncludeDir; - } - --+ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared -++ /// Nix-specific multiple-output handling: override ActiveLibDir - + if (!IsInDevelopmentTree) { --+ bool WantShared = true; --+ for (int i = 1; i < argc; ++i) { --+ StringRef Arg = argv[i]; --+ if (Arg == "--link-shared") --+ WantShared = true; --+ else if (Arg == "--link-static") --+ WantShared = false; // the last one wins --+ } --+ --+ if (WantShared) --+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; -++ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; - + } - + - /// We only use `shared library` mode in cases where the static library form -diff --git a/pkgs/development/compilers/llvm/8/llvm/default.nix b/pkgs/development/compilers/llvm/8/llvm/default.nix -index 83b779b56d827..48a434b24c7cd 100644 ---- a/pkgs/development/compilers/llvm/8/llvm/default.nix -+++ b/pkgs/development/compilers/llvm/8/llvm/default.nix -@@ -79,7 +79,7 @@ in stdenv.mkDerivation ({ - --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}" ''${extra_libdir})' "" - '' - # Patch llvm-config to return correct library path based on --link-{shared,static}. -- + optionalString (enableSharedLibraries) '' -+ + '' - substitute '${./outputs.patch}' ./outputs.patch --subst-var lib - patch -p1 < ./outputs.patch - '' + '' -diff --git a/pkgs/development/compilers/llvm/8/llvm/outputs.patch b/pkgs/development/compilers/llvm/8/llvm/outputs.patch -index 40096fa3497fd..878460e05b8af 100644 ---- a/pkgs/development/compilers/llvm/8/llvm/outputs.patch -+++ b/pkgs/development/compilers/llvm/8/llvm/outputs.patch -@@ -2,23 +2,13 @@ diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.c - index 94d426b..37f7794 100644 - --- a/tools/llvm-config/llvm-config.cpp - +++ b/tools/llvm-config/llvm-config.cpp --@@ -333,6 +333,21 @@ int main(int argc, char **argv) { -+@@ -333,6 +333,11 @@ int main(int argc, char **argv) { - ActiveIncludeOption = "-I" + ActiveIncludeDir; - } - --+ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared -++ /// Nix-specific multiple-output handling: override ActiveLibDir - + if (!IsInDevelopmentTree) { --+ bool WantShared = true; --+ for (int i = 1; i < argc; ++i) { --+ StringRef Arg = argv[i]; --+ if (Arg == "--link-shared") --+ WantShared = true; --+ else if (Arg == "--link-static") --+ WantShared = false; // the last one wins --+ } --+ --+ if (WantShared) --+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; -++ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; - + } - + - /// We only use `shared library` mode in cases where the static library form -diff --git a/pkgs/development/compilers/llvm/9/llvm/default.nix b/pkgs/development/compilers/llvm/9/llvm/default.nix -index 570795824ee58..a569c00071de0 100644 ---- a/pkgs/development/compilers/llvm/9/llvm/default.nix -+++ b/pkgs/development/compilers/llvm/9/llvm/default.nix -@@ -77,7 +77,7 @@ in stdenv.mkDerivation (rec { - --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}" ''${extra_libdir})' "" - '' - # Patch llvm-config to return correct library path based on --link-{shared,static}. -- + optionalString (enableSharedLibraries) '' -+ + '' - substitute '${./outputs.patch}' ./outputs.patch --subst-var lib - patch -p1 < ./outputs.patch - '' + '' -diff --git a/pkgs/development/compilers/llvm/9/llvm/outputs.patch b/pkgs/development/compilers/llvm/9/llvm/outputs.patch -index 40096fa3497fd..878460e05b8af 100644 ---- a/pkgs/development/compilers/llvm/9/llvm/outputs.patch -+++ b/pkgs/development/compilers/llvm/9/llvm/outputs.patch -@@ -2,23 +2,13 @@ diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.c - index 94d426b..37f7794 100644 - --- a/tools/llvm-config/llvm-config.cpp - +++ b/tools/llvm-config/llvm-config.cpp --@@ -333,6 +333,21 @@ int main(int argc, char **argv) { -+@@ -333,6 +333,11 @@ int main(int argc, char **argv) { - ActiveIncludeOption = "-I" + ActiveIncludeDir; - } - --+ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared -++ /// Nix-specific multiple-output handling: override ActiveLibDir - + if (!IsInDevelopmentTree) { --+ bool WantShared = true; --+ for (int i = 1; i < argc; ++i) { --+ StringRef Arg = argv[i]; --+ if (Arg == "--link-shared") --+ WantShared = true; --+ else if (Arg == "--link-static") --+ WantShared = false; // the last one wins --+ } --+ --+ if (WantShared) --+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; -++ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; - + } - + - /// We only use `shared library` mode in cases where the static library form -diff --git a/pkgs/development/compilers/llvm/git/llvm/default.nix b/pkgs/development/compilers/llvm/git/llvm/default.nix -index daf4cfe808b6c..4c895f81dbbac 100644 ---- a/pkgs/development/compilers/llvm/git/llvm/default.nix -+++ b/pkgs/development/compilers/llvm/git/llvm/default.nix -@@ -60,7 +60,7 @@ in stdenv.mkDerivation (rec { - --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" - '' - # Patch llvm-config to return correct library path based on --link-{shared,static}. -- + optionalString (enableSharedLibraries) '' -+ + '' - substitute '${./outputs.patch}' ./outputs.patch --subst-var lib - patch -p1 < ./outputs.patch - '' + '' -diff --git a/pkgs/development/compilers/llvm/git/llvm/outputs.patch b/pkgs/development/compilers/llvm/git/llvm/outputs.patch -index 40096fa3497fd..878460e05b8af 100644 ---- a/pkgs/development/compilers/llvm/git/llvm/outputs.patch -+++ b/pkgs/development/compilers/llvm/git/llvm/outputs.patch -@@ -2,23 +2,13 @@ diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.c - index 94d426b..37f7794 100644 - --- a/tools/llvm-config/llvm-config.cpp - +++ b/tools/llvm-config/llvm-config.cpp --@@ -333,6 +333,21 @@ int main(int argc, char **argv) { -+@@ -333,6 +333,11 @@ int main(int argc, char **argv) { - ActiveIncludeOption = "-I" + ActiveIncludeDir; - } - --+ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared -++ /// Nix-specific multiple-output handling: override ActiveLibDir - + if (!IsInDevelopmentTree) { --+ bool WantShared = true; --+ for (int i = 1; i < argc; ++i) { --+ StringRef Arg = argv[i]; --+ if (Arg == "--link-shared") --+ WantShared = true; --+ else if (Arg == "--link-static") --+ WantShared = false; // the last one wins --+ } --+ --+ if (WantShared) --+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; -++ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; - + } - + - /// We only use `shared library` mode in cases where the static library form -diff --git a/pkgs/development/compilers/llvm/rocm/llvm/outputs.patch b/pkgs/development/compilers/llvm/rocm/llvm/outputs.patch -index 40096fa3497fd..878460e05b8af 100644 ---- a/pkgs/development/compilers/llvm/rocm/llvm/outputs.patch -+++ b/pkgs/development/compilers/llvm/rocm/llvm/outputs.patch -@@ -2,23 +2,13 @@ diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.c - index 94d426b..37f7794 100644 - --- a/tools/llvm-config/llvm-config.cpp - +++ b/tools/llvm-config/llvm-config.cpp --@@ -333,6 +333,21 @@ int main(int argc, char **argv) { -+@@ -333,6 +333,11 @@ int main(int argc, char **argv) { - ActiveIncludeOption = "-I" + ActiveIncludeDir; - } - --+ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared -++ /// Nix-specific multiple-output handling: override ActiveLibDir - + if (!IsInDevelopmentTree) { --+ bool WantShared = true; --+ for (int i = 1; i < argc; ++i) { --+ StringRef Arg = argv[i]; --+ if (Arg == "--link-shared") --+ WantShared = true; --+ else if (Arg == "--link-static") --+ WantShared = false; // the last one wins --+ } --+ --+ if (WantShared) --+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; -++ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; - + } - + - /// We only use `shared library` mode in cases where the static library form diff --git a/llvm/default.nix b/llvm/default.nix new file mode 100644 index 00000000..8f65dfda --- /dev/null +++ b/llvm/default.nix @@ -0,0 +1,242 @@ +{ lib, stdenv +, pkgsBuildBuild +, fetchurl +, fetchpatch +, cmake +, python3 +, libffi +, libbfd +, libpfm +, libxml2 +, ncurses +, zlib +, llvmPackages_12 +, debugVersion ? false +, enableManpages ? false +, enableSharedLibraries ? (!stdenv.hostPlatform.isStatic && !stdenv.targetPlatform.isMinGW) +, enablePFM ? !(stdenv.isDarwin + || stdenv.isAarch64 # broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 + || stdenv.isAarch32 # broken for the armv7l builder + || stdenv.targetPlatform.isMinGW +) +, enablePolly ? false +}: + +let + inherit (lib) optional optionals optionalString; + + release_version = "12.0.1"; + candidate = ""; # empty or "rcN" + dash-candidate = lib.optionalString (candidate != "") "-${candidate}"; + version = "${release_version}${dash-candidate}"; # differentiating these (variables) is important for RCs + fetch = name: sha256: fetchurl { + url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/${name}-${release_version}${candidate}.src.tar.xz"; + inherit sha256; + }; + + # Used when creating a version-suffixed symlink of libLLVM.dylib + shortVersion = with lib; + concatStringsSep "." (take 1 (splitString "." release_version)); + +in stdenv.mkDerivation (rec { + pname = "llvm"; + inherit version; + + src = fetch pname "1pzx9zrmd7r3481sbhwvkms68fwhffpp4mmz45dgrkjpyl2q96kx"; + polly_src = fetch "polly" "1yfm9ixda4a2sx7ak5vswijx4ydk5lv1c1xh39xmd2kh299y4m12"; + + unpackPhase = '' + unpackFile $src + mv llvm-${release_version}* llvm + sourceRoot=$PWD/llvm + '' + optionalString enablePolly '' + unpackFile $polly_src + mv polly-* $sourceRoot/tools/polly + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + nativeBuildInputs = [ cmake python3 ] + ++ optionals enableManpages [ python3.pkgs.sphinx python3.pkgs.recommonmark ]; + + buildInputs = [ libxml2 libffi ] + ++ optional enablePFM libpfm; # exegesis + + propagatedBuildInputs = optionals (stdenv.buildPlatform == stdenv.hostPlatform) [ ncurses ] + ++ [ zlib ]; + + patches = [ + ./gnu-install-dirs.patch + # On older CPUs (e.g. Hydra/wendy) we'd be getting an error in this test. + (fetchpatch { + name = "uops-CMOV16rm-noreg.diff"; + url = "https://github.com/llvm/llvm-project/commit/9e9f991ac033.diff"; + sha256 = "sha256:12s8vr6ibri8b48h2z38f3afhwam10arfiqfy4yg37bmc054p5hi"; + stripLen = 1; + }) + ./llvm-future-riscv-abi.diff + ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; + + postPatch = optionalString stdenv.isDarwin '' + substituteInPlace cmake/modules/AddLLVM.cmake \ + --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ + --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" + '' + # Patch llvm-config to return correct library path based on --link-{shared,static}. + + '' + substitute '${./outputs.patch}' ./outputs.patch --subst-var lib + patch -p1 < ./outputs.patch + '' + '' + # FileSystem permissions tests fail with various special bits + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "Path.cpp" "" + rm unittests/Support/Path.cpp + substituteInPlace unittests/IR/CMakeLists.txt \ + --replace "PassBuilderCallbacksTest.cpp" "" + rm unittests/IR/PassBuilderCallbacksTest.cpp + # TODO: Fix failing tests: + rm test/DebugInfo/X86/vla-multi.ll + '' + optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -i ${../../TLI-musl.patch} + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "add_subdirectory(DynamicLibrary)" "" + rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp + # valgrind unhappy with musl or glibc, but fails w/musl only + rm test/CodeGen/AArch64/wineh4.mir + '' + optionalString stdenv.hostPlatform.isAarch32 '' + # skip failing X86 test cases on 32-bit ARM + rm test/DebugInfo/X86/convert-debugloc.ll + rm test/DebugInfo/X86/convert-inlined.ll + rm test/DebugInfo/X86/convert-linked.ll + rm test/tools/dsymutil/X86/op-convert.test + '' + optionalString (stdenv.hostPlatform.system == "armv6l-linux") '' + # Seems to require certain floating point hardware (NEON?) + rm test/ExecutionEngine/frem.ll + '' + '' + patchShebangs test/BugPoint/compile-custom.ll.py + ''; + + # hacky fix: created binaries need to be run before installation + preBuild = '' + mkdir -p $out/ + ln -sv $PWD/lib $out + ''; + + # E.g. mesa.drivers use the build-id as a cache key (see #93946): + LDFLAGS = optionalString (enableSharedLibraries && !stdenv.isDarwin) "-Wl,--build-id=sha1"; + + cmakeFlags = with stdenv; [ + "-DLLVM_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake/llvm/" + "-DCMAKE_BUILD_TYPE=${if debugVersion then "Debug" else "Release"}" + "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc + "-DLLVM_BUILD_TESTS=${if stdenv.targetPlatform.isMinGW then "OFF" else "ON"}" + "-DLLVM_ENABLE_FFI=ON" + "-DLLVM_ENABLE_RTTI=ON" + "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_ENABLE_DUMP=ON" + "-DLLVM_TARGETS_TO_BUILD=X86;ARM;RISCV" + ] ++ optionals enableSharedLibraries [ + "-DLLVM_LINK_LLVM_DYLIB=ON" + ] ++ optionals enableManpages [ + "-DLLVM_BUILD_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ optionals (!isDarwin && !stdenv.targetPlatform.isMinGW) [ + "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" + ] ++ optionals isDarwin [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DCAN_TARGET_i386=false" + ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DCMAKE_CROSSCOMPILING=True" + "-DLLVM_TABLEGEN=${llvmPackages_12.tools.llvm}/bin/llvm-tblgen" + ( + let + nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; + nativeBintools = nativeCC.bintools.bintools; + nativeToolchainFlags = [ + "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" + "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" + "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" + "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" + "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" + ]; + in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=${lib.concatStringsSep ";" nativeToolchainFlags}" + ) + ]; + + postBuild = '' + rm -fR $out + ''; + + preCheck = '' + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib + ''; + + postInstall = '' + mkdir -p $python/share + mv $out/share/opt-viewer $python/share/opt-viewer + moveToOutput "bin/llvm-config*" "$dev" + substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ + --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \ + --replace "$out/bin/llvm-config" "$dev/bin/llvm-config" + substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ + --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}'"$lib"'")' + '' + + optionalString (stdenv.isDarwin && enableSharedLibraries) '' + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib + '' + + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native + ''; + + doCheck = false; # the ABI change breaks RISC-V FP tests + + checkTarget = "check-all"; + + requiredSystemFeatures = [ "big-parallel" ]; + meta = { + homepage = "https://llvm.org/"; + description = "A collection of modular and reusable compiler and toolchain technologies"; + longDescription = '' + The LLVM Project is a collection of modular and reusable compiler and + toolchain technologies. Despite its name, LLVM has little to do with + traditional virtual machines. The name "LLVM" itself is not an acronym; it + is the full name of the project. + LLVM began as a research project at the University of Illinois, with the + goal of providing a modern, SSA-based compilation strategy capable of + supporting both static and dynamic compilation of arbitrary programming + languages. Since then, LLVM has grown to be an umbrella project consisting + of a number of subprojects, many of which are being used in production by + a wide variety of commercial and open source projects as well as being + widely used in academic research. Code in the LLVM project is licensed + under the "Apache 2.0 License with LLVM exceptions". + ''; + }; +} // lib.optionalAttrs enableManpages { + pname = "llvm-manpages"; + + buildPhase = '' + make docs-llvm-man + ''; + + propagatedBuildInputs = []; + + installPhase = '' + make -C docs install + ''; + + postPatch = null; + postInstall = null; + + outputs = [ "out" ]; + + doCheck = false; + + meta = { + description = "man pages for LLVM ${version}"; + }; +}) diff --git a/llvm/gnu-install-dirs-polly.patch b/llvm/gnu-install-dirs-polly.patch new file mode 100644 index 00000000..68f3c453 --- /dev/null +++ b/llvm/gnu-install-dirs-polly.patch @@ -0,0 +1,105 @@ +diff --git a/tools/polly/CMakeLists.txt b/tools/polly/CMakeLists.txt +index ca7c04c565bb..6ed5db5dd4f8 100644 +--- a/tools/polly/CMakeLists.txt ++++ b/tools/polly/CMakeLists.txt +@@ -2,7 +2,11 @@ + if (NOT DEFINED LLVM_MAIN_SRC_DIR) + project(Polly) + cmake_minimum_required(VERSION 3.13.4) ++endif() ++ ++include(GNUInstallDirs) + ++if (NOT DEFINED LLVM_MAIN_SRC_DIR) + # Where is LLVM installed? + find_package(LLVM CONFIG REQUIRED) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) +@@ -122,13 +126,13 @@ include_directories( + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + ) + + install(DIRECTORY ${POLLY_BINARY_DIR}/include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE +diff --git a/tools/polly/cmake/CMakeLists.txt b/tools/polly/cmake/CMakeLists.txt +index 7cc129ba2e90..137be25e4b80 100644 +--- a/tools/polly/cmake/CMakeLists.txt ++++ b/tools/polly/cmake/CMakeLists.txt +@@ -79,18 +79,18 @@ file(GENERATE + + # Generate PollyConfig.cmake for the install tree. + unset(POLLY_EXPORTS) +-set(POLLY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") ++set(POLLY_INSTALL_PREFIX "") + set(POLLY_CONFIG_LLVM_CMAKE_DIR "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}") ++set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") ++set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + if (POLLY_BUNDLED_ISL) + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" +- "${POLLY_INSTALL_PREFIX}/include/polly" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}/polly" + ) + else() + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_INCLUDEDIR}" + ${ISL_INCLUDE_DIRS} + ) + endif() +@@ -100,12 +100,12 @@ endif() + foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS) + get_target_property(tgt_type ${tgt} TYPE) + if (tgt_type STREQUAL "EXECUTABLE") +- set(tgt_prefix "bin/") ++ set(tgt_prefix "${CMAKE_INSTALL_BINDIR}/") + else() +- set(tgt_prefix "lib/") ++ set(tgt_prefix "${CMAKE_INSTALL_LIBDIR}/") + endif() + +- set(tgt_path "${CMAKE_INSTALL_PREFIX}/${tgt_prefix}$") ++ set(tgt_path "${tgt_prefix}$") + file(RELATIVE_PATH tgt_path ${POLLY_CONFIG_CMAKE_DIR} ${tgt_path}) + + if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY") +diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake +index 518a09b45a42..bd9d6f5542ad 100644 +--- a/tools/polly/cmake/polly_macros.cmake ++++ b/tools/polly/cmake/polly_macros.cmake +@@ -44,8 +44,8 @@ macro(add_polly_library name) + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly") + install(TARGETS ${name} + EXPORT LLVMExports +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) + endmacro(add_polly_library) +diff --git a/tools/polly/lib/External/CMakeLists.txt b/tools/polly/lib/External/CMakeLists.txt +index 8991094d92c7..178d8ad606bb 100644 +--- a/tools/polly/lib/External/CMakeLists.txt ++++ b/tools/polly/lib/External/CMakeLists.txt +@@ -275,7 +275,7 @@ if (POLLY_BUNDLED_ISL) + install(DIRECTORY + ${ISL_SOURCE_DIR}/include/ + ${ISL_BINARY_DIR}/include/ +- DESTINATION include/polly ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/polly + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE diff --git a/llvm/gnu-install-dirs.patch b/llvm/gnu-install-dirs.patch new file mode 100644 index 00000000..da8dc144 --- /dev/null +++ b/llvm/gnu-install-dirs.patch @@ -0,0 +1,417 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 277d0fe54d7b..af69c8be8745 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -256,15 +256,21 @@ if (CMAKE_BUILD_TYPE AND + message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") + endif() + ++include(GNUInstallDirs) ++ + set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" ) + +-set(LLVM_TOOLS_INSTALL_DIR "bin" CACHE STRING "Path for binary subdirectory (defaults to 'bin')") ++set(LLVM_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING ++ "Path for binary subdirectory (defaults to 'bin')") + mark_as_advanced(LLVM_TOOLS_INSTALL_DIR) + + set(LLVM_UTILS_INSTALL_DIR "${LLVM_TOOLS_INSTALL_DIR}" CACHE STRING + "Path to install LLVM utilities (enabled by LLVM_INSTALL_UTILS=ON) (defaults to LLVM_TOOLS_INSTALL_DIR)") + mark_as_advanced(LLVM_UTILS_INSTALL_DIR) + ++set(LLVM_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/cmake/llvm" CACHE STRING ++ "Path for CMake subdirectory (defaults to lib/cmake/llvm)" ) ++ + # They are used as destination of target generators. + set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) + set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) +@@ -567,9 +573,9 @@ option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF) + option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON) + option (LLVM_ENABLE_BINDINGS "Build bindings." ON) + +-set(LLVM_INSTALL_DOXYGEN_HTML_DIR "share/doc/llvm/doxygen-html" ++set(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html" + CACHE STRING "Doxygen-generated HTML documentation install directory") +-set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "share/doc/llvm/ocaml-html" ++set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html" + CACHE STRING "OCamldoc-generated HTML documentation install directory") + + option (LLVM_BUILD_EXTERNAL_COMPILER_RT +@@ -1027,7 +1033,7 @@ endif() + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/llvm include/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "*.def" +@@ -1038,7 +1044,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "*.def" +@@ -1052,13 +1058,13 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + if (LLVM_INSTALL_MODULEMAPS) + install(DIRECTORY include/llvm include/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "module.modulemap" + ) + install(FILES include/llvm/module.install.modulemap +- DESTINATION include/llvm ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm + COMPONENT llvm-headers + RENAME "module.extern.modulemap" + ) +diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake +index 97c9980c7de3..409e8b615f75 100644 +--- a/cmake/modules/AddLLVM.cmake ++++ b/cmake/modules/AddLLVM.cmake +@@ -804,9 +804,9 @@ macro(add_llvm_library name) + + install(TARGETS ${name} + ${export_to_llvmexports} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +- RUNTIME DESTINATION bin COMPONENT ${name}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${name}) + + if (NOT LLVM_ENABLE_IDE) + add_llvm_install_targets(install-${name} +@@ -1022,7 +1022,7 @@ function(process_llvm_pass_plugins) + "set(LLVM_STATIC_EXTENSIONS ${LLVM_STATIC_EXTENSIONS})") + install(FILES + ${llvm_cmake_builddir}/LLVMConfigExtensions.cmake +- DESTINATION ${LLVM_INSTALL_PACKAGE_DIR} ++ DESTINATION ${LLVM_INSTALL_CMAKE_DIR} + COMPONENT cmake-exports) + + set(ExtensionDef "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def") +@@ -1242,7 +1242,7 @@ macro(add_llvm_example name) + endif() + add_llvm_executable(${name} ${ARGN}) + if( LLVM_BUILD_EXAMPLES ) +- install(TARGETS ${name} RUNTIME DESTINATION examples) ++ install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples) + endif() + set_target_properties(${name} PROPERTIES FOLDER "Examples") + endmacro(add_llvm_example name) +@@ -1854,7 +1854,7 @@ function(llvm_install_library_symlink name dest type) + set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX}) + set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX}) + +- set(output_dir lib${LLVM_LIBDIR_SUFFIX}) ++ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 AND "${type}" STREQUAL "SHARED") + set(output_dir bin) + endif() +@@ -1871,7 +1871,7 @@ function(llvm_install_library_symlink name dest type) + endif() + endfunction() + +-function(llvm_install_symlink name dest) ++function(llvm_install_symlink name dest output_dir) + cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN}) + foreach(path ${CMAKE_MODULE_PATH}) + if(EXISTS ${path}/LLVMInstallSymlink.cmake) +@@ -1894,7 +1894,7 @@ function(llvm_install_symlink name dest) + set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX}) + + install(SCRIPT ${INSTALL_SYMLINK} +- CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})" ++ CODE "install_symlink(${full_name} ${full_dest} ${output_dir})" + COMPONENT ${component}) + + if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE) +@@ -1977,7 +1977,8 @@ function(add_llvm_tool_symlink link_name target) + endif() + + if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS) +- llvm_install_symlink(${link_name} ${target}) ++ GNUInstallDirs_get_absolute_install_dir(output_dir LLVM_TOOLS_INSTALL_DIR) ++ llvm_install_symlink(${link_name} ${target} ${output_dir}) + endif() + endif() + endfunction() +@@ -2100,9 +2101,9 @@ function(llvm_setup_rpath name) + + if (APPLE) + set(_install_name_dir INSTALL_NAME_DIR "@rpath") +- set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "@loader_path/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + elseif(UNIX) +- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") + set_property(TARGET ${name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-z,origin ") +diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake +index 554046b20edf..4d1ad980641e 100644 +--- a/cmake/modules/AddOCaml.cmake ++++ b/cmake/modules/AddOCaml.cmake +@@ -144,9 +144,9 @@ function(add_ocaml_library name) + endforeach() + + if( APPLE ) +- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + elseif( UNIX ) +- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + endif() + list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") + +diff --git a/cmake/modules/AddSphinxTarget.cmake b/cmake/modules/AddSphinxTarget.cmake +index e80c3b5c1cac..482f6d715ef5 100644 +--- a/cmake/modules/AddSphinxTarget.cmake ++++ b/cmake/modules/AddSphinxTarget.cmake +@@ -90,7 +90,7 @@ function (add_sphinx_target builder project) + endif() + elseif (builder STREQUAL html) + string(TOUPPER "${project}" project_upper) +- set(${project_upper}_INSTALL_SPHINX_HTML_DIR "share/doc/${project}/html" ++ set(${project_upper}_INSTALL_SPHINX_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/html" + CACHE STRING "HTML documentation install directory for ${project}") + + # '/.' indicates: copy the contents of the directory directly into +diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt +index 505dc9a29d70..36e6c63af3f4 100644 +--- a/cmake/modules/CMakeLists.txt ++++ b/cmake/modules/CMakeLists.txt +@@ -1,4 +1,4 @@ +-set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm) ++set(LLVM_INSTALL_PACKAGE_DIR ${LLVM_INSTALL_CMAKE_DIR} CACHE STRING "Path for CMake subdirectory (defaults to 'cmake/llvm')") + set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") + + # First for users who use an installed LLVM, create the LLVMExports.cmake file. +@@ -107,13 +107,13 @@ foreach(p ${_count}) + set(LLVM_CONFIG_CODE "${LLVM_CONFIG_CODE} + get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)") + endforeach(p) +-set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/include") ++set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") + set(LLVM_CONFIG_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}") + set(LLVM_CONFIG_MAIN_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}") +-set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib\${LLVM_LIBDIR_SUFFIX}") ++set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}") + set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}") + set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}") +-set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin") ++set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}") + + # Generate a default location for lit + if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS) +diff --git a/cmake/modules/LLVMInstallSymlink.cmake b/cmake/modules/LLVMInstallSymlink.cmake +index 09fed8085c23..aa79f192abf0 100644 +--- a/cmake/modules/LLVMInstallSymlink.cmake ++++ b/cmake/modules/LLVMInstallSymlink.cmake +@@ -10,7 +10,7 @@ function(install_symlink name target outdir) + set(LINK_OR_COPY copy) + endif() + +- set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}/") ++ set(bindir "${DESTDIR}${outdir}/") + + message(STATUS "Creating ${name}") + +diff --git a/docs/CMake.rst b/docs/CMake.rst +index bb821b417ad9..6a528f7c2ad3 100644 +--- a/docs/CMake.rst ++++ b/docs/CMake.rst +@@ -196,7 +196,7 @@ CMake manual, or execute ``cmake --help-variable VARIABLE_NAME``. + **LLVM_LIBDIR_SUFFIX**:STRING + Extra suffix to append to the directory where libraries are to be + installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` +- to install libraries to ``/usr/lib64``. ++ to install libraries to ``/usr/lib64``. See also ``CMAKE_INSTALL_LIBDIR``. + + **CMAKE_C_FLAGS**:STRING + Extra flags to use when compiling C source files. +@@ -550,8 +550,8 @@ LLVM-specific variables + + **LLVM_INSTALL_DOXYGEN_HTML_DIR**:STRING + The path to install Doxygen-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/doxygen-html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html`. + + **LLVM_ENABLE_SPHINX**:BOOL + If specified, CMake will search for the ``sphinx-build`` executable and will make +@@ -582,13 +582,33 @@ LLVM-specific variables + + **LLVM_INSTALL_SPHINX_HTML_DIR**:STRING + The path to install Sphinx-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/html`. + + **LLVM_INSTALL_OCAMLDOC_HTML_DIR**:STRING + The path to install OCamldoc-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/ocaml-html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html`. ++ ++**CMAKE_INSTALL_BINDIR**:STRING ++ The path to install binary tools, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `bin`. ++ ++**CMAKE_INSTALL_LIBDIR**:STRING ++ The path to install libraries, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `lib`. ++ ++**CMAKE_INSTALL_INCLUDEDIR**:STRING ++ The path to install header files, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `include`. ++ ++**CMAKE_INSTALL_DOCDIR**:STRING ++ The path to install documentation, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `share/doc`. ++ ++**CMAKE_INSTALL_MANDIR**:STRING ++ The path to install manpage files, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `share/man`. + + **LLVM_CREATE_XCODE_TOOLCHAIN**:BOOL + macOS Only: If enabled CMake will generate a target named +@@ -786,9 +806,11 @@ the ``cmake`` command or by setting it directly in ``ccmake`` or ``cmake-gui``). + + This file is available in two different locations. + +-* ``/lib/cmake/llvm/LLVMConfig.cmake`` where +- ```` is the install prefix of an installed version of LLVM. +- On Linux typically this is ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. ++* ``LLVMConfig.cmake`` where ++ ```` is the location where LLVM CMake modules are ++ installed as part of an installed version of LLVM. This is typically ++ ``cmake/llvm/`` within the lib directory. On Linux, this is typically ++ ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. + + * ``/lib/cmake/llvm/LLVMConfig.cmake`` where + ```` is the root of the LLVM build tree. **Note: this is only +diff --git a/examples/Bye/CMakeLists.txt b/examples/Bye/CMakeLists.txt +index bb96edb4b4bf..678c22fb43c8 100644 +--- a/examples/Bye/CMakeLists.txt ++++ b/examples/Bye/CMakeLists.txt +@@ -14,6 +14,6 @@ if (NOT WIN32) + BUILDTREE_ONLY + ) + +- install(TARGETS ${name} RUNTIME DESTINATION examples) ++ install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples) + set_target_properties(${name} PROPERTIES FOLDER "Examples") + endif() +diff --git a/include/llvm/CMakeLists.txt b/include/llvm/CMakeLists.txt +index b46319f24fc8..2feabd1954e4 100644 +--- a/include/llvm/CMakeLists.txt ++++ b/include/llvm/CMakeLists.txt +@@ -5,5 +5,5 @@ add_subdirectory(Frontend) + # If we're doing an out-of-tree build, copy a module map for generated + # header files into the build area. + if (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +- configure_file(module.modulemap.build module.modulemap COPYONLY) ++ configure_file(module.modulemap.build ${LLVM_INCLUDE_DIR}/module.modulemap COPYONLY) + endif (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in +index ebe5b73a5c65..70c497be12f5 100644 +--- a/tools/llvm-config/BuildVariables.inc.in ++++ b/tools/llvm-config/BuildVariables.inc.in +@@ -23,6 +23,10 @@ + #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@" + #define LLVM_BUILDMODE "@LLVM_BUILDMODE@" + #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@" ++#define LLVM_INSTALL_BINDIR "@CMAKE_INSTALL_BINDIR@" ++#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@" ++#define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@" ++#define LLVM_INSTALL_CMAKEDIR "@LLVM_INSTALL_CMAKE_DIR@" + #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" + #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@" + #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@" +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp +index 1a2f04552d13..44fa7d3eec6b 100644 +--- a/tools/llvm-config/llvm-config.cpp ++++ b/tools/llvm-config/llvm-config.cpp +@@ -357,12 +357,26 @@ int main(int argc, char **argv) { + ("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include"); + } else { + ActivePrefix = CurrentExecPrefix; +- ActiveIncludeDir = ActivePrefix + "/include"; +- SmallString<256> path(StringRef(LLVM_TOOLS_INSTALL_DIR)); +- sys::fs::make_absolute(ActivePrefix, path); +- ActiveBinDir = std::string(path.str()); +- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX; +- ActiveCMakeDir = ActiveLibDir + "/cmake/llvm"; ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_INCLUDEDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveIncludeDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_BINDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveBinDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveLibDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_CMAKEDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveCMakeDir = std::string(path.str()); ++ } + ActiveIncludeOption = "-I" + ActiveIncludeDir; + } + +diff --git a/tools/lto/CMakeLists.txt b/tools/lto/CMakeLists.txt +index 2963f97cad88..69d66c9c9ca1 100644 +--- a/tools/lto/CMakeLists.txt ++++ b/tools/lto/CMakeLists.txt +@@ -25,7 +25,7 @@ add_llvm_library(LTO SHARED INSTALL_WITH_TOOLCHAIN ${SOURCES} DEPENDS + intrinsics_gen) + + install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/lto.h +- DESTINATION include/llvm-c ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm-c + COMPONENT LTO) + + if (APPLE) +diff --git a/tools/opt-viewer/CMakeLists.txt b/tools/opt-viewer/CMakeLists.txt +index ead73ec13a8f..250362021f17 100644 +--- a/tools/opt-viewer/CMakeLists.txt ++++ b/tools/opt-viewer/CMakeLists.txt +@@ -8,7 +8,7 @@ set (files + + foreach (file ${files}) + install(PROGRAMS ${file} +- DESTINATION share/opt-viewer ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/opt-viewer + COMPONENT opt-viewer) + endforeach (file) + +diff --git a/tools/remarks-shlib/CMakeLists.txt b/tools/remarks-shlib/CMakeLists.txt +index 865436247270..ce1daa62f6ab 100644 +--- a/tools/remarks-shlib/CMakeLists.txt ++++ b/tools/remarks-shlib/CMakeLists.txt +@@ -19,7 +19,7 @@ if(LLVM_ENABLE_PIC) + endif() + + install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/Remarks.h +- DESTINATION include/llvm-c ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm-c + COMPONENT Remarks) + + if (APPLE) diff --git a/llvm/llvm-future-riscv-abi.diff b/llvm/llvm-future-riscv-abi.diff new file mode 100644 index 00000000..2427ed0e --- /dev/null +++ b/llvm/llvm-future-riscv-abi.diff @@ -0,0 +1,28 @@ +diff --git a/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp b/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp +index 0aba18b20..9bb75e7f4 100644 +--- a/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp ++++ b/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp +@@ -33,6 +33,8 @@ ABI computeTargetABI(const Triple &TT, FeatureBitset FeatureBits, + auto TargetABI = getTargetABI(ABIName); + bool IsRV64 = TT.isArch64Bit(); + bool IsRV32E = FeatureBits[RISCV::FeatureRV32E]; ++ bool IsRV32D = FeatureBits[RISCV::FeatureStdExtD]; ++ bool IsRV32F = FeatureBits[RISCV::FeatureStdExtF]; + + if (!ABIName.empty() && TargetABI == ABI_Unknown) { + errs() +@@ -56,10 +58,10 @@ ABI computeTargetABI(const Triple &TT, FeatureBitset FeatureBits, + if (TargetABI != ABI_Unknown) + return TargetABI; + +- // For now, default to the ilp32/ilp32e/lp64 ABI if no explicit ABI is given +- // or an invalid/unrecognised string is given. In the future, it might be +- // worth changing this to default to ilp32f/lp64f and ilp32d/lp64d when +- // hardware support for floating point is present. ++ if (IsRV32D) ++ return ABI_ILP32D; ++ if (IsRV32F) ++ return ABI_ILP32F; + if (IsRV32E) + return ABI_ILP32E; + if (IsRV64) diff --git a/llvm/outputs.patch b/llvm/outputs.patch new file mode 100644 index 00000000..878460e0 --- /dev/null +++ b/llvm/outputs.patch @@ -0,0 +1,16 @@ +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp +index 94d426b..37f7794 100644 +--- a/tools/llvm-config/llvm-config.cpp ++++ b/tools/llvm-config/llvm-config.cpp +@@ -333,6 +333,11 @@ int main(int argc, char **argv) { + ActiveIncludeOption = "-I" + ActiveIncludeDir; + } + ++ /// Nix-specific multiple-output handling: override ActiveLibDir ++ if (!IsInDevelopmentTree) { ++ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX; ++ } ++ + /// We only use `shared library` mode in cases where the static library form + /// of the components provided are not available; note however that this is + /// skipped if we're run from within the build dir. However, once installed,