desktop icon indicating copy to clipboard operation
desktop copied to clipboard

CMake: use ccache and sccache for compiler caching

Open Be-ing opened this issue 4 years ago • 20 comments

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]

Be-ing avatar Nov 03 '21 01:11 Be-ing

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.

FlexW avatar Nov 03 '21 14:11 FlexW

Yes, good idea.

Be-ing avatar Nov 03 '21 14:11 Be-ing

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.

Be-ing avatar Nov 03 '21 16:11 Be-ing

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?

Be-ing avatar Nov 03 '21 16:11 Be-ing

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.

FlexW avatar Nov 04 '21 14:11 FlexW

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.

Be-ing avatar Nov 05 '21 13:11 Be-ing

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

mgallien avatar Nov 05 '21 17:11 mgallien

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

Be-ing avatar Nov 05 '21 17:11 Be-ing

Is there anything left to do here?

Be-ing avatar Nov 08 '21 23:11 Be-ing

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

mgallien avatar Nov 12 '21 15:11 mgallien

@Be-ing sorry for almost forgetting about this can you rebase ?

mgallien avatar Jan 11 '22 13:01 mgallien

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

eli-schwartz avatar Jan 11 '22 22:01 eli-schwartz

This CMake module creates CCACHE and SCCACHE boolean CMake options to manually disable compiler caching is desired.

Be-ing avatar Jan 12 '22 01:01 Be-ing

I don't mind, but this includes code originally written by @emabrey so she would need to approve relicensing it as well.

Be-ing avatar Jan 20 '22 14:01 Be-ing

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?

camilasan avatar Feb 07 '22 17:02 camilasan

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

emabrey avatar Feb 08 '22 07:02 emabrey

I just noticed that I had not updated the SPDX license identifier when copying this module to another repo. I just fixed that.

Be-ing avatar Mar 09 '22 22:03 Be-ing

/rebase

camilasan avatar May 11 '22 10:05 camilasan

Codecov Report

Merging #3947 (8f83cdd) into master (eec4069) will increase coverage by 0.03%. The diff coverage is n/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     

see 3 files with indirect coverage changes

codecov[bot] avatar Aug 22 '23 09:08 codecov[bot]

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.

nextcloud-desktop-bot avatar Aug 23 '23 13:08 nextcloud-desktop-bot

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

Rello avatar Dec 03 '24 09:12 Rello