Skip to content

Commit

Permalink
build(linux): add homebrew support
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher committed Jun 11, 2024
1 parent e1f0ca8 commit b6c4f05
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 30 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ jobs:
tag: ${{ needs.setup_release.outputs.release_tag }}
token: ${{ secrets.GH_BOT_TOKEN }}

build_mac_brew:
build_homebrew:
needs: [setup_release]
strategy:
fail-fast: false # false to test all, true to fail entire job if any fail
Expand All @@ -491,21 +491,21 @@ jobs:
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
# while GitHub has larger macOS runners, they are not available for our repos :(
- os_version: "12"
release: true
os_name: "macos"
- os_version: "13"
os_name: "macos"
- os_version: "14"
name: Homebrew (macOS-${{ matrix.os_version }})
runs-on: macos-${{ matrix.os_version }}
os_name: "macos"
- os_version: "latest"
os_name: "ubuntu"
release: true
name: Homebrew (${{ matrix.os_name }}-${{ matrix.os_version }})
runs-on: ${{ matrix.os_name }}-${{ matrix.os_version }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Dependencies Homebrew
run: |
# install dependencies using homebrew
brew install cmake
- name: Configure formula
run: |
# variables for formula
Expand Down Expand Up @@ -557,7 +557,7 @@ jobs:
path: homebrew/

- name: Validate Homebrew Formula
uses: LizardByte/homebrew-release-action@v2024.609.4731
uses: LizardByte/homebrew-release-action@fix(action)-print-output-in-realtime
with:
formula_file: ${{ github.workspace }}/homebrew/sunshine.rb
git_email: ${{ secrets.GH_BOT_EMAIL }}
Expand Down
41 changes: 34 additions & 7 deletions cmake/compile_definitions/linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,42 @@ elseif(NOT LIBDRM_FOUND)
endif()

# evdev
pkg_check_modules(PC_EVDEV libevdev REQUIRED)
find_path(EVDEV_INCLUDE_DIR libevdev/libevdev.h
HINTS ${PC_EVDEV_INCLUDE_DIRS} ${PC_EVDEV_INCLUDEDIR})
find_library(EVDEV_LIBRARY
NAMES evdev libevdev)
pkg_check_modules(PC_EVDEV libevdev)
if(PC_EVDEV_FOUND)
find_path(EVDEV_INCLUDE_DIR libevdev/libevdev.h
HINTS ${PC_EVDEV_INCLUDE_DIRS} ${PC_EVDEV_INCLUDEDIR})
find_library(EVDEV_LIBRARY
NAMES evdev libevdev)
else()
include(ExternalProject)

set(libevdev_version libevdev-1.13.2)

ExternalProject_Add(libevdev
URL http://www.freedesktop.org/software/libevdev/${libevdev_version}.tar.xz
PREFIX ${libevdev_version}
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR>
BUILD_COMMAND "make"
INSTALL_COMMAND ""
)

ExternalProject_Get_Property(libevdev SOURCE_DIR)
message(STATUS "libevdev source dir: ${SOURCE_DIR}")
set(EVDEV_INCLUDE_DIR "${SOURCE_DIR}")

ExternalProject_Get_Property(libevdev BINARY_DIR)
message(STATUS "libevdev binary dir: ${BINARY_DIR}")
set(EVDEV_LIBRARY "${BINARY_DIR}/libevdev/.libs/libevdev.a")

# compile libevdev before sunshine
set(SUNSHINE_TARGET_DEPENDENCIES ${SUNSHINE_TARGET_DEPENDENCIES} libevdev)
endif()

if(EVDEV_INCLUDE_DIR AND EVDEV_LIBRARY)
include_directories(SYSTEM ${EVDEV_INCLUDE_DIR})
list(APPEND PLATFORM_LIBRARIES ${EVDEV_LIBRARY})
else()
message(FATAL_ERROR "Couldn't find or fetch libevdev")
endif()

# vaapi
Expand Down Expand Up @@ -226,7 +254,7 @@ else()
message(STATUS "Tray icon disabled")
endif()

if (${SUNSHINE_TRAY} EQUAL 0 AND SUNSHINE_REQUIRE_TRAY)
if(${SUNSHINE_ENABLE_TRAY} AND ${SUNSHINE_TRAY} EQUAL 0 AND SUNSHINE_REQUIRE_TRAY)
message(FATAL_ERROR "Tray icon is required")
endif()

Expand All @@ -253,5 +281,4 @@ list(APPEND PLATFORM_LIBRARIES

include_directories(
SYSTEM
"${CMAKE_SOURCE_DIR}/third-party/nv-codec-headers/include"
"${CMAKE_SOURCE_DIR}/third-party/glad/include")
5 changes: 2 additions & 3 deletions cmake/prep/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ option(CUDA_INHERIT_COMPILE_OPTIONS
your IDE throws errors about unknown flags after running cmake." ON)

if(UNIX)
# technically, the homebrew build could be on linux as well... no idea if it would actually work
option(SUNSHINE_BUILD_HOMEBREW
"Enable a Homebrew build." OFF)
option(SUNSHINE_CONFIGURE_HOMEBREW
"Configure macOS Homebrew formula. Recommended to use with SUNSHINE_CONFIGURE_ONLY" OFF)
endif ()

if(APPLE)
option(SUNSHINE_CONFIGURE_HOMEBREW
"Configure macOS Homebrew formula. Recommended to use with SUNSHINE_CONFIGURE_ONLY" OFF)
option(SUNSHINE_CONFIGURE_PORTFILE
"Configure macOS Portfile. Recommended to use with SUNSHINE_CONFIGURE_ONLY" OFF)
option(SUNSHINE_PACKAGE_MACOS
Expand Down
13 changes: 8 additions & 5 deletions cmake/prep/special_package_configuration.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
if (APPLE)
if(UNIX)
if(${SUNSHINE_CONFIGURE_HOMEBREW})
configure_file(packaging/sunshine.rb sunshine.rb @ONLY)
endif()
endif()

if(APPLE)
if(${SUNSHINE_CONFIGURE_PORTFILE})
configure_file(packaging/macos/Portfile Portfile @ONLY)
endif()
if(${SUNSHINE_CONFIGURE_HOMEBREW})
configure_file(packaging/macos/sunshine.rb sunshine.rb @ONLY)
endif()
elseif (UNIX)
elseif(UNIX)
# configure the .desktop file
if(${SUNSHINE_BUILD_APPIMAGE})
configure_file(packaging/linux/AppImage/sunshine.desktop sunshine.desktop @ONLY)
Expand Down
3 changes: 3 additions & 0 deletions cmake/targets/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# this file will also load platform specific macros

add_executable(sunshine ${SUNSHINE_TARGET_FILES})
foreach(dep ${SUNSHINE_TARGET_DEPENDENCIES})
add_dependencies(sunshine ${dep}) # compile these before sunshine
endforeach()

# platform specific target definitions
if(WIN32)
Expand Down
52 changes: 47 additions & 5 deletions packaging/macos/sunshine.rb → packaging/sunshine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ class @PROJECT_NAME@ < Formula
license all_of: ["GPL-3.0-only"]
head "@GITHUB_CLONE_URL@", branch: "@GITHUB_DEFAULT_BRANCH@"

# https://docs.brew.sh/Brew-Livecheck#githublatest-strategy-block
livecheck do
url :stable
regex(/^v?(\d+\.\d+\.\d+)$/i)
strategy :github_latest do |json, regex|
match = json["tag_name"]&.match(regex)
next if match.blank?

match[1]
end
end

depends_on "boost" => :build
depends_on "cmake" => :build
depends_on "node" => :build
Expand All @@ -18,6 +30,27 @@ class @PROJECT_NAME@ < Formula
depends_on "openssl"
depends_on "opus"

on_linux do
depends_on "libcap"
depends_on "libdrm"
depends_on "libnotify"
depends_on "libva"
depends_on "libvdpau"
depends_on "libx11"
depends_on "libxcb"
depends_on "libxcursor"
depends_on "libxfixes"
depends_on "libxi"
depends_on "libxinerama"
depends_on "libxrandr"
depends_on "libxtst"
depends_on "mesa"
depends_on "numactl"
depends_on "pulseaudio"
depends_on "systemd"
depends_on "wayland"
end

def install
ENV["BRANCH"] = "@GITHUB_BRANCH@"
ENV["BUILD_VERSION"] = "@BUILD_VERSION@"
Expand All @@ -26,16 +59,19 @@ def install
args = %W[
-DBUILD_WERROR=ON
-DCMAKE_INSTALL_PREFIX=#{prefix}
-DHOMEBREW_ALLOW_FETCHCONTENT=ON
-DOPENSSL_ROOT_DIR=#{Formula["openssl"].opt_prefix}
-DSUNSHINE_ASSETS_DIR=sunshine/assets
-DSUNSHINE_BUILD_HOMEBREW=ON
-DSUNSHINE_ENABLE_TRAY=OFF
-DTESTS_ENABLE_PYTHON_TESTS=OFF
]
system "cmake", "-S", ".", "-B", "build", *std_cmake_args, *args

cd "build" do
system "make", "-j"
system "make", "install"

bin.install "tests/test_sunshine"
end
end
Expand All @@ -45,17 +81,23 @@ def install
end

def caveats
<<~EOS
caveats_message = <<~EOS
Thanks for installing @PROJECT_NAME@!
To get started, review the documentation at:
https://docs.lizardbyte.dev/projects/sunshine/en/latest/
EOS

Sunshine can only access microphones on macOS due to system limitations.
To stream system audio use "Soundflower" or "BlackHole".
if OS.mac?
caveats_message += <<~EOS
Sunshine can only access microphones on macOS due to system limitations.
To stream system audio use "Soundflower" or "BlackHole".
Gamepads are not currently supported on macOS.
EOS
Gamepads are not currently supported on macOS.
EOS
end

caveats_message
end

test do
Expand Down
5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ list(REMOVE_ITEM SUNSHINE_SOURCES ${CMAKE_SOURCE_DIR}/src/main.cpp)
add_executable(${PROJECT_NAME}
${TEST_SOURCES}
${SUNSHINE_SOURCES})

foreach(dep ${SUNSHINE_TARGET_DEPENDENCIES})
add_dependencies(${PROJECT_NAME} ${dep}) # compile these before sunshine
endforeach()

set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20)
target_link_libraries(${PROJECT_NAME}
${SUNSHINE_EXTERNAL_LIBRARIES}
Expand Down

0 comments on commit b6c4f05

Please sign in to comment.