bazel-cwd 0.1.1

Get the current working directory in a Bazel-aware manner
Documentation
  • Coverage
  • 66.67%
    2 out of 3 items documented1 out of 3 items with examples
  • Size
  • Source code size: 18.35 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.07 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • kesyog/bazel-cwd
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • kesyog

bazel-cwd

Crates.io Version docs.rs Crates.io License

Resolve paths in a Bazel-aware manner.

As described in https://bazel.build/docs/user-manual#running-executables, the bazel run command runs from the runfiles tree of the binary, not the location where bazel run was run from. This must be accounted for in order to resolve relative paths in a user-friendly manner.

Bazel does expose the "correct" path via an environment variable. This crates provides a helper trait BazelPath and an unbazelify function to resolve paths the way you'd probably expect. It has reasonable fallback behavior when passed an absolute path or when used from outside of bazel run.

use std::path::Path;
use bazel_cwd::BazelPath;

let path = Path::new("foo/bar");
let resolved_path = path.unbazelify().unwrap();
// resolved_path will be an absolute path, resolving the relative path against the directory
// `bazel run` was run in.

This is not an officially supported Google product.