From 7369e558aeebfa4eeddc3606d37f5599fed51f5a Mon Sep 17 00:00:00 2001 From: Shaohui Liu Date: Tue, 24 Sep 2024 16:48:33 +0800 Subject: [PATCH] [Dev] Add rerun example --- bazel/workspace.bzl | 2 ++ experimental/rerun_example/BUILD | 15 +++++++++ experimental/rerun_example/README.md | 8 +++++ experimental/rerun_example/rerun_example.cpp | 25 ++++++++++++++ third_party/arrow/arrow.BUILD | 1 + third_party/arrow/workspace.bzl | 2 +- third_party/rerun/BUILD | 1 + third_party/rerun/README.md | 1 + third_party/rerun/rerun.BUILD | 35 ++++++++++++++++++++ third_party/rerun/workspace.bzl | 13 ++++++++ 10 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 experimental/rerun_example/BUILD create mode 100644 experimental/rerun_example/README.md create mode 100644 experimental/rerun_example/rerun_example.cpp create mode 100644 third_party/rerun/BUILD create mode 100644 third_party/rerun/README.md create mode 100644 third_party/rerun/rerun.BUILD create mode 100644 third_party/rerun/workspace.bzl diff --git a/bazel/workspace.bzl b/bazel/workspace.bzl index 2fccbbf..50ed186 100644 --- a/bazel/workspace.bzl +++ b/bazel/workspace.bzl @@ -48,6 +48,7 @@ load("//third_party/rules_ros2:workspace.bzl", rules_ros2 = "repo") load("//third_party/mcap:workspace.bzl", mcap = "repo") load("//third_party/onnxruntime:workspace.bzl", onnxruntime = "repo") load("//third_party/foxglove_schemas:workspace.bzl", foxglove_schemas = "repo") +load("//third_party/rerun:workspace.bzl", rerun = "repo") def init_language_repos(): toolchains_llvm() @@ -99,6 +100,7 @@ def init_third_parties(): mcap() foxglove_schemas() onnxruntime() + rerun() # Define all external repositories required by def repositories(): diff --git a/experimental/rerun_example/BUILD b/experimental/rerun_example/BUILD new file mode 100644 index 0000000..e00214c --- /dev/null +++ b/experimental/rerun_example/BUILD @@ -0,0 +1,15 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary") +package(default_visibility = ["//visibility:public"]) + +cc_binary( + name = "rerun_example", + srcs = [ + "rerun_example.cpp", + ], + linkopts = ["-ldl"], + tags = ["no-tidy"], + deps = [ + "@com_github_google_glog//:glog", + "@rerun", + ], +) diff --git a/experimental/rerun_example/README.md b/experimental/rerun_example/README.md new file mode 100644 index 0000000..55f6cfa --- /dev/null +++ b/experimental/rerun_example/README.md @@ -0,0 +1,8 @@ +## Rerun.io + +### Cpp SDK +https://ref.rerun.io/docs/cpp/stable/index.html + +### References +- https://github.com/kyle-figure/bazel-minimal-rerun +- https://github.com/rerun-io/rerun diff --git a/experimental/rerun_example/rerun_example.cpp b/experimental/rerun_example/rerun_example.cpp new file mode 100644 index 0000000..781ed9d --- /dev/null +++ b/experimental/rerun_example/rerun_example.cpp @@ -0,0 +1,25 @@ +#include +#include + +#include "glog/logging.h" + +using rerun::demo::grid3d; + +int main() { + LOG(INFO) << "Start a rerun example"; + auto rec = rerun::RecordingStream("rerun_example_cpp"); + + rerun::spawn().exit_on_failure(); + + // Create some data using the `grid` utility function. + std::vector points = + grid3d(-10.f, 10.f, 10); + std::vector colors = grid3d(0, 255, 10); + + // Log the "my_points" entity with our data, using the `Points3D` archetype. + rec.log("my_points", + rerun::Points3D(points).with_colors(colors).with_radii({0.5f})); + + rec.save("example.rrd").exit_on_failure(); + return 0; +} diff --git a/third_party/arrow/arrow.BUILD b/third_party/arrow/arrow.BUILD index ebd90ba..4ac2c48 100644 --- a/third_party/arrow/arrow.BUILD +++ b/third_party/arrow/arrow.BUILD @@ -1,5 +1,6 @@ # Description: # Apache Arrow library +# See: https://github.com/tensorflow/io/blob/master/WORKSPACE package(default_visibility = ["//visibility:public"]) diff --git a/third_party/arrow/workspace.bzl b/third_party/arrow/workspace.bzl index b3c11f3..f30a711 100644 --- a/third_party/arrow/workspace.bzl +++ b/third_party/arrow/workspace.bzl @@ -5,7 +5,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") def repo(): http_archive( name = "arrow", - build_file = "//third_party/arrow:arrow.BUILD", + build_file = "//third_party:arrow.BUILD", sha256 = "57e13c62f27b710e1de54fd30faed612aefa22aa41fa2c0c3bacd204dd18a8f3", strip_prefix = "arrow-apache-arrow-7.0.0", urls = [ diff --git a/third_party/rerun/BUILD b/third_party/rerun/BUILD new file mode 100644 index 0000000..ffd0fb0 --- /dev/null +++ b/third_party/rerun/BUILD @@ -0,0 +1 @@ +package(default_visibility = ["//visibility:public"]) diff --git a/third_party/rerun/README.md b/third_party/rerun/README.md new file mode 100644 index 0000000..f819e88 --- /dev/null +++ b/third_party/rerun/README.md @@ -0,0 +1 @@ +Copied from https://github.com/kyle-figure/bazel-minimal-rerun/tree/main diff --git a/third_party/rerun/rerun.BUILD b/third_party/rerun/rerun.BUILD new file mode 100644 index 0000000..0138f05 --- /dev/null +++ b/third_party/rerun/rerun.BUILD @@ -0,0 +1,35 @@ +load("@rules_cc//cc:defs.bzl", "cc_import") +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob(["**"]), +) + +cc_import( + name = "rerun_core", + static_library = "@rerun//:lib/librerun_c__linux_x64.a", +) + +cc_library( + name = "rerun", + srcs = glob([ + "src/rerun/*.cpp", + "src/rerun/**/*.cpp", + ]), + hdrs = glob([ + "src/rerun.hpp", + "src/rerun/c/*.h", + "src/rerun/*.hpp", + "src/rerun/**/*.hpp", + ]), + includes = [ + "src", + ], + deps = [ + ":rerun_core", + "@arrow", + ], +) diff --git a/third_party/rerun/workspace.bzl b/third_party/rerun/workspace.bzl new file mode 100644 index 0000000..7920620 --- /dev/null +++ b/third_party/rerun/workspace.bzl @@ -0,0 +1,13 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def clean_dep(dep): + return str(Label(dep)) + +def repo(): + http_archive( + name = "rerun", + build_file = "//third_party/rerun:rerun.BUILD", + sha256 = "5f38113a647c72255b902fc3e00ca090c8011821550c94554c8c3845d2eac2a3", + strip_prefix = "rerun_cpp_sdk", + url = "https://github.com/rerun-io/rerun/releases/download/0.13.0/rerun_cpp_sdk.zip", + )