@@ -21,6 +21,8 @@ load(":glob_excludes.bzl", "glob_excludes")
21
21
load (":py_exec_tools_toolchain.bzl" , "py_exec_tools_toolchain" )
22
22
load (":semver.bzl" , "semver" )
23
23
24
+ _IS_FREETHREADED = Label ("//python/config_settings:is_py_freethreaded" )
25
+
24
26
def define_hermetic_runtime_toolchain_impl (
25
27
* ,
26
28
name ,
@@ -45,7 +47,7 @@ def define_hermetic_runtime_toolchain_impl(
45
47
python_version: {type}`str` The Python version, in `major.minor.micro`
46
48
format.
47
49
python_bin: {type}`str` The path to the Python binary within the
48
- repositoroy .
50
+ repository .
49
51
coverage_tool: {type}`str` optional target to the coverage tool to
50
52
use.
51
53
"""
@@ -67,19 +69,23 @@ def define_hermetic_runtime_toolchain_impl(
67
69
exclude = [
68
70
# Unused shared libraries. `python` executable and the `:libpython` target
69
71
# depend on `libpython{python_version}.so.1.0`.
70
- "lib/libpython{major}.{minor}.so" .format (** version_dict ),
72
+ "lib/libpython{major}.{minor}* .so" .format (** version_dict ),
71
73
# static libraries
72
74
"lib/**/*.a" ,
73
75
# 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
76
+ "lib/python{major}.{minor}*/**/test/**" .format (** version_dict ),
77
+ "lib/python{major}.{minor}*/**/tests/**" .format (** version_dict ),
78
+ # During pyc creation, temp files named *.pyc.NNN are created
79
+ "**/__pycache__/*.pyc.*" ,
77
80
] + glob_excludes .version_dependent_exclusions () + extra_files_glob_exclude ,
78
81
),
79
82
)
80
83
cc_import (
81
84
name = "interface" ,
82
- interface_library = "libs/python{major}{minor}.lib" .format (** version_dict ),
85
+ interface_library = select ({
86
+ _IS_FREETHREADED : "libs/python{major}{minor}t.lib" .format (** version_dict ),
87
+ "//conditions:default" : "libs/python{major}{minor}.lib" .format (** version_dict ),
88
+ }),
83
89
system_provided = True ,
84
90
)
85
91
@@ -96,14 +102,62 @@ def define_hermetic_runtime_toolchain_impl(
96
102
hdrs = [":includes" ],
97
103
includes = [
98
104
"include" ,
99
- "include/python{major}.{minor}" .format (** version_dict ),
100
- "include/python{major}.{minor}m" .format (** version_dict ),
105
+ ] + select ({
106
+ _IS_FREETHREADED : [
107
+ "include/python{major}.{minor}t" .format (** version_dict ),
108
+ ],
109
+ "//conditions:default" : [
110
+ "include/python{major}.{minor}" .format (** version_dict ),
111
+ "include/python{major}.{minor}m" .format (** version_dict ),
112
+ ],
113
+ }),
114
+ )
115
+ native .config_setting (
116
+ name = "is_freethreaded_linux" ,
117
+ flag_values = {
118
+ Label ("//python/config_settings:py_freethreaded" ): "yes" ,
119
+ },
120
+ constraint_values = [
121
+ "@platforms//os:linux" ,
101
122
],
123
+ visibility = ["//visibility:private" ],
102
124
)
125
+ native .config_setting (
126
+ name = "is_freethreaded_osx" ,
127
+ flag_values = {
128
+ Label ("//python/config_settings:py_freethreaded" ): "yes" ,
129
+ },
130
+ constraint_values = [
131
+ "@platforms//os:osx" ,
132
+ ],
133
+ visibility = ["//visibility:private" ],
134
+ )
135
+ native .config_setting (
136
+ name = "is_freethreaded_windows" ,
137
+ flag_values = {
138
+ Label ("//python/config_settings:py_freethreaded" ): "yes" ,
139
+ },
140
+ constraint_values = [
141
+ "@platforms//os:windows" ,
142
+ ],
143
+ visibility = ["//visibility:private" ],
144
+ )
145
+
103
146
cc_library (
104
147
name = "libpython" ,
105
148
hdrs = [":includes" ],
106
149
srcs = select ({
150
+ ":is_freethreaded_linux" : [
151
+ "lib/libpython{major}.{minor}t.so" .format (** version_dict ),
152
+ "lib/libpython{major}.{minor}t.so.1.0" .format (** version_dict ),
153
+ ],
154
+ ":is_freethreaded_osx" : [
155
+ "lib/libpython{major}.{minor}t.dylib" .format (** version_dict ),
156
+ ],
157
+ ":is_freethreaded_windows" : [
158
+ "python3.dll" ,
159
+ "libs/python{major}{minor}t.lib" .format (** version_dict ),
160
+ ],
107
161
"@platforms//os:linux" : [
108
162
"lib/libpython{major}.{minor}.so" .format (** version_dict ),
109
163
"lib/libpython{major}.{minor}.so.1.0" .format (** version_dict ),
@@ -132,12 +186,18 @@ def define_hermetic_runtime_toolchain_impl(
132
186
"micro" : str (version_info .patch ),
133
187
"minor" : str (version_info .minor ),
134
188
},
135
- # Convert empty string to None
136
- coverage_tool = coverage_tool or None ,
189
+ coverage_tool = select ({
190
+ # Convert empty string to None
191
+ ":coverage_enabled" : coverage_tool or None ,
192
+ "//conditions:default" : None ,
193
+ }),
137
194
python_version = "PY3" ,
138
195
implementation_name = "cpython" ,
139
196
# See https://peps.python.org/pep-3147/ for pyc tag infix format
140
- pyc_tag = "cpython-{major}{minor}" .format (** version_dict ),
197
+ pyc_tag = select ({
198
+ _IS_FREETHREADED : "cpython-{major}{minor}t" .format (** version_dict ),
199
+ "//conditions:default" : "cpython-{major}{minor}" .format (** version_dict ),
200
+ }),
141
201
)
142
202
143
203
py_runtime_pair (
0 commit comments