]> git.ipfire.org Git - thirdparty/ccache.git/blob - doc/MANUAL.adoc
chore: Fix typos
[thirdparty/ccache.git] / doc / MANUAL.adoc
1 = ccache(1)
2 :mansource: Ccache {revnumber}
3
4 == Name
5
6 ccache - a fast C/C++ compiler cache
7
8
9 == Synopsis
10
11 [verse]
12 *ccache* [_options_]
13 *ccache* _compiler_ [_compiler options_]
14 _compiler_ [_compiler options_] (ccache masquerading as the compiler)
15
16
17 == Description
18
19 Ccache is a compiler cache. It speeds up recompilation by caching the result of
20 previous compilations and detecting when the same compilation is being done
21 again.
22
23 Ccache has been carefully written to always produce exactly the same compiler
24 output that you would get without the cache. The only way you should be able to
25 tell that you are using ccache is the speed. Currently known exceptions to this
26 goal are listed under _<<Caveats>>_. If you discover an undocumented case where
27 ccache changes the output of your compiler, please let us know.
28
29
30 == Run modes
31
32 There are two different ways to use ccache to cache a compilation:
33
34 1. Prefix your compilation command with `ccache`. This method is most convenient
35 if you just want to try out ccache or wish to use it for some specific
36 projects. Example:
37 +
38 -------------------------------------------------------------------------------
39 ccache gcc -c example.c
40 -------------------------------------------------------------------------------
41 +
42 2. Let ccache masquerade as the compiler. This method is most useful when you
43 wish to use ccache for all your compilations. To do this, create a symbolic
44 link to ccache named as the compiler. For example, here is set up ccache to
45 masquerade as `gcc` and `g++`:
46 +
47 -------------------------------------------------------------------------------
48 cp ccache /usr/local/bin/
49 ln -s ccache /usr/local/bin/gcc
50 ln -s ccache /usr/local/bin/g++
51 -------------------------------------------------------------------------------
52 +
53 On platforms that don't support symbolic links you can simply copy ccache to the
54 compiler name instead for a similar effect:
55 +
56 -------------------------------------------------------------------------------
57 cp ccache /usr/local/bin/gcc
58 cp ccache /usr/local/bin/g++
59 -------------------------------------------------------------------------------
60 +
61 And so forth. This will work as long as the directory with symbolic links or
62 ccache copies comes before the directory with the compiler (typically
63 `/usr/bin`) in `PATH`.
64 +
65 WARNING: The technique of letting ccache masquerade as the compiler works well,
66 but currently doesn't interact well with other tools that do the same thing. See
67 _<<Using ccache with other compiler wrappers>>_.
68
69
70 == Command line options
71
72 These command line options only apply when you invoke ccache as "`ccache`". When
73 ccache masquerades as a compiler (as described in the previous section), the
74 normal compiler options apply and you should refer to the compiler's
75 documentation.
76
77
78 === Common options
79
80 *-c*, *--cleanup*::
81
82 Clean up the cache by removing old cached files until the specified file
83 number and cache size limits are not exceeded. This also recalculates the
84 cache file count and size totals. Normally, there is no need to initiate
85 cleanup manually as ccache keeps the cache below the specified limits at
86 runtime and keeps statistics up to date on each compilation. Forcing a
87 cleanup is mostly useful if you have modified the cache contents manually or
88 believe that the cache size statistics may be inaccurate.
89
90 *-C*, *--clear*::
91
92 Clear the entire cache, removing all cached files, but keeping the
93 configuration file.
94
95 *--config-path* _PATH_::
96
97 Let the command line options operate on configuration file _PATH_ instead of
98 the default. Using this option has the same effect as setting (overriding)
99 the environment variable `CCACHE_CONFIGPATH` temporarily.
100
101 *-d*, *--dir* _PATH_::
102
103 Let the command line options operate on cache directory _PATH_ instead of
104 the default. For example, to show statistics for a cache directory at
105 `/shared/ccache` you can run `ccache -d /shared/ccache -s`. Using this option
106 has the same effect as setting the environment variable `CCACHE_DIR`
107 temporarily.
108
109 *--evict-namespace* _NAMESPACE_::
110
111 Remove files created in the given <<config_namespace,*namespace*>> from the
112 cache.
113
114 *--evict-older-than* _AGE_::
115
116 Remove files older than _AGE_ from the cache. _AGE_ should be an unsigned
117 integer with a `d` (days) or `s` (seconds) suffix. If combined with
118 `--evict-namespace`, only remove old files within that namespace.
119
120 *-h*, *--help*::
121
122 Print a summary of command line options.
123
124 *-F* _NUM_, *--max-files* _NUM_::
125
126 Set the maximum number of files allowed in the cache to _NUM_. Use 0 for no
127 limit. The value is stored in a configuration file in the cache directory
128 and applies to all future compilations.
129
130 *-M* _SIZE_, *--max-size* _SIZE_::
131
132 Set the maximum size of the files stored in the cache. _SIZE_ should be a
133 number followed by an optional suffix: k, M, G, T (decimal), Ki, Mi, Gi or
134 Ti (binary). The default suffix is G. Use 0 for no limit. The value is
135 stored in a configuration file in the cache directory and applies to all
136 future compilations.
137
138 *-X* _LEVEL_, *--recompress* _LEVEL_::
139
140 Recompress the cache to level _LEVEL_ using the Zstandard algorithm. The
141 level can be an integer, with the same semantics as the
142 <<config_compression_level,*compression_level*>> configuration option, or
143 the special value *uncompressed* for no compression. See _<<Cache
144 compression>>_ for more information. This can potentially take a long time
145 since all files in the cache need to be visited. Only files that are
146 currently compressed with a different level than _LEVEL_ will be
147 recompressed.
148
149 *--recompress-threads* _THREADS_::
150
151 Use up to _THREADS_ threads when recompressing the cache. The default is to
152 use one thread per CPU.
153
154 *-o* _KEY=VALUE_, *--set-config* _KEY_=_VALUE_::
155
156 Set configuration option _KEY_ to _VALUE_. See _<<Configuration>>_ for more
157 information.
158
159 *-x*, *--show-compression*::
160
161 Print cache compression statistics. See _<<Cache compression>>_ for more
162 information. This can potentially take a long time since all files in the
163 cache need to be visited.
164
165 *-p*, *--show-config*::
166
167 Print current configuration options and from where they originate
168 (environment variable, configuration file or compile-time default) in
169 human-readable format.
170
171 *--show-log-stats*::
172
173 Print statistics counters from the stats log in human-readable format. See
174 <<config_stats_log,*stats_log*>>. Use `-v`/`--verbose` once or twice for
175 more details.
176
177 *-s*, *--show-stats*::
178
179 Print a summary of configuration and statistics counters in human-readable
180 format. Use `-v`/`--verbose` once or twice for more details.
181
182 *-v*, *--verbose*::
183
184 Increase verbosity. The option can be given multiple times.
185
186 *-V*, *--version*::
187
188 Print version and copyright information.
189
190 *-z*, *--zero-stats*::
191
192 Zero the cache statistics (but not the configuration options).
193
194
195 === Options for remote file-based storage
196
197 *--trim-dir* _PATH_::
198
199 Remove old files from directory _PATH_ until it is at most the size
200 specified by `--trim-max-size`.
201 +
202 WARNING: Don't use this option to trim the local cache. To trim the local cache
203 directory to a certain size, use `CCACHE_MAXSIZE=_SIZE_ ccache -c`.
204
205 *--trim-max-size* _SIZE_::
206
207 Specify the maximum size for `--trim-dir`. _SIZE_ should be a number
208 followed by an optional suffix: k, M, G, T (decimal), Ki, Mi, Gi or Ti
209 (binary). The default suffix is G.
210
211 *--trim-method* _METHOD_::
212
213 Specify the method to trim a directory with `--trim-dir`. Possible values
214 are:
215 +
216 --
217 *atime*::
218 LRU (least recently used) using the file access timestamp. This is the
219 default.
220 *mtime*::
221 LRU (least recently used) using the file modification timestamp.
222 --
223
224 *--trim-recompress* _LEVEL_::
225
226 Recompress to level _LEVEL_ using the Zstandard algorithm when using
227 `--trim-dir`. The level can be an integer, with the same semantics as the
228 <<config_compression_level,*compression_level*>> configuration option, or
229 the special value *uncompressed* for no compression. See _<<Cache
230 compression>>_ for more information. This can potentially take a long time
231 since all files in the cache need to be visited. Only files that are
232 currently compressed with a different level than _LEVEL_ will be
233 recompressed.
234
235 *--trim-recompress-threads* _THREADS_::
236
237 Recompress using up to _THREADS_ threads with `--trim-recompress`. The
238 default is to use one thread per CPU.
239
240
241 === Options for scripting or debugging
242
243 *--checksum-file* _PATH_::
244
245 Print the checksum (128 bit XXH3) of the file at _PATH_ (`-` for standard
246 input).
247
248 *--extract-result* _PATH_::
249
250 Extract data stored in the result file at _PATH_ (`-` for standard input).
251 The data will be written to `ccache-result.*` files in to the current
252 working directory. This option is only useful when debugging ccache and its
253 behavior.
254
255 *-k* _KEY_, *--get-config* _KEY_::
256
257 Print the value of configuration option _KEY_. See _<<Configuration>>_ for
258 more information.
259
260 *--hash-file* _PATH_::
261
262 Print the hash (160 bit BLAKE3) of the file at _PATH_ (`-` for standard
263 input). This is only useful when debugging ccache and its behavior.
264
265 *--inspect* _PATH_::
266
267 Print the content of a result or manifest file at _PATH_ (`-` for standard
268 input) to standard output in human-readable format. File content embedded in
269 a result file will however not be printed; use `--extract-result` to extract
270 the file content. This option is only useful when debugging ccache and its
271 behavior.
272
273 *--print-stats*::
274
275 Print statistics counter IDs and corresponding values in machine-parsable
276 (tab-separated) format.
277
278
279
280 === Extra options
281
282 When run as a compiler, ccache usually just takes the same command line options
283 as the compiler you are using. The only exception to this is the option
284 `--ccache-skip`. That option can be used to tell ccache to avoid interpreting
285 the next option in any way and to pass it along to the compiler as-is.
286
287 NOTE: `--ccache-skip` currently only tells ccache not to interpret the next
288 option as a special compiler option -- the option will still be included in the
289 direct mode hash.
290
291 The reason this can be important is that ccache does need to parse the command
292 line and determine what is an input filename and what is a compiler option, as
293 it needs the input filename to determine the name of the resulting object file
294 (among other things). The heuristic ccache uses when parsing the command line
295 is that any argument that exists as a file is treated as an input file name. By
296 using `--ccache-skip` you can force an option to not be treated as an input
297 file name and instead be passed along to the compiler as a command line option.
298
299 Another case where `--ccache-skip` can be useful is if ccache interprets an
300 option specially but shouldn't, since the option has another meaning for your
301 compiler than what ccache thinks.
302
303
304 == Configuration
305
306 Ccache's default behavior can be overridden by options in configuration files,
307 which in turn can be overridden by environment variables with names starting
308 with `CCACHE_`. Ccache normally reads configuration from two files: first a
309 system-level configuration file and secondly a cache-specific configuration
310 file. The priorities of configuration options are as follows (where 1 is
311 highest):
312
313 1. Environment variables.
314 2. The cache-specific configuration file (see below).
315 3. The system (read-only) configuration file `<sysconfdir>/ccache.conf`
316 (typically `/etc/ccache.conf` or `/usr/local/etc/ccache.conf`).
317 4. Compile-time defaults.
318
319 As a special case, if the environment variable `CCACHE_CONFIGPATH` is set it
320 specifies the configuration file, and the system configuration file won't be
321 read.
322
323
324 === Location of the configuration file
325
326 The location of the cache-specific configuration file is determined like this on
327 non-Windows systems:
328
329 1. If `CCACHE_CONFIGPATH` is set, use that path.
330 2. Otherwise, if the environment variable `CCACHE_DIR` is set then use
331 `$CCACHE_DIR/ccache.conf`.
332 3. Otherwise, if <<config_cache_dir,*cache_dir*>> is set in the system
333 configuration file then use `<cache_dir>/ccache.conf`.
334 4. Otherwise, if there is a legacy `$HOME/.ccache` directory then use
335 `$HOME/.ccache/ccache.conf`.
336 5. Otherwise, if `XDG_CONFIG_HOME` is set then use
337 `$XDG_CONFIG_HOME/ccache/ccache.conf`.
338 6. Otherwise, use
339 `$HOME/Library/Preferences/ccache/ccache.conf` (macOS) or
340 `$HOME/.config/ccache/ccache.conf` (other systems).
341
342 On Windows, this is the method used to find the configuration file:
343
344 1. If `CCACHE_CONFIGPATH` is set, use that path.
345 2. Otherwise, if the environment variable `CCACHE_DIR` is set then use
346 `%CCACHE_DIR%/ccache.conf`.
347 3. Otherwise, if <<config_cache_dir,*cache_dir*>> is set in the system
348 configuration file then use `<cache_dir>\ccache.conf`. The
349 system-wide configuration on Windows is
350 `%ALLUSERSPROFILE%\ccache\ccache.conf` by default. The `ALLUSERSPROFILE`
351 environment variable is usually `C:\ProgramData`.
352 4. Otherwise, if there is a legacy `%USERPROFILE%\.ccache` directory then use
353 `%USERPROFILE%\.ccache\ccache.conf`.
354 5. Otherwise, use `%LOCALAPPDATA%\ccache\ccache.conf` if it exists.
355 6. Otherwise, use `%APPDATA%\ccache\ccache.conf`.
356
357 See also the <<config_cache_dir,*cache_dir*>> configuration option for how the
358 cache directory location is determined.
359
360
361 === Configuration file syntax
362
363 Configuration files are in a simple "`key = value`" format, one option per
364 line. Lines starting with a hash sign are comments. Blank lines are ignored, as
365 is whitespace surrounding keys and values. Example:
366
367 -------------------------------------------------------------------------------
368 # Set maximum cache size to 10 GB:
369 max_size = 10G
370 -------------------------------------------------------------------------------
371
372
373 === Boolean values
374
375 Some configuration options are boolean values (i.e. truth values). In a
376 configuration file, such values must be set to the string *true* or *false*.
377 For the corresponding environment variables, the semantics are a bit different:
378
379 * A set environment variable means "`true`" (even if set to the empty string).
380 * The following case-insensitive negative values are considered an error
381 (instead of surprising the user): *0*, *false*, *disable* and *no*.
382 * An unset environment variable means "`false`".
383
384 Each boolean environment variable also has a negated form starting with
385 `CCACHE_NO`. For example, `CCACHE_COMPRESS` can be set to force compression and
386 `CCACHE_NOCOMPRESS` can be set to force no compression.
387
388
389 === Configuration options
390
391 Below is a list of available configuration options. The corresponding
392 environment variable name is indicated in parentheses after each configuration
393 option key.
394
395 [#config_absolute_paths_in_stderr]
396 *absolute_paths_in_stderr* (*CCACHE_ABSSTDERR*)::
397
398 This option specifies whether ccache should rewrite relative paths in the
399 compiler's standard error output to absolute paths. This can be useful if
400 you use <<config_base_dir,*base_dir*>> with a build system (e.g. CMake with
401 the "Unix Makefiles" generator) that executes the compiler in a different
402 working directory, which makes relative paths in compiler errors or
403 warnings incorrect. The default is false.
404
405 [#config_base_dir]
406 *base_dir* (*CCACHE_BASEDIR*)::
407
408 This option should be an absolute path to a directory. If set, ccache will
409 rewrite absolute paths into paths relative to the current working directory,
410 but only absolute paths that begin with *base_dir*. Cache results can then
411 be shared for compilations in different directories even if the project uses
412 absolute paths in the compiler command line. See also the discussion under
413 _<<Compiling in different directories>>_. If set to the empty string (which
414 is the default), no rewriting is done.
415 +
416 A typical path to use as *base_dir* is your home directory or another directory
417 that is a parent of your project directories. Don't use `/` as the base
418 directory since that will make ccache also rewrite paths to system header
419 files, which typically is contraproductive.
420 +
421 For example, say that Alice's current working directory is
422 `/home/alice/project1/build` and that she compiles like this:
423 +
424 -------------------------------------------------------------------------------
425 ccache gcc -I/usr/include/example -I/home/alice/project2/include -c /home/alice/project1/src/example.c
426 -------------------------------------------------------------------------------
427 +
428 Here is what ccache will actually execute for different *base_dir* values:
429 +
430 -------------------------------------------------------------------------------
431 # Current working directory: /home/alice/project1/build
432
433 # With base_dir = /:
434 gcc -I../../../../usr/include/example -I../../project2/include -c ../src/example.c
435
436 # With base_dir = /home or /home/alice:
437 gcc -I/usr/include/example -I../../project2/include -c ../src/example.c
438
439 # With base_dir = /home/alice/project1 or /home/alice/project1/src:
440 gcc -I/usr/include/example -I/home/alice/project2/include -c ../src/example.c
441 -------------------------------------------------------------------------------
442 +
443 If Bob has put `project1` and `project2` in `/home/bob/stuff` and both users
444 have set *base_dir* to `/home` or `/home/$USER`, then Bob will get a cache hit
445 (if they share ccache directory) since the actual command line will be
446 identical to that of Alice:
447 +
448 -------------------------------------------------------------------------------
449 # Current working directory: /home/bob/stuff/project1/build
450
451 # With base_dir = /home or /home/bob:
452 gcc -I/usr/include/example -I../../project2/include -c ../src/example.c
453 -------------------------------------------------------------------------------
454 +
455 Without *base_dir* there will be a cache miss since the absolute paths will
456 differ. With *base_dir* set to `/` there will be a cache miss since the
457 relative path to `/usr/include/example` will be different. With *base_dir* set
458 to `/home/bob/stuff/project1` there will a cache miss since the path to
459 project2 will be a different absolute path.
460 +
461 WARNING: Rewriting absolute paths to relative is kind of a brittle hack. It
462 works OK in many cases, but there might be cases where things break. One known
463 issue is that absolute paths are not reproduced in dependency files, which can
464 mess up dependency detection in tools like Make and Ninja. If possible, use
465 relative paths in the first place instead instead of using *base_dir*.
466
467 [#config_cache_dir]
468 *cache_dir* (*CCACHE_DIR*)::
469
470 This option specifies where ccache will keep its cached compiler outputs.
471 +
472 On non-Windows systems, the default is `$HOME/.ccache` if such a directory
473 exists, otherwise `$XDG_CACHE_HOME/ccache` if `XDG_CACHE_HOME` is set, otherwise
474 `$HOME/Library/Caches/ccache` (macOS) or `$HOME/.config/ccache` (other systems).
475 +
476 On Windows, the default is `%USERPROFILE%\.ccache` if such a directory exists,
477 otherwise `%LOCALAPPDATA%\ccache`.
478 +
479 WARNING: Previous ccache versions defaulted to storing the cache in
480 `%APPDATA%\ccache` on Windows. This can result in large network file transfers
481 of the cache in domain environments and similar problems. Please check this
482 directory for cache directories and either delete them or the whole directory,
483 or move them to the `%LOCALAPPDATA%\ccache` directory.
484 +
485 See also _<<Location of the configuration file>>_.
486
487 [#config_compiler]
488 *compiler* (*CCACHE_COMPILER* or (deprecated) *CCACHE_CC*)::
489
490 This option can be used to force the name of the compiler to use. If set to
491 the empty string (which is the default), ccache works it out from the
492 command line.
493
494 [#config_compiler_check]
495 *compiler_check* (*CCACHE_COMPILERCHECK*)::
496
497 By default, ccache includes the modification time ("`mtime`") and size of
498 the compiler in the hash to ensure that results retrieved from the cache
499 are accurate. If compiler plugins are used, these plugins will also be
500 added to the hash. This option can be used to select another strategy.
501 Possible values are:
502 +
503 --
504 *content*::
505 Hash the content of the compiler binary. This makes ccache very slightly
506 slower compared to *mtime*, but makes it cope better with compiler upgrades
507 during a build bootstrapping process.
508 *mtime*::
509 Hash the compiler's mtime and size, which is fast. This is the default.
510 *none*::
511 Don't hash anything. This may be good for situations where you can safely
512 use the cached results even though the compiler's mtime or size has changed
513 (e.g. if the compiler is built as part of your build system and the
514 compiler's source has not changed, or if the compiler only has changes that
515 don't affect code generation). You should only use *none* if you know what
516 you are doing.
517 *string:value*::
518 Hash *value*. This can for instance be a compiler revision number or
519 another string that the build system generates to identify the compiler.
520 _a command string_::
521 Hash the standard output and standard error output of the specified
522 command. The string will be split on whitespace to find out the command and
523 arguments to run. No other interpretation of the command string will be
524 done, except that the special word *%compiler%* will be replaced with the
525 path to the compiler. Several commands can be specified with semicolon as
526 separator. Examples:
527 +
528 ----
529 %compiler% -v
530 ----
531 +
532 ----
533 %compiler% -dumpmachine; %compiler% -dumpversion
534 ----
535 +
536 You should make sure that the specified command is as fast as possible since it
537 will be run once for each ccache invocation.
538 +
539 Identifying the compiler using a command is useful if you want to avoid cache
540 misses when the compiler has been rebuilt but not changed.
541 +
542 Another case is when the compiler (as seen by ccache) actually isn't the real
543 compiler but another compiler wrapper -- in that case, the default *mtime*
544 method will hash the mtime and size of the other compiler wrapper, which means
545 that ccache won't be able to detect a compiler upgrade. Using a suitable command
546 to identify the compiler is thus safer, but it's also slower, so you should
547 consider continue using the *mtime* method in combination with the
548 *prefix_command* option if possible. See
549 _<<Using ccache with other compiler wrappers>>_.
550 --
551
552 [#config_compiler_type]
553 *compiler_type* (*CCACHE_COMPILERTYPE*)::
554
555 Ccache normally guesses the compiler type based on the compiler name. The
556 *compiler_type* option lets you force a compiler type. This can be useful
557 if the compiler has a non-standard name but is actually one of the known
558 compiler types. Possible values are:
559 +
560 --
561 *auto*::
562 Guess one of the types below based on the compiler name (following
563 symlinks). This is the default.
564 *clang*::
565 Clang-based compiler.
566 *clang-cl*::
567 clang-cl.
568 *gcc*::
569 GCC-based compiler.
570 *icl*::
571 Intel compiler on Windows.
572 *msvc*::
573 Microsoft Visual C++ (MSVC).
574 *nvcc*::
575 NVCC (CUDA) compiler.
576 *other*::
577 Any compiler other than the known types.
578 --
579
580 [#config_compression]
581 *compression* (*CCACHE_COMPRESS* or *CCACHE_NOCOMPRESS*, see _<<Boolean values>>_ above)::
582
583 If true, ccache will compress data it puts in the cache. However, this
584 option has no effect on how files are retrieved from the cache; compressed
585 and uncompressed results will still be usable regardless of this option.
586 The default is true.
587 +
588 Compression is done using the Zstandard algorithm. The algorithm is fast enough
589 that there should be little reason to turn off compression to gain performance.
590 One exception is if the cache is located on a compressed file system, in which
591 case the compression performed by ccache of course is redundant.
592 +
593 Compression will be disabled if file cloning (the
594 <<config_file_clone,*file_clone*>> option) or hard linking (the
595 <<config_hard_link,*hard_link*>> option) is enabled.
596
597 [#config_compression_level]
598 *compression_level* (*CCACHE_COMPRESSLEVEL*)::
599
600 This option determines the level at which ccache will compress object files
601 using the real-time compression algorithm Zstandard. It only has effect if
602 <<config_compression,*compression*>> is enabled (which it is by default).
603 Zstandard is extremely fast for decompression and very fast for compression
604 for lower compression levels. The default is 0.
605 +
606 Semantics of *compression_level*:
607 +
608 --
609 *> 0*::
610 A positive value corresponds to normal Zstandard compression levels. Lower
611 levels (e.g. *1*) mean faster compression but worse compression ratio.
612 Higher levels (e.g. *19*) mean slower compression but better compression
613 ratio. The maximum possible value depends on the libzstd version, but at
614 least up to 19 is available for all versions. Decompression speed is
615 essentially the same for all levels. As a rule of thumb, use level 5 or
616 lower since higher levels may slow down compilations noticeably. Higher
617 levels are however useful when recompressing the cache with command line
618 option `-X`/`--recompress`.
619 *< 0*::
620 A negative value corresponds to Zstandard's "`ultra-fast`" compression
621 levels, which are even faster than level 1 but with less good compression
622 ratios. For instance, level *-3* corresponds to `--fast=3` for the `zstd`
623 command line tool. In practice, there is little use for levels lower than
624 *-5* or so.
625 *0* (default)::
626 The value *0* means that ccache will choose a suitable level, currently
627 *1*.
628 --
629 +
630 See the http://zstd.net[Zstandard documentation] for more information.
631
632 [#config_cpp_extension]
633 *cpp_extension* (*CCACHE_EXTENSION*)::
634
635 This option can be used to force a certain extension for the intermediate
636 preprocessed file. The default is to automatically determine the extension
637 to use for intermediate preprocessor files based on the type of file being
638 compiled, but that sometimes doesn't work. For example, when using the
639 "`aCC`" compiler on HP-UX, set the cpp extension to *i*.
640
641 [#config_debug]
642 *debug* (*CCACHE_DEBUG* or *CCACHE_NODEBUG*, see _<<Boolean values>>_ above)::
643
644 If true, enable the debug mode. The debug mode creates per-object debug
645 files that are helpful when debugging unexpected cache misses. Note however
646 that ccache performance will be reduced slightly. See _<<Cache debugging>>_
647 for more information. The default is false.
648
649 [#config_debug_dir]
650 *debug_dir* (*CCACHE_DEBUGDIR*)::
651
652 Specifies where to write per-object debug files if the <<config_debug,debug
653 mode>> is enabled. If set to the empty string, the files will be written
654 next to the object file. If set to a directory, the debug files will be
655 written with full absolute paths in that directory, creating it if needed.
656 The default is the empty string.
657 +
658 For example, if *debug_dir* is set to `/example`, the current working directory
659 is `/home/user` and the object file is `build/output.o` then the debug log will
660 be written to `/example/home/user/build/output.o.ccache-log`. See also
661 _<<Cache debugging>>_.
662
663 [#config_depend_mode]
664 *depend_mode* (*CCACHE_DEPEND* or *CCACHE_NODEPEND*, see _<<Boolean values>>_ above)::
665
666 If true, the depend mode will be used. The default is false. See
667 _<<The depend mode>>_.
668
669 [#config_direct_mode]
670 *direct_mode* (*CCACHE_DIRECT* or *CCACHE_NODIRECT*, see _<<Boolean values>>_ above)::
671
672 If true, the direct mode will be used. The default is true. See
673 _<<The direct mode>>_.
674
675 [#config_disable]
676 *disable* (*CCACHE_DISABLE* or *CCACHE_NODISABLE*, see _<<Boolean values>>_ above)::
677
678 When true, ccache will just call the real compiler, bypassing the cache
679 completely. The default is false.
680
681 [#config_extra_files_to_hash]
682 *extra_files_to_hash* (*CCACHE_EXTRAFILES*)::
683
684 This option is a list of paths to files that ccache will include in the the
685 hash sum that identifies the build. The list separator is semicolon on
686 Windows systems and colon on other systems.
687
688 [#config_file_clone]
689 *file_clone* (*CCACHE_FILECLONE* or *CCACHE_NOFILECLONE*, see _<<Boolean values>>_ above)::
690
691 If true, ccache will attempt to use file cloning (also known as "`copy on
692 write`", "`CoW`" or "`reflinks`") to store and fetch cached compiler
693 results. *file_clone* has priority over <<config_hard_link,*hard_link*>>.
694 The default is false.
695 +
696 Files stored by cloning cannot be compressed, so the cache size will likely be
697 significantly larger if this option is enabled. However, performance may be
698 improved depending on the use case.
699 +
700 Unlike the <<config_hard_link,*hard_link*>> option, *file_clone* is completely
701 safe to use, but not all file systems support the feature. For such file
702 systems, ccache will fall back to use plain copying (or hard links if
703 <<config_hard_link,*hard_link*>> is enabled).
704
705 [#config_hard_link]
706 *hard_link* (*CCACHE_HARDLINK* or *CCACHE_NOHARDLINK*, see _<<Boolean values>>_ above)::
707
708 If true, ccache will attempt to use hard links to store and fetch cached
709 object files. The default is false.
710 +
711 Files stored via hard links cannot be compressed, so the cache size will likely
712 be significantly larger if this option is enabled. However, performance may be
713 improved depending on the use case.
714 +
715 WARNING: Do not enable this option unless you are aware of these caveats:
716 +
717 * If the resulting file is modified, the file in the cache will also be
718 modified since they share content, which corrupts the cache entry. As of
719 version 4.0, ccache makes stored and fetched object files read-only as a
720 safety measure. Furthermore, a simple integrity check is made for cached
721 object files by verifying that their sizes are correct. This means that
722 mistakes like `strip file.o` or `echo >file.o` will be detected even if the
723 object file is made writable, but a modification that doesn't change the file
724 size will not.
725 * Programs that don't expect that files from two different identical
726 compilations are hard links to each other can fail.
727 * Programs that rely on modification times (like `make`) can be confused if
728 several users (or one user with several build trees) use the same cache
729 directory. The reason for this is that the object files share i-nodes and
730 therefore modification times. If `file.o` is in build tree *A* (hard-linked
731 from the cache) and `file.o` then is produced by ccache in build tree *B* by
732 hard-linking from the cache, the modification timestamp will be updated for
733 `file.o` in build tree *A* as well. This can retrigger relinking in build tree
734 *A* even though nothing really has changed.
735
736 [#config_hash_dir]
737 *hash_dir* (*CCACHE_HASHDIR* or *CCACHE_NOHASHDIR*, see _<<Boolean values>>_ above)::
738
739 If true (which is the default), ccache will include the current working
740 directory (CWD) in the hash that is used to distinguish two compilations
741 when generating debug info (compiler option `-g` with variations).
742 Exception: The CWD will not be included in the hash if
743 <<config_base_dir,*base_dir*>> is set (and matches the CWD) and the
744 compiler option `-fdebug-prefix-map` is used. See also the discussion under
745 _<<Compiling in different directories>>_.
746 +
747 The reason for including the CWD in the hash by default is to prevent a problem
748 with the storage of the current working directory in the debug info of an
749 object file, which can lead ccache to return a cached object file that has the
750 working directory in the debug info set incorrectly.
751 +
752 You can disable this option to get cache hits when compiling the same source
753 code in different directories if you don't mind that CWD in the debug info
754 might be incorrect.
755
756 [#config_ignore_headers_in_manifest]
757 *ignore_headers_in_manifest* (*CCACHE_IGNOREHEADERS*)::
758
759 This option is a list of paths to files (or directories with headers) that
760 ccache will *not* include in the manifest list that makes up the direct
761 mode. Note that this can cause stale cache hits if those headers do indeed
762 change. The list separator is semicolon on Windows systems and colon on
763 other systems.
764
765 [#config_ignore_options]
766 *ignore_options* (*CCACHE_IGNOREOPTIONS*)::
767
768 This option is a space-delimited list of compiler options that ccache will
769 exclude from the hash. Excluding a compiler option from the hash can be
770 useful when you know it doesn't affect the result (but ccache doesn't know
771 that), or when it does and you don't care. If a compiler option in the list
772 is suffixed with an asterisk (`*`) it will be matched as a prefix. For
773 example, `+-fmessage-length=*+` will match both `-fmessage-length=20` and
774 `-fmessage-length=70`.
775
776 [#config_inode_cache]
777 *inode_cache* (*CCACHE_INODECACHE* or *CCACHE_NOINODECACHE*, see _<<Boolean values>>_ above)::
778
779 If true, ccache will cache source file hashes based on device, inode and
780 timestamps. This reduces the time spent on hashing include files since the
781 result can be reused between compilations. The default is true. The feature
782 requires <<config_temporary_dir,*temporary_dir*>> to be located on a local
783 filesystem of a supported type.
784 +
785 NOTE: The inode cache feature is currently not available on Windows.
786
787 [#config_keep_comments_cpp]
788 *keep_comments_cpp* (*CCACHE_COMMENTS* or *CCACHE_NOCOMMENTS*, see _<<Boolean values>>_ above)::
789
790 If true, ccache will not discard the comments before hashing preprocessor
791 output. The default is false. This can be used to check documentation with
792 `-Wdocumentation`.
793
794 [#config_log_file]
795 *log_file* (*CCACHE_LOGFILE*)::
796
797 If set to a file path, ccache will write information on what it is doing to
798 the specified file. This is useful for tracking down problems.
799 +
800 If set to *syslog*, ccache will log using `syslog()` instead of to a file. If
801 you use rsyslogd, you can add something like this to `/etc/rsyslog.conf` or a
802 file in `/etc/rsyslog.d`:
803 +
804 -------------------------------------------------------------------------------
805 # log ccache to file
806 :programname, isequal, "ccache" /var/log/ccache
807 # remove from syslog
808 & ~
809 -------------------------------------------------------------------------------
810
811 [#config_max_files]
812 *max_files* (*CCACHE_MAXFILES*)::
813
814 This option specifies the maximum number of files to keep in the cache. Use
815 0 for no limit (which is the default). See also _<<Cache size management>>_.
816
817 [#config_max_size]
818 *max_size* (*CCACHE_MAXSIZE*)::
819
820 This option specifies the maximum size of the cache. Use 0 for no limit. The
821 default value is 5G. Available suffixes: k, M, G, T (decimal) and Ki, Mi,
822 Gi, Ti (binary). The default suffix is G. See also
823 _<<Cache size management>>_.
824
825 [#config_msvc_dep_prefix]
826 *msvc_dep_prefix* (*CCACHE_MSVC_DEP_PREFIX*)::
827
828 This option specifies the prefix of included files output for MSVC compiler.
829 The default prefix is "`Note: including file:`". If you use a localized
830 compiler, this should be set accordingly.
831
832 [#config_namespace]
833 *namespace* (*CCACHE_NAMESPACE*)::
834
835 If set, the namespace string will be added to the hashed data for each
836 compilation. This will make the associated cache entries logically separate
837 from cache entries with other namespaces, but they will still share the same
838 storage space. Cache entries can also be selectively removed from the local
839 cache with the command line option `--evict-namespace`, potentially in
840 combination with `--evict-older-than`.
841 +
842 For instance, if you use the same local cache for several disparate projects,
843 you can use a unique namespace string for each one. This allows you to remove
844 cache entries that belong to a certain project if you stop working with that
845 project.
846
847 [#config_path]
848 *path* (*CCACHE_PATH*)::
849
850 If set, ccache will search directories in this list when looking for the
851 real compiler. The list separator is semicolon on Windows systems and colon
852 on other systems. If not set, ccache will look for the first executable
853 matching the compiler name in the normal `PATH` that isn't a symbolic link
854 to ccache itself.
855
856 [#config_pch_external_checksum]
857 *pch_external_checksum* (*CCACHE_PCH_EXTSUM* or *CCACHE_NOPCH_EXTSUM*, see _<<Boolean values>>_ above)::
858
859 When this option is set, and ccache finds a precompiled header file,
860 ccache will look for a file with the extension "`.sum`" added
861 (e.g. "`pre.h.gch.sum`"), and if found, it will hash this file instead
862 of the precompiled header itself to work around the performance
863 penalty of hashing very large files.
864
865 [#config_prefix_command]
866 *prefix_command* (*CCACHE_PREFIX*)::
867
868 This option adds a list of prefixes (separated by space) to the command line
869 that ccache uses when invoking the compiler. See also
870 _<<Using ccache with other compiler wrappers>>_.
871
872 [#config_prefix_command_cpp]
873 *prefix_command_cpp* (*CCACHE_PREFIX_CPP*)::
874
875 This option adds a list of prefixes (separated by space) to the command
876 line that ccache uses when invoking the preprocessor.
877
878 [#config_read_only]
879 *read_only* (*CCACHE_READONLY* or *CCACHE_NOREADONLY*, see _<<Boolean values>>_ above)::
880
881 If true, ccache will attempt to use existing cached results, but it will not
882 add new results to any cache backend. Statistics counters will still be
883 updated, though, unless the <<config_stats,*stats*>> option is set to
884 *false*.
885 +
886 If you are using this because your ccache directory is read-only, you need to
887 set <<config_temporary_dir,*temporary_dir*>> since ccache will fail to create
888 temporary files otherwise. You may also want to set <<config_stats,*stats*>> to
889 *false* make ccache not even try to update stats files.
890
891 [#config_read_only_direct]
892 *read_only_direct* (*CCACHE_READONLY_DIRECT* or *CCACHE_NOREADONLY_DIRECT*, see _<<Boolean values>>_ above)::
893
894 Just like <<config_read_only,*read_only*>> except that ccache will only try
895 to retrieve results from the cache using the direct mode, not the
896 preprocessor mode. See documentation for <<config_read_only,*read_only*>>
897 regarding using a read-only ccache directory.
898
899 [#config_recache]
900 *recache* (*CCACHE_RECACHE* or *CCACHE_NORECACHE*, see _<<Boolean values>>_ above)::
901
902 If true, ccache will not use any previously stored result. New results will
903 still be cached, possibly overwriting any pre-existing results.
904
905 [#config_remote_only]
906 *remote_only* (*CCACHE_REMOTE_ONLY* or *CCACHE_NOREMOTE_ONLY*, see _<<Boolean values>>_ above)::
907
908 If true, ccache will only use <<config_remote_storage,remote storage>>. The
909 default is false. Note that cache statistics counters will still be kept in
910 the local cache directory unless <<config_stats,*stats*>> is false. See also
911 _<<Storage interaction>>_.
912
913 [#config_remote_storage]
914 *remote_storage* (*CCACHE_REMOTE_STORAGE*)::
915
916 This option specifies one or several storage backends (separated by space)
917 to query after checking the local cache (unless
918 <<config_remote_only,*remote_only*>> is true). See
919 _<<Remote storage backends>>_ for documentation of syntax and available
920 backends.
921 +
922 Examples:
923 +
924 * `+file:/shared/nfs/directory+`
925 * `+file:///shared/nfs/one|read-only file:///shared/nfs/two+`
926 * `+http://example.com/cache+`
927 * `+redis://example.com+`
928 +
929 NOTE: In previous ccache versions this option was called *secondary_storage*
930 (*CCACHE_SECONDARY_STORAGE*), which can still be used as an alias.
931
932 [#config_reshare]
933 *reshare* (*CCACHE_RESHARE* or *CCACHE_NORESHARE*, see _<<Boolean values>>_ above)::
934
935 If true, ccache will write results to remote storage even for local storage
936 cache hits. The default is false.
937
938 [#config_run_second_cpp]
939 *run_second_cpp* (*CCACHE_CPP2* or *CCACHE_NOCPP2*, see _<<Boolean values>>_ above)::
940
941 If true, ccache will first run the preprocessor to preprocess the source
942 code (see _<<The preprocessor mode>>_) and then on a cache miss run the
943 compiler on the source code to get hold of the object file. This is the
944 default.
945 +
946 If false, ccache will first run preprocessor to preprocess the source code and
947 then on a cache miss run the compiler on the _preprocessed source code_ instead
948 of the original source code. This makes cache misses slightly faster since the
949 source code only has to be preprocessed once. The downside is that some
950 compilers won't produce the same result (for instance diagnostics warnings)
951 when compiling preprocessed source code.
952 +
953 A solution to the above mentioned downside is to set *run_second_cpp* to false
954 and pass `-fdirectives-only` (for GCC) or `-frewrite-includes` (for Clang) to
955 the compiler. This will cause the compiler to leave the macros and other
956 preprocessor information, and only process the *#include* directives. When run
957 in this way, the preprocessor arguments will be passed to the compiler since it
958 still has to do _some_ preprocessing (like macros).
959 +
960 This option is ignored with MSVC, as there is no way to make it compile without
961 preprocessing first.
962
963 [#config_sloppiness]
964 *sloppiness* (*CCACHE_SLOPPINESS*)::
965
966 By default, ccache tries to give as few false cache hits as possible.
967 However, in certain situations it's possible that you know things that
968 ccache can't take for granted. This option makes it possible to tell
969 ccache to relax some checks in order to increase the hit rate. The value
970 should be a comma-separated string with one or several of the following
971 values:
972 +
973 --
974 *clang_index_store*::
975 Ignore the Clang compiler option `-index-store-path` and its argument when
976 computing the manifest hash. This is useful if you use Xcode, which uses an
977 index store path derived from the local project path. Note that the index
978 store won't be updated correctly on cache hits if you enable this
979 sloppiness.
980 *file_stat_matches*::
981 Ccache normally examines a file's contents to determine whether it matches
982 the cached version. With this sloppiness set, ccache will consider a file
983 as matching its cached version if the mtimes and ctimes match.
984 *file_stat_matches_ctime*::
985 Ignore ctimes when *file_stat_matches* is enabled. This can be useful when
986 backdating files' mtimes in a controlled way.
987 *gcno_cwd*::
988 By default, ccache will include the current working directory in the hash
989 when producing a `.gcno` file (when compiling with `-ftest-coverage` or
990 `--coverage`). This is because GCC 9+ includes the current working directory
991 in the `.gcno` file. The *gcno_cwd* sloppiness makes ccache not hash the
992 current working directory so that you can get cache hits when compiling in
993 different directories, with the tradeoff of potentially getting an incorrect
994 directory in the `.gcno` file. *gcno_cwd* also disables hashing of the
995 current working directory if `-fprofile-abs-path` is used.
996 *include_file_ctime*::
997 By default, ccache will disable the direct mode if an include file has too
998 new ctime. This sloppiness disables that check. See also _<<Handling of
999 newly created header files>>_.
1000 *include_file_mtime*::
1001 By default, ccache will disable the direct mode if an include file has too
1002 new mtime. This sloppiness disables that check. See also _<<Handling of
1003 newly created header files>>_.
1004 *ivfsoverlay*::
1005 Ignore the Clang compiler option `-ivfsoverlay` and its argument. This is
1006 useful if you use Xcode, which uses a virtual file system (VFS) for things
1007 like combining Objective-C and Swift code.
1008 *locale*::
1009 Ccache includes the environment variables `LANG`, `LC_ALL`, `LC_CTYPE` and
1010 `LC_MESSAGES` in the hash by default since they may affect localization of
1011 compiler warning messages. Set this sloppiness to tell ccache not to do
1012 that.
1013 *modules*::
1014 By default, ccache will not cache compilations if `-fmodules` is used since
1015 it cannot hash the state of compiler's internal representation of relevant
1016 modules. This sloppiness allows caching in such a case. See
1017 _<<C++ modules>>_ for more information.
1018 *pch_defines*::
1019 Be sloppy about `#define` directives when precompiling a header file. See
1020 _<<Precompiled headers>>_ for more information.
1021 *random_seed*::
1022 Ignore the `-frandom-seed` option and its arguments when computing the input
1023 hash. This is useful if your build system generates different seeds between
1024 builds and you are OK with reusing cached results.
1025 *system_headers*::
1026 By default, ccache will also include all system headers in the manifest.
1027 With this sloppiness set, ccache will only include system headers in the
1028 hash but not add the system header files to the list of include files.
1029 *time_macros*::
1030 Ignore `+__DATE__+`, `+__TIME__+` and `+__TIMESTAMP__+` being present in the
1031 source code.
1032 --
1033 +
1034 See the discussion under _<<Troubleshooting>>_ for more information.
1035
1036 [#config_stats]
1037 *stats* (*CCACHE_STATS* or *CCACHE_NOSTATS*, see _<<Boolean values>>_ above)::
1038
1039 If true, ccache will update the statistics counters on each compilation. The
1040 default is true. If false, _<<automatic cleanup>>_ will be disabled as well.
1041
1042 [#config_stats_log]
1043 *stats_log* (*CCACHE_STATSLOG*)::
1044
1045 If set to a file path, ccache will write statistics counter updates to the
1046 specified file. This is useful for getting statistics for individual builds.
1047 To show a summary of the current stats log, use `ccache --show-log-stats`.
1048 +
1049 NOTE: Lines in the stats log starting with a hash sign (`#`) are comments.
1050
1051 [#config_temporary_dir]
1052 *temporary_dir* (*CCACHE_TEMPDIR*)::
1053
1054 This option specifies where ccache will put temporary files. The default is
1055 `$XDG_RUNTIME_DIR/ccache-tmp` (typically `/run/user/<UID>/ccache-tmp`) if
1056 `XDG_RUNTIME_DIR` is set and the directory exists, otherwise
1057 `<cache_dir>/tmp`.
1058 +
1059 NOTE: In previous versions of ccache, *CCACHE_TEMPDIR* had to be on the same
1060 filesystem as the `CCACHE_DIR` path, but this requirement has been relaxed.
1061
1062 [#config_umask]
1063 *umask* (*CCACHE_UMASK*)::
1064
1065 This option (an octal integer) specifies the umask for files and directories
1066 in the cache directory. This is mostly useful when you wish to share your
1067 cache with other users.
1068
1069
1070 == Remote storage backends
1071
1072 The <<config_remote_storage,*remote_storage*>> option lets you configure ccache
1073 to use one or several remote storage backends. By default, the local cache
1074 directory located in <<config_cache_dir,*cache_dir*>> will be queried first and
1075 remote storage second, but <<config_remote_only,*remote_only*>> can be set to
1076 true to disable local storage. Note that cache statistics counters will still be
1077 kept in the local cache directory -- remote storage backends only store
1078 compilation results and manifests.
1079
1080 A remote storage backend is specified with a URL, optionally followed by a pipe
1081 (`|`) and a pipe-separated list of attributes. An attribute is _key_=_value_ or
1082 just _key_ as a short form of _key_=*true*. Attribute values must be
1083 https://en.wikipedia.org/wiki/Percent-encoding[percent-encoded] if they contain
1084 percent, pipe or space characters.
1085
1086 === Attributes for all backends
1087
1088 These optional attributes are available for all remote storage backends:
1089
1090 * *read-only*: If *true*, only read from this backend, don't write. The default
1091 is *false*.
1092 * *shards*: A comma-separated list of names for sharding (partitioning) the
1093 cache entries using
1094 https://en.wikipedia.org/wiki/Rendezvous_hashing[Rendezvous hashing],
1095 typically to spread the cache over a server cluster. When set, the storage URL
1096 must contain an asterisk (`+*+`), which will be replaced by one of the shard
1097 names to form a real URL. A shard name can optionally have an appended weight
1098 within parentheses to indicate how much of the key space should be associated
1099 with that shard. A shard with weight *w* will contain *w*/*S* of the cache,
1100 where *S* is the sum of all shard weights. A weight could for instance be set
1101 to represent the available memory for a memory cache on a specific server. The
1102 default weight is *1*.
1103 +
1104 Examples:
1105 +
1106 --
1107 * `+redis://cache-*.example.com|shards=a(3),b(1),c(1.5)+` will put 55% (3/5.5)
1108 of the cache on `+redis://cache-a.example.com+`, 18% (1/5.5) on
1109 `+redis://cache-b.example.com+` and 27% (1.5/5.5) on
1110 `+redis://cache-c.example.com+`.
1111 * `+http://example.com/*|shards=alpha,beta+` will put 50% of the cache on
1112 `+http://example.com/alpha+` and 50% on `+http://example.com/beta+`.
1113 --
1114
1115
1116 === Storage interaction
1117
1118 The table below describes the interaction between local and remote storage on
1119 cache hits and misses if <<config_remote_only,*remote_only*>> is false (which is
1120 the default):
1121
1122 [options="header",cols="20%,20%,60%"]
1123 |==============================================================================
1124 | *Local storage* | *Remote storage* | *What happens*
1125
1126 | miss | miss | Compile, write to local, write to remote^[1]^
1127 | miss | hit | Read from remote, write to local
1128 | hit | - | Read from local, don't write to remote^[2]^
1129
1130 |==============================================================================
1131
1132 ^[1]^ Unless remote storage has attribute `read-only=true`. +
1133 ^[2]^ Unless local storage is set to share its cache hits with the
1134 <<config_reshare,*reshare*>> option.
1135
1136 If <<config_remote_only,*remote_only*>> is true:
1137
1138 [options="header",cols="20%,20%,60%"]
1139 |==============================================================================
1140 | *Local storage* | *Remote storage* | *What happens*
1141
1142 | - | miss | Compile, write to remote, don't write to local
1143 | - | hit | Read from remote, don't write to local
1144
1145 |==============================================================================
1146
1147 === File storage backend
1148
1149 URL format: `+file:DIRECTORY+` or `+file://[HOST]DIRECTORY+`
1150
1151 This backend stores data as separate files in a directory structure below
1152 *DIRECTORY*, similar (but not identical) to the local cache storage. A typical
1153 use case for this backend would be sharing a cache on an NFS directory.
1154 *DIRECTORY* must start with a slash. *HOST* can be the empty string or
1155 localhost. On Windows, *HOST* can also be the name of a server hosting a shared
1156 folder.
1157
1158 IMPORTANT: ccache will not perform any cleanup of the storage -- that has to be
1159 done by other means, for instance by running `ccache --trim-dir` periodically.
1160
1161 Examples:
1162
1163 * `+file:/shared/nfs/directory+`
1164 * `+file:///shared/nfs/directory|umask=002|update-mtime=true+`
1165 * `+file://example.com/shared/folder+`
1166
1167 Optional attributes:
1168
1169 * *layout*: How to store file under the cache directory. Available values:
1170 +
1171 --
1172 * *flat*: Store all files directly under the cache directory.
1173 * *subdirs*: Store files in 256 subdirectories of the cache directory.
1174 --
1175 +
1176 The default is *subdirs*.
1177 * *umask*: This attribute (an octal integer) overrides the umask to use for
1178 files and directories in the cache directory.
1179 * *update-mtime*: If *true*, update the modification time (mtime) of cache
1180 entries that are read. The default is *false*.
1181
1182
1183 === HTTP storage backend
1184
1185 URL format: `+http://HOST[:PORT][/PATH]+`
1186
1187 This backend stores data in an HTTP-compatible server. The required HTTP methods
1188 are `GET`, `PUT` and `DELETE`.
1189
1190 IMPORTANT: ccache will not perform any cleanup of the storage -- that has to be
1191 done by other means, for instance by running `ccache --trim-dir` periodically.
1192
1193 NOTE: HTTPS is not supported.
1194
1195 TIP: See https://ccache.dev/howto/http-storage.html[How to set up HTTP storage]
1196 for hints on how to set up an HTTP server for use with ccache.
1197
1198 Examples:
1199
1200 * `+http://localhost+`
1201 * `+http://someusername:p4ssw0rd@example.com/cache/+`
1202 * `+http://localhost:8080|layout=bazel|connect-timeout=50+`
1203
1204 Optional attributes:
1205
1206 * *bearer-token*: Bearer token used to authorize the HTTP requests.
1207 * *connect-timeout*: Timeout (in ms) for network connection. The default is 100.
1208 * *keep-alive*: If *true*, keep the HTTP connection to the storage server open
1209 to avoid reconnects. The default is *true*.
1210 * *layout*: How to map key names to the path part of the URL. Available values:
1211 +
1212 --
1213 * *bazel*: Store values in a format compatible with the Bazel HTTP caching
1214 protocol. More specifically, the entries will be stored as 64 hex digits
1215 under the `/ac/` part of the cache.
1216 +
1217 NOTE: You may have to disable verification of action cache values in the server
1218 for this to work since ccache entries are not valid action result metadata
1219 values.
1220 * *flat*: Append the key directly to the path part of the URL (with a leading
1221 slash if needed).
1222 * *subdirs*: Append the first two characters of the key to the URL (with a
1223 leading slash if needed), followed by a slash and the rest of the key. This
1224 divides the entries into 256 buckets.
1225 --
1226 +
1227 The default is *subdirs*.
1228 * *operation-timeout*: Timeout (in ms) for HTTP requests. The default is 10000.
1229
1230
1231 === Redis storage backend
1232
1233 URL formats:
1234
1235 `+redis://[[USERNAME:]PASSWORD@]HOST[:PORT][/DBNUMBER]+` +
1236 `+redis+unix:SOCKET_PATH[?db=DBNUMBER]+` +
1237 `+redis+unix://[[USERNAME:]PASSWORD@localhost]SOCKET_PATH[?db=DBNUMBER]+`
1238
1239 This backend stores data in a https://redis.io[Redis] (or Redis-compatible)
1240 server. There are implementations for both memory-based and disk-based storage.
1241 *PORT* defaults to *6379* and *DBNUMBER* defaults to *0*.
1242
1243 NOTE: ccache will not perform any cleanup of the Redis storage, but you can
1244 https://redis.io/topics/lru-cache[configure LRU eviction].
1245
1246 TIP: See https://ccache.dev/howto/redis-storage.html[How to set up Redis
1247 storage] for hints on setting up a Redis server for use with ccache.
1248
1249 TIP: You can set up a cluster of Redis servers using the `shards` attribute
1250 described in _<<Remote storage backends>>_.
1251
1252 Examples:
1253
1254 * `+redis://localhost+`
1255 * `+redis://p4ssw0rd@cache.example.com:6379/0|connect-timeout=50+`
1256 * `+redis+unix:/run/redis.sock+`
1257 * `+redis+unix:///run/redis.sock+`
1258 * `+redis+unix://p4ssw0rd@localhost/run/redis.sock?db=0+`
1259
1260 Optional attributes:
1261
1262 * *connect-timeout*: Timeout (in ms) for network connection. The default is 100.
1263 * *operation-timeout*: Timeout (in ms) for Redis commands. The default is 10000.
1264
1265
1266 == Cache size management
1267
1268 By default, ccache has a 5 GB limit on the total size of files in the cache and
1269 no limit on the number of files. You can set different limits using the command
1270 line options `-M`/`--max-size` and `-F`/`--max-files`. Use the
1271 `-s`/`--show-stats` option to see the cache size and the currently configured
1272 limits (in addition to other various statistics).
1273
1274 Cleanup can be triggered in two different ways: automatic and manual.
1275
1276
1277 === Automatic cleanup
1278
1279 After a new compilation result has been written to the local cache, ccache will
1280 trigger an automatic cleanup if <<config_max_size,*max_size*>> or
1281 <<config_max_files,*max_files*>> is exceeded. The cleanup removes cache entries
1282 in LRU (least recently used) order based on the modification time (mtime) of
1283 files in the cache. For this reason, ccache updates mtime of the cache files
1284 read on a cache hit to mark them as recently used.
1285
1286
1287 === Manual cleanup
1288
1289 You can run `ccache -c/--cleanup` to force cleanup of the whole cache. This will
1290 recalculate the cache size information and also make sure that the cache size
1291 does not exceed <<config_max_size,*max_size*>> and
1292 <<config_max_files,*max_files*>>.
1293
1294
1295 == Cache compression
1296
1297 Ccache will by default compress all data it puts into the cache using the
1298 compression algorithm http://zstd.net[Zstandard] (zstd) using compression level
1299 1. The algorithm is fast enough that there should be little reason to turn off
1300 compression to gain performance. One exception is if the cache is located on a
1301 compressed file system, in which case the compression performed by ccache of
1302 course is redundant. See the documentation for the configuration options
1303 <<config_compression,*compression*>> and
1304 <<config_compression_level,*compression_level*>> for more information.
1305
1306 You can use the command line option `-x`/`--show-compression` to print
1307 information related to compression. Example:
1308
1309 -------------------------------------------------------------------------------
1310 Total data: 14.8 GB (16.0 GB disk blocks)
1311 Compressed data: 11.3 GB (30.6% of original size)
1312 Original size: 36.9 GB
1313 Compression ratio: 3.267 x (69.4% space savings)
1314 Incompressible data: 3.5 GB
1315 -------------------------------------------------------------------------------
1316
1317 Notes:
1318
1319 * The "`disk blocks`" size is the cache size when taking disk block size into
1320 account. This value should match the "`Cache size`" value from "`ccache
1321 --show-stats`". The other size numbers refer to actual content sizes.
1322 * "`Compressed data`" refers to result and manifest files stored in the cache.
1323 * "`Incompressible data`" refers to files that are always stored uncompressed
1324 (triggered by enabling <<config_file_clone,*file_clone*>> or
1325 <<config_hard_link,*hard_link*>>) or unknown files (for instance files
1326 created by older ccache versions).
1327 * The compression ratio is affected by
1328 <<config_compression_level,*compression_level*>>.
1329
1330 The cache data can also be recompressed to another compression level (or made
1331 uncompressed) with the command line option `-X`/`--recompress`. If you choose to
1332 disable compression by default or to use a low compression level, you can
1333 (re)compress newly cached data with a higher compression level after the build
1334 or at another time when there are more CPU cycles available, for instance every
1335 night. Full recompression potentially takes a lot of time, but only files that
1336 are currently compressed with a different level than the target level will be
1337 recompressed.
1338
1339
1340 == Cache statistics
1341
1342 `ccache --show-stats` shows a summary of statistics, including cache size,
1343 cleanups (number of performed cleanups, either implicitly due to a cache size
1344 limit being reached or due to explicit `ccache -c` calls), overall hit rate, hit
1345 rate for <<The direct mode,direct>>/<<The preprocessor mode,preprocessed>> modes
1346 and hit rate for local and <<config_remote_storage,remote storage>>.
1347
1348 The summary also includes counters called "`Errors`" and "`Uncacheable`", which
1349 are sums of more detailed counters. To see those detailed counters, use the
1350 `-v`/`--verbose` flag. The verbose mode can show the following counters:
1351
1352 [options="header",cols="30%,70%"]
1353 |==============================================================================
1354 | *Counter* | *Description*
1355
1356 | Autoconf compile/link |
1357 Uncacheable compilation or linking by an Autoconf test.
1358
1359 | Bad compiler arguments |
1360 Malformed compiler argument, e.g. missing a value for a compiler option that
1361 requires an argument or failure to read a file specified by a compiler option
1362 argument.
1363
1364 | Called for linking |
1365 The compiler was called for linking, not compiling. Ccache only supports
1366 compilation of a single file, i.e. calling the compiler with the `-c` option to
1367 produce a single object file from a single source file.
1368
1369 | Called for preprocessing |
1370 The compiler was called for preprocessing, not compiling.
1371
1372 | Could not use modules |
1373 Preconditions for using <<C++ modules>> were not fulfilled.
1374
1375 | Could not use precompiled header |
1376 Preconditions for using <<Precompiled headers,precompiled headers>> were not
1377 fulfilled.
1378
1379 | Could not write to output file |
1380 The output path specified with `-o` could not be written to.
1381
1382 | Compilation failed |
1383 The compilation failed. No result stored in the cache.
1384
1385 | Compiler check failed |
1386 A compiler check program specified by
1387 <<config_compiler_check,*compiler_check*>> (*CCACHE_COMPILERCHECK*) failed.
1388
1389 | Compiler output file missing |
1390 One of the files expected to be produced by the compiler was missing after
1391 compilation.
1392
1393 | Compiler produced empty output |
1394 The compiler's output file (typically an object file) was empty after
1395 compilation.
1396
1397 | Could not find the compiler |
1398 The compiler to execute could not be found.
1399
1400 | Error hashing extra file |
1401 Failure reading a file specified by
1402 <<config_extra_files_to_hash,*extra_files_to_hash*>> (*CCACHE_EXTRAFILES*).
1403
1404 | Forced recache |
1405 <<config_recache,*CCACHE_RECACHE*>> was used to overwrite an existing result.
1406
1407 | Internal error |
1408 Unexpected failure, e.g. due to problems reading/writing the cache.
1409
1410 | Missing cache file |
1411 A file was unexpectedly missing from the cache. This only happens in rare
1412 situations, e.g. if one ccache instance is about to get a file from the cache
1413 while another instance removed the file as part of cache cleanup.
1414
1415 | Multiple source files |
1416 The compiler was called to compile multiple source files in one go. This is not
1417 supported by ccache.
1418
1419 | No input file |
1420 No input file was specified to the compiler.
1421
1422 | Output to stdout |
1423 The compiler was instructed to write its output to standard output using `-o -`.
1424 This is not supported by ccache.
1425
1426 | Preprocessing failed |
1427 Preprocessing the source code using the compiler's `-E` option failed.
1428
1429 | Unsupported code directive |
1430 Code like the assembler `.incbin` directive was found. This is not supported
1431 by ccache.
1432
1433 | Unsupported compiler option |
1434 A compiler option not supported by ccache was found.
1435
1436 | Unsupported environment variable |
1437 An environment variable not supported by ccache was set.
1438
1439 | Unsupported source language |
1440 A source language e.g. specified with `-x` was unsupported by ccache.
1441
1442 |==============================================================================
1443
1444
1445 == How ccache works
1446
1447 The basic idea is to detect when you are compiling exactly the same code a
1448 second time and reuse the previously produced output. The detection is done by
1449 hashing different kinds of information that should be unique for the
1450 compilation and then using the hash sum to identify the cached output. Ccache
1451 uses BLAKE3, a very fast cryptographic hash algorithm, for the hashing. On a
1452 cache hit, ccache is able to supply all of the correct compiler outputs
1453 (including all warnings, dependency file, etc) from the cache. Data stored in
1454 the cache is checksummed with XXH3, an extremely fast non-cryptographic
1455 algorithm, to detect corruption.
1456
1457 Ccache has two ways of gathering information used to look up results in the
1458 cache:
1459
1460 * the *preprocessor mode*, where ccache runs the preprocessor on the source
1461 code and hashes the result
1462 * the *direct mode*, where ccache hashes the source code and include files
1463 directly
1464
1465 The direct mode is generally faster since running the preprocessor has some
1466 overhead.
1467
1468 If no previous result is detected (i.e., there is a cache miss) using the direct
1469 mode, ccache will fall back to the preprocessor mode unless the *depend mode* is
1470 enabled. In the depend mode, ccache never runs the preprocessor, not even on
1471 cache misses. Read more in _<<The depend mode>>_ below.
1472
1473
1474 === Common hashed information
1475
1476 The following information is always included in the hash:
1477
1478 * the extension used by the compiler for a file with preprocessor output
1479 (normally `.i` for C code and `.ii` for C++ code)
1480 * the compiler's size and modification time (or other compiler-specific
1481 information specified by <<config_compiler_check,*compiler_check*>>)
1482 * the name of the compiler
1483 * the current directory (if <<config_hash_dir,*hash_dir*>> is enabled)
1484 * contents of files specified by
1485 <<config_extra_files_to_hash,*extra_files_to_hash*>> (if any)
1486
1487
1488 === The preprocessor mode
1489
1490 In the preprocessor mode, the hash is formed of the common information and:
1491
1492 * the preprocessor output from running the compiler with `-E`
1493 * the command line options except those that affect include files (`-I`,
1494 `-include`, `-D`, etc; the theory is that these command line options will
1495 change the preprocessor output if they have any effect at all)
1496 * any standard error output generated by the preprocessor
1497
1498 Based on the hash, the cached compilation result can be looked up directly in
1499 the cache.
1500
1501
1502 === The direct mode
1503
1504 In the direct mode, the hash is formed of the common information and:
1505
1506 * the input source file
1507 * the compiler options
1508
1509 Based on the hash, a data structure called "`manifest`" is looked up in the
1510 cache. The manifest contains:
1511
1512 * references to cached compilation results (object file, dependency file, etc)
1513 that were produced by previous compilations that matched the hash
1514 * paths to the include files that were read at the time the compilation results
1515 were stored in the cache
1516 * hash sums of the include files at the time the compilation results were
1517 stored in the cache
1518
1519 The current contents of the include files are then hashed and compared to the
1520 information in the manifest. If there is a match, ccache knows the result of
1521 the compilation. If there is no match, ccache falls back to running the
1522 preprocessor. The output from the preprocessor is parsed to find the include
1523 files that were read. The paths and hash sums of those include files are then
1524 stored in the manifest along with information about the produced compilation
1525 result.
1526
1527 There is a catch with the direct mode: header files that were used by the
1528 compiler are recorded, but header files that were *not* used, but would have
1529 been used if they existed, are not. So, when ccache checks if a result can be
1530 taken from the cache, it currently can't check if the existence of a new header
1531 file should invalidate the result. In practice, the direct mode is safe to use
1532 in the absolute majority of cases.
1533
1534 The direct mode will be disabled if any of the following holds:
1535
1536 * <<config_direct_mode,*direct_mode*>> is false
1537 * a modification time of one of the include files is too new (needed to avoid a
1538 race condition)
1539 * a compiler option not supported by the direct mode is used:
1540 ** a `-Wp,++*++` compiler option other than `-Wp,-MD,<path>`, `-Wp,-MMD,<path>`,
1541 `-Wp,-D<macro[=defn]>` or `-Wp,-U<macro>`
1542 ** `-Xpreprocessor`
1543 * the string `+__TIME__+` is present in the source code
1544
1545
1546 === The depend mode
1547
1548 If the depend mode is enabled, ccache will not use the preprocessor at all. The
1549 hash used to identify results in the cache will be based on the direct mode
1550 hash described above plus information about include files read from the
1551 dependency list generated by MSVC with `/showIncludes`, or the dependency file
1552 generated by other compilers with `-MD` or `-MMD`.
1553
1554 Advantages:
1555
1556 * The ccache overhead of a cache miss will be much smaller.
1557 * Not running the preprocessor at all can be good if compilation is performed
1558 remotely, for instance when using distcc or similar; ccache then won't make
1559 potentially costly preprocessor calls on the local machine.
1560
1561 Disadvantages:
1562
1563 * The cache hit rate will likely be lower since any change to compiler options
1564 or source code will make the hash different. Compare this with the default
1565 setup where ccache will fall back to the preprocessor mode, which is tolerant
1566 to some types of changes of compiler options and source code changes.
1567 * If `-MD` is used, the manifest entries will include system header files as
1568 well, thus slowing down cache hits slightly, just as using `-MD` slows down
1569 make. This is also the case for MSVC with `/showIncludes`.
1570 * If `-MMD` is used, the manifest entries will not include system header files,
1571 which means ccache will ignore changes in them.
1572
1573 The depend mode will be disabled if any of the following holds:
1574
1575 * <<config_depend_mode,*depend_mode*>> is false.
1576 * <<config_run_second_cpp,*run_second_cpp*>> is false.
1577 * The compiler is not generating dependencies using `-MD` or `-MMD` (for MSVC,
1578 `/showIncludes` is added automatically if not specified by the user).
1579
1580
1581 == Handling of newly created header files
1582
1583 If modification time (mtime) or status change time (ctime) of one of the include
1584 files is equal to (or newer than) the time compilation is being done, ccache
1585 disables the direct mode (or, in the case of a <<Precompiled headers,precompiled
1586 header>>, disables caching completely). This done as a safety measure to avoid a
1587 race condition (see below).
1588
1589 To be able to use a newly created header files in direct mode (or use a newly
1590 precompiled header), either:
1591
1592 * create the include file earlier in the build process, or
1593 * set <<config_sloppiness,*sloppiness*>> to
1594 *include_file_ctime,include_file_mtime* if you are willing to take the risk,
1595 for instance if you know that your build system is robust enough not to
1596 trigger the race condition.
1597
1598 For reference, the race condition mentioned above consists of these events:
1599
1600 1. The preprocessor is run.
1601 2. An include file is modified by someone.
1602 3. The new include file is hashed by ccache.
1603 4. The real compiler is run on the preprocessor's output, which contains data
1604 from the old header file.
1605 5. The wrong object file is stored in the cache.
1606
1607
1608 == Cache debugging
1609
1610 To find out what information ccache actually is hashing, you can enable the
1611 debug mode via the configuration option <<config_debug,*debug*>> or by setting
1612 `CCACHE_DEBUG` in the environment. This can be useful if you are investigating
1613 why you don't get cache hits. Note that performance will be reduced slightly.
1614
1615 When the debug mode is enabled, ccache will create up to five additional files
1616 next to the object file:
1617
1618 [options="header",cols="30%,70%"]
1619 |==============================================================================
1620 | *Filename* | *Description*
1621
1622 | `<objectfile>.<timestamp>.ccache-input-c` |
1623 Binary input hashed by both the direct mode and the preprocessor mode.
1624
1625 | `<objectfile>.<timestamp>.ccache-input-d` |
1626 Binary input only hashed by the direct mode.
1627
1628 | `<objectfile>.<timestamp>.ccache-input-p` |
1629 Binary input only hashed by the preprocessor mode.
1630
1631 | `<objectfile>.<timestamp>.ccache-input-text` |
1632 Human-readable combined diffable text version of the three files above.
1633
1634 | `<objectfile>.<timestamp>.ccache-log` |
1635 Log for this object file.
1636
1637 |==============================================================================
1638
1639 The timestamp format is
1640 `<year><month><day>_<hour><minute><second>_<microsecond>`.
1641
1642 If <<config_debug_dir,*debug_dir*>> (environment variable `CCACHE_DEBUGDIR`) is
1643 set, the files above will be written to that directory with full absolute paths
1644 instead of next to the object file.
1645
1646 In the direct mode, ccache uses the 160 bit BLAKE3 hash of the
1647 "`ccache-input-c`" + "`ccache-input-d`" data (where *+* means concatenation),
1648 while the "`ccache-input-c`" + "`ccache-input-p`" data is used in the
1649 preprocessor mode.
1650
1651 The "`ccache-input-text`" file is a combined text version of the three binary
1652 input files. It has three sections ("`COMMON`", "`DIRECT MODE`" and
1653 "`PREPROCESSOR MODE`"), which is turn contain annotations that say what kind of
1654 data comes next.
1655
1656 To debug why you don't get an expected cache hit for an object file, you can do
1657 something like this:
1658
1659 1. Enable `debug` (`CCACHE_DEBUG`).
1660 2. Build.
1661 3. Clean and build again.
1662 4. Compare the `<objectfile>.<timestamp>.ccache-input-text` files for the two
1663 builds. This together with the `<objectfile>.<timestamp>.ccache-log` files
1664 should give you some clues about what is happening.
1665
1666
1667 == Compiling in different directories
1668
1669 Some information included in the hash that identifies a unique compilation can
1670 contain absolute paths:
1671
1672 * The preprocessed source code may contain absolute paths to include files if
1673 the compiler option `-g` is used or if absolute paths are given to `-I` and
1674 similar compiler options.
1675 * Paths specified by compiler options (such as `-I`, `-MF`, etc) on the command
1676 line may be absolute.
1677 * The source code file path may be absolute, and that path may substituted for
1678 `+__FILE__+` macros in the source code or included in warnings emitted to
1679 standard error by the preprocessor.
1680
1681 This means that if you compile the same code in different locations, you can't
1682 share compilation results between the different build directories since you get
1683 cache misses because of the absolute build directory paths that are part of the
1684 hash.
1685
1686 Here's what can be done to enable cache hits between different build
1687 directories:
1688
1689 * If you build with `-g` (or similar) to add debug information to the object
1690 file, you must either:
1691 ** use the compiler option `-fdebug-prefix-map=<old>=<new>` for relocating
1692 debug info to a common prefix (e.g. `-fdebug-prefix-map=$PWD=.`); or
1693 ** set *hash_dir = false*.
1694 * If you use absolute paths anywhere on the command line (e.g. the source code
1695 file path or an argument to compiler options like `-I` and `-MF`), you must
1696 set <<config_base_dir,*base_dir*>> to an absolute path to a "`base
1697 directory`". Ccache will then rewrite absolute paths under that directory to
1698 relative before computing the hash.
1699
1700
1701 == Precompiled headers
1702
1703 Ccache has support for precompiled headers with GCC and Clang. However, you have
1704 to do some things to make it work properly:
1705
1706 * You must set <<config_sloppiness,*sloppiness*>> to *pch_defines,time_macros*.
1707 The reason is that ccache can't tell whether `+__TIME__+`, `+__DATE__+` or
1708 `+__TIMESTAMP__+` is used when using a precompiled header. Further, it can't
1709 detect changes in ``#define``s in the source code because of how preprocessing
1710 works in combination with precompiled headers.
1711 * You may also want to include *include_file_mtime,include_file_ctime* in
1712 <<config_sloppiness,*sloppiness*>>. See
1713 _<<Handling of newly created header files>>_.
1714 * You must either:
1715 +
1716 --
1717 * use the compiler option `-include` to include the precompiled header (i.e.,
1718 don't use `#include` in the source code to include the header; the filename
1719 itself must be sufficient to find the header, i.e. `-I` paths are not
1720 searched); or
1721 * (for the Clang compiler) use the compiler option `-include-pch` to include
1722 the PCH file generated from the precompiled header; or
1723 * (for the GCC compiler) add the compiler option `-fpch-preprocess` when
1724 compiling.
1725 --
1726 +
1727 * If you use Clang, you must compile with `-fno-pch-timestamp`.
1728
1729 If you don't do this, either the non-precompiled version of the header file will
1730 be used (if available) or ccache will fall back to running the real compiler and
1731 increase the statistics counter "`Preprocessing failed`" (if the non-precompiled
1732 header file is not available).
1733
1734
1735 == C++ modules
1736
1737 Ccache has support for Clang's `-fmodules` option. In practice ccache only
1738 additionally hashes `module.modulemap` files; it does not know how Clang
1739 handles its cached binary form of modules so those are ignored. This should not
1740 matter in practice: as long as everything else (including `module.modulemap`
1741 files) is the same the cached result should work. Still, you must set
1742 <<config_sloppiness,*sloppiness*>> to *modules* to allow caching.
1743
1744 You must use both <<The direct mode,*direct mode*>> and
1745 <<The depend mode,*depend mode*>>. When using
1746 <<The preprocessor mode,the preprocessor mode>> Clang does not provide enough
1747 information to allow hashing of `module.modulemap` files.
1748
1749
1750 == Sharing a local cache
1751
1752 A group of developers can increase the cache hit rate by sharing a local cache
1753 directory. To share a local cache without unpleasant side effects, the following
1754 conditions should to be met:
1755
1756 * Use the same cache directory.
1757 * Make sure that the configuration option <<config_hard_link,*hard_link*>> is
1758 false (which is the default).
1759 * Make sure that all users are in the same group.
1760 * Set the configuration option <<config_umask,*umask*>> to *002*. This ensures
1761 that cached files are accessible to everyone in the group.
1762 * Make sure that all users have write permission in the entire cache directory
1763 (and that you trust all users of the shared cache).
1764 * Make sure that the setgid bit is set on all directories in the cache. This
1765 tells the filesystem to inherit group ownership for new directories. The
1766 following command might be useful for this:
1767 +
1768 ----
1769 find $CCACHE_DIR -type d | xargs chmod g+s
1770 ----
1771
1772 The reason to avoid the hard link mode is that the hard links cause unwanted
1773 side effects, as all links to a cached file share the file's modification
1774 timestamp. This results in false dependencies to be triggered by
1775 timestamp-based build systems whenever another user links to an existing file.
1776 Typically, users will see that their libraries and binaries are relinked
1777 without reason.
1778
1779 You may also want to make sure that a base directory is set appropriately, as
1780 discussed in a previous section.
1781
1782
1783 == Sharing a cache on NFS
1784
1785 It is possible to put the cache directory on an NFS filesystem (or similar
1786 filesystems), but keep in mind that:
1787
1788 * Having the cache on NFS may slow down compilation. Make sure to do some
1789 benchmarking to see if it's worth it.
1790 * Ccache hasn't been tested very thoroughly on NFS.
1791
1792 A tip is to set <<config_temporary_dir,*temporary_dir*>> to a directory on the
1793 local host to avoid NFS traffic for temporary files.
1794
1795 It is recommended to use the same operating system version when using a shared
1796 cache. If operating system versions are different then system include files
1797 will likely be different and there will be few or no cache hits between the
1798 systems. One way of improving cache hit rate in that case is to set
1799 <<config_sloppiness,*sloppiness*>> to *system_headers* to ignore system
1800 headers.
1801
1802 An alternative to putting the main cache directory on NFS is to set up a
1803 <<config_remote_storage,remote storage>> file cache.
1804
1805
1806 == Using ccache with other compiler wrappers
1807
1808 The recommended way of combining ccache with another compiler wrapper (such as
1809 "`distcc`") is by letting ccache execute the compiler wrapper. This is
1810 accomplished by defining <<config_prefix_command,*prefix_command*>>, for
1811 example by setting the environment variable `CCACHE_PREFIX` to the name of the
1812 wrapper (e.g. `distcc`). Ccache will then prefix the command line with the
1813 specified command when running the compiler. To specify several prefix
1814 commands, set <<config_prefix_command,*prefix_command*>> to a colon-separated
1815 list of commands.
1816
1817 Unless you set <<config_compiler_check,*compiler_check*>> to a suitable command
1818 (see the description of that configuration option), it is not recommended to use
1819 the form `ccache anotherwrapper compiler args` as the compilation command. It's
1820 also not recommended to use the masquerading technique for the other compiler
1821 wrapper. The reason is that by default, ccache will in both cases hash the mtime
1822 and size of the other wrapper instead of the real compiler, which means that:
1823
1824 * Compiler upgrades will not be detected properly.
1825 * The cached results will not be shared between compilations with and without
1826 the other wrapper.
1827
1828 Another minor thing is that if <<config_prefix_command,*prefix_command*>> is
1829 used, ccache will not invoke the other wrapper when running the preprocessor,
1830 which increases performance. You can use
1831 <<config_prefix_command_cpp,*prefix_command_cpp*>> if you also want to invoke
1832 the other wrapper when doing preprocessing (normally by adding `-E`).
1833
1834
1835 == Caveats
1836
1837 * The direct mode fails to pick up new header files in some rare scenarios. See
1838 _<<The direct mode>>_ above.
1839
1840
1841 == Troubleshooting
1842
1843 === General
1844
1845 A general tip for getting information about what ccache is doing is to enable
1846 debug logging by setting the configuration option <<config_debug,*debug*>> (or
1847 the environment variable *CCACHE_DEBUG*); see _<<Cache debugging>>_
1848 for more information. Another way of keeping track of what is
1849 happening is to check the output of *ccache -s*.
1850
1851
1852 === Performance
1853
1854 Ccache has been written to perform well out of the box, but sometimes you may
1855 have to do some adjustments of how you use the compiler and ccache in order to
1856 improve performance.
1857
1858 Since ccache works best when I/O is fast, put the cache directory on a fast
1859 storage device if possible. Having lots of free memory so that files in the
1860 cache directory stay in the disk cache is also preferable.
1861
1862 A good way of monitoring how well ccache works is to run `ccache -s` before and
1863 after your build and then compare the statistics counters. Here are some common
1864 problems and what may be done to increase the hit rate:
1865
1866 * If the counter for preprocessed cache hits has been incremented instead of the
1867 one for direct cache hits, ccache has fallen back to preprocessor mode, which
1868 is generally slower. Some possible reasons are:
1869 ** The source code has been modified in such a way that the preprocessor output
1870 is not affected.
1871 ** Compiler arguments that are hashed in the direct mode but not in the
1872 preprocessor mode have changed (`-I`, `-include`, `-D`, etc) and they didn't
1873 affect the preprocessor output.
1874 ** The compiler option `-Xpreprocessor` or `-Wp,++*++` (except `-Wp,-MD,<path>`,
1875 `-Wp,-MMD,<path>`, and `-Wp,-D<define>`) is used.
1876 ** This was the first compilation with a new value of the
1877 <<config_base_dir,base directory>>.
1878 ** A modification or status change time of one of the include files is too new
1879 (created the same second as the compilation is being done). See
1880 _<<Handling of newly created header files>>_.
1881 ** The `+__TIME__+` preprocessor macro is (potentially) being used. Ccache turns
1882 off direct mode if `+__TIME__+` is present in the source code. This is done
1883 as a safety measure since the string indicates that a `+__TIME__+` macro
1884 _may_ affect the output. (To be sure, ccache would have to run the
1885 preprocessor, but the sole point of the direct mode is to avoid that.) If you
1886 know that `+__TIME__+` isn't used in practise, or don't care if ccache
1887 produces objects where `+__TIME__+` is expanded to something in the past, you
1888 can set <<config_sloppiness,*sloppiness*>> to *time_macros*.
1889 ** The `+__DATE__+` preprocessor macro is (potentially) being used and the date
1890 has changed. This is similar to how `+__TIME__+` is handled. If `+__DATE__+`
1891 is present in the source code, ccache hashes the current date in order to be
1892 able to produce the correct object file if the `+__DATE__+` macro affects the
1893 output. If you know that `+__DATE__+` isn't used in practise, or don't care
1894 if ccache produces objects where `+__DATE__+` is expanded to something in the
1895 past, you can set <<config_sloppiness,*sloppiness*>> to *time_macros*.
1896 ** The `+__TIMESTAMP__+` preprocessor macro is (potentially) being used and the
1897 source file's modification time has changed. This is similar to how
1898 `+__TIME__+` is handled. If `+__TIMESTAMP__+` is present in the source code,
1899 ccache hashes the string representation of the source file's modification
1900 time in order to be able to produce the correct object file if the
1901 `+__TIMESTAMP__+` macro affects the output. If you know that
1902 `+__TIMESTAMP__+` isn't used in practise, or don't care if ccache produces
1903 objects where `+__TIMESTAMP__+` is expanded to something in the past, you can
1904 set <<config_sloppiness,*sloppiness*>> to *time_macros*.
1905 ** The input file path has changed. Ccache includes the input file path in the
1906 direct mode hash to be able to take relative include files into account and
1907 to produce a correct object file if the source code includes a `+__FILE__+`
1908 macro.
1909 * If a cache hit counter was not incremented even though the same code has been
1910 compiled and cached before, ccache has either detected that something has
1911 changed anyway or a cleanup has been performed (either explicitly or
1912 implicitly when a cache limit has been reached). Some perhaps unobvious things
1913 that may result in a cache miss are usage of `+__TIME__+`, `+__DATE__+` or
1914 `+__TIMESTAMP__+` macros, or use of automatically generated code that contains
1915 a timestamp, build counter or other volatile information.
1916 * If "`Multiple source files`" has been incremented, it's an indication that the
1917 compiler has been invoked on several source code files at once. Ccache doesn't
1918 support that. Compile the source code files separately if possible.
1919 * If "`Unsupported compiler option`" has been incremented, enable debug logging
1920 and check which compiler option was rejected.
1921 * If "`Preprocessing failed`" has been incremented, one possible reason is that
1922 precompiled headers are being used. See _<<Precompiled headers>>_ for how to
1923 remedy this.
1924 * If "`Could not use precompiled header`" has been incremented, see
1925 _<<Precompiled headers>>_.
1926 * If "`Could not use modules`" has been incremented, see _<<C++ modules>>_.
1927
1928
1929 === Corrupt object files
1930
1931 It should be noted that ccache is susceptible to general storage problems. If a
1932 bad object file sneaks into the cache for some reason, it will of course stay
1933 bad. Some possible reasons for erroneous object files are bad hardware (disk
1934 drive, disk controller, memory, etc), buggy drivers or file systems, a bad
1935 <<config_prefix_command,*prefix_command*>> or compiler wrapper. If this
1936 happens, the easiest way of fixing it is this:
1937
1938 1. Build so that the bad object file ends up in the build tree.
1939 2. Remove the bad object file from the build tree.
1940 3. Rebuild with `CCACHE_RECACHE` set.
1941
1942 An alternative is to clear the whole cache with `ccache -C` if you don't mind
1943 losing other cached results.
1944
1945 There are no reported issues about ccache producing broken object files
1946 reproducibly. That doesn't mean it can't happen, so if you find a repeatable
1947 case, please report it.
1948
1949
1950 == More information
1951
1952 Credits, mailing list information, bug reporting instructions, source code,
1953 etc, can be found on ccache's web site: <https://ccache.dev>.
1954
1955
1956 == Author
1957
1958 Ccache was originally written by Andrew Tridgell and is currently developed and
1959 maintained by Joel Rosdahl. See AUTHORS.txt or AUTHORS.html and
1960 <https://ccache.dev/credits.html> for a list of contributors.