From 6c86168604ce8d293bd218528f009f2296ef897a Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 12 Sep 2021 22:17:17 -0500 Subject: [PATCH] tests: add wasi/wasm build tests --- WORKSPACE | 11 ++++- tests/extra_targets/wasm/BUILD.bazel | 73 ++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 tests/extra_targets/wasm/BUILD.bazel diff --git a/WORKSPACE b/WORKSPACE index 7bdefd31f..7e537f6af 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -97,8 +97,17 @@ llvm_toolchain( }, ) -# Well known repos; present here only for testing. +# `bazel_skylib`; we're using its `build_test` test +http_archive( + name = "bazel_skylib", + urls = [ + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz", + ], + sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c", +) +# Well known repos; present here only for testing. http_archive( name = "com_google_googletest", sha256 = "9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb", diff --git a/tests/extra_targets/wasm/BUILD.bazel b/tests/extra_targets/wasm/BUILD.bazel new file mode 100644 index 000000000..3e22596b5 --- /dev/null +++ b/tests/extra_targets/wasm/BUILD.bazel @@ -0,0 +1,73 @@ +load("@bazel_skylib//rules:build_test.bzl", "build_test") +load(":transitions.bzl", "wasm_file", "wasi_file") + +# config_setting( +# name = "no_shared_objects", +# values = { +# "features": "-supports_dynamic_linker", +# } +# ) + +# cc_library( +# name = "stdlib-wasm", +# srcs = ["stdlib.cc"], +# hdrs = ["stdlib.h"], +# features = [ +# "-supports_dynamic_linker", +# ], +# target_compatible_with = [ +# "@platforms//cpu:wasm32", +# "@platforms//os:wasi", +# ], +# ) + +# TODO: add a rule that transitions --platforms to `//test:wasm` to ensure that +# toolchain resolution picks `@llvm_toolchain//:cc-clang-*_wasm32-unknown-unknown`. +# +# also have it set `--features=-supports_dynamic_linker`; ideally this would be in +# the toolchain definition but the downside of switching to using +# `unix_cc_toolchain_config.bzl` is that we lose this knob +# +# it's not clear yet if supporting different targets runs counter to using +# `unix_cc_toolchain_config.bzl` altogether – so far things are manageable but +# it's already apparent that we'll be sacrificing some power/configurability + +############################################################################### + +platform( + name = "wasm", + constraint_values = [ + "@platforms//cpu:wasm32", + "@platforms//os:none", + ], +) + +wasm_file( + name = "test.wasm", + src = "//tests:simple_binary", +) + +build_test( + name = "wasm_build_chk", + targets = [":test.wasm"], +) + +############################################################################### + +platform( + name = "wasi", + constraint_values = [ + "@platforms//cpu:wasm32", + "@platforms//os:wasi", + ], +) + +wasi_file( + name = "test.wasi", + src = "//tests:stdlib_binary", +) + +build_test( + name = "wasi_build_chk", + targets = [":test.wasi"], +)