anvil-sys
Raw Rust bindings to the plugin API 2 of Anvil,
the native plugin loader for Europa Universalis IV 1.37.5 (include/anvil/anvil_plugin.h),
and to the services Anvil ships: anvil-game.game and anvil-game.world
(anvil_game.h), anvil-overlay.panel (anvil_panel.h), anvil-overlay.input (anvil_input.h) and anvil.benchmark
(anvil_benchmark.h). no_std, no dependencies.
Most plugins want the safe crate on top of it,
anvil-sdk (library anvil).
src/bindings.rsis generated bybindgenfrom the headers and committed. CI regenerates it and fails when it differs (sdk/rust/regen-bindings.ps1).- A service table is
#[repr(C)]withOption<unsafe extern "C" fn>fields; theANVIL_*_HASmacros are C, so comparesizewithoffset_of!before using a function appended after the service's first release. AnvilCpuContextis#[repr(C)], 408 bytes (checked at compile time).- C enums are plain integer constants (
AnvilResult,ANVIL_OK, …): a value from the host never becomes an invalid Rust enum. AnvilPluginLoadFnis the type ofanvil_plugin_load, the one function a plugin exports. The crate declares no extern functions.
A plugin on the raw API is a cdylib that exports anvil_plugin_load and
returns an AnvilResult. Catch panics at every function the game or Anvil
calls: unwinding into them aborts the process. anvil gen --lang rust writes
the typed symbols (symbols.gen.rs) from the plugin's symbols.toml.
The version of this crate is the version of Anvil whose headers it binds.
License: MIT.