Skip to content

Commit 1022c34

Browse files
build: add freebsd support
1 parent 3239f2e commit 1022c34

23 files changed

Lines changed: 441 additions & 26 deletions

File tree

.github/workflows/ci-freebsd.yml

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
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+
FREEBSD_CLANG_VERSION: 19
18+
19+
jobs:
20+
build_freebsd:
21+
name: ${{ matrix.cmake_processor }}-${{ matrix.bsd_release }}
22+
if: github.event_name != 'pull_request' || matrix.pr == true
23+
runs-on: ubuntu-latest
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
include:
28+
- bsd_release: "14.3"
29+
arch: x86_64
30+
cmake_processor: amd64
31+
pr: true
32+
runner: ubuntu-latest
33+
- bsd_release: "14.3"
34+
arch: aarch64
35+
cmake_processor: aarch64
36+
pr: false
37+
runner: ubuntu-latest # ubuntu-24.04-arm is slower with the FreeBSD VM
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v5
41+
with:
42+
submodules: recursive
43+
44+
- name: Get Processor Count
45+
id: processor_count
46+
shell: bash
47+
run: |
48+
PROCESSOR_COUNT=$(nproc)
49+
echo "PROCESSOR_COUNT=${PROCESSOR_COUNT}" >> "${GITHUB_OUTPUT}"
50+
echo "PROCESSOR_COUNT: $PROCESSOR_COUNT"
51+
52+
- name: Setup FreeBSD
53+
uses: vmactions/freebsd-vm@v1.2.3
54+
with:
55+
arch: ${{ matrix.arch }}
56+
cpu: ${{ steps.processor_count.outputs.PROCESSOR_COUNT }}
57+
# TODO: there is no libcap for freebsd... we need graphics/libdrm if we find a way to use libcap
58+
# TODO: docs are off because doxygen is too old: https://www.freshports.org/devel/doxygen/ must be >= 1.10
59+
prepare: |
60+
set -e
61+
62+
pkg update
63+
pkg upgrade -y
64+
pkg install -y \
65+
audio/opus \
66+
audio/pulseaudio \
67+
devel/cmake-core \
68+
devel/evdev-proto \
69+
devel/git \
70+
devel/libayatana-appindicator \
71+
devel/libevdev \
72+
devel/libnotify \
73+
devel/llvm${{ env.FREEBSD_CLANG_VERSION }} \
74+
devel/ninja \
75+
devel/pkgconf \
76+
ftp/curl \
77+
graphics/libdrm \
78+
graphics/wayland \
79+
lang/python312 \
80+
multimedia/libva \
81+
net/miniupnpc \
82+
ports-mgmt/pkg \
83+
security/openssl \
84+
shells/bash \
85+
www/npm \
86+
x11/libX11 \
87+
x11/libxcb \
88+
x11/libXfixes \
89+
x11/libXrandr \
90+
x11/libXtst \
91+
x11-servers/xorg-server
92+
93+
# create symlink for shebang bash compatibility
94+
ln -s /usr/local/bin/bash /bin/bash
95+
96+
# setup python
97+
ln -s /usr/local/bin/python3.12 /usr/local/bin/python
98+
release: ${{ matrix.bsd_release }}
99+
run: |
100+
set -e
101+
102+
# fix git safe.directory issues
103+
git config --global --add safe.directory "*"
104+
105+
# install gcvor
106+
python -m pip install gcovr
107+
sync: nfs
108+
109+
- name: Configure
110+
env:
111+
BRANCH: ${{ github.head_ref || github.ref_name }}
112+
BUILD_VERSION: ${{ inputs.release_version }}
113+
COMMIT: ${{ inputs.release_commit }}
114+
shell: freebsd {0}
115+
run: |
116+
set -e
117+
cd "${GITHUB_WORKSPACE}"
118+
119+
export BRANCH="${BRANCH}"
120+
export BUILD_VERSION="${BUILD_VERSION}"
121+
export COMMIT="${COMMIT}"
122+
123+
cc_path="$(which clang${{ env.FREEBSD_CLANG_VERSION }})"
124+
cxx_path="$(which clang++${{ env.FREEBSD_CLANG_VERSION }})"
125+
126+
export CC="${cc_path}"
127+
export CXX="${cxx_path}"
128+
129+
mkdir -p build
130+
cmake \
131+
-B build \
132+
-G Ninja \
133+
-S . \
134+
-DBUILD_DOCS=OFF \
135+
-DBUILD_WERROR=OFF \
136+
-DCMAKE_BUILD_TYPE=Release \
137+
-DCMAKE_INSTALL_PREFIX=/usr/local \
138+
-DSUNSHINE_ASSETS_DIR=share/assets \
139+
-DSUNSHINE_EXECUTABLE_PATH=/usr/local/bin/sunshine \
140+
-DSUNSHINE_ENABLE_CUDA=OFF \
141+
-DSUNSHINE_ENABLE_DRM=OFF \
142+
-DSUNSHINE_ENABLE_WAYLAND=OFF \
143+
-DSUNSHINE_ENABLE_X11=ON \
144+
-DSUNSHINE_PUBLISHER_NAME='${{ github.repository_owner }}' \
145+
-DSUNSHINE_PUBLISHER_WEBSITE='https://app.lizardbyte.dev' \
146+
-DSUNSHINE_PUBLISHER_ISSUE_URL='https://app.lizardbyte.dev/support'
147+
148+
- name: Build
149+
shell: freebsd {0}
150+
run: |
151+
set -e
152+
cd "${GITHUB_WORKSPACE}"
153+
ninja -C build
154+
155+
- name: Package
156+
shell: freebsd {0}
157+
run: |
158+
set -e
159+
cd "${GITHUB_WORKSPACE}"
160+
161+
mkdir -p artifacts
162+
163+
cd build
164+
cpack -G FREEBSD
165+
166+
# move compiled files to artifacts
167+
mv ./cpack_artifacts/Sunshine.pkg \
168+
../artifacts/Sunshine-FreeBSD-${{ matrix.bsd_release }}-${{ matrix.cmake_processor }}.pkg
169+
170+
- name: Debug +MANIFEST
171+
if: always()
172+
shell: bash
173+
working-directory: build/cpack_artifacts
174+
run: cat ./_CPack_Packages/FreeBSD/FREEBSD/Sunshine/+MANIFEST
175+
176+
- name: Test
177+
id: test
178+
if: always()
179+
shell: freebsd {0}
180+
run: |
181+
set -e
182+
cd "${GITHUB_WORKSPACE}/build/tests"
183+
184+
export DISPLAY=:1
185+
Xvfb ${DISPLAY} -screen 0 1024x768x24 &
186+
187+
./test_sunshine --gtest_color=yes --gtest_output=xml:test_results.xml
188+
189+
- name: Generate gcov report
190+
id: test_report
191+
# any except canceled or skipped
192+
if: >-
193+
always() &&
194+
(steps.test.outcome == 'success' || steps.test.outcome == 'failure')
195+
shell: freebsd {0}
196+
run: |
197+
cd "${GITHUB_WORKSPACE}/build"
198+
python -m gcovr . -r ../src \
199+
--exclude-noncode-lines \
200+
--exclude-throw-branches \
201+
--exclude-unreachable-branches \
202+
--verbose \
203+
--xml-pretty \
204+
-o coverage.xml
205+
206+
- name: Upload coverage artifact
207+
if: >-
208+
always() &&
209+
(steps.test_report.outcome == 'success')
210+
uses: actions/upload-artifact@v4
211+
with:
212+
name: coverage-FreeBSD-${{ matrix.bsd_release }}-${{ matrix.cmake_processor }}
213+
path: |
214+
build/coverage.xml
215+
build/tests/test_results.xml
216+
if-no-files-found: error
217+
218+
- name: Upload Artifacts
219+
uses: actions/upload-artifact@v4
220+
with:
221+
name: build-FreeBSD-${{ matrix.bsd_release }}-${{ matrix.cmake_processor }}
222+
path: artifacts/
223+
if-no-files-found: error

