From 51c335db845581a8e4739196c077e81edc6e8470 Mon Sep 17 00:00:00 2001 From: Hadrian Burkhardt Date: Sat, 24 Oct 2026 19:53:56 +0200 Subject: [PATCH] chore(m0): initialize cargo workspace, crate skeletons and ci gate --- Cargo.lock | 140 ++++++++++++++++++++++++++++++++++++++ Cargo.toml | 33 +++++++++ crates/content/Cargo.toml | 11 +++ crates/content/src/lib.rs | 9 +++ crates/ffi/Cargo.toml | 14 ++++ crates/ffi/src/lib.rs | 16 +++++ crates/server/Cargo.toml | 11 +++ crates/server/src/lib.rs | 14 ++++ crates/sim/Cargo.toml | 18 +++++ crates/sim/src/lib.rs | 19 ++++++ rust-toolchain.toml | 5 ++ tools/balance/Cargo.toml | 16 +++++ tools/balance/src/main.rs | 8 +++ tools/ci.sh | 21 ++++++ 14 files changed, 335 insertions(+) create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 crates/content/Cargo.toml create mode 100644 crates/content/src/lib.rs create mode 100644 crates/ffi/Cargo.toml create mode 100644 crates/ffi/src/lib.rs create mode 100644 crates/server/Cargo.toml create mode 100644 crates/server/src/lib.rs create mode 100644 crates/sim/Cargo.toml create mode 100644 crates/sim/src/lib.rs create mode 100644 rust-toolchain.toml create mode 100644 tools/balance/Cargo.toml create mode 100644 tools/balance/src/main.rs create mode 100755 tools/ci.sh diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..e95a74d --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,140 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "balance" +version = "0.1.0" +dependencies = [ + "content", + "serde_json", + "sim", +] + +[[package]] +name = "content" +version = "0.1.0" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "ffi" +version = "0.1.0" +dependencies = [ + "content", + "sim", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "server" +version = "0.1.0" +dependencies = [ + "content", + "sim", +] + +[[package]] +name = "sim" +version = "0.1.0" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "syn" +version = "3.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..8319e3c --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,33 @@ +[workspace] +resolver = "2" +members = [ + "crates/sim", + "crates/content", + "crates/ffi", + "crates/server", + "tools/balance", +] + +[workspace.package] +version = "0.1.0" +edition = "2021" +rust-version = "1.85" +authors = ["Hadrian Burkhardt "] +repository = "https://example.invalid/iron-arc" + +[workspace.dependencies] +serde = { version = "1", features = ["derive"] } +serde_json = "1" +sim = { path = "crates/sim" } +content = { path = "crates/content" } + +[profile.dev] +opt-level = 1 + +[profile.dev.package."*"] +opt-level = 2 + +[profile.release] +lto = "thin" +codegen-units = 1 +panic = "abort" diff --git a/crates/content/Cargo.toml b/crates/content/Cargo.toml new file mode 100644 index 0000000..4c5b9df --- /dev/null +++ b/crates/content/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "content" +version.workspace = true +edition.workspace = true +rust-version.workspace = true +authors.workspace = true +description = "Data-driven content models (tanks, weapons, maps) with validation" + +[dependencies] +serde.workspace = true +serde_json.workspace = true diff --git a/crates/content/src/lib.rs b/crates/content/src/lib.rs new file mode 100644 index 0000000..299b72c --- /dev/null +++ b/crates/content/src/lib.rs @@ -0,0 +1,9 @@ +//! Content models and validation for tanks, weapons and map presets. +//! +//! Content is versioned as a whole: `content_hash` pins a ruleset so that +//! replays stay verifiable (see docs/protocol.md). + +/// Placeholder until M2 fills in the models. +pub fn content_hash_placeholder() -> &'static str { + "b3:uninitialized" +} diff --git a/crates/ffi/Cargo.toml b/crates/ffi/Cargo.toml new file mode 100644 index 0000000..8bb2bd6 --- /dev/null +++ b/crates/ffi/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "ffi" +version.workspace = true +edition.workspace = true +rust-version.workspace = true +authors.workspace = true +description = "CDylib bridge between Flutter and the deterministic simulation" + +[lib] +crate-type = ["cdylib", "staticlib"] + +[dependencies] +sim.workspace = true +content.workspace = true diff --git a/crates/ffi/src/lib.rs b/crates/ffi/src/lib.rs new file mode 100644 index 0000000..621e8b2 --- /dev/null +++ b/crates/ffi/src/lib.rs @@ -0,0 +1,16 @@ +//! Flutter <-> Rust bridge (flutter_rust_bridge API lives here from M3 on). + +/// Smoke entry point so the Android build proves the CDylib pipeline works. +pub fn sim_version() -> String { + sim::SIM_VERSION.to_string() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn exposes_sim_version() { + assert_eq!(sim_version(), "0.1.0"); + } +} diff --git a/crates/server/Cargo.toml b/crates/server/Cargo.toml new file mode 100644 index 0000000..72816e4 --- /dev/null +++ b/crates/server/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "server" +version.workspace = true +edition.workspace = true +rust-version.workspace = true +authors.workspace = true +description = "Replay validation service (referee)" + +[dependencies] +sim.workspace = true +content.workspace = true diff --git a/crates/server/src/lib.rs b/crates/server/src/lib.rs new file mode 100644 index 0000000..8c68679 --- /dev/null +++ b/crates/server/src/lib.rs @@ -0,0 +1,14 @@ +//! Replay validation service. Filled in at M4 (axum, sqlx, HMAC tokens). + +/// Reports which simulation version this server validates against. +pub fn validated_sim_version() -> &'static str { + sim::SIM_VERSION +} + +#[cfg(test)] +mod tests { + #[test] + fn reports_sim_version() { + assert_eq!(super::validated_sim_version(), sim::SIM_VERSION); + } +} diff --git a/crates/sim/Cargo.toml b/crates/sim/Cargo.toml new file mode 100644 index 0000000..61f02c4 --- /dev/null +++ b/crates/sim/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "sim" +version.workspace = true +edition.workspace = true +rust-version.workspace = true +authors.workspace = true +description = "Deterministic artillery simulation core (fixed-point, no_std)" + +[lib] +crate-type = ["rlib"] + +[features] +default = [] +serde = ["dep:serde", "dep:serde_json"] + +[dependencies] +serde = { workspace = true, optional = true } +serde_json = { workspace = true, optional = true } diff --git a/crates/sim/src/lib.rs b/crates/sim/src/lib.rs new file mode 100644 index 0000000..204adcf --- /dev/null +++ b/crates/sim/src/lib.rs @@ -0,0 +1,19 @@ +//! Deterministic artillery simulation core. +//! +//! Rules (see docs/ADR/0002-determinismus-fixed-point.md): +//! - no floating point arithmetic +//! - no `HashMap`/`HashSet` iteration +//! - no `std::time`, no threads, no `unsafe` +//! - fixed 60 Hz tick +#![cfg_attr(not(test), no_std)] +#![forbid(unsafe_code)] +#![deny(clippy::float_arithmetic)] + +#[cfg(not(test))] +extern crate alloc; + +/// Version of the simulation. Bumped on any formula/balance change. +pub const SIM_VERSION: &str = "0.1.0"; + +/// Fixed simulation tick rate in Hz. +pub const TICK_HZ: u32 = 60; diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..2b2fc5c --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,5 @@ +[toolchain] +channel = "stable" +profile = "minimal" +components = ["rustfmt", "clippy"] +targets = ["aarch64-linux-android", "armv7-linux-androideabi", "x86_64-linux-android"] diff --git a/tools/balance/Cargo.toml b/tools/balance/Cargo.toml new file mode 100644 index 0000000..8020737 --- /dev/null +++ b/tools/balance/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "balance" +version.workspace = true +edition.workspace = true +rust-version.workspace = true +authors.workspace = true +description = "Headless mass simulation for balance tuning" + +[[bin]] +name = "balance" +path = "src/main.rs" + +[dependencies] +sim.workspace = true +content.workspace = true +serde_json.workspace = true diff --git a/tools/balance/src/main.rs b/tools/balance/src/main.rs new file mode 100644 index 0000000..8cbd6d8 --- /dev/null +++ b/tools/balance/src/main.rs @@ -0,0 +1,8 @@ +//! Headless balance CLI. Real implementation at M2. + +fn main() { + println!( + "balance: sim_version={} (not implemented yet, M2)", + sim::SIM_VERSION + ); +} diff --git a/tools/ci.sh b/tools/ci.sh new file mode 100755 index 0000000..0926353 --- /dev/null +++ b/tools/ci.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# Full local CI gate. Fails fast on the first broken rule. +set -euo pipefail +cd "$(dirname "$0")/.." + +echo '==> cargo fmt --check' +cargo fmt --all -- --check + +echo '==> clippy (deny warnings)' +cargo clippy --workspace --all-targets -- -D warnings + +echo '==> float guard in crates/sim/src' +if grep -rnE '(^|[^A-Za-z0-9_])f(32|64)([^A-Za-z0-9_]|$)' crates/sim/src --include='*.rs' | grep -v '^.*://' ; then + echo 'ERROR: floating point types in crates/sim (see ADR 0002)' >&2 + exit 1 +fi + +echo '==> cargo test' +cargo test --workspace + +echo '==> OK'