chore: Add FreeBSD build to CI.

This commit is contained in:
iphydf 2021-12-20 16:57:11 +00:00
parent 3f0ab46229
commit 656c7692a3
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
5 changed files with 10 additions and 286 deletions

View File

@ -38,3 +38,13 @@ jobs:
run: .travis/cmake-win64 install
- name: Cross compilation
run: .travis/cmake-win64 script
freebsd:
runs-on: ubuntu-latest
container: toxchat/freebsd
steps:
- uses: actions/checkout@v2
- name: Build on FreeBSD
run:
cd .. && mv c-toxcore / && mkdir c-toxcore &&
cd /work && ./cmake-freebsd-stage2

View File

@ -1,43 +0,0 @@
#!/bin/bash
# Common variables and functions
NPROC=$(nproc)
SCREEN_SESSION=freebsd
SSH_PORT=10022
FREEBSD_VERSION="12.1"
IMAGE_NAME=FreeBSD-$FREEBSD_VERSION-RELEASE-amd64.raw
# https://download.freebsd.org/ftp/releases/VM-IMAGES/12.1-RELEASE/amd64/Latest/
IMAGE_SHA512="a65da6260f5f894fc86fbe1f27dad7800906da7cffaa5077f82682ab74b6dd46c4ce87158c14b726d74ca3c6d611bea3bb336164da3f1cb990550310b110da22"
RUN() {
ssh -t -o ConnectionAttempts=120 -o ConnectTimeout=2 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p "$SSH_PORT" "$@"
}
start_vm() {
screen -d -m qemu-system-x86_64 -curses -m 2048 -smp "$NPROC" -net user,hostfwd=tcp::"$SSH_PORT"-:22 -net nic "$IMAGE_NAME"
# Wait for ssh to start listening on the port
while ! echo "exit" | nc localhost "$SSH_PORT" | grep 'OpenSSH'; do
sleep 5
done
# Test that ssh works
RUN uname -a
RUN last
}
stop_vm() {
# Turn it off
# We use this contraption because for some reason `shutdown -h now` and
# `poweroff` result in FreeBSD not shutting down on Travis (they work on my
# machine though)
RUN "shutdown -p +5sec && sleep 30" || true
# Wait for the qemu process to terminate
while pgrep qemu; do
sleep 5
done
}

View File

