Skip to content

Commit

Permalink
Forward clippy, rustfmt, and rust-analyzer through wasm_bindgen (#3094)
Browse files Browse the repository at this point in the history
This allows targets gated by `target_compatible_with =
["@platforms//cpu:wasm32"]` to have clippy and rustfmt run on them as
well as include those targets in rust-analyzer outputs.
  • Loading branch information
UebelAndre authored Dec 12, 2024
1 parent eccf91a commit d8a660c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 19 additions & 2 deletions extensions/wasm_bindgen/private/wasm_bindgen.bzl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Bazel rules for [wasm-bindgen](https://crates.io/crates/wasm-bindgen)"""

load("@rules_rust//rust:defs.bzl", "rust_common")
load("@rules_rust//rust:defs.bzl", "rust_analyzer_aspect", "rust_clippy_aspect", "rust_common", "rustfmt_aspect")

# buildifier: disable=bzl-visibility
load("@rules_rust//rust/private:providers.bzl", "RustAnalyzerGroupInfo", "RustAnalyzerInfo")
load("@rules_rust//rust/private:providers.bzl", "ClippyInfo", "RustAnalyzerGroupInfo", "RustAnalyzerInfo")
load("//:providers.bzl", "RustWasmBindgenInfo")
load(":transitions.bzl", "wasm_bindgen_transition")

Expand Down Expand Up @@ -118,6 +118,18 @@ def _rust_wasm_bindgen_impl(ctx):
if RustAnalyzerInfo in ctx.attr.wasm_file:
providers.append(ctx.attr.wasm_file[RustAnalyzerInfo])

if ClippyInfo in ctx.attr.wasm_file:
providers.append(ctx.attr.wasm_file[ClippyInfo])

if OutputGroupInfo in ctx.attr.wasm_file:
output_info = ctx.attr.wasm_file[OutputGroupInfo]
output_groups = {}
for group in ["rusfmt_checks", "clippy_checks", "rust_analyzer_crate_spec"]:
if hasattr(output_info, group):
output_groups[group] = getattr(output_info, group)

providers.append(OutputGroupInfo(**output_groups))

return providers

WASM_BINDGEN_ATTR = {
Expand All @@ -140,6 +152,11 @@ WASM_BINDGEN_ATTR = {
"wasm_file": attr.label(
doc = "The `.wasm` file or crate to generate bindings for.",
allow_single_file = True,
aspects = [
rust_analyzer_aspect,
rustfmt_aspect,
rust_clippy_aspect,
],
cfg = wasm_bindgen_transition,
mandatory = True,
),
Expand Down
2 changes: 2 additions & 0 deletions extensions/wasm_bindgen/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ rust_binary(
name = "hello_world_bin_wasm",
srcs = ["main.rs"],
edition = "2018",
target_compatible_with = ["@platforms//cpu:wasm32"],
deps = [
"@rules_rust_wasm_bindgen//3rdparty:wasm_bindgen",
],
Expand All @@ -35,6 +36,7 @@ rust_shared_library(
name = "hello_world_lib_wasm",
srcs = ["main.rs"],
edition = "2018",
target_compatible_with = ["@platforms//cpu:wasm32"],
deps = [
"@rules_rust_wasm_bindgen//3rdparty:wasm_bindgen",
],
Expand Down

0 comments on commit d8a660c

Please sign in to comment.