diff --git a/crates/build-rs-test-lib/build.rs b/crates/build-rs-test-lib/build.rs index a6065ef03..1167a3490 100644 --- a/crates/build-rs-test-lib/build.rs +++ b/crates/build-rs-test-lib/build.rs @@ -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()); diff --git a/crates/build-rs/src/input.rs b/crates/build-rs/src/input.rs index 94d19302a..93faf1400 100644 --- a/crates/build-rs/src/input.rs +++ b/crates/build-rs/src/input.rs @@ -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 {