1
Fork 0
mirror of https://github.com/RGBCube/embd-rs synced 2025-07-28 14:07:45 +00:00

Better error messages when procmacro2_semver_exempt is not set

This commit is contained in:
RGBCube 2024-05-22 10:57:48 +03:00
parent 661d2d54c0
commit 0c9527c653
No known key found for this signature in database
2 changed files with 30 additions and 2 deletions

View file

@ -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();