@@ -111,7 +111,7 @@ def call(command, *, quiet, **kwargs):
111
111
112
112
def build_platform ():
113
113
"""The name of the build/host platform."""
114
- # Can also be found via `config.guess`.`
114
+ # Can also be found via `config.guess`.
115
115
return sysconfig .get_config_var ("BUILD_GNU_TYPE" )
116
116
117
117
@@ -127,6 +127,15 @@ def build_python_path():
127
127
return binary
128
128
129
129
130
+ def build_python_is_pydebug ():
131
+ """Find out if the build Python is a pydebug build."""
132
+ test = "import sys, test.support; sys.exit(test.support.Py_DEBUG)"
133
+ result = subprocess .run ([build_python_path (), "-c" , test ],
134
+ stdout = subprocess .PIPE ,
135
+ stderr = subprocess .PIPE )
136
+ return bool (result .returncode )
137
+
138
+
130
139
@subdir (BUILD_DIR , clean_ok = True )
131
140
def configure_build_python (context , working_dir ):
132
141
"""Configure the build/host Python."""
@@ -213,18 +222,15 @@ def configure_wasi_python(context, working_dir):
213
222
lib_dirs = list (python_build_dir .glob ("lib.*" ))
214
223
assert len (lib_dirs ) == 1 , f"Expected a single lib.* directory in { python_build_dir } "
215
224
lib_dir = os .fsdecode (lib_dirs [0 ])
216
- pydebug = lib_dir .endswith ("-pydebug" )
217
- python_version = lib_dir .removesuffix ("-pydebug" ).rpartition ("-" )[- 1 ]
218
- sysconfig_data = f"{ wasi_build_dir } /build/lib.wasi-wasm32-{ python_version } "
219
- if pydebug :
220
- sysconfig_data += "-pydebug"
225
+ python_version = lib_dir .rpartition ("-" )[- 1 ]
226
+ sysconfig_data_dir = f"{ wasi_build_dir } /build/lib.wasi-wasm32-{ python_version } "
221
227
222
228
# Use PYTHONPATH to include sysconfig data which must be anchored to the
223
229
# WASI guest's `/` directory.
224
230
args = {"GUEST_DIR" : "/" ,
225
231
"HOST_DIR" : CHECKOUT ,
226
232
"ENV_VAR_NAME" : "PYTHONPATH" ,
227
- "ENV_VAR_VALUE" : f"/{ sysconfig_data } " ,
233
+ "ENV_VAR_VALUE" : f"/{ sysconfig_data_dir } " ,
228
234
"PYTHON_WASM" : working_dir / "python.wasm" }
229
235
# Check dynamically for wasmtime in case it was specified manually via
230
236
# `--host-runner`.
@@ -244,7 +250,7 @@ def configure_wasi_python(context, working_dir):
244
250
f"--host={ context .host_triple } " ,
245
251
f"--build={ build_platform ()} " ,
246
252
f"--with-build-python={ build_python } " ]
247
- if pydebug :
253
+ if build_python_is_pydebug () :
248
254
configure .append ("--with-pydebug" )
249
255
if context .args :
250
256
configure .extend (context .args )
0 commit comments