1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 fetchpatch,
6 cmake,
7 static ? stdenv.hostPlatform.isStatic,
8 cxxStandard ? null,
9}:
10
11stdenv.mkDerivation rec {
12 pname = "abseil-cpp";
13 version = "20210324.2";
14
15 src = fetchFromGitHub {
16 owner = "abseil";
17 repo = "abseil-cpp";
18 rev = version;
19 sha256 = "sha256-fcxPhuI2eL/fnd6nT11p8DpUNwGNaXZmd03yOiZcOT0=";
20 };
21
22 patches =
23 [
24 # Use CMAKE_INSTALL_FULL_{LIBDIR,INCLUDEDIR}
25 # https://github.com/abseil/abseil-cpp/pull/963
26 (fetchpatch {
27 url = "https://github.com/abseil/abseil-cpp/commit/5bfa70c75e621c5d5ec095c8c4c0c050dcb2957e.patch";
28 sha256 = "0nhjxqfxpi2pkfinnqvd5m4npf9l1kg39mjx9l3087ajhadaywl5";
29 })
30
31 # Bacport gcc-13 fix:
32 # https://github.com/abseil/abseil-cpp/pull/1187
33 (fetchpatch {
34 name = "gcc-13.patch";
35 url = "https://github.com/abseil/abseil-cpp/commit/36a4b073f1e7e02ed7d1ac140767e36f82f09b7c.patch";
36 hash = "sha256-aA7mwGEtv/cQINcawjkukmCvfNuqwUeDFssSiNKPdgg=";
37 })
38 ]
39 ++ lib.optionals stdenv.hostPlatform.isLoongArch64 [
40 # https://github.com/abseil/abseil-cpp/pull/1110
41 (fetchpatch {
42 url = "https://github.com/abseil/abseil-cpp/commit/808bc202fc13e85a7948db0d7fb58f0f051200b1.patch";
43 sha256 = "sha256-ayY/aV/xWOdEyFSDqV7B5WDGvZ0ASr/aeBeYwP5RZVc=";
44 })
45 ]
46 ++ lib.optionals stdenv.hostPlatform.isDarwin [
47 # Don’t propagate the path to CoreFoundation. Otherwise, it’s impossible to build packages
48 # that require a different SDK other than the default one.
49 ./cmake-core-foundation.patch
50 ];
51
52 cmakeFlags =
53 [
54 "-DBUILD_SHARED_LIBS=${if static then "OFF" else "ON"}"
55 ]
56 ++ lib.optionals (cxxStandard != null) [
57 "-DCMAKE_CXX_STANDARD=${cxxStandard}"
58 ];
59
60 nativeBuildInputs = [ cmake ];
61
62 meta = with lib; {
63 description = "Open-source collection of C++ code designed to augment the C++ standard library";
64 homepage = "https://abseil.io/";
65 license = licenses.asl20;
66 platforms = platforms.all;
67 maintainers = [ maintainers.andersk ];
68 # Requires LFS64 APIs. 202401 and later are fine.
69 broken = stdenv.hostPlatform.isMusl;
70 };
71}