-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathwasmtime.py
More file actions
executable file
·82 lines (62 loc) · 2.47 KB
/
Copy pathwasmtime.py
File metadata and controls
executable file
·82 lines (62 loc) · 2.47 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
76
77
78
79
80
81
82
import os
import shlex
import subprocess
from pathlib import Path
from typing import Dict, List, Tuple, Optional
# shlex.split() splits according to shell quoting rules
WASMTIME = shlex.split(os.getenv("WASMTIME", "wasmtime"), posix=os.name != "nt")
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 get_wasi_worlds() -> List[str]:
return ["wasi:cli/command", "wasi:http/service"]
def compute_argv(test_path: str,
args_env_root: Tuple[List[str], Dict[str, str], Optional[str]],
proposals: List[str],
wasi_world: str,
wasi_version: str) -> List[str]:
argv = []
argv += WASMTIME
args, env, root = args_env_root
for k, v in env.items():
argv += ["--env", f"{k}={v}"]
if root:
argv += ["--dir", f"{root}::/"] # noqa: E231
argv += [test_path]
argv += args
_add_wasi_version_options(argv, wasi_version, proposals, wasi_world)
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], wasi_world: str) -> None:
splice_pos = len(WASMTIME)
while splice_pos > 1 and argv[splice_pos - 1].startswith("-"):
splice_pos -= 1
match wasi_world:
case "wasi:cli/command":
pass
case "wasi:http/service":
argv[splice_pos:splice_pos] = \
["serve", "-Scli", "--addr=127.0.0.1:0"]
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"
argv[splice_pos:splice_pos] = ["-Wcomponent-model-async",
f"-Sp3{flags_from_proposals}"]