22 stdenv.mkDerivation rec {
24 version = "1.59.1"; # N.B: if you change this, please update:
25 # pythonPackages.grpcio-tools
26 # pythonPackages.grpcio-status
28 src = fetchFromGitHub {
32 hash = "sha256-4bou7oFQOgyxjFqJdmiFT8xEMCsOap9v34W6SPrT4WQ=";
33 fetchSubmodules = true;
38 # armv6l support, https://github.com/grpc/grpc/pull/21341
39 name = "grpc-link-libatomic.patch";
40 url = "https://github.com/lopsided98/grpc/commit/a9b917666234f5665c347123d699055d8c2537b2.patch";
41 hash = "sha256-Lm0GQsz/UjBbXXEE14lT0dcRzVmCKycrlrdBJj+KLu8=";
45 nativeBuildInputs = [ cmake pkg-config ]
46 ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) grpc;
47 propagatedBuildInputs = [ c-ares re2 zlib abseil-cpp ];
48 buildInputs = [ openssl protobuf ]
49 ++ lib.optionals stdenv.isLinux [ libnsl ];
52 "-DgRPC_ZLIB_PROVIDER=package"
53 "-DgRPC_CARES_PROVIDER=package"
54 "-DgRPC_RE2_PROVIDER=package"
55 "-DgRPC_SSL_PROVIDER=package"
56 "-DgRPC_PROTOBUF_PROVIDER=package"
57 "-DgRPC_ABSL_PROVIDER=package"
58 "-DBUILD_SHARED_LIBS=ON"
59 ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
60 "-D_gRPC_PROTOBUF_PROTOC_EXECUTABLE=${buildPackages.protobuf}/bin/protoc"
61 "-D_gRPC_CPP_PLUGIN=${buildPackages.grpc}/bin/grpc_cpp_plugin"
63 # The build scaffold defaults to c++14 on darwin, even when the compiler uses
64 # a more recent c++ version by default [1]. However, downgrades are
65 # problematic, because the compatibility types in abseil will have different
66 # interface definitions than the ones used for building abseil itself.
67 # [1] https://github.com/grpc/grpc/blob/v1.57.0/CMakeLists.txt#L239-L243
69 defaultCxxIsOlderThan17 =
70 (stdenv.cc.isClang && lib.versionAtLeast stdenv.cc.cc.version "16.0")
71 || (stdenv.cc.isGNU && lib.versionAtLeast stdenv.cc.cc.version "11.0");
72 in lib.optionals (stdenv.hostPlatform.isDarwin && defaultCxxIsOlderThan17)
74 "-DCMAKE_CXX_STANDARD=17"
77 # CMake creates a build directory by default, this conflicts with the
78 # basel BUILD file on case-insensitive filesystems.
83 # When natively compiling, grpc_cpp_plugin is executed from the build directory,
84 # needing to load dynamic libraries from the build directory, so we set
85 # LD_LIBRARY_PATH to enable this. When cross compiling we need to avoid this,
86 # since it can cause the grpc_cpp_plugin executable from buildPackages to
87 # crash if build and host architecture are compatible (e. g. pkgsLLVM).
88 preBuild = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
89 export LD_LIBRARY_PATH=$(pwd)''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH
92 env.NIX_CFLAGS_COMPILE = toString ([
94 ] ++ lib.optionals stdenv.isDarwin [
95 # Workaround for https://github.com/llvm/llvm-project/issues/48757
96 "-Wno-elaborated-enum-base"
99 enableParallelBuilds = true;
102 inherit (python3.pkgs) grpcio-status grpcio-tools;
107 description = "The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)";
108 license = licenses.asl20;
109 maintainers = with maintainers; [ lnl7 marsam ];
110 homepage = "https://grpc.io/";
111 platforms = platforms.all;
112 changelog = "https://github.com/grpc/grpc/releases/tag/v${version}";