aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/pkgs/development/python-modules/protobuf/default.nix
blob: ab95eeb51f9149be30ee00f43fa113147617b607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
{ buildPackages, stdenv, fetchpatch, python, buildPythonPackage, isPy37
, protobuf, google_apputils, pyext, libcxx, isPy27
, disabled, doCheck ? true }:

with stdenv.lib;

buildPythonPackage {
  inherit (protobuf) pname src version;
  inherit disabled;
  doCheck = doCheck && !isPy27; # setuptools>=41.4 no longer collects correctly on python2

  NIX_CFLAGS_COMPILE = toString (
    # work around python distutils compiling C++ with $CC
    optional stdenv.isDarwin "-I${libcxx}/include/c++/v1"
    ++ optional (versionOlder protobuf.version "2.7.0") "-std=c++98"
  );

  outputs = [ "out" "dev" ];

  propagatedBuildInputs = [ google_apputils ];
  propagatedNativeBuildInputs = [ buildPackages.protobuf ];  # For protoc.
  nativeBuildInputs = [ google_apputils pyext ];
  buildInputs = [ protobuf ];

  patches = optional (isPy37 && (versionOlder protobuf.version "3.6.1.2"))
    # Python 3.7 compatibility (not needed for protobuf >= 3.6.1.2)
    (fetchpatch {
      url = "https://github.com/protocolbuffers/protobuf/commit/0a59054c30e4f0ba10f10acfc1d7f3814c63e1a7.patch";
      sha256 = "09hw22y3423v8bbmc9xm07znwdxfbya6rp78d4zqw6fisdvjkqf1";
      stripLen = 1;
    })
  ;

  prePatch = ''
    while [ ! -d python ]; do
      cd *
    done
    cd python
  '';

  preConfigure = optionalString (versionAtLeast protobuf.version "2.6.0") ''
    export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
    export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION=2
  '';

  preBuild = ''
    # Workaround for https://github.com/google/protobuf/issues/2895
    ${python.pythonForBuild.interpreter} setup.py build
  '' + optionalString (versionAtLeast protobuf.version "2.6.0") ''
    ${python.pythonForBuild.interpreter} setup.py build_ext --cpp_implementation
  '';

  installFlags = optional (versionAtLeast protobuf.version "2.6.0")
    "--install-option='--cpp_implementation'";

  # the _message.so isn't installed, so we'll do that manually.
  # if someone can figure out a less hacky way to get the _message.so to
  # install, please do replace this.
  postInstall = optionalString (versionAtLeast protobuf.version "2.6.0") ''
    cp -v $(find build -name "_message*") $out/${python.sitePackages}/google/protobuf/pyext
  '';

  meta = {
    description = "Protocol Buffers are Google's data interchange format";
    homepage = "https://developers.google.com/protocol-buffers/";
    license = licenses.bsd3;
  };

  passthru.protobuf = protobuf;
}