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// issue 1315 / phase-451 W4 — ONE arm, because all nine define the SAME type.
16//
17// These were nine separate `#[cfg(feature = "platform-<x>")]` blocks, each
18// `pub type ConcretePlatform = nros_platform_cffi::CffiPlatform;` — identical
19// right-hand sides, mutually exclusive only by CONVENTION. Turning on two
20// platform features at once is then E0428, "defined multiple times", and
21// nothing in the tree did that until three crates became workspace members:
22// `cargo check --workspace` UNIFIES features across every member, so one
23// member wanting `platform-freertos` beside another wanting `platform-posix`
24// broke a crate neither of them names.
25//
26// `any(...)` is not a widening: nine arms that produce one type ARE one arm,
27// and writing them separately only bought a collision. A future platform whose
28// ConcretePlatform is NOT `CffiPlatform` gets its own `cfg` with a
29// `not(...)` on this one — which is the point at which the exclusivity becomes
30// real and should be stated, rather than assumed nine times.
31#[cfg(any(
32 feature = "platform-posix",
33 feature = "platform-cffi",
34 feature = "platform-mps2-an385",
35 feature = "platform-stm32f4",
36 feature = "platform-esp32-qemu",
37 feature = "platform-nuttx",
38 feature = "platform-freertos",
39 feature = "platform-threadx",
40 feature = "platform-zephyr",
41))]
42pub type ConcretePlatform = nros_platform_cffi::CffiPlatform;
43
44// ============================================================================
45// Phase 71.22 — opaque-buffer sizes for `_z_sys_net_socket_t` /
46// `_z_sys_net_endpoint_t`, resolved per platform.
47//
48// Each `nros-platform-*` crate computes these from `core::mem::size_of`
49// over its private `Socket` / `Endpoint` struct (which mirrors zenoh-pico's
50// platform header). Re-exporting them here lets callers like
51// RMW transport adapters size their opaque buffers exactly via
52// `nros_platform::NET_SOCKET_SIZE`, instead of paying for a `[u8; 64]`
53// worst-case.
54//
55// Bare-metal platforms (`platform-mps2-an385`, `platform-stm32f4`,
56// `platform-esp32`, `platform-esp32-qemu`, `platform-cffi`) don't yet
57// have a typed socket struct exposed; callers there get a 64-byte
58// fallback. Once the smoltcp platform crates publish their own
59// `Socket` / `Endpoint` (Phase 71.26), they can plug in alongside the
60// RTOS variants below.
61
62// POSIX still publishes typed socket sizes (the only host-runnable
63// platform crate left + the only one whose Socket / Endpoint layout
64// varies meaningfully). Every other platform uses the 64-byte fallback
65// — bare-metal smoltcp is 2 / 6 bytes; the RTOS C ports own the layout
66// behind their `_z_sys_net_*` typedefs and can publish a tighter size
67// later if the headroom matters.
68// Phase 104.A.3 — POSIX net-size constants formerly re-exported from
69// `nros_platform_posix::net::*`. Inlined here so `nros-platform`
70// stops Rust-importing the concrete POSIX platform crate. The values
71// mirror `nros-platform-posix/src/net.rs`:
72// * `Socket` = `{ int fd }` → `size_of::<c_int>() == 4` on every
73// POSIX ABI we target.
74// * `Endpoint` = `{ struct addrinfo* iptcp }` → native pointer
75// size (8 on 64-bit, 4 on 32-bit).
76//
77// Both expressible via `core::ffi` without pulling libc / the
78// concrete platform crate. Phase 123's `nros-platform-posix`
79// Rust-crate deletion adopts the same inline shape on the
80// release-prep branch.
81// Phase 129.C.3.b — exported unconditionally. Previously gated
82// on a specific `platform-<rtos>` feature, which forced every
83// RMW crate that imported them to
84// forward a `nros-platform/platform-*` feature so the constants
85// would resolve. Worst-case 64-byte / 8-aligned storage covers
86// every supported platform — POSIX's `{ int fd }` socket and
87// pointer endpoint, bare-metal smoltcp / lwIP / NetX handles
88// alike. Consumers that want a tighter packing can opt into a
89// per-platform `nros_platform_*` storage type at the link
90// layer once that ABI lands.
91pub const NET_SOCKET_SIZE: usize = 64;
92pub const NET_SOCKET_ALIGN: usize = 8;
93pub const NET_ENDPOINT_SIZE: usize = 64;
94pub const NET_ENDPOINT_ALIGN: usize = 8;