Expand description
js2rust-bridge-macro — compile-time bridge macros for js2rust.
Stages:
- P-A2 —
bridge!: project-level wiring macro. Readsjs2rust.toml(the[output]section) plus the codegenmanifest.json, validates the contract, and expands into thegenmodule tree (include!of the offline codegen output) with aninclude_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-levelbridge!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>"? }.