From d391623d949dae0f05e734d129dac86626751dd5 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Wed, 25 Feb 2026 23:47:17 +0000 Subject: [PATCH] protobuf_34: init at 34.0 Changelog: https://github.com/protocolbuffers/protobuf/releases/tag/v34.0 --- pkgs/development/libraries/protobuf/34.nix | 9 +++ .../fix-upb-linkarr-sentinel-init.patch | 35 +++++++++++ .../libraries/protobuf/generic.nix | 24 ++++++-- .../development/python-modules/protobuf/7.nix | 58 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + pkgs/top-level/python-packages.nix | 5 ++ 6 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 pkgs/development/libraries/protobuf/34.nix create mode 100644 pkgs/development/libraries/protobuf/fix-upb-linkarr-sentinel-init.patch create mode 100644 pkgs/development/python-modules/protobuf/7.nix diff --git a/pkgs/development/libraries/protobuf/34.nix b/pkgs/development/libraries/protobuf/34.nix new file mode 100644 index 000000000000..eec03e75e67f --- /dev/null +++ b/pkgs/development/libraries/protobuf/34.nix @@ -0,0 +1,9 @@ +{ callPackage, ... }@args: + +callPackage ./generic.nix ( + { + version = "34.0"; + hash = "sha256-qtSP3I7RA7F6tKe+VfGd+oNXMT5HZ/Xl7u4vkefNxX4="; + } + // args +) diff --git a/pkgs/development/libraries/protobuf/fix-upb-linkarr-sentinel-init.patch b/pkgs/development/libraries/protobuf/fix-upb-linkarr-sentinel-init.patch new file mode 100644 index 000000000000..688bfcf6088a --- /dev/null +++ b/pkgs/development/libraries/protobuf/fix-upb-linkarr-sentinel-init.patch @@ -0,0 +1,35 @@ +diff --git a/upb/port/def.inc b/upb/port/def.inc +index f66885ddf55cf..1305fd164b293 100644 +--- a/upb/port/def.inc ++++ b/upb/port/def.inc +@@ -534,7 +534,7 @@ Error, UINTPTR_MAX is undefined + #define UPB_LINKARR_DECLARE(name, type) \ + extern type __start_linkarr_##name; \ + extern type __stop_linkarr_##name; \ +- UPB_LINKARR_APPEND(name) \ +- UPB_LINKARR_SENTINEL type UPB_linkarr_internal_empty_##name[1] ++ UPB_LINKARR_APPEND(name) \ ++ UPB_LINKARR_SENTINEL type UPB_linkarr_internal_empty_##name[1] = {0} + #define UPB_LINKARR_START(name) (&__start_linkarr_##name) + #define UPB_LINKARR_STOP(name) (&__stop_linkarr_##name) + +@@ -554,7 +554,7 @@ Error, UINTPTR_MAX is undefined + extern type __stop_linkarr_##name __asm( \ + "section$end$__DATA$" \ + "__la_" #name); \ +- UPB_LINKARR_APPEND(name) \ +- UPB_LINKARR_SENTINEL type UPB_linkarr_internal_empty_##name[1] ++ UPB_LINKARR_APPEND(name) \ ++ UPB_LINKARR_SENTINEL type UPB_linkarr_internal_empty_##name[1] = {0} + #define UPB_LINKARR_START(name) (&__start_linkarr_##name) + #define UPB_LINKARR_STOP(name) (&__stop_linkarr_##name) + +@@ -570,7 +570,7 @@ Error, UINTPTR_MAX is undefined + + #define UPB_LINKARR_ATTR + +-#define UPB_LINKARR_SENTINEL UPB_RETAIN __attribute__((weak, used)) ++#define UPB_LINKARR_SENTINEL __attribute__((weak, used)) + + #if defined(__ELF__) || defined(__wasm__) + diff --git a/pkgs/development/libraries/protobuf/generic.nix b/pkgs/development/libraries/protobuf/generic.nix index 8487277c20f7..3488b63b1cf2 100644 --- a/pkgs/development/libraries/protobuf/generic.nix +++ b/pkgs/development/libraries/protobuf/generic.nix @@ -64,12 +64,28 @@ stdenv.mkDerivation (finalAttrs: { url = "https://github.com/protocolbuffers/protobuf/commit/211f52431b9ec30d4d4a1c76aafd64bd78d93c43.patch"; hash = "sha256-2/vc4anc+kH7otfLHfBtW8dRowPyObiXZn0+HtQktak="; }) + ] + ++ lib.optionals (lib.versionAtLeast version "34") [ + # upb linker-array fix for newer toolchains (notably GCC 15): + # `UPB_linkarr_internal_empty_upb_AllExts` can conflict with extension + # entries in `linkarr_upb_AllExts` during test builds. + # Context: https://github.com/protocolbuffers/protobuf/issues/21021 + ./fix-upb-linkarr-sentinel-init.patch ]; - postPatch = lib.optionalString (stdenv.hostPlatform.isDarwin && lib.versionOlder version "29") '' - substituteInPlace src/google/protobuf/testing/googletest.cc \ - --replace-fail 'tmpnam(b)' '"'$TMPDIR'/foo"' - ''; + postPatch = + lib.optionalString (stdenv.hostPlatform.isDarwin && lib.versionOlder version "29") '' + substituteInPlace src/google/protobuf/testing/googletest.cc \ + --replace-fail 'tmpnam(b)' '"'$TMPDIR'/foo"' + '' + # Keep the sentinel macro non-retained for GCC 15+ to match generated + # extension objects in linker arrays and avoid section type conflicts. + + lib.optionalString (lib.versionAtLeast version "34") '' + substituteInPlace upb/port/def.inc \ + --replace-fail \ + '#define UPB_LINKARR_SENTINEL UPB_RETAIN __attribute__((weak, used))' \ + '#define UPB_LINKARR_SENTINEL __attribute__((weak, used))' + ''; preHook = '' export build_protobuf=${ diff --git a/pkgs/development/python-modules/protobuf/7.nix b/pkgs/development/python-modules/protobuf/7.nix new file mode 100644 index 000000000000..627c67844622 --- /dev/null +++ b/pkgs/development/python-modules/protobuf/7.nix @@ -0,0 +1,58 @@ +{ + buildPythonPackage, + fetchPypi, + lib, + python, + setuptools, + protobuf, +}: + +buildPythonPackage (finalAttrs: { + pname = "protobuf"; + version = "7.34.0"; + pyproject = true; + + src = fetchPypi { + inherit (finalAttrs) pname version; + hash = "sha256-OHGj32fHEKr3u40hTMmXNC5jzuvZQMjH/GXJs9aXWRo="; + }; + + build-system = [ setuptools ]; + + propagatedNativeBuildInputs = [ + protobuf + ]; + + doCheck = + # https://protobuf.dev/support/cross-version-runtime-guarantee/#backwards + # The non-python protobuf provides the protoc binary which must not be newer. + assert lib.versionAtLeast finalAttrs.version ("7." + protobuf.version); + # the pypi source archive does not ship tests + false; + + pythonImportsCheck = [ + "google.protobuf" + "google.protobuf.compiler" + "google.protobuf.internal" + "google.protobuf.pyext" + "google.protobuf.testdata" + "google.protobuf.util" + "google._upb._message" + ]; + + # Tries to explicitly create a namespace package with pkg_resources, + # which breaks everything with our PYTHONPATH setup. + postInstall = '' + rm $out/${python.sitePackages}/google/__init__.py + ''; + + meta = { + description = "Protocol Buffers are Google's data interchange format"; + homepage = "https://developers.google.com/protocol-buffers/"; + changelog = "https://github.com/protocolbuffers/protobuf/releases/v${ + builtins.substring 2 (-1) finalAttrs.version + }"; + license = lib.licenses.bsd3; + maintainers = with lib.maintainers; [ GaetanLepage ]; + }; +}) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 795c9087f068..de80af30e3f9 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -7296,6 +7296,7 @@ with pkgs; inherit ({ + protobuf_34 = callPackage ../development/libraries/protobuf/34.nix { }; protobuf_33 = callPackage ../development/libraries/protobuf/33.nix { }; protobuf_32 = callPackage ../development/libraries/protobuf/32.nix { }; protobuf_31 = callPackage ../development/libraries/protobuf/31.nix { }; @@ -7313,6 +7314,7 @@ with pkgs; abseil-cpp = abseil-cpp_202103; }; }) + protobuf_34 protobuf_33 protobuf_32 protobuf_31 diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 7736b86decc1..dd523d17b472 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -12813,6 +12813,11 @@ self: super: with self; { inherit (pkgs.__splicedPackages) protobuf; }; + # Protobuf 7.x + protobuf7 = callPackage ../development/python-modules/protobuf/7.nix { + inherit (pkgs.__splicedPackages) protobuf; + }; + protoletariat = callPackage ../development/python-modules/protoletariat { }; proton-client = callPackage ../development/python-modules/proton-client { };