1{ stdenv, python, buildPythonPackage
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 = [ protobuf google_apputils ];
17 buildInputs = [ google_apputils pyext ];
18
19 prePatch = ''
20 while [ ! -d python ]; do
21 cd *
22 done
23 cd python
24 '';
25
26 preConfigure = optionalString (versionAtLeast protobuf.version "2.6.0") ''
27 export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
28 export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION=2
29 '';
30
31 preBuild = ''
32 # Workaround for https://github.com/google/protobuf/issues/2895
33 ${python}/bin/${python.executable} setup.py build
34 '' + optionalString (versionAtLeast protobuf.version "2.6.0") ''
35 ${python}/bin/${python.executable} setup.py build_ext --cpp_implementation
36 '';
37
38 installFlags = optional (versionAtLeast protobuf.version "2.6.0")
39 "--install-option='--cpp_implementation'";
40
41 # the _message.so isn't installed, so we'll do that manually.
42 # if someone can figure out a less hacky way to get the _message.so to
43 # install, please do replace this.
44 postInstall = optionalString (versionAtLeast protobuf.version "2.6.0") ''
45 cp -v $(find build -name "_message*") $out/${python.sitePackages}/google/protobuf/pyext
46 '';
47
48 meta = {
49 description = "Protocol Buffers are Google's data interchange format";
50 homepage = https://developers.google.com/protocol-buffers/;
51 };
52
53 passthru.protobuf = protobuf;
54}