diff --git a/macro/src/lib.rs b/macro/src/lib.rs index a8137880ee3..19ce95e0e5a 100644 --- a/macro/src/lib.rs +++ b/macro/src/lib.rs @@ -201,6 +201,22 @@ fn validate_type_path(path: &syn::Path, metadata: &Metadata) { } } +/// Resolves a path, handling the $OUT_DIR placeholder if present. +/// If $OUT_DIR is present in the path, it's replaced with the actual OUT_DIR environment variable. +/// Otherwise, the path is resolved relative to CARGO_MANIFEST_DIR. +fn resolve_path(path_str: &str) -> std::path::PathBuf { + if path_str.contains("$OUT_DIR") { + let out_dir = std::env::var("OUT_DIR").unwrap_or_else(|_| { + abort_call_site!("$OUT_DIR is used in path but OUT_DIR environment variable is not set") + }); + std::path::Path::new(&path_str.replace("$OUT_DIR", &out_dir)).into() + } else { + let root = std::env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".into()); + let root_path = std::path::Path::new(&root); + root_path.join(path_str) + } +} + /// Fetches metadata in a blocking manner, from a url or file path. fn fetch_metadata(args: &RuntimeMetadataArgs) -> Result { // Do we want to fetch unstable metadata? This only works if fetching from a URL. @@ -213,9 +229,7 @@ fn fetch_metadata(args: &RuntimeMetadataArgs) -> Result Result