@@ -17,6 +17,7 @@ load("@bazel_skylib//lib:dicts.bzl", "dicts")
1717load ("@bazel_skylib//lib:paths.bzl" , "paths" )
1818load ("@bazel_skylib//rules:common_settings.bzl" , "BuildSettingInfo" )
1919load (":attributes.bzl" , "NATIVE_RULES_ALLOWLIST_ATTRS" )
20+ load (":flags.bzl" , "FreeThreadedFlag" )
2021load (":py_internal.bzl" , "py_internal" )
2122load (":py_runtime_info.bzl" , "DEFAULT_BOOTSTRAP_TEMPLATE" , "DEFAULT_STUB_SHEBANG" , "PyRuntimeInfo" )
2223load (":reexports.bzl" , "BuiltinPyRuntimeInfo" )
@@ -101,6 +102,13 @@ def _py_runtime_impl(ctx):
101102            interpreter_version_info ["minor" ],
102103        )
103104
105+     abi_flags  =  ctx .attr .abi_flags 
106+     if  abi_flags  ==  "<AUTO>" :
107+         abi_flags  =  "" 
108+         if  ctx .attr ._py_freethreaded_flag [BuildSettingInfo ].value  ==  FreeThreadedFlag .YES :
109+             abi_flags  +=  "t" 
110+ 
111+     # Args common to both BuiltinPyRuntimeInfo and PyRuntimeInfo 
104112    py_runtime_info_kwargs  =  dict (
105113        interpreter_path  =  interpreter_path  or  None ,
106114        interpreter  =  interpreter ,
@@ -120,6 +128,7 @@ def _py_runtime_impl(ctx):
120128        pyc_tag  =  pyc_tag ,
121129        stage2_bootstrap_template  =  ctx .file .stage2_bootstrap_template ,
122130        zip_main_template  =  ctx .file .zip_main_template ,
131+         abi_flags  =  abi_flags ,
123132    ))
124133
125134    if  not  IS_BAZEL_7_OR_HIGHER :
@@ -179,6 +188,14 @@ py_runtime(
179188""" ,
180189    fragments  =  ["py" ],
181190    attrs  =  dicts .add (NATIVE_RULES_ALLOWLIST_ATTRS , {
191+         "abi_flags" : attr .string (
192+             default  =  "<AUTO>" ,
193+             doc  =  """ 
194+ The runtime's ABI flags, i.e. `sys.abiflags`. 
195+ 
196+ If not set, then it will be set based on flags. 
197+ """ ,
198+         ),
182199        "bootstrap_template" : attr .label (
183200            allow_single_file  =  True ,
184201            default  =  DEFAULT_BOOTSTRAP_TEMPLATE ,
@@ -335,6 +352,9 @@ The {obj}`PyRuntimeInfo.zip_main_template` field.
335352::: 
336353""" ,
337354        ),
355+         "_py_freethreaded_flag" : attr .label (
356+             default  =  "//python/config_settings:py_freethreaded" ,
357+         ),
338358        "_python_version_flag" : attr .label (
339359            default  =  "//python/config_settings:python_version" ,
340360        ),
0 commit comments