earthly / lib

Mozilla Public License 2.0
7 stars 11 forks source link

[lib/rust] RUSTFLAGS might introduce cache-misses in the target mount cache #30

Open idelvall opened 9 months ago

idelvall commented 9 months ago

Sharing target mount cache across builds with different RUSTFLAGS overwrites cache entries and results in cache misses. The reason is $CARGO_TARGET_DIR cache entries, despite depending on RUSTFLAGS are not keyed by them.

Context

Current version of the lib/rust library uses several mount caches per tuple of {runner, project, os_release}:

The problem comes when RUSTFLAGS are changed, some cache entries might be overwritten, or when the user Earthfile has successive +CARGO builds in the same Earthly target using different RUSTFLAGS. These scenarios would result in the loss of the original cache entries.

References

Proposal

We could additionally key $CARGO_TARGET_DIR mount caches by the whole cargo command + hashOf(rustflags) to make sure these caches are only reused across builds of the same command, with the same RUSTFLAGS