Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade qemu and integrate qemu-user runners for loongarch64 #1466

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/1466.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "added",
"description": "Upgrade qemu and integrate qemu-user runners for loongarch64-linux-gnu",
"issues": [1467]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ terminate.
| `i686-linux-android` [1] | 9.0.8 | 9.0.8 | ✓ | 6.1.0 | ✓ |
| `i686-pc-windows-gnu` | N/A | 9.4 | ✓ | N/A | ✓ |
| `i686-unknown-linux-gnu` | 2.31 | 9.4.0 | ✓ | 6.1.0 | ✓ |
| `loongarch64-unknown-linux-gnu` | 2.36 | 13.2.0 | ✓ | N/A | |
| `loongarch64-unknown-linux-gnu` | 2.36 | 13.2.0 | ✓ | 8.2.2 | |
| `mips-unknown-linux-gnu` | 2.30 | 9.4.0 | ✓ | 6.1.0 | ✓ |
| `mips-unknown-linux-musl` | 1.2.3 | 9.2.0 | ✓ | 6.1.0 | ✓ |
| `mips64-unknown-linux-gnuabi64` | 2.30 | 9.4.0 | ✓ | 6.1.0 | ✓ |
Expand Down
16 changes: 16 additions & 0 deletions docker/Dockerfile.loongarch64-unknown-linux-gnu
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,31 @@ RUN /crosstool-ng.sh loongarch64-unknown-linux-gnu.config 5

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

COPY deny-debian-packages.sh /
RUN TARGET_ARCH=loong64 /deny-debian-packages.sh

COPY qemu.sh /
RUN /qemu.sh loongarch64

COPY qemu-runner base-runner.sh /
COPY toolchain.cmake /opt/toolchain.cmake

ENV CROSS_TOOLCHAIN_PREFIX=loongarch64-unknown-linux-gnu-
ENV CROSS_SYSROOT=/x-tools/loongarch64-unknown-linux-gnu/loongarch64-unknown-linux-gnu/sysroot/
ENV CROSS_TARGET_RUNNER="/qemu-runner loongarch64"
ENV CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_LINKER="$CROSS_TOOLCHAIN_PREFIX"gcc \
CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_RUNNER="$CROSS_TARGET_RUNNER" \
AR_loongarch64_unknown_linux_gnu="$CROSS_TOOLCHAIN_PREFIX"ar \
CC_loongarch64_unknown_linux_gnu="$CROSS_TOOLCHAIN_PREFIX"gcc \
CXX_loongarch64_unknown_linux_gnu="$CROSS_TOOLCHAIN_PREFIX"g++ \
CMAKE_TOOLCHAIN_FILE_loongarch64_unknown_linux_gnu=/opt/toolchain.cmake \
BINDGEN_EXTRA_CLANG_ARGS_loongarch64_unknown_linux_gnu="--sysroot=$CROSS_SYSROOT -idirafter/usr/include" \
QEMU_LD_PREFIX="$CROSS_SYSROOT" \
RUST_TEST_THREADS=1 \
CROSS_CMAKE_SYSTEM_NAME=Linux \
CROSS_CMAKE_SYSTEM_PROCESSOR=loongarch64 \
CROSS_CMAKE_CRT=gnu \
CROSS_CMAKE_OBJECT_FLAGS="-ffunction-sections -fdata-sections -fPIC"

RUN mv $CROSS_SYSROOT/lib/* $CROSS_SYSROOT/lib64/
RUN sed -e "s#@DEFAULT_QEMU_LD_PREFIX@#$QEMU_LD_PREFIX#g" -i /qemu-runner
29 changes: 29 additions & 0 deletions docker/qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,25 @@ build_static_pixman() {
rm -rf "${td}"
}

build_static_slirp() {
local version=4.1.0

local td
td="$(mktemp -d)"

pushd "${td}"

curl --retry 3 -sSfL "https://gitlab.freedesktop.org/slirp/libslirp//-/archive/v${version}/libslirp-v${version}.tar.gz" -O
tar -xzf "libslirp-v${version}.tar.gz"
meson setup -Ddefault_library=static libslirp-v${version} build
ninja -C build
install -m 644 ./build/libslirp.a /usr/lib64/

popd

rm -rf "${td}"
}

main() {
local version=5.1.0

Expand Down Expand Up @@ -180,6 +199,16 @@ main() {
if_ubuntu install_packages ninja-build
fi

# if we have python3.8+, we can install qemu 8.2.2, which needs ninja-build,
# meson, python3-pip and libslirp-dev.
# ubuntu 16.04 only provides python3.5, so remove when we have a newer qemu.
is_ge_python38=$(python3 -c "import sys; print(int(sys.version_info >= (3, 8)))")
if [[ "${is_ge_python38}" == "1" ]]; then
if_ubuntu version=8.2.2
if_ubuntu install_packages ninja-build meson python3-pip libslirp-dev
if_ubuntu build_static_slirp
fi

local td
td="$(mktemp -d)"

Expand Down
2 changes: 2 additions & 0 deletions targets.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ os = "ubuntu-latest"
cpp = true
dylib = true
std = true
run = true
runners = "qemu-user"

[[target]]
target = "mips-unknown-linux-gnu"
Expand Down
Loading