Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle VS Build Tools 2022 when trying to detect VS version. #186

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions cc/private/toolchain/windows_cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,17 @@ def _find_vc_path(repository_ctx):
repository_ctx,
"'PROGRAMFILES(X86)' environment variable is not set, using '%s' as default" % program_files_dir,
)
for path in [
"Microsoft Visual Studio\\2019\\Preview\\VC",
"Microsoft Visual Studio\\2019\\BuildTools\\VC",
"Microsoft Visual Studio\\2019\\Community\\VC",
"Microsoft Visual Studio\\2019\\Professional\\VC",
"Microsoft Visual Studio\\2019\\Enterprise\\VC",
"Microsoft Visual Studio\\2017\\BuildTools\\VC",
"Microsoft Visual Studio\\2017\\Community\\VC",
"Microsoft Visual Studio\\2017\\Professional\\VC",
"Microsoft Visual Studio\\2017\\Enterprise\\VC",
"Microsoft Visual Studio 14.0\\VC",
]:
all_vc_locations = []
for vs_year in ["2022", "2019", "2017"]:
all_vc_locations.extend([
"Microsoft Visual Studio\\{vs_year}\\Preview\\VC".format(vs_year = vs_year),
"Microsoft Visual Studio\\{vs_year}\\BuildTools\\VC".format(vs_year = vs_year),
"Microsoft Visual Studio\\{vs_year}\\Community\\VC".format(vs_year = vs_year),
"Microsoft Visual Studio\\{vs_year}\\Professional\\VC".format(vs_year = vs_year),
"Microsoft Visual Studio\\{vs_year}\\Enterprise\\VC".format(vs_year = vs_year),
])
all_vc_locations.append("Microsoft Visual Studio 14.0\\VC")
for path in all_vc_locations:
path = program_files_dir + "\\" + path
if repository_ctx.path(path).exists:
vc_dir = path
Expand All @@ -221,18 +220,21 @@ def _find_vc_path(repository_ctx):
auto_configure_warning_maybe(repository_ctx, "Visual C++ build tools found at %s" % vc_dir)
return vc_dir

def _is_vs_2017_or_2019(vc_path):
"""Check if the installed VS version is Visual Studio 2017."""
def _is_vs_newer_than_2017(vc_path):
"""Check if the installed VS version is Visual Studio 2017 or newer."""

# In VS 2017 and 2019, the location of VC is like:
# In VS 2017, 2019 and 2022, the location of VC is like:
# C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\
# In VS 2015 or older version, it is like:
# C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\
return vc_path.find("2017") != -1 or vc_path.find("2019") != -1
for vs_year in ["2017", "2019", "2022"]:
if vc_path.find(vs_year) != -1:
return True
return False

def _find_vcvars_bat_script(repository_ctx, vc_path):
"""Find batch script to set up environment variables for VC. Doesn't %-escape the result."""
if _is_vs_2017_or_2019(vc_path):
if _is_vs_newer_than_2017(vc_path):
vcvars_script = vc_path + "\\Auxiliary\\Build\\VCVARSALL.BAT"
else:
vcvars_script = vc_path + "\\VCVARSALL.BAT"
Expand All @@ -250,7 +252,7 @@ def _is_support_vcvars_ver(vc_full_version):

def _is_support_winsdk_selection(repository_ctx, vc_path):
"""Windows SDK selection is supported with VC 2017 / 2019 or with full VS 2015 installation."""
if _is_vs_2017_or_2019(vc_path):
if _is_vs_newer_than_2017(vc_path):
return True

# By checking the source code of VCVARSALL.BAT in VC 2015, we know that
Expand Down Expand Up @@ -292,7 +294,7 @@ def setup_vc_env_vars(repository_ctx, vc_path, envvars = [], allow_empty = False

# Get VC version set by user. Only supports VC 2017 & 2019.
vcvars_ver = ""
if _is_vs_2017_or_2019(vc_path):
if _is_vs_newer_than_2017(vc_path):
full_version = _get_vc_full_version(repository_ctx, vc_path)

# Because VCVARSALL.BAT is from the latest VC installed, so we check if the latest
Expand Down Expand Up @@ -363,7 +365,7 @@ def _get_winsdk_full_version(repository_ctx):
def _find_msvc_tool(repository_ctx, vc_path, tool):
"""Find the exact path of a specific build tool in MSVC. Doesn't %-escape the result."""
tool_path = None
if _is_vs_2017_or_2019(vc_path):
if _is_vs_newer_than_2017(vc_path):
full_version = _get_vc_full_version(repository_ctx, vc_path)
if full_version:
tool_path = "%s\\Tools\\MSVC\\%s\\bin\\HostX64\\x64\\%s" % (vc_path, full_version, tool)
Expand Down