use uuid again since proc_macro::Span isn't unique enough

This commit is contained in:
eugineerd 2025-07-16 21:59:54 +00:00
parent 5dd2e99c7c
commit 655a2f81b1
2 changed files with 5 additions and 18 deletions

View File

@ -23,7 +23,7 @@ auto_register = []
# Enables automatic reflection using inventory. Not supported on all platforms.
auto_register_inventory = ["auto_register"]
# Enables automatic reflection on platforms not supported by inventory. See `load_type_registrations` for more info.
auto_register_static = ["auto_register"]
auto_register_static = ["auto_register", "dep:uuid"]
[dependencies]
bevy_macro_utils = { path = "../../bevy_macro_utils", version = "0.17.0-dev" }
@ -31,6 +31,9 @@ indexmap = "2.0"
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "2.0", features = ["full", "extra-traits"] }
uuid = { version = "1.13.1", default-features = false, features = [
"v4",
], optional = true }
[target.'cfg(target_arch = "wasm32")'.dependencies]
# TODO: Assuming all wasm builds are for the browser. Require `no_std` support to break assumption.

View File

@ -169,11 +169,8 @@ pub fn reflect_auto_registration(meta: &ReflectMeta) -> Option<proc_macro2::Toke
};
if cfg!(feature = "auto_register_static") {
use core::hash::{Hash, Hasher};
use proc_macro::Span;
use std::{
env, fs,
hash::DefaultHasher,
io::Write,
path::PathBuf,
sync::{LazyLock, Mutex},
@ -207,20 +204,7 @@ pub fn reflect_auto_registration(meta: &ReflectMeta) -> Option<proc_macro2::Toke
Mutex::new(file)
});
let crate_name =
env::var("CARGO_CRATE_NAME").expect("Expected cargo to set CARGO_CRATE_NAME env var");
let span = Span::call_site();
let mut hasher = DefaultHasher::new();
span.file().hash(&mut hasher);
let file_path_hash = hasher.finish();
let export_name = format!(
"_bevy_reflect_register_{}_{}_{}_{}",
crate_name,
file_path_hash,
span.line(),
span.column(),
);
let export_name = format!("_bevy_reflect_register_{}", uuid::Uuid::new_v4().as_u128());
{
let mut file = REGISTRATION_FNS_EXPORT.lock().unwrap();