Skip to content

Commit 54b6392

Browse files
committed
[libc++] Run the Lit test suite against an installed version of the library
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 6808e6c commit 54b6392

13 files changed

+96
-28
lines changed

libcxx/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS
132132
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
133133
set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-gcc.cfg.in")
134134
elseif(MINGW)
135-
set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-mingw.cfg.in")
135+
if (LIBCXX_ENABLE_SHARED)
136+
set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-mingw.cfg.in")
137+
else()
138+
set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static-mingw.cfg.in")
139+
endif()
136140
elseif(WIN32) # clang-cl
137141
if (LIBCXX_ENABLE_SHARED)
138142
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
@@ -1,6 +1,62 @@
11
include(HandleLitArguments)
22
add_subdirectory(tools)
33

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

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

0 commit comments

Comments
 (0)