From 4b83beb208e671fa6bf3ecd790eff34c20a1996e Mon Sep 17 00:00:00 2001 From: inky Date: Thu, 1 Feb 2024 11:26:31 -0600 Subject: [PATCH] CI: Setup cross build test (#296) * build: allow set TOOLPREFIX * readme: add cross build steps * ci: Setup cross build * ci: use var in step name * ci: split build / build test * ci: add more arch * ci: update ppc triple * ci: update actions/checkout * ci: todo: fix arm cross build * ci: add more misp ci * ci: remove mips64, mips64el * ci: add more ppc ci * ci: reopen arm CI --- .github/workflows/cross.yml | 60 +++++++++++++++++++++++++++++++++++++ Make.inc | 7 +++-- README.md | 19 ++++++++++++ 3 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/cross.yml diff --git a/.github/workflows/cross.yml b/.github/workflows/cross.yml new file mode 100644 index 00000000..2834ced1 --- /dev/null +++ b/.github/workflows/cross.yml @@ -0,0 +1,60 @@ +name: Cross + +on: + pull_request: + branches: + - master + push: + branches: + - master + tags: '*' + +jobs: + build-cross-qemu: + runs-on: ubuntu-latest + name: build-cross-qemu-${{ matrix.config.arch }} + strategy: + fail-fast: false + matrix: + config: + - { arch: arm, triple: arm-linux-gnueabihf } + - { arch: aarch64, triple: aarch64-linux-gnu } + - { arch: ppc, triple: powerpc-linux-gnu } + - { arch: ppc64, triple: powerpc64-linux-gnu } + - { arch: ppc64le, triple: powerpc64le-linux-gnu } + - { arch: mips, triple: mips-linux-gnu } + - { arch: mipsel, triple: mipsel-linux-gnu } + # Builds successfully, but tests fail. + # - { arch: mips64, triple: mips64-linux-gnuabi64 } + # - { arch: mips64el, triple: mips64el-linux-gnuabi64 } + - { arch: riscv64, triple: riscv64-linux-gnu } + - { arch: s390x, triple: s390x-linux-gnu } + env: + ARCH: ${{ matrix.config.arch }} + TRIPLE: ${{ matrix.config.triple }} + steps: + - uses: actions/checkout@v4 + - name: Install QEMU + # this ensure install latest qemu on ubuntu, apt get version is old + env: + QEMU_SRC: "http://archive.ubuntu.com/ubuntu/pool/universe/q/qemu" + QEMU_VER: "qemu-user-static_7\\.2+dfsg-.*_amd64.deb$" + run: | + DEB=`curl -s $QEMU_SRC/ | grep -o -E 'href="([^"#]+)"' | cut -d'"' -f2 | grep $QEMU_VER | tail -1` + wget $QEMU_SRC/$DEB + sudo dpkg -i $DEB + - name: Install toolchain gcc-${{ matrix.config.triple }} + run: | + sudo apt update + sudo apt install gcc-$TRIPLE -y + - name: Build with ${{ matrix.config.triple }}-gcc + run: make ARCH=$ARCH TOOLPREFIX=$TRIPLE- + - name: Build tests + run: make -C test ARCH=$ARCH TOOLPREFIX=$TRIPLE- + - name: Run Tests + env: + QEMU_EXEC: qemu-${{ matrix.config.arch }}-static + CROSS_LIB: /usr/${{ matrix.config.triple }} + run: | + $QEMU_EXEC -L . -L $CROSS_LIB/ test/test-float + $QEMU_EXEC -L . -L $CROSS_LIB/ test/test-double diff --git a/Make.inc b/Make.inc index c0536a1c..76124999 100644 --- a/Make.inc +++ b/Make.inc @@ -30,6 +30,7 @@ CODE_COVERAGE ?= 0 USEGCC ?= 1 USECLANG ?= 0 +TOOLPREFIX ?= ifneq (,$(findstring $(OS),Darwin FreeBSD OpenBSD)) USEGCC ?= 0 @@ -41,7 +42,7 @@ USECLANG = 1 TOOLPREFIX = llvm- endif -AR ?= $(TOOLPREFIX)ar +AR := $(TOOLPREFIX)ar ifeq ($(USECLANG),1) USEGCC ?= 0 @@ -50,7 +51,7 @@ CFLAGS_add += -fno-builtin -fno-strict-aliasing endif ifeq ($(USEGCC),1) -CC ?= $(TOOLPREFIX)gcc +CC := $(TOOLPREFIX)gcc CFLAGS_add += -fno-gnu89-inline -fno-builtin endif @@ -66,7 +67,7 @@ override ARCH := aarch64 endif ifeq ($(findstring arm,$(ARCH)),arm) override ARCH := arm -MARCH ?= armv7-a +MARCH ?= armv7-a+fp CFLAGS_add += -mhard-float endif ifeq ($(findstring powerpc,$(ARCH)),powerpc) diff --git a/README.md b/README.md index b6cd376e..4c5ba206 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,25 @@ loongarch64. i686. GCC 4.8 is the minimum requirement for correct codegen on older 32-bit architectures. + +**Cross Build** +Take `riscv64` as example: +1. install `qemu-riscv64-static`, `gcc-riscv64-linux-gnu` +2. Cross build: +```sh +ARCH=riscv64 +TRIPLE=$ARCH-linux-gnu +make ARCH=$ARCH TOOLPREFIX=$TRIPLE- -j +make -C test ARCH=$ARCH TOOLPREFIX=$TRIPLE- -j +``` + +3. Run test with qemu: +```sh +qemu-$ARCH-static -L . -L /usr/$TRIPLE/ test/test-float +qemu-$ARCH-static -L . -L /usr/$TRIPLE/ test/test-double +``` + + ### CMake 1. Create build directory with `mkdir build` and navigate into it with `cd build`.