cmake: make ccache opt-in when Tracy is consumed as a subdirectory dependency#1413
Open
blozano-tt wants to merge 1 commit into
Open
cmake: make ccache opt-in when Tracy is consumed as a subdirectory dependency#1413blozano-tt wants to merge 1 commit into
blozano-tt wants to merge 1 commit into
Conversation
Tracy's config.cmake sets RULE_LAUNCH_COMPILE ccache as a GLOBAL CMake
property. When Tracy is consumed via add_subdirectory() by a parent project
that already manages ccache (e.g. via CMAKE_CXX_COMPILER_LAUNCHER), both
mechanisms activate simultaneously. The compiler gets double-wrapped:
ccache cmake -E env CCACHE_SLOPPINESS=... ccache clang++ -c foo.cpp
The outer ccache sees 'cmake' as the compiler and rejects every translation
unit as 'Multiple source files'. This caused 82.6% cache-miss rate in
tenstorrent/tt-metal after Tracy was integrated as a subdirectory dependency
(1856/2248 compilations uncacheable). See:
tenstorrent/tt-metal#47617
Fix: detect whether Tracy is the top-level project at configure time. If it
is, NO_CCACHE defaults to OFF (existing behavior, ccache enabled). If it is
a subdirectory, NO_CCACHE defaults to ON, suppressing the global property.
Parent projects that explicitly want Tracy's ccache can still set
-DNO_CCACHE=OFF; the override semantics of set_option are unchanged.
This makes the ccache integration opt-in when Tracy is used as a
dependency, matching the principle of least surprise for CMake consumers.
Owner
|
Why are you trying to build Tracy tools as a part of some external project? |
|
We use them to systematically capture and export tracy runs. Single build builds them all. If they have tracy enabled they are going to need the tools as well. |
Owner
|
I don't think adapting to any possible external build configuration is what I want to do (except for the client, of course). https://cmake.org/cmake/help/latest/module/ExternalProject.html is probably the solution you're looking for. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
cmake/config.cmakesets the global CMake propertyRULE_LAUNCH_COMPILE ccachewhenever ccache is found andNO_CCACHEis off (the default). This is appropriate when building Tracy directly, but when Tracy is consumed as a subdirectory dependency viaadd_subdirectory(), the global property leaks into the parent build.If the parent project already manages ccache — for example via
CMAKE_CXX_COMPILER_LAUNCHER— both mechanisms activate at the same time. CMake then generates Ninja rules that double-wrap the compiler:```
ccache cmake -E env CCACHE_SLOPPINESS=... ccache clang++ -c foo.cpp
```
The outer
ccacheinvocation seescmake(notclang++) as the compiler and rejects every translation unit with "Multiple source files".Real-world impact: after integrating Tracy into tenstorrent/tt-metal, 1856 of 2248 compilations became uncacheable (82.6% miss rate). The project was forced to work around it with
set(NO_CCACHE ON)before the Tracyadd_subdirectorycalls (tenstorrent/tt-metal#47617). This fix addresses the root cause upstream.Fix
Detect whether Tracy is the top-level CMake project at configure time:
NO_CCACHEdefaults toOFF— ccache enabled, existing behavior preserved for Tracy CLI users building Tracy directly.NO_CCACHEdefaults toON— the globalRULE_LAUNCH_COMPILEproperty is not set, preventing leakage into the parent build. Parent projects that explicitly want Tracy's ccache can still pass-DNO_CCACHE=OFF.This makes ccache opt-in when Tracy is used as a dependency, matching the principle of least surprise for CMake consumers.
Testing
Build Tracy CLI tools directly — behaviour unchanged (ccache still active by default).
Consume Tracy as a subdirectory in a project that sets
CMAKE_CXX_COMPILER_LAUNCHER=ccache— no more double-wrapping; the parent's ccache operates correctly.