fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
13746789
main
1"""Rust WASM-bindgen rules for interfacing with aspect-build/rules_js""" 2 3load ( "@aspect_rules_js//js:providers.bzl" , "js_info" ) 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 _js_rust_wasm_bindgen_impl ( ctx ): 10toolchain = ctx . toolchains [ Label ( "//:toolchain_type" )] 11 12info = rust_wasm_bindgen_action ( 13ctx = ctx , 14toolchain = toolchain , 15wasm_file = ctx . attr . wasm_file , 16target_output = ctx . attr . target , 17flags = ctx . attr . bindgen_flags , 18) 19 20providers = [ 21DefaultInfo ( 22files = depset ([ info . wasm ], transitive = [ info . js , info . ts ]), 23), 24info , 25# Return a structure that is compatible with the deps[] of a ts_library. 26js_info ( 27target = ctx . label , 28sources = info . js , 29transitive_sources = info . js , 30types = info . ts , 31transitive_types = info . ts , 32), 33] 34 35if RustAnalyzerGroupInfo in ctx . attr . wasm_file : 36providers . append ( ctx . attr . wasm_file [ RustAnalyzerGroupInfo ]) 37 38if RustAnalyzerInfo in ctx . attr . wasm_file : 39providers . append ( ctx . attr . wasm_file [ RustAnalyzerInfo ]) 40 41return providers 42 43js_rust_wasm_bindgen = rule ( 44doc = """\ 45Generates javascript and typescript bindings for a webassembly module using [wasm-bindgen][ws] that interface with [aspect-build/rules_js][abjs]. 46 47[ws]: https://rustwasm.github.io/docs/wasm-bindgen/ 48[abjs]: https://github.com/aspect-build/rules_js 49""" , 50implementation = _js_rust_wasm_bindgen_impl , 51attrs = WASM_BINDGEN_ATTR , 52toolchains = [ 53str ( Label ( "//:toolchain_type" )), 54], 55)