Skip to content
New issue

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

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

Already on GitHub? # to your account

Add optional caching #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pzmarzly
Copy link
Contributor

In a project I'm working on, this decreases overall build time from between 8 and 10 to between 5 and 7 seconds.

@ZaneHannanAU
Copy link

Faster build time (considering my own is 10+ mins) is always good.

👍

@utkarshkukreti
Copy link
Owner

While a faster build time is good, I'm not sure about writing cached files into the user's system's cache directory. Is there any other popular crate which does this?

@pzmarzly
Copy link
Contributor Author

Is there any other popular crate which does this?

I wasn't familiar with any, which is why I suggested it as an optional feature. Quick search on crates.io led me to gmp-mpfr-sys, which creates temporary files in ~/.cache/gmp-mpfr-sys, though it doesn't have to (it could use $OUT_DIR provided by cargo).

I was thinking about using target dir, but AFAIK we don't get any path to it. We would need to either:

a) assume it's $PWD/target - but it's sometimes not,
b) assume it's $CARGO_MANIFEST_DIR/target - false in multi-crate projects,
c) use $PWD to find a topmost directory that contains both Cargo.toml and target - which would work for 99% of use cases, but that 1% of users could get surprised

Many Rust developers already have large ~/.cargo/registry and ~/.cache/sccache dirs, so I thought writing few hundred KBs to ~/.cache wouldn't be that much of an issue if users were warned about that.

@Kijewski
Copy link
Contributor

Cargo actually provides a per-crate temporary directory for such a use-case. You can have a look how I use caching in Nate: build.rs, generate.rs. (Actually I use it because then you have better error messages. The caching is only a by-product.)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants