qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: WANG Xuerui <git@xen0n.name>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"XiaoJuan Yang" <yangxiaojuan@loongson.cn>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Laurent Vivier" <laurent@vivier.eu>,
	"WANG Xuerui" <git@xen0n.name>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Song Gao" <gaosong@loongson.cn>
Subject: [PATCH v9 31/31] tests/docker: Add gentoo-loongarch64-cross image and run cross builds in GitLab
Date: Tue, 14 Dec 2021 16:01:54 +0800	[thread overview]
Message-ID: <20211214080154.196350-32-git@xen0n.name> (raw)
In-Reply-To: <20211214080154.196350-1-git@xen0n.name>

Normally this would be based on qemu/debian10 or qemu/ubuntu2004, but
after a week-long struggle, I still cannot build stage2 gcc with the
known-good LoongArch toolchain sources, so I chose the least-resistance
path with Gentoo as base image. As this image is not expected to be
re-built by CI, like hexagon, it should not take much maintenance
effort; also it's expected to be replaced as soon as Debian is
available.

As the LoongArch target has not been merged yet, a check-tcg job is not
added at the moment, but cross builds with the TCG port are already
possible, and added to CI matrix.

Due to constant flux of the toolchain sources used (especially that of
glibc), the binaries built with this image could currently segfault when
run on actual hardware. This image is expected to be updated once a
known-good combination is again verified.

As a reference, the image takes about 27 minutes to rebuild on a
Threadripper 3990X system with Docker operating on HDD; YMMV but it
probably wouldn't become significantly shorter, as everything needs to
be built from source in our case.

Signed-off-by: WANG Xuerui <git@xen0n.name>
---
 .gitlab-ci.d/container-cross.yml              |  27 ++++
 .gitlab-ci.d/crossbuilds.yml                  |  19 +++
 MAINTAINERS                                   |   2 +
 tests/docker/Makefile.include                 |  21 +++
 .../gentoo-loongarch64-cross.docker           |  19 +++
 .../build-toolchain.sh                        | 125 ++++++++++++++++++
 6 files changed, 213 insertions(+)
 create mode 100644 tests/docker/dockerfiles/gentoo-loongarch64-cross.docker
 create mode 100755 tests/docker/dockerfiles/gentoo-loongarch64-cross.docker.d/build-toolchain.sh

diff --git a/.gitlab-ci.d/container-cross.yml b/.gitlab-ci.d/container-cross.yml
index a3b5b90552..7a8cc556cc 100644
--- a/.gitlab-ci.d/container-cross.yml
+++ b/.gitlab-ci.d/container-cross.yml
@@ -82,6 +82,33 @@ hppa-debian-cross-container:
   variables:
     NAME: debian-hppa-cross
 
+# Similar to hexagon, we don't want to build loongarch64 in the CI either.
+loongarch64-cross-container:
+  image: docker:stable
+  stage: containers
+  rules:
+    - if: '$CI_PROJECT_NAMESPACE == "qemu-project"'
+      when: never
+    - when: always
+  variables:
+    NAME: gentoo-loongarch64-cross
+    GIT_DEPTH: 1
+  services:
+    - docker:dind
+  before_script:
+    - export TAG="$CI_REGISTRY_IMAGE/qemu/$NAME:latest"
+    - export COMMON_TAG="$CI_REGISTRY/qemu-project/qemu/qemu/$NAME:latest"
+    - docker info
+    - docker login $CI_REGISTRY -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD"
+  script:
+    - echo "TAG:$TAG"
+    - echo "COMMON_TAG:$COMMON_TAG"
+    - docker pull $COMMON_TAG
+    - docker tag $COMMON_TAG $TAG
+    - docker push "$TAG"
+  after_script:
+    - docker logout
+
 m68k-debian-cross-container:
   extends: .container_job_template
   stage: containers-layer2
diff --git a/.gitlab-ci.d/crossbuilds.yml b/.gitlab-ci.d/crossbuilds.yml
index 17d6cb3e45..b1cbc9cc43 100644
--- a/.gitlab-ci.d/crossbuilds.yml
+++ b/.gitlab-ci.d/crossbuilds.yml
@@ -68,6 +68,25 @@ cross-i386-tci:
     EXTRA_CONFIGURE_OPTS: --target-list=i386-softmmu,i386-linux-user,aarch64-softmmu,aarch64-linux-user,ppc-softmmu,ppc-linux-user
     MAKE_CHECK_ARGS: check check-tcg
 
