Skip to content

Commit 6465aeb

Browse files
committed
End-to-end tagging for everything C++
1 parent a82a5bb commit 6465aeb

File tree

326 files changed

+3077
-561
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

326 files changed

+3077
-561
lines changed

crates/build/re_types_builder/src/codegen/cpp/mod.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ impl QuotedObject {
559559
.map(|m| m.to_cpp_tokens(&quote!(#type_ident)));
560560

561561
let indicator_comment = quote_doc_comment("Indicator component, used to identify the archetype when converting to a list of components.");
562-
let indicator_fqname =
562+
let indicator_component_fqname =
563563
format!("{}Indicator", obj.fqname).replace("archetypes", "components");
564564
let doc_hide_comment = quote_hide_from_docs();
565565
let deprecation_notice = quote_deprecation_notice(obj);
@@ -586,7 +586,7 @@ impl QuotedObject {
586586
#(#field_declarations;)*
587587

588588
public:
589-
static constexpr const char IndicatorComponentName[] = #indicator_fqname;
589+
static constexpr const char IndicatorComponentName[] = #indicator_component_fqname;
590590
#NEWLINE_TOKEN
591591
#NEWLINE_TOKEN
592592
#indicator_comment
@@ -1576,6 +1576,7 @@ fn to_arrow_method(
15761576

15771577
fn archetype_serialize(type_ident: &Ident, obj: &Object, hpp_includes: &mut Includes) -> Method {
15781578
hpp_includes.insert_rerun("component_batch.hpp");
1579+
hpp_includes.insert_rerun("component_descriptor.hpp");
15791580
hpp_includes.insert_rerun("collection.hpp");
15801581
hpp_includes.insert_system("vector"); // std::vector
15811582

@@ -1586,28 +1587,39 @@ fn archetype_serialize(type_ident: &Ident, obj: &Object, hpp_includes: &mut Incl
15861587
quote!(archetypes)
15871588
};
15881589

1590+
let archetype_name = &obj.fqname;
1591+
15891592
let num_fields = quote_integer(obj.fields.len() + 1); // Plus one for the indicator.
15901593
let push_batches = obj.fields.iter().map(|field| {
15911594
let field_name = field_name_identifier(field);
1595+
let field_fqname = &field.typ.fqname();
15921596
let field_accessor = quote!(archetype.#field_name);
15931597

15941598
let push_back = quote! {
15951599
RR_RETURN_NOT_OK(result.error);
15961600
cells.push_back(std::move(result.value));
15971601
};
15981602

1603+
let archetype_field_name = field.snake_case_name();
1604+
15991605
// TODO(andreas): Introducing MonoCollection will remove the need for distinguishing these two cases.
16001606
if field.is_nullable && !obj.attrs.has(ATTR_RERUN_LOG_MISSING_AS_EMPTY) {
16011607
quote! {
16021608
if (#field_accessor.has_value()) {
1603-
auto result = ComponentBatch::from_loggable(#field_accessor.value());
1609+
auto result = ComponentBatch::from_loggable(
1610+
#field_accessor.value(),
1611+
ComponentDescriptor(#archetype_name, #archetype_field_name, #field_fqname)
1612+
);
16041613
#push_back
16051614
}
16061615
}
16071616
} else {
16081617
quote! {
16091618
{
1610-
auto result = ComponentBatch::from_loggable(#field_accessor);
1619+
auto result = ComponentBatch::from_loggable(
1620+
#field_accessor,
1621+
ComponentDescriptor(#archetype_name, #archetype_field_name, #field_fqname)
1622+
);
16111623
#push_back
16121624
}
16131625
}
@@ -2560,14 +2572,16 @@ fn quote_loggable_hpp_and_cpp(
25602572
let methods_cpp = methods.iter().map(|m| m.to_cpp_tokens(&loggable_type_name));
25612573
let hide_from_docs_comment = quote_hide_from_docs();
25622574

2575+
hpp_includes.insert_rerun("component_descriptor.hpp");
2576+
25632577
let hpp = quote! {
25642578
namespace rerun {
25652579
#predeclarations_and_static_assertions
25662580

25672581
#hide_from_docs_comment
25682582
template<>
25692583
struct #loggable_type_name {
2570-
static constexpr const char Name[] = #fqname;
2584+
static constexpr ComponentDescriptor Descriptor = #fqname;
25712585
#NEWLINE_TOKEN
25722586
#NEWLINE_TOKEN
25732587
#(#methods_hpp)*

crates/store/re_chunk/src/chunk.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl Chunk {
285285
timelines == rhs_timelines
286286
}
287287
// TODO(cmc): we cannot compare tags yet, need to support Python & C++ first
288-
// && *components == rhs.components
288+
&& *components == rhs.components // TODO
289289
&& {
290290
let lhs_components_no_tags: ChunkComponents = components
291291
.clone()

crates/top/rerun_c/src/arrow_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{CError, CErrorCode};
22

3-
/// Converts a C-FFI arrow array into a Rust component batch, taking ownership of the underlying arrow data. ///
3+
/// Converts a C-FFI arrow array into a Rust component batch, taking ownership of the underlying arrow data.
44
///
55
/// Safety:
66
/// This must only be ever called once for a given ffi array.

crates/top/rerun_c/src/component_type_registry.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use once_cell::sync::Lazy;
22
use parking_lot::RwLock;
3-
use re_sdk::ComponentName;
3+
use re_sdk::ComponentDescriptor;
44

55
use crate::{CComponentTypeHandle, CError, CErrorCode};
66

77
pub struct ComponentType {
8-
pub name: ComponentName,
8+
pub descriptor: ComponentDescriptor,
99
pub datatype: arrow2::datatypes::DataType,
1010
}
1111

@@ -18,22 +18,25 @@ pub struct ComponentTypeRegistry {
1818
impl ComponentTypeRegistry {
1919
pub fn register(
2020
&mut self,
21-
name: ComponentName,
21+
descriptor: ComponentDescriptor,
2222
datatype: arrow2::datatypes::DataType,
2323
) -> CComponentTypeHandle {
2424
#[cfg(debug_assertions)]
2525
{
2626
for ty in &self.types {
2727
assert_ne!(
28-
ty.name, name,
29-
"Component type with the same name already registered"
28+
ty.descriptor, descriptor,
29+
"Component type with the same descriptor already registered"
3030
);
3131
}
3232
}
3333

3434
let id = self.next_id;
3535
self.next_id += 1;
36-
self.types.push(ComponentType { name, datatype });
36+
self.types.push(ComponentType {
37+
descriptor,
38+
datatype,
39+
});
3740
id
3841
}
3942

crates/top/rerun_c/src/lib.rs

+51-18
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ use once_cell::sync::Lazy;
2020
use arrow_utils::arrow_array_from_c_ffi;
2121
use re_sdk::{
2222
external::nohash_hasher::IntMap,
23-
log::{Chunk, ChunkComponents, ChunkId, PendingRow, TimeColumn},
23+
log::{Chunk, ChunkId, PendingRow, TimeColumn},
2424
time::TimeType,
25-
ComponentDescriptor, ComponentName, EntityPath, RecordingStream, RecordingStreamBuilder,
26-
StoreKind, TimePoint, Timeline,
25+
ComponentDescriptor, EntityPath, RecordingStream, RecordingStreamBuilder, StoreKind, TimePoint,
26+
Timeline,
2727
};
2828
use recording_streams::{recording_stream, RECORDING_STREAMS};
2929

@@ -161,10 +161,18 @@ pub struct CStoreInfo {
161161
pub store_kind: CStoreKind,
162162
}
163163

164+
/// See `rr_component_descriptor` in the C header.
165+
#[repr(C)]
166+
pub struct CComponentDescriptor {
167+
pub archetype_name: CStringView,
168+
pub archetype_field_name: CStringView,
169+
pub component_name: CStringView,
170+
}
171+
164172
/// See `rr_component_type` in the C header.
165173
#[repr(C)]
166174
pub struct CComponentType {
167-
pub name: CStringView,
175+
pub descriptor: CComponentDescriptor,
168176
pub schema: arrow2::ffi::ArrowSchema,
169177
}
170178

@@ -341,8 +349,30 @@ pub extern "C" fn rr_spawn(spawn_opts: *const CSpawnOptions, error: *mut CError)
341349
fn rr_register_component_type_impl(
342350
component_type: &CComponentType,
343351
) -> Result<CComponentTypeHandle, CError> {
344-
let component_name = component_type.name.as_str("component_type.name")?;
345-
let component_name = ComponentName::from(component_name);
352+
let CComponentDescriptor {
353+
archetype_name,
354+
archetype_field_name,
355+
component_name,
356+
} = &component_type.descriptor;
357+
358+
let archetype_name = if !archetype_name.is_null() {
359+
Some(archetype_name.as_str("component_type.descriptor.archetype_name")?)
360+
} else {
361+
None
362+
};
363+
let archetype_field_name = if !archetype_field_name.is_null() {
364+
Some(archetype_field_name.as_str("component_type.descriptor.archetype_field_name")?)
365+
} else {
366+
None
367+
};
368+
let component_name = component_name.as_str("component_type.descriptor.component_name")?;
369+
370+
let component_descr = ComponentDescriptor {
371+
archetype_name: archetype_name.map(Into::into),
372+
archetype_field_name: archetype_field_name.map(Into::into),
373+
component_name: component_name.into(),
374+
};
375+
346376
let schema =
347377
unsafe { arrow2::ffi::import_field_from_c(&component_type.schema) }.map_err(|err| {
348378
CError::new(
@@ -353,7 +383,7 @@ fn rr_register_component_type_impl(
353383

354384
Ok(COMPONENT_TYPES
355385
.write()
356-
.register(component_name, schema.data_type))
386+
.register(component_descr, schema.data_type))
357387
}
358388

359389
#[allow(unsafe_code)]
@@ -790,7 +820,7 @@ fn rr_recording_stream_log_impl(
790820
let component_type = component_type_registry.get(*component_type)?;
791821
let datatype = component_type.datatype.clone();
792822
let values = unsafe { arrow_array_from_c_ffi(array, datatype) }?;
793-
components.insert(ComponentDescriptor::new(component_type.name), values);
823+
components.insert(component_type.descriptor.clone(), values);
794824
}
795825
}
796826

@@ -978,20 +1008,23 @@ fn rr_recording_stream_send_columns_impl(
9781008
)
9791009
})?;
9801010

981-
Ok((ComponentDescriptor::new(component_type.name), component_values.clone()))
1011+
Ok((component_type.descriptor.clone(), component_values.clone()))
9821012
})
9831013
.collect::<Result<_, CError>>()?
9841014
};
9851015

986-
let components: ChunkComponents = components.into_iter().collect();
987-
988-
let chunk = Chunk::from_auto_row_ids(id, entity_path.into(), time_columns, components)
989-
.map_err(|err| {
990-
CError::new(
991-
CErrorCode::RecordingStreamChunkValidationFailure,
992-
&format!("Failed to create chunk: {err}"),
993-
)
994-
})?;
1016+
let chunk = Chunk::from_auto_row_ids(
1017+
id,
1018+
entity_path.into(),
1019+
time_columns,
1020+
components.into_iter().collect(),
1021+
)
1022+
.map_err(|err| {
1023+
CError::new(
1024+
CErrorCode::RecordingStreamChunkValidationFailure,
1025+
&format!("Failed to create chunk: {err}"),
1026+
)
1027+
})?;
9951028

9961029
stream.send_chunk(chunk);
9971030

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <rerun.hpp>
2+
3+
int main() {
4+
const auto rec = rerun::RecordingStream("rerun_example_descriptors_builtin_archetype");
5+
rec.spawn().exit_on_failure();
6+
7+
rec.log_static("data", rerun::Points3D({{1.0f, 2.0f, 3.0f}}).with_radii({0.3f, 0.2f, 0.1f}));
8+
9+
// The tags are indirectly checked by the Rust version (have a look over there for more info).
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <rerun.hpp>
2+
3+
int main() {
4+
const auto rec = rerun::RecordingStream("rerun_example_descriptors_builtin_component");
5+
rec.spawn().exit_on_failure();
6+
7+
rerun::Position3D positions[1] = {{1.0f, 2.0f, 3.0f}};
8+
rec.log_static("data", positions);
9+
10+
// The tags are indirectly checked by the Rust version (have a look over there for more info).
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include <rerun.hpp>
2+
#include <vector>
3+
4+
struct CustomPosition3D {
5+
rerun::components::Position3D position;
6+
};
7+
8+
template <>
9+
struct rerun::Loggable<CustomPosition3D> {
10+
static constexpr ComponentDescriptor Descriptor = "user.CustomPosition3D";
11+
12+
static const std::shared_ptr<arrow::DataType>& arrow_datatype() {
13+
return rerun::Loggable<rerun::components::Position3D>::arrow_datatype();
14+
}
15+
16+
// TODO(#4257) should take a rerun::Collection instead of pointer and size.
17+
static rerun::Result<std::shared_ptr<arrow::Array>> to_arrow(
18+
const CustomPosition3D* instances, size_t num_instances
19+
) {
20+
return rerun::Loggable<rerun::components::Position3D>::to_arrow(
21+
reinterpret_cast<const rerun::components::Position3D*>(instances),
22+
num_instances
23+
);
24+
}
25+
};
26+
27+
/// A custom archetype that extends Rerun's builtin `rerun::Points3D` archetype with a custom component.
28+
struct CustomPoints3D {
29+
static constexpr const char IndicatorComponentName[] = "user.CustomPoints3DIndicator";
30+
using IndicatorComponent = rerun::components::IndicatorComponent<IndicatorComponentName>;
31+
32+
rerun::Collection<CustomPosition3D> positions;
33+
std::optional<rerun::Collection<rerun::Color>> colors;
34+
};
35+
36+
template <>
37+
struct rerun::AsComponents<CustomPoints3D> {
38+
static Result<std::vector<ComponentBatch>> serialize(const CustomPoints3D& archetype) {
39+
std::vector<rerun::ComponentBatch> batches;
40+
41+
CustomPoints3D::IndicatorComponent indicator;
42+
batches.push_back(ComponentBatch::from_loggable(indicator).value_or_throw());
43+
44+
// TODO: with_methods would be nice
45+
auto positions_descr = rerun::ComponentDescriptor(
46+
"user.CustomArchetype",
47+
"positions",
48+
Loggable<CustomPosition3D>::Descriptor.component_name
49+
);
50+
batches.push_back(
51+
ComponentBatch::from_loggable(archetype.positions, positions_descr).value_or_throw()
52+
);
53+
54+
if (archetype.colors) {
55+
// TODO: with_methods would be nice
56+
auto colors_descr = rerun::ComponentDescriptor(
57+
"user.CustomArchetype",
58+
"colors",
59+
Loggable<rerun::Color>::Descriptor.component_name
60+
);
61+
batches.push_back(
62+
ComponentBatch::from_loggable(archetype.colors, colors_descr).value_or_throw()
63+
);
64+
}
65+
66+
return batches;
67+
}
68+
};
69+
70+
int main() {
71+
const auto rec = rerun::RecordingStream("rerun_example_descriptors_custom_archetype");
72+
rec.spawn().exit_on_failure();
73+
74+
CustomPosition3D positions[1] = {rerun::components::Position3D{1.0f, 2.0f, 3.0f}};
75+
rerun::Color colors[1] = {rerun::Color(0xFF00FFFF)};
76+
77+
rec.log_static("data", CustomPoints3D{positions, colors});
78+
79+
// The tags are indirectly checked by the Rust version (have a look over there for more info).
80+
}

0 commit comments

Comments
 (0)