#path #ci #xtask #check #repo #repository #compile-time

macro build repo_path

Access paths in your repository, with compile-time checks

2 stable releases

1.1.0 Jan 25, 2025
1.0.0 Jan 12, 2025

#435 in Build Utils

Download history 95/week @ 2025-01-07 86/week @ 2025-01-14 110/week @ 2025-01-21 124/week @ 2025-01-28 305/week @ 2025-02-04 135/week @ 2025-02-11

694 downloads per month
Used in 4 crates (via cicero_path)

Apache-2.0

20KB
135 lines

repo_path

Access paths in your repository, with compile-time checks.
This is useful in particular when you're writing your CI code in Rust, e.g. via the cargo-xtask pattern.

use repo_path::repo_path;

let readme = repo_path!("README.md");
let ui_tests = repo_path!("tests/ui/");
let repo_root = repo_path!(); //equivalent to repo_path!(".")

The macro checks whether the path exists and constructs a PathBuf containing an absolute path. If the path does not exist, the compiler will error during compilation:

use repo_path::repo_path;

let non_existent = repo_path!("non/existent/path.txt");

This allows you to move files around without having to worry that a reference silently breaks, similar to the way std::include_str!() works.

How it works

During compilation, the macro looks for the .git directory to determine the root of your repository.
Then it joins the path you specified to the root and checks if the resulting path exists.

The path of your repository root is cached during compilation, so that you can use repo_path!() many times without a significant compile-time burden.

Usage in a library

Because the macro fetches the path during compilation, you cannot use it in libraries that want to access your user's repository (it will return paths for your own repository).
For that purpose, use the repo_path_lib crate instead.

Changelog

See the changelog here: https://codeberg.org/trem/repo_path/src/branch/main/CHANGELOG.md

Dependencies

~0.2–2.2MB
~52K SLoC