-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
How to effectively clean target folder for CI caching #5885
Comments
Thanks for the report! Right now there's not a great answer here in that Cargo doesn't have anything implemented to do something like this nor does it internally support the ability to know which artifacts are super old. Currently I'd recommend using something like |
Thanks for the quick answer! |
For posterity: in my .travis.ci, in This seems to greatly speed-up CI builds. I wonder if we can make caching easier by adding more structure to the |
Thanks for sharing! l I've tried something like this already.
The problem is that our project is a workspace and things are not that easy
then. Many crates depend on each other and thus cause many workspace
related artifacts in `target/` - impossible to delete so that the cache is
not poisoned.
For now, we use sccache with the local directory cache and only put that
into the travis cache. We don't cache the target folder at all.
Works reasonably well so far.
…On Thu, 25 Oct 2018, 03:14 Aleksey Kladov, ***@***.***> wrote:
For posterity: in my .travis.ci, in before_cache, I try to explicitly
delete artifacts for current workspace, while keeping artifacts from the
deps intact:
https://github.com/rust-analyzer/rust-analyzer/blob/9a7db8fa009c612168ef16f6ed72315b5406ed09/.travis.yml#L2-L4
This seems to greatly speed-up CI builds. I wonder if we can make caching
easier by adding more structure to the target dir? If, for example, we
group artifacts into folders based on source_id, then it should be easy to
purge anything not from crates.io.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#5885 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFO3NbwV0lCzFfeQotYWY3Vl6gmY7znZks5uoJHUgaJpZM4V6UfN>
.
|
So, I've been using the https://travis-ci.org/rust-analyzer/rust-analyzer/jobs/463540847 One interesting bit is compilation:
This is awesome, considering the fact that rust-analyzer has 145 dependencies, two of which are Another interesting bit is cache uploading:
I think such caching strategy may make a huge difference for project which build/gate on stable (nightly is trickier, because cache will die with the next nightly). In terms of cost/benefit, I think adding a small help from the Cargo's side (dumping all deps from crates.io source to a separate cachable dir) will be very welcome here. cc @rust-lang/cargo: perhaps I am overly enthusiastic here, but it does look like a low-hanging watermelon :) |
I don't think there's any disagreement that Cargo can do a lot here, just needs someone to help push through a design! |
Made a rough POC here: matklad@b3566b1 It was harder then anticipated, mainly because we have three different dirs we need to account for: The real implementation should probably transpose the order of directories:
so that you can point CI cache to However, with this design, if we then allow overriding the location of |
Does this also account/work for workspaces? We have had the biggest problems with workspaces because local crates depend on each other and that causes a weird structure inside the target folder. Nice that this is being worked on! :) |
I don't know how the files are currently laid out, so my opinion should come with a big helping of salt, it would be lovely to have the rust version in the path for artifacts that can only be used by that version of rust. That would make it straightforward to make a GC that dells artifacts that are for a version of rust that are no longer installed. This is not mutually exclusive with other information being encoded in the path, or stored in some other format (like a timestamp file). |
cc crates.io having trouble with this. |
Found something that might be useful in this regard: |
* Delete files from target/ dir to avoid caching them on CI idea from here rust-lang/cargo#5885 (comment) * Delete examples
So, we at clap tried to optimize the cache for CI since we kept making the cache bigger every time we ran on Travis. We took inspiration from rust-analyzer and ended up with the following: https://github.com/clap-rs/clap/pull/1658/files#diff-354f30a63fb0907d4ad57269548329e3R5-R16 It has multiple packages and also has trybuild tests. I am not sure if I was overzealous a bit. But I thought you guys might want to know. |
341: Enable caching for Github Actions r=korken89 a=AfoHT Using [GHA caching](https://docs.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows) to store key parts of the testing environment. One example is downloading `arm-none-eabi-gcc` (which takes roughly 1 minute) for each checkexamples. The rustup setup is roughly 200MB and restores nicely. Rust examples can be found [here](https://github.com/actions/cache/blob/master/examples.md#rust---cargo) **Something to discuss:** Several notable projects remove some problematic files in order to keep cache size reasonable [rust-analyzer](https://github.com/rust-analyzer/rust-analyzer/blob/9a7db8fa009c612168ef16f6ed72315b5406ed09/.travis.yml#L2-L4) [cargo duscussion](rust-lang/cargo#5885) [tantivity-search](https://github.com/tantivy-search/tantivy/pull/531/files) [clap-rs](https://github.com/clap-rs/clap/pull/1658/files#diff-354f30a63fb0907d4ad57269548329e3R5-R16) Co-authored-by: Henrik Tjäder <henrik@tjaders.com>
FYI there is now https://crates.io/crates/cargo-cache though #12633 might be able to help with this. |
I'm using the GitHub Action |
I have a workspace repository with several crates in it (> 10). A clean build of all of them takes about 10 minutes on Travis, which is why I want to cache the
target/
folder.The problem is, the target folder gets quite big (~ 1.7GB) so it takes also about 3 minutes to upload the cache to S3 after the build.
The question is: How can I clean the
target
folder from any artifacts generated by my own code?If I can achieve that, then the
target
folder would only have the artifacts of all the dependencies in it. As long as they don't change, Travis would not have to re-upload the cache. At the same time, rebuilding only the workspace crates takes only 30 seconds.I have already tried several things:
cargo clean -p
for every workspace packagetarget
that mention a workspace crate's nameNone of the above were enough in order to get the
target
folder into a state where NOTHING changes between two builds.I couldn't really understand the layout of the
target
folder: The artifacts of dependencies seem to be mixed up with those of the workspace crates. Is there some documentation available on how the target folder is structured?The text was updated successfully, but these errors were encountered: