Merge pull request #3039 from dotnet-bot/from-tfs
[platform/upstream/coreclr.git] / build.cmd
1 @if not defined __echo @echo off
2 setlocal EnableDelayedExpansion EnableExtensions
3
4 set __ThisScriptShort=%0
5 set __ThisScriptFull="%~f0"
6
7 :: Note that the msbuild project files (specifically, dir.proj) will use the following variables, if set:
8 ::      __BuildArch         -- default: x64
9 ::      __BuildType         -- default: Debug
10 ::      __BuildOS           -- default: Windows_NT
11 ::      __ProjectDir        -- default: directory of the dir.props file
12 ::      __SourceDir         -- default: %__ProjectDir%\src\
13 ::      __PackagesDir       -- default: %__ProjectDir%\packages\
14 ::      __RootBinDir        -- default: %__ProjectDir%\bin\
15 ::      __BinDir            -- default: %__RootBinDir%\%__BuildOS%.%__BuildArch.%__BuildType%\
16 ::      __IntermediatesDir
17 ::      __PackagesBinDir    -- default: %__BinDir%\.nuget
18 ::      __TestWorkingDir    -- default: %__RootBinDir%\tests\%__BuildOS%.%__BuildArch.%__BuildType%\
19 ::
20 :: Thus, these variables are not simply internal to this script!
21 ::
22 :: The UseRoslynCompiler variable is used by src\mscorlib\GenerateCompilerResponseFile.targets.
23
24 :: Set the default arguments for build
25 set __BuildArch=x64
26 set __BuildType=Debug
27 set __BuildOS=Windows_NT
28
29 :: Default to highest Visual Studio version available
30 set __VSVersion=vs2015
31
32 if defined VS140COMNTOOLS set __VSVersion=vs2015
33
34 :: Define a prefix for most output progress messages that come from this script. That makes
35 :: it easier to see where these are coming from. Note that there is a trailing space here.
36 set __MsgPrefix=BUILD: 
37
38 :: Set the various build properties here so that CMake and MSBuild can pick them up
39 set "__ProjectDir=%~dp0"
40 :: remove trailing slash
41 if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%"
42 set "__ProjectFilesDir=%__ProjectDir%"
43 set "__SourceDir=%__ProjectDir%\src"
44 set "__PackagesDir=%__ProjectDir%\packages"
45 set "__RootBinDir=%__ProjectDir%\bin"
46 set "__LogsDir=%__RootBinDir%\Logs"
47
48 set __CleanBuild=
49 set __MscorlibOnly=
50 set __ConfigureOnly=
51 set __SkipConfigure=
52 set __SkipMscorlibBuild=
53 set __SkipNativeBuild=
54 set __SkipTestBuild=
55 set __DoCrossgen=
56 set __BuildSequential=
57 set __msbuildCleanBuildArgs=
58 set __msbuildExtraArgs=
59
60 set __BuildAll=
61
62 set __BuildArchX64=0
63 set __BuildArchX86=0
64 set __BuildArchArm=0
65 set __BuildArchArm64=0
66
67 set __BuildTypeDebug=0
68 set __BuildTypeChecked=0
69 set __BuildTypeRelease=0
70
71 REM __PassThroughArgs is a set of things that will be passed through to nested calls to build.cmd
72 REM when using "all".
73 set __PassThroughArgs=
74
75 :Arg_Loop
76 if "%1" == "" goto ArgsDone
77
78 if /i "%1" == "/?"    goto Usage
79 if /i "%1" == "-?"    goto Usage
80 if /i "%1" == "/h"    goto Usage
81 if /i "%1" == "-h"    goto Usage
82 if /i "%1" == "/help" goto Usage
83 if /i "%1" == "-help" goto Usage
84
85 if /i "%1" == "all"                 (set __BuildAll=1&shift&goto Arg_Loop)
86
87 if /i "%1" == "x64"                 (set __BuildArchX64=1&shift&goto Arg_Loop)
88 if /i "%1" == "x86"                 (set __BuildArchX86=1&shift&goto Arg_Loop)
89 if /i "%1" == "arm"                 (set __BuildArchArm=1&shift&goto Arg_Loop)
90 if /i "%1" == "arm64"               (set __BuildArchArm64=1&shift&goto Arg_Loop)
91
92 if /i "%1" == "debug"               (set __BuildTypeDebug=1&shift&goto Arg_Loop)
93 if /i "%1" == "checked"             (set __BuildTypeChecked=1&shift&goto Arg_Loop)
94 if /i "%1" == "release"             (set __BuildTypeRelease=1&shift&goto Arg_Loop)
95
96 REM All arguments after this point will be passed through directly to build.cmd on nested invocations
97 REM using the "all" argument, and must be added to the __PassThroughArgs variable.
98 set __PassThroughArgs=%__PassThroughArgs% %1
99
100 if /i "%1" == "clean"               (set __CleanBuild=1&shift&goto Arg_Loop)
101
102 if /i "%1" == "freebsdmscorlib"     (set __MscorlibOnly=1&set __BuildOS=FreeBSD&shift&goto Arg_Loop)
103 if /i "%1" == "linuxmscorlib"       (set __MscorlibOnly=1&set __BuildOS=Linux&shift&goto Arg_Loop)
104 if /i "%1" == "osxmscorlib"         (set __MscorlibOnly=1&set __BuildOS=OSX&shift&goto Arg_Loop)
105 if /i "%1" == "windowsmscorlib"     (set __MscorlibOnly=1&set __BuildOS=Windows_NT&shift&goto Arg_Loop)
106
107 if /i "%1" == "vs2015"              (set __VSVersion=%1&shift&goto Arg_Loop)
108 if /i "%1" == "configureonly"       (set __ConfigureOnly=1&set __SkipMscorlibBuild=1&set __SkipTestBuild=1&shift&goto Arg_Loop)
109 if /i "%1" == "skipconfigure"       (set __SkipConfigure=1&shift&goto Arg_Loop)
110 if /i "%1" == "skipmscorlib"        (set __SkipMscorlibBuild=1&shift&goto Arg_Loop)
111 if /i "%1" == "skipnative"          (set __SkipNativeBuild=1&shift&goto Arg_Loop)
112 if /i "%1" == "skiptests"           (set __SkipTestBuild=1&shift&goto Arg_Loop)
113 if /i "%1" == "docrossgen"          (set __DoCrossgen=1&shift&goto Arg_Loop)
114 if /i "%1" == "sequential"          (set __BuildSequential=1&shift&goto Arg_Loop)
115 if /i "%1" == "priority"            (set __TestPriority=%2&set __PassThroughArgs=%__PassThroughArgs% %2&shift&shift&goto Arg_Loop)
116
117 @REM For backwards compatibility, continue accepting "skiptestbuild", which was the original name of the option.
118 if /i "%1" == "skiptestbuild"       (set __SkipTestBuild=1&shift&goto Arg_Loop)
119
120 @REM It was initially /toolset_dir. Not sure why, since it doesn't match the other usage.
121 if /i "%1" == "/toolset_dir"        (set __ToolsetDir=%2&set __PassThroughArgs=%__PassThroughArgs% %2&shift&shift&goto Arg_Loop)
122 if /i "%1" == "toolset_dir"         (set __ToolsetDir=%2&set __PassThroughArgs=%__PassThroughArgs% %2&shift&shift&goto Arg_Loop)
123
124 if /i not "%1" == "msbuildargs" goto SkipMsbuildArgs
125 :: All the rest of the args will be collected and passed directly to msbuild.
126 :CollectMsbuildArgs
127 shift
128 if "%1"=="" goto ArgsDone
129 set __msbuildExtraArgs=%__msbuildExtraArgs% %1
130 set __PassThroughArgs=%__PassThroughArgs% %1
131 goto CollectMsbuildArgs
132 :SkipMsbuildArgs
133
134 echo Invalid command-line argument: %1
135 goto Usage
136
137 :ArgsDone
138
139 if defined __ConfigureOnly if defined __SkipConfigure (
140     echo "Error: option 'configureonly' is incompatible with 'skipconfigure'
141     goto Usage
142 )
143
144 if defined __SkipMscorlibBuild if defined __MscorlibOnly (
145     echo Error: option 'skipmscorlib' is incompatible with 'freebsdmscorlib', 'linuxmscorlib', 'osxmscorlib', and 'windowsmscorlib'.
146     goto Usage
147 )
148
149 if defined __BuildAll goto BuildAll
150
151 set /A __TotalSpecifiedBuildArch=__BuildArchX64 + __BuildArchX86 + __BuildArchArm + __BuildArchArm64
152 if %__TotalSpecifiedBuildArch% GTR 1 (
153     echo Error: more than one build architecture specified, but "all" not specified.
154     goto Usage
155 )
156
157 if %__BuildArchX64%==1      set __BuildArch=x64
158 if %__BuildArchX86%==1      set __BuildArch=x86
159 if %__BuildArchArm%==1      set __BuildArch=arm
160 if %__BuildArchArm64%==1    set __BuildArch=arm64
161
162 set /A __TotalSpecifiedBuildType=__BuildTypeDebug + __BuildTypeChecked + __BuildTypeRelease
163 if %__TotalSpecifiedBuildType% GTR 1 (
164     echo Error: more than one build type specified, but "all" not specified.
165     goto Usage
166 )
167
168 if %__BuildTypeDebug%==1    set __BuildType=Debug
169 if %__BuildTypeChecked%==1  set __BuildType=Checked
170 if %__BuildTypeRelease%==1  set __BuildType=Release
171
172 echo %__MsgPrefix%Commencing CoreCLR Repo build
173
174 :: Set the remaining variables based upon the determined build configuration
175 set "__BinDir=%__RootBinDir%\Product\%__BuildOS%.%__BuildArch%.%__BuildType%"
176 set "__IntermediatesDir=%__RootBinDir%\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
177 set "__PackagesBinDir=%__BinDir%\.nuget"
178 set "__TestBinDir=%__RootBinDir%\tests\%__BuildOS%.%__BuildArch%.%__BuildType%"
179 set "__TestIntermediatesDir=%__RootBinDir%\tests\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
180
181 :: Use this variable to locate dynamically generated files; the actual location though will be different.
182 set "__GeneratedIntermediatesDir=%__IntermediatesDir%\Generated_latest"
183
184 :: Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash
185 set "__CMakeBinDir=%__BinDir%"
186 set "__CMakeBinDir=%__CMakeBinDir:\=/%"
187
188 :: Configure environment if we are doing a clean build.
189 if not defined __CleanBuild goto SkipCleanBuild
190 echo %__MsgPrefix%Doing a clean build
191
192 :: MSBuild projects would need a rebuild
193 set __msbuildCleanBuildArgs=/t:rebuild
194
195 :: Cleanup the previous output for the selected configuration
196 if exist "%__BinDir%"               rd /s /q "%__BinDir%"
197 if exist "%__IntermediatesDir%"     rd /s /q "%__IntermediatesDir%"
198 if exist "%__TestBinDir%"           rd /s /q "%__TestBinDir%"
199 if exist "%__TestIntermediatesDir%" rd /s /q "%__TestIntermediatesDir%"
200 if exist "%__LogsDir%"              del /f /q "%__LogsDir%\*_%__BuildOS%__%__BuildArch%__%__BuildType%.*"
201
202 :SkipCleanBuild
203
204 if not exist "%__BinDir%"           md "%__BinDir%"
205 if not exist "%__IntermediatesDir%" md "%__IntermediatesDir%"
206 if not exist "%__LogsDir%"          md "%__LogsDir%"
207
208 :: CMake isn't a requirement when building mscorlib only
209 if defined __MscorlibOnly goto CheckVS
210
211 echo %__MsgPrefix%Checking prerequisites
212
213 :: Eval the output from probe-win1.ps1
214 for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy RemoteSigned "& ""%__SourceDir%\pal\tools\probe-win.ps1"""') do %%a
215
216 :CheckVS
217
218 set __VSProductVersion=
219 if /i "%__VSVersion%" == "vs2015" set __VSProductVersion=140
220
221 :: Check presence of VS
222 if not defined VS%__VSProductVersion%COMNTOOLS goto NoVS
223
224 set __VSToolsRoot=!VS%__VSProductVersion%COMNTOOLS!
225 if %__VSToolsRoot:~-1%==\ set "__VSToolsRoot=%__VSToolsRoot:~0,-1%"
226
227 :: Does VS really exist?
228 if not exist "%__VSToolsRoot%\..\IDE\devenv.exe"      goto NoVS
229 if not exist "%__VSToolsRoot%\..\..\VC\vcvarsall.bat" goto NoVS
230 if not exist "%__VSToolsRoot%\VsDevCmd.bat"           goto NoVS
231
232 :MSBuild14
233 set _msbuildexe="%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe"
234 set UseRoslynCompiler=true
235 :CheckMSBuild14
236 if not exist %_msbuildexe% set _msbuildexe="%ProgramFiles%\MSBuild\14.0\Bin\MSBuild.exe"
237 if not exist %_msbuildexe% echo %__MsgPrefix%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
238
239 :: Note: We've disabled node reuse because it causes file locking issues.
240 ::       The issue is that we extend the build with our own targets which
241 ::       means that that rebuilding cannot successfully delete the task
242 ::       assembly. 
243 set __msbuildCommonArgs=/nologo /nodeReuse:false %__msbuildCleanBuildArgs% %__msbuildExtraArgs%
244
245 if not defined __BuildSequential (
246     set __msbuildCommonArgs=%__msbuildCommonArgs% /maxcpucount
247 )
248
249 REM =========================================================================================
250 REM ===
251 REM === Restore Build Tools
252 REM ===
253 REM =========================================================================================
254 call %~dp0init-tools.cmd 
255
256 REM =========================================================================================
257 REM ===
258 REM === Start the build steps
259 REM ===
260 REM =========================================================================================
261
262 if defined __MscorlibOnly goto PerformMScorlibBuild
263
264 if defined __SkipNativeBuild (
265     echo %__MsgPrefix%Skipping native components build
266     goto SkipNativeBuild
267 )
268
269 echo %__MsgPrefix%Commencing build of native components for %__BuildOS%.%__BuildArch%.%__BuildType%
270
271 REM Use setlocal to restrict environment changes form vcvarsall.bat and more to just this native components build section.
272 setlocal EnableDelayedExpansion EnableExtensions
273
274 if /i not "%__BuildArch%" == "arm64" goto NotArm64Build
275
276 rem arm64 builds currently use private toolset which has not been released yet
277 REM TODO, remove once the toolset is open.
278
279 if /i "%__ToolsetDir%" == "" (
280     echo %__MsgPrefix%Error: A toolset directory is required for the Arm64 Windows build. Use the toolset_dir argument.
281     exit /b 1
282 )
283
284 set PATH=%PATH%;%__ToolsetDir%\cpp\bin
285 set LIB=%__ToolsetDir%\OS\lib;%__ToolsetDir%\cpp\lib
286 set INCLUDE=^
287 %__ToolsetDir%\cpp\inc;^
288 %__ToolsetDir%\OS\inc\Windows;^
289 %__ToolsetDir%\OS\inc\Windows\crt;^
290 %__ToolsetDir%\cpp\inc\vc;^
291 %__ToolsetDir%\OS\inc\win8
292
293 goto GenVSSolution
294
295 :NotArm64Build
296
297 :: Set the environment for the native build
298 set __VCBuildArch=x86_amd64
299 if /i "%__BuildArch%" == "x86" (set __VCBuildArch=x86)
300 echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\..\..\VC\vcvarsall.bat" %__VCBuildArch%
301 call                                 "%__VSToolsRoot%\..\..\VC\vcvarsall.bat" %__VCBuildArch%
302 @if defined __echo @echo on
303
304 if not defined VSINSTALLDIR (
305     echo %__MsgPrefix%Error: VSINSTALLDIR variable not defined.
306     exit /b 1
307 )
308 if not exist "%VSINSTALLDIR%DIA SDK" goto NoDIA
309
310 :GenVSSolution
311
312 if defined __SkipConfigure goto SkipConfigure
313
314 echo %__MsgPrefix%Regenerating the Visual Studio solution
315
316 pushd "%__IntermediatesDir%"
317 call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" "%__ProjectDir%" %__VSVersion% %__BuildArch%
318 @if defined __echo @echo on
319 popd
320
321 :SkipConfigure
322
323 if not exist "%__IntermediatesDir%\install.vcxproj" (
324     echo %__MsgPrefix%Error: failed to generate native component build project!
325     exit /b 1
326 )
327
328 REM =========================================================================================
329 REM ===
330 REM === Build the CLR VM
331 REM ===
332 REM =========================================================================================
333
334 if defined __ConfigureOnly goto SkipNativeBuild
335
336 echo %__MsgPrefix%Invoking msbuild
337
338 set "__BuildLog=%__LogsDir%\CoreCLR_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
339 set "__BuildWrn=%__LogsDir%\CoreCLR_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
340 set "__BuildErr=%__LogsDir%\CoreCLR_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
341 set __msbuildLogArgs=^
342 /fileloggerparameters:Verbosity=normal;LogFile="%__BuildLog%" ^
343 /fileloggerparameters1:WarningsOnly;LogFile="%__BuildWrn%" ^
344 /fileloggerparameters2:ErrorsOnly;LogFile="%__BuildErr%" ^
345 /consoleloggerparameters:Summary ^
346 /verbosity:minimal
347
348 set __msbuildArgs="%__IntermediatesDir%\install.vcxproj" %__msbuildCommonArgs% %__msbuildLogArgs% /p:Configuration=%__BuildType%
349
350 if /i "%__BuildArch%" == "arm64" (  
351     REM TODO, remove once we have msbuild support for this platform.
352     set __msbuildArgs=%__msbuildArgs% /p:UseEnv=true
353 ) else (
354     set __msbuildArgs=%__msbuildArgs% /p:Platform=%__BuildArch%
355 )
356
357 %_msbuildexe% %__msbuildArgs%
358 if errorlevel 1 (
359     echo %__MsgPrefix%Error: native component build failed. Refer to the build log files for details:
360     echo     %__BuildLog%
361     echo     %__BuildWrn%
362     echo     %__BuildErr%
363     exit /b 1
364 )
365
366 REM endlocal to rid us of environment changes from vcvarsall.bat
367 endlocal
368
369 :SkipNativeBuild
370
371 REM =========================================================================================
372 REM ===
373 REM === Mscorlib build section.
374 REM ===
375 REM =========================================================================================
376
377 :PerformMScorlibBuild
378 if defined __SkipMscorlibBuild (
379     echo %__MsgPrefix%Skipping Mscorlib build
380     goto SkipMscorlibBuild
381 )
382
383 echo %__MsgPrefix%Commencing build of mscorlib for %__BuildOS%.%__BuildArch%.%__BuildType%
384
385 REM setlocal to prepare for vsdevcmd.bat
386 setlocal EnableDelayedExpansion EnableExtensions
387
388 rem Explicitly set Platform causes conflicts in mscorlib project files. Clear it to allow building from VS x64 Native Tools Command Prompt
389 set Platform=
390
391 :: Set the environment for the managed build
392 echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\VsDevCmd.bat"
393 call                                 "%__VSToolsRoot%\VsDevCmd.bat"
394
395 set "__BuildLog=%__LogsDir%\MScorlib_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
396 set "__BuildWrn=%__LogsDir%\MScorlib_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
397 set "__BuildErr=%__LogsDir%\MScorlib_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
398 set __msbuildLogArgs=^
399 /fileloggerparameters:Verbosity=normal;LogFile="%__BuildLog%" ^
400 /fileloggerparameters1:WarningsOnly;LogFile="%__BuildWrn%" ^
401 /fileloggerparameters2:ErrorsOnly;LogFile="%__BuildErr%" ^
402 /consoleloggerparameters:Summary ^
403 /verbosity:minimal
404
405 set __msbuildArgs="%__ProjectFilesDir%\build.proj" %__msbuildCommonArgs% %__msbuildLogArgs%
406
407 set __BuildNugetPackage=true
408 if defined __MscorlibOnly       set __BuildNugetPackage=false
409 if /i "%__BuildArch%" =="arm64" set __BuildNugetPackage=false
410 if %__BuildNugetPackage%==false set __msbuildArgs=%__msbuildArgs% /p:BuildNugetPackage=false
411
412 %_msbuildexe% %__msbuildArgs%
413 if errorlevel 1 (
414     echo %__MsgPrefix%Error: MScorlib build failed. Refer to the build log files for details:
415     echo     %__BuildLog%
416     echo     %__BuildWrn%
417     echo     %__BuildErr%
418     exit /b 1
419 )
420
421 if defined __MscorlibOnly (
422     echo %__MsgPrefix%Mscorlib successfully built.
423     exit /b 0
424 )
425
426 REM Consider doing crossgen build of mscorlib.
427
428 if /i "%__BuildArch%" == "x86" (
429     if not defined __DoCrossgen (
430         echo %__MsgPrefix%Skipping Crossgen
431         goto SkipCrossGenBuild
432     )
433 )
434
435 if /i "%__BuildArch%" == "arm64" (
436     if not defined __DoCrossgen (
437         echo %__MsgPrefix%Skipping Crossgen
438         goto SkipCrossGenBuild
439     )
440 )
441
442 echo %__MsgPrefix%Generating native image of mscorlib for %__BuildOS%.%__BuildArch%.%__BuildType%
443
444 set "__CrossGenMScorlibLog=%__LogsDir%\CrossgenMScorlib_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
445 "%__BinDir%\crossgen.exe" "%__BinDir%\mscorlib.dll" > "%__CrossGenMScorlibLog%" 2>&1
446 if errorlevel 1 (
447     echo %__MsgPrefix%Error: CrossGen mscorlib build failed. Refer to the build log file for details:
448     echo     %__CrossGenMScorlibLog%
449     exit /b 1
450 )
451
452 :SkipCrossGenBuild
453
454 REM endlocal to rid us of environment changes from vsdevenv.bat
455 endlocal
456
457 :SkipMscorlibBuild
458
459 REM =========================================================================================
460 REM ===
461 REM === Test build section
462 REM ===
463 REM =========================================================================================
464
465 if defined __SkipTestBuild (
466     echo %__MsgPrefix%Skipping test build
467     goto SkipTestBuild
468 )
469
470 echo %__MsgPrefix%Commencing build of tests for %__BuildOS%.%__BuildArch%.%__BuildType%
471
472 REM Construct the arguments to pass to the test build script.
473
474 set __BuildtestArgs=%__BuildArch% %__BuildType% %__VSVersion%
475
476 if defined __CleanBuild (
477     set "__BuildtestArgs=%__BuildtestArgs% clean"
478 )
479
480 if defined __BuildSequential (
481     set "__BuildtestArgs=%__BuildtestArgs% sequential"
482 )
483
484 if defined __TestPriority (
485     set "__BuildtestArgs=%__BuildtestArgs% Priority %__TestPriority%"
486 )
487
488 call %__ProjectDir%\tests\buildtest.cmd %__BuildtestArgs%
489
490 if errorlevel 1 (
491     REM buildtest.cmd has already emitted an error message and mentioned the build log file to examine.
492     exit /b 1
493 )
494
495 :SkipTestBuild
496
497 REM =========================================================================================
498 REM ===
499 REM === All builds complete!
500 REM ===
501 REM =========================================================================================
502
503 echo %__MsgPrefix%Repo successfully built.
504 echo %__MsgPrefix%Product binaries are available at !__BinDir!
505 if not defined __SkipTestBuild (
506     echo %__MsgPrefix%Test binaries are available at !__TestBinDir!
507 )
508 exit /b 0
509
510 REM =========================================================================================
511 REM ===
512 REM === Handle the "all" case.
513 REM ===
514 REM =========================================================================================
515
516 :BuildAll
517
518 set __BuildArchList=
519
520 set /A __TotalSpecifiedBuildArch=__BuildArchX64 + __BuildArchX86 + __BuildArchArm + __BuildArchArm64
521 if %__TotalSpecifiedBuildArch% EQU 0 (
522     REM Nothing specified means we want to build all architectures.
523     set __BuildArchList=x64 x86 arm arm64
524 )
525
526 REM Otherwise, add all the specified architectures to the list.
527
528 if %__BuildArchX64%==1      set __BuildArchList=%__BuildArchList% x64
529 if %__BuildArchX86%==1      set __BuildArchList=%__BuildArchList% x86
530 if %__BuildArchArm%==1      set __BuildArchList=%__BuildArchList% arm
531 if %__BuildArchArm64%==1    set __BuildArchList=%__BuildArchList% arm64
532
533 set __BuildTypeList=
534
535 set /A __TotalSpecifiedBuildType=__BuildTypeDebug + __BuildTypeChecked + __BuildTypeRelease
536 if %__TotalSpecifiedBuildType% EQU 0 (
537     REM Nothing specified means we want to build all build types.
538     set __BuildTypeList=Debug Checked Release
539 )
540
541 if %__BuildTypeDebug%==1    set __BuildTypeList=%__BuildTypeList% Debug
542 if %__BuildTypeChecked%==1  set __BuildTypeList=%__BuildTypeList% Checked
543 if %__BuildTypeRelease%==1  set __BuildTypeList=%__BuildTypeList% Release
544
545 REM Create a temporary file to collect build results. We always build all flavors specified, and
546 REM report a summary of the results at the end.
547
548 set __AllBuildSuccess=true
549 set __BuildResultFile=%TEMP%\build-all-summary-%RANDOM%.txt
550 if exist %__BuildResultFile% del /f /q %__BuildResultFile%
551
552 for %%i in (%__BuildArchList%) do (
553     for %%j in (%__BuildTypeList%) do (
554         call :BuildOne %%i %%j
555     )
556 )
557
558 if %__AllBuildSuccess%==true (
559     echo %__MsgPrefix%All builds succeeded!
560     exit /b 0
561 ) else (
562     echo %__MsgPrefix%Builds failed:
563     type %__BuildResultFile%
564     del /f /q %__BuildResultFile%
565     exit /b 1
566 )
567
568 REM This code is unreachable, but leaving it nonetheless, just in case things change.
569 exit /b 99
570
571 :BuildOne
572 set __BuildArch=%1
573 set __BuildType=%2
574 set __NextCmd=call %__ThisScriptFull% %__BuildArch% %__BuildType% %__PassThroughArgs%
575 echo %__MsgPrefix%Invoking: %__NextCmd%
576 %__NextCmd%
577 if errorlevel 1 (
578     echo %__MsgPrefix%    %__BuildArch% %__BuildType% %__PassThroughArgs% >> %__BuildResultFile%
579     set __AllBuildSuccess=false
580 )
581 exit /b 0
582
583 REM =========================================================================================
584 REM ===
585 REM === Helper routines
586 REM ===
587 REM =========================================================================================
588
589 :Usage
590 echo.
591 echo Build the CoreCLR repo.
592 echo.
593 echo Usage:
594 echo     %__ThisScriptShort% [option1] [option2] ...
595 echo or:
596 echo     %__ThisScriptShort% all [option1] [option2] ...
597 echo.
598 echo All arguments are optional. The options are:
599 echo.
600 echo./? -? /h -h /help -help: view this message.
601 echo Build architecture: one of x64, x86, arm, arm64 ^(default: x64^).
602 echo Build type: one of Debug, Checked, Release ^(default: Debug^).
603 echo Visual Studio version: ^(default: VS2015^).
604 echo clean: force a clean build ^(default is to perform an incremental build^).
605 echo docrossgen: do a crossgen build of mscorlib.
606 echo msbuildargs ... : all arguments following this tag will be passed directly to msbuild.
607 echo mscorlib version: one of freebsdmscorlib, linuxmscorlib, osxmscorlib,
608 echo     or windowsmscorlib. If one of these is passed, only mscorlib is built,
609 echo     for the specified platform ^(FreeBSD, Linux, OS X, or Windows,
610 echo     respectively^).
611 echo priority ^<N^> : specify a set of test that will be built and run, with priority N.
612 echo sequential: force a non-parallel build ^(default is to build in parallel
613 echo     using all processors^).
614 echo configureonly: skip all builds; only run CMake ^(default: CMake and builds are run^)
615 echo skipconfigure: skip CMake ^(default: CMake is run^)
616 echo skipmscorlib: skip building mscorlib ^(default: mscorlib is built^).
617 echo skipnative: skip building native components ^(default: native components are built^).
618 echo skiptests: skip building tests ^(default: tests are built^).
619 echo toolset_dir ^<dir^> : set the toolset directory -- Arm64 use only. Required for Arm64 builds.
620 echo.
621 echo If "all" is specified, then all build architectures and types are built. If, in addition,
622 echo one or more build architectures or types is specified, then only those build architectures
623 echo and types are built.
624 echo.
625 echo For example:
626 echo     build all
627 echo        -- builds all architectures, and all build types per architecture
628 echo     build all x86
629 echo        -- builds all build types for x86
630 echo     build all x64 x86 Checked Release
631 echo        -- builds x64 and x86 architectures, Checked and Release build types for each
632 exit /b 1
633
634 :NoVS
635 echo Visual Studio 2015+ ^(Community is free^) is a prerequisite to build this repository.
636 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites
637 exit /b 1
638
639 :NoDIA
640 echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
641 This is due to a bug in the Visual Studio installer. It does not install DIA SDK at "%VSINSTALLDIR%" but rather ^
642 at the install location of previous Visual Studio version. The workaround is to copy the DIA SDK folder from the Visual Studio install location ^
643 of the previous version to "%VSINSTALLDIR%" and then build.
644 :: DIA SDK not included in Express editions
645 echo Visual Studio Express does not include the DIA SDK. ^
646 You need Visual Studio 2015+ (Community is free).
647 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites
648 exit /b 1