.github/workflows/ci.yml

Lines changed: 23 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
@@ -124,8 +132,10 @@ jobs:
124132
if: >-
125133
always() &&
126134
!cancelled() &&
127-
startsWith(github.repository, 'LizardByte/')
135+
startsWith(github.repository, 'LizardByte/') &&
136+
(github.event_name != 'pull_request' || matrix.pr == true)
128137
needs:
138+
- build-freebsd
129139
- build-linux
130140
- build-linux-flatpak
131141
- build-homebrew
@@ -135,18 +145,30 @@ jobs:
135145
fail-fast: false
136146
matrix:
137147
include:
148+
- name: FreeBSD-14.3-amd64
149+
coverage: true
150+
pr: true
151+
- name: FreeBSD-14.3-aarch64
152+
coverage: true
153+
pr: false
138154
- name: Linux-AppImage
139155
coverage: true
156+
pr: true
140157
- name: Homebrew-macos-14
141158
coverage: false
159+
pr: true
142160
- name: Homebrew-macos-15
143161
coverage: false
162+
pr: true
144163
- name: Homebrew-macos-26
145164
coverage: false
165+
pr: true
146166
- name: Homebrew-ubuntu-latest
147167
coverage: false
168+
pr: true
148169
- name: Windows-AMD64
149170
coverage: true
171+
pr: true
150172
steps:
151173
- name: Checkout
152174
uses: actions/checkout@v5

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

