Skip to content

Commit ed92cf9

Browse files
authored
Merge pull request #199 from saulecabrera/op-based-configuration
Support operation based configuration
2 parents f13976f + 9ad2e3b commit ed92cf9

22 files changed

Lines changed: 865 additions & 323 deletions

adapters/pywasm.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import subprocess
22
import os
33
import shlex
4+
import sys
45
from pathlib import Path
56
from typing import Dict, List, Tuple
7+
import importlib
8+
69

710
# shlex.split() splits according to shell quoting rules
811
RUN_PYWASM = Path(__file__).parent.parent / "tools" / "run-pywasm"
@@ -25,15 +28,21 @@ def get_wasi_versions() -> List[str]:
2528
return ["wasm32-wasip1"]
2629

2730
def compute_argv(test_path: str,
28-
args: List[str],
29-
env: Dict[str, str],
30-
dirs: List[Tuple[Path, str]],
31+
args_env_dirs: Tuple[List[str], Dict[str, str], List[Tuple[Path, str]]],
32+
proposals: List[str],
3133
wasi_version: str) -> List[str]:
32-
argv = [str(RUN_PYWASM)]
34+
35+
argv = []
36+
argv += [str(RUN_PYWASM)]
37+
args, env, dirs = args_env_dirs
38+
3339
for k, v in env.items():
3440
argv += ["--env", f"{k}={v}"]
41+
3542
for host, guest in dirs:
3643
argv += ["--dir", f"{host}::{guest}"] # noqa: E231
44+
3745
argv += [test_path]
46+
3847
argv += args
3948
return argv

adapters/wasm-micro-runtime.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import subprocess
22
import os
33
import shlex
4+
import sys
45
from pathlib import Path
56
from typing import Dict, List, Tuple
7+
import importlib
8+
69

710
# shlex.split() splits according to shell quoting rules
811
IWASM = shlex.split(os.getenv("IWASM", "iwasm"))
@@ -26,15 +29,21 @@ def get_wasi_versions() -> List[str]:
2629

2730

2831
def compute_argv(test_path: str,
29-
args: List[str],
30-
env: Dict[str, str],
31-
dirs: List[Tuple[Path, str]],
32+
args_env_dirs: Tuple[List[str], Dict[str, str], List[Tuple[Path, str]]],
33+
proposals: List[str],
3234
wasi_version: str) -> List[str]:
33-
argv = [] + IWASM
35+
36+
argv = []
37+
argv += IWASM
38+
args, env, dirs = args_env_dirs
39+
3440
for k, v in env.items():
3541
argv += ["--env", f"{k}={v}"]
42+
3643
for host, guest in dirs:
3744
argv += ["--map-dir", f"{host}::{guest}"] # noqa: E231
45+
3846
argv += [test_path]
47+
3948
argv += args
4049
return argv

adapters/wasmedge.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import subprocess
22
import os
33
import shlex
4+
import sys
45
from pathlib import Path
56
from typing import Dict, List, Tuple
7+
import importlib
8+
69

710
# shlex.split() splits according to shell quoting rules
811
WASMEDGE = shlex.split(os.getenv("WASMEDGE", "wasmedge"))
@@ -26,15 +29,21 @@ def get_wasi_versions() -> List[str]:
2629

2730

2831
def compute_argv(test_path: str,
29-
args: List[str],
30-
env: Dict[str, str],
31-
dirs: List[Tuple[Path, str]],
32+
args_env_dirs: Tuple[List[str], Dict[str, str], List[Tuple[Path, str]]],
33+
proposals: List[str],
3234
wasi_version: str) -> List[str]:
33-
argv = [] + WASMEDGE
35+
36+
argv = []
37+
argv += WASMEDGE
38+
args, env, dirs = args_env_dirs
39+
3440
for k, v in env.items():
3541
argv += ["--env", f"{k}={v}"]
42+
3643
for host, guest in dirs:
3744
argv += ["--dir", f"{guest}:{host}"]
45+
3846
argv += [test_path]
47+
3948
argv += args
4049
return argv

adapters/wasmtime.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import subprocess
22
import os
33
import shlex
4+
import sys
45
from pathlib import Path
56
from typing import Dict, List, Tuple
7+
import importlib
8+
69

710
# shlex.split() splits according to shell quoting rules
811
WASMTIME = shlex.split(os.getenv("WASMTIME", "wasmtime"))
@@ -26,33 +29,46 @@ def get_wasi_versions() -> List[str]:
2629

2730

