|
| 1 | +{ |
| 2 | + lib, |
| 3 | + stdenv, |
| 4 | + fetchFromGitHub, |
| 5 | + fetchpatch, |
| 6 | + buildPackages, |
| 7 | + cmake, |
| 8 | + zlib, |
| 9 | + c-ares, |
| 10 | + pkg-config, |
| 11 | + re2, |
| 12 | + openssl, |
| 13 | + protobuf, |
| 14 | + grpc, |
| 15 | + abseil-cpp, |
| 16 | + libnsl, |
| 17 | + |
| 18 | + # tests |
| 19 | + python3, |
| 20 | + arrow-cpp, |
| 21 | +}: |
| 22 | + |
| 23 | +# This package should be updated together with all related python grpc packages |
| 24 | +# to ensure compatibility. |
| 25 | +# nixpkgs-update: no auto update |
| 26 | +stdenv.mkDerivation rec { |
| 27 | + pname = "grpc"; |
| 28 | + version = "1.69.0"; # N.B: if you change this, please update: |
| 29 | + # pythonPackages.grpcio |
| 30 | + # pythonPackages.grpcio-channelz |
| 31 | + # pythonPackages.grpcio-health-checking |
| 32 | + # pythonPackages.grpcio-reflection |
| 33 | + # pythonPackages.grpcio-status |
| 34 | + # pythonPackages.grpcio-testing |
| 35 | + # pythonPackages.grpcio-tools |
| 36 | + |
| 37 | + src = fetchFromGitHub { |
| 38 | + owner = "grpc"; |
| 39 | + repo = "grpc"; |
| 40 | + rev = "v${version}"; |
| 41 | + hash = "sha256-rRiPUcr6of/sjqB+qr7eOkKVFGTnu8UjluULmcn8df4="; |
| 42 | + fetchSubmodules = true; |
| 43 | + }; |
| 44 | + |
| 45 | + patches = [ |
| 46 | + (fetchpatch { |
| 47 | + # armv6l support, https://github.com/grpc/grpc/pull/21341 |
| 48 | + name = "grpc-link-libatomic.patch"; |
| 49 | + url = "https://github.com/lopsided98/grpc/commit/a9b917666234f5665c347123d699055d8c2537b2.patch"; |
| 50 | + hash = "sha256-Lm0GQsz/UjBbXXEE14lT0dcRzVmCKycrlrdBJj+KLu8="; |
| 51 | + }) |
| 52 | + # fix build of 1.63.0 and newer on darwin: https://github.com/grpc/grpc/issues/36654 |
| 53 | + ] ++ (lib.optional stdenv.hostPlatform.isDarwin ./dynamic-lookup-darwin.patch); |
| 54 | + |
| 55 | + nativeBuildInputs = [ |
| 56 | + cmake |
| 57 | + pkg-config |
| 58 | + ] ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) grpc; |
| 59 | + propagatedBuildInputs = [ |
| 60 | + c-ares |
| 61 | + re2 |
| 62 | + zlib |
| 63 | + abseil-cpp |
| 64 | + ]; |
| 65 | + buildInputs = [ |
| 66 | + openssl |
| 67 | + protobuf |
| 68 | + ] ++ lib.optionals stdenv.hostPlatform.isLinux [ libnsl ]; |
| 69 | + |
| 70 | + cmakeFlags = |
| 71 | + [ |
| 72 | + "-DgRPC_ZLIB_PROVIDER=package" |
| 73 | + "-DgRPC_CARES_PROVIDER=package" |
| 74 | + "-DgRPC_RE2_PROVIDER=package" |
| 75 | + "-DgRPC_SSL_PROVIDER=package" |
| 76 | + "-DgRPC_PROTOBUF_PROVIDER=package" |
| 77 | + "-DgRPC_ABSL_PROVIDER=package" |
| 78 | + "-DBUILD_SHARED_LIBS=ON" |
| 79 | + ] |
| 80 | + ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ |
| 81 | + "-D_gRPC_PROTOBUF_PROTOC_EXECUTABLE=${buildPackages.protobuf}/bin/protoc" |
| 82 | + "-D_gRPC_CPP_PLUGIN=${buildPackages.grpc}/bin/grpc_cpp_plugin" |
| 83 | + ] |
| 84 | + # The build scaffold defaults to c++14 on darwin, even when the compiler uses |
| 85 | + # a more recent c++ version by default [1]. However, downgrades are |
| 86 | + # problematic, because the compatibility types in abseil will have different |
| 87 | + # interface definitions than the ones used for building abseil itself. |
| 88 | + # [1] https://github.com/grpc/grpc/blob/v1.57.0/CMakeLists.txt#L239-L243 |
| 89 | + ++ ( |
| 90 | + let |
| 91 | + defaultCxxIsOlderThan17 = |
| 92 | + (stdenv.cc.isClang && lib.versionAtLeast stdenv.cc.cc.version "16.0") |
| 93 | + || (stdenv.cc.isGNU && lib.versionAtLeast stdenv.cc.cc.version "11.0"); |
| 94 | + in |
| 95 | + lib.optionals (stdenv.hostPlatform.isDarwin && defaultCxxIsOlderThan17) [ |
| 96 | + "-DCMAKE_CXX_STANDARD=17" |
| 97 | + ] |
| 98 | + ); |
| 99 | + |
| 100 | + # CMake creates a build directory by default, this conflicts with the |
| 101 | + # basel BUILD file on case-insensitive filesystems. |
| 102 | + preConfigure = '' |
| 103 | + rm -vf BUILD |
| 104 | + ''; |
| 105 | + |
| 106 | + # When natively compiling, grpc_cpp_plugin is executed from the build directory, |
| 107 | + # needing to load dynamic libraries from the build directory, so we set |
| 108 | + # LD_LIBRARY_PATH to enable this. When cross compiling we need to avoid this, |
| 109 | + # since it can cause the grpc_cpp_plugin executable from buildPackages to |
| 110 | + # crash if build and host architecture are compatible (e. g. pkgsLLVM). |
| 111 | + preBuild = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) '' |
| 112 | + export LD_LIBRARY_PATH=$(pwd)''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH |
| 113 | + ''; |
| 114 | + |
| 115 | + env.NIX_CFLAGS_COMPILE = toString ( |
| 116 | + [ |
| 117 | + "-Wno-error" |
| 118 | + ] |
| 119 | + ++ lib.optionals stdenv.hostPlatform.isDarwin [ |
| 120 | + # Workaround for https://github.com/llvm/llvm-project/issues/48757 |
| 121 | + "-Wno-elaborated-enum-base" |
| 122 | + ] |
| 123 | + ); |
| 124 | + |
| 125 | + enableParallelBuilding = true; |
| 126 | + |
| 127 | + passthru.tests = { |
| 128 | + inherit (python3.pkgs) grpcio-status grpcio-tools jaxlib; |
| 129 | + inherit arrow-cpp; |
| 130 | + }; |
| 131 | + |
| 132 | + meta = with lib; { |
| 133 | + description = "C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)"; |
| 134 | + license = licenses.asl20; |
| 135 | + maintainers = with maintainers; [ lnl7 ]; |
| 136 | + homepage = "https://grpc.io/"; |
| 137 | + platforms = platforms.all; |
| 138 | + changelog = "https://github.com/grpc/grpc/releases/tag/v${version}"; |
| 139 | + }; |
| 140 | +} |
0 commit comments