+# Upstream LoongArch support is still incomplete, but toolchain is already
+# usable and partially merged, so the host support is already testable; but
+# don't let failures block CI.
+cross-loongarch64-system:
+  extends: .cross_system_build_job
+  allow_failure: true
+  needs:
+    job: loongarch64-cross-container
+  variables:
+    IMAGE: gentoo-loongarch64-cross
+
+cross-loongarch64-user:
+  extends: .cross_user_build_job
+  allow_failure: true
+  needs:
+    job: loongarch64-cross-container
+  variables:
+    IMAGE: gentoo-loongarch64-cross
+
 cross-mips-system:
   extends: .cross_system_build_job
   needs:
diff --git a/MAINTAINERS b/MAINTAINERS
index 1312a00f0d..55925e6b5f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3142,6 +3142,8 @@ LoongArch64 TCG target
 M: WANG Xuerui <git@xen0n.name>
 S: Maintained
 F: tcg/loongarch64/
+F: tests/docker/dockerfiles/gentoo-loongarch64-cross.docker
+F: tests/docker/dockerfiles/gentoo-loongarch64-cross.docker.d/
 
 MIPS TCG target
 M: Philippe Mathieu-Daudé <f4bug@amsat.org>
diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include
index f1a0c5db7a..a2cdf193bb 100644
--- a/tests/docker/Makefile.include
+++ b/tests/docker/Makefile.include
@@ -176,6 +176,27 @@ docker-image-debian-hexagon-cross: $(DOCKER_FILES_DIR)/debian-hexagon-cross.dock
 				qemu/debian-hexagon-cross --add-current-user,		\
 			"PREPARE", "debian-hexagon-cross"))
 
