@@ -112,7 +112,7 @@ def call(command, *, quiet, **kwargs):
112112
113113def build_platform ():
114114 """The name of the build/host platform."""
115- # Can also be found via `config.guess`.`
115+ # Can also be found via `config.guess`.
116116 return sysconfig .get_config_var ("BUILD_GNU_TYPE" )
117117
118118
@@ -128,6 +128,15 @@ def build_python_path():
128128 return binary
129129
130130
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+
131140@subdir (BUILD_DIR , clean_ok = True )
132141def configure_build_python (context , working_dir ):
133142 """Configure the build/host Python."""
@@ -214,18 +223,15 @@ def configure_wasi_python(context, working_dir):
214223 lib_dirs = list (python_build_dir .glob ("lib.*" ))
215224 assert len (lib_dirs ) == 1 , f"Expected a single lib.* directory in { python_build_dir } "
216225 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 } "
222228
223229 # Use PYTHONPATH to include sysconfig data which must be anchored to the
224230 # WASI guest's `/` directory.
225231 args = {"GUEST_DIR" : "/" ,
226232 "HOST_DIR" : CHECKOUT ,
227233 "ENV_VAR_NAME" : "PYTHONPATH" ,
228- "ENV_VAR_VALUE" : f"/{ sysconfig_data } " ,
234+ "ENV_VAR_VALUE" : f"/{ sysconfig_data_dir } " ,
229235 "PYTHON_WASM" : working_dir / "python.wasm" }
230236 # Check dynamically for wasmtime in case it was specified manually via
231237 # `--host-runner`.
@@ -245,7 +251,7 @@ def configure_wasi_python(context, working_dir):
245251 f"--host={ context .host_triple } " ,
246252 f"--build={ build_platform ()} " ,
247253 f"--with-build-python={ build_python } " ]
248- if pydebug :
254+ if build_python_is_pydebug () :
249255 configure .append ("--with-pydebug" )
250256 if context .args :
251257 configure .extend (context .args )
0 commit comments