From: Anton Lapounov Date: Sun, 14 Mar 2021 21:48:27 +0000 (-0700) Subject: Consolidate VS detection logic (#49593) X-Git-Tag: submit/tizen/20210909.063632~2708 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c156959c33e48651b4ebfb51c64de510aadfefb3;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Consolidate VS detection logic (#49593) --- diff --git a/eng/native/init-compiler-and-cmake.cmd b/eng/native/init-compiler-and-cmake.cmd deleted file mode 100644 index 43e4cf8..0000000 --- a/eng/native/init-compiler-and-cmake.cmd +++ /dev/null @@ -1,92 +0,0 @@ -@if not defined _echo @echo off -rem -rem This file locates VS C++ compilers and cmake for windows. - -rem Make sure the current directory stays intact -set VSCMD_START_DIR="%CD%" - -:SetupArgs -:: Initialize the args that will be passed to cmake -set __VCBuildArch=x86_amd64 - -:Arg_Loop -:: Since the native build requires some configuration information before msbuild is called, we have to do some manual args parsing -if [%1] == [] goto :ToolsVersion -if /i [%1] == [x86] ( set __VCBuildArch=x86&&shift&goto Arg_Loop) -if /i [%1] == [arm] ( set __VCBuildArch=x86_arm&&shift&goto Arg_Loop) -if /i [%1] == [x64] ( set __VCBuildArch=x86_amd64&&shift&goto Arg_Loop) -if /i [%1] == [arm64] ( set __VCBuildArch=x86_arm64&&shift&goto Arg_Loop) - -shift -goto :Arg_Loop - -:ToolsVersion -:: Default to highest Visual Studio version available -:: -:: For VS2017 and later, multiple instances can be installed on the same box SxS and VSxxxCOMNTOOLS is only set if the user -:: has launched the VS2017 or VS2019 Developer Command Prompt. -:: -:: Following this logic, we will default to the VS2017 or VS2019 toolset if VS150COMNTOOLS or VS160COMMONTOOLS tools is -:: set, as this indicates the user is running from the VS2017 or VS2019 Developer Command Prompt and -:: is already configured to use that toolset. Otherwise, we will fail the script if no supported VS instance can be found. - -if defined VisualStudioVersion goto :RunVCVars - -set _VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -if exist %_VSWHERE% ( - for /f "usebackq tokens=*" %%i in (`%_VSWHERE% -latest -prerelease -property installationPath`) do set _VSCOMNTOOLS=%%i\Common7\Tools -) -if not exist "%_VSCOMNTOOLS%" goto :MissingVersion - -call "%_VSCOMNTOOLS%\VsDevCmd.bat" -no_logo - -:RunVCVars -if "%VisualStudioVersion%"=="16.0" ( - goto :VS2019 -) else if "%VisualStudioVersion%"=="15.0" ( - goto :VS2017 -) - -:MissingVersion -:: Can't find appropriate VS install -echo Error: Visual Studio 2019 required -echo Please see https://github.com/dotnet/runtime/tree/main/docs/workflow/building/libraries for build instructions. -exit /b 1 - -:VS2019 -:: Setup vars for VS2019 -set __VSVersion=vs2019 -set __PlatformToolset=v142 -:: Set the environment for the native build -call "%VS160COMNTOOLS%..\..\VC\Auxiliary\Build\vcvarsall.bat" %__VCBuildArch% -goto FindDIASDK - -:VS2017 -:: Setup vars for VS2017 -set __VSVersion=vs2017 -set __PlatformToolset=v141 -:: Set the environment for the native build -call "%VS150COMNTOOLS%..\..\VC\Auxiliary\Build\vcvarsall.bat" %__VCBuildArch% -goto FindDIASDK - -:FindDIASDK -if exist "%VSINSTALLDIR%DIA SDK" goto CheckRepoRoot -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 - -:CheckRepoRoot - -if exist "%__repoRoot%" goto :FindCMake -:: Can't find repo root -echo Error: variable __repoRoot not set. -exit /b 1 - -:FindCMake -:: Find CMake - -:: Eval the output from set-cmake-path.ps1 -for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "cd "%__repoRoot:"=%"; & eng\native\set-cmake-path.ps1"') do %%a diff --git a/eng/native/init-vs-env.cmd b/eng/native/init-vs-env.cmd new file mode 100644 index 0000000..c05214b --- /dev/null +++ b/eng/native/init-vs-env.cmd @@ -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 diff --git a/src/coreclr/build-runtime.cmd b/src/coreclr/build-runtime.cmd index 7373015..18a7f39 100644 --- a/src/coreclr/build-runtime.cmd +++ b/src/coreclr/build-runtime.cmd @@ -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\ @@ -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 @@ -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 @@ -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 diff --git a/src/coreclr/crossgen-corelib.cmd b/src/coreclr/crossgen-corelib.cmd index 882404d..52bbb6b 100644 --- a/src/coreclr/crossgen-corelib.cmd +++ b/src/coreclr/crossgen-corelib.cmd @@ -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 @@ -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%" @@ -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 diff --git a/src/coreclr/crossgen-corelib.proj b/src/coreclr/crossgen-corelib.proj index 8687641..b2a1848 100644 --- a/src/coreclr/crossgen-corelib.proj +++ b/src/coreclr/crossgen-corelib.proj @@ -88,7 +88,7 @@ - call $([MSBuild]::NormalizePath('$(RepoRoot)', 'src', 'coreclr', 'setup_vs_tools.cmd')) && + call $([MSBuild]::NormalizePath('$(RepoRoot)', 'eng', 'native', 'init-vs-env.cmd')) && $(CrossGen1Cmd) /out "$(CoreLibOutputPath)" $(CrossGenDllCmd) "$(CoreLibInputPath)" diff --git a/src/coreclr/setup_vs_tools.cmd b/src/coreclr/setup_vs_tools.cmd deleted file mode 100644 index 055a5dd..0000000 --- a/src/coreclr/setup_vs_tools.cmd +++ /dev/null @@ -1,42 +0,0 @@ -@if not defined _echo @echo off - -REM This script is responsible for setting up the vs2017 or vs2019 env -REM All passed arguments are ignored -REM Script will return with 0 if pass, 1 if there is a failure to find either -REM vs2017 or vs2019 - -:: Default to highest Visual Studio version available -:: -:: 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 not supported -:: instance can be found. - -if defined VisualStudioVersion ( - if not defined __VSVersion echo %__MsgPrefix%Detected Visual Studio %VisualStudioVersion% developer command ^prompt environment - goto skip_setup -) - -echo %__MsgPrefix%Searching ^for Visual Studio installation -set _VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -if exist %_VSWHERE% ( - for /f "usebackq tokens=*" %%i in (`%_VSWHERE% -latest -prerelease -property installationPath`) do set _VSCOMNTOOLS=%%i\Common7\Tools - goto call_vs -) - -:call_vs -if not exist "%_VSCOMNTOOLS%" ( - echo %__MsgPrefix%Error: Visual Studio 2019 required. - echo Please see https://github.com/dotnet/runtime/blob/main/docs/workflow/requirements/windows-requirements.md for build instructions. - exit /b 1 -) -echo %__MsgPrefix%"%_VSCOMNTOOLS%\VsDevCmd.bat" -call "%_VSCOMNTOOLS%\VsDevCmd.bat" - -:skip_setup - -exit /b 0 diff --git a/src/libraries/Native/build-native.cmd b/src/libraries/Native/build-native.cmd index 6b6b74d..8cbe62d 100644 --- a/src/libraries/Native/build-native.cmd +++ b/src/libraries/Native/build-native.cmd @@ -11,7 +11,6 @@ set __CMakeBinDir="" set __IntermediatesDir="" set __BuildArch=x64 set __BuildTarget="build" -set __VCBuildArch=x86_amd64 set __TargetOS=windows set CMAKE_BUILD_TYPE=Debug set "__LinkArgs= " @@ -20,17 +19,17 @@ set __Ninja=0 :Arg_Loop :: Since the native build requires some configuration information before msbuild is called, we have to do some manual args parsing -if [%1] == [] goto :ToolsVersion +if [%1] == [] goto :InitVSEnv if /i [%1] == [Release] ( set CMAKE_BUILD_TYPE=Release&&shift&goto Arg_Loop) if /i [%1] == [Debug] ( set CMAKE_BUILD_TYPE=Debug&&shift&goto Arg_Loop) -if /i [%1] == [AnyCPU] ( set __BuildArch=x64&&set __VCBuildArch=x86_amd64&&shift&goto Arg_Loop) -if /i [%1] == [x86] ( set __BuildArch=x86&&set __VCBuildArch=x86&&shift&goto Arg_Loop) -if /i [%1] == [arm] ( set __BuildArch=arm&&set __VCBuildArch=x86_arm&&shift&goto Arg_Loop) -if /i [%1] == [x64] ( set __BuildArch=x64&&set __VCBuildArch=x86_amd64&&shift&goto Arg_Loop) -if /i [%1] == [amd64] ( set __BuildArch=x64&&set __VCBuildArch=x86_amd64&&shift&goto Arg_Loop) -if /i [%1] == [arm64] ( set __BuildArch=arm64&&set __VCBuildArch=x86_arm64&&shift&goto Arg_Loop) -if /i [%1] == [wasm] ( set __BuildArch=wasm&&set __VCBuildArch=x86_amd64&&shift&goto Arg_Loop) +if /i [%1] == [AnyCPU] ( set __BuildArch=x64&&shift&goto Arg_Loop) +if /i [%1] == [x86] ( set __BuildArch=x86&&shift&goto Arg_Loop) +if /i [%1] == [arm] ( set __BuildArch=arm&&shift&goto Arg_Loop) +if /i [%1] == [x64] ( set __BuildArch=x64&&shift&goto Arg_Loop) +if /i [%1] == [amd64] ( set __BuildArch=x64&&shift&goto Arg_Loop) +if /i [%1] == [arm64] ( set __BuildArch=arm64&&shift&goto Arg_Loop) +if /i [%1] == [wasm] ( set __BuildArch=wasm&&shift&goto Arg_Loop) if /i [%1] == [outconfig] ( set __outConfig=%2&&shift&&shift&goto Arg_Loop) @@ -43,56 +42,10 @@ if /i [%1] == [ninja] ( set __Ninja=1&&shift&goto Arg_Loop) shift goto :Arg_Loop -:ToolsVersion -:: Default to highest Visual Studio version available -:: -:: For VS2017 and later, multiple instances can be installed on the same box SxS and VSxxxCOMNTOOLS is only set if the user -:: has launched the VS2017 or VS2019 Developer Command Prompt. -:: -:: Following this logic, we will default to the VS2017 or VS2019 toolset if VS150COMNTOOLS or VS160COMMONTOOLS tools is -:: set, as this indicates the user is running from the VS2017 or VS2019 Developer Command Prompt and -:: is already configured to use that toolset. Otherwise, we will fail the script if no supported VS instance can be found. - -if defined VisualStudioVersion goto :RunVCVars - -set _VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -if exist %_VSWHERE% ( - for /f "usebackq tokens=*" %%i in (`%_VSWHERE% -latest -prerelease -property installationPath`) do set _VSCOMNTOOLS=%%i\Common7\Tools -) -if not exist "%_VSCOMNTOOLS%" goto :MissingVersion - -call "%_VSCOMNTOOLS%\VsDevCmd.bat" -no_logo - -:RunVCVars -if "%VisualStudioVersion%"=="16.0" ( - goto :VS2019 -) else if "%VisualStudioVersion%"=="15.0" ( - goto :VS2017 -) - -:MissingVersion -:: Can't find appropriate VS install -echo Error: Visual Studio 2019 required -echo Please see https://github.com/dotnet/runtime/tree/main/docs/workflow/building/libraries for build instructions. -exit /b 1 +:InitVSEnv +call "%__engNativeDir%\init-vs-env.cmd" %__BuildArch% +if NOT [%errorlevel%] == [0] goto :Failure -:VS2019 -:: Setup vars for VS2019 -set __VSVersion=vs2019 -set __PlatformToolset=v142 -:: Set the environment for the native build -call "%VS160COMNTOOLS%..\..\VC\Auxiliary\Build\vcvarsall.bat" %__VCBuildArch% -goto :SetupDirs - -:VS2017 -:: Setup vars for VS2017 -set __VSVersion=vs2017 -set __PlatformToolset=v141 -:: Set the environment for the native build -call "%VS150COMNTOOLS%..\..\VC\Auxiliary\Build\vcvarsall.bat" %__VCBuildArch% -goto :SetupDirs - -:SetupDirs :: Setup to cmake the native components echo Commencing build of native components echo. @@ -122,22 +75,6 @@ set MSBUILD_EMPTY_PROJECT_CONTENT= ^ echo %MSBUILD_EMPTY_PROJECT_CONTENT% > "%__artifactsDir%\obj\native\Directory.Build.props" echo %MSBUILD_EMPTY_PROJECT_CONTENT% > "%__artifactsDir%\obj\native\Directory.Build.targets" -if exist "%VSINSTALLDIR%DIA SDK" goto FindCMake -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 - -:FindCMake -if defined CMakePath goto GenVSSolution -:: Find CMake - -:: Eval the output from set-cmake-path.ps1 -for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& ""%__repoRoot%\eng\native\set-cmake-path.ps1"""') do %%a - -:GenVSSolution :: generate version file powershell -NoProfile -ExecutionPolicy ByPass -NoLogo -File "%__repoRoot%\eng\common\msbuild.ps1" /clp:nosummary %__ArcadeScriptArgs%^ "%__repoRoot%\eng\empty.csproj" /p:NativeVersionFile="%__artifactsDir%\obj\_version.h"^ diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 4b2d2ab..228a9f9 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -362,7 +362,7 @@ <_MonoCMakeConfigureCommand>cmake @(_MonoCMakeArgs, ' ') $(MonoCMakeExtraArgs) $(MonoProjectRoot) <_MonoCMakeConfigureCommand Condition="'$(TargetsBrowser)' != 'true' and '$(_MonoRunInitCompiler)' != 'false' and '$(OS)' != 'Windows_NT'">bash -c 'source $(RepositoryEngineeringDir)native/init-compiler.sh $(Platform) $(MonoCCompiler) && @(_MonoBuildEnv, ' ') $(_MonoCMakeConfigureCommand)' - <_MonoCMakeConfigureCommand Condition="'$(TargetsBrowser)' != 'true' and '$(_MonoRunInitCompiler)' != 'false' and '$(OS)' == 'Windows_NT'">set __repoRoot="$(RepoRoot)" && call "$(RepositoryEngineeringDir)native\init-compiler-and-cmake.cmd" $(Platform) && cd /D "$(MonoObjDir)" && @(_MonoBuildEnv, ' ') $(_MonoCMakeConfigureCommand) + <_MonoCMakeConfigureCommand Condition="'$(TargetsBrowser)' != 'true' and '$(_MonoRunInitCompiler)' != 'false' and '$(OS)' == 'Windows_NT'">call "$(RepositoryEngineeringDir)native\init-vs-env.cmd" $(Platform) && cd /D "$(MonoObjDir)" && @(_MonoBuildEnv, ' ') $(_MonoCMakeConfigureCommand) <_MonoCMakeConfigureCommand Condition="'$(TargetsBrowser)' != 'true' and '$(_MonoRunInitCompiler)' == 'false'">$(_MonoCCOption) $(_MonoCXXOption) @(_MonoBuildEnv, ' ') $(_MonoCMakeConfigureCommand) <_MonoCMakeConfigureCommand Condition="'$(TargetsBrowser)' == 'true'">bash -c 'source $(EMSDK_PATH)/emsdk_env.sh && emcmake $(_MonoCMakeConfigureCommand)' @@ -370,7 +370,7 @@ <_MonoCMakeBuildCommand Condition="'$(MonoVerboseBuild)' == 'true'">$(_MonoCMakeBuildCommand) --verbose <_MonoCMakeBuildCommand Condition="'$(_MonoUseNinja)' != 'true'">$(_MonoCMakeBuildCommand) --parallel $([System.Environment]::ProcessorCount) <_MonoCMakeBuildCommand Condition="'$(TargetsBrowser)' != 'true' and '$(OS)' != 'Windows_NT'">@(_MonoBuildEnv, ' ') $(_MonoCMakeBuildCommand) - <_MonoCMakeBuildCommand Condition="'$(TargetsBrowser)' != 'true' and '$(OS)' == 'Windows_NT'">set __repoRoot="$(RepoRoot)" && call "$(RepositoryEngineeringDir)native\init-compiler-and-cmake.cmd" $(Platform) && cd /D "$(MonoObjDir)" && @(_MonoBuildEnv, ' ') $(_MonoCMakeBuildCommand) + <_MonoCMakeBuildCommand Condition="'$(TargetsBrowser)' != 'true' and '$(OS)' == 'Windows_NT'">call "$(RepositoryEngineeringDir)native\init-vs-env.cmd" $(Platform) && cd /D "$(MonoObjDir)" && @(_MonoBuildEnv, ' ') $(_MonoCMakeBuildCommand) @@ -508,11 +508,11 @@ <_MonoAotCrossOffsetsCommand Condition="'$(MonoUseCrossTool)' == 'true'">python3 $(MonoProjectRoot)mono/tools/offsets-tool/offsets-tool.py @(MonoAotCrossOffsetsToolParams, ' ') <_MonoAotCMakeConfigureCommand>cmake @(MonoAOTCMakeArgs, ' ') $(MonoProjectRoot) - <_MonoAotCMakeConfigureCommand Condition="'$(OS)' == 'Windows_NT'">set __repoRoot="$(RepoRoot)" && call "$(RepositoryEngineeringDir)native\init-compiler-and-cmake.cmd" $(Platform) && cd /D "$(MonoObjDir)\cross" && @(_MonoBuildEnv, ' ') $(_MonoAotCMakeConfigureCommand) + <_MonoAotCMakeConfigureCommand Condition="'$(OS)' == 'Windows_NT'">call "$(RepositoryEngineeringDir)native\init-vs-env.cmd" $(Platform) && cd /D "$(MonoObjDir)\cross" && @(_MonoBuildEnv, ' ') $(_MonoAotCMakeConfigureCommand) <_MonoAotCMakeBuildCommand>cmake --build . --target install --config $(Configuration) <_MonoAotCMakeBuildCommand Condition="'$(MonoVerboseBuild)' == 'true'">$(_MonoAotCMakeBuildCommand) --verbose <_MonoAotCMakeBuildCommand Condition="'$(_MonoUseNinja)' != 'true'">$(_MonoAotCMakeBuildCommand) --parallel $([System.Environment]::ProcessorCount) - <_MonoAotCMakeBuildCommand Condition="'$(OS)' == 'Windows_NT'">set __repoRoot="$(RepoRoot)" && call "$(RepositoryEngineeringDir)native\init-compiler-and-cmake.cmd" $(Platform) && cd /D "$(MonoObjDir)\cross" && @(_MonoBuildEnv, ' ') $(_MonoAotCMakeBuildCommand) + <_MonoAotCMakeBuildCommand Condition="'$(OS)' == 'Windows_NT'">call "$(RepositoryEngineeringDir)native\init-vs-env.cmd" $(Platform) && cd /D "$(MonoObjDir)\cross" && @(_MonoBuildEnv, ' ') $(_MonoAotCMakeBuildCommand) <_MonoAotPrebuiltOffsetsFile>$(ArtifactsObjDir)\mono\offsetfiles\$(PlatformConfigPathPart)\cross\$([System.IO.Path]::GetFileName('$(MonoAotOffsetsFile)')) diff --git a/src/native/corehost/build.cmd b/src/native/corehost/build.cmd index 82832da..9e44ccc 100644 --- a/src/native/corehost/build.cmd +++ b/src/native/corehost/build.cmd @@ -12,7 +12,6 @@ set __CMakeBinDir="" set __IntermediatesDir="" set __BuildArch=x64 set __appContainer="" -set __VCBuildArch=x86_amd64 set CMAKE_BUILD_TYPE=Debug set "__LinkArgs= " set "__LinkLibraries= " @@ -21,16 +20,16 @@ set __IncrementalNativeBuild=0 set __Ninja=0 :Arg_Loop -if [%1] == [] goto :ToolsVersion +if [%1] == [] goto :InitVSEnv if /i [%1] == [Release] ( set CMAKE_BUILD_TYPE=Release&&shift&goto Arg_Loop) if /i [%1] == [Debug] ( set CMAKE_BUILD_TYPE=Debug&&shift&goto Arg_Loop) -if /i [%1] == [AnyCPU] ( set __BuildArch=x64&&set __VCBuildArch=x86_amd64&&shift&goto Arg_Loop) -if /i [%1] == [x86] ( set __BuildArch=x86&&set __VCBuildArch=x86&&shift&goto Arg_Loop) -if /i [%1] == [arm] ( set __BuildArch=arm&&set __VCBuildArch=x86_arm&&shift&goto Arg_Loop) -if /i [%1] == [x64] ( set __BuildArch=x64&&set __VCBuildArch=x86_amd64&&shift&goto Arg_Loop) -if /i [%1] == [amd64] ( set __BuildArch=x64&&set __VCBuildArch=x86_amd64&&shift&goto Arg_Loop) -if /i [%1] == [arm64] ( set __BuildArch=arm64&&set __VCBuildArch=x86_arm64&&shift&goto Arg_Loop) +if /i [%1] == [AnyCPU] ( set __BuildArch=x64&&shift&goto Arg_Loop) +if /i [%1] == [x86] ( set __BuildArch=x86&&shift&goto Arg_Loop) +if /i [%1] == [arm] ( set __BuildArch=arm&&shift&goto Arg_Loop) +if /i [%1] == [x64] ( set __BuildArch=x64&&shift&goto Arg_Loop) +if /i [%1] == [amd64] ( set __BuildArch=x64&&shift&goto Arg_Loop) +if /i [%1] == [arm64] ( set __BuildArch=arm64&&shift&goto Arg_Loop) if /i [%1] == [portable] ( set __PortableBuild=1&&shift&goto Arg_Loop) if /i [%1] == [rid] ( set __TargetRid=%2&&shift&&shift&goto Arg_Loop) @@ -48,53 +47,13 @@ if /i [%1] == [ninja] (set __Ninja=1) if /i [%1] == [runtimeflavor] (set __RuntimeFlavor=%2&&shift&&shift&goto Arg_Loop) if /i [%1] == [runtimeconfiguration] (set __RuntimeConfiguration=%2&&shift&&shift&goto Arg_Loop) - shift goto :Arg_Loop -:ToolsVersion - -if defined VisualStudioVersion goto :RunVCVars - -set _VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -if exist %_VSWHERE% ( - for /f "usebackq tokens=*" %%i in (`%_VSWHERE% -latest -prerelease -property installationPath`) do set _VSCOMNTOOLS=%%i\Common7\Tools -) -if not exist "%_VSCOMNTOOLS%" set _VSCOMNTOOLS=%VS140COMNTOOLS% -if not exist "%_VSCOMNTOOLS%" goto :MissingVersion - -set VSCMD_START_DIR="%~dp0" -call "%_VSCOMNTOOLS%\VsDevCmd.bat" - -:RunVCVars -if "%VisualStudioVersion%"=="16.0" ( - goto :VS2019 -) else if "%VisualStudioVersion%"=="15.0" ( - goto :VS2017 -) - -:MissingVersion -:: Can't find required VS install -echo Error: Visual Studio 2019 required -echo Please see https://github.com/dotnet/runtime/blob/main/docs/workflow/requirements/windows-requirements.md for build requirements. -exit /b 1 +:InitVSEnv +call "%__engNativeDir%\init-vs-env.cmd" %__BuildArch% +if NOT [%errorlevel%] == [0] goto :Failure -:VS2019 -:: Setup vars for VS2019 -set __PlatformToolset=v142 -set __VSVersion=vs2019 -:: Set the environment for the native build -call "%VS160COMNTOOLS%..\..\VC\Auxiliary\Build\vcvarsall.bat" %__VCBuildArch% -goto :SetupDirs - -:VS2017 -:: Setup vars for VS2017 -set __PlatformToolset=v141 -set __VSVersion=vs2017 -:: Set the environment for the native build -call "%VS150COMNTOOLS%..\..\VC\Auxiliary\Build\vcvarsall.bat" %__VCBuildArch% - -:SetupDirs if [%__rootDir%] == [] ( echo Root directory must be provided via the rootDir parameter. exit /b 1 @@ -126,22 +85,6 @@ if exist "%__IntermediatesDir%" rd /s /q "%__IntermediatesDir%" :CreateIntermediates if not exist "%__IntermediatesDir%" md "%__IntermediatesDir%" -if exist "%VSINSTALLDIR%DIA SDK" goto FindCMake -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 - -:FindCMake -if defined CMakePath goto GenVSSolution -:: Find CMake - -:: Eval the output from set-cmake-path.ps1 -for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& ""%__engNativeDir%\set-cmake-path.ps1"""') do %%a - -:GenVSSolution if /i "%__BuildArch%" == "x64" (set cm_BaseRid=win7) if /i "%__BuildArch%" == "x86" (set cm_BaseRid=win7) if /i "%__BuildArch%" == "arm" (set cm_BaseRid=win8) diff --git a/src/tests/build.cmd b/src/tests/build.cmd index 4e33642..3366e25 100644 --- a/src/tests/build.cmd +++ b/src/tests/build.cmd @@ -15,17 +15,11 @@ for %%i in ("%__RepoRootDir%") do SET "__RepoRootDir=%%~fi" set "__TestDir=%__RepoRootDir%\src\tests" -call %__RepoRootDir%\src\coreclr\setup_vs_tools.cmd +call %__RepoRootDir%\eng\native\init-vs-env.cmd if NOT '%ERRORLEVEL%' == '0' exit /b 1 -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 +if defined VCINSTALLDIR ( + set "__VCToolsRoot=%VCINSTALLDIR%Auxiliary\Build" ) :: Set the default arguments for build @@ -219,12 +213,6 @@ echo %__MsgPrefix%Using environment: "%__VCToolsRoot%\vcvarsall.bat" %__VCBuildA call "%__VCToolsRoot%\vcvarsall.bat" %__VCBuildArch% @if defined _echo @echo on -if not defined VSINSTALLDIR ( - echo %__ErrMsgPrefix%%__MsgPrefix%Error: VSINSTALLDIR variable not defined. - exit /b 1 -) -if not exist "%VSINSTALLDIR%DIA SDK" goto NoDIA - set __ExtraCmakeArgs="-DCMAKE_SYSTEM_VERSION=10.0" call "%__RepoRootDir%\eng\native\gen-buildsys.cmd" "%__ProjectFilesDir%" "%__NativeTestIntermediatesDir%" %__VSVersion% %__BuildArch% !__ExtraCmakeArgs! @@ -307,10 +295,6 @@ if defined __SkipManaged goto SkipManagedBuild echo %__MsgPrefix%Starting the Managed Tests Build -if not defined VSINSTALLDIR ( - echo %__ErrMsgPrefix%%__MsgPrefix%Error: build.cmd should be run from a Visual Studio Command Prompt. Please see https://github.com/dotnet/runtime/tree/main/docs/workflow for build instructions. - exit /b 1 -) set __AppendToLog=false set __BuildLogRootName=Tests_Managed set __BuildLog=%__LogsDir%\%__BuildLogRootName%_%__TargetOS%__%__BuildArch%__%__BuildType%.log @@ -571,14 +555,6 @@ echo allTargets: Build managed tests for all target platforms. echo -verbose: enables detailed file logging for the msbuild tasks into the msbuild log file. 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 - :PrecompileFX set "__CrossgenOutputDir=%__TestIntermediatesDir%\crossgen.out"