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 6e118a62bf
PiperOrigin-RevId: 942223178
This commit is contained in:
Mitchell Allain 2026-07-03 12:37:16 -07:00 committed by Copybara-Service
parent e1b94ce8f9
commit 3aa022a269

View file

@ -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',