Skip to content

chore: use sccache for cargo tests#3612

Merged
sxlijin merged 1 commit into
canaryfrom
sam/sccache-ci
Jun 2, 2026
Merged

chore: use sccache for cargo tests#3612
sxlijin merged 1 commit into
canaryfrom
sam/sccache-ci

Conversation

@sxlijin

@sxlijin sxlijin commented May 29, 2026

Copy link
Copy Markdown
Contributor

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 #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

@vercel

vercel Bot commented May 29, 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 Building Building Preview, Comment Jun 2, 2026 3:37am

Request Review

@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Replaces GitHub Actions rust-cache with sccache (optional R2/S3 backend), adds sccache exports to .envrc, pins direnv/sccache in mise.toml, refactors setup-mise to selective installs, extends the reusable workflow to accept optional R2 credentials, and updates all Rust CI jobs to install/load sccache, restart its server, persist env, and show stats.

Changes

sccache with R2 backend caching

Layer / File(s) Summary
Tool pinning and sccache exports
mise.toml, .envrc
Pins direnv and sccache in mise.toml. Adds a shared sccache export block in .envrc exporting RUSTC_WRAPPER, SCCACHE_BUCKET, SCCACHE_REGION, SCCACHE_ENDPOINT, SCCACHE_S3_KEY_PREFIX, SCCACHE_IDLE_TIMEOUT, and SCCACHE_ERROR_LOG with ${VAR:-default} fallbacks; updates non-nix bootstrap to conditionally add brew LLVM to PATH only outside CI and adjusts mise activation messaging/behavior.
Platform-specific socket export
.envrc
SCCACHE_SERVER_UDS=${repo_root}/.baml-sccache.sock is now exported only on non-Windows-like platforms using uname pattern matching.
Selective mise install action
.github/actions/setup-mise/action.yml
Refactors the composite action to disable automatic tool installs and run mise install conditionally: install only install_args when provided, otherwise install all pinned tools. Updates install_args input documentation to clarify space-separated tool names.
Workflow interface and R2 credential handling
.github/workflows/cargo-tests.reusable.yaml
Adds optional BAML_SCCACHE_R2_ACCESS_KEY_ID and BAML_SCCACHE_R2_SECRET_ACCESS_KEY to workflow_call.secrets, documents sccache-first cache strategy, and sets workflow-level defaults (RUSTC_WRAPPER, SCCACHE_S3_KEY_PREFIX).
CI job migration from rust-cache to sccache
.github/workflows/cargo-tests.reusable.yaml
Across cargo-test-*, sdk-tests, cargo-build-msrv, cargo-doc, snapshot-tests: installs sccache/direnv via setup-mise, runs a shared “Load .envrc” step that conditionally maps/unsets R2/AWS creds, restarts the sccache server, and persists sccache env vars to GITHUB_ENV; sets Swatinem/rust-cache with cache-targets: false; and adds sccache --show-stats steps guarded by if: always(). cargo-test-wasm also ensures the wasm32-unknown-unknown target.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

  • BoundaryML/baml#3553: Related changes to .github/actions/setup-mise/action.yml and mise install flow / tool pinning.
  • BoundaryML/baml#3609: Overlapping edits to .envrc socket/worktree sccache wiring.
  • BoundaryML/baml#3603: Adds the baml-sccache wrapper that maps R2 secrets to AWS env vars consumed by CI sccache setup.

Poem

🐰 I nibble on configs late at night,

I pin the tools and set the flags just right,
CI hums and sccache springs to life,
R2 stores the crumbs — builds hop light,
A cheerful hop across the CI light.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'chore: use sccache for cargo tests' accurately describes the main objective of the changeset, which is to integrate sccache for Rust compilation caching across cargo test workflows and local development environments.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sam/sccache-ci

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.

@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: d8e9e359dd

ℹ️ 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".

