feat(build-rs): Add cargo_manifest_path

This commit is contained in:
Ed Page 2024-11-13 13:54:48 -06:00
parent 4ff0809afd
commit 611ec991fb
2 changed files with 13 additions and 0 deletions

View File

@ -47,6 +47,7 @@ fn smoke_test_inputs() {
dbg!(cargo_encoded_rustflags());
dbg!(cargo_feature("unstable"));
dbg!(cargo_manifest_dir());
dbg!(cargo_manifest_path());
dbg!(cargo_manifest_links());
dbg!(cargo_pkg_authors());
dbg!(cargo_pkg_description());

View File

@ -29,6 +29,18 @@ pub fn cargo_manifest_dir() -> PathBuf {
to_path(var_or_panic("CARGO_MANIFEST_DIR"))
}
/// The path to the manifest of your package.
#[track_caller]
pub fn cargo_manifest_path() -> PathBuf {
var_os("CARGO_MANIFEST_PATH")
.map(to_path)
.unwrap_or_else(|| {
let mut path = cargo_manifest_dir();
path.push("Cargo.toml");
path
})
}
/// The manifest `links` value.
#[track_caller]
pub fn cargo_manifest_links() -> Option<String> {