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

Consolidate VS detection logic #49593

Merged
merged 2 commits into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
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
92 changes: 0 additions & 92 deletions eng/native/init-compiler-and-cmake.cmd

This file was deleted.

71 changes: 71 additions & 0 deletions eng/native/init-vs-env.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
@if not defined _echo @echo off

:: Initializes Visual Studio developer environment. If a build architecture is passed
:: as an argument, it also initializes VC++ build environment and CMakePath.

set "__VCBuildArch="
if /i "%~1" == "x86" (set __VCBuildArch=x86)
if /i "%~1" == "x64" (set __VCBuildArch=x86_amd64)
if /i "%~1" == "arm" (set __VCBuildArch=x86_arm)
if /i "%~1" == "arm64" (set __VCBuildArch=x86_arm64)
if /i "%~1" == "wasm" (set __VCBuildArch=x86_amd64)

:: Default to highest Visual Studio version available that has Visual C++ tools.
::
:: For VS2017 and later, multiple instances can be installed on the same box SxS and VS1*0COMNTOOLS
:: is no longer set as a global environment variable and is instead only set if the user
:: has launched the Visual Studio Developer Command Prompt.
::
:: Following this logic, we will default to the Visual Studio toolset assocated with the active
:: Developer Command Prompt. Otherwise, we will query VSWhere to locate the later version of
:: Visual Studio available on the machine. Finally, we will fail the script if no supported
:: instance can be found.

if defined VisualStudioVersion goto :VSDetected

set "__VSWhere=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
set "__VSCOMNTOOLS="

if exist "%__VSWhere%" (
for /f "tokens=*" %%p in (
'"%__VSWhere%" -latest -prerelease -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath'
) do set __VSCOMNTOOLS=%%p\Common7\Tools
)

if not exist "%__VSCOMNTOOLS%" goto :VSMissing

:: Make sure the current directory stays intact
set "VSCMD_START_DIR=%CD%"

call "%__VSCOMNTOOLS%\VsDevCmd.bat" -no_logo

:: Clean up helper variables
set "__VSWhere="
set "__VSCOMNTOOLS="
set "VSCMD_START_DIR="

:VSDetected
if "%VisualStudioVersion%"=="16.0" (
set __VSVersion=vs2019
set __PlatformToolset=v142
goto :SetVCEnvironment
)

:VSMissing
echo %__MsgPrefix%Error: Visual Studio 2019 with C++ tools required. ^
Please see https://github.com/dotnet/runtime/blob/main/docs/workflow/requirements/windows-requirements.md for build requirements.
exit /b 1

:SetVCEnvironment

if "%__VCBuildArch%"=="" exit /b 0

:: Set the environment for the native build
call "%VCINSTALLDIR%Auxiliary\Build\vcvarsall.bat" %__VCBuildArch%
if not "%ErrorLevel%"=="0" exit /b 1

set "__VCBuildArch="

:: Set CMakePath by evaluating the output from set-cmake-path.ps1.
:: In case of a failure the output is "exit /b 1".
for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "%~dp0set-cmake-path.ps1"') do %%a
38 changes: 9 additions & 29 deletions src/coreclr/build-runtime.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,11 @@ set "__MsgPrefix=BUILD: "
echo %__MsgPrefix%Starting Build at %TIME%

set __ThisScriptFull="%~f0"
set __ThisScriptDir="%~dp0"

call %__ThisScriptDir%\setup_vs_tools.cmd
if NOT '%ERRORLEVEL%' == '0' goto ExitWithError

if defined VS160COMNTOOLS (
set "__VSToolsRoot=%VS160COMNTOOLS%"
set "__VCToolsRoot=%VS160COMNTOOLS%\..\..\VC\Auxiliary\Build"
set __VSVersion=vs2019
) else if defined VS150COMNTOOLS (
set "__VSToolsRoot=%VS150COMNTOOLS%"
set "__VCToolsRoot=%VS150COMNTOOLS%\..\..\VC\Auxiliary\Build"
set __VSVersion=vs2017
)

:: Note that the msbuild project files (specifically, dir.proj) will use the following variables, if set:
:: __BuildArch -- default: x64
:: __BuildType -- default: Debug
:: __TargetOS -- default: windows
:: __TargetOS -- default: windows
:: __ProjectDir -- default: directory of the dir.props file
:: __RepoRootDir -- default: directory two levels above the dir.props file
:: __RootBinDir -- default: %__RepoRootDir%\artifacts\
Expand Down Expand Up @@ -207,6 +193,14 @@ if defined __Priority (
)
)

:: Initialize VS environment
call %__RepoRootDir%\eng\native\init-vs-env.cmd
if NOT '%ERRORLEVEL%' == '0' goto ExitWithError

if defined VCINSTALLDIR (
set "__VCToolsRoot=%VCINSTALLDIR%Auxiliary\Build"
)

if defined __BuildAll goto BuildAll

