Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions rust/runfiles/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions rust/runfiles/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "runfiles"
version = "0.1.0"
edition = "2018"
license = "Apache-2.0"
description = "Runfiles lookup library for Bazel-built Rust binaries and tests."
repository = "https://github.com/bazelbuild/rules_rust"

[lib]
path = "runfiles.rs"
19 changes: 18 additions & 1 deletion rust/runfiles/runfiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,27 @@ const TEST_SRCDIR_ENV_VAR: &str = "TEST_SRCDIR";
#[macro_export]
macro_rules! rlocation {
($r:expr, $path:expr) => {
$r.rlocation_from($path, env!("REPOSITORY_NAME"))
{
let repo = option_env!("REPOSITORY_NAME");
$r.rlocation_from($path, $crate::repository_name(repo))
}
};
}

/// Return the build-time repository name.
///
/// Bazel sets the `REPOSITORY_NAME` environment variable while compiling this crate. When
/// building via Cargo (e.g., from a git dependency), callers must either set the same
/// environment variable at compile time or call `rlocation_from` directly with an explicit
/// `source_repo`. This function panics if the value is not available.
pub fn repository_name(repo: Option<&'static str>) -> &'static str {
repo.unwrap_or_else(|| {
panic!(
"REPOSITORY_NAME was not set at compile time; set it or call rlocation_from directly"
)
})
}

/// The error type for [Runfiles] construction.
#[derive(Debug)]
pub enum RunfilesError {
Expand Down