#cargo #bazel #testing

build runfiles

Bazel runfiles support for cargo

1 unstable release

0.1.0 Dec 29, 2022

#430 in Build Utils

Download history 2113/week @ 2023-12-31 2685/week @ 2024-01-07 3171/week @ 2024-01-14 2864/week @ 2024-01-21 3357/week @ 2024-01-28 2759/week @ 2024-02-04 2047/week @ 2024-02-11 1922/week @ 2024-02-18 1889/week @ 2024-02-25 2335/week @ 2024-03-03 2211/week @ 2024-03-10 2349/week @ 2024-03-17 4228/week @ 2024-03-24 4038/week @ 2024-03-31 3662/week @ 2024-04-07 510/week @ 2024-04-14

12,647 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