Skip to content

Commit 1d6d916

Browse files
build: add freebsd support (#4049)
1 parent 2dbe837 commit 1d6d916

31 files changed

+1055
-39
lines changed

.github/workflows/ci-freebsd.yml

Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
---
2+
name: CI-FreeBSD
3+
permissions:
4+
contents: read
5+
6+
on:
7+
workflow_call:
8+
inputs:
9+
release_commit:
10+
required: true
11+
type: string
12+
release_version:
13+
required: true
14+
type: string
15+
16+
env:
17+
BRANCH: ${{ github.head_ref || github.ref_name }}
18+
BUILD_VERSION: ${{ inputs.release_version }}
19+
COMMIT: ${{ inputs.release_commit }}
20+
FREEBSD_CLANG_VERSION: 19
21+
22+
jobs:
23+
setup-matrix:
24+
name: Setup Build Matrix
25+
runs-on: ubuntu-latest
26+
outputs:
27+
matrix: ${{ steps.generate-matrix.outputs.matrix }}
28+
steps:
29+
- name: Generate Matrix
30+
id: generate-matrix
31+
shell: bash
32+
run: |
33+
# Base matrix with amd64 build
34+
matrix='{
35+
"include": [
36+
{
37+
"bsd_release": "14.3",
38+
"arch": "x86_64",
39+
"cmake_processor": "amd64",
40+
"runner": "ubuntu-latest"
41+
}
42+
]
43+
}'
44+
45+
# Add aarch64 build only if not a pull request event
46+
if [[ "${{ github.event_name }}" != "pull_request" ]]; then
47+
matrix=$(echo "$matrix" | jq '.include += [{
48+
"bsd_release": "14.3",
49+
"arch": "aarch64",
50+
"cmake_processor": "aarch64",
51+
"runner": "ubuntu-latest"
52+
}]')
53+
fi
54+
55+
# Use heredoc for multiline JSON output
56+
{
57+
echo "matrix<<EOF"
58+
echo "$matrix"
59+
echo "EOF"
60+
} >> "${GITHUB_OUTPUT}"
61+
62+
echo "Generated matrix:"
63+
echo "$matrix" | jq .
64+
65+
build_freebsd:
66+
name: ${{ matrix.cmake_processor }}-${{ matrix.bsd_release }}
67+
runs-on: ubuntu-latest
68+
needs: setup-matrix
69+
strategy:
70+
fail-fast: false
71+
matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }}
72+
steps:
73+
- name: Checkout
74+
uses: actions/checkout@v5
75+
with:
76+
submodules: recursive
77+
78+
- name: Get Processor Count
79+
id: processor_count
80+
shell: bash
81+
run: |
82+
PROCESSOR_COUNT=$(nproc)
83+
echo "PROCESSOR_COUNT=${PROCESSOR_COUNT}" >> "${GITHUB_OUTPUT}"
84+
echo "PROCESSOR_COUNT: $PROCESSOR_COUNT"
85+
86+
- name: Setup FreeBSD
87+
uses: vmactions/freebsd-vm@783ae15c0393f8a2582a139f76cc55f2d887b4a6 # v1.2.6
88+
with:
89+
arch: ${{ matrix.arch }}
90+
cpu: ${{ steps.processor_count.outputs.PROCESSOR_COUNT }}
91+
envs: 'BRANCH BUILD_VERSION COMMIT'
92+
# TODO: there is no libcap for freebsd... we need graphics/libdrm if we find a way to use libcap
93+
# TODO: docs are off because doxygen is too old: https://www.freshports.org/devel/doxygen/ must be >= 1.10
94+
prepare: |
95+
set -e
96+
97+
pkg update
98+
pkg upgrade -y
99+
pkg install -y \
100+
audio/opus \
101+
audio/pulseaudio \
102+
devel/boost-all \
103+
devel/cmake-core \
104+
devel/evdev-proto \
105+
devel/git \
106+
devel/libayatana-appindicator \
107+
devel/libevdev \
108+
devel/libnotify \
109+
devel/llvm${{ env.FREEBSD_CLANG_VERSION }} \
110+
devel/ninja \
111+
devel/pkgconf \
112+
ftp/curl \
113+
graphics/libdrm \
114+
graphics/wayland \
115+
lang/python312 \
116+
multimedia/libva \
117+
net/miniupnpc \
118+
ports-mgmt/pkg \
119+
security/openssl \
120+
shells/bash \
121+
www/npm \
122+
x11/libX11 \
123+
x11/libxcb \
124+
x11/libXfixes \
125+
x11/libXrandr \
126+
x11/libXtst \
127+
x11-servers/xorg-server
128+
129+
# create symlink for shebang bash compatibility
130+
ln -s /usr/local/bin/bash /bin/bash
131+
132+
# setup python
133+
ln -s /usr/local/bin/python3.12 /usr/local/bin/python
134+
python -m ensurepip
135+
release: ${{ matrix.bsd_release }}
136+
run: |
137+
set -e
138+
# install gcvor
139+
python -m pip install gcovr
140+
141+
# fix git safe.directory issues
142+
git config --global --add safe.directory "*"
143+
sync: nfs # sshfs is used for build-deps; however it's much slower than nfs
144+
145+
- name: Configure
146+
shell: freebsd {0}
147+
run: |
148+
set -e
149+
cd "${GITHUB_WORKSPACE}"
150+
151+
cc_path="$(which clang${{ env.FREEBSD_CLANG_VERSION }})"
152+
cxx_path="$(which clang++${{ env.FREEBSD_CLANG_VERSION }})"
153+
154+
export CC="${cc_path}"
155+
export CXX="${cxx_path}"
156+
157+
mkdir -p build
158+
cmake \
159+
-B build \
160+
-G Ninja \
161+
-S . \
162+
-DBUILD_DOCS=OFF \
163+
-DBUILD_WERROR=OFF \
164+
-DCMAKE_BUILD_TYPE=Release \
165+
-DCMAKE_INSTALL_PREFIX=/usr/local \
166+
-DSUNSHINE_ASSETS_DIR=share/assets \
167+
-DSUNSHINE_EXECUTABLE_PATH=/usr/local/bin/sunshine \
168+
-DSUNSHINE_ENABLE_CUDA=OFF \
169+
-DSUNSHINE_ENABLE_DRM=OFF \
170+
-DSUNSHINE_ENABLE_WAYLAND=ON \
171+
-DSUNSHINE_ENABLE_X11=ON \
172+
-DSUNSHINE_PUBLISHER_NAME='${{ github.repository_owner }}' \
173+
-DSUNSHINE_PUBLISHER_WEBSITE='https://app.lizardbyte.dev' \
174+
-DSUNSHINE_PUBLISHER_ISSUE_URL='https://app.lizardbyte.dev/support'
175+
176+
- name: Build
177+
shell: freebsd {0}
178+
run: |
179+
set -e
180+
cd "${GITHUB_WORKSPACE}"
181+
ninja -C build
182+
183+
- name: Package
184+
shell: freebsd {0}
185+
run: |
186+
set -e
187+
cd "${GITHUB_WORKSPACE}"
188+
189+
mkdir -p artifacts
190+
191+
cd build
192+
cpack -G FREEBSD
193+
194+
# move compiled files to artifacts
195+
mv ./cpack_artifacts/Sunshine.pkg \
196+
../artifacts/Sunshine-FreeBSD-${{ matrix.bsd_release }}-${{ matrix.cmake_processor }}.pkg
197+
198+
- name: Debug
199+
if: always()
200+
shell: bash
201+
working-directory: build/cpack_artifacts/_CPack_Packages/FreeBSD/FREEBSD/Sunshine
202+
run: |
203+
echo "FreeBSD CPack Debug"
204+
echo "===== Staging Directory Contents ====="
205+
ls -la
206+
echo ""
207+
echo "===== +MANIFEST Content ====="
208+
cat +MANIFEST
209+
echo ""
210+
211+
# use tar to print the contents of the pkg
212+
cd "${GITHUB_WORKSPACE}/artifacts"
213+
echo "===== Package Contents ====="
214+
tar -tvf Sunshine-FreeBSD-${{ matrix.bsd_release }}-${{ matrix.cmake_processor }}.pkg
215+
echo ""
216+
echo "===== Package Statistics ====="
217+
echo -n "Total files in package: "
218+
tar -tf Sunshine-FreeBSD-${{ matrix.bsd_release }}-${{ matrix.cmake_processor }}.pkg 2>&1 | wc -l
219+
echo ""
220+
echo "Package file size:"
221+
ls -lh Sunshine-FreeBSD-${{ matrix.bsd_release }}-${{ matrix.cmake_processor }}.pkg
222+
223+
- name: Test
224+
id: test
225+
shell: freebsd {0}
226+
run: |
227+
set -e
228+
cd "${GITHUB_WORKSPACE}/build/tests"
229+
230+
export DISPLAY=:1
231+
Xvfb ${DISPLAY} -screen 0 1024x768x24 &
232+
XVFB_PID=$!
233+
234+
./test_sunshine --gtest_color=yes --gtest_output=xml:test_results.xml
235+
236+
kill ${XVFB_PID}
237+
238+
- name: Generate gcov report
239+
id: test_report
240+
# any except canceled or skipped
241+
if: >-
242+
always() &&
243+
(steps.test.outcome == 'success' || steps.test.outcome == 'failure')
244+
shell: freebsd {0}
245+
run: |
246+
cd "${GITHUB_WORKSPACE}/build"
247+
python -m gcovr . -r ../src \
248+
--exclude-noncode-lines \
249+
--exclude-throw-branches \
250+
--exclude-unreachable-branches \
251+
--verbose \
252+
--xml-pretty \
253+
-o coverage.xml
254+
255+
- name: Upload coverage artifact
256+
if: >-
257+
always() &&
258+
(steps.test_report.outcome == 'success')
259+
uses: actions/upload-artifact@v5
260+
with:
261+
name: coverage-FreeBSD-${{ matrix.bsd_release }}-${{ matrix.cmake_processor }}
262+
path: |
263+
build/coverage.xml
264+
build/tests/test_results.xml
265+
if-no-files-found: error
266+
267+
- name: Upload Artifacts
268+
uses: actions/upload-artifact@v4
269+
with:
270+
name: build-FreeBSD-${{ matrix.bsd_release }}-${{ matrix.cmake_processor }}
271+
path: artifacts/
272+
if-no-files-found: error

