mirror of
https://github.com/espressif/esp-idf.git
synced 2026-05-30 17:46:32 +03:00
fix(mbedtls): compile esp_mem.c in IDF component lib instead of builtin target
esp_mem.c in the builtin target via target_sources(builtin PRIVATE ...) called from the parent CMakeLists. This cross-directory source injection causes CMake's Ninja generator on Windows to produce unstable TARGET_PDB/RSP_FILE paths across reconfigures, changing the ninja command hash and forcing a re-archive of libmbed-builtin.a on every cmake run — even when no source changed. This broke test_rebuild_source_files. Fix by adding esp_mem.c to the IDF mbedtls component library (mbedtls_srcs) instead. The final ELF link uses --start-group, so builtin's platform.o resolves esp_mbedtls_mem_calloc/free from the component library regardless of archive order. esp_mem.c is IDF-specific code (heap_caps_calloc, sdkconfig.h) and belongs in the port layer, not in any submodule target.
This commit is contained in:
@@ -26,7 +26,7 @@ if(NOT ${IDF_TARGET} STREQUAL "linux")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(mbedtls_srcs "")
|
||||
set(mbedtls_srcs "port/esp_mem.c")
|
||||
set(mbedtls_include_dirs
|
||||
"port/include"
|
||||
"mbedtls/include"
|
||||
@@ -55,14 +55,8 @@ idf_component_register(SRCS "${mbedtls_srcs}"
|
||||
# Add MBEDTLS_MAJOR_VERSION definition to the component library
|
||||
target_compile_definitions(${COMPONENT_LIB} INTERFACE MBEDTLS_MAJOR_VERSION=4)
|
||||
|
||||
# Determine the type of mbedtls component library
|
||||
if(mbedtls_srcs STREQUAL "")
|
||||
# For no sources in component library we must use "INTERFACE"
|
||||
set(linkage_type INTERFACE)
|
||||
else()
|
||||
set(linkage_type PUBLIC)
|
||||
endif()
|
||||
|
||||
# Set the type of mbedtls component library
|
||||
set(linkage_type PUBLIC)
|
||||
|
||||
if(CONFIG_MBEDTLS_CERTIFICATE_BUNDLE)
|
||||
set(bundle_name "x509_crt_bundle")
|
||||
@@ -343,14 +337,6 @@ endif()
|
||||
if(NOT ${IDF_TARGET} STREQUAL "linux")
|
||||
target_sources(tfpsacrypto PRIVATE "${COMPONENT_DIR}/port/esp_hardware.c")
|
||||
endif()
|
||||
# esp_mem.c defines esp_mbedtls_mem_calloc/free, which platform.c (inside the
|
||||
# 'builtin' archive) calls via MBEDTLS_PLATFORM_STD_CALLOC/FREE. Compiling
|
||||
# esp_mem.c directly into 'builtin' ensures the symbols are in the same archive
|
||||
# as their caller, avoiding any link-order dependency on a separate archive.
|
||||
# port/include (for esp_mem.h) and the IDF global includes (sdkconfig.h,
|
||||
# esp_attr.h, esp_heap_caps.h) are both available here via directory-level
|
||||
# include_directories set up by idf_component_register before add_subdirectory.
|
||||
target_sources(builtin PRIVATE "${COMPONENT_DIR}/port/esp_mem.c")
|
||||
|
||||
if(CONFIG_SOC_AES_SUPPORTED)
|
||||
target_include_directories(tfpsacrypto PRIVATE "${COMPONENT_DIR}/port/aes/include")
|
||||
|
||||
Reference in New Issue
Block a user