Skip to content

Commit 0e8208e

Browse files
authored
[libc++] Run the Lit test suite against an installed version of the library (#96910)
We always strive to test libc++ as close as possible to the way we are actually shipping it. This was approximated reasonably well by setting up the minimal driver flags when running the test suite, however we were running the test suite against the library located in the build directory. This patch improves the situation by installing the library (the headers, the built library, modules, etc) into a fake location and then running the test suite against that fake "installation root". This should open the door to getting rid of the temporary copy of the headers we make during the build process, however this is left for a future improvement. Note that this adds quite a bit of verbosity whenever running the test suite because we install the headers beforehand every time. We should be able to override this to silence it, however CMake doesn't currently give us a way to do that, see https://gitlab.kitware.com/cmake/cmake/-/issues/26085.
1 parent f581553 commit 0e8208e

13 files changed

+96
-28
lines changed

libcxx/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS
131131
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
132132
set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-gcc.cfg.in")
133133
elseif(MINGW)
134-
set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-mingw.cfg.in")
134+
if (LIBCXX_ENABLE_SHARED)
135+
set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-mingw.cfg.in")
136+
else()
137+
set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static-mingw.cfg.in")
138+
endif()
135139
elseif(WIN32) # clang-cl
136140
if (LIBCXX_ENABLE_SHARED)
137141
set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-clangcl.cfg.in")

libcxx/cmake/caches/Apple.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
set(CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
2+
set(CMAKE_INSTALL_NAME_DIR "/usr/lib" CACHE STRING "")
23
set(CMAKE_POSITION_INDEPENDENT_CODE OFF CACHE BOOL "")
34

45
set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")

libcxx/modules/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ add_custom_target(generate-cxx-modules
202202
ALL DEPENDS
203203
${_all_modules}
204204
)
205-
add_dependencies(cxx-test-depends generate-cxx-modules)
206205

207206
# Configure the modules manifest.
208207
# Use the relative path between the installation and the module in the json

libcxx/src/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ endif()
309309

310310
# Add a meta-target for both libraries.
311311
add_custom_target(cxx DEPENDS ${LIBCXX_BUILD_TARGETS})
312-
add_dependencies(cxx-test-depends cxx)
313312

314313
set(LIBCXX_EXPERIMENTAL_SOURCES
315314
experimental/keep.cpp
@@ -357,7 +356,6 @@ set_target_properties(cxx_experimental
357356
)
358357
cxx_add_common_build_flags(cxx_experimental)
359358
target_compile_options(cxx_experimental PUBLIC -D_LIBCPP_ENABLE_EXPERIMENTAL)
360-
add_dependencies(cxx-test-depends cxx_experimental)
361359

362360
if (LIBCXX_INSTALL_SHARED_LIBRARY)
363361
install(TARGETS cxx_shared

libcxx/test/CMakeLists.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,62 @@ if (LIBCXX_INCLUDE_BENCHMARKS)
55
add_subdirectory(benchmarks)
66
endif()
77

8+
# Install the library at a fake location so we can run the test suite against it.
9+
# This ensures that we run the test suite against a setup that matches what we ship
10+
# in production as closely as possible (in terms of file paths, rpaths, etc).
11+
set(LIBCXX_TESTING_INSTALL_PREFIX "${LIBCXX_BINARY_DIR}/test-suite-install")
12+
if (LIBCXX_CXX_ABI STREQUAL "libcxxabi")
13+
add_custom_target(install-cxxabi-test-suite-prefix
14+
DEPENDS cxxabi-headers
15+
cxxabi
16+
COMMAND ${CMAKE_COMMAND} -E make_directory "${LIBCXX_TESTING_INSTALL_PREFIX}"
17+
COMMAND "${CMAKE_COMMAND}"
18+
-DCMAKE_INSTALL_COMPONENT=cxxabi-headers
19+
-DCMAKE_INSTALL_PREFIX="${LIBCXX_TESTING_INSTALL_PREFIX}"
20+
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
21+
COMMAND "${CMAKE_COMMAND}"
22+
-DCMAKE_INSTALL_COMPONENT=cxxabi
23+
-DCMAKE_INSTALL_PREFIX="${LIBCXX_TESTING_INSTALL_PREFIX}"
24+
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
25+
add_dependencies(cxx-test-depends install-cxxabi-test-suite-prefix)
26+
endif()
27+
28+
if (LIBCXXABI_USE_LLVM_UNWINDER AND TARGET unwind)
29+
add_custom_target(install-unwind-test-suite-prefix
30+
DEPENDS unwind-headers
31+
unwind
32+
COMMAND ${CMAKE_COMMAND} -E make_directory "${LIBCXX_TESTING_INSTALL_PREFIX}"
33+
COMMAND "${CMAKE_COMMAND}"
34+
-DCMAKE_INSTALL_COMPONENT=unwind-headers
35+
-DCMAKE_INSTALL_PREFIX="${LIBCXX_TESTING_INSTALL_PREFIX}"
36+
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
37+
COMMAND "${CMAKE_COMMAND}"
38+
-DCMAKE_INSTALL_COMPONENT=unwind
39+
-DCMAKE_INSTALL_PREFIX="${LIBCXX_TESTING_INSTALL_PREFIX}"
40+
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
41+
add_dependencies(cxx-test-depends install-unwind-test-suite-prefix)
42+
endif()
43+
44+
add_custom_target(install-cxx-test-suite-prefix
45+
DEPENDS cxx-headers
46+
cxx
47+
cxx_experimental
48+
cxx-modules
49+
COMMAND ${CMAKE_COMMAND} -E make_directory "${LIBCXX_TESTING_INSTALL_PREFIX}"
50+
COMMAND "${CMAKE_COMMAND}"
51+
-DCMAKE_INSTALL_COMPONENT=cxx-headers
52+
-DCMAKE_INSTALL_PREFIX="${LIBCXX_TESTING_INSTALL_PREFIX}"
53+
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
54+
COMMAND "${CMAKE_COMMAND}"
55+
-DCMAKE_INSTALL_COMPONENT=cxx-modules
56+
-DCMAKE_INSTALL_PREFIX="${LIBCXX_TESTING_INSTALL_PREFIX}"
57+
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
58+
COMMAND "${CMAKE_COMMAND}"
59+
-DCMAKE_INSTALL_COMPONENT=cxx
60+
-DCMAKE_INSTALL_PREFIX="${LIBCXX_TESTING_INSTALL_PREFIX}"
61+
-P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
62+
add_dependencies(cxx-test-depends install-cxx-test-suite-prefix)
63+
864
set(AUTO_GEN_COMMENT "## Autogenerated by libcxx configuration.\n# Do not edit!")
965
set(SERIALIZED_LIT_PARAMS "# Lit parameters serialized here for llvm-lit to pick them up\n")
1066

libcxx/test/configs/cmake-bridge.cfg.in

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ config.test_exec_root = os.path.join('@CMAKE_BINARY_DIR@', 'test')
2424

2525
# Add substitutions for bootstrapping the test suite configuration
2626
config.substitutions.append(('%{libcxx-dir}', '@LIBCXX_SOURCE_DIR@'))
27-
config.substitutions.append(('%{include-dir}', '@LIBCXX_GENERATED_INCLUDE_DIR@'))
28-
config.substitutions.append(('%{target-include-dir}', '@LIBCXX_GENERATED_INCLUDE_TARGET_DIR@'))
29-
config.substitutions.append(('%{lib-dir}', '@LIBCXX_LIBRARY_DIR@'))
30-
config.substitutions.append(('%{module-dir}', '@LIBCXX_GENERATED_MODULE_DIR@'))
27+
config.substitutions.append(('%{install-prefix}', '@LIBCXX_TESTING_INSTALL_PREFIX@'))
28+
config.substitutions.append(('%{include-dir}', '@LIBCXX_TESTING_INSTALL_PREFIX@/@LIBCXX_INSTALL_INCLUDE_DIR@'))
29+
config.substitutions.append(('%{target-include-dir}', '@LIBCXX_TESTING_INSTALL_PREFIX@/@LIBCXX_INSTALL_INCLUDE_TARGET_DIR@'))
30+
config.substitutions.append(('%{lib-dir}', '@LIBCXX_TESTING_INSTALL_PREFIX@/@LIBCXX_INSTALL_LIBRARY_DIR@'))
31+
config.substitutions.append(('%{module-dir}', '@LIBCXX_TESTING_INSTALL_PREFIX@/@LIBCXX_INSTALL_MODULES_DIR@'))
3132
config.substitutions.append(('%{test-tools-dir}', '@LIBCXX_TEST_TOOLS_PATH@'))

libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ config.substitutions.append(('%{link_flags}',
2525
'-nostdlib -L %{lib-dir} -lc++ -l' + cxx_lib
2626
))
2727
config.substitutions.append(('%{exec}',
28-
'%{executor} --execdir %T --prepend_env PATH=%{lib-dir} -- '
28+
'%{executor} --execdir %T --prepend_env PATH=%{install-prefix}/bin -- '
2929
))
3030

3131
import os, site
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This testing configuration handles running the test suite against LLVM's libc++
2+
# using either a DLL or a static library, with MinGW/Clang on Windows.
3+
4+
lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
5+
6+
config.substitutions.append(('%{flags}', ''))
7+
config.substitutions.append(('%{compile_flags}',
8+
'-nostdinc++ -I %{target-include-dir} -I %{include-dir} -I %{libcxx-dir}/test/support'
9+
))
10+
config.substitutions.append(('%{link_flags}',
11+
'-nostdlib++ -L %{lib-dir} -lc++'
12+
))
13+
config.substitutions.append(('%{exec}',
14+
'%{executor} --execdir %T --prepend_env PATH=%{install-prefix}/bin -- '
15+
))
16+
17+
import os, site
18+
site.addsitedir(os.path.join('@LIBCXX_SOURCE_DIR@', 'utils'))
19+
import libcxx.test.params, libcxx.test.config
20+
libcxx.test.config.configure(
21+
libcxx.test.params.DEFAULT_PARAMETERS,
22+
libcxx.test.features.DEFAULT_FEATURES,
23+
config,
24+
lit_config
25+
)

libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ config.substitutions.append(('%{link_flags}',
2626
'-nostdlib -L %{lib-dir} -lc++ -l' + cxx_lib
2727
))
2828
config.substitutions.append(('%{exec}',
29-
'%{executor} --execdir %T --prepend_env PATH=%{lib-dir} -- '
29+
'%{executor} --execdir %T --prepend_env PATH=%{install-prefix}/bin -- '
3030
))
3131

3232
import os, site

libcxx/test/libcxx/vendor/apple/system-install-properties.sh.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@
3232
// various tools like dyld and ld64 will treat us specially if they recognize us as being a
3333
// system library.
3434
//
35-
// TODO: We currently don't do that correctly in the CMake build.
36-
//
37-
// XRUNX: otool -L "%{lib-dir}/libc++.1.dylib" | grep '/usr/lib/libc++.1.dylib'
38-
// XRUNX: ! otool -l "%{lib-dir}/libc++.1.dylib" | grep -E "LC_RPATH|@loader_path|@rpath"
35+
// RUN: otool -L "%{lib-dir}/libc++.1.dylib" | grep '/usr/lib/libc++.1.dylib'
36+
// RUN: otool -l "%{lib-dir}/libc++.1.dylib" | grep -vE "LC_RPATH|@loader_path|@rpath"
3937

4038
// Make sure the compatibility_version of libc++ is 1.0.0.
4139
// Failure to respect this can result in applications not being able to find libc++

libcxx/utils/ci/apple-install-libcxx.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ for arch in ${architectures}; do
129129
-C "${llvm_root}/libcxx/cmake/caches/Apple.cmake" \
130130
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
131131
-DCMAKE_INSTALL_PREFIX="${build_dir}/${arch}-install" \
132-
-DCMAKE_INSTALL_NAME_DIR="/usr/lib" \
133132
-DCMAKE_OSX_ARCHITECTURES="${arch}" \
134133
-DLIBCXXABI_LIBRARY_VERSION="${version}" \
135134
-DLIBCXX_LIBRARY_VERSION="${version}" \

libcxx/utils/ci/run-buildbot

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,6 @@ function check-runtimes() {
154154

155155
echo "+++ Running the libunwind tests"
156156
${NINJA} -vC "${BUILD_DIR}" check-unwind
157-
158-
# TODO: On macOS 13.5, the linker seems to have an issue where it will pick up
159-
# a library if it exists inside a -L search path, even if we don't link
160-
# against that library. This happens with libunwind.dylib if it is built
161-
# at the point when we run the libc++ tests, which causes issues cause we
162-
# are also linking against the system unwinder.
163-
#
164-
# I believe this is a linker regression and I reported it as rdar://115842730.
165-
# It should be possible to move this installation step back to the top once
166-
# that issue has been resolved, but in the meantime it doesn't really hurt to
167-
# have it here.
168-
echo "--- Installing libc++, libc++abi and libunwind to a fake location"
169-
${NINJA} -vC "${BUILD_DIR}" install-cxx install-cxxabi install-unwind
170157
}
171158

172159
# TODO: The goal is to test this against all configurations. We should also move

0 commit comments

Comments
 (0)