From b6ef9ec78f157c0e8d4d3a7b7c111b2de6c9194f Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Thu, 5 Mar 2026 17:32:51 +0000 Subject: [PATCH 01/13] Support DESTDIR for install and add build-system test Signed-off-by: Yi Wu --- library/CMakeLists.txt | 2 +- tests/scripts/components-build-system.sh | 26 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 5474e2cacf..19386ee4d4 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -362,7 +362,7 @@ foreach(target IN LISTS tf_psa_crypto_library_targets) RENAME "libmbedcrypto.so.${MBEDTLS_VERSION}" ) install(CODE " - set(_libdir \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\") + set(_libdir \"\$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\") execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"libmbedcrypto.so.${MBEDTLS_VERSION}\" diff --git a/tests/scripts/components-build-system.sh b/tests/scripts/components-build-system.sh index ce923b5cc4..34b3c985dd 100644 --- a/tests/scripts/components-build-system.sh +++ b/tests/scripts/components-build-system.sh @@ -155,6 +155,32 @@ support_test_cmake_as_package_install () { support_test_cmake_out_of_source } +component_test_cmake_install_with_destdir () { + # Remove existing generated files so that we use the ones CMake + # generates + $MAKE_COMMAND neat + + msg "install: cmake with DESTDIR staging" + MBEDTLS_ROOT_DIR="$PWD" + mkdir "$OUT_OF_SOURCE_DIR" + cd "$OUT_OF_SOURCE_DIR" + cmake -DGEN_FILES=ON -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DCMAKE_INSTALL_PREFIX:PATH=/usr "$MBEDTLS_ROOT_DIR" + make + + DESTDIR="$OUT_OF_SOURCE_DIR/stage" make install + + install_libdir="$(sed -n 's/^CMAKE_INSTALL_LIBDIR:PATH=//p' CMakeCache.txt)" + test -n "$install_libdir" + test -L "$OUT_OF_SOURCE_DIR/stage/usr/${install_libdir}/libmbedcrypto.so" + + cd "$MBEDTLS_ROOT_DIR" + rm -rf "$OUT_OF_SOURCE_DIR" +} + +support_test_cmake_install_with_destdir () { + support_test_cmake_out_of_source +} + component_build_cmake_custom_config_file () { # Make a copy of config file to use for the in-tree test cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h From d9fa082e30ee2fa8e8f88bf01ebf5b6362e55f90 Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Tue, 10 Mar 2026 11:04:06 +0000 Subject: [PATCH 02/13] Add changelog Signed-off-by: Yi Wu --- ChangeLog.d/cmake-destdir-instal.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 ChangeLog.d/cmake-destdir-instal.txt diff --git a/ChangeLog.d/cmake-destdir-instal.txt b/ChangeLog.d/cmake-destdir-instal.txt new file mode 100644 index 0000000000..15892b951a --- /dev/null +++ b/ChangeLog.d/cmake-destdir-instal.txt @@ -0,0 +1,3 @@ +Bugfix + * CMake installs now honor `DESTDIR` for the compatibility + `libmbedcrypto.so` symlink during staged installs. \ No newline at end of file From 287d0a8d3c6557d46c3b6229e9965f59b4792086 Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Fri, 13 Mar 2026 10:11:42 +0000 Subject: [PATCH 03/13] ChangeLog newline fix Signed-off-by: Yi Wu --- ChangeLog.d/cmake-destdir-instal.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ChangeLog.d/cmake-destdir-instal.txt b/ChangeLog.d/cmake-destdir-instal.txt index 15892b951a..5bf4c363de 100644 --- a/ChangeLog.d/cmake-destdir-instal.txt +++ b/ChangeLog.d/cmake-destdir-instal.txt @@ -1,3 +1,3 @@ -Bugfix +Changes * CMake installs now honor `DESTDIR` for the compatibility - `libmbedcrypto.so` symlink during staged installs. \ No newline at end of file + `libmbedcrypto.so` symlink during staged installs. From a8a111182703cafd00490c84f92227beb88bb731 Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Fri, 13 Mar 2026 10:16:30 +0000 Subject: [PATCH 04/13] ChangeLog fix Signed-off-by: Yi Wu --- ChangeLog.d/cmake-destdir-instal.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ChangeLog.d/cmake-destdir-instal.txt b/ChangeLog.d/cmake-destdir-instal.txt index 5bf4c363de..a5471d08d7 100644 --- a/ChangeLog.d/cmake-destdir-instal.txt +++ b/ChangeLog.d/cmake-destdir-instal.txt @@ -1,3 +1,3 @@ Changes - * CMake installs now honor `DESTDIR` for the compatibility - `libmbedcrypto.so` symlink during staged installs. + * Restore DESTDIR support for CMake installs of compatibility + `libmbedcrypto` symlinks. From 532db3d49ef3ea774fb08333fca36b7a784df60d Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Thu, 26 Mar 2026 09:23:44 +0000 Subject: [PATCH 05/13] Test: add symlinks and dangling link check Signed-off-by: Yi Wu --- tests/scripts/components-build-system.sh | 34 +++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tests/scripts/components-build-system.sh b/tests/scripts/components-build-system.sh index 34b3c985dd..e882720690 100644 --- a/tests/scripts/components-build-system.sh +++ b/tests/scripts/components-build-system.sh @@ -169,9 +169,37 @@ component_test_cmake_install_with_destdir () { DESTDIR="$OUT_OF_SOURCE_DIR/stage" make install - install_libdir="$(sed -n 's/^CMAKE_INSTALL_LIBDIR:PATH=//p' CMakeCache.txt)" - test -n "$install_libdir" - test -L "$OUT_OF_SOURCE_DIR/stage/usr/${install_libdir}/libmbedcrypto.so" + install_lib_subdir="$(sed -n 's/^CMAKE_INSTALL_LIBDIR:PATH=//p' CMakeCache.txt)" + if [ -z "$install_lib_subdir" ]; then + echo "Error: Failed to read CMAKE_INSTALL_LIBDIR from CMakeCache.txt" >&2 + exit 1 + fi + + install_lib_path="$OUT_OF_SOURCE_DIR/stage/usr/${install_lib_subdir}" + + if [ ! -L "$install_lib_path/libmbedcrypto.so" ]; then + echo "Error: Expected symlink missing: $install_lib_path/libmbedcrypto.so" >&2 + ls -l "$install_lib_path" >&2 || true + exit 1 + fi + + # Match the install(CODE) logic in library/CMakeLists.txt: + # libmbedcrypto.so.${MBEDTLS_CRYPTO_SOVERSION} -> libmbedcrypto.so.${MBEDTLS_VERSION} + # libmbedcrypto.so -> libmbedcrypto.so.${MBEDTLS_CRYPTO_SOVERSION} + symlink_count="$(find "$install_lib_path" -maxdepth 1 -type l -name 'libmbedcrypto.so*' | wc -l)" + if [ "$symlink_count" -lt 2 ]; then + echo "Error: Expected at least 2 libmbedcrypto.so* symlinks, got $symlink_count" >&2 + ls -l "$install_lib_path"/libmbedcrypto.so* >&2 || true + exit 1 + fi + + for symlink in "$install_lib_path"/libmbedcrypto.so*; do + if [ -L "$symlink" ] && [ ! -e "$symlink" ]; then + echo "Error: Dangling symlink found: $symlink -> $(readlink "$symlink")" >&2 + ls -l "$install_lib_path"/libmbedcrypto.so* >&2 || true + exit 1 + fi + done cd "$MBEDTLS_ROOT_DIR" rm -rf "$OUT_OF_SOURCE_DIR" From f14f28ce75a8943e2d1ddfc15a00f3fbda358df5 Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Fri, 10 Apr 2026 10:27:09 +0100 Subject: [PATCH 06/13] ChangeLog padding space fix Signed-off-by: Yi Wu --- ChangeLog.d/cmake-destdir-instal.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.d/cmake-destdir-instal.txt b/ChangeLog.d/cmake-destdir-instal.txt index a5471d08d7..3dd2d167b1 100644 --- a/ChangeLog.d/cmake-destdir-instal.txt +++ b/ChangeLog.d/cmake-destdir-instal.txt @@ -1,3 +1,3 @@ Changes * Restore DESTDIR support for CMake installs of compatibility - `libmbedcrypto` symlinks. + `libmbedcrypto` symlinks. From 15be9e904863f4edd46c4b3b45f7d441e098334f Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Fri, 10 Apr 2026 14:33:39 +0100 Subject: [PATCH 07/13] ChangeLog fixes Signed-off-by: Yi Wu --- ChangeLog.d/cmake-destdir-instal.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ChangeLog.d/cmake-destdir-instal.txt b/ChangeLog.d/cmake-destdir-instal.txt index 3dd2d167b1..6d6e4dc1a7 100644 --- a/ChangeLog.d/cmake-destdir-instal.txt +++ b/ChangeLog.d/cmake-destdir-instal.txt @@ -1,3 +1,3 @@ -Changes +Feature * Restore DESTDIR support for CMake installs of compatibility - `libmbedcrypto` symlinks. + libmbedcrypto symlinks. Fixes #10627. From e9e0409b11e4c204c6a09a50b26709fab5a741cb Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Mon, 13 Apr 2026 12:48:01 +0100 Subject: [PATCH 08/13] tests: fix DESTDIR install checks and add macOS compatibility Signed-off-by: Yi Wu --- tests/scripts/components-build-system.sh | 50 ++++++++++-------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/tests/scripts/components-build-system.sh b/tests/scripts/components-build-system.sh index e882720690..0aba7f7f3b 100644 --- a/tests/scripts/components-build-system.sh +++ b/tests/scripts/components-build-system.sh @@ -170,39 +170,31 @@ component_test_cmake_install_with_destdir () { DESTDIR="$OUT_OF_SOURCE_DIR/stage" make install install_lib_subdir="$(sed -n 's/^CMAKE_INSTALL_LIBDIR:PATH=//p' CMakeCache.txt)" - if [ -z "$install_lib_subdir" ]; then - echo "Error: Failed to read CMAKE_INSTALL_LIBDIR from CMakeCache.txt" >&2 - exit 1 - fi + [ -n "$install_lib_subdir" ] # Failed to read CMAKE_INSTALL_LIBDIR from CMakeCache.txt install_lib_path="$OUT_OF_SOURCE_DIR/stage/usr/${install_lib_subdir}" - if [ ! -L "$install_lib_path/libmbedcrypto.so" ]; then - echo "Error: Expected symlink missing: $install_lib_path/libmbedcrypto.so" >&2 - ls -l "$install_lib_path" >&2 || true - exit 1 + if [[ "$OSTYPE" == linux* ]]; then + # library/CMakeLists.txt installs libmbedcrypto.so with a versioned + # symlink chain on Linux. + for lib in tfpsacrypto mbedcrypto mbedx509 mbedtls; do + [ -f "$install_lib_path/lib${lib}.a" ] + [ -L "$install_lib_path/lib${lib}.so" ] + [ -e "$install_lib_path/lib${lib}.so" ] + versioned=( "$install_lib_path/lib${lib}.so".* ) + [ -L "${versioned[0]}" ] + [ -e "${versioned[0]}" ] + done + elif [[ "$OSTYPE" == darwin* ]]; then + # On macOS the custom install logic installs libmbedcrypto.dylib + # directly without a versioned symlink chain. + for lib in tfpsacrypto mbedcrypto mbedx509 mbedtls; do + [ -f "$install_lib_path/lib${lib}.a" ] + [ -e "$install_lib_path/lib${lib}.dylib" ] + done + else + echo "Unsupported platform for DESTDIR shared library checks" fi - - # Match the install(CODE) logic in library/CMakeLists.txt: - # libmbedcrypto.so.${MBEDTLS_CRYPTO_SOVERSION} -> libmbedcrypto.so.${MBEDTLS_VERSION} - # libmbedcrypto.so -> libmbedcrypto.so.${MBEDTLS_CRYPTO_SOVERSION} - symlink_count="$(find "$install_lib_path" -maxdepth 1 -type l -name 'libmbedcrypto.so*' | wc -l)" - if [ "$symlink_count" -lt 2 ]; then - echo "Error: Expected at least 2 libmbedcrypto.so* symlinks, got $symlink_count" >&2 - ls -l "$install_lib_path"/libmbedcrypto.so* >&2 || true - exit 1 - fi - - for symlink in "$install_lib_path"/libmbedcrypto.so*; do - if [ -L "$symlink" ] && [ ! -e "$symlink" ]; then - echo "Error: Dangling symlink found: $symlink -> $(readlink "$symlink")" >&2 - ls -l "$install_lib_path"/libmbedcrypto.so* >&2 || true - exit 1 - fi - done - - cd "$MBEDTLS_ROOT_DIR" - rm -rf "$OUT_OF_SOURCE_DIR" } support_test_cmake_install_with_destdir () { From 6fb557c31a0327f86a8a0dc281d98171931e4762 Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Mon, 13 Apr 2026 15:00:44 +0100 Subject: [PATCH 09/13] ChangeLog fix Signed-off-by: Yi Wu --- ChangeLog.d/cmake-destdir-instal.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.d/cmake-destdir-instal.txt b/ChangeLog.d/cmake-destdir-instal.txt index 6d6e4dc1a7..1638a4bea9 100644 --- a/ChangeLog.d/cmake-destdir-instal.txt +++ b/ChangeLog.d/cmake-destdir-instal.txt @@ -1,3 +1,3 @@ -Feature +Features * Restore DESTDIR support for CMake installs of compatibility libmbedcrypto symlinks. Fixes #10627. From 331ad77fe24c5756e9b3bc658cb5b24e55254148 Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Mon, 13 Apr 2026 15:13:52 +0100 Subject: [PATCH 10/13] test: add debug output and fix for win config Signed-off-by: Yi Wu --- tests/scripts/components-build-system.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/scripts/components-build-system.sh b/tests/scripts/components-build-system.sh index 0aba7f7f3b..d901f98090 100644 --- a/tests/scripts/components-build-system.sh +++ b/tests/scripts/components-build-system.sh @@ -174,15 +174,22 @@ component_test_cmake_install_with_destdir () { install_lib_path="$OUT_OF_SOURCE_DIR/stage/usr/${install_lib_subdir}" - if [[ "$OSTYPE" == linux* ]]; then + if [[ "$OSTYPE" != darwin* ]]; then # library/CMakeLists.txt installs libmbedcrypto.so with a versioned # symlink chain on Linux. for lib in tfpsacrypto mbedcrypto mbedx509 mbedtls; do + if [ "$QUIET" -eq 0 ]; then + echo "Checking lib=$lib" + fi [ -f "$install_lib_path/lib${lib}.a" ] [ -L "$install_lib_path/lib${lib}.so" ] [ -e "$install_lib_path/lib${lib}.so" ] versioned=( "$install_lib_path/lib${lib}.so".* ) - [ -L "${versioned[0]}" ] + if [ "$QUIET" -eq 0 ]; then + declare -p versioned + fi + [ "${#versioned[@]}" -ge 1 ] + # [ -L "${versioned[0]}" ] [ -e "${versioned[0]}" ] done elif [[ "$OSTYPE" == darwin* ]]; then From f38b17e7a0a0e88bd29fccc125ff56f5dfd48d64 Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Tue, 14 Apr 2026 10:12:44 +0100 Subject: [PATCH 11/13] test: reorder if-else structure Signed-off-by: Yi Wu --- tests/scripts/components-build-system.sh | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/scripts/components-build-system.sh b/tests/scripts/components-build-system.sh index d901f98090..37764bc1b8 100644 --- a/tests/scripts/components-build-system.sh +++ b/tests/scripts/components-build-system.sh @@ -174,7 +174,14 @@ component_test_cmake_install_with_destdir () { install_lib_path="$OUT_OF_SOURCE_DIR/stage/usr/${install_lib_subdir}" - if [[ "$OSTYPE" != darwin* ]]; then + if [[ "$OSTYPE" == darwin* ]]; then + # On macOS the custom install logic installs libmbedcrypto.dylib + # directly without a versioned symlink chain. + for lib in tfpsacrypto mbedcrypto mbedx509 mbedtls; do + [ -f "$install_lib_path/lib${lib}.a" ] + [ -e "$install_lib_path/lib${lib}.dylib" ] + done + else # library/CMakeLists.txt installs libmbedcrypto.so with a versioned # symlink chain on Linux. for lib in tfpsacrypto mbedcrypto mbedx509 mbedtls; do @@ -188,19 +195,10 @@ component_test_cmake_install_with_destdir () { if [ "$QUIET" -eq 0 ]; then declare -p versioned fi - [ "${#versioned[@]}" -ge 1 ] - # [ -L "${versioned[0]}" ] + # [ "${#versioned[@]}" -ge 1 ] + [ -L "${versioned[0]}" ] [ -e "${versioned[0]}" ] done - elif [[ "$OSTYPE" == darwin* ]]; then - # On macOS the custom install logic installs libmbedcrypto.dylib - # directly without a versioned symlink chain. - for lib in tfpsacrypto mbedcrypto mbedx509 mbedtls; do - [ -f "$install_lib_path/lib${lib}.a" ] - [ -e "$install_lib_path/lib${lib}.dylib" ] - done - else - echo "Unsupported platform for DESTDIR shared library checks" fi } From 0c02d74a483b9f0e18c04a9fc4186cb243829b09 Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Tue, 14 Apr 2026 11:06:16 +0100 Subject: [PATCH 12/13] test: versioned symlink order fix Signed-off-by: Yi Wu --- tests/scripts/components-build-system.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/scripts/components-build-system.sh b/tests/scripts/components-build-system.sh index 37764bc1b8..86519fcd89 100644 --- a/tests/scripts/components-build-system.sh +++ b/tests/scripts/components-build-system.sh @@ -191,13 +191,21 @@ component_test_cmake_install_with_destdir () { [ -f "$install_lib_path/lib${lib}.a" ] [ -L "$install_lib_path/lib${lib}.so" ] [ -e "$install_lib_path/lib${lib}.so" ] + + # do not assume a fixed match ordering. versioned=( "$install_lib_path/lib${lib}.so".* ) if [ "$QUIET" -eq 0 ]; then declare -p versioned fi - # [ "${#versioned[@]}" -ge 1 ] - [ -L "${versioned[0]}" ] - [ -e "${versioned[0]}" ] + versioned_symlink= + for candidate in "${versioned[@]}"; do + if [ -L "$candidate" ]; then + versioned_symlink="$candidate" + break + fi + done + [ -n "$versioned_symlink" ] + [ -e "$versioned_symlink" ] done fi } From 970df30a8f23b2d0e26a77072bcf08ce6bff017d Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Wed, 15 Apr 2026 11:58:23 +0100 Subject: [PATCH 13/13] test: improve symlink checks Signed-off-by: Yi Wu --- tests/scripts/components-build-system.sh | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/scripts/components-build-system.sh b/tests/scripts/components-build-system.sh index 86519fcd89..bf0262484e 100644 --- a/tests/scripts/components-build-system.sh +++ b/tests/scripts/components-build-system.sh @@ -192,20 +192,15 @@ component_test_cmake_install_with_destdir () { [ -L "$install_lib_path/lib${lib}.so" ] [ -e "$install_lib_path/lib${lib}.so" ] - # do not assume a fixed match ordering. - versioned=( "$install_lib_path/lib${lib}.so".* ) + # Match ABI-version names such as libxxx.so.17 + # and check that symlink. + versioned=( "$install_lib_path/lib${lib}.so".+([0-9]) ) if [ "$QUIET" -eq 0 ]; then declare -p versioned fi - versioned_symlink= - for candidate in "${versioned[@]}"; do - if [ -L "$candidate" ]; then - versioned_symlink="$candidate" - break - fi - done - [ -n "$versioned_symlink" ] - [ -e "$versioned_symlink" ] + [ "${#versioned[@]}" -eq 1 ] + [ -L "${versioned[0]}" ] + [ -e "${versioned[0]}" ] done fi }