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