#cargo #bazel #testing

build runfiles

Bazel runfiles support for cargo

1 unstable release

0.1.0 Dec 29, 2022

#508 in Build Utils

Download history 2251/week @ 2024-03-08 2205/week @ 2024-03-15 3892/week @ 2024-03-22 4250/week @ 2024-03-29 3507/week @ 2024-04-05 1505/week @ 2024-04-12 4/week @ 2024-04-19 2/week @ 2024-04-26 143/week @ 2024-05-03 45/week @ 2024-05-10 24/week @ 2024-05-17 14/week @ 2024-05-24 26/week @ 2024-05-31 35/week @ 2024-06-07 23/week @ 2024-06-14 6/week @ 2024-06-21

97 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