2021-01-09 10:05:03 +00:00
|
|
|
{ buildPackages
|
2021-02-05 17:12:51 +00:00
|
|
|
, lib
|
2021-01-09 10:05:03 +00:00
|
|
|
, buildPythonPackage
|
|
|
|
, protobuf
|
2022-11-02 22:02:43 +00:00
|
|
|
, isPyPy
|
2023-01-20 10:41:00 +00:00
|
|
|
, fetchpatch
|
|
|
|
, pythonAtLeast
|
2021-01-09 10:05:03 +00:00
|
|
|
}:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-11-21 17:40:18 +00:00
|
|
|
let
|
|
|
|
versionMajor = lib.versions.major protobuf.version;
|
|
|
|
versionMinor = lib.versions.minor protobuf.version;
|
|
|
|
versionPatch = lib.versions.patch protobuf.version;
|
|
|
|
in
|
2020-04-24 23:36:52 +00:00
|
|
|
buildPythonPackage {
|
2022-11-21 17:40:18 +00:00
|
|
|
inherit (protobuf) pname src;
|
|
|
|
|
|
|
|
# protobuf 3.21 coresponds with its python library 4.21
|
|
|
|
version =
|
|
|
|
if lib.versionAtLeast protobuf.version "3.21"
|
|
|
|
then "${toString (lib.toInt versionMajor + 1)}.${versionMinor}.${versionPatch}"
|
|
|
|
else protobuf.version;
|
|
|
|
|
2022-11-02 22:02:43 +00:00
|
|
|
disabled = isPyPy;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-11-21 17:40:18 +00:00
|
|
|
sourceRoot = "source/python";
|
|
|
|
|
2023-01-20 10:41:00 +00:00
|
|
|
patches = lib.optionals (pythonAtLeast "3.11") [
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/protocolbuffers/protobuf/commit/da973aff2adab60a9e516d3202c111dbdde1a50f.patch";
|
|
|
|
stripLen = 2;
|
|
|
|
extraPrefix = "";
|
|
|
|
hash = "sha256-a/12C6yIe1tEKjsMxcfDAQ4JHolA8CzkN7sNG8ZspPs=";
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
prePatch = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
if [[ "$(<../version.json)" != *'"python": "'"$version"'"'* ]]; then
|
|
|
|
echo "Python library version mismatch. Derivation version: $version, actual: $(<../version.json)"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
outputs = [ "out" "dev" ];
|
|
|
|
|
2022-11-02 22:02:43 +00:00
|
|
|
buildInputs = [ protobuf ];
|
|
|
|
|
|
|
|
propagatedNativeBuildInputs = [
|
|
|
|
# For protoc of the same version.
|
|
|
|
buildPackages."protobuf${lib.versions.major protobuf.version}_${lib.versions.minor protobuf.version}"
|
|
|
|
];
|
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
setupPyGlobalFlags = [ "--cpp_implementation" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-12-19 01:06:50 +00:00
|
|
|
pythonImportsCheck = [
|
|
|
|
"google.protobuf"
|
|
|
|
"google.protobuf.internal._api_implementation" # Verify that --cpp_implementation worked
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-11-02 22:02:43 +00:00
|
|
|
passthru = {
|
|
|
|
inherit protobuf;
|
|
|
|
};
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Protocol Buffers are Google's data interchange format";
|
|
|
|
homepage = "https://developers.google.com/protocol-buffers/";
|
|
|
|
license = licenses.bsd3;
|
2021-12-19 01:06:50 +00:00
|
|
|
maintainers = with maintainers; [ knedlsepp ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|