Skip to content

Commit 82a53af

Browse files
authored
Upgrade qemu and integrate qemu-user runners for loongarch64 (#1466)
Even though the Debian/LoongArch port is still in progress, qemu-user is now available. This PR upgrades qemu to version `8.2.2` and incorporates qemu-user runners for the `loongarch64-unknown-linux-gnu` target. Close #1467
2 parents 49b3245 + ab48325 commit 82a53af

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

.changes/1466.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": "Upgrade qemu and integrate qemu-user runners for loongarch64-linux-gnu",
4+
"issues": [1467]
5+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ terminate.
224224
| `i686-linux-android` [1] | 9.0.8 | 9.0.8 || 6.1.0 ||
225225
| `i686-pc-windows-gnu` | N/A | 9.4 || N/A ||
226226
| `i686-unknown-linux-gnu` | 2.31 | 9.4.0 || 6.1.0 ||
227-
| `loongarch64-unknown-linux-gnu` | 2.36 | 13.2.0 || N/A | |
227+
| `loongarch64-unknown-linux-gnu` | 2.36 | 13.2.0 || 8.2.2 | |
228228
| `mips-unknown-linux-gnu` | 2.30 | 9.4.0 || 6.1.0 ||
229229
| `mips-unknown-linux-musl` | 1.2.3 | 9.2.0 || 6.1.0 ||
230230
| `mips64-unknown-linux-gnuabi64` | 2.30 | 9.4.0 || 6.1.0 ||

docker/Dockerfile.loongarch64-unknown-linux-gnu

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,31 @@ RUN /crosstool-ng.sh loongarch64-unknown-linux-gnu.config 5
1919

2020
ENV PATH /x-tools/loongarch64-unknown-linux-gnu/bin/:$PATH
2121

22+
COPY deny-debian-packages.sh /
23+
RUN TARGET_ARCH=loong64 /deny-debian-packages.sh
24+
25+
COPY qemu.sh /
26+
RUN /qemu.sh loongarch64
27+
28+
COPY qemu-runner base-runner.sh /
2229
COPY toolchain.cmake /opt/toolchain.cmake
2330

2431
ENV CROSS_TOOLCHAIN_PREFIX=loongarch64-unknown-linux-gnu-
32+
ENV CROSS_SYSROOT=/x-tools/loongarch64-unknown-linux-gnu/loongarch64-unknown-linux-gnu/sysroot/
33+
ENV CROSS_TARGET_RUNNER="/qemu-runner loongarch64"
2534
ENV CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_LINKER="$CROSS_TOOLCHAIN_PREFIX"gcc \
35+
CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_RUNNER="$CROSS_TARGET_RUNNER" \
2636
AR_loongarch64_unknown_linux_gnu="$CROSS_TOOLCHAIN_PREFIX"ar \
2737
CC_loongarch64_unknown_linux_gnu="$CROSS_TOOLCHAIN_PREFIX"gcc \
2838
CXX_loongarch64_unknown_linux_gnu="$CROSS_TOOLCHAIN_PREFIX"g++ \
2939
CMAKE_TOOLCHAIN_FILE_loongarch64_unknown_linux_gnu=/opt/toolchain.cmake \
40+
BINDGEN_EXTRA_CLANG_ARGS_loongarch64_unknown_linux_gnu="--sysroot=$CROSS_SYSROOT -idirafter/usr/include" \
41+
QEMU_LD_PREFIX="$CROSS_SYSROOT" \
42+
RUST_TEST_THREADS=1 \
3043
CROSS_CMAKE_SYSTEM_NAME=Linux \
3144
CROSS_CMAKE_SYSTEM_PROCESSOR=loongarch64 \
3245
CROSS_CMAKE_CRT=gnu \
3346
CROSS_CMAKE_OBJECT_FLAGS="-ffunction-sections -fdata-sections -fPIC"
47+
48+
RUN mv $CROSS_SYSROOT/lib/* $CROSS_SYSROOT/lib64/
49+
RUN sed -e "s#@DEFAULT_QEMU_LD_PREFIX@#$QEMU_LD_PREFIX#g" -i /qemu-runner

docker/qemu.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,25 @@ build_static_pixman() {
109109
rm -rf "${td}"
110110
}
111111

112+
build_static_slirp() {
113+
local version=4.1.0
114+
115+
local td
116+
td="$(mktemp -d)"
117+
118+
pushd "${td}"
119+
120+
curl --retry 3 -sSfL "https://gitlab.freedesktop.org/slirp/libslirp//-/archive/v${version}/libslirp-v${version}.tar.gz" -O
121+
tar -xzf "libslirp-v${version}.tar.gz"
122+
meson setup -Ddefault_library=static libslirp-v${version} build
123+
ninja -C build
124+
install -m 644 ./build/libslirp.a /usr/lib64/
125+
126+
popd
127+
128+
rm -rf "${td}"
129+
}
130+
112131
main() {
113132
local version=5.1.0
114133

@@ -180,6 +199,16 @@ main() {
180199
if_ubuntu install_packages ninja-build
181200
fi
182201

202+
# if we have python3.8+, we can install qemu 8.2.2, which needs ninja-build,
203+
# meson, python3-pip and libslirp-dev.
204+
# ubuntu 16.04 only provides python3.5, so remove when we have a newer qemu.
205+
is_ge_python38=$(python3 -c "import sys; print(int(sys.version_info >= (3, 8)))")
206+
if [[ "${is_ge_python38}" == "1" ]]; then
207+
if_ubuntu version=8.2.2
208+
if_ubuntu install_packages ninja-build meson python3-pip libslirp-dev
209+
if_ubuntu build_static_slirp
210+
fi
211+
183212
local td
184213
td="$(mktemp -d)"
185214

targets.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ os = "ubuntu-latest"
120120
cpp = true
121121
dylib = true
122122
std = true
123+
run = true
124+
runners = "qemu-user"
123125

124126
[[target]]
125127
target = "mips-unknown-linux-gnu"

0 commit comments

Comments
 (0)