Merge pull request #303449 from ExpidusOS/feat/llvm-git-commonify-libcxx

llvmPackages_{12,13,14,15,16,17,18,git}: use common libcxx
This commit is contained in:
Weijia Wang 2024-04-13 16:31:35 +02:00 committed by GitHub
commit e65e742588
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 173 additions and 1000 deletions

View File

@ -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
@ -288,7 +288,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;
};

View File

@ -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 ];
};
}

View File

@ -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
@ -328,7 +328,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;

View File

@ -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 ];
};
}

View File

@ -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
@ -329,7 +329,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;
};

View File

@ -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
@ -336,7 +336,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;
};

View File

@ -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 ];
};
}

View File

@ -352,7 +352,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;
};

View File

@ -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 ];
};
}

View File

@ -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
@ -337,7 +337,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;
};

View File

@ -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 ];
};
}

View File

@ -330,7 +330,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;
};

View File

@ -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 ];
};
}

View File

@ -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";
}))

View File

@ -335,7 +335,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;
};

View File

@ -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 ];
};
}