diff --git a/Cargo.lock b/Cargo.lock index 4e6ae6a58ba..6d4f6143863 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6398,6 +6398,7 @@ version = "0.1.0" dependencies = [ "oximeter-impl", "proc-macro2", + "quote", "syn 2.0.64", ] diff --git a/oximeter/timeseries-macro/Cargo.toml b/oximeter/timeseries-macro/Cargo.toml index 26c58b66a34..35fd384afdb 100644 --- a/oximeter/timeseries-macro/Cargo.toml +++ b/oximeter/timeseries-macro/Cargo.toml @@ -9,6 +9,7 @@ proc-macro = true [dependencies] oximeter-impl.workspace = true proc-macro2.workspace = true +quote.workspace = true syn.workspace = true [lints] diff --git a/oximeter/timeseries-macro/src/lib.rs b/oximeter/timeseries-macro/src/lib.rs index 3c30aa8f3fc..4926d11d8c9 100644 --- a/oximeter/timeseries-macro/src/lib.rs +++ b/oximeter/timeseries-macro/src/lib.rs @@ -6,7 +6,20 @@ pub fn use_timeseries( ) -> proc_macro::TokenStream { match syn::parse::(tokens) { Ok(path) => { - let filename = path.value(); + let filename = + match std::path::Path::new(&path.value()).canonicalize() { + Ok(f) => f.display().to_string(), + Err(e) => { + let msg = format!( + "Failed to canonicalize file from path '{}': {:?}", + path.value(), + e, + ); + return syn::Error::new(path.span(), msg) + .into_compile_error() + .into(); + } + }; let contents = match std::fs::read_to_string(&filename) { Ok(c) => c, Err(e) => { @@ -21,7 +34,15 @@ pub fn use_timeseries( } }; match oximeter_impl::schema::codegen::use_timeseries(&contents) { - Ok(toks) => return toks.into(), + Ok(toks) => { + return quote::quote! { + /// Include the schema file itself to ensure we recompile + /// when that changes. + const _: &str = include_str!(#filename); + #toks + } + .into() + } Err(e) => { let msg = format!( "Failed to generate timeseries types \