[Lldb-commits] [lldb] [lldb][ClangExpressionParser] Set BuiltinHeadersInSystemModules depending on SDK version (PR #101778)
Adrian Prantl via lldb-commits
lldb-commits at lists.llvm.org
Mon Aug 5 10:11:22 PDT 2024
================
@@ -561,7 +562,85 @@ static void SetupLangOpts(CompilerInstance &compiler,
lang_opts.NoBuiltin = true;
}
-static void SetupImportStdModuleLangOpts(CompilerInstance &compiler) {
+// NOTE: should be kept in sync with sdkSupportsBuiltinModules in
+// Toolchains/Darwin.cpp
+static bool
+sdkSupportsBuiltinModulesImpl(const llvm::Triple &triple,
+ const std::optional<DarwinSDKInfo> &SDKInfo) {
+ if (!SDKInfo)
+ return false;
+
+ VersionTuple SDKVersion = SDKInfo->getVersion();
+ switch (triple.getOS()) {
+ case Triple::OSType::MacOSX:
+ return SDKVersion >= VersionTuple(15U);
+ case Triple::OSType::IOS:
+ return SDKVersion >= VersionTuple(18U);
+ case Triple::OSType::TvOS:
+ return SDKVersion >= VersionTuple(18U);
+ case Triple::OSType::WatchOS:
+ return SDKVersion >= VersionTuple(11U);
+ case Triple::OSType::XROS:
+ return SDKVersion >= VersionTuple(2U);
+ default:
+ // New SDKs support builtin modules from the start.
+ return true;
+ }
+}
+
+/// Returns true if the SDK for the specified triple supports
+/// builtin modules in system headers. This is used to decide
+/// whether to pass -fbuiltin-headers-in-system-modules to
+/// the compiler instance when compiling the `std` module.
+///
+/// This function assumes one of the directories in \ref include_dirs
+/// is an SDK path that exists on the host. The SDK version is
+/// read from the SDKSettings.json in that directory.
+///
+/// \param[in] triple The target triple.
+/// \param[in] include_dirs The include directories the compiler will use
+/// during header search.
+///
+static bool
+sdkSupportsBuiltinModules(llvm::Triple const &triple,
+ std::vector<std::string> const &include_dirs) {
+ // Find an SDK directory.
+ static constexpr std::string_view s_sdk_suffix = ".sdk";
+ auto it = llvm::find_if(include_dirs, [](std::string const &path) {
+ return path.find(s_sdk_suffix) != std::string::npos;
+ });
----------------
adrian-prantl wrote:
There is also this, which might be shorter. https://llvm.org/doxygen/namespacellvm_1_1sys_1_1path.html#ad7c38f73fbf2f1a4ed9578621c6bfe8b
https://github.com/llvm/llvm-project/pull/101778
More information about the lldb-commits
mailing list