Search code examples
npmgypccache

Can I get npm / gyp to use ccache?


ccache is a fantastic way to speed up building C binaries which you have already built previously, by caching the results. (Another great tool is distcc, which will pass code to other machines for parallel compilation!)

Can I get npm to use ccache when it build C files using gyp?

Here is a way to test:

$ time npm install mmmagic
...
npm install mmmagic  103.83s user 9.06s system 100% cpu 1:51.84 total

$ rm -rf node_modules/mmmagic

$ time npm install mmmagic
...
npm install mmmagic  103.48s user 8.59s system 102% cpu 1:48.87 total

If we can use ccache, it should be significantly faster on the second attempt.

Another way to see if ccache is being called, and if it is helping, is to run this in a separate terminal while a build is underway:

$ watch -d ccache -s

This will display a live update of ccache's statistics.


Solution

  • You should be able to do this by setting your environment variables correctly. For a C compiler: export CC="ccache gcc" (or export CC="ccache clang") should work fine.