From 6f90ff6e93fb8c00d6f343f4322a570c8dcc0c0b Mon Sep 17 00:00:00 2001 From: Hanif Koh Date: Fri, 11 Sep 2026 17:29:28 +0800 Subject: [PATCH] Allow ccache with PCH Clang records the modification time of every input in the precompiled header, so a fresh checkout produces a different header and every file that includes it misses the compiler cache. -fno-pch-timestamp makes the header reproducible, and pch_defines lets ccache cache the header itself. The precompiled header no longer has to be turned off when the cache is on. --- .github/workflows/build_orca.yml | 10 ++++------ cmake/modules/PrecompiledHeader.cmake | 7 +++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_orca.yml b/.github/workflows/build_orca.yml index f1fb29c46b..e51cb2e37a 100644 --- a/.github/workflows/build_orca.yml +++ b/.github/workflows/build_orca.yml @@ -117,12 +117,10 @@ jobs: run: | echo "CMAKE_C_COMPILER_LAUNCHER=ccache" >> "$GITHUB_ENV" echo "CMAKE_CXX_COMPILER_LAUNCHER=ccache" >> "$GITHUB_ENV" - # Headers a fresh checkout has just written, and the few files that - # use __DATE__ or __TIME__. - echo "CCACHE_SLOPPINESS=time_macros,include_file_mtime,include_file_ctime" >> "$GITHUB_ENV" - # Clang rebuilds the precompiled header with a fresh timestamp on - # every run, so everything that includes it would miss. - echo "ORCA_EXTRA_BUILD_ARGS=-DSLIC3R_PCH=OFF" >> "$GITHUB_ENV" + # Headers a fresh checkout has just written, the few files that + # use __DATE__ or __TIME__, and the precompiled header, whose + # macros ccache cannot see. + echo "CCACHE_SLOPPINESS=pch_defines,time_macros,include_file_mtime,include_file_ctime" >> "$GITHUB_ENV" # The restored directory carries the previous run's counters. ccache -z diff --git a/cmake/modules/PrecompiledHeader.cmake b/cmake/modules/PrecompiledHeader.cmake index 7ef80aacff..7d8b3a5603 100644 --- a/cmake/modules/PrecompiledHeader.cmake +++ b/cmake/modules/PrecompiledHeader.cmake @@ -256,6 +256,13 @@ function(add_precompiled_header _target _input) message(STATUS "Adding precompiled header ${_input} to target ${_target}.") target_precompile_headers(${_target} PRIVATE ${_input}) + # Clang records the modification time of every input in the precompiled + # header, which makes it differ between two checkouts of the same source + # and defeats a compiler cache. The build system already rebuilds the + # header when an input changes. + target_compile_options(${_target} PRIVATE + "$<$:SHELL:-Xclang -fno-pch-timestamp>") + get_target_property(_sources ${_target} SOURCES) list(FILTER _sources INCLUDE REGEX ".*\\.mm?")