Skip to content

Cargo build caching#719

Merged
cpuguy83 merged 34 commits intoproject-dalec:mainfrom
bchuo:cargo-build-caching
Oct 6, 2025
Merged

Cargo build caching#719
cpuguy83 merged 34 commits intoproject-dalec:mainfrom
bchuo:cargo-build-caching

Conversation

@bchuo
Copy link
Contributor

@bchuo bchuo commented Jul 24, 2025

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, using fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when the PR gets merged):
Fixes #612

Special notes for your reviewer:

@bchuo bchuo force-pushed the cargo-build-caching branch 3 times, most recently from 832c52d to d136b17 Compare July 28, 2025 20:16
@bchuo bchuo marked this pull request as ready for review July 29, 2025 20:10
Copilot AI review requested due to automatic review settings July 29, 2025 20:10
@bchuo bchuo requested a review from a team as a code owner July 29, 2025 20:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces Cargo build caching functionality to improve Rust compilation performance by implementing sccache (Shared Compilation Cache) support across various targets and platforms.

  • Adds automatic Cargo cache injection when Rust dependencies are detected
  • Implements sccache-based caching for Rust/Cargo builds with cross-platform support
  • Integrates test coverage for the new Cargo caching functionality

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
cache.go Defines CargoBuildCache types, constants, and sccache installation logic
generator_cargohome.go Updates cargo home generation to support sccache binary caching
docs/spec.schema.json Adds schema definitions for the new CargoBuildCache configuration
targets/windows/handle_zip.go Implements Windows-specific cargo cache setup and sccache environment
targets/linux/deb/distro/pkg.go Adds cargo cache support for Debian packaging with alternative Rust paths
targets/linux/rpm/distro/pkg.go Implements cargo cache support for RPM packaging
packaging/linux/deb/debroot.go Sets up sccache environment in Debian build scripts
packaging/linux/rpm/rpmbuild.go Integrates cargo cache setup in RPM build process
test/cache_test.go Adds comprehensive test cases for cargo build caching
test/linux_target_test.go Adds cargo cache test integration for Linux targets
test/windows_test.go Adds cargo cache test and package override for Windows
helpers.go Adds HasRust helper function to detect Rust dependencies
load_test.go Updates validation error messages to include cargobuild
targets/linux/deb/debian/bullseye.go Updates Debian archive URL (unrelated change)

@bchuo bchuo force-pushed the cargo-build-caching branch from 4576ec2 to 385239d Compare July 30, 2025 14:19
@bchuo bchuo force-pushed the cargo-build-caching branch 4 times, most recently from 686ea7f to bc50a0f Compare August 5, 2025 18:29
@bchuo bchuo force-pushed the cargo-build-caching branch from 366c9fb to 706b3a8 Compare August 6, 2025 18:29
@bchuo bchuo force-pushed the cargo-build-caching branch from 0e7cb18 to 2524101 Compare August 6, 2025 19:46
Copy link
Collaborator

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

This is also going to need changes to the website caching docs.

cache.go Outdated
BazelDefaultSocketID = "bazel-default" // Default ID for bazel socket

// SccacheVersion defines the version of sccache to install
SccacheVersion = "v0.10.0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need all these exported vars?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you unexport these values? It seems like they aren't used outside of this package.

cache.go Outdated
// Set up a simple environment variable to enable sccache
llb.AddEnv("RUSTC_WRAPPER", sccacheBinary).SetRunOption(ei)

// Create a symbolic link from /usr/local/bin/sccache to the actual binary
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment about symbolic link doesn't seem correct since this is mounting the actual binary.

}

if addCargoCache {
spec.Build.Caches = append(spec.Build.Caches, dalec.CacheConfig{
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should only add a cargo cache if its not already there.

})
}

cargoBin, err := searchForAltRust(ctx, client, spec, targetKey, worker, opts...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was this needed for the change?
I know we have this for go because it was actually problematic (but unrelated to caching).

@pmengelbert
Copy link
Contributor

pmengelbert commented Aug 25, 2025

Help your reviewers by using PR descriptions and commit messages with full descriptions of what was changed and why. (For future commits to this PR, don't bother going back and adding descriptions to your old commits).

cache.go Outdated
BazelDefaultSocketID = "bazel-default" // Default ID for bazel socket

// SccacheVersion defines the version of sccache to install
SccacheVersion = "v0.10.0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you unexport these values? It seems like they aren't used outside of this package.

@bchuo bchuo force-pushed the cargo-build-caching branch from 54571f9 to 767a726 Compare September 9, 2025 18:57
cache.go Outdated
// sccache target architectures
sccacheArchLinuxX64 = "x86_64-unknown-linux-musl"
sccacheArchLinuxArm64 = "aarch64-unknown-linux-musl"
sccacheArchLinuxArmV7 = "armv7-unknown-linux-musleabihf"
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be a mismatch with what's on the release page.

Suggested change
sccacheArchLinuxArmV7 = "armv7-unknown-linux-musleabihf"
sccacheArchLinuxArmV7 = "armv7-unknown-linux-musleabi"

testAutoGobuildCache(ctx, t, testConfig.Target)
})

t.Run("auto cargobuild cache", func(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Test naming is no longer quite right.
Also rust cache

})
}

func testAutoCargobuildCache(ctx context.Context, t *testing.T, cfg targetConfig) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same, re: test name.

}

testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
// Test that cargo cache is NOT automatically enabled (it's opt-in only now)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment is not neccessary, or could be updated to something along the lines of // test no cache

@bchuo bchuo force-pushed the cargo-build-caching branch from 7e78ed8 to c68fdd4 Compare September 18, 2025 18:52
Copy link
Collaborator

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

Just one more set of minor things and this should be good to go!

testAutoGobuildCache(ctx, t, tcfg)
})

t.Run("auto rust cache", func(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's rename this test, it's just testing the rust caching (no auto)

testAutoGobuildCache(ctx, t, testConfig.Target)
})

t.Run("auto rust cache", func(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's rename this test, it's just testing the rust caching (no auto)

})
}

func testAutoRustCache(ctx context.Context, t *testing.T, cfg targetConfig) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's rename this test, it's just testing the rust caching (no auto)

@cpuguy83 cpuguy83 merged commit 48ebcd7 into project-dalec:main Oct 6, 2025
22 checks passed
@cpuguy83 cpuguy83 added this to the v0.18 milestone Oct 17, 2025
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.

[REQ] Support caching cargo builds

5 participants