'How to effectively cache cargo/Rust projects in an Azure Build Pipeline
I have a set of Azure Build Pipelines that compile rust projects and currently use blob storage to store the .cargo and target folders as a cache.
When compiling locally, once a binary is compiled the first time, subsequent cargo build's don't compile the dependent libraries/crates again, just the local binary, however with my current pipeline system, after downloading the cache and using the correct target folder to build into, the pipeline still downloads and builds crates.
This is my config.toml for the cache and any pipeline builds.
[build]
target-dir = "./target"
dep-info-basedir = "."
incremental = true
It has reduced compilation times in some cases but not nearly as much as I expect. Can I cache more folders to increase speed? Is there some cache identifier that cargo is checking and fouling the cache over?
The pipelines run a custom xtask binary which performs many tasks including running cargo build --release could this be causing issues?
Solution 1:[1]
The cache and artifacts sections are very important ! its saves the data under :
- .cargo/
- .cache/sccache
- target/x86_64-unknown-linux-musl/release/material (this is our final binary).
All data that is created in the first run of the CI jobs will be now saved and uploaded to the Gitlab coordinator. On the next build (new codes are pushed), we will not start the build from scratch, we just build the new packages , the old data will be injected with <<:*caching_rust after the image keyword.
Minimal example for using just Cache
job_build_and_test:
stage: build
script:
- npm install
- gulp test:unit
cache:
key: ${CI_BUILD_REF_NAME}
paths:
- node_modules/
To know more about caching and artifacts flow this link : cache and artifacts.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kangcheng Jin-MSFT |
