Skip to content

Commit 24e05e8

Browse files
committed
feature: add support for pywasm runtime
1 parent ce12493 commit 24e05e8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

adapters/pywasm-runtime.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import argparse
2+
import os
3+
import sys
4+
5+
import pywasm # pip install pywasm
6+
7+
parser = argparse.ArgumentParser()
8+
parser.add_argument("--version", action="store_true")
9+
parser.add_argument("--test-file", action="store")
10+
parser.add_argument("--arg", action="append", default=[])
11+
parser.add_argument("--env", action="append", default=[])
12+
parser.add_argument("--dir", action="append", default=[])
13+
14+
args = parser.parse_args()
15+
16+
if args.version:
17+
print('pywasm: https://github.com/mohanson/pywasm/releases/latest')
18+
sys.exit(0)
19+
20+
runtime = pywasm.core.Runtime()
21+
wasi = pywasm.wasi.Preview1(
22+
[os.path.basename(args.test_file)] + args.arg,
23+
{e: e for e in args.dir},
24+
dict([e.split('=') for e in args.env]),
25+
)
26+
wasi.bind(runtime)
27+
exit = wasi.main(runtime, runtime.instance_from_file(args.test_file))
28+
sys.exit(exit)

0 commit comments

Comments
 (0)