Commit graph

16 commits

Author SHA1 Message Date
Shoji Tokunaga
d1202bd501 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>
2026-06-20 10:33:46 -03:00
Shoji Tokunaga
33d96e92e5 apps/tools: Enable Rust sim builds on Intel Macs
Select the Mach-O Rust target (x86_64-unknown-nuttx-macho.json) when
building Rust apps for the simulator on x86_64 macOS.

Signed-off-by: Shoji Tokunaga <toku@mac.com>
2026-06-09 07:08:41 +08:00
Shoji Tokunaga
9796690b7b apps/cmake: Fix aarch64 NuttX Rust target specs
Add aarch64 Rust target specs for NuttX, including a Mach-O variant
for macOS sim builds. Use the NuttX custom targets instead of
aarch64-apple-darwin so Rust std is built with target_os=nuttx while
still producing link-compatible objects for sim.

Signed-off-by: Shoji Tokunaga <toku@mac.com>
2026-06-02 13:06:58 +02:00
Shoji Tokunaga
e536adaabc apps/cmake: Add DEPENDS for Rust-related files.
* Add `DEPENDS` to ensure staticlib rebuilds when Rust-related files change.
* Uses `GLOB_RECURSE` to search for Rust-related files.

Signed-off-by: Shoji Tokunaga <toku@mac.com>
2026-05-19 11:22:47 +08:00
Shoji Tokunaga
bb7c83b01c apps:cmake: Add APPLE to a build target for sim's configuration using CMake.
* Add Rust target conversion support for `aarch64` on acOS/Linux (and Linux `arm`).
* When a Rust target is unsupported and results in an empty configuration, trigger a CMake `FATAL_ERROR`.

Signed-off-by: Shoji Tokunaga <toku@mac.com>
2026-05-18 12:22:48 +08:00
Shoji Tokunaga
c10ce6aa4f apps/cmake: Make hello_rust_cargo buildable with cmake
* Resolve APPDIR.
* Remove "debug" from RUST_PROFILE_FLAG.
* Add JSON specification compatibility flag.
* Correct the directory structure for RUST_LIB_PATH.

Signed-off-by: Shoji Tokunaga <toku@mac.com>
2026-05-14 07:16:15 -04:00
Huang Qi
f90e1e184f tools/build: Make Rust target triples for x86 use JSON files
X86 support for Rust needs more test and verification, and not
upstreamed to Rust side yet.

It's better to use custom target triples for x86 by json files for now,
and it can be upstreamed to Rust side if stable enough.

Changed the Rust target triples in the CMake configuration to reference JSON files for x86_64 and i486 architectures. This improves the build process by providing more detailed target specifications.
* Added JSON files for i486 and x86_64 targets
* Updated CMake functions to use the new target triples
* Enhanced build directory structure for Rust crates

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2026-03-13 12:37:55 +01:00
Huang Qi
b5d151f73f cmake/tools: Fix panic_immediate_abort deprecation in Rust build
Replace deprecated -Zbuild-std-features=panic_immediate_abort with
-Cpanic=immediate-abort compiler flag via RUSTFLAGS.

The panic_immediate_abort feature has been stabilized as a real panic
strategy in recent Rust nightly versions. The old method of enabling
it via -Zbuild-std-features is no longer supported and triggers a
compile error in core/src/panicking.rs.

Changes:
* cmake/nuttx_add_rust.cmake: Use RUSTFLAGS with -Cpanic=immediate-abort
* tools/Rust.mk: Use RUSTFLAGS with -Cpanic=immediate-abort

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2026-03-10 18:23:22 -03:00
Huang Qi
99d2de6540 tools: Export NUTTX_INCLUDE_DIR for Rust builds
Set NUTTX_INCLUDE_DIR in the Rust build commands to include the necessary directories for proper compilation.
* Ensured correct include paths for Rust projects
* Improved build reliability for Rust components

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2025-03-24 20:34:29 +08:00
Huang Qi
285607608e tools/Rust: Add support for x86 platform
Summary:
- Added support for x86 and x86_64 architectures in the Rust build system
- Updated `nuttx_rust_target_triple` function in `cmake/nuttx_add_rust.cmake` to handle x86 and x86_64 target triples
- Updated `RUST_TARGET_TRIPLE` macro in `tools/Rust.mk` to include x86 and x86_64 target triples

