From a4397e133a907b2ce0cabe8d7fda4314056f3c8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Desbiens?= Date: Mon, 24 Aug 2026 14:47:26 -0400 Subject: [PATCH] Reconfigured the build when the requested compiler changes (#657) CMake records the compiler it detected inside the build directory and keeps using it on every later configure. Since cmake/linux.cmake began honouring CC, that made a compiler switch silently ineffective: CC=gcc-14 ./run.sh build against an existing build directory printed "ninja: no work to do", exited 0, and left the previous compiler in place. Anyone verifying a change against a second compiler would have been reading stale results while being told the build had succeeded. generate() now compares the compiler recorded in the build directory with the one currently requested, and reconfigures from scratch when they differ. The comparison uses the path as CMake records it, which is the unresolved path as given, so /usr/bin/gcc matches command -v gcc rather than the versioned target its symlink points at. build_libs() gets the same treatment. Only the C compiler is consulted: both trees that use this script declare LANGUAGES C, so no CXX compiler is ever detected. Nothing is reconfigured unless the compiler actually changed, so repeat builds stay incremental and the default path is unchanged. Assisted-by: Claude Code (Opus 5) --- scripts/cmake_bootstrap.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/scripts/cmake_bootstrap.sh b/scripts/cmake_bootstrap.sh index d66d668d..014f4423 100755 --- a/scripts/cmake_bootstrap.sh +++ b/scripts/cmake_bootstrap.sh @@ -31,8 +31,32 @@ function validate() { help } +# CMake records the compiler it detected inside the build directory and keeps using it on +# every later configure. Changing CC would otherwise be ignored without a word: the build +# reports success while still using the compiler the directory was first configured with, +# so anyone verifying a change against a second compiler would be reading stale results. +# Only the C compiler is consulted, because these test trees declare LANGUAGES C. +function compiler_changed() { + local build=$1 + local recorded requested + + [ -d "build/$build" ] || return 1 + + recorded=$(sed -n 's/^set(CMAKE_C_COMPILER "\(.*\)")$/\1/p' build/$build/CMakeFiles/*/CMakeCCompiler.cmake 2>/dev/null | head -1) + [ -n "$recorded" ] || return 1 + + requested=$(command -v "${CC:-gcc}" 2>/dev/null) + [ -n "$requested" ] || return 1 + + [ "$recorded" != "$requested" ] +} + function generate() { build=$1 + if compiler_changed $build; then + echo "Compiler changed since build/$build was configured. Reconfiguring from scratch." + rm -rf build/$build + fi cmake -Bbuild/$build -GNinja -DBUILD_SHARED_LIBS=ON -DCMAKE_TOOLCHAIN_FILE=$(dirname $(realpath $0))/../cmake/linux.cmake -DCMAKE_BUILD_TYPE=$build . } @@ -41,6 +65,10 @@ function build() { } function build_libs() { + if compiler_changed libs; then + echo "Compiler changed since build/libs was configured. Reconfiguring from scratch." + rm -rf build/libs + fi cmake -Bbuild/libs -GNinja -DBUILD_SHARED_LIBS=ON -DCMAKE_TOOLCHAIN_FILE=$(dirname $(realpath $0))/../cmake/linux.cmake libs cmake --build build/libs }