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

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

commit f90e1e184ff5eefe147f1386cf172058b50ff98a
Author: Huang Qi <[email protected]>
AuthorDate: Fri Mar 13 14:29:19 2026 +0800

    tools/build: Make Rust target triples for x86 use JSON files
    
    X86 support for Rust needs more test and verification, and not
    upstreamed to Rust side yet.
    
    It's better to use custom target triples for x86 by json files for now,
    and it can be upstreamed to Rust side if stable enough.
    
    Changed the Rust target triples in the CMake configuration to reference 
JSON files for x86_64 and i486 architectures. This improves the build process 
by providing more detailed target specifications.
    * Added JSON files for i486 and x86_64 targets
    * Updated CMake functions to use the new target triples
    * Enhanced build directory structure for Rust crates
    
    Signed-off-by: Huang Qi <[email protected]>
---
 cmake/nuttx_add_rust.cmake      | 18 ++++++++++++------
 tools/Rust.mk                   |  8 +++++---
 tools/i486-unknown-nuttx.json   | 33 +++++++++++++++++++++++++++++++++
 tools/x86_64-unknown-nuttx.json | 36 ++++++++++++++++++++++++++++++++++++
 4 files changed, 86 insertions(+), 9 deletions(-)

diff --git a/cmake/nuttx_add_rust.cmake b/cmake/nuttx_add_rust.cmake
index d50482ef7..0d1f09839 100644
--- a/cmake/nuttx_add_rust.cmake
+++ b/cmake/nuttx_add_rust.cmake
@@ -48,9 +48,9 @@ include(nuttx_parse_function_args)
 
 function(nuttx_rust_target_triple ARCHTYPE ABITYPE CPUTYPE OUTPUT)
   if(ARCHTYPE STREQUAL "x86_64")
-    set(TARGET_TRIPLE "x86_64-unknown-nuttx")
+    set(TARGET_TRIPLE "${APPDIR}/tools/x86_64-unknown-nuttx.json")
   elseif(ARCHTYPE STREQUAL "x86")
-    set(TARGET_TRIPLE "i686-unknown-nuttx")
+    set(TARGET_TRIPLE "${APPDIR}/tools/i486-unknown-nuttx.json")
   elseif(ARCHTYPE MATCHES "thumb")
     if(ARCHTYPE MATCHES "thumbv8m")
       # Extract just the base architecture type (thumbv8m.main or 
thumbv8m.base)
@@ -138,10 +138,16 @@ function(nuttx_add_rust)
   nuttx_rust_target_triple(${LLVM_ARCHTYPE} ${LLVM_ABITYPE} ${LLVM_CPUTYPE}
                            RUST_TARGET)
 
-  # Set up build directory in current binary dir
-  set(RUST_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CRATE_NAME})
-  set(RUST_LIB_PATH
-      ${RUST_BUILD_DIR}/${RUST_TARGET}/${RUST_PROFILE}/lib${CRATE_NAME}.a)
+  # Get binary directory path using target triple base name if it's a JSON file
+  if(RUST_TARGET MATCHES ".json$")
+    get_filename_component(TARGET_BASE ${RUST_TARGET} NAME_WE)
+  else()
+    set(TARGET_BASE ${RUST_TARGET})
+  endif()
+
+  set(RUST_BUILD_DIR
+      ${CMAKE_CURRENT_BINARY_DIR}/${CRATE_NAME}/target/${TARGET_BASE})
+  set(RUST_LIB_PATH ${RUST_BUILD_DIR}/${RUST_PROFILE}/lib${CRATE_NAME}.a)
 
   # Create build directory
   file(MAKE_DIRECTORY ${RUST_BUILD_DIR})
