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