From 768c995f165f25d5a8fb119e31b1f6237868c8dd Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Fri, 4 Jul 2025 20:16:38 -0400 Subject: [PATCH] build: add freebsd support --- .github/workflows/ci-freebsd.yml | 171 ++++++++++++++++++ .github/workflows/ci.yml | 8 + CMakeLists.txt | 4 + cmake/compile_definitions/linux.cmake | 9 +- cmake/dependencies/common.cmake | 3 + cmake/packaging/linux.cmake | 23 +++ docs/app_examples.md | 27 +++ docs/building.md | 37 ++++ docs/configuration.md | 25 +-- docs/getting_started.md | 11 +- src/platform/linux/misc.cpp | 33 +++- src/system_tray.cpp | 2 +- src/video.cpp | 4 +- src/video.h | 2 +- .../common/assets/web/PlatformLayout.vue | 4 + src_assets/common/assets/web/apps.html | 6 +- src_assets/common/assets/web/config.html | 2 +- .../assets/web/configs/tabs/Advanced.vue | 6 + .../assets/web/configs/tabs/AudioVideo.vue | 3 + .../common/assets/web/configs/tabs/Inputs.vue | 8 +- .../tabs/audiovideo/AdapterNameSelector.vue | 3 + .../tabs/audiovideo/DisplayDeviceOptions.vue | 2 + .../tabs/audiovideo/DisplayOutputSelector.vue | 5 + 23 files changed, 373 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/ci-freebsd.yml diff --git a/.github/workflows/ci-freebsd.yml b/.github/workflows/ci-freebsd.yml new file mode 100644 index 00000000..99389658 --- /dev/null +++ b/.github/workflows/ci-freebsd.yml @@ -0,0 +1,171 @@ +--- +name: CI-FreeBSD +permissions: + contents: read + +on: + workflow_call: + inputs: + release_commit: + required: true + type: string + release_version: + required: true + type: string + +env: + FREEBSD_CLANG_VERSION: 19 + +jobs: + build_freebsd: + name: ${{ matrix.cmake_processor }}-${{ matrix.bsd_release }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - bsd_release: "14.3" + arch: x86_64 + cmake_processor: amd64 + runner: ubuntu-latest + - bsd_release: "14.3" + arch: aarch64 + cmake_processor: aarch64 + runner: ubuntu-latest # ubuntu-24.04-arm is slower with the FreeBSD VM + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Get Processor Count + id: processor_count + shell: bash + run: | + PROCESSOR_COUNT=$(nproc) + echo "PROCESSOR_COUNT=${PROCESSOR_COUNT}" >> $GITHUB_OUTPUT + echo "PROCESSOR_COUNT: $PROCESSOR_COUNT" + + - name: Setup FreeBSD + uses: vmactions/freebsd-vm@v1.2.1 + with: + arch: ${{ matrix.arch }} + cpu: ${{ steps.processor_count.outputs.PROCESSOR_COUNT }} + # TODO: there is no libcap for freebsd... we need graphics/libdrm if we find a way to use libcap + # TODO: docs are off because doxygen is too old: https://www.freshports.org/devel/doxygen/ must be >= 1.10 + prepare: | + set -e + + pkg update + pkg upgrade -y + pkg install -y \ + audio/opus \ + audio/pulseaudio \ + devel/cmake-core \ + devel/evdev-proto \ + devel/git \ + devel/libayatana-appindicator \ + devel/libevdev \ + devel/libnotify \ + devel/llvm${{ env.FREEBSD_CLANG_VERSION }} \ + devel/ninja \ + devel/pkgconf \ + ftp/curl \ + graphics/libdrm \ + graphics/wayland \ + multimedia/libva \ + net/miniupnpc \ + ports-mgmt/pkg \ + security/openssl \ + shells/bash \ + www/npm \ + x11/libX11 \ + x11/libxcb \ + x11/libXfixes \ + x11/libXrandr \ + x11/libXtst + + # create symlink for shebang bash compatibility + ln -s /usr/local/bin/bash /bin/bash + release: ${{ matrix.bsd_release }} + run: | + set -e + + # fix git safe.directory issues + git config --global --add safe.directory "*" + sync: nfs + + - name: Configure + env: + BRANCH: ${{ github.head_ref || github.ref_name }} + BUILD_VERSION: ${{ inputs.release_version }} + COMMIT: ${{ inputs.release_commit }} + shell: freebsd {0} + run: | + set -e + cd $GITHUB_WORKSPACE + + export BRANCH=${{ env.BRANCH }} + export BUILD_VERSION=${{ env.BUILD_VERSION }} + export COMMIT=${{ env.COMMIT }} + + export CC=$(which clang${{ env.FREEBSD_CLANG_VERSION }}) + export CXX=$(which clang++${{ env.FREEBSD_CLANG_VERSION }}) + + mkdir -p build + cmake \ + -B build \ + -G Ninja \ + -S . \ + -DBUILD_DOCS=OFF \ + -DBUILD_WERROR=OFF \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/usr/local \ + -DSUNSHINE_ASSETS_DIR=share/assets \ + -DSUNSHINE_EXECUTABLE_PATH=/usr/local/bin/sunshine \ + -DSUNSHINE_ENABLE_CUDA=OFF \ + -DSUNSHINE_ENABLE_DRM=OFF \ + -DSUNSHINE_ENABLE_WAYLAND=OFF \ + -DSUNSHINE_ENABLE_X11=ON \ + -DSUNSHINE_PUBLISHER_NAME='${{ github.repository_owner }}' \ + -DSUNSHINE_PUBLISHER_WEBSITE='https://app.lizardbyte.dev' \ + -DSUNSHINE_PUBLISHER_ISSUE_URL='https://app.lizardbyte.dev/support' + + - name: Build + shell: freebsd {0} + run: | + set -e + cd $GITHUB_WORKSPACE + ninja -C build + + - name: Package + shell: freebsd {0} + run: | + set -e + cd $GITHUB_WORKSPACE + + mkdir -p artifacts + + cd build + cpack -G FREEBSD --verbose --debug + + # move compiled files to artifacts + mv ./cpack_artifacts/Sunshine* ../artifacts/ + + - name: Debug cpack_artifacts + if: always() + shell: bash + working-directory: build/cpack_artifacts + run: | + ls -R . + + # print contents of manifest + echo "Manifest:" + cat ./_CPack_Packages/FreeBSD/FREEBSD/Sunshine/+MANIFEST + + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + name: build-FreeBSD-${{ matrix.bsd_release }}-${{ matrix.cmake_processor }} + path: artifacts/ + if-no-files-found: error diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad2dd394..3fd85a31 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,6 +68,14 @@ jobs: GH_BOT_TOKEN: ${{ secrets.GH_BOT_TOKEN }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + build-freebsd: + name: FreeBSD + needs: release-setup + uses: ./.github/workflows/ci-freebsd.yml + with: + release_commit: ${{ needs.release-setup.outputs.release_commit }} + release_version: ${{ needs.release-setup.outputs.release_version }} + build-homebrew: name: Homebrew needs: release-setup diff --git a/CMakeLists.txt b/CMakeLists.txt index 5cedee55..08c0b1ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,10 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE) endif() +if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + set(FREEBSD ON) +endif() + # set the module path, used for includes set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") diff --git a/cmake/compile_definitions/linux.cmake b/cmake/compile_definitions/linux.cmake index 27f52e63..e869d044 100644 --- a/cmake/compile_definitions/linux.cmake +++ b/cmake/compile_definitions/linux.cmake @@ -1,6 +1,10 @@ # linux specific compile definitions -add_compile_definitions(SUNSHINE_PLATFORM="linux") +if(FREEBSD) + add_compile_definitions(SUNSHINE_PLATFORM="freebsd") +else() + add_compile_definitions(SUNSHINE_PLATFORM="linux") +endif() # AppImage if(${SUNSHINE_BUILD_APPIMAGE}) @@ -224,6 +228,9 @@ endif() # These need to be set before adding the inputtino subdirectory in order for them to be picked up set(LIBEVDEV_CUSTOM_INCLUDE_DIR "${EVDEV_INCLUDE_DIR}") set(LIBEVDEV_CUSTOM_LIBRARY "${EVDEV_LIBRARY}") +if(FREEBSD) + set(USE_UHID OFF) +endif() add_subdirectory("${CMAKE_SOURCE_DIR}/third-party/inputtino") list(APPEND SUNSHINE_EXTERNAL_LIBRARIES inputtino::libinputtino) diff --git a/cmake/dependencies/common.cmake b/cmake/dependencies/common.cmake index c92b4777..9f12f1bc 100644 --- a/cmake/dependencies/common.cmake +++ b/cmake/dependencies/common.cmake @@ -30,6 +30,9 @@ include_directories(SYSTEM ${MINIUPNP_INCLUDE_DIRS}) if(NOT DEFINED FFMPEG_PREPARED_BINARIES) if(WIN32) set(FFMPEG_PLATFORM_LIBRARIES mfplat ole32 strmiids mfuuid vpl) + elseif(FREEBSD) + # numa is not available on FreeBSD + set(FFMPEG_PLATFORM_LIBRARIES va va-drm va-x11 X11) elseif(UNIX AND NOT APPLE) set(FFMPEG_PLATFORM_LIBRARIES numa va va-drm va-x11 X11) endif() diff --git a/cmake/packaging/linux.cmake b/cmake/packaging/linux.cmake index 659bbc37..cd6f2b3b 100644 --- a/cmake/packaging/linux.cmake +++ b/cmake/packaging/linux.cmake @@ -30,6 +30,14 @@ else() endif() endif() +# RPM specific +set(CPACK_RPM_PACKAGE_LICENSE "GPLv3") + +# FreeBSD specific +set(CPACK_FREEBSD_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}") +set(CPACK_FREEBSD_PACKAGE_ORIGIN "misc/${CPACK_PACKAGE_NAME}") +set(CPACK_FREEBSD_PACKAGE_LICENSE "GPLv3") + # Post install set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${SUNSHINE_SOURCE_ASSETS_DIR}/linux/misc/postinst") set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${SUNSHINE_SOURCE_ASSETS_DIR}/linux/misc/postinst") @@ -69,6 +77,14 @@ set(CPACK_RPM_PACKAGE_REQUIRES "\ numactl-libs >= 2.0.14, \ openssl >= 3.0.2, \ pulseaudio-libs >= 10.0") +set(CPACK_FREEBSD_PACKAGE_DEPS "\) + ${CPACK_FREEBSD_PLATFORM_PACKAGE_DEPS} \ + audio/opus, \ + ftp/curl, \ + devel/libevdev, \ + x11/libX11, \ + net/miniupnpc, \ + security/openssl") if(NOT BOOST_USE_STATIC) set(CPACK_DEBIAN_PACKAGE_DEPENDS "\ @@ -83,6 +99,9 @@ if(NOT BOOST_USE_STATIC) boost-locale >= ${Boost_VERSION}, \ boost-log >= ${Boost_VERSION}, \ boost-program-options >= ${Boost_VERSION}") + set(CPACK_FREEBSD_PACKAGE_DEPS "\) + ${CPACK_FREEBSD_PACKAGE_DEPS}, \ + devel/boost-libs") endif() # This should automatically figure out dependencies, doesn't work with the current config @@ -133,6 +152,10 @@ if(${SUNSHINE_TRAY} STREQUAL 1) set(CPACK_RPM_PACKAGE_REQUIRES "\ ${CPACK_RPM_PACKAGE_REQUIRES}, \ libappindicator-gtk3 >= 12.10.0") + set(CPACK_FREEBSD_PACKAGE_DEPS "\ + ${CPACK_FREEBSD_PACKAGE_DEPS}, \ + devel/libayatana-appindicator, \ + devel/libnotify") endif() # desktop file diff --git a/docs/app_examples.md b/docs/app_examples.md index 782681fd..6a40ce9c 100644 --- a/docs/app_examples.md +++ b/docs/app_examples.md @@ -22,6 +22,14 @@ adding an image or a log file (via the `Output` field).} process is killed.} @tabs{ + @tab{FreeBSD | + \| Field \| Value \| + \|------------------------------\|------------------------------------------------------\| + \| Application Name \| @code{}Steam Big Picture@endcode \| + \| Command Preporations -> Undo \| @code{}setsid steam steam://close/bigpicture@endcode \| + \| Detached Commands \| @code{}setsid steam steam://open/bigpicture@endcode \| + \| Image \| @code{}steam.png@endcode \| + } @tab{Linux | \| Field \| Value \| \|------------------------------\|------------------------------------------------------\| @@ -89,6 +97,12 @@ process is killed.} #### URI @tabs{ + @tab{FreeBSD | + \| Field \| Value \| + \|-------------------\|------------------------------------------------------\| + \| Application Name \| @code{}Surviving Mars@endcode \| + \| Detached Commands \| @code{}setsid steam steam://rungameid/464920@endcode \| + } @tab{Linux | \| Field \| Value \| \|-------------------\|------------------------------------------------------\| @@ -111,6 +125,13 @@ process is killed.} #### Binary (w/ working directory @tabs{ + @tab{FreeBSD | + \| Field \| Value \| + \|-------------------\|--------------------------------------------------------------\| + \| Application Name \| @code{}Surviving Mars@endcode \| + \| Command \| @code{}MarsSteam@endcode \| + \| Working Directory \| @code{}~/.steam/steam/SteamApps/common/Survivng Mars@endcode \| + } @tab{Linux | \| Field \| Value \| \|-------------------\|--------------------------------------------------------------\| @@ -136,6 +157,12 @@ process is killed.} #### Binary (w/o working directory) @tabs{ + @tab{FreeBSD | + \| Field \| Value \| + \|-------------------\|------------------------------------------------------------------------\| + \| Application Name \| @code{}Surviving Mars@endcode \| + \| Command \| @code{}~/.steam/steam/SteamApps/common/Survivng Mars/MarsSteam@endcode \| + } @tab{Linux | \| Field \| Value \| \|-------------------\|------------------------------------------------------------------------\| diff --git a/docs/building.md b/docs/building.md index b7f5d402..0eae596a 100644 --- a/docs/building.md +++ b/docs/building.md @@ -5,6 +5,38 @@ Sunshine binaries are built using [CMake](https://cmake.org) and requires `cmake ### Dependencies +#### FreeBSD +@attention{Sunshine support for FreeBSD is experimental and may be incomplete or not work as expected.} + +##### Install dependencies +```sh +pkg install -y \ + audio/opus \ + audio/pulseaudio \ + devel/cmake \ + devel/evdev-proto \ + devel/git \ + devel/libayatana-appindicator \ + devel/libevdev \ + devel/libnotify \ + devel/ninja \ + devel/pkgconf \ + ftp/curl \ + graphics/libdrm \ + graphics/wayland \ + multimedia/libva \ + net/miniupnpc \ + ports-mgmt/pkg \ + security/openssl \ + shells/bash \ + www/npm \ + x11/libX11 \ + x11/libxcb \ + x11/libXfixes \ + x11/libXrandr \ + x11/libXtst +``` + #### Linux Dependencies vary depending on the distribution. You can reference our [linux_build.sh](https://github.com/LizardByte/Sunshine/blob/master/scripts/linux_build.sh) script for a list of @@ -124,6 +156,11 @@ ninja -C build ### Package @tabs{ + @tab{FreeBSD | @tabs{ + @tab{pkg | ```bash + cpack -G FREEBSD --config ./build/CPackConfig.cmake + ```} + }} @tab{Linux | @tabs{ @tab{deb | ```bash cpack -G DEB --config ./build/CPackConfig.cmake diff --git a/docs/configuration.md b/docs/configuration.md index f788729d..6c9682bf 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -26,6 +26,7 @@ location by modifying the configuration file. | OS | Location | |---------|-------------------------------------------------| | Docker | @code{}/config@endcode | +| FreeBSD | @code{}~/.config/sunshine@endcode | | Linux | @code{}~/.config/sunshine@endcode | | macOS | @code{}~/.config/sunshine@endcode | | Windows | @code{}%ProgramFiles%\\Sunshine\\config@endcode | @@ -316,12 +317,12 @@ editing the `conf` file in a text editor. Use the examples as reference.
cmd /C <{{ $t('apps.env_qres_path') }}>\QRes.exe /X:%SUNSHINE_CLIENT_WIDTH% /Y:%SUNSHINE_CLIENT_HEIGHT% /R:%SUNSHINE_CLIENT_FPS%
sh -c "xrandr --output HDMI-1 --mode \"${SUNSHINE_CLIENT_WIDTH}x${SUNSHINE_CLIENT_HEIGHT}\" --rate ${SUNSHINE_CLIENT_FPS}"
+ TODO ++
Info: Detecting displays