Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6eacff8

Browse files
authoredAug 1, 2024
Unrolled build for rust-lang#127490
Rollup merge of rust-lang#127490 - ferrocene:hoverbear/add-riscv64gc-unknown-linux-target-page, r=pietroalbini Add target page for riscv64gc-unknown-linux-gnu I was reading rust-lang#113739 and realized I knew most of the information necessary to create the `riscv64gc-unknown-linux-gnu` target page.
2 parents e60ebb2 + 462a48e commit 6eacff8

File tree

3 files changed

+131
-1
lines changed

3 files changed

+131
-1
lines changed
 

‎src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
- [riscv32im-risc0-zkvm-elf](platform-support/riscv32im-risc0-zkvm-elf.md)
6666
- [riscv32imac-unknown-xous-elf](platform-support/riscv32imac-unknown-xous-elf.md)
6767
- [riscv32*-unknown-none-elf](platform-support/riscv32-unknown-none-elf.md)
68+
- [riscv64gc-unknown-linux-gnu](platform-support/riscv64gc-unknown-linux-gnu.md)
6869
- [sparc-unknown-none-elf](./platform-support/sparc-unknown-none-elf.md)
6970
- [*-pc-windows-gnullvm](platform-support/pc-windows-gnullvm.md)
7071
- [\*-nto-qnx-\*](platform-support/nto-qnx.md)

‎src/doc/rustc/src/platform-support.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ target | notes
9797
`powerpc-unknown-linux-gnu` | PowerPC Linux (kernel 3.2, glibc 2.17)
9898
`powerpc64-unknown-linux-gnu` | PPC64 Linux (kernel 3.2, glibc 2.17)
9999
`powerpc64le-unknown-linux-gnu` | PPC64LE Linux (kernel 3.10, glibc 2.17)
100-
`riscv64gc-unknown-linux-gnu` | RISC-V Linux (kernel 4.20, glibc 2.29)
100+
[`riscv64gc-unknown-linux-gnu`](platform-support/riscv64gc-unknown-linux-gnu.md) | RISC-V Linux (kernel 4.20, glibc 2.29)
101101
`s390x-unknown-linux-gnu` | S390x Linux (kernel 3.2, glibc 2.17)
102102
`x86_64-unknown-freebsd` | 64-bit FreeBSD
103103
`x86_64-unknown-illumos` | illumos
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# `riscv64gc-unknown-linux-gnu`
2+
3+
**Tier: 2 (with Host Tools)**
4+
5+
RISC-V targets using the *RV64I* base instruction set with the *G* collection of extensions, as well as the *C* extension.
6+
7+
8+
## Target maintainers
9+
10+
- Kito Cheng, <kito.cheng@gmail.com>, [@kito-cheng](https://github.com/kito-cheng)
11+
- Michael Maitland, <michaeltmaitland@gmail.com>, [@michaelmaitland](https://github.com/michaelmaitland)
12+
- Robin Randhawa, <robin.randhawa@sifive.com>, [@robin-randhawa-sifive](https://github.com/robin-randhawa-sifive)
13+
- Craig Topper, <craig.topper@sifive.com>, [@topperc](https://github.com/topperc)
14+
15+
## Requirements
16+
17+
This target requires:
18+
19+
* Linux Kernel version 4.20 or later
20+
* glibc 2.17 or later
21+
22+
23+
## Building the target
24+
25+
These targets are distributed through `rustup`, and otherwise require no
26+
special configuration.
27+
28+
If you need to build your own Rust for some reason though, the targets can be
29+
enabled in `config.toml`. For example:
30+
31+
```toml
32+
[build]
33+
target = ["riscv64gc-unknown-linux-gnu"]
34+
```
35+
36+
37+
## Building Rust programs
38+
39+
40+
On a RISC-V host, the `riscv64gc-unknown-linux-gnu` target should be automatically
41+
installed and used by default.
42+
43+
On a non-RISC-V host, add the target:
44+
45+
```bash
46+
rustup target add riscv64gc-unknown-linux-gnu
47+
```
48+
49+
Then cross compile crates with:
50+
51+
```bash
52+
cargo build --target riscv64gc-unknown-linux-gnu
53+
```
54+
55+
56+
## Testing
57+
58+
There are no special requirements for testing and running the targets.
59+
For testing cross builds on the host, please refer to the "Cross-compilation
60+
toolchains and C code"
61+
section below.
62+
63+
64+
## Cross-compilation toolchains and C code
65+
66+
A RISC-V toolchain can be obtained for Windows/Mac/Linux from the
67+
[`riscv-gnu-toolchain`](https://github.com/riscv-collab/riscv-gnu-toolchain)
68+
repostory. Binaries are available via
69+
[embecosm](https://www.embecosm.com/resources/tool-chain-downloads/#riscv-linux),
70+
and may also be available from your OS's package manager.
71+
72+
On Ubuntu, a RISC-V toolchain can be installed with:
73+
74+
```bash
75+
apt install gcc-riscv64-linux-gnu g++-riscv64-linux-gnu libc6-dev-riscv64-cross
76+
```
77+
78+
Depending on your system, you may need to configure the target to use the GNU
79+
GCC linker. To use it, add the following to your `.cargo/config.toml`:
80+
81+
```toml
82+
[target.riscv64gc-unknown-linux-gnu]
83+
linker = "riscv64-linux-gnu-gcc"
84+
```
85+
86+
If your `riscv64-linux-gnu-*` toolchain is not in your `PATH` you may need to
87+
configure additional settings:
88+
89+
```toml
90+
[target.riscv64gc-unknown-linux-gnu]
91+
# Adjust the paths to point at your toolchain
92+
cc = "/TOOLCHAIN_PATH/bin/riscv64-linux-gnu-gcc"
93+
cxx = "/TOOLCHAIN_PATH/bin/riscv64-linux-gnu-g++"
94+
ar = "/TOOLCHAIN_PATH/bin/riscv64-linux-gnu-ar"
95+
ranlib = "/TOOLCHAIN_PATH/bin/riscv64-linux-gnu-ranlib"
96+
linker = "/TOOLCHAIN_PATH/bin/riscv64-linux-gnu-gcc"
97+
```
98+
99+
To test cross compiled binaries on a non-RISCV-V host, you can use
100+
[`qemu`](https://www.qemu.org/docs/master/system/target-riscv.html).
101+
On Ubuntu, a RISC-V emulator can be obtained with:
102+
103+
```bash
104+
apt install qemu-system-riscv64
105+
```
106+
107+
Then, in `.cargo/config.toml` set the `runner`:
108+
109+
```toml
110+
[target.riscv64gc-unknown-linux-gnu]
111+
runner = "qemu-riscv64-static -L /usr/riscv64-linux-gnu -cpu rv64"
112+
```
113+
114+
On Mac and Linux, it's also possible to use
115+
[`lima`](https://github.com/lima-vm/lima) to emulate RISC-V in a similar way to
116+
how WSL2 works on Windows:
117+
118+
```bash
119+
limactl start template://riscv
120+
limactl shell riscv
121+
```
122+
123+
Using [Docker (with BuildKit)](https://docs.docker.com/build/buildkit/) the
124+
[`riscv64/ubuntu`](https://hub.docker.com/r/riscv64/ubuntu) image can be used
125+
to buiild or run `riscv64gc-unknown-linux-gnu` binaries.
126+
127+
```bash
128+
docker run --platform linux/riscv64 -ti --rm --mount "type=bind,src=$(pwd),dst=/checkout" riscv64/ubuntu bash
129+
```

0 commit comments

Comments
 (0)
Failed to load comments.