mirror of
https://github.com/RGBCube/embd-rs
synced 2025-07-28 05:57:44 +00:00
Better error messages when procmacro2_semver_exempt is not set
This commit is contained in:
parent
661d2d54c0
commit
0c9527c653
2 changed files with 30 additions and 2 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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<u8> {
|
|||
/// }
|
||||
/// ```
|
||||
#[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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue