diff --git a/crates/build/re_types_builder/src/codegen/rust/reflection.rs b/crates/build/re_types_builder/src/codegen/rust/reflection.rs index 308929bbef70..c3c7739001a1 100644 --- a/crates/build/re_types_builder/src/codegen/rust/reflection.rs +++ b/crates/build/re_types_builder/src/codegen/rust/reflection.rs @@ -23,7 +23,7 @@ pub fn generate_reflection( // Put into its own subfolder since codegen is set up in a way that it thinks that everything // inside the folder is either generated or an extension to the generated code. // This way we don't have to build an exception just for this file. - let path = Utf8PathBuf::from("crates/viewer/re_viewer/src/reflection/mod.rs"); + let path = Utf8PathBuf::from("crates/store/re_types/src/reflection/mod.rs"); let mut imports = BTreeSet::new(); let component_reflection = generate_component_reflection( @@ -60,9 +60,9 @@ pub fn generate_reflection( SerializationError, }; - /// Generates reflection about all known components. - /// - /// Call only once and reuse the results. + #[doc = "Generates reflection about all known components."] + #[doc = ""] + #[doc = "Call only once and reuse the results."] pub fn generate_reflection() -> Result { re_tracing::profile_function!(); @@ -95,10 +95,11 @@ fn generate_component_reflection( .objects_of_kind(ObjectKind::Component) .filter(|obj| !obj.is_testing()) { + let crate_name = patched_crate_name(&obj.crate_name()); if let Some(scope) = obj.scope() { - imports.insert(format!("{}::{scope}::components::*", obj.crate_name())); + imports.insert(format!("{crate_name}::{scope}::components::*")); } else { - imports.insert(format!("{}::components::*", obj.crate_name())); + imports.insert(format!("{crate_name}::components::*")); } let type_name = format_ident!("{}", obj.name); @@ -152,9 +153,9 @@ fn generate_component_reflection( } quote! { - /// Generates reflection about all known components. - /// - /// Call only once and reuse the results. + #[doc = "Generates reflection about all known components."] + #[doc = ""] + #[doc = "Call only once and reuse the results."] fn generate_component_reflection() -> Result { re_tracing::profile_function!(); let array = [ @@ -246,9 +247,9 @@ fn generate_archetype_reflection(reporter: &Reporter, objects: &Objects) -> Toke } quote! { - /// Generates reflection about all known archetypes. - /// - /// Call only once and reuse the results. + #[doc = "Generates reflection about all known archetypes."] + #[doc = ""] + #[doc = "Call only once and reuse the results."] fn generate_archetype_reflection() -> ArchetypeReflectionMap { re_tracing::profile_function!(); let array = [ @@ -258,3 +259,13 @@ fn generate_archetype_reflection(reporter: &Reporter, objects: &Objects) -> Toke } } } + +/// Returns `crate_name` as is, unless it's `re_types`, in which case it's replace by `crate`, +/// because that's where this code lives. +fn patched_crate_name(crate_name: &str) -> String { + if crate_name == "re_types" { + "crate".to_owned() + } else { + crate_name.to_owned() + } +} diff --git a/crates/store/re_chunk/src/chunk.rs b/crates/store/re_chunk/src/chunk.rs index b7ddcda62982..8184bb5178d7 100644 --- a/crates/store/re_chunk/src/chunk.rs +++ b/crates/store/re_chunk/src/chunk.rs @@ -74,7 +74,7 @@ impl ChunkComponents { } /// Returns all list arrays for the given component name. - /// + /// /// I.e semantically equivalent to `get("MyComponent:*.*")` #[inline] pub fn get_by_component_name<'a>( diff --git a/crates/store/re_types/src/lib.rs b/crates/store/re_types/src/lib.rs index f6e07a7d97f0..9ad5c1d25cf2 100644 --- a/crates/store/re_types/src/lib.rs +++ b/crates/store/re_types/src/lib.rs @@ -246,6 +246,22 @@ pub mod datatypes { /// The blueprint-specific components. pub mod blueprint; +/// Run-time reflection for reading meta-data about components and archetypes. +pub mod reflection { + + // Some reflection types are so fundamental and used everywhere that we want them to be + // exposed by `re_types_core` directly; that way we don't force a dependency on the `re_types` + // behemoth just so one can use one of these fundamental reflection types. + // + // To do so, re-inject `re_types_core`'s datatypes into our own module. + + #[path = "../reflection/mod.rs"] + mod _reflection; + + pub use self::_reflection::*; + pub use re_types_core::reflection::*; +} + // --- // One almost never uses `re_types` without `re_types_core`, so we reexport these core types diff --git a/crates/viewer/re_viewer/src/reflection/.gitattributes b/crates/store/re_types/src/reflection/.gitattributes similarity index 100% rename from crates/viewer/re_viewer/src/reflection/.gitattributes rename to crates/store/re_types/src/reflection/.gitattributes diff --git a/crates/viewer/re_viewer/src/reflection/mod.rs b/crates/store/re_types/src/reflection/mod.rs similarity index 99% rename from crates/viewer/re_viewer/src/reflection/mod.rs rename to crates/store/re_types/src/reflection/mod.rs index 078c12c34885..ee95b1db1c8f 100644 --- a/crates/viewer/re_viewer/src/reflection/mod.rs +++ b/crates/store/re_types/src/reflection/mod.rs @@ -3,8 +3,8 @@ #![allow(clippy::too_many_lines)] #![allow(clippy::wildcard_imports)] #![allow(unused_imports)] -use re_types::blueprint::components::*; -use re_types::components::*; +use crate::blueprint::components::*; +use crate::components::*; use re_types_core::components::*; use re_types_core::{ reflection::{ diff --git a/crates/viewer/re_viewer/src/app.rs b/crates/viewer/re_viewer/src/app.rs index b8d36e4d2899..870e52527f4c 100644 --- a/crates/viewer/re_viewer/src/app.rs +++ b/crates/viewer/re_viewer/src/app.rs @@ -296,7 +296,7 @@ impl App { let panel_state_overrides = startup_options.panel_state_overrides; - let reflection = crate::reflection::generate_reflection().unwrap_or_else(|err| { + let reflection = re_types::reflection::generate_reflection().unwrap_or_else(|err| { re_log::error!( "Failed to create list of serialized default values for components: {err}" ); diff --git a/crates/viewer/re_viewer/src/lib.rs b/crates/viewer/re_viewer/src/lib.rs index 60fef300f387..8e17962aa5bf 100644 --- a/crates/viewer/re_viewer/src/lib.rs +++ b/crates/viewer/re_viewer/src/lib.rs @@ -11,14 +11,14 @@ mod app_blueprint; mod app_state; mod background_tasks; pub mod env_vars; -#[cfg(not(target_arch = "wasm32"))] -mod loading; -mod reflection; mod saving; mod screenshotter; mod ui; mod viewer_analytics; +#[cfg(not(target_arch = "wasm32"))] +mod loading; + /// Auto-generated blueprint-related types. /// /// They all implement the [`re_types_core::Component`] trait. diff --git a/scripts/ci/check_large_files.py b/scripts/ci/check_large_files.py index 694ff8672e90..b83948029e1c 100755 --- a/scripts/ci/check_large_files.py +++ b/scripts/ci/check_large_files.py @@ -10,8 +10,8 @@ "crates/build/re_types_builder/src/reflection.rs", "crates/store/re_dataframe/src/query.rs", "crates/store/re_types/src/datatypes/tensor_buffer.rs", + "crates/store/re_types/src/reflection/mod.rs", "crates/viewer/re_ui/data/Inter-Medium.otf", - "crates/viewer/re_viewer/src/reflection/mod.rs", "docs/snippets/INDEX.md", "pixi.lock", "rerun_cpp/docs/Doxyfile",