Skip to content

Rust support for x86#3423

Merged
simbit18 merged 2 commits intoapache:masterfrom
no1wudi:rust
Mar 13, 2026
Merged

Rust support for x86#3423
simbit18 merged 2 commits intoapache:masterfrom
no1wudi:rust

Conversation

@no1wudi
Copy link
Contributor

@no1wudi no1wudi commented Mar 13, 2026

Summary

This PR adds JSON-based target specification files for x86 and x86_64 architectures to enable Rust support on NuttX RTOS with proper target configuration.

Why change is necessary?

X86 support for Rust in NuttX is still under development and has not been upstreamed to the Rust compiler yet. The default Rust target triples for x86 architectures do not properly support NuttX-specific requirements such as soft-float, proper ABI settings, and NuttX-specific linker configurations.

What functional part of the code is being changed?

  • Build system: cmake/nuttx_add_rust.cmake - Updated to use JSON target specification files for x86/x86_64 architectures
  • Build system: tools/Rust.mk - Updated build configuration
  • Target specifications: Added tools/x86_64-unknown-nuttx.json and tools/i486-unknown-nuttx.json
    How does the change exactly work?
  • Instead of using built-in Rust target triples (x86_64-unknown-nuttx, i686-unknown-nuttx), the build system now references custom JSON target specification files
  • These JSON files define:
    • Architecture-specific features (disabled MMX/SSE/AVX, enabled soft-float)
    • Proper data layout and ABI settings (x86-softfloat)
    • Linker configuration (rust-lld with gnu-lld flavor)
    • Position-independent executable support
    • Stack probing configuration
    • Sanitizer support (kcfi, kernel-address)
  • The CMake function nuttx_rust_target_triple() now returns the path to JSON files for x86 architectures
  • Build directory structure is enhanced to handle JSON target specifications by extracting the base target name
    Key changes:
  1. Added JSON files for i486 and x86_64 targets with complete target specifications
  2. Updated CMake functions to use the new target triples
  3. Enhanced build directory structure for Rust crates
  4. Fixed target-pointer-width type from string to numeric to comply with recent rustc JSON format requirements

Impact

  • Is new feature added? Is existing feature changed?
    YES - New feature: Adds JSON-based target specification support for x86/x86_64 Rust builds on NuttX
  • Impact on user (will user need to adapt to change)?
    NO - This is a build system improvement that is transparent to end users. Developers building Rust applications for x86 NuttX targets will automatically benefit from the proper target configuration.
  • Impact on build (will build process change)?
    YES - The build process for Rust applications on x86/x86_64 architectures will now use custom JSON target specifications instead of relying on built-in Rust target triples. This provides more accurate and maintainable target configurations.
  • Impact on hardware (will arch(s) / board(s) / driver(s) change)?
    YES - Affects x86 and x86_64 architectures. Enables proper Rust support with soft-float and correct ABI settings for these architectures on NuttX.
  • Impact on documentation (is update required / provided)?
    NO - The change is internal to the build system and does not require documentation updates for general users.
  • Impact on security (any sort of implications)?
    NO - This change only affects build configuration and does not introduce security implications.
  • Impact on compatibility (backward/forward/interoperability)?
    NO - This is a new feature addition and does not break existing functionality. Future compatibility is improved as we can now maintain our own target specifications independent of Rust upstream.
  • Anything else to consider?
    Once x86 Rust support stabilizes and is upstreamed to the Rust compiler, we can consider removing these custom JSON files and using the built-in target triples.

Testing

I confirm that changes are verified on local setup and works as intended:
Build Host(s):

  • OS: Linux (Ubuntu)
  • CPU: x86_64
  • Compiler: GCC, Rust (with x86 target support)
    Target(s):
  • arch: x86_64
  • board: sim (simulator)

no1wudi added 2 commits March 13, 2026 14:29
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 <huangqi3@xiaomi.com>
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 <huangqi3@xiaomi.com>
Copy link
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @no1wudi :-)

@simbit18 simbit18 merged commit ea22a66 into apache:master Mar 13, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants