Install Sccache on Raspberry Pi

Install Sccache on Raspberry Pi

Sccache is a command line utility designed to accelerate the recompilation process by caching previously compiled objects. It supports languages such as C, C++, Rust, and more. By storing the results of previous compilations and reusing them when identical inputs are encountered, Sccache dramatically reduces the time required for subsequent builds. Functionally, Sccache is comparable to the Ccache tool.

This tutorial shows how to install Sccache on Raspberry Pi.

Install Sccache

Retrieve the latest release version of Sccache from its official GitHub repository and assign it to variable:

SCCACHE_VERSION=$(curl -s "https://api.github.com/repos/mozilla/sccache/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+')

Download Sccache using previously identified version:

wget -qO sccache.tar.gz https://github.com/mozilla/sccache/releases/latest/download/sccache-v$SCCACHE_VERSION-aarch64-unknown-linux-musl.tar.gz

Create a temporary directory and extract the contents of the tar.gz file into it:

mkdir sccache-temp
tar xf sccache.tar.gz --strip-components=1 -C sccache-temp

Move the sccache executable to the /usr/local/bin directory:

sudo mv sccache-temp/sccache /usr/local/bin

Set execute permission:

sudo chmod a+x /usr/local/bin/sccache

Check the Sccache version by running the following command:

sccache --version

Lastly, remove the temporary directory and the downloaded file:

rm -rf sccache.tar.gz sccache-temp

Testing Sccache

To use Sccache, simply prefix the compilation command with sccache.

For demonstration purposes, create a main.cpp file:

nano main.cpp

Add the following lines of code:

#include <iostream>

int main() {
    std::cout << "Hello world" << std::endl;

    return 0;
}

Compile the code by prefixing the command with sccache as shown:

sccache g++ main.cpp -o test

Uninstall Sccache

To uninstall Sccache, just delete its executable file:

sudo rm -rf /usr/local/bin/sccache

Leave a Comment

Cancel reply

Your email address will not be published.