diff options
author | Alyssa Ross <hi@alyssa.is> | 2023-12-15 19:32:38 +0100 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2023-12-15 19:32:38 +0100 |
commit | 6b8e2555ef013b579cda57025b17d662e0f1fe1f (patch) | |
tree | 5a83c673af26c9976acd5a5dfa20e09e06898047 /nixpkgs/pkgs/development/compilers/llvm/17/libcxx/default.nix | |
parent | 66ca7a150b5c051f0728f13134e6265cc46f370c (diff) | |
parent | 02357adddd0889782362d999628de9d309d202dc (diff) | |
download | nixlib-6b8e2555ef013b579cda57025b17d662e0f1fe1f.tar nixlib-6b8e2555ef013b579cda57025b17d662e0f1fe1f.tar.gz nixlib-6b8e2555ef013b579cda57025b17d662e0f1fe1f.tar.bz2 nixlib-6b8e2555ef013b579cda57025b17d662e0f1fe1f.tar.lz nixlib-6b8e2555ef013b579cda57025b17d662e0f1fe1f.tar.xz nixlib-6b8e2555ef013b579cda57025b17d662e0f1fe1f.tar.zst nixlib-6b8e2555ef013b579cda57025b17d662e0f1fe1f.zip |
Merge branch 'nixos-unstable-small' of https://github.com/NixOS/nixpkgs
Diffstat (limited to 'nixpkgs/pkgs/development/compilers/llvm/17/libcxx/default.nix')
-rw-r--r-- | nixpkgs/pkgs/development/compilers/llvm/17/libcxx/default.nix | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/compilers/llvm/17/libcxx/default.nix b/nixpkgs/pkgs/development/compilers/llvm/17/libcxx/default.nix new file mode 100644 index 000000000000..7b9996641663 --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/llvm/17/libcxx/default.nix @@ -0,0 +1,114 @@ +{ lib, stdenv, llvm_meta +, monorepoSrc, runCommand +, cmake, ninja, python3, fixDarwinDylibNames, version +, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else libcxxabi +, libcxxabi, libcxxrt, libunwind +, enableShared ? !stdenv.hostPlatform.isStatic + +# If headersOnly is true, the resulting package would only include the headers. +# Use this to break the circular dependency between libcxx and libcxxabi. +# +# Some context: +# https://reviews.llvm.org/rG1687f2bbe2e2aaa092f942d4a97d41fad43eedfb +, headersOnly ? false +}: + +let + basename = "libcxx"; +in + +assert stdenv.isDarwin -> cxxabi.libName == "c++abi"; + +stdenv.mkDerivation rec { + pname = basename + lib.optionalString headersOnly "-headers"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${basename} "$out" + mkdir -p "$out/libcxxabi" + cp -r ${monorepoSrc}/libcxxabi/include "$out/libcxxabi" + mkdir -p "$out/llvm" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" + cp -r ${monorepoSrc}/third-party "$out" + cp -r ${monorepoSrc}/runtimes "$out" + ''; + + sourceRoot = "${src.name}/runtimes"; + + outputs = [ "out" ] ++ lib.optional (!headersOnly) "dev"; + + prePatch = '' + cd ../${basename} + chmod -R u+w . + ''; + + postPatch = '' + cd ../runtimes + ''; + + preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' + patchShebangs utils/cat_files.py + ''; + + nativeBuildInputs = [ cmake ninja python3 ] + ++ lib.optional stdenv.isDarwin fixDarwinDylibNames; + + buildInputs = + lib.optionals (!headersOnly) [ cxxabi ] + ++ lib.optionals (stdenv.hostPlatform.useLLVM or false && !stdenv.hostPlatform.isWasm) [ libunwind ]; + + cmakeFlags = let + # See: https://libcxx.llvm.org/BuildingLibcxx.html#cmdoption-arg-libcxx-cxx-abi-string + libcxx_cxx_abi_opt = { + "c++abi" = "system-libcxxabi"; + "cxxrt" = "libcxxrt"; + }.${cxxabi.libName} or (throw "unknown cxxabi: ${cxxabi.libName} (${cxxabi.pname})"); + in [ + "-DLLVM_ENABLE_RUNTIMES=libcxx" + "-DLIBCXX_CXX_ABI=${if headersOnly then "none" else libcxx_cxx_abi_opt}" + ] ++ lib.optional (!headersOnly && cxxabi.libName == "c++abi") "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${cxxabi.dev}/include/c++/v1" + ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" + ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ + "-DLIBCXX_USE_COMPILER_RT=ON" + # There's precedent for this in llvm-project/libcxx/cmake/caches. + # In a monorepo build you might do the following in the libcxxabi build: + # -DLLVM_ENABLE_PROJECTS=libcxxabi;libunwinder + # -DLIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY=On + # libcxx appears to require unwind and doesn't pull it in via other means. + "-DLIBCXX_ADDITIONAL_LIBRARIES=unwind" + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXX_ENABLE_THREADS=OFF" + "-DLIBCXX_ENABLE_FILESYSTEM=OFF" + "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" + "-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker + ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF" + # If we're only building the headers we don't actually *need* a functioning + # C/C++ compiler: + ++ lib.optionals (headersOnly) [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + ]; + + ninjaFlags = lib.optional headersOnly "generate-cxx-headers"; + installTargets = lib.optional headersOnly "install-cxx-headers"; + + passthru = { + isLLVM = true; + inherit cxxabi; + }; + + meta = llvm_meta // { + homepage = "https://libcxx.llvm.org/"; + description = "C++ standard library"; + longDescription = '' + libc++ is an implementation of the C++ standard library, targeting C++11, + C++14 and above. + ''; + # "All of the code in libc++ is dual licensed under the MIT license and the + # UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} |