1# ===----------------------------------------------------------------------===## 2# 3# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4# See https://llvm.org/LICENSE.txt for license information. 5# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6# 7# ===----------------------------------------------------------------------===## 8 9# This configuration builds the C++23 std module. 10# It is build when the current lit configuration supports modules. 11# 12# TODO MODULES Evaluate whether this file can be removed when CMake supports 13# modules in libc++. 14 15import os 16import site 17import subprocess 18import libcxx.test.params, libcxx.test.config, libcxx.test.dsl 19 20 21def getSubstitution(substitution, config): 22 for orig, replacement in config.substitutions: 23 if orig == substitution: 24 return replacement 25 raise ValueError("Substitution {} is not in the config.".format(substitution)) 26 27 28def appendToSubstitution(substitutions, key, value): 29 return [(k, v + " " + value) if k == key else (k, v) for (k, v) in substitutions] 30 31 32std = getSubstitution("%{cxx_std}", config) 33if std == "cxx26": 34 std = "26" 35elif std == "cxx23": 36 std = "23" 37elif std == "cxx20": 38 std = "20" 39else: 40 std = "" 41 42if ( 43 std 44 and not "libcpp-has-no-std-modules" in config.available_features 45 and not "clang-modules-build" in config.available_features 46): 47 build = os.path.join(config.test_exec_root, "__config_module__") 48 config.substitutions = appendToSubstitution( 49 config.substitutions, 50 "%{compile_flags}", 51 "-fprebuilt-module-path=" 52 + os.path.join(config.test_exec_root, "__config_module__/CMakeFiles/std.dir"), 53 ) 54 55 cmake = getSubstitution("%{cmake}", config) 56 flags = getSubstitution("%{flags}", config) 57 if "c++experimental" in config.available_features: 58 flags = f"{flags} -D_LIBCPP_ENABLE_EXPERIMENTAL" 59 60 subprocess.check_call( 61 [cmake, f"-DCMAKE_CXX_STANDARD={std}", f"-DCMAKE_CXX_FLAGS={flags}", build], 62 env={}, 63 ) 64 subprocess.check_call([cmake, "--build", build, "--", "-v"], env={}) 65 config.substitutions = appendToSubstitution( 66 config.substitutions, 67 "%{link_flags}", 68 os.path.join(build, "libc++std.a"), 69 ) 70