build(linux): explicitely set CC and CXX compilers (#4325)
This commit is contained in:
parent
ed7b78f138
commit
246d8f179f
2 changed files with 24 additions and 41 deletions
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue