Skip to content

PICO_PLATFORM=host does not allow pico_mbedtls #2427

Open
@oyama

Description

@oyama

I'd like to use pico_mbedtls_crypto for using on a development host.
Running tests on the host is often more convenient than on the device, especially when verifying complex behavior. However, it seems that rp2_common/pico_mbedtls is not available when building for the host, as it's not included in pico-sdk/src/host.cmake.

As a workaround, I’m currently using the following in my CMakeLists.txt to manually bring in mbedtls:

include(FetchContent)
# Import mbedtls from pico-sdk into the project directory.
FetchContent_Declare(mbedtls SOURCE_DIR ${PICO_SDK_PATH}/lib/mbedtls)
FetchContent_GetProperties(mbedtls)
if(NOT mbedtls_POPULATED)
  FetchContent_Populate(mbedtls)
  add_subdirectory(${mbedtls_SOURCE_DIR} ${mbedtls_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

target_link_libraries(unittest PRIVATE mbedcrypto)

This works, but it would be simpler if pico_mbedtls were included in host.cmake.
The following patch would make it available:

diff --git a/src/host.cmake b/src/host.cmake
index 3399866..c7366da 100644
--- a/src/host.cmake
+++ b/src/host.cmake
@@ -1,5 +1,6 @@
 set(CMAKE_DIR cmake)
 set(COMMON_DIR common)
+set(RP2_COMMON_DIR rp2_common)
 set(HOST_DIR host)
 
 include (${CMAKE_DIR}/no_hardware.cmake)
@@ -19,6 +20,9 @@ include (${CMAKE_DIR}/no_hardware.cmake)
  pico_add_subdirectory(${COMMON_DIR}/pico_util)
  pico_add_subdirectory(${COMMON_DIR}/pico_stdlib_headers)
 
+# rp2_common
+ pico_add_subdirectory(${RP2_COMMON_DIR}/pico_mbedtls)
+
 # host-specific
  pico_add_subdirectory(${HOST_DIR}/hardware_divider)
  pico_add_subdirectory(${HOST_DIR}/hardware_gpio)

Would it be possible to support this, or is there a recommended alternative approach?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions