Skip to content

Commit ce42e4b

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 059e305 commit ce42e4b

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
@@ -77,8 +77,13 @@ function(rust_cargo_application)
7777

7878
# TODO: Make sure RUSTFLAGS is not set.
7979

80-
# TODO: Let this be configurable, or based on Kconfig debug?
81-
set(RUST_BUILD_TYPE debug)
80+
if(CONFIG_DEBUG)
81+
set(RUST_BUILD_TYPE "debug")
82+
set(rust_build_type_arg "")
83+
else()
84+
set(RUST_BUILD_TYPE "release")
85+
set(rust_build_type_arg "--release")
86+
endif()
8287
set(BUILD_LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${RUST_TARGET}/${RUST_BUILD_TYPE}")
8388

8489
set(CARGO_TARGET_DIR "${CMAKE_CURRENT_BINARY_DIR}/rust/target")
@@ -152,8 +157,7 @@ ${config_paths}
152157
INCLUDE_DEFINES="${include_defines}"
153158
WRAPPER_FILE="${WRAPPER_FILE}"
154159
cargo build
155-
# TODO: release flag if release build
156-
# --release
160+
${rust_build_type_arg}
157161

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

0 commit comments

Comments
 (0)