Skip to content

Conversation

@ldionne
Copy link
Member

@ldionne ldionne commented Dec 9, 2025

Based on comments in #171474, it was brought to my attention that we can modernize and simplify how we perform the test suite installation in libc++ and libc++abi.

Based on comments in llvm#171474, it was brought to my attention that
we can modernize and simplify how we perform the test suite installation
in libc++ and libc++abi.
@ldionne ldionne requested review from a team as code owners December 9, 2025 20:55
@ldionne ldionne requested a review from arichardson December 9, 2025 20:56
@llvmbot llvmbot added libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. libc++abi libc++abi C++ Runtime Library. Not libc++. labels Dec 9, 2025
@llvmbot
Copy link
Member

llvmbot commented Dec 9, 2025

@llvm/pr-subscribers-libcxx

@llvm/pr-subscribers-libcxxabi

Author: Louis Dionne (ldionne)

Changes

Based on comments in #171474, it was brought to my attention that we can modernize and simplify how we perform the test suite installation in libc++ and libc++abi.


Full diff: https://github.com/llvm/llvm-project/pull/171504.diff

2 Files Affected:

  • (modified) libcxx/test/CMakeLists.txt (+10-47)
  • (modified) libcxxabi/test/CMakeLists.txt (+12-47)
diff --git a/libcxx/test/CMakeLists.txt b/libcxx/test/CMakeLists.txt
index f4e577aed57de..57474f92a4bfd 100644
--- a/libcxx/test/CMakeLists.txt
+++ b/libcxx/test/CMakeLists.txt
@@ -5,57 +5,20 @@ add_subdirectory(tools)
 # This ensures that we run the test suite against a setup that matches what we ship
 # in production as closely as possible (in terms of file paths, rpaths, etc).
 set(LIBCXX_TESTING_INSTALL_PREFIX "${LIBCXX_BINARY_DIR}/test-suite-install")
+set(libcxx_test_suite_install_targets cxx-headers cxx cxx_experimental cxx-modules)
 if (LIBCXX_CXX_ABI STREQUAL "libcxxabi")
-  add_custom_target(install-cxxabi-test-suite-prefix
-                        DEPENDS cxxabi-headers
-                                cxxabi
-                        COMMAND ${CMAKE_COMMAND} -E make_directory "${LIBCXX_TESTING_INSTALL_PREFIX}"
-                        COMMAND "${CMAKE_COMMAND}"
-                                -DCMAKE_INSTALL_COMPONENT=cxxabi-headers
-                                -DCMAKE_INSTALL_PREFIX="${LIBCXX_TESTING_INSTALL_PREFIX}"
-                                -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
-                        COMMAND "${CMAKE_COMMAND}"
-                                -DCMAKE_INSTALL_COMPONENT=cxxabi
-                                -DCMAKE_INSTALL_PREFIX="${LIBCXX_TESTING_INSTALL_PREFIX}"
-                                -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
-  add_dependencies(cxx-test-depends install-cxxabi-test-suite-prefix)
+  list(APPEND libcxx_test_suite_install_targets cxxabi-headers cxxabi)
 endif()
-
 if (LIBCXXABI_USE_LLVM_UNWINDER AND TARGET unwind)
-  add_custom_target(install-unwind-test-suite-prefix
-  DEPENDS unwind-headers
-          unwind
-  COMMAND ${CMAKE_COMMAND} -E make_directory "${LIBCXX_TESTING_INSTALL_PREFIX}"
-  COMMAND "${CMAKE_COMMAND}"
-          -DCMAKE_INSTALL_COMPONENT=unwind-headers
-          -DCMAKE_INSTALL_PREFIX="${LIBCXX_TESTING_INSTALL_PREFIX}"
-          -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
-  COMMAND "${CMAKE_COMMAND}"
-          -DCMAKE_INSTALL_COMPONENT=unwind
-          -DCMAKE_INSTALL_PREFIX="${LIBCXX_TESTING_INSTALL_PREFIX}"
-          -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
-  add_dependencies(cxx-test-depends install-unwind-test-suite-prefix)
+  list(APPEND libcxx_test_suite_install_targets unwind-headers unwind)
 endif()
-
-add_custom_target(install-cxx-test-suite-prefix
-                      DEPENDS cxx-headers
-                              cxx
-                              cxx_experimental
-                              cxx-modules
-                      COMMAND ${CMAKE_COMMAND} -E make_directory "${LIBCXX_TESTING_INSTALL_PREFIX}"
-                      COMMAND "${CMAKE_COMMAND}"
-                              -DCMAKE_INSTALL_COMPONENT=cxx-headers
-                              -DCMAKE_INSTALL_PREFIX="${LIBCXX_TESTING_INSTALL_PREFIX}"
-                              -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
-                      COMMAND "${CMAKE_COMMAND}"
-                              -DCMAKE_INSTALL_COMPONENT=cxx-modules
-                              -DCMAKE_INSTALL_PREFIX="${LIBCXX_TESTING_INSTALL_PREFIX}"
-                              -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
-                      COMMAND "${CMAKE_COMMAND}"
-                              -DCMAKE_INSTALL_COMPONENT=cxx
-                              -DCMAKE_INSTALL_PREFIX="${LIBCXX_TESTING_INSTALL_PREFIX}"
-                              -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
-add_dependencies(cxx-test-depends install-cxx-test-suite-prefix)
+foreach(target IN LISTS libcxx_test_suite_install_targets)
+  add_custom_target(libcxx-test-suite-install-${target} DEPENDS "${target}"
+                    COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}"
+                                               --prefix "${LIBCXX_TESTING_INSTALL_PREFIX}"
+                                               --component "${target}")
+  add_dependencies(cxx-test-depends libcxx-test-suite-install-${target})
+endforeach()
 
 set(AUTO_GEN_COMMENT "## Autogenerated by libcxx configuration.\n# Do not edit!")
 set(SERIALIZED_LIT_PARAMS "# Lit parameters serialized here for llvm-lit to pick them up\n")
diff --git a/libcxxabi/test/CMakeLists.txt b/libcxxabi/test/CMakeLists.txt
index 9eabfb08240b6..021bd7cc959e2 100644
--- a/libcxxabi/test/CMakeLists.txt
+++ b/libcxxabi/test/CMakeLists.txt
@@ -8,56 +8,21 @@ macro(pythonize_bool var)
   endif()
 endmacro()
 
+# Install the library and its dependencies at a fake location so we can run the test
+# suite against it. This ensures that we run the test suite against a setup that matches
+# what we ship in production as closely as possible (in terms of file paths, rpaths, etc).
 set(LIBCXXABI_TESTING_INSTALL_PREFIX "${LIBCXXABI_BINARY_DIR}/test-suite-install")
-add_custom_target(libcxxabi-install-cxx-for-testing
-                      DEPENDS cxx-headers
-                              cxx
-                              cxx_experimental
-                              cxx-modules
-                      COMMAND ${CMAKE_COMMAND} -E make_directory "${LIBCXXABI_TESTING_INSTALL_PREFIX}"
-                      COMMAND "${CMAKE_COMMAND}"
-                              -DCMAKE_INSTALL_COMPONENT=cxx-headers
-                              -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_TESTING_INSTALL_PREFIX}"
-                              -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
-                      COMMAND "${CMAKE_COMMAND}"
-                              -DCMAKE_INSTALL_COMPONENT=cxx-modules
-                              -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_TESTING_INSTALL_PREFIX}"
-                              -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
-                      COMMAND "${CMAKE_COMMAND}"
-                              -DCMAKE_INSTALL_COMPONENT=cxx
-                              -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_TESTING_INSTALL_PREFIX}"
-                              -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
-add_dependencies(cxxabi-test-depends libcxxabi-install-cxx-for-testing)
-
-add_custom_target(libcxxabi-install-cxxabi-for-testing
-                      DEPENDS cxxabi-headers
-                              cxxabi
-                      COMMAND ${CMAKE_COMMAND} -E make_directory "${LIBCXXABI_TESTING_INSTALL_PREFIX}"
-                      COMMAND "${CMAKE_COMMAND}"
-                              -DCMAKE_INSTALL_COMPONENT=cxxabi-headers
-                              -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_TESTING_INSTALL_PREFIX}"
-                              -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
-                      COMMAND "${CMAKE_COMMAND}"
-                              -DCMAKE_INSTALL_COMPONENT=cxxabi
-                              -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_TESTING_INSTALL_PREFIX}"
-                              -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
-add_dependencies(cxxabi-test-depends libcxxabi-install-cxxabi-for-testing)
-
+set(libcxxabi_test_suite_install_targets cxx-headers cxx cxx_experimental cxx-modules cxxabi-headers cxxabi)
 if (LIBCXXABI_USE_LLVM_UNWINDER AND TARGET unwind)
-  add_custom_target(libcxxabi-install-unwind-for-testing
-    DEPENDS unwind-headers
-            unwind
-    COMMAND ${CMAKE_COMMAND} -E make_directory "${LIBCXXABI_TESTING_INSTALL_PREFIX}"
-    COMMAND "${CMAKE_COMMAND}"
-            -DCMAKE_INSTALL_COMPONENT=unwind-headers
-            -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_TESTING_INSTALL_PREFIX}"
-            -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
-    COMMAND "${CMAKE_COMMAND}"
-            -DCMAKE_INSTALL_COMPONENT=unwind
-            -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_TESTING_INSTALL_PREFIX}"
-            -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
-  add_dependencies(cxxabi-test-depends libcxxabi-install-unwind-for-testing)
+  list(APPEND libcxxabi_test_suite_install_targets unwind-headers unwind)
 endif()
+foreach(target IN LISTS libcxxabi_test_suite_install_targets)
+  add_custom_target(libcxxabi-test-suite-install-${target} DEPENDS "${target}"
+                    COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}"
+                                               --prefix "${LIBCXXABI_TESTING_INSTALL_PREFIX}"
+                                               --component "${target}")
+  add_dependencies(cxxabi-test-depends libcxxabi-test-suite-install-${target})
+endforeach()
 
 pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER)
 

Copy link
Member

@arichardson arichardson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much simpler. Nice! Not tested it locally but lgtm assuming the tests pass

@ldionne
Copy link
Member Author

ldionne commented Dec 9, 2025

Looks much simpler. Nice! Not tested it locally but lgtm assuming the tests pass

I think I am running into race conditions between the install targets in the CI. I may have to artificially serialize these installations, which IMO is OK.

@arichardson
Copy link
Member

Looks much simpler. Nice! Not tested it locally but lgtm assuming the tests pass

I think I am running into race conditions between the install targets in the CI. I may have to artificially serialize these installations, which IMO is OK.

Does that mean we have multiple install steps trying to write the same file? The one CI failure I see is

  -- Set runtime path of "/home/gha/actions-runner/_work/llvm-project/llvm-project/build/generic-gcc/libcxx/test-suite-install/lib/libc++.so.1.0" to ""
  CMake Error at /home/gha/actions-runner/_work/llvm-project/llvm-project/build/generic-gcc/libcxx/src/cmake_install.cmake:103 (file):
    file INSTALL cannot find
    "/home/gha/actions-runner/_work/llvm-project/llvm-project/build/generic-gcc/lib/libc++experimental.a":

This suggests to me that we are just missing a dependency somewhere?

@ldionne ldionne merged commit f582fc6 into llvm:main Dec 11, 2025
76 of 79 checks passed
@ldionne ldionne deleted the review/simplify-libcxx-test-dependencies branch December 11, 2025 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++abi libc++abi C++ Runtime Library. Not libc++. libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants