nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ lib, stdenv, llvm_meta, fetch, cmake, python3, fixDarwinDylibNames, version
2, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else libcxxabi
3, libcxxabi, libcxxrt
4}:
5
6assert stdenv.isDarwin -> cxxabi.pname == "libcxxabi";
7
8stdenv.mkDerivation {
9 pname = "libcxx";
10 inherit version;
11
12 src = fetch "libcxx" "0rzw4qvxp6qx4l4h9amrq02gp7hbg8lw4m0sy3k60f50234gnm3n";
13
14 postUnpack = ''
15 unpackFile ${libcxxabi.src}
16 export LIBCXXABI_INCLUDE_DIR="$PWD/$(ls -d libcxxabi-${version}*)/include"
17 '';
18
19 outputs = [ "out" "dev" ];
20
21 patches = [
22 ./gnu-install-dirs.patch
23 ] ++ lib.optionals stdenv.hostPlatform.isMusl [
24 ../../libcxx-0001-musl-hacks.patch
25 ];
26
27 # Prevent errors like "error: 'foo' is unavailable: introduced in macOS yy.zz"
28 postPatch = ''
29 substituteInPlace include/__config \
30 --replace "#define _LIBCPP_USE_AVAILABILITY_APPLE" ""
31 '';
32
33 prePatch = ''
34 substituteInPlace lib/CMakeLists.txt --replace "/usr/lib/libc++" "\''${LIBCXX_LIBCXXABI_LIB_PATH}/libc++"
35 '';
36
37 preConfigure = ''
38 # Get headers from the cxxabi source so we can see private headers not installed by the cxxabi package
39 cmakeFlagsArray=($cmakeFlagsArray -DLIBCXX_CXX_ABI_INCLUDE_PATHS="$LIBCXXABI_INCLUDE_DIR")
40 '' + lib.optionalString stdenv.hostPlatform.isMusl ''
41 patchShebangs utils/cat_files.py
42 '';
43 nativeBuildInputs = [ cmake ]
44 ++ lib.optional stdenv.hostPlatform.isMusl python3
45 ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;
46
47 buildInputs = [ cxxabi ];
48
49 cmakeFlags = [
50 "-DLIBCXX_LIBCPPABI_VERSION=2"
51 "-DLIBCXX_CXX_ABI=${cxxabi.pname}"
52 ] ++ lib.optional stdenv.hostPlatform.isMusl "-DLIBCXX_HAS_MUSL_LIBC=1"
53 ++ lib.optional (cxxabi.pname == "libcxxabi") "-DLIBCXX_LIBCXXABI_LIB_PATH=${cxxabi}/lib";
54
55 preInstall = lib.optionalString (stdenv.isDarwin) ''
56 for file in lib/*.dylib; do
57 if [ -L "$file" ]; then continue; fi
58
59 baseName=$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))
60 installName="$out/lib/$baseName"
61 abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/')
62
63 for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do
64 ${stdenv.cc.targetPrefix}install_name_tool -change $other ${cxxabi}/lib/$abiName $file
65 done
66 done
67 '';
68
69 passthru = {
70 isLLVM = true;
71 inherit cxxabi;
72 };
73
74 meta = llvm_meta // {
75 homepage = "https://libcxx.llvm.org/";
76 description = "C++ standard library";
77 longDescription = ''
78 libc++ is an implementation of the C++ standard library, targeting C++11,
79 C++14 and above.
80 '';
81 # "All of the code in libc++ is dual licensed under the MIT license and the
82 # UIUC License (a BSD-like license)":
83 license = with lib.licenses; [ mit ncsa ];
84 };
85}