Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
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.54.2"; # 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-OIRqH+h8Kjbw3X5slpdCfNN0f027WuvHG3q7KUuSWo8="; 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/164f55260262c816e19cd2c41b564486097d62fe.patch"; 41 hash = "sha256-d6kMyjL5ZnEnEz4XZfRgXJBH53gp1r7q1tlwh+HM6+Y="; 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 "-DCMAKE_CXX_STANDARD=${passthru.cxxStandard}" 60 ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ 61 "-D_gRPC_PROTOBUF_PROTOC_EXECUTABLE=${buildPackages.protobuf}/bin/protoc" 62 ]; 63 64 # CMake creates a build directory by default, this conflicts with the 65 # basel BUILD file on case-insensitive filesystems. 66 preConfigure = '' 67 rm -vf BUILD 68 ''; 69 70 # When natively compiling, grpc_cpp_plugin is executed from the build directory, 71 # needing to load dynamic libraries from the build directory, so we set 72 # LD_LIBRARY_PATH to enable this. When cross compiling we need to avoid this, 73 # since it can cause the grpc_cpp_plugin executable from buildPackages to 74 # crash if build and host architecture are compatible (e. g. pkgsLLVM). 75 preBuild = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) '' 76 export LD_LIBRARY_PATH=$(pwd)''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH 77 ''; 78 79 env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang "-Wno-error=unknown-warning-option" 80 + lib.optionalString stdenv.isAarch64 "-Wno-error=format-security"; 81 82 enableParallelBuilds = true; 83 84 passthru.cxxStandard = 85 let 86 # Needs to be compiled with -std=c++11 for clang < 11. Interestingly this is 87 # only an issue with the useLLVM stdenv, not the darwin stdenv… 88 # https://github.com/grpc/grpc/issues/26473#issuecomment-860885484 89 useLLVMAndOldCC = (stdenv.hostPlatform.useLLVM or false) && lib.versionOlder stdenv.cc.cc.version "11.0"; 90 # With GCC 9 (current aarch64-linux) it fails with c++17 but OK with c++14. 91 useOldGCC = !(stdenv.hostPlatform.useLLVM or false) && lib.versionOlder stdenv.cc.cc.version "10"; 92 in 93 (if useLLVMAndOldCC then "11" else if useOldGCC then "14" else "17"); 94 95 passthru.tests = { 96 inherit (python3.pkgs) grpcio-status grpcio-tools; 97 inherit arrow-cpp; 98 }; 99 100 meta = with lib; { 101 description = "The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)"; 102 license = licenses.asl20; 103 maintainers = with maintainers; [ lnl7 marsam ]; 104 homepage = "https://grpc.io/"; 105 platforms = platforms.all; 106 changelog = "https://github.com/grpc/grpc/releases/tag/v${version}"; 107 }; 108}