diff --git a/scripts/linux_build.sh b/scripts/linux_build.sh index 055e7796..21a3d718 100755 --- a/scripts/linux_build.sh +++ b/scripts/linux_build.sh @@ -23,19 +23,23 @@ sudo_cmd="sudo" ubuntu_test_repo=0 step="all" +# constants +AARCH64="aarch64" +DOXYGEN="doxygen" + # Reusable function to detect nvcc path function detect_nvcc_path() { local nvcc_path="" # First check for system-installed CUDA nvcc_path=$(command -v nvcc 2>/dev/null) || true - if [ -n "$nvcc_path" ]; then + if [[ -n "$nvcc_path" ]]; then echo "$nvcc_path" return 0 fi # Then check for locally installed CUDA in build directory - if [ -f "${build_dir}/cuda/bin/nvcc" ]; then + if [[ -f "${build_dir}/cuda/bin/nvcc" ]]; then echo "${build_dir}/cuda/bin/nvcc" return 0 fi @@ -47,9 +51,9 @@ function detect_nvcc_path() { # Reusable function to setup NVM environment function setup_nvm_environment() { # Only setup NVM if it should be used for this distro - if [ "$nvm_node" == 1 ]; then + if [[ "$nvm_node" == 1 ]]; then # Check if NVM is installed and source it - if [ -f "$HOME/.nvm/nvm.sh" ]; then + if [[ -f "$HOME/.nvm/nvm.sh" ]]; then # shellcheck source=/dev/null source "$HOME/.nvm/nvm.sh" # Use the default node version installed by NVM @@ -60,6 +64,7 @@ function setup_nvm_environment() { echo "NVM not found, using system Node.js if available" fi fi + return 0 } function _usage() { @@ -191,17 +196,18 @@ function add_arch_deps() { 'wayland' ) - if [ "$skip_libva" == 0 ]; then + if [[ "$skip_libva" == 0 ]]; then dependencies+=( "libva" # VA-API ) fi - if [ "$skip_cuda" == 0 ]; then + if [[ "$skip_cuda" == 0 ]]; then dependencies+=( "cuda" # VA-API ) fi + return 0 } function add_debian_based_deps() { @@ -212,7 +218,7 @@ function add_debian_based_deps() { "build-essential" "cmake" "desktop-file-utils" - "doxygen" + "${DOXYGEN}" "file" "flex" # required if we need to compile doxygen "gcc-${gcc_version}" @@ -248,18 +254,20 @@ function add_debian_based_deps() { "xvfb" # necessary for headless unit testing ) - if [ "$skip_libva" == 0 ]; then + if [[ "$skip_libva" == 0 ]]; then dependencies+=( "libva-dev" # VA-API ) fi + return 0 } function add_test_ppa() { - if [ "$ubuntu_test_repo" == 1 ]; then + if [[ "$ubuntu_test_repo" == 1 ]]; then $package_install_command "software-properties-common" ${sudo_cmd} add-apt-repository ppa:ubuntu-toolchain-r/test -y fi + return 0 } function add_debian_deps() { @@ -269,6 +277,7 @@ function add_debian_deps() { "libayatana-appindicator3-dev" "systemd-dev" ) + return 0 } function add_ubuntu_deps() { @@ -277,6 +286,7 @@ function add_ubuntu_deps() { dependencies+=( "libappindicator3-dev" ) + return 0 } function add_fedora_deps() { @@ -284,7 +294,7 @@ function add_fedora_deps() { "appstream" "cmake" "desktop-file-utils" - "doxygen" + "${DOXYGEN}" "gcc${gcc_version}" "gcc${gcc_version}-c++" "git" @@ -319,11 +329,12 @@ function add_fedora_deps() { "xorg-x11-server-Xvfb" # necessary for headless unit testing ) - if [ "$skip_libva" == 0 ]; then + if [[ "$skip_libva" == 0 ]]; then dependencies+=( "libva-devel" # VA-API ) fi + return 0 } function install_cuda() { @@ -333,27 +344,27 @@ function install_cuda() { fi local cuda_override_arg="" - if [ "$distro" == "fedora" ]; then + if [[ "$distro" == "fedora" ]]; then cuda_override_arg="--override" fi local cuda_prefix="https://developer.download.nvidia.com/compute/cuda/" local cuda_suffix="" - if [ "$architecture" == "aarch64" ]; then + if [[ "$architecture" == "${AARCH64}" ]]; then local cuda_suffix="_sbsa" fi - if [ "$architecture" == "aarch64" ]; then + if [[ "$architecture" == "${AARCH64}" ]]; then # we need to patch the math-vector.h file for aarch64 fedora # back up /usr/include/bits/math-vector.h math_vector_file="" - if [ "$distro" == "ubuntu" ] || [ "$version" == "24.04" ]; then + if [[ "$distro" == "ubuntu" ]] || [[ "$version" == "24.04" ]]; then math_vector_file="/usr/include/aarch64-linux-gnu/bits/math-vector.h" - elif [ "$distro" == "fedora" ]; then + elif [[ "$distro" == "fedora" ]]; then math_vector_file="/usr/include/bits/math-vector.h" fi - if [ -n "$math_vector_file" ]; then + if [[ -n "$math_vector_file" ]]; then # patch headers https://bugs.launchpad.net/ubuntu/+source/mumax3/+bug/2032624 ${sudo_cmd} cp "$math_vector_file" "$math_vector_file.bak" ${sudo_cmd} sed -i 's/__Float32x4_t/int/g' "$math_vector_file" @@ -372,10 +383,10 @@ function install_cuda() { rm "${build_dir}/cuda.run" # run cuda patches - if [ "$cuda_patches" == 1 ]; then + if [[ "$cuda_patches" == 1 ]]; then echo "Applying CUDA patches" local patch_dir="${script_dir}/../packaging/linux/patches/${architecture}" - if [ -d "$patch_dir" ]; then + if [[ -d "$patch_dir" ]]; then for patch in "$patch_dir"/*.patch; do echo "Applying patch: $patch" patch -p2 \ @@ -388,6 +399,7 @@ function install_cuda() { echo "No patches found for architecture: $architecture" fi fi + return 0 } function check_version() { @@ -398,18 +410,18 @@ function check_version() { echo "Checking if $package_name is installed and at least version $min_version" - if [ "$distro" == "debian" ] || [ "$distro" == "ubuntu" ]; then + if [[ "$distro" == "debian" ]] || [[ "$distro" == "ubuntu" ]]; then installed_version=$(dpkg -s "$package_name" 2>/dev/null | grep '^Version:' | awk '{print $2}') - elif [ "$distro" == "fedora" ]; then + elif [[ "$distro" == "fedora" ]]; then installed_version=$(rpm -q --queryformat '%{VERSION}' "$package_name" 2>/dev/null) - elif [ "$distro" == "arch" ]; then + elif [[ "$distro" == "arch" ]]; then installed_version=$(pacman -Q "$package_name" | awk '{print $2}' ) else echo "Unsupported Distro" return 1 fi - if [ -z "$installed_version" ]; then + if [[ -z "$installed_version" ]]; then echo "Package not installed" return 1 fi @@ -430,13 +442,13 @@ function run_step_deps() { # Update the package list $package_update_command - if [ "$distro" == "arch" ]; then + if [[ "$distro" == "arch" ]]; then add_arch_deps - elif [ "$distro" == "debian" ]; then + elif [[ "$distro" == "debian" ]]; then add_debian_deps - elif [ "$distro" == "ubuntu" ]; then + elif [[ "$distro" == "ubuntu" ]]; then add_ubuntu_deps - elif [ "$distro" == "fedora" ]; then + elif [[ "$distro" == "fedora" ]]; then add_fedora_deps ${sudo_cmd} dnf group install "$dev_tools_group" -y fi @@ -455,10 +467,10 @@ function run_step_deps() { # compile cmake if the version is too low if ! check_version "cmake" "$cmake_min" "inf"; then cmake_prefix="https://github.com/Kitware/CMake/releases/download/v" - if [ "$architecture" == "x86_64" ]; then + if [[ "$architecture" == "x86_64" ]]; then cmake_arch="x86_64" - elif [ "$architecture" == "aarch64" ]; then - cmake_arch="aarch64" + elif [[ "$architecture" == "${AARCH64}" ]]; then + cmake_arch="${AARCH64}" fi url="${cmake_prefix}${target_cmake_version}/cmake-${target_cmake_version}-linux-${cmake_arch}.sh" echo "cmake url: ${url}" @@ -469,27 +481,27 @@ function run_step_deps() { fi # compile doxygen if version is too low - if ! check_version "doxygen" "$doxygen_min" "$doxygen_max"; then - if [ "${SUNSHINE_COMPILE_DOXYGEN}" == "true" ]; then + if ! check_version "${DOXYGEN}" "$doxygen_min" "$doxygen_max"; then + if [[ "${SUNSHINE_COMPILE_DOXYGEN}" == "true" ]]; then echo "Compiling doxygen" - doxygen_url="https://github.com/doxygen/doxygen/releases/download/Release_${_doxygen_min}/doxygen-${doxygen_min}.src.tar.gz" - echo "doxygen url: ${doxygen_url}" + doxygen_url="https://github.com/doxygen/doxygen/releases/download/Release_${_doxygen_min}/${DOXYGEN}-${doxygen_min}.src.tar.gz" + echo "${DOXYGEN} url: ${doxygen_url}" pushd "${build_dir}" - wget "$doxygen_url" --progress=bar:force:noscroll -q --show-progress -O "doxygen.tar.gz" - tar -xzf "doxygen.tar.gz" - cd "doxygen-${doxygen_min}" + wget "$doxygen_url" --progress=bar:force:noscroll -q --show-progress -O "${DOXYGEN}.tar.gz" + tar -xzf "${DOXYGEN}.tar.gz" + cd "${DOXYGEN}-${doxygen_min}" cmake -DCMAKE_BUILD_TYPE=Release -G="Ninja" -B="build" -S="." ninja -C "build" -j"${num_processors}" ${sudo_cmd} ninja -C "build" install popd else - echo "Doxygen version not in range, skipping docs" + echo "${DOXYGEN} version not in range, skipping docs" # Note: cmake_args will be set in cmake step fi fi # install node from nvm - if [ "$nvm_node" == 1 ]; then + if [[ "$nvm_node" == 1 ]]; then nvm_url="https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh" echo "nvm url: ${nvm_url}" wget -qO- ${nvm_url} | bash @@ -501,9 +513,10 @@ function run_step_deps() { fi # run the cuda install - if [ "$skip_cuda" == 0 ]; then + if [[ "$skip_cuda" == 0 ]]; then install_cuda fi + return 0 } function run_step_cmake() { @@ -514,7 +527,7 @@ function run_step_cmake() { # Detect CUDA path using the reusable function nvcc_path="" - if [ "$skip_cuda" == 0 ]; then + if [[ "$skip_cuda" == 0 ]]; then nvcc_path=$(detect_nvcc_path) fi @@ -537,32 +550,30 @@ function run_step_cmake() { "-DSUNSHINE_ENABLE_DRM=ON" ) - if [ "$appimage_build" == 1 ]; then + if [[ "$appimage_build" == 1 ]]; then cmake_args+=("-DSUNSHINE_BUILD_APPIMAGE=ON") fi # Publisher metadata - if [ -n "$publisher_name" ]; then + if [[ -n "$publisher_name" ]]; then cmake_args+=("-DSUNSHINE_PUBLISHER_NAME='${publisher_name}'") fi - if [ -n "$publisher_website" ]; then + if [[ -n "$publisher_website" ]]; then cmake_args+=("-DSUNSHINE_PUBLISHER_WEBSITE='${publisher_website}'") fi - if [ -n "$publisher_issue_url" ]; then + if [[ -n "$publisher_issue_url" ]]; then cmake_args+=("-DSUNSHINE_PUBLISHER_ISSUE_URL='${publisher_issue_url}'") fi # Handle doxygen docs flag - if ! check_version "doxygen" "$doxygen_min" "$doxygen_max"; then - if [ "${SUNSHINE_COMPILE_DOXYGEN}" != "true" ]; then - cmake_args+=("-DBUILD_DOCS=OFF") - fi + if ! check_version "${DOXYGEN}" "$doxygen_min" "$doxygen_max" && [[ "${SUNSHINE_COMPILE_DOXYGEN}" != "true" ]]; then + cmake_args+=("-DBUILD_DOCS=OFF") fi # Handle CUDA - if [ "$skip_cuda" == 0 ]; then + if [[ "$skip_cuda" == 0 ]]; then cmake_args+=("-DSUNSHINE_ENABLE_CUDA=ON") - if [ -n "$nvcc_path" ]; then + if [[ -n "$nvcc_path" ]]; then cmake_args+=("-DCMAKE_CUDA_COMPILER:PATH=$nvcc_path") cmake_args+=("-DCMAKE_CUDA_HOST_COMPILER=gcc-${gcc_version}") fi @@ -575,6 +586,7 @@ function run_step_cmake() { echo "cmake args:" echo "${cmake_args[@]}" cmake "${cmake_args[@]}" + return 0 } function run_step_validation() { @@ -584,9 +596,10 @@ function run_step_validation() { appstreamcli validate "build/dev.lizardbyte.app.Sunshine.metainfo.xml" appstream-util validate "build/dev.lizardbyte.app.Sunshine.metainfo.xml" desktop-file-validate "build/dev.lizardbyte.app.Sunshine.desktop" - if [ "$appimage_build" == 0 ]; then + if [[ "$appimage_build" == 0 ]]; then desktop-file-validate "build/dev.lizardbyte.app.Sunshine.terminal.desktop" fi + return 0 } function run_step_build() { @@ -597,30 +610,31 @@ function run_step_build() { # Build the project ninja -C "build" + return 0 } function run_step_package() { echo "Running step: Package" # Create the package - if [ "$skip_package" == 0 ]; then - if [ "$distro" == "debian" ] || [ "$distro" == "ubuntu" ]; then + if [[ "$skip_package" == 0 ]]; then + if [[ "$distro" == "debian" ]] || [[ "$distro" == "ubuntu" ]]; then cpack -G DEB --config ./build/CPackConfig.cmake - elif [ "$distro" == "fedora" ]; then + elif [[ "$distro" == "fedora" ]]; then cpack -G RPM --config ./build/CPackConfig.cmake fi fi + return 0 } function run_step_cleanup() { echo "Running step: Cleanup" - if [ "$skip_cleanup" == 0 ]; then - # restore the math-vector.h file - if [ "$architecture" == "aarch64" ] && [ -n "$math_vector_file" ]; then - ${sudo_cmd} mv -f "$math_vector_file.bak" "$math_vector_file" - fi + # restore the math-vector.h file + if [[ "$skip_cleanup" == 0 ]] && [[ "$architecture" == "${AARCH64}" ]] && [[ -n "$math_vector_file" ]]; then + ${sudo_cmd} mv -f "$math_vector_file.bak" "$math_vector_file" fi + return 0 } function run_install() { @@ -657,6 +671,7 @@ function run_install() { exit 1 ;; esac + return 0 } # Determine the OS and call the appropriate function @@ -764,13 +779,13 @@ echo "Detected Distro: $distro" echo "Detected Version: $version" echo "Detected Architecture: $architecture" -if [ "$architecture" != "x86_64" ] && [ "$architecture" != "aarch64" ]; then +if [[ "$architecture" != "x86_64" ]] && [[ "$architecture" != "${AARCH64}" ]]; then echo "Unsupported Architecture" exit 1 fi # export variables for github actions ci -if [ -f "$GITHUB_ENV" ]; then +if [[ -f "$GITHUB_ENV" ]]; then { echo "CC=gcc-${gcc_version}" echo "CXX=g++-${gcc_version}" diff --git a/scripts/macos_build.sh b/scripts/macos_build.sh new file mode 100755 index 00000000..80a3d936 --- /dev/null +++ b/scripts/macos_build.sh @@ -0,0 +1,199 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Default value for arguments +num_processors=$(sysctl -n hw.ncpu) +publisher_name="LizardByte" +publisher_website="https://app.lizardbyte.dev" +publisher_issue_url="https://app.lizardbyte.dev/support" +step="all" +build_docs="ON" +build_type="Release" +build_system="Unix Makefiles" + +# environment variables +BUILD_VER="" +BRANCH=$(git rev-parse --abbrev-ref HEAD) +COMMIT=$(git rev-parse --short HEAD) + +export BUILD_VER +export BRANCH +export COMMIT + +# boost could be included here but cmake will build the right version we need +required_formulas=( + "cmake" + "doxygen" + "graphviz" + "node" + "pkgconf" + "icu4c@78" + "miniupnpc" + "openssl@3" + "opus" + "llvm" +) + +function _usage() { + local exit_code=$1 + + cat </dev/null)" + "-DSUNSHINE_ASSETS_DIR=sunshine/assets" + "-DSUNSHINE_BUILD_HOMEBREW=ON" + "-DSUNSHINE_ENABLE_TRAY=ON" + "-DBUILD_DOCS=${build_docs}" + "-DBOOST_USE_STATIC=OFF" + ) + + # Publisher metadata + if [[ -n "$publisher_name" ]]; then + cmake_args+=("-DSUNSHINE_PUBLISHER_NAME='${publisher_name}'") + fi + if [[ -n "$publisher_website" ]]; then + cmake_args+=("-DSUNSHINE_PUBLISHER_WEBSITE='${publisher_website}'") + fi + if [[ -n "$publisher_issue_url" ]]; then + cmake_args+=("-DSUNSHINE_PUBLISHER_ISSUE_URL='${publisher_issue_url}'") + fi + + # Cmake stuff here + mkdir -p "build" + echo "cmake args:" + echo "${cmake_args[@]}" + cmake "${cmake_args[@]}" + return 0 +} + +function run_step_build() { + echo "Running step: Build" + make -C "${build_dir}" -j "${num_processors}" + + echo "*** To complete installation, run:" + echo + echo " sudo make -C \"${build_dir}\" install" + echo " /usr/local/bin/sunshine" + return 0 +} + +function run_install() { + case "$step" in + deps) + run_step_deps + ;; + cmake) + run_step_cmake + ;; + build) + run_step_build + ;; + all) + run_step_deps + run_step_cmake + run_step_build + ;; + *) + echo "Invalid step: $step" + echo "Valid steps are: deps, cmake, build, all" + exit 1 + ;; + esac + return 0 +} + +# Parse named arguments +while getopts ":h-:" opt; do + case ${opt} in + h ) _usage 0 ;; + - ) + case "${OPTARG}" in + help) _usage 0 ;; + num-processors=*) + num_processors="${OPTARG#*=}" + ;; + publisher-name=*) + publisher_name="${OPTARG#*=}" + ;; + publisher-website=*) + publisher_website="${OPTARG#*=}" + ;; + publisher-issue-url=*) + publisher_issue_url="${OPTARG#*=}" + ;; + step=*) + step="${OPTARG#*=}" + ;; + debug) + build_type="Debug" + ;; + skip-docs) + build_docs="OFF" + ;; + *) + echo "Invalid option: --${OPTARG}" 1>&2 + _usage 1 + ;; + esac + ;; + \? ) + echo "Invalid option: -${OPTARG}" 1>&2 + _usage 1 + ;; + esac +done +shift $((OPTIND -1)) + +# get directory of this script +script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +build_dir="$script_dir/../build" +echo "Script Directory: $script_dir" +echo "Build Directory: $build_dir" +mkdir -p "$build_dir" + +run_install