1{ lib 2, stdenv 3, fetchFromGitHub 4, c-ares 5, cmake 6, crc32c 7, curl 8, gbenchmark 9, grpc 10, gtest 11, ninja 12, nlohmann_json 13, openssl 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 = "d4f3468ef85278428005ed555b3a85db91551ee6"; 22 googleapis = fetchFromGitHub { 23 owner = "googleapis"; 24 repo = "googleapis"; 25 rev = googleapisRev; 26 hash = "sha256-sIQVFQhE3Ae6ia45apzdgtwzglMM4hFZ8efNAhMO5ZY="; 27 }; 28 excludedTests = builtins.fromTOML (builtins.readFile ./skipped_tests.toml); 29in 30stdenv.mkDerivation rec { 31 pname = "google-cloud-cpp"; 32 version = "1.38.0"; 33 34 src = fetchFromGitHub { 35 owner = "googleapis"; 36 repo = "google-cloud-cpp"; 37 rev = "v${version}"; 38 sha256 = "sha256-kobOkohWIDTQaaihhoh/25tZUNv+CjKFwj2xQqO52bA="; 39 }; 40 41 postPatch = '' 42 substituteInPlace external/googleapis/CMakeLists.txt \ 43 --replace "https://github.com/googleapis/googleapis/archive/\''${GOOGLE_CLOUD_CPP_GOOGLEAPIS_COMMIT_SHA}.tar.gz" "file://${googleapis}" 44 45 # https://github.com/googleapis/google-cloud-cpp/issues/8992 46 for file in external/googleapis/config.pc.in google/cloud/{,*/}config.pc.in; do 47 substituteInPlace "$file" \ 48 --replace '$'{prefix}/@CMAKE_INSTALL_LIBDIR@ @CMAKE_INSTALL_FULL_LIBDIR@ \ 49 --replace '$'{prefix}/@CMAKE_INSTALL_INCLUDEDIR@ @CMAKE_INSTALL_FULL_INCLUDEDIR@ \ 50 --replace '$'{prefix}/@CMAKE_INSTALL_BINDIR@ @CMAKE_INSTALL_FULL_BINDIR@ 51 done 52 ''; 53 54 nativeBuildInputs = [ 55 cmake 56 ninja 57 pkg-config 58 ] ++ lib.optionals (!doInstallCheck) [ 59 # enable these dependencies when doInstallCheck is false because we're 60 # unconditionally building tests and benchmarks 61 # 62 # when doInstallCheck is true, these deps are added to installCheckInputs 63 gbenchmark 64 gtest 65 ]; 66 67 buildInputs = [ 68 c-ares 69 crc32c 70 (curl.override { inherit openssl; }) 71 grpc 72 nlohmann_json 73 openssl 74 protobuf 75 ]; 76 77 doInstallCheck = true; 78 79 preInstallCheck = 80 let 81 # These paths are added to (DY)LD_LIBRARY_PATH because they contain 82 # testing-only shared libraries that do not need to be installed, but 83 # need to be loadable by the test executables. 84 # 85 # Setting (DY)LD_LIBRARY_PATH is only necessary when building shared libraries. 86 additionalLibraryPaths = [ 87 "$PWD/google/cloud/bigtable" 88 "$PWD/google/cloud/bigtable/benchmarks" 89 "$PWD/google/cloud/pubsub" 90 "$PWD/google/cloud/spanner" 91 "$PWD/google/cloud/spanner/benchmarks" 92 "$PWD/google/cloud/storage" 93 "$PWD/google/cloud/storage/benchmarks" 94 "$PWD/google/cloud/testing_util" 95 ]; 96 ldLibraryPathName = "${lib.optionalString stdenv.isDarwin "DY"}LD_LIBRARY_PATH"; 97 in 98 lib.optionalString doInstallCheck ( 99 lib.optionalString (!staticOnly) '' 100 export ${ldLibraryPathName}=${lib.concatStringsSep ":" additionalLibraryPaths} 101 '' + '' 102 export GTEST_FILTER="-${lib.concatStringsSep ":" excludedTests.cases}" 103 '' 104 ); 105 106 installCheckPhase = lib.optionalString doInstallCheck '' 107 runHook preInstallCheck 108 109 # disable tests that contact the internet 110 ctest --exclude-regex '^(${lib.concatStringsSep "|" excludedTests.whole})' 111 112 runHook postInstallCheck 113 ''; 114 115 installCheckInputs = lib.optionals doInstallCheck [ 116 gbenchmark 117 gtest 118 ]; 119 120 cmakeFlags = [ 121 "-DBUILD_SHARED_LIBS:BOOL=${if staticOnly then "OFF" else "ON"}" 122 # unconditionally build tests to catch linker errors as early as possible 123 # this adds a good chunk of time to the build 124 "-DBUILD_TESTING:BOOL=ON" 125 "-DGOOGLE_CLOUD_CPP_ENABLE_EXAMPLES:BOOL=OFF" 126 ] ++ lib.optionals (apis != [ "*" ]) [ 127 "-DGOOGLE_CLOUD_CPP_ENABLE=${lib.concatStringsSep ";" apis}" 128 ]; 129 130 meta = with lib; { 131 license = with licenses; [ asl20 ]; 132 homepage = "https://github.com/googleapis/google-cloud-cpp"; 133 description = "C++ Idiomatic Clients for Google Cloud Platform services"; 134 maintainers = with maintainers; [ cpcloud ]; 135 }; 136}