From 59a66fa17d0c1ec36b4168438b89095c257762fb Mon Sep 17 00:00:00 2001 From: Shoji Tokunaga Date: Mon, 1 Jun 2026 15:32:15 +0900 Subject: [PATCH] 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 --- boards/sim/sim/sim/scripts/Make.defs | 20 ++++++++++---- tools/Rust.defs | 2 ++ tools/aarch64-unknown-nuttx-macho.json | 1 + tools/sethost.sh | 3 +++ tools/x86_64-unknown-nuttx-macho.json | 36 ++++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 tools/x86_64-unknown-nuttx-macho.json diff --git a/boards/sim/sim/sim/scripts/Make.defs b/boards/sim/sim/sim/scripts/Make.defs index 2cc3d159d27..0b61eaebddd 100644 --- a/boards/sim/sim/sim/scripts/Make.defs +++ b/boards/sim/sim/sim/scripts/Make.defs @@ -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. diff --git a/tools/Rust.defs b/tools/Rust.defs index 50225761e63..ca87f901cfc 100644 --- a/tools/Rust.defs +++ b/tools/Rust.defs @@ -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 diff --git a/tools/aarch64-unknown-nuttx-macho.json b/tools/aarch64-unknown-nuttx-macho.json index 5410ffd9f21..8a2de4f90e7 100644 --- a/tools/aarch64-unknown-nuttx-macho.json +++ b/tools/aarch64-unknown-nuttx-macho.json @@ -23,6 +23,7 @@ }, "os": "nuttx", "panic-strategy": "abort", + "relocation-model": "pic", "split-debuginfo": "off", "stack-probes": { "kind": "inline" diff --git a/tools/sethost.sh b/tools/sethost.sh index 71fb33938b5..772c34b6688 100755 --- a/tools/sethost.sh +++ b/tools/sethost.sh @@ -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 diff --git a/tools/x86_64-unknown-nuttx-macho.json b/tools/x86_64-unknown-nuttx-macho.json new file mode 100644 index 00000000000..5e5fc7a206e --- /dev/null +++ b/tools/x86_64-unknown-nuttx-macho.json @@ -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" +}