riscv64gc-unknown-linux-gnu
Tier: 2 (with Host Tools)
Linux GNU libc RISC-V target using the RV64I base instruction set with the G collection of extensions, as well as the C extension.
Target maintainers
@kito-cheng @michaelmaitland @robin-randhawa-sifive @topperc
Requirements
This target requires:
- Linux Kernel version 4.20 or later
- glibc 2.17 or later
Building the target
This target is distributed through rustup, and otherwise requires no
special configuration.
If you need to build your own Rust for some reason though, the target can be
enabled in bootstrap.toml. For example:
[build]
target = ["riscv64gc-unknown-linux-gnu"]
Building Rust programs
On a riscv64gc-unknown-linux-gnu host, the riscv64gc-unknown-linux-gnu
target should be automatically installed and used by default.
On all other hosts, add the target:
Then cross compile crates with:
Testing
There are no special requirements for testing and running the target. For testing cross builds on the host, please refer to the "Cross-compilation toolchains and C code" section below.
Cross-compilation toolchains and C code
A RISC-V toolchain can be obtained for Windows/Mac/Linux from the
riscv-gnu-toolchain
repository. Binaries are available via
embecosm,
and may also be available from your OS's package manager.
On Ubuntu, a RISC-V toolchain can be installed with:
Depending on your system, you may need to configure the target to use the GNU
GCC linker. To use it, add the following to your .cargo/config.toml:
[target.riscv64gc-unknown-linux-gnu]
linker = "riscv64-linux-gnu-gcc"
If your riscv64-linux-gnu-* toolchain is not in your PATH you may need to
configure additional settings:
[target.riscv64gc-unknown-linux-gnu]
# Adjust the paths to point at your toolchain
cc = "/TOOLCHAIN_PATH/bin/riscv64-linux-gnu-gcc"
cxx = "/TOOLCHAIN_PATH/bin/riscv64-linux-gnu-g++"
ar = "/TOOLCHAIN_PATH/bin/riscv64-linux-gnu-ar"
ranlib = "/TOOLCHAIN_PATH/bin/riscv64-linux-gnu-ranlib"
linker = "/TOOLCHAIN_PATH/bin/riscv64-linux-gnu-gcc"
To test cross compiled binaries on a non-RISCV-V host, you can use
qemu.
On Ubuntu, a RISC-V emulator can be obtained with:
Then, in .cargo/config.toml set the runner:
[target.riscv64gc-unknown-linux-gnu]
runner = "qemu-riscv64-static -L /usr/riscv64-linux-gnu -cpu rv64"
On Mac and Linux, it's also possible to use
lima to emulate RISC-V in a similar way to
how WSL2 works on Windows:
Using Docker (with BuildKit) the
riscv64/ubuntu image can be used
to build or run riscv64gc-unknown-linux-gnu binaries.