From fa9e6f05bedf2dbfc67f6372b5016bb629e9e859 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sun, 29 Sep 2024 01:06:19 -0400 Subject: [PATCH] build(fedora): add copr build --- .github/workflows/ci-copr.yml | 32 ++++ packaging/linux/fedora/copr-build.sh | 37 +++++ packaging/linux/fedora/sunshine.spec | 237 +++++++++++++++++++++++++++ 3 files changed, 306 insertions(+) create mode 100644 .github/workflows/ci-copr.yml create mode 100644 packaging/linux/fedora/copr-build.sh create mode 100644 packaging/linux/fedora/sunshine.spec diff --git a/.github/workflows/ci-copr.yml b/.github/workflows/ci-copr.yml new file mode 100644 index 00000000000..516f4891b3d --- /dev/null +++ b/.github/workflows/ci-copr.yml @@ -0,0 +1,32 @@ +--- +name: CI Copr + +on: + pull_request: + branches: [master] + types: [opened, synchronize, reopened] + push: + branches: [master] + workflow_dispatch: + +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + +jobs: + build: + name: Copr build + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Submit the build + env: + COPR_PR_WEBHOOK: + https://copr.fedorainfracloud.org/webhooks/custom-dir/lizardbyte/Sunshine:custom:pr:${{github.event.number}}/4544d2cd-9bf4-4409-a767-a9ee5673c3f2/sunshine/ + COPR_PUSH_WEBHOOK: ${{ secrets.COPR_PUSH_WEBHOOK }}/sunshine/ + run: | + curl https://raw.githubusercontent.com/praiskup/copr-ci-tooling/main/copr-gh-actions-submit > submit + bash submit ${{ github.event.pull_request.number }} diff --git a/packaging/linux/fedora/copr-build.sh b/packaging/linux/fedora/copr-build.sh new file mode 100644 index 00000000000..efb459f2556 --- /dev/null +++ b/packaging/linux/fedora/copr-build.sh @@ -0,0 +1,37 @@ +#! /bin/sh -x + +# This file is not used directly in this repository. It should be uploaded to Copr whenever the file changes. + +set -e +resultdir=$PWD +git clone https://github.com/LizardByte/Sunshine.git --depth 1 +cd Sunshine + +# optional part; drop if building against 'master' is enough +if test -z "$REVISION"; then + # the hook_payload file contains webhook JSON payload (copr creates it for + # us); it is created only if the build is triggered by Custom webhook. + if test -f "$resultdir"/hook_payload; then + git clone https://github.com/praiskup/copr-ci-tooling \ + "$resultdir/cct" --depth 1 + export PATH="$resultdir/cct:$PATH" + github-checkout "$resultdir"/hook_payload + fi +else + git checkout "$REVISION" +fi + +# cmake and cpack +./scripts/linux_build.sh \ + --publisher-name='LizardByte' \ + --publisher-website='https://app.lizardbyte.dev' \ + --publisher-issue-url='https://app.lizardbyte.dev/support' \ + --sudo-off + +# tests +export DISPLAY=:1 +Xvfb ${DISPLAY} -screen 0 1024x768x24 & +./build/tests/test_sunshine --gtest_color=yes + +# Move the generated RPM to the result directory +mv ./build/cpack_artifacts/Sunshine.rpm "$resultdir/sunshine.rpm" diff --git a/packaging/linux/fedora/sunshine.spec b/packaging/linux/fedora/sunshine.spec new file mode 100644 index 00000000000..3659b1f37ae --- /dev/null +++ b/packaging/linux/fedora/sunshine.spec @@ -0,0 +1,237 @@ +%global build_timestamp %(date +"%Y%m%d") +%undefine _hardened_build + +Name: sunshine +Version: 2024.911.215654 # TODO: can we get this dynamically? +Summary: Sunshine is a self-hosted game stream host for Moonlight. +Release: 1%{?dist} +License: GPLv3-only +URL: https://github.com/LizardByte/Sunshine +Source0: sunshine.sysusers # TODO: what is this? +Source1: Linux-x86_64.tar.gz # TODO: convert build-deps to cmake project and remove this + +BuildRequires: boost-devel +BuildRequires: cmake +BuildRequires: gcc +BuildRequires: gcc-c++ +BuildRequires: libayatana-appindicator3-devel +BuildRequires: libcap-devel +BuildRequires: libcurl-devel +BuildRequires: libdrm-devel +BuildRequires: libevdev-devel +BuildRequires: libgudev +BuildRequires: libnotify-devel +BuildRequires: libva-devel +BuildRequires: libvdpau-devel +BuildRequires: libX11-devel +BuildRequires: libxcb-devel +BuildRequires: libXcursor-devel +BuildRequires: libXfixes-devel +BuildRequires: libXi-devel +BuildRequires: libXinerama-devel +BuildRequires: libXrandr-devel +BuildRequires: libXtst-devel +BuildRequires: git +BuildRequires: mesa-libGL-devel +BuildRequires: miniupnpc-devel +BuildRequires: npm +BuildRequires: numactl-devel +BuildRequires: openssl-devel +BuildRequires: opus-devel +BuildRequires: pulseaudio-libs-devel +BuildRequires: rpm-build +BuildRequires: systemd-udev +BuildRequires: systemd-rpm-macros +%{?sysusers_requires_compat} # TODO: what is this? +BuildRequires: wget +BuildRequires: which + +# Conditional BuildRequires for cuda-gcc based on Fedora version and architecture +%if 0%{?fedora} >= 40 && "%{_target_cpu}" == "x86_64" +BuildRequires: cuda-gcc-c++ # TODO: why not use this for all builds? +%endif + +Requires: boost >= 1.85.0 +Requires: libcap >= 2.22 +Requires: libcurl >= 7.0 +Requires: libdrm > 2.4.97 +Requires: libevdev >= 1.5.6 +Requires: libopusenc >= 0.2.1 +Requires: libva >= 2.14.0 +Requires: libvdpau >= 1.5 +Requires: libwayland-client >= 1.20.0 +Requires: libX11 >= 1.7.3.1 +Requires: miniupnpc >= 2.2.4 +Requires: numactl-libs >= 2.0.14 +Requires: openssl >= 3.0.2 +Requires: pulseaudio-libs >= 10.0 +Requires: libayatana-appindicator3 >= 0.5.3 + +%description +Sunshine is a self-hosted game stream host for Moonlight. Offering low latency, cloud gaming server capabilities with support for AMD, Intel, and Nvidia GPUs for hardware encoding. Software encoding is also available. You can connect to Sunshine from any Moonlight client on a variety of devices. A web UI is provided to allow configuration, and client pairing, from your favorite web browser. Pair from the local server or any mobile device. + +%prep +git clone --single-branch --branch master https://github.com/LizardByte/Sunshine +cd Sunshine +git fetch --tags +git checkout v%{version} +git submodule update --init --recursive +npm install + +# patches +%autopatch -p1 + +# HACK: ffmpeg needs to be built with up-to-date libs, lets drop in our own built on Fedora for the build to replace the Ubuntu built versions +tar -xzf %{_sourcedir}/Linux-x86_64.tar.gz -C third-party/build-deps/ffmpeg/Linux-x86_64 --strip-components=1 + +%build +# Set up the build directory for Sunshine +mkdir -p %{_builddir}/Sunshine/build +cd %{_builddir}/Sunshine/build + +# we need to clear these flags to avoid linkage errors with cuda-gcc-c++ +export CFLAGS="" +export CXXFLAGS="" +export FFLAGS="" +export FCFLAGS="" +export LDFLAGS="" + +# Detect the architecture and Fedora version +ARCH=$(uname -m) +FEDORA_VERSION=%{fedora} + +if [ "$ARCH" == "x86_64" ] && [ "$FEDORA_VERSION" -ge 40 ]; then # TODO: we can use cuda for aarch64 too + # Set up CUDA environment variables + export CUDA_VERSION="12.6.0" + export CUDA_BUILD="560.28.03" + export CUDA_RUNFILE="cuda_${CUDA_VERSION}_${CUDA_BUILD}_linux.run" + export CUDA_INSTALL_PATH="%{_builddir}/cuda-$CUDA_VERSION" + export CUDA_URL="https://developer.download.nvidia.com/compute/cuda/${CUDA_VERSION}/local_installers/${CUDA_RUNFILE}" + export NVCC_PREPEND_FLAGS='-ccbin /usr/bin/cuda -allow-unsupported-compiler' + + # Install CUDA if not already installed + if [ ! -d "${CUDA_INSTALL_PATH}" ]; then + curl -o "./cuda.run" "${CUDA_URL}" + chmod a+x ./cuda.run + ./cuda.run --silent --toolkit --override --no-drm --no-man-page --no-opengl-libs --toolkitpath=${CUDA_INSTALL_PATH} + rm ./cuda.run + else + echo "CUDA is already installed at ${CUDA_INSTALL_PATH}, skipping installation." + fi + + # Update environment variables for CUDA + export PATH=${CUDA_INSTALL_PATH}/bin:${PATH} + export LD_LIBRARY_PATH=${CUDA_INSTALL_PATH}/lib64:${LD_LIBRARY_PATH} + export PATH=/usr/bin/cuda:$PATH + + # Configure cmake to use CUDA + # TODO: set extra cmake args to use when building with cuda and just have one cmake call + cmake .. \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF \ + -DCMAKE_POSITION_INDEPENDENT_CODE=OFF \ + -DCMAKE_INSTALL_PREFIX=%{_prefix} \ + -DBUILD_DOCS=OFF \ + -DSUNSHINE_ENABLE_CUDA=ON \ + -DCMAKE_CUDA_COMPILER=${CUDA_INSTALL_PATH}/bin/nvcc \ + -DSUNSHINE_ASSETS_DIR=%{_datadir}/sunshine \ + -DSUNSHINE_EXECUTABLE_PATH=%{_bindir}/sunshine \ + -DSUNSHINE_ENABLE_WAYLAND=ON \ + -DSUNSHINE_ENABLE_X11=ON \ + -DSUNSHINE_ENABLE_DRM=ON + %make_build + +else + # Configure cmake without CUDA + cmake .. \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF \ + -DCMAKE_POSITION_INDEPENDENT_CODE=OFF \ + -DCMAKE_INSTALL_PREFIX=%{_prefix} \ + -DBUILD_DOCS=OFF \ + -DSUNSHINE_ENABLE_CUDA=OFF \ + -DSUNSHINE_ASSETS_DIR=%{_datadir}/sunshine \ + -DSUNSHINE_EXECUTABLE_PATH=%{_bindir}/sunshine \ + -DSUNSHINE_ENABLE_WAYLAND=ON \ + -DSUNSHINE_ENABLE_X11=ON \ + -DSUNSHINE_ENABLE_DRM=ON + %make_build +fi + +%install +cd %{_builddir}/Sunshine/build +%make_install + +# Add modules-load configuration +install -D -m 0644 /dev/stdin %{buildroot}/usr/lib/modules-load.d/uhid.conf <