nros_platform/resolve.rs
1//! Concrete platform type alias resolved at compile time.
2//!
3//! When a platform feature is enabled, [`ConcretePlatform`] resolves to
4//! the active backend. When no platform is selected (e.g., default workspace
5//! build), the type is not defined — downstream crates that need it must
6//! enable a platform feature.
7
8// Phase 121.7.b / 121.8.e — uniform CffiPlatform routing for every
9// platform that impls the full canonical surface (clock + alloc +
10// sleep + yield + random + time + threading + net). POSIX, the four
11// RTOS kernels, the four bare-metal embedded crates, and platform-cffi
12// itself all route through CffiPlatform. Bare-metal net surface is
13// backed by `nros_smoltcp::define_smoltcp_platform!` (PlatformTcp /
14// Udp / SocketHelpers / UdpMulticast) emitted by each platform crate.
15#[cfg(feature = "platform-posix")]
16pub type ConcretePlatform = nros_platform_cffi::CffiPlatform;
17
18#[cfg(feature = "platform-cffi")]
19pub type ConcretePlatform = nros_platform_cffi::CffiPlatform;
20
21#[cfg(feature = "platform-mps2-an385")]
22pub type ConcretePlatform = nros_platform_cffi::CffiPlatform;
23
24#[cfg(feature = "platform-stm32f4")]
25pub type ConcretePlatform = nros_platform_cffi::CffiPlatform;
26
27#[cfg(feature = "platform-esp32-qemu")]
28pub type ConcretePlatform = nros_platform_cffi::CffiPlatform;
29
30// Phase 121.3.deprecate-rust-migrate: the four deprecated RTOS
31// platforms resolve to `CffiPlatform` and reach their kernel impl
32// through the deprecated Rust crate's `cffi-export` macro emission
33// (enabled transitively by the `platform-<rtos>` feature). Same
34// runtime behaviour as before — every Rust trait call now hops one
35// extra `extern "C"` indirection. The deprecated Rust crates stay
36// for that transitive emission until consumers move to a C-side
37// symbol provider (`nros-platform-<rtos>-c`) and we drop the Rust
38// kernel crates entirely.
39#[cfg(feature = "platform-nuttx")]
40pub type ConcretePlatform = nros_platform_cffi::CffiPlatform;
41
42#[cfg(feature = "platform-freertos")]
43pub type ConcretePlatform = nros_platform_cffi::CffiPlatform;
44
45#[cfg(feature = "platform-threadx")]
46pub type ConcretePlatform = nros_platform_cffi::CffiPlatform;
47
48#[cfg(feature = "platform-zephyr")]
49pub type ConcretePlatform = nros_platform_cffi::CffiPlatform;
50
51// ============================================================================
52// Phase 71.22 — opaque-buffer sizes for `_z_sys_net_socket_t` /
53// `_z_sys_net_endpoint_t`, resolved per platform.
54//
55// Each `nros-platform-*` crate computes these from `core::mem::size_of`
56// over its private `Socket` / `Endpoint` struct (which mirrors zenoh-pico's
57// platform header). Re-exporting them here lets callers like
58// RMW transport adapters size their opaque buffers exactly via
59// `nros_platform::NET_SOCKET_SIZE`, instead of paying for a `[u8; 64]`
60// worst-case.
61//
62// Bare-metal platforms (`platform-mps2-an385`, `platform-stm32f4`,
63// `platform-esp32`, `platform-esp32-qemu`, `platform-cffi`) don't yet
64// have a typed socket struct exposed; callers there get a 64-byte
65// fallback. Once the smoltcp platform crates publish their own
66// `Socket` / `Endpoint` (Phase 71.26), they can plug in alongside the
67// RTOS variants below.
68
69// POSIX still publishes typed socket sizes (the only host-runnable
70// platform crate left + the only one whose Socket / Endpoint layout
71// varies meaningfully). Every other platform uses the 64-byte fallback
72// — bare-metal smoltcp is 2 / 6 bytes; the RTOS C ports own the layout
73// behind their `_z_sys_net_*` typedefs and can publish a tighter size
74// later if the headroom matters.
75// Phase 104.A.3 — POSIX net-size constants formerly re-exported from
76// `nros_platform_posix::net::*`. Inlined here so `nros-platform`
77// stops Rust-importing the concrete POSIX platform crate. The values
78// mirror `nros-platform-posix/src/net.rs`:
79// * `Socket` = `{ int fd }` → `size_of::<c_int>() == 4` on every
80// POSIX ABI we target.
81// * `Endpoint` = `{ struct addrinfo* iptcp }` → native pointer
82// size (8 on 64-bit, 4 on 32-bit).
83//
84// Both expressible via `core::ffi` without pulling libc / the
85// concrete platform crate. Phase 123's `nros-platform-posix`
86// Rust-crate deletion adopts the same inline shape on the
87// release-prep branch.
88// Phase 129.C.3.b — exported unconditionally. Previously gated
89// on a specific `platform-<rtos>` feature, which forced every
90// RMW crate that imported them to
91// forward a `nros-platform/platform-*` feature so the constants
92// would resolve. Worst-case 64-byte / 8-aligned storage covers
93// every supported platform — POSIX's `{ int fd }` socket and
94// pointer endpoint, bare-metal smoltcp / lwIP / NetX handles
95// alike. Consumers that want a tighter packing can opt into a
96// per-platform `nros_platform_*` storage type at the link
97// layer once that ABI lands.
98pub const NET_SOCKET_SIZE: usize = 64;
99pub const NET_SOCKET_ALIGN: usize = 8;
100pub const NET_ENDPOINT_SIZE: usize = 64;
101pub const NET_ENDPOINT_ALIGN: usize = 8;