Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable /Zi when using ccache on Windows/MSVC. #11841

Merged
merged 1 commit into from
Jan 14, 2023

Conversation

ScottTodd
Copy link
Member

One step towards enabling ccache on our Windows CI, but there are a few details to still work through: #11009 (comment).

On my machine, I see these results (sample size 1):

clean build (no cache): 528 seconds

λ ccache --show-stats
Cacheable calls:   3942 / 3943 (99.97%)
  Hits:               2 / 3942 ( 0.05%)
    Direct:           0 /    2 ( 0.00%)
    Preprocessed:     2 /    2 (100.0%)
  Misses:          3940 / 3942 (99.95%)
Uncacheable calls:    1 / 3943 ( 0.03%)
Local storage:
  Cache size (GB): 2.21 / 5.00 (44.21%)
  Cleanups:          16

clean build (with cache): 96 seconds

λ ccache --show-stats
Cacheable calls:   3942 / 3943 (99.97%)
  Hits:            3939 / 3942 (99.92%)
    Direct:        3939 / 3939 (100.0%)
    Preprocessed:     0 / 3939 ( 0.00%)
  Misses:             3 / 3942 ( 0.08%)
Uncacheable calls:    1 / 3943 ( 0.03%)
Local storage:
  Cache size (GB): 2.21 / 5.00 (44.23%)

My only changes to enable ccache were:

  • Download ccache.exe and put it on my PATH
  • Configure CMake with -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache (added to "cmake.configureArgs": [ ... ] in VSCode settings)

@ScottTodd ScottTodd added infrastructure Relating to build systems, CI, or testing platform/windows 🚪 Windows-specific build, execution, benchmarking, and deployment labels Jan 14, 2023
@ScottTodd ScottTodd requested a review from benvanik January 14, 2023 00:39
Comment on lines +436 to +441
message(STATUS "Replacing /Zi with /Z7 since ccache is in use and does not support /Zi")
# https://learn.microsoft.com/en-us/cpp/build/reference/z7-zi-zi-debug-information-format
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this will affect downstream users too. Not really a fan of when projects modify global flags, but I think this is niche enough...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it's conditional on ccache usage and anyone using ccache would need the same thing it seems ok - may still conflict with a user's similar hacks but probably worth waiting for that to be an issue :)

Copy link
Collaborator

@benvanik benvanik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love this!

