File
Blob: firmware/main/CMakeLists.txt
| 1 | # HAL 0.46 compiles wrappers for these S3 drivers even when only its task API is used. |
| 2 | set(RUST_DRIVER_DEPS driver sdmmc esp_driver_gptimer esp_driver_i2c esp_driver_i2s |
| 3 | esp_driver_ledc esp_driver_pcnt esp_driver_rmt esp_driver_sdmmc |
| 4 | esp_driver_sdspi esp_driver_spi esp_driver_twai esp_driver_uart |
| 5 | esp_driver_usb_serial_jtag) |
| 6 | |
| 7 | idf_component_register( |
| 8 | SRCS "../platform/entry.c" "../platform/board.c" "../platform/certificate.c" |
| 9 | "../platform/http.c" "../platform/audio.c" "../platform/metrics.c" |
| 10 | "../platform/crypto_aes.c" "../platform/crypto_hash.c" "../platform/crypto_ec.c" |
| 11 | WHOLE_ARCHIVE |
| 12 | INCLUDE_DIRS "../platform/include" "${CMAKE_BINARY_DIR}/private" |
| 13 | PRIV_REQUIRES esp_psram esp_driver_gpio esp_wifi wpa_supplicant esp_netif esp_event |
| 14 | esp_timer esp_system spi_flash esp_partition heap json mbedtls |
| 15 | esp_http_client esp-tls esp_driver_tsens pthread vfs esp_vfs_console esp-dsp esp_audio_codec |
| 16 | ${RUST_DRIVER_DEPS}) |
| 17 | |
| 18 | if(RADIO_CRYPTO_PROFILE) |
| 19 | target_sources(${COMPONENT_LIB} PRIVATE "../platform/crypto_profile.c") |
| 20 | target_link_options(${COMPONENT_LIB} INTERFACE |
| 21 | "-Wl,--wrap=radio_crypto_hmac" |
| 22 | "-Wl,--wrap=radio_crypto_aes_ctr" |
| 23 | "-Wl,--wrap=radio_crypto_aes_gcm" |
| 24 | "-Wl,--wrap=esp_mbedtls_mem_calloc") |
| 25 | endif() |
| 26 | |
| 27 | set(RUST_TARGET "xtensa-esp32s3-espidf") |
| 28 | set(RUST_TARGET_DIR "${CMAKE_BINARY_DIR}/cargo") |
| 29 | set(RUST_ARCHIVE "${RUST_TARGET_DIR}/${RUST_TARGET}/release/libesp32_radio.a") |
| 30 | set(RUST_FEATURE_ARGS "") |
| 31 | if(RADIO_CRYPTO_SELF_TEST) |
| 32 | list(APPEND RUST_FEATURE_ARGS --features crypto-self-test) |
| 33 | endif() |
| 34 | if(RADIO_CRYPTO_PROFILE) |
| 35 | list(APPEND RUST_FEATURE_ARGS --features crypto-profile) |
| 36 | endif() |
| 37 | idf_build_get_property(radio_sdkconfig SDKCONFIG) |
| 38 | idf_build_get_property(radio_idf_path IDF_PATH) |
| 39 | |
| 40 | # esp-idf-sys does not track CMake's SDK inputs in Cargo. |
| 41 | # Include their fingerprint in RUSTFLAGS so SDK changes regenerate bindings. |
| 42 | # The build helper verifies native checkouts against the pins in project.py. |
| 43 | set(radio_binding_files "${radio_sdkconfig}" |
| 44 | "${CMAKE_CURRENT_LIST_DIR}/../CMakeLists.txt" "${CMAKE_CURRENT_LIST_FILE}" |
| 45 | "${CMAKE_CURRENT_LIST_DIR}/idf_component.yml" |
| 46 | "${CMAKE_CURRENT_LIST_DIR}/../dependencies.lock" |
| 47 | "${CMAKE_CURRENT_LIST_DIR}/../../scripts/project.py") |
| 48 | get_target_property(radio_binding_includes ${COMPONENT_LIB} INCLUDE_DIRECTORIES) |
| 49 | get_target_property(radio_binding_components ${COMPONENT_LIB} LINK_LIBRARIES) |
| 50 | set(radio_binding_inputs |
| 51 | "${radio_idf_path}|${radio_sdkconfig}|${CMAKE_BINARY_DIR}|${CMAKE_C_COMPILER}|${CMAKE_C_COMPILER_VERSION}|$ENV{LIBCLANG_PATH}|${radio_binding_includes}|${radio_binding_components}") |
| 52 | foreach(radio_binding_file IN LISTS radio_binding_files) |
| 53 | get_filename_component(radio_binding_file "${radio_binding_file}" ABSOLUTE) |
| 54 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${radio_binding_file}") |
| 55 | file(SHA256 "${radio_binding_file}" radio_binding_file_hash) |
| 56 | string(APPEND radio_binding_inputs "|${radio_binding_file}|${radio_binding_file_hash}") |
| 57 | endforeach() |
| 58 | string(SHA256 radio_binding_fingerprint "${radio_binding_inputs}") |
| 59 | |
| 60 | add_custom_target(radio_rust_build |
| 61 | COMMAND ${CMAKE_COMMAND} -E env |
| 62 | "CARGO_CMAKE_BUILD_INCLUDES=$<TARGET_PROPERTY:${COMPONENT_LIB},INCLUDE_DIRECTORIES>" |
| 63 | "CARGO_CMAKE_BUILD_LINK_LIBRARIES=$<TARGET_PROPERTY:${COMPONENT_LIB},LINK_LIBRARIES>" |
| 64 | "CARGO_CMAKE_BUILD_SDKCONFIG=${radio_sdkconfig}" |
| 65 | "CARGO_CMAKE_BUILD_ESP_IDF=${radio_idf_path}" |
| 66 | "CARGO_CMAKE_BUILD_COMPILER=${CMAKE_C_COMPILER}" |
| 67 | "CARGO_WORKSPACE_DIR=${CMAKE_CURRENT_LIST_DIR}/.." |
| 68 | "RUSTFLAGS=--cfg espidf_time64 --cfg radio_idf_build_${radio_binding_fingerprint}" |
| 69 | "CARGO_TARGET_DIR=${RUST_TARGET_DIR}" |
| 70 | cargo +esp-radio build --manifest-path "${CMAKE_CURRENT_LIST_DIR}/../Cargo.toml" |
| 71 | --package esp32-radio --release --locked --target ${RUST_TARGET} |
| 72 | -Zbuild-std=std,panic_abort ${RUST_FEATURE_ARGS} |
| 73 | BYPRODUCTS "${RUST_ARCHIVE}" |
| 74 | WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/.." |
| 75 | VERBATIM USES_TERMINAL) |
| 76 | add_prebuilt_library(radio_rust "${RUST_ARCHIVE}" PRIV_REQUIRES pthread vfs) |
| 77 | add_dependencies(radio_rust radio_rust_build) |
| 78 | target_link_libraries(${COMPONENT_LIB} PRIVATE radio_rust) |