Skip to main content

Module backend

Module backend 

Source
Expand description

The language-backend framework.

Every idiomatic WeaveFFI generator does the same three things: it walks the BindingModel in a fixed order (enums → structs → callbacks → listeners → functions), dispatches each function on its CallShape, and writes a primary source file plus a handful of package manifests. Before this module existed, all eleven generators hand-rolled that walk, that dispatch, that file I/O, and their own copy of the Generator glue; they drifted.

LanguageBackend captures the common structure as a trait whose hooks a backend implements, and the free run/output_files functions plus the impl_generator_via_backend! macro provide the shared driver. A backend now owns only language-specific rendering: type mapping, marshalling, and the exact text of each declaration. The traversal order, the call-shape dispatch, the model construction, and the bridge to the object-safe Generator/DynGenerator layer all live here, once.

Structs§

OutputFile
A single generated file: its full path (under the output directory) and the rendered contents. Backends return these from LanguageBackend::files; the driver creates parent directories and writes them.

Traits§

LanguageBackend
An idiomatic language backend over the shared BindingModel.

Functions§

output_files
The sorted list of paths a backend would write, the body of the Generator::output_files impl that impl_generator_via_backend! generates. Used by --dry-run and weaveffi diff. Paths are normalised to / separators so the listing is identical across operating systems.
package_files
Build the model and assemble the package a backend produces, the body of the Generator::package impl that impl_generator_via_backend! generates. Returns None when the backend does not support packaging.
run
Build the model and write every file a backend produces.