c-with-rust: make cmake call cargo

This commit is contained in:
Travis Burtrum 2024-02-08 22:49:40 -05:00
parent ec1a638e20
commit 6e48ce664e
4 changed files with 27 additions and 4 deletions

View File

@ -15,11 +15,14 @@ add_executable(
blink.c blink.c
) )
add_subdirectory(rblink)
add_dependencies(blink rblink)
# pull in common dependencies # pull in common dependencies
target_link_libraries( target_link_libraries(
blink blink
pico_stdlib pico_stdlib
/tmp/cargo-target/thumbv6m-none-eabi/release/librblink.a ${CMAKE_CURRENT_BINARY_DIR}/rblink/librblink.a
) )
# create map/bin/hex file etc. # create map/bin/hex file etc.

View File

@ -51,6 +51,9 @@ int c_main() {
gpio_put(LED_PIN, 0); gpio_put(LED_PIN, 0);
sleep_ms(sleep); sleep_ms(sleep);
sleep = add_half(sleep); sleep = add_half(sleep);
if(sleep > 2000) {
reset_usb_boot(LED_PIN, 0);
}
} }
} }

View File

@ -5,9 +5,6 @@ set -euxo pipefail
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "$SCRIPT_DIR"/rblink
CARGO_TARGET_DIR=/tmp/cargo-target cargo build --release --target thumbv6m-none-eabi
mkdir -p /tmp/8 mkdir -p /tmp/8
cd /tmp/8 cd /tmp/8

View File

@ -0,0 +1,20 @@
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CARGO_CMD cargo build --target thumbv6m-none-eabi)
set(TARGET_DIR "debug")
else ()
set(CARGO_CMD cargo build --release --target thumbv6m-none-eabi)
set(TARGET_DIR "release")
endif ()
set(RBLINK_A "${CMAKE_CURRENT_BINARY_DIR}/thumbv6m-none-eabi/${TARGET_DIR}/librblink.a")
add_custom_target(rblink ALL
COMMENT "Compiling rblink module"
COMMAND CARGO_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR} ${CARGO_CMD}
COMMAND cp ${RBLINK_A} ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(rblink PROPERTIES LOCATION ${CMAKE_CURRENT_BINARY_DIR})
add_test(NAME rblink_test
COMMAND cargo test
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})