From 246d8f179f0bb5b09fd1f6d7f3e215db09ae822b Mon Sep 17 00:00:00 2001 From: PVermeer Date: Sat, 11 Oct 2025 16:26:40 +0200 Subject: [PATCH] build(linux): explicitely set CC and CXX compilers (#4325) --- .github/workflows/ci-linux.yml | 2 +- scripts/linux_build.sh | 63 +++++++++++++--------------------- 2 files changed, 24 insertions(+), 41 deletions(-) diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 57723fe3..bbe1c952 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -186,7 +186,7 @@ jobs: working-directory: build run: | ${{ steps.python.outputs.python-path }} -m pip install gcovr - ${{ steps.python.outputs.python-path }} -m gcovr . -r ../src \ + ${{ steps.python.outputs.python-path }} -m gcovr --gcov-executable "gcov-${GCC_VERSION}" . -r ../src \ --exclude-noncode-lines \ --exclude-throw-branches \ --exclude-unreachable-branches \ diff --git a/scripts/linux_build.sh b/scripts/linux_build.sh index 7128e093..2c10065f 100755 --- a/scripts/linux_build.sh +++ b/scripts/linux_build.sh @@ -23,15 +23,6 @@ sudo_cmd="sudo" ubuntu_test_repo=0 step="all" -# common variables -gcc_alternative_files=( - "gcc" - "g++" - "gcov" - "gcc-ar" - "gcc-ranlib" -) - # Reusable function to detect nvcc path function detect_nvcc_path() { local nvcc_path="" @@ -340,6 +331,11 @@ function install_cuda() { return fi + local cuda_override_arg="" + 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 @@ -371,7 +367,7 @@ function install_cuda() { echo "cuda url: ${url}" wget "$url" --progress=bar:force:noscroll -q --show-progress -O "${build_dir}/cuda.run" chmod a+x "${build_dir}/cuda.run" - "${build_dir}/cuda.run" --silent --toolkit --toolkitpath="${build_dir}/cuda" --no-opengl-libs --no-man-page --no-drm + "${build_dir}/cuda.run" --silent --toolkit --toolkitpath="${build_dir}/cuda" --no-opengl-libs --no-man-page --no-drm "$cuda_override_arg" rm "${build_dir}/cuda.run" # run cuda patches @@ -452,24 +448,8 @@ function run_step_deps() { source ~/.bashrc #set gcc version based on distros - if [ "$distro" == "arch" ]; then - export CC=gcc-14 - export CXX=g++-14 - elif [ "$distro" == "debian" ] || [ "$distro" == "ubuntu" ]; then - for file in "${gcc_alternative_files[@]}"; do - file_path="/etc/alternatives/$file" - if [ -e "$file_path" ]; then - ${sudo_cmd} mv "$file_path" "$file_path.bak" - fi - done - - ${sudo_cmd} update-alternatives --install \ - /usr/bin/gcc gcc /usr/bin/gcc-${gcc_version} 100 \ - --slave /usr/bin/g++ g++ /usr/bin/g++-${gcc_version} \ - --slave /usr/bin/gcov gcov /usr/bin/gcov-${gcc_version} \ - --slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-${gcc_version} \ - --slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-${gcc_version} - fi + export CC=gcc-${gcc_version} + export CXX=g++-${gcc_version} # compile cmake if the version is too low if ! check_version "cmake" "$cmake_min" "inf"; then @@ -537,6 +517,10 @@ function run_step_cmake() { nvcc_path=$(detect_nvcc_path) fi + #set gcc version based on distros + export CC=gcc-${gcc_version} + export CXX=g++-${gcc_version} + # prepare CMAKE args cmake_args=( "-B=build" @@ -579,6 +563,7 @@ function run_step_cmake() { cmake_args+=("-DSUNSHINE_ENABLE_CUDA=ON") if [ -n "$nvcc_path" ]; then cmake_args+=("-DCMAKE_CUDA_COMPILER:PATH=$nvcc_path") + cmake_args+=("-DCMAKE_CUDA_HOST_COMPILER=gcc-${gcc_version}") fi else cmake_args+=("-DSUNSHINE_ENABLE_CUDA=OFF") @@ -630,17 +615,6 @@ function run_step_cleanup() { echo "Running step: Cleanup" if [ "$skip_cleanup" == 0 ]; then - # Restore the original gcc alternatives - if [ "$distro" == "debian" ] || [ "$distro" == "ubuntu" ]; then - for file in "${gcc_alternative_files[@]}"; do - if [ -e "/etc/alternatives/$file.bak" ]; then - ${sudo_cmd} mv "/etc/alternatives/$file.bak" "/etc/alternatives/$file" - else - ${sudo_cmd} rm "/etc/alternatives/$file" - fi - done - fi - # 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" @@ -775,9 +749,18 @@ if [ "$architecture" != "x86_64" ] && [ "$architecture" != "aarch64" ]; then exit 1 fi +# export variables for github actions ci +if [ -f "$GITHUB_ENV" ]; then + { + echo "CC=gcc-${gcc_version}" + echo "CXX=g++-${gcc_version}" + echo "GCC_VERSION=${gcc_version}" + } >> "$GITHUB_ENV" +fi + # get directory of this script script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -build_dir="$script_dir/../build" +build_dir=$(readlink -f "$script_dir/../build") echo "Script Directory: $script_dir" echo "Build Directory: $build_dir" mkdir -p "$build_dir"