fork/rules_rust

git clone https://git.julia.blue/fork/rules_rust

UebelAndreAllow rust_wasm_bindgen rules to re-expose rust-analyzer providers (#3035)13746789

main
1.9 KiB60 linesraw
1"""Rust WASM-bindgen rules for interfacing with bazelbuild/rules_nodejs"""
2
3load("@rules_nodejs//nodejs:providers.bzl", "DeclarationInfo", "JSModuleInfo")
4
5# buildifier: disable=bzl-visibility
6load("@rules_rust//rust/private:providers.bzl", "RustAnalyzerGroupInfo", "RustAnalyzerInfo")
7load("//private:wasm_bindgen.bzl", "WASM_BINDGEN_ATTR", "rust_wasm_bindgen_action")
8
9def _nodejs_rust_wasm_bindgen_impl(ctx):
10    toolchain = ctx.toolchains[Label("//:toolchain_type")]
11
12    info = rust_wasm_bindgen_action(
13        ctx = ctx,
14        toolchain = toolchain,
15        wasm_file = ctx.attr.wasm_file,
16        target_output = ctx.attr.target,
17        flags = ctx.attr.bindgen_flags,
18    )
19
20    # Return a structure that is compatible with the deps[] of a ts_library.
21    declarations = info.ts
22    es5_sources = info.js
23
24    providers = [
25        DefaultInfo(
26            files = depset([info.wasm], transitive = [info.js, info.ts]),
27        ),
28        DeclarationInfo(
29            declarations = declarations,
30            transitive_declarations = declarations,
31            type_blocklisted_declarations = depset([]),
32        ),
33        JSModuleInfo(
34            direct_sources = es5_sources,
35            sources = es5_sources,
36        ),
37        info,
38    ]
39
40    if RustAnalyzerGroupInfo in ctx.attr.wasm_file:
41        providers.append(ctx.attr.wasm_file[RustAnalyzerGroupInfo])
42
43    if RustAnalyzerInfo in ctx.attr.wasm_file:
44        providers.append(ctx.attr.wasm_file[RustAnalyzerInfo])
45
46    return providers
47
48nodejs_rust_wasm_bindgen = rule(
49    doc = """\
50Generates javascript and typescript bindings for a webassembly module using [wasm-bindgen][ws] that interface with [bazelbuild/rules_nodejs][bbnjs].
51
52[ws]: https://rustwasm.github.io/docs/wasm-bindgen/
53[bbnjs]: https://github.com/bazelbuild/rules_nodejs
54""",
55    implementation = _nodejs_rust_wasm_bindgen_impl,
56    attrs = WASM_BINDGEN_ATTR,
57    toolchains = [
58        str(Label("//:toolchain_type")),
59    ],
60)