Skip to content

Commit 05a2dac

Browse files
committed
wip: add barebone Github actions pipeline.
1 parent d6ef599 commit 05a2dac

File tree

5 files changed

+214
-0
lines changed

5 files changed

+214
-0
lines changed

.github/workflows/bsd-user.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Build, Test & Publush
2+
3+
# Controls when the action will run.
4+
on:
5+
# Triggers the workflow on all push or pull request events
6+
push:
7+
pull_request:
8+
9+
release:
10+
types: [created]
11+
12+
# Allows you to run this workflow manually from the Actions tab
13+
workflow_dispatch:
14+
15+
schedule:
16+
- cron: "0 0 * * *"
17+
18+
# added using https://github.com/step-security/secure-repo
19+
permissions:
20+
contents: read
21+
22+
jobs:
23+
build_in_docker:
24+
name: Build&Push to Registry
25+
runs-on: ubuntu-latest
26+
permissions:
27+
packages: write
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
base_image: ['debian:sid-slim', 'debian:12-slim', 'ubuntu:latest']
32+
env:
33+
GHCR_REPO: ghcr.io/${{ github.repository_owner }}/qemu-bsd-user-l4b
34+
BASE_IMAGE: ${{ matrix.base_image }}
35+
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v4
39+
40+
- name: Set up QEMU
41+
id: qemu
42+
uses: docker/setup-qemu-action@v3
43+
44+
- name: Set up Docker Buildx
45+
uses: docker/setup-buildx-action@v3
46+
47+
- name: Login to GitHub Container Registry
48+
uses: docker/login-action@v3
49+
with:
50+
registry: ghcr.io
51+
username: ${{ github.repository_owner }}
52+
password: ${{ secrets.GITHUB_TOKEN }}
53+
54+
- name: Set dynamic environment
55+
run: |
56+
GIT_BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
57+
OS_TAG="`echo ${{ env.BASE_IMAGE }} | sed 's|:|-|g'`"
58+
# linux/arm/v7 is missing latest clang
59+
PLATFORMS="`docker manifest inspect ${{ env.BASE_IMAGE }} | \
60+
jq -r '.manifests[] | "\(.platform.os)/\(.platform.architecture)\(if .platform.variant != null then "/\(.platform.variant)" else "" end)"' | \
61+
sort -u | ./bsd-user/scripts/ci/get-arch-buildargs fltplatforms | paste -sd ','`"
62+
echo "GIT_BRANCH=${GIT_BRANCH}" >> $GITHUB_ENV
63+
echo "PLATFORMS=${PLATFORMS}" >> $GITHUB_ENV
64+
echo "OS_TAG=${OS_TAG}" >> $GITHUB_ENV
65+
echo "BUILD_IMAGE=${{ env.GHCR_REPO }}:latest-${OS_TAG}" >> $GITHUB_ENV
66+
67+
- name: Build Docker image
68+
uses: docker/build-push-action@v6
69+
env:
70+
CACHE_SPEC: "type=registry,ref=${{ env.GHCR_REPO }}:${{ env.GIT_BRANCH }}-${{ env.OS_TAG}}-buildcache"
71+
with:
72+
context: .
73+
file: ./bsd-user/scripts/ci/Dockerfile
74+
build-args: |
75+
BASE_IMAGE=${{ env.BASE_IMAGE }}
76+
tags: ${{ env.BUILD_IMAGE }}
77+
platforms: ${{ env.PLATFORMS }}
78+
push: false
79+
cache-from: ${{ env.CACHE_SPEC }}
80+
cache-to: ${{ env.CACHE_SPEC }},mode=max

bsd-user/scripts/ci/Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# syntax=docker/dockerfile:1.7-labs
2+
3+
ARG BASE_IMAGE="debian:sid-slim"
4+
FROM ${BASE_IMAGE} AS build
5+
LABEL maintainer="Maksym Sobolyev <[email protected]>"
6+
7+
ARG DEBIAN_FRONTEND=noninteractive
8+
ARG APT_INSTALL="apt-get install --no-install-recommends -y"
9+
ARG APT_UPDATE="apt-get -y update -qq"
10+
RUN ${APT_UPDATE}
11+
ARG CLANG_VER=19
12+
ARG BUILD_PKGS="libelf-dev llvm-${CLANG_VER} clang-${CLANG_VER} python-is-python3 \
13+
python3-pip python3-setuptools ninja-build pkg-config libglib2.0-dev git \
14+
libbsd-dev"
15+
WORKDIR /src
16+
RUN --mount=type=bind,source=bsd-user/scripts/ci/pre-build.sh,target=pre-build.sh \
17+
./pre-build.sh
18+
RUN ${APT_INSTALL} ${BUILD_PKGS}
19+
ARG TARGETPLATFORM
20+
ARG BASE_IMAGE
21+
RUN --mount=type=bind,target=.,rw \
22+
eval `./bsd-user/scripts/ci/get-arch-buildargs platformopts` && \
23+
bsd-user/scripts/ci/build.sh

bsd-user/scripts/ci/build.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
set -e
4+
set -x
5+
6+
BDIR=build_ci
7+
8+
_EXTRA_CFLAGS="-O1 -pipe -ffunction-sections -fdata-sections"
9+
if [ ! -z "${EXTRA_CFLAGS}" ]
10+
then
11+
_EXTRA_CFLAGS="${_EXTRA_CFLAGS} ${EXTRA_CFLAGS}"
12+
fi
13+
_EXTRA_LDFLAGS="-Wl,--gc-sections"
14+
if [ ! -z "${EXTRA_LDFLAGS}" ]
15+
then
16+
_EXTRA_LDLAGS="${_EXTRA_LDFLAGS} ${EXTRA_LDFLAGS}"
17+
fi
18+
19+
mkdir ${BDIR}
20+
cd ${BDIR}
21+
../configure --disable-system --static --target-list=x86_64-bsd-user \
22+
--extra-cflags="${_EXTRA_CFLAGS}" --cc="clang-${CLANG_VER}" \
23+
--extra-ldflags="${_EXTRA_LDLAGS}"
24+
ninja
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
debug_broken() {
6+
echo "${BASE_IMAGE}: ${1} is BROKEN: ${2}" >&2
7+
}
8+
9+
fltplatforms() {
10+
FILT="grep -v -e unknown" # docker multi-arch is weird
11+
case "${BASE_IMAGE}" in
12+
debian:sid*)
13+
FILT_ADD="linux/mips64le"
14+
debug_broken "linux/mips64le" 'apt-get: Exec format error'
15+
;;
16+
debian:12*)
17+
FILT_ADD="linux/arm/v7 linux/ppc64le linux/mips64le"
18+
debug_broken "linux/arm/v7" 'Unable to locate package llvm-18'
19+
debug_broken "linux/ppc64le" 'Unable to locate package llvm-18'
20+
debug_broken "linux/mips64le" 'Unable to locate package llvm-18'
21+
;;
22+
ubuntu:latest)
23+
FILT_ADD="linux/ppc64le linux/arm/v7"
24+
debug_broken "linux/ppc64le" 'ERROR: C compiler "clang-18" either does not exist or does not work.'
25+
debug_broken "linux/arm/v7" 'Unable to locate package llvm-18'
26+
;;
27+
*)
28+
;;
29+
esac
30+
for f in linux/riscv64 linux/s390x
31+
do
32+
FILT_ADD="${FILT_ADD} ${f}"
33+
debug_broken "${f}" "host is not supported yet (send PR!)"
34+
done
35+
if [ ! -z "${FILT_ADD}" ]
36+
then
37+
for f in ${FILT_ADD}
38+
do
39+
FILT="${FILT} -e ^${f}\$"
40+
done
41+
fi
42+
${FILT}
43+
}
44+
45+
platformopts() {
46+
case "${BASE_IMAGE}" in
47+
debian:12*)
48+
EXTRA_CFLAGS="-DHAVE_BSD_STRING_H=1"
49+
case "${TARGETPLATFORM}" in
50+
linux/386|linux/arm/v5)
51+
EXTRA_CFLAGS="${EXTRA_CFLAGS} -Wno-atomic-alignment"
52+
;;
53+
esac
54+
echo "export EXTRA_CFLAGS=\"${EXTRA_CFLAGS}\""
55+
echo "export EXTRA_LDFLAGS=\"-lbsd -lmd\""
56+
;;
57+
esac
58+
test ! -z "${@}" && echo "${@}"
59+
}
60+
61+
case "${1}" in
62+
platformopts)
63+
shift
64+
platformopts "${@}"
65+
;;
66+
fltplatforms)
67+
fltplatforms
68+
;;
69+
*)
70+
echo "usage: `basename "${0}"` (platformopts|fltplatforms) [opts]" 2>&1
71+
exit 1
72+
;;
73+
esac

bsd-user/scripts/ci/pre-build.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
install_clang() {
6+
${APT_INSTALL} curl gpg lsb-release ca-certificates
7+
MYREL="`lsb_release -c | grep ^Codename | awk '{print $2}'`"
8+
echo "deb [signed-by=/usr/share/keyrings/llvm.gpg] http://apt.llvm.org/${MYREL}/ llvm-toolchain-${MYREL}-${CLANG_VER} main" > /etc/apt/sources.list.d/llvm.list
9+
curl https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor > /usr/share/keyrings/llvm.gpg
10+
${APT_UPDATE}
11+
apt-mark hold ca-certificates
12+
}
13+
14+
install_clang

0 commit comments

Comments
 (0)