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