-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathwasmtime.py
More file actions
executable file
·75 lines (57 loc) · 2.28 KB
/
wasmtime.py
File metadata and controls
executable file
·75 lines (57 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
import shlex
import subprocess
from pathlib import Path
from typing import Dict, List, Tuple
# shlex.split() splits according to shell quoting rules
WASMTIME = shlex.split(os.getenv("WASMTIME", "wasmtime"))
def get_name() -> str:
return "wasmtime"
def get_version() -> str:
# ensure no args when version is queried
result = subprocess.run(WASMTIME[0:1] + ["--version"],
encoding="UTF-8", capture_output=True,
check=True)
output = result.stdout.splitlines()[0].split(" ")
return output[1]
def get_wasi_versions() -> List[str]:
return ["wasm32-wasip1", "wasm32-wasip3"]
def compute_argv(test_path: str,
args_env_dirs: Tuple[List[str], Dict[str, str], List[Tuple[Path, str]]],
proposals: List[str],
wasi_version: str) -> List[str]:
argv = []
argv += WASMTIME
args, env, dirs = args_env_dirs
for k, v in env.items():
argv += ["--env", f"{k}={v}"]
for host, guest in dirs:
argv += ["--dir", f"{host}::{guest}"] # noqa: E231
argv += [test_path]
argv += args
_add_wasi_version_options(argv, wasi_version, proposals)
return argv
# The user might provide WASMTIME="wasmtime --option -Sfoo". Let's
# insert the options to choose the WASI version before the user's
# options, so that the user can override our choices.
def _add_wasi_version_options(argv: List[str], wasi_version: str, proposals: List[str]) -> None:
splice_pos = len(WASMTIME)
while splice_pos > 1 and argv[splice_pos - 1].startswith("-"):
splice_pos -= 1
match wasi_version:
case "wasm32-wasip1":
pass
case "wasm32-wasip3":
flags_from_proposals = ""
if "http" in proposals:
flags_from_proposals += ",http"
if "sockets" in proposals:
flags_from_proposals += ",inherit-network"
if "http/service" in proposals:
flags_from_proposals += ",cli"
argv[splice_pos:splice_pos] = ["serve", "--addr=127.0.0.1:0"]
splice_pos += 1
argv[splice_pos:splice_pos] = ["-Wcomponent-model-async",
f"-Sp3{flags_from_proposals}"]
case _:
pass