1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 replaceVars,
6 c-ares,
7 cmake,
8 crc32c,
9 curl,
10 gbenchmark,
11 grpc,
12 gtest,
13 ninja,
14 nlohmann_json,
15 openssl,
16 pkg-config,
17 protobuf_31,
18 pkgsBuildHost,
19 # default list of APIs: https://github.com/googleapis/google-cloud-cpp/blob/v1.32.1/CMakeLists.txt#L173
20 apis ? [ "*" ],
21 staticOnly ? stdenv.hostPlatform.isStatic,
22}:
23let
24 # defined in cmake/GoogleapisConfig.cmake
25 googleapisRev = "f01a17a560b4fbc888fd552c978f4e1f8614100b";
26 googleapis = fetchFromGitHub {
27 name = "googleapis-src";
28 owner = "googleapis";
29 repo = "googleapis";
30 rev = googleapisRev;
31 hash = "sha256-eJA3KM/CZMKTR3l6omPJkxqIBt75mSNsxHnoC+1T4gw=";
32 };
33in
34stdenv.mkDerivation rec {
35 pname = "google-cloud-cpp";
36 version = "2.38.0";
37
38 src = fetchFromGitHub {
39 owner = "googleapis";
40 repo = "google-cloud-cpp";
41 rev = "v${version}";
42 sha256 = "sha256-TF3MLBmjUbKJkZVcaPXbagXrAs3eEhlNQBjYQf0VtT8=";
43 };
44
45 patches = [
46 (replaceVars ./hardcode-googleapis-path.patch {
47 url = googleapis;
48 })
49 ];
50
51 nativeBuildInputs = [
52 cmake
53 ninja
54 pkg-config
55 ];
56
57 buildInputs = [
58 c-ares
59 crc32c
60 (curl.override { inherit openssl; })
61 grpc
62 nlohmann_json
63 openssl
64 protobuf_31
65 gbenchmark
66 gtest
67 ];
68
69 doInstallCheck = true;
70
71 preInstallCheck =
72 let
73 # These paths are added to (DY)LD_LIBRARY_PATH because they contain
74 # testing-only shared libraries that do not need to be installed, but
75 # need to be loadable by the test executables.
76 #
77 # Setting (DY)LD_LIBRARY_PATH is only necessary when building shared libraries.
78 additionalLibraryPaths = [
79 "$PWD/google/cloud/bigtable"
80 "$PWD/google/cloud/bigtable/benchmarks"
81 "$PWD/google/cloud/pubsub"
82 "$PWD/google/cloud/spanner"
83 "$PWD/google/cloud/spanner/benchmarks"
84 "$PWD/google/cloud/storage"
85 "$PWD/google/cloud/storage/benchmarks"
86 "$PWD/google/cloud/testing_util"
87 ];
88 ldLibraryPathName = "${lib.optionalString stdenv.hostPlatform.isDarwin "DY"}LD_LIBRARY_PATH";
89 in
90 lib.optionalString doInstallCheck (
91 lib.optionalString (!staticOnly) ''
92 export ${ldLibraryPathName}=${lib.concatStringsSep ":" additionalLibraryPaths}
93 ''
94 );
95
96 installCheckPhase =
97 let
98 disabledTests = lib.optionalString stdenv.hostPlatform.isDarwin ''
99 common_internal_async_connection_ready_test
100 bigtable_async_read_stream_test
101 bigtable_metadata_update_policy_test
102 bigtable_bigtable_benchmark_test
103 bigtable_embedded_server_test
104 '';
105 in
106 ''
107 runHook preInstallCheck
108
109 # Disable any integration tests, which need to contact the internet.
110 ctest \
111 --label-exclude integration-test \
112 --exclude-from-file <(echo '${disabledTests}')
113
114 runHook postInstallCheck
115 '';
116
117 nativeInstallCheckInputs = lib.optionals doInstallCheck [
118 gbenchmark
119 gtest
120 ];
121
122 cmakeFlags = [
123 "-DBUILD_SHARED_LIBS:BOOL=${if staticOnly then "OFF" else "ON"}"
124 # unconditionally build tests to catch linker errors as early as possible
125 # this adds a good chunk of time to the build
126 "-DBUILD_TESTING:BOOL=ON"
127 "-DGOOGLE_CLOUD_CPP_ENABLE_EXAMPLES:BOOL=OFF"
128 ]
129 ++ lib.optionals (apis != [ "*" ]) [
130 "-DGOOGLE_CLOUD_CPP_ENABLE=${lib.concatStringsSep ";" apis}"
131 ]
132 ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
133 "-DGOOGLE_CLOUD_CPP_GRPC_PLUGIN_EXECUTABLE=${lib.getBin pkgsBuildHost.grpc}/bin/grpc_cpp_plugin"
134 ];
135
136 requiredSystemFeatures = [ "big-parallel" ];
137
138 meta = with lib; {
139 license = with licenses; [ asl20 ];
140 homepage = "https://github.com/googleapis/google-cloud-cpp";
141 description = "C++ Idiomatic Clients for Google Cloud Platform services";
142 platforms = lib.platforms.linux ++ lib.platforms.darwin;
143 maintainers = with maintainers; [ cpcloud ];
144 };
145}