Skip to content

Commit 3824dc9

Browse files
[3.13] GH-121521: Detect when wasmtime is not installed in Tools/wasm/wasi.py (GH-121522) (GH-121558)
GH-121521: Detect when wasmtime is not installed in `Tools/wasm/wasi.py` (GH-121522) (cherry picked from commit f621618) Co-authored-by: Brett Cannon <[email protected]>
1 parent 20a6341 commit 3824dc9

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

Tools/wasm/wasi.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local"
2727
LOCAL_SETUP_MARKER = "# Generated by Tools/wasm/wasi.py\n".encode("utf-8")
2828

29+
WASMTIME_VAR_NAME = "WASMTIME"
30+
WASMTIME_HOST_RUNNER_VAR = f"{{{WASMTIME_VAR_NAME}}}"
31+
2932

3033
def updated_env(updates={}):
3134
"""Create a new dict representing the environment to use.
@@ -215,11 +218,20 @@ def configure_wasi_python(context, working_dir):
215218

216219
# Use PYTHONPATH to include sysconfig data which must be anchored to the
217220
# WASI guest's `/` directory.
218-
host_runner = context.host_runner.format(GUEST_DIR="/",
219-
HOST_DIR=CHECKOUT,
220-
ENV_VAR_NAME="PYTHONPATH",
221-
ENV_VAR_VALUE=f"/{sysconfig_data}",
222-
PYTHON_WASM=working_dir / "python.wasm")
221+
args = {"GUEST_DIR": "/",
222+
"HOST_DIR": CHECKOUT,
223+
"ENV_VAR_NAME": "PYTHONPATH",
224+
"ENV_VAR_VALUE": f"/{sysconfig_data}",
225+
"PYTHON_WASM": working_dir / "python.wasm"}
226+
# Check dynamically for wasmtime in case it was specified manually via
227+
# `--host-runner`.
228+
if WASMTIME_HOST_RUNNER_VAR in context.host_runner:
229+
if wasmtime := shutil.which("wasmtime"):
230+
args[WASMTIME_VAR_NAME] = wasmtime
231+
else:
232+
raise FileNotFoundError("wasmtime not found; download from "
233+
"https://github.com/bytecodealliance/wasmtime")
234+
host_runner = context.host_runner.format_map(args)
223235
env_additions = {"CONFIG_SITE": config_site, "HOSTRUNNER": host_runner}
224236
build_python = os.fsdecode(build_python_path())
225237
# The path to `configure` MUST be relative, else `python.wasm` is unable
@@ -277,7 +289,7 @@ def clean_contents(context):
277289

278290

279291
def main():
280-
default_host_runner = (f"{shutil.which('wasmtime')} run "
292+
default_host_runner = (f"{WASMTIME_HOST_RUNNER_VAR} run "
281293
# Make sure the stack size will work for a pydebug
282294
# build.
283295
# The 8388608 value comes from `ulimit -s` under Linux

0 commit comments

Comments
 (0)