|
| 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 | +``` |
0 commit comments