Skip to content

Commit 2112cdc

Browse files
authored
Unrolled build for rust-lang#121412
Rollup merge of rust-lang#121412 - androm3da:bcain/update_hex_docs_03, r=Amanieu platform docs: clarify hexagon-unknown-none-elf example, add hexagon-unknown-linux-musl
2 parents 71a7b66 + cd47739 commit 2112cdc

File tree

4 files changed

+121
-5
lines changed

4 files changed

+121
-5
lines changed

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
- [\*-unknown-fuchsia](platform-support/fuchsia.md)
4040
- [\*-kmc-solid_\*](platform-support/kmc-solid.md)
4141
- [csky-unknown-linux-gnuabiv2\*](platform-support/csky-unknown-linux-gnuabiv2.md)
42+
- [hexagon-unknown-linux-musl](platform-support/hexagon-unknown-linux-musl.md)
4243
- [hexagon-unknown-none-elf](platform-support/hexagon-unknown-none-elf.md)
4344
- [loongarch\*-unknown-linux-\*](platform-support/loongarch-linux.md)
4445
- [loongarch\*-unknown-none\*](platform-support/loongarch-none.md)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ target | std | host | notes
286286
`bpfel-unknown-none` | * | | BPF (little endian)
287287
`csky-unknown-linux-gnuabiv2` | ✓ | | C-SKY abiv2 Linux (little endian)
288288
`csky-unknown-linux-gnuabiv2hf` | ✓ | | C-SKY abiv2 Linux, hardfloat (little endian)
289-
[`hexagon-unknown-none-elf`](platform-support/hexagon-unknown-none-elf.md)| * | Bare Hexagon (v60+, HVX)
290-
`hexagon-unknown-linux-musl` | ? | |
289+
[`hexagon-unknown-none-elf`](platform-support/hexagon-unknown-none-elf.md)| * | | Bare Hexagon (v60+, HVX)
290+
[`hexagon-unknown-linux-musl`](platform-support/hexagon-unknown-linux-musl.md) | | | Hexagon Linux
291291
`i386-apple-ios` | ✓ | | 32-bit x86 iOS [^x86_32-floats-return-ABI]
292292
[`i586-pc-nto-qnx700`](platform-support/nto-qnx.md) | * | | 32-bit x86 QNX Neutrino 7.0 RTOS [^x86_32-floats-return-ABI]
293293
[`i586-unknown-netbsd`](platform-support/netbsd.md) | ✓ | | 32-bit x86, restricted to Pentium
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# `hexagon-unknown-linux-musl`
2+
3+
**Tier: 3**
4+
5+
Target for cross-compiling Linux user-mode applications targeting the Hexagon
6+
DSP architecture.
7+
8+
| Target | Descriptions |
9+
| ------------------------ | ----------------------------------------- |
10+
| hexagon-unknown-linux-musl | Hexagon 32-bit Linux |
11+
12+
## Target maintainers
13+
14+
- [Brian Cain](https://github.com/androm3da), `[email protected]`
15+
16+
## Requirements
17+
The target is cross-compiled. This target supports `std`. By default, code
18+
generated with this target should run on Hexagon DSP hardware.
19+
20+
- `-Ctarget-cpu=hexagonv73` adds support for instructions defined up to Hexagon V73.
21+
22+
Binaries can be run using QEMU user emulation. On Debian-based systems, it should be
23+
sufficient to install the package `qemu-user-static` to be able to run simple static
24+
binaries:
25+
26+
```text
27+
# apt install qemu-user-static
28+
# qemu-hexagon-static ./hello
29+
```
30+
31+
In order to build linux programs with Rust, you will require a linker capable
32+
of targeting hexagon. You can use `clang`/`lld` from the [hexagon toolchain
33+
using exclusively public open source repos](https://github.com/quic/toolchain_for_hexagon/releases).
34+
35+
Also included in that toolchain is the C library that can be used when creating
36+
dynamically linked executables.
37+
38+
```text
39+
# /opt/clang+llvm-18.1.0-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/bin/qemu-hexagon -L /opt/clang+llvm-18.1.0-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/target/hexagon-unknown-linux-musl/usr/ ./hello
40+
```
41+
42+
## Building the target
43+
Because it is Tier 3, rust does not yet ship pre-compiled artifacts for this
44+
target.
45+
46+
Therefore, you can build Rust with support for the target by adding it to the
47+
target list in `config.toml`, a sample configuration is shown below.
48+
49+
```toml
50+
[build]
51+
target = [ "hexagon-unknown-linux-musl"]
52+
53+
[target.hexagon-unknown-linux-musl]
54+
55+
cc = "hexagon-unknown-linux-musl-clang"
56+
cxx = "hexagon-unknown-linux-musl-clang++"
57+
linker = "hexagon-unknown-linux-musl-clang"
58+
ar = "hexagon-unknown-linux-musl-ar"
59+
ranlib = "hexagon-unknown-linux-musl-ranlib"
60+
musl-root = "/opt/clang+llvm-18.1.0-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/target/hexagon-unknown-linux-musl/usr"
61+
llvm-libunwind = 'in-tree'
62+
qemu-rootfs = "/opt/clang+llvm-18.1.0-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/target/hexagon-unknown-linux-musl/usr"
63+
```
64+
65+
66+
## Testing
67+
68+
Currently there is no support to run the rustc test suite for this target.
69+
70+
71+
## Building Rust programs
72+
73+
Download and install the hexagon open source toolchain from https://github.com/quic/toolchain_for_hexagon/releases
74+
75+
The following `.cargo/config` is needed inside any project directory to build
76+
for the Hexagon Linux target:
77+
78+
```toml
79+
[build]
80+
target = "hexagon-unknown-linux-musl"
81+
82+
[target.hexagon-unknown-linux-musl]
83+
linker = "hexagon-unknown-linux-musl-clang"
84+
ar = "hexagon-unknown-linux-musl-ar"
85+
runner = "qemu-hexagon -L /opt/clang+llvm-18.1.0-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/target/hexagon-unknown-linux-musl/usr"
86+
```
87+
88+
Edit the "runner" in `.cargo/config` to point to the path to your toolchain's
89+
C library.
90+
91+
```text
92+
...
93+
runner = "qemu-hexagon -L /path/to/my/inst/clang+llvm-18.1.0-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/target/hexagon-unknown-linux-musl/usr"
94+
...
95+
```
96+
97+
Build/run your rust program with `qemu-hexagon` in your `PATH`:
98+
99+
```text
100+
export PATH=/path/to/my/inst/clang+llvm-18.1.0-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/bin/:$PATH
101+
cargo run -Zbuild-std -Zbuild-std-features=llvm-libunwind
102+
```

src/doc/rustc/src/platform-support/hexagon-unknown-none-elf.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ target = ["<target for your host>", "hexagon-unknown-none-elf"]
4141
cc = "hexagon-unknown-none-elf-clang"
4242
cxx = "hexagon-unknown-none-elf-clang++"
4343
linker = "hexagon-unknown-none-elf-clang"
44+
ranlib = "hexagon-unknown-none-elf-ranlib"
45+
ar = "hexagon-unknown-none-elf-ar"
4446
llvm-libunwind = 'in-tree'
4547
```
4648

@@ -142,7 +144,7 @@ ${cc} --target=hexagon-unknown-none-elf -o testit \
142144
${g0_lib_path}/init.o \
143145
-L${sdk_libs}/${q6_arch}/ \
144146
-L${sdk_libs}/ \
145-
testit.c \
147+
wrap.c \
146148
target/hexagon-unknown-none-elf/${build_cfg}/libdemo1_hexagon.rlib \
147149
target/hexagon-unknown-none-elf/${build_cfg}/deps/libcore-*.rlib \
148150
target/hexagon-unknown-none-elf/${build_cfg}/deps/libcompiler_builtins-*.rlib \
@@ -217,7 +219,18 @@ fn rust_eh_personality() {}
217219
218220
```
219221

220-
Next, save the script below as `build.sh` and edit it to suit your
222+
Next, create a C program as an entry point, save the content below as
223+
`wrap.c`:
224+
225+
```C
226+
int hello();
227+
228+
int main() {
229+
hello();
230+
}
231+
```
232+
233+
Then, save the script below as `build.sh` and edit it to suit your
221234
environment. The script below will build a shared object against the QuRT
222235
RTOS which is suitable for emulation or on-device testing when loaded via
223236
the fastrpc-shell.
@@ -248,7 +261,7 @@ ${cc} --target=hexagon-unknown-none-elf -o testit.so \
248261
-Wl,--wrap=realloc \
249262
-Wl,--wrap=memalign \
250263
-m${q6_arch} \
251-
testit.c \
264+
wrap.c \
252265
target/hexagon-unknown-none-elf/${build_cfg}/libdemo2_hexagon.rlib \
253266
target/hexagon-unknown-none-elf/${build_cfg}/deps/libcore-*.rlib \
254267
target/hexagon-unknown-none-elf/${build_cfg}/deps/libcompiler_builtins-*.rlib \

0 commit comments

Comments
 (0)