Introduction
factorio-rs lets you write Factorio mods in Rust. A CLI tool reads your .rs
sources, lowers them through an intermediate representation, and emits a
standard Factorio mod (Lua + info.json + optional locale).
It does not compile Rust to native code or WASM for Factorio. The game still loads Lua. Think of factorio-rs as an authoring layer that transpiles to Factorio’s modding API.
Pieces
Section titled “Pieces”| Piece | Crate / binary | Role |
|---|---|---|
| SDK | factorio-rs |
Dependency for your mod crate (API stubs + macros) |
| CLI | package factorio-rs-cli, binary factorio-rs |
init, build, package, install, open |
Pipeline
Section titled “Pipeline”- Discover stage modules (
control,settings,data,shared, …). - Lower Rust (
syn) into IR. - Optionally prune unreachable code (release-style profiles).
- Generate Lua under
output_dir(defaultdist/), including stage entry files and locale.cfgfiles declared withlocale!.
Generated Lua headers look like:
-- Generated by factorio-rs@0.1.2-- Profile: debug-- Module: `control`What still uses Cargo
Section titled “What still uses Cargo”cargo check/cargo buildvalidate your Rust (macros, types).factorio-rs builddoes not invoke Cargo; it transpiles sources directly.
You typically iterate with both: check with Cargo, emit the mod with the CLI.
Language surface
Section titled “Language surface”Only a subset of Rust is transpiled. See
Language support for statements, expressions, Option /
Vec behaviour, and common unsupported constructs. Optional
Tracing macros lower to colored game.print. Generated API
stubs prefer concrete concepts and Identification enums
over LuaAny.