Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions tests/c/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@prelude//utils:utils.bzl", "value_or")
load("//tools:conformance.bzl", "wasi_test")

_DEFAULT_FIXTURE_DIRS = {
Expand All @@ -12,9 +13,7 @@ def _config_for(name, conf):
return path if glob([path]) else None

def _fixture_dirs_for(config, dirs):
if dirs != None:
return dirs
return _DEFAULT_FIXTURE_DIRS if config else {}
return value_or(dirs, _DEFAULT_FIXTURE_DIRS if config else {})

def _c_artifact(name):
native.cxx_binary(
Expand Down
5 changes: 2 additions & 3 deletions tests/rust/wasm32-wasip1/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@prelude//utils:utils.bzl", "value_or")
load("//platforms:defs.bzl", "transition_alias")
load("//tools:conformance.bzl", "wasi_test")

Expand All @@ -13,9 +14,7 @@ def _config_for(name, conf):
return path if glob([path]) else None

def _fixture_dirs_for(config, dirs):
if dirs != None:
return dirs
return _DEFAULT_FIXTURE_DIRS if config else {}
return value_or(dirs, _DEFAULT_FIXTURE_DIRS if config else {})

def _rust_artifact(name, deps):
native.rust_binary(
Expand Down
8 changes: 5 additions & 3 deletions tests/rust/wasm32-wasip3/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@prelude//utils:utils.bzl", "value_or")
load("@wasmono//:defs.bzl", "wasm_component")
load("//tools:conformance.bzl", "wasi_test")

Expand All @@ -13,9 +14,10 @@ def _config_for(name, conf):
return path if glob([path]) else None

def _fixture_dirs_for(config, dirs):
if dirs != None:
return dirs
return _DEFAULT_FIXTURE_DIRS if config and config.startswith("src/bin/filesystem-") else {}
return value_or(
dirs,
_DEFAULT_FIXTURE_DIRS if config and config.startswith("src/bin/filesystem-") else {},
)

def _rust_p3_artifact(name, deps, wit_srcs):
module_name = "{}_module".format(name)
Expand Down
27 changes: 15 additions & 12 deletions toolchains/runtimes/runtimes.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Download rules for WASI runtime binaries used by the test suite."""

load("@prelude//utils:expect.bzl", "expect")
load("@wasmono//toolchains/wasm:node.bzl", "NodeInfo")
load("@wasmono//:defs.bzl", "host_arch", "host_os")
load(":releases.bzl", "WAMR_RELEASES", "WASMEDGE_RELEASES", "WASMTIME_RELEASES", "WAZERO_RELEASES")
Expand All @@ -16,24 +17,26 @@ def _runtime_platform() -> str:

def _runtime_release(releases, runtime_name: str, version: str, target_compatible_with = []):
platform = _runtime_platform()
if version not in releases:
fail("Unknown {} version '{}'. Available: {}".format(
runtime_name,
version,
", ".join(releases.keys()),
))
expect(
version in releases,
"Unknown {} version '{}'. Available: {}",
runtime_name,
version,
", ".join(releases.keys()),
)

release = releases[version]
if platform not in release and target_compatible_with:
for fallback in release.values():
return fallback

if platform not in release:
fail("No {} release for platform '{}'. Available: {}".format(
runtime_name,
platform,
", ".join(release.keys()),
))
expect(
platform in release,
"No {} release for platform '{}'. Available: {}",
runtime_name,
platform,
", ".join(release.keys()),
)
return release[platform]

def _runtime_distribution_impl(ctx: AnalysisContext) -> list[Provider]:
Expand Down
30 changes: 18 additions & 12 deletions toolchains/rust/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Adapted from https://github.com/rue-language/rue/blob/trunk/toolchains/rust/defs
"""

load("@prelude//rust:rust_toolchain.bzl", "PanicRuntime", "RustToolchainInfo")
load("@prelude//utils:expect.bzl", "expect")
load("@wasmono//:defs.bzl", "host_arch", "host_os")
load(
":releases.bzl",
Expand All @@ -26,17 +27,21 @@ _HOST_TRIPLES = {
def host_rust_triple() -> str:
"""Return the Rust host triple for the machine running Buck."""
key = "{}-{}".format(host_arch(), host_os())
if key not in _HOST_TRIPLES:
fail("Unsupported host platform for the hermetic Rust toolchain: '{}'".format(key))
expect(
key in _HOST_TRIPLES,
"Unsupported host platform for the hermetic Rust toolchain: '{}'",
key,
)
return _HOST_TRIPLES[key]

def download_rust_host(name: str, triple: str):
"""Download the combined ``rust`` package for ``triple``."""
if triple not in RUST_HOST_RELEASES:
fail("No pinned Rust host release for '{}'. Available: {}".format(
triple,
", ".join(sorted(RUST_HOST_RELEASES.keys())),
))
expect(
triple in RUST_HOST_RELEASES,
"No pinned Rust host release for '{}'. Available: {}",
triple,
", ".join(sorted(RUST_HOST_RELEASES.keys())),
)
native.http_archive(
name = name,
urls = [rust_host_url(triple)],
Expand All @@ -47,11 +52,12 @@ def download_rust_host(name: str, triple: str):

def download_rust_std(name: str, target: str):
"""Download the ``rust-std`` package for a wasm ``target``."""
if target not in RUST_STD_RELEASES:
fail("No pinned Rust std release for '{}'. Available: {}".format(
target,
", ".join(sorted(RUST_STD_RELEASES.keys())),
))
expect(
target in RUST_STD_RELEASES,
"No pinned Rust std release for '{}'. Available: {}",
target,
", ".join(sorted(RUST_STD_RELEASES.keys())),
)
native.http_archive(
name = name,
urls = [rust_std_url(target)],
Expand Down
35 changes: 25 additions & 10 deletions tools/conformance.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ The build target that produces a `.wasm` file should stay language-specific

load("@prelude//decls:common.bzl", "buck")
load("@prelude//test:inject_test_run_info.bzl", "inject_test_run_info")
load("@prelude//utils:expect.bzl", "expect")
load("@prelude//utils:type_defs.bzl", "type_utils")
load("@prelude//utils:utils.bzl", "value_or")
load(":runtime.bzl", "WasiRuntimeInfo")

WasiTestInfo = provider(
Expand Down Expand Up @@ -55,23 +58,32 @@ def wasi_manifest(
)

def _infer_test_name(wasm):
if type(wasm) != type(""):
fail("wasi_test: test_name is required when wasm is not a label string")
if ":" not in wasm:
fail("wasi_test: cannot infer test_name from '{}'; pass test_name explicitly".format(wasm))
expect(
type_utils.is_string(wasm),
"wasi_test: test_name is required when wasm is not a label string",
)
expect(
":" in wasm,
"wasi_test: cannot infer test_name from '{}'; pass test_name explicitly",
wasm,
)
return wasm.rsplit(":", 1)[1]

def _single_output(dep, attr_name):
outputs = dep[DefaultInfo].default_outputs
if len(outputs) != 1:
fail("{} must provide exactly one output, got {}".format(attr_name, len(outputs)))
expect(
len(outputs) == 1,
"{} must provide exactly one output, got {}",
attr_name,
len(outputs),
)
return outputs[0]

def _wasi_test_impl(ctx: AnalysisContext) -> list[Provider]:
wasm = _single_output(ctx.attrs.wasm, "wasm")
runtime_info = ctx.attrs.runtime[WasiRuntimeInfo]
runtime = runtime_info.runtime
expectations = ctx.attrs.expectations or runtime_info.expectations
expectations = value_or(ctx.attrs.expectations, runtime_info.expectations)

cmd = cmd_args(ctx.attrs._runner[RunInfo])
cmd.add("--wasm", wasm)
Expand Down Expand Up @@ -203,12 +215,15 @@ def _wasi_test_suite_impl(ctx: AnalysisContext) -> list[Provider]:
other_outputs.extend(default_info.other_outputs)

# Collect test metadata, flattening nested wasi_suite targets.
expect(
WasiTestInfo in test or WasiTestSuiteInfo in test,
"{} does not provide WasiTestInfo or WasiTestSuiteInfo",
test.label,
)
if WasiTestInfo in test:
tests.append(test[WasiTestInfo])
elif WasiTestSuiteInfo in test:
tests.extend(test[WasiTestSuiteInfo].tests)
else:
fail("{} does not provide WasiTestInfo or WasiTestSuiteInfo".format(test.label))
tests.extend(test[WasiTestSuiteInfo].tests)

return [
DefaultInfo(
Expand Down
26 changes: 17 additions & 9 deletions tools/dist.bzl
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
"""Rules for packaging WASI tests into a distribution archive."""

load("@prelude//utils:dicts.bzl", "update_x")
load("@prelude//utils:expect.bzl", "expect")
load("@prelude//utils:utils.bzl", "map_idx")
load("//tools:conformance.bzl", "WasiTestSuiteInfo")

def _single_output(dep, attr_name):
outputs = dep[DefaultInfo].default_outputs
if len(outputs) != 1:
fail("{} must provide exactly one output, got {}".format(attr_name, len(outputs)))
expect(
len(outputs) == 1,
"{} must provide exactly one output, got {}",
attr_name,
len(outputs),
)
return outputs[0]

def _add_item(items, path, src):
Expand All @@ -23,19 +30,20 @@ def _wasi_dist_impl(ctx: AnalysisContext) -> list[Provider]:

for suite in ctx.attrs.suites:
for test in suite[WasiTestSuiteInfo].tests:
if test.dist_dir == None:
fail("{} does not set dist_dir in wasi_test".format(test.test_name))
expect(test.dist_dir != None, "{} does not set dist_dir in wasi_test", test.test_name)

manifest_path = "{}/manifest.json".format(test.dist_dir)
manifest = {
"name": test.suite_name,
"version": test.wasi_version,
}

if manifest_path in manifests and manifests[manifest_path] != manifest:
fail("conflicting manifest metadata for {}".format(manifest_path))

manifests[manifest_path] = manifest
update_x(
manifests,
manifest_path,
manifest,
fmt = "conflicting manifest metadata for {}: {} != {}",
)

_add_item(item_map, "{}/{}.wasm".format(test.dist_dir, test.test_name), test.wasm)
_add_item(item_map, "{}/{}.json".format(test.dist_dir, test.test_name), test.config)
Expand Down Expand Up @@ -73,7 +81,7 @@ def _wasi_dist_impl(ctx: AnalysisContext) -> list[Provider]:
spec,
"--output",
output.as_output(),
hidden = [item["src"] for item in items],
hidden = map_idx("src", items),
),
category = "wasi_dist",
)
Expand Down
Loading