]> git.lizzy.rs Git - rust.git/blob - src/doc/rustc/src/platform-support/armv7-unknown-linux-uclibceabi.md
Rollup merge of #106692 - eggyal:mv-binary_heap.rs-binary_heap/mod.rs, r=Mark-Simulacrum
[rust.git] / src / doc / rustc / src / platform-support / armv7-unknown-linux-uclibceabi.md
1 # `armv7-unknown-linux-uclibceabi`
2
3 **Tier: 3**
4
5 This 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
13 This target is cross compiled, and requires a cross toolchain.
14
15 This target supports host tools and std.
16
17 ## Building the target
18
19 You 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
23 Utilizing 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
28 Here is a sample config if using your own toolchain.
29
30 ```toml
31 [build]
32 build-stage = 2
33 target = ["armv7-unknown-linux-uclibceabi"]
34
35 [target.armv7-unknown-linux-uclibceabi]
36 cc = "/path/to/arm-unknown-linux-uclibcgnueabi-gcc"
37 cxx = "/path/to/arm-unknown-linux-uclibcgnueabi-g++"
38 ar = "path/to/arm-unknown-linux-uclibcgnueabi-ar"
39 ranlib = "path/to/arm-unknown-linux-uclibcgnueabi-ranlib"
40 linker = "/path/to/arm-unknown-linux-uclibcgnueabi-gcc"
41 ```
42
43 ## Building Rust programs
44
45 The following assumes you are using the Tomatoware toolchain and environment. Adapt if you are using your own toolchain.
46
47 ### Native compilation
48
49 Since 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
51 To 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
58 If you bootstrap rust on your own using the project above, it will create a .deb file that you then can install with
59 ```text
60 dpkg -i rust_1.xx.x-x_arm.deb
61 ```
62
63 After completing these steps you can use rust normally in a native environment.
64
65 ### Cross Compilation
66
67 To cross compile, you'll need to:
68
69 * Build the rust cross toochain using  [rust-bootstrap-armv7-unknown-linux-uclibceabi](https://github.com/lancethepants/rust-bootstrap-armv7-unknown-linux-uclibceabi) or your own built toolchain.
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
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" \
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' \
85     cargo +stage2 \
86     build \
87     --target armv7-unknown-linux-uclibceabi \
88     --release
89     ```
90 * Copy the binary to your target device and run.
91
92 We 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.
93
94 ### Test with QEMU
95
96 To 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
98 CC_armv7_unknown_linux_uclibceabi=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-gcc \
99 CXX_armv7_unknown_linux_uclibceabi=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-g++ \
100 AR_armv7_unknown_linux_uclibceabi=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-ar \
101 CFLAGS_armv7_unknown_linux_uclibceabi="-march=armv7-a -mtune=cortex-a9" \
102 CXXFLAGS_armv7_unknown_linux_uclibceabi="-march=armv7-a -mtune=cortex-a9" \
103 CARGO_TARGET_ARMV7_UNKNOWN_LINUX_UCLIBCEABI_LINKER=/opt/tomatoware/arm-soft-mmc/bin/arm-linux-gcc \
104 CARGO_TARGET_ARMV7_UNKNOWN_LINUX_UCLIBCEABI_RUNNER="qemu-arm-static -L /opt/tomatoware/arm-soft-mmc/arm-tomatoware-linux-uclibcgnueabi/sysroot/" \
105 cargo +stage2 \
106 run \
107 --target armv7-unknown-linux-uclibceabi \
108 --release
109 ```
110 ### Run in a chroot
111
112 It's also possible to build in a chroot environment. This is a convenient way to work without needing to access the target hardware.
113
114 To 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
122 From 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
129 After completing these steps you can use rust normally in a chroot environment.
130
131 Remember when using `sudo` the root user's PATH could differ from your user's PATH.