@ -1,124 +0,0 @@
#!/bin/bash
# Download and initial setup of the FreeBSD VM
ACTION="$1"
set -eux
. .travis/cmake-freebsd-env.sh
travis_install() {
git tag -l --sort=version:refname >GIT_TAGS
OLD_PWD="$PWD"
mkdir -p /opt/freebsd/cache
cd /opt/freebsd/cache
# === Get the VM image, set it up and cache ===
# Create image if it's not cached, or if this build script has changed, or a new toxcore tag was pushed
sha256sum "$OLD_PWD/.travis/cmake-freebsd-env.sh" >/tmp/sha
sha256sum "$OLD_PWD/.travis/cmake-freebsd-stage1" >>/tmp/sha
sha256sum "$OLD_PWD/.travis/cmake-freebsd-stage1.expect" >>/tmp/sha
if [ ! -f "./$IMAGE_NAME.tgz" ] || [ ! -f ./cmake-freebsd-stage1-all.sha256 ] || [ "$(cat cmake-freebsd-stage1-all.sha256)" != "$(cat /tmp/sha)" ] || ! diff -u ./GIT_TAGS "$OLD_PWD/GIT_TAGS"; then
rm -rf ./*
while true; do
# Selecting random mirror from https://www.freebsd.org/doc/handbook/mirrors-ftp.html
# Note that not all mirrors listed on that page are working, so we have removed them
# There are no arrays in sh so we get a bit clever
DL_MIRROR_1=1
DL_MIRROR_2=2
DL_MIRROR_3=3
DL_MIRROR_4=4
DL_MIRROR_5=5
DL_MIRROR_6=6
DL_MIRROR_7=7
DL_MIRROR_8=10
DL_MIRROR_9=11
DL_MIRROR_10=13
DL_MIRROR_11=14
# There are 11 mirrors
DL_MIRROR_RANDOM=$(expr "$(date +%s)" % 11 + 1)
DL_URL="ftp://ftp$(eval echo \$DL_MIRROR_"$DL_MIRROR_RANDOM").us.freebsd.org/pub/FreeBSD/releases/VM-IMAGES/$FREEBSD_VERSION-RELEASE/amd64/Latest/$IMAGE_NAME.xz"
# Make sure there are no partial downloads from the previous loop iterations
rm -rf ./*
wget --tries 1 "$DL_URL" && break
done
if ! (echo "$IMAGE_SHA512 $IMAGE_NAME.xz" | sha512sum -c --status -); then
echo "Error: sha512 of $IMAGE_NAME.xz doesn't match the known one"
exit 1
fi
unxz "$IMAGE_NAME.xz"
sudo apt-get update
sudo apt-get install -y qemu screen expect
# The downloaded image has little free disk space
qemu-img resize -f raw "$IMAGE_NAME" +5G
NPROC=$NPROC SSH_PORT=$SSH_PORT IMAGE_NAME="$IMAGE_NAME" screen "$OLD_PWD/.travis/cmake-freebsd-stage1.expect"
start_vm
# Update system
RUN env PAGER=cat env ASSUME_ALWAYS_YES=YES freebsd-update --not-running-from-cron fetch
# It fails if there is nothing to install, so we make it always succeed with true
RUN env PAGER=cat env ASSUME_ALWAYS_YES=YES freebsd-update --not-running-from-cron install || true
# Update packages
RUN env PAGER=cat env ASSUME_ALWAYS_YES=YES pkg upgrade
# Install and set bash as the default shell for the root user
RUN env PAGER=cat env ASSUME_ALWAYS_YES=YES pkg install bash
RUN chsh -s /usr/local/bin/bash root
# Install required toxcore dependencies
RUN PAGER=cat ASSUME_ALWAYS_YES=YES pkg install \
git \
opus \
libconfig \
libvpx \
libsodium \
gmake \
cmake \
pkgconf \
portaudio \
libsndfile \
texinfo \
autotools
# === Cache the VM image ===
stop_vm
# Create cache
tar -Sczvf "$IMAGE_NAME.tgz" "$IMAGE_NAME"
rm "$IMAGE_NAME"
cp "$OLD_PWD/GIT_TAGS" .
sha256sum "$OLD_PWD/.travis/cmake-freebsd-env.sh" >cmake-freebsd-stage1-all.sha256
sha256sum "$OLD_PWD/.travis/cmake-freebsd-stage1" >>cmake-freebsd-stage1-all.sha256
sha256sum "$OLD_PWD/.travis/cmake-freebsd-stage1.expect" >>cmake-freebsd-stage1-all.sha256
ls -lh
fi
cd "$OLD_PWD"
}
travis_script() {
echo "Nothing to do here. Building happens in stage 2."
}
if [ "-z" "$ACTION" ]; then
"travis_script"
else
"travis_$ACTION"
fi

View File

@ -1,41 +0,0 @@
#!/usr/bin/expect -f
set timeout -1
# Note: doesn't work if -nographic is used instead of -curses
spawn qemu-system-x86_64 -curses -m 2048 -smp $env(NPROC) -net user,hostfwd=tcp::$env(SSH_PORT)-:22 -net nic "$env(IMAGE_NAME)"
# Skip the boot menu
expect "to boot or any other key to stop"
send -- "\r"
expect "login: "
send -- "root\r"
# Setup DHCP networking and paswordless ssh
expect "root@freebsd:~ # "
send -- "echo \"ifconfig_em0=DHCP\" >> /etc/rc.conf\r"
expect "root@freebsd:~ # "
send -- "echo \"Port 22\" >> /etc/ssh/sshd_config\r"
expect "root@freebsd:~ # "
send -- "echo \"PermitRootLogin yes\" >> /etc/ssh/sshd_config\r"
expect "root@freebsd:~ # "
send -- "echo \"PasswordAuthentication yes\" >> /etc/ssh/sshd_config\r"
expect "root@freebsd:~ # "
send -- "echo \"PermitEmptyPasswords yes\" >> /etc/ssh/sshd_config\r"
expect "root@freebsd:~ # "
send -- "echo \"sshd_enable=YES\" >> /etc/rc.conf\r"
expect "root@freebsd:~ # "
# Set the empty password
send -- "passwd\r"
expect "New Password:"
send -- "\r"
expect "Retype New Password:"
send -- "\r"
expect "root@freebsd:~ # "
# Done
send -- "poweroff\r"
wait
exit 0

View File

@ -1,78 +0,0 @@
#!/bin/bash
# Toxcore building
ACTION="$1"
set -eux
. .travis/cmake-freebsd-env.sh
travis_install() {
sudo apt-get update
sudo apt-get install -y qemu screen
OLD_PWD="$PWD"
mkdir -p /opt/freebsd/cache
cd /opt/freebsd/cache
# Extract the cached image
tar -Sxzvf "$IMAGE_NAME.tgz"
# Get the image we will be using out of the cached directory
mv "$IMAGE_NAME" ..
ls -lh
cd ..
ls -lh
# === Get VM ready to build the code ===
start_vm
cd "$OLD_PWD"
# Copy over toxcore code from Travis to qemu
scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -P "$SSH_PORT" -r ./* root@localhost:~
RUN ls -lh
}
travis_script() {
CACHEDIR="none"
. ".travis/flags-$CC.sh"
add_ld_flag -Wl,-z,defs
# Make compilation error on a warning
add_flag -Werror
RUN 'cmake -B_build -H. \
-DCMAKE_C_FLAGS="$C_FLAGS" \
-DCMAKE_CXX_FLAGS="$CXX_FLAGS" \
-DCMAKE_EXE_LINKER_FLAGS="$LD_FLAGS" \
-DCMAKE_SHARED_LINKER_FLAGS="$LD_FLAGS" \
-DCMAKE_INSTALL_PREFIX:PATH="_install" \
-DMIN_LOGGER_LEVEL=TRACE \
-DMUST_BUILD_TOXAV=ON \
-DNON_HERMETIC_TESTS=ON \
-DSTRICT_ABI=ON \
-DTEST_TIMEOUT_SECONDS=300 \
-DUSE_IPV6=OFF \
-DAUTOTEST=ON'
# We created the VM with the same number of cores as the host, so the host-ran `nproc` here is fine
RUN 'gmake "-j$NPROC" -k install -C_build'
RUN 'gmake "-j$NPROC" test ARGS="-j50" -C_build || \
gmake "-j1" -C_build test ARGS="-j1 --rerun-failed" || \
gmake "-j1" -C_build test ARGS="-j1 --rerun-failed" CTEST_OUTPUT_ON_FAILURE=1 || \
true'
}
if [ "-z" "$ACTION" ]; then
"travis_script"
else
"travis_$ACTION"
fi