Skip to content

Commit 4d998f2

Browse files
zhangskzcopybara-github
authored andcommitted
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 ``` Fixes #19454 #test-continuous PiperOrigin-RevId: 702375059
1 parent a1b0088 commit 4d998f2

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

.github/workflows/test_python.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ jobs:
113113
env:
114114
KOKORO_PYTHON_VERSION: ${{ matrix.version }}
115115
with:
116+
version: 7.1.2 # Bazel version
116117
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
117118
bazel-cache: python_macos/${{ matrix.type }}_${{ matrix.version }}
118119
bazel: >-

python/build_targets.bzl

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
# Protobuf Python runtime
2-
#
3-
# See also code generation logic under /src/google/protobuf/compiler/python.
4-
#
5-
# Most users should depend upon public aliases in the root:
6-
# //:protobuf_python
7-
# //:well_known_types_py_pb2
1+
"""
2+
Protobuf Python runtime
83
4+
See also code generation logic under /src/google/protobuf/compiler/python.
5+
6+
Most users should depend upon public aliases in the root:
7+
//:protobuf_python
8+
//:well_known_types_py_pb2
9+
"""
10+
11+
load("@bazel_skylib//lib:selects.bzl", "selects")
912
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
1013
load("@rules_python//python:defs.bzl", "py_library")
1114
load("//:protobuf.bzl", "internal_py_proto_library")
@@ -76,6 +79,13 @@ def build_targets(name):
7679
copts = COPTS + [
7780
"-DPYTHON_PROTO2_CPP_IMPL_V2",
7881
],
82+
linkopts = selects.with_or({
83+
(
84+
"//python/dist:osx_x86_64",
85+
"//python/dist:osx_aarch64",
86+
): ["-Wl,-undefined,dynamic_lookup"],
87+
"//conditions:default": [],
88+
}),
7989
linkshared = 1,
8090
linkstatic = 1,
8191
tags = [
@@ -110,6 +120,13 @@ def build_targets(name):
110120
"//conditions:default": [],
111121
":allow_oversize_protos": ["-DPROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS=1"],
112122
}),
123+
linkopts = selects.with_or({
124+
(
125+
"//python/dist:osx_x86_64",
126+
"//python/dist:osx_aarch64",
127+
): ["-Wl,-undefined,dynamic_lookup"],
128+
"//conditions:default": [],
129+
}),
113130
includes = ["."],
114131
linkshared = 1,
115132
linkstatic = 1,

python/py_extension.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def py_extension(name, srcs, copts, deps = [], **kwargs):
2121
(
2222
"//python/dist:osx_x86_64",
2323
"//python/dist:osx_aarch64",
24-
): ["-undefined", "dynamic_lookup"],
24+
): ["-Wl,-undefined,dynamic_lookup"],
2525
"//python/dist:windows_x86_32": ["-static-libgcc"],
2626
"//conditions:default": [],
2727
}),

0 commit comments

Comments
 (0)