Skip to content

Commit

Permalink
ci for linux-amd64, linux-aarch64, win-mingw64
Browse files Browse the repository at this point in the history
  • Loading branch information
antmak authored and igrr committed Nov 21, 2023
1 parent 440d035 commit 4512cda
Show file tree
Hide file tree
Showing 7 changed files with 395 additions and 0 deletions.
211 changes: 211 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
name: 'build'

on: [push, pull_request]

jobs:

Vars:
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.Vars.outputs.VERSION }}
PROJECT_NAME: ${{ steps.Vars.outputs.PROJECT_NAME }}
REPOSITORY_URL: ${{ steps.Vars.outputs.REPOSITORY_URL }}
steps:
- id: Vars
run: |
echo "ref_type: ${{ github.ref_type }}"
echo "ref: ${{ github.ref }}"
echo "sha: ${{ github.sha }}"
echo ""
if [[ "${{ github.ref_type }}" == "tag" ]]; then
VERSION=${{ github.ref }}
VERSION=${VERSION#"refs/tags/"}
VERSION=${VERSION//"-"/"_"} # replace dashes with underscores in the version
else
VERSION=${{ github.sha }}
VERSION=g${VERSION:0:8}
fi
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
echo $VERSION
OWNER=${{ github.repository_owner }}
FULLNAME=${{ github.repository }}
PROJECT_NAME=${FULLNAME#"$OWNER/"}
echo "PROJECT_NAME=$PROJECT_NAME" >> "$GITHUB_OUTPUT"
echo $PROJECT_NAME
REPOSITORY_URL=${{ github.server_url }}/${{ github.repository }}
echo "REPOSITORY_URL=$REPOSITORY_URL" >> "$GITHUB_OUTPUT"
echo $REPOSITORY_URL
Build:
needs: [ Vars ]
env:
# A simple way to spread several environments for Windows. But to be more precise, we need to somehow add different envs to mastrix.include

MSYSTEM: MINGW64 # Ref: https://www.msys2.org/docs/environments/
CHERE_INVOKING: 'yes'
MSYS: 'winsymlinks:native'
strategy:
fail-fast: false
matrix:
# Naming MinGW platforms: https://sourceforge.net/p/mingw-w64/wiki2/TypeTriplets/
platform: [x86_64-linux-gnu, aarch64-linux-gnu, x86_64-w64-mingw32]
target: [xtensa-softmmu, riscv32-softmmu]

include:
- platform: x86_64-linux-gnu
runs_on: ubuntu-20.04
container: ubuntu:20.04
shell: bash -e {0}
run_prerequisites: "./.github/workflows/scripts/prerequisites-native.sh"
run_configure: "./.github/workflows/scripts/configure-native.sh"

- platform: aarch64-linux-gnu
runs_on: ubuntu-20.04
# Used the minimal docker-hub's image instead of the heavy GitHub's one for correct croossbuild prerequisites
container: ubuntu:20.04
shell: bash -e {0}
run_prerequisites: "./.github/workflows/scripts/prerequisites-cross-linux-arm64.sh"
run_configure: "./.github/workflows/scripts/configure-cross-linux-arm64.sh"

- platform: x86_64-w64-mingw32
runs_on: windows-2022
shell: msys2 {0}
run_configure: "./.github/workflows/scripts/configure-static.sh"

runs-on: ${{ matrix.runs_on }}
container: ${{ matrix.container }}
defaults:
run:
shell: ${{ matrix.shell }}

steps:
- uses: actions/checkout@v4

- name: Install Linux prerequisites (${{ matrix.target }} @ ${{ matrix.platform }})
if : ${{ matrix.platform != 'x86_64-w64-mingw32' }}
run: |
${{ matrix.run_prerequisites }}
- name: Install MSYS2 prerequisites (${{ matrix.target }} @ ${{ matrix.platform }})
if : ${{ matrix.platform == 'x86_64-w64-mingw32' }}
uses: msys2/setup-msys2@v2
with:
cache: true
msystem: MINGW64
install: >-
diffutils
git
mingw-w64-x86_64-gcc
mingw-w64-x86_64-glib2
mingw-w64-x86_64-libgcrypt
mingw-w64-x86_64-libiconv
mingw-w64-x86_64-libslirp
mingw-w64-x86_64-ninja
mingw-w64-x86_64-pixman
mingw-w64-x86_64-pkg-config
mingw-w64-x86_64-python
mingw-w64-x86_64-SDL2
- name: Configure (${{ matrix.target }} @ ${{ matrix.platform }})
env:
VERSION: ${{ needs.Vars.outputs.VERSION }}
TARGET: ${{ matrix.target }}
run: |
${{ matrix.run_configure }}
- name: Build (${{ matrix.target }} @ ${{ matrix.platform }})
run: |
ninja -C build install
- name: Package (${{ matrix.target }} @ ${{ matrix.platform }})
env:
VERSION: ${{ needs.Vars.outputs.VERSION }}
PROJECT_NAME: ${{ needs.Vars.outputs.PROJECT_NAME }}
PLATFORM: ${{ matrix.platform }}
TARGET: ${{ matrix.target }}
run: |
find $PWD/install/qemu/share/qemu/ -maxdepth 1 -mindepth 1 -not -name 'esp*.bin' -exec rm -rfv {} \;
export DIST_DIR=${PWD}/dist
mkdir -p ${DIST_DIR}
cd $PWD/install
ARCHIVE_NAME=${PROJECT_NAME}-${TARGET}-${VERSION}-${PLATFORM}.tar.xz
tar -cJvf ${DIST_DIR}/${ARCHIVE_NAME} qemu > ${DIST_DIR}/dist-filelist-${TARGET}-${PLATFORM}.txt 2>&1
echo "${ARCHIVE_NAME}" > ${DIST_DIR}/file_${PLATFORM}_${TARGET}
- name: Dist filelist (dbg) (${{ matrix.target }} @ ${{ matrix.platform }})
uses: actions/upload-artifact@v3
with:
name: dist-filelist-${{ matrix.target }}-${{ matrix.platform }}
path: |
dist/dist-filelist-*
- name: Dist artifacts (${{ matrix.target }} @ ${{ matrix.platform }})
uses: actions/upload-artifact@v3
with:
# TODO split artifacts for tests
name: dist-qemu
path: |
dist
Upload:
if: startsWith(github.ref, 'refs/tags/')
needs: [ Vars, Build ]
runs-on: ubuntu-latest
steps :
- name: Create a source archive
id: create-source
env:
VERSION: ${{ needs.Vars.outputs.VERSION }}
PROJECT_NAME: ${{ needs.Vars.outputs.PROJECT_NAME }}
REPOSITORY_URL: ${{ needs.Vars.outputs.REPOSITORY_URL }}
run: |
export RELEASE_CHECKSUM_FILE="${PROJECT_NAME}-${VERSION}-checksum.sha256"
echo "RELEASE_CHECKSUM_FILE=$RELEASE_CHECKSUM_FILE" >> "$GITHUB_OUTPUT"
RELEASE_SRC_NAME="${PROJECT_NAME}-${VERSION}-src"
export RELEASE_SRC_FILE="${PROJECT_NAME}-${VERSION}-src.tar.xz"
echo "RELEASE_SRC_FILE=$RELEASE_SRC_FILE" >> "$GITHUB_OUTPUT"
rm -rf -- "${RELEASE_SRC_NAME}" "${RELEASE_SRC_FILE}"
git clone --quiet --depth 1 --recurse-submodules --shallow-submodules "${REPOSITORY_URL}" "${RELEASE_SRC_NAME}"
find "${RELEASE_SRC_NAME}" -name ".git" -type d -exec rm -rf -- "{}" +
find "${RELEASE_SRC_NAME}" -name .git\* -exec rm -rf -- {} +
tar -cJvf "${RELEASE_SRC_FILE}" "${RELEASE_SRC_NAME}" > src-filelist.txt 2>&1
rm -rf -- "${RELEASE_SRC_NAME}"
ls -l
- name: Source filelist (dbg)
uses: actions/upload-artifact@v3
with:
name: src-filelist
path: |
src-filelist.txt
- uses: actions/download-artifact@v3
with:
name: dist-qemu

- name: Create a checksum file
env:
RELEASE_CHECKSUM_FILE: ${{ steps.create-source.outputs.RELEASE_CHECKSUM_FILE }}
RELEASE_SRC_FILE: ${{ steps.create-source.outputs.RELEASE_SRC_FILE }}
run: |
ls -l
DIST_FILE_LIST=$(find . -name file_\* -exec cat {} \+)
DIST_FILE_LIST="${DIST_FILE_LIST} ${RELEASE_SRC_FILE}"
for n in $DIST_FILE_LIST; do
sz=$(stat -c%s "${n}")
printf "# %s: %s bytes\n" "${n}" "${sz}" >> "${RELEASE_CHECKSUM_FILE}"
sha256sum -b "${n}" >> "${RELEASE_CHECKSUM_FILE}"
done
DIST_FILE_LIST="${DIST_FILE_LIST} ${RELEASE_CHECKSUM_FILE}"
# remove new lines from file list
DIST_FILE_LIST="${DIST_FILE_LIST//$'\n'/ }"
cat "${RELEASE_CHECKSUM_FILE}"
rm -rf -- upload && mkdir -p upload && mv -v ${DIST_FILE_LIST} upload/
- name: Release
uses: softprops/action-gh-release@v1
with:
files: upload/*
31 changes: 31 additions & 0 deletions .github/workflows/scripts/configure-cross-linux-arm64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

set -euo pipefail

TARGET=${TARGET:-xtensa-softmmu}
VERSION=${VERSION:-dev}

# Replacing libgcrypt method to 'pkg-config' for crossbuilding on Linux
sed -z -i "s/\(.*dependency('libgcrypt'.*method: '\)config-tool\('.*\)/\1pkg-config\2/g" -- meson.build

echo DBG
./configure --help

./configure \
--bindir=bin \
--cross-prefix=aarch64-linux-gnu- \
--datadir=share/qemu \
--disable-capstone \
--disable-docs \
--disable-gtk \
--disable-user \
--disable-vnc \
--enable-gcrypt \
--enable-sdl \
--enable-slirp \
--extra-cflags=-Werror \
--prefix=${PWD}/install/qemu \
--target-list=${TARGET} \
--with-pkgversion="${VERSION}" \
--with-suffix="" \
|| { cat meson-logs/meson-log.txt && false; }
33 changes: 33 additions & 0 deletions .github/workflows/scripts/configure-native.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

set -euo pipefail

TARGET=${TARGET:-xtensa-softmmu}
VERSION=${VERSION:-dev}

echo DBG
./configure --help

# Building with -Werror only on Linux as that breaks some features detection in meson on macOS.
# Defining --bindir, --datadir, etc - to have the same directory tree on Linux and Windows
# also adding --with-suffix="" to avoid doubled "qemu/qemu" path.
#
# MinGW build ref: https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-qemu/PKGBUILD

./configure \
--bindir=bin \
--datadir=share/qemu \
--disable-capstone \
--disable-docs \
--disable-gtk \
--disable-user \
--disable-vnc \
--enable-gcrypt \
--enable-sdl \
--enable-slirp \
--extra-cflags=-Werror \
--prefix=${PWD}/install/qemu \
--target-list=${TARGET} \
--with-pkgversion="${VERSION}" \
--with-suffix="" \
|| { cat meson-logs/meson-log.txt && false; }
36 changes: 36 additions & 0 deletions .github/workflows/scripts/configure-static.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

set -euo pipefail

TARGET=${TARGET:-xtensa-softmmu}
VERSION=${VERSION:-dev}

# Force enable libiconv. It's a workaround for a transitive dependency of libintl. Disabling with configure options doesn't work. Enable it for consistent.
# (only for MinGW static build)

sed -z -i "s/qemu_ldflags = \[\]/qemu_ldflags = \['-liconv','-Wl,--allow-multiple-definition'\]/g" -- meson.build

echo DBG
./configure --help

./configure \
--bindir=bin \
--datadir=share/qemu \
--disable-capstone \
--disable-docs \
--disable-gettext \
--disable-gtk \
--disable-qga-vss \
--disable-user \
--disable-vnc \
--enable-gcrypt \
--enable-iconv \
--enable-sdl \
--enable-slirp \
--extra-cflags=-Werror \
--prefix=${PWD}/install/qemu \
--static \
--target-list=${TARGET} \
--with-pkgversion="${VERSION}" \
--with-suffix="" \
|| { cat meson-logs/meson-log.txt && false; }
16 changes: 16 additions & 0 deletions .github/workflows/scripts/install-native.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -euo pipefail

export DEBIAN_FRONTEND="noninteractive"

apt-get update -y -q \
&& apt-get install -y -q --no-install-recommends \
libglib2.0-0 \
libpixman-1-0 \
libsdl2-2.0-0 \
libslirp0 \
&& :

# w/ SDL2 20 MB
# w/o SDL2 5 MB
45 changes: 45 additions & 0 deletions .github/workflows/scripts/prerequisites-cross-linux-arm64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

set -euo pipefail

export DEBIAN_FRONTEND="noninteractive"

EXTRA_APT_SOURCES="
deb [arch=arm64] http://ports.ubuntu.com/ focal main restricted
deb [arch=arm64] http://ports.ubuntu.com/ focal-updates main restricted
deb [arch=arm64] http://ports.ubuntu.com/ focal universe
deb [arch=arm64] http://ports.ubuntu.com/ focal-updates universe
deb [arch=arm64] http://ports.ubuntu.com/ focal multiverse
deb [arch=arm64] http://ports.ubuntu.com/ focal-updates multiverse
deb [arch=arm64] http://ports.ubuntu.com/ focal-backports main restricted universe multiverse
"

dpkg --add-architecture arm64
echo -e "$EXTRA_APT_SOURCES" > /etc/apt/sources.list.d/arm-cross-compile-sources.list
echo DBG1
cat /etc/apt/sources.list.d/arm-cross-compile-sources.list
sed -E -i 's/deb (http|file|mirror)/deb [arch=amd64] \1/' /etc/apt/sources.list
echo DBG2
cat /etc/apt/sources.list | grep -v "^#"
echo DBG3 /etc/apt/apt-mirrors.txt
test -f /etc/apt/apt-mirrors.txt && cat /etc/apt/apt-mirrors.txt | grep -v "^#"

apt-get update -y -q \
&& apt-get install -y -q --no-install-recommends \
binutils-aarch64-linux-gnu \
build-essential \
crossbuild-essential-arm64 \
gcc-aarch64-linux-gnu \
git \
libgcrypt20-dev:arm64 \
libglib2.0-dev:arm64 \
libgpg-error-dev:arm64 \
libpixman-1-dev:arm64 \
libsdl2-dev:arm64 \
libslirp-dev:arm64 \
ninja-build \
python3-pip \
zlib1g-dev:arm64 \
&& :

/usr/bin/pip3 install meson==1.2.3
Loading

0 comments on commit 4512cda

Please sign in to comment.