From ff8d656851dc502efd99f587d7dfef1bf2bc086b Mon Sep 17 00:00:00 2001
From: Michael Tautschnig <tautschn@amazon.com>
Date: Mon, 20 Nov 2023 09:46:32 +0000
Subject: [PATCH] Run FreeBSD build and test in CI

Uses https://github.com/cross-platform-actions/action, and can be
extended to OpenBSD and NetBSD.
---
 .github/workflows/bsd.yaml | 59 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 .github/workflows/bsd.yaml

diff --git a/.github/workflows/bsd.yaml b/.github/workflows/bsd.yaml
new file mode 100644
index 00000000000..66119ca9954
--- /dev/null
+++ b/.github/workflows/bsd.yaml
@@ -0,0 +1,59 @@
+name: Build and Test on *BSD
+on:
+  push:
+    branches: [ develop ]
+  pull_request:
+    branches: [ develop ]
+
+jobs:
+  # This job takes approximately X to Y minutes
+  freebsd:
+    runs-on: macos-12
+    steps:
+      - uses: actions/checkout@v3
+        with:
+          submodules: recursive
+      - name: Prepare ccache
+        uses: actions/cache@v3
+        with:
+          path: .ccache
+          key: freebsd-13.2-gmake-${{ github.ref }}-${{ github.sha }}-PR
+          restore-keys: |
+            freebsd-13.2-gmake-${{ github.ref }}
+            freebsd-13.2-gmake
+      - name: ccache environment
+        run: |
+          echo "CCACHE_BASEDIR=$PWD" >> $GITHUB_ENV
+          echo "CCACHE_DIR=$PWD/.ccache" >> $GITHUB_ENV
+      - name: Build and Test
+        uses: cross-platform-actions/action@v0.21.1
+        with:
+          operating_system: freebsd
+          version: '13.2'
+          run: |
+            echo "Fetch dependencies"
+            sudo pkg install bash gmake git www/p5-libwww python python3 patch flex bison ccache cvc5 z3
+            echo "Fetch JBMC dependencies"
+            sudo pkg install openjdk8 wget maven
+            echo "Zero ccache stats and limit in size"
+            ccache -z --max-size=500M
+            echo "Build with gmake"
+            gmake -C src minisat2-download
+            gmake -C src -j $(sysctl -n hw.ncpu)
+            gmake -C jbmc/src setup-submodules
+            gmake -C jbmc/src -j $(sysctl -n hw.ncpu)
+            echo "Print ccache stats"
+            ccache -s
+            echo "Checking completeness of help output"
+            scripts/check_help.sh
+            echo "Run unit tests"
+            gmake -C unit test
+            gmake -C jbmc/unit test
+            echo "Running expected failure tests"
+            gmake TAGS="[!shouldfail]" -C unit test
+            gmake TAGS="[!shouldfail]" -C jbmc/unit test
+            echo "Run regression tests"
+            gmake -C regression test
+            gmake -C regression/cbmc test-paths-lifo
+            env PATH=$PATH:`pwd`/src/solvers gmake -C regression/cbmc test-cprover-smt2
+            gmake -C jbmc/regression test