This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 59a66fa17d0 tools: Enable Rust sim builds on Intel Macs
59a66fa17d0 is described below

commit 59a66fa17d0c1ec36b4168438b89095c257762fb
Author: Shoji Tokunaga <[email protected]>
AuthorDate: Mon Jun 1 15:32:15 2026 +0900

    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 <[email protected]>
---
 boards/sim/sim/sim/scripts/Make.defs                 | 20 +++++++++++++++-----
 tools/Rust.defs                                      |  2 ++
 tools/aarch64-unknown-nuttx-macho.json               |  1 +
 tools/sethost.sh                                     |  3 +++
 ...tx-macho.json => x86_64-unknown-nuttx-macho.json} | 15 ++++++++-------
 5 files changed, 29 insertions(+), 12 deletions(-)

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/aarch64-unknown-nuttx-macho.json 
b/tools/x86_64-unknown-nuttx-macho.json
similarity index 71%
copy from tools/aarch64-unknown-nuttx-macho.json
copy to tools/x86_64-unknown-nuttx-macho.json
index 5410ffd9f21..5e5fc7a206e 100644
--- a/tools/aarch64-unknown-nuttx-macho.json
+++ b/tools/x86_64-unknown-nuttx-macho.json
@@ -1,28 +1,29 @@
 {
-  "arch": "aarch64",
+  "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-n32:64-S128-Fn32",
+  "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,
-  "features": "+v8a,+strict-align,+neon",
-  "frame-pointer": "non-leaf",
+  "frame-pointer": "always",
   "function-sections": false,
   "linker-flavor": "gnu-lld",
   "lld-flavor": "darwin",
-  "llvm-target": "arm64-apple-macosx",
-  "max-atomic-width": 128,
+  "llvm-target": "x86_64-apple-macosx",
+  "max-atomic-width": 64,
   "metadata": {
-    "description": "aarch64 Mach-O target for NuttX sim on macOS",
+    "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"

Reply via email to