Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
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 = "13d5b3f3f9412f38427c8ad48068f04ad1ee9808"; 22 googleapis = fetchFromGitHub { 23 name = "googleapis-src"; 24 owner = "googleapis"; 25 repo = "googleapis"; 26 rev = googleapisRev; 27 hash = "sha256-SiU7N1EQ/7LWhUwgf4c0CBfUzNGiLe4sSbbJmJF3sao="; 28 }; 29 excludedTests = builtins.fromTOML (builtins.readFile ./skipped_tests.toml); 30in 31stdenv.mkDerivation rec { 32 pname = "google-cloud-cpp"; 33 version = "2.4.0"; 34 35 src = fetchFromGitHub { 36 owner = "googleapis"; 37 repo = "google-cloud-cpp"; 38 rev = "v${version}"; 39 sha256 = "sha256-o8aURM8fvxn0FZjuqJGclq9Brss8LOFZzD0FV2j/lUc="; 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 doInstallCheck = true; 72 73 preInstallCheck = 74 let 75 # These paths are added to (DY)LD_LIBRARY_PATH because they contain 76 # testing-only shared libraries that do not need to be installed, but 77 # need to be loadable by the test executables. 78 # 79 # Setting (DY)LD_LIBRARY_PATH is only necessary when building shared libraries. 80 additionalLibraryPaths = [ 81 "$PWD/google/cloud/bigtable" 82 "$PWD/google/cloud/bigtable/benchmarks" 83 "$PWD/google/cloud/pubsub" 84 "$PWD/google/cloud/spanner" 85 "$PWD/google/cloud/spanner/benchmarks" 86 "$PWD/google/cloud/storage" 87 "$PWD/google/cloud/storage/benchmarks" 88 "$PWD/google/cloud/testing_util" 89 ]; 90 ldLibraryPathName = "${lib.optionalString stdenv.isDarwin "DY"}LD_LIBRARY_PATH"; 91 in 92 lib.optionalString doInstallCheck ( 93 lib.optionalString (!staticOnly) '' 94 export ${ldLibraryPathName}=${lib.concatStringsSep ":" additionalLibraryPaths} 95 '' + '' 96 export GTEST_FILTER="-${lib.concatStringsSep ":" excludedTests.cases}" 97 '' 98 ); 99 100 installCheckPhase = lib.optionalString doInstallCheck '' 101 runHook preInstallCheck 102 103 # disable tests that contact the internet 104 ctest --exclude-regex '^(${lib.concatStringsSep "|" excludedTests.whole})' 105 106 runHook postInstallCheck 107 ''; 108 109 nativeInstallCheckInputs = lib.optionals doInstallCheck [ 110 gbenchmark 111 gtest 112 ]; 113 114 cmakeFlags = [ 115 "-DBUILD_SHARED_LIBS:BOOL=${if staticOnly then "OFF" else "ON"}" 116 # unconditionally build tests to catch linker errors as early as possible 117 # this adds a good chunk of time to the build 118 "-DBUILD_TESTING:BOOL=ON" 119 "-DGOOGLE_CLOUD_CPP_ENABLE_EXAMPLES:BOOL=OFF" 120 "-DCMAKE_CXX_STANDARD=${grpc.cxxStandard}" 121 ] ++ lib.optionals (apis != [ "*" ]) [ 122 "-DGOOGLE_CLOUD_CPP_ENABLE=${lib.concatStringsSep ";" apis}" 123 ]; 124 125 meta = with lib; { 126 license = with licenses; [ asl20 ]; 127 homepage = "https://github.com/googleapis/google-cloud-cpp"; 128 description = "C++ Idiomatic Clients for Google Cloud Platform services"; 129 maintainers = with maintainers; [ cpcloud ]; 130 }; 131}