From d8a660cd6e78af52a146a0a3a85306c380ce02d8 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Thu, 12 Dec 2024 15:40:56 -0800 Subject: [PATCH] Forward clippy, rustfmt, and rust-analyzer through wasm_bindgen (#3094) 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. --- .../wasm_bindgen/private/wasm_bindgen.bzl | 21 +++++++++++++++++-- extensions/wasm_bindgen/test/BUILD.bazel | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/extensions/wasm_bindgen/private/wasm_bindgen.bzl b/extensions/wasm_bindgen/private/wasm_bindgen.bzl index 01c7c66374..667b254506 100644 --- a/extensions/wasm_bindgen/private/wasm_bindgen.bzl +++ b/extensions/wasm_bindgen/private/wasm_bindgen.bzl @@ -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") @@ -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 = { @@ -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, ), diff --git a/extensions/wasm_bindgen/test/BUILD.bazel b/extensions/wasm_bindgen/test/BUILD.bazel index 45df94f9ed..26addefcd8 100644 --- a/extensions/wasm_bindgen/test/BUILD.bazel +++ b/extensions/wasm_bindgen/test/BUILD.bazel @@ -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", ], @@ -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", ],