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