|
26 | 26 | LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local"
|
27 | 27 | LOCAL_SETUP_MARKER = "# Generated by Tools/wasm/wasi.py\n".encode("utf-8")
|
28 | 28 |
|
| 29 | +WASMTIME_VAR_NAME = "WASMTIME" |
| 30 | +WASMTIME_HOST_RUNNER_VAR = f"{{{WASMTIME_VAR_NAME}}}" |
| 31 | + |
29 | 32 |
|
30 | 33 | def updated_env(updates={}):
|
31 | 34 | """Create a new dict representing the environment to use.
|
@@ -215,11 +218,20 @@ def configure_wasi_python(context, working_dir):
|
215 | 218 |
|
216 | 219 | # Use PYTHONPATH to include sysconfig data which must be anchored to the
|
217 | 220 | # 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) |
223 | 235 | env_additions = {"CONFIG_SITE": config_site, "HOSTRUNNER": host_runner}
|
224 | 236 | build_python = os.fsdecode(build_python_path())
|
225 | 237 | # The path to `configure` MUST be relative, else `python.wasm` is unable
|
@@ -277,7 +289,7 @@ def clean_contents(context):
|
277 | 289 |
|
278 | 290 |
|
279 | 291 | def main():
|
280 |
| - default_host_runner = (f"{shutil.which('wasmtime')} run " |
| 292 | + default_host_runner = (f"{WASMTIME_HOST_RUNNER_VAR} run " |
281 | 293 | # Make sure the stack size will work for a pydebug
|
282 | 294 | # build.
|
283 | 295 | # The 8388608 value comes from `ulimit -s` under Linux
|
|
0 commit comments