diff --git a/tools/Rust.mk b/tools/Rust.mk
index ad2fb3a82..8e037aef6 100644
--- a/tools/Rust.mk
+++ b/tools/Rust.mk
@@ -47,10 +47,10 @@
 define RUST_TARGET_TRIPLE
 $(or \
   $(and $(filter x86_64,$(LLVM_ARCHTYPE)), \
-    x86_64-unknown-nuttx \
+    $(APPDIR)/tools/x86_64-unknown-nuttx.json \
   ), \
   $(and $(filter x86,$(LLVM_ARCHTYPE)), \
-    i686-unknown-nuttx \
+    $(APPDIR)/tools/i486-unknown-nuttx.json \
   ), \
   $(and $(filter thumb%,$(LLVM_ARCHTYPE)), \
     $(if $(filter thumbv8m%,$(LLVM_ARCHTYPE)), \
@@ -132,5 +132,7 @@ endef
 #   Path to the Rust binary (e.g. 
path/to/project/target/riscv32imac-unknown-nuttx-elf/release/libhello.a)
 
 define RUST_GET_BINDIR
-$(2)/$(1)/target/$(strip $(call RUST_TARGET_TRIPLE))/$(if 
$(CONFIG_DEBUG_FULLOPT),release,debug)/lib$(1).a
+$(2)/$(1)/target/$(strip $(if $(findstring .json,$(call RUST_TARGET_TRIPLE)), \
+       $(basename $(notdir $(call RUST_TARGET_TRIPLE))), \
+       $(call RUST_TARGET_TRIPLE)))/$(if 
$(CONFIG_DEBUG_FULLOPT),release,debug)/lib$(1).a
 endef
diff --git a/tools/i486-unknown-nuttx.json b/tools/i486-unknown-nuttx.json
new file mode 100644
index 000000000..8d52aa161
--- /dev/null
+++ b/tools/i486-unknown-nuttx.json
@@ -0,0 +1,33 @@
+{
+  "arch": "x86",
+  "cpu": "i486",
+  "crt-objects-fallback": "false",
+  "data-layout": 
"e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i128:128-f64:32:64-f80:32-n8:16:32-S128",
+  "features": 
"-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2,+soft-float",
+  "default-dwarf-version": 2,
+  "dynamic-linking": true,
+  "has-rpath": true,
+  "has-thread-local": true,
+  "linker-flavor": "gnu-lld",
+  "llvm-target": "i486-unknown-nuttx",
+  "max-atomic-width": 64,
+  "metadata": {
+    "description": "32-bit x86, resricted to i486",
+    "host_tools": false,
+    "std": true,
+    "tier": 3
+  },
+  "no-default-libraries": true,
+  "os": "nuttx",
+  "position-independent-executables": false,
+  "relro-level": "full",
+  "rustc-abi": "x86-softfloat",
+  "stack-probes": {
+    "kind": "inline"
+  },
+  "target-family": [
+    "unix"
+  ],
+  "target-mcount": "__mcount",
+  "target-pointer-width": "32"
+}
diff --git a/tools/x86_64-unknown-nuttx.json b/tools/x86_64-unknown-nuttx.json
new file mode 100644
index 000000000..4a5b84901
--- /dev/null
+++ b/tools/x86_64-unknown-nuttx.json
@@ -0,0 +1,36 @@
+{
+  "arch": "x86_64",
+  "cpu": "x86-64",
+  "crt-objects-fallback": "false",
+  "data-layout": 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
+  "disable-redzone": true,
+  "features": 
"-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2,+soft-float",
+  "linker": "rust-lld",
+  "linker-flavor": "gnu-lld",
+  "llvm-target": "x86_64-unknown-nuttx",
+  "max-atomic-width": 64,
+  "metadata": {
+    "description": "x86_64 target for NuttX RTOS with softfloat",
+    "host_tools": false,
+    "std": true,
+    "tier": 3
+  },
+  "panic-strategy": "abort",
+  "plt-by-default": false,
+  "position-independent-executables": true,
+  "relro-level": "full",
+  "rustc-abi": "x86-softfloat",
+  "stack-probes": {
+    "kind": "inline"
+  },
+  "static-position-independent-executables": true,
+  "supported-sanitizers": [
+    "kcfi",
+    "kernel-address"
+  ],
+  "os": "nuttx",
+  "target-family": [
+    "unix"
+  ],
+  "target-pointer-width": "64"
+}
\ No newline at end of file

Reply via email to