Shared scratch for build scripts
This crate exposes a compile-time temporary directory sharable by multiple
crates in a build graph and erased by
The intended usage is from a build.rs Cargo build script, or more likely from a library which is called by other crates' build scripts.
# Cargo.toml  = "1.0"
This functionality is different from OUT_DIR in that the same directory path will be seen by all crates whose build passes a matching
suffixargument, and each crate can see content placed into the directory by those other crates' build scripts that have already run.
This functionality is similar to OUT_DIR in that both are erased when a
cargo cleanis executed.
This functionality is similar to temp_dir() in that stuff that goes in is visible to subsequently running build scripts.
This functionality is different from temp_dir() in that
cargo cleancleans up the contents.
You'll want to consider what happens when Cargo runs multiple build scripts concurrently that access the same scratch dir. In some use cases you likely want some synchronization over the contents of the scratch directory, such as by an advisory file lock. On Unix-like and Windows host systems the simplest way to sequence the build scripts such that each one gets exclusive access one after the other is something like:
use File; use io;
This simplest approach is fine for a cache which is slow to fill (maybe a large download) but fast/almost immediate to use. On the other hand if the build scripts using your cache will take a while to complete even if they only read from the scratch directory, a different approach which allows readers to make progress in parallel would perform better.
use ; use io;
For use cases that are not just a matter of the first build script writing to
the directory and the rest reading, more elaborate schemes involving
lock_shared might be something to consider.