Replace individual Rust crate building with unified library approach through
makefile modifications for better build performance and dependency management.
* Updated Application.mk to include Rust.mk and add unified build targets
* Modified top-level Makefile to integrate RUST_BUILD_UNIFIED in build process
* Added RUST_CLEAN_UNIFIED call to Application.mk clean target
* Updated Makefile distclean target to remove rust_unified_lib directory
* Updated example Makefiles to use nuttx_add_rust registration function
* Removed manual EXTRA_LIBS configurations from Rust example Make.defs files
* Added .rdat registry files and rust_unified_lib to gitignore
* Enhanced tools/Rust.mk with unified build system functions
The unified system builds all registered Rust crates together through
makefile integration, improving compilation efficiency and enabling better
dependency management across the NuttX applications framework.
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Add hyphen-to-underscore conversion when creating module re-exports
in the generated src/lib.rs file. Rust module names must be valid
identifiers, so hyphens in crate names are converted to underscores
to prevent compilation errors.
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Add NUTTX_BUILD_DIR environment variable to the cargo build command
in the Rust unified library build process. This allows Rust code to
access the NuttX build directory path during compilation, enabling
better integration between Rust and NuttX build systems.
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Remove quotes around target-pointer-width values in i486 and x86_64
target configuration files to change from string to numeric type.
This change is required due to recent rustc JSON format modifications
that expect numeric values instead of strings for target-pointer-width.
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
1. Check if CUSTOM_MODULE_PATH exists and add it to CMAKE_MODULE_PATH
2. This allows for custom modules to be included in the build process
Signed-off-by: pengyinjie <pengyinjie@xiaomi.com>
Renaming "modlib" to "libelf" is more in line with the implementation content,
which makes it easier for individual developers to understand the capabilities of this module.
CONFIG_LIBC_MODLIB -> CONFIG_LIBC_ELF
Signed-off-by: chao an <anchao.archer@bytedance.com>
- Add unified Rust library generation tool (generate_rust_unified_lib.py)
- Refactor nuttx_add_rust.cmake to use unified library approach
- Support building multiple Rust crates as a single static library
- Add .config file generation support for unified library
- Update Rust examples to remove duplicate crate-type configuration
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Add support for 64-bit WebAssembly architecture by including
appropriate compiler and optimization flags when CONFIG_ARCH_64BIT
is enabled.
* Add --target=wasm64 compile option for 64-bit builds
* Enable memory64 feature in wasm-opt optimization
* Improve WebAssembly build system compatibility with 64-bit targets
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
- Update Wasm.mk to pass WOPTFLAGS to wasm-opt invocation in LINK_WASM
- Improve error message for wasm-opt failures
- Enables additional wasm-opt options (e.g., --enable-memory64) to be set via WOPTFLAGS for more flexible optimization and compatibility
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Add the asan-% pattern to CFLAGS_STRIP in WASI-SDK.defs to filter out AddressSanitizer-related flags that are not supported by wasm-clang.
* Prevents unsupported asan flags from being passed to the WASI toolchain
* Improves compatibility and avoids build errors when compiling for WebAssembly
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
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>
we exec install phase by default in kernel mod,
which does not apply to wasm bin.
make[3]: *** No rule to make target 'install'. Stop.
make[1]: *** [Makefile💯 .import] Error 2
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
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>
Refactor the WASMLD and LINK_WASM macros to improve readability and maintainability.
* Added detailed comments explaining the functionality of each macro
* Streamlined the linking process for WebAssembly modules
* Improved error handling during the build process
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Refactor the WAMR_AOT_COMPILE macro to improve readability and
clarity in its parameters and functionality.
* Added detailed comments explaining parameters and behavior
* Simplified the logic for AOT and XIP compilation
* Improved maintainability of the build process
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Changed the separator in the destination path from '#' to '%'
to improve compatibility with file naming conventions, '#' in file name may lead to file name parse error in Makefile.
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
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>
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>
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>
- Update Wasm.mk to pass WOPTFLAGS to wasm-opt invocation in LINK_WASM
- Improve error message for wasm-opt failures
- Enables additional wasm-opt options (e.g., --enable-memory64) to be set via WOPTFLAGS for more flexible optimization and compatibility
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Support building WASM applications for 64-bit platforms (X64 and ARM64) by setting the target to wasm64.
* WASM_BUILD is no longer forcibly disabled for 64-bit architectures
* WCFLAGS now includes --target=wasm64 for Intel64 and ARM64
* Allows proper WebAssembly builds on supported 64-bit platforms
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Summary:
- Updated the `CFLAGS_STRIP` variable to include flags related to code coverage (`-fprofile%`, `-f%coverage%`) in the list of flags to be filtered out when constructing `WCFLAGS`
- This ensures that unsupported flags are not passed to the wasm-clang compiler, which previously caused build errors
Impact:
- No functional changes to the codebase
- Enhances the build process for WebAssembly targets by preventing the inclusion of unsupported compiler flags, thus avoiding build failures and improving compatibility
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
System is unknown to cmake, create:
Platform/WASI to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
Your CMakeCache.txt file was copied to CopyOfCMakeCache.txt. Please post that file on discourse.cmake.org.
CMake Error at CMakeLists.txt:100 (add_subdirectory):
add_subdirectory given source
"/home/data/vela/tmp/apps/frameworks/security/ta/alipay
/home/data/vela/tmp/apps/frameworks/security/ta/comsst
/home/data/vela/tmp/apps/frameworks/security/ta/hello_world
/home/data/vela/tmp/apps/frameworks/security/ta/pin
/home/data/vela/tmp/apps/frameworks/security/ta/triad
/home/data/vela/tmp/apps/frameworks/security/ta/wxcodepay" which is not an
existing directory.
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
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>
Summary:
Added a limit to CJSON_NESTING_LIMIT. The default value is 1000, which can cause stack overflow in some test cases.
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>