fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
13746789
main
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 ): 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 20# Return a structure that is compatible with the deps[] of a ts_library. 21declarations = info . ts 22es5_sources = info . js 23 24providers = [ 25DefaultInfo ( 26files = depset ([ info . wasm ], transitive = [ info . js , info . ts ]), 27), 28DeclarationInfo ( 29declarations = declarations , 30transitive_declarations = declarations , 31type_blocklisted_declarations = depset ([]), 32), 33JSModuleInfo ( 34direct_sources = es5_sources , 35sources = es5_sources , 36), 37info , 38] 39 40if RustAnalyzerGroupInfo in ctx . attr . wasm_file : 41providers . append ( ctx . attr . wasm_file [ RustAnalyzerGroupInfo ]) 42 43if RustAnalyzerInfo in ctx . attr . wasm_file : 44providers . append ( ctx . attr . wasm_file [ RustAnalyzerInfo ]) 45 46return providers 47 48nodejs_rust_wasm_bindgen = rule ( 49doc = """\ 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""" , 55implementation = _nodejs_rust_wasm_bindgen_impl , 56attrs = WASM_BINDGEN_ATTR , 57toolchains = [ 58str ( Label ( "//:toolchain_type" )), 59], 60)