fork/rules_rust

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

UebelAndreMoved rust extension rules into a separate `rules_rust_ext` workspace. (#3007)2bad96d9

cleanup
1.4 KiB44 linesraw
1"""Rust WASM-bindgen rules for interfacing with aspect-build/rules_js"""
2
3load("@aspect_rules_js//js:providers.bzl", "js_info")
4load("//private:wasm_bindgen.bzl", "WASM_BINDGEN_ATTR", "rust_wasm_bindgen_action")
5
6def _js_rust_wasm_bindgen_impl(ctx):
7    toolchain = ctx.toolchains[Label("//:toolchain_type")]
8
9    info = rust_wasm_bindgen_action(
10        ctx = ctx,
11        toolchain = toolchain,
12        wasm_file = ctx.attr.wasm_file,
13        target_output = ctx.attr.target,
14        bindgen_flags = ctx.attr.bindgen_flags,
15    )
16
17    return [
18        DefaultInfo(
19            files = depset([info.wasm], transitive = [info.js, info.ts]),
20        ),
21        info,
22        # Return a structure that is compatible with the deps[] of a ts_library.
23        js_info(
24            target = ctx.label,
25            sources = info.js,
26            transitive_sources = info.js,
27            types = info.ts,
28            transitive_types = info.ts,
29        ),
30    ]
31
32js_rust_wasm_bindgen = rule(
33    doc = """\
34Generates javascript and typescript bindings for a webassembly module using [wasm-bindgen][ws] that interface with [aspect-build/rules_js][abjs].
35
36[ws]: https://rustwasm.github.io/docs/wasm-bindgen/
37[abjs]: https://github.com/aspect-build/rules_js
38""",
39    implementation = _js_rust_wasm_bindgen_impl,
40    attrs = WASM_BINDGEN_ATTR,
41    toolchains = [
42        str(Label("//:toolchain_type")),
43    ],
44)