Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at litex 1.8 kB view raw
1{ buildPackages 2, lib 3, buildPythonPackage 4, protobuf 5, isPyPy 6, fetchpatch 7, pythonAtLeast 8}: 9 10let 11 versionMajor = lib.versions.major protobuf.version; 12 versionMinor = lib.versions.minor protobuf.version; 13 versionPatch = lib.versions.patch protobuf.version; 14in 15buildPythonPackage { 16 inherit (protobuf) pname src; 17 18 # protobuf 3.21 corresponds with its python library 4.21 19 version = 20 if lib.versionAtLeast protobuf.version "3.21" 21 then "${toString (lib.toInt versionMajor + 1)}.${versionMinor}.${versionPatch}" 22 else protobuf.version; 23 24 disabled = isPyPy; 25 26 sourceRoot = "source/python"; 27 28 patches = lib.optionals (pythonAtLeast "3.11") [ 29 (fetchpatch { 30 url = "https://github.com/protocolbuffers/protobuf/commit/da973aff2adab60a9e516d3202c111dbdde1a50f.patch"; 31 stripLen = 2; 32 extraPrefix = ""; 33 hash = "sha256-a/12C6yIe1tEKjsMxcfDAQ4JHolA8CzkN7sNG8ZspPs="; 34 }) 35 ]; 36 37 prePatch = '' 38 if [[ "$(<../version.json)" != *'"python": "'"$version"'"'* ]]; then 39 echo "Python library version mismatch. Derivation version: $version, actual: $(<../version.json)" 40 exit 1 41 fi 42 ''; 43 44 buildInputs = [ protobuf ]; 45 46 propagatedNativeBuildInputs = [ 47 # For protoc of the same version. 48 buildPackages."protobuf${lib.versions.major protobuf.version}_${lib.versions.minor protobuf.version}" 49 ]; 50 51 setupPyGlobalFlags = [ "--cpp_implementation" ]; 52 53 pythonImportsCheck = [ 54 "google.protobuf" 55 "google.protobuf.internal._api_implementation" # Verify that --cpp_implementation worked 56 ]; 57 58 passthru = { 59 inherit protobuf; 60 }; 61 62 meta = with lib; { 63 description = "Protocol Buffers are Google's data interchange format"; 64 homepage = "https://developers.google.com/protocol-buffers/"; 65 license = licenses.bsd3; 66 maintainers = with maintainers; [ knedlsepp ]; 67 }; 68}