Skip to content

apps/cmake: Fix aarch64 NuttX Rust target specs#3510

Open
toku-mac wants to merge 1 commit into
apache:masterfrom
toku-mac:fix_aarch64_target_specs
Open

apps/cmake: Fix aarch64 NuttX Rust target specs#3510
toku-mac wants to merge 1 commit into
apache:masterfrom
toku-mac:fix_aarch64_target_specs

Conversation

@toku-mac
Copy link
Copy Markdown
Contributor

Summary

Previously, aarch64 sim builds on macOS used aarch64-apple-darwin,
which sets target_os=macos and causes NuttX-specific cfg guards to be silently skipped.

This PR adds two custom Rust target JSON files:

  • tools/aarch64-unknown-nuttx.json — ELF target for Linux/bare-metal
  • tools/aarch64-unknown-nuttx-macho.json — Mach-O target for macOS sim

Rust.mk and cmake/nuttx_add_rust.cmake are updated to select the
appropriate target.

Depends on the corresponding nuttx-side PR. #18992

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 #18978

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.

Comment thread tools/aarch64-unknown-nuttx-macho.json Outdated
"arch": "aarch64",
"archive-format": "darwin",
"binary-format": "mach-o",
"crt-objects-fallback": "false",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we reuse the same file from nuttx git?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is your intention the same as the patch below?
Also, should I move tools/aarch64-unknown-nuttx.json to the nuttx git as well?

diff --git a/cmake/nuttx_add_rust.cmake b/cmake/nuttx_add_rust.cmake
index dfa91c31c..2c28983f0 100644
--- a/cmake/nuttx_add_rust.cmake
+++ b/cmake/nuttx_add_rust.cmake
@@ -57,7 +57,8 @@ function(nuttx_rust_target_triple ARCHTYPE ABITYPE CPUTYPE OUTPUT)
     set(TARGET_TRIPLE "${APPDIR}/tools/i486-unknown-nuttx.json")
   elseif(ARCHTYPE STREQUAL "aarch64")
     if(CONFIG_ARCH_SIM AND CONFIG_HOST_MACOS)
-      set(TARGET_TRIPLE "${APPDIR}/tools/aarch64-unknown-nuttx-macho.json")
+      set(TARGET_TRIPLE
+          "${PROJECT_SOURCE_DIR}/tools/aarch64-unknown-nuttx-macho.json")
     else()
       set(TARGET_TRIPLE "${APPDIR}/tools/aarch64-unknown-nuttx.json")
     endif()
diff --git a/tools/Rust.mk b/tools/Rust.mk
index 9ca03bdac..4fc74af4e 100644
--- a/tools/Rust.mk
+++ b/tools/Rust.mk
@@ -56,7 +56,7 @@ $(or \
   ), \
   $(and $(filter aarch64,$(LLVM_ARCHTYPE)), \
     $(if $(and $(filter sim,$(CONFIG_ARCH)),$(filter y,$(CONFIG_HOST_MACOS))), \
-      $(APPDIR)/tools/aarch64-unknown-nuttx-macho.json, \
+      $(TOPDIR)/tools/aarch64-unknown-nuttx-macho.json, \
       $(APPDIR)/tools/aarch64-unknown-nuttx.json \
     ) \
   ), \

Add aarch64 Rust target specs for NuttX, including a Mach-O variant
for macOS sim builds. Use the NuttX custom targets instead of
aarch64-apple-darwin so Rust std is built with target_os=nuttx while
still producing link-compatible objects for sim.

Signed-off-by: Shoji Tokunaga <toku@mac.com>
@toku-mac toku-mac force-pushed the fix_aarch64_target_specs branch from 77b62fc to 6e58319 Compare May 29, 2026 14:10
@toku-mac
Copy link
Copy Markdown
Contributor Author

Since the PR on the nuttx git repository has been merged into master, I've decided not to move the tools/aarch64-unknown-nuttx.json file from the apps git.
Please review commit 6e58319.

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.

2 participants