lol
1{ lib
2, stdenv
3, fetchFromGitHub
4, fetchpatch
5, buildPackages
6, cmake
7, zlib
8, c-ares
9, pkg-config
10, re2
11, openssl
12, protobuf
13, grpc
14, abseil-cpp
15, libnsl
16
17# tests
18, python3
19, arrow-cpp
20}:
21
22stdenv.mkDerivation rec {
23 pname = "grpc";
24 version = "1.59.1"; # N.B: if you change this, please update:
25 # pythonPackages.grpcio-tools
26 # pythonPackages.grpcio-status
27
28 src = fetchFromGitHub {
29 owner = "grpc";
30 repo = "grpc";
31 rev = "v${version}";
32 hash = "sha256-4bou7oFQOgyxjFqJdmiFT8xEMCsOap9v34W6SPrT4WQ=";
33 fetchSubmodules = true;
34 };
35
36 patches = [
37 (fetchpatch {
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=";
42 })
43 ];
44
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 ];
50
51 cmakeFlags = [
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"
62 ]
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
68 ++ (let
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)
73 [
74 "-DCMAKE_CXX_STANDARD=17"
75 ]);
76
77 # CMake creates a build directory by default, this conflicts with the
78 # basel BUILD file on case-insensitive filesystems.
79 preConfigure = ''
80 rm -vf BUILD
81 '';
82
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
90 '';
91
92 env.NIX_CFLAGS_COMPILE = toString ([
93 "-Wno-error"
94 ] ++ lib.optionals stdenv.isDarwin [
95 # Workaround for https://github.com/llvm/llvm-project/issues/48757
96 "-Wno-elaborated-enum-base"
97 ]);
98
99 enableParallelBuilds = true;
100
101 passthru.tests = {
102 inherit (python3.pkgs) grpcio-status grpcio-tools;
103 inherit arrow-cpp;
104 };
105
106 meta = with lib; {
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}";
113 };
114}