xref: /freebsd/contrib/llvm-project/llvm/include/llvm/WindowsDriver/MSVCPaths.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
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 
12 #include "llvm/ADT/SmallString.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/Compiler.h"
15 #include "llvm/TargetParser/Triple.h"
16 #include <optional>
17 #include <string>
18 
19 namespace llvm {
20 
21 namespace vfs {
22 class FileSystem;
23 }
24 
25 enum class SubDirectoryType {
26   Bin,
27   Include,
28   Lib,
29 };
30 
31 enum class ToolsetLayout {
32   OlderVS,
33   VS2017OrNewer,
34   DevDivInternal,
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.
40 LLVM_ABI const char *archToWindowsSDKArch(llvm::Triple::ArchType Arch);
41 
42 // Similar to the above function, but for Visual Studios before VS2017.
43 LLVM_ABI const char *archToLegacyVCArch(llvm::Triple::ArchType Arch);
44 
45 // Similar to the above function, but for DevDiv internal builds.
46 LLVM_ABI const char *archToDevDivInternalArch(llvm::Triple::ArchType Arch);
47 
48 LLVM_ABI bool appendArchToWindowsSDKLibPath(int SDKMajor,
49                                             llvm::SmallString<128> LibPath,
50                                             llvm::Triple::ArchType Arch,
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.
57 LLVM_ABI std::string getSubDirectoryPath(SubDirectoryType Type,
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.
65 LLVM_ABI bool useUniversalCRT(ToolsetLayout VSLayout,
66                               const std::string &VCToolChainPath,
67                               llvm::Triple::ArchType TargetArch,
68                               llvm::vfs::FileSystem &VFS);
69 
70 /// Get Windows SDK installation directory.
71 LLVM_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 
79 LLVM_ABI bool
80 getUniversalCRTSdkDir(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.
87 LLVM_ABI bool
88 findVCToolChainViaCommandLine(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.
95 LLVM_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.
105 LLVM_ABI bool
106 findVCToolChainViaSetupConfig(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.
113 LLVM_ABI bool findVCToolChainViaRegistry(std::string &Path,
114                                          ToolsetLayout &VSLayout);
115 
116 } // namespace llvm
117 
118 #endif
119