Skip to content

Commit e63e727

Browse files
committed
Per-target rust testsuite
As in #112, we reorganize the directory structure and change to a python build script, with the goal of making space for wasip3. Before, it was: - tests/rust/: Root of cargo package - tests/rust/src: Rust source files - tests/rust/testsuite: JSON test files, fs-tests.dir; built .wasm files dumped here Now it is: - tests/rust/wasm32-wasip1: Root of cargo package for wasip1 builds - tests/rust/wasm32-wasip1/src: Rust source, but also JSON and fs-tests.dir - tests/rust/testsuite/: Removed; instead it is a built dir - tests/rust/testsuite/wasm32-wasip1: All wasm and json files copied here
1 parent 9315be9 commit e63e727

File tree

99 files changed

+96
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+96
-8
lines changed

.github/workflows/compile-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
- name: Build tests
6666
working-directory: tests/rust
6767
run: |
68-
./build.sh
68+
./build.py
6969
7070
- name: Upload precompiled tests
7171
if: matrix.os == 'ubuntu-latest'

.github/workflows/daily-runtime-validation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
-r ./adapters/${{ matrix.runtime }}.py \
7878
--json-output-location results.json \
7979
-t tests/assemblyscript/testsuite \
80-
tests/rust/testsuite \
80+
tests/rust/testsuite/wasm32-wasip1 \
8181
tests/c/testsuite
8282
8383
- name: Configure git

tests/rust/build.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import json
5+
import shlex
6+
import shutil
7+
import subprocess
8+
import sys
9+
from pathlib import Path
10+
11+
parser = argparse.ArgumentParser()
12+
parser.add_argument("--dry-run", action="store_true")
13+
parser.add_argument("--verbose", action="store_true")
14+
parser.add_argument("--release", action="store_true")
15+
16+
args = parser.parse_args()
17+
18+
SYSTEMS = ['wasm32']
19+
VERSIONS = ['wasip1'] # + ['wasip2', 'wasip3']
20+
21+
def compute_target(system, version):
22+
return f"{system}-{version}"
23+
24+
def compute_build_target(system, version):
25+
if version == 'wasip3':
26+
# wasm32-wasip3 triple not yet supported.
27+
return compute_target(system, 'wasip2')
28+
return compute_target(system, version)
29+
30+
BASE_DIR = Path(__file__).parent
31+
32+
def run(argv):
33+
if args.verbose:
34+
print(shlex.join([str(x) for x in argv]))
35+
if not args.dry_run:
36+
r = subprocess.run(argv)
37+
if r.returncode != 0:
38+
sys.exit(r.returncode)
39+
40+
def cp(src, dst):
41+
if args.verbose:
42+
print(f"cp {src} {dst}")
43+
if not args.dry_run:
44+
shutil.copy(src, dst)
45+
46+
def cp_R(src, dst):
47+
if args.verbose:
48+
print(f"cp -R {src} {dst}")
49+
if not args.dry_run:
50+
shutil.copytree(src, dst, dirs_exist_ok=True)
51+
52+
def write_manifest(path, manifest):
53+
if args.verbose:
54+
print(f"writing {path}")
55+
if not args.dry_run:
56+
path.write_text(json.dumps(manifest))
57+
58+
def mkdir_p(path):
59+
if args.verbose:
60+
print(f"mkdir -p {path}")
61+
if not args.dry_run:
62+
path.mkdir(parents=True, exist_ok=True)
63+
64+
for system in SYSTEMS:
65+
for version in VERSIONS:
66+
target = compute_target(system, version)
67+
build_target = compute_build_target(system, version)
68+
build_mode = "release" if args.release else "debug"
69+
70+
build_args = ["cargo", "build",
71+
f"--manifest-path={BASE_DIR / target / 'Cargo.toml'}",
72+
f"--target={build_target}"]
73+
if args.release:
74+
build_args.append("--release")
75+
run(build_args)
76+
77+
obj_dir = BASE_DIR / target / "target" / build_target / build_mode
78+
src_dir = BASE_DIR / target / "src" / "bin"
79+
dst_dir = BASE_DIR / "testsuite" / target
80+
mkdir_p(dst_dir)
81+
82+
write_manifest(dst_dir / "manifest.json",
83+
{'name': f"WASI Rust tests [{target}]"})
84+
85+
for src in src_dir.glob("*.rs"):
86+
obj = (obj_dir / src.name).with_suffix(".wasm")
87+
dst = (dst_dir / src.name).with_suffix(".wasm")
88+
cp(obj, dst)
89+
src_json = src.with_suffix(".json")
90+
if src_json.exists():
91+
cp(src_json, dst.with_suffix(".json"))
92+
with src_json.open() as f:
93+
for d in json.load(f).get('dirs', []):
94+
cp_R(src.parent / d, dst.parent / d)

tests/rust/build.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)