From f408d3a1c6aefb144fad3c0faabdecbc3457b38e Mon Sep 17 00:00:00 2001 From: Mingxin Wang Date: Thu, 19 Nov 2026 22:41:17 +0800 Subject: [PATCH] Work around the broken libc++.modules.json packaged by Ubuntu 26.04 in CI - Passed `CMAKE_CXX_STDLIB_MODULES_JSON` with `/usr/lib/llvm-N/lib/libc++.modules.json` to the default and freestanding configures of the clang compatibility jobs, because `libc++-N-dev` for LLVM 19 to 22 on Ubuntu 26.04 also ships a copy under `/usr/lib/x86_64-linux-gnu` whose relative source paths only resolve from `/usr/lib/llvm-N/lib`, clang reports that copy, and CMake 4.5 builds the `std` module for every target that scans for modules. - Disabled `import std` for freestanding builds with libstdc++ by setting `CMAKE_CXX_STDLIB_MODULES_JSON` to an empty string, because libstdc++ cannot build its `std` module with `-ffreestanding` (https://gcc.gnu.org/PR125460). libstdc++ is recognized by the name of the modules metadata file, because a `__GLIBCXX__` check runs a try_compile after which CMake 4.5 ignores the empty value. --- .github/workflows/bvt-compatibility.yml | 5 +++-- CMakeLists.txt | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bvt-compatibility.yml b/.github/workflows/bvt-compatibility.yml index a6d7a39c..1779d8af 100644 --- a/.github/workflows/bvt-compatibility.yml +++ b/.github/workflows/bvt-compatibility.yml @@ -45,6 +45,7 @@ jobs: CC=clang-${{ matrix.compiler.version }} CXX=clang++-${{ matrix.compiler.version }} CXXFLAGS=-stdlib=libc++ + CXX_STDLIB_MODULES_JSON=/usr/lib/llvm-${{ matrix.compiler.version }}/lib/libc++.modules.json EOF - name: Check toolchain versions @@ -55,12 +56,12 @@ jobs: - name: Build and run test with cmake run: | - cmake --preset default '-DPROXY_BUILD_MODULES=${{ matrix.compiler.modules }}' '-DBUILD_DOC_TESTING=${{ matrix.compiler.doc_tests }}' + cmake --preset default '-DPROXY_BUILD_MODULES=${{ matrix.compiler.modules }}' '-DBUILD_DOC_TESTING=${{ matrix.compiler.doc_tests }}' ${CXX_STDLIB_MODULES_JSON:+"-DCMAKE_CXX_STDLIB_MODULES_JSON=$CXX_STDLIB_MODULES_JSON"} cmake --build --preset default -j ctest --preset default -j - name: Build and run freestanding test with cmake run: | - cmake --preset freestanding '-DPROXY_BUILD_MODULES=${{ matrix.compiler.modules }}' '-DBUILD_DOC_TESTING=${{ matrix.compiler.doc_tests }}' + cmake --preset freestanding '-DPROXY_BUILD_MODULES=${{ matrix.compiler.modules }}' '-DBUILD_DOC_TESTING=${{ matrix.compiler.doc_tests }}' ${CXX_STDLIB_MODULES_JSON:+"-DCMAKE_CXX_STDLIB_MODULES_JSON=$CXX_STDLIB_MODULES_JSON"} cmake --build --preset freestanding -j ctest --preset freestanding -j diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b17bc61..78ef1cc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,10 @@ set(CMAKE_CXX_EXTENSIONS OFF) if(PROXY_FREESTANDING) add_compile_options(-ffreestanding -fno-exceptions -fno-rtti) add_link_options(-nodefaultlibs -lc) + # libstdc++ cannot build its std module with -ffreestanding (https://gcc.gnu.org/PR125460). + if(CMAKE_CXX_STDLIB_MODULES_JSON MATCHES "libstdc\\+\\+\\.modules\\.json$") + set(CMAKE_CXX_STDLIB_MODULES_JSON "") + endif() endif() file(GLOB_RECURSE proxy_public_headers CONFIGURE_DEPENDS