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