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.73k stars 540 forks source link

MSVC Precompiled header flags not supported: "multiple input files"; Seeking workaround... #988

Open DragonAxe opened 3 years ago

DragonAxe commented 3 years ago

Versions tried: v0.2.15 and v0.2.16-alpha.0 (master build at 3f318a8675e4c3de4f5e8ab2d086189f2ae5f5cf)

Per a comment here: https://github.com/mozilla/sccache/issues/950 I tried downgrading to v0.2.12. However, while I no longer got "multiple input files" warnings, all compile requests were categorized as "Non-cacheable compilations".

Here is an example compile command:

C:\path\to\sccache.exe C:\PROGRA~2\MICROS~1\2019\BUILDT~1\VC\Tools\MSVC\1428~1.299\bin\Hostx64\x64\cl.exe 
 /nologo
 /TP
 -DBOOST_ALL_DYN_LINK
 -DBOOST_ALL_NO_LIB
 -DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
 -DBOOST_EXCEPTION_MINI_BOOST
 -DBOOST_FILESYSTEM_NO_DEPRECATED
 -DBOOST_STACKTRACE_LINK
 -DBOOST_TEST_IGNORE_NON_ZERO_CHILD_CODE
 -DBOOST_TEST_IGNORE_SIGCHLD
 -DBOOST_THREAD_VERSION=3
 -DBOOST_USE_WINDOWS_H
 -DBOOST_USE_WINFIB
 -DBOOST_UUID_RANDOM_PROVIDER_FORCE_WINCRYPT
 -DPROJECT_FLAG_SHARED_LIBRARY
 -DNOMINMAX
 -DPROTOBUF_USE_DLLS
 -DTEST
 -DWIN32_LEAN_AND_MEAN
 -IC:\src\path\to\includes
 -I.
 -IC:\src\path\to\includes\project1\src
 -IC:\src\path\to\includes\project2\include
 /DWIN32
 /D_WINDOWS
 /GR
 /EHsc
 /D_WIN32_WINNT=0x0601
 /DWINVER=0x0601
 /Zc:__cplusplus
 /FS
 /errorReport:none
 /Zm500
 /bigobj
 /MP
 /MD 
 /Ob2
 /DNDEBUG
 /GS-
 /O1
 /Oi
 /Zi
 -experimental:external
 -external:W0
 -external:IC:/path/to/external/includes/project1/includes
 -external:IC:/path/to/external/includes/project2/includes
 -external:IC:/path/to/external/includes/project3/includes
 -external:IC:/path/to/external/includes/project4/includes
 -external:IC:/path/to/external/includes/project5/includes
 -external:IC:/path/to/external/includes/project6/includes
 -external:IC:/path/to/external/includes/project7/includes
 -external:IC:/path/to/external/includes/project8/includes
 /D_USE_MATH_DEFINES
 /DNOMINMAX
 /DWIN32_LEAN_AND_MEAN
 /permissive-
 /Zc:externConstexpr
 /await
 /W4
 /D_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING
 /D_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING
 /D_CRT_SECURE_NO_DEPRECATE
 /wd4251
 /wd4275
 /wd4503
 /wd4127
 /wd4100
 /wd4702
 /wd4267
 /WX
 -std:c++latest
 /showIncludes
 /Fopath\to\object\output\dir\objectfile.cpp.obj
 /Fdpath\to\program\database\dir\
 /FS
 -c C:\path\to\source\cpp\file\code.cpp

Thank you all in advance!

DragonAxe commented 3 years ago

After some more testing, it appears the /Zm500 argument is not recognized as a valid flag.

jviotti commented 3 years ago

@DragonAxe Do you mean that removing /Zm500 made it work for you?

DragonAxe commented 3 years ago

@jviotti I didn't try removing that flag. Instead, I added some print statements to parse_arguments() in src/compiler/msvc.rs to see which of my compiler options was being picked up as an input file by Sccache. In that same file I also noticed this comment: // TODO: what do do with precompiled header flags? eg: /Y-, /Yc, /YI, /Yu, /Zf, /ZH, /Zm

I tried adding msvc_flag!("Zm500", PassThrough), to the list of recognized msvc_args!, but wasn't able to get it to work by ignoring that argument (just as a temporary workaround to get things to work locally). I don't know enough about Rust or Sccache to do things other than trial and error at this point.

DragonAxe commented 3 years ago

@DragonAxe Do you mean that removing /Zm500 made it work for you?

@jviotti Yes, after disabling the addition of the /Zm500 flag in my cmake, I was able to get sccache to start caching (and the speed increase was glorious! :D ).