Skip to main content

Module env

Module env 

Source
Expand description

issue 0687 — the hosted edge of configuration: every env var nano-ros honours is read here, and the core takes values.

phase-359 W10 stage B — read through the C library’s getenv, so it needs a C library and not std: target_os = "linux" is “a C library is linked” on this tree. It exists on every Linux build, env or not, because the C / C++ entries of a #![no_std] image inside a host process (threadx-linux, freertos-posix — issue 1763) resolve their boot config through it. The env FEATURE is the user-facing half: from_env, init*, Context::new. The hosted edge of configuration: the process environment.

issue 0687 / phase-359 W10. Every env var nano-ros honours is read HERE and nowhere else. The core (nros-node) takes values — ExecutorConfig:: resolve_with accepts an EnvRung of already-resolved fields — so it needs no std, no env capability, and no stub on the five ports that have no environment to read.

That is the difference between this and the ABI ports W10 made for the clock, sleep, tasks and the log sink: those name capabilities every RTOS HAS. A process environment is not one. Modelling it as an ABI entry would have put return 0 in five ports and permanent surface in the header, for a facility that exists on one platform family.

One reader, through the C library (phase-359 W10 stage B). The environment is read with getenv, not std::env. A process environment is a property of the PROCESS, not of the Rust standard library: threadx-linux and freertos-posix are #![no_std] images that are still Linux processes with a C library, and issue 1763 measured what happens when they stop honouring $ROS_DOMAIN_ID (parallel cells shared a domain and heard each other). There used to be two readers — this one on std::env and host_env on getenv — with the same variables and rules; they are one now, and nros needs no std to be a hosted edge. The edge is “a C library is linked”, which on this tree is target_os = "linux"; a cross target has no getenv and this module does not exist there.

Strings are borrowed from the process environment, which outlives the boot, so the resolved config’s &'static str fields point straight into it. No cache is needed (the old std::env reader kept a OnceLock only to turn an owned String into a &'static str, and its staleness was issue 0607). Nothing in nano-ros calls setenv after boot.

What lives here:

  • ExecutorConfigEnvExt::from_env — the constructor that used to be an inherent method on ExecutorConfig. Bring the trait into scope (the prelude has it) and the call site spelling is unchanged. env feature.
  • resolve_hosted / try_resolve_hosted — RFC-0045 precedence model A with the environment rung on top. The C / C++ entries call these on every Linux build, env or not.
  • rmw_selector — the one $NROS_RMW reader (issue 0687’s first half).
  • var / read_file — the two C-library reads the hosted init* entries need ($RMW_IMPLEMENTATION, --params-file).
  • write_file, rename, set_var, exe_name, thread_key, exit — the rest of the hosted PROCESS edge, for the C / C++ surfaces (phase-359 W10 stage C). nros-c and nros-cpp write their census, metadata and profile files through these instead of std::fs / std::process, so the image root never links libstd: a census is a property of a process with a C library, not of the Rust standard library. One spelling of each C-library call, here, rather than one per crate.

Traits§

ExecutorConfigEnvExt
ExecutorConfig::from_env(), as an extension trait.

Functions§

exe_name
The file name of this process’s executable (/proc/self/exe’s last component) — what std::env::current_exe() + file_name() gave. None when the link cannot be read.
exit
End the process with code, running atexit handlers and flushing stdio — std::process::exit.
read_file
A whole file, through the C library — std::fs::read_to_string for a crate with no std. --params-file reads through it, and so do the C / C++ surfaces’ own params-file entries.
rename
Rename from to to, replacing to — std::fs::rename. Same filesystem only, which is how its callers use it (write-then-rename beside the target).
resolve_hosted
RFC-0045 precedence model A with the environment on top: env (var set) > baked > compiled default.
rmw_selector
The answer to “which RMW backend did the user select” — one reader, one semantic, for every consumer.
set_var⚠
Set $name to value for this process — std::env::set_var.
thread_key
A key unique to the calling thread among live threads — the address a thread_local! would give, without std. pthread_t on Linux is the thread’s descriptor address.
try_resolve_hosted
Fallible resolve_hosted — returns BootConfigError instead of panicking, so the C / C++ FFI shims can surface a return code.
var
$NAME as UTF-8, or None when unset or not UTF-8 (std::env::var’s two Err cases, which the old std reader also treated as unset).
write_file
Write bytes to path, creating or truncating it — std::fs::write for a crate with no std. The error is a short reason, as for read_file.