ci: simplify gcc toolchain logic - no update-alternatives needed

This commit is contained in:
Nicholas Dudfield
2025-08-18 20:34:49 +07:00
parent 6684075a28
commit b822b66825

View File

@@ -65,53 +65,37 @@ jobs:
- name: Install build dependencies
run: |
# If using Clang with specific GCC toolchain, remove GCC 14 FIRST
if [ -n "${{ matrix.clang_gcc_toolchain }}" ]; then
echo "=== Removing GCC 14 before installing other versions ==="
# If using Clang with specific GCC toolchain that's NOT 14, remove GCC 14 first
if [ -n "${{ matrix.clang_gcc_toolchain }}" ] && [ "${{ matrix.clang_gcc_toolchain }}" != "14" ]; then
echo "=== Removing GCC 14 to use GCC ${{ matrix.clang_gcc_toolchain }} ==="
# Remove ALL GCC 14 related packages including headers
sudo apt-get remove -y gcc-14 g++-14 cpp-14 libgcc-14-dev libstdc++-14-dev gcc-14-base || true
# Hold packages to prevent them from being installed as dependencies
sudo apt-mark hold gcc-14 g++-14 cpp-14 libgcc-14-dev libstdc++-14-dev gcc-14-base || true
# Clear apt cache to prevent any cached GCC 14 packages
sudo apt-get clean
sudo apt-get autoclean
fi
# Now update and install required packages
sudo apt-get update
sudo apt-get install -y ninja-build ${{ matrix.cc }} ${{ matrix.cxx }} ccache
# Install specific GCC toolchain for Clang if specified
if [ -n "${{ matrix.clang_gcc_toolchain }}" ]; then
# Install specific GCC toolchain for Clang if specified (but not 14 which is already there)
if [ -n "${{ matrix.clang_gcc_toolchain }}" ] && [ "${{ matrix.clang_gcc_toolchain }}" != "14" ]; then
echo "=== Installing GCC ${{ matrix.clang_gcc_toolchain }} toolchain for Clang ==="
sudo apt-get install -y gcc-${{ matrix.clang_gcc_toolchain }} g++-${{ matrix.clang_gcc_toolchain }}
# Set the specified GCC version as the system default using update-alternatives
echo "Setting GCC ${{ matrix.clang_gcc_toolchain }} as the default compiler"
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${{ matrix.clang_gcc_toolchain }} 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-${{ matrix.clang_gcc_toolchain }} 100
sudo update-alternatives --set gcc /usr/bin/gcc-${{ matrix.clang_gcc_toolchain }}
sudo update-alternatives --set g++ /usr/bin/g++-${{ matrix.clang_gcc_toolchain }}
# Create symlinks for cpp as well
sudo update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-${{ matrix.clang_gcc_toolchain }} 100
sudo update-alternatives --set cpp /usr/bin/cpp-${{ matrix.clang_gcc_toolchain }}
# Verify the change
fi
# Verify what Clang will use
if [ -n "${{ matrix.clang_gcc_toolchain }}" ]; then
echo "=== Verifying GCC configuration ==="
gcc --version
g++ --version
which gcc
ls -la /usr/bin/gcc*
ls -la /usr/bin/g++*
# Show what include paths exist
echo "=== Available C++ include directories ==="
ls -la /usr/include/c++/ || true
# Show what Clang will use
echo "=== Checking what headers Clang will use ==="
${{ matrix.cxx }} -E -x c++ - -v < /dev/null 2>&1 | grep "^ /"
fi