#cargo #bazel #testing

build runfiles

Bazel runfiles support for cargo

1 unstable release

0.1.0 Dec 29, 2022

#633 in Build Utils

Download history 1/week @ 2024-08-24 38/week @ 2024-08-31 3/week @ 2024-09-07 8/week @ 2024-09-21 10/week @ 2024-09-28 2/week @ 2024-10-05 162/week @ 2024-10-26 252/week @ 2024-11-02 225/week @ 2024-11-09 233/week @ 2024-11-16 37/week @ 2024-11-23 265/week @ 2024-11-30 186/week @ 2024-12-07

783 downloads per month

Apache-2.0

12KB
195 lines

Bazel runfiles support for cargo.

The source code is just copied directly from rules_rust/tools/runfiles/runfiles.rs. Tests are not expected to work. This is mainly useful for:

  • Bootstrapping cargo_universe.
  • Allowing things depending on runfiles to be built with cargo.
  • Allow requesting dependiencies on runfiles in cargo.toml.
  • Support IDE code completion.

lib.rs:

Runfiles lookup library for Bazel-built Rust binaries and tests.

USAGE:

  1. Depend on this runfiles library from your build rule:

      rust_binary(
          name = "my_binary",
          ...
          data = ["//path/to/my/data.txt"],
          deps = ["@rules_rust//tools/runfiles"],
      )
    
  2. Import the runfiles library.

    extern crate runfiles;
    
    use runfiles::Runfiles;
    
  3. Create a Runfiles object and use rlocation to look up runfile paths:

    
    use runfiles::Runfiles;
    
    let r = Runfiles::create().unwrap();
    let path = r.rlocation("my_workspace/path/to/my/data.txt");
    
    let f = File::open(path).unwrap();
    // ...
    

No runtime deps