aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Tools/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/wasm')
-rw-r--r--Tools/wasm/emscripten/__main__.py3
-rw-r--r--Tools/wasm/wasi.py2
-rw-r--r--Tools/wasm/wasi/__main__.py30
3 files changed, 21 insertions, 14 deletions
diff --git a/Tools/wasm/emscripten/__main__.py b/Tools/wasm/emscripten/__main__.py
index 849bd5de44e..c0d58aeaadd 100644
--- a/Tools/wasm/emscripten/__main__.py
+++ b/Tools/wasm/emscripten/__main__.py
@@ -167,11 +167,12 @@ def make_build_python(context, working_dir):
@subdir(HOST_BUILD_DIR, clean_ok=True)
def make_emscripten_libffi(context, working_dir):
shutil.rmtree(working_dir / "libffi-3.4.6", ignore_errors=True)
- with tempfile.NamedTemporaryFile(suffix=".tar.gz") as tmp_file:
+ with tempfile.NamedTemporaryFile(suffix=".tar.gz", delete_on_close=False) as tmp_file:
with urlopen(
"https://github.com/libffi/libffi/releases/download/v3.4.6/libffi-3.4.6.tar.gz"
) as response:
shutil.copyfileobj(response, tmp_file)
+ tmp_file.close()
shutil.unpack_archive(tmp_file.name, working_dir)
call(
[EMSCRIPTEN_DIR / "make_libffi.sh"],
diff --git a/Tools/wasm/wasi.py b/Tools/wasm/wasi.py
index c0f7ccd51aa..b49b27cbbbe 100644
--- a/Tools/wasm/wasi.py
+++ b/Tools/wasm/wasi.py
@@ -3,7 +3,7 @@ if __name__ == "__main__":
import runpy
import sys
- print("⚠️ WARNING: This script is deprecated and slated for removal in Python 3.19; "
+ print("⚠️ WARNING: This script is deprecated and slated for removal in Python 3.20; "
"execute the `wasi/` directory instead (i.e. `python Tools/wasm/wasi`)\n",
file=sys.stderr)
diff --git a/Tools/wasm/wasi/__main__.py b/Tools/wasm/wasi/__main__.py
index 6af9b5f12cb..54ccc95157d 100644
--- a/Tools/wasm/wasi/__main__.py
+++ b/Tools/wasm/wasi/__main__.py
@@ -112,7 +112,7 @@ def call(command, *, quiet, **kwargs):
def build_platform():
"""The name of the build/host platform."""
- # Can also be found via `config.guess`.`
+ # Can also be found via `config.guess`.
return sysconfig.get_config_var("BUILD_GNU_TYPE")
@@ -128,6 +128,15 @@ def build_python_path():
return binary
+def build_python_is_pydebug():
+ """Find out if the build Python is a pydebug build."""
+ test = "import sys, test.support; sys.exit(test.support.Py_DEBUG)"
+ result = subprocess.run([build_python_path(), "-c", test],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ return bool(result.returncode)
+
+
@subdir(BUILD_DIR, clean_ok=True)
def configure_build_python(context, working_dir):
"""Configure the build/host Python."""
@@ -214,18 +223,15 @@ def configure_wasi_python(context, working_dir):
lib_dirs = list(python_build_dir.glob("lib.*"))
assert len(lib_dirs) == 1, f"Expected a single lib.* directory in {python_build_dir}"
lib_dir = os.fsdecode(lib_dirs[0])
- pydebug = lib_dir.endswith("-pydebug")
- python_version = lib_dir.removesuffix("-pydebug").rpartition("-")[-1]
- sysconfig_data = f"{wasi_build_dir}/build/lib.wasi-wasm32-{python_version}"
- if pydebug:
- sysconfig_data += "-pydebug"
+ python_version = lib_dir.rpartition("-")[-1]
+ sysconfig_data_dir = f"{wasi_build_dir}/build/lib.wasi-wasm32-{python_version}"
# Use PYTHONPATH to include sysconfig data which must be anchored to the
# WASI guest's `/` directory.
args = {"GUEST_DIR": "/",
"HOST_DIR": CHECKOUT,
"ENV_VAR_NAME": "PYTHONPATH",
- "ENV_VAR_VALUE": f"/{sysconfig_data}",
+ "ENV_VAR_VALUE": f"/{sysconfig_data_dir}",
"PYTHON_WASM": working_dir / "python.wasm"}
# Check dynamically for wasmtime in case it was specified manually via
# `--host-runner`.
@@ -245,7 +251,7 @@ def configure_wasi_python(context, working_dir):
f"--host={context.host_triple}",
f"--build={build_platform()}",
f"--with-build-python={build_python}"]
- if pydebug:
+ if build_python_is_pydebug():
configure.append("--with-pydebug")
if context.args:
configure.extend(context.args)
@@ -258,7 +264,7 @@ def configure_wasi_python(context, working_dir):
with exec_script.open("w", encoding="utf-8") as file:
file.write(f'#!/bin/sh\nexec {host_runner} {python_wasm} "$@"\n')
exec_script.chmod(0o755)
- print(f"🏃‍♀️ Created {exec_script} ... ")
+ print(f"🏃‍♀️ Created {exec_script} (--host-runner)... ")
sys.stdout.flush()
@@ -270,10 +276,10 @@ def make_wasi_python(context, working_dir):
quiet=context.quiet)
exec_script = working_dir / "python.sh"
- subprocess.check_call([exec_script, "--version"])
+ call([exec_script, "--version"], quiet=False)
print(
- f"🎉 Use '{exec_script.relative_to(context.init_dir)}' "
- "to run CPython in wasm runtime"
+ f"🎉 Use `{exec_script.relative_to(context.init_dir)}` "
+ "to run CPython w/ the WASI host specified by --host-runner"
)