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