Skip to content

Commit 67e5f1e

Browse files
authored
Merge pull request #67473 from apple/maxd/wasm-run-tests
tests: configure Wasm runtime selection in `lit.cfg` Currently `wasmer` is hardcoded as a Wasm runtime for running tests. We should make this configurable to be able to select an arbitrary runtime.
2 parents cbc854f + b53646a commit 67e5f1e

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

test/lit.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ config.swift_demangle_yamldump = inferSwiftBinary('swift-demangle-yamldump')
348348
config.swift_demangle = inferSwiftBinary('swift-demangle')
349349
config.benchmark_o = inferSwiftBinary('Benchmark_O')
350350
config.benchmark_driver = inferSwiftBinary('Benchmark_Driver')
351-
config.wasmer = inferSwiftBinary('wasmer')
352351
config.wasm_ld = inferSwiftBinary('wasm-ld')
353352
config.swift_plugin_server = inferSwiftBinary('swift-plugin-server')
354353

@@ -1849,7 +1848,9 @@ elif run_os == 'wasi':
18491848
config.swift_test_options, config.swift_frontend_test_options])
18501849
subst_target_swift_frontend_mock_sdk = config.target_swift_frontend
18511850
subst_target_swift_frontend_mock_sdk_after = ""
1852-
config.target_run = '%s run --backend cranelift --' % config.wasmer
1851+
config.target_run = os.path.join(config.swift_utils, 'wasm-run.py')
1852+
config.target_env_prefix = 'WASM_RUN_CHILD_'
1853+
18531854
if 'interpret' in lit_config.params:
18541855
use_interpreter_for_simple_runs()
18551856
config.target_sil_opt = (

utils/wasm-run.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import os
5+
import subprocess
6+
import sys
7+
8+
9+
def collect_wasm_env(local_env=os.environ, prefix='WASM_RUN_CHILD_'):
10+
return dict((key[len(prefix):], value)
11+
for key, value in local_env.items() if key.startswith(prefix))
12+
13+
14+
class WasmtimeRunner(object):
15+
def __init__(self):
16+
pass
17+
18+
def run(self, args):
19+
command = self.invocation(args)
20+
if args.verbose:
21+
print(' '.join(command), file=sys.stderr)
22+
23+
if not args.dry_run:
24+
subprocess.check_call(command)
25+
26+
def invocation(self, args):
27+
command = ["wasmtime", "run"]
28+
envs = collect_wasm_env()
29+
for key in envs:
30+
command.append("--env")
31+
command.append(f"{key}={envs[key]}")
32+
command.append("--")
33+
command.extend(args.command)
34+
return command
35+
36+
37+
def main():
38+
parser = argparse.ArgumentParser()
39+
40+
parser.add_argument('-v', '--verbose', action='store_true', dest='verbose',
41+
help='print commands as they are run')
42+
parser.add_argument('-n', '--dry-run', action='store_true', dest='dry_run',
43+
help="print the commands that would have been run, but"
44+
" don't actually run them")
45+
parser.add_argument('command', nargs=argparse.REMAINDER,
46+
help='the command to run', metavar='command...')
47+
48+
args = parser.parse_args()
49+
runner = WasmtimeRunner()
50+
runner.run(args)
51+
52+
53+
if __name__ == "__main__":
54+
main()

0 commit comments

Comments
 (0)