1{ buildPackages
2, lib
3, fetchpatch
4, python
5, buildPythonPackage
6, isPy37
7, protobuf
8, google-apputils ? null
9, six
10, pyext
11, isPy27
12, disabled
13, doCheck ? true
14}:
15
16buildPythonPackage {
17 inherit (protobuf) pname src version;
18 inherit disabled;
19 doCheck = doCheck && !isPy27; # setuptools>=41.4 no longer collects correctly on python2
20
21 outputs = [ "out" "dev" ];
22
23 propagatedBuildInputs = [ six ] ++ lib.optionals isPy27 [ google-apputils ];
24 propagatedNativeBuildInputs = [ buildPackages.protobuf ]; # For protoc.
25 nativeBuildInputs = [ pyext ] ++ lib.optionals isPy27 [ google-apputils ];
26 buildInputs = [ protobuf ];
27
28 patches = lib.optional (isPy37 && (lib.versionOlder protobuf.version "3.6.1.2"))
29 # Python 3.7 compatibility (not needed for protobuf >= 3.6.1.2)
30 (fetchpatch {
31 url = "https://github.com/protocolbuffers/protobuf/commit/0a59054c30e4f0ba10f10acfc1d7f3814c63e1a7.patch";
32 sha256 = "09hw22y3423v8bbmc9xm07znwdxfbya6rp78d4zqw6fisdvjkqf1";
33 stripLen = 1;
34 })
35 ;
36
37 prePatch = ''
38 while [ ! -d python ]; do
39 cd *
40 done
41 cd python
42 '';
43
44 preConfigure = lib.optionalString (lib.versionAtLeast protobuf.version "2.6.0") ''
45 export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
46 export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION=2
47 '';
48
49 preBuild = ''
50 # Workaround for https://github.com/google/protobuf/issues/2895
51 ${python.pythonForBuild.interpreter} setup.py build
52 '' + lib.optionalString (lib.versionAtLeast protobuf.version "2.6.0") ''
53 ${python.pythonForBuild.interpreter} setup.py build_ext --cpp_implementation
54 '';
55
56 installFlags = lib.optional (lib.versionAtLeast protobuf.version "2.6.0")
57 "--install-option='--cpp_implementation'";
58
59 # the _message.so isn't installed, so we'll do that manually.
60 # if someone can figure out a less hacky way to get the _message.so to
61 # install, please do replace this.
62 postInstall = lib.optionalString (lib.versionAtLeast protobuf.version "2.6.0") ''
63 cp -v $(find build -name "_message*") $out/${python.sitePackages}/google/protobuf/pyext
64 '';
65
66 meta = with lib; {
67 description = "Protocol Buffers are Google's data interchange format";
68 homepage = "https://developers.google.com/protocol-buffers/";
69 license = licenses.bsd3;
70 };
71
72 passthru.protobuf = protobuf;
73}