Skip to content

Instantly share code, notes, and snippets.

@jjgod
Last active October 31, 2023 06:57
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save jjgod/4966579 to your computer and use it in GitHub Desktop.
Save jjgod/4966579 to your computer and use it in GitHub Desktop.
Using ccache for Mac builds

Introduction

ccache is a compiler cache. It speeds up recompilation of C/C++ code by caching previous compilations and detecting when the same compilation is being done again. This often results in a significant speedup in common compilations, especially when switching between branches. This page is about using ccache on Mac with clang and ninja build system. If you want to use Xcode, please refer to the old CCacheMac page.

In order to use ccache with clang, you need to use the current git HEAD, since the most recent version (3.1.9) doesn't contain the patch needed for using chromium style plugin.

Installation

To install ccache with homebrew, use the following command:

brew install --HEAD ccache

You can also download and install yourself (with GNU automake, autoconf and libtool installed):

git clone git://git.samba.org/ccache.git
cd ccache
./autogen.sh
./configure && make && make install

Make sure ccache can be found in your $PATH.

You can also just use the current released version of ccache (3.1.8 or 3.1.9) and disable chromium style plugin with clang_use_chrome_plugins=0 in your GYP_DEFINES.

Use with Gyp/gclient

We have to set two environment variables (CC and CXX) before calling gclient runhooks or build/gyp_chromium, given you are currently in chromium/src directory:

export CC="ccache clang -Qunused-arguments"
export CXX="ccache clang++ -Qunused-arguments"

Then run:

GYP_GENERATORS="ninja" ./build/gyp_chromium

or

GYP_GENERATORS="ninja" gclient runhooks

(Instead of relying on the clang/clang++ for building chromium in your $PATH, you can also use the absolute path here.)

Build

In build phase, the following environment variables must be set (assuming you are in chromium/src):

export CCACHE_CPP2=yes
export CCACHE_SLOPPINESS=time_macros
export PATH=`pwd`/third_party/llvm-build/Release+Asserts/bin:$PATH

Then you can just run ninja as normal:

ninja -C out/Release chrome

Optional Steps

  • Configure ccache to use a different cache size with ccache -M <max size>. You can see a list of configuration options by calling ccache alone.
  • The default ccache directory is ~/.ccache. You might want to symlink it to another directory (for example, when using FileVault for your home directory).
@leeight
Copy link

leeight commented Oct 9, 2013

It looks like not work on my MBP :-(

@mandliya
Copy link

mandliya commented Jun 6, 2015

Is this fixed, I am getting "make: *** No rule to make target -lz', needed byccache'. Stop."

@thinktapper
Copy link

I'm also getting "No rule to make target -lz', needed byccache'" on my MBP 8,2 with Yosemite 10.10.5

@wolfhechel
Copy link

That's because the Make implementation bundled with XCode Command Line Tools doesn't understand the
-lz kind of dependencies, installing gnu-make from brew and compile it with gmake instead.

@thefourtheye
Copy link

I am getting

==> Cloning https://github.com/jrosdahl/ccache.git
Updating /Library/Caches/Homebrew/ccache--git
==> Checking out branch master
==> ./autogen.sh
==> ./configure --prefix=/usr/local/Cellar/ccache/HEAD --mandir=/usr/local/Cellar/ccache/HEAD/share/man --with-bundled-zlib
==> make
==> make install
Last 15 lines from /Users/.../Library/Logs/Homebrew/ccache/04.make:
2016-04-20 11:27:33 +0530

make
install

asciidoc -a revnumber=unknown -d manpage -b docbook MANUAL.txt
make: asciidoc: No such file or directory
make: *** [MANUAL.xml] Error 1

READ THIS: https://git.io/brew-troubleshooting
If reporting this issue please do so at (not Homebrew/brew):
  https://github.com/Homebrew/homebrew-core/issues

@purepure
Copy link

I am getting this issue as @thefourtheye too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment