CMake: use ccache and sccache for compiler caching
First build on Fedora 35 with an Intel Core i7 8550U: 4.5 minutes
Repeat build with ccache after deleting CMake build directory and creating a new one: 1.5 minutes
This code is adapted from Tenacity, written by myself and @emabrey, licensed GPLv2 or later.
ccache is easily available from Linux distribution packages and Homebrew on macOS. sccache is the only currently maintained compiler cache for MSVC and can be installed easily from Chocolatey on Windows.
Signed-off-by: Be [email protected]
Nice :) thank you. I haven't tested it yet, but do you think it would be possible to extract the logic into a ccache.cmake file (or similar) and put this file into the module folder? Would help with the readability.
Yes, good idea.
I refactored it to not even check for ccache if CMake is using MSVC as the compiler. Extracting this to a CMake module is a good idea. This could be easily dropped into any CMake project now.
The next step after this could be using this on CI. I haven't worked with Drone before but I suppose it shouldn't be too hard. I don't see how macOS builds are done though... is CI only running for Linux and Windows?
The next step after this could be using this on CI. I haven't worked with Drone before but I suppose it shouldn't be too hard. I don't see how macOS builds are done though... is CI only running for Linux and Windows?
Yes, correct. CI is only running on Windows and Linux.
my question is because I believe some people might have ccache installed but would not necessarily want to use it
Why? I have never seen anyone raise concern about this. If they are bothered by this, they could uninstall ccache, or manually specify -D CCACHE=OFF. FWIW Meson uses ccache by default.
or is there absolutely no downside to use it ? (disc space usage, ...)
The only downside is storage space used. The maximum cache size can be set with ccache -M. The default size limit is 5 GB.
my question is because I believe some people might have ccache installed but would not necessarily want to use it
Why? I have never seen anyone raise concern about this. If they are bothered by this, they could uninstall ccache, or manually specify
-D CCACHE=OFF. FWIW Meson uses ccache by default.
How do you make sure that in no case you can get obsolete compilation products being used ?
I have bad memories of such tools that would often fail (OK, not ccache but still).
I am genuinely curious about ccache as I rarely used it in the past.
or is there absolutely no downside to use it ? (disc space usage, ...)
The only downside is storage space used. The maximum cache size can be set with
ccache -M. The default size limit is 5 GB.
should not be a problem for people familiar with it
How do you make sure that in no case you can get obsolete compilation products being used ?
This is ccache's job and it does a really good job of it. I have never once had a problem that was fixed by disabling ccache.
https://ccache.dev/manual/4.4.2.html#_how_ccache_works
Is there anything left to do here?
Is there anything left to do here?
we are in the process of pushing a release and master is frozen we are going to have to wait sorry
@Be-ing sorry for almost forgetting about this can you rebase ?
FWIW, while I've never had a problem caused by ccache doing bad caches that caused the wrong results, there are definitely times I didn't want to use ccache even when it is installed. Both because of the space, and because ccache is, by design, a bit slower than running the compiler on its own -- due to the file copying it kind of has to be. So, one might want to disable ccache if it is known that the build itself is a one-off build of something and the work will never be reused.
meson enables it by default, which generally works quite well, but only if you let it autodetect the compiler. You can specify CC=gcc to avoid autodetection, or CC=/path/to/ccache gcc to manually force ccache on together with the chosen compiler.
Apparently cmake defines a special option for a compiler wrapper? Interesting. Anyway, offering a cmake option to disable ccache is all that I think is needed, and that is done here... now the trick is to let people know that such an option exists without first running cmake, having it detect ccache, and then running cmake -LH and rapidly eyeballing the long list of internal state variables until you find ones that look like they toggle options. That problem might be unfixable, though. :D
This CMake module creates CCACHE and SCCACHE boolean CMake options to manually disable compiler caching is desired.
I don't mind, but this includes code originally written by @emabrey so she would need to approve relicensing it as well.
I don't mind, but this includes code originally written by @emabrey so she would need to approve relicensing it as well.
Hi @emabrey, would you be ok with relicensing it as well?
I don't mind, but this includes code originally written by @emabrey so she would need to approve relicensing it as well.
Hi @emabrey, would you be ok with relicensing it as well?
Yes I'm okay with a re-license under BSD 3-clause
I just noticed that I had not updated the SPDX license identifier when copying this module to another repo. I just fixed that.
/rebase
Codecov Report
Merging #3947 (8f83cdd) into master (eec4069) will increase coverage by
0.03%. The diff coverage isn/a.
Additional details and impacted files
@@ Coverage Diff @@
## master #3947 +/- ##
==========================================
+ Coverage 60.09% 60.12% +0.03%
==========================================
Files 145 145
Lines 18810 18810
==========================================
+ Hits 11303 11309 +6
+ Misses 7507 7501 -6
AppImage file: nextcloud-PR-3947-8f83cdde40420a19a72c9cc986b2c70e8a9fcff1-x86_64.AppImage
To test this change/fix you can simply download above AppImage file and test it.
Please make sure to quit your existing Nextcloud app and backup your data.
Hello,
Thank you for your contribution to the Desktop Client with this pull request. We are closing this request as it is outdated, no longer relevant (e.g., due to Qt 6), or does not align with the current roadmap.
We truly value your support and hope to see more contributions from you in the future!
Best regards, Nextcloud Desktop Team