]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] GH-121521: Detect when wasmtime is not installed in `Tools/wasm/wasi.py` ...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 9 Jul 2024 22:31:39 +0000 (00:31 +0200)
committerGitHub <noreply@github.com>
Tue, 9 Jul 2024 22:31:39 +0000 (22:31 +0000)
GH-121521: Detect when wasmtime is not installed in `Tools/wasm/wasi.py` (GH-121522)
(cherry picked from commit f62161837e68c1c77961435f1b954412dd5c2b65)

Co-authored-by: Brett Cannon <brett@python.org>
Tools/wasm/wasi.py

index efb005e53ab989b488f68a40573ec413a235327a..d4394d7dc1d02606b7b982eb557c8e254d467bff 100644 (file)
@@ -26,6 +26,9 @@ HOST_DIR = CROSS_BUILD_DIR / HOST_TRIPLE
 LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local"
 LOCAL_SETUP_MARKER = "# Generated by Tools/wasm/wasi.py\n".encode("utf-8")
 
+WASMTIME_VAR_NAME = "WASMTIME"
+WASMTIME_HOST_RUNNER_VAR = f"{{{WASMTIME_VAR_NAME}}}"
+
 
 def updated_env(updates={}):
     """Create a new dict representing the environment to use.
@@ -215,11 +218,20 @@ def configure_wasi_python(context, working_dir):
 
     # Use PYTHONPATH to include sysconfig data which must be anchored to the
     # WASI guest's `/` directory.
-    host_runner = context.host_runner.format(GUEST_DIR="/",
-                                             HOST_DIR=CHECKOUT,
-                                             ENV_VAR_NAME="PYTHONPATH",
-                                             ENV_VAR_VALUE=f"/{sysconfig_data}",
-                                             PYTHON_WASM=working_dir / "python.wasm")
+    args = {"GUEST_DIR": "/",
+            "HOST_DIR": CHECKOUT,
+            "ENV_VAR_NAME": "PYTHONPATH",
+            "ENV_VAR_VALUE": f"/{sysconfig_data}",
+            "PYTHON_WASM": working_dir / "python.wasm"}
+    # Check dynamically for wasmtime in case it was specified manually via
+    # `--host-runner`.
+    if WASMTIME_HOST_RUNNER_VAR in context.host_runner:
+        if wasmtime := shutil.which("wasmtime"):
+            args[WASMTIME_VAR_NAME] = wasmtime
+        else:
+            raise FileNotFoundError("wasmtime not found; download from "
+                                    "https://github.com/bytecodealliance/wasmtime")
+    host_runner = context.host_runner.format_map(args)
     env_additions = {"CONFIG_SITE": config_site, "HOSTRUNNER": host_runner}
     build_python = os.fsdecode(build_python_path())
     # The path to `configure` MUST be relative, else `python.wasm` is unable
@@ -277,7 +289,7 @@ def clean_contents(context):
 
 
 def main():
-    default_host_runner = (f"{shutil.which('wasmtime')} run "
+    default_host_runner = (f"{WASMTIME_HOST_RUNNER_VAR} run "
                         # Make sure the stack size will work for a pydebug
                         # build.
                         # The 8388608 value comes from `ulimit -s` under Linux