Merge branch 'python-review' of https://github.com/haberman/upb into python-review

pull/13171/head
Joshua Haberman 3 years ago
commit 56e47fd783
  1. 14
      bazel/workspace_defs.bzl
  2. 11
      python/BUILD

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

@ -27,6 +27,10 @@ load(
"//bazel:build_defs.bzl", "//bazel:build_defs.bzl",
"UPB_DEFAULT_COPTS", "UPB_DEFAULT_COPTS",
) )
load(
"@python_headers//:build_defs.bzl",
"EXT_SUFFIX",
)
cc_binary( cc_binary(
name = "message", name = "message",
@ -45,7 +49,10 @@ cc_binary(
], ],
# We use a linker script to hide all symbols except the entry point for # We use a linker script to hide all symbols except the entry point for
# the module. # 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, linkshared = True,
linkstatic = True, linkstatic = True,
deps = [ deps = [
@ -60,7 +67,7 @@ cc_binary(
genrule( genrule(
name = "message_ext", name = "message_ext",
srcs = [":message"], srcs = [":message"],
outs = ["google/protobuf/pyext/_message.cpython-39-x86_64-linux-gnu.so"], outs = ["google/protobuf/pyext/_message" + EXT_SUFFIX],
cmd = "cp $< $@", cmd = "cp $< $@",
) )

Loading…
Cancel
Save