]> git.proxmox.com Git - rustc.git/blame - src/doc/rustc/src/platform-support/armv7-unknown-linux-uclibceabi.md
New upstream version 1.71.1+dfsg1
[rustc.git] / src / doc / rustc / src / platform-support / armv7-unknown-linux-uclibceabi.md
CommitLineData
5099ac24
FG
1# `armv7-unknown-linux-uclibceabi`
2
3**Tier: 3**
4
5This target supports ARMv7 softfloat CPUs and uses the uclibc-ng standard library. This is a common configuration on many consumer routers (e.g., Netgear R7000, Asus RT-AC68U).
6
7## Target maintainers
8
9* [@lancethepants](https://github.com/lancethepants)
10
11## Requirements
12
13This target is cross compiled, and requires a cross toolchain.
14
15This target supports host tools and std.
16
17## Building the target
18
19You will need to download or build a `'C'` cross toolchain that targets ARMv7 softfloat and that uses the uclibc-ng standard library. If your target hardware is something like a router or an embedded device, keep in mind that manufacturer supplied SDKs for this class of CPU could be outdated and potentially unsuitable for bootstrapping rust.
20
21[Here](https://github.com/lancethepants/tomatoware-toolchain) is a sample toolchain that is built using [buildroot](https://buildroot.org/). It uses modern toolchain components, older thus universal kernel headers (2.6.36.4), and is used for a project called [Tomatoware](https://github.com/lancethepants/tomatoware). This toolchain is patched so that its sysroot is located at /mmc (e.g., /mmc/bin, /mmc/lib, /mmc/include). This is useful in scenarios where the root filesystem is read-only but you are able attach external storage loaded with user applications. Tomatoware is an example of this that even allows you to run various compilers and developer tools natively on the target device.
22
23Utilizing the Tomatoware toolchain this target can be built for cross compilation and native compilation (host tools) with project
24
25[rust-bootstrap-armv7-unknown-linux-uclibceabi](https://github.com/lancethepants/rust-bootstrap-armv7-unknown-linux-uclibceabi).
26
27
28Here is a sample config if using your own toolchain.
29
30```toml
31[build]
32build-stage = 2
33target = ["armv7-unknown-linux-uclibceabi"]
34
35[target.armv7-unknown-linux-uclibceabi]
36cc = "/path/to/arm-unknown-linux-uclibcgnueabi-gcc"
37cxx = "/path/to/arm-unknown-linux-uclibcgnueabi-g++"
38ar = "path/to/arm-unknown-linux-uclibcgnueabi-ar"
5e7ed085
FG
39ranlib = "path/to/arm-unknown-linux-uclibcgnueabi-ranlib"
40linker = "/path/to/arm-unknown-linux-uclibcgnueabi-gcc"
5099ac24
FG
41```
42
43## Building Rust programs
44
45The following assumes you are using the Tomatoware toolchain and environment. Adapt if you are using your own toolchain.
46
47### Native compilation
48
49Since this target supports host tools, you can natively build rust applications directly on your target device. This can be convenient because it removes the complexities of cross compiling and you can immediately test and deploy your binaries. One downside is that compiling on your ARMv7 CPU will probably be much slower than cross compilation on your x86 machine.
50
51To setup native compilation:
52
53* Download Tomatoware to your device using the latest nightly release found [here](https://files.lancethepants.com/Tomatoware/Nightly/).
54* Extract `tar zxvf arm-soft-mmc.tgz -C /mmc`
55* Add `/mmc/bin:/mmc:sbin/` to your PATH, or `source /mmc/etc/profile`
56* `apt update && apt install rust`
57
58If you bootstrap rust on your own using the project above, it will create a .deb file that you then can install with
59```text
60dpkg -i rust_1.xx.x-x_arm.deb
61```
62
63After completing these steps you can use rust normally in a native environment.
64
65### Cross Compilation
66
67To cross compile, you'll need to:
68
49aad941 69* Build the rust cross toolchain using [rust-bootstrap-armv7-unknown-linux-uclibceabi](https://github.com/lancethepants/rust-bootstrap-armv7-unknown-linux-uclibceabi) or your own built toolchain.
5099ac24
FG
70* Link your built toolchain with
71
72 ```text
73 rustup toolchain link stage2 \
74 ${HOME}/rust-bootstrap-armv7-unknown-linux-uclibceabi/src/rust/rust/build/x86_64-unknown-linux-gnu/stage2
75 ```
76* Build with:
77 ```text
5e7ed085
FG
78 CC_armv7_unknown_linux_uclibceabi=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-gcc \
79 CXX_armv7_unknown_linux_uclibceabi=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-g++ \
80 AR_armv7_unknown_linux_uclibceabi=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-ar \
81 CFLAGS_armv7_unknown_linux_uclibceabi="-march=armv7-a -mtune=cortex-a9" \
82 CXXFLAGS_armv7_unknown_linux_uclibceabi="-march=armv7-a -mtune=cortex-a9" \
5099ac24
FG
83 CARGO_TARGET_ARMV7_UNKNOWN_LINUX_UCLIBCEABI_LINKER=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-gcc \
84 CARGO_TARGET_ARMV7_UNKNOWN_LINUX_UCLIBCEABI_RUSTFLAGS='-Clink-arg=-s -Clink-arg=-Wl,--dynamic-linker=/mmc/lib/ld-uClibc.so.1 -Clink-arg=-Wl,-rpath,/mmc/lib' \
5e7ed085
FG
85 cargo +stage2 \
86 build \
87 --target armv7-unknown-linux-uclibceabi \
88 --release
5099ac24
FG
89 ```
90* Copy the binary to your target device and run.
91
5e7ed085 92We specify `CC`, `CXX`, `AR`, `CFLAGS`, and `CXXFLAGS` environment variables because sometimes a project or a subproject requires the use of your `'C'` cross toolchain. Since Tomatoware has a modified sysroot we also pass via RUSTFLAGS the location of the dynamic-linker and rpath.
5099ac24
FG
93
94### Test with QEMU
95
96To test a cross-compiled binary on your build system follow the instructions for `Cross Compilation`, install `qemu-arm-static`, and run with the following.
97```text
5e7ed085
FG
98CC_armv7_unknown_linux_uclibceabi=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-gcc \
99CXX_armv7_unknown_linux_uclibceabi=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-g++ \
100AR_armv7_unknown_linux_uclibceabi=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-ar \
101CFLAGS_armv7_unknown_linux_uclibceabi="-march=armv7-a -mtune=cortex-a9" \
102CXXFLAGS_armv7_unknown_linux_uclibceabi="-march=armv7-a -mtune=cortex-a9" \
5099ac24
FG
103CARGO_TARGET_ARMV7_UNKNOWN_LINUX_UCLIBCEABI_LINKER=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-gcc \
104CARGO_TARGET_ARMV7_UNKNOWN_LINUX_UCLIBCEABI_RUNNER="qemu-arm-static -L /opt/tomatoware/arm-soft-mmc/arm-tomatoware-linux-uclibcgnueabi/sysroot/" \
5e7ed085
FG
105cargo +stage2 \
106run \
107--target armv7-unknown-linux-uclibceabi \
108--release
5099ac24
FG
109```
110### Run in a chroot
111
112It's also possible to build in a chroot environment. This is a convenient way to work without needing to access the target hardware.
113
114To build the chroot:
115
116* `sudo debootstrap --arch armel bullseye $HOME/debian`
117* `sudo chroot $HOME/debian/ /bin/bash`
118* `mount proc /proc -t proc`
119* `mount -t sysfs /sys sys/`
120* `export PATH=/mmc/bin:/mmc/sbin:$PATH`
121
122From here you can setup your environment (e.g., add user, install wget).
123
124* Download Tomatoware to the chroot environment using the latest nightly release found [here](https://files.lancethepants.com/Tomatoware/Nightly/).
125* Extract `tar zxvf arm-soft-mmc.tgz -C /mmc`
126* Add `/mmc/bin:/mmc:sbin/` to your PATH, or `source /mmc/etc/profile`
127* `sudo /mmc/bin/apt update && sudo /mmc/bin/apt install rust`
128
129After completing these steps you can use rust normally in a chroot environment.
130
131Remember when using `sudo` the root user's PATH could differ from your user's PATH.