Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:45

0001 //===-- MSVCPaths.h - MSVC path-parsing helpers -----------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_WINDOWSDRIVER_MSVCPATHS_H
0010 #define LLVM_WINDOWSDRIVER_MSVCPATHS_H
0011 
0012 #include "llvm/ADT/SmallString.h"
0013 #include "llvm/ADT/StringRef.h"
0014 #include "llvm/TargetParser/Triple.h"
0015 #include <optional>
0016 #include <string>
0017 
0018 namespace llvm {
0019 
0020 namespace vfs {
0021 class FileSystem;
0022 }
0023 
0024 enum class SubDirectoryType {
0025   Bin,
0026   Include,
0027   Lib,
0028 };
0029 
0030 enum class ToolsetLayout {
0031   OlderVS,
0032   VS2017OrNewer,
0033   DevDivInternal,
0034 };
0035 
0036 // Windows SDKs and VC Toolchains group their contents into subdirectories based
0037 // on the target architecture. This function converts an llvm::Triple::ArchType
0038 // to the corresponding subdirectory name.
0039 const char *archToWindowsSDKArch(llvm::Triple::ArchType Arch);
0040 
0041 // Similar to the above function, but for Visual Studios before VS2017.
0042 const char *archToLegacyVCArch(llvm::Triple::ArchType Arch);
0043 
0044 // Similar to the above function, but for DevDiv internal builds.
0045 const char *archToDevDivInternalArch(llvm::Triple::ArchType Arch);
0046 
0047 bool appendArchToWindowsSDKLibPath(int SDKMajor, llvm::SmallString<128> LibPath,
0048                                    llvm::Triple::ArchType Arch,
0049                                    std::string &path);
0050 
0051 // Get the path to a specific subdirectory in the current toolchain for
0052 // a given target architecture.
0053 // VS2017 changed the VC toolchain layout, so this should be used instead
0054 // of hardcoding paths.
0055 std::string getSubDirectoryPath(SubDirectoryType Type, ToolsetLayout VSLayout,
0056                                 const std::string &VCToolChainPath,
0057                                 llvm::Triple::ArchType TargetArch,
0058                                 llvm::StringRef SubdirParent = "");
0059 
0060 // Check if the Include path of a specified version of Visual Studio contains
0061 // specific header files. If not, they are probably shipped with Universal CRT.
0062 bool useUniversalCRT(ToolsetLayout VSLayout, const std::string &VCToolChainPath,
0063                      llvm::Triple::ArchType TargetArch,
0064                      llvm::vfs::FileSystem &VFS);
0065 
0066 /// Get Windows SDK installation directory.
0067 bool getWindowsSDKDir(vfs::FileSystem &VFS,
0068                       std::optional<llvm::StringRef> WinSdkDir,
0069                       std::optional<llvm::StringRef> WinSdkVersion,
0070                       std::optional<llvm::StringRef> WinSysRoot,
0071                       std::string &Path, int &Major,
0072                       std::string &WindowsSDKIncludeVersion,
0073                       std::string &WindowsSDKLibVersion);
0074 
0075 bool getUniversalCRTSdkDir(vfs::FileSystem &VFS,
0076                            std::optional<llvm::StringRef> WinSdkDir,
0077                            std::optional<llvm::StringRef> WinSdkVersion,
0078                            std::optional<llvm::StringRef> WinSysRoot,
0079                            std::string &Path, std::string &UCRTVersion);
0080 
0081 // Check command line arguments to try and find a toolchain.
0082 bool findVCToolChainViaCommandLine(
0083     vfs::FileSystem &VFS, std::optional<llvm::StringRef> VCToolsDir,
0084     std::optional<llvm::StringRef> VCToolsVersion,
0085     std::optional<llvm::StringRef> WinSysRoot, std::string &Path,
0086     ToolsetLayout &VSLayout);
0087 
0088 // Check various environment variables to try and find a toolchain.
0089 bool findVCToolChainViaEnvironment(vfs::FileSystem &VFS, std::string &Path,
0090                                    ToolsetLayout &VSLayout);
0091 
0092 // Query the Setup Config server for installs, then pick the newest version
0093 // and find its default VC toolchain. If `VCToolsVersion` is specified, that
0094 // version is preferred over the latest version.
0095 //
0096 // This is the preferred way to discover new Visual Studios, as they're no
0097 // longer listed in the registry.
0098 bool
0099 findVCToolChainViaSetupConfig(vfs::FileSystem &VFS,
0100                               std::optional<llvm::StringRef> VCToolsVersion,
0101                               std::string &Path, ToolsetLayout &VSLayout);
0102 
0103 // Look in the registry for Visual Studio installs, and use that to get
0104 // a toolchain path. VS2017 and newer don't get added to the registry.
0105 // So if we find something here, we know that it's an older version.
0106 bool findVCToolChainViaRegistry(std::string &Path, ToolsetLayout &VSLayout);
0107 
0108 } // namespace llvm
0109 
0110 #endif