From 654bec1b5a916744c528160b631efe89c13af399 Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Fri, 13 Mar 2026 14:29:19 +0800 Subject: [PATCH 1/2] 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 --- 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(-) create mode 100644 tools/i486-unknown-nuttx.json create mode 100644 tools/x86_64-unknown-nuttx.json diff --git a/cmake/nuttx_add_rust.cmake b/cmake/nuttx_add_rust.cmake index d50482ef763..0d1f09839ca 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 ad2fb3a8212..8e037aef6e0 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 00000000000..8d52aa16163 --- /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 00000000000..4a5b8490106 --- /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 From 4e2a4ebf1a530837c2efbe47b333d9978c3a679c Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Fri, 13 Mar 2026 14:29:37 +0800 Subject: [PATCH 2/2] tools: Fix target-pointer-width type in x86 target configs Remove quotes around target-pointer-width values in i486 and x86_64 target configuration files to change from string to numeric type. This change is required due to recent rustc JSON format modifications that expect numeric values instead of strings for target-pointer-width. Signed-off-by: Huang Qi --- tools/i486-unknown-nuttx.json | 2 +- tools/x86_64-unknown-nuttx.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/i486-unknown-nuttx.json b/tools/i486-unknown-nuttx.json index 8d52aa16163..93cd434185a 100644 --- a/tools/i486-unknown-nuttx.json +++ b/tools/i486-unknown-nuttx.json @@ -29,5 +29,5 @@ "unix" ], "target-mcount": "__mcount", - "target-pointer-width": "32" + "target-pointer-width": 32 } diff --git a/tools/x86_64-unknown-nuttx.json b/tools/x86_64-unknown-nuttx.json index 4a5b8490106..d12fecb8a74 100644 --- a/tools/x86_64-unknown-nuttx.json +++ b/tools/x86_64-unknown-nuttx.json @@ -32,5 +32,5 @@ "target-family": [ "unix" ], - "target-pointer-width": "64" + "target-pointer-width": 64 } \ No newline at end of file