Description / Steps to reproduce the issue
Description
When building a Rust crate using CMake with a specific target triple (e.g., thumbv8m.main-nuttx-eabihf), the linker fails to find the generated static library (lib<crate>.a).
This is because nuttx_add_rust.cmake incorrectly constructs the build directory path by appending the target triple to the --target-dir argument. Since Cargo itself also appends the target triple to the directory specified by --target-dir, it results in a nested directory structure like:
.../target/<target-triple>/<target-triple>/debug/lib<crate>.a
However, the CMake script expects the library to be at:
.../target/<target-triple>/debug/lib<crate>.a
Steps to Reproduce
- Configure NuttX for a board that supports Rust (e.g.,
nucleo-h563zi:nsh).
- Use CMake to build the project:
cmake -S . -B build-debug -DBOARD_CONFIG=nucleo-h563zi:nsh -GNinja
cmake --build build-debug -t olddefconfig
cmake --build build-debug -j 6
- The build fails during the linking stage with an error similar to:
/path/to/arm-none-eabi/bin/ld: cannot find apps/examples/rust/hello/hello/target/thumbv8m.main-nuttx-eabihf/debug/libhello.a: No such file or directory
Expected Behavior
The Rust library should be correctly located by the linker, and the build should complete successfully.
Actual Behavior
The linker fails because it looks for the library in the wrong location due to the nested directory structure created by the incorrect --target-dir usage.
Proposed Fix
Modify apps/cmake/nuttx_add_rust.cmake to set RUST_BUILD_DIR without the target triple and update RUST_LIB_PATH to include the target triple in the expected location.
# Before
set(RUST_BUILD_DIR
${CMAKE_CURRENT_BINARY_DIR}/${CRATE_NAME}/target/${TARGET_BASE})
set(RUST_LIB_PATH ${RUST_BUILD_DIR}/${RUST_PROFILE}/lib${CRATE_NAME}.a)
# After
set(RUST_BUILD_DIR
${CMAKE_CURRENT_BINARY_DIR}/${CRATE_NAME}/target)
set(RUST_LIB_PATH ${RUST_BUILD_DIR}/${TARGET_BASE}/${RUST_PROFILE}/lib${CRATE_NAME}.a)
On which OS does this issue occur?
[OS: Mac]
What is the version of your OS?
26.4.1
NuttX Version
12.13.0
Issue Architecture
[Arch: arm]
Issue Area
[Area: Examples]
Host information
No response
Verification
Description / Steps to reproduce the issue
Description
When building a Rust crate using CMake with a specific target triple (e.g.,
thumbv8m.main-nuttx-eabihf), the linker fails to find the generated static library (lib<crate>.a).This is because
nuttx_add_rust.cmakeincorrectly constructs the build directory path by appending the target triple to the--target-dirargument. Since Cargo itself also appends the target triple to the directory specified by--target-dir, it results in a nested directory structure like:.../target/<target-triple>/<target-triple>/debug/lib<crate>.aHowever, the CMake script expects the library to be at:
.../target/<target-triple>/debug/lib<crate>.aSteps to Reproduce
nucleo-h563zi:nsh).cmake -S . -B build-debug -DBOARD_CONFIG=nucleo-h563zi:nsh -GNinja cmake --build build-debug -t olddefconfig cmake --build build-debug -j 6Expected Behavior
The Rust library should be correctly located by the linker, and the build should complete successfully.
Actual Behavior
The linker fails because it looks for the library in the wrong location due to the nested directory structure created by the incorrect
--target-dirusage.Proposed Fix
Modify
apps/cmake/nuttx_add_rust.cmaketo setRUST_BUILD_DIRwithout the target triple and updateRUST_LIB_PATHto include the target triple in the expected location.On which OS does this issue occur?
[OS: Mac]
What is the version of your OS?
26.4.1
NuttX Version
12.13.0
Issue Architecture
[Arch: arm]
Issue Area
[Area: Examples]
Host information
No response
Verification