mozilla / sccache

Sccache is a ccache-like tool. It is used as a compiler wrapper and avoids compilation when possible. Sccache has the capability to utilize caching in remote storage environments, including various cloud storage options, or alternatively, in local storage.
Apache License 2.0
5.7k stars 540 forks source link

sccache - cmake and ninja issues #1822

Open fbarreto75 opened 1 year ago

fbarreto75 commented 1 year ago

I am having issues implementing sccache with cmake ninja and msvc The compilation does complete but it is not caching at all... I am using /Zi and /Fd flags, which based on the doc is supported..

Any help is welcome.

sccache log :

[2023-06-28T17:55:51Z INFO  sccache::server] start_server: port: 4226
[2023-06-28T17:55:51Z INFO  sccache::server] No scheduler address configured, disabling distributed sccache
[2023-06-28T17:55:51Z DEBUG sccache::cache::cache] Init disk cache with dir "c:\\source\\sccache", size 10737418240
[2023-06-28T17:55:51Z INFO  sccache::server] server has setup with ReadWrite
[2023-06-28T17:55:51Z INFO  sccache::server] server started, listening on port 4226
[2023-06-28T17:55:51Z DEBUG sccache::server] handle_client: compile
[2023-06-28T17:55:51Z DEBUG sccache::compiler::compiler] Found MSVC (is clang: false)
[2023-06-28T17:55:51Z DEBUG sccache::server] check_compiler: Supported compiler
[2023-06-28T17:55:51Z DEBUG sccache::server] parse_arguments: Ok: ["/nologo", "/TP", "-DBOMGAR", "-DBOOST_ALL_NO_LIB", "-DBOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE", "-DCMAKE_BUILD_DIR=C:/Source/workspace/master@2/test/build", "-DNOMINMAX", "-DPSAPI_VERSION=1", "-DUNICODE", "-DWIN32", "-DWIN32_LEAN_AND_MEAN", "-D_ATL_NO_COM", "-D_BIND_TO_CURRENT_CRT_VERSION=1", "-D_CRT_NONSTDC_NO_WARNINGS", "-D_CRT_SECURE_NO_WARNINGS", "-D_DEBUG", "-D_SCL_SECURE_NO_WARNINGS", "-D_THREAD_SAFE", "-D_UNICODE", "-D_WIN32", "-D_WINSOCK_DEPRECATED_NO_WARNINGS", "-D__func__=__FUNCTION__", "-IC:\\Source\\workspace\\master@2\\build\\usr-x64\\include", "-IC:\\Source\\workspace\\master@2", "/DWIN32", "/D_WINDOWS", "/W3", "/GR", "/EHsc", "/MP", "/bigobj", "/GR", "/EHsc", "/W3", "/Zc:__cplusplus", "/wd4100", "/wd4355", "/wd4800", "/wd4834", "/guard:cf", "/MTd", "/Zi", "/Ob0", "/Od", "/RTC1", "-std:c++17", "/showIncludes", "/FoCMakeFiles\\test.dir\\hello.cpp.obj", "/FdCMakeFiles\\test.dir\\", "/FS", "-c", "..\\hello.cpp"]
[2023-06-28T17:55:51Z DEBUG sccache::compiler::compiler] [hello.cpp.obj]: get_cached_or_compile: ["/nologo", "/TP", "-DBOMGAR", "-DBOOST_ALL_NO_LIB", "-DBOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE", "-DCMAKE_BUILD_DIR=C:/Source/workspace/master@2/test/build", "-DNOMINMAX", "-DPSAPI_VERSION=1", "-DUNICODE", "-DWIN32", "-DWIN32_LEAN_AND_MEAN", "-D_ATL_NO_COM", "-D_BIND_TO_CURRENT_CRT_VERSION=1", "-D_CRT_NONSTDC_NO_WARNINGS", "-D_CRT_SECURE_NO_WARNINGS", "-D_DEBUG", "-D_SCL_SECURE_NO_WARNINGS", "-D_THREAD_SAFE", "-D_UNICODE", "-D_WIN32", "-D_WINSOCK_DEPRECATED_NO_WARNINGS", "-D__func__=__FUNCTION__", "-IC:\\Source\\workspace\\master@2\\build\\usr-x64\\include", "-IC:\\Source\\workspace\\master@2", "/DWIN32", "/D_WINDOWS", "/W3", "/GR", "/EHsc", "/MP", "/bigobj", "/GR", "/EHsc", "/W3", "/Zc:__cplusplus", "/wd4100", "/wd4355", "/wd4800", "/wd4834", "/guard:cf", "/MTd", "/Zi", "/Ob0", "/Od", "/RTC1", "-std:c++17", "/showIncludes", "/FoCMakeFiles\\test.dir\\hello.cpp.obj", "/FdCMakeFiles\\test.dir\\", "/FS", "-c", "..\\hello.cpp"]
[2023-06-28T17:55:51Z DEBUG sccache::compiler::msvc] preprocess: Some("C:\\PROGRA~2\\MICROS~1\\2019\\PROFES~1\\VC\\Tools\\MSVC\\1427~1.291\\bin\\Hostx64\\x64\\cl.exe" "-EP" "..\\hello.cpp" "-nologo" "-DBOMGAR" "-DBOOST_ALL_NO_LIB" "-DBOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE" "-DCMAKE_BUILD_DIR=C:/Source/workspace/master@2/test/build" "-DNOMINMAX" "-DPSAPI_VERSION=1" "-DUNICODE" "-DWIN32" "-DWIN32_LEAN_AND_MEAN" "-D_ATL_NO_COM" "-D_BIND_TO_CURRENT_CRT_VERSION=1" "-D_CRT_NONSTDC_NO_WARNINGS" "-D_CRT_SECURE_NO_WARNINGS" "-D_DEBUG" "-D_SCL_SECURE_NO_WARNINGS" "-D_THREAD_SAFE" "-D_UNICODE" "-D_WIN32" "-D_WINSOCK_DEPRECATED_NO_WARNINGS" "-D__func__=__FUNCTION__" "-IC:\\Source\\workspace\\master@2\\build\\usr-x64\\include" "-IC:\\Source\\workspace\\master@2" "/DWIN32" "/D_WINDOWS" "/showIncludes" "/nologo" "/TP" "/W3" "/GR" "/EHsc" "/bigobj" "/GR" "/EHsc" "/W3" "/Zc:__cplusplus" "/wd4100" "/wd4355" "/wd4800" "/wd4834" "/guard:cf" "/MTd" "/Zi" "/Ob0" "/Od" "/RTC1" "-std:c++17" "/FdCMakeFiles\\test.dir\\" "/wd4668")

