| # ===----------------------------------------------------------------------===## |
| # |
| # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| # See https://llvm.org/LICENSE.txt for license information. |
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| # |
| # ===----------------------------------------------------------------------===## |
| |
| # This configuration builds the C++23 std module. |
| # It is build when the current lit configuration supports modules. |
| # |
| # TODO MODULES Evaluate whether this file can be removed when CMake supports |
| # modules in libc++. |
| |
| import os |
| import site |
| import subprocess |
| import libcxx.test.params, libcxx.test.config, libcxx.test.dsl |
| |
| |
| def getSubstitution(substitution, config): |
| for orig, replacement in config.substitutions: |
| if orig == substitution: |
| return replacement |
| raise ValueError("Substitution {} is not in the config.".format(substitution)) |
| |
| |
| def appendToSubstitution(substitutions, key, value): |
| return [(k, v + " " + value) if k == key else (k, v) for (k, v) in substitutions] |
| |
| |
| std = getSubstitution("%{cxx_std}", config) |
| if std == "cxx26": |
| std = "26" |
| elif std == "cxx23": |
| std = "23" |
| else: |
| std = "" |
| |
| if ( |
| std |
| and not "libcpp-has-no-std-modules" in config.available_features |
| and not "modules-build" in config.available_features |
| ): |
| build = os.path.join(config.test_exec_root, "__config_module__") |
| config.substitutions = appendToSubstitution( |
| config.substitutions, |
| "%{compile_flags}", |
| "-fprebuilt-module-path=" |
| + os.path.join(config.test_exec_root, "__config_module__/CMakeFiles/std.dir"), |
| ) |
| |
| flags = getSubstitution("%{flags}", config) |
| cmake = getSubstitution("%{cmake}", config) |
| |
| subprocess.check_call( |
| [cmake, f"-DCMAKE_CXX_STANDARD={std}", f"-DCMAKE_CXX_FLAGS={flags}", build], |
| env={}, |
| ) |
| subprocess.check_call([cmake, "--build", build, "--", "-v"], env={}) |
| config.substitutions = appendToSubstitution( |
| config.substitutions, |
| "%{link_flags}", |
| os.path.join(build, "libc++std.a"), |
| ) |