kache README

The project's README from github.com/kunobi-ninja/kache. As one markdown file: README.md.

CI Bench Crates.io Documentation Product page

Kache

Kache is a compiler cache for Rust, C/C++, and CUDA. It keys every compiler invocation by the content of its inputs, so a crate built once is restored instead of rebuilt in your next worktree, branch, or CI run. Outputs live in a local content-addressed store and can be shared through S3-compatible or filesystem remotes. Linux, macOS, and Windows are supported and release-tested.

Built by Kunobi.

Benchmarks · Kache vs sccache · CI setup

Diagram of four Firefox worktrees sharing cached build outputs through reflinks.

See how Kache shares build outputs across worktrees →

Install

cargo install kache
kache init

That's it. Your Cargo commands do not change.

kache init sets rustc-wrapper in Cargo's config. On Unix it also adds the [env] keys for build-script C and C++. Run kache init --check to preview the changes, or kache init --no-service to skip the OS service.

kache init previewing its changes, applying them, and kache doctor passing every check.

cargo install needs Rust 1.95 or newer. Prebuilt packages exist for Homebrew, APT, AUR, winget, Scoop, Chocolatey, mise, and Nix; release builds cover x86_64 and ARM on all three platforms. See Install Kache for each channel.

See your first cache hit

After kache init, build the same revision in two temporary worktrees. Each gets its own target directory, so your existing build outputs stay in place. The second tree's report lists the hits, and a bypass reason for every unit that still compiled.

A second worktree of the same commit building from cache hits, then the build report showing 42 of 42 crates cached.

How it works

Kache has three parts: a compiler wrapper, a local store, and an optional daemon.

Hits, misses, and passthroughs are reported per unit, and kache why-miss explains what changed. Read the architecture →

What Kache caches

Workload Status Notes
Rust libraries and build scripts Supported Run kache init
Rust executables Supported on Linux and macOS Disabled by default on Windows
C and C++ object files Supported GCC, Clang, Apple Clang, and clang-cl. Build scripts via kache init; other builds via shims or CC/CXX
CUDA object files Supported Single-source nvcc -c and -dc via CUDACXX="kache nvcc" or a CMake launcher
Local storage Built in Content-addressed store with garbage collection
S3-compatible remote storage Built in Includes AWS S3, MinIO, and Cloudflare R2
Filesystem remote storage Built in Useful for shared disks and CI volumes

Bytes a second Firefox worktree adds to disk on APFS: about 3 GB for Kache, which reflinks the other 13.5 GB, against 16.7 GB for sccache, which writes an independent copy.

In a Firefox 151 benchmark with Kache 0.7.0 on macOS/APFS, the second worktree added about 3 GB of new data. Read the measurements and methodology →

Need to choose between compiler caches? Read Kache or sccache?.

Tested nightly on real projects

The scheduled benchmark workflow runs real cold/warm builds of Firefox, LLVM, Substrate, SurrealDB, Lance, OpenDAL, cuda-oxide, and eza on Linux, compares Firefox with sccache, and exercises Firefox on Windows. It also measures how much of a Firefox build survives a source update.

Each run checks its own measurement validity and uploads reports, traces, and logs for 30 days. Treat timing or hit-rate numbers as evidence only when the individual job succeeds and its benchmark verdict is ok.

See the benchmark setup and report guide →

CI

The official action installs Kache and wires it into the build:

- uses: kunobi-ninja/kache-action@v1

- run: cargo build --locked

See the CI guide for GitHub Actions and shell-based CI examples.

C and C++

On Unix, install compiler-name shims and put that directory first in PATH. Make, CMake, autotools, and Arch PKGBUILDs that call gcc by name then go through Kache. No CC= edit and no shell wrapper.

kache install-shims
export PATH="$HOME/.local/lib/kache/shims:$PATH"

APT and AUR packages install /usr/lib/kache. Nix packages include the same symlinks in ${kache}/shims and ${kache}/lib/kache; see the Nix configuration example.

kache init can create the user farm; it does not change PATH. For makepkg, put the same assignment in ~/.makepkg.conf. Wrap extra names already on PATH with kache install-shims --from-path.

