@@ -50,6 +50,7 @@ def define_hermetic_runtime_toolchain_impl(
5050 use.
5151 """
5252 _ = name # @unused
53+ is_freethreaded = Label ("//python/config_settings:is_py_freethreaded" )
5354 version_info = semver (python_version )
5455 version_dict = version_info .to_dict ()
5556 native .filegroup (
@@ -65,21 +66,27 @@ def define_hermetic_runtime_toolchain_impl(
6566 # Platform-agnostic filegroup can't match on all patterns.
6667 allow_empty = True ,
6768 exclude = [
68- # Unused shared libraries. `python` executable and the `:libpython` target
69- # depend on `libpython{python_version}.so.1.0`.
70- "lib/libpython{major}.{minor}.so" .format (** version_dict ),
7169 # static libraries
7270 "lib/**/*.a" ,
71+ # During pyc creation, temp files named *.pyc.NNN are created
72+ "**/__pycache__/*.pyc.*" ,
73+ # Do exclusions for all known ABIs
74+ # Unused shared libraries. `python` executable and the `:libpython` target
75+ # depend on `libpython{python_version}.so.1.0`.
76+ "lib/libpython{major}.{minor}*.so" .format (** version_dict ),
77+ "lib/libpython{major}.{minor}*.so" .format (** version_dict ),
7378 # tests for the standard libraries.
74- "lib/python{major}.{minor}/**/test/**" .format (** version_dict ),
75- "lib/python{major}.{minor}/**/tests/**" .format (** version_dict ),
76- "**/__pycache__/*.pyc.*" , # During pyc creation, temp files named *.pyc.NNN are created
79+ "lib/python{major}.{minor}*/**/test/**" .format (** version_dict ),
80+ "lib/python{major}.{minor}*/**/tests/**" .format (** version_dict ),
7781 ] + glob_excludes .version_dependent_exclusions () + extra_files_glob_exclude ,
7882 ),
7983 )
8084 cc_import (
8185 name = "interface" ,
82- interface_library = "libs/python{major}{minor}.lib" .format (** version_dict ),
86+ interface_library = select ({
87+ is_freethreaded : "libs/python{major}{minor}t.lib" .format (** version_dict ),
88+ "//conditions:default" : "libs/python{major}{minor}.lib" .format (** version_dict ),
89+ }),
8390 system_provided = True ,
8491 )
8592
@@ -96,14 +103,65 @@ def define_hermetic_runtime_toolchain_impl(
96103 hdrs = [":includes" ],
97104 includes = [
98105 "include" ,
99- "include/python{major}.{minor}" .format (** version_dict ),
100- "include/python{major}.{minor}m" .format (** version_dict ),
106+ ] + select ({
107+ is_freethreaded : [
108+ "include/python{major}.{minor}t" .format (** version_dict ),
109+ # FIXME @aignas 2024-11-05: the following looks fishy - should
110+ # we have a config setting for `m` (i.e. DEBUG builds)?
111+ "include/python{major}.{minor}tm" .format (** version_dict ),
112+ ],
113+ "//conditions:default" : [
114+ "include/python{major}.{minor}" .format (** version_dict ),
115+ "include/python{major}.{minor}m" .format (** version_dict ),
116+ ],
117+ }),
118+ )
119+ native .config_setting (
120+ name = "is_freethreaded_linux" ,
121+ flag_values = {
122+ Label ("//python/config_settings:py_freethreaded" ): "yes" ,
123+ },
124+ constraint_values = [
125+ "@platforms//os:linux" ,
126+ ],
127+ visibility = ["//visibility:private" ],
128+ )
129+ native .config_setting (
130+ name = "is_freethreaded_osx" ,
131+ flag_values = {
132+ Label ("//python/config_settings:py_freethreaded" ): "yes" ,
133+ },
134+ constraint_values = [
135+ "@platforms//os:osx" ,
136+ ],
137+ visibility = ["//visibility:private" ],
138+ )
139+ native .config_setting (
140+ name = "is_freethreaded_windows" ,
141+ flag_values = {
142+ Label ("//python/config_settings:py_freethreaded" ): "yes" ,
143+ },
144+ constraint_values = [
145+ "@platforms//os:windows" ,
101146 ],
147+ visibility = ["//visibility:private" ],
102148 )
149+
103150 cc_library (
104151 name = "libpython" ,
105152 hdrs = [":includes" ],
106153 srcs = select ({
154+ ":is_freethreaded_linux" : [
155+ "lib/libpython{major}.{minor}t.so" .format (** version_dict ),
156+ "lib/libpython{major}.{minor}t.so.1.0" .format (** version_dict ),
157+ ],
158+ ":is_freethreaded_osx" : [
159+ "lib/libpython{major}.{minor}t.dylib" .format (** version_dict ),
160+ ],
161+ ":is_freethreaded_windows" : [
162+ "python3.dll" ,
163+ "libs/python{major}{minor}t.lib" .format (** version_dict ),
164+ ],
107165 "@platforms//os:linux" : [
108166 "lib/libpython{major}.{minor}.so" .format (** version_dict ),
109167 "lib/libpython{major}.{minor}.so.1.0" .format (** version_dict ),
@@ -137,7 +195,10 @@ def define_hermetic_runtime_toolchain_impl(
137195 python_version = "PY3" ,
138196 implementation_name = "cpython" ,
139197 # See https://peps.python.org/pep-3147/ for pyc tag infix format
140- pyc_tag = "cpython-{major}{minor}" .format (** version_dict ),
198+ pyc_tag = select ({
199+ is_freethreaded : "cpython-{major}{minor}t" .format (** version_dict ),
200+ "//conditions:default" : "cpython-{major}{minor}" .format (** version_dict ),
201+ }),
141202 )
142203
143204 py_runtime_pair (
0 commit comments