|
| 1 | +From 55c25a8ec55837c1ccfdbca10c06a15c6f2a2665 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Bruce Dawson < [email protected]> |
| 3 | +Date: Tue, 21 Dec 2021 16:19:32 +0000 |
| 4 | +Subject: [PATCH 2/5] build: Relanding Rudimentary support for Visual Studio |
| 5 | + 2022. |
| 6 | + |
| 7 | +This CL patches vs_toolchain.py to handle an installed version of |
| 8 | +Visual Studio 2022. This is a necessary first step towards supporting |
| 9 | +VS2022, but it's not sufficient. There are no guarantees that the |
| 10 | +MSVC143 toolchain produces acceptable results. |
| 11 | + |
| 12 | +Visual Studio 2022 is the first 64-bit edition, so it is installed in |
| 13 | +C:\Program Files\, not C:\Program Files (x86)\. Handling both VS2022 and |
| 14 | +older versions introduces a bit of extra complexity in the path |
| 15 | +detection code. We'll be able to remove this complexity when we remove |
| 16 | +support for VS2019 and below. |
| 17 | + |
| 18 | +This was originally landed as crrev.com/c/3316095 but that change broke |
| 19 | +arm64 builds because this change inadvertently changed the toolset |
| 20 | +version for prepackaged toolchains which arm64 use to find the UCRT. |
| 21 | + |
| 22 | +Tested: Full build with Visual Studio 2022 Professional retail, gn gen |
| 23 | +of x64 and arm64 with packaged toolchain. |
| 24 | + |
| 25 | +Bug: 1277518 |
| 26 | +Change-Id: Ic942ba82a71799bbe14dc64e4e640d9d36e62b22 |
| 27 | +Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3351095 |
| 28 | +Reviewed-by: Victor Costan < [email protected]> |
| 29 | +Reviewed-by: Peter Wen < [email protected]> |
| 30 | +Commit-Queue: Bruce Dawson < [email protected]> |
| 31 | +Cr-Commit-Position: refs/heads/main@{#953228} |
| 32 | +--- |
| 33 | + build/vs_toolchain.py | 58 ++++++++++++++++++------------ |
| 34 | + docs/windows_build_instructions.md | 8 +++-- |
| 35 | + 2 files changed, 40 insertions(+), 26 deletions(-) |
| 36 | + |
| 37 | +diff --git a/build/vs_toolchain.py b/build/vs_toolchain.py |
| 38 | +index ecf0971ab1349..e759bd6ca2afe 100755 |
| 39 | +--- a/build/vs_toolchain.py |
| 40 | ++++ b/build/vs_toolchain.py |
| 41 | +@@ -39,15 +39,20 @@ script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 42 | + json_data_file = os.path.join(script_dir, 'win_toolchain.json') |
| 43 | + |
| 44 | + # VS versions are listed in descending order of priority (highest first). |
| 45 | ++# The first version is assumed by this script to be the one that is packaged, |
| 46 | ++# which makes a difference for the arm64 runtime. |
| 47 | + MSVS_VERSIONS = collections.OrderedDict([ |
| 48 | +- ('2019', '16.0'), |
| 49 | +- ('2017', '15.0'), |
| 50 | ++ ('2019', '16.0'), # Default and packaged version of Visual Studio. |
| 51 | ++ ('2022', '17.0'), |
| 52 | ++ ('2017', '15.0'), |
| 53 | + ]) |
| 54 | + |
| 55 | + # List of preferred VC toolset version based on MSVS |
| 56 | ++# Order is not relevant for this dictionary. |
| 57 | + MSVC_TOOLSET_VERSION = { |
| 58 | +- '2019' : 'VC142', |
| 59 | +- '2017' : 'VC141', |
| 60 | ++ '2022': 'VC143', |
| 61 | ++ '2019': 'VC142', |
| 62 | ++ '2017': 'VC141', |
| 63 | + } |
| 64 | + |
| 65 | + def _HostIsWindows(): |
| 66 | +@@ -167,13 +172,17 @@ def GetVisualStudioVersion(): |
| 67 | + # Checking vs%s_install environment variables. |
| 68 | + # For example, vs2019_install could have the value |
| 69 | + # "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community". |
| 70 | +- # Only vs2017_install and vs2019_install are supported. |
| 71 | ++ # Only vs2017_install, vs2019_install and vs2022_install are supported. |
| 72 | + path = os.environ.get('vs%s_install' % version) |
| 73 | + if path and os.path.exists(path): |
| 74 | + available_versions.append(version) |
| 75 | + break |
| 76 | + # Detecting VS under possible paths. |
| 77 | +- path = os.path.expandvars('%ProgramFiles(x86)%' + |
| 78 | ++ if version >= '2022': |
| 79 | ++ program_files_path_variable = '%ProgramFiles%' |
| 80 | ++ else: |
| 81 | ++ program_files_path_variable = '%ProgramFiles(x86)%' |
| 82 | ++ path = os.path.expandvars(program_files_path_variable + |
| 83 | + '/Microsoft Visual Studio/%s' % version) |
| 84 | + if path and any( |
| 85 | + os.path.exists(os.path.join(path, edition)) |
| 86 | +@@ -200,23 +209,26 @@ def DetectVisualStudioPath(): |
| 87 | + # the registry. For details see: |
| 88 | + # https://blogs.msdn.microsoft.com/heaths/2016/09/15/changes-to-visual-studio-15-setup/ |
| 89 | + # For now we use a hardcoded default with an environment variable override. |
| 90 | +- for path in ( |
| 91 | +- os.environ.get('vs%s_install' % version_as_year), |
| 92 | +- os.path.expandvars('%ProgramFiles(x86)%' + |
| 93 | +- '/Microsoft Visual Studio/%s/Enterprise' % |
| 94 | +- version_as_year), |
| 95 | +- os.path.expandvars('%ProgramFiles(x86)%' + |
| 96 | +- '/Microsoft Visual Studio/%s/Professional' % |
| 97 | +- version_as_year), |
| 98 | +- os.path.expandvars('%ProgramFiles(x86)%' + |
| 99 | +- '/Microsoft Visual Studio/%s/Community' % |
| 100 | +- version_as_year), |
| 101 | +- os.path.expandvars('%ProgramFiles(x86)%' + |
| 102 | +- '/Microsoft Visual Studio/%s/Preview' % |
| 103 | +- version_as_year), |
| 104 | +- os.path.expandvars('%ProgramFiles(x86)%' + |
| 105 | +- '/Microsoft Visual Studio/%s/BuildTools' % |
| 106 | +- version_as_year)): |
| 107 | ++ if version_as_year >= '2022': |
| 108 | ++ program_files_path_variable = '%ProgramFiles%' |
| 109 | ++ else: |
| 110 | ++ program_files_path_variable = '%ProgramFiles(x86)%' |
| 111 | ++ for path in (os.environ.get('vs%s_install' % version_as_year), |
| 112 | ++ os.path.expandvars(program_files_path_variable + |
| 113 | ++ '/Microsoft Visual Studio/%s/Enterprise' % |
| 114 | ++ version_as_year), |
| 115 | ++ os.path.expandvars(program_files_path_variable + |
| 116 | ++ '/Microsoft Visual Studio/%s/Professional' % |
| 117 | ++ version_as_year), |
| 118 | ++ os.path.expandvars(program_files_path_variable + |
| 119 | ++ '/Microsoft Visual Studio/%s/Community' % |
| 120 | ++ version_as_year), |
| 121 | ++ os.path.expandvars(program_files_path_variable + |
| 122 | ++ '/Microsoft Visual Studio/%s/Preview' % |
| 123 | ++ version_as_year), |
| 124 | ++ os.path.expandvars(program_files_path_variable + |
| 125 | ++ '/Microsoft Visual Studio/%s/BuildTools' % |
| 126 | ++ version_as_year)): |
| 127 | + if path and os.path.exists(path): |
| 128 | + return path |
| 129 | + |
| 130 | +diff --git a/docs/windows_build_instructions.md b/docs/windows_build_instructions.md |
| 131 | +index 2cfd0f7cebb81..83de36d71a69e 100644 |
| 132 | +--- a/docs/windows_build_instructions.md |
| 133 | ++++ b/docs/windows_build_instructions.md |
| 134 | +@@ -90,10 +90,12 @@ Also, add a DEPOT_TOOLS_WIN_TOOLCHAIN system variable in the same way, and set |
| 135 | + it to 0. This tells depot_tools to use your locally installed version of Visual |
| 136 | + Studio (by default, depot_tools will try to use a google-internal version). |
| 137 | + |
| 138 | +-You may also have to set variable `vs2017_install` or `vs2019_install` to your |
| 139 | +-installation path of Visual Studio 2017 or 19, like |
| 140 | ++You may also have to set variable `vs2017_install` or `vs2019_install` or |
| 141 | ++`vs2022_install` to your installation path of Visual Studio 2017 or 19 or 22, like |
| 142 | + `set vs2019_install=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional` |
| 143 | +-for Visual Studio 2019. |
| 144 | ++for Visual Studio 2019, or |
| 145 | ++`set vs2022_install=C:\Program Files\Microsoft Visual Studio\2022\Professional` |
| 146 | ++for Visual Studio 2022. |
| 147 | + |
| 148 | + From a cmd.exe shell, run: |
| 149 | + |
| 150 | +-- |
| 151 | +2.33.0.windows.2 |
| 152 | + |
0 commit comments