From 782fc2ebac4bb51f6d86f9e998143585edc7d212 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 28 Mar 2024 11:24:06 -0700 Subject: [PATCH] llvmPackages_{12,13,14,15,16,17,18,git}: use common libcxx --- .../development/compilers/llvm/12/default.nix | 32 +++- .../compilers/llvm/12/libcxx/default.nix | 139 ----------------- .../development/compilers/llvm/13/default.nix | 19 ++- .../compilers/llvm/13/libcxx/default.nix | 135 ---------------- .../development/compilers/llvm/14/default.nix | 19 ++- .../development/compilers/llvm/15/default.nix | 27 +++- .../compilers/llvm/15/libcxx/default.nix | 145 ------------------ .../development/compilers/llvm/16/default.nix | 2 +- .../compilers/llvm/16/libcxx/default.nix | 125 --------------- .../development/compilers/llvm/17/default.nix | 12 +- .../compilers/llvm/17/libcxx/default.nix | 136 ---------------- .../development/compilers/llvm/18/default.nix | 6 +- .../compilers/llvm/18/libcxx/default.nix | 130 ---------------- .../llvm/{14 => common}/libcxx/default.nix | 110 +++++++------ .../compilers/llvm/git/default.nix | 6 +- .../compilers/llvm/git/libcxx/default.nix | 130 ---------------- 16 files changed, 173 insertions(+), 1000 deletions(-) delete mode 100644 pkgs/development/compilers/llvm/12/libcxx/default.nix delete mode 100644 pkgs/development/compilers/llvm/13/libcxx/default.nix delete mode 100644 pkgs/development/compilers/llvm/15/libcxx/default.nix delete mode 100644 pkgs/development/compilers/llvm/16/libcxx/default.nix delete mode 100644 pkgs/development/compilers/llvm/17/libcxx/default.nix delete mode 100644 pkgs/development/compilers/llvm/18/libcxx/default.nix rename pkgs/development/compilers/llvm/{14 => common}/libcxx/default.nix (64%) delete mode 100644 pkgs/development/compilers/llvm/git/libcxx/default.nix diff --git a/pkgs/development/compilers/llvm/12/default.nix b/pkgs/development/compilers/llvm/12/default.nix index d35d463f0bb6..f88f7cf7fa52 100644 --- a/pkgs/development/compilers/llvm/12/default.nix +++ b/pkgs/development/compilers/llvm/12/default.nix @@ -1,6 +1,6 @@ { lowPrio, newScope, pkgs, lib, stdenv, cmake , preLibcCrossHeaders -, fetchpatch +, substitute, fetchFromGitHub, fetchpatch , libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith , buildLlvmTools # tools, but from the previous stage, for cross , targetLlvmLibraries # libraries, but from the next stage, for cross @@ -254,7 +254,35 @@ let libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; - libcxx = callPackage ./libcxx { + libcxx = callPackage ../common/libcxx { + src = fetchFromGitHub { + owner = "llvm"; + repo = "llvm-project"; + rev = "refs/tags/llvmorg-${version}"; + sparseCheckout = [ + "libcxx" + "libcxxabi" + "llvm/cmake" + "llvm/utils" + "runtimes" + ]; + hash = "sha256-etxgXIdWxMTmbZ83Hsc0w6Jt5OSQSUEPVEWqLkHsNBY="; + }; + patches = [ + (substitute { + src = ../common/libcxxabi/wasm.patch; + replacements = [ + "--replace-fail" "/cmake/" "/llvm/cmake/" + ]; + }) + ] ++ lib.optionals stdenv.hostPlatform.isMusl [ + (substitute { + src = ../common/libcxx/libcxx-0001-musl-hacks.patch; + replacements = [ + "--replace-fail" "/include/" "/libcxx/include/" + ]; + }) + ]; inherit llvm_meta; stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; }; diff --git a/pkgs/development/compilers/llvm/12/libcxx/default.nix b/pkgs/development/compilers/llvm/12/libcxx/default.nix deleted file mode 100644 index 7c6174711456..000000000000 --- a/pkgs/development/compilers/llvm/12/libcxx/default.nix +++ /dev/null @@ -1,139 +0,0 @@ -{ lib, stdenv, llvm_meta -, fetchFromGitHub, runCommand, substitute -, cmake, lndir, ninja, python3, fixDarwinDylibNames, version -, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else null -, libcxxrt, libunwind -, enableShared ? !stdenv.hostPlatform.isStatic -}: - -# external cxxabi is not supported on Darwin as the build will not link libcxx -# properly and not re-export the cxxabi symbols into libcxx -# https://github.com/NixOS/nixpkgs/issues/166205 -# https://github.com/NixOS/nixpkgs/issues/269548 -assert cxxabi == null || !stdenv.hostPlatform.isDarwin; -let - basename = "libcxx"; - cxxabiName = "lib${if cxxabi == null then "cxxabi" else cxxabi.libName}"; - runtimes = [ "libcxx" ] ++ lib.optional (cxxabi == null) "libcxxabi"; - - # Note: useLLVM is likely false for Darwin but true under pkgsLLVM - useLLVM = stdenv.hostPlatform.useLLVM or false; - - cxxabiCMakeFlags = lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ - "-DLIBCXXABI_USE_COMPILER_RT=ON" - "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXXABI_ENABLE_THREADS=OFF" - "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared) [ - "-DLIBCXXABI_ENABLE_SHARED=OFF" - ]; - - cxxCMakeFlags = [ - "-DLIBCXX_CXX_ABI=${cxxabiName}" - ] ++ lib.optionals (cxxabi != null) [ - "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${lib.getDev cxxabi}/include" - ] ++ lib.optionals (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) [ - "-DLIBCXX_HAS_MUSL_LIBC=1" - ] ++ lib.optionals useLLVM [ - "-DLIBCXX_USE_COMPILER_RT=ON" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXX_ENABLE_THREADS=OFF" - "-DLIBCXX_ENABLE_FILESYSTEM=OFF" - "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared) [ - "-DLIBCXX_ENABLE_SHARED=OFF" - ]; - - cmakeFlags = [ - "-DLLVM_ENABLE_RUNTIMES=${lib.concatStringsSep ";" runtimes}" - ] ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ - # libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib, - # but that does not appear to be the case for example when building - # pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc). - "-DCMAKE_EXE_LINKER_FLAGS=-nostdlib" - "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DCMAKE_CXX_COMPILER_WORKS=ON" - "-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker - ] ++ cxxCMakeFlags - ++ lib.optionals (cxxabi == null) cxxabiCMakeFlags; - -in - -stdenv.mkDerivation rec { - pname = basename; - inherit version cmakeFlags; - - src = fetchFromGitHub { - owner = "llvm"; - repo = "llvm-project"; - rev = "refs/tags/llvmorg-${version}"; - sparseCheckout = [ - "libcxx" - "libcxxabi" - "llvm/cmake" - "llvm/utils" - "runtimes" - ]; - hash = "sha256-etxgXIdWxMTmbZ83Hsc0w6Jt5OSQSUEPVEWqLkHsNBY="; - }; - - outputs = [ "out" "dev" ]; - - patches = [ - (substitute { - src = ../../common/libcxxabi/wasm.patch; - replacements = [ - "--replace-fail" "/cmake/" "/llvm/cmake/" - ]; - }) - ] ++ lib.optionals stdenv.hostPlatform.isMusl [ - (substitute { - src = ../../common/libcxx/libcxx-0001-musl-hacks.patch; - replacements = [ - "--replace-fail" "/include/" "/libcxx/include/" - ]; - }) - ]; - - postPatch = '' - cd runtimes - ''; - - preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' - patchShebangs utils/cat_files.py - ''; - - nativeBuildInputs = [ cmake ninja python3 ] - ++ lib.optional stdenv.isDarwin fixDarwinDylibNames - ++ lib.optional (cxxabi != null) lndir; - - buildInputs = [ cxxabi ] - ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ libunwind ]; - - # libc++.so is a linker script which expands to multiple libraries, - # libc++.so.1 and libc++abi.so or the external cxxabi. ld-wrapper doesn't - # support linker scripts so the external cxxabi needs to be symlinked in - postInstall = lib.optionalString (cxxabi != null) '' - lndir ${lib.getDev cxxabi}/include $out/include/c++/v1 - lndir ${lib.getLib cxxabi}/lib $out/lib - ''; - - passthru = { - isLLVM = true; - }; - - meta = llvm_meta // { - homepage = "https://libcxx.llvm.org/"; - description = "C++ standard library"; - longDescription = '' - libc++ is an implementation of the C++ standard library, targeting C++11, - C++14 and above. - ''; - # "All of the code in libc++ is dual licensed under the MIT license and the - # UIUC License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; - }; -} diff --git a/pkgs/development/compilers/llvm/13/default.nix b/pkgs/development/compilers/llvm/13/default.nix index 2f314e67bf90..a93a8819567c 100644 --- a/pkgs/development/compilers/llvm/13/default.nix +++ b/pkgs/development/compilers/llvm/13/default.nix @@ -1,7 +1,7 @@ { lowPrio, newScope, pkgs, lib, stdenv, cmake , preLibcCrossHeaders , fetchpatch -, libxml2, python3, isl, fetchFromGitHub, overrideCC, wrapCCWith, wrapBintoolsWith +, libxml2, python3, isl, fetchFromGitHub, substitute, overrideCC, wrapCCWith, wrapBintoolsWith , buildLlvmTools # tools, but from the previous stage, for cross , targetLlvmLibraries # libraries, but from the next stage, for cross , targetLlvm @@ -291,7 +291,22 @@ in let libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; - libcxx = callPackage ./libcxx { + libcxx = callPackage ../common/libcxx { + patches = [ + (substitute { + src = ../common/libcxxabi/wasm.patch; + replacements = [ + "--replace-fail" "/cmake/" "/llvm/cmake/" + ]; + }) + ] ++ lib.optionals stdenv.hostPlatform.isMusl [ + (substitute { + src = ../common/libcxx/libcxx-0001-musl-hacks.patch; + replacements = [ + "--replace-fail" "/include/" "/libcxx/include/" + ]; + }) + ]; inherit llvm_meta; stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; monorepoSrc = src; diff --git a/pkgs/development/compilers/llvm/13/libcxx/default.nix b/pkgs/development/compilers/llvm/13/libcxx/default.nix deleted file mode 100644 index b39b4f37ff1c..000000000000 --- a/pkgs/development/compilers/llvm/13/libcxx/default.nix +++ /dev/null @@ -1,135 +0,0 @@ -{ lib, stdenv, llvm_meta -, monorepoSrc, runCommand, substitute -, cmake, lndir, ninja, python3, fixDarwinDylibNames, version -, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else null -, libcxxrt, libunwind -, enableShared ? !stdenv.hostPlatform.isStatic -}: - -# external cxxabi is not supported on Darwin as the build will not link libcxx -# properly and not re-export the cxxabi symbols into libcxx -# https://github.com/NixOS/nixpkgs/issues/166205 -# https://github.com/NixOS/nixpkgs/issues/269548 -assert cxxabi == null || !stdenv.hostPlatform.isDarwin; -let - basename = "libcxx"; - cxxabiName = "lib${if cxxabi == null then "cxxabi" else cxxabi.libName}"; - runtimes = [ "libcxx" ] ++ lib.optional (cxxabi == null) "libcxxabi"; - - # Note: useLLVM is likely false for Darwin but true under pkgsLLVM - useLLVM = stdenv.hostPlatform.useLLVM or false; - - cxxabiCMakeFlags = lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ - "-DLIBCXXABI_USE_COMPILER_RT=ON" - "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXXABI_ENABLE_THREADS=OFF" - "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared) [ - "-DLIBCXXABI_ENABLE_SHARED=OFF" - ]; - - cxxCMakeFlags = [ - "-DLIBCXX_CXX_ABI=${cxxabiName}" - ] ++ lib.optionals (cxxabi != null) [ - "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${lib.getDev cxxabi}/include" - ] ++ lib.optionals (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) [ - "-DLIBCXX_HAS_MUSL_LIBC=1" - ] ++ lib.optionals useLLVM [ - "-DLIBCXX_USE_COMPILER_RT=ON" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXX_ENABLE_THREADS=OFF" - "-DLIBCXX_ENABLE_FILESYSTEM=OFF" - "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared) [ - "-DLIBCXX_ENABLE_SHARED=OFF" - ]; - - cmakeFlags = [ - "-DLLVM_ENABLE_RUNTIMES=${lib.concatStringsSep ";" runtimes}" - ] ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ - # libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib, - # but that does not appear to be the case for example when building - # pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc). - "-DCMAKE_EXE_LINKER_FLAGS=-nostdlib" - "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DCMAKE_CXX_COMPILER_WORKS=ON" - "-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker - ] ++ cxxCMakeFlags - ++ lib.optionals (cxxabi == null) cxxabiCMakeFlags; - -in - -stdenv.mkDerivation rec { - pname = basename; - inherit version cmakeFlags; - - src = runCommand "${pname}-src-${version}" {} ('' - mkdir -p "$out/llvm" - cp -r ${monorepoSrc}/libcxx "$out" - cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" - cp -r ${monorepoSrc}/llvm/utils "$out/llvm" - cp -r ${monorepoSrc}/runtimes "$out" - '' + lib.optionalString (cxxabi == null) '' - cp -r ${monorepoSrc}/libcxxabi "$out" - ''); - - outputs = [ "out" "dev" ]; - - patches = [ - (substitute { - src = ../../common/libcxxabi/wasm.patch; - replacements = [ - "--replace-fail" "/cmake/" "/llvm/cmake/" - ]; - }) - ] ++ lib.optionals stdenv.hostPlatform.isMusl [ - (substitute { - src = ../../common/libcxx/libcxx-0001-musl-hacks.patch; - replacements = [ - "--replace-fail" "/include/" "/libcxx/include/" - ]; - }) - ]; - - postPatch = '' - cd runtimes - ''; - - preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' - patchShebangs utils/cat_files.py - ''; - - nativeBuildInputs = [ cmake ninja python3 ] - ++ lib.optional stdenv.isDarwin fixDarwinDylibNames - ++ lib.optional (cxxabi != null) lndir; - - buildInputs = [ cxxabi ] - ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ libunwind ]; - - # libc++.so is a linker script which expands to multiple libraries, - # libc++.so.1 and libc++abi.so or the external cxxabi. ld-wrapper doesn't - # support linker scripts so the external cxxabi needs to be symlinked in - postInstall = lib.optionalString (cxxabi != null) '' - lndir ${lib.getDev cxxabi}/include ''${!outputDev}/include/c++/v1 - lndir ${lib.getLib cxxabi}/lib ''${!outputLib}/lib - ''; - - passthru = { - isLLVM = true; - }; - - meta = llvm_meta // { - homepage = "https://libcxx.llvm.org/"; - description = "C++ standard library"; - longDescription = '' - libc++ is an implementation of the C++ standard library, targeting C++11, - C++14 and above. - ''; - # "All of the code in libc++ is dual licensed under the MIT license and the - # UIUC License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; - }; -} diff --git a/pkgs/development/compilers/llvm/14/default.nix b/pkgs/development/compilers/llvm/14/default.nix index 158cd60c03d2..dc26d47f7486 100644 --- a/pkgs/development/compilers/llvm/14/default.nix +++ b/pkgs/development/compilers/llvm/14/default.nix @@ -1,6 +1,6 @@ { lowPrio, newScope, pkgs, lib, stdenv, cmake , preLibcCrossHeaders -, libxml2, python3, fetchFromGitHub, overrideCC, wrapCCWith, wrapBintoolsWith +, libxml2, python3, fetchFromGitHub, substitute, overrideCC, wrapCCWith, wrapBintoolsWith , buildLlvmTools # tools, but from the previous stage, for cross , targetLlvmLibraries # libraries, but from the next stage, for cross , targetLlvm @@ -289,7 +289,22 @@ in let libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; - libcxx = callPackage ./libcxx { + libcxx = callPackage ../common/libcxx { + patches = [ + (substitute { + src = ../common/libcxxabi/wasm.patch; + replacements = [ + "--replace-fail" "/cmake/" "/llvm/cmake/" + ]; + }) + ] ++ lib.optionals stdenv.hostPlatform.isMusl [ + (substitute { + src = ../common/libcxx/libcxx-0001-musl-hacks.patch; + replacements = [ + "--replace-fail" "/include/" "/libcxx/include/" + ]; + }) + ]; inherit llvm_meta; stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; }; diff --git a/pkgs/development/compilers/llvm/15/default.nix b/pkgs/development/compilers/llvm/15/default.nix index 3c4d656a8f32..8f49b7e0625e 100644 --- a/pkgs/development/compilers/llvm/15/default.nix +++ b/pkgs/development/compilers/llvm/15/default.nix @@ -1,6 +1,6 @@ { lowPrio, newScope, pkgs, lib, stdenv, cmake, ninja , preLibcCrossHeaders -, libxml2, python3, fetchFromGitHub, overrideCC, wrapCCWith, wrapBintoolsWith +, libxml2, python3, fetchFromGitHub, fetchpatch, substitute, overrideCC, wrapCCWith, wrapBintoolsWith , buildLlvmTools # tools, but from the previous stage, for cross , targetLlvmLibraries # libraries, but from the next stage, for cross , targetLlvm @@ -307,7 +307,30 @@ in let # `libcxx` requires a fairly modern C++ compiler, # so: we use the clang from this LLVM package set instead of the regular # stdenv's compiler. - libcxx = callPackage ./libcxx { + libcxx = callPackage ../common/libcxx { + patches = [ + # See: + # - https://reviews.llvm.org/D133566 + # - https://github.com/NixOS/nixpkgs/issues/214524#issuecomment-1429146432 + # !!! Drop in LLVM 16+ + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/57c7bb3ec89565c68f858d316504668f9d214d59.patch"; + hash = "sha256-B07vHmSjy5BhhkGSj3e1E0XmMv5/9+mvC/k70Z29VwY="; + }) + (substitute { + src = ../common/libcxxabi/wasm.patch; + replacements = [ + "--replace-fail" "/cmake/" "/llvm/cmake/" + ]; + }) + ] ++ lib.optionals stdenv.hostPlatform.isMusl [ + (substitute { + src = ../common/libcxx/libcxx-0001-musl-hacks.patch; + replacements = [ + "--replace-fail" "/include/" "/libcxx/include/" + ]; + }) + ]; inherit llvm_meta; stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; }; diff --git a/pkgs/development/compilers/llvm/15/libcxx/default.nix b/pkgs/development/compilers/llvm/15/libcxx/default.nix deleted file mode 100644 index 89181bcbdbbf..000000000000 --- a/pkgs/development/compilers/llvm/15/libcxx/default.nix +++ /dev/null @@ -1,145 +0,0 @@ -{ lib, stdenv, llvm_meta -, monorepoSrc, runCommand, fetchpatch, substitute -, cmake, lndir, ninja, python3, fixDarwinDylibNames, version -, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else null -, libcxxrt, libunwind -, enableShared ? !stdenv.hostPlatform.isStatic -}: - -# external cxxabi is not supported on Darwin as the build will not link libcxx -# properly and not re-export the cxxabi symbols into libcxx -# https://github.com/NixOS/nixpkgs/issues/166205 -# https://github.com/NixOS/nixpkgs/issues/269548 -assert cxxabi == null || !stdenv.hostPlatform.isDarwin; -let - basename = "libcxx"; - cxxabiName = "lib${if cxxabi == null then "cxxabi" else cxxabi.libName}"; - runtimes = [ "libcxx" ] ++ lib.optional (cxxabi == null) "libcxxabi"; - - # Note: useLLVM is likely false for Darwin but true under pkgsLLVM - useLLVM = stdenv.hostPlatform.useLLVM or false; - - cxxabiCMakeFlags = lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ - "-DLIBCXXABI_USE_COMPILER_RT=ON" - "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXXABI_ENABLE_THREADS=OFF" - "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared) [ - "-DLIBCXXABI_ENABLE_SHARED=OFF" - ]; - - cxxCMakeFlags = [ - "-DLIBCXX_CXX_ABI=${cxxabiName}" - ] ++ lib.optionals (cxxabi != null) [ - "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${lib.getDev cxxabi}/include" - ] ++ lib.optionals (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) [ - "-DLIBCXX_HAS_MUSL_LIBC=1" - ] ++ lib.optionals useLLVM [ - "-DLIBCXX_USE_COMPILER_RT=ON" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXX_ENABLE_THREADS=OFF" - "-DLIBCXX_ENABLE_FILESYSTEM=OFF" - "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared) [ - "-DLIBCXX_ENABLE_SHARED=OFF" - ]; - - cmakeFlags = [ - "-DLLVM_ENABLE_RUNTIMES=${lib.concatStringsSep ";" runtimes}" - ] ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ - # libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib, - # but that does not appear to be the case for example when building - # pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc). - "-DCMAKE_EXE_LINKER_FLAGS=-nostdlib" - "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DCMAKE_CXX_COMPILER_WORKS=ON" - "-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker - ] ++ cxxCMakeFlags - ++ lib.optionals (cxxabi == null) cxxabiCMakeFlags; - -in - -stdenv.mkDerivation rec { - pname = basename; - inherit version cmakeFlags; - - src = runCommand "${pname}-src-${version}" {} ('' - mkdir -p "$out/llvm" - cp -r ${monorepoSrc}/cmake "$out" - cp -r ${monorepoSrc}/libcxx "$out" - cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" - cp -r ${monorepoSrc}/llvm/utils "$out/llvm" - cp -r ${monorepoSrc}/third-party "$out" - cp -r ${monorepoSrc}/runtimes "$out" - '' + lib.optionalString (cxxabi == null) '' - cp -r ${monorepoSrc}/libcxxabi "$out" - ''); - - outputs = [ "out" "dev" ]; - - patches = [ - # See: - # - https://reviews.llvm.org/D133566 - # - https://github.com/NixOS/nixpkgs/issues/214524#issuecomment-1429146432 - # !!! Drop in LLVM 16+ - (fetchpatch { - url = "https://github.com/llvm/llvm-project/commit/57c7bb3ec89565c68f858d316504668f9d214d59.patch"; - hash = "sha256-B07vHmSjy5BhhkGSj3e1E0XmMv5/9+mvC/k70Z29VwY="; - }) - (substitute { - src = ../../common/libcxxabi/wasm.patch; - replacements = [ - "--replace-fail" "/cmake/" "/llvm/cmake/" - ]; - }) - ] ++ lib.optionals stdenv.hostPlatform.isMusl [ - (substitute { - src = ../../common/libcxx/libcxx-0001-musl-hacks.patch; - replacements = [ - "--replace-fail" "/include/" "/libcxx/include/" - ]; - }) - ]; - - postPatch = '' - cd runtimes - ''; - - preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' - patchShebangs utils/cat_files.py - ''; - - nativeBuildInputs = [ cmake ninja python3 ] - ++ lib.optional stdenv.isDarwin fixDarwinDylibNames - ++ lib.optional (cxxabi != null) lndir; - - buildInputs = [ cxxabi ] - ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ libunwind ]; - - # libc++.so is a linker script which expands to multiple libraries, - # libc++.so.1 and libc++abi.so or the external cxxabi. ld-wrapper doesn't - # support linker scripts so the external cxxabi needs to be symlinked in - postInstall = lib.optionalString (cxxabi != null) '' - lndir ${lib.getDev cxxabi}/include ''${!outputDev}/include/c++/v1 - lndir ${lib.getLib cxxabi}/lib ''${!outputLib}/lib - ''; - - passthru = { - isLLVM = true; - }; - - meta = llvm_meta // { - homepage = "https://libcxx.llvm.org/"; - description = "C++ standard library"; - longDescription = '' - libc++ is an implementation of the C++ standard library, targeting C++11, - C++14 and above. - ''; - # "All of the code in libc++ is dual licensed under the MIT license and the - # UIUC License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; - }; -} diff --git a/pkgs/development/compilers/llvm/16/default.nix b/pkgs/development/compilers/llvm/16/default.nix index 2028b48bd080..cdff909ba9fb 100644 --- a/pkgs/development/compilers/llvm/16/default.nix +++ b/pkgs/development/compilers/llvm/16/default.nix @@ -322,7 +322,7 @@ in let # `libcxx` requires a fairly modern C++ compiler, # so: we use the clang from this LLVM package set instead of the regular # stdenv's compiler. - libcxx = callPackage ./libcxx { + libcxx = callPackage ../common/libcxx { inherit llvm_meta; stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; }; diff --git a/pkgs/development/compilers/llvm/16/libcxx/default.nix b/pkgs/development/compilers/llvm/16/libcxx/default.nix deleted file mode 100644 index 146424113ec4..000000000000 --- a/pkgs/development/compilers/llvm/16/libcxx/default.nix +++ /dev/null @@ -1,125 +0,0 @@ -{ lib, stdenv, llvm_meta -, monorepoSrc, runCommand, fetchpatch -, cmake, lndir, ninja, python3, fixDarwinDylibNames, version -, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else null -, libcxxrt, libunwind -, enableShared ? !stdenv.hostPlatform.isStatic -}: - -# external cxxabi is not supported on Darwin as the build will not link libcxx -# properly and not re-export the cxxabi symbols into libcxx -# https://github.com/NixOS/nixpkgs/issues/166205 -# https://github.com/NixOS/nixpkgs/issues/269548 -assert cxxabi == null || !stdenv.hostPlatform.isDarwin; -let - basename = "libcxx"; - cxxabiName = "lib${if cxxabi == null then "cxxabi" else cxxabi.libName}"; - runtimes = [ "libcxx" ] ++ lib.optional (cxxabi == null) "libcxxabi"; - - # Note: useLLVM is likely false for Darwin but true under pkgsLLVM - useLLVM = stdenv.hostPlatform.useLLVM or false; - - cxxabiCMakeFlags = lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ - "-DLIBCXXABI_USE_COMPILER_RT=ON" - "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXXABI_ENABLE_THREADS=OFF" - "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared) [ - "-DLIBCXXABI_ENABLE_SHARED=OFF" - ]; - - cxxCMakeFlags = [ - "-DLIBCXX_CXX_ABI=${cxxabiName}" - ] ++ lib.optionals (cxxabi != null) [ - "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${lib.getDev cxxabi}/include" - ] ++ lib.optionals (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) [ - "-DLIBCXX_HAS_MUSL_LIBC=1" - ] ++ lib.optionals useLLVM [ - "-DLIBCXX_USE_COMPILER_RT=ON" - # There's precedent for this in llvm-project/libcxx/cmake/caches. - # In a monorepo build you might do the following in the libcxxabi build: - # -DLLVM_ENABLE_PROJECTS=libcxxabi;libunwinder - # -DLIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY=On - # libcxx appears to require unwind and doesn't pull it in via other means. - "-DLIBCXX_ADDITIONAL_LIBRARIES=unwind" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXX_ENABLE_THREADS=OFF" - "-DLIBCXX_ENABLE_FILESYSTEM=OFF" - "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared) [ - "-DLIBCXX_ENABLE_SHARED=OFF" - ]; - - cmakeFlags = [ - "-DLLVM_ENABLE_RUNTIMES=${lib.concatStringsSep ";" runtimes}" - ] ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ - # libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib, - # but that does not appear to be the case for example when building - # pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc). - "-DCMAKE_EXE_LINKER_FLAGS=-nostdlib" - "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DCMAKE_CXX_COMPILER_WORKS=ON" - "-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker - ] ++ cxxCMakeFlags - ++ lib.optionals (cxxabi == null) cxxabiCMakeFlags; - -in - -stdenv.mkDerivation rec { - pname = basename; - inherit version cmakeFlags; - - src = runCommand "${pname}-src-${version}" {} ('' - mkdir -p "$out/llvm" - cp -r ${monorepoSrc}/cmake "$out" - cp -r ${monorepoSrc}/libcxx "$out" - cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" - cp -r ${monorepoSrc}/llvm/utils "$out/llvm" - cp -r ${monorepoSrc}/third-party "$out" - cp -r ${monorepoSrc}/runtimes "$out" - '' + lib.optionalString (cxxabi == null) '' - cp -r ${monorepoSrc}/libcxxabi "$out" - ''); - - sourceRoot = "${src.name}/runtimes"; - - outputs = [ "out" "dev" ]; - - preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' - patchShebangs utils/cat_files.py - ''; - - nativeBuildInputs = [ cmake ninja python3 ] - ++ lib.optional stdenv.isDarwin fixDarwinDylibNames - ++ lib.optional (cxxabi != null) lndir; - - buildInputs = [ cxxabi ] - ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ libunwind ]; - - # libc++.so is a linker script which expands to multiple libraries, - # libc++.so.1 and libc++abi.so or the external cxxabi. ld-wrapper doesn't - # support linker scripts so the external cxxabi needs to be symlinked in - postInstall = lib.optionalString (cxxabi != null) '' - lndir ${lib.getDev cxxabi}/include ''${!outputDev}/include/c++/v1 - lndir ${lib.getLib cxxabi}/lib ''${!outputLib}/lib - ''; - - passthru = { - isLLVM = true; - }; - - meta = llvm_meta // { - homepage = "https://libcxx.llvm.org/"; - description = "C++ standard library"; - longDescription = '' - libc++ is an implementation of the C++ standard library, targeting C++11, - C++14 and above. - ''; - # "All of the code in libc++ is dual licensed under the MIT license and the - # UIUC License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; - }; -} diff --git a/pkgs/development/compilers/llvm/17/default.nix b/pkgs/development/compilers/llvm/17/default.nix index 42888dcc951a..9e3d8391bbea 100644 --- a/pkgs/development/compilers/llvm/17/default.nix +++ b/pkgs/development/compilers/llvm/17/default.nix @@ -1,6 +1,6 @@ { lowPrio, newScope, pkgs, lib, stdenv, cmake, ninja , preLibcCrossHeaders -, libxml2, python3, fetchFromGitHub, overrideCC, wrapCCWith, wrapBintoolsWith +, libxml2, python3, fetchFromGitHub, fetchpatch, overrideCC, wrapCCWith, wrapBintoolsWith , buildLlvmTools # tools, but from the previous stage, for cross , targetLlvmLibraries # libraries, but from the next stage, for cross , targetLlvm @@ -307,7 +307,15 @@ in let # `libcxx` requires a fairly modern C++ compiler, # so: we use the clang from this LLVM package set instead of the regular # stdenv's compiler. - libcxx = callPackage ./libcxx { + libcxx = callPackage ../common/libcxx { + patches = lib.optionals (stdenv.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13") [ + # https://github.com/llvm/llvm-project/issues/64226 + (fetchpatch { + name = "0042-mbstate_t-not-defined.patch"; + url = "https://github.com/macports/macports-ports/raw/acd8acb171f1658596ed1cf25da48d5b932e2d19/lang/llvm-17/files/0042-mbstate_t-not-defined.patch"; + hash = "sha256-jo+DYA6zuSv9OH3A0bYwY5TlkWprup4OKQ7rfK1WHBI="; + }) + ]; inherit llvm_meta; stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; }; diff --git a/pkgs/development/compilers/llvm/17/libcxx/default.nix b/pkgs/development/compilers/llvm/17/libcxx/default.nix deleted file mode 100644 index 9ee4fd180d4b..000000000000 --- a/pkgs/development/compilers/llvm/17/libcxx/default.nix +++ /dev/null @@ -1,136 +0,0 @@ -{ lib, stdenv, llvm_meta -, monorepoSrc, runCommand, fetchpatch -, cmake, lndir, ninja, python3, fixDarwinDylibNames, version -, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else null -, libcxxrt, libunwind -, enableShared ? !stdenv.hostPlatform.isStatic -}: - -# external cxxabi is not supported on Darwin as the build will not link libcxx -# properly and not re-export the cxxabi symbols into libcxx -# https://github.com/NixOS/nixpkgs/issues/166205 -# https://github.com/NixOS/nixpkgs/issues/269548 -assert cxxabi == null || !stdenv.hostPlatform.isDarwin; -let - basename = "libcxx"; - cxxabiName = "lib${if cxxabi == null then "cxxabi" else cxxabi.libName}"; - runtimes = [ "libcxx" ] ++ lib.optional (cxxabi == null) "libcxxabi"; - - # Note: useLLVM is likely false for Darwin but true under pkgsLLVM - useLLVM = stdenv.hostPlatform.useLLVM or false; - - cxxabiCMakeFlags = lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ - "-DLIBCXXABI_USE_COMPILER_RT=ON" - "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXXABI_ENABLE_THREADS=OFF" - "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared) [ - "-DLIBCXXABI_ENABLE_SHARED=OFF" - ]; - - cxxCMakeFlags = [ - "-DLIBCXX_CXX_ABI=${cxxabiName}" - ] ++ lib.optionals (cxxabi != null) [ - "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${lib.getDev cxxabi}/include" - ] ++ lib.optionals (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) [ - "-DLIBCXX_HAS_MUSL_LIBC=1" - ] ++ lib.optionals useLLVM [ - "-DLIBCXX_USE_COMPILER_RT=ON" - # There's precedent for this in llvm-project/libcxx/cmake/caches. - # In a monorepo build you might do the following in the libcxxabi build: - # -DLLVM_ENABLE_PROJECTS=libcxxabi;libunwinder - # -DLIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY=On - # libcxx appears to require unwind and doesn't pull it in via other means. - "-DLIBCXX_ADDITIONAL_LIBRARIES=unwind" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXX_ENABLE_THREADS=OFF" - "-DLIBCXX_ENABLE_FILESYSTEM=OFF" - "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared) [ - "-DLIBCXX_ENABLE_SHARED=OFF" - ]; - - cmakeFlags = [ - "-DLLVM_ENABLE_RUNTIMES=${lib.concatStringsSep ";" runtimes}" - ] ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ - # libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib, - # but that does not appear to be the case for example when building - # pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc). - "-DCMAKE_EXE_LINKER_FLAGS=-nostdlib" - "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DCMAKE_CXX_COMPILER_WORKS=ON" - "-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker - ] ++ cxxCMakeFlags - ++ lib.optionals (cxxabi == null) cxxabiCMakeFlags; - -in - -stdenv.mkDerivation rec { - pname = basename; - inherit version cmakeFlags; - - src = runCommand "${pname}-src-${version}" {} ('' - mkdir -p "$out/llvm" - cp -r ${monorepoSrc}/cmake "$out" - cp -r ${monorepoSrc}/libcxx "$out" - cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" - cp -r ${monorepoSrc}/llvm/utils "$out/llvm" - cp -r ${monorepoSrc}/third-party "$out" - cp -r ${monorepoSrc}/runtimes "$out" - '' + lib.optionalString (cxxabi == null) '' - cp -r ${monorepoSrc}/libcxxabi "$out" - ''); - - outputs = [ "out" "dev" ]; - - patches = lib.optionals (stdenv.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13") [ - # https://github.com/llvm/llvm-project/issues/64226 - (fetchpatch { - name = "0042-mbstate_t-not-defined.patch"; - url = "https://github.com/macports/macports-ports/raw/acd8acb171f1658596ed1cf25da48d5b932e2d19/lang/llvm-17/files/0042-mbstate_t-not-defined.patch"; - hash = "sha256-jo+DYA6zuSv9OH3A0bYwY5TlkWprup4OKQ7rfK1WHBI="; - }) - ]; - - postPatch = '' - cd runtimes - ''; - - preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' - patchShebangs utils/cat_files.py - ''; - - nativeBuildInputs = [ cmake ninja python3 ] - ++ lib.optional stdenv.isDarwin fixDarwinDylibNames - ++ lib.optional (cxxabi != null) lndir; - - buildInputs = [ cxxabi ] - ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ libunwind ]; - - # libc++.so is a linker script which expands to multiple libraries, - # libc++.so.1 and libc++abi.so or the external cxxabi. ld-wrapper doesn't - # support linker scripts so the external cxxabi needs to be symlinked in - postInstall = lib.optionalString (cxxabi != null) '' - lndir ${lib.getDev cxxabi}/include ''${!outputDev}/include/c++/v1 - lndir ${lib.getLib cxxabi}/lib ''${!outputLib}/lib - ''; - - passthru = { - isLLVM = true; - }; - - meta = llvm_meta // { - homepage = "https://libcxx.llvm.org/"; - description = "C++ standard library"; - longDescription = '' - libc++ is an implementation of the C++ standard library, targeting C++11, - C++14 and above. - ''; - # "All of the code in libc++ is dual licensed under the MIT license and the - # UIUC License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; - }; -} diff --git a/pkgs/development/compilers/llvm/18/default.nix b/pkgs/development/compilers/llvm/18/default.nix index f34d4f58a02a..bc00ecf18d5f 100644 --- a/pkgs/development/compilers/llvm/18/default.nix +++ b/pkgs/development/compilers/llvm/18/default.nix @@ -307,7 +307,11 @@ in let # `libcxx` requires a fairly modern C++ compiler, # so: we use the clang from this LLVM package set instead of the regular # stdenv's compiler. - libcxx = callPackage ./libcxx { + libcxx = callPackage ../common/libcxx { + patches = lib.optionals (stdenv.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13") [ + # https://github.com/llvm/llvm-project/issues/64226 + ./libcxx/0001-darwin-10.12-mbstate_t-fix.patch + ]; inherit llvm_meta; stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; }; diff --git a/pkgs/development/compilers/llvm/18/libcxx/default.nix b/pkgs/development/compilers/llvm/18/libcxx/default.nix deleted file mode 100644 index d6c304c0b476..000000000000 --- a/pkgs/development/compilers/llvm/18/libcxx/default.nix +++ /dev/null @@ -1,130 +0,0 @@ -{ lib, stdenv, llvm_meta -, monorepoSrc, runCommand -, cmake, lndir, ninja, python3, fixDarwinDylibNames, version -, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else null -, libcxxrt, libunwind -, enableShared ? !stdenv.hostPlatform.isStatic -}: - -# external cxxabi is not supported on Darwin as the build will not link libcxx -# properly and not re-export the cxxabi symbols into libcxx -# https://github.com/NixOS/nixpkgs/issues/166205 -# https://github.com/NixOS/nixpkgs/issues/269548 -assert cxxabi == null || !stdenv.hostPlatform.isDarwin; -let - basename = "libcxx"; - cxxabiName = "lib${if cxxabi == null then "cxxabi" else cxxabi.libName}"; - runtimes = [ "libcxx" ] ++ lib.optional (cxxabi == null) "libcxxabi"; - - # Note: useLLVM is likely false for Darwin but true under pkgsLLVM - useLLVM = stdenv.hostPlatform.useLLVM or false; - - cxxabiCMakeFlags = [ - "-DLIBCXXABI_USE_LLVM_UNWINDER=OFF" - ] ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ - "-DLIBCXXABI_ADDITIONAL_LIBRARIES=unwind" - "-DLIBCXXABI_USE_COMPILER_RT=ON" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXXABI_ENABLE_THREADS=OFF" - "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared) [ - "-DLIBCXXABI_ENABLE_SHARED=OFF" - ]; - - cxxCMakeFlags = [ - "-DLIBCXX_CXX_ABI=${cxxabiName}" - ] ++ lib.optionals (cxxabi != null) [ - "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${lib.getDev cxxabi}/include" - ] ++ lib.optionals (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) [ - "-DLIBCXX_HAS_MUSL_LIBC=1" - ] ++ lib.optionals (lib.versionAtLeast version "18" && !useLLVM && stdenv.hostPlatform.libc == "glibc" && !stdenv.hostPlatform.isStatic) [ - "-DLIBCXX_ADDITIONAL_LIBRARIES=gcc_s" - ] ++ lib.optionals useLLVM [ - "-DLIBCXX_USE_COMPILER_RT=ON" - # There's precedent for this in llvm-project/libcxx/cmake/caches. - # In a monorepo build you might do the following in the libcxxabi build: - # -DLLVM_ENABLE_PROJECTS=libcxxabi;libunwinder - # -DLIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY=On - # libcxx appears to require unwind and doesn't pull it in via other means. - "-DLIBCXX_ADDITIONAL_LIBRARIES=unwind" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXX_ENABLE_THREADS=OFF" - "-DLIBCXX_ENABLE_FILESYSTEM=OFF" - "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared) [ - "-DLIBCXX_ENABLE_SHARED=OFF" - ]; - - cmakeFlags = [ - "-DLLVM_ENABLE_RUNTIMES=${lib.concatStringsSep ";" runtimes}" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DCMAKE_CXX_COMPILER_WORKS=ON" - "-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker - ] ++ cxxCMakeFlags - ++ lib.optionals (cxxabi == null) cxxabiCMakeFlags; - -in - -stdenv.mkDerivation rec { - pname = basename; - inherit version cmakeFlags; - - src = runCommand "${pname}-src-${version}" {} ('' - mkdir -p "$out/llvm" - cp -r ${monorepoSrc}/cmake "$out" - cp -r ${monorepoSrc}/libcxx "$out" - cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" - cp -r ${monorepoSrc}/llvm/utils "$out/llvm" - cp -r ${monorepoSrc}/third-party "$out" - cp -r ${monorepoSrc}/runtimes "$out" - '' + lib.optionalString (cxxabi == null) '' - cp -r ${monorepoSrc}/libcxxabi "$out" - ''); - - outputs = [ "out" "dev" ]; - - patches = lib.optionals (stdenv.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13") [ - # https://github.com/llvm/llvm-project/issues/64226 - ./0001-darwin-10.12-mbstate_t-fix.patch - ]; - - postPatch = '' - cd runtimes - ''; - - preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' - patchShebangs utils/cat_files.py - ''; - - nativeBuildInputs = [ cmake ninja python3 ] - ++ lib.optional stdenv.isDarwin fixDarwinDylibNames - ++ lib.optional (cxxabi != null) lndir; - - buildInputs = [ cxxabi ] - ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ libunwind ]; - - # libc++.so is a linker script which expands to multiple libraries, - # libc++.so.1 and libc++abi.so or the external cxxabi. ld-wrapper doesn't - # support linker scripts so the external cxxabi needs to be symlinked in - postInstall = lib.optionalString (cxxabi != null) '' - lndir ${lib.getDev cxxabi}/include ''${!outputDev}/include/c++/v1 - lndir ${lib.getLib cxxabi}/lib ''${!outputLib}/lib - ''; - - passthru = { - isLLVM = true; - }; - - meta = llvm_meta // { - homepage = "https://libcxx.llvm.org/"; - description = "C++ standard library"; - longDescription = '' - libc++ is an implementation of the C++ standard library, targeting C++11, - C++14 and above. - ''; - # "All of the code in libc++ is dual licensed under the MIT license and the - # UIUC License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; - }; -} diff --git a/pkgs/development/compilers/llvm/14/libcxx/default.nix b/pkgs/development/compilers/llvm/common/libcxx/default.nix similarity index 64% rename from pkgs/development/compilers/llvm/14/libcxx/default.nix rename to pkgs/development/compilers/llvm/common/libcxx/default.nix index 79eeadb1c593..de895125f883 100644 --- a/pkgs/development/compilers/llvm/14/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/common/libcxx/default.nix @@ -1,8 +1,21 @@ -{ lib, stdenv, llvm_meta -, monorepoSrc, runCommand, substitute -, cmake, lndir, ninja, python3, fixDarwinDylibNames, version +{ lib +, stdenv +, llvm_meta +, release_version +, monorepoSrc ? null +, src ? null +, patches ? [] +, runCommand +, substitute +, cmake +, lndir +, ninja +, python3 +, fixDarwinDylibNames +, version , cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else null -, libcxxrt, libunwind +, libcxxrt +, libunwind , enableShared ? !stdenv.hostPlatform.isStatic }: @@ -13,16 +26,39 @@ assert cxxabi == null || !stdenv.hostPlatform.isDarwin; let basename = "libcxx"; + pname = basename; cxxabiName = "lib${if cxxabi == null then "cxxabi" else cxxabi.libName}"; runtimes = [ "libcxx" ] ++ lib.optional (cxxabi == null) "libcxxabi"; # Note: useLLVM is likely false for Darwin but true under pkgsLLVM useLLVM = stdenv.hostPlatform.useLLVM or false; - cxxabiCMakeFlags = lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ + src' = if monorepoSrc != null then + runCommand "${pname}-src-${version}" {} ('' + mkdir -p "$out/llvm" + '' + (lib.optionalString (lib.versionAtLeast release_version "14") '' + cp -r ${monorepoSrc}/cmake "$out" + '') + '' + cp -r ${monorepoSrc}/libcxx "$out" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" + '' + (lib.optionalString (lib.versionAtLeast release_version "14") '' + cp -r ${monorepoSrc}/third-party "$out" + '') + '' + cp -r ${monorepoSrc}/runtimes "$out" + '' + (lib.optionalString (cxxabi == null) '' + cp -r ${monorepoSrc}/libcxxabi "$out" + '')) else src; + + cxxabiCMakeFlags = lib.optionals (lib.versionAtLeast release_version "18") [ + "-DLIBCXXABI_USE_LLVM_UNWINDER=OFF" + ] ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) (if lib.versionAtLeast release_version "18" then [ + "-DLIBCXXABI_ADDITIONAL_LIBRARIES=unwind" + "-DLIBCXXABI_USE_COMPILER_RT=ON" + ] else [ "-DLIBCXXABI_USE_COMPILER_RT=ON" "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + ]) ++ lib.optionals stdenv.hostPlatform.isWasm [ "-DLIBCXXABI_ENABLE_THREADS=OFF" "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" ] ++ lib.optionals (!enableShared) [ @@ -35,8 +71,12 @@ let "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${lib.getDev cxxabi}/include" ] ++ lib.optionals (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) [ "-DLIBCXX_HAS_MUSL_LIBC=1" + ] ++ lib.optionals (lib.versionAtLeast release_version "18" && !useLLVM && stdenv.hostPlatform.libc == "glibc" && !stdenv.hostPlatform.isStatic) [ + "-DLIBCXX_ADDITIONAL_LIBRARIES=gcc_s" ] ++ lib.optionals useLLVM [ "-DLIBCXX_USE_COMPILER_RT=ON" + ] ++ lib.optionals (useLLVM && lib.versionAtLeast release_version "16") [ + "-DLIBCXX_ADDITIONAL_LIBRARIES=unwind" ] ++ lib.optionals stdenv.hostPlatform.isWasm [ "-DLIBCXX_ENABLE_THREADS=OFF" "-DLIBCXX_ENABLE_FILESYSTEM=OFF" @@ -62,48 +102,13 @@ let in -stdenv.mkDerivation rec { - pname = basename; - inherit version cmakeFlags; +stdenv.mkDerivation (rec { + inherit pname version cmakeFlags patches; - src = runCommand "${pname}-src-${version}" {} ('' - mkdir -p "$out/llvm" - cp -r ${monorepoSrc}/cmake "$out" - cp -r ${monorepoSrc}/libcxx "$out" - cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" - cp -r ${monorepoSrc}/llvm/utils "$out/llvm" - cp -r ${monorepoSrc}/third-party "$out" - cp -r ${monorepoSrc}/runtimes "$out" - '' + lib.optionalString (cxxabi == null) '' - cp -r ${monorepoSrc}/libcxxabi "$out" - ''); + src = src'; outputs = [ "out" "dev" ]; - patches = [ - (substitute { - src = ../../common/libcxxabi/wasm.patch; - replacements = [ - "--replace-fail" "/cmake/" "/llvm/cmake/" - ]; - }) - ] ++ lib.optionals stdenv.hostPlatform.isMusl [ - (substitute { - src = ../../common/libcxx/libcxx-0001-musl-hacks.patch; - replacements = [ - "--replace-fail" "/include/" "/libcxx/include/" - ]; - }) - ]; - - postPatch = '' - # fix CMake error when static and LIBCXXABI_USE_LLVM_UNWINDER=ON. aren't - # building unwind so don't need to depend on it - substituteInPlace libcxx/src/CMakeLists.txt \ - --replace-fail "add_dependencies(cxx_static unwind)" "# add_dependencies(cxx_static unwind)" - cd runtimes - ''; - preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' patchShebangs utils/cat_files.py ''; @@ -119,8 +124,8 @@ stdenv.mkDerivation rec { # libc++.so.1 and libc++abi.so or the external cxxabi. ld-wrapper doesn't # support linker scripts so the external cxxabi needs to be symlinked in postInstall = lib.optionalString (cxxabi != null) '' - lndir ${lib.getDev cxxabi}/include ''${!outputDev}/include/c++/v1 - lndir ${lib.getLib cxxabi}/lib ''${!outputLib}/lib + lndir ${lib.getDev cxxabi}/include $out/include/c++/v1 + lndir ${lib.getLib cxxabi}/lib $out/lib ''; passthru = { @@ -138,4 +143,15 @@ stdenv.mkDerivation rec { # UIUC License (a BSD-like license)": license = with lib.licenses; [ mit ncsa ]; }; -} +} // (if (lib.versionOlder release_version "16" || lib.versionAtLeast release_version "17") then { + postPatch = (lib.optionalString (lib.versionAtLeast release_version "14" && lib.versionOlder release_version "15") '' + # fix CMake error when static and LIBCXXABI_USE_LLVM_UNWINDER=ON. aren't + # building unwind so don't need to depend on it + substituteInPlace libcxx/src/CMakeLists.txt \ + --replace-fail "add_dependencies(cxx_static unwind)" "# add_dependencies(cxx_static unwind)" + '') + '' + cd runtimes + ''; +} else { + sourceRoot = "${src'.name}/runtimes"; +})) diff --git a/pkgs/development/compilers/llvm/git/default.nix b/pkgs/development/compilers/llvm/git/default.nix index cbb380260dee..c4e22d902c0f 100644 --- a/pkgs/development/compilers/llvm/git/default.nix +++ b/pkgs/development/compilers/llvm/git/default.nix @@ -312,7 +312,11 @@ in let # `libcxx` requires a fairly modern C++ compiler, # so: we use the clang from this LLVM package set instead of the regular # stdenv's compiler. - libcxx = callPackage ./libcxx { + libcxx = callPackage ../common/libcxx { + patches = lib.optionals (stdenv.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13") [ + # https://github.com/llvm/llvm-project/issues/64226 + ./libcxx/0001-darwin-10.12-mbstate_t-fix.patch + ]; inherit llvm_meta; stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; }; diff --git a/pkgs/development/compilers/llvm/git/libcxx/default.nix b/pkgs/development/compilers/llvm/git/libcxx/default.nix deleted file mode 100644 index d6c304c0b476..000000000000 --- a/pkgs/development/compilers/llvm/git/libcxx/default.nix +++ /dev/null @@ -1,130 +0,0 @@ -{ lib, stdenv, llvm_meta -, monorepoSrc, runCommand -, cmake, lndir, ninja, python3, fixDarwinDylibNames, version -, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else null -, libcxxrt, libunwind -, enableShared ? !stdenv.hostPlatform.isStatic -}: - -# external cxxabi is not supported on Darwin as the build will not link libcxx -# properly and not re-export the cxxabi symbols into libcxx -# https://github.com/NixOS/nixpkgs/issues/166205 -# https://github.com/NixOS/nixpkgs/issues/269548 -assert cxxabi == null || !stdenv.hostPlatform.isDarwin; -let - basename = "libcxx"; - cxxabiName = "lib${if cxxabi == null then "cxxabi" else cxxabi.libName}"; - runtimes = [ "libcxx" ] ++ lib.optional (cxxabi == null) "libcxxabi"; - - # Note: useLLVM is likely false for Darwin but true under pkgsLLVM - useLLVM = stdenv.hostPlatform.useLLVM or false; - - cxxabiCMakeFlags = [ - "-DLIBCXXABI_USE_LLVM_UNWINDER=OFF" - ] ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ - "-DLIBCXXABI_ADDITIONAL_LIBRARIES=unwind" - "-DLIBCXXABI_USE_COMPILER_RT=ON" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXXABI_ENABLE_THREADS=OFF" - "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared) [ - "-DLIBCXXABI_ENABLE_SHARED=OFF" - ]; - - cxxCMakeFlags = [ - "-DLIBCXX_CXX_ABI=${cxxabiName}" - ] ++ lib.optionals (cxxabi != null) [ - "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${lib.getDev cxxabi}/include" - ] ++ lib.optionals (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) [ - "-DLIBCXX_HAS_MUSL_LIBC=1" - ] ++ lib.optionals (lib.versionAtLeast version "18" && !useLLVM && stdenv.hostPlatform.libc == "glibc" && !stdenv.hostPlatform.isStatic) [ - "-DLIBCXX_ADDITIONAL_LIBRARIES=gcc_s" - ] ++ lib.optionals useLLVM [ - "-DLIBCXX_USE_COMPILER_RT=ON" - # There's precedent for this in llvm-project/libcxx/cmake/caches. - # In a monorepo build you might do the following in the libcxxabi build: - # -DLLVM_ENABLE_PROJECTS=libcxxabi;libunwinder - # -DLIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY=On - # libcxx appears to require unwind and doesn't pull it in via other means. - "-DLIBCXX_ADDITIONAL_LIBRARIES=unwind" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DLIBCXX_ENABLE_THREADS=OFF" - "-DLIBCXX_ENABLE_FILESYSTEM=OFF" - "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared) [ - "-DLIBCXX_ENABLE_SHARED=OFF" - ]; - - cmakeFlags = [ - "-DLLVM_ENABLE_RUNTIMES=${lib.concatStringsSep ";" runtimes}" - ] ++ lib.optionals stdenv.hostPlatform.isWasm [ - "-DCMAKE_C_COMPILER_WORKS=ON" - "-DCMAKE_CXX_COMPILER_WORKS=ON" - "-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker - ] ++ cxxCMakeFlags - ++ lib.optionals (cxxabi == null) cxxabiCMakeFlags; - -in - -stdenv.mkDerivation rec { - pname = basename; - inherit version cmakeFlags; - - src = runCommand "${pname}-src-${version}" {} ('' - mkdir -p "$out/llvm" - cp -r ${monorepoSrc}/cmake "$out" - cp -r ${monorepoSrc}/libcxx "$out" - cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" - cp -r ${monorepoSrc}/llvm/utils "$out/llvm" - cp -r ${monorepoSrc}/third-party "$out" - cp -r ${monorepoSrc}/runtimes "$out" - '' + lib.optionalString (cxxabi == null) '' - cp -r ${monorepoSrc}/libcxxabi "$out" - ''); - - outputs = [ "out" "dev" ]; - - patches = lib.optionals (stdenv.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13") [ - # https://github.com/llvm/llvm-project/issues/64226 - ./0001-darwin-10.12-mbstate_t-fix.patch - ]; - - postPatch = '' - cd runtimes - ''; - - preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' - patchShebangs utils/cat_files.py - ''; - - nativeBuildInputs = [ cmake ninja python3 ] - ++ lib.optional stdenv.isDarwin fixDarwinDylibNames - ++ lib.optional (cxxabi != null) lndir; - - buildInputs = [ cxxabi ] - ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ libunwind ]; - - # libc++.so is a linker script which expands to multiple libraries, - # libc++.so.1 and libc++abi.so or the external cxxabi. ld-wrapper doesn't - # support linker scripts so the external cxxabi needs to be symlinked in - postInstall = lib.optionalString (cxxabi != null) '' - lndir ${lib.getDev cxxabi}/include ''${!outputDev}/include/c++/v1 - lndir ${lib.getLib cxxabi}/lib ''${!outputLib}/lib - ''; - - passthru = { - isLLVM = true; - }; - - meta = llvm_meta // { - homepage = "https://libcxx.llvm.org/"; - description = "C++ standard library"; - longDescription = '' - libc++ is an implementation of the C++ standard library, targeting C++11, - C++14 and above. - ''; - # "All of the code in libc++ is dual licensed under the MIT license and the - # UIUC License (a BSD-like license)": - license = with lib.licenses; [ mit ncsa ]; - }; -}