Share an API between mods
This is a short recipe. Full reference: Sharing code between mods.
Provider: export
Section titled “Provider: export”In the provider mod (control or shared stage):
#[factorio_rs::export]pub fn greet(name: &str) -> String { format!("hello, {name}")}Build the provider. Exports are written to .factorio-rs/exports.json and
published for consumers (not the deprecated emit_api / api_dir keys).
Consumer: depend and call
Section titled “Consumer: depend and call”cd consumer-modfactorio-rs add ../provider # or a crates.io / git dep with Factorio metadataThen:
use provider::greet;
#[factorio_rs::event(OnSingleplayerInit)]pub fn on_singleplayer_init() { println!("{}", greet("world"));}Control-stage exports go through Factorio remote; shared-stage exports become
requires. The CLI generates a binding crate under .factorio-rs/bindings/ for
typed use paths.
Checklist
Section titled “Checklist”- Provider has
[package.metadata.factorio](see the dependencies page). - Consumer lists the Factorio mod dependency (often via
factorio-rs add). - Both mods are present in the Factorio mods folder when you run the game.
Working tree: provider / consumer example.