Fix the build on macos.

pull/13171/head
Joshua Haberman 3 years ago
parent ae160982e3
commit 98eab1c0c2
  1. 14
      bazel/workspace_defs.bzl
  2. 11
      python/BUILD

@ -34,17 +34,23 @@ cc_library(
)
"""
def _find_python_dir(repository_ctx):
py_program = "import sysconfig; print(sysconfig.get_config_var('INCLUDEPY'), end='')"
result = repository_ctx.execute(["python3", "-c", py_program])
_build_defs_file = """
EXT_SUFFIX = "%s"
"""
def _get_config_var(repository_ctx, name):
py_program = "import sysconfig; print(sysconfig.get_config_var('%s'), end='')"
result = repository_ctx.execute(["python3", "-c", py_program % (name)])
if result.return_code != 0:
fail("No python3 executable available on the system")
return result.stdout
def _python_headers_impl(repository_ctx):
path = _find_python_dir(repository_ctx)
path = _get_config_var(repository_ctx, "INCLUDEPY")
ext_suffix = _get_config_var(repository_ctx, "EXT_SUFFIX")
repository_ctx.symlink(path, "python")
repository_ctx.file("BUILD.bazel", _build_file)
repository_ctx.file("build_defs.bzl", _build_defs_file % ext_suffix)
# The python_headers() repository rule exposes Python headers from the system.
#

@ -27,6 +27,10 @@ load(
"//bazel:build_defs.bzl",
"UPB_DEFAULT_COPTS",
)
load(
"@python_headers//:build_defs.bzl",
"EXT_SUFFIX",
)
cc_binary(
name = "message",
@ -45,7 +49,10 @@ cc_binary(
],
# We use a linker script to hide all symbols except the entry point for
# the module.
linkopts = ["-Wl,--version-script,$(location :version_script.lds)"],
linkopts = select({
"@platforms//os:linux": ["-Wl,--version-script,$(location :version_script.lds)"],
"@platforms//os:macos": ["-Wl,-exported_symbol", "-Wl,_PyInit__message"],
}),
linkshared = True,
linkstatic = True,
deps = [
@ -60,7 +67,7 @@ cc_binary(
genrule(
name = "message_ext",
srcs = [":message"],
outs = ["google/protobuf/pyext/_message.cpython-39-x86_64-linux-gnu.so"],
outs = ["google/protobuf/pyext/_message" + EXT_SUFFIX],
cmd = "cp $< $@",
)

Loading…
Cancel
Save