Skip to content

[BUG] cmake: Fix invalid --debug argument in cargo build command #3472

@toku-mac

Description

@toku-mac

Description / Steps to reproduce the issue

Description:
When building NuttX with Rust applications using CMake, the build fails because cargo build is invoked with an invalid --debug argument. In Cargo, the debug build is the default, and it does not recognize a --debug flag (it uses --release for optimized builds).

Steps to Reproduce:

  1. Configure NuttX for a board with a Rust example (e.g., nucleo-h563zi:nsh with Rust enabled).
  2. Run CMake configuration:
    cmake -S . -B build -DBOARD_CONFIG=nucleo-h563zi:nsh -GNinja
  3. Attempt to build:
    cmake --build build

Expected Result:
The Rust crate should be compiled successfully using the default Cargo profile.

Actual Result:
The build fails with the following error:

FAILED: apps/examples/rust/hello/hello/target/.../debug/libhello.a
...
cargo build --debug -Zbuild-std=std,panic_abort ...
error: unexpected argument '--debug' found

  tip: `--debug` is the default for `cargo build`; instead `--release` is supported

Usage: cargo build [OPTIONS]

Proposed Fix:
The nuttx_add_rust.cmake script currently uses --${RUST_PROFILE} which evaluates to cargo build --debug when CONFIG_DEBUG_FULLOPT is not set. This should be changed to omit the flag for debug builds and only provide --release when appropriate.

  # Determine build profile based on CONFIG_DEBUG_FULLOPT
  if(CONFIG_DEBUG_FULLOPT)
    set(RUST_PROFILE_FLAG "--release")
    set(RUST_PROFILE "release")
    ...
  else()
    set(RUST_PROFILE_FLAG "")
    set(RUST_PROFILE "debug")
    ...
  endif()

  # In add_custom_command
  COMMAND
    ...
    cargo build ${RUST_PROFILE_FLAG}
    ...

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

  • I have verified before submitting the report.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions