Procedural macros that turn safe, annotated Rust into the WeaveFFI C ABI.
A producer annotates an ordinary Rust module with #[weaveffi::module] and
tags the items it wants to export. The macro lowers the module to the
WeaveFFI IR (through [weaveffi_bridge]), builds the canonical
BindingModel, and emits the
#[no_mangle] extern "C" thunks every generated language binding calls.
All of the unsafe marshalling lives in the weaveffi-abi runtime, so the
producer writes only safe Rust.
#[weaveffi::module]
pub mod calculator {
/// Add two integers.
#[weaveffi::export]
pub fn add(a: i32, b: i32) -> i32 {
a + b
}
}
weaveffi::export_runtime!();
The same IR the macro lowers is what weaveffi generate path/to/lib.rs
reads, so the generated bindings and the producer cannot drift.
Attributes
- [
macro@module] marks an exported namespace (the driver attribute). - [
macro@export] exports a function; [macro@record] a by-value struct; [macro@enumeration] a#[repr(i32)]C-style enum. - [
macro@interface] declares an opaque object type whoseimplblock'spub fns become constructors, methods, and statics. - [
macro@error] declares the module's error domain from a unit-variant enum with explicit discriminants. - [
macro@callback] / [macro@listener] declare a callback and an event listener; [macro@cancellable] marks an async function as cancellable.
The item-level attributes are inert markers that [macro@module] reads; on
their own they expand to the item unchanged.