Repository navigation
Description
My general understanding is that ccache uses the dependencies information provided by -MD compiler flags to determine if something changed for the current source file, and if the dependencies have not changed, and the compiler command line is identical then it will serve the object file from the cache.
The Visual C++ compiler has for a while now the /showIncludes parameter which is similar to -MD gcc/clang parameter.
This article from 2008 How to Get Dependencies from /showIncludes tells us that the Visual C++ compiler uses the stderr instead of stdout to display the includes, and it provides a python script which does the command line parsing.
A simple C hello world program like this:
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
will output something like this:
$ cl /showIncludes hello.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27027.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
hello.c
Note: including file: C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\stdio.h
Note: including file: C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt.h
Note: including file: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\vcruntime.h
Note: including file: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\sal.h
Note: including file: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\concurrencysal.h
Note: including file: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\vadefs.h
Note: including file: C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_wstdio.h
Note: including file: C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_stdio_config.h
Microsoft (R) Incremental Linker Version 14.16.27027.1
Copyright (C) Microsoft Corporation. All rights reserved.
/out:hello.exe
hello.obj
Ninja build tool knows about this and they have their own parser for the output. CMake took the ninja parser and built a tool cmcldeps which ships with CMake on Windows since 2012 or so.
By running cmcldeps like this:
cmcldeps C hello.c hello.d hello.obj "Note: including file:" cl cl hello.c
I got the hello.d file:
hello.obj: \
C:\\Program\ Files\ (x86)\\Microsoft\ Visual\ Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include\\concurrencysal.h \
C:\\Program\ Files\ (x86)\\Microsoft\ Visual\ Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include\\sal.h \
C:\\Program\ Files\ (x86)\\Microsoft\ Visual\ Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include\\vadefs.h \
C:\\Program\ Files\ (x86)\\Microsoft\ Visual\ Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include\\vcruntime.h \
C:\\Program\ Files\ (x86)\\Windows\ Kits\\10\\include\\10.0.17763.0\\ucrt\\corecrt.h \
C:\\Program\ Files\ (x86)\\Windows\ Kits\\10\\include\\10.0.17763.0\\ucrt\\corecrt_stdio_config.h \
C:\\Program\ Files\ (x86)\\Windows\ Kits\\10\\include\\10.0.17763.0\\ucrt\\corecrt_wstdio.h \
C:\\Program\ Files\ (x86)\\Windows\ Kits\\10\\include\\10.0.17763.0\\ucrt\\stdio.h \
Testing with clang-cl I got the following result:
$ set PATH=%PATH%;c:\Program Files\LLVM\bin
c:\Temp
$ clang-cl /showIncludes hello.c
Note: including file: C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\stdio.h
Note: including file: C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt.h
Note: including file: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\vcruntime.h
Note: including file: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\sal.h
Note: including file: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\concurrencysal.h
Note: including file: c:\Program Files\LLVM\lib\clang\7.0.1\include\vadefs.h
Note: including file: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\vadefs.h
Note: including file: C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_wstdio.h
Note: including file: C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_stdio_config.h
which when called with
cmcldeps C hello.c hello.d hello.obj "Note: including file:" clang-cl clang-cl hello.c
resulted in:
hello.obj: \
C:\\Program\ Files\ (x86)\\Microsoft\ Visual\ Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include\\concurrencysal.h \
C:\\Program\ Files\ (x86)\\Microsoft\ Visual\ Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include\\sal.h \
C:\\Program\ Files\ (x86)\\Microsoft\ Visual\ Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include\\vadefs.h \
C:\\Program\ Files\ (x86)\\Microsoft\ Visual\ Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include\\vcruntime.h \
C:\\Program\ Files\ (x86)\\Windows\ Kits\\10\\include\\10.0.17763.0\\ucrt\\corecrt.h \
C:\\Program\ Files\ (x86)\\Windows\ Kits\\10\\include\\10.0.17763.0\\ucrt\\corecrt_stdio_config.h \
C:\\Program\ Files\ (x86)\\Windows\ Kits\\10\\include\\10.0.17763.0\\ucrt\\corecrt_wstdio.h \
C:\\Program\ Files\ (x86)\\Windows\ Kits\\10\\include\\10.0.17763.0\\ucrt\\stdio.h \
c:\\Program\ Files\\LLVM\\lib\\clang\\7.0.1\\include\\vadefs.h \
I have seen the work done with #162 and it's unfortunate that we didn't get Visual C++ support in ccache.
The hard part is to take into consideration all the Visual C++ / Clang-cl flags.
Activity
jrosdahl commentedon Jun 5, 2019
Hi Cristian!
Well, yes, but only in the depend mode, which isn't enabled by default. The default method is to run the preprocessor and check its output, including which include files was read.
I can totally understand that you and others think that it's unfortunate. But for me, it's liberating not having to spend my limited time on things I'm not interested in. Since you have seen #162, I guess you have seen my response as well. What I wrote then is still accurate.
It's not only a matter of "getting Visual C++ support", it's about "getting Visual C++ support and then (for many years) maintain and fix bugs in the code and having to deal with the complexity cost brought by the increased design and test space".
As mentioned in my response to #162, a sibling "ccache for windows" project, run by others, would be great! Would you like to help with such an effort?
Yes, but also general basic Windows-related things like how filenames, files and processes (and likely sockets in the future) are handled. Even keeping ccache just compiling on Windows is not trivial.
cristianadam commentedon Jun 11, 2019
What Joel tried with #162 is to get ccache to support Visual C++, and at the same time build ccache itself with Visual C++.
I'm just interested in the former. I'm happy to build ccache with MinGW, and have support for Visual C++.
I only want to use the same caching tool cross platform. I assume all these ccache clones:
were created because ccache was written in C, and the build and testing support was complicated to handle Windows / Visual C++.
As it turns out buildcache in written in C++, builds with CMake, and supports Visual C++. It might be wiser for me to just use buildcache, instead of trying to get ccache to do exactly the same thing.
jrosdahl commentedon Jun 11, 2019
Just to avoid confusion here: #162 was jd-gasquel's PR, not mine. The problem with #162 was that it was just too messy and intrusive to even begin considering.
Thanks for the clarification.
Well, build and testing support, and being written in C, could very well be part of the motivation behind the projects you mention, but I doubt that they were the primary trigger. More likely reasons:
Regarding reason one: The situation would not be different if ccache had been written in C++ or any other language from start. The reason why there are no suitable abstractions in place is because ccache started out as a very small and straightforward hack in 2002 by Andrew Tridgell, who I assume only had the goal of making something that worked for the compilers and systems that were relevant for Samba at the time. Things like various attempts of Windows support, support for Clang, etc, were added in more or less hacky ways along the road.
Regarding reason two: I welcome more active developers on the team. If we were more, we could certainly take on bigger tasks. But as long as we are very few with limited time to spare, I just have to try to adjust my time resources accordingly. I hope that this makes sense to you.
If you or anybody else steps forward and want to work on abstracting the frontend code, and to maintain Visual C++ parts of ccache, then I'm all for it. But I think that at least in the short term, such an effort is better done in another repository than the main ccache repository. This way the "ccache for Visual C++" project can have a release schedule separate from the main ccache project. The sibling project would contribute refactorings back to the main ccache project, and if everything goes well, the sibling project can merge back to the main project eventually.
I had not heard about buildcache before, but it looks like a nice project.
afbjorklund commentedon Jul 21, 2019
So I guess we can close this now ? Seems like different platforms have some very different issues...
Says
clcache:My suggestion is to drop all Windows support (not MSYS2!) in ccache, and let it be handled properly.
jrosdahl commentedon Jul 21, 2019
Sounds OK from my perspective (but then again I'm not a Windows user and don't know details about the different Windows ecosystems).
@cristianadam: What's your view on this? Would an MSYS2 version of ccache suffice, or is there a value in the MinGW version?
afbjorklund commentedon Jul 21, 2019
We could drop MSYS2 support as well, if we don't want to handle things like missing symlinks (#170).
But currently they are being patched downstream (since a year) and seem to work, so maybe keep it ?
PR #246 (apr 2018)
a.k.a. https://github.com/msys2/MSYS2-packages/blob/master/ccache/ccache-3.4.2-msys.patch
cristianadam commentedon Jul 22, 2019
@jrosdahl At the moment I like not having to install MSYS2 just to compile ccache. Qt ships with MinGW compiler and it's all we actually need.
But as it turns out I will really need to have Visual C++ support, because of Clang-Cl.
If you decide to remove stuff I'll probably have to add it to my fork. :(
afbjorklund commentedon Jul 22, 2019
But maybe that's a good thing, rather than it have stuck in a PR queue ?
And then you can set up proper support for CI (like Appveyor), instead of hoping.
I was trying to make it work using MinGW and WINE, but that only goes so far...
Most of the remaining bugs can only be found/fixed on the actual Windows OS.
Personally I think keeping MSYS2 (Cygwin) is a reasonable/maintainable effort.
Having a MinGW version "would have been nice", but I'm not using Windows myself.
Anyway, the code that I had written (now abandoned) only catered for MinGW's MSYS.
Even though it did run on Windows, it still had a decent shell and a normal gcc compiler.
Thus it could still use autotools, and didn't have to handle all strange paths and params.
But even that was a lot of code and work, so it is much easier to stick to POSIX and MSYS2.
Note:
MSYS = Win32 = Windows
MSYS2 = Cygwin = POSIX
There is support for both environments (three if you count 32-bit vs 64-bit) in Mingw-w64,
which makes things rather confusing... It is also a full compiler toolchain, and not a shell.
So we use the two
w64-mingw32cross-compilers to target the different Windows targets.And that runs fine also on Linux, the main problem is doing proper testing - without Windows.
Thus:
MSYS != MSYS2
MinGW != Mingw-w64
jrosdahl commentedon Jul 27, 2019
@cristianadam wrote:
Why is installing MSYS2 a problem? (Excuse me if the question is strange, I don't know much about the ecosystem you're in.)
I agree with @afbjorklund: Maybe it's a good thing if you would take over the Windows native parts since you're interested in them? Or maybe you want to help out maintaining Windows-related code in ccache?
afbjorklund commentedon Jul 28, 2019
Basically MSYS2 is a nice POSIX emulator, if you don't like the Windows environment. Like Cygwin.
jrosdahl commentedon Jul 28, 2019
See also #447.