From 506bf2b28abdb091ee25dcfdb1567b9be1d5c8c9 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 6 Jul 2023 13:02:08 +0200 Subject: [PATCH 01/11] Move C++ SDK to own repository --- crates/rerun_c/{example_c => example}/.gitignore | 0 crates/rerun_c/{example_c => example}/Makefile | 0 crates/rerun_c/{example_c => example}/README.md | 0 crates/rerun_c/{example_c => example}/main.c | 0 crates/rerun_c/run_examples.sh | 3 +-- rerun_cpp/README.md | 6 ++++++ .../rerun_c/example_cpp => rerun_cpp/example}/.gitignore | 0 .../example_cpp => rerun_cpp/example}/CMakeLists.txt | 7 ++++--- .../rerun_c/example_cpp => rerun_cpp/example}/README.md | 0 .../example_cpp => rerun_cpp/example}/build_and_run.sh | 0 {crates/rerun_c/example_cpp => rerun_cpp/example}/main.cpp | 0 {crates/rerun_c => rerun_cpp}/src/rerun.hpp | 0 12 files changed, 11 insertions(+), 5 deletions(-) rename crates/rerun_c/{example_c => example}/.gitignore (100%) rename crates/rerun_c/{example_c => example}/Makefile (100%) rename crates/rerun_c/{example_c => example}/README.md (100%) rename crates/rerun_c/{example_c => example}/main.c (100%) create mode 100644 rerun_cpp/README.md rename {crates/rerun_c/example_cpp => rerun_cpp/example}/.gitignore (100%) rename {crates/rerun_c/example_cpp => rerun_cpp/example}/CMakeLists.txt (91%) rename {crates/rerun_c/example_cpp => rerun_cpp/example}/README.md (100%) rename {crates/rerun_c/example_cpp => rerun_cpp/example}/build_and_run.sh (100%) rename {crates/rerun_c/example_cpp => rerun_cpp/example}/main.cpp (100%) rename {crates/rerun_c => rerun_cpp}/src/rerun.hpp (100%) diff --git a/crates/rerun_c/example_c/.gitignore b/crates/rerun_c/example/.gitignore similarity index 100% rename from crates/rerun_c/example_c/.gitignore rename to crates/rerun_c/example/.gitignore diff --git a/crates/rerun_c/example_c/Makefile b/crates/rerun_c/example/Makefile similarity index 100% rename from crates/rerun_c/example_c/Makefile rename to crates/rerun_c/example/Makefile diff --git a/crates/rerun_c/example_c/README.md b/crates/rerun_c/example/README.md similarity index 100% rename from crates/rerun_c/example_c/README.md rename to crates/rerun_c/example/README.md diff --git a/crates/rerun_c/example_c/main.c b/crates/rerun_c/example/main.c similarity index 100% rename from crates/rerun_c/example_c/main.c rename to crates/rerun_c/example/main.c diff --git a/crates/rerun_c/run_examples.sh b/crates/rerun_c/run_examples.sh index 56f9eb5835e0..e4a3770cf04c 100755 --- a/crates/rerun_c/run_examples.sh +++ b/crates/rerun_c/run_examples.sh @@ -4,5 +4,4 @@ set -eu script_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) set -x -(cd "$script_path/example_c" && make run) -"$script_path/example_cpp/build_and_run.sh" +(cd "$script_path/example" && make run) diff --git a/rerun_cpp/README.md b/rerun_cpp/README.md new file mode 100644 index 000000000000..8518a5e9a595 --- /dev/null +++ b/rerun_cpp/README.md @@ -0,0 +1,6 @@ +# Rerun C++ SDK + +This is not yet ready to be used. + +## Test it +rerun_cpp/example/build_and_run.sh diff --git a/crates/rerun_c/example_cpp/.gitignore b/rerun_cpp/example/.gitignore similarity index 100% rename from crates/rerun_c/example_cpp/.gitignore rename to rerun_cpp/example/.gitignore diff --git a/crates/rerun_c/example_cpp/CMakeLists.txt b/rerun_cpp/example/CMakeLists.txt similarity index 91% rename from crates/rerun_c/example_cpp/CMakeLists.txt rename to rerun_cpp/example/CMakeLists.txt index f72639dcd412..641436bfbeac 100644 --- a/crates/rerun_c/example_cpp/CMakeLists.txt +++ b/rerun_cpp/example/CMakeLists.txt @@ -44,12 +44,12 @@ else() endif() if(APPLE) - target_link_libraries(rerun_example PRIVATE ${CMAKE_SOURCE_DIR}/../../../target/debug/librerun_c.a) + target_link_libraries(rerun_example PRIVATE ${CMAKE_SOURCE_DIR}/../../target/debug/librerun_c.a) target_link_libraries(rerun_example PRIVATE "-framework CoreFoundation" "-framework IOKit") endif() if(LINUX) - target_link_libraries(rerun_example PRIVATE ${CMAKE_SOURCE_DIR}/../../../target/debug/librerun_c.a) + target_link_libraries(rerun_example PRIVATE ${CMAKE_SOURCE_DIR}/../../target/debug/librerun_c.a) target_link_libraries(rerun_example PRIVATE "-lm") endif() @@ -59,6 +59,7 @@ else() target_link_libraries(rerun_example PRIVATE Arrow::arrow_static) endif() -include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/../src) # for rerun.hpp +include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/../../crates/rerun_c/src) # for rerun.h (Rerun C SDK) +include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/../src) # for rerun.hpp (Rerun C++ SDK) target_link_libraries(rerun_example PRIVATE loguru::loguru) diff --git a/crates/rerun_c/example_cpp/README.md b/rerun_cpp/example/README.md similarity index 100% rename from crates/rerun_c/example_cpp/README.md rename to rerun_cpp/example/README.md diff --git a/crates/rerun_c/example_cpp/build_and_run.sh b/rerun_cpp/example/build_and_run.sh similarity index 100% rename from crates/rerun_c/example_cpp/build_and_run.sh rename to rerun_cpp/example/build_and_run.sh diff --git a/crates/rerun_c/example_cpp/main.cpp b/rerun_cpp/example/main.cpp similarity index 100% rename from crates/rerun_c/example_cpp/main.cpp rename to rerun_cpp/example/main.cpp diff --git a/crates/rerun_c/src/rerun.hpp b/rerun_cpp/src/rerun.hpp similarity index 100% rename from crates/rerun_c/src/rerun.hpp rename to rerun_cpp/src/rerun.hpp From 7f49d8d97b5c70d62fed310bfd969cf45117fa8a Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 6 Jul 2023 14:24:36 +0200 Subject: [PATCH 02/11] Split CMakeLists.txt into a project of three files and move C++ SDK definitions to a .cpp file --- rerun_cpp/.gitignore | 1 + rerun_cpp/CMakeLists.txt | 6 ++++ rerun_cpp/build_and_run.sh | 16 +++++++++ rerun_cpp/example/.gitignore | 3 -- rerun_cpp/example/CMakeLists.txt | 47 +++--------------------- rerun_cpp/example/build_and_run.sh | 14 -------- rerun_cpp/example/main.cpp | 3 ++ rerun_cpp/src/CMakeLists.txt | 58 ++++++++++++++++++++++++++++++ rerun_cpp/src/rerun.cpp | 54 ++++++++++++++++++++++++++++ rerun_cpp/src/rerun.hpp | 54 ++-------------------------- 10 files changed, 146 insertions(+), 110 deletions(-) create mode 100644 rerun_cpp/.gitignore create mode 100644 rerun_cpp/CMakeLists.txt create mode 100755 rerun_cpp/build_and_run.sh delete mode 100644 rerun_cpp/example/.gitignore delete mode 100755 rerun_cpp/example/build_and_run.sh create mode 100644 rerun_cpp/src/CMakeLists.txt create mode 100644 rerun_cpp/src/rerun.cpp diff --git a/rerun_cpp/.gitignore b/rerun_cpp/.gitignore new file mode 100644 index 000000000000..567609b1234a --- /dev/null +++ b/rerun_cpp/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/rerun_cpp/CMakeLists.txt b/rerun_cpp/CMakeLists.txt new file mode 100644 index 000000000000..13f41954602f --- /dev/null +++ b/rerun_cpp/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.16) + +project(rerun_cpp_proj LANGUAGES CXX) + +add_subdirectory(src) # The Rerun C++ SDK library +add_subdirectory(example) diff --git a/rerun_cpp/build_and_run.sh b/rerun_cpp/build_and_run.sh new file mode 100755 index 000000000000..58ef0b2e04bf --- /dev/null +++ b/rerun_cpp/build_and_run.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -eu +script_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) +cd "$script_path" +set -x + +mkdir -p build +pushd build + cargo build -p rerun_c # TODO(emilk): add this to CMakelists.txt instead? + cmake -DCMAKE_BUILD_TYPE=Debug .. + make # VERBOSE=1 +popd + +./build/example/rerun_example + diff --git a/rerun_cpp/example/.gitignore b/rerun_cpp/example/.gitignore deleted file mode 100644 index 56b46229372f..000000000000 --- a/rerun_cpp/example/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.bin -*.o -build/ diff --git a/rerun_cpp/example/CMakeLists.txt b/rerun_cpp/example/CMakeLists.txt index 641436bfbeac..9cbc69bac78e 100644 --- a/rerun_cpp/example/CMakeLists.txt +++ b/rerun_cpp/example/CMakeLists.txt @@ -1,40 +1,18 @@ cmake_minimum_required(VERSION 3.16) -project(RerunExample) - -option(ARROW_LINK_SHARED "Link to the Arrow shared library" ON) - -find_package(Arrow REQUIRED) - -set(CMAKE_DL_LIBS "dl") # Required by Loguru for backtraces +# project(RerunExample) # ------------------------------------------------------------------------------ -# Loguru, see https://github.com/emilk/loguru/blob/master/loguru_cmake_example/CMakeLists.txt -include(FetchContent) -FetchContent_Declare(LoguruGitRepo - GIT_REPOSITORY "https://github.com/emilk/loguru" # can be a filesystem path - GIT_TAG "master" -) - -# set any loguru compile-time flags before calling MakeAvailable() -set(LOGURU_STACKTRACES 1) -FetchContent_MakeAvailable(LoguruGitRepo) # defines target 'loguru::loguru' -# ------------------------------------------------------------------------------ +# Arrow requires a C++17 compliant compiler if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) endif() -# Arrow requires a C++17 compliant compiler -set(CMAKE_CXX_STANDARD_REQUIRED ON) - if(NOT DEFINED CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() -message(STATUS "Arrow version: ${ARROW_VERSION}") -message(STATUS "Arrow SO version: ${ARROW_FULL_SO_VERSION}") - add_executable(rerun_example main.cpp) if(MSVC) @@ -43,23 +21,8 @@ else() target_compile_options(rerun_example PRIVATE -Wall -Wextra -Wpedantic -Wcast-align -Wcast-qual -Wformat=2 -Wmissing-include-dirs -Wnull-dereference -Woverloaded-virtual -Wpointer-arith -Wshadow -Wswitch-enum -Wvla -Wno-sign-compare -Wconversion -Wunused -Wold-style-cast -Wno-missing-braces) endif() -if(APPLE) - target_link_libraries(rerun_example PRIVATE ${CMAKE_SOURCE_DIR}/../../target/debug/librerun_c.a) - target_link_libraries(rerun_example PRIVATE "-framework CoreFoundation" "-framework IOKit") -endif() - -if(LINUX) - target_link_libraries(rerun_example PRIVATE ${CMAKE_SOURCE_DIR}/../../target/debug/librerun_c.a) - target_link_libraries(rerun_example PRIVATE "-lm") -endif() - -if(ARROW_LINK_SHARED) - target_link_libraries(rerun_example PRIVATE Arrow::arrow_shared) -else() - target_link_libraries(rerun_example PRIVATE Arrow::arrow_static) -endif() +include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/../src) # For rerun.hpp (Rerun C++ SDK) -include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/../../crates/rerun_c/src) # for rerun.h (Rerun C SDK) -include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/../src) # for rerun.hpp (Rerun C++ SDK) +include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/../../crates/rerun_c/src) # For rerun.h (Rerun C SDK) TODO: remove -target_link_libraries(rerun_example PRIVATE loguru::loguru) +target_link_libraries(rerun_example PRIVATE loguru::loguru rerun_sdk) diff --git a/rerun_cpp/example/build_and_run.sh b/rerun_cpp/example/build_and_run.sh deleted file mode 100755 index 1f2c2b8dee5c..000000000000 --- a/rerun_cpp/example/build_and_run.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -set -eu -script_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) -cd "$script_path" -set -x - -mkdir -p build -cd build - -cargo build -p rerun_c # TODO(emilk): add this to CMakelists.txt instead? -cmake -DCMAKE_BUILD_TYPE=Debug .. -make -./rerun_example diff --git a/rerun_cpp/example/main.cpp b/rerun_cpp/example/main.cpp index 72edea4d1d9c..120ff509ea8a 100644 --- a/rerun_cpp/example/main.cpp +++ b/rerun_cpp/example/main.cpp @@ -2,6 +2,9 @@ #define RERUN_WITH_ARROW 1 +#include // TODO: use C++ wrappers instead + +#include #include int main(int argc, char** argv) { diff --git a/rerun_cpp/src/CMakeLists.txt b/rerun_cpp/src/CMakeLists.txt new file mode 100644 index 000000000000..ed43f1de32fd --- /dev/null +++ b/rerun_cpp/src/CMakeLists.txt @@ -0,0 +1,58 @@ +cmake_minimum_required(VERSION 3.16) + +add_library(rerun_sdk rerun.cpp) + +# ------------------------------------------------------------------------------ + +# For rerun.h (Rerun C SDK): +include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/../../crates/rerun_c/src) + +# Make sure the compiler can find include files for rerun +# when other libraries or executables link to rerun: +target_include_directories(rerun_sdk PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +# ------------------------------------------------------------------------------ +# Loguru logging library (https://github.com/emilk/loguru): +set(CMAKE_DL_LIBS "dl") # Required by Loguru for backtraces + +# Loguru, see https://github.com/emilk/loguru/blob/master/loguru_cmake_example/CMakeLists.txt +include(FetchContent) +FetchContent_Declare(LoguruGitRepo + GIT_REPOSITORY "https://github.com/emilk/loguru" # can be a filesystem path + GIT_TAG "master" +) + +# set any loguru compile-time flags before calling MakeAvailable() +set(LOGURU_STACKTRACES 1) +FetchContent_MakeAvailable(LoguruGitRepo) # defines target 'loguru::loguru' + +target_link_libraries(rerun_sdk PRIVATE loguru::loguru) + +# ------------------------------------------------------------------------------ +if(APPLE) + target_link_libraries(rerun_sdk PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug/librerun_c.a) + target_link_libraries(rerun_sdk PRIVATE "-framework CoreFoundation" "-framework IOKit") +endif() + +if(LINUX) + target_link_libraries(rerun_sdk PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug/librerun_c.a) + target_link_libraries(rerun_sdk PRIVATE "-lm") +endif() + +# ----------------------------------------------------------------------------- +# Arrow: +option(ARROW_LINK_SHARED "Link to the Arrow shared library" ON) + +find_package(Arrow REQUIRED) + +# Arrow requires a C++17 compliant compiler +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +message(STATUS "Arrow version: ${ARROW_VERSION}") +message(STATUS "Arrow SO version: ${ARROW_FULL_SO_VERSION}") + +if(ARROW_LINK_SHARED) + target_link_libraries(rerun_sdk PRIVATE Arrow::arrow_shared) +else() + target_link_libraries(rerun_sdk PRIVATE Arrow::arrow_static) +endif() diff --git a/rerun_cpp/src/rerun.cpp b/rerun_cpp/src/rerun.cpp new file mode 100644 index 000000000000..6100aa0f15e7 --- /dev/null +++ b/rerun_cpp/src/rerun.cpp @@ -0,0 +1,54 @@ +#include "rerun.hpp" + +#include +#include +#include +#include + +#include + +namespace rerun { + const char* version_string() { + return rr_version_string(); + } + + arrow::Result> points3(size_t num_points, const float* xyz) { + arrow::MemoryPool* pool = arrow::default_memory_pool(); + + auto x_builder = std::make_shared(pool); + auto y_builder = std::make_shared(pool); + auto z_builder = std::make_shared(pool); + + auto nullable = false; + + auto data_type = arrow::struct_({field("x", arrow::float32(), nullable), + field("y", arrow::float32(), nullable), + field("z", arrow::float32(), nullable)}); + auto struct_builder = + arrow::StructBuilder(data_type, pool, {x_builder, y_builder, z_builder}); + + for (size_t i = 0; i < num_points; ++i) { + ARROW_RETURN_NOT_OK(struct_builder.Append()); + ARROW_RETURN_NOT_OK(x_builder->Append(xyz[3 * i + 0])); + ARROW_RETURN_NOT_OK(y_builder->Append(xyz[3 * i + 1])); + ARROW_RETURN_NOT_OK(z_builder->Append(xyz[3 * i + 2])); + } + + std::shared_ptr array; + ARROW_RETURN_NOT_OK(struct_builder.Finish(&array)); + + auto name = "points"; // Unused, but should be the name of the field in the archetype + auto schema = arrow::schema({arrow::field(name, data_type, nullable)}); + + return arrow::Table::Make(schema, {array}); + } + + arrow::Result> ipc_from_table(const arrow::Table& table) { + ERROR_CONTEXT("ipc_from_table", ""); + ARROW_ASSIGN_OR_RAISE(auto output, arrow::io::BufferOutputStream::Create()); + ARROW_ASSIGN_OR_RAISE(auto writer, arrow::ipc::MakeStreamWriter(output, table.schema())); + ARROW_RETURN_NOT_OK(writer->WriteTable(table)); + ARROW_RETURN_NOT_OK(writer->Close()); + return output->Finish(); + } +} // namespace rerun diff --git a/rerun_cpp/src/rerun.hpp b/rerun_cpp/src/rerun.hpp index 1f84350e4b5e..3c4c231bfa26 100644 --- a/rerun_cpp/src/rerun.hpp +++ b/rerun_cpp/src/rerun.hpp @@ -3,69 +3,21 @@ #ifndef RERUN_HPP #define RERUN_HPP -#include - namespace rerun { - inline const char* version_string() { - return rr_version_string(); - } + const char* version_string(); } // namespace rerun // ---------------------------------------------------------------------------- // Arrow integration -#if RERUN_WITH_ARROW - #include -#include -#include - -#include namespace rerun { - arrow::Result> points3(size_t num_points, const float* xyz) { - arrow::MemoryPool* pool = arrow::default_memory_pool(); - - auto x_builder = std::make_shared(pool); - auto y_builder = std::make_shared(pool); - auto z_builder = std::make_shared(pool); - - auto nullable = false; - - auto data_type = arrow::struct_({field("x", arrow::float32(), nullable), - field("y", arrow::float32(), nullable), - field("z", arrow::float32(), nullable)}); - auto struct_builder = - arrow::StructBuilder(data_type, pool, {x_builder, y_builder, z_builder}); + arrow::Result> points3(size_t num_points, const float* xyz); - for (size_t i = 0; i < num_points; ++i) { - ARROW_RETURN_NOT_OK(struct_builder.Append()); - ARROW_RETURN_NOT_OK(x_builder->Append(xyz[3 * i + 0])); - ARROW_RETURN_NOT_OK(y_builder->Append(xyz[3 * i + 1])); - ARROW_RETURN_NOT_OK(z_builder->Append(xyz[3 * i + 2])); - } - - std::shared_ptr array; - ARROW_RETURN_NOT_OK(struct_builder.Finish(&array)); - - auto name = "points"; // Unused, but should be the name of the field in the archetype - auto schema = arrow::schema({arrow::field(name, data_type, nullable)}); - - return arrow::Table::Make(schema, {array}); - } - - arrow::Result> ipc_from_table(const arrow::Table& table) { - ERROR_CONTEXT("ipc_from_table", ""); - ARROW_ASSIGN_OR_RAISE(auto output, arrow::io::BufferOutputStream::Create()); - ARROW_ASSIGN_OR_RAISE(auto writer, arrow::ipc::MakeStreamWriter(output, table.schema())); - ARROW_RETURN_NOT_OK(writer->WriteTable(table)); - ARROW_RETURN_NOT_OK(writer->Close()); - return output->Finish(); - } + arrow::Result> ipc_from_table(const arrow::Table& table); } // namespace rerun -#endif // RERUN_WITH_ARROW - // ---------------------------------------------------------------------------- #endif // RERUN_HPP From 46c098f97535339577b02554285c3934116a4afe Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 6 Jul 2023 14:26:14 +0200 Subject: [PATCH 03/11] Rename C++ namespace to rr --- rerun_cpp/example/main.cpp | 6 +++--- rerun_cpp/src/rerun.cpp | 4 ++-- rerun_cpp/src/rerun.hpp | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/rerun_cpp/example/main.cpp b/rerun_cpp/example/main.cpp index 120ff509ea8a..f713f8d743e9 100644 --- a/rerun_cpp/example/main.cpp +++ b/rerun_cpp/example/main.cpp @@ -12,7 +12,7 @@ int main(int argc, char** argv) { loguru::g_preamble_thread = false; loguru::init(argc, argv); // installs signal handlers - LOG_F(INFO, "Rerun C++ SDK version: %s", rerun::version_string()); + LOG_F(INFO, "Rerun C++ SDK version: %s", rr::version_string()); const rr_store_info store_info = { .application_id = "c-example-app", @@ -21,8 +21,8 @@ int main(int argc, char** argv) { rr_recording_stream rec_stream = rr_recording_stream_new(&store_info, "0.0.0.0:9876"); float xyz[9] = {0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 5.0, 5.0, 5.0}; - auto points = rerun::points3(3, xyz).ValueOrDie(); - auto buffer = rerun::ipc_from_table(*points).ValueOrDie(); + auto points = rr::points3(3, xyz).ValueOrDie(); + auto buffer = rr::ipc_from_table(*points).ValueOrDie(); const rr_data_cell data_cells[1] = {rr_data_cell{ .component_name = "rerun.point3d", diff --git a/rerun_cpp/src/rerun.cpp b/rerun_cpp/src/rerun.cpp index 6100aa0f15e7..2cc6056e441c 100644 --- a/rerun_cpp/src/rerun.cpp +++ b/rerun_cpp/src/rerun.cpp @@ -7,7 +7,7 @@ #include -namespace rerun { +namespace rr { const char* version_string() { return rr_version_string(); } @@ -51,4 +51,4 @@ namespace rerun { ARROW_RETURN_NOT_OK(writer->Close()); return output->Finish(); } -} // namespace rerun +} // namespace rr diff --git a/rerun_cpp/src/rerun.hpp b/rerun_cpp/src/rerun.hpp index 3c4c231bfa26..d3f9520d8ab7 100644 --- a/rerun_cpp/src/rerun.hpp +++ b/rerun_cpp/src/rerun.hpp @@ -3,20 +3,20 @@ #ifndef RERUN_HPP #define RERUN_HPP -namespace rerun { +namespace rr { const char* version_string(); -} // namespace rerun +} // namespace rr // ---------------------------------------------------------------------------- // Arrow integration #include -namespace rerun { +namespace rr { arrow::Result> points3(size_t num_points, const float* xyz); arrow::Result> ipc_from_table(const arrow::Table& table); -} // namespace rerun +} // namespace rr // ---------------------------------------------------------------------------- From 909bada3b1ac72a1cd51514c133035cf8f4fd6ca Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 6 Jul 2023 14:51:31 +0200 Subject: [PATCH 04/11] Only lint "GitHub" in .md files --- .github/workflows/reusable_pr_summary.yml | 2 +- scripts/ci/check_pr_checkboxes.py | 4 ++-- scripts/ci/generate_pr_summary.py | 6 +++--- scripts/ci/generate_prerelease_pip_index.py | 2 +- scripts/ci/update_pr_body.py | 6 +++--- scripts/lint.py | 17 ++++++++++------- scripts/upload_image.py | 2 +- 7 files changed, 21 insertions(+), 18 deletions(-) diff --git a/.github/workflows/reusable_pr_summary.yml b/.github/workflows/reusable_pr_summary.yml index 9db29d066f91..e6291fa5f13c 100644 --- a/.github/workflows/reusable_pr_summary.yml +++ b/.github/workflows/reusable_pr_summary.yml @@ -46,7 +46,7 @@ jobs: version: '>= 363.0.0' - name: Install deps - run: pip install google-cloud-storage Jinja2 PyGithub # NOLINT + run: pip install google-cloud-storage Jinja2 PyGithub - name: Render HTML template run: | diff --git a/scripts/ci/check_pr_checkboxes.py b/scripts/ci/check_pr_checkboxes.py index c1d33a9cd08f..06fa75fc6683 100755 --- a/scripts/ci/check_pr_checkboxes.py +++ b/scripts/ci/check_pr_checkboxes.py @@ -4,7 +4,7 @@ import argparse -from github import Github # NOLINT +from github import Github def main() -> None: @@ -14,7 +14,7 @@ def main() -> None: parser.add_argument("--pr-number", required=True, type=int, help="PR number") args = parser.parse_args() - gh = Github(args.github_token) # NOLINT + gh = Github(args.github_token) repo = gh.get_repo(args.github_repository) pr = repo.get_pull(args.pr_number) diff --git a/scripts/ci/generate_pr_summary.py b/scripts/ci/generate_pr_summary.py index 1c31cadf31eb..17d5b69a9865 100644 --- a/scripts/ci/generate_pr_summary.py +++ b/scripts/ci/generate_pr_summary.py @@ -7,7 +7,7 @@ This is expected to be run by the `reusable_pr_summary.yml` GitHub workflow. Requires the following packages: - pip install google-cloud-storage Jinja2 PyGithub # NOLINT + pip install google-cloud-storage Jinja2 PyGithub """ from __future__ import annotations @@ -16,14 +16,14 @@ import os from typing import Any -from github import Github # NOLINT +from github import Github from google.cloud import storage from jinja2 import Template def generate_pr_summary(github_token: str, github_repository: str, pr_number: int, upload: bool) -> None: # Initialize the GitHub and GCS clients - gh = Github(github_token) # NOLINT + gh = Github(github_token) gcs_client = storage.Client() # Get the list of commits associated with the PR diff --git a/scripts/ci/generate_prerelease_pip_index.py b/scripts/ci/generate_prerelease_pip_index.py index 0755b92b5c5d..e25ebc7e6408 100644 --- a/scripts/ci/generate_prerelease_pip_index.py +++ b/scripts/ci/generate_prerelease_pip_index.py @@ -7,7 +7,7 @@ This is expected to be run by the `reusable_pip_index.yml` GitHub workflow. Requires the following packages: - pip install google-cloud-storage Jinja2 PyGithub # NOLINT + pip install google-cloud-storage Jinja2 PyGithub """ from __future__ import annotations diff --git a/scripts/ci/update_pr_body.py b/scripts/ci/update_pr_body.py index b145cbeea1ec..d6bb347a8c68 100755 --- a/scripts/ci/update_pr_body.py +++ b/scripts/ci/update_pr_body.py @@ -6,7 +6,7 @@ This is expected to be run by the `reusable_update_pr_body.yml` GitHub workflow. Requires the following packages: - pip install Jinja2 PyGithub # NOLINT + pip install Jinja2 PyGithub """ from __future__ import annotations @@ -14,7 +14,7 @@ import logging import urllib.parse -from github import Github # NOLINT +from github import Github from jinja2 import DebugUndefined, select_autoescape from jinja2.sandbox import SandboxedEnvironment @@ -31,7 +31,7 @@ def main() -> None: parser.add_argument("--pr-number", required=True, type=int, help="PR number") args = parser.parse_args() - gh = Github(args.github_token) # NOLINT + gh = Github(args.github_token) repo = gh.get_repo(args.github_repository) pr = repo.get_pull(args.pr_number) diff --git a/scripts/lint.py b/scripts/lint.py index c0f00083a66b..a29fd00109c7 100755 --- a/scripts/lint.py +++ b/scripts/lint.py @@ -25,15 +25,16 @@ explicit_quotes = re.compile(r'[^(]\\"\{\w*\}\\"') # looks for: \"{foo}\" -def lint_line(line: str) -> str | None: +def lint_line(line: str, file_extension: str = "rs") -> str | None: if "NOLINT" in line: return None # NOLINT ignores the linter - if "Github" in line: - return "It's 'GitHub', not 'Github'" + if file_extension == "md": + if "Github" in line: + return "It's 'GitHub', not 'Github'" - if " github " in line: - return "It's 'GitHub', not 'github'" + if " github " in line: + return "It's 'GitHub', not 'github'" if "FIXME" in line: return "we prefer TODO over FIXME" @@ -370,13 +371,15 @@ def test_lint_workspace_deps() -> None: def lint_file(filepath: str, args: Any) -> int: + file_extension = filepath.split(".")[-1] + with open(filepath) as f: lines_in = f.readlines() num_errors = 0 for line_nr, line in enumerate(lines_in): - error = lint_line(line) + error = lint_line(line, file_extension) if error is not None: num_errors += 1 print(f"{filepath}:{line_nr+1}: {error}") @@ -438,7 +441,7 @@ def main() -> None: root_dirpath = os.path.abspath(f"{script_dirpath}/..") os.chdir(root_dirpath) - extensions = ["c", "cpp", "fbs", "h", "hpp" "html", "js", "md", "py", "rs", "sh", "toml", "wgsl", "yml"] + extensions = ["c", "cpp", "fbs", "h", "hpp" "html", "js", "md", "py", "rs", "sh", "toml", "txt", "wgsl", "yml"] exclude_dirs = {"env", "renv", "venv", "venv3.10", "target", "target_ra", "target_wasm", ".nox"} diff --git a/scripts/upload_image.py b/scripts/upload_image.py index 23afe61484e9..aaccf107c89e 100755 --- a/scripts/upload_image.py +++ b/scripts/upload_image.py @@ -7,7 +7,7 @@ ------------ Requires the following packages: - pip install google-cloud-storage # NOLINT + pip install google-cloud-storage Before running, you have to authenticate via the Google Cloud CLI: - Install it (https://cloud.google.com/storage/docs/gsutil_install) From 37fef019c7b27a8e3f483b66276a20ebb9b48d1a Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 6 Jul 2023 15:26:43 +0200 Subject: [PATCH 05/11] Write a proper C++ API --- .clang-format | 1 + _typos.toml | 2 +- crates/rerun_c/example/main.c | 2 +- rerun_cpp/README.md | 7 ++++ rerun_cpp/example/CMakeLists.txt | 2 -- rerun_cpp/example/main.cpp | 19 +++------- rerun_cpp/src/rerun.cpp | 61 ++++++++++++++++++++++++++++++++ rerun_cpp/src/rerun.hpp | 40 +++++++++++++++++++++ 8 files changed, 116 insertions(+), 18 deletions(-) diff --git a/.clang-format b/.clang-format index f978d57533af..b042635392c5 100644 --- a/.clang-format +++ b/.clang-format @@ -2,6 +2,7 @@ BasedOnStyle: Google # Make it slightly more similar to Rust. # Based loosly on https://gist.github.com/YodaEmbedding/c2c77dc693d11f3734d78489f9a6eea4 +AccessModifierOffset: -2 AllowShortBlocksOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: Empty diff --git a/_typos.toml b/_typos.toml index adb9d5b658d4..4fb279cb56d1 100644 --- a/_typos.toml +++ b/_typos.toml @@ -12,9 +12,9 @@ extend-exclude = [ [default.extend-words] lod = "lod" # level-of-detail -teh = "teh" # part of @teh-cmc ND = "ND" # np.NDArray somes = "somes" # many `Some` +teh = "teh" # part of @teh-cmc # American English: grey = "gray" diff --git a/crates/rerun_c/example/main.c b/crates/rerun_c/example/main.c index c04b9b5627ae..96eb424be291 100644 --- a/crates/rerun_c/example/main.c +++ b/crates/rerun_c/example/main.c @@ -8,7 +8,7 @@ int main(void) { .application_id = "c-example-app", .store_kind = RERUN_STORE_KIND_RECORDING, }; - rr_recording_stream rec_stream = rr_recording_stream_new(&store_info, "0.0.0.0:9876"); + rr_recording_stream rec_stream = rr_recording_stream_new(&store_info, "127.0.0.1:9876"); printf("rec_stream: %d\n", rec_stream); diff --git a/rerun_cpp/README.md b/rerun_cpp/README.md index 8518a5e9a595..c48e156dfa79 100644 --- a/rerun_cpp/README.md +++ b/rerun_cpp/README.md @@ -4,3 +4,10 @@ This is not yet ready to be used. ## Test it rerun_cpp/example/build_and_run.sh + +# TODO +* CI +* Code-gen +* Documentation +* Packaging +* Publishing diff --git a/rerun_cpp/example/CMakeLists.txt b/rerun_cpp/example/CMakeLists.txt index 9cbc69bac78e..af764b822b9c 100644 --- a/rerun_cpp/example/CMakeLists.txt +++ b/rerun_cpp/example/CMakeLists.txt @@ -23,6 +23,4 @@ endif() include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/../src) # For rerun.hpp (Rerun C++ SDK) -include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/../../crates/rerun_c/src) # For rerun.h (Rerun C SDK) TODO: remove - target_link_libraries(rerun_example PRIVATE loguru::loguru rerun_sdk) diff --git a/rerun_cpp/example/main.cpp b/rerun_cpp/example/main.cpp index f713f8d743e9..2570abbb4fed 100644 --- a/rerun_cpp/example/main.cpp +++ b/rerun_cpp/example/main.cpp @@ -2,8 +2,6 @@ #define RERUN_WITH_ARROW 1 -#include // TODO: use C++ wrappers instead - #include #include @@ -14,25 +12,18 @@ int main(int argc, char** argv) { LOG_F(INFO, "Rerun C++ SDK version: %s", rr::version_string()); - const rr_store_info store_info = { - .application_id = "c-example-app", - .store_kind = RERUN_STORE_KIND_RECORDING, - }; - rr_recording_stream rec_stream = rr_recording_stream_new(&store_info, "0.0.0.0:9876"); + auto rr_stream = rr::RecordingStream{"c-example-app", "127.0.0.1:9876"}; float xyz[9] = {0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 5.0, 5.0, 5.0}; auto points = rr::points3(3, xyz).ValueOrDie(); auto buffer = rr::ipc_from_table(*points).ValueOrDie(); - const rr_data_cell data_cells[1] = {rr_data_cell{ + const rr::DataCell data_cells[1] = {rr::DataCell{ .component_name = "rerun.point3d", - .num_bytes = static_cast(buffer->size()), + .num_bytes = static_cast(buffer->size()), .bytes = buffer->data(), }}; - const rr_data_row data_row = { - .entity_path = "points", .num_instances = 3, .num_data_cells = 1, .data_cells = data_cells}; - rr_log(rec_stream, &data_row); - - rr_recording_stream_free(rec_stream); + uint32_t num_instances = 3; + rr_stream.log_data_row("points", num_instances, 1, data_cells); } diff --git a/rerun_cpp/src/rerun.cpp b/rerun_cpp/src/rerun.cpp index 2cc6056e441c..f728f4e74fbb 100644 --- a/rerun_cpp/src/rerun.cpp +++ b/rerun_cpp/src/rerun.cpp @@ -12,6 +12,67 @@ namespace rr { return rr_version_string(); } + // ------------------------------------------------------------------------ + + RecordingStream RecordingStream::s_global; + + RecordingStream::RecordingStream(const char* app_id, const char* addr, StoreKind store_kind) { + ERROR_CONTEXT("RecordingStream", ""); + + int32_t c_store_kind; + switch (store_kind) { + case StoreKind::Recording: + c_store_kind = RERUN_STORE_KIND_RECORDING; + break; + case StoreKind::Blueprint: + c_store_kind = RERUN_STORE_KIND_BLUEPRINT; + break; + } + + rr_store_info store_info = { + .application_id = app_id, + .store_kind = c_store_kind, + }; + this->_id = rr_recording_stream_new(&store_info, addr); + } + + RecordingStream::~RecordingStream() { + rr_recording_stream_free(this->_id); + } + + void RecordingStream::init_global(const char* app_id, const char* addr) { + s_global = RecordingStream{app_id, addr}; + } + + RecordingStream RecordingStream::global() { + return s_global; + } + + void RecordingStream::log_data_row(const char* entity_path, uint32_t num_instances, + size_t num_data_cells, const DataCell* data_cells) { + // Map to C API: + std::vector c_data_cells; + c_data_cells.reserve(num_data_cells); + for (size_t i = 0; i < num_data_cells; ++i) { + c_data_cells.push_back({ + .component_name = data_cells[i].component_name, + .num_bytes = data_cells[i].num_bytes, + .bytes = data_cells[i].bytes, + }); + } + + const rr_data_row c_data_row = { + .entity_path = entity_path, + .num_instances = num_instances, + .num_data_cells = static_cast(num_data_cells), + .data_cells = c_data_cells.data(), + }; + + rr_log(this->_id, &c_data_row); + } + + // ------------------------------------------------------------------------ + arrow::Result> points3(size_t num_points, const float* xyz) { arrow::MemoryPool* pool = arrow::default_memory_pool(); diff --git a/rerun_cpp/src/rerun.hpp b/rerun_cpp/src/rerun.hpp index d3f9520d8ab7..5de31d87fb47 100644 --- a/rerun_cpp/src/rerun.hpp +++ b/rerun_cpp/src/rerun.hpp @@ -3,8 +3,48 @@ #ifndef RERUN_HPP #define RERUN_HPP +#include +#include + namespace rr { + /// The Rerun C++ SDK version as a human-readable string. const char* version_string(); + + enum StoreKind { + Recording, + Blueprint, + }; + + struct DataCell { + const char* component_name; + size_t num_bytes; + const uint8_t* bytes; + }; + + class RecordingStream { + public: + RecordingStream(const char* app_id, const char* addr, + StoreKind store_kind = StoreKind::Recording); + ~RecordingStream(); + + /// Must be called first, if at all. + static void init_global(const char* app_id, const char* addr); + + /// Access the global recording stream. + /// Aborts if `init_global` has not yet been called. + static RecordingStream global(); + + void log_data_row(const char* entity_path, uint32_t num_instances, size_t num_data_cells, + const DataCell* data_cells); + + private: + RecordingStream() : _id{0} {} + RecordingStream(uint32_t id) : _id{id} {} + + uint32_t _id; + + static RecordingStream s_global; + }; } // namespace rr // ---------------------------------------------------------------------------- From 31037f5eb75b5fe2adb52747b494a55ed157e314 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 6 Jul 2023 16:39:31 +0200 Subject: [PATCH 06/11] Prepare for running C++ stuff on CI --- ci_docker/Dockerfile | 3 +++ rerun_cpp/README.md | 3 +++ scripts/setup.sh | 6 ++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ci_docker/Dockerfile b/ci_docker/Dockerfile index 4e4f19f3f1a5..d326cf7190dd 100644 --- a/ci_docker/Dockerfile +++ b/ci_docker/Dockerfile @@ -6,9 +6,12 @@ LABEL version="0.7" LABEL description="Docker image used for the CI of https://github.com/rerun-io/rerun" # Install the ubuntu package dependencies +# This mirrors scripts/setup.sh ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y --no-install-recommends \ + apache-arrow cmake \ build-essential \ + cmake \ curl \ git \ libatk-bridge2.0 \ diff --git a/rerun_cpp/README.md b/rerun_cpp/README.md index c48e156dfa79..41100a2386a9 100644 --- a/rerun_cpp/README.md +++ b/rerun_cpp/README.md @@ -2,6 +2,9 @@ This is not yet ready to be used. +## Requirements +Run `scripts/setup.sh`. + ## Test it rerun_cpp/example/build_and_run.sh diff --git a/scripts/setup.sh b/scripts/setup.sh index 8897f4c0ceb3..1dc7a4d618ee 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash -# Setup required to build rerun +# Setup required to build rerun. +# This file is mirrored in ci_docker/Dockerfile. set -eu script_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) @@ -31,7 +32,8 @@ elif [ -x "$(command -v dnf)" ]; then pkg-config fi -packagesNeeded='flatbuffers' +# C++ SDK requires `apache-arrow` and `cmake` +packagesNeeded='apache-arrow cmake flatbuffers' if [ -x "$(command -v brew)" ]; then brew install $packagesNeeded elif [ -x "$(command -v port)" ]; then sudo port install $packagesNeeded elif [ -x "$(command -v apt-get)" ]; then sudo apt-get -y install $packagesNeeded From 52d74d3900c14d90ba96340612482f1754bda648 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 6 Jul 2023 17:01:22 +0200 Subject: [PATCH 07/11] Use GLOB to find C++ source files --- rerun_cpp/src/CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/rerun_cpp/src/CMakeLists.txt b/rerun_cpp/src/CMakeLists.txt index ed43f1de32fd..2687315aa452 100644 --- a/rerun_cpp/src/CMakeLists.txt +++ b/rerun_cpp/src/CMakeLists.txt @@ -1,6 +1,15 @@ cmake_minimum_required(VERSION 3.16) -add_library(rerun_sdk rerun.cpp) +# NOTE: CMake docs strongly discourages using GLOB, and instead suggests +# manually listing all the files, like it's 1972. +# However, that won't work for use since we auto-generate the source tree. +# See https://cmake.org/cmake/help/latest/command/file.html#glob +file(GLOB rerun_sdk_SRC CONFIGURE_DEPENDS + "*.hpp" + "*.cpp" +) + +add_library(rerun_sdk ${rerun_sdk_SRC}) # ------------------------------------------------------------------------------ From eafe047a417137f88366a92af6b9e3b07667fb43 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 6 Jul 2023 17:05:43 +0200 Subject: [PATCH 08/11] Move recording stream to its own hpp/cpp --- rerun_cpp/src/recording_stream.cpp | 65 ++++++++++++++++++++++++++++++ rerun_cpp/src/recording_stream.hpp | 42 +++++++++++++++++++ rerun_cpp/src/rerun.cpp | 59 --------------------------- rerun_cpp/src/rerun.hpp | 45 +-------------------- 4 files changed, 109 insertions(+), 102 deletions(-) create mode 100644 rerun_cpp/src/recording_stream.cpp create mode 100644 rerun_cpp/src/recording_stream.hpp diff --git a/rerun_cpp/src/recording_stream.cpp b/rerun_cpp/src/recording_stream.cpp new file mode 100644 index 000000000000..b5a2ebfcccc5 --- /dev/null +++ b/rerun_cpp/src/recording_stream.cpp @@ -0,0 +1,65 @@ +#include "recording_stream.hpp" + +#include + +#include +#include + +namespace rr { + RecordingStream RecordingStream::s_global; + + RecordingStream::RecordingStream(const char* app_id, const char* addr, StoreKind store_kind) { + ERROR_CONTEXT("RecordingStream", ""); + + int32_t c_store_kind; + switch (store_kind) { + case StoreKind::Recording: + c_store_kind = RERUN_STORE_KIND_RECORDING; + break; + case StoreKind::Blueprint: + c_store_kind = RERUN_STORE_KIND_BLUEPRINT; + break; + } + + rr_store_info store_info = { + .application_id = app_id, + .store_kind = c_store_kind, + }; + this->_id = rr_recording_stream_new(&store_info, addr); + } + + RecordingStream::~RecordingStream() { + rr_recording_stream_free(this->_id); + } + + void RecordingStream::init_global(const char* app_id, const char* addr) { + s_global = RecordingStream{app_id, addr}; + } + + RecordingStream RecordingStream::global() { + return s_global; + } + + void RecordingStream::log_data_row(const char* entity_path, uint32_t num_instances, + size_t num_data_cells, const DataCell* data_cells) { + // Map to C API: + std::vector c_data_cells; + c_data_cells.reserve(num_data_cells); + for (size_t i = 0; i < num_data_cells; ++i) { + c_data_cells.push_back({ + .component_name = data_cells[i].component_name, + .num_bytes = data_cells[i].num_bytes, + .bytes = data_cells[i].bytes, + }); + } + + const rr_data_row c_data_row = { + .entity_path = entity_path, + .num_instances = num_instances, + .num_data_cells = static_cast(num_data_cells), + .data_cells = c_data_cells.data(), + }; + + rr_log(this->_id, &c_data_row); + } +} // namespace rr diff --git a/rerun_cpp/src/recording_stream.hpp b/rerun_cpp/src/recording_stream.hpp new file mode 100644 index 000000000000..eb0883d01dff --- /dev/null +++ b/rerun_cpp/src/recording_stream.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include // size_t +#include // uint32_t etc + +namespace rr { + enum StoreKind { + Recording, + Blueprint, + }; + + struct DataCell { + const char* component_name; + size_t num_bytes; + const uint8_t* bytes; + }; + + class RecordingStream { + public: + RecordingStream(const char* app_id, const char* addr, + StoreKind store_kind = StoreKind::Recording); + ~RecordingStream(); + + /// Must be called first, if at all. + static void init_global(const char* app_id, const char* addr); + + /// Access the global recording stream. + /// Aborts if `init_global` has not yet been called. + static RecordingStream global(); + + void log_data_row(const char* entity_path, uint32_t num_instances, size_t num_data_cells, + const DataCell* data_cells); + + private: + RecordingStream() : _id{0} {} + RecordingStream(uint32_t id) : _id{id} {} + + uint32_t _id; + + static RecordingStream s_global; + }; +} // namespace rr diff --git a/rerun_cpp/src/rerun.cpp b/rerun_cpp/src/rerun.cpp index f728f4e74fbb..bf02a7bd9108 100644 --- a/rerun_cpp/src/rerun.cpp +++ b/rerun_cpp/src/rerun.cpp @@ -14,65 +14,6 @@ namespace rr { // ------------------------------------------------------------------------ - RecordingStream RecordingStream::s_global; - - RecordingStream::RecordingStream(const char* app_id, const char* addr, StoreKind store_kind) { - ERROR_CONTEXT("RecordingStream", ""); - - int32_t c_store_kind; - switch (store_kind) { - case StoreKind::Recording: - c_store_kind = RERUN_STORE_KIND_RECORDING; - break; - case StoreKind::Blueprint: - c_store_kind = RERUN_STORE_KIND_BLUEPRINT; - break; - } - - rr_store_info store_info = { - .application_id = app_id, - .store_kind = c_store_kind, - }; - this->_id = rr_recording_stream_new(&store_info, addr); - } - - RecordingStream::~RecordingStream() { - rr_recording_stream_free(this->_id); - } - - void RecordingStream::init_global(const char* app_id, const char* addr) { - s_global = RecordingStream{app_id, addr}; - } - - RecordingStream RecordingStream::global() { - return s_global; - } - - void RecordingStream::log_data_row(const char* entity_path, uint32_t num_instances, - size_t num_data_cells, const DataCell* data_cells) { - // Map to C API: - std::vector c_data_cells; - c_data_cells.reserve(num_data_cells); - for (size_t i = 0; i < num_data_cells; ++i) { - c_data_cells.push_back({ - .component_name = data_cells[i].component_name, - .num_bytes = data_cells[i].num_bytes, - .bytes = data_cells[i].bytes, - }); - } - - const rr_data_row c_data_row = { - .entity_path = entity_path, - .num_instances = num_instances, - .num_data_cells = static_cast(num_data_cells), - .data_cells = c_data_cells.data(), - }; - - rr_log(this->_id, &c_data_row); - } - - // ------------------------------------------------------------------------ - arrow::Result> points3(size_t num_points, const float* xyz) { arrow::MemoryPool* pool = arrow::default_memory_pool(); diff --git a/rerun_cpp/src/rerun.hpp b/rerun_cpp/src/rerun.hpp index 5de31d87fb47..0ccb68351ed0 100644 --- a/rerun_cpp/src/rerun.hpp +++ b/rerun_cpp/src/rerun.hpp @@ -1,50 +1,11 @@ // The Rerun C++ SDK. +#pragma once -#ifndef RERUN_HPP -#define RERUN_HPP - -#include -#include +#include "recording_stream.hpp" namespace rr { /// The Rerun C++ SDK version as a human-readable string. const char* version_string(); - - enum StoreKind { - Recording, - Blueprint, - }; - - struct DataCell { - const char* component_name; - size_t num_bytes; - const uint8_t* bytes; - }; - - class RecordingStream { - public: - RecordingStream(const char* app_id, const char* addr, - StoreKind store_kind = StoreKind::Recording); - ~RecordingStream(); - - /// Must be called first, if at all. - static void init_global(const char* app_id, const char* addr); - - /// Access the global recording stream. - /// Aborts if `init_global` has not yet been called. - static RecordingStream global(); - - void log_data_row(const char* entity_path, uint32_t num_instances, size_t num_data_cells, - const DataCell* data_cells); - - private: - RecordingStream() : _id{0} {} - RecordingStream(uint32_t id) : _id{id} {} - - uint32_t _id; - - static RecordingStream s_global; - }; } // namespace rr // ---------------------------------------------------------------------------- @@ -59,5 +20,3 @@ namespace rr { } // namespace rr // ---------------------------------------------------------------------------- - -#endif // RERUN_HPP From a4e8576b04e30789f51ea0b43de11eae84c54489 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 6 Jul 2023 17:07:41 +0200 Subject: [PATCH 09/11] Add some docs --- rerun_cpp/src/rerun.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rerun_cpp/src/rerun.hpp b/rerun_cpp/src/rerun.hpp index 0ccb68351ed0..adb28a7d1ef4 100644 --- a/rerun_cpp/src/rerun.hpp +++ b/rerun_cpp/src/rerun.hpp @@ -16,6 +16,10 @@ namespace rr { namespace rr { arrow::Result> points3(size_t num_points, const float* xyz); + /// Encode the given arrow table in the Arrow IPC encapsulated message format. + /// + /// * + /// * arrow::Result> ipc_from_table(const arrow::Table& table); } // namespace rr From e09c462c9a5d243e28710d1d03768076a2eb1f1f Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 6 Jul 2023 17:11:54 +0200 Subject: [PATCH 10/11] fix --- rerun_cpp/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rerun_cpp/README.md b/rerun_cpp/README.md index 41100a2386a9..e27e375d5287 100644 --- a/rerun_cpp/README.md +++ b/rerun_cpp/README.md @@ -8,9 +8,10 @@ Run `scripts/setup.sh`. ## Test it rerun_cpp/example/build_and_run.sh -# TODO +# To do: * CI * Code-gen * Documentation * Packaging * Publishing +* … From d018ef5e7678fcea9fd39b13f00589a5670faf70 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 7 Jul 2023 09:32:54 +0200 Subject: [PATCH 11/11] remove duplicated cmake Co-authored-by: Clement Rey --- ci_docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci_docker/Dockerfile b/ci_docker/Dockerfile index d326cf7190dd..e2d2818dcd5b 100644 --- a/ci_docker/Dockerfile +++ b/ci_docker/Dockerfile @@ -9,7 +9,7 @@ LABEL description="Docker image used for the CI of https://github.com/rerun-io/r # This mirrors scripts/setup.sh ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y --no-install-recommends \ - apache-arrow cmake \ + apache-arrow \ build-essential \ cmake \ curl \