Skip to content

Commit

Permalink
Fix riscv64gc-unknown-linux-gnu target (#1525)
Browse files Browse the repository at this point in the history
Fix #1423
  • Loading branch information
Emilgardis authored Jul 11, 2024
2 parents 33c4d26 + b780664 commit 7b79041
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changes/1525.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"description": "Fix riscv64gc-unknown-linux-gnu target",
"issues": [1423],
"type": "fixed"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ terminate.
| `powerpc-unknown-linux-gnu` | 2.31 | 9.4.0 || 6.1.0 ||
| `powerpc64-unknown-linux-gnu` | 2.31 | 9.4.0 || 6.1.0 ||
| `powerpc64le-unknown-linux-gnu` | 2.31 | 9.4.0 || 6.1.0 ||
| `riscv64gc-unknown-linux-gnu` | 2.31 | 9.4.0 || 6.1.0 ||
| `riscv64gc-unknown-linux-gnu` | 2.35 | 11.4.0 || 8.2.2 ||
| `s390x-unknown-linux-gnu` | 2.31 | 9.4.0 || 6.1.0 ||
| `sparc64-unknown-linux-gnu` | 2.31 | 9.4.0 || 6.1.0 ||
| `sparcv9-sun-solaris` | 1.22.7 | 8.4.0 || N/A | |
Expand Down
4 changes: 0 additions & 4 deletions ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ main() {
# don't use xargo: should have native support just from rustc
rustup toolchain add nightly
CROSS+=("+nightly")
elif [[ "${TARGET}" == "riscv64gc-unknown-linux-gnu" ]]; then
# FIXME: riscv64gc-unknown-linux-gnu is broken on rustc 1.75, see https://github.com/cross-rs/cross/issues/1423
rustup toolchain add 1.70
CROSS+=("+1.70")
fi

if (( ${STD:-0} )); then
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.riscv64gc-unknown-linux-gnu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:20.04 as cross-base
FROM ubuntu:22.04 as cross-base
ENV DEBIAN_FRONTEND=noninteractive

COPY common.sh lib.sh /
Expand Down
12 changes: 12 additions & 0 deletions docker/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ if_ubuntu() {
fi
}

if_ubuntu_ge() {
if grep -q -i ubuntu /etc/os-release; then
local ver
ver="$(source /etc/os-release; echo $VERSION_ID)"
if dpkg --compare-versions "$ver" "ge" "$1"; then
shift
eval "${@}"
fi
fi
}


GNU_MIRRORS=(
"https://ftp.gnu.org/gnu/"
"https://ftpmirror.gnu.org/"
Expand Down
13 changes: 9 additions & 4 deletions docker/linux-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ main() {
;;
riscv64)
kernel='6.*-riscv64'
debsource="deb http://ftp.ports.debian.org/debian-ports unstable main"
debsource="${debsource}\ndeb http://ftp.ports.debian.org/debian-ports unreleased main"
debsource="${debsource}\ndeb http://deb.debian.org/debian unstable main"
debsource="deb http://deb.debian.org/debian unstable main"
deps=(libcrypt1:"${arch}")
;;
s390x)
Expand Down Expand Up @@ -365,6 +363,7 @@ mkdir /dev/pts
mount -t devpts none /dev/pts/
# some archs does not have virtio modules
# fscache is builtin on riscv64
insmod /modules/failover.ko || insmod /modules/failover.ko.xz || true
insmod /modules/net_failover.ko || insmod /modules/net_failover.ko.xz || true
insmod /modules/virtio.ko || insmod /modules/virtio.ko.xz || true
Expand All @@ -375,7 +374,7 @@ insmod /modules/virtio_pci_modern_dev.ko || insmod /modules/virtio_pci_modern_de
insmod /modules/virtio_pci.ko || insmod /modules/virtio_pci.ko.xz || true
insmod /modules/virtio_net.ko || insmod /modules/virtio_net.ko.xz || true
insmod /modules/netfs.ko || insmod /modules/netfs.ko.xz || true
insmod /modules/fscache.ko || insmod /modules/fscache.ko.xz
insmod /modules/fscache.ko || insmod /modules/fscache.ko.xz || true
insmod /modules/9pnet.ko || insmod /modules/9pnet.ko.xz
insmod /modules/9pnet_virtio.ko || insmod /modules/9pnet_virtio.ko.xz || true
insmod /modules/9p.ko || insmod /modules/9p.ko.xz
Expand All @@ -390,6 +389,12 @@ mount -t 9p -o trans=virtio target /target -oversion=9p2000.u || true
exec dropbear -F -E -B
EOF

if [[ "${arch}" == "riscv64" ]]; then
# Symlink dynamic loader to /lib/ld-linux-riscv64-lp64d.so.1
mkdir -p "${root}/lib"
ln -s /usr/lib/riscv64-linux-gnu/ld-linux-riscv64-lp64d.so.1 "${root}/lib/ld-linux-riscv64-lp64d.so.1"
fi

chmod +x "${root}/init"
cd "${root}"
find . | cpio --create --format='newc' --quiet | gzip >../initrd.gz
Expand Down
7 changes: 7 additions & 0 deletions docker/qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ build_static_libffi () {
build_static_libmount () {
local version_spec=2.23.2
local version=2.23

if_ubuntu_ge 22.04 version_spec=2.37.2
if_ubuntu_ge 22.04 version=2.37

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

Expand Down Expand Up @@ -191,6 +195,9 @@ main() {
libselinux1-dev \
zlib1g-dev

# ubuntu no longer provides statically linked libmount
if_ubuntu_ge 22.04 build_static_libmount

# if we have python3.6+, we can install qemu 7.0.0, which needs ninja-build
# ubuntu 16.04 only provides python3.5, so remove when we have a newer qemu.
is_ge_python36=$(python3 -c "import sys; print(int(sys.version_info >= (3, 6)))")
Expand Down
3 changes: 3 additions & 0 deletions xtask/src/target_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ case "${target}" in
libc=$(max_glibc_version "${libdir}")
fi
;;
riscv64gc-unknown-linux-gnu)
libc="$(dpkg-query --showformat='${Version}' --show libc6-riscv64-cross | cut -d- -f1)"
;;
*-*-linux-gnu*)
toolchain_prefix="${!cc_var//-gcc/}"
libdir="/usr/${toolchain_prefix}/lib"
Expand Down

0 comments on commit 7b79041

Please sign in to comment.