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 propagatedBuildInputs = [ six ] ++ lib.optionals isPy27 [ google-apputils ];
22 propagatedNativeBuildInputs = [ buildPackages.protobuf ]; # For protoc.
23 nativeBuildInputs = [ pyext ] ++ lib.optionals isPy27 [ google-apputils ];
24 buildInputs = [ protobuf ];
25
26 patches = lib.optional (isPy37 && (lib.versionOlder protobuf.version "3.6.1.2"))
27 # Python 3.7 compatibility (not needed for protobuf >= 3.6.1.2)
28 (fetchpatch {
29 url = "https://github.com/protocolbuffers/protobuf/commit/0a59054c30e4f0ba10f10acfc1d7f3814c63e1a7.patch";
30 sha256 = "09hw22y3423v8bbmc9xm07znwdxfbya6rp78d4zqw6fisdvjkqf1";
31 stripLen = 1;
32 })
33 ;
34
35 prePatch = ''
36 while [ ! -d python ]; do
37 cd *
38 done
39 cd python
40 '';
41
42 setupPyGlobalFlags = lib.optional (lib.versionAtLeast protobuf.version "2.6.0")
43 "--cpp_implementation";
44
45 pythonImportsCheck = [
46 "google.protobuf"
47 ] ++ lib.optionals (lib.versionAtLeast protobuf.version "2.6.0") [
48 "google.protobuf.internal._api_implementation" # Verify that --cpp_implementation worked
49 ];
50
51 meta = with lib; {
52 description = "Protocol Buffers are Google's data interchange format";
53 homepage = "https://developers.google.com/protocol-buffers/";
54 license = licenses.bsd3;
55 maintainers = with maintainers; [ knedlsepp ];
56 };
57
58 passthru.protobuf = protobuf;
59}