cargo-bin-file 0.1.0

Read binary paths from Cargo's CARGO_BIN_FILE_* environment variables
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented1 out of 1 items with examples
  • Size
  • Source code size: 5.49 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 244.7 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 7s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • RoxyOS/cargo-bin-file
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • NikoPit

cargo-bin-file

Small helper for reading binary paths from Cargo's CARGO_BIN_FILE_* environment variables.

This is useful in integration tests or benchmarks where Cargo exposes the path to a compiled binary from another package.

What it does

Given a crate name like example-crate, this crate looks up:

CARGO_BIN_FILE_EXAMPLE_CRATE

If that environment variable exists, it returns the value as a PathBuf. Otherwise it returns None.

Example

use cargo_bin_file::bin_path;

let key = "CARGO_BIN_FILE_EXAMPLE_CRATE";

unsafe {
    std::env::set_var(key, "/tmp/example-crate");
}

assert_eq!(
    bin_path("example-crate"),
    Some(std::path::PathBuf::from("/tmp/example-crate"))
);

unsafe {
    std::env::remove_var(key);
}

Notes

  • Hyphens in crate names are converted to underscores.
  • ASCII letters are uppercased to match Cargo's environment variable format.
  • This crate only reads the environment variable. It does not check whether the resulting path exists.
  • The library currently exposes a single helper, bin_path, for looking up a path by binary crate name.

License

Licensed under either of:

  • MIT
  • Apache-2.0