+#
+# Same for loongarch64-cross.
+#
+docker-image-gentoo-loongarch64-cross: $(DOCKER_FILES_DIR)/gentoo-loongarch64-cross.docker
+	$(if $(NOCACHE), 								\
+		$(call quiet-command,							\
+			$(DOCKER_SCRIPT) build -t qemu/gentoo-loongarch64-cross -f $< 	\
+			$(if $V,,--quiet) --no-cache 					\
+			--registry $(DOCKER_REGISTRY) --extra-files			\
+			$(DOCKER_FILES_DIR)/gentoo-loongarch64-cross.docker.d/build-toolchain.sh, \
+			"BUILD", "gentoo-loongarch64-cross"),				\
+		$(call quiet-command,							\
+			$(DOCKER_SCRIPT) fetch $(if $V,,--quiet)			\
+				qemu/gentoo-loongarch64-cross $(DOCKER_REGISTRY),	\
+			"FETCH", "gentoo-loongarch64-cross")				\
+		$(call quiet-command,							\
+			$(DOCKER_SCRIPT) update $(if $V,,--quiet) 			\
+				qemu/gentoo-loongarch64-cross --add-current-user,	\
+			"PREPARE", "gentoo-loongarch64-cross"))
+
+
 debian-toolchain-run = \
 	$(if $(NOCACHE), 						\
 		$(call quiet-command,					\
diff --git a/tests/docker/dockerfiles/gentoo-loongarch64-cross.docker b/tests/docker/dockerfiles/gentoo-loongarch64-cross.docker
new file mode 100644
index 0000000000..c02d25101b
--- /dev/null
+++ b/tests/docker/dockerfiles/gentoo-loongarch64-cross.docker
@@ -0,0 +1,19 @@
+#
+# Docker LoongArch64 cross-compiler target
+#
+# This docker target is used for building loongarch64 tests. As it also
+# needs to be able to build QEMU itself in CI we include it's
+# build-deps. It is also a "stand-alone" image so as not to be
+# triggered by re-builds on other base images given it takes a long
+# time to build.
+#
+
+FROM docker.io/gentoo/stage3:20211124
+
+ADD build-toolchain.sh /root/build-toolchain.sh
+RUN cd /root && ./build-toolchain.sh
+
+# Specify the cross prefix for this image (see tests/docker/common.rc)
+ENV QEMU_CONFIGURE_OPTS --cross-prefix=loongarch64-unknown-linux-gnu-
+# We don't have target support at the moment, so just verify that things build
+ENV DEF_TARGET_LIST x86_64-softmmu,x86_64-linux-user
diff --git a/tests/docker/dockerfiles/gentoo-loongarch64-cross.docker.d/build-toolchain.sh b/tests/docker/dockerfiles/gentoo-loongarch64-cross.docker.d/build-toolchain.sh
new file mode 100755
index 0000000000..94292a014d
--- /dev/null
+++ b/tests/docker/dockerfiles/gentoo-loongarch64-cross.docker.d/build-toolchain.sh
@@ -0,0 +1,125 @@
+#!/bin/bash
+
+set -e
+
+TRIPLE=loongarch64-unknown-linux-gnu
+CROSSDEV_OV=/opt/crossdev-overlay
+LOONGSON_OV=/opt/loongson-overlay
+CROSS_EMERGE="${TRIPLE}-emerge"
+
+# this will break on non-SMP machines, but no one should build this image
+# on such machine in the first place
+J=$(expr $(nproc) / 2)
+echo "MAKEOPTS=\"-j${J} -l${J}\"" >> /etc/portage/make.conf
+echo "EGIT_CLONE_TYPE=shallow" >> /etc/portage/make.conf
+
+# these features are not supported in Docker
+export FEATURES="-ipc-sandbox -network-sandbox"
+
+# populate Portage tree
+GENTOO_MIRROR='https://bouncer.gentoo.org/fetch/root/all'
+PORTAGE_SNAPSHOT_FILE=gentoo-20211123.tar.xz
+pushd /tmp
+    wget "${GENTOO_MIRROR}/snapshots/${PORTAGE_SNAPSHOT_FILE}"
+
+    mkdir -p /var/db/repos/gentoo
+    pushd /var/db/repos/gentoo
+        tar -xf "/tmp/${PORTAGE_SNAPSHOT_FILE}" --strip-components=1
+    popd
+
+    rm "$PORTAGE_SNAPSHOT_FILE"
+popd
+
+emerge -j crossdev dev-vcs/git
+
+# prepare for crossdev
+mkdir /etc/portage/repos.conf
+crossdev -t "$TRIPLE" --ov-output "$CROSSDEV_OV" --init-target
+
+git clone https://github.com/xen0n/loongson-overlay.git "$LOONGSON_OV"
+pushd "$LOONGSON_OV"
+    git checkout 075db64f56efab0108f8b82a5868fb58760d54a0
+popd
+
+pushd "${CROSSDEV_OV}/cross-${TRIPLE}"
+    rm binutils gcc glibc linux-headers
+    ln -s "${LOONGSON_OV}/sys-devel/binutils" .
+    ln -s "${LOONGSON_OV}/sys-devel/gcc" .
+    ln -s "${LOONGSON_OV}/sys-libs/glibc" .
+    ln -s "${LOONGSON_OV}/sys-kernel/linux-headers" .
+popd
+
+cat > "${CROSSDEV_OV}/metadata/layout.conf" <<EOF
+masters = gentoo
+repo-name = crossdev-overlay
+manifest-hashes = SHA256 SHA512 WHIRLPOOL
+thin-manifests = true
+EOF
+
+chown -R portage:portage "$CROSSDEV_OV"
+chown -R portage:portage "$LOONGSON_OV"
+
+# patch Portage tree for linux-headers
+pushd /var/db/repos/gentoo
+
+# this is to please checkpatch, hmm...
+TAB="$(printf "\t")"
+patch -Np1 <<EOF
+--- a/eclass/toolchain-funcs.eclass${TAB}2021-11-16 23:28:36.425419786 +0800
++++ b/eclass/toolchain-funcs.eclass${TAB}2021-11-16 23:29:30.378384948 +0800
+@@ -675,6 +675,7 @@
+ ${TAB}${TAB}${TAB}fi
+ ${TAB}${TAB}${TAB};;
+ ${TAB}${TAB}ia64*)${TAB}${TAB}echo ia64;;
++${TAB}${TAB}loongarch*)${TAB}ninj loongarch loong;;
+ ${TAB}${TAB}m68*)${TAB}${TAB}echo m68k;;
+ ${TAB}${TAB}metag*)${TAB}${TAB}echo metag;;
+ ${TAB}${TAB}microblaze*)${TAB}echo microblaze;;
+@@ -752,6 +753,7 @@
+ ${TAB}${TAB}hppa*)${TAB}${TAB}echo big;;
+ ${TAB}${TAB}i?86*)${TAB}${TAB}echo little;;
+ ${TAB}${TAB}ia64*)${TAB}${TAB}echo little;;
++${TAB}${TAB}loongarch*)${TAB}echo little;;
+ ${TAB}${TAB}m68*)${TAB}${TAB}echo big;;
+ ${TAB}${TAB}mips*l*)${TAB}echo little;;
+ ${TAB}${TAB}mips*)${TAB}${TAB}echo big;;
+EOF
+unset TAB
+
+popd
+
+# make cross toolchain
+crossdev -t "$TRIPLE" --without-headers \
+    --binutils 2.37_p1-r1 \
+    --gcc 12.0.0_pre9999
+
+# prepare for loongarch cross emerges
+pushd "/usr/${TRIPLE}/etc/portage"
+    rm make.profile
+    ln -s "$LOONGSON_OV"/profiles/desktop/3a5000 ./make.profile
+
+    mkdir repos.conf
+    cat > repos.conf/loongson.conf <<EOF
+[loongson]
+priority = 50
+location = $LOONGSON_OV
+auto-sync = No
+EOF
+
+popd
+
+# add build deps for qemu
+
+# gawk seems to have problems installing with concurrency, and its deps
+# include ncurses that needs disabling sandbox to correctly build under
+# Docker, so just turn off sandbox for all emerges
+export FEATURES="$FEATURES -sandbox -usersandbox"
+$CROSS_EMERGE -1 --onlydeps -j$J gawk
+mkdir -p "/usr/${TRIPLE}/bin"
+MAKEOPTS='-j1' $CROSS_EMERGE -1 gawk
+
+# then build the rest
+$CROSS_EMERGE -1 --onlydeps -j$J qemu
+
+# clean up downloaded files and Portage tree for smaller image
+rm -rf /var/db/repos/gentoo /var/cache/distfiles
-- 
2.34.0



  parent reply	other threads:[~2021-12-14  8:24 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-14  8:01 [PATCH v9 00/31] LoongArch64 port of QEMU TCG WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 01/31] elf: Add machine type value for LoongArch WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 02/31] MAINTAINERS: Add tcg/loongarch64 entry with myself as maintainer WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 03/31] tcg/loongarch64: Add the tcg-target.h file WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 04/31] tcg/loongarch64: Add generated instruction opcodes and encoding helpers WANG Xuerui
