Skip to content

tools/rust: Fix aarch64 NuttX Rust target specs#18992

Merged
jerpelea merged 1 commit into
apache:masterfrom
toku-mac:fix_aarch64_target_specs
May 29, 2026
Merged

tools/rust: Fix aarch64 NuttX Rust target specs#18992
jerpelea merged 1 commit into
apache:masterfrom
toku-mac:fix_aarch64_target_specs

Conversation

@toku-mac
Copy link
Copy Markdown
Contributor

Summary

Previously, sim builds on Apple Silicon used aarch64-apple-darwin as
the Rust target, which sets target_os=macos and breaks NuttX-specific
conditional compilation.

This PR introduces tools/aarch64-unknown-nuttx-macho.json, a custom
Rust target that sets os=nuttx while producing Mach-O objects
compatible with the macOS simulator linker. tools/Rust.defs is updated
to select this target when building sim on macOS.

Impact

Allows proper building of sim on Apple Silicon Macs and aarch64 Linux.
(Support for Intel Macs will be considered separately.)

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.
  • This PR is a successor of PR arch/sim: Translate Apple clock IDs for macOS sim #18978

Configuration and Build:

rm -rf build-debug
make distclean
cmake -S . -B build-debug -DBOARD_CONFIG=sim:nsh -GNinja

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
" >> build-debug/.config

cmake --build build-debug -t olddefconfig
cmake --build build-debug

Testing logs before change:

NuttShell (NSH) NuttX-12.13.0
nsh> hello_rust_cargo
{"name":"John","age":30}
{"name":"Jane","age":25}
Deserialized: Alice is 28 years old
Pretty JSON:
{
  "name": "Alice",
  "age": 28
}

thread '<unnamed>' (1797510) panicked at /Users/toku/.rustup/toolchains/nightly-2026-04-29-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/pal/unix/time.rs:107:68:
called `Result::unwrap()` on an `Err` value: Os { code: 0, kind: Uncategorized, message: "Unknown error 0" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Testing logs after change:

NuttShell (NSH) NuttX-12.13.0
nsh> hello_rust_cargo
{"name":"John","age":30}
{"name":"Jane","age":25}
Deserialized: Alice is 28 years old
Pretty JSON:
{
  "name": "Alice",
  "age": 28
}
Hello world from tokio!

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 a custom aarch64 Mach-O Rust target for macOS sim builds and use it
instead of an Apple Darwin Rust target. This keeps Rust cfg values aligned
with NuttX while producing Mach-O objects required by the simulator link.

Also align sim host handling for aarch64 Linux by detecting `aarch64` as
`HOST_ARM64` and avoiding x86-specific `-mcmodel` and `-no-pie` options
on ARM64 hosts.

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

lupyuen commented May 29, 2026

@no1wudi Could you review this PR? And also this one below thanks :-)

@jerpelea jerpelea merged commit 7c38d58 into apache:master May 29, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: simulator Issues related to the SIMulator Area: Build system Board: simulator Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants