Skip to content

Commit f550fd5

Browse files
Alexhuszaghoooohhoo
andcommitted
Add CentOS7-compatible target for aarch64.
Co-authored-by: oooohhoo <oooohhoo@users.noreply.github.com>
1 parent 47df5c7 commit f550fd5

File tree

6 files changed

+174
-0
lines changed

6 files changed

+174
-0
lines changed

.changes/1006.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "added",
3+
"description": "add CentOS7-compatible target for aarch64",
4+
"issues": [528]
5+
}

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ jobs:
210210
- { target: thumbv7m-none-eabi, os: ubuntu-latest, std: 1 }
211211
- { target: cross, os: ubuntu-latest }
212212
- { target: zig, os: ubuntu-latest }
213+
- { target: aarch64-unknown-linux-gnu, sub: centos, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1, runners: qemu-user qemu-system }
214+
213215
214216
build:
215217
name: target (${{ matrix.pretty }},${{ matrix.os }})

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ terminate.
321321
|--------------------------------------|-------:|--------:|:---:|------:|:------:|
322322
| `aarch64-linux-android` [1] | 9.0.8 | 9.0.8 || 6.1.0 ||
323323
| `aarch64-unknown-linux-gnu` | 2.31 | 9.4.0 || 6.1.0 ||
324+
| `aarch64-unknown-linux-gnu:centos` [7] | 2.17 | 4.8.5 | | 4.2.1 ||
324325
| `aarch64-unknown-linux-musl` | 1.1.24 | 9.2.0 || 6.1.0 ||
325326
| `arm-linux-androideabi` [1] | 9.0.8 | 9.0.8 || 6.1.0 ||
326327
| `arm-unknown-linux-gnueabi` | 2.31 | 9.4.0 || 6.1.0 ||
@@ -392,6 +393,8 @@ terminate.
392393

393394
[6] libc = emscripten and GCC = clang
394395

396+
[7] Must change `image = "aarch64-unknown-linux-gnu:main-centos"` in `Cross.toml` for `[target.aarch64-unknown-linux-gnu]` to use the CentOS7-compatible target.
397+
395398
<!--[7] libc = emscripten and GCC = clang. The Docker images for these targets are currently not built automatically
396399
due to a [compiler bug](https://github.com/rust-lang/rust/issues/98216), you will have to build them yourself for now.-->
397400

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM ubuntu:20.04
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
5+
COPY lib.sh /
6+
COPY linux-image.sh /
7+
RUN /linux-image.sh aarch64
8+
9+
FROM centos:7
10+
11+
COPY common.sh lib.sh /
12+
RUN /common.sh
13+
14+
COPY cmake.sh /
15+
RUN /cmake.sh
16+
17+
COPY xargo.sh /
18+
RUN /xargo.sh
19+
20+
COPY qemu.sh /
21+
RUN /qemu.sh aarch64 softmmu
22+
23+
COPY dropbear.sh /
24+
RUN /dropbear.sh
25+
26+
COPY --from=0 /qemu /qemu
27+
28+
COPY linux-runner base-runner.sh /
29+
30+
COPY aarch64-linux-gnu-glibc.sh /
31+
RUN /aarch64-linux-gnu-glibc.sh
32+
33+
34+
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
35+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER="/linux-runner aarch64" \
36+
CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \
37+
CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ \
38+
BINDGEN_EXTRA_CLANG_ARGS_aarch64_unknown_linux_gnu="--sysroot=/usr/aarch64-linux-gnu" \
39+
QEMU_LD_PREFIX=/usr/aarch64-linux-gnu \
40+
RUST_TEST_THREADS=1

docker/aarch64-linux-gnu-glibc.sh

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/usr/bin/env bash
2+
3+
set -x
4+
set -euo pipefail
5+
6+
unpack_rpm() {
7+
local package="${1}"
8+
curl --retry 3 "http://mirror.centos.org/altarch/7/os/aarch64/Packages/${package}" -O
9+
rpm2cpio "${package}" | cpio -idmv
10+
}
11+
12+
symlink_gcc_lib() {
13+
local prefix="${1}"
14+
shift
15+
local srcfile="${1}"
16+
shift
17+
local dstdir="/usr/lib/gcc/aarch64-linux-gnu"
18+
19+
ln -s "${prefix}/lib/${srcfile}" "${dstdir}/4.8.2/${srcfile}"
20+
ln -s "${prefix}/lib/${srcfile}" "${dstdir}/4.8.5/${srcfile}"
21+
22+
local dstfile
23+
for dstfile in "${@}"; do
24+
ln -s "${prefix}/lib/${srcfile}" "${dstdir}/4.8.2/${dstfile}"
25+
ln -s "${prefix}/lib/${srcfile}" "${dstdir}/4.8.5/${dstfile}"
26+
done
27+
}
28+
29+
cp_gcc_archive() {
30+
local name="${1}"
31+
local srcdir="usr/lib/gcc/aarch64-redhat-linux/"
32+
local dstdir="/usr/lib/gcc/aarch64-linux-gnu/"
33+
cp "${srcdir}/4.8.2/${name}" "${dstdir}/4.8.2/${name}"
34+
cp "${srcdir}/4.8.5/${name}" "${dstdir}/4.8.5/${name}"
35+
}
36+
37+
main() {
38+
yum install -y epel-release
39+
yum install -y gcc-aarch64-linux-gnu gcc-c++-aarch64-linux-gnu binutils-aarch64-linux-gnu binutils gcc-c++ glibc-devel
40+
yum clean all
41+
42+
local td
43+
td="$(mktemp -d)"
44+
45+
pushd "${td}"
46+
47+
local target=aarch64-linux-gnu
48+
local prefix="/usr/${target}"
49+
local kernel_v4="4.18.20"
50+
51+
curl --retry 3 "https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-${kernel_v4}.tar.xz" -O
52+
tar -xvf "linux-${kernel_v4}.tar.xz"
53+
pushd "linux-${kernel_v4}"
54+
make ARCH=arm64 INSTALL_HDR_PATH="${prefix}" headers_install
55+
popd
56+
57+
curl --retry 3 http://ftp.gnu.org/gnu/glibc/glibc-2.17.tar.xz -O
58+
tar -xvf glibc-2.17.tar.xz
59+
mkdir build
60+
pushd build
61+
CC=/usr/bin/aarch64-linux-gnu-gcc \
62+
CXX=/usr/bin/aarch64-linux-gnu-g++ \
63+
LD=/usr/bin/aarch64-linux-gnu-ld \
64+
AR=/usr/bin/aarch64-linux-gnu-ar \
65+
RANLIB=/usr/bin/aarch64-linux-gnu-ranlib \
66+
../glibc-2.17/configure \
67+
--prefix="${prefix}" \
68+
--build="${MACHTYPE}" \
69+
--host="${target}" \
70+
--target="${target}" \
71+
--with-arch=aarch64 \
72+
--with-headers="${prefix}/include" \
73+
--libdir="${prefix}/lib" \
74+
--libexecdir="${prefix}/lib"
75+
76+
make -j && make install
77+
popd
78+
79+
mkdir -p "${prefix}"/{include,lib}
80+
mkdir -p "/usr/lib/gcc/aarch64-linux-gnu"/{4.8.2,4.8.5}
81+
82+
mkdir libgcc
83+
pushd libgcc
84+
unpack_rpm "libgcc-4.8.5-44.el7.aarch64.rpm"
85+
mv lib64/* "${prefix}/lib"
86+
# C++ support needs `libgcc.so`, even though it warns about `libgcc_s.so`
87+
symlink_gcc_lib "${prefix}" "libgcc_s.so.1" "libgcc_s.so" "libgcc.so"
88+
popd
89+
90+
mkdir libstdcpp
91+
pushd libstdcpp
92+
unpack_rpm "libstdc++-4.8.5-44.el7.aarch64.rpm"
93+
unpack_rpm "libstdc++-devel-4.8.5-44.el7.aarch64.rpm"
94+
unpack_rpm "libstdc++-static-4.8.5-44.el7.aarch64.rpm"
95+
mv usr/include/* "${prefix}/include"
96+
mv usr/lib64/* "${prefix}/lib"
97+
symlink_gcc_lib "${prefix}" "libstdc++.so.6" "libstdc++.so"
98+
cp_gcc_archive "libstdc++.a"
99+
cp_gcc_archive "libsupc++.a"
100+
popd
101+
102+
local cpp_include=/usr/aarch64-linux-gnu/include/c++
103+
local cpp_482="${cpp_include}/4.8.2"
104+
local cpp_485="${cpp_include}/4.8.5"
105+
local redhat_482="${cpp_482}/aarch64-redhat-linux"
106+
local redhat_485="${cpp_485}/aarch64-redhat-linux"
107+
mv "${redhat_482}/bits"/* "${cpp_482}/bits"
108+
mv "${redhat_482}/ext"/* "${cpp_482}/ext"
109+
# these are currently empty, but might contain content later
110+
mv "${redhat_485}/bits"/* "${cpp_485}/bits" || true
111+
mv "${redhat_485}/ext"/* "${cpp_485}/ext" || true
112+
113+
popd
114+
115+
rm -rf "${td}"
116+
rm "${0}"
117+
}
118+
119+
main "${@}"

src/docker/provided_images.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,9 @@ pub static PROVIDED_IMAGES: &[ProvidedImage] = &[
278278
platforms: &[ImagePlatform::DEFAULT],
279279
sub: None
280280
},
281+
ProvidedImage {
282+
name: "aarch64-unknown-linux-gnu",
283+
platforms: &[ImagePlatform::DEFAULT],
284+
sub: Some("centos")
285+
},
281286
];

0 commit comments

Comments
 (0)