Skip to main content

Crate js2rust_bridge_macro

Crate js2rust_bridge_macro 

Source
Expand description

js2rust-bridge-macro — compile-time bridge macros for js2rust.

Stages:

  • P-A2 — bridge!: project-level wiring macro. Reads js2rust.toml (the [output] section) plus the codegen manifest.json, validates the contract, and expands into the gen module tree (include! of the offline codegen output) with an include_bytes! dependency-tracking sentinel so rustc rebuilds when codegen reruns.
  • P-A3 (this revision) — func / route: single-file translation attribute macros. Translate one JS source inside macro expansion (same Rust → Rhai tiers as the offline pipeline, no codegen products needed), replace the annotated fn with the translated handler, and emit sentinels tracking the JS source, the config, and the GraphQL schema. The JS fallback tier is not supported in single-file mode — use the project-level bridge! instead.

Dependency direction (Cargo requires a DAG):

js2rust-bridge-macro ──▶ js2rust   (macro expansion uses the translator)
       ▲                       ▲
       └──── user crate ───────┘

This crate may depend on js2rust; js2rust must never depend on this crate. Generated code references runtime types via ::js2rust::....

§bridge! usage

ⓘ
js2rust_bridge_macro::bridge! { config: "js2rust.toml" };
// or simply: js2rust_bridge_macro::bridge! {};
//            (defaults to config = "js2rust.toml")

The config path is resolved against CARGO_MANIFEST_DIR of the crate invoking the macro. The expanded code is:

ⓘ
pub mod gen { include!(concat!(env!("CARGO_MANIFEST_DIR"), "/<output>/gen.rs")); }
const _: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/<output>/manifest.json"));

The sentinel makes rustc track manifest.json: rerunning the offline codegen (which rewrites the manifest) automatically triggers recompile, closing the classic proc-macro “external file not tracked” gap.

Macros§

bridge
Expand bridge! { config: "<path>"? }.

Attribute Macros§

func
Attribute macro: translate ONE JS source at compile time and replace the annotated fn with the translated handler (P-A3).
route
Route flavor of func (entry route(code[, extra]), returns Route).