Skip to content

Commit 69d7b6d

Browse files
feat(packaging/linux): enable cuda support for homebrew (#4593)
1 parent c313851 commit 69d7b6d

File tree

1 file changed

+83
-28
lines changed

1 file changed

+83
-28
lines changed

packaging/sunshine.rb

Lines changed: 83 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require "language/node"
22

33
class Sunshine < Formula
4+
CUDA_VERSION = "13.1".freeze
5+
CUDA_FORMULA = "cuda@#{CUDA_VERSION}".freeze
46
GCC_VERSION = "14".freeze
57
GCC_FORMULA = "gcc@#{GCC_VERSION}".freeze
68
IS_UPSTREAM_REPO = ENV.fetch("GITHUB_REPOSITORY", "") == "LizardByte/Sunshine"
@@ -33,13 +35,12 @@ class Sunshine < Formula
3335
sha256 x86_64_linux: "0000000000000000000000000000000000000000000000000000000000000000"
3436
end
3537

36-
option "with-docs", "Enable docs"
3738
option "with-static-boost", "Enable static link of Boost libraries"
3839
option "without-static-boost", "Disable static link of Boost libraries" # default option
3940

4041
depends_on "cmake" => :build
41-
depends_on "doxygen" => :build
42-
depends_on "graphviz" => :build
42+
depends_on "doxygen" => [:build, :recommended]
43+
depends_on "graphviz" => :build if build.with? "doxygen"
4344
depends_on "node" => :build
4445
depends_on "pkgconf" => :build
4546
depends_on "gcovr" => :test
@@ -56,6 +57,7 @@ class Sunshine < Formula
5657

5758
on_linux do
5859
depends_on GCC_FORMULA => [:build, :test]
60+
depends_on "lizardbyte/homebrew/#{CUDA_FORMULA}" => [:build, :recommended]
5961
depends_on "at-spi2-core"
6062
depends_on "avahi"
6163
depends_on "ayatana-ido"
@@ -102,19 +104,23 @@ class Sunshine < Formula
102104
cause "Requires C++23 support"
103105
end
104106

105-
def install
107+
def setup_build_environment
106108
ENV["BRANCH"] = "@GITHUB_BRANCH@"
107109
ENV["BUILD_VERSION"] = "@BUILD_VERSION@"
108110
ENV["COMMIT"] = "@GITHUB_COMMIT@"
109111

110-
if OS.linux?
111-
# Use GCC because gcov from llvm cannot handle our paths
112-
gcc_path = Formula[GCC_FORMULA]
113-
ENV["CC"] = "#{gcc_path.opt_bin}/gcc-#{GCC_VERSION}"
114-
ENV["CXX"] = "#{gcc_path.opt_bin}/g++-#{GCC_VERSION}"
115-
end
112+
setup_linux_gcc_environment if OS.linux?
113+
end
116114

117-
args = %W[
115+
def setup_linux_gcc_environment
116+
# Use GCC because gcov from llvm cannot handle our paths
117+
gcc_path = Formula[GCC_FORMULA]
118+
ENV["CC"] = "#{gcc_path.opt_bin}/gcc-#{GCC_VERSION}"
119+
ENV["CXX"] = "#{gcc_path.opt_bin}/g++-#{GCC_VERSION}"
120+
end
121+
122+
def base_cmake_args
123+
%W[
118124
-DBUILD_WERROR=ON
119125
-DCMAKE_CXX_STANDARD=23
120126
-DCMAKE_INSTALL_PREFIX=#{prefix}
@@ -126,52 +132,95 @@ def install
126132
-DSUNSHINE_PUBLISHER_WEBSITE='https://app.lizardbyte.dev'
127133
-DSUNSHINE_PUBLISHER_ISSUE_URL='https://app.lizardbyte.dev/support'
128134
]
135+
end
129136

137+
def add_test_args(args)
130138
if IS_UPSTREAM_REPO
131139
args << "-DBUILD_TESTS=ON"
132140
ohai "Building tests: enabled"
133141
else
134142
args << "-DBUILD_TESTS=OFF"
135143
ohai "Building tests: disabled"
136144
end
145+
end
137146

138-
if build.with? "docs"
147+
def add_docs_args(args)
148+
if build.with? "doxygen"
139149
ohai "Building docs: enabled"
140150
args << "-DBUILD_DOCS=ON"
141151
else
142152
ohai "Building docs: disabled"
143153
args << "-DBUILD_DOCS=OFF"
144154
end
155+
end
145156

157+
def add_boost_args(args)
146158
if build.without? "static-boost"
147159
args << "-DBOOST_USE_STATIC=OFF"
148160
ohai "Disabled statically linking Boost libraries"
149161
else
150-
args << "-DBOOST_USE_STATIC=ON"
151-
ohai "Enabled statically linking Boost libraries"
152-
153-
unless Formula["icu4c"].any_version_installed?
154-
odie <<~EOS
155-
icu4c must be installed to link against static Boost libraries,
156-
either install icu4c or use brew install sunshine --with-static-boost instead
157-
EOS
158-
end
159-
ENV.append "CXXFLAGS", "-I#{Formula["icu4c"].opt_include}"
160-
icu4c_lib_path = Formula["icu4c"].opt_lib.to_s
161-
ENV.append "LDFLAGS", "-L#{icu4c_lib_path}"
162-
ENV["LIBRARY_PATH"] = icu4c_lib_path
163-
ohai "Linking against ICU libraries at: #{icu4c_lib_path}"
162+
configure_static_boost(args)
164163
end
164+
end
165+
166+
def configure_static_boost(args)
167+
args << "-DBOOST_USE_STATIC=ON"
168+
ohai "Enabled statically linking Boost libraries"
165169

166-
args << "-DCUDA_FAIL_ON_MISSING=OFF" if OS.linux?
170+
unless Formula["icu4c"].any_version_installed?
171+
odie <<~EOS
172+
icu4c must be installed to link against static Boost libraries,
173+
either install icu4c or use brew install sunshine --with-static-boost instead
174+
EOS
175+
end
176+
ENV.append "CXXFLAGS", "-I#{Formula["icu4c"].opt_include}"
177+
icu4c_lib_path = Formula["icu4c"].opt_lib.to_s
178+
ENV.append "LDFLAGS", "-L#{icu4c_lib_path}"
179+
ENV["LIBRARY_PATH"] = icu4c_lib_path
180+
ohai "Linking against ICU libraries at: #{icu4c_lib_path}"
181+
end
167182

183+
def add_cuda_args(args)
184+
return unless OS.linux?
185+
186+
if build.with?(CUDA_FORMULA)
187+
configure_cuda(args)
188+
else
189+
args << "-DSUNSHINE_ENABLE_CUDA=OFF"
190+
ohai "CUDA disabled"
191+
end
192+
end
193+
194+
def configure_cuda(args)
195+
cuda_path = Formula["lizardbyte/homebrew/#{CUDA_FORMULA}"]
196+
nvcc_path = "#{cuda_path.opt_bin}/nvcc"
197+
gcc_path = Formula[GCC_FORMULA]
198+
199+
args << "-DSUNSHINE_ENABLE_CUDA=ON"
200+
args << "-DCMAKE_CUDA_COMPILER:PATH=#{nvcc_path}"
201+
args << "-DCMAKE_CUDA_HOST_COMPILER=#{gcc_path.opt_bin}/gcc-#{GCC_VERSION}"
202+
ohai "CUDA enabled with nvcc at: #{nvcc_path}"
203+
end
204+
205+
def build_cmake_args
206+
args = base_cmake_args
207+
add_test_args(args)
208+
add_docs_args(args)
209+
add_boost_args(args)
210+
add_cuda_args(args)
211+
args
212+
end
213+
214+
def build_and_install_project
168215
system "cmake", "-S", ".", "-B", "build", "-G", "Unix Makefiles",
169216
*std_cmake_args,
170-
*args
217+
*build_cmake_args
171218

172219
system "make", "-C", "build"
173220
system "make", "-C", "build", "install"
221+
end
174222

223+
def install_platform_specific_files
175224
bin.install "build/tests/test_sunshine" if IS_UPSTREAM_REPO
176225

177226
# codesign the binary on intel macs
@@ -180,6 +229,12 @@ def install
180229
bin.install "src_assets/linux/misc/postinst" if OS.linux?
181230
end
182231

232+
def install
233+
setup_build_environment
234+
build_and_install_project
235+
install_platform_specific_files
236+
end
237+
183238
service do
184239
run [opt_bin/"sunshine", "~/.config/sunshine/sunshine.conf"]
185240
end

0 commit comments

Comments
 (0)