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