Crates.io | cargo-mtime |
lib.rs | cargo-mtime |
version | 0.1.1 |
source | src |
created_at | 2024-03-11 21:07:35.013675 |
updated_at | 2024-03-13 21:01:15.558944 |
description | Simple tool to manage file mtime values in sandboxed compilation. |
homepage | |
repository | https://github.com/tgolsson/cargo-mtime |
max_upload_size | |
id | 1169843 |
size | 40,918 |
cargo-mtime
This is a small utility that can be used to manage mtimes for sandboxed compilation with Cargo. Since Cargo relies on file-system mtime information for invalidating builds, moving files to a temporary directory for builds will also trigger large rebuilds. There has been a few attempts at solving this upstream, but nothing has been stabilized or accepted.
I'm working on supporting Rust in Pants, which uses sha-based caching at the top already, which means that it is always going to be more conservative for when a build should happen. Still, Cargo rebuilds more than needed due to changing paths and updated mtimes, even with a cache being available. This small utility makes Cargo smarter by restoring the mtime to the cached mtime of the file.
How does it work?
This tool is trivially implemented. It uses a single file to capture the sha256 of each file at compilation, along with the mtime of it. When ran again on the same source tree, it'll refresh the database but also reset the mtime to the timestamp in the database.
To configure it, you can use either positional arguments or environment flags:
$ CARGO_MTIME_ROOT=. CARGO_MTIME_DB_PATH=~/.cache/mtimes/project.db cargo-mtime-memoize
$ cargo-mtime-memoize . ~/.cache/mtimes/project.db
Do not mix databases between projects, it might lead to Cargo not rebuilding correctly.