Skip to content

apps/tools: Make hello_rust_cargo buildable with make#3501

Merged
lupyuen merged 1 commit into
apache:masterfrom
toku-mac:fix_cargo_make
May 26, 2026
Merged

apps/tools: Make hello_rust_cargo buildable with make#3501
lupyuen merged 1 commit into
apache:masterfrom
toku-mac:fix_cargo_make

Conversation

@toku-mac
Copy link
Copy Markdown
Contributor

Summary

Fix the Make-based build for Rust-enabled sim:nsh configurations.

This change addresses two Make/Cargo issues:

Add the missing Apple Silicon macOS Rust target mapping

When building sim:nsh with Make on an ARM64 macOS host, LLVM_ARCHTYPE is set to aarch64. However, apps/tools/Rust.mk did not handle aarch64 in RUST_TARGET_TRIPLE, so Cargo was invoked with an empty --target argument:

error: "--target" takes a target architecture as an argument.

The Make build now maps this case to the same target used by the CMake Rust helper: aarch64-apple-darwin

Pass -Zjson-target-spec to Cargo

The Rust build uses JSON target specifications for NuttX targets such as the simulator targets under apps/tools/. Cargo requires -Zjson-target-spec when building with these JSON target files.

Impact

  • Impact on build: Enables building with Make/Cargo configurations.

Testing

I confirm that changes are verified on local setup and works as intended:

  • Build Host(s): OS (macOS 26.5), CPU(Apple M1), compiler(Apple clang version 21.0.0)
  • Target(s): arch(sim)
  • Ensure your PATH environment variable is properly configured to allow execution of: menuconfig, olddefconfig, savedefconfig, and setconfig.
  • Use the Rust toolchain version prior to nightly-2026-04-29 to avoid errors related to lib/rustlib/src/rust/library/std/src/sys/net/connection/socket/unix.rs.

Configuration:

make distclean
./tools/configure.sh sim:nsh
make menuconfig

printf "CONFIG_SYSTEM_TIME64=y
CONFIG_FS_LARGEFILE=y
CONFIG_TLS_NELEM=16
CONFIG_DEV_URANDOM=y
CONFIG_EXAMPLES_HELLO_RUST_CARGO=y
CONFIG_EXAMPLES_HELLO_RUST_CARGO_STACKSIZE=8192
# CONFIG_COVERAGE_TOOLCHAIN is not set
CONFIG_COVERAGE_NONE=y
" >> .config

make olddefconfig

Testing logs before change:

❯ make
Create version.h
Building Rust code with cargo...
error: "--target" takes a target architecture as an argument.

Run `rustup target list` to see possible targets.
make[3]: *** [Makefile:31: context] Error 101
make[2]: *** [Makefile:57: /Users/toku/nuttxspace/apps/examples/rust/hello_context] Error 2
make[1]: *** [Makefile:187: context] Error 2
make: *** [tools/Unix.mk:471: /Users/toku/nuttxspace/apps/.context] Error 2

Testing logs after change:

> make
...
  Compiling tokio v1.52.3
   Compiling hello v0.1.0 (/Users/toku/nuttxspace/apps/examples/rust/hello)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 20.92s
LN: platform/board to /Users/toku/nuttxspace/apps/platform/dummy
Register: gpio
Register: hello
Register: hello_rust_cargo
Register: dd
Register: dumpstack
Register: nsh
Register: sh
Register: ostest
CP:  /Users/toku/nuttxspace/nuttx/include/nuttx/config.h
CP:  /Users/toku/nuttxspace/nuttx/include/nuttx/fs/hostfs.h
LD:  nuttx
ld: warning: -ld_classic is deprecated and will be removed in a future release
ld: warning: -ld_classic is deprecated and will be removed in a future release

PR verification Self-Check

  • My PR adheres to Contributing Guidelines and Documentation (git commit title and message, coding standard, etc).
  • My PR is ready for review and can be safely merged into a codebase.

* Add JSON specification compatibility flag.
* Add Rust target conversion support for `aarch64` on macOS.

Signed-off-by: Shoji Tokunaga <toku@mac.com>
@lupyuen
Copy link
Copy Markdown
Member

lupyuen commented May 26, 2026

@no1wudi Could you review this PR? Thanks :-)

@lupyuen lupyuen merged commit 72bedd5 into apache:master May 26, 2026
41 checks passed
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.

4 participants