1{ lib 2, stdenv 3, fetchFromGitHub 4, abseil-cpp 5, c-ares 6, cmake 7, crc32c 8, curl 9, gbenchmark 10, grpc 11, gtest 12, ninja 13, nlohmann_json 14, pkg-config 15, protobuf 16 # default list of APIs: https://github.com/googleapis/google-cloud-cpp/blob/v1.32.1/CMakeLists.txt#L173 17, apis ? [ "*" ] 18, staticOnly ? stdenv.hostPlatform.isStatic 19}: 20let 21 googleapisRev = "ed739492993c4a99629b6430affdd6c0fb59d435"; 22 googleapis = fetchFromGitHub { 23 owner = "googleapis"; 24 repo = "googleapis"; 25 rev = googleapisRev; 26 hash = "sha256:1xrnh77vb8hxmf1ywqsifzd39kylhbdyah0b0b9bm7nw0mnahssl"; 27 }; 28 excludedTests = builtins.fromTOML (builtins.readFile ./skipped_tests.toml); 29in 30stdenv.mkDerivation rec { 31 pname = "google-cloud-cpp"; 32 version = "1.32.1"; 33 34 src = fetchFromGitHub { 35 owner = "googleapis"; 36 repo = "google-cloud-cpp"; 37 rev = "v${version}"; 38 sha256 = "0g720sni70nlncv4spm4rlfykdkpjnv81axfz2jd1arpdajm0mg9"; 39 }; 40 41 postPatch = '' 42 substituteInPlace external/googleapis/CMakeLists.txt \ 43 --replace "https://github.com/googleapis/googleapis/archive/${googleapisRev}.tar.gz" "file://${googleapis}" 44 ''; 45 46 nativeBuildInputs = [ 47 cmake 48 ninja 49 pkg-config 50 ] ++ lib.optionals (!doInstallCheck) [ 51 # enable these dependencies when doInstallCheck failse because we're 52 # unconditionally building tests and benchmarks 53 # 54 # when doInstallCheck is true, these deps are added to installCheckInputs 55 gbenchmark 56 gtest 57 ]; 58 59 buildInputs = [ 60 abseil-cpp 61 c-ares 62 crc32c 63 curl 64 grpc 65 nlohmann_json 66 protobuf 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.isDarwin "DY"}LD_LIBRARY_PATH"; 89 in 90 lib.optionalString doInstallCheck ( 91 lib.optionalString (!staticOnly) '' 92 export ${ldLibraryPathName}=${lib.concatStringsSep ":" additionalLibraryPaths} 93 '' + '' 94 export GTEST_FILTER="-${lib.concatStringsSep ":" excludedTests.cases}" 95 '' 96 ); 97 98 installCheckPhase = lib.optionalString doInstallCheck '' 99 runHook preInstallCheck 100 101 # disable tests that contact the internet 102 ctest --exclude-regex '^(${lib.concatStringsSep "|" excludedTests.whole})' 103 104 runHook postInstallCheck 105 ''; 106 107 installCheckInputs = lib.optionals doInstallCheck [ 108 gbenchmark 109 gtest 110 ]; 111 112 cmakeFlags = [ 113 "-DBUILD_SHARED_LIBS:BOOL=${if staticOnly then "OFF" else "ON"}" 114 # unconditionally build tests to catch linker errors as early as possible 115 # this adds a good chunk of time to the build 116 "-DBUILD_TESTING:BOOL=ON" 117 "-DGOOGLE_CLOUD_CPP_ENABLE_EXAMPLES:BOOL=OFF" 118 ] ++ lib.optionals (apis != [ "*" ]) [ 119 "-DGOOGLE_CLOUD_CPP_ENABLE=${lib.concatStringsSep ";" apis}" 120 ]; 121 122 meta = with lib; { 123 license = with licenses; [ asl20 ]; 124 homepage = "https://github.com/googleapis/google-cloud-cpp"; 125 description = "C++ Idiomatic Clients for Google Cloud Platform services"; 126 maintainers = with maintainers; [ cpcloud ]; 127 }; 128}