LLVM 22.0.0git
MSVCPaths.h
Go to the documentation of this file.
1//===-- MSVCPaths.h - MSVC path-parsing helpers -----------------*- C++ -*-===//
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#ifndef LLVM_WINDOWSDRIVER_MSVCPATHS_H
10#define LLVM_WINDOWSDRIVER_MSVCPATHS_H
11
13#include "llvm/ADT/StringRef.h"
16#include <optional>
17#include <string>
18
19namespace llvm {
20
21namespace vfs {
22class FileSystem;
23}
24
25enum class SubDirectoryType {
26 Bin,
27 Include,
28 Lib,
29};
30
31enum class ToolsetLayout {
32 OlderVS,
35};
36
37// Windows SDKs and VC Toolchains group their contents into subdirectories based
38// on the target architecture. This function converts an llvm::Triple::ArchType
39// to the corresponding subdirectory name.
41
42// Similar to the above function, but for Visual Studios before VS2017.
44
45// Similar to the above function, but for DevDiv internal builds.
47
51 std::string &path);
52
53// Get the path to a specific subdirectory in the current toolchain for
54// a given target architecture.
55// VS2017 changed the VC toolchain layout, so this should be used instead
56// of hardcoding paths.
58 ToolsetLayout VSLayout,
59 const std::string &VCToolChainPath,
60 llvm::Triple::ArchType TargetArch,
61 llvm::StringRef SubdirParent = "");
62
63// Check if the Include path of a specified version of Visual Studio contains
64// specific header files. If not, they are probably shipped with Universal CRT.
66 const std::string &VCToolChainPath,
67 llvm::Triple::ArchType TargetArch,
69
70/// Get Windows SDK installation directory.
71LLVM_ABI bool getWindowsSDKDir(vfs::FileSystem &VFS,
72 std::optional<llvm::StringRef> WinSdkDir,
73 std::optional<llvm::StringRef> WinSdkVersion,
74 std::optional<llvm::StringRef> WinSysRoot,
75 std::string &Path, int &Major,
76 std::string &WindowsSDKIncludeVersion,
77 std::string &WindowsSDKLibVersion);
78
79LLVM_ABI bool
80getUniversalCRTSdkDir(vfs::FileSystem &VFS,
81 std::optional<llvm::StringRef> WinSdkDir,
82 std::optional<llvm::StringRef> WinSdkVersion,
83 std::optional<llvm::StringRef> WinSysRoot,
84 std::string &Path, std::string &UCRTVersion);
85
86// Check command line arguments to try and find a toolchain.
87LLVM_ABI bool
88findVCToolChainViaCommandLine(vfs::FileSystem &VFS,
89 std::optional<llvm::StringRef> VCToolsDir,
90 std::optional<llvm::StringRef> VCToolsVersion,
91 std::optional<llvm::StringRef> WinSysRoot,
92 std::string &Path, ToolsetLayout &VSLayout);
93
94// Check various environment variables to try and find a toolchain.
95LLVM_ABI bool findVCToolChainViaEnvironment(vfs::FileSystem &VFS,
96 std::string &Path,
97 ToolsetLayout &VSLayout);
98
99// Query the Setup Config server for installs, then pick the newest version
100// and find its default VC toolchain. If `VCToolsVersion` is specified, that
101// version is preferred over the latest version.
102//
103// This is the preferred way to discover new Visual Studios, as they're no
104// longer listed in the registry.
105LLVM_ABI bool
106findVCToolChainViaSetupConfig(vfs::FileSystem &VFS,
107 std::optional<llvm::StringRef> VCToolsVersion,
108 std::string &Path, ToolsetLayout &VSLayout);
109
110// Look in the registry for Visual Studio installs, and use that to get
111// a toolchain path. VS2017 and newer don't get added to the registry.
112// So if we find something here, we know that it's an older version.
113LLVM_ABI bool findVCToolChainViaRegistry(std::string &Path,
114 ToolsetLayout &VSLayout);
115
116} // namespace llvm
117
118#endif
RelocType Type
Definition: COFFYAML.cpp:410
#define LLVM_ABI
Definition: Compiler.h:213
This file defines the SmallString class.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
The virtual file system interface.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI const char * archToWindowsSDKArch(llvm::Triple::ArchType Arch)
Definition: MSVCPaths.cpp:264
LLVM_ABI bool getWindowsSDKDir(vfs::FileSystem &VFS, std::optional< llvm::StringRef > WinSdkDir, std::optional< llvm::StringRef > WinSdkVersion, std::optional< llvm::StringRef > WinSysRoot, std::string &Path, int &Major, std::string &WindowsSDKIncludeVersion, std::string &WindowsSDKLibVersion)
Get Windows SDK installation directory.
Definition: MSVCPaths.cpp:401
SubDirectoryType
Definition: MSVCPaths.h:25
LLVM_ABI bool useUniversalCRT(ToolsetLayout VSLayout, const std::string &VCToolChainPath, llvm::Triple::ArchType TargetArch, llvm::vfs::FileSystem &VFS)
Definition: MSVCPaths.cpp:393
LLVM_ABI bool findVCToolChainViaCommandLine(vfs::FileSystem &VFS, std::optional< llvm::StringRef > VCToolsDir, std::optional< llvm::StringRef > VCToolsVersion, std::optional< llvm::StringRef > WinSysRoot, std::string &Path, ToolsetLayout &VSLayout)
Definition: MSVCPaths.cpp:494
LLVM_ABI bool getUniversalCRTSdkDir(vfs::FileSystem &VFS, std::optional< llvm::StringRef > WinSdkDir, std::optional< llvm::StringRef > WinSdkVersion, std::optional< llvm::StringRef > WinSysRoot, std::string &Path, std::string &UCRTVersion)
Definition: MSVCPaths.cpp:463
LLVM_ABI bool findVCToolChainViaEnvironment(vfs::FileSystem &VFS, std::string &Path, ToolsetLayout &VSLayout)
Definition: MSVCPaths.cpp:521
LLVM_ABI const char * archToLegacyVCArch(llvm::Triple::ArchType Arch)
Definition: MSVCPaths.cpp:280
ToolsetLayout
Definition: MSVCPaths.h:31
LLVM_ABI const char * archToDevDivInternalArch(llvm::Triple::ArchType Arch)
Definition: MSVCPaths.cpp:298
LLVM_ABI std::string getSubDirectoryPath(SubDirectoryType Type, ToolsetLayout VSLayout, const std::string &VCToolChainPath, llvm::Triple::ArchType TargetArch, llvm::StringRef SubdirParent="")
Definition: MSVCPaths.cpp:339
LLVM_ABI bool findVCToolChainViaSetupConfig(vfs::FileSystem &VFS, std::optional< llvm::StringRef > VCToolsVersion, std::string &Path, ToolsetLayout &VSLayout)
Definition: MSVCPaths.cpp:630
LLVM_ABI bool appendArchToWindowsSDKLibPath(int SDKMajor, llvm::SmallString< 128 > LibPath, llvm::Triple::ArchType Arch, std::string &path)
Definition: MSVCPaths.cpp:314
LLVM_ABI bool findVCToolChainViaRegistry(std::string &Path, ToolsetLayout &VSLayout)
Definition: MSVCPaths.cpp:727