Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: New app to build Rust with Cargo #2487

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

no1wudi
Copy link
Contributor

@no1wudi no1wudi commented Aug 18, 2024

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 rust-lang/rust#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.

TODO

  1. Add support for Rust in CMake based system
  2. Upstream https://github.com/no1wudi/libc to rust-lang/libc
  3. Port libstd of Rust to NuttX, which blocked by 2.

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 rust-lang/rust#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 <[email protected]>
@nuttxpr
Copy link

nuttxpr commented Oct 23, 2024

[Experimental Bot, please feedback here]

PR Requirements Review

Meeting Requirements? Partially

Summary:

  • Why? Provides a more common and ecosystem-friendly way to build Rust applications for NuttX.
  • What? Introduces cargo as a build method for Rust applications.
  • How? Leverages nightly Rust versions supporting NuttX as a direct target. Provides a hello world example.
  • Issues/PRs: None linked.

Impact:

  • New Feature: YES (cargo-based build)
  • User Impact: YES (Need nightly Rust, specific target config, potential future changes due to TODOs)
  • Build Impact: YES (Requires cargo, nightly Rust toolchain)
  • Hardware Impact: Potentially, depending on target triple support.
  • Documentation Impact: YES (Required for new build process, Rust support)
  • Security Impact: Unclear, requires further analysis of Rust integration.
  • Compatibility Impact: Potential forward compatibility issues due to reliance on nightly Rust.

Testing:

  • Incomplete: Only mentions target architecture, not specific boards or configurations tested on.
  • Logs: Missing.

Specific Concerns

  • Rust Integration Maturity: Heavy reliance on nightly Rust and upstreaming efforts (libc, libstd) indicates this is an early-stage integration. PR should clearly communicate this.
  • TODOs: The extensive TODO list suggests this is a work in progress. It's important to clarify the scope of this specific PR versus future work.
  • Target Specificity: The PR should clearly document supported target triples and any limitations.
  • Testing: More comprehensive testing is needed across various architectures, boards, and configurations. Provide detailed logs.
  • Documentation: This is crucial for a new build system and language integration. Detailed instructions, configuration options, and limitations should be included.

Recommendation

This PR addresses a desirable feature but is not yet ready for merging in its current state. Address the concerns outlined above to ensure a robust, well-documented, and well-tested addition to NuttX.

@cederom cederom requested a review from lupyuen October 23, 2024 03:10
COMMAND
cargo build --release -Zbuild-std=core --manifest-path
${CMAKE_CURRENT_SOURCE_DIR}/hello/Cargo.toml --target
riscv32imac-unknown-nuttx-elf --target-dir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we generalize the common to a function for all possible arch?

OUTPUT
${CMAKE_BINARY_DIR}/hello_rust_cargo/riscv32imac-unknown-nuttx-elf/release/libhello.a
COMMAND
cargo build --release -Zbuild-std=core --manifest-path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we move to examples/hello_rust_cargo/hello/

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or better examples/rust/cargo/hello? :-)

PROGNAME = $(CONFIG_EXAMPLES_HELLO_RUST_CARGO_PROGNAME)
PRIORITY = $(CONFIG_EXAMPLES_HELLO_RUST_CARGO_PRIORITY)
STACKSIZE = $(CONFIG_EXAMPLES_HELLO_RUST_CARGO_STACKSIZE)
MODULE = $(CONFIG_EXAMPLES_HELLO_RUST_CARGO)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to link libhello.a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants