nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ lib, stdenv, llvm_meta, cmake, python3, src, cxx-headers, libunwind, version
2, enableShared ? !stdenv.hostPlatform.isStatic
3, standalone ? stdenv.hostPlatform.useLLVM or false
4, withLibunwind ? !stdenv.isDarwin && !stdenv.hostPlatform.isWasm
5}:
6
7stdenv.mkDerivation rec {
8 pname = "libcxxabi";
9 inherit version;
10
11 inherit src;
12 sourceRoot = "source/${pname}";
13
14 outputs = [ "out" "dev" ];
15
16 postUnpack = lib.optionalString stdenv.isDarwin ''
17 export TRIPLE=x86_64-apple-darwin
18 '' + lib.optionalString stdenv.hostPlatform.isWasm ''
19 patch -p1 -d llvm -i ${./wasm.patch}
20 '';
21
22 patches = [
23 ./gnu-install-dirs.patch
24 ];
25
26 nativeBuildInputs = [ cmake python3 ];
27 buildInputs = lib.optional withLibunwind libunwind;
28
29 cmakeFlags = [
30 "-DLIBCXXABI_LIBCXX_INCLUDES=${cxx-headers}/include/c++/v1"
31 ] ++ lib.optionals standalone [
32 "-DLLVM_ENABLE_LIBCXX=ON"
33 ] ++ lib.optionals (standalone && withLibunwind) [
34 "-DLIBCXXABI_USE_LLVM_UNWINDER=ON"
35 ] ++ lib.optionals stdenv.hostPlatform.isWasm [
36 "-DLIBCXXABI_ENABLE_THREADS=OFF"
37 "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF"
38 ] ++ lib.optionals (!enableShared) [
39 "-DLIBCXXABI_ENABLE_SHARED=OFF"
40 ];
41
42 preInstall = lib.optionalString stdenv.isDarwin ''
43 for file in lib/*.dylib; do
44 if [ -L "$file" ]; then continue; fi
45
46 # Fix up the install name. Preserve the basename, just replace the path.
47 installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))"
48
49 # this should be done in CMake, but having trouble figuring out
50 # the magic combination of necessary CMake variables
51 # if you fancy a try, take a look at
52 # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling
53 ${stdenv.cc.targetPrefix}install_name_tool -id $installName $file
54
55 # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes
56 # libcxxabi to sometimes link against a different version of itself.
57 # Here we simply make that second reference point to ourselves.
58 for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do
59 ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file
60 done
61 done
62 '';
63
64 postInstall = ''
65 mkdir -p "$dev/include"
66 install -m 644 ../include/${if stdenv.isDarwin then "*" else "cxxabi.h"} "$dev/include"
67 '';
68
69 passthru = {
70 libName = "c++abi";
71 };
72
73 meta = llvm_meta // {
74 homepage = "https://libcxxabi.llvm.org/";
75 description = "Provides C++ standard library support";
76 longDescription = ''
77 libc++abi is a new implementation of low level support for a standard C++ library.
78 '';
79 # "All of the code in libc++abi is dual licensed under the MIT license and
80 # the UIUC License (a BSD-like license)":
81 license = with lib.licenses; [ mit ncsa ];
82 maintainers = llvm_meta.maintainers ++ [ lib.maintainers.vlstill ];
83 };
84}