tools: Enable Rust sim builds on Intel Macs

Add support for building Rust apps on the NuttX simulator running on
Intel (x86_64) macOS.

- Add tools/x86_64-unknown-nuttx-macho.json, a Mach-O Rust target for
  the macOS sim.
- Rust.defs: select the new x86_64 macho target for sim on macOS.
- boards/sim/.../Make.defs: keep the default PIC/PIE-compatible code
  generation on macOS by not adding -fno-pic/-mcmodel=medium.
- sethost.sh: enable CONFIG_HOST_X86_64 for non-arm64 hosts.

Signed-off-by: Shoji Tokunaga <toku@mac.com>
This commit is contained in:
Shoji Tokunaga 2026-06-01 15:32:15 +09:00 committed by Xiang Xiao
parent 3c8621cb89
commit 59a66fa17d
5 changed files with 57 additions and 5 deletions

View file

@ -149,11 +149,16 @@ ifeq ($(CONFIG_SIM_M32),y)
ARCHCFLAGS += -m32
ARCHCXXFLAGS += -m32
else
ARCHCFLAGS += -fno-pic
ARCHCXXFLAGS += -fno-pic
ifeq ($(CONFIG_HOST_X86_64),y)
ARCHCFLAGS += -mcmodel=medium
ARCHCXXFLAGS += -mcmodel=medium
# On macOS, keep the default PIC/PIE-compatible code generation.
# Adding -fno-pic (which implies -mdynamic-no-pic on Apple clang) makes
# the final PIE link emit "PIE disabled. Absolute addressing ..." warnings.
ifneq ($(CONFIG_HOST_MACOS),y)
ARCHCFLAGS += -fno-pic
ARCHCXXFLAGS += -fno-pic
ifeq ($(CONFIG_HOST_X86_64),y)
ARCHCFLAGS += -mcmodel=medium
ARCHCXXFLAGS += -mcmodel=medium
endif
endif
endif
@ -327,6 +332,11 @@ ifeq ($(CONFIG_SIM_M32),y)
SHMODULEFLAGS += -melf_i386
LDELFFLAGS += -melf_i386
else ifeq ($(CONFIG_HOST_MACOS)$(CONFIG_HOST_X86_64),yy)
# Keep the default PIE link mode on macOS.
# -no_pie is deprecated for newer macOS deployment targets, and the
# PIC/PIE-compatible code generation above lets the PIE link succeed.
else ifeq ($(CONFIG_HOST_MACOS)$(CONFIG_HOST_ARM64),)
# To compile 64-bit Sim, adding no-pie is necessary to prevent linking errors
# but this may cause other issues on Ubuntu 20.

View file

@ -46,6 +46,8 @@ ifeq ($(CONFIG_ARCH_SIM),y)
else ifeq ($(CONFIG_HOST_MACOS),y)
ifeq ($(LLVM_ARCHTYPE),aarch64)
RUSTFLAGS += --target $(TOPDIR)/tools/aarch64-unknown-nuttx-macho.json
else ifeq ($(LLVM_ARCHTYPE),x86_64)
RUSTFLAGS += --target $(TOPDIR)/tools/x86_64-unknown-nuttx-macho.json
else
$(error Unsupported Rust SIM target on macOS: LLVM_ARCHTYPE=$(LLVM_ARCHTYPE))
endif

View file

@ -23,6 +23,7 @@
},
"os": "nuttx",
"panic-strategy": "abort",
"relocation-model": "pic",
"split-debuginfo": "off",
"stack-probes": {
"kind": "inline"

View file

@ -191,6 +191,9 @@ if [ "X$host" == "Xlinux" -o "X$host" == "Xmacos" -o "X$host" == "Xbsd" ]; then
if [ "X$cpu" == "Xarm64" ]; then
echo " Select CONFIG_HOST_ARM64=y"
kconfig-tweak --file $nuttx/.config --enable CONFIG_HOST_ARM64
else
echo " Select CONFIG_HOST_X86_64=y"
kconfig-tweak --file $nuttx/.config --enable CONFIG_HOST_X86_64
fi
fi

View file

@ -0,0 +1,36 @@
{
"arch": "x86_64",
"archive-format": "darwin",
"binary-format": "mach-o",
"cpu": "x86-64",
"crt-objects-fallback": "false",
"data-layout": "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
"debuginfo-kind": "dwarf",
"default-uwtable": true,
"disable-redzone": true,
"emit-debug-gdb-scripts": false,
"frame-pointer": "always",
"function-sections": false,
"linker-flavor": "gnu-lld",
"lld-flavor": "darwin",
"llvm-target": "x86_64-apple-macosx",
"max-atomic-width": 64,
"metadata": {
"description": "x86_64 Mach-O target for NuttX sim on macOS",
"host_tools": false,
"std": true,
"tier": 3
},
"os": "nuttx",
"panic-strategy": "abort",
"relocation-model": "pic",
"split-debuginfo": "off",
"stack-probes": {
"kind": "inline"
},
"target-family": [
"unix"
],
"target-pointer-width": 64,
"vendor": "unknown"
}