Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion python/private/get_local_runtime_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ def _unique_basenames(inputs: dict[str, None]) -> list[str]:
"abi_dynamic_libraries": _unique_basenames(abi_dynamic_libraries),
"abi_interface_libraries": _unique_basenames(abi_interface_libraries),
"abi_flags": abi_flags,
"abi_tag": config_vars.get("SOABI") or "",
"abi_tag": "-".join((config_vars.get("SOABI") or "").split("-")[:2])
if "-" in (config_vars.get("SOABI") or "")
else (config_vars.get("SOABI") or ""),
"shlib_suffix": ".dylib" if _IS_DARWIN else "",
"additional_dlls": dlls,
"defines": defines,
Expand Down
8 changes: 8 additions & 0 deletions python/private/local_runtime_repo_setup.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,21 @@ def define_local_runtime_toolchain_impl(
hdrs = [":includes"],
defines = defines, # NOTE: Users should define Py_LIMITED_API=3
srcs = abi3_libraries + additional_dlls,
deps = select({
"@bazel_tools//src/conditions:windows": [":abi3_interface"],
"//conditions:default": [],
}),
)

cc_library(
name = "libpython",
hdrs = [":includes"],
defines = defines,
srcs = libraries + additional_dlls,
deps = select({
"@bazel_tools//src/conditions:windows": [":interface"],
"//conditions:default": [],
}),
)

# runtime configuration
Expand Down
16 changes: 3 additions & 13 deletions tests/integration/local_toolchains/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
# limitations under the License.

load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_python//python:py_test.bzl", "py_test")
load(":py_extension.bzl", "py_extension")
load("@rules_python//python/cc:py_extension.bzl", "py_extension")

py_test(
name = "local_runtime_test",
Expand Down Expand Up @@ -60,24 +59,15 @@ string_flag(
)

# Build rules to generate a python extension.
cc_library(
name = "echo_ext_cc",
testonly = True,
srcs = ["echo_ext.cc"],
deps = [
"@rules_python//python/cc:current_py_cc_headers",
],
alwayslink = True,
)

py_extension(
name = "echo_ext",
testonly = True,
srcs = ["echo_ext.cc"],
copts = select({
"@rules_cc//cc/compiler:msvc-cl": [],
"//conditions:default": ["-fvisibility=hidden"],
}),
deps = [":echo_ext_cc"],
imports = ["."],
)

py_test(
Expand Down
21 changes: 20 additions & 1 deletion tests/integration/local_toolchains/echo_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
import glob
import importlib.util
import os
import sys
import unittest

import echo_ext
try:
import echo_ext
except ModuleNotFoundError:
echo_ext = None
for path in sys.path:
matches = glob.glob(os.path.join(path, "echo_ext*.*"))
for m in matches:
if m.endswith(".so") or m.endswith(".pyd"):
spec = importlib.util.spec_from_file_location("echo_ext", m)
echo_ext = importlib.util.module_from_spec(spec)
spec.loader.exec_module(echo_ext)
break
if echo_ext:
break
if not echo_ext:
raise ModuleNotFoundError("No module named 'echo_ext'")


class ExtensionTest(unittest.TestCase):
Expand Down
154 changes: 0 additions & 154 deletions tests/integration/local_toolchains/py_extension.bzl

This file was deleted.