nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
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}:
20
21stdenv.mkDerivation rec {
22 pname = "grpc";
23 version = "1.46.3"; # N.B: if you change this, please update:
24 # pythonPackages.grpcio-tools
25 # pythonPackages.grpcio-status
26
27 src = fetchFromGitHub {
28 owner = "grpc";
29 repo = "grpc";
30 rev = "v${version}";
31 sha256 = "sha256-RiXtKlRtlbqwrSxI904dgSu3da0A6Fwk+/hWHIG7A5E=";
32 fetchSubmodules = true;
33 };
34
35 patches = [
36 # Fix build on armv6l (https://github.com/grpc/grpc/pull/21341)
37 (fetchpatch {
38 url = "https://github.com/grpc/grpc/commit/2f4cf1d9265c8e10fb834f0794d0e4f3ec5ae10e.patch";
39 sha256 = "0ams3jmgh9yzwmxcg4ifb34znamr7pb4qm0609kvil9xqvkqz963";
40 })
41
42 # Revert gRPC C++ Mutex to be an alias of Abseil, because it breaks dependent packages
43 (fetchpatch {
44 url = "https://github.com/grpc/grpc/commit/931f91b745cd5b2864a0d1787815871d0bd844ae.patch";
45 sha256 = "0vc93g2i4982ys4gzyaxdv9ni25yk10sxq3n7fkz8dypy8sylck7";
46 revert = true;
47 })
48 ];
49
50 nativeBuildInputs = [ cmake pkg-config ]
51 ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) grpc;
52 propagatedBuildInputs = [ c-ares re2 zlib abseil-cpp ];
53 buildInputs = [ c-ares.cmake-config openssl protobuf ]
54 ++ lib.optionals stdenv.isLinux [ libnsl ];
55
56 cmakeFlags = [
57 "-DgRPC_ZLIB_PROVIDER=package"
58 "-DgRPC_CARES_PROVIDER=package"
59 "-DgRPC_RE2_PROVIDER=package"
60 "-DgRPC_SSL_PROVIDER=package"
61 "-DgRPC_PROTOBUF_PROVIDER=package"
62 "-DgRPC_ABSL_PROVIDER=package"
63 "-DBUILD_SHARED_LIBS=ON"
64 "-DCMAKE_SKIP_BUILD_RPATH=OFF"
65 ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
66 "-D_gRPC_PROTOBUF_PROTOC_EXECUTABLE=${buildPackages.protobuf}/bin/protoc"
67 ] ++ lib.optionals ((stdenv.hostPlatform.useLLVM or false) && lib.versionOlder stdenv.cc.cc.version "11.0") [
68 # Needs to be compiled with -std=c++11 for clang < 11. Interestingly this is
69 # only an issue with the useLLVM stdenv, not the darwin stdenv…
70 # https://github.com/grpc/grpc/issues/26473#issuecomment-860885484
71 "-DCMAKE_CXX_STANDARD=11"
72 ];
73
74 # CMake creates a build directory by default, this conflicts with the
75 # basel BUILD file on case-insensitive filesystems.
76 preConfigure = ''
77 rm -vf BUILD
78 '';
79
80 # When natively compiling, grpc_cpp_plugin is executed from the build directory,
81 # needing to load dynamic libraries from the build directory, so we set
82 # LD_LIBRARY_PATH to enable this. When cross compiling we need to avoid this,
83 # since it can cause the grpc_cpp_plugin executable from buildPackages to
84 # crash if build and host architecture are compatible (e. g. pkgsLLVM).
85 preBuild = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
86 export LD_LIBRARY_PATH=$(pwd)''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH
87 '';
88
89 NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang "-Wno-error=unknown-warning-option"
90 + lib.optionalString stdenv.isAarch64 "-Wno-error=format-security";
91
92 enableParallelBuilds = true;
93
94 passthru.tests = {
95 inherit (python3.pkgs) grpcio-status grpcio-tools;
96 };
97
98 meta = with lib; {
99 description = "The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)";
100 license = licenses.asl20;
101 maintainers = with maintainers; [ lnl7 marsam ];
102 homepage = "https://grpc.io/";
103 platforms = platforms.all;
104 changelog = "https://github.com/grpc/grpc/releases/tag/v${version}";
105 };
106}