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