Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools/[Rust|D]: Fix the Rust and D Builds for QEMU RISC-V #70

Closed
wants to merge 8 commits into from

Conversation

lupyuen
Copy link

@lupyuen lupyuen commented Aug 6, 2024

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. 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, 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/platforms/ubuntu.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

$ 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 is missing: Build Log

$ 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

$ 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

$ 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'

@lupyuen lupyuen changed the title safer-rust-blinky3 tools/Rust.defs: Fix the Rust Build for QEMU RISC-V 64-bit Aug 6, 2024
@lupyuen lupyuen changed the title tools/Rust.defs: Fix the Rust Build for QEMU RISC-V 64-bit tools/[Rust | D]: Fix the Rust Build for QEMU RISC-V 64-bit Aug 6, 2024
@lupyuen lupyuen changed the title tools/[Rust | D]: Fix the Rust Build for QEMU RISC-V 64-bit tools/[Rust|D]: Fix the Rust Build for QEMU RISC-V 64-bit Aug 6, 2024
@lupyuen lupyuen changed the title tools/[Rust|D]: Fix the Rust Build for QEMU RISC-V 64-bit tools/[Rust|D]: Fix the Rust and D Builds for QEMU RISC-V Aug 6, 2024
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
@lupyuen lupyuen closed this Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant