libcxx/libcxxabi: Fix build on Windows with lld

This commit is contained in:
Shea Levy 2022-05-03 13:02:37 -04:00
parent 5ca96b948c
commit b7b9b73760
No known key found for this signature in database
GPG Key ID: 5C0BD6957D86FE27
6 changed files with 85 additions and 26 deletions

View File

@ -1,5 +1,5 @@
{ lib, stdenv, llvm_meta, src, cmake, python3, fixDarwinDylibNames, version
, libcxxabi
, libcxxabi, libunwind
, enableShared ? !stdenv.hostPlatform.isStatic
# If headersOnly is true, the resulting package would only include the headers.
@ -32,7 +32,7 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ cmake python3 ]
++ lib.optional stdenv.isDarwin fixDarwinDylibNames;
buildInputs = lib.optionals (!headersOnly) [ libcxxabi ];
buildInputs = lib.optionals (!headersOnly) ([ libcxxabi ] ++ lib.optional libcxxabi.useLLVMUnwinder libunwind);
cmakeFlags = [ "-DLIBCXX_CXX_ABI=libcxxabi" ]
++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1"
@ -41,7 +41,13 @@ stdenv.mkDerivation rec {
"-DLIBCXX_ENABLE_THREADS=OFF"
"-DLIBCXX_ENABLE_FILESYSTEM=OFF"
"-DLIBCXX_ENABLE_EXCEPTIONS=OFF"
] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF";
]
++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"
++ lib.optionals (!headersOnly && libcxxabi.semi-static) [
"-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=TRUE"
"-DLIBCXX_CXX_ABI_LIBRARY_PATH=${libcxxabi}/lib"
] ++ lib.optional (!headersOnly && libcxxabi.useLLVMUnwinder)
"-DLIBCXXABI_USE_LLVM_UNWINDER=ON";
buildFlags = lib.optional headersOnly "generate-cxx-headers";
installTargets = lib.optional headersOnly "install-cxx-headers";

View File

