Caching a part's build artifacts

Packaging a large Rust project, the veloren snap has significant build times. I use GitLab CI to publish nightly builds to the edge channel.
Ideally, I would be able to cache the build (target) folder for the veloren part. Is there a way to do this reliably with snapcraft? I can see some hacky ways in which I can accomplish this (e.g. manually copying the cached target folder in override-build). Are there better ways to do this? Thanks!

2 Likes

I expect it’s building in destructive mode so you could try caching the parts, prime and stage directories. In destructive mode I’m not sure that Snapcraft would invalidate/ignore artifacts produced from a different version of Snapcraft, so there’s risk of breakage there. If the cache works, I’d suggest invalidating it if the Snapcraft version changes.

If you try it, I’d love to hear how it works out :smiley:

2 Likes

Each tool usually has a mechanism for caching, I use CCACHE for my big c++ builds and store that externally, rust has something of the sorts too https://doc.rust-lang.org/cargo/guide/build-cache.html.

While reading that, I noticed we might need to look into the Dep-Info section there and add some logic to the plugin to handle that.

1 Like