10000 GH-121521: Detect when wasmtime is not installed in `Tools/wasm/wasi.py` by brettcannon · Pull Request #121522 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-121521: Detect when wasmtime is not installed in Tools/wasm/wasi.py #121522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
GH-121521: Detect when wasmtime is not installed in Tools/wasm/wasi.py
  • Loading branch information
brettcannon committed Jul 9, 2024
commit ce896b7154eb1e6d26561773361e97b6e5947206
23 changes: 17 additions & 6 deletions Tools/wasm/wasi.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local"
LOCAL_SETUP_MARKER = "# Generated by Tools/wasm/wasi.py\n".encode("utf-8")

WASMTIME_VAR = "{WASMTIME}"


def updated_env(updates={}):
"""Create a new dict representing the environment to use.
Expand Down Expand Up @@ -215,11 +217,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_VAR in context.host_runner:
if not (wasmtime := shutil.which("wasmtime")):
raise FileNotFoundError("wasmtime not found; download from "
"https://github.com/bytecodealliance/wasmtime")
else:
args[WASMTIME_VAR.removeprefix("{").removesuffix("}")] = 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
Expand Down Expand Up @@ -277,7 +288,7 @@ def clean_contents(context):


def main():
default_host_runner = (f"{shutil.which('wasmtime')} run "
default_host_runner = (f"{WASMTIME_VAR} run "
# Make sure the stack size will work for a pydebug
# build.
# Use 16 MiB stack.
Expand Down
Loading
0