Cotton code
95 lines · 3.9 KB · RustRaw
//! The boundary the phone links against.//!//! Step 3 of the Rust core (M1–M2). A `staticlib` with a C ABI of SIX//! functions — open, close, call, subscribe, version, free — and everything//! else a method name inside `cotton_call`. The header `include/cotton_ffi.h`//! is generated from `ffi.rs` and committed; `cargo test -p cotton-ffi` fails//! when they drift.//!//! Why this shape rather than UniFFI or swift-bridge: a surface this small does//! not need a second code generator in the build graph, and a `staticlib` is one//! binary with no dylib to sign separately and no dynamic loader.//! **ONE BUILD.** The client half alone — `read.*`, `write`, `capture.*`,//! `bootstrap.*`, `join.*` and the rest, over the phone's copy. A method this//! core does not know answers `unknown_method` by construction.//! `tests/phone_boundary.rs` reads the resolved graph and keeps it free of//! every server dependency./// How a device of the person's own writes — the same tool handlers an/// assistant calls. Shared: the Mac and the phone are the same kind of caller/// (design P3), and since H3 they are the same SCREENS.pub mod authoring;pub mod events;pub mod ffi;/// One synthetic life on disk, shared by every suite in this crate on BOTH/// builds. Nothing real, ever ([nothing-real-ever-goes-in-cotton-s-public-tree]).#[cfg(test)]pub mod fixture;pub mod handle;pub mod methods;/// The client's own families: the route table, the per-screen reads, the one/// `write`, the join and the bootstrap. Named `phone` because the phone is the/// caller that needed every one of them first; a serving Mac answers the same/// names over the file it holds open (see the module note).pub mod phone;pub mod shell;pub use events::{EventBus, EventKind};pub use ffi::{    cotton_call, cotton_close, cotton_open, cotton_string_free, cotton_subscribe, cotton_version,};pub use handle::{    CottonHandle, IdentityRead, OpenConfig, OpenError, OpenMode, ServerPhase, ServerStatus,};pub use methods::{dispatch, methods, MethodError, ALL_METHODS, CLIENT_METHODS};/// What this core was built from, as `build.rs` stamped it.#[derive(Debug, Clone, Copy, PartialEq, Eq)]pub struct BuildCommit {    /// The full sha of HEAD at the build; empty outside a git checkout.    pub commit: &'static str,    /// Whether crates/ held edits HEAD does not.    pub dirty: bool,    /// crates/' content as a git tree hash (`scripts/lib/crates-tree.sh`):    /// what `scripts/core-fresh.sh` compares with a checkout's.    pub crates_tree: &'static str,}impl BuildCommit {    /// Nine characters of the commit, `.dirty` after them when crates/ held    /// edits: semver build metadata, as `cotton_version` carries it.    pub fn short(&self) -> Option<String> {        let short = self.commit.get(..9)?;        Some(if self.dirty { format!("{short}.dirty") } else { short.to_string() })    }}/// The stamp this core carries.pub fn build_commit() -> BuildCommit {    BuildCommit {        commit: env!("COTTON_BUILD_COMMIT"),        dirty: env!("COTTON_BUILD_DIRTY") == "1",        crates_tree: env!("COTTON_BUILD_CRATES_TREE"),    }}/// The stamp as one string in the archive itself, which `scripts/core-fresh.sh`/// reads out of an xcframework without running it. Its shape is that script's/// pattern; change both together.#[used]static BUILD_STAMP: &str = concat!(    "cotton-core-build:",    env!("COTTON_BUILD_COMMIT"),    ":",    env!("COTTON_BUILD_DIRTY"),    ":",    env!("COTTON_BUILD_CRATES_TREE"),);/// The kit whose pictures this core carries (`cotton_core::kit::CORE_KIT`;/// between the colon and the semicolon, empty for the whole core), in the/// archive for `scripts/core-fresh.sh` as the stamp above is: a core built/// for one app is no core for a walk of another.#[used]static KIT_STAMP: &str = concat!("cotton-core-kit:", env!("COTTON_BUILD_CORE_KIT"), ";");