diff --git a/embd-macros/src/lib.rs b/embd-macros/src/lib.rs index c4686be..898a55b 100644 --- a/embd-macros/src/lib.rs +++ b/embd-macros/src/lib.rs @@ -1,16 +1,28 @@ #![allow(unexpected_cfgs)] -#![cfg(procmacro2_semver_exempt)] +#[cfg(procmacro2_semver_exempt)] use std::{ fs, path::Path, }; +#[cfg(not(procmacro2_semver_exempt))] +compile_error!( + r#"pass `--cfg procmacro2_semver_exempt` to rustc to compile embd-macros or add this to your `.cargo/config.toml`: + +[build] +rustflags = [ "--cfg", "procmacro2_semver_exempt" ] + +"# +); + +#[cfg(procmacro2_semver_exempt)] use proc_macro as pm1; use proc_macro2::TokenStream; use quote::{ quote, ToTokens, }; +#[cfg(procmacro2_semver_exempt)] use syn::{ parse_macro_input, spanned::Spanned, @@ -30,6 +42,7 @@ impl ToTokens for TokenVec { } #[proc_macro] +#[cfg(procmacro2_semver_exempt)] pub fn __dir(input: pm1::TokenStream) -> pm1::TokenStream { let input2 = input.clone(); let path = parse_macro_input!(input2 as LitStr).value(); @@ -52,12 +65,14 @@ pub fn __dir(input: pm1::TokenStream) -> pm1::TokenStream { .into() } +#[cfg(procmacro2_semver_exempt)] fn dir_debug(path: &str) -> TokenStream { quote! { ::embd::__dir_runtime(file!(), #path) } } +#[cfg(procmacro2_semver_exempt)] fn dir_release(input: TokenStream, path: &str) -> TokenStream { let neighbor = TokenStream::from(input).span().source_file().path(); @@ -80,6 +95,7 @@ fn dir_release(input: TokenStream, path: &str) -> TokenStream { } } +#[cfg(procmacro2_semver_exempt)] fn read_dir(directory: &Path) -> TokenVec { let mut entries = Vec::new(); diff --git a/embd/src/lib.rs b/embd/src/lib.rs index 20404fe..0780950 100644 --- a/embd/src/lib.rs +++ b/embd/src/lib.rs @@ -1,11 +1,20 @@ #![allow(unexpected_cfgs)] -#![cfg(procmacro2_semver_exempt)] use std::{ borrow::Cow, fs, path::Path, }; +#[cfg(not(procmacro2_semver_exempt))] +compile_error!( + r#"pass `--cfg procmacro2_semver_exempt` to rustc to compile embd or add this to your `.cargo/config.toml`: + +[build] +rustflags = [ "--cfg", "procmacro2_semver_exempt" ] + +"# +); + #[doc(hidden)] pub fn __string_runtime(neighbor: &str, path: &str) -> String { let file = Path::new(neighbor) @@ -27,6 +36,7 @@ pub fn __string_runtime(neighbor: &str, path: &str) -> String { /// } /// ``` #[macro_export] +#[cfg(procmacro2_semver_exempt)] macro_rules! string { ($path:literal) => {{ #[cfg(debug_assertions)] @@ -62,6 +72,7 @@ pub fn __bytes_runtime(neighbor: &str, path: &str) -> Vec { /// } /// ``` #[macro_export] +#[cfg(procmacro2_semver_exempt)] macro_rules! bytes { ($path:literal) => {{ #[cfg(debug_assertions)] @@ -223,4 +234,5 @@ pub fn __dir_runtime(neighbor: &str, path: &str) -> Dir { /// let content: embd::Dir = embd::dir!("../assets"); /// } /// ``` +#[cfg(procmacro2_semver_exempt)] pub use embd_macros::__dir as dir;