2021-01-05 11:25:54 +00:00
|
|
|
{ buildPackages
|
2021-01-24 00:29:22 +00:00
|
|
|
, lib
|
2021-01-05 11:25:54 +00:00
|
|
|
, fetchpatch
|
|
|
|
, python
|
|
|
|
, buildPythonPackage
|
|
|
|
, isPy37
|
|
|
|
, protobuf
|
2021-03-24 16:45:56 +00:00
|
|
|
, google-apputils ? null
|
2021-01-05 11:25:54 +00:00
|
|
|
, six
|
|
|
|
, pyext
|
|
|
|
, libcxx
|
|
|
|
, isPy27
|
|
|
|
, disabled
|
|
|
|
, doCheck ? true
|
|
|
|
}:
|
2017-01-23 13:25:19 +00:00
|
|
|
|
2019-08-13 22:52:01 +01:00
|
|
|
buildPythonPackage {
|
2020-09-30 05:30:17 +01:00
|
|
|
inherit (protobuf) pname src version;
|
2019-10-17 16:59:01 +01:00
|
|
|
inherit disabled;
|
|
|
|
doCheck = doCheck && !isPy27; # setuptools>=41.4 no longer collects correctly on python2
|
2017-01-23 13:25:19 +00:00
|
|
|
|
2020-09-30 05:30:17 +01:00
|
|
|
outputs = [ "out" "dev" ];
|
|
|
|
|
2021-01-24 00:29:22 +00:00
|
|
|
propagatedBuildInputs = [ six ] ++ lib.optionals isPy27 [ google-apputils ];
|
2021-01-05 11:25:54 +00:00
|
|
|
propagatedNativeBuildInputs = [ buildPackages.protobuf ]; # For protoc.
|
2021-01-24 00:29:22 +00:00
|
|
|
nativeBuildInputs = [ pyext ] ++ lib.optionals isPy27 [ google-apputils ];
|
2019-02-15 08:02:59 +00:00
|
|
|
buildInputs = [ protobuf ];
|
2017-01-23 13:25:19 +00:00
|
|
|
|
2021-01-24 00:29:22 +00:00
|
|
|
patches = lib.optional (isPy37 && (lib.versionOlder protobuf.version "3.6.1.2"))
|
2019-03-09 14:19:32 +00:00
|
|
|
# Python 3.7 compatibility (not needed for protobuf >= 3.6.1.2)
|
2018-11-24 23:09:52 +00:00
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/protocolbuffers/protobuf/commit/0a59054c30e4f0ba10f10acfc1d7f3814c63e1a7.patch";
|
|
|
|
sha256 = "09hw22y3423v8bbmc9xm07znwdxfbya6rp78d4zqw6fisdvjkqf1";
|
|
|
|
stripLen = 1;
|
|
|
|
})
|
2018-12-10 03:15:48 +00:00
|
|
|
;
|
2018-11-24 23:09:52 +00:00
|
|
|
|
2017-01-23 13:25:19 +00:00
|
|
|
prePatch = ''
|
|
|
|
while [ ! -d python ]; do
|
|
|
|
cd *
|
|
|
|
done
|
|
|
|
cd python
|
|
|
|
'';
|
|
|
|
|
2021-01-24 00:29:22 +00:00
|
|
|
preConfigure = lib.optionalString (lib.versionAtLeast protobuf.version "2.6.0") ''
|
2017-01-23 13:25:19 +00:00
|
|
|
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
|
|
|
|
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION=2
|
|
|
|
'';
|
|
|
|
|
2018-08-17 00:35:17 +01:00
|
|
|
preBuild = ''
|
|
|
|
# Workaround for https://github.com/google/protobuf/issues/2895
|
2020-09-30 05:30:17 +01:00
|
|
|
${python.pythonForBuild.interpreter} setup.py build
|
2021-01-24 00:29:22 +00:00
|
|
|
'' + lib.optionalString (lib.versionAtLeast protobuf.version "2.6.0") ''
|
2020-09-30 05:30:17 +01:00
|
|
|
${python.pythonForBuild.interpreter} setup.py build_ext --cpp_implementation
|
2017-01-23 13:25:19 +00:00
|
|
|
'';
|
|
|
|
|
2021-01-24 00:29:22 +00:00
|
|
|
installFlags = lib.optional (lib.versionAtLeast protobuf.version "2.6.0")
|
2017-01-23 13:25:19 +00:00
|
|
|
"--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.
|
2021-01-24 00:29:22 +00:00
|
|
|
postInstall = lib.optionalString (lib.versionAtLeast protobuf.version "2.6.0") ''
|
2017-01-23 13:25:19 +00:00
|
|
|
cp -v $(find build -name "_message*") $out/${python.sitePackages}/google/protobuf/pyext
|
|
|
|
'';
|
|
|
|
|
2021-01-24 00:29:22 +00:00
|
|
|
meta = with lib; {
|
2017-01-23 13:25:19 +00:00
|
|
|
description = "Protocol Buffers are Google's data interchange format";
|
2020-04-01 02:11:51 +01:00
|
|
|
homepage = "https://developers.google.com/protocol-buffers/";
|
2019-09-13 00:43:15 +01:00
|
|
|
license = licenses.bsd3;
|
2017-01-23 13:25:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
passthru.protobuf = protobuf;
|
|
|
|
}
|