From 95a6892aacfef6c7862058fcdc495f6b35df9367 Mon Sep 17 00:00:00 2001 From: Matthew Carlson Date: Wed, 19 Jun 2024 21:31:38 -0700 Subject: BaseTools: Add VS2022 support. Adding tools_def for VS2022. Update WindowsVsToolChain to support VS2022. Update set_vsPrefix_envs and toolsetup and edksetup to support VS2022. Signed-off-by: Aaron Pop --- BaseTools/Conf/tools_def.template | 165 ++++++++++++++++++++- .../WindowsVsToolChain/WindowsVsToolChain.py | 158 +++++++++++++++++++- BaseTools/set_vsprefix_envs.bat | 62 ++++++++ BaseTools/toolsetup.bat | 12 +- 4 files changed, 390 insertions(+), 7 deletions(-) (limited to 'BaseTools') diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template index c34ecfd557..0dea1899fb 100755 --- a/BaseTools/Conf/tools_def.template +++ b/BaseTools/Conf/tools_def.template @@ -20,8 +20,9 @@ # - Remove VS2008, VS2010, VS2012, VS2013, CLANG35, CLANG38, EBC # - Add GCC and GCCNOLTO # - Deprecate GCC48, GCC49 and GCC5. +# 3.01 - Add toolchain for VS2022 # -#!VERSION=3.00 +#!VERSION=3.01 IDENTIFIER = Default TOOL_CHAIN_CONF @@ -50,6 +51,13 @@ DEFINE VS2019_BIN_X64 = DEF(VS2019_BIN)\HostDEF(VS_HOST)\x64 DEFINE VS2019_BIN_ARM = DEF(VS2019_BIN)\HostDEF(VS_HOST)\arm DEFINE VS2019_BIN_AARCH64 = DEF(VS2019_BIN)\HostDEF(VS_HOST)\arm64 +DEFINE VS2022_BIN = ENV(VS2022_PREFIX)bin +DEFINE VS2022_BIN_HOST = DEF(VS2022_BIN)\HostDEF(VS_HOST)\DEF(VS_HOST) +DEFINE VS2022_BIN_IA32 = DEF(VS2022_BIN)\HostDEF(VS_HOST)\x86 +DEFINE VS2022_BIN_X64 = DEF(VS2022_BIN)\HostDEF(VS_HOST)\x64 +DEFINE VS2022_BIN_ARM = DEF(VS2022_BIN)\HostDEF(VS_HOST)\arm +DEFINE VS2022_BIN_AARCH64 = DEF(VS2022_BIN)\HostDEF(VS_HOST)\arm64 + # # Resource compiler # @@ -62,7 +70,7 @@ DEFINE WINSDKx86_BIN = ENV(WINSDKx86_PREFIX) DEFINE WINSDK81_BIN = ENV(WINSDK81_PREFIX)x86\ DEFINE WINSDK81x86_BIN = ENV(WINSDK81x86_PREFIX)x64 -# Microsoft Visual Studio 2017/2019 Professional Edition +# Microsoft Visual Studio 2017/2019/2022 Professional Edition DEFINE WINSDK10_BIN = ENV(WINSDK10_PREFIX)DEF(VS_HOST) # These defines are needed for certain Microsoft Visual Studio tools that @@ -158,9 +166,11 @@ DEFINE DTC_BIN = ENV(DTC_PREFIX)dtc # Required to build platforms or ACPI tables: # Intel(r) ACPI Compiler (iasl.exe) from # https://acpica.org/downloads -# Note: -# Building of XIP firmware images for ARM/ARM64 is not currently supported (only applications). -# /FILEALIGN:4096 and other changes are needed for ARM firmware builds. +# VS2022 -win32,win64- Requires: +# Microsoft Visual Studio 2022 version 17.0 or later +# Optional: +# Required to build EBC drivers: +# Intel(r) Compiler for Efi Byte Code (Intel(r) EBC Compiler) # GCCNOLTO -Linux,Windows- Requires: # GCC 4.9 targeting x86_64-linux-gnu, aarch64-linux-gnu, or arm-linux-gnueabi # Optional: @@ -723,6 +733,151 @@ NOOPT_VS2019_AARCH64_ASM_FLAGS = /nologo RELEASE_VS2019_AARCH64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /DRIVER /MERGE:.rdata=.data NOOPT_VS2019_AARCH64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /DRIVER /DEBUG +#################################################################################### +# VS2022 - Microsoft Visual Studio 2022 with Intel ASL +# ASL - Intel ACPI Source Language Compiler (iasl.exe) +#################################################################################### +# VS2022 - Microsoft Visual Studio 2022 with Intel ASL +*_VS2022_*_*_FAMILY = MSFT +*_VS2022_*_*_DLL = DEF(VS2022_BIN_HOST) + +*_VS2022_*_MAKE_PATH = DEF(VS2022_BIN_HOST)\nmake.exe +*_VS2022_*_MAKE_FLAG = /nologo +*_VS2022_*_RC_PATH = DEF(RC_PATH) + +*_VS2022_*_MAKE_FLAGS = /nologo +*_VS2022_*_SLINK_FLAGS = /NOLOGO /LTCG +*_VS2022_*_APP_FLAGS = /nologo /E /TC +*_VS2022_*_PP_FLAGS = /nologo /E /TC /FIAutoGen.h +*_VS2022_*_VFRPP_FLAGS = /nologo /E /TC /DVFRCOMPILE /FI$(MODULE_NAME)StrDefs.h +# *_VS2022_*_DLINK2_FLAGS = /WHOLEARCHIVE # MU_CHANGE +*_VS2022_*_ASM16_PATH = DEF(VS2022_BIN_IA32)\ml.exe +*_VS2022_*_DEPS_FLAGS = DEF(MSFT_DEPS_FLAGS) +################## +# ASL definitions +################## +*_VS2022_*_ASL_PATH = DEF(WIN_IASL_BIN) +*_VS2022_*_ASL_FLAGS = DEF(DEFAULT_WIN_ASL_FLAGS) +*_VS2022_*_ASL_OUTFLAGS = DEF(DEFAULT_WIN_ASL_OUTFLAGS) +*_VS2022_*_ASLCC_FLAGS = DEF(MSFT_ASLCC_FLAGS) +*_VS2022_*_ASLPP_FLAGS = DEF(MSFT_ASLPP_FLAGS) +*_VS2022_*_ASLDLINK_FLAGS = DEF(MSFT_ASLDLINK_FLAGS) + +################## +# IA32 definitions +################## +*_VS2022_IA32_CC_PATH = DEF(VS2022_BIN_IA32)\cl.exe +*_VS2022_IA32_VFRPP_PATH = DEF(VS2022_BIN_IA32)\cl.exe +*_VS2022_IA32_ASLCC_PATH = DEF(VS2022_BIN_IA32)\cl.exe +*_VS2022_IA32_ASLPP_PATH = DEF(VS2022_BIN_IA32)\cl.exe +*_VS2022_IA32_SLINK_PATH = DEF(VS2022_BIN_IA32)\lib.exe +*_VS2022_IA32_DLINK_PATH = DEF(VS2022_BIN_IA32)\link.exe +*_VS2022_IA32_ASLDLINK_PATH= DEF(VS2022_BIN_IA32)\link.exe +*_VS2022_IA32_APP_PATH = DEF(VS2022_BIN_IA32)\cl.exe +*_VS2022_IA32_PP_PATH = DEF(VS2022_BIN_IA32)\cl.exe +*_VS2022_IA32_ASM_PATH = DEF(VS2022_BIN_IA32)\ml.exe + + *_VS2022_IA32_MAKE_FLAGS = /nologo + DEBUG_VS2022_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Z7 /Gw +RELEASE_VS2022_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gw +NOOPT_VS2022_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Z7 /Od + + DEBUG_VS2022_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd /Zi +RELEASE_VS2022_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd +NOOPT_VS2022_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd /Zi + + DEBUG_VS2022_IA32_NASM_FLAGS = -Ox -f win32 -g +RELEASE_VS2022_IA32_NASM_FLAGS = -Ox -f win32 +NOOPT_VS2022_IA32_NASM_FLAGS = -O0 -f win32 -g + + DEBUG_VS2022_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG +RELEASE_VS2022_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /MERGE:.rdata=.data +NOOPT_VS2022_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG + +################## +# X64 definitions +################## +*_VS2022_X64_CC_PATH = DEF(VS2022_BIN_X64)\cl.exe +*_VS2022_X64_PP_PATH = DEF(VS2022_BIN_X64)\cl.exe +*_VS2022_X64_APP_PATH = DEF(VS2022_BIN_X64)\cl.exe +*_VS2022_X64_VFRPP_PATH = DEF(VS2022_BIN_X64)\cl.exe +*_VS2022_X64_ASLCC_PATH = DEF(VS2022_BIN_X64)\cl.exe +*_VS2022_X64_ASLPP_PATH = DEF(VS2022_BIN_X64)\cl.exe +*_VS2022_X64_ASM_PATH = DEF(VS2022_BIN_X64)\ml64.exe +*_VS2022_X64_SLINK_PATH = DEF(VS2022_BIN_X64)\lib.exe +*_VS2022_X64_DLINK_PATH = DEF(VS2022_BIN_X64)\link.exe +*_VS2022_X64_ASLDLINK_PATH = DEF(VS2022_BIN_X64)\link.exe + + DEBUG_VS2022_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Z7 /Gw +RELEASE_VS2022_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Gw +NOOPT_VS2022_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Z7 /Od + + DEBUG_VS2022_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd /Zi +RELEASE_VS2022_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd +NOOPT_VS2022_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd /Zi + + DEBUG_VS2022_X64_NASM_FLAGS = -Ox -f win64 -g +RELEASE_VS2022_X64_NASM_FLAGS = -Ox -f win64 +NOOPT_VS2022_X64_NASM_FLAGS = -O0 -f win64 -g + + DEBUG_VS2022_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4281 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG /ALIGN:4096 /DLL +RELEASE_VS2022_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4281 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /MERGE:.rdata=.data /ALIGN:4096 /DLL +NOOPT_VS2022_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4281 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG /ALIGN:4096 /DLL + +################# +# ARM definitions +################# +*_VS2022_ARM_CC_PATH = DEF(VS2022_BIN_ARM)\cl.exe +*_VS2022_ARM_VFRPP_PATH = DEF(VS2022_BIN_ARM)\cl.exe +*_VS2022_ARM_SLINK_PATH = DEF(VS2022_BIN_ARM)\lib.exe +*_VS2022_ARM_DLINK_PATH = DEF(VS2022_BIN_ARM)\link.exe +*_VS2022_ARM_APP_PATH = DEF(VS2022_BIN_ARM)\cl.exe +*_VS2022_ARM_PP_PATH = DEF(VS2022_BIN_ARM)\cl.exe +*_VS2022_ARM_ASM_PATH = DEF(VS2022_BIN_ARM)\armasm.exe +*_VS2022_ARM_ASLCC_PATH = DEF(VS2022_BIN_ARM)\cl.exe +*_VS2022_ARM_ASLPP_PATH = DEF(VS2022_BIN_ARM)\cl.exe +*_VS2022_ARM_ASLDLINK_PATH = DEF(VS2022_BIN_ARM)\link.exe + + *_VS2022_ARM_MAKE_FLAGS = /nologo + DEBUG_VS2022_ARM_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Zi /Gw /Oi- +RELEASE_VS2022_ARM_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gw /Oi- +NOOPT_VS2022_ARM_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Zi /Od /Oi- + + DEBUG_VS2022_ARM_ASM_FLAGS = /nologo /g +RELEASE_VS2022_ARM_ASM_FLAGS = /nologo +NOOPT_VS2022_ARM_ASM_FLAGS = /nologo + + DEBUG_VS2022_ARM_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG +RELEASE_VS2022_ARM_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /MERGE:.rdata=.data +NOOPT_VS2022_ARM_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG + +##################### +# AARCH64 definitions +##################### +*_VS2022_AARCH64_CC_PATH = DEF(VS2022_BIN_AARCH64)\cl.exe +*_VS2022_AARCH64_VFRPP_PATH = DEF(VS2022_BIN_AARCH64)\cl.exe +*_VS2022_AARCH64_SLINK_PATH = DEF(VS2022_BIN_AARCH64)\lib.exe +*_VS2022_AARCH64_DLINK_PATH = DEF(VS2022_BIN_AARCH64)\link.exe +*_VS2022_AARCH64_APP_PATH = DEF(VS2022_BIN_AARCH64)\cl.exe +*_VS2022_AARCH64_PP_PATH = DEF(VS2022_BIN_AARCH64)\cl.exe +*_VS2022_AARCH64_ASM_PATH = DEF(VS2022_BIN_AARCH64)\armasm64.exe +*_VS2022_AARCH64_ASLCC_PATH = DEF(VS2022_BIN_AARCH64)\cl.exe +*_VS2022_AARCH64_ASLPP_PATH = DEF(VS2022_BIN_AARCH64)\cl.exe +*_VS2022_AARCH64_ASLDLINK_PATH = DEF(VS2022_BIN_AARCH64)\link.exe + + *_VS2022_AARCH64_MAKE_FLAGS = /nologo + DEBUG_VS2022_AARCH64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Zi /Gw /Oi- +RELEASE_VS2022_AARCH64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gw /Oi- +NOOPT_VS2022_AARCH64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Zi /Od /Oi- + + DEBUG_VS2022_AARCH64_ASM_FLAGS = /nologo /g +RELEASE_VS2022_AARCH64_ASM_FLAGS = /nologo +NOOPT_VS2022_AARCH64_ASM_FLAGS = /nologo + + DEBUG_VS2022_AARCH64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /DRIVER /DEBUG +RELEASE_VS2022_AARCH64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /DRIVER /MERGE:.rdata=.data +NOOPT_VS2022_AARCH64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /DRIVER /DEBUG + #################################################################################### # GCC Common #################################################################################### diff --git a/BaseTools/Plugin/WindowsVsToolChain/WindowsVsToolChain.py b/BaseTools/Plugin/WindowsVsToolChain/WindowsVsToolChain.py index 615b5ed6d1..04e59f10f1 100644 --- a/BaseTools/Plugin/WindowsVsToolChain/WindowsVsToolChain.py +++ b/BaseTools/Plugin/WindowsVsToolChain/WindowsVsToolChain.py @@ -1,5 +1,8 @@ # @file WindowsVsToolChain.py -# Plugin to configures paths for the VS2017 and VS2019 tool chain +# Plugin to configure the environment for the VS2017, VS2019, and VS2022 toolchains +# +# This plugin also runs for CLANGPDB toolchain on Windows as that toolchain +# leverages nmake from VS and needs to the SDK paths for unit tests ## # This plugin works in conjuncture with the tools_def # @@ -173,6 +176,159 @@ class WindowsVsToolChain(IUefiBuildPlugin): self.Logger.error("Path for VS2019 toolchain is invalid") return -2 + # + # VS2022 - VS2022 allows a user to install many copies/versions of the tools. + # If a specific version is required then the user must set both env variables: + # VS170INSTALLPATH: base install path on system to VC install dir. Here you will find the VC folder, etc + # VS170TOOLVER: version number for the VC compiler tools + # VS2022_PREFIX: path to MSVC compiler folder with trailing slash (can be used instead of two vars above) + # VS2022_HOST: set the host architecture to use for host tools, and host libs, etc + elif thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "VS2022": + + # check to see if host is configured + # HostType for VS2022 should be (defined in tools_def): + # x86 == 32bit Intel + # x64 == 64bit Intel + # arm == 32bit Arm + # arm64 == 64bit Arm + # + HostType = shell_environment.GetEnvironment().get_shell_var("VS2022_HOST") + if HostType is not None: + HostType = HostType.lower() + self.Logger.info( + f"HOST TYPE defined by environment. Host Type is {HostType}") + else: + HostInfo = GetHostInfo() + if HostInfo.arch == "x86": + if HostInfo.bit == "32": + HostType = "x86" + elif HostInfo.bit == "64": + HostType = "x64" + else: + raise NotImplementedError() + + # VS2022_HOST options are not exactly the same as QueryVcVariables. This translates. + VC_HOST_ARCH_TRANSLATOR = { + "x86": "x86", "x64": "AMD64", "arm": "not supported", "arm64": "not supported"} + + # check to see if full path already configured + if shell_environment.GetEnvironment().get_shell_var("VS2022_PREFIX") is not None: + self.Logger.debug("VS2022_PREFIX is already set.") + + else: + install_path = self._get_vs_install_path( + "VS2022".lower(), "VS170INSTALLPATH") + vc_ver = self._get_vc_version(install_path, "VS170TOOLVER") + + if install_path is None or vc_ver is None: + self.Logger.error( + "Failed to configure environment for VS2022") + return -1 + + version_aggregator.GetVersionAggregator().ReportVersion( + "Visual Studio Install Path", install_path, version_aggregator.VersionTypes.INFO) + version_aggregator.GetVersionAggregator().ReportVersion( + "VC Version", vc_ver, version_aggregator.VersionTypes.TOOL) + + # make VS2022_PREFIX to align with tools_def.txt + prefix = os.path.join(install_path, "VC", + "Tools", "MSVC", vc_ver) + prefix = prefix + os.path.sep + shell_environment.GetEnvironment().set_shell_var("VS2022_PREFIX", prefix) + shell_environment.GetEnvironment().set_shell_var("VS2022_HOST", HostType) + + shell_env = shell_environment.GetEnvironment() + # Use the tools lib to determine the correct values for the vars that interest us. + vs_vars = locate_tools.QueryVcVariables( + interesting_keys, VC_HOST_ARCH_TRANSLATOR[HostType], vs_version="VS2022") + for (k, v) in vs_vars.items(): + shell_env.set_shell_var(k, v) + + # now confirm it exists + if not os.path.exists(shell_environment.GetEnvironment().get_shell_var("VS2022_PREFIX")): + self.Logger.error("Path for VS2022 toolchain is invalid") + return -2 + + # + # CLANGPDB on Windows uses nmake from + # the VS compiler toolchain. Find a version and set + # as the CLANG_HOST_BIN path if not already set. + # + # Also get the platform header files, SDK, etc based on the + # host type. This is used for unit test compilation. + # If CLANG_VS_HOST is not set then find the host type based on Host Info. + ## + elif thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "CLANGPDB": + HostInfo = GetHostInfo() + + # check to see if host is configured + # HostType for VS tools should be (defined in tools_def): + # x86 == 32bit Intel + # x64 == 64bit Intel + # arm == 32bit Arm + # arm64 == 64bit Arm + # + HostType = shell_environment.GetEnvironment().get_shell_var("CLANG_VS_HOST") + if HostType is not None: + HostType = HostType.lower() + self.Logger.info( + f"CLANG_VS_HOST defined by environment. Value is {HostType}") + else: + #figure it out based on host info + if HostInfo.arch == "x86": + if HostInfo.bit == "32": + HostType = "x86" + elif HostInfo.bit == "64": + HostType = "x64" + else: + # anything other than x86 or x64 is not supported + raise NotImplementedError() + + # CLANG_VS_HOST options are not exactly the same as QueryVcVariables. This translates. + VC_HOST_ARCH_TRANSLATOR = { + "x86": "x86", "x64": "AMD64", "arm": "not supported", "arm64": "not supported"} + + # now get the environment variables for the platform + shell_env = shell_environment.GetEnvironment() + # Use the tools lib to determine the correct values for the vars that interest us. + vs_vars = locate_tools.QueryVcVariables( + interesting_keys, VC_HOST_ARCH_TRANSLATOR[HostType]) + for (k, v) in vs_vars.items(): + shell_env.set_shell_var(k, v) + + ## + # If environment already has CLANG_HOST_BIN set then user has already + # set the path to the VS tools like nmake.exe + ## + if shell_environment.GetEnvironment().get_shell_var("CLANG_HOST_BIN") is not None: + self.Logger.debug("CLANG_HOST_BIN is already set.") + + else: + install_path = self._get_vs_install_path(None, None) + vc_ver = self._get_vc_version(install_path, None) + + if install_path is None or vc_ver is None: + self.Logger.error("Failed to configure environment for VS") + return -1 + + version_aggregator.GetVersionAggregator().ReportVersion( + "Visual Studio Install Path", install_path, version_aggregator.VersionTypes.INFO) + version_aggregator.GetVersionAggregator().ReportVersion( + "VC Version", vc_ver, version_aggregator.VersionTypes.TOOL) + + # make path align with tools_def.txt + prefix = os.path.join(install_path, "VC", "Tools", "MSVC", vc_ver) + clang_host_bin_prefix = os.path.join(prefix, "bin", "Host%s" % HostType, HostType) + + # now confirm it exists + if not os.path.exists(clang_host_bin_prefix): + self.Logger.error("Path for VS toolchain is invalid") + return -2 + + # The environment is using nmake (not make) so add "n" to the end of the path. + # The rest of the command is derived from definitions in tools.def. + shell_environment.GetEnvironment().set_shell_var("CLANG_HOST_BIN", os.path.join(clang_host_bin_prefix, "n")) + return 0 def _get_vs_install_path(self, vs_version, varname): diff --git a/BaseTools/set_vsprefix_envs.bat b/BaseTools/set_vsprefix_envs.bat index 0b9a0c75b9..39e4e004b5 100644 --- a/BaseTools/set_vsprefix_envs.bat +++ b/BaseTools/set_vsprefix_envs.bat @@ -18,6 +18,7 @@ set SCRIPT_ERROR=1 goto :EOF :main +if /I "%1"=="VS2022" goto SetVS2022 if /I "%1"=="VS2019" goto SetVS2019 if /I "%1"=="VS2017" goto SetVS2017 if /I "%1"=="VS2015" goto SetVS2015 @@ -166,6 +167,67 @@ if not defined WINSDK_PATH_FOR_RC_EXE ( if /I "%1"=="VS2019" goto SetWinDDK +:SetVS2022 +if not defined VS170COMNTOOLS ( + @REM clear two envs so that vcvars32.bat can run successfully. + set VSINSTALLDIR= + set VCToolsVersion= + if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ( + if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools" ( + call "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools -version 17,18 > vswhereInfo + for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do ( + if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat" + ) + del vswhereInfo + ) else ( + call "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -version 17,18 > vswhereInfo + for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do ( + if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat" + ) + del vswhereInfo + ) + ) else if exist "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" ( + if exist "%ProgramFiles%\Microsoft Visual Studio\2022\BuildTools" ( + call "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools -version 17,18 > vswhereInfo + for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do ( + if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat" + ) + del vswhereInfo + ) else ( + call "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" -version 17,18 > vswhereInfo + for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do ( + if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat" + ) + del vswhereInfo + ) + ) else ( + if /I "%1"=="VS2022" goto ToolNotInstall + goto SetWinDDK + ) +) + +if defined VCToolsInstallDir ( + if not defined VS2022_PREFIX ( + set "VS2022_PREFIX=%VCToolsInstallDir%" + ) + if not defined WINSDK10_PREFIX ( + if defined WindowsSdkVerBinPath ( + set "WINSDK10_PREFIX=%WindowsSdkVerBinPath%" + ) else if exist "%ProgramFiles(x86)%\Windows Kits\10\bin" ( + set "WINSDK10_PREFIX=%ProgramFiles(x86)%\Windows Kits\10\bin\" + ) else if exist "%ProgramFiles%\Windows Kits\10\bin" ( + set "WINSDK10_PREFIX=%ProgramFiles%\Windows Kits\10\bin\" + ) + ) +) +if not defined WINSDK_PATH_FOR_RC_EXE ( + if defined WINSDK10_PREFIX ( + set "WINSDK_PATH_FOR_RC_EXE=%WINSDK10_PREFIX%x86" + ) +) + +if /I "%1"=="VS2022" goto SetWinDDK + :SetWinDDK if not defined WINDDK3790_PREFIX ( set WINDDK3790_PREFIX=C:\WINDDK\3790.1830\bin\ diff --git a/BaseTools/toolsetup.bat b/BaseTools/toolsetup.bat index 22bd0faeb9..5b1070f1e4 100755 --- a/BaseTools/toolsetup.bat +++ b/BaseTools/toolsetup.bat @@ -44,6 +44,12 @@ if /I "%1"=="/?" goto Usage set FORCE_REBUILD=TRUE goto loop ) + if /I "%1"=="VS2022" ( + shift + set VS2022=TRUE + set VSTool=VS2022 + goto loop + ) if /I "%1"=="VS2019" ( shift set VS2019=TRUE @@ -172,7 +178,9 @@ IF NOT exist "%EDK_TOOLS_PATH%\set_vsprefix_envs.bat" ( @echo. goto end ) -if defined VS2019 ( +if defined VS2022 ( + call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2022 +) else if defined VS2019 ( call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2019 ) else if defined VS2017 ( call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2017 @@ -437,12 +445,14 @@ if %ERRORLEVEL% EQU 0 ( @echo VS2015 Set the env for VS2015 build. @echo VS2017 Set the env for VS2017 build. @echo VS2019 Set the env for VS2019 build. + @echo VS2022 Set the env for VS2022 build. @echo. :end set REBUILD= set FORCE_REBUILD= set RECONFIG= +set VS2022= set VS2019= set VS2017= set VS2015= -- cgit v1.2.3