nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at netboot-syslinux-multiplatform 98 lines 3.2 kB view raw
1{ lib, stdenv, llvm_meta 2, monorepoSrc, runCommand 3, cmake, python3, fixDarwinDylibNames, version 4, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else libcxxabi 5, libcxxabi, libcxxrt 6, enableShared ? !stdenv.hostPlatform.isStatic 7 8# If headersOnly is true, the resulting package would only include the headers. 9# Use this to break the circular dependency between libcxx and libcxxabi. 10# 11# Some context: 12# https://reviews.llvm.org/rG1687f2bbe2e2aaa092f942d4a97d41fad43eedfb 13, headersOnly ? false 14}: 15 16let 17 basename = "libcxx"; 18in 19 20assert stdenv.isDarwin -> cxxabi.pname == "libcxxabi"; 21 22stdenv.mkDerivation rec { 23 pname = basename + lib.optionalString headersOnly "-headers"; 24 inherit version; 25 26 src = runCommand "${pname}-src-${version}" {} '' 27 mkdir -p "$out" 28 cp -r ${monorepoSrc}/cmake "$out" 29 cp -r ${monorepoSrc}/${basename} "$out" 30 mkdir -p "$out/libcxxabi" 31 cp -r ${monorepoSrc}/libcxxabi/include "$out/libcxxabi" 32 mkdir -p "$out/llvm" 33 cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" 34 cp -r ${monorepoSrc}/llvm/utils "$out/llvm" 35 ''; 36 37 sourceRoot = "${src.name}/${basename}"; 38 39 outputs = [ "out" ] ++ lib.optional (!headersOnly) "dev"; 40 41 patches = [ 42 ./gnu-install-dirs.patch 43 ] ++ lib.optionals stdenv.hostPlatform.isMusl [ 44 ../../libcxx-0001-musl-hacks.patch 45 ]; 46 47 preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' 48 patchShebangs utils/cat_files.py 49 ''; 50 51 nativeBuildInputs = [ cmake python3 ] 52 ++ lib.optional stdenv.isDarwin fixDarwinDylibNames; 53 54 buildInputs = lib.optionals (!headersOnly) [ cxxabi ]; 55 56 cmakeFlags = [ "-DLIBCXX_CXX_ABI=${cxxabi.pname}" ] 57 ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" 58 ++ lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON" 59 ++ lib.optionals stdenv.hostPlatform.isWasm [ 60 "-DLIBCXX_ENABLE_THREADS=OFF" 61 "-DLIBCXX_ENABLE_FILESYSTEM=OFF" 62 "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" 63 ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"; 64 65 buildFlags = lib.optional headersOnly "generate-cxx-headers"; 66 installTargets = lib.optional headersOnly "install-cxx-headers"; 67 68 preInstall = lib.optionalString (stdenv.isDarwin && !headersOnly) '' 69 for file in lib/*.dylib; do 70 if [ -L "$file" ]; then continue; fi 71 72 baseName=$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1)) 73 installName="$out/lib/$baseName" 74 abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') 75 76 for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do 77 ${stdenv.cc.targetPrefix}install_name_tool -change $other ${cxxabi}/lib/$abiName $file 78 done 79 done 80 ''; 81 82 passthru = { 83 isLLVM = true; 84 inherit cxxabi; 85 }; 86 87 meta = llvm_meta // { 88 homepage = "https://libcxx.llvm.org/"; 89 description = "C++ standard library"; 90 longDescription = '' 91 libc++ is an implementation of the C++ standard library, targeting C++11, 92 C++14 and above. 93 ''; 94 # "All of the code in libc++ is dual licensed under the MIT license and the 95 # UIUC License (a BSD-like license)": 96 license = with lib.licenses; [ mit ncsa ]; 97 }; 98}