toku-mac opened a new issue, #3473:
URL: https://github.com/apache/nuttx-apps/issues/3473

   ### 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
   1. Configure NuttX for a board that supports Rust (e.g., 
`nucleo-h563zi:nsh`).
   2. Use CMake to build the project:
      ```bash
      cmake -S . -B build-debug -DBOARD_CONFIG=nucleo-h563zi:nsh -GNinja
      cmake --build build-debug -t olddefconfig
      cmake --build build-debug -j 6
      ```
   3. 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.
   
   ```cmake
   # 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
   
   - [x] I have verified before submitting the report.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to