nixpkgs/pkgs/development/python-modules/protobuf/default.nix

67 lines
2.2 KiB
Nix
Raw Normal View History

pythonPackages.protobuf: apply patch for python 3.7 only when building with it Change introduced in #50672. The patch does not apply on older protobuf like protobuf3_1 ``` $ nix-build -E 'with import ./. { }; python3Packages.protobuf.override { protobuf = protobuf3_1; }' unpacking sources unpacking source archive /nix/store/1zdyl0cxaa8ha2v1zp75zzdjd6j99d0m-source source root is source setting SOURCE_DATE_EPOCH to timestamp 315619200 of file source/util/python/BUILD patching sources applying patch /nix/store/yagx7hvylnnjq7lxbcia0y5lq1r736w3-0a59054c30e4f0ba10f10acfc1d7f3814c63e1a7.patch patching file google/protobuf/pyext/descriptor.cc Hunk #1 succeeded at 55 (offset -1 lines). patching file google/protobuf/pyext/descriptor_containers.cc patching file google/protobuf/pyext/descriptor_pool.cc Hunk #1 succeeded at 47 (offset -1 lines). patching file google/protobuf/pyext/extension_dict.cc Hunk #1 FAILED at 53. 1 out of 1 hunk FAILED -- saving rejects to file google/protobuf/pyext/extension_dict.cc.rej patching file google/protobuf/pyext/message.cc Hunk #1 succeeded at 82 (offset 3 lines). Hunk #2 succeeded at 1425 (offset -104 lines). ``` Since the patch isn't necessary on python versions older than 3.7, let's only apply it for version 3.7. This means that most things using older protobuf implementation will now be able to build when using an older pythonPackage set (as is most probably the case anyway). This still leaves protobuf 3.1 using packages hanging, but the errors will be localized to those that would be breaking anyway with the upgrade to 3.7 as default python.
2018-12-10 03:15:48 +00:00
{ stdenv, fetchpatch, python, buildPythonPackage, isPy37
, protobuf, google_apputils, pyext, libcxx
, disabled, doCheck ? true }:
with stdenv.lib;
2019-08-13 22:52:01 +01:00
buildPythonPackage {
inherit (protobuf) name src version;
inherit disabled doCheck;
2017-09-03 15:20:31 +01:00
NIX_CFLAGS_COMPILE =
# work around python distutils compiling C++ with $CC
optional stdenv.isDarwin "-I${libcxx}/include/c++/v1"
++ optional (versionOlder protobuf.version "2.7.0") "-std=c++98";
2019-02-15 08:02:59 +00:00
propagatedBuildInputs = [ google_apputils ];
propagatedNativeBuildInputs = [ protobuf ]; # For protoc.
nativeBuildInputs = [ google_apputils pyext ];
2019-02-15 08:02:59 +00:00
buildInputs = [ protobuf ];
2019-03-09 14:19:32 +00:00
patches = optional (isPy37 && (versionOlder protobuf.version "3.6.1.2"))
# Python 3.7 compatibility (not needed for protobuf >= 3.6.1.2)
(fetchpatch {
url = "https://github.com/protocolbuffers/protobuf/commit/0a59054c30e4f0ba10f10acfc1d7f3814c63e1a7.patch";
sha256 = "09hw22y3423v8bbmc9xm07znwdxfbya6rp78d4zqw6fisdvjkqf1";
stripLen = 1;
})
pythonPackages.protobuf: apply patch for python 3.7 only when building with it Change introduced in #50672. The patch does not apply on older protobuf like protobuf3_1 ``` $ nix-build -E 'with import ./. { }; python3Packages.protobuf.override { protobuf = protobuf3_1; }' unpacking sources unpacking source archive /nix/store/1zdyl0cxaa8ha2v1zp75zzdjd6j99d0m-source source root is source setting SOURCE_DATE_EPOCH to timestamp 315619200 of file source/util/python/BUILD patching sources applying patch /nix/store/yagx7hvylnnjq7lxbcia0y5lq1r736w3-0a59054c30e4f0ba10f10acfc1d7f3814c63e1a7.patch patching file google/protobuf/pyext/descriptor.cc Hunk #1 succeeded at 55 (offset -1 lines). patching file google/protobuf/pyext/descriptor_containers.cc patching file google/protobuf/pyext/descriptor_pool.cc Hunk #1 succeeded at 47 (offset -1 lines). patching file google/protobuf/pyext/extension_dict.cc Hunk #1 FAILED at 53. 1 out of 1 hunk FAILED -- saving rejects to file google/protobuf/pyext/extension_dict.cc.rej patching file google/protobuf/pyext/message.cc Hunk #1 succeeded at 82 (offset 3 lines). Hunk #2 succeeded at 1425 (offset -104 lines). ``` Since the patch isn't necessary on python versions older than 3.7, let's only apply it for version 3.7. This means that most things using older protobuf implementation will now be able to build when using an older pythonPackage set (as is most probably the case anyway). This still leaves protobuf 3.1 using packages hanging, but the errors will be localized to those that would be breaking anyway with the upgrade to 3.7 as default python.
2018-12-10 03:15:48 +00:00
;
prePatch = ''
while [ ! -d python ]; do
cd *
done
cd python
'';
preConfigure = optionalString (versionAtLeast protobuf.version "2.6.0") ''
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION=2
'';
preBuild = ''
# Workaround for https://github.com/google/protobuf/issues/2895
${python.interpreter} setup.py build
'' + optionalString (versionAtLeast protobuf.version "2.6.0") ''
${python.interpreter} setup.py build_ext --cpp_implementation
'';
installFlags = optional (versionAtLeast protobuf.version "2.6.0")
"--install-option='--cpp_implementation'";
# the _message.so isn't installed, so we'll do that manually.
# if someone can figure out a less hacky way to get the _message.so to
# install, please do replace this.
postInstall = optionalString (versionAtLeast protobuf.version "2.6.0") ''
cp -v $(find build -name "_message*") $out/${python.sitePackages}/google/protobuf/pyext
'';
meta = {
description = "Protocol Buffers are Google's data interchange format";
homepage = https://developers.google.com/protocol-buffers/;
license = licenses.bsd3;
};
passthru.protobuf = protobuf;
}