1{ buildPackages
2, lib
3, buildPythonPackage
4, protobuf
5, pyext
6, isPyPy
7}:
8
9let
10 versionMajor = lib.versions.major protobuf.version;
11 versionMinor = lib.versions.minor protobuf.version;
12 versionPatch = lib.versions.patch protobuf.version;
13in
14buildPythonPackage {
15 inherit (protobuf) pname src;
16
17 # protobuf 3.21 coresponds with its python library 4.21
18 version =
19 if lib.versionAtLeast protobuf.version "3.21"
20 then "${toString (lib.toInt versionMajor + 1)}.${versionMinor}.${versionPatch}"
21 else protobuf.version;
22
23 disabled = isPyPy;
24
25 sourceRoot = "source/python";
26
27 prePatch = ''
28 if [[ "$(<../version.json)" != *'"python": "'"$version"'"'* ]]; then
29 echo "Python library version mismatch. Derivation version: $version, actual: $(<../version.json)"
30 exit 1
31 fi
32 '';
33
34 nativeBuildInputs = [ pyext ];
35
36 buildInputs = [ protobuf ];
37
38 propagatedNativeBuildInputs = [
39 # For protoc of the same version.
40 buildPackages."protobuf${lib.versions.major protobuf.version}_${lib.versions.minor protobuf.version}"
41 ];
42
43 setupPyGlobalFlags = "--cpp_implementation";
44
45 pythonImportsCheck = [
46 "google.protobuf"
47 "google.protobuf.internal._api_implementation" # Verify that --cpp_implementation worked
48 ];
49
50 passthru = {
51 inherit protobuf;
52 };
53
54 meta = with lib; {
55 description = "Protocol Buffers are Google's data interchange format";
56 homepage = "https://developers.google.com/protocol-buffers/";
57 license = licenses.bsd3;
58 maintainers = with maintainers; [ knedlsepp ];
59 };
60}