@ScottTodd ScottTodd enabled auto-merge (squash) January 14, 2023 00:46
@ScottTodd ScottTodd merged commit fc61048 into iree-org:main Jan 14, 2023
@ScottTodd ScottTodd deleted the windows-ccache branch January 14, 2023 01:12
jpienaar pushed a commit that referenced this pull request May 1, 2023
One step towards enabling [ccache](https://ccache.dev/) on our Windows
CI, but there are a few details to still work through:
#11009 (comment).

On my machine, I see these results (sample size 1):

> clean build (no cache): 528 seconds
> ```
> λ ccache --show-stats
> Cacheable calls:   3942 / 3943 (99.97%)
>   Hits:               2 / 3942 ( 0.05%)
>     Direct:           0 /    2 ( 0.00%)
>     Preprocessed:     2 /    2 (100.0%)
>   Misses:          3940 / 3942 (99.95%)
> Uncacheable calls:    1 / 3943 ( 0.03%)
> Local storage:
>   Cache size (GB): 2.21 / 5.00 (44.21%)
>   Cleanups:          16
> ```
> clean build (with cache): 96 seconds
> ```
> λ ccache --show-stats
> Cacheable calls:   3942 / 3943 (99.97%)
>   Hits:            3939 / 3942 (99.92%)
>     Direct:        3939 / 3939 (100.0%)
>     Preprocessed:     0 / 3939 ( 0.00%)
>   Misses:             3 / 3942 ( 0.08%)
> Uncacheable calls:    1 / 3943 ( 0.03%)
> Local storage:
>   Cache size (GB): 2.21 / 5.00 (44.23%)
> ```

My only changes to enable ccache were:
* Download ccache.exe and put it on my `PATH`
* Configure CMake with `-DCMAKE_C_COMPILER_LAUNCHER=ccache
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache` (added to `"cmake.configureArgs":
[ ... ]` in VSCode settings)
ScottTodd added a commit to nod-ai/TheRock that referenced this pull request Feb 20, 2025
Progress on #36. This fixes
ccache when compiling with `-DCMAKE_BUILD_TYPE=RelWithDebInfo` and MSVC
on Windows.

Before:
```
λ ccache --show-stats
Cacheable calls:      0 / 4309 ( 0.00%)
  Hits:               0
    Direct:           0
    Preprocessed:     0
  Misses:             0
Uncacheable calls: 4309 / 4309 (100.0%)
Local storage:
  Cache size (GB):  0.0 / 50.0 ( 0.00%)
```

After:
```
λ ccache --show-stats
Cacheable calls:   4099 / 4309 (95.13%)
  Hits:            4054 / 4099 (98.90%)
    Direct:        3482 / 4054 (85.89%)
    Preprocessed:   572 / 4054 (14.11%)
  Misses:            45 / 4099 ( 1.10%)
Uncacheable calls:  210 / 4309 ( 4.87%)
Local storage:
  Cache size (GB):  4.2 / 50.0 ( 8.34%)
  Hits:            4054 / 4099 (98.90%)
  Misses:            45 / 4099 ( 1.10%)
```

We had a different workaround in IREE:
iree-org/iree#11841. I tried a solution like
that one in this project but the meta-project nature of TheRock
discourages setting implicit top level options. Instead, I followed how
other options like `CMAKE_CXX_COMPILER_LAUNCHER` are forwarded to
subprojects explicitly.


### Debugging notes

I followed https://ccache.dev/manual/4.10.2.html#_cache_debugging:

```bash
ccache --set-config debug=true
ccache --set-config debug_dir=D:\cache\ccache_debug
ccache --show-config
# confirm that the options are set
```

Then I looked in files like
`D:\cache\ccache_debug\projects\TheRock\build\compiler\amd-llvm\build\lib\Support\CMakeFiles\LLVMSupport.dir\Allocator.cpp.obj.20250219_112722_308872.ccache-log`

and found logs like these:
```
[2025-02-19T11:27:22.309172 28480] Command line: ccache C:\\PROGRA~2\\MICROS~2\\2022\\BUILDT~1\\VC\\Tools\\MSVC\\1442~1.344\\bin\\Hostx64\\x64\\cl.exe /nologo /TP -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -ID:\\projects\\TheRock\\build\\compiler\\amd-llvm\\build\\lib\\Support -ID:\\projects\\TheRock\\compiler\\amd-llvm\\llvm\\lib\\Support -ID:\\projects\\TheRock\\build\\compiler\\amd-llvm\\build\\include -ID:\\projects\\TheRock\\compiler\\amd-llvm\\llvm\\include /DWIN32;/D_WINDOWS;/EHsc /DWIN32 /D_WINDOWS /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -w14062 -we4238 /Gw /O2 /Ob1 /DNDEBUG -std:c++17 -MD -Zi /EHs-c- /GR- /showIncludes /Folib\\Support\\CMakeFiles\\LLVMSupport.dir\\Allocator.cpp.obj /Fdlib\\Support\\CMakeFiles\\LLVMSupport.dir\\LLVMSupport.pdb /FS -c D:\\projects\\TheRock\\compiler\\amd-llvm\\llvm\\lib\\Support\\Allocator.cpp
[2025-02-19T11:27:22.312459 28480] Hostname: DESKTOP-HTCE3IS
[2025-02-19T11:27:22.312465 28480] Working directory: D:\projects\TheRock\build\compiler\amd-llvm\build
[2025-02-19T11:27:22.312475 28480] Compiler: C:\PROGRA~2\MICROS~2\2022\BUILDT~1\VC\Tools\MSVC\1442~1.344\bin\Hostx64\x64\cl.exe
[2025-02-19T11:27:22.312476 28480] Compiler type: msvc
[2025-02-19T11:27:22.312846 28480] Detected input file: D:\projects\TheRock\compiler\amd-llvm\llvm\lib\Support\Allocator.cpp
[2025-02-19T11:27:22.312852 28480] Compiler option -Zi is unsupported
[2025-02-19T11:27:22.312857 28480] Failed; falling back to running the real compiler
```

From there it was whack-a-mole trying to find where the `-Zi` flag came
from, checking source code and eventually finding
https://github.com/llvm/llvm-project/blob/c0c42c8b3213520700f15587ab8aa4477a286ff9/cmake/Modules/CMakePolicy.cmake#L9-L20.
Reading the docs informed me that my prior workaround of manipulating
`CMAKE_C_FLAGS_RELWITHDEBINFO` is outdated and actually won't work when
the new policy is enabled.

With the right fix, I deleted my build directory, re-ran a full build,
and checked the ccache stats and log files to ensure that ccache was
operating as expected again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infrastructure Relating to build systems, CI, or testing platform/windows 🚪 Windows-specific build, execution, benchmarking, and deployment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants