Skip to main content

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