Kache inspects the real compiler invocation. Unsupported or unsafe invocations pass through. See C and C++.

Storage and remotes

The default local cache is:

Open the configuration editor with kache config, or edit the TOML file directly. A minimal S3-compatible remote looks like this:

[cache.remote]
type = "s3"
bucket = "my-build-cache"
region = "us-east-1"

Credentials come from the standard AWS environment variables or credential chain. See S3 setup and filesystem setup.

Useful commands

kache monitor                 # live build and cache activity
kache stats                   # non-interactive summary
kache report --last-build     # hits, misses, and bypass reasons of the latest build
kache doctor                  # setup and integrity checks
kache install-shims           # Unix compiler-name PATH farm
kache why-miss <crate>        # explain the latest miss
kache list                    # inspect cached entries
kache gc                      # enforce cache limits
kache sync                    # pull from and push to the configured remote
kache daemon status           # inspect the background service

kache monitor following a build, then the Why, Projects, and Store tabs.

Run kache help <command> for exact flags. The command reference covers every top-level command.

To pass one build through without changing the setup, run it with KACHE_DISABLED=1.

Documentation

Also from Kunobi

For Kubernetes and GitOps, Kunobi Desktop lets you inspect clusters and manage Flux and Argo CD.

Questions and gaps

Development

git clone https://github.com/kunobi-ninja/kache.git
cd kache
cargo test --workspace --all-features

See CONTRIBUTING.md before opening a pull request.

Kache is licensed under the Apache License 2.0.

kache (kunobi-ninja/kache)

Searching Database…

1.2K ·GitHub
这是什么?Kache 是一个面向 Rust、C/C++ 和 CUDA 的编译缓存工具。它根据输入内容为每次构建生成键,因此编译过一次的代码,在下一次使用不同工作树、分支或 CI 运行时会被直接恢复,而不用重新编译。
为什么它自称零拷贝?构建产物存放在本地一个按内容寻址的存储库里,相同的字节只保存一份。在文件系统支持的情况下,恢复时使用写时复制克隆,这正是第二个工作树几乎不占额外磁盘空间的原因。
怎么让它配合 Cargo 使用?运行 kache init 即可:它会在 Cargo 的配置里设置 rustc-wrapper,在 Unix 上还会为构建脚本的 C 和 C++ 添加 [env] 配置项。你的 cargo 命令完全不变,而且可以先用 kache init --check 预览将要做的修改。
怎么安装?需要先装 Rust 工具链吗?预构建软件包覆盖 x86_64 和 ARM 架构,支持 Homebrew、APT、AUR、winget、Scoop、Chocolatey、mise 和 Nix。只有 cargo install 需要 Rust 1.95 或更新版本。
它到底缓存什么?哪些功能不是所有平台都支持?Rust 库和构建脚本在所有平台都支持,但 Rust 可执行文件只支持 Linux 和 macOS——在 Windows 上默认禁用。CUDA 支持覆盖单文件的 nvcc -c 和 -dc 调用,遇到不支持或不安全的编译器调用时会直接放行,不做缓存。
第二个工作树实际会占多少磁盘空间?在一项 Firefox 151 基准测试中(Kache 0.7.0,macOS/APFS),第二个工作树只新增了大约 3 GB 数据,而不是把整个构建目录复制一份。
多个构建同时需要同一个产物时会怎样?到达相同键的并发构建会合并到同一次执行中,所以无论有多少个 Cargo 进程同时请求,编译器在同一台机器上对每个键只运行一次。
它在真实项目上测过吗,还是只有玩具示例?一个定期运行的基准测试工作流会在 Linux 上对 Firefox、LLVM、Substrate、SurrealDB、Lance、OpenDAL、cuda-oxide 和 eza 进行冷构建和热构建,另外还会在 Windows 上构建 Firefox。每次运行都会校验自身测量的有效性,并上传报告、追踪记录和日志,保留 30 天。
Size
23.9 MB
Stars
1.2K
Age
8mo
Commits · 90 Days