set /A __TotalSpecifiedBuildArch=__BuildArchX64 + __BuildArchX86 + __BuildArchArm + __BuildArchArm64
Expand Down Expand Up @@ -610,12 +604,6 @@ if %__BuildNative% EQU 1 (
call "%__VCToolsRoot%\vcvarsall.bat" !__VCBuildArch!
@if defined _echo @echo on

if not defined VSINSTALLDIR (
echo %__ErrMsgPrefix%%__MsgPrefix%Error: VSINSTALLDIR variable not defined.
goto ExitWithError
)
if not exist "!VSINSTALLDIR!DIA SDK" goto NoDIA

if defined __SkipConfigure goto SkipConfigure

echo %__MsgPrefix%Regenerating the Visual Studio solution
Expand Down Expand Up @@ -845,11 +833,3 @@ echo -- builds all build types for x86
echo build -all -x64 -x86 -Checked -Release
echo -- builds x64 and x86 architectures, Checked and Release build types for each
exit /b 1

:NoDIA
echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
Did you install all the requirements for building on Windows, including the "Desktop Development with C++" workload? ^
Please see https://github.com/dotnet/runtime/blob/main/docs/workflow/requirements/windows-requirements.md ^
Another possibility is that you have a parallel installation of Visual Studio and the DIA SDK is there. In this case it ^
may help to copy its "DIA SDK" folder into "%VSINSTALLDIR%" manually, then try again.
exit /b 1
43 changes: 4 additions & 39 deletions src/coreclr/crossgen-corelib.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ set "__MsgPrefix=CROSSGEN-CORELIB: "

echo %__MsgPrefix%Starting Build at %TIME%

set __ThisScriptFull="%~f0"
set __ThisScriptDir=%~dp0

:: Note that the msbuild project files (specifically, dir.proj) will use the following variables, if set:
:: __BuildArch -- default: x64
:: __BuildType -- default: Debug
Expand Down Expand Up @@ -133,39 +130,15 @@ if not exist "%__BinDir%" md "%__BinDir%"
if not exist "%__IntermediatesDir%" md "%__IntermediatesDir%"
if not exist "%__LogsDir%" md "%__LogsDir%"


call "%__ThisScriptDir%"\setup_vs_tools.cmd
if NOT '%ERRORLEVEL%' == '0' goto ExitWithError

if defined VS160COMNTOOLS (
set "__VSToolsRoot=%VS160COMNTOOLS%"
set "__VCToolsRoot=%VS160COMNTOOLS%\..\..\VC\Auxiliary\Build"
set __VSVersion=vs2019
) else if defined VS150COMNTOOLS (
set "__VSToolsRoot=%VS150COMNTOOLS%"
set "__VCToolsRoot=%VS150COMNTOOLS%\..\..\VC\Auxiliary\Build"
set __VSVersion=vs2017
)

REM Need VC native tools environment for the host arch to find Microsoft.DiaSymReader.Native in the Visual Studio install.
set __VCBuildArch=x86_amd64
if /i "%__BuildArch%" == "x86" ( set __VCBuildArch=x86 )
if /i "%__BuildArch%" == "arm" (
set __VCBuildArch=x86_arm
)
if /i "%__BuildArch%" == "arm64" (
set __VCBuildArch=x86_arm64
)
call %__RepoRootDir%\eng\native\init-vs-env.cmd %__BuildArch%
if NOT '%ERRORLEVEL%' == '0' goto ExitWithError

echo %__MsgPrefix%Using environment: "%__VCToolsRoot%\vcvarsall.bat" !__VCBuildArch!
call "%__VCToolsRoot%\vcvarsall.bat" !__VCBuildArch!
@if defined _echo @echo on

if not defined VSINSTALLDIR (
echo %__ErrMsgPrefix%%__MsgPrefix%Error: VSINSTALLDIR variable not defined.
goto ExitWithError
if defined VCINSTALLDIR (
set "__VCToolsRoot=%VCINSTALLDIR%Auxiliary\Build"
)
if not exist "!VSINSTALLDIR!DIA SDK" goto NoDIA

echo %__MsgPrefix%Generating native image of System.Private.CoreLib for %__TargetOS%.%__BuildArch%.%__BuildType%. Logging to "%__CrossGenCoreLibLog%".
if exist "%__CrossGenCoreLibLog%" del "%__CrossGenCoreLibLog%"
Expand Down Expand Up @@ -257,11 +230,3 @@ exit /b 1

:ExitWithCode
exit /b !__exitCode!

:NoDIA
echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
Did you install all the requirements for building on Windows, including the "Desktop Development with C++" workload? ^
Please see https://github.com/dotnet/runtime/blob/main/docs/workflow/requirements/windows-requirements.md ^
Another possibility is that you have a parallel installation of Visual Studio and the DIA SDK is there. In this case it ^
may help to copy its "DIA SDK" folder into "%VSINSTALLDIR%" manually, then try again.
exit /b 1
2 changes: 1 addition & 1 deletion src/coreclr/crossgen-corelib.proj
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
</PropertyGroup>

<PropertyGroup Condition="'$(UseCrossgen2)' != 'true'">
<VsSetupCmd>call $([MSBuild]::NormalizePath('$(RepoRoot)', 'src', 'coreclr', 'setup_vs_tools.cmd')) &amp;&amp;</VsSetupCmd>
<VsSetupCmd>call $([MSBuild]::NormalizePath('$(RepoRoot)', 'eng', 'native', 'init-vs-env.cmd')) &amp;&amp;</VsSetupCmd>

<CrossGenDllCmd>$(CrossGen1Cmd) /out "$(CoreLibOutputPath)"</CrossGenDllCmd>
<CrossGenDllCmd>$(CrossGenDllCmd) "$(CoreLibInputPath)"</CrossGenDllCmd>
Expand Down
42 changes: 0 additions & 42 deletions src/coreclr/setup_vs_tools.cmd

This file was deleted.

Loading