Skip to content

Commit e3cc500

Browse files
committed
cmake: Set the release/debug based on Kconfig
Use the Zephyr KConfig `CONFIG_DEBUG` to determine if the Rust code should be built as release or debug. This will better optimize the code. Applications can still set options for `[profile.release]` to enable things such as run time assertions. For example, debug symbols can still be enabled with `debug = "full"`, which attempts to insert debugging information, although the optimizer can still make the code challenging to debug.o `debug-assertions = true`, and `overflow-checks = true` can still be enabled in the release builds, for some additional checks. Signed-off-by: David Brown <[email protected]>
1 parent 900f6d0 commit e3cc500

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

CMakeLists.txt

+8-4
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,13 @@ function(rust_cargo_application)
8080

8181
# TODO: Make sure RUSTFLAGS is not set.
8282

83-
# TODO: Let this be configurable, or based on Kconfig debug?
84-
set(RUST_BUILD_TYPE debug)
83+
if(CONFIG_DEBUG)
84+
set(RUST_BUILD_TYPE "debug")
85+
set(rust_build_type_arg "")
86+
else()
87+
set(RUST_BUILD_TYPE "release")
88+
set(rust_build_type_arg "--release")
89+
endif()
8590
set(BUILD_LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${RUST_TARGET}/${RUST_BUILD_TYPE}")
8691

8792
set(CARGO_TARGET_DIR "${CMAKE_CURRENT_BINARY_DIR}/rust/target")
@@ -159,8 +164,7 @@ ${config_paths}
159164
DT_AUGMENTS="${DT_AUGMENTS}"
160165
BINARY_DIR_INCLUDE_GENERATED="${BINARY_DIR_INCLUDE_GENERATED}"
161166
cargo build
162-
# TODO: release flag if release build
163-
# --release
167+
${rust_build_type_arg}
164168

165169
# Override the features according to the shield given. For a general case,
166170
# this will need to come from a variable or argument.

0 commit comments

Comments
 (0)