2831
def compute_argv(test_path: str,
29-
args: List[str],
30-
env: Dict[str, str],
31-
dirs: List[Tuple[Path, str]],
32+
args_env_dirs: Tuple[List[str], Dict[str, str], List[Tuple[Path, str]]],
33+
proposals: List[str],
3234
wasi_version: str) -> List[str]:
33-
argv = [] + WASMTIME
35+
36+
argv = []
37+
argv += WASMTIME
38+
args, env, dirs = args_env_dirs
39+
3440
for k, v in env.items():
3541
argv += ["--env", f"{k}={v}"]
42+
3643
for host, guest in dirs:
3744
argv += ["--dir", f"{host}::{guest}"] # noqa: E231
45+
3846
argv += [test_path]
47+
3948
argv += args
40-
_add_wasi_version_options(argv, wasi_version)
49+
_add_wasi_version_options(argv, wasi_version, proposals)
4150
return argv
4251

4352

4453
# The user might provide WASMTIME="wasmtime --option -Sfoo". Let's
4554
# insert the options to choose the WASI version before the user's
4655
# options, so that the user can override our choices.
47-
def _add_wasi_version_options(argv: List[str], wasi_version: str) -> None:
56+
def _add_wasi_version_options(argv: List[str], wasi_version: str, proposals: List[str]) -> None:
4857
splice_pos = len(WASMTIME)
4958
while splice_pos > 1 and args[splice_pos-1].startswith("-"):
5059
splice_pos -= 1
5160
match wasi_version:
5261
case "wasm32-wasip1":
5362
pass
5463
case "wasm32-wasip3":
64+
flags_from_proposals = ""
65+
if "http" in proposals:
66+
flags_from_proposals += ",http"
67+
if "sockets" in proposals:
68+
flags_from_proposals += ",inherit-network"
69+
5570
argv[splice_pos:splice_pos] = ["-Wcomponent-model-async",
56-
"-Sp3,http,inherit-network"]
71+
f"-Sp3{flags_from_proposals}"]
72+
5773
case _:
5874
pass

adapters/wazero.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import subprocess
22
import os
33
import shlex
4+
import sys
45
from pathlib import Path
56
from typing import Dict, List, Tuple
7+
import importlib
8+
69

710
# shlex.split() splits according to shell quoting rules
811
WAZERO = shlex.split(os.getenv("WAZERO", "wazero"))
@@ -28,15 +31,22 @@ def get_wasi_versions() -> List[str]:
2831

2932

3033
def compute_argv(test_path: str,
31-
args: List[str],
32-
env: Dict[str, str],
33-
dirs: List[Tuple[Path, str]],
34+
args_env_dirs: Tuple[List[str], Dict[str, str], List[Tuple[Path, str]]],
35+
proposals: List[str],
3436
wasi_version: str) -> List[str]:
35-
argv = WAZERO + ["run", "-hostlogging=filesystem"]
37+
38+
argv = []
39+
argv += WAZERO
40+
argv += ["run", "-hostlogging=filesystem"]
41+
args, env, dirs = args_env_dirs
42+
3643
for k, v in env.items():
3744
argv += [f"-env={k}={v}"]
45+
3846
for host, guest in dirs:
3947
argv += [f"-mount={host}:{guest}"]
48+
4049
argv += [test_path]
50+
4151
argv += args
4252
return argv

adapters/wizard.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import subprocess
22
import os
33
import shlex
4+
import sys
45
from pathlib import Path
56
from typing import Dict, List, Tuple
7+
import importlib
8+
69

710
# shlex.split() splits according to shell quoting rules
811
WIZARD = shlex.split(os.getenv("WIZARD", "wizeng.x86-64-linux"))
@@ -34,16 +37,22 @@ def get_wasi_versions() -> List[str]:
3437

3538

3639
def compute_argv(test_path: str,
37-
args: List[str],
38-
env: Dict[str, str],
39-
dirs: List[Tuple[Path, str]],
40+
args_env_dirs: Tuple[List[str], Dict[str, str], List[Tuple[Path, str]]],
41+
proposals: List[str],
4042
wasi_version: str) -> List[str]:
41-
argv = [] + WIZARD
43+
44+
argv = []
45+
argv += WIZARD
46+
args, env, dirs = args_env_dirs
47+
4248
for k, v in env.items():
4349
argv += [f"--env={k}={v}"]
50+
4451
for host, guest in dirs:
4552
# FIXME: https://github.com/titzer/wizard-engine/issues/482
4653
argv += [f"--dir={host}"]
54+
4755
argv += [test_path]
56+
4857
argv += args
4958
return argv

0 commit comments

Comments
 (0)