Skip to content

Commit

Permalink
Add linker flags enabling undefined dynamic_lookup for macOS for Pyth…
Browse files Browse the repository at this point in the history
…on 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
  • Loading branch information
zhangskz authored and copybara-github committed Dec 3, 2024
1 parent a1b0088 commit 4d998f2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ jobs:
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: >-
Expand Down
31 changes: 24 additions & 7 deletions python/build_targets.bzl
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -76,6 +79,13 @@ def build_targets(name):
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 = [
Expand Down Expand Up @@ -110,6 +120,13 @@ def build_targets(name):
"//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,
Expand Down
2 changes: 1 addition & 1 deletion python/py_extension.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def py_extension(name, srcs, copts, deps = [], **kwargs):
(
"//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": [],
}),
Expand Down

0 comments on commit 4d998f2

Please sign in to comment.