andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 1 | # Using CCache on Mac |
| 2 | |
David Sanders | e7cc34c | 2022-02-11 00:13:23 | [diff] [blame] | 3 | [ccache](https://ccache.dev/) is a compiler cache. It speeds up |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 4 | recompilation of C/C++ code by caching previous compilations and detecting when |
| 5 | the same compilation is being done again. This often results in a significant |
| 6 | speedup in common compilations, especially when switching between branches. This |
David Sanders | e7cc34c | 2022-02-11 00:13:23 | [diff] [blame] | 7 | page is about using ccache on Mac with clang and the Ninja build system. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 8 | |
| 9 | [TOC] |
| 10 | |
| 11 | ## Installation |
| 12 | |
David Sanders | e7cc34c | 2022-02-11 00:13:23 | [diff] [blame] | 13 | To install ccache with [Homebrew](https://brew.sh/), run `brew install ccache`. |
| 14 | With [MacPorts](https://macports.org/), run `port install ccache`. You can also |
| 15 | download and install yourself, using the |
| 16 | [instructions in |
| 17 | the repository](https://github.com/ccache/ccache/blob/master/doc/INSTALL.md). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 18 | |
| 19 | Make sure ccache can be found in your `$PATH`. |
| 20 | |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 21 | ## Use with GN |
| 22 | |
David Sanders | e7cc34c | 2022-02-11 00:13:23 | [diff] [blame] | 23 | You just need to set the `cc_wrapper` GN variable. You can do so by running |
| 24 | `gn args out/Default` and adding |
| 25 | `cc_wrapper="env CCACHE_SLOPPINESS=time_macros ccache"` to the build arguments. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 26 | |
| 27 | ## Build |
| 28 | |
David Sanders | e7cc34c | 2022-02-11 00:13:23 | [diff] [blame] | 29 | After setting the `cc_wrapper` GN variable you can just run ninja as normal: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 30 | |
| 31 | ```shell |
David Sanders | e7cc34c | 2022-02-11 00:13:23 | [diff] [blame] | 32 | ninja -C out/Default chrome |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 33 | ``` |
| 34 | |
| 35 | ## Optional Steps |
| 36 | |
| 37 | * Configure ccache to use a different cache size with `ccache -M <max size>`. |
David Sanders | e7cc34c | 2022-02-11 00:13:23 | [diff] [blame] | 38 | You can see a list of configuration options by calling `ccache` alone. |