examples/rust: Avoid the infinite loop on sim for hello_rust_cargo

On the sim target (Windows/macOS/Linux), hello_rust_cargo_main() ended
with an infinite `loop {}` that never returned control to NSH, so the
example could not exit and the shell prompt hung.

Introduce a Cargo `sim` feature that is enabled only when CONFIG_ARCH_SIM
is set, and use it to compile out the trailing infinite loop and return 0
instead. Other embedded targets keep the original looping behavior.

Signed-off-by: Shoji Tokunaga <toku@mac.com>
This commit is contained in:
Shoji Tokunaga 2026-06-15 17:28:54 +09:00 committed by Alan C. Assis
parent ee4727fdba
commit d1202bd501
6 changed files with 35 additions and 7 deletions

View file

@ -90,11 +90,12 @@ endef
# Build Rust project using cargo
#
# Usage: $(call RUST_CARGO_BUILD,cratename,prefix)
# Usage: $(call RUST_CARGO_BUILD,cratename,prefix[,features])
#
# Inputs:
# cratename - Name of the Rust crate (e.g. hello)
# prefix - Path prefix to the crate (e.g. path/to/project)
# features - Optional Cargo features to enable
#
# Output:
# None, builds the Rust project
@ -105,7 +106,8 @@ define RUST_CARGO_BUILD
RUSTFLAGS="-Zunstable-options -Cpanic=immediate-abort" \
cargo build --release -Zbuild-std=std,panic_abort -Zjson-target-spec \
--manifest-path $(2)/$(1)/Cargo.toml \
--target $(call RUST_TARGET_TRIPLE)
--target $(call RUST_TARGET_TRIPLE) \
$(if $(strip $(3)),--features $(3),)
endef
else
define RUST_CARGO_BUILD
@ -113,7 +115,8 @@ define RUST_CARGO_BUILD
NUTTX_INCLUDE_DIR=$(TOPDIR)/include:$(TOPDIR)/include/arch \
cargo build -Zbuild-std=std,panic_abort -Zjson-target-spec \
--manifest-path $(2)/$(1)/Cargo.toml \
--target $(call RUST_TARGET_TRIPLE)
--target $(call RUST_TARGET_TRIPLE) \
$(if $(strip $(3)),--features $(3),)
endef
endif