Skip to content

Commit c94ff29

Browse files
committed
feat: ad PyRuntimeInfo.abi_flags
1 parent daed352 commit c94ff29

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ A brief description of the categories of changes:
5151
* (toolchain) Support for freethreaded Python toolchains is now available. Use
5252
the config flag `//python/config_settings:py_freethreaded` to toggle the
5353
selection of the free-threaded toolchains.
54+
* (toolchain) {obj}`py_runtime.abi_flags` attribute and
55+
{obj}`PyRuntimeInfo.abi_flags` field added.
5456

5557
{#v0-0-0-removed}
5658
### Removed

python/private/py_runtime_info.bzl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def _PyRuntimeInfo_init(
6767
bootstrap_template = None,
6868
interpreter_version_info = None,
6969
stage2_bootstrap_template = None,
70-
zip_main_template = None):
70+
zip_main_template = None,
71+
abi_flags = ""):
7172
if (interpreter_path and interpreter) or (not interpreter_path and not interpreter):
7273
fail("exactly one of interpreter or interpreter_path must be specified")
7374

@@ -105,6 +106,7 @@ def _PyRuntimeInfo_init(
105106
stub_shebang = DEFAULT_STUB_SHEBANG
106107

107108
return {
109+
"abi_flags": abi_flags,
108110
"bootstrap_template": bootstrap_template,
109111
"coverage_files": coverage_files,
110112
"coverage_tool": coverage_tool,
@@ -133,6 +135,11 @@ the same conventions as the standard CPython interpreter.
133135
""",
134136
init = _PyRuntimeInfo_init,
135137
fields = {
138+
"abi_flags": """
139+
:type: str
140+
141+
The runtime's ABI flags, i.e. `sys.abiflags`.
142+
""",
136143
"bootstrap_template": """
137144
:type: File
138145

python/private/py_runtime_rule.bzl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ def _py_runtime_impl(ctx):
101101
interpreter_version_info["minor"],
102102
)
103103

104+
abi_flags = ctx.attr.abi_flags
105+
if abi_flags == "<AUTO>":
106+
abi_flags = ""
107+
if ctx.attr._py_freethreaded_flag[BuildSettingInfo].value == FreeThreadedFlag.YES:
108+
abi_flags += "t"
109+
110+
# Args common to both BuiltinPyRuntimeInfo and PyRuntimeInfo
104111
py_runtime_info_kwargs = dict(
105112
interpreter_path = interpreter_path or None,
106113
interpreter = interpreter,
@@ -120,6 +127,7 @@ def _py_runtime_impl(ctx):
120127
pyc_tag = pyc_tag,
121128
stage2_bootstrap_template = ctx.file.stage2_bootstrap_template,
122129
zip_main_template = ctx.file.zip_main_template,
130+
abi_flags = abi_flags,
123131
))
124132

125133
if not IS_BAZEL_7_OR_HIGHER:
@@ -179,6 +187,14 @@ py_runtime(
179187
""",
180188
fragments = ["py"],
181189
attrs = dicts.add(NATIVE_RULES_ALLOWLIST_ATTRS, {
190+
"abi_flags": attr.string(
191+
default = "<AUTO>",
192+
doc = """
193+
The runtime's ABI flags, i.e. `sys.abiflags`.
194+
195+
If not set, then it will be set based on flags.
196+
""",
197+
),
182198
"bootstrap_template": attr.label(
183199
allow_single_file = True,
184200
default = DEFAULT_BOOTSTRAP_TEMPLATE,
@@ -335,6 +351,9 @@ The {obj}`PyRuntimeInfo.zip_main_template` field.
335351
:::
336352
""",
337353
),
354+
"_py_freethreaded_flag": attr.label(
355+
default = "//python/config_settings:py_freethreaded",
356+
),
338357
"_python_version_flag": attr.label(
339358
default = "//python/config_settings:python_version",
340359
),

0 commit comments

Comments
 (0)