1{ stdenv, fetchpatch, python, buildPythonPackage, isPy37
2, protobuf, google_apputils, pyext, libcxx
3, disabled, doCheck ? true }:
4
5with stdenv.lib;
6
7buildPythonPackage rec {
8 inherit (protobuf) name src version;
9 inherit disabled doCheck;
10
11 NIX_CFLAGS_COMPILE =
12 # work around python distutils compiling C++ with $CC
13 optional stdenv.isDarwin "-I${libcxx}/include/c++/v1"
14 ++ optional (versionOlder protobuf.version "2.7.0") "-std=c++98";
15
16 propagatedBuildInputs = [ google_apputils ];
17 propagatedNativeBuildInputs = [ protobuf ]; # For protoc.
18 nativeBuildInputs = [ google_apputils pyext ];
19 buildInputs = [ protobuf ];
20
21 patches = optional isPy37
22 # Python 3.7 compatibility (remove when protobuf 3.7 is released)
23 (fetchpatch {
24 url = "https://github.com/protocolbuffers/protobuf/commit/0a59054c30e4f0ba10f10acfc1d7f3814c63e1a7.patch";
25 sha256 = "09hw22y3423v8bbmc9xm07znwdxfbya6rp78d4zqw6fisdvjkqf1";
26 stripLen = 1;
27 })
28 ;
29
30 prePatch = ''
31 while [ ! -d python ]; do
32 cd *
33 done
34 cd python
35 '';
36
37 preConfigure = optionalString (versionAtLeast protobuf.version "2.6.0") ''
38 export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
39 export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION=2
40 '';
41
42 preBuild = ''
43 # Workaround for https://github.com/google/protobuf/issues/2895
44 ${python}/bin/${python.executable} setup.py build
45 '' + optionalString (versionAtLeast protobuf.version "2.6.0") ''
46 ${python}/bin/${python.executable} setup.py build_ext --cpp_implementation
47 '';
48
49 installFlags = optional (versionAtLeast protobuf.version "2.6.0")
50 "--install-option='--cpp_implementation'";
51
52 # the _message.so isn't installed, so we'll do that manually.
53 # if someone can figure out a less hacky way to get the _message.so to
54 # install, please do replace this.
55 postInstall = optionalString (versionAtLeast protobuf.version "2.6.0") ''
56 cp -v $(find build -name "_message*") $out/${python.sitePackages}/google/protobuf/pyext
57 '';
58
59 meta = {
60 description = "Protocol Buffers are Google's data interchange format";
61 homepage = https://developers.google.com/protocol-buffers/;
62 };
63
64 passthru.protobuf = protobuf;
65}