.github/workflows/ci.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ jobs:
6969
GH_BOT_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
7070
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7171

72+
build-freebsd:
73+
name: FreeBSD
74+
needs: release-setup
75+
uses: ./.github/workflows/ci-freebsd.yml
76+
with:
77+
release_commit: ${{ needs.release-setup.outputs.release_commit }}
78+
release_version: ${{ needs.release-setup.outputs.release_version }}
79+
7280
build-homebrew:
7381
name: Homebrew
7482
needs: release-setup
@@ -133,6 +141,7 @@ jobs:
133141
!cancelled() &&
134142
startsWith(github.repository, 'LizardByte/')
135143
needs:
144+
- build-freebsd
136145
- build-linux
137146
- build-linux-flatpak
138147
- build-homebrew
@@ -142,29 +151,53 @@ jobs:
142151
fail-fast: false
143152
matrix:
144153
include:
154+
- name: FreeBSD-14.3-amd64
155+
coverage: true
156+
pr: true
157+
- name: FreeBSD-14.3-aarch64
158+
coverage: true
159+
pr: false
145160
- name: Linux-AppImage
146161
coverage: true
162+
pr: true
147163
- name: Homebrew-macos-14
148164
coverage: false
165+
pr: true
149166
- name: Homebrew-macos-15
150167
coverage: false
168+
pr: true
151169
- name: Homebrew-macos-26
152170
coverage: false
171+
pr: true
153172
- name: Homebrew-ubuntu-latest
154173
coverage: false
174+
pr: true
155175
- name: Windows-AMD64
156176
coverage: true
177+
pr: true
157178
steps:
179+
- name: Should run
180+
id: should_run
181+
run: |
182+
if [ ${{ github.event_name }} != 'pull_request' ] || [ ${{ matrix.pr }} == 'true' ]; then
183+
echo "SHOULD_RUN=true" >> "${GITHUB_OUTPUT}"
184+
else
185+
echo "SHOULD_RUN=false" >> "${GITHUB_OUTPUT}"
186+
fi
187+
158188
- name: Checkout
189+
if: steps.should_run.outputs.SHOULD_RUN == 'true'
159190
uses: actions/checkout@v5
160191

161192
- name: Download coverage artifact
193+
if: steps.should_run.outputs.SHOULD_RUN == 'true'
162194
uses: actions/download-artifact@v6
163195
with:
164196
name: coverage-${{ matrix.name }}
165197
path: _coverage
166198

167199
- name: Upload test results
200+
if: steps.should_run.outputs.SHOULD_RUN == 'true'
168201
uses: codecov/test-results-action@v1
169202
with:
170203
disable_search: true
@@ -175,8 +208,8 @@ jobs:
175208
verbose: true
176209

177210
- name: Upload coverage
211+
if: steps.should_run.outputs.SHOULD_RUN == 'true' && matrix.coverage != false
178212
uses: codecov/codecov-action@v5
179-
if: matrix.coverage != false
180213
with:
181214
disable_search: true
182215
fail_ci_if_error: true
@@ -193,6 +226,7 @@ jobs:
193226
needs:
194227
- release-setup
195228
- build-docker
229+
- build-freebsd
196230
- build-linux
197231
- build-linux-flatpak
198232
- build-homebrew

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
2424
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
2525
endif()
2626

27+
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
28+
set(FREEBSD ON)
29+
endif()
30+
2731
# set the module path, used for includes
2832
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
2933

0 commit comments

Comments
 (0)