Add linker flags enabling undefined dynamic_lookup for macOS for Python api_implementation.so and message.so
Enable Bazel 7 macOS test coverage which otherwise fails with
```
Undefined symbols for architecture arm64:
"_PyModule_AddIntConstant", referenced from:
_PyInit__api_implementation in api_implementation.o
"_PyModule_Create2", referenced from:
_PyInit__api_implementation in api_implementation.o
"__Py_Dealloc", referenced from:
_PyInit__api_implementation in api_implementation.o
ld: symbol(s) not found for architecture arm64
```
#test-continuous
PiperOrigin-RevId: 702103016
diff --git a/.github/workflows/test_python.yml b/.github/workflows/test_python.yml
index 5ede687..902287c 100644
--- a/.github/workflows/test_python.yml
+++ b/.github/workflows/test_python.yml
@@ -110,6 +110,7 @@
env:
KOKORO_PYTHON_VERSION: ${{ matrix.version }}
with:
+ version: 7.1.2 # Bazel version
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: python_macos/${{ matrix.type }}_${{ matrix.version }}
bazel: >-
diff --git a/python/build_targets.bzl b/python/build_targets.bzl
index ee765ab..25a13cc 100644
--- a/python/build_targets.bzl
+++ b/python/build_targets.bzl
@@ -1,11 +1,14 @@
-# Protobuf Python runtime
-#
-# See also code generation logic under /src/google/protobuf/compiler/python.
-#
-# Most users should depend upon public aliases in the root:
-# //:protobuf_python
-# //:well_known_types_py_pb2
+"""
+Protobuf Python runtime
+See also code generation logic under /src/google/protobuf/compiler/python.
+
+Most users should depend upon public aliases in the root:
+ //:protobuf_python
+ //:well_known_types_py_pb2
+"""
+
+load("@bazel_skylib//lib:selects.bzl", "selects")
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_python//python:defs.bzl", "py_library")
load("//:protobuf.bzl", "internal_py_proto_library")
@@ -76,6 +79,13 @@
copts = COPTS + [
"-DPYTHON_PROTO2_CPP_IMPL_V2",
],
+ linkopts = selects.with_or({
+ (
+ "//python/dist:osx_x86_64",
+ "//python/dist:osx_aarch64",
+ ): ["-Wl,-undefined,dynamic_lookup"],
+ "//conditions:default": [],
+ }),
linkshared = 1,
linkstatic = 1,
tags = [
@@ -110,6 +120,13 @@
"//conditions:default": [],
":allow_oversize_protos": ["-DPROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS=1"],
}),
+ linkopts = selects.with_or({
+ (
+ "//python/dist:osx_x86_64",
+ "//python/dist:osx_aarch64",
+ ): ["-Wl,-undefined,dynamic_lookup"],
+ "//conditions:default": [],
+ }),
includes = ["."],
linkshared = 1,
linkstatic = 1,
diff --git a/python/py_extension.bzl b/python/py_extension.bzl
index 2741cdf..4844886 100644
--- a/python/py_extension.bzl
+++ b/python/py_extension.bzl
@@ -21,7 +21,7 @@
(
"//python/dist:osx_x86_64",
"//python/dist:osx_aarch64",
- ): ["-undefined", "dynamic_lookup"],
+ ): ["-Wl,-undefined,dynamic_lookup"],
"//python/dist:windows_x86_32": ["-static-libgcc"],
"//conditions:default": [],
}),