feat(macos/build): add basic macOS build script based on linux_build.sh (#4598)
This commit is contained in:
parent
aea9512682
commit
f879294449
2 changed files with 276 additions and 62 deletions
|
|
@ -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}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue