From fb8a7c774d62406bba98765236111159edfa96c1 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Wed, 10 Dec 2025 07:59:17 -0500 Subject: [PATCH] [libunwind] Make sure libunwind test dependencies are installed before running tests (#171474) This patch adds an installation step where we install libc++ in a fake installation tree before testing libunwind. This is necessary because some configurations (in particular "generic-merged") require libc++ to be installed, since the libunwind tests are actually linking libc++.so in which libc++abi.a and libunwind.a have been merged. Without this, we were actually failing to find `libc++.so` to link against and then linking against whatever system library we'd find in the provided search directories. While this happens to work in the current CI configuration, this breaks down when updating to newer build tools. --- libunwind/CMakeLists.txt | 3 +++ libunwind/test/CMakeLists.txt | 29 ++++++++++++++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt index 97edff0b87ea..fbef71f3f744 100644 --- a/libunwind/CMakeLists.txt +++ b/libunwind/CMakeLists.txt @@ -336,6 +336,9 @@ if (RUNTIMES_EXECUTE_ONLY_CODE) add_compile_definitions(_LIBUNWIND_EXECUTE_ONLY_CODE) endif() +add_custom_target(unwind-test-depends + COMMENT "Build dependencies required to run the libunwind test suite.") + #=============================================================================== # Setup Source Code #=============================================================================== diff --git a/libunwind/test/CMakeLists.txt b/libunwind/test/CMakeLists.txt index c222c0bdbf5a..42838218dac4 100644 --- a/libunwind/test/CMakeLists.txt +++ b/libunwind/test/CMakeLists.txt @@ -8,19 +8,22 @@ macro(pythonize_bool var) endif() endmacro() +# Install targets required to run libunwind tests into a temporary location. +# +# This ensures that we run the tests against the final installed products, which +# is closer to what we actually ship than the contents of the build tree. set(LIBUNWIND_TESTING_INSTALL_PREFIX "${LIBUNWIND_BINARY_DIR}/test-suite-install") -add_custom_target(libunwind-install-unwind-for-testing - DEPENDS unwind-headers - unwind - COMMAND ${CMAKE_COMMAND} -E make_directory "${LIBUNWIND_TESTING_INSTALL_PREFIX}" - COMMAND "${CMAKE_COMMAND}" - -DCMAKE_INSTALL_COMPONENT=unwind-headers - -DCMAKE_INSTALL_PREFIX="${LIBUNWIND_TESTING_INSTALL_PREFIX}" - -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" - COMMAND "${CMAKE_COMMAND}" - -DCMAKE_INSTALL_COMPONENT=unwind - -DCMAKE_INSTALL_PREFIX="${LIBUNWIND_TESTING_INSTALL_PREFIX}" - -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") +set(libunwind_test_suite_install_targets unwind-headers unwind) +if ("libcxx" IN_LIST LLVM_ENABLE_RUNTIMES) + list(APPEND libunwind_test_suite_install_targets cxx-headers cxx cxx_experimental cxx-modules cxxabi-headers cxxabi) +endif() +foreach(target IN LISTS libunwind_test_suite_install_targets) + add_custom_target(libunwind-test-suite-install-${target} DEPENDS "${target}" + COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}" + --prefix "${LIBUNWIND_TESTING_INSTALL_PREFIX}" + --component "${target}") + add_dependencies(unwind-test-depends libunwind-test-suite-install-${target}) +endforeach() pythonize_bool(LIBUNWIND_ENABLE_CET) pythonize_bool(LIBUNWIND_ENABLE_GCS) @@ -62,4 +65,4 @@ configure_lit_site_cfg( add_lit_testsuite(check-unwind "Running libunwind tests" ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS libunwind-install-unwind-for-testing) + DEPENDS unwind-test-depends)