22 # This package should be updated together with all related python grpc packages
23 # to ensure compatibility.
24 # nixpkgs-update: no auto update
25 stdenv.mkDerivation rec {
27 version = "1.67.0"; # N.B: if you change this, please update:
28 # pythonPackages.grpcio
29 # pythonPackages.grpcio-channelz
30 # pythonPackages.grpcio-health-checking
31 # pythonPackages.grpcio-reflection
32 # pythonPackages.grpcio-status
33 # pythonPackages.grpcio-testing
34 # pythonPackages.grpcio-tools
36 src = fetchFromGitHub {
40 hash = "sha256-NjoSm3ZiHqe0QeVRFWO2FheoOzKjSX2oyiCM3qNUxhM=";
41 fetchSubmodules = true;
46 # armv6l support, https://github.com/grpc/grpc/pull/21341
47 name = "grpc-link-libatomic.patch";
48 url = "https://github.com/lopsided98/grpc/commit/a9b917666234f5665c347123d699055d8c2537b2.patch";
49 hash = "sha256-Lm0GQsz/UjBbXXEE14lT0dcRzVmCKycrlrdBJj+KLu8=";
51 # fix build of 1.63.0 and newer on darwin: https://github.com/grpc/grpc/issues/36654
52 ] ++ (lib.optional stdenv.hostPlatform.isDarwin ./dynamic-lookup-darwin.patch);
54 nativeBuildInputs = [ cmake pkg-config ]
55 ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) grpc;
56 propagatedBuildInputs = [ c-ares re2 zlib abseil-cpp ];
57 buildInputs = [ openssl protobuf ]
58 ++ lib.optionals stdenv.hostPlatform.isLinux [ libnsl ];
61 "-DgRPC_ZLIB_PROVIDER=package"
62 "-DgRPC_CARES_PROVIDER=package"
63 "-DgRPC_RE2_PROVIDER=package"
64 "-DgRPC_SSL_PROVIDER=package"
65 "-DgRPC_PROTOBUF_PROVIDER=package"
66 "-DgRPC_ABSL_PROVIDER=package"
67 "-DBUILD_SHARED_LIBS=ON"
68 ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
69 "-D_gRPC_PROTOBUF_PROTOC_EXECUTABLE=${buildPackages.protobuf}/bin/protoc"
70 "-D_gRPC_CPP_PLUGIN=${buildPackages.grpc}/bin/grpc_cpp_plugin"
72 # The build scaffold defaults to c++14 on darwin, even when the compiler uses
73 # a more recent c++ version by default [1]. However, downgrades are
74 # problematic, because the compatibility types in abseil will have different
75 # interface definitions than the ones used for building abseil itself.
76 # [1] https://github.com/grpc/grpc/blob/v1.57.0/CMakeLists.txt#L239-L243
78 defaultCxxIsOlderThan17 =
79 (stdenv.cc.isClang && lib.versionAtLeast stdenv.cc.cc.version "16.0")
80 || (stdenv.cc.isGNU && lib.versionAtLeast stdenv.cc.cc.version "11.0");
81 in lib.optionals (stdenv.hostPlatform.isDarwin && defaultCxxIsOlderThan17)
83 "-DCMAKE_CXX_STANDARD=17"
86 # CMake creates a build directory by default, this conflicts with the
87 # basel BUILD file on case-insensitive filesystems.
92 # When natively compiling, grpc_cpp_plugin is executed from the build directory,
93 # needing to load dynamic libraries from the build directory, so we set
94 # LD_LIBRARY_PATH to enable this. When cross compiling we need to avoid this,
95 # since it can cause the grpc_cpp_plugin executable from buildPackages to
96 # crash if build and host architecture are compatible (e. g. pkgsLLVM).
97 preBuild = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
98 export LD_LIBRARY_PATH=$(pwd)''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH
101 env.NIX_CFLAGS_COMPILE = toString ([
103 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
104 # Workaround for https://github.com/llvm/llvm-project/issues/48757
105 "-Wno-elaborated-enum-base"
108 enableParallelBuilding = true;
111 inherit (python3.pkgs) grpcio-status grpcio-tools jaxlib;
116 description = "C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)";
117 license = licenses.asl20;
118 maintainers = with maintainers; [ lnl7 ];
119 homepage = "https://grpc.io/";
120 platforms = platforms.all;
121 changelog = "https://github.com/grpc/grpc/releases/tag/v${version}";