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 7, 2024
1 parent 3b3e681 commit d2cc861
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 0 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,100 @@ 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"
commit=${{ github.sha }}
clone_url=${{ github.event.repository.clone_url }}
source_tarball=${{ github.event.repository.html_url }}/archive/${commit}.tar.gz
branch="${{ github.ref_name }}"
else
echo "This is a PR event"
commit=${{ github.event.pull_request.head.sha }}
clone_url=${{ github.event.pull_request.head.repo.clone_url }}
source_tarball=${{ github.event.pull_request.head.repo.html_url }}/archive/${commit}.tar.gz
branch="${{ github.event.pull_request.head.ref }}"
fi
echo "Commit: ${commit}"
echo "Clone URL: ${clone_url}"
mkdir build
cd build
cmake \
-DGITHUB_COMMIT="${commit}" \
-DGITHUB_CLONE_URL="${clone_url}" \
-DGITHUB_BRANCH="${branch}" \
-DSUNSHINE_CONFIGURE_HOMEBREW=ON \
-DSUNSHINE_CONFIGURE_ONLY=ON \
..
cd ..
# copy formula to artifacts
mkdir -p artifacts
cp -f ./build/sunshine.rb ./artifacts/
# move formula to build/Formula
mkdir -p build/Formula
mv ./build/sunshine.rb ./build/Formula/sunshine.rb
# testing
cat ./artifacts/sunshine.rb
- name: Install formula
run: |
brew install ./build/Formula/sunshine.rb
- name: Upload Artifacts
if: ${{ matrix.release }}
uses: actions/upload-artifact@v4
with:
name: sunshine-homebrew
path: artifacts/

- name: Create/Update GitHub Release
if: ${{ needs.setup_release.outputs.create_release == 'true' && matrix.release }}
uses: ncipollo/release-action@v1
with:
name: ${{ needs.setup_release.outputs.release_name }}
tag: ${{ needs.setup_release.outputs.release_tag }}
commit: ${{ needs.setup_release.outputs.release_commit }}
artifacts: "*artifacts/*"
token: ${{ secrets.GH_BOT_TOKEN }}
allowUpdates: true
body: ${{ needs.setup_release.outputs.release_body }}
discussionCategory: announcements
prerelease: ${{ needs.setup_release.outputs.pre_release }}

build_mac_port:
needs: [check_changelog, setup_release]
strategy:
Expand Down
2 changes: 2 additions & 0 deletions cmake/prep/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ option(CUDA_INHERIT_COMPILE_OPTIONS
your IDE throws errors about unknown flags after running cmake." ON)

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
51 changes: 51 additions & 0 deletions packaging/macos/sunshine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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
# initialize submodules
system "git", "submodule", "update", "--remote", "--init", "--recursive", "--depth", "1"

# todo: fix vite build
system "sed", "-i", "''", "s/SUNSHINE_SOURCE_ASSETS_DIR=${SUNSHINE_SOURCE_ASSETS_DIR} SUNSHINE_ASSETS_DIR=${CMAKE_BINARY_DIR}//", "cmake/targets/common.cmake"

args = %W[
-DBUIld_WERROR=ON
-DOPENSSL_ROOT_DIR=#{Formula["openssl"].opt_prefix}
-DSUNSHINE_ASSETS_DIR=sunshine/assets
]
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
shell_output("#{bin}/sunshine --version").strip

# todo: add unit tests
end
end

0 comments on commit d2cc861

Please sign in to comment.