diff --git a/CMakeLists.txt b/CMakeLists.txt index 6289ea57515f..e9b4084fd206 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ endif() # ------------------------------------------------------------------------------ -function(set_default_warning_settings target) +function(rerun_strict_warning_settings target) if(MSVC) # TODO(andreas): Try to enable /Wall target_compile_options(${target} PRIVATE /W4) @@ -151,9 +151,9 @@ if(NOT WIN32) set(LOGURU_STACKTRACES 1) endif() - # ------------------------------------------------------------------------------ -add_subdirectory(rerun_cpp) # The Rerun C++ SDK library +add_subdirectory(crates/rerun_c) # The Rerun C SDK library, must be included before the C++ SDK. +add_subdirectory(rerun_cpp) # The Rerun C++ SDK library. add_subdirectory(examples/cpp) add_subdirectory(tests/cpp) add_subdirectory(docs/code-examples) diff --git a/crates/rerun_c/CMakeLists.txt b/crates/rerun_c/CMakeLists.txt new file mode 100644 index 000000000000..4c3fcca9f16a --- /dev/null +++ b/crates/rerun_c/CMakeLists.txt @@ -0,0 +1,37 @@ +# Builds rerun_c from source. + +# Determine Rust's librerun path. +if(APPLE) + set(RERUN_C_BUILD_ARTIFACT ${CMAKE_CURRENT_SOURCE_DIR}/../../target/release/librerun_c.a) +elseif(UNIX) # if(LINUX) # CMake 3.25 + set(RERUN_C_BUILD_ARTIFACT ${CMAKE_CURRENT_SOURCE_DIR}/../../target/release/librerun_c.a) +elseif(WIN32) + set(RERUN_C_BUILD_ARTIFACT ${CMAKE_CURRENT_SOURCE_DIR}/../../target/release/rerun_c.lib) +else() + message(FATAL_ERROR "Unsupported platform.") +endif() + +# Setup rerun_c library +add_library(rerun_c STATIC IMPORTED GLOBAL) +set_target_properties(rerun_c PROPERTIES IMPORTED_LOCATION ${RERUN_C_BUILD_ARTIFACT}) + +# Just depend on all rust and toml files, it's hard to know which files exactly are relevant. +file(GLOB_RECURSE RERUN_C_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../crates/*.rs" "${CMAKE_CURRENT_SOURCE_DIR}/../crates/*.toml") +add_custom_command( + OUTPUT ${RERUN_C_BUILD_ARTIFACT} + DEPENDS ${RERUN_C_SOURCES} + COMMAND cargo build --release -p rerun_c + COMMENT "Building rerun_c from source" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../.. +) + +# In CMake you can't depend on an output file directly. We have to wrap this in a target that rerun_c then depends on. +add_custom_target(rerun_c_build DEPENDS "${RERUN_C_BUILD_ARTIFACT}") +add_dependencies(rerun_c rerun_c_build) + +# Put `rerun.h` into the same place where it's on a user's machine and apply CMake variables like version number. +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/src/rerun.h" + "${CMAKE_CURRENT_SOURCE_DIR}/../../rerun_cpp/src/rerun/c/rerun.h" + NEWLINE_STYLE LF # Specify line endings, otherwise CMake wants to change them on Windows. +) diff --git a/docs/code-examples/CMakeLists.txt b/docs/code-examples/CMakeLists.txt index 602cbc3cb187..2b207eb46b3b 100644 --- a/docs/code-examples/CMakeLists.txt +++ b/docs/code-examples/CMakeLists.txt @@ -19,7 +19,7 @@ foreach(SOURCE_PATH ${sources_list}) add_executable(${EXAMPLE_TARGET} ${SOURCE_PATH}) - set_default_warning_settings(${EXAMPLE_TARGET}) + rerun_strict_warning_settings(${EXAMPLE_TARGET}) target_link_libraries(${EXAMPLE_TARGET} PRIVATE rerun_sdk) add_dependencies(doc_examples ${EXAMPLE_TARGET}) diff --git a/examples/cpp/clock/CMakeLists.txt b/examples/cpp/clock/CMakeLists.txt index 158f89eac651..aeca4f0f25e9 100644 --- a/examples/cpp/clock/CMakeLists.txt +++ b/examples/cpp/clock/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.16...3.27) # This can be done by passing `-DRERUN_CPP_URL=` to cmake. if(DEFINED RERUN_REPOSITORY) add_executable(example_clock main.cpp) - set_default_warning_settings(example_clock) + rerun_strict_warning_settings(example_clock) else() project(example_clock LANGUAGES CXX) diff --git a/examples/cpp/custom_component_adapter/CMakeLists.txt b/examples/cpp/custom_component_adapter/CMakeLists.txt index db01338415d3..827140a47d18 100644 --- a/examples/cpp/custom_component_adapter/CMakeLists.txt +++ b/examples/cpp/custom_component_adapter/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.16...3.27) # This can be done by passing `-DRERUN_CPP_URL=` to cmake. if(DEFINED RERUN_REPOSITORY) add_executable(example_custom_component_adapter main.cpp) - set_default_warning_settings(example_custom_component_adapter) + rerun_strict_warning_settings(example_custom_component_adapter) else() project(example_custom_component_adapter LANGUAGES CXX) diff --git a/examples/cpp/dna/CMakeLists.txt b/examples/cpp/dna/CMakeLists.txt index b6531daea233..81995d33edda 100644 --- a/examples/cpp/dna/CMakeLists.txt +++ b/examples/cpp/dna/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.16...3.27) # This can be done by passing `-DRERUN_CPP_URL=` to cmake. if(DEFINED RERUN_REPOSITORY) add_executable(example_dna main.cpp) - set_default_warning_settings(example_dna) + rerun_strict_warning_settings(example_dna) else() project(example_dna LANGUAGES CXX) diff --git a/examples/cpp/minimal/CMakeLists.txt b/examples/cpp/minimal/CMakeLists.txt index 7512a7f5d5b1..350f36e33d27 100644 --- a/examples/cpp/minimal/CMakeLists.txt +++ b/examples/cpp/minimal/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.16...3.27) # This can be done by passing `-DRERUN_CPP_URL=` to cmake. if(DEFINED RERUN_REPOSITORY) add_executable(example_minimal main.cpp) - set_default_warning_settings(example_minimal) + rerun_strict_warning_settings(example_minimal) else() project(example_minimal LANGUAGES CXX) diff --git a/examples/cpp/spawn_viewer/CMakeLists.txt b/examples/cpp/spawn_viewer/CMakeLists.txt index bc73373c2cf2..2c13800d18ff 100644 --- a/examples/cpp/spawn_viewer/CMakeLists.txt +++ b/examples/cpp/spawn_viewer/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.16...3.27) # This can be done by passing `-DRERUN_CPP_URL=` to cmake. if(DEFINED RERUN_REPOSITORY) add_executable(example_spawn_viewer main.cpp) - set_default_warning_settings(example_spawn_viewer) + rerun_strict_warning_settings(example_spawn_viewer) else() project(example_spawn_viewer LANGUAGES CXX) diff --git a/rerun_cpp/CMakeLists.txt b/rerun_cpp/CMakeLists.txt index b1d408ae54da..6256592bc34a 100644 --- a/rerun_cpp/CMakeLists.txt +++ b/rerun_cpp/CMakeLists.txt @@ -1,11 +1,16 @@ +# ------------------------------------------------------------------------------ +# Rerun C++ SDK +# +# For more information check README.md +# ------------------------------------------------------------------------------ + cmake_minimum_required(VERSION 3.16...3.27) message("Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} (${CMAKE_CXX_COMPILER})") -# 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 +# ------------------------------------------------------------------------------ +# Base setup for rerun_sdk C++ library. + file(GLOB_RECURSE rerun_sdk_SRC CONFIGURE_DEPENDS "src/*.hpp" "src/*.cpp" @@ -24,44 +29,18 @@ if(MSVC) target_compile_options(rerun_sdk PRIVATE "/MP") endif() -# ------------------------------------------------------------------------------ -# Rerun development setup only: -if(DEFINED RERUN_REPOSITORY) - # TODO(andreas): use add_custom_command instead so this runs at build time! https://cmake.org/cmake/help/latest/command/add_custom_command.html#command:add_custom_command - execute_process(COMMAND cargo build --release -p rerun_c RESULT_VARIABLE ret) # We link against this, so must be up-to-date - - # execute process doesn't fail if the process fails. - # `COMMAND_ERROR_IS_FATAL ANY` parameter fixes this but is only available in CMake 3.19 - if(NOT(ret EQUAL "0")) - message(FATAL_ERROR "Failed to build rerun_c.") - endif() - - # Overwrite where to find rerun_c library. - if(APPLE) - set(RERUN_C_LIB_DEFAULT ${CMAKE_CURRENT_SOURCE_DIR}/../target/release/librerun_c.a) - elseif(UNIX) # if(LINUX) # CMake 3.25 - set(RERUN_C_LIB_DEFAULT ${CMAKE_CURRENT_SOURCE_DIR}/../target/release/librerun_c.a) - elseif(WIN32) - set(RERUN_C_LIB_DEFAULT ${CMAKE_CURRENT_SOURCE_DIR}/../target/release/rerun_c.lib) - else() - message(FATAL_ERROR "Unsupported platform.") - endif() - - # Set very strict warning settings when we're testing the SDK. - # We don't want to force this on any user! - set_default_warning_settings(rerun_sdk) - - # Put `rerun.h` into the same place where it's on a user's machine and apply CMake variables like version number. - configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/../crates/rerun_c/src/rerun.h" - "${CMAKE_CURRENT_SOURCE_DIR}/src/rerun/c/rerun.h" - NEWLINE_STYLE LF # Specify line endings, otherwise CMake wants to change them on Windows. - ) +# Set default warning settings if defined. +if (COMMAND rerun_strict_warning_settings) + message("Building Rerun C++ SDK with strict compilation warnings.") + rerun_strict_warning_settings(rerun_sdk) endif() # ------------------------------------------------------------------------------ -# Setup rerun_c dependency: -if(NOT DEFINED RERUN_C_LIB_DEFAULT) +# Setup rerun_c dependency if it wasn't set up already. +if(NOT TARGET rerun_c) + add_library(rerun_c STATIC IMPORTED GLOBAL) + + # Inside the repo build ourselves, otherwise default to a local `lib` folder. set(RERUN_C_DEFAULT_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/) if(APPLE) @@ -81,21 +60,18 @@ if(NOT DEFINED RERUN_C_LIB_DEFAULT) else() message(WARNING "Unsupported platform ${RERUN_C_LIB_DEFAULT}, can't find rerun_c library.") endif() -endif() -set(RERUN_C_LIB ${RERUN_C_LIB_DEFAULT} CACHE PATH "\ -Where to find the rerun_c library.\n\ -If not specified, a local rerun_c with the current system architecture will be used." -) + set(RERUN_C_LIB ${RERUN_C_LIB_DEFAULT} CACHE PATH "\ + Where to find the rerun_c library.\n\ + If not specified, a local rerun_c with the current system architecture will be used." + ) -if("${RERUN_C_LIB}" STREQUAL "") - message(FATAL_ERROR "RERUN_C_LIB is not set.") -endif() + if("${RERUN_C_LIB}" STREQUAL "") + message(FATAL_ERROR "RERUN_C_LIB is not set.") + endif() -# For cleanliness, create a rerun_c target with the correct dependencies. -# This allows other targets to depend on rerun_c directly if they need to. -add_library(rerun_c STATIC IMPORTED) -set_target_properties(rerun_c PROPERTIES IMPORTED_LOCATION ${RERUN_C_LIB}) + set_target_properties(rerun_c PROPERTIES IMPORTED_LOCATION ${RERUN_C_LIB}) +endif() if(APPLE) target_link_libraries(rerun_c INTERFACE "-framework CoreFoundation" "-framework IOKit") @@ -108,7 +84,7 @@ endif() target_link_libraries(rerun_sdk PRIVATE rerun_c) # ----------------------------------------------------------------------------- -# Arrow: +# Arrow dependency. # This makes the setup a lot easier on Windows where we otherwise need to put Arrow.dll either in path or copy it with the executable. # Additionally reduces risk of picking up system libraries on Mac / Linux. set(RERUN_ARROW_LINK_SHARED_DEFAULT OFF) @@ -116,151 +92,24 @@ option(RERUN_ARROW_LINK_SHARED "Link to the Arrow shared library" ${RERUN_ARROW_ option(RERUN_DOWNLOAD_AND_BUILD_ARROW "If enabled, arrow will be added as an external project and built with the minimal set required by the Rerun C++ SDK" ON) if(RERUN_DOWNLOAD_AND_BUILD_ARROW) - include(ExternalProject) - - set(ARROW_DOWNLOAD_PATH ${CMAKE_BINARY_DIR}/arrow) - - if(RERUN_ARROW_LINK_SHARED) - set(ARROW_BUILD_SHARED ON) - set(ARROW_BUILD_STATIC OFF) - - if(APPLE) - set(ARROW_LIBRARY_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow.dylib) - elseif(UNIX) # if(LINUX) # CMake 3.25 - set(ARROW_LIBRARY_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow.so) - elseif(WIN32) - set(ARROW_LIBRARY_FILE ${ARROW_DOWNLOAD_PATH}/bin/arrow.dll) - else() - message(FATAL_ERROR "Unsupported platform.") - endif() - else() - set(ARROW_BUILD_SHARED OFF) - set(ARROW_BUILD_STATIC ON) - - if(APPLE) - set(ARROW_LIBRARY_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow.a) - set(ARROW_BUNDLED_DEPENDENCIES_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow_bundled_dependencies.a) - elseif(UNIX) # if(LINUX) # CMake 3.25 - set(ARROW_LIBRARY_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow.a) - set(ARROW_BUNDLED_DEPENDENCIES_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow_bundled_dependencies.a) - elseif(WIN32) - set(ARROW_LIBRARY_FILE ${ARROW_DOWNLOAD_PATH}/lib/arrow_static.lib) - set(ARROW_BUNDLED_DEPENDENCIES_FILE ${ARROW_DOWNLOAD_PATH}/lib/arrow_bundled_dependencies.lib) - else() - message(FATAL_ERROR "Unsupported platform.") - endif() - endif() - - - if(MSVC) - # Enable multithreaded compiling of Arrow on MSVC. - set(ARROW_CXXFLAGS "/MP") - # ASAN doesn't work with arrow (yet?) - set(ARROW_ASAN OFF) - else() - set(ARROW_CXXFLAGS "") - set(ARROW_ASAN ${RERUN_USE_ASAN}) - endif() - - # Workaround for https://github.com/apache/arrow/issues/36117 - # This works around linking issues on Windows we got after enabling mimalloc. - if(MSVC) - file(MAKE_DIRECTORY ${ARROW_DOWNLOAD_PATH}/src/arrow_cpp-build/debug/) - file(MAKE_DIRECTORY ${ARROW_DOWNLOAD_PATH}/src/arrow_cpp-build/relwithdebinfo/) - file(MAKE_DIRECTORY ${ARROW_DOWNLOAD_PATH}/src/arrow_cpp-build/release/) - endif() - - if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set(ARROW_CMAKE_PRESET ninja-debug-minimal) - else() - set(ARROW_CMAKE_PRESET ninja-release-minimal) - endif() - - ExternalProject_Add( - arrow_cpp - PREFIX ${ARROW_DOWNLOAD_PATH} - GIT_REPOSITORY https://github.com/apache/arrow.git - GIT_TAG apache-arrow-10.0.1 - GIT_SHALLOW ON - GIT_PROGRESS OFF # Git progress sounds like a nice idea but is in practive very spammy. - - # LOG_X ON means that the output of the command will - # be logged to a file _instead_ of printed to the console. - LOG_CONFIGURE ON - LOG_BUILD ON - LOG_INSTALL ON - - CMAKE_ARGS - --preset ${ARROW_CMAKE_PRESET} - -DARROW_BOOST_USE_SHARED=OFF - -DARROW_BUILD_SHARED=${ARROW_BUILD_SHARED} - -DARROW_BUILD_STATIC=${ARROW_BUILD_STATIC} - -DARROW_CXXFLAGS=${ARROW_CXXFLAGS} - -DARROW_IPC=ON - -DARROW_JEMALLOC=OFF # We encountered some build issues with jemalloc, use mimalloc instead. - -DARROW_MIMALLOC=ON - -DARROW_USE_ASAN=${ARROW_ASAN} - -DARROW_USE_TSAN=OFF - -DARROW_USE_UBSAN=OFF - -DBOOST_SOURCE=BUNDLED - -DCMAKE_INSTALL_PREFIX=${ARROW_DOWNLOAD_PATH} - -Dxsimd_SOURCE=BUNDLED - -DBOOST_SOURCE=BUNDLED - -DARROW_BOOST_USE_SHARED=OFF - -DARROW_CXXFLAGS=${DARROW_CXXFLAGS} - SOURCE_SUBDIR cpp - BUILD_BYPRODUCTS ${ARROW_LIBRARY_FILE} ${ARROW_BUNDLED_DEPENDENCIES_FILE} - ) - - # arrow_cpp target is not a library. Assemble one from it. - if(RERUN_ARROW_LINK_SHARED) - add_library(RerunArrowTarget SHARED IMPORTED) - - # For windows we need to know both the dll AND the import library. - if(WIN32) - set_target_properties(RerunArrowTarget PROPERTIES IMPORTED_IMPLIB ${ARROW_DOWNLOAD_PATH}/lib/arrow.lib) - endif() - else() - add_library(RerunArrowTarget STATIC IMPORTED) - - # Need to set the ARROW_STATIC define, otherwise arrow functions are dllimport decorated on Windows. - target_compile_definitions(RerunArrowTarget INTERFACE ARROW_STATIC) - - # We have to explicitly opt in the arrow bundled dependencies, otherwise we're missing the symbols for mimalloc. - add_library(RerunArrowTargetBundledDeps STATIC IMPORTED) - add_dependencies(RerunArrowTargetBundledDeps arrow_cpp) - set_target_properties(RerunArrowTargetBundledDeps PROPERTIES - IMPORTED_LOCATION ${ARROW_BUNDLED_DEPENDENCIES_FILE} - ) - target_link_libraries(RerunArrowTarget INTERFACE RerunArrowTargetBundledDeps) - endif() - - add_dependencies(RerunArrowTarget arrow_cpp) - set_target_properties(RerunArrowTarget PROPERTIES - IMPORTED_LOCATION ${ARROW_LIBRARY_FILE} - INTERFACE_INCLUDE_DIRECTORIES ${ARROW_DOWNLOAD_PATH}/include - ) - - # Hack to propagate INTERFACE_INCLUDE_DIRECTORIES. - # via https://stackoverflow.com/a/47358004 - file(MAKE_DIRECTORY ${ARROW_DOWNLOAD_PATH}/include) + include(download_and_build_arrow.cmake) + download_and_build_arrow() # populates `rerun_arrow_target` else() find_package(Arrow REQUIRED) if(RERUN_ARROW_LINK_SHARED) - message(STATUS "Arrow SO version: ${ARROW_FULL_SO_VERSION}") - add_library(RerunArrowTarget ALIAS Arrow::arrow_shared) + add_library(rerun_arrow_target ALIAS Arrow::arrow_shared) else() - message(STATUS "Arrow version: ${ARROW_VERSION}") - add_library(RerunArrowTarget ALIAS Arrow::arrow_static) + add_library(rerun_arrow_target ALIAS Arrow::arrow_static) endif() endif() -target_link_libraries(rerun_sdk PRIVATE RerunArrowTarget) +target_link_libraries(rerun_sdk PRIVATE rerun_arrow_target) + # ----------------------------------------------------------------------------- -# Add test subfolder if we're inside the Rerun repository -# (we don't ship them in our fetch-content bundle) -if(DEFINED RERUN_REPOSITORY) +# Add tests if they exist (they are not part of the distribution zip). +# Has direct dpeendency to arrow, so needs to happen last. +if(EXISTS tests) add_subdirectory(tests) endif() diff --git a/rerun_cpp/README.md b/rerun_cpp/README.md index 4a10dac89c23..d6e42d3d5880 100644 --- a/rerun_cpp/README.md +++ b/rerun_cpp/README.md @@ -1,10 +1,61 @@ # Rerun C++ SDK -Read our [getting-started guide](https://www.rerun.io/docs/getting-started/cpp) for information on how to use the Rerun C++ SDK. +The Rerun C++ SDK allows logging data to Rerun directly from C++. -## Development -### Requirements -Run `scripts/setup.sh`. +Read the [getting started guide](https://www.rerun.io/docs/getting-started/cpp) for information on how to use the Rerun C++ SDK. -### Test it -`just cpp-test` +## Build & Distribution + +### Overview + +To avoid compatibility issues across different platforms, compiler versions and C++ standard library versions +the C++ SDK is expected to be built from source. + +From a build system perspective, the SDK consists of three dependencies: + +* [SDK source](https://github.com/rerun-io/rerun/tree/latest/rerun_cpp/src/) + * this includes **both** source and header files! +* [rerun_c](https://github.com/rerun-io/rerun/tree/latest/crates/rerun_c/) static libraries + * Rerun C is a minimal C SDK and forms the bridge to the shared Rust codebase + * due to the rigidity of the C ABI and lack of complex standard library types in the interface, + compatibility issues between compilers are less of a concern + which is why offer pre-built libraries with every release for all major platforms +* [Apache Arrow C++ library](https://arrow.apache.org/docs/cpp/index.html) + * The SDK uses this library to perform all serialization before handing data over to rerun_c + * See [Install arrow-cpp](https://www.rerun.io/docs/howto/arrow-cpp-install) for how to install this library + + +### SDK bundle (`rerun_cpp_sdk.zip`) + +For convenience, Rerun provides a C++ SDK bundle with every release. +(this includes our regular [Development Builds](https://github.com/rerun-io/rerun/releases/tag/prerelease)!) + +This is a simple zip archive containing the SDK the [repository](https://github.com/rerun-io/rerun/tree/latest/rerun_cpp) +(excluding the tests folder) and a `lib` folder with prebuilt rerun_c libraries for all major desktop platforms. +The rerun_c libraries follow a simple name schema that the CMake script can pick up. + + +### Building with CMake + +See [C++ SDK CMake](https://www.rerun.io/docs/reference/cpp-sdk-cmake) for deeper dive on +how to use the SDK's `CMakeLists.txt` and an overview over all CMake configuration options. + +### Without CMake + +In order to build without CMake, you have to add all files from the [src/](https://github.com/rerun-io/rerun/tree/latest/rerun_cpp/src/) folder +either directly to your project or a library. +In addition, you need to link the `rerun_c` libraries and the [Arrow C++ library](https://arrow.apache.org/docs/cpp/index.html). + +Make sure to compile with C++17 or newer. + +For more information on how to install Arrow, see [Install arrow-cpp](https://www.rerun.io/docs/howto/arrow-cpp-install). + + +## Development in the Rerun repository + +Refer to the [build instruction](https://github.com/rerun-io/rerun/tree/latest/BUILD.md) at the repo root. + +Keep in mind that all archetypes/components/datatypes are mostly generated by the [Rerun types builder](https://github.com/rerun-io/rerun/tree/latest/crates/re_types_builder). +Use `just codegen` to run code generation. Generally, all generated code files are part of the repository, +so you only have to do that if you change the data definition or make changes to `_ext.cpp` files which +extend generated types. diff --git a/rerun_cpp/download_and_build_arrow.cmake b/rerun_cpp/download_and_build_arrow.cmake new file mode 100644 index 000000000000..8a16da82b168 --- /dev/null +++ b/rerun_cpp/download_and_build_arrow.cmake @@ -0,0 +1,134 @@ +# Downloads and builds Apache Arrow from source. +# +# Populates `rerun_arrow_target` with the final arrow target. +# Tries to build an as small as possible version of Arrow that is compatible with the Rerun C++ SDK. +function(download_and_build_arrow) + include(ExternalProject) + + set(ARROW_DOWNLOAD_PATH ${CMAKE_BINARY_DIR}/arrow) + + if(RERUN_ARROW_LINK_SHARED) + set(ARROW_BUILD_SHARED ON) + set(ARROW_BUILD_STATIC OFF) + + if(APPLE) + set(ARROW_LIBRARY_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow.dylib) + elseif(UNIX) # if(LINUX) # CMake 3.25 + set(ARROW_LIBRARY_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow.so) + elseif(WIN32) + set(ARROW_LIBRARY_FILE ${ARROW_DOWNLOAD_PATH}/bin/arrow.dll) + else() + message(FATAL_ERROR "Unsupported platform.") + endif() + else() + set(ARROW_BUILD_SHARED OFF) + set(ARROW_BUILD_STATIC ON) + + if(APPLE) + set(ARROW_LIBRARY_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow.a) + set(ARROW_BUNDLED_DEPENDENCIES_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow_bundled_dependencies.a) + elseif(UNIX) # if(LINUX) # CMake 3.25 + set(ARROW_LIBRARY_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow.a) + set(ARROW_BUNDLED_DEPENDENCIES_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow_bundled_dependencies.a) + elseif(WIN32) + set(ARROW_LIBRARY_FILE ${ARROW_DOWNLOAD_PATH}/lib/arrow_static.lib) + set(ARROW_BUNDLED_DEPENDENCIES_FILE ${ARROW_DOWNLOAD_PATH}/lib/arrow_bundled_dependencies.lib) + else() + message(FATAL_ERROR "Unsupported platform.") + endif() + endif() + + # Enable multithreaded compiling of Arrow on MSVC. + if(MSVC) + # Enable multithreaded compiling of Arrow on MSVC. + set(ARROW_CXXFLAGS "/MP") + # ASAN doesn't work with arrow (yet?) + set(ARROW_ASAN OFF) + else() + set(ARROW_CXXFLAGS "") + set(ARROW_ASAN ${RERUN_USE_ASAN}) + endif() + + # Workaround for https://github.com/apache/arrow/issues/36117 + # This works around linking issues on Windows we got after enabling mimalloc. + if(MSVC) + file(MAKE_DIRECTORY ${ARROW_DOWNLOAD_PATH}/src/arrow_cpp-build/debug/) + file(MAKE_DIRECTORY ${ARROW_DOWNLOAD_PATH}/src/arrow_cpp-build/relwithdebinfo/) + file(MAKE_DIRECTORY ${ARROW_DOWNLOAD_PATH}/src/arrow_cpp-build/release/) + endif() + + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(ARROW_CMAKE_PRESET ninja-debug-minimal) + else() + set(ARROW_CMAKE_PRESET ninja-release-minimal) + endif() + + ExternalProject_Add( + arrow_cpp + PREFIX ${ARROW_DOWNLOAD_PATH} + GIT_REPOSITORY https://github.com/apache/arrow.git + GIT_TAG apache-arrow-10.0.1 + GIT_SHALLOW ON + GIT_PROGRESS OFF # Git progress sounds like a nice idea but is in practive very spammy. + + # LOG_X ON means that the output of the command will + # be logged to a file _instead_ of printed to the console. + LOG_CONFIGURE ON + LOG_BUILD ON + LOG_INSTALL ON + + CMAKE_ARGS + --preset ${ARROW_CMAKE_PRESET} + -DARROW_BOOST_USE_SHARED=OFF + -DARROW_BUILD_SHARED=${ARROW_BUILD_SHARED} + -DARROW_BUILD_STATIC=${ARROW_BUILD_STATIC} + -DARROW_CXXFLAGS=${DARROW_CXXFLAGS} + -DARROW_IPC=ON + -DARROW_JEMALLOC=OFF # We encountered some build issues with jemalloc, use mimalloc instead. + -DARROW_MIMALLOC=ON + -DARROW_USE_ASAN=${RERUN_USE_ASAN} + -DARROW_USE_TSAN=OFF + -DARROW_USE_UBSAN=OFF + -DBOOST_SOURCE=BUNDLED + -DCMAKE_INSTALL_PREFIX=${ARROW_DOWNLOAD_PATH} + -Dxsimd_SOURCE=BUNDLED + -DBOOST_SOURCE=BUNDLED + -DARROW_BOOST_USE_SHARED=OFF + -DARROW_CXXFLAGS=${DARROW_CXXFLAGS} + SOURCE_SUBDIR cpp + BUILD_BYPRODUCTS ${ARROW_LIBRARY_FILE} ${ARROW_BUNDLED_DEPENDENCIES_FILE} + ) + + # arrow_cpp target is not a library. Assemble one from it. + if(RERUN_ARROW_LINK_SHARED) + add_library(rerun_arrow_target SHARED IMPORTED GLOBAL) + + # For windows we need to know both the dll AND the import library. + if(WIN32) + set_target_properties(rerun_arrow_target PROPERTIES IMPORTED_IMPLIB ${ARROW_DOWNLOAD_PATH}/lib/arrow.lib) + endif() + else() + add_library(rerun_arrow_target STATIC IMPORTED GLOBAL) + + # Need to set the ARROW_STATIC define, otherwise arrow functions are dllimport decorated on Windows. + target_compile_definitions(rerun_arrow_target INTERFACE ARROW_STATIC) + + # We have to explicitly opt in the arrow bundled dependencies, otherwise we're missing the symbols for mimalloc. + add_library(arrow_targetBundledDeps STATIC IMPORTED) + add_dependencies(arrow_targetBundledDeps arrow_cpp) + set_target_properties(arrow_targetBundledDeps PROPERTIES + IMPORTED_LOCATION ${ARROW_BUNDLED_DEPENDENCIES_FILE} + ) + target_link_libraries(rerun_arrow_target INTERFACE arrow_targetBundledDeps) + endif() + + add_dependencies(rerun_arrow_target arrow_cpp) + set_target_properties(rerun_arrow_target PROPERTIES + IMPORTED_LOCATION ${ARROW_LIBRARY_FILE} + INTERFACE_INCLUDE_DIRECTORIES ${ARROW_DOWNLOAD_PATH}/include + ) + + # Hack to propagate INTERFACE_INCLUDE_DIRECTORIES. + # via https://stackoverflow.com/a/47358004 + file(MAKE_DIRECTORY ${ARROW_DOWNLOAD_PATH}/include) +endfunction() diff --git a/rerun_cpp/tests/CMakeLists.txt b/rerun_cpp/tests/CMakeLists.txt index d32a4ba7c8d0..ac2734480013 100644 --- a/rerun_cpp/tests/CMakeLists.txt +++ b/rerun_cpp/tests/CMakeLists.txt @@ -15,7 +15,7 @@ file(GLOB_RECURSE rerun_sdk_tests_SRC CONFIGURE_DEPENDS ) add_executable(rerun_sdk_tests ${rerun_sdk_tests_SRC}) -set_default_warning_settings(rerun_sdk_tests) +rerun_strict_warning_settings(rerun_sdk_tests) # Include arrow explicitly again, otherwise the arrow headers won't be found. -target_link_libraries(rerun_sdk_tests PRIVATE loguru::loguru Catch2::Catch2 rerun_sdk RerunArrowTarget) +target_link_libraries(rerun_sdk_tests PRIVATE loguru::loguru Catch2::Catch2 rerun_sdk rerun_arrow_target) diff --git a/scripts/ci/bundle_and_upload_rerun_cpp.py b/scripts/ci/bundle_and_upload_rerun_cpp.py index 71e85ac4f9cc..346423799ffd 100644 --- a/scripts/ci/bundle_and_upload_rerun_cpp.py +++ b/scripts/ci/bundle_and_upload_rerun_cpp.py @@ -102,8 +102,9 @@ def main() -> None: download_rerun_c(package_dir + "/lib", git_hash, args.platform_filter) logging.info("Copying files…") - shutil.copy("rerun_cpp/CMakeLists.txt", package_dir + "/CMakeLists.txt") - shutil.copytree("rerun_cpp/src/", package_dir + "/src/") + shutil.copytree( + src="rerun_cpp/", dst=package_dir + "/", ignore=shutil.ignore_patterns("tests"), dirs_exist_ok=True + ) logging.info(f"Packaging {package_dir}.zip…") rerun_zip = shutil.make_archive( diff --git a/tests/cpp/roundtrips/CMakeLists.txt b/tests/cpp/roundtrips/CMakeLists.txt index 2cd9e55f352c..9d45e3c13a3e 100644 --- a/tests/cpp/roundtrips/CMakeLists.txt +++ b/tests/cpp/roundtrips/CMakeLists.txt @@ -13,7 +13,7 @@ foreach(DIR ${sources_list}) set(ROUNDTRIP_TARGET roundtrip_${ARCHETYPE}) add_executable(${ROUNDTRIP_TARGET} ${DIR}/main.cpp) - set_default_warning_settings(${ROUNDTRIP_TARGET}) + rerun_strict_warning_settings(${ROUNDTRIP_TARGET}) target_link_libraries(${ROUNDTRIP_TARGET} PRIVATE rerun_sdk) ELSE() CONTINUE()