From b4144dfba531b47f84c86d2abe96754b29a3f656 Mon Sep 17 00:00:00 2001 From: Cristhian Date: Mon, 7 Sep 2026 14:33:50 -0300 Subject: [PATCH] match the cargo profile to CMAKE_BUILD_TYPE The dora bindings were always built with the debug profile and linked from target/debug, so a release build still pulled in unoptimized arrow, zenoh and opentelemetry code -- a 640 MB dora_zed against 48 MB once the profile follows the build type. --- DoraTargets.cmake | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/DoraTargets.cmake b/DoraTargets.cmake index dce36b6..2c25324 100644 --- a/DoraTargets.cmake +++ b/DoraTargets.cmake @@ -5,6 +5,16 @@ set(dora_c_include_dir "${CMAKE_CURRENT_BINARY_DIR}/include/c") set(dora_cxx_include_dir "${CMAKE_CURRENT_BINARY_DIR}/include/cxx") set(node_bridge "${CMAKE_CURRENT_BINARY_DIR}/node_bridge.cc") +# Match the cargo profile to the CMake build type, so a release build does not +# link unoptimized dora bindings. +if(CMAKE_BUILD_TYPE MATCHES "^(Release|RelWithDebInfo|MinSizeRel)$") + set(_cargo_profile_flag --release) + set(_cargo_target_subdir release) +else() + set(_cargo_profile_flag "") + set(_cargo_target_subdir debug) +endif() + if(DORA_ROOT_DIR AND EXISTS "${DORA_ROOT_DIR}/Cargo.toml") include(ExternalProject) ExternalProject_Add(Dora @@ -12,10 +22,10 @@ if(DORA_ROOT_DIR AND EXISTS "${DORA_ROOT_DIR}/Cargo.toml") BUILD_IN_SOURCE True CONFIGURE_COMMAND "" BUILD_COMMAND - cargo build + cargo build ${_cargo_profile_flag} --package dora-node-api-c && - cargo build + cargo build ${_cargo_profile_flag} --package dora-node-api-cxx INSTALL_COMMAND "" ) @@ -37,7 +47,7 @@ if(DORA_ROOT_DIR AND EXISTS "${DORA_ROOT_DIR}/Cargo.toml") add_custom_target(Dora_c DEPENDS ${dora_c_include_dir}) add_custom_target(Dora_cxx DEPENDS ${node_bridge} ${dora_cxx_include_dir}) - set(dora_link_dirs ${DORA_ROOT_DIR}/target/debug) + set(dora_link_dirs ${DORA_ROOT_DIR}/target/${_cargo_target_subdir}) else() include(ExternalProject) @@ -79,11 +89,11 @@ else() BUILD_IN_SOURCE True CONFIGURE_COMMAND "" BUILD_COMMAND - cargo build + cargo build ${_cargo_profile_flag} --package dora-node-api-c --target-dir ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target && - cargo build + cargo build ${_cargo_profile_flag} --package dora-node-api-cxx --target-dir ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target INSTALL_COMMAND "" @@ -104,7 +114,7 @@ else() cp ../apis/c/node ${CMAKE_CURRENT_BINARY_DIR}/include/c -r ) - set(dora_link_dirs ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target/debug) + set(dora_link_dirs ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target/${_cargo_target_subdir}) add_custom_target(Dora_c DEPENDS ${dora_c_include_dir}) add_custom_target(Dora_cxx DEPENDS ${node_bridge} ${dora_cxx_include_dir})