#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 2933/week @ 2023-12-07 2834/week @ 2023-12-14 2068/week @ 2023-12-21 1969/week @ 2023-12-28 2324/week @ 2024-01-04 3042/week @ 2024-01-11 3129/week @ 2024-01-18 3192/week @ 2024-01-25 3077/week @ 2024-02-01 2199/week @ 2024-02-08 1953/week @ 2024-02-15 1888/week @ 2024-02-22 2190/week @ 2024-02-29 2260/week @ 2024-03-07 2254/week @ 2024-03-14 2710/week @ 2024-03-21

9,655 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