Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global caches & cargo-sweep #20

Merged
merged 21 commits into from
Nov 3, 2023
Merged

global caches & cargo-sweep #20

merged 21 commits into from
Nov 3, 2023

Conversation

idelvall
Copy link
Member

@idelvall idelvall commented Oct 30, 2023

Summary

This PR:

  • Runs cargo sweep after the user cargo sub-command
  • Introduces @ijc RUN_WITH_CACHE UDC
  • Caches $CARGO_HOME is a non-locking global cache (shared across all Earthfiles). This significantly reduces cache size

On global cache

In order to make the new global cache work with sharing=shared mode (that allows parallel builds to access its contents), I had to make sure that $CARGO_HOME/.package-cache was also being stored in the cache, since this the file used by Cargo as a lock to synchronize the access to $CARGO_HOME from parallel builds.

The simplest way I found to achieve this was by temporarily changing the whole $CARGO_HOME location to a folder within the cache, while running the same bin/cargo program.

Copy link

@ijc ijc left a comment

Choose a reason for hiding this comment

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

LGTM.

rust/Earthfile Outdated Show resolved Hide resolved
@idelvall
Copy link
Member Author

Ok, by using global caches (caches with id) I encounter this exact problem https://users.rust-lang.org/t/does-dockers-mount-type-cache-cause-problems/97073.
Now trying to understand why cargo locks don't work in the buildkit cache mount...

@idelvall
Copy link
Member Author

I've checked and flock properly works on shared cache mounts, so still investigating why I am facing this rust-lang/cargo#11376

@idelvall
Copy link
Member Author

This looks promising: rust-lang/cargo#11376 (comment)

@idelvall idelvall marked this pull request as ready for review November 2, 2023 08:52
@idelvall idelvall requested a review from a team as a code owner November 2, 2023 08:52
@idelvall idelvall requested a review from ijc November 2, 2023 09:29
rust/Earthfile Show resolved Hide resolved
@idelvall
Copy link
Member Author

idelvall commented Nov 2, 2023

This last commit sets $CARGO_INSTALL_ROOT pointing to the original $CARGO_HOME (in the target filesystem, not the mount cache).

The reason is that, installed crates are not fetched on demand if not found (they need to be installed), so if BK GC removes them from the cache then the build will fail, while if they are stored in the target layers and BK GCed them, the build will rerun those commands and install them back.

This setting makes cargo install to store the crates in the target filesystem to avoid such scenario

rust/Earthfile Outdated Show resolved Hide resolved
rust/Earthfile Outdated Show resolved Hide resolved
Copy link
Contributor

@idodod idodod left a comment

Choose a reason for hiding this comment

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

Looks good, just a few minor comments.

rust/Earthfile Outdated Show resolved Hide resolved
rust/Earthfile Outdated Show resolved Hide resolved
rust/Earthfile Show resolved Hide resolved
@idelvall idelvall changed the title adds cargo-sweep and changes how stoml is installed global caches & cargo-sweep Nov 2, 2023
rust/README.md Outdated Show resolved Hide resolved
rust/Earthfile Outdated Show resolved Hide resolved
rust/Earthfile Show resolved Hide resolved
rust/Earthfile Outdated Show resolved Hide resolved
rust/Earthfile Outdated Show resolved Hide resolved
rust/Earthfile Outdated Show resolved Hide resolved
@idelvall idelvall merged commit f8906ce into main Nov 3, 2023
2 checks passed
@idelvall idelvall deleted the nacho/cargo-sweep branch November 3, 2023 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants