1{ lib, stdenv, fetch, cmake, python, llvm, libcxxabi, fixDarwinDylibNames, version }:
2
3stdenv.mkDerivation rec {
4 name = "libc++-${version}";
5
6 src = fetch "libcxx" "003wwniwlikgh38cbqbcshc5gkiv3a2jkmbn6am9s46y5gfrk3zs";
7
8 postUnpack = ''
9 unpackFile ${libcxxabi.src}
10 export LIBCXXABI_INCLUDE_DIR="$PWD/$(ls -d libcxxabi-${version}*)/include"
11 '';
12
13 # on next rebuild, this can be replaced with optionals; for now set to null to avoid
14 # patches = stdenv.lib.optionals stdenv.hostPlatform.isMusl [
15 patches = if stdenv.hostPlatform.isMusl then [
16 ../../libcxx-0001-musl-hacks.patch
17 ] else null;
18
19 prePatch = ''
20 substituteInPlace lib/CMakeLists.txt --replace "/usr/lib/libc++" "\''${LIBCXX_LIBCXXABI_LIB_PATH}/libc++"
21 '';
22
23 preConfigure = ''
24 # Get headers from the cxxabi source so we can see private headers not installed by the cxxabi package
25 cmakeFlagsArray=($cmakeFlagsArray -DLIBCXX_CXX_ABI_INCLUDE_PATHS="$LIBCXXABI_INCLUDE_DIR")
26 '' + lib.optionalString stdenv.hostPlatform.isMusl ''
27 patchShebangs utils/cat_files.py
28 '';
29 nativeBuildInputs = [ cmake ] ++ stdenv.lib.optional stdenv.hostPlatform.isMusl python;
30
31 buildInputs = [ libcxxabi ] ++ lib.optional stdenv.isDarwin fixDarwinDylibNames;
32
33 cmakeFlags = [
34 "-DLIBCXX_LIBCXXABI_LIB_PATH=${libcxxabi}/lib"
35 "-DLIBCXX_LIBCPPABI_VERSION=2"
36 "-DLIBCXX_CXX_ABI=libcxxabi"
37 ] ++ stdenv.lib.optional stdenv.hostPlatform.isMusl "-DLIBCXX_HAS_MUSL_LIBC=1";
38
39 enableParallelBuilding = true;
40
41 linkCxxAbi = stdenv.isLinux;
42
43 setupHook = ./setup-hook.sh;
44
45 meta = {
46 homepage = http://libcxx.llvm.org/;
47 description = "A new implementation of the C++ standard library, targeting C++11";
48 license = with stdenv.lib.licenses; [ ncsa mit ];
49 platforms = stdenv.lib.platforms.unix;
50 };
51}