cmake/compile_definitions/linux.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# linux specific compile definitions
22

3-
add_compile_definitions(SUNSHINE_PLATFORM="linux")
3+
if(FREEBSD)
4+
add_compile_definitions(SUNSHINE_PLATFORM="freebsd")
5+
else()
6+
add_compile_definitions(SUNSHINE_PLATFORM="linux")
7+
endif()
48

59
# AppImage
610
if(${SUNSHINE_BUILD_APPIMAGE})
@@ -211,6 +215,9 @@ endif()
211215
# These need to be set before adding the inputtino subdirectory in order for them to be picked up
212216
set(LIBEVDEV_CUSTOM_INCLUDE_DIR "${EVDEV_INCLUDE_DIR}")
213217
set(LIBEVDEV_CUSTOM_LIBRARY "${EVDEV_LIBRARY}")
218+
if(FREEBSD)
219+
set(USE_UHID OFF)
220+
endif()
214221

215222
add_subdirectory("${CMAKE_SOURCE_DIR}/third-party/inputtino")
216223
list(APPEND SUNSHINE_EXTERNAL_LIBRARIES inputtino::libinputtino)

cmake/dependencies/common.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ include_directories(SYSTEM ${MINIUPNP_INCLUDE_DIRS})
3030
if(NOT DEFINED FFMPEG_PREPARED_BINARIES)
3131
if(WIN32)
3232
set(FFMPEG_PLATFORM_LIBRARIES mfplat ole32 strmiids mfuuid vpl)
33+
elseif(FREEBSD)
34+
# numa is not available on FreeBSD
35+
set(FFMPEG_PLATFORM_LIBRARIES va va-drm va-x11 X11)
3336
elseif(UNIX AND NOT APPLE)
3437
set(FFMPEG_PLATFORM_LIBRARIES numa va va-drm va-x11 X11)
3538
endif()

cmake/packaging/linux.cmake

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ else()
3030
endif()
3131
endif()
3232

33+
# RPM specific
34+
set(CPACK_RPM_PACKAGE_LICENSE "GPLv3")
35+
36+
# FreeBSD specific
37+
set(CPACK_FREEBSD_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
38+
set(CPACK_FREEBSD_PACKAGE_ORIGIN "misc/${CPACK_PACKAGE_NAME}")
39+
set(CPACK_FREEBSD_PACKAGE_LICENSE "GPLv3")
40+
3341
# Post install
3442
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${SUNSHINE_SOURCE_ASSETS_DIR}/linux/misc/postinst")
3543
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${SUNSHINE_SOURCE_ASSETS_DIR}/linux/misc/postinst")
@@ -73,6 +81,14 @@ set(CPACK_RPM_PACKAGE_REQUIRES "\
7381
openssl >= 3.0.2, \
7482
pulseaudio-libs >= 10.0, \
7583
which >= 2.21")
84+
list(APPEND CPACK_FREEBSD_PACKAGE_DEPS
85+
audio/opus
86+
ftp/curl
87+
devel/libevdev
88+
x11/libX11
89+
net/miniupnpc
90+
security/openssl
91+
)
7692

7793
if(NOT BOOST_USE_STATIC)
7894
set(CPACK_DEBIAN_PACKAGE_DEPENDS "\
@@ -87,6 +103,9 @@ if(NOT BOOST_USE_STATIC)
87103
boost-locale >= ${Boost_VERSION}, \
88104
boost-log >= ${Boost_VERSION}, \
89105
boost-program-options >= ${Boost_VERSION}")
106+
list(APPEND CPACK_FREEBSD_PACKAGE_DEPS
107+
devel/boost-libs
108+
)
90109
endif()
91110

92111
# This should automatically figure out dependencies, doesn't work with the current config
@@ -137,6 +156,10 @@ if(${SUNSHINE_TRAY} STREQUAL 1)
137156
set(CPACK_RPM_PACKAGE_REQUIRES "\
138157
${CPACK_RPM_PACKAGE_REQUIRES}, \
139158
libappindicator-gtk3 >= 12.10.0")
159+
list(APPEND CPACK_FREEBSD_PACKAGE_DEPS
160+
devel/libayatana-appindicator
161+
devel/libnotify
162+
)
140163
endif()
141164

142165
# desktop file

0 commit comments

Comments
 (0)