[2023-06-28T17:55:51Z DEBUG sccache::compiler::compiler] [hello.cpp.obj]: generate_hash_key took 0.137 s
[2023-06-28T17:55:51Z DEBUG sccache::compiler::compiler] [hello.cpp.obj]: Cache miss in 0.000 s
[2023-06-28T17:55:51Z DEBUG sccache::compiler::compiler] [hello.cpp.obj]: Compiling locally

[2023-06-28T17:55:52Z DEBUG sccache::compiler::compiler] [hello.cpp.obj]: Compiled in 0.428 s, but not cacheable
[2023-06-28T17:55:52Z DEBUG sccache::server] compile result: not cacheable
C:\Users\build\AppData\Roaming\Mozilla\sccache\config> sccache --show-stats
Compile requests                      2
Compile requests executed             2
Cache hits                            0
Cache misses                          2
Cache misses (C/C++)                  2
Cache timeouts                        0
Cache read errors                     0
Forced recaches                       0
Cache write errors                    0
Compilation failures                  0
Cache errors                          0
Non-cacheable compilations            2
Non-cacheable calls                   0
Non-compilation calls                 0
Unsupported compiler calls            0
Average cache write               0.000 s
Average compiler                  0.000 s
Average cache read hit            0.000 s
Failed distributed compilations       0
Cache location                  Local disk: "c:\\source\\sccache"
Version (client)                0.5.4
Cache size                          369 KiB
Max cache size                       10 GiB

Replacing the /Zi flag by /Z7 would fix, but it is not a thing we would like to do... if sccache would not work I would like any recommendation on a caching system that would.

Thank you

mathstuf commented 1 year ago

There's a rabbit hole of links from this CMake issue. Basically, CMake defaults to a debug mechanism that sccache can't work with because it writes to .pdb files through a service which isn't possible to reliably cache.