@@ -111,7 +111,7 @@ def call(command, *, quiet, **kwargs):
111111
112112def build_platform ():
113113 """The name of the build/host platform."""
114- # Can also be found via `config.guess`.`
114+ # Can also be found via `config.guess`.
115115 return sysconfig .get_config_var ("BUILD_GNU_TYPE" )
116116
117117
@@ -127,6 +127,15 @@ def build_python_path():
127127 return binary
128128
129129
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+
130139@subdir (BUILD_DIR , clean_ok = True )
131140def configure_build_python (context , working_dir ):
132141 """Configure the build/host Python."""
@@ -213,18 +222,15 @@ def configure_wasi_python(context, working_dir):
213222 lib_dirs = list (python_build_dir .glob ("lib.*" ))
214223 assert len (lib_dirs ) == 1 , f"Expected a single lib.* directory in { python_build_dir } "
215224 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 } "
221227
222228 # Use PYTHONPATH to include sysconfig data which must be anchored to the
223229 # WASI guest's `/` directory.
224230 args = {"GUEST_DIR" : "/" ,
225231 "HOST_DIR" : CHECKOUT ,
226232 "ENV_VAR_NAME" : "PYTHONPATH" ,
227- "ENV_VAR_VALUE" : f"/{ sysconfig_data } " ,
233+ "ENV_VAR_VALUE" : f"/{ sysconfig_data_dir } " ,
228234 "PYTHON_WASM" : working_dir / "python.wasm" }
229235 # Check dynamically for wasmtime in case it was specified manually via
230236 # `--host-runner`.
@@ -244,7 +250,7 @@ def configure_wasi_python(context, working_dir):
244250 f"--host={ context .host_triple } " ,
245251 f"--build={ build_platform ()} " ,
246252 f"--with-build-python={ build_python } " ]
247- if pydebug :
253+ if build_python_is_pydebug () :
248254 configure .append ("--with-pydebug" )
249255 if context .args :
250256 configure .extend (context .args )
0 commit comments