Skip to content

Commit 2da2be4

Browse files
authored
GH-131769: fix detecting a pydebug build of the build Python when building for WASI (GH-134015)
1 parent 9b292ff commit 2da2be4

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix detecting when the build Python in a cross-build is a pydebug build.

Tools/wasm/wasi/__main__.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def call(command, *, quiet, **kwargs):
112112

113113
def 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)
132141
def 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

Comments
 (0)