Skip to content

Commit

Permalink
build(macos): add homebrew formula
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher committed Mar 8, 2024
1 parent 7cdd156 commit 659e0d7
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 7 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,95 @@ jobs:
discussionCategory: announcements
prerelease: ${{ needs.setup_release.outputs.pre_release }}

build_mac_brew:
needs: [check_changelog, setup_release]
strategy:
fail-fast: false # false to test all, true to fail entire job if any fail
matrix:
include:
# 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_version: "13"
- os_version: "14"
name: Homebrew (macOS-${{ matrix.os_version }})
runs-on: macos-${{ 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
branch=${GITHUB_HEAD_REF}
# check the branch variable
if [ -z "$branch" ]
then
echo "This is a PUSH event"
clone_url=${{ github.event.repository.clone_url }}
branch="${{ github.ref_name }}"
else
echo "This is a PR event"
clone_url=${{ github.event.pull_request.head.repo.clone_url }}
branch="${{ github.event.pull_request.head.ref }}"
fi
echo "Branch: ${branch}"
echo "Clone URL: ${clone_url}"
mkdir build
cd build
cmake \
-DGITHUB_BRANCH="${branch}" \
-DGITHUB_CLONE_URL="${clone_url}" \
-DSUNSHINE_CONFIGURE_HOMEBREW=ON \
-DSUNSHINE_CONFIGURE_ONLY=ON \
..
cd ..
# copy formula to artifacts
mkdir -p homebrew/Formula
cp -f ./build/sunshine.rb ./homebrew/Formula/sunshine.rb
# testing
cat ./homebrew/Formula/sunshine.rb
- name: Install formula
env:
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
run: |
brew install --verbose ./build/sunshine.rb
- name: Test formula
run: |
brew test sunshine
- name: Upload Artifacts
if: ${{ matrix.release }}
uses: actions/upload-artifact@v4
with:
name: sunshine-homebrew
path: homebrew/

- name: Publish Homebrew Formula
if: |
(github.repository_owner == 'LizardByte' &&
needs.setup_release.outputs.create_release == 'true' &&
github.ref == 'refs/heads/master' &&
matrix.release)
uses: LizardByte/homebrew-release-action@v2024.307.223116
with:
git_email: ${{ secrets.GH_BOT_EMAIL }}
git_username: ${{ secrets.GH_BOT_NAME }}
token: ${{ secrets.GH_BOT_TOKEN }}

build_mac_port:
needs: [check_changelog, setup_release]
strategy:
Expand Down
8 changes: 8 additions & 0 deletions cmake/prep/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ option(CUDA_INHERIT_COMPILE_OPTIONS
"When building CUDA code, inherit compile options from the the main project. You may want to disable this if
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)
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
3 changes: 3 additions & 0 deletions cmake/prep/special_package_configuration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ 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)
include(GNUInstallDirs) # this needs to be included prior to configuring the desktop files

Expand Down
13 changes: 12 additions & 1 deletion cmake/targets/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,19 @@ endif()

target_compile_options(sunshine PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${SUNSHINE_COMPILE_OPTIONS}>;$<$<COMPILE_LANGUAGE:CUDA>:${SUNSHINE_COMPILE_OPTIONS_CUDA};-std=c++17>) # cmake-lint: disable=C0301

# Homebrew build fails the vite build if we set these environment variables
if(${SUNSHINE_BUILD_HOMEBREW})
set(NPM_SOURCE_ASSETS_DIR "")
set(NPM_ASSETS_DIR "")
set(NPM_BUILD_HOMEBREW "true")
else()
set(NPM_SOURCE_ASSETS_DIR ${SUNSHINE_SOURCE_ASSETS_DIR})
set(NPM_ASSETS_DIR ${CMAKE_BINARY_DIR})
set(NPM_BUILD_HOMEBREW "")
endif()

#WebUI build
add_custom_target(web-ui ALL
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
COMMENT "Installing NPM Dependencies and Building the Web UI"
COMMAND bash -c \"npm install && SUNSHINE_SOURCE_ASSETS_DIR=${SUNSHINE_SOURCE_ASSETS_DIR} SUNSHINE_ASSETS_DIR=${CMAKE_BINARY_DIR} npm run build\") # cmake-lint: disable=C0301
COMMAND bash -c \"npm install && SUNSHINE_BUILD_HOMEBREW=${NPM_BUILD_HOMEBREW} SUNSHINE_SOURCE_ASSETS_DIR=${NPM_SOURCE_ASSETS_DIR} SUNSHINE_ASSETS_DIR=${NPM_ASSETS_DIR} npm run build\") # cmake-lint: disable=C0301
10 changes: 10 additions & 0 deletions docs/source/about/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,16 @@ Install
cd /etc/sunshine/assets
uninstall_pkg.sh
.. tab:: Homebrew

#. Install `Homebrew <https://docs.brew.sh/Installation>`__
#. Update the Homebrew sources and install Sunshine.

.. code-block:: bash
brew tap LizardByte/homebrew
brew install sunshine
.. tab:: Portfile

#. Install `MacPorts <https://www.macports.org>`__
Expand Down
62 changes: 62 additions & 0 deletions packaging/macos/sunshine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require "language/node"

class @PROJECT_NAME@ < Formula
desc "@PROJECT_DESCRIPTION@"
homepage "@PROJECT_HOMEPAGE_URL@"
url "@GITHUB_CLONE_URL@",
tag: "@GITHUB_BRANCH@"
version "@PROJECT_VERSION@"
license all_of: ["GPL-3.0-only"]
head "@GITHUB_CLONE_URL@"

depends_on "boost" => :build
depends_on "cmake" => :build
depends_on "pkg-config" => :build
depends_on "curl"
depends_on "miniupnpc"
depends_on "node"
depends_on "openssl"
depends_on "opus"

def install
args = %W[
-DBUIld_WERROR=ON
-DCMAKE_INSTALL_PREFIX=#{prefix}
-DOPENSSL_ROOT_DIR=#{Formula["openssl"].opt_prefix}
-DSUNSHINE_ASSETS_DIR=sunshine/assets
-DSUNSHINE_BUILD_HOMEBREW=ON
]
system "cmake", "-S", ".", "-B", "build", *std_cmake_args, *args

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

service do
run [opt_bin/"sunshine", "~/.config/sunshine/sunshine.conf"]
end

test do
# test that the binary runs at all
output = shell_output("#{bin}/sunshine --version").strip
puts output

# todo: add unit tests
end

def caveats
<<~EOS
Thanks for installing @PROJECT_NAME@!
To get started, review the documentation at:
https://docs.lizardbyte.dev/projects/sunshine/en/latest/
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
end
end
17 changes: 11 additions & 6 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ import process from 'process'
let assetsSrcPath = 'src_assets/common/assets/web';
let assetsDstPath = 'build/assets/web';

if (process.env.SUNSHINE_SOURCE_ASSETS_DIR) {
console.log("Using srcdir from Cmake: " + resolve(process.env.SUNSHINE_SOURCE_ASSETS_DIR,"common/assets/web"));
assetsSrcPath = resolve(process.env.SUNSHINE_SOURCE_ASSETS_DIR,"common/assets/web")
if (process.env.SUNSHINE_BUILD_HOMEBREW) {
console.log("Building for homebrew, using default paths")
}
if (process.env.SUNSHINE_ASSETS_DIR) {
console.log("Using destdir from Cmake: " + resolve(process.env.SUNSHINE_ASSETS_DIR,"assets/web"));
assetsDstPath = resolve(process.env.SUNSHINE_ASSETS_DIR,"assets/web")
else {
if (process.env.SUNSHINE_SOURCE_ASSETS_DIR) {
console.log("Using srcdir from Cmake: " + resolve(process.env.SUNSHINE_SOURCE_ASSETS_DIR,"common/assets/web"));
assetsSrcPath = resolve(process.env.SUNSHINE_SOURCE_ASSETS_DIR,"common/assets/web")
}
if (process.env.SUNSHINE_ASSETS_DIR) {
console.log("Using destdir from Cmake: " + resolve(process.env.SUNSHINE_ASSETS_DIR,"assets/web"));
assetsDstPath = resolve(process.env.SUNSHINE_ASSETS_DIR,"assets/web")
}
}

let header = fs.readFileSync(resolve(assetsSrcPath, "template_header.html"))
Expand Down

0 comments on commit 659e0d7

Please sign in to comment.