From 3aa022a269f193025f8288cd89e96075c08fea2f Mon Sep 17 00:00:00 2001 From: Mitchell Allain Date: Fri, 3 Jul 2026 12:37:16 -0700 Subject: [PATCH] Configure extra compile args in setup.py (#28264) Fixes https://github.com/protocolbuffers/protobuf/issues/28261 by setting symbol visibility in `setup.py`, similar to `py_extension.bzl`, using the existing branching logic to bypass the flag on MSVC. This issue manifests in the [NixOS/nixpkgs](https://github.com/NixOS/nixpkgs) build of the `protobuf` python package, which contains upb symbols, and causes fatal failures when loaded in a process that separately links/loads libprotobuf. We'll supply a patch there as well, until this can be backported or released in future protobuf versions. Closes #28264 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28264 from mitchallain:mallain/fix-python-upb-symbols 6e118a62bfd076fbf07b1a5fe3decfd969207c3b PiperOrigin-RevId: 942223178 --- python/dist/setup.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/dist/setup.py b/python/dist/setup.py index 314b1cb375..c47f524d1c 100755 --- a/python/dist/setup.py +++ b/python/dist/setup.py @@ -33,9 +33,12 @@ def GetVersion(): current_dir = os.path.dirname(os.path.abspath(__file__)) extra_link_args = [] +extra_compile_args = [] if sys.platform.startswith('win'): extra_link_args = ['-static'] +else: + extra_compile_args = ['-fvisibility=hidden'] # If at some point the fasttable decoder is ready for prime time, we could # enable it here. But even then we'll need to disable it on platforms where @@ -86,6 +89,7 @@ setup( include_dirs=[current_dir, os.path.join(current_dir, 'utf8_range')], language='c', extra_link_args=extra_link_args, + extra_compile_args=extra_compile_args, ) ], python_requires='>=3.10',