From d0f91f8631878eb62f529e21832ca800ff9c749c Mon Sep 17 00:00:00 2001 From: PG Herveou Date: Tue, 9 Dec 2025 12:56:18 +0100 Subject: [PATCH] Allow passing $OUT_DIR in the runtime_metadata_path attribute (#2142) * Allow passing $OUT_DIR in the runtime_metadata_path attribute * nit * fix build * PR review * ignore instead of no_run --- macro/src/lib.rs | 25 +++++++++++++++++++------ subxt/src/lib.rs | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/macro/src/lib.rs b/macro/src/lib.rs index f870289d5c..08d1d74165 100644 --- a/macro/src/lib.rs +++ b/macro/src/lib.rs @@ -212,6 +212,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. @@ -224,9 +240,7 @@ fn fetch_metadata(args: &RuntimeMetadataArgs) -> Result Result