1c5fb05f6SPeter Kasting //===-- MSVCPaths.h - MSVC path-parsing helpers -----------------*- C++ -*-===// 2c5fb05f6SPeter Kasting // 3c5fb05f6SPeter Kasting // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4c5fb05f6SPeter Kasting // See https://llvm.org/LICENSE.txt for license information. 5c5fb05f6SPeter Kasting // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6c5fb05f6SPeter Kasting // 7c5fb05f6SPeter Kasting //===----------------------------------------------------------------------===// 8c5fb05f6SPeter Kasting 9c13a09a4SKazu Hirata #ifndef LLVM_WINDOWSDRIVER_MSVCPATHS_H 10c13a09a4SKazu Hirata #define LLVM_WINDOWSDRIVER_MSVCPATHS_H 11c5fb05f6SPeter Kasting 12f06d487dSserge-sans-paille #include "llvm/ADT/SmallString.h" 13c5fb05f6SPeter Kasting #include "llvm/ADT/StringRef.h" 1462c7f035SArchibald Elliott #include "llvm/TargetParser/Triple.h" 152c5d49cfSFangrui Song #include <optional> 16c5fb05f6SPeter Kasting #include <string> 17c5fb05f6SPeter Kasting 18c5fb05f6SPeter Kasting namespace llvm { 19c5fb05f6SPeter Kasting 20f06d487dSserge-sans-paille namespace vfs { 21f06d487dSserge-sans-paille class FileSystem; 22f06d487dSserge-sans-paille } 23f06d487dSserge-sans-paille 24c5fb05f6SPeter Kasting enum class SubDirectoryType { 25c5fb05f6SPeter Kasting Bin, 26c5fb05f6SPeter Kasting Include, 27c5fb05f6SPeter Kasting Lib, 28c5fb05f6SPeter Kasting }; 29c5fb05f6SPeter Kasting 30c5fb05f6SPeter Kasting enum class ToolsetLayout { 31c5fb05f6SPeter Kasting OlderVS, 32c5fb05f6SPeter Kasting VS2017OrNewer, 33c5fb05f6SPeter Kasting DevDivInternal, 34c5fb05f6SPeter Kasting }; 35c5fb05f6SPeter Kasting 36c5fb05f6SPeter Kasting // Windows SDKs and VC Toolchains group their contents into subdirectories based 37c5fb05f6SPeter Kasting // on the target architecture. This function converts an llvm::Triple::ArchType 38c5fb05f6SPeter Kasting // to the corresponding subdirectory name. 39c5fb05f6SPeter Kasting const char *archToWindowsSDKArch(llvm::Triple::ArchType Arch); 40c5fb05f6SPeter Kasting 41c5fb05f6SPeter Kasting // Similar to the above function, but for Visual Studios before VS2017. 42c5fb05f6SPeter Kasting const char *archToLegacyVCArch(llvm::Triple::ArchType Arch); 43c5fb05f6SPeter Kasting 44c5fb05f6SPeter Kasting // Similar to the above function, but for DevDiv internal builds. 45c5fb05f6SPeter Kasting const char *archToDevDivInternalArch(llvm::Triple::ArchType Arch); 46c5fb05f6SPeter Kasting 47c5fb05f6SPeter Kasting bool appendArchToWindowsSDKLibPath(int SDKMajor, llvm::SmallString<128> LibPath, 48c5fb05f6SPeter Kasting llvm::Triple::ArchType Arch, 49c5fb05f6SPeter Kasting std::string &path); 50c5fb05f6SPeter Kasting 51c5fb05f6SPeter Kasting // Get the path to a specific subdirectory in the current toolchain for 52c5fb05f6SPeter Kasting // a given target architecture. 53c5fb05f6SPeter Kasting // VS2017 changed the VC toolchain layout, so this should be used instead 54c5fb05f6SPeter Kasting // of hardcoding paths. 55c5fb05f6SPeter Kasting std::string getSubDirectoryPath(SubDirectoryType Type, ToolsetLayout VSLayout, 56c5fb05f6SPeter Kasting const std::string &VCToolChainPath, 57c5fb05f6SPeter Kasting llvm::Triple::ArchType TargetArch, 58c5fb05f6SPeter Kasting llvm::StringRef SubdirParent = ""); 59c5fb05f6SPeter Kasting 60c5fb05f6SPeter Kasting // Check if the Include path of a specified version of Visual Studio contains 61c5fb05f6SPeter Kasting // specific header files. If not, they are probably shipped with Universal CRT. 62c5fb05f6SPeter Kasting bool useUniversalCRT(ToolsetLayout VSLayout, const std::string &VCToolChainPath, 63c5fb05f6SPeter Kasting llvm::Triple::ArchType TargetArch, 64c5fb05f6SPeter Kasting llvm::vfs::FileSystem &VFS); 65c5fb05f6SPeter Kasting 66c5fb05f6SPeter Kasting /// Get Windows SDK installation directory. 67c5fb05f6SPeter Kasting bool getWindowsSDKDir(vfs::FileSystem &VFS, 682c5d49cfSFangrui Song std::optional<llvm::StringRef> WinSdkDir, 692c5d49cfSFangrui Song std::optional<llvm::StringRef> WinSdkVersion, 702c5d49cfSFangrui Song std::optional<llvm::StringRef> WinSysRoot, 71c5fb05f6SPeter Kasting std::string &Path, int &Major, 72c5fb05f6SPeter Kasting std::string &WindowsSDKIncludeVersion, 73c5fb05f6SPeter Kasting std::string &WindowsSDKLibVersion); 74c5fb05f6SPeter Kasting 75c5fb05f6SPeter Kasting bool getUniversalCRTSdkDir(vfs::FileSystem &VFS, 762c5d49cfSFangrui Song std::optional<llvm::StringRef> WinSdkDir, 772c5d49cfSFangrui Song std::optional<llvm::StringRef> WinSdkVersion, 782c5d49cfSFangrui Song std::optional<llvm::StringRef> WinSysRoot, 792c5d49cfSFangrui Song std::string &Path, std::string &UCRTVersion); 80c5fb05f6SPeter Kasting 81c5fb05f6SPeter Kasting // Check command line arguments to try and find a toolchain. 82c5fb05f6SPeter Kasting bool findVCToolChainViaCommandLine( 832c5d49cfSFangrui Song vfs::FileSystem &VFS, std::optional<llvm::StringRef> VCToolsDir, 842c5d49cfSFangrui Song std::optional<llvm::StringRef> VCToolsVersion, 852c5d49cfSFangrui Song std::optional<llvm::StringRef> WinSysRoot, std::string &Path, 86c5fb05f6SPeter Kasting ToolsetLayout &VSLayout); 87c5fb05f6SPeter Kasting 88c5fb05f6SPeter Kasting // Check various environment variables to try and find a toolchain. 89c5fb05f6SPeter Kasting bool findVCToolChainViaEnvironment(vfs::FileSystem &VFS, std::string &Path, 90c5fb05f6SPeter Kasting ToolsetLayout &VSLayout); 91c5fb05f6SPeter Kasting 92c5fb05f6SPeter Kasting // Query the Setup Config server for installs, then pick the newest version 93*af5f4682SSaleem Abdulrasool // and find its default VC toolchain. If `VCToolsVersion` is specified, that 94*af5f4682SSaleem Abdulrasool // version is preferred over the latest version. 95*af5f4682SSaleem Abdulrasool // 96c5fb05f6SPeter Kasting // This is the preferred way to discover new Visual Studios, as they're no 97c5fb05f6SPeter Kasting // longer listed in the registry. 98*af5f4682SSaleem Abdulrasool bool 99*af5f4682SSaleem Abdulrasool findVCToolChainViaSetupConfig(vfs::FileSystem &VFS, 100*af5f4682SSaleem Abdulrasool std::optional<llvm::StringRef> VCToolsVersion, 101*af5f4682SSaleem Abdulrasool std::string &Path, ToolsetLayout &VSLayout); 102c5fb05f6SPeter Kasting 103c5fb05f6SPeter Kasting // Look in the registry for Visual Studio installs, and use that to get 104c5fb05f6SPeter Kasting // a toolchain path. VS2017 and newer don't get added to the registry. 105c5fb05f6SPeter Kasting // So if we find something here, we know that it's an older version. 106c5fb05f6SPeter Kasting bool findVCToolChainViaRegistry(std::string &Path, ToolsetLayout &VSLayout); 107c5fb05f6SPeter Kasting 108c5fb05f6SPeter Kasting } // namespace llvm 109c5fb05f6SPeter Kasting 110c5fb05f6SPeter Kasting #endif 111