Skip to content

ci: R2-backed cache-cargo-home action for cargo download caches#3624

Open
sxlijin wants to merge 2 commits into
canaryfrom
sam/cache-cargo-home
Open

ci: R2-backed cache-cargo-home action for cargo download caches#3624
sxlijin wants to merge 2 commits into
canaryfrom
sam/cache-cargo-home

Conversation

@sxlijin

@sxlijin sxlijin commented May 31, 2026

Copy link
Copy Markdown
Contributor

Stacked on #3612 (sccache). Merge #3612 first.

Adds .github/actions/cache-cargo-home, a node20 action that reads baml_language/Cargo.lock and restores ~/.cargo/{registry/cache,registry/index,git/db} from R2 at job start, then uploads anything newly fetched at job end — replacing Swatinem/rust-cache for the cargo download caches (sccache still owns target/).

  • Granular & Cargo.lock-driven: one R2 object per crate (crates/<index>/<name>-<ver>.crate), per sparse-index entry (registry-index/<index>/<sharded-name>), and per git db (git-db/<ident>-<hash>.tar). The cache is shared across jobs and tolerant to Cargo.lock changes (each lockfile reads the subset it needs).
  • R2 access is hand-rolled SigV4 (no AWS SDK in the committed bundle); large git dbs upload via presigned S3 multipart and restore streams to disk.
  • Restoring the sparse-index entries + config.json lets cargo resolve offline, skipping the online "Updating crates.io index" pass.

The action is fully unit-tested (incl. live R2 round-trips) and validated across linux/macOS/Windows.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c34561d1-f805-4b57-a39b-d8fd2b2b02e2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sam/cache-cargo-home

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vercel

vercel Bot commented May 31, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview, Comment Jun 2, 2026 3:37am
promptfiddle Ready Ready Preview, Comment Jun 2, 2026 3:37am
promptfiddle2 Ready Ready Preview, Comment Jun 2, 2026 3:37am

Request Review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4c40bcfb59

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

try {
if (!(await fileExists(src))) return; // build didn't end up fetching it.
const key = crateObjectKey(CRATES_IO_INDEX, c.crateFile);
if (await store.has(key)) return; // another job already uploaded it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Repair corrupt crate objects instead of skipping existing keys

When restore marks a crate missed because the cached bytes failed the Cargo.lock checksum, the post step reaches this path after Cargo has downloaded the correct .crate. Since the R2 key is only name-version, store.has(key) is still true for the corrupt object, so this return leaves the bad cache entry in place and every future job will redownload the crate after the same checksum mismatch; keying by checksum or overwriting objects for checksum-mismatch misses would let the cache self-heal.

Useful? React with 👍 / 👎.

@github-actions

github-actions Bot commented May 31, 2026

Copy link
Copy Markdown

No description provided.

@codspeed-hq

codspeed-hq Bot commented May 31, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 13 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing sam/cache-cargo-home (8300850) with sam/sccache-ci (cd40db1)2

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on sam/sccache-ci (8b10020) during the generation of this report, so 0a57ff6 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@sxlijin sxlijin force-pushed the sam/cache-cargo-home branch from 4c40bcf to 8300850 Compare June 2, 2026 01:51
@sxlijin sxlijin force-pushed the sam/cache-cargo-home branch from 8300850 to 0998d85 Compare June 2, 2026 02:24
@sxlijin sxlijin force-pushed the sam/cache-cargo-home branch from 0998d85 to a7871ab Compare June 2, 2026 02:40
@sxlijin sxlijin force-pushed the sam/cache-cargo-home branch from a7871ab to ef692dc Compare June 2, 2026 02:42
@sxlijin sxlijin force-pushed the sam/cache-cargo-home branch from ef692dc to 29377f8 Compare June 2, 2026 02:50
sxlijin and others added 2 commits June 1, 2026 20:18
Route RUSTC_WRAPPER through a baml-sccache wrapper (tools/baml-sccache on POSIX, the native tools_sccache crate on Windows) backed by R2, configured entirely from .envrc so CI matches local shells. mise installs sccache + direnv; each cargo job loads .envrc via `direnv export gha`.

Swatinem/rust-cache still caches the cargo registry/git download state, with cache-targets: false so sccache owns target/ and the two caches don't compete.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add .github/actions/cache-cargo-home, a node20 action that reads baml_language/Cargo.lock and restores ~/.cargo/{registry/cache,registry/index,git/db} from R2 at job start, then uploads anything newly fetched at job end — replacing Swatinem/rust-cache for the download caches (sccache still owns target/).

Granular and Cargo.lock-driven: one object per crate, per sparse-index entry, and per git db, so the cache is shared across jobs and tolerant to Cargo.lock changes. R2 access is hand-rolled SigV4 (no AWS SDK); large git dbs upload via presigned S3 multipart.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@sxlijin sxlijin force-pushed the sam/cache-cargo-home branch from 29377f8 to 5d6de7c Compare June 2, 2026 03:18
Base automatically changed from sam/sccache-ci to canary June 2, 2026 04:37
pull Bot pushed a commit to justinlietz93/baml that referenced this pull request Jun 2, 2026
Use sccache (R2-backed) for Rust **compilation** artifacts in the cargo
CI jobs, configured entirely from `.envrc` so CI matches local shells.

- `tools_sccache` crate / `tools/baml-sccache` wrapper: a
`RUSTC_WRAPPER` that maps `BAML_SCCACHE_R2_*` → `AWS_*` and execs
sccache (native crate on Windows, shell script on POSIX).
- mise installs sccache + direnv; each cargo job loads `.envrc` via
`direnv export gha` (the single source of truth for the sccache/R2
config).
- **Swatinem/rust-cache still caches the cargo registry/git download
state**, with `cache-targets: false` so sccache owns `target/` and the
two caches don't compete. Fork PRs without R2 secrets fall back to the
runner-local cache.

Follow-up BoundaryML#3624 replaces Swatinem for the download caches with a
granular, Cargo.lock-driven R2 action (`cache-cargo-home`); this PR is
the sccache base it stacks on.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant