@echo off setlocal EnableDelayedExpansion :: Set the default arguments for build set __BuildArch=x64 set __BuildType=Debug set __BuildOS=Windows_NT :: Default to highest Visual Studio version available set __VSVersion=vs2015 if defined VS120COMNTOOLS set __VSVersion=vs2013 if defined VS140COMNTOOLS set __VSVersion=vs2015 :: Set the various build properties here so that CMake and MSBuild can pick them up set "__ProjectDir=%~dp0" :: remove trailing slash if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%" set "__ProjectFilesDir=%__ProjectDir%" set "__SourceDir=%__ProjectDir%\src" set "__PackagesDir=%__ProjectDir%\packages" set "__RootBinDir=%__ProjectDir%\bin" set "__LogsDir=%__RootBinDir%\Logs" set __MSBCleanBuildArgs= set __SkipTestBuild= set __DoCrossgen= :Arg_Loop if "%1" == "" goto ArgsDone if /i "%1" == "/?" goto Usage if /i "%1" == "x64" (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" == "arm64" (set __BuildArch=arm64&&shift&goto Arg_Loop) if /i "%1" == "debug" (set __BuildType=Debug&shift&goto Arg_Loop) if /i "%1" == "release" (set __BuildType=Release&shift&goto Arg_Loop) if /i "%1" == "clean" (set __CleanBuild=1&shift&goto Arg_Loop) if /i "%1" == "freebsdmscorlib" (set __MscorlibOnly=1&set __BuildOS=FreeBSD&shift&goto Arg_Loop) if /i "%1" == "linuxmscorlib" (set __MscorlibOnly=1&set __BuildOS=Linux&shift&goto Arg_Loop) if /i "%1" == "osxmscorlib" (set __MscorlibOnly=1&set __BuildOS=OSX&shift&goto Arg_Loop) if /i "%1" == "windowsmscorlib" (set __MscorlibOnly=1&set __BuildOS=Windows_NT&shift&goto Arg_Loop) if /i "%1" == "vs2013" (set __VSVersion=%1&shift&goto Arg_Loop) if /i "%1" == "vs2015" (set __VSVersion=%1&shift&goto Arg_Loop) if /i "%1" == "skiptestbuild" (set __SkipTestBuild=1&shift&goto Arg_Loop) if /i "%1" == "docrossgen" (set __DoCrossgen=1&shift&goto Arg_Loop) if /i "%1" == "/toolset_dir" (set __ToolsetDir=%2&shift&shift&goto Arg_Loop) echo Invalid commandline argument: %1 goto Usage :ArgsDone echo Commencing CoreCLR Repo build echo. :: Set the remaining variables based upon the determined build configuration set "__BinDir=%__RootBinDir%\Product\%__BuildOS%.%__BuildArch%.%__BuildType%" set "__IntermediatesDir=%__RootBinDir%\obj\%__BuildOS%.%__BuildArch%.%__BuildType%" set "__PackagesBinDir=%__BinDir%\.nuget" set "__TestBinDir=%__RootBinDir%\tests\%__BuildOS%.%__BuildArch%.%__BuildType%" set "__TestIntermediatesDir=%__RootBinDir%\tests\obj\%__BuildOS%.%__BuildArch%.%__BuildType%" :: Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash set "__CMakeBinDir=%__BinDir%" set "__CMakeBinDir=%__CMakeBinDir:\=/%" :: Configure environment if we are doing a clean build. if not defined __CleanBuild goto MakeDirs echo Doing a clean build echo. :: MSBuild projects would need a rebuild set __MSBCleanBuildArgs=/t:rebuild :: Cleanup the previous output for the selected configuration if exist "%__BinDir%" rd /s /q "%__BinDir%" if exist "%__IntermediatesDir%" rd /s /q "%__IntermediatesDir%" if exist "%__TestBinDir%" rd /s /q "%__TestBinDir%" if exist "%__TestIntermediatesDir%" rd /s /q "%__TestIntermediatesDir%" if exist "%__LogsDir%" del /f /q "%__LogsDir%\*_%__BuildOS%__%__BuildArch%__%__BuildType%.*" :MakeDirs if not exist "%__BinDir%" md "%__BinDir%" if not exist "%__IntermediatesDir%" md "%__IntermediatesDir%" if not exist "%__LogsDir%" md "%__LogsDir%" :: CMake isn't a requirement when building mscorlib only if defined __MscorlibOnly goto CheckVS :CheckPrereqs :: Check prerequisites echo Checking pre-requisites... echo. :: Eval the output from probe-win1.ps1 for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy RemoteSigned "& ""%__SourceDir%\pal\tools\probe-win.ps1"""') do %%a goto CheckVS :CheckVS set __VSProductVersion= if /i "%__VSVersion%" == "vs2013" set __VSProductVersion=120 if /i "%__VSVersion%" == "vs2015" set __VSProductVersion=140 :: Check presence of VS if defined VS%__VSProductVersion%COMNTOOLS goto CheckVSExistence echo Visual Studio 2013+ (Community is free) is a pre-requisite to build this repository. echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites exit /b 1 :CheckVSExistence :: Does VS 2013 or VS 2015 really exist? if exist "!VS%__VSProductVersion%COMNTOOLS!\..\IDE\devenv.exe" goto CheckMSBuild echo Visual Studio 2013+ (Community is free) is a pre-requisite to build this repository. echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites exit /b 1 :CheckMSBuild :: Note: We've disabled node reuse because it causes file locking issues. :: The issue is that we extend the build with our own targets which :: means that that rebuilding cannot successfully delete the task :: assembly. if /i "%__VSVersion%" =="vs2015" goto MSBuild14 set _msbuildexe="%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" if not exist %_msbuildexe% set _msbuildexe="%ProgramFiles%\MSBuild\12.0\Bin\MSBuild.exe" if not exist %_msbuildexe% set _msbuildexe="%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" goto :CheckMSBuild14 :MSBuild14 set _msbuildexe="%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" set UseRoslynCompiler=true :CheckMSBuild14 if not exist %_msbuildexe% set _msbuildexe="%ProgramFiles%\MSBuild\14.0\Bin\MSBuild.exe" if not exist %_msbuildexe% echo Error: Could not find MSBuild.exe. Please see https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md for build instructions. && exit /b 1 :: All set to commence the build setlocal EnableDelayedExpansion if defined __MscorlibOnly goto PerformMScorlibBuild echo Commencing build of native components for %__BuildOS%.%__BuildArch%.%__BuildType% echo. rem arm64 builds currently use private toolset which has not been released yet if /i "%__BuildArch%" == "arm64" ( REM TODO, remove once the toolset is open. if not "%__BuildOS%" == "Windows_NT" goto GenVSSolution if /i "%__ToolsetDir%" == "" ( echo "A toolset directory is required for the Arm64 Windows build." exit /b 1 ) ) REM TODO, remove once the toolset is open. if /i "%__BuildArch%" == "arm64" set PATH=%PATH%;%__ToolsetDir%\cpp\bin if /i "%__BuildArch%" == "arm64" set LIB=%__ToolsetDir%\OS\lib if /i "%__BuildArch%" == "arm64" set INCLUDE=%__ToolsetDir%\cpp\inc;%__ToolsetDir%\OS\inc\Windows;%__ToolsetDir%\OS\inc\Windows\crt;%__ToolsetDir%\cpp\inc\vc;%__ToolsetDir%\OS\inc\win8; if /i "%__BuildArch%" == "arm64" goto GenVSSolution :: Set the environment for the native build set __VCBuildArch=x86_amd64 if /i "%__BuildArch%" == "x86" (set __VCBuildArch=x86) call "!VS%__VSProductVersion%COMNTOOLS!\..\..\VC\vcvarsall.bat" %__VCBuildArch% if exist "%VSINSTALLDIR%DIA SDK" goto GenVSSolution echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^ This is due to a bug in the Visual Studio installer. It does not install DIA SDK at "%VSINSTALLDIR%" but rather ^ at VS install location of previous version. Workaround is to copy DIA SDK folder from VS install location ^ of previous version to "%VSINSTALLDIR%" and then resume build. :: DIA SDK not included in Express editions echo Visual Studio 2013 Express does not include the DIA SDK. ^ You need Visual Studio 2013+ (Community is free). echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites exit /b 1 :GenVSSolution :: Regenerate the VS solution pushd "%__IntermediatesDir%" call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" "%__ProjectDir%" %__VSVersion% %__BuildArch% popd :BuildComponents if exist "%__IntermediatesDir%\install.vcxproj" goto BuildCoreCLR echo Failed to generate native component build project! exit /b 1 REM Build CoreCLR :BuildCoreCLR set "__CoreCLRBuildLog=%__LogsDir%\CoreCLR_%__BuildOS%__%__BuildArch%__%__BuildType%.log" if /i "%__BuildArch%" == "arm64" ( REM TODO, remove once we have msbuild support for this platform. %_msbuildexe% "%__IntermediatesDir%\install.vcxproj" %__MSBCleanBuildArgs% /nologo /maxcpucount /nodeReuse:false /p:Configuration=%__BuildType% /p:UseEnv=true /fileloggerparameters:Verbosity=normal;LogFile="%__CoreCLRBuildLog%" ) else ( %_msbuildexe% "%__IntermediatesDir%\install.vcxproj" %__MSBCleanBuildArgs% /nologo /maxcpucount /nodeReuse:false /p:Configuration=%__BuildType% /p:Platform=%__BuildArch% /fileloggerparameters:Verbosity=normal;LogFile="%__CoreCLRBuildLog%" ) IF NOT ERRORLEVEL 1 goto PerformMScorlibBuild echo Native component build failed. Refer !__CoreCLRBuildLog! for details. exit /b 1 :PerformMScorlibBuild REM endlocal to rid us of environment changes from vcvarsall.bat endlocal REM setlocal to prepare for vsdevcmd.bat setlocal set __AdditionalMSBuildArgs= rem Explicitly set Platform causes conflicts in mscorlib project files. Clear it to allow building from VS x64 Native Tools Command Prompt set Platform= if defined __MscorlibOnly set __AdditionalMSBuildArgs=/p:BuildNugetPackage=false if /i "%__BuildArch%" =="arm64" set __AdditionalMSBuildArgs=/p:BuildNugetPackage=false :: Set the environment for the managed build call "!VS%__VSProductVersion%COMNTOOLS!\VsDevCmd.bat" echo Commencing build of mscorlib for %__BuildOS%.%__BuildArch%.%__BuildType% echo. set "__MScorlibBuildLog=%__LogsDir%\MScorlib_%__BuildOS%__%__BuildArch%__%__BuildType%.log" %_msbuildexe% "%__ProjectFilesDir%\build.proj" %__MSBCleanBuildArgs% /nologo /maxcpucount /verbosity:minimal /nodeReuse:false /fileloggerparameters:Verbosity=normal;LogFile="%__MScorlibBuildLog%" %__AdditionalMSBuildArgs% IF NOT ERRORLEVEL 1 ( if defined __MscorlibOnly exit /b 0 goto CrossGenMscorlib ) echo MScorlib build failed. Refer !__MScorlibBuildLog! for details. exit /b 1 :CrossGenMscorlib if /i "%__BuildArch%" == "x86" ( if not defined __DoCrossgen ( echo Skipping Crossgen goto PerformTestBuild ) ) if /i "%__BuildArch%" == "arm64" ( if not defined __DoCrossgen ( echo Skipping Crossgen goto PerformTestBuild ) ) echo Generating native image of mscorlib for %__BuildOS%.%__BuildArch%.%__BuildType% echo. set "__CrossGenMScorlibLog=%__LogsDir%\CrossgenMScorlib_%__BuildOS%__%__BuildArch%__%__BuildType%.log" "%__BinDir%\crossgen.exe" "%__BinDir%\mscorlib.dll" > "%__CrossGenMScorlibLog%" 2>&1 IF NOT ERRORLEVEL 1 ( goto PerformTestBuild ) echo CrossGen mscorlib failed. Refer !__CrossGenMScorlibLog! for details. exit /b 1 :PerformTestBuild if defined __SkipTestBuild ( echo Skipping test build goto SuccessfulBuild ) echo. echo Commencing build of tests for %__BuildOS%.%__BuildArch%.%__BuildType% echo. call %__ProjectDir%\tests\buildtest.cmd IF NOT ERRORLEVEL 1 goto SuccessfulBuild echo Test binaries build failed. Refer !__TestManagedBuildLog! for details. exit /b 1 :SuccessfulBuild ::Build complete echo Repo successfully built. echo. echo Product binaries are available at !__BinDir! if not defined __SkipTestBuild ( echo Test binaries are available at !__TestBinDir! ) exit /b 0 :Usage echo. echo Usage: echo %0 BuildArch BuildType [clean] [vsversion] where: echo. echo BuildArch can be: x64, x86, arm64 echo BuildType can be: Debug, Release echo Clean - optional argument to force a clean build. echo VSVersion - optional argument to use VS2013 or VS2015 (default VS2015) echo windowsmscorlib - Build mscorlib for Windows echo linuxmscorlib - Build mscorlib for Linux echo osxmscorlib - Build mscorlib for OS X echo skiptestbuild - Skip building tests echo toolset_dir - toolset directory -- Arm64 use only. exit /b 1