From add6320cdd60add4ec40c6b86218670b0b03ef79 Mon Sep 17 00:00:00 2001 From: Viacheslav Lotsmanov Date: Fri, 29 Jul 2022 03:13:05 +0300 Subject: [PATCH] Pin versions of gRPC dependencies --- nix/grpc-pin/grpc.nix | 108 +++++++++++++++++++++++++++++++++ nix/grpc-pin/grpcio-status.nix | 43 +++++++++++++ nix/grpc-pin/grpcio-tools.nix | 31 ++++++++++ release.nix | 33 ++++++++-- 4 files changed, 210 insertions(+), 5 deletions(-) create mode 100644 nix/grpc-pin/grpc.nix create mode 100644 nix/grpc-pin/grpcio-status.nix create mode 100644 nix/grpc-pin/grpcio-tools.nix diff --git a/nix/grpc-pin/grpc.nix b/nix/grpc-pin/grpc.nix new file mode 100644 index 0000000..267450f --- /dev/null +++ b/nix/grpc-pin/grpc.nix @@ -0,0 +1,108 @@ +# Copy-paste from nixpkgs “release-22.05” branch + +{ lib +, stdenv +, fetchFromGitHub +, fetchpatch +, buildPackages +, cmake +, zlib +, c-ares +, pkg-config +, re2 +, openssl +, protobuf +, grpc +, abseil-cpp +, libnsl + +# tests +, python3 +}: + +stdenv.mkDerivation rec { + pname = "grpc"; + version = "1.46.3"; # N.B: if you change this, please update: + # pythonPackages.grpcio-tools + # pythonPackages.grpcio-status + + src = fetchFromGitHub { + owner = "grpc"; + repo = "grpc"; + rev = "v${version}"; + sha256 = "sha256-RiXtKlRtlbqwrSxI904dgSu3da0A6Fwk+/hWHIG7A5E="; + fetchSubmodules = true; + }; + + patches = [ + # Fix build on armv6l (https://github.com/grpc/grpc/pull/21341) + (fetchpatch { + url = "https://github.com/grpc/grpc/commit/2f4cf1d9265c8e10fb834f0794d0e4f3ec5ae10e.patch"; + sha256 = "0ams3jmgh9yzwmxcg4ifb34znamr7pb4qm0609kvil9xqvkqz963"; + }) + + # Revert gRPC C++ Mutex to be an alias of Abseil, because it breaks dependent packages + (fetchpatch { + url = "https://github.com/grpc/grpc/commit/931f91b745cd5b2864a0d1787815871d0bd844ae.patch"; + sha256 = "0vc93g2i4982ys4gzyaxdv9ni25yk10sxq3n7fkz8dypy8sylck7"; + revert = true; + }) + ]; + + nativeBuildInputs = [ cmake pkg-config ] + ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) grpc; + propagatedBuildInputs = [ c-ares re2 zlib abseil-cpp ]; + buildInputs = [ c-ares.cmake-config openssl protobuf ] + ++ lib.optionals stdenv.isLinux [ libnsl ]; + + cmakeFlags = [ + "-DgRPC_ZLIB_PROVIDER=package" + "-DgRPC_CARES_PROVIDER=package" + "-DgRPC_RE2_PROVIDER=package" + "-DgRPC_SSL_PROVIDER=package" + "-DgRPC_PROTOBUF_PROVIDER=package" + "-DgRPC_ABSL_PROVIDER=package" + "-DBUILD_SHARED_LIBS=ON" + "-DCMAKE_SKIP_BUILD_RPATH=OFF" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-D_gRPC_PROTOBUF_PROTOC_EXECUTABLE=${buildPackages.protobuf}/bin/protoc" + ] ++ lib.optionals ((stdenv.hostPlatform.useLLVM or false) && lib.versionOlder stdenv.cc.cc.version "11.0") [ + # Needs to be compiled with -std=c++11 for clang < 11. Interestingly this is + # only an issue with the useLLVM stdenv, not the darwin stdenv… + # https://github.com/grpc/grpc/issues/26473#issuecomment-860885484 + "-DCMAKE_CXX_STANDARD=11" + ]; + + # CMake creates a build directory by default, this conflicts with the + # basel BUILD file on case-insensitive filesystems. + preConfigure = '' + rm -vf BUILD + ''; + + # When natively compiling, grpc_cpp_plugin is executed from the build directory, + # needing to load dynamic libraries from the build directory, so we set + # LD_LIBRARY_PATH to enable this. When cross compiling we need to avoid this, + # since it can cause the grpc_cpp_plugin executable from buildPackages to + # crash if build and host architecture are compatible (e. g. pkgsLLVM). + preBuild = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) '' + export LD_LIBRARY_PATH=$(pwd)''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH + ''; + + NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang "-Wno-error=unknown-warning-option" + + lib.optionalString stdenv.isAarch64 "-Wno-error=format-security"; + + enableParallelBuilds = true; + + passthru.tests = { + inherit (python3.pkgs) grpcio-status grpcio-tools; + }; + + meta = with lib; { + description = "The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)"; + license = licenses.asl20; + maintainers = with maintainers; [ lnl7 marsam ]; + homepage = "https://grpc.io/"; + platforms = platforms.all; + changelog = "https://github.com/grpc/grpc/releases/tag/v${version}"; + }; +} diff --git a/nix/grpc-pin/grpcio-status.nix b/nix/grpc-pin/grpcio-status.nix new file mode 100644 index 0000000..d39f3c9 --- /dev/null +++ b/nix/grpc-pin/grpcio-status.nix @@ -0,0 +1,43 @@ +# Copy-paste from nixpkgs “release-22.05” branch + +{ lib +, buildPythonPackage +, fetchPypi +, googleapis-common-protos +, grpcio +, protobuf +, pythonOlder +}: + +buildPythonPackage rec { + pname = "grpcio-status"; + version = "1.46.3"; + format = "setuptools"; + + disabled = pythonOlder "3.6"; + + src = fetchPypi { + inherit pname version; + sha256 = "78442ac7d2813c56f9cc04f713efd7088596b10f88a4ddd09279211cc48402d5"; + }; + + propagatedBuildInputs = [ + googleapis-common-protos + grpcio + protobuf + ]; + + # Projec thas no tests + doCheck = false; + + pythonImportsCheck = [ + "grpc_status" + ]; + + meta = with lib; { + description = "GRPC Python status proto mapping"; + homepage = "https://github.com/grpc/grpc/tree/master/src/python/grpcio_status"; + license = licenses.asl20; + maintainers = with maintainers; [ fab ]; + }; +} diff --git a/nix/grpc-pin/grpcio-tools.nix b/nix/grpc-pin/grpcio-tools.nix new file mode 100644 index 0000000..fbab154 --- /dev/null +++ b/nix/grpc-pin/grpcio-tools.nix @@ -0,0 +1,31 @@ +# Copy-paste from nixpkgs “release-22.05” branch + +{ lib, buildPythonPackage, fetchPypi, protobuf, grpcio, setuptools }: + +buildPythonPackage rec { + pname = "grpcio-tools"; + version = "1.46.3"; + + src = fetchPypi { + inherit pname version; + sha256 = "31fee436ace5b3bd950cc3a8e68d6b84de1d6dc755959db7badc3470cdf22f70"; + }; + + outputs = [ "out" "dev" ]; + + enableParallelBuilding = true; + + propagatedBuildInputs = [ protobuf grpcio setuptools ]; + + # no tests in the package + doCheck = false; + + pythonImportsCheck = [ "grpc_tools" ]; + + meta = with lib; { + description = "Protobuf code generator for gRPC"; + license = licenses.asl20; + homepage = "https://grpc.io/grpc/python/"; + maintainers = with maintainers; [ ]; + }; +} diff --git a/release.nix b/release.nix index bfaadc8..d039b6b 100644 --- a/release.nix +++ b/release.nix @@ -66,8 +66,35 @@ # };); let + # Taking specific Python version. + # + # N.B. Mind that some of the dependencies of gRPC Python packages + # (“grpcio-status” and “grpcio-tools”) do not support Python 2 anymore: + # “error: mox-0.7.8 not supported for interpreter python2.7”. + # So do not use “python” as a value since it defaults to Python 2. + pythonVer = "python3"; + overlay = pkgsSelf: pkgsSuper: { + # “grpc-haskell” is made for specific version of gRPC library. + # So this override makes sure it would still work against another nixpkgs + # pin where gRPC can have different version. + grpc = pkgsSelf.callPackage nix/grpc-pin/grpc.nix { + # grpc builds with c++14 so abseil must also be built that way + abseil-cpp = pkgsSelf.abseil-cpp_202111.override { + cxxStandard = "14"; + }; + }; + + # As recommended for “grpc” derivation also overriding + # “grpcio-status” and “grpcio-tools” to the same version. + ${pythonVer} = pkgsSuper.${pythonVer}.override { + packageOverrides = pySelf: pySuper: { + grpcio-status = pySelf.callPackage nix/grpc-pin/grpcio-status.nix {}; + grpcio-tools = pySelf.callPackage nix/grpc-pin/grpcio-tools.nix {}; + }; + }; + haskellPackages = (hsPkgsOverridden pkgsSuper).extend (hsSelf: hsSuper: { grpc-haskell-core = @@ -98,7 +125,7 @@ let pkgs.turtle ]); - python = pkgsSelf.python.withPackages (pkgs: [ + python = pkgsSelf.${pythonVer}.withPackages (pkgs: [ pkgs.grpcio-tools ]); @@ -186,10 +213,6 @@ let export LD_LIBRARY_PATH=${pkgsSelf.grpc}/lib''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH ''; }); - - # Fix this error when entering a nix-shell: - # error: mox-0.7.8 not supported for interpreter python2.7 - python = pkgsSelf.python3; }; hsAddPatch = pkgs: patchFile: