Sccache

0.14.0 · active · verified Mon Apr 13

Sccache (Shared Compilation Cache) is a ccache-like tool written in Rust that acts as a compiler wrapper to accelerate build times by caching compilation results. It supports C/C++, Rust, and CUDA, and can utilize various local and cloud storage backends like S3, Google Cloud Storage, Redis, and Memcached. The PyPI package for sccache (version 0.14.0) primarily provides access to this binary tool for Python environments. It is actively maintained by Mozilla and a community of contributors, with regular releases providing new features and bug fixes.

Warnings

Install

Quickstart

Sccache is primarily used as a command-line wrapper for compilers, configuring your build system to use `sccache` as the compiler executable or wrapper. The PyPI package installs the `sccache` binary. This example demonstrates how to invoke `sccache` via Python's `subprocess` module to wrap a Rust build, showing the typical `RUSTC_WRAPPER` environment variable usage. For C/C++ builds, you would typically set `CC='sccache gcc'` or `CXX='sccache g++'`.

import os
import subprocess

# Ensure sccache is in PATH or set SCCACHE env var if installed elsewhere
# For simplicity, assuming 'sccache' is callable from PATH after 'pip install sccache'

# Start the sccache server in the background (optional, but recommended for efficiency)
# The server automatically stops after 10 minutes of inactivity by default.
subprocess.run(['sccache', '--start-server'])

# Example usage: Compile a Rust project with sccache
# This environment variable tells Cargo/rustc to use sccache as a wrapper
env = os.environ.copy()
env['RUSTC_WRAPPER'] = 'sccache'

print('Building Rust project with sccache...')
try:
    # Simulate a Rust build command
    subprocess.run(['cargo', 'build', '--release'], env=env, check=True)
    print('First build (warming cache) completed.')

    # Run again to demonstrate caching effect
    subprocess.run(['cargo', 'clean'], check=True)
    print('Cache cleaned, running second build...')
    subprocess.run(['cargo', 'build', '--release'], env=env, check=True)
    print('Second build (should be faster due to cache) completed.')

    # Show sccache statistics
    subprocess.run(['sccache', '--show-stats'], check=True)

finally:
    # Stop the sccache server
    subprocess.run(['sccache', '--stop-server'])
    print('Sccache server stopped.')

view raw JSON →