Comment on lines +48 to +49
echo "AWS_ACCESS_KEY_ID=${BAML_SCCACHE_R2_ACCESS_KEY_ID}"
echo "AWS_SECRET_ACCESS_KEY=${BAML_SCCACHE_R2_SECRET_ACCESS_KEY}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid exporting R2 credentials to PR-controlled cargo steps

In ci.yaml, pull_request runs invoke this reusable workflow with secrets: inherit before running PR-controlled cargo build/test code. Writing AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to $GITHUB_ENV makes those long-lived R2 credentials available to every later cargo build script and test in the job, so a same-repo PR can exfiltrate them or write arbitrary cache entries. Gate the remote cache setup to trusted refs/events, or avoid placing the secrets in the job environment used by cargo code.

Useful? React with 👍 / 👎.

Comment thread .envrc Outdated
# Shared sccache configuration. Keep credential values out of the repo:
# put BAML_SCCACHE_R2_ACCESS_KEY_ID and BAML_SCCACHE_R2_SECRET_ACCESS_KEY
# in $HOME/.envrc.baml for local shells, or in GitHub Actions secrets for CI.
export RUSTC_WRAPPER="${RUSTC_WRAPPER:-baml-sccache}"

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 Gate local RUSTC_WRAPPER on sccache availability

