Skip to content

Commit 4b83beb

Browse files
authored
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
1 parent fc36466 commit 4b83beb

File tree

3 files changed

+83
-3
lines changed

3 files changed

+83
-3
lines changed

.github/workflows/cross.yml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Cross
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
push:
8+
branches:
9+
- master
10+
tags: '*'
11+
12+
jobs:
13+
build-cross-qemu:
14+
runs-on: ubuntu-latest
15+
name: build-cross-qemu-${{ matrix.config.arch }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
config:
20+
- { arch: arm, triple: arm-linux-gnueabihf }
21+
- { arch: aarch64, triple: aarch64-linux-gnu }
22+
- { arch: ppc, triple: powerpc-linux-gnu }
23+
- { arch: ppc64, triple: powerpc64-linux-gnu }
24+
- { arch: ppc64le, triple: powerpc64le-linux-gnu }
25+
- { arch: mips, triple: mips-linux-gnu }
26+
- { arch: mipsel, triple: mipsel-linux-gnu }
27+
# Builds successfully, but tests fail.
28+
# - { arch: mips64, triple: mips64-linux-gnuabi64 }
29+
# - { arch: mips64el, triple: mips64el-linux-gnuabi64 }
30+
- { arch: riscv64, triple: riscv64-linux-gnu }
31+
- { arch: s390x, triple: s390x-linux-gnu }
32+
env:
33+
ARCH: ${{ matrix.config.arch }}
34+
TRIPLE: ${{ matrix.config.triple }}
35+
steps:
36+
- uses: actions/checkout@v4
37+
- name: Install QEMU
38+
# this ensure install latest qemu on ubuntu, apt get version is old
39+
env:
40+
QEMU_SRC: "http://archive.ubuntu.com/ubuntu/pool/universe/q/qemu"
41+
QEMU_VER: "qemu-user-static_7\\.2+dfsg-.*_amd64.deb$"
42+
run: |
43+
DEB=`curl -s $QEMU_SRC/ | grep -o -E 'href="([^"#]+)"' | cut -d'"' -f2 | grep $QEMU_VER | tail -1`
44+
wget $QEMU_SRC/$DEB
45+
sudo dpkg -i $DEB
46+
- name: Install toolchain gcc-${{ matrix.config.triple }}
47+
run: |
48+
sudo apt update
49+
sudo apt install gcc-$TRIPLE -y
50+
- name: Build with ${{ matrix.config.triple }}-gcc
51+
run: make ARCH=$ARCH TOOLPREFIX=$TRIPLE-
52+
- name: Build tests
53+
run: make -C test ARCH=$ARCH TOOLPREFIX=$TRIPLE-
54+
- name: Run Tests
55+
env:
56+
QEMU_EXEC: qemu-${{ matrix.config.arch }}-static
57+
CROSS_LIB: /usr/${{ matrix.config.triple }}
58+
run: |
59+
$QEMU_EXEC -L . -L $CROSS_LIB/ test/test-float
60+
$QEMU_EXEC -L . -L $CROSS_LIB/ test/test-double

Make.inc

+4-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ CODE_COVERAGE ?= 0
3030

3131
USEGCC ?= 1
3232
USECLANG ?= 0
33+
TOOLPREFIX ?=
3334

3435
ifneq (,$(findstring $(OS),Darwin FreeBSD OpenBSD))
3536
USEGCC ?= 0
@@ -41,7 +42,7 @@ USECLANG = 1
4142
TOOLPREFIX = llvm-
4243
endif
4344

44-
AR ?= $(TOOLPREFIX)ar
45+
AR := $(TOOLPREFIX)ar
4546

4647
ifeq ($(USECLANG),1)
4748
USEGCC ?= 0
@@ -50,7 +51,7 @@ CFLAGS_add += -fno-builtin -fno-strict-aliasing
5051
endif
5152

5253
ifeq ($(USEGCC),1)
53-
CC ?= $(TOOLPREFIX)gcc
54+
CC := $(TOOLPREFIX)gcc
5455
CFLAGS_add += -fno-gnu89-inline -fno-builtin
5556
endif
5657

@@ -66,7 +67,7 @@ override ARCH := aarch64
6667
endif
6768
ifeq ($(findstring arm,$(ARCH)),arm)
6869
override ARCH := arm
69-
MARCH ?= armv7-a
70+
MARCH ?= armv7-a+fp
7071
CFLAGS_add += -mhard-float
7172
endif
7273
ifeq ($(findstring powerpc,$(ARCH)),powerpc)

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@ loongarch64.
3535
i686. GCC 4.8 is the minimum requirement for correct codegen on
3636
older 32-bit architectures.
3737

38+
39+
**Cross Build**
40+
Take `riscv64` as example:
41+
1. install `qemu-riscv64-static`, `gcc-riscv64-linux-gnu`
42+
2. Cross build:
43+
```sh
44+
ARCH=riscv64
45+
TRIPLE=$ARCH-linux-gnu
46+
make ARCH=$ARCH TOOLPREFIX=$TRIPLE- -j
47+
make -C test ARCH=$ARCH TOOLPREFIX=$TRIPLE- -j
48+
```
49+
50+
3. Run test with qemu:
51+
```sh
52+
qemu-$ARCH-static -L . -L /usr/$TRIPLE/ test/test-float
53+
qemu-$ARCH-static -L . -L /usr/$TRIPLE/ test/test-double
54+
```
55+
56+
3857
### CMake
3958

4059
1. Create build directory with `mkdir build` and navigate into it with `cd build`.

0 commit comments

Comments
 (0)