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 = optionalString (versionAtLeast protobuf.version "2.6.0") ''
32 ${python}/bin/${python.executable} setup.py build_ext --cpp_implementation
33 '';
34
35 installFlags = optional (versionAtLeast protobuf.version "2.6.0")
36 "--install-option='--cpp_implementation'";
37
38 # the _message.so isn't installed, so we'll do that manually.
39 # if someone can figure out a less hacky way to get the _message.so to
40 # install, please do replace this.
41 postInstall = optionalString (versionAtLeast protobuf.version "2.6.0") ''
42 cp -v $(find build -name "_message*") $out/${python.sitePackages}/google/protobuf/pyext
43 '';
44
45 meta = {
46 description = "Protocol Buffers are Google's data interchange format";
47 homepage = https://developers.google.com/protocol-buffers/;
48 };
49
50 passthru.protobuf = protobuf;
51}