2021-12-14 13:16   ` Philippe Mathieu-Daudé
2021-12-14  8:01 ` [PATCH v9 05/31] tcg/loongarch64: Add register names, allocation order and input/output sets WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 06/31] tcg/loongarch64: Define the operand constraints WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 07/31] tcg/loongarch64: Implement necessary relocation operations WANG Xuerui
2021-12-14 13:19   ` Philippe Mathieu-Daudé
2021-12-14  8:01 ` [PATCH v9 08/31] tcg/loongarch64: Implement the memory barrier op WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 09/31] tcg/loongarch64: Implement tcg_out_mov and tcg_out_movi WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 10/31] tcg/loongarch64: Implement goto_ptr WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 11/31] tcg/loongarch64: Implement sign-/zero-extension ops WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 12/31] tcg/loongarch64: Implement not/and/or/xor/nor/andc/orc ops WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 13/31] tcg/loongarch64: Implement deposit/extract ops WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 14/31] tcg/loongarch64: Implement bswap{16,32,64} ops WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 15/31] tcg/loongarch64: Implement clz/ctz ops WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 16/31] tcg/loongarch64: Implement shl/shr/sar/rotl/rotr ops WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 17/31] tcg/loongarch64: Implement add/sub ops WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 18/31] tcg/loongarch64: Implement mul/mulsh/muluh/div/divu/rem/remu ops WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 19/31] tcg/loongarch64: Implement br/brcond ops WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 20/31] tcg/loongarch64: Implement setcond ops WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 21/31] tcg/loongarch64: Implement tcg_out_call WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 22/31] tcg/loongarch64: Implement simple load/store ops WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 23/31] tcg/loongarch64: Add softmmu load/store helpers, implement qemu_ld/qemu_st ops WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 24/31] tcg/loongarch64: Implement tcg_target_qemu_prologue WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 25/31] tcg/loongarch64: Implement exit_tb/goto_tb WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 26/31] tcg/loongarch64: Implement tcg_target_init WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 27/31] tcg/loongarch64: Register the JIT WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 28/31] common-user: Add safe syscall handling for loongarch64 hosts WANG Xuerui
2021-12-14 13:29   ` Philippe Mathieu-Daudé
2021-12-14 15:16     ` WANG Xuerui
2021-12-14 15:38       ` Philippe Mathieu-Daudé
2021-12-14 19:29   ` Richard Henderson
2021-12-14 20:49     ` Peter Maydell
2021-12-15 12:57     ` WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 29/31] linux-user: Implement CPU-specific signal handler " WANG Xuerui
2021-12-14  8:01 ` [PATCH v9 30/31] configure, meson.build: Mark support " WANG Xuerui
2021-12-14  8:01 ` WANG Xuerui [this message]
2021-12-14 13:23   ` [PATCH v9 31/31] tests/docker: Add gentoo-loongarch64-cross image and run cross builds in GitLab Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211214080154.196350-32-git@xen0n.name \
    --to=git@xen0n.name \
    --cc=alex.bennee@linaro.org \
    --cc=f4bug@amsat.org \
    --cc=gaosong@loongson.cn \
    --cc=laurent@vivier.eu \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=yangxiaojuan@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).