Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions cmake/nuttx_add_rust.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ include(nuttx_parse_function_args)
# ~~~

function(nuttx_rust_target_triple ARCHTYPE ABITYPE CPUTYPE OUTPUT)
get_filename_component(APPDIR "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/.."
ABSOLUTE)
if(ARCHTYPE STREQUAL "x86_64")
set(TARGET_TRIPLE "${APPDIR}/tools/x86_64-unknown-nuttx.json")
elseif(ARCHTYPE STREQUAL "x86")
Expand Down Expand Up @@ -127,9 +129,11 @@ function(nuttx_add_rust)

# Determine build profile based on CONFIG_DEBUG_FULLOPT
if(CONFIG_DEBUG_FULLOPT)
set(RUST_PROFILE_FLAG "-Zjson-target-spec --release")
set(RUST_PROFILE "release")
set(RUST_PANIC_FLAGS "-Zunstable-options -Cpanic=immediate-abort")
else()
set(RUST_PROFILE_FLAG "-Zjson-target-spec")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it really needed for non x86 target?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, currently APPDIR is only required for "x86_64" and "x86" architectures.
Should I put it inside the if hierarchy?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess if it's essential for x86 target and acceptable for other targets, you can move it to line 166 instead of dup them here?

set(RUST_PROFILE "debug")
set(RUST_PANIC_FLAGS "")
endif()
Expand All @@ -145,9 +149,9 @@ function(nuttx_add_rust)
set(TARGET_BASE ${RUST_TARGET})
endif()

set(RUST_BUILD_DIR
${CMAKE_CURRENT_BINARY_DIR}/${CRATE_NAME}/target/${TARGET_BASE})
set(RUST_LIB_PATH ${RUST_BUILD_DIR}/${RUST_PROFILE}/lib${CRATE_NAME}.a)
set(RUST_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CRATE_NAME}/target)
set(RUST_LIB_PATH
${RUST_BUILD_DIR}/${TARGET_BASE}/${RUST_PROFILE}/lib${CRATE_NAME}.a)

# Create build directory
file(MAKE_DIRECTORY ${RUST_BUILD_DIR})
Expand All @@ -158,7 +162,7 @@ function(nuttx_add_rust)
COMMAND
${CMAKE_COMMAND} -E env
NUTTX_INCLUDE_DIR=${PROJECT_SOURCE_DIR}/include:${CMAKE_BINARY_DIR}/include:${CMAKE_BINARY_DIR}/include/arch
RUSTFLAGS=${RUST_PANIC_FLAGS} cargo build --${RUST_PROFILE}
RUSTFLAGS=${RUST_PANIC_FLAGS} cargo build ${RUST_PROFILE_FLAG}
-Zbuild-std=std,panic_abort --manifest-path ${CRATE_PATH}/Cargo.toml
--target ${RUST_TARGET} --target-dir ${RUST_BUILD_DIR}
COMMENT "Building Rust crate ${CRATE_NAME}"
Expand Down
Loading