Skip to content

Commit b582e9a

Browse files
committed
refactor(runtime setup): Add separate ABI3 Python headers target
Until now, we silently link extensions with both stable and unstable ABI libs, with the latter taking precedence in symbol resolution, because it appears first in the linker command AND, crucially, contains all CPython symbols present in the stable ABI library, thus overriding them. This has the effect that stable ABI extensions on Windows are useable only with the Python distribution that they were built on. The now introduced separate ABI3 header target fixes this, and should be used for C++ extensions on Windows if stable ABI builds are requested. Idea as formulated by `@dgrunwald-qt` in nicholasjng/nanobind-bazel#72 (comment).
1 parent ea4b040 commit b582e9a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

python/private/hermetic_runtime_repo_setup.bzl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,26 @@ def define_hermetic_runtime_toolchain_impl(
109109
cc_library(
110110
name = "python_headers",
111111
deps = select({
112-
"@bazel_tools//src/conditions:windows": [":interface", ":abi3_interface"],
112+
"@bazel_tools//src/conditions:windows": [":interface"],
113+
"//conditions:default": None,
114+
}),
115+
hdrs = [":includes"],
116+
includes = [
117+
"include",
118+
] + select({
119+
_IS_FREETHREADED_YES: [
120+
"include/python{major}.{minor}t".format(**version_dict),
121+
],
122+
_IS_FREETHREADED_NO: [
123+
"include/python{major}.{minor}".format(**version_dict),
124+
"include/python{major}.{minor}m".format(**version_dict),
125+
],
126+
}),
127+
)
128+
cc_library(
129+
name = "python_headers_abi3",
130+
deps = select({
131+
"@bazel_tools//src/conditions:windows": [":abi3_interface"],
113132
"//conditions:default": None,
114133
}),
115134
hdrs = [":includes"],

0 commit comments

Comments
 (0)