Skip to content

Commit

Permalink
C++ codegen of structs and unions (#2707)
Browse files Browse the repository at this point in the history
* Part of #2647

### What
This declares all C++ types and their fields. A matching `#include` list
is also included. The resulting C++ builds.

Test it yourself with `cargo codegen &&
./examples/cpp/minimal/build_and_run.sh`

Sum-types are implemented via "tagged unions" approach, basically an
emulation of how Rust does it under the hood. see #2647 for details.

### Done:
* struct declarations
* enum declarations
* enum destructors
* enum move semantics
* enum static constructors
* Implicit constructors for enums
* Implicit constructor for single-fields structs (e.g. `Vec3D`)

### Still left to do:
* Arrow-serialization
* Helper functions for building archetypes (needs design)

### Things I think we should punt on:
* Copy constructors
* Copy assignment operator

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/2707) (if
applicable)

- [PR Build Summary](https://build.rerun.io/pr/2707)
- [Docs
preview](https://rerun.io/preview/pr%3Aemilk%2Fcodegen-cpp-struct/docs)
- [Examples
preview](https://rerun.io/preview/pr%3Aemilk%2Fcodegen-cpp-struct/examples)
  • Loading branch information
emilk authored Jul 19, 2023
1 parent e8520f6 commit d77d5ec
Show file tree
Hide file tree
Showing 60 changed files with 2,091 additions and 189 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ AlwaysBreakBeforeMultilineStrings: true
BinPackArguments: false
ColumnLimit: 100
ContinuationIndentWidth: 4
EmptyLineBeforeAccessModifier: LogicalBlock
IndentWidth: 4
IndentWrappedFunctionNames: true
InsertTrailingCommas: Wrapped
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
PointerAlignment: Left
SeparateDefinitionBlocks: Always
SpacesBeforeTrailingComments: 1
2 changes: 1 addition & 1 deletion crates/re_types/source_hash.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This is a sha256 hash for all direct and indirect dependencies of this crate's build script.
# It can be safely removed at anytime to force the build script to run again.
# Check out build.rs to see how it's computed.
d5ccdc80e148c8058d3885418f9c701fbae4a5fbb92defb9bd625ad27ed97a25
289571cd5bcef516a43ead1678f39054c300890396d13933dc26d9294a07dffe
2 changes: 1 addition & 1 deletion crates/re_types_builder/src/arrow_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl From<DataType> for LazyDatatype {
DataType::Extension(name, datatype, metadata) => {
LazyDatatype::Extension(name, Box::new((*datatype).into()), metadata)
}
_ => unimplemented!("{datatype:#?}"), // NOLINT
_ => unimplemented!("{datatype:#?}"),
}
}
}
Expand Down
Loading

1 comment on commit d77d5ec

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Rust Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.25.

Benchmark suite Current: d77d5ec Previous: e8520f6 Ratio
batch_points_arrow/encode_log_msg 89184 ns/iter (± 188) 49631 ns/iter (± 154) 1.80

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.