feat(build): provide ldgen with a list of mutable libraries

The build system keeps track of each component source. Currently
there are four types of sources:

1. "project_components" - project components
2. "project_extra_components" - components from EXTRA_COMPONENT_DIRS
3. "project_managed_components" - custom project dependencies managed by the IDF Component Manager
4. "idf_components" - ESP-IDF built-in components, typically under /components

This can be used to identify the component libraries that are likely to
change during application development and pass them to ldgen as mutable
libraries. Add all components with "project_components" as their source
as mutable.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
This commit is contained in:
Frantisek Hrbata
2025-05-22 14:52:27 +02:00
parent 8ac9e65f4f
commit 1eceeaace2
+38
View File
@@ -88,6 +88,32 @@ function(__ldgen_get_lib_deps_of_target target out_list_var)
set(${out_list_var} ${out_list} PARENT_SCOPE)
endfunction()
# __ldgen_get_mutable_libs
#
# Helper function to get the list of library file name generator expressions
# for project components. These libraries are placed by ldgen into a separate
# location in the linker script, allowing the fast reflashing feature.
#
function(__ldgen_get_mutable_libs out_list_var)
set(mutable_libs)
idf_build_get_property(build_component_targets __BUILD_COMPONENT_TARGETS)
foreach(component_target ${build_component_targets})
__component_get_property(component_source ${component_target} COMPONENT_SOURCE)
__component_get_property(component_lib ${component_target} COMPONENT_LIB)
__component_get_property(component_type ${component_target} COMPONENT_TYPE)
if("${component_type}" STREQUAL "CONFIG_ONLY")
# Configuration only component interface target without a library.
continue()
endif()
if(NOT "${component_source}" STREQUAL "project_components")
# Add only project components as mutable.
continue()
endif()
set(unstable_lib "$<TARGET_LINKER_FILE_NAME:${component_lib}>")
list(APPEND mutable_libs "${unstable_lib}")
endforeach()
set(${out_list_var} ${mutable_libs} PARENT_SCOPE)
endfunction()
# __ldgen_create_target
#
@@ -177,6 +203,17 @@ function(__ldgen_create_target exe_target)
message(STATUS "Mapping check enabled in ldgen")
endif()
if(CONFIG_ESPTOOLPY_FAST_REFLASHING)
# Create a file containing a list of mutable libraries used by ldgen
# for fast reflashing.
set(mutable_libs_path "${build_dir}/ldgen_mutable_libraries")
__ldgen_get_mutable_libs(mutable_libs)
list(JOIN mutable_libs "\n" mutable_libs_str)
file(GENERATE OUTPUT "${mutable_libs_path}"
CONTENT "${mutable_libs_str}")
set(mutable_libs_option "--mutable-libraries-file" "${mutable_libs_path}")
endif()
add_custom_command(
OUTPUT ${output}
COMMAND ${python} "${idf_path}/tools/ldgen/ldgen.py"
@@ -189,6 +226,7 @@ function(__ldgen_create_target exe_target)
--libraries-file "${build_dir}/ldgen_libraries"
--objdump "${CMAKE_OBJDUMP}"
${ldgen_check}
${mutable_libs_option}
DEPENDS ${template} ${ldgen_fragment_files} ${ldgen_deps} ${SDKCONFIG}
VERBATIM
)