Skip to content

Commit bc3eb35

Browse files
committed
add platform support details file for armv7-unknown-linux-uclibc
1 parent 11381a5 commit bc3eb35

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

compiler/rustc_codegen_llvm/src/callee.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ pub fn get_fn(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value
175175
// should use dllimport for functions.
176176
if cx.use_dll_storage_attrs
177177
&& tcx.is_dllimport_foreign_item(instance_def_id)
178-
&& tcx.sess.target.env != "gnu"
179-
&& tcx.sess.target.env != "uclibc"
178+
&& !matches!(tcx.sess.target.env.as_ref(), "gnu" | "uclibc")
180179
{
181180
llvm::LLVMSetDLLStorageClass(llfn, llvm::DLLStorageClass::DllImport);
182181
}

compiler/rustc_target/src/spec/armv7_unknown_linux_uclibceabihf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub fn target() -> Target {
1717
cpu: "generic".to_string(),
1818
max_atomic_width: Some(64),
1919
mcount: "_mcount".to_string(),
20+
abi: "eabihf".to_string(),
2021
..base
2122
},
2223
}

library/std/src/sys/unix/process/process_unix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl Command {
419419
}
420420

421421
// Only glibc 2.24+ posix_spawn() supports returning ENOENT directly.
422-
#[cfg(all(target_os = "linux", any(target_env = "gnu", target_env = "uclibc")))]
422+
#[cfg(all(target_os = "linux", target_env = "gnu"))]
423423
{
424424
if let Some(version) = sys::os::glibc_version() {
425425
if version < (2, 24) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# armv7-unknown-linux-uclibceabihf
2+
3+
**Tier: 3**
4+
5+
This tier supports the ARMv7 processor running a Linux kernel and uClibc-ng standard library. It provides full support for rust and the rust standard library.
6+
7+
## Designated Developers
8+
9+
* [@skrap](https://github.com/skrap)
10+
11+
## Requirements
12+
13+
This target is cross compiled, and requires a cross toolchain. You can find suitable pre-built toolchains at [bootlin](https://toolchains.bootlin.com/) or build one yourself via [buildroot](https://buildroot.org).
14+
15+
## Building
16+
17+
### Get a C toolchain
18+
19+
Compiling rust for this target has been tested on `x86_64` linux hosts. Other host types have not been tested, but may work, if you can find a suitable cross compilation toolchain for them.
20+
21+
If you don't already have a suitable toolchain, download one [here](https://toolchains.bootlin.com/downloads/releases/toolchains/armv7-eabihf/tarballs/armv7-eabihf--uclibc--bleeding-edge-2020.08-1.tar.bz2), and unpack it into a directory.
22+
23+
### Configure rust
24+
25+
The target can be built by enabling it for a `rustc` build, by placing the following in `config.toml`:
26+
27+
```toml
28+
[build]
29+
target = ["armv7-unknown-linux-uclibceabihf"]
30+
stage = 2
31+
32+
[target.armv7-unknown-linux-uclibceabihf]
33+
# ADJUST THIS PATH TO POINT AT YOUR TOOLCHAIN
34+
cc = "/TOOLCHAIN_PATH/bin/arm-buildroot-linux-uclibcgnueabihf-gcc"
35+
```
36+
37+
### Build
38+
39+
```sh
40+
# in rust dir
41+
./x.py build --stage 2
42+
```
43+
44+
## Building and Running Rust Programs
45+
46+
To test cross-compiled binaries on a `x86_64` system, you can use the `qemu-arm` [userspace emulation](https://qemu-project.gitlab.io/qemu/user/main.html) program. This avoids having a full emulated ARM system by doing dynamic binary translation and dynamic system call translation. It lets you run ARM programs directly on your `x86_64` kernel. It's very convenient!
47+
48+
To use:
49+
50+
* Install `qemu-arm` according to your distro.
51+
* Link your built toolchain via:
52+
* `rustup toolchain link stage2 ${RUST}/build/x86_64-unknown-linux-gnu/stage2`
53+
* Create a test program
54+
55+
```sh
56+
cargo new hello_world
57+
cd hello_world
58+
```
59+
60+
* Build and run
61+
62+
```sh
63+
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_UCLIBCEABIHF_RUNNER="qemu-arm -L ${TOOLCHAIN}/arm-buildroot-linux-uclibcgnueabihf/sysroot/" \
64+
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_UCLIBCEABIHF_LINKER=${TOOLCHAIN}/bin/arm-buildroot-linux-uclibcgnueabihf-gcc \
65+
cargo +stage2 run --target armv7-unknown-linux-uclibceabihf
66+
```

0 commit comments

Comments
 (0)