lol
at 23.05-pre 107 lines 3.7 kB view raw
1{ lib, stdenv, llvm_meta, cmake, python3 2, monorepoSrc, runCommand, fetchpatch 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 cp -r ${monorepoSrc}/llvm/utils "$out/llvm" 22 cp -r ${monorepoSrc}/runtimes "$out" 23 ''; 24 25 sourceRoot = "${src.name}/runtimes"; 26 27 outputs = [ "out" "dev" ]; 28 29 postUnpack = lib.optionalString stdenv.isDarwin '' 30 export TRIPLE=x86_64-apple-darwin 31 '' + lib.optionalString stdenv.hostPlatform.isWasm '' 32 patch -p1 -d llvm -i ${./wasm.patch} 33 ''; 34 35 prePatch = '' 36 cd ../${pname} 37 chmod -R u+w . 38 ''; 39 40 patches = [ 41 ./gnu-install-dirs.patch 42 43 # https://reviews.llvm.org/D132298, Allow building libcxxabi alone 44 (fetchpatch { 45 url = "https://github.com/llvm/llvm-project/commit/e6a0800532bb409f6d1c62f3698bdd6994a877dc.patch"; 46 sha256 = "1xyjd56m4pfwq8p3xh6i8lhkk9kq15jaml7qbhxdf87z4jjkk63a"; 47 stripLen = 1; 48 }) 49 ]; 50 51 postPatch = '' 52 cd ../runtimes 53 ''; 54 55 nativeBuildInputs = [ cmake python3 ]; 56 buildInputs = lib.optional (!stdenv.isDarwin && !stdenv.hostPlatform.isWasm) libunwind; 57 58 cmakeFlags = [ 59 "-DLLVM_ENABLE_RUNTIMES=libcxxabi" 60 "-DLIBCXXABI_LIBCXX_INCLUDES=${cxx-headers}/include/c++/v1" 61 ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ 62 "-DLLVM_ENABLE_LIBCXX=ON" 63 "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" 64 ] ++ lib.optionals stdenv.hostPlatform.isWasm [ 65 "-DLIBCXXABI_ENABLE_THREADS=OFF" 66 "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" 67 ] ++ lib.optionals (!enableShared) [ 68 "-DLIBCXXABI_ENABLE_SHARED=OFF" 69 ]; 70 71 preInstall = lib.optionalString stdenv.isDarwin '' 72 for file in lib/*.dylib; do 73 # Fix up the install name. Preserve the basename, just replace the path. 74 installName="$out/lib/$(basename $(otool -D $file | tail -n 1))" 75 76 # this should be done in CMake, but having trouble figuring out 77 # the magic combination of necessary CMake variables 78 # if you fancy a try, take a look at 79 # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling 80 ${stdenv.cc.targetPrefix}install_name_tool -id $installName $file 81 82 # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes 83 # libcxxabi to sometimes link against a different version of itself. 84 # Here we simply make that second reference point to ourselves. 85 for other in $(otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do 86 ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file 87 done 88 done 89 ''; 90 91 postInstall = '' 92 mkdir -p "$dev/include" 93 install -m 644 ../../${pname}/include/${if stdenv.isDarwin then "*" else "cxxabi.h"} "$dev/include" 94 ''; 95 96 meta = llvm_meta // { 97 homepage = "https://libcxxabi.llvm.org/"; 98 description = "Provides C++ standard library support"; 99 longDescription = '' 100 libc++abi is a new implementation of low level support for a standard C++ library. 101 ''; 102 # "All of the code in libc++abi is dual licensed under the MIT license and 103 # the UIUC License (a BSD-like license)": 104 license = with lib.licenses; [ mit ncsa ]; 105 maintainers = llvm_meta.maintainers ++ [ lib.maintainers.vlstill ]; 106 }; 107}