Impact:
- Enables Rust crate compilation for x86 and x86_64 platforms
- No functional changes for existing architectures (ARM, RISC-V, etc.)
- Improves platform compatibility and expands Rust support in NuttX

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2025-01-29 13:41:30 +08:00
xuxin19
fb367c9792 cmake(enhance):Enhanced full WASM library and application compilation
1.add complete compilation FLAGS for wasm toolchain
2.wasm build no longer traverses the native directory, saving build time
3.implement OPT and AOT process actions for wasm files
4.create a bridge interface for navtie build and wasm build

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2025-01-23 14:26:08 +08:00
Huang Qi
efcfd87b44 tools/Rust: Add support for panic_immediate_abort
Summary:
- Added support for `panic_immediate_abort` in Rust builds, which causes the system to abort immediately on panic instead of unwinding the stack
- Enabled `-Zbuild-std-features=panic_immediate_abort` flag for release builds when `CONFIG_DEBUG_FULLOPT` is set
- Updated both CMake and Makefile build systems to include the new flag

Impact:
- Significantly reduces binary size (e.g., from 2270605 to 84987 bytes for riscv64imc)
- Changes panic behavior to immediate abort, which may be preferred for embedded systems
- Improves system reliability by preventing undefined behavior from stack unwinding in constrained environments
- Maintains compatibility with existing Rust code while providing a more deterministic panic handling mechanism

For example, if it is enabled, the system will panic immediately:
```
NuttShell (NSH) NuttX-12.8.0
nsh> hello_rust_cargo
{"name":"John","age":30}
{"name":"Jane","age":25}
Deserialized: Alice is 28 years old
Pretty JSON:
{
  "name": "Alice",
  "age": 28
}
riscv_exception: EXCEPTION: Illegal instruction. MCAUSE: 0000000000000002, EPC: 0000000080027df6, MTVAL: 0000000000000000
riscv_exception: PANIC!!! Exception = 0000000000000002
dump_assert_info: Current Version: NuttX  12.8.0 8e3621e059 Jan 20 2025 14:45:00 risc-v
dump_assert_info: Assertion failed panic: at file: :0 task: hello_rust_cargo process: hello_rust_cargo 0x80020588
/* Stack dump from NuttX */
```
vs the default behavior:
```
NuttShell (NSH) NuttX-12.8.0
nsh> hello_rust_cargo
{"name":"John","age":30}
{"name":"Jane","age":25}
Deserialized: Alice is 28 years old
Pretty JSON:
{
  "name": "Alice",
  "age": 28
}

thread '<unnamed>' panicked at /home/huang/Work/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/src/rust/library/std/src/sys/random/unix_legacy.rs:19:10:
failed to generate random data: Os { code: 2, kind: NotFound, message: "No such file or directory" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
nsh>
```

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2025-01-20 19:48:25 +08:00
Huang Qi
f7e7453807 examples: New app to build Rust with Cargo
Build Rust applictions with cargo is the most commn way,
and it's more easy to cooporate with Rust ecosystem.

This example shows how to use cargo to build a simple hello world
application.

And please notice that you need to install nighly version of rustc
to support this feature, any version after https://github.com/rust-lang/rust/pull/127755
is merged, can use NuttX as cargo target directly.

Build
-----

To build hello_rust_cargo application, you can use any target that based
on RISCV32IMAC, for example:
```
cmake -B build -DBOARD_CONFIG=rv-virt:nsh -GNinja .
```

And disable ARCH_FPU in menuconfig, since the hard coded target triple
in this demo is `riscv32imac`.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2025-01-10 22:25:13 +08:00
Alin Jerpelea
7fe01f1c52 cmake: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-12-19 15:25:28 +08:00
Huang Qi
9320597c00 wamr: Add external module registration mechanism
This patch adds module registration mechanism for WAMR runtime.

To register a module, these steps are required:
1. Include Module.mk in your module's Makefile
2. Define WAMR_MODULE_NAME as the module name
3. Implement bool wamr_module_WAMR_MODULE_NAME_register(void) function in your module's source file
4. Enable INTERPRETERS_WAMR_EXTERNAL_MODULE_REGISTRY in menuconfig

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-09-28 15:47:40 +08:00
xuxin19
3d8dc5dce5 cmake:implement CMake build for NuttX Lua interpreter
add CMake module for register lua mod
nsh> lua
Lua 5.4.0  Copyright (C) 1994-2020 Lua.org, PUC-Rio
> hello.say_hello()
Hello World!
> io.write("abs is =",math.abs(-10),"\n")
abs is =10
> os.exit()
nsh>

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-09-13 12:31:10 +08:00