pages tagged ccacheFeeding the Cloudhttps://feeding.cloud.geek.nz/tags/ccache/Feeding the Cloudikiwiki2021-06-11T20:43:57ZSeeding sccache for Faster Brave Browser Buildshttps://feeding.cloud.geek.nz/posts/seeding-brave-browser-sccache/
<a href="https://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>
2021-06-11T20:43:57Z2019-03-22T23:25:00Z
<p><a href="https://github.com/brave/brave-browser/wiki#build-brave">Compiling the
Brave Browser</a>
(based on <a href="https://www.chromium.org/Home">Chromium</a>) on Linux can take a
really long time and so most developers use
<a href="https://github.com/brave/brave-browser/wiki/sccache-for-faster-builds">sccache</a>
to cache objects files and speed up future re-compilations.</p>
<p>Here's the cronjob I wrote to seed my local cache every work day to
pre-compile the latest builds:</p>
<pre><code>30 23 * * 0-4 francois /usr/bin/chronic /home/francois/bin/seed-brave-browser-cache
</code></pre>
<p>and here are the contents of that script:</p>
<pre><code>#!/bin/bash
set -e
# Set the path and sccache environment variables correctly
source ${HOME}/.bashrc-brave
export LANG=en_CA.UTF-8
cd ${HOME}/devel/brave-browser-cache
echo "Environment:"
echo "- HOME = ${HOME}"
echo "- PATH = ${PATH}"
echo "- PWD = ${PWD}"
echo "- SHELL = ${SHELL}"
echo "- BASH_ENV = ${BASH_ENV}"
echo
echo $(date)
echo "=> Clean up repo and delete old build output"
rm -rf src/out node_modules src/brave/node_modules
git clean -f -d
git checkout HEAD package-lock.json
find -name "*.pyc" -delete
echo $(date)
echo "=> Update repo"
git fetch --prune origin
git pull
npm install
rm -rf src/brave/*
git -C src/third_party/devtools-frontend/src/ reset --hard
gclient sync -D
git -C src/brave pull
git -C src/brave reset --hard
npm run init
echo $(date)
echo "=> Debug build"
killall sccache || true
ionice nice timeout --foreground 4h npm run build || ionice nice timeout 4h npm run build
ionice nice ninja -C src/out/Component brave_unit_tests
ionice nice ninja -C src/out/Component brave_browser_tests
echo
echo $(date)
echo "=> Release build"
killall sccache || true
ionice nice timeout --foreground 5h npm run build Release || ionice nice timeout 5h npm run build Release
ionice nice ninja -C src/out/Release brave_unit_tests
ionice nice ninja -C src/out/Release brave_browser_tests
echo
echo $(date)
echo "=> Delete build output"
rm -rf src/out
</code></pre>
<p>It references a <code>~/.bashrc-brave</code> file which contains:</p>
<pre><code>#!/bin/sh
export PATH="${PATH}:${HOME}/bin:${HOME}/devel/brave-browser/vendor/depot_tools:${HOME}/.cargo/bin"
export SCCACHE_DIR="${HOME}/.cache/sccache"
export SCCACHE_CACHE_SIZE=200G
export NO_AUTH_BOTO_CONFIG="${HOME}/.boto"
</code></pre>
<h2 id="ccache_instead_of_sccache">ccache instead of sccache</h2>
<p>While I started using sccache for compiling Brave, I recently switched to
<a href="https://ccache.dev">ccache</a> as sccache turned out to be fairly
<a href="https://github.com/brave/brave-browser/wiki/sccache-for-faster-builds#troubleshooting-the-install">unreliable</a>
at compiling Chromium.</p>
<p>Switching to <code>ccache</code> is easy, simply install the package:</p>
<pre><code>apt install ccache
</code></pre>
<p>and then set the <a href="https://github.com/brave/brave-browser/wiki/sccache-for-faster-builds#setting-the-environment-variable">environment
variable</a>
in <code>.npmrc</code>:</p>
<pre><code>sccache = ccache
</code></pre>
<p>Finally, you'll probably want to increase the maximum cache size:</p>
<pre><code>ccache --max-size=200G
</code></pre>
<p>in order to fit all of Chromium/Brave in the cache.</p>