lupyuen opened a new pull request, #12852:
URL: https://github.com/apache/nuttx/pull/12852

   ## Summary
   
   This PR fixes the build for Rust Apps on QEMU RISC-V 64-bit. Previously the 
Rust Build selected the [incorrect Rust Target 
riscv64i-unknown-none-elf](https://lupyuen.github.io/articles/rust5#rust-target-is-incorrect).
 Now the Rust Build selects the correct Rust Target: riscv64gc-unknown-none-elf.
   
   To validate the fix, we create a new NuttX Config `rv-virt:leds64_rust` that 
builds the `leds_rust` example for QEMU RISC-V 64-bit. `leds_rust` will be 
compiled for every run of NuttX CI.
   
   Note that Rust Apps won't build correctly for QEMU RISC-V 32-bit. This 
requires a [Rust Custom Target for 
riscv32gc](https://lupyuen.github.io/articles/rust4#custom-target-for-rust), 
which will make the NuttX Makefiles much more complicated.
   
   This PR also fixes the 32-bit RISC-V Target for D Apps. D Targets 
("riscv32") are named differently from Rust Targets ("riscv32gc"), this PR 
restores the correct Target Names.
   
   ### Modified Files
   
   `tools/Rust.defs`: Rename the RISC-V ISA `imafdc` to `gc` for Rust Targets
   
   `tools/D.defs`: Exclude the RISC-V ISA for D Targets
   
   `tools/ci/docker/linux/Dockerfile`, `tools/ci/platforms/ubuntu.sh`, 
`tools/ci/platforms/msys2.sh`: Add Rust Target `riscv64gc-unknown-none-elf` for 
CI
   
   ### New Files
   
   `boards/risc-v/qemu-rv/rv-virt/configs/leds64_rust/defconfig`: Add new NuttX 
Config `rv-virt:leds64_rust`
   
   ## Updated Docs
   
   `applications/examples/leds_rust/index.rst`: Add `leds_rust` example app
   
   `platforms/risc-v/qemu-rv/boards/rv-virt/index.rst`: Add 
`rv-virt:leds64_rust` config
   
   ## Impact
   
   Previously, Rust and D Apps failed to build for QEMU RISC-V due to the 
incorrect target. With this PR, they will build correctly. There is no impact 
on C Apps.
   
   ## Testing
   
   __For Rust Apps:__ We tested the `leds_rust` example app on 
`rv-virt:leds64_rust` (QEMU RISC-V 64-bit): [Test 
Log](https://gist.github.com/lupyuen/e44e8db4cd1a0ab67dad741aa1b314dd)
   
   ```text
   $ tools/configure.sh rv-virt:leds64_rust
   ...
   NuttShell (NSH) NuttX-12.4.0
   nsh> uname -a
   NuttX 12.4.0 723281ed9b Aug  6 2024 15:37:10 risc-v rv-virt
   
   nsh> leds_rust
   Hello, Rust!!
   Opening /dev/userleds
   Set LED 1 to 1
   board_userled: LED 1 set to 1
   board_userled: LED 2 set to 0
   board_userled: LED 3 set to 0
   Sleeping...
   Set LED 1 to 0
   board_userled: LED 1 set to 0
   board_userled: LED 2 set to 0
   board_userled: LED 3 set to 0
   ```
   
   Note that `leds_rust` won't build correctly for 32-bit `rv-virt:leds`. To 
date, NuttX has never supported Rust Apps for QEMU RISC-V 32-bit, because the 
[Rust Custom Target for 
riscv32gc](https://lupyuen.github.io/articles/rust4#custom-target-for-rust) is 
missing: [Build 
Log](https://gist.github.com/lupyuen/0ea3dfea5a7fb9ddb7f712f80e1940d4)
   
   ```text
   $ tools/configure.sh rv-virt:leds
   $ kconfig-tweak --enable CONFIG_EXAMPLES_LEDS_RUST
   $ make olddefconfig
   $ make
   error: Error loading target specification:
   Could not find specification for target "riscv32gc-unknown-none-elf"
   ```
   
   __For D Apps:__ We tested the `hello_d` example app on `rv-virt:nsh` (QEMU 
RISC-V 32-bit): [Test 
Log](https://gist.github.com/lupyuen/6f7a6a3452797fee46e3605e7c54a6b5)
   
   ```text
   $ tools/configure.sh rv-virt:nsh
   $ kconfig-tweak --enable CONFIG_EXAMPLES_HELLO_D
   $ make olddefconfig
   ...
   NuttShell (NSH) NuttX-12.4.0
   nsh> uname -a
   NuttX 12.4.0 723281ed9b Aug  6 2024 15:33:01 risc-v rv-virt
   
   nsh> hello_d
   Hello World, [generic-rv32]!
   hello_d_main: Saying hello from the dynamically constructed instance
   DHelloWorld.HelloWorld: CONSTRUCTION FAILED!
   hello_d_main: Saying hello from the instance constructed on the stack
   DHelloWorld.HelloWorld: Hello, World!!
   ```
   
   Note that `hello_d` won't build correctly for 64-bit `rv-virt:nsh64`. To 
date, NuttX has never supported 64-bit RISC-V for D Apps: [Build 
Log](https://gist.github.com/lupyuen/e7dbd6ec3ea0a15c87201f75c4334415)
   
   ```text
   $ tools/configure.sh rv-virt:nsh64
   $ kconfig-tweak --enable CONFIG_EXAMPLES_HELLO_D
   $ make olddefconfig
   $ make
   nuttx/staging/libapps.a(hello_d_main.d.apps.examples.hello_d_1.o): in 
function `DHelloWorld::HelloWorld()':
   
apps/examples/hello_d/hello_d_main.d:67:(.text._ZN11DHelloWorld10HelloWorldEv+0x14):
 relocation truncated to fit: R_RISCV_HI20 against `.L.str'
   nuttx/staging/libapps.a(hello_d_main.d.apps.examples.hello_d_1.o): in 
function `hello_d_main':
   apps/examples/hello_d/hello_d_main.d:106:(.text.hello_d_main+0x14): 
relocation truncated to fit: R_RISCV_HI20 against `.L.str.2'
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to