Speeding up builds using a compiler cache - ccache

Technical questions regarding the XTC tools and programming with XMOS.
andyn_ff
Newbie
Posts: 1
Joined: Fri Sep 19, 2025 9:54 am

Speeding up builds using a compiler cache - ccache

Post by andyn_ff »

Hi,
I am working on speeding up our builds using XTC 15.3.1 on Ubuntu. We are using the xcommon build system with xmake, haven't looked at moving the project to CMake yet.

ccache works by intercepting calls to the compiler and cacheing the outcome, so that if it receives identical calls with identical sources it doesn't need to call the compiler at all after the first time. To use ccache, I have added a symlink (to ccache) to the PATH masquerading as `xcc`, and ccache will then find the real xcc later in the PATH. This is a normal way to use ccache according to the docs: https://ccache.dev/manual/latest.html#_run_modes (although previously I have only used as a compiler 'prefix' launcher using CMake).

I've got ccache working, I think, but unfortunately it looks like all the calls to `xcc` are not something ccache considers cacheable. The reasons are given in the ccache stats, a full dump is below. 'Called for linking' is fair enough and I can't expect to do much about that. However, 'Multiple source files' seems a shame - it looks like this is unsupported by ccache, but I haven't hit this stumbling block when using ccache with other compilers.

Does anyone have any experience to share using a cache with the XMOS build system, or any insight from docs I haven't spotted yet?

I'm still looking into this, but my guess from inspecting the Makefiles in XTC_TOOL_PATH/build/xcommon/module_xcommon/build is that the .xn file is always being passed to xcc as well as the source itself, and ccache is detecting this as an additional C source file rather than a compiler option. If I'm right about this, my workaround might be, instead of symlinking xcc to ccache directly, to symlink xcc to a ccache wrapper script that inserts `--cache-skip` before any .xn file detected in the command, and add the .xn file to ccache's `extra_files_to_hash` list so that the cache will still be invalidated if the content of the xn file is changed. Since my solution is starting to get a bit complicated, I want to check if there's any prior art for this or if I'm missing something.

ccache stats on first compilation (nothing currently in the cache):

Code: Select all

ccache --show-stats --verbose --verbose
Cache directory:                          /var/cache/ccache
Config file:                              /var/cache/ccache/ccache.conf
System config file:                       /etc/ccache.conf
Stats updated:                            Fri Sep 19 08:42:30 2025
Stats zeroed:                             never
Cacheable calls:                            0 / 694 ( 0.00%)
  Hits:                                     0
    Direct:                                 0
    Preprocessed:                           0
  Misses:                                   0
Uncacheable calls:                        694 / 694 (100.0%)
  Autoconf compile/link:                    0 / 694 ( 0.00%)
  Bad compiler arguments:                   0 / 694 ( 0.00%)
  Called for linking:                     463 / 694 (66.71%)
  Called for preprocessing:                 0 / 694 ( 0.00%)
  Ccache disabled:                          0 / 694 ( 0.00%)
  Compilation failed:                       0 / 694 ( 0.00%)
  Compiler output file missing:             0 / 694 ( 0.00%)
  Compiler produced empty output:           0 / 694 ( 0.00%)
  Compiler produced stdout:                 0 / 694 ( 0.00%)
  Could not use modules:                    0 / 694 ( 0.00%)
  Could not use precompiled header:         0 / 694 ( 0.00%)
  Forced recache:                           0 / 694 ( 0.00%)
  Multiple source files:                  231 / 694 (33.29%)
  No input file:                            0 / 694 ( 0.00%)
  Output to stdout:                         0 / 694 ( 0.00%)
  Preprocessing failed:                     0 / 694 ( 0.00%)
  Unsupported code directive:               0 / 694 ( 0.00%)
  Unsupported compiler option:              0 / 694 ( 0.00%)
  Unsupported environment variable:         0 / 694 ( 0.00%)
  Unsupported source language:              0 / 694 ( 0.00%)