nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at netboot-syslinux-multiplatform 120 lines 4.2 kB view raw
1{ lib, stdenv, llvm_meta, cmake, ninja, 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 ninja 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 62 # `libcxxabi`'s build does not need a toolchain with a c++ stdlib attached 63 # (we specify the headers it should use explicitly above). 64 # 65 # CMake however checks for this anyways; this flag tells it not to. See: 66 # https://github.com/llvm/llvm-project/blob/4bd3f3759259548e159aeba5c76efb9a0864e6fa/llvm/runtimes/CMakeLists.txt#L243 67 "-DCMAKE_CXX_COMPILER_WORKS=ON" 68 ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ 69 "-DLLVM_ENABLE_LIBCXX=ON" 70 "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" 71 ] ++ lib.optionals stdenv.hostPlatform.isWasm [ 72 "-DLIBCXXABI_ENABLE_THREADS=OFF" 73 "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" 74 ] ++ lib.optionals (!enableShared) [ 75 "-DLIBCXXABI_ENABLE_SHARED=OFF" 76 ]; 77 78 preInstall = lib.optionalString stdenv.isDarwin '' 79 for file in lib/*.dylib; do 80 if [ -L "$file" ]; then continue; fi 81 82 # Fix up the install name. Preserve the basename, just replace the path. 83 installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" 84 85 # this should be done in CMake, but having trouble figuring out 86 # the magic combination of necessary CMake variables 87 # if you fancy a try, take a look at 88 # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling 89 ${stdenv.cc.targetPrefix}install_name_tool -id $installName $file 90 91 # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes 92 # libcxxabi to sometimes link against a different version of itself. 93 # Here we simply make that second reference point to ourselves. 94 for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do 95 ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file 96 done 97 done 98 ''; 99 100 postInstall = '' 101 mkdir -p "$dev/include" 102 install -m 644 ../../${pname}/include/${if stdenv.isDarwin then "*" else "cxxabi.h"} "$dev/include" 103 ''; 104 105 passthru = { 106 libName = "c++abi"; 107 }; 108 109 meta = llvm_meta // { 110 homepage = "https://libcxxabi.llvm.org/"; 111 description = "Provides C++ standard library support"; 112 longDescription = '' 113 libc++abi is a new implementation of low level support for a standard C++ library. 114 ''; 115 # "All of the code in libc++abi is dual licensed under the MIT license and 116 # the UIUC License (a BSD-like license)": 117 license = with lib.licenses; [ mit ncsa ]; 118 maintainers = llvm_meta.maintainers ++ [ lib.maintainers.vlstill ]; 119 }; 120}