@ -2,9 +2,14 @@
, enableShared ? !stdenv.hostPlatform.isStatic
, standalone ? stdenv.hostPlatform.useLLVM or false
, withLibunwind ? !stdenv.isDarwin && !stdenv.isFreeBSD && !stdenv.hostPlatform.isWasm
}:
}: let
# lld doesn't support unresolved references on Windows https://github.com/llvm/llvm-project/issues/55245
semi-static = enableShared && stdenv.hostPlatform.isWindows && stdenv.cc.bintools.isLld;
stdenv.mkDerivation rec {
enableShared' = enableShared && !semi-static;
useLLVMUnwinder = standalone && withLibunwind;
in stdenv.mkDerivation rec {
pname = "libcxxabi";
inherit version;
@ -26,17 +31,22 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ cmake python3 ];
buildInputs = lib.optional withLibunwind libunwind;
passthru = { inherit semi-static useLLVMUnwinder; };
cmakeFlags = [
"-DLIBCXXABI_LIBCXX_INCLUDES=${cxx-headers}/include/c++/v1"
] ++ lib.optionals standalone [
"-DLLVM_ENABLE_LIBCXX=ON"
] ++ lib.optionals (standalone && withLibunwind) [
] ++ lib.optionals useLLVMUnwinder [
"-DLIBCXXABI_USE_LLVM_UNWINDER=ON"
] ++ lib.optionals stdenv.hostPlatform.isWasm [
"-DLIBCXXABI_ENABLE_THREADS=OFF"
"-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF"
] ++ lib.optionals (!enableShared) [
] ++ lib.optionals (!enableShared') [
"-DLIBCXXABI_ENABLE_SHARED=OFF"
] ++ lib.optionals semi-static [
"-DLIBCXX_ENABLE_SHARED=ON"
"-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON"
] ++ lib.optional stdenv.cc.isCompilerRT
"-DLIBCXXABI_USE_COMPILER_RT=ON";
@ -57,7 +67,7 @@ stdenv.mkDerivation rec {
install -d -m 755 $out/include $out/lib
install -m 644 lib/libc++abi.a $out/lib
install -m 644 ../include/cxxabi.h $out/include
'' + lib.optionalString enableShared ''
'' + lib.optionalString enableShared' ''
install -m 644 lib/libc++abi.so.1.0 $out/lib
ln -s libc++abi.so.1.0 $out/lib/libc++abi.so
ln -s libc++abi.so.1.0 $out/lib/libc++abi.so.1

View File

@ -1,7 +1,7 @@
{ lib, stdenv, llvm_meta
, monorepoSrc, runCommand
, cmake, python3, fixDarwinDylibNames, version
, libcxxabi
, libcxxabi, libunwind
, enableShared ? !stdenv.hostPlatform.isStatic
# If headersOnly is true, the resulting package would only include the headers.
@ -48,7 +48,7 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ cmake python3 ]
++ lib.optional stdenv.isDarwin fixDarwinDylibNames;
buildInputs = lib.optionals (!headersOnly) [ libcxxabi ];
buildInputs = lib.optionals (!headersOnly) ([ libcxxabi ] ++ lib.optional libcxxabi.useLLVMUnwinder libunwind);
cmakeFlags = [ "-DLIBCXX_CXX_ABI=libcxxabi" ]
++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1"
@ -57,7 +57,13 @@ stdenv.mkDerivation rec {
"-DLIBCXX_ENABLE_THREADS=OFF"
"-DLIBCXX_ENABLE_FILESYSTEM=OFF"
"-DLIBCXX_ENABLE_EXCEPTIONS=OFF"
] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF";
]
++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"
++ lib.optionals (!headersOnly && libcxxabi.semi-static) [
"-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=TRUE"
"-DLIBCXX_CXX_ABI_LIBRARY_PATH=${libcxxabi}/lib"
] ++ lib.optional (!headersOnly && libcxxabi.useLLVMUnwinder)
"-DLIBCXXABI_USE_LLVM_UNWINDER=ON";
buildFlags = lib.optional headersOnly "generate-cxx-headers";
installTargets = lib.optional headersOnly "install-cxx-headers";

View File

@ -2,9 +2,17 @@
, monorepoSrc, runCommand
, cxx-headers, libunwind, version
, enableShared ? !stdenv.hostPlatform.isStatic
}:
}: let
withLibunwind = !stdenv.isDarwin && !stdenv.isFreeBSD && !stdenv.hostPlatform.isWasm;
stdenv.mkDerivation rec {
semi-static = enableShared && stdenv.hostPlatform.isWindows && stdenv.cc.bintools.isLld;
enableShared' = enableShared && !semi-static;
standalone = stdenv.hostPlatform.useLLVM or false;
useLLVMUnwinder = standalone && withLibunwind;
in stdenv.mkDerivation rec {
pname = "libcxxabi";
inherit version;
@ -35,18 +43,24 @@ stdenv.mkDerivation rec {
];
nativeBuildInputs = [ cmake python3 ];
buildInputs = lib.optional (!stdenv.isDarwin && !stdenv.isFreeBSD && !stdenv.hostPlatform.isWasm) libunwind;
buildInputs = lib.optional withLibunwind libunwind;
passthru = { inherit semi-static useLLVMUnwinder; };
cmakeFlags = [
"-DLIBCXXABI_LIBCXX_INCLUDES=${cxx-headers}/include/c++/v1"
] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [
] ++ lib.optionals standalone [
"-DLLVM_ENABLE_LIBCXX=ON"
] ++ lib.optionals useLLVMUnwinder [
"-DLIBCXXABI_USE_LLVM_UNWINDER=ON"
] ++ lib.optionals stdenv.hostPlatform.isWasm [
"-DLIBCXXABI_ENABLE_THREADS=OFF"
"-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF"
] ++ lib.optionals (!enableShared) [
] ++ lib.optionals (!enableShared') [
"-DLIBCXXABI_ENABLE_SHARED=OFF"
] ++ lib.optionals semi-static [
"-DLIBCXX_ENABLE_SHARED=ON"
"-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON"
] ++ lib.optional stdenv.cc.isCompilerRT
"-DLIBCXXABI_USE_COMPILER_RT=ON";
@ -67,7 +81,7 @@ stdenv.mkDerivation rec {
install -d -m 755 $out/include $out/lib
install -m 644 lib/libc++abi.a $out/lib
install -m 644 ../include/cxxabi.h $out/include
'' + lib.optionalString enableShared ''
'' + lib.optionalString enableShared' ''
install -m 644 lib/libc++abi.so.1.0 $out/lib
ln -s libc++abi.so.1.0 $out/lib/libc++abi.so
ln -s libc++abi.so.1.0 $out/lib/libc++abi.so.1

View File

@ -1,7 +1,7 @@
{ lib, stdenv, llvm_meta
, monorepoSrc, runCommand
, cmake, python3, fixDarwinDylibNames, version
, libcxxabi
, libcxxabi, libunwind
, enableShared ? !stdenv.hostPlatform.isStatic
# If headersOnly is true, the resulting package would only include the headers.
@ -48,7 +48,7 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ cmake python3 ]
++ lib.optional stdenv.isDarwin fixDarwinDylibNames;
buildInputs = lib.optionals (!headersOnly) [ libcxxabi ];
buildInputs = lib.optionals (!headersOnly) ([ libcxxabi ] ++ lib.optional libcxxabi.useLLVMUnwinder libunwind);
cmakeFlags = [ "-DLIBCXX_CXX_ABI=libcxxabi" ]
++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1"
@ -57,7 +57,14 @@ stdenv.mkDerivation rec {
"-DLIBCXX_ENABLE_THREADS=OFF"
"-DLIBCXX_ENABLE_FILESYSTEM=OFF"
"-DLIBCXX_ENABLE_EXCEPTIONS=OFF"
] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF";
]
++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"
++ lib.optionals (!headersOnly && libcxxabi.semi-static) [
"-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=TRUE"
"-DLIBCXX_CXX_ABI_LIBRARY_PATH=${libcxxabi}/lib"
] ++ lib.optional (!headersOnly && libcxxabi.useLLVMUnwinder)
"-DLIBCXXABI_USE_LLVM_UNWINDER=ON";
buildFlags = lib.optional headersOnly "generate-cxx-headers";
installTargets = lib.optional headersOnly "install-cxx-headers";

View File

@ -2,7 +2,17 @@
, monorepoSrc, runCommand
, cxx-headers, libunwind, version
, enableShared ? !stdenv.hostPlatform.isStatic
}:
}: let
withLibunwind = !stdenv.isDarwin && !stdenv.isFreeBSD && !stdenv.hostPlatform.isWasm;
semi-static = enableShared && stdenv.hostPlatform.isWindows && stdenv.cc.bintools.isLld;
enableShared' = enableShared && !semi-static;
standalone = stdenv.hostPlatform.useLLVM or false;
useLLVMUnwinder = standalone && withLibunwind;
in
stdenv.mkDerivation rec {
pname = "libcxxabi";
@ -35,22 +45,28 @@ stdenv.mkDerivation rec {
];
nativeBuildInputs = [ cmake python3 ];
buildInputs = lib.optional (!stdenv.isDarwin && !stdenv.isFreeBSD && !stdenv.hostPlatform.isWasm) libunwind;
buildInputs = lib.optional withLibunwind libunwind;
passthru = { inherit semi-static useLLVMUnwinder; };
cmakeFlags = [
"-DLIBCXXABI_LIBCXX_INCLUDES=${cxx-headers}/include/c++/v1"
] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [
] ++ lib.optionals standalone [
"-DLLVM_ENABLE_LIBCXX=ON"
] ++ lib.optionals useLLVMUnwinder [
"-DLIBCXXABI_USE_LLVM_UNWINDER=ON"
] ++ lib.optionals stdenv.hostPlatform.isWasm [
"-DLIBCXXABI_ENABLE_THREADS=OFF"
"-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF"
] ++ lib.optionals (!enableShared) [
] ++ lib.optionals (!enableShared') [
"-DLIBCXXABI_ENABLE_SHARED=OFF"
] ++ lib.optionals semi-static [
"-DLIBCXX_ENABLE_SHARED=ON"
"-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON"
] ++ lib.optional stdenv.cc.isCompilerRT
"-DLIBCXXABI_USE_COMPILER_RT=ON";
installPhase = if stdenv.isDarwin
then ''
for file in lib/*.dylib; do
@ -68,7 +84,7 @@ stdenv.mkDerivation rec {
install -d -m 755 $out/include $out/lib
install -m 644 lib/libc++abi.a $out/lib
install -m 644 ../include/cxxabi.h $out/include
'' + lib.optionalString enableShared ''
'' + lib.optionalString enableShared' ''
install -m 644 lib/libc++abi.so.1.0 $out/lib
ln -s libc++abi.so.1.0 $out/lib/libc++abi.so
ln -s libc++abi.so.1.0 $out/lib/libc++abi.so.1