When direnv is loaded on a machine that has not separately installed sccache (it is not provisioned by the repo's mise.toml or flake.nix), this default makes every local cargo invocation execute tools/baml-sccache; that wrapper ends with exec sccache, so cargo fails before invoking rustc instead of building normally. Only set RUSTC_WRAPPER when sccache exists, provision it in the dev environment, or leave it opt-in for local shells.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.envrc:
- Around line 12-18: The .envrc currently exports SCCACHE_* R2/S3 vars
unconditionally and tools/baml-sccache only sets
AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY when BAML_SCCACHE_R2_* are present, so
local builds can try to use remote storage without credentials; update
tools/baml-sccache to detect the absence of BAML_SCCACHE_R2_* (or missing AWS
creds) and either set SCCACHE_S3_NO_CREDENTIALS=true or unset/override
SCCACHE_BUCKET, SCCACHE_ENDPOINT and SCCACHE_S3_KEY_PREFIX before exec sccache
"$@", and also ensure AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY are unset when
switching to no-creds mode; reference the BAML_SCCACHE_R2_* vars, the
SCCACHE_S3_NO_CREDENTIALS env var, and the script tools/baml-sccache when making
the change.

In @.github/actions/setup-sccache/action.yml:
- Around line 42-50: The step is leaking R2 credentials by appending
AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to $GITHUB_ENV; remove the two lines
that echo AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY so only SCCACHE_BUCKET,
SCCACHE_REGION, SCCACHE_ENDPOINT and SCCACHE_S3_KEY_PREFIX are written to
GITHUB_ENV. Locate the conditional that checks BAML_SCCACHE_R2_ACCESS_KEY_ID and
BAML_SCCACHE_R2_SECRET_ACCESS_KEY and delete the two echo lines for
AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY (keep the other echo lines intact);
if needed, ensure the sccache daemon is started with those credentials in a
restricted environment rather than exporting them to GITHUB_ENV.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 927ba0ea-2f9c-4fea-8250-7ff6df010eb9

📥 Commits

Reviewing files that changed from the base of the PR and between 54f6897 and d8e9e35.

📒 Files selected for processing (3)
  • .envrc
  • .github/actions/setup-sccache/action.yml
  • .github/workflows/cargo-tests.reusable.yaml

Comment thread .envrc Outdated
Comment on lines +42 to +50
if [[ -n "${BAML_SCCACHE_R2_ACCESS_KEY_ID}" && -n "${BAML_SCCACHE_R2_SECRET_ACCESS_KEY}" ]]; then
{
echo "SCCACHE_BUCKET=baml-build1"
echo "SCCACHE_REGION=auto"
echo "SCCACHE_ENDPOINT=https://321ca319116f1e5eefa9135d9d019a5a.r2.cloudflarestorage.com"
echo "SCCACHE_S3_KEY_PREFIX=${SCCACHE_S3_KEY_PREFIX}"
echo "AWS_ACCESS_KEY_ID=${BAML_SCCACHE_R2_ACCESS_KEY_ID}"
echo "AWS_SECRET_ACCESS_KEY=${BAML_SCCACHE_R2_SECRET_ACCESS_KEY}"
} >> "$GITHUB_ENV"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Does sccache read AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY at server start, so the client process running cargo does not need them when an authenticated server is already running?

💡 Result:

Yes, sccache reads environment variables like AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY at server start [1]. Because sccache operates on a client-server architecture, the server process maintains the cache connection state [2][3]. When you run a cargo build, the client (your cargo process) sends the command to the already-running server daemon [2][1]. Since the server is the component responsible for performing the S3 operations and maintaining the authentication state, it must have access to the credentials when it starts [1]. Consequently, once the server is successfully running with the necessary credentials, the client process itself does not need these environment variables to be set in its own environment [2][3]. If you restart the server, however, it will need to be able to resolve the credentials again (e.g., from the environment, shared config files, or IAM instance metadata) to initialize the S3 connection [4][5]. Note that environment variables are only read at the time the server process is launched; they are not dynamically re-read from the client's environment during subsequent requests [1].

Citations:


Stop exporting R2 AWS_* credentials to GITHUB_ENV

sccache reads AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY from its environment when the server daemon starts; once that daemon is running, later cargo invocations are just clients and don’t need AWS_* set themselves. Appending the R2 keys to $GITHUB_ENV unnecessarily exposes them to all subsequent steps (including PR-controlled build/test), creating a credential leak and cache-poisoning risk. Remove the two echo AWS_* lines.

🔒️ Keep R2 keys out of the shared job environment
           {
             echo "SCCACHE_BUCKET=baml-build1"
             echo "SCCACHE_REGION=auto"
             echo "SCCACHE_ENDPOINT=https://321ca319116f1e5eefa9135d9d019a5a.r2.cloudflarestorage.com"
             echo "SCCACHE_S3_KEY_PREFIX=${SCCACHE_S3_KEY_PREFIX}"
-            echo "AWS_ACCESS_KEY_ID=${BAML_SCCACHE_R2_ACCESS_KEY_ID}"
-            echo "AWS_SECRET_ACCESS_KEY=${BAML_SCCACHE_R2_SECRET_ACCESS_KEY}"
           } >> "$GITHUB_ENV"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [[ -n "${BAML_SCCACHE_R2_ACCESS_KEY_ID}" && -n "${BAML_SCCACHE_R2_SECRET_ACCESS_KEY}" ]]; then
{
echo "SCCACHE_BUCKET=baml-build1"
echo "SCCACHE_REGION=auto"
echo "SCCACHE_ENDPOINT=https://321ca319116f1e5eefa9135d9d019a5a.r2.cloudflarestorage.com"
echo "SCCACHE_S3_KEY_PREFIX=${SCCACHE_S3_KEY_PREFIX}"
echo "AWS_ACCESS_KEY_ID=${BAML_SCCACHE_R2_ACCESS_KEY_ID}"
echo "AWS_SECRET_ACCESS_KEY=${BAML_SCCACHE_R2_SECRET_ACCESS_KEY}"
} >> "$GITHUB_ENV"
if [[ -n "${BAML_SCCACHE_R2_ACCESS_KEY_ID}" && -n "${BAML_SCCACHE_R2_SECRET_ACCESS_KEY}" ]]; then
{
echo "SCCACHE_BUCKET=baml-build1"
echo "SCCACHE_REGION=auto"
echo "SCCACHE_ENDPOINT=https://321ca319116f1e5eefa9135d9d019a5a.r2.cloudflarestorage.com"
echo "SCCACHE_S3_KEY_PREFIX=${SCCACHE_S3_KEY_PREFIX}"
} >> "$GITHUB_ENV"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/actions/setup-sccache/action.yml around lines 42 - 50, The step is
leaking R2 credentials by appending AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
to $GITHUB_ENV; remove the two lines that echo AWS_ACCESS_KEY_ID and
AWS_SECRET_ACCESS_KEY so only SCCACHE_BUCKET, SCCACHE_REGION, SCCACHE_ENDPOINT
and SCCACHE_S3_KEY_PREFIX are written to GITHUB_ENV. Locate the conditional that
checks BAML_SCCACHE_R2_ACCESS_KEY_ID and BAML_SCCACHE_R2_SECRET_ACCESS_KEY and
delete the two echo lines for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY (keep
the other echo lines intact); if needed, ensure the sccache daemon is started
with those credentials in a restricted environment rather than exporting them to
GITHUB_ENV.

@github-actions

github-actions Bot commented May 29, 2026

Copy link
Copy Markdown

Binary size checks passed

7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
baml-cli Linux 🔒 20.0 MB 8.3 MB file 19.4 MB +563.1 KB (+2.9%) OK
packed-program Linux 🔒 15.0 MB 6.3 MB file 14.7 MB +324.9 KB (+2.2%) OK
baml-cli macOS 🔒 15.1 MB 7.2 MB file 15.1 MB +16 B (+0.0%) OK
packed-program macOS 🔒 11.4 MB 5.5 MB file 11.2 MB +264.9 KB (+2.4%) OK
baml-cli Windows 🔒 16.3 MB 7.4 MB file 16.3 MB +1.0 KB (+0.0%) OK
packed-program Windows 🔒 12.1 MB 5.6 MB file 11.9 MB +297.3 KB (+2.5%) OK
bridge_wasm WASM 13.4 MB 🔒 3.9 MB gzip 3.8 MB +2.0 KB (+0.1%) OK

🔒 = the size this artifact is GATED on (ceiling + delta). Binaries gate on file size (installed binary); WASM gates on gzip (download size). The other size is shown for information only.


Generated by cargo size-gate · workflow run

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
.github/workflows/cargo-tests.reusable.yaml (1)

58-88: 🏗️ Heavy lift

Consider extracting sccache setup to a composite action.

This ~25-line shell script is duplicated verbatim across 8 jobs (linux, macos, windows, sdk-tests, wasm, msrv, cargo-doc, snapshot-tests). Any bug fix or enhancement would require updating all 8 locations.

Consider extracting this into a local composite action (e.g., .github/actions/setup-sccache) that encapsulates the direnv loading, credential handling, server startup, and GITHUB_ENV persistence. The action could accept the two R2 secrets as inputs.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/cargo-tests.reusable.yaml around lines 58 - 88, The
sccache setup block (step named "Load .envrc") is duplicated across multiple
jobs; extract it into a reusable local composite action (e.g.,
.github/actions/setup-sccache) that accepts inputs for
BAML_SCCACHE_R2_ACCESS_KEY_ID and BAML_SCCACHE_R2_SECRET_ACCESS_KEY and
encapsulates the direnv loading, export/eval of RUSTC_WRAPPER/SCCACHE_ERROR_LOG,
the AWS credential conditional, sccache --stop-server / --start-server, and the
loop that writes variables to GITHUB_ENV; replace the inline script with a uses:
./.github/actions/setup-sccache step that maps the two secrets to inputs and
preserves the same exported variables (SCCACHE_*, AWS_ACCESS_KEY_ID/SECRET,
RUSTC_WRAPPER, and SCCACHE_ERROR_LOG) so behavior with variables like
SCCACHE_BUCKET, SCCACHE_BASEDIRS and RUNNER_TEMP remains identical.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.envrc:
- Around line 27-29: The PATH_add call is brittle because it assumes "brew
--prefix llvm" succeeds; guard it by first checking that Homebrew reports llvm
is installed (or that brew --prefix llvm returns a valid directory) before
calling PATH_add. Update the .envrc snippet around the PATH_add invocation so
that after confirming command -v brew and CI checks, you verify llvm exists
(e.g., via brew ls/ls --versions or by capturing brew --prefix llvm and testing
the resulting directory) and only then call PATH_add with the llvm bin path;
reference the PATH_add invocation and the brew --prefix llvm call to locate the
change.

---

Nitpick comments:
In @.github/workflows/cargo-tests.reusable.yaml:
- Around line 58-88: The sccache setup block (step named "Load .envrc") is
duplicated across multiple jobs; extract it into a reusable local composite
action (e.g., .github/actions/setup-sccache) that accepts inputs for
BAML_SCCACHE_R2_ACCESS_KEY_ID and BAML_SCCACHE_R2_SECRET_ACCESS_KEY and
encapsulates the direnv loading, export/eval of RUSTC_WRAPPER/SCCACHE_ERROR_LOG,
the AWS credential conditional, sccache --stop-server / --start-server, and the
loop that writes variables to GITHUB_ENV; replace the inline script with a uses:
./.github/actions/setup-sccache step that maps the two secrets to inputs and
preserves the same exported variables (SCCACHE_*, AWS_ACCESS_KEY_ID/SECRET,
RUSTC_WRAPPER, and SCCACHE_ERROR_LOG) so behavior with variables like
SCCACHE_BUCKET, SCCACHE_BASEDIRS and RUNNER_TEMP remains identical.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 287d85e2-2952-4fb3-9b40-44380bfbfc97

📥 Commits

Reviewing files that changed from the base of the PR and between d8e9e35 and e91e59b.

📒 Files selected for processing (3)
  • .envrc
  • .github/workflows/cargo-tests.reusable.yaml
  • mise.toml
✅ Files skipped from review due to trivial changes (1)
  • mise.toml

Comment thread .envrc
Comment on lines +27 to +29
if [ "${CI:-}" != "true" ] && command -v brew >/dev/null 2>&1; then
PATH_add "$(brew --prefix llvm)/bin"
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Guard brew --prefix llvm before PATH_add to avoid brittle direnv loads.

If Homebrew exists but llvm isn’t installed, brew --prefix llvm can fail and make local shell init noisy/fragile. Add a lightweight existence check first.

Proposed patch
-    if [ "${CI:-}" != "true" ] && command -v brew >/dev/null 2>&1; then
-        PATH_add "$(brew --prefix llvm)/bin"
+    if [ "${CI:-}" != "true" ] && command -v brew >/dev/null 2>&1; then
+        if brew --prefix llvm >/dev/null 2>&1; then
+            PATH_add "$(brew --prefix llvm)/bin"
+        fi
     fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [ "${CI:-}" != "true" ] && command -v brew >/dev/null 2>&1; then
PATH_add "$(brew --prefix llvm)/bin"
fi
if [ "${CI:-}" != "true" ] && command -v brew >/dev/null 2>&1; then
if brew --prefix llvm >/dev/null 2>&1; then
PATH_add "$(brew --prefix llvm)/bin"
fi
fi
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.envrc around lines 27 - 29, The PATH_add call is brittle because it assumes
"brew --prefix llvm" succeeds; guard it by first checking that Homebrew reports
llvm is installed (or that brew --prefix llvm returns a valid directory) before
calling PATH_add. Update the .envrc snippet around the PATH_add invocation so
that after confirming command -v brew and CI checks, you verify llvm exists
(e.g., via brew ls/ls --versions or by capturing brew --prefix llvm and testing
the resulting directory) and only then call PATH_add with the llvm bin path;
reference the PATH_add invocation and the brew --prefix llvm call to locate the
change.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
.github/workflows/cargo-tests.reusable.yaml (1)

70-100: ⚖️ Poor tradeoff

Consider extracting the repeated "Load .envrc" block into a composite action.

This ~30-line script is duplicated verbatim across 8 jobs (cargo-test-linux, cargo-test-macos, cargo-test-windows, sdk-tests, cargo-test-wasm, cargo-build-msrv, cargo-doc, snapshot-tests). Any future bug fix or enhancement would require updating all 8 copies, risking drift.

A composite action at .github/actions/load-sccache-env/action.yml could encapsulate this logic and accept the R2 secrets as inputs, reducing maintenance burden and ensuring consistency.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/cargo-tests.reusable.yaml around lines 70 - 100, Extract
the repeated "Load .envrc" step into a reusable composite action (e.g.,
.github/actions/load-sccache-env/action.yml) that accepts inputs for
BAML_SCCACHE_R2_ACCESS_KEY_ID and BAML_SCCACHE_R2_SECRET_ACCESS_KEY and exposes
outputs or writes to GITHUB_ENV; move the logic that sets RUSTC_WRAPPER,
SCCACHE_ERROR_LOG (using RUNNER_TEMP), conditionally exports/unsets
AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY and other SCCACHE_* vars, runs sccache
--stop-server && sccache --start-server, and appends the selected env vars to
GITHUB_ENV into the composite action; then replace each "Load .envrc" job step
with a single uses: ./.github/actions/load-sccache-env and pass the two secrets
via with:, ensuring the composite action mirrors behavior for the loop that
writes variables into GITHUB_ENV and preserves SCCACHE_ERROR_LOG and RUNNER_TEMP
usage.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In @.github/workflows/cargo-tests.reusable.yaml:
- Around line 70-100: Extract the repeated "Load .envrc" step into a reusable
composite action (e.g., .github/actions/load-sccache-env/action.yml) that
accepts inputs for BAML_SCCACHE_R2_ACCESS_KEY_ID and
BAML_SCCACHE_R2_SECRET_ACCESS_KEY and exposes outputs or writes to GITHUB_ENV;
move the logic that sets RUSTC_WRAPPER, SCCACHE_ERROR_LOG (using RUNNER_TEMP),
conditionally exports/unsets AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY and other
SCCACHE_* vars, runs sccache --stop-server && sccache --start-server, and
appends the selected env vars to GITHUB_ENV into the composite action; then
replace each "Load .envrc" job step with a single uses:
./.github/actions/load-sccache-env and pass the two secrets via with:, ensuring
the composite action mirrors behavior for the loop that writes variables into
GITHUB_ENV and preserves SCCACHE_ERROR_LOG and RUNNER_TEMP usage.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f0f62ab2-1ccf-4790-9489-ba75b5351f7a

📥 Commits

Reviewing files that changed from the base of the PR and between e91e59b and 739ea16.

📒 Files selected for processing (3)
  • .envrc
  • .github/workflows/cargo-tests.reusable.yaml
  • mise.toml
🚧 Files skipped from review as they are similar to previous changes (2)
  • mise.toml
  • .envrc

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
.github/workflows/cargo-tests.reusable.yaml (1)

70-100: ⚖️ Poor tradeoff

Consider extracting the "Load .envrc" block into a reusable composite action.

The ~30-line shell script for loading .envrc, mapping R2 secrets, restarting sccache, and persisting env vars is duplicated verbatim across 8 jobs. Extracting it into a dedicated composite action (e.g., .github/actions/setup-sccache) would reduce maintenance burden and risk of drift when updating the logic.

This is a good-to-have improvement that can be deferred if the explicit inline approach is preferred for CI debuggability.

Also applies to: 169-199, 261-291, 378-408, 477-507, 577-607, 657-687, 737-767

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/cargo-tests.reusable.yaml around lines 70 - 100, The "Load
.envrc" job block is duplicated across many jobs; extract that ~30-line shell
snippet into a reusable composite GitHub Action (e.g.,
.github/actions/setup-sccache) that exposes inputs for the secret names and any
toggles and encapsulates the steps: run direnv allow/eval, export RUSTC_WRAPPER
and SCCACHE_ERROR_LOG, conditionally map
BAML_SCCACHE_R2_ACCESS_KEY_ID/BAML_SCCACHE_R2_SECRET_ACCESS_KEY to
AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY, restart sccache, and persist the
environment variables (the same list used in the for loop) to GITHUB_ENV; then
replace each inline "Load .envrc" step with a uses: call to the new action
passing the required secrets/inputs.
.github/actions/setup-mise/action.yml (1)

52-60: 💤 Low value

Remove unused install_args from mise-action invocation.

Since install: false (line 55), the install_args parameter on line 60 is not used by jdx/mise-action. The actual install is now delegated to the explicit mise install steps below. This parameter can be removed to avoid confusion.

🧹 Proposed cleanup
     - name: Install mise
       uses: jdx/[email protected]
       with:
         install: false
         # Our own prefix (not the upstream default), shared across every
         # baml_language workflow. Bump the trailing number to invalidate
         # every consumer's cache at once.
         cache_key_prefix: mise-baml1
-        install_args: ${{ inputs.install_args }}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/actions/setup-mise/action.yml around lines 52 - 60, Remove the
unused install_args input from the jdx/mise-action invocation: since the action
is called with install: false (in the step using jdx/[email protected]) the
install_args parameter is ignored and only causes confusion, so delete the
install_args: ${{ inputs.install_args }} line from that action step and keep the
explicit subsequent mise install steps as the source of truth.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In @.github/actions/setup-mise/action.yml:
- Around line 52-60: Remove the unused install_args input from the
jdx/mise-action invocation: since the action is called with install: false (in
the step using jdx/[email protected]) the install_args parameter is ignored and
only causes confusion, so delete the install_args: ${{ inputs.install_args }}
line from that action step and keep the explicit subsequent mise install steps
as the source of truth.

In @.github/workflows/cargo-tests.reusable.yaml:
- Around line 70-100: The "Load .envrc" job block is duplicated across many
jobs; extract that ~30-line shell snippet into a reusable composite GitHub
Action (e.g., .github/actions/setup-sccache) that exposes inputs for the secret
names and any toggles and encapsulates the steps: run direnv allow/eval, export
RUSTC_WRAPPER and SCCACHE_ERROR_LOG, conditionally map
BAML_SCCACHE_R2_ACCESS_KEY_ID/BAML_SCCACHE_R2_SECRET_ACCESS_KEY to
AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY, restart sccache, and persist the
environment variables (the same list used in the for loop) to GITHUB_ENV; then
replace each inline "Load .envrc" step with a uses: call to the new action
passing the required secrets/inputs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c63447b5-ad36-4dbc-b1e6-53bf4b2791f5

📥 Commits

Reviewing files that changed from the base of the PR and between 739ea16 and 207b915.

📒 Files selected for processing (4)
  • .envrc
  • .github/actions/setup-mise/action.yml
  • .github/workflows/cargo-tests.reusable.yaml
  • mise.toml
✅ Files skipped from review due to trivial changes (1)
  • mise.toml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .envrc

coderabbitai[bot]
coderabbitai Bot previously requested changes May 29, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
.github/workflows/cargo-tests.reusable.yaml (2)

65-71: ⚖️ Poor tradeoff

Static analysis flags unpinned action reference.

Swatinem/rust-cache@v2 uses a version tag rather than a commit hash. For enhanced supply-chain security, consider pinning to a specific commit hash. This applies to all 8 usages in this file.

Example pinning
-- uses: Swatinem/rust-cache@v2
+# Pinned from v2.x.x (update hash when upgrading)
+- uses: Swatinem/rust-cache@<commit-sha>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/cargo-tests.reusable.yaml around lines 65 - 71, The
workflow uses the unpinned action reference Swatinem/rust-cache@v2 which should
be replaced with a specific commit SHA for supply-chain security; locate every
usage of the identifier Swatinem/rust-cache@v2 in the file (all 8 occurrences)
and update each to Swatinem/rust-cache@<commit-sha> using the exact git commit
hash for the version you vetted, ensuring the same pinned SHA is applied
consistently and updating any accompanying comments or save-if/shared-key
parameters unchanged.

73-103: ⚖️ Poor tradeoff

Consider extracting the .envrc loading logic to a composite action.

This ~30-line bash script is duplicated verbatim across 8 jobs. Extracting it to a composite action (e.g., .github/actions/load-envrc-sccache/action.yml) would centralize maintenance and reduce the risk of drift when updates are needed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/cargo-tests.reusable.yaml around lines 73 - 103, Extract
the repeated "Load .envrc" bash block into a reusable composite action and
replace each duplicated job step with a single uses: call; specifically, move
the logic that handles direnv allow/eval, exports RUSTC_WRAPPER and
SCCACHE_ERROR_LOG, conditionally maps
BAML_SCCACHE_R2_ACCESS_KEY_ID/BAML_SCCACHE_R2_SECRET_ACCESS_KEY to
AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY (or unsets SCCACHE_*/AWS_* and emits the
notice), restarts sccache (sccache --stop-server || true; sccache
--start-server) and the for-loop that writes envs to GITHUB_ENV into the
composite action (e.g., accept inputs for the two secrets and RUNNER_TEMP, and
expose any needed outputs or simply set environment in the caller); then update
every job that currently runs the "Load .envrc" step to call this composite
action to centralize maintenance and avoid drift.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/cargo-tests.reusable.yaml:
- Around line 99-103: The env propagation loop in
.github/workflows/cargo-tests.reusable.yaml omits SCCACHE_SERVER_UDS so later
steps don't receive the UDS path; update the list of variable names iterated
(the for ... in ...) to include SCCACHE_SERVER_UDS so the existing check if [[
-n "${!name+x}" ]] and the printf "%s=%s\n" "$name" "${!name}" >> "$GITHUB_ENV"
will persist SCCACHE_SERVER_UDS into GITHUB_ENV and ensure clients/servers use
the same socket endpoint.

---

Nitpick comments:
In @.github/workflows/cargo-tests.reusable.yaml:
- Around line 65-71: The workflow uses the unpinned action reference
Swatinem/rust-cache@v2 which should be replaced with a specific commit SHA for
supply-chain security; locate every usage of the identifier
Swatinem/rust-cache@v2 in the file (all 8 occurrences) and update each to
Swatinem/rust-cache@<commit-sha> using the exact git commit hash for the version
you vetted, ensuring the same pinned SHA is applied consistently and updating
any accompanying comments or save-if/shared-key parameters unchanged.
- Around line 73-103: Extract the repeated "Load .envrc" bash block into a
reusable composite action and replace each duplicated job step with a single
uses: call; specifically, move the logic that handles direnv allow/eval, exports
RUSTC_WRAPPER and SCCACHE_ERROR_LOG, conditionally maps
BAML_SCCACHE_R2_ACCESS_KEY_ID/BAML_SCCACHE_R2_SECRET_ACCESS_KEY to
AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY (or unsets SCCACHE_*/AWS_* and emits the
notice), restarts sccache (sccache --stop-server || true; sccache
--start-server) and the for-loop that writes envs to GITHUB_ENV into the
composite action (e.g., accept inputs for the two secrets and RUNNER_TEMP, and
expose any needed outputs or simply set environment in the caller); then update
every job that currently runs the "Load .envrc" step to call this composite
action to centralize maintenance and avoid drift.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a878ae66-02ca-4fdf-aa7e-b251269a4d10

📥 Commits

Reviewing files that changed from the base of the PR and between 207b915 and 78a0154.

📒 Files selected for processing (4)
  • .envrc
  • .github/actions/setup-mise/action.yml
  • .github/workflows/cargo-tests.reusable.yaml
  • mise.toml
✅ Files skipped from review due to trivial changes (1)
  • mise.toml
🚧 Files skipped from review as they are similar to previous changes (2)
  • .github/actions/setup-mise/action.yml
  • .envrc

Comment thread .github/workflows/cargo-tests.reusable.yaml Outdated
@codspeed-hq

codspeed-hq Bot commented May 30, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 13 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing sam/sccache-ci (cd40db1) with canary (066b6cb)

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.

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]>
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