envcache 0.1.3

A build.rs helper crate for caching environment variables
Documentation
  • Coverage
  • 75%
    3 out of 4 items documented1 out of 4 items with examples
  • Size
  • Source code size: 6.21 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.28 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • sheredom/envcache
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • sheredom

🏴‍☠️ envcache

Actions Status Crates.io API Docs

The envcache crate (environment cache) lets users cache environmental variables in a build.rs script, so that subsequent calls to cargo are not required to be ran with the same variable specified.

For example, let's assume you have a build.rs that requires SOME_VAR to be specified for work. Maybe its a path to some library that lives outside of the Rust ecosystem (like LLVM):

SOME_VAR=42 cargo test
cargo clippy # Will fail because SOME_VAR is not set

This would fail because the run to cargo clippy requires that it is run with SOME_VAR=42. With the envcache, we can use a build.rs that ensures this will run:

use envcache;
# std::env::set_var("OUT_DIR", std::env::temp_dir());
let mut envcache = envcache::EnvCache::new();
envcache.cache("SOME_VAR");

Now if we run this again:

SOME_VAR=42 cargo test
cargo clippy # SOME_VAR will be 42

You can change a previously set cached variable by simply re-specifying it on the command line:

SOME_VAR=42 cargo test
SOME_VAR=13 cargo test
cargo test # SOME_VAR will be 13!

Note that running cargo clean will remove any previously cached variables, so running:

SOME_VAR=42 cargo test
cargo clippy # Will work because we've cached SOME_VAR
cargo clean
cargo test # Will fail because SOME_VAR won't be set