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.
This commit is contained in:
2026-09-07 14:33:50 -03:00
parent d62f4fbb29
commit b4144dfba5
+16 -6
View File
@@ -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(dora_cxx_include_dir "${CMAKE_CURRENT_BINARY_DIR}/include/cxx")
set(node_bridge "${CMAKE_CURRENT_BINARY_DIR}/node_bridge.cc") 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") if(DORA_ROOT_DIR AND EXISTS "${DORA_ROOT_DIR}/Cargo.toml")
include(ExternalProject) include(ExternalProject)
ExternalProject_Add(Dora ExternalProject_Add(Dora
@@ -12,10 +22,10 @@ if(DORA_ROOT_DIR AND EXISTS "${DORA_ROOT_DIR}/Cargo.toml")
BUILD_IN_SOURCE True BUILD_IN_SOURCE True
CONFIGURE_COMMAND "" CONFIGURE_COMMAND ""
BUILD_COMMAND BUILD_COMMAND
cargo build cargo build ${_cargo_profile_flag}
--package dora-node-api-c --package dora-node-api-c
&& &&
cargo build cargo build ${_cargo_profile_flag}
--package dora-node-api-cxx --package dora-node-api-cxx
INSTALL_COMMAND "" 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_c DEPENDS ${dora_c_include_dir})
add_custom_target(Dora_cxx DEPENDS ${node_bridge} ${dora_cxx_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() else()
include(ExternalProject) include(ExternalProject)
@@ -79,11 +89,11 @@ else()
BUILD_IN_SOURCE True BUILD_IN_SOURCE True
CONFIGURE_COMMAND "" CONFIGURE_COMMAND ""
BUILD_COMMAND BUILD_COMMAND
cargo build cargo build ${_cargo_profile_flag}
--package dora-node-api-c --package dora-node-api-c
--target-dir ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target --target-dir ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target
&& &&
cargo build cargo build ${_cargo_profile_flag}
--package dora-node-api-cxx --package dora-node-api-cxx
--target-dir ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target --target-dir ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target
INSTALL_COMMAND "" INSTALL_COMMAND ""
@@ -104,7 +114,7 @@ else()
cp ../apis/c/node ${CMAKE_CURRENT_BINARY_DIR}/include/c -r 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_c DEPENDS ${dora_c_include_dir})
add_custom_target(Dora_cxx DEPENDS ${node_bridge} ${dora_cxx_include_dir}) add_custom_target(Dora_cxx DEPENDS ${node_bridge} ${dora_cxx_include_dir})