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

macro build repo_path

Access paths in your repository, with compile-time checks

1 stable release

new 1.0.0 Jan 12, 2025

#343 in Build Utils

Download history 139/week @ 2025-01-12

139 downloads per month

Apache-2.0

12KB
121 lines

repo_path

Access paths in your repository, with compile-time checks.

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!() 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.

Dependencies

~235–680KB
~16K SLoC