Skip to main content

Crate js2rust_bridge_macro

Crate js2rust_bridge_macro 

Source
Expand description

Proc-macro for generating Rust FFI bindings from js2rust C ABI export metadata.

§Usage

js2rust_bridge! {
    "js_src/main.js",    // core JS file path (relative to CARGO_MANIFEST_DIR)
    // Sync host functions (optional, comma-separated):
    host_add(i64, i64) -> i64,
    host_concat(str, str) -> str,
    // Async host functions (called with `await` from JS):
    async fetch_user(str) -> { id: i64, name: str },
}

The macro transpiles JS to Zig inline, writes output to .js2zig-cache/{group}/, and generates Rust FFI bindings. The group name is derived from the file name (sanitized for Zig identifiers). A minimal build.rs is only needed to link the compiled static library.

Macros§

js2rust_bridge
Function-like proc-macro: js2rust_bridge!("js_src/main.js", host_fns...).