feat(ffi): prove dart-to-rust pipeline and arm64 determinism on device

This commit is contained in:
2026-10-24 22:27:48 +02:00
parent 214ab7aac7
commit e371c72a35
11 changed files with 276 additions and 114 deletions
+52 -6
View File
@@ -1,8 +1,43 @@
//! Flutter <-> Rust bridge (flutter_rust_bridge API lives here from M3 on).
//! Flutter <-> Rust bridge.
//!
//! Until the flutter_rust_bridge integration (M3) this crate exposes plain
//! C ABI functions so the Android pipeline can be verified end to end.
/// Smoke entry point so the Android build proves the CDylib pipeline works.
pub fn sim_version() -> String {
sim::SIM_VERSION.to_string()
/// Magic marker to verify that the CDylib was loaded and symbols resolve.
pub const ABI_MARKER: u32 = 0x1A2B_3C4D;
/// Returns [`ABI_MARKER`].
#[no_mangle]
pub extern "C" fn iron_arc_abi_marker() -> u32 {
ABI_MARKER
}
/// Runs a fixed scripted match and returns its state hash.
///
/// The same seed must produce the same hash on every target (android arm64,
/// x86_64, wasm). This is the cross-target determinism probe from ADR 0002.
#[no_mangle]
pub extern "C" fn iron_arc_selftest(seed: u64) -> u64 {
let mut sim = sim::state::Sim::default_match(seed);
let _ = sim.submit(sim::state::Command::Fire {
angle_mdeg: 45_000,
power: sim::fixed::from_int(1),
weapon: 1,
});
for _ in 0..300 {
sim.tick();
}
sim.state_hash()
}
/// Returns the simulation version as a packed `major*10000 + minor*100 + patch`.
#[no_mangle]
pub extern "C" fn iron_arc_sim_version_code() -> u32 {
let mut parts = sim::SIM_VERSION.split('.').filter_map(|p| p.parse::<u32>().ok());
let major = parts.next().unwrap_or(0);
let minor = parts.next().unwrap_or(0);
let patch = parts.next().unwrap_or(0);
major * 10_000 + minor * 100 + patch
}
#[cfg(test)]
@@ -10,7 +45,18 @@ mod tests {
use super::*;
#[test]
fn exposes_sim_version() {
assert_eq!(sim_version(), "0.1.0");
fn marker_is_stable() {
assert_eq!(iron_arc_abi_marker(), ABI_MARKER);
}
#[test]
fn selftest_is_deterministic() {
assert_eq!(iron_arc_selftest(42), iron_arc_selftest(42));
assert_ne!(iron_arc_selftest(42), iron_arc_selftest(43));
}
#[test]
fn version_code_is_packed() {
assert_eq!(iron_arc_sim_version_code(), 100);
}
}
+27
View File
@@ -0,0 +1,27 @@
//! Prints the reference state hash for the cross-target determinism probe.
//! Usage: `cargo run -p sim --example selftest -- [seed]`
use std::env;
use sim::fixed::from_int;
use sim::state::{Command, Sim};
fn main() {
let seed: u64 = env::args()
.nth(1)
.and_then(|a| a.parse().ok())
.unwrap_or(42);
let mut sim = Sim::default_match(seed);
sim.submit(Command::Fire {
angle_mdeg: 45_000,
power: from_int(1),
weapon: 1,
})
.expect("scripted command must be valid");
for _ in 0..300 {
sim.tick();
}
println!("seed={seed} sim_version={} hash={}", sim::SIM_VERSION, sim.state_hash());
}