Merge pull request #17072 from CarolEidt/Fix545505
[platform/upstream/coreclr.git] / build.cmd
1 @if not defined _echo @echo off
2 setlocal EnableDelayedExpansion EnableExtensions
3
4 :: Define a prefix for most output progress messages that come from this script. That makes
5 :: it easier to see where these are coming from. Note that there is a trailing space here.
6 set "__MsgPrefix=BUILD: "
7
8 echo %__MsgPrefix%Starting Build at %TIME%
9 set __ThisScriptFull="%~f0"
10 set __ThisScriptDir="%~dp0"
11
12 call "%__ThisScriptDir%"\setup_vs_tools.cmd
13 if NOT '%ERRORLEVEL%' == '0' exit /b 1
14
15 if defined VS150COMNTOOLS (
16   set "__VSToolsRoot=%VS150COMNTOOLS%"
17   set "__VCToolsRoot=%VS150COMNTOOLS%\..\..\VC\Auxiliary\Build"
18   set __VSVersion=vs2017
19 ) else (
20   set "__VSToolsRoot=%VS140COMNTOOLS%"
21   set "__VCToolsRoot=%VS140COMNTOOLS%\..\..\VC"
22   set __VSVersion=vs2015
23 )
24
25 :: Note that the msbuild project files (specifically, dir.proj) will use the following variables, if set:
26 ::      __BuildArch         -- default: x64
27 ::      __BuildType         -- default: Debug
28 ::      __BuildOS           -- default: Windows_NT
29 ::      __ProjectDir        -- default: directory of the dir.props file
30 ::      __SourceDir         -- default: %__ProjectDir%\src\
31 ::      __PackagesDir       -- default: %__ProjectDir%\packages\
32 ::      __RootBinDir        -- default: %__ProjectDir%\bin\
33 ::      __BinDir            -- default: %__RootBinDir%\%__BuildOS%.%__BuildArch.%__BuildType%\
34 ::      __IntermediatesDir
35 ::      __PackagesBinDir    -- default: %__BinDir%\.nuget
36 ::      __TestWorkingDir    -- default: %__RootBinDir%\tests\%__BuildOS%.%__BuildArch.%__BuildType%\
37 ::
38 :: Thus, these variables are not simply internal to this script!
39
40 :: Set the default arguments for build
41 set __BuildArch=x64
42 set __BuildType=Debug
43 set __BuildOS=Windows_NT
44
45 :: Set the various build properties here so that CMake and MSBuild can pick them up
46 set "__ProjectDir=%~dp0"
47 :: remove trailing slash
48 if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%"
49 set "__ProjectFilesDir=%__ProjectDir%"
50 set "__SourceDir=%__ProjectDir%\src"
51 set "__PackagesDir=%DotNetRestorePackagesPath%"
52 if [%__PackagesDir%]==[] set "__PackagesDir=%__ProjectDir%\packages"
53 set "__RootBinDir=%__ProjectDir%\bin"
54 set "__LogsDir=%__RootBinDir%\Logs"
55 set "__PgoOptDataVersion="
56 set "__IbcOptDataVersion="
57
58 set __BuildAll=
59
60 set __BuildArchX64=0
61 set __BuildArchX86=0
62 set __BuildArchArm=0
63 set __BuildArchArm64=0
64
65 set __BuildTypeDebug=0
66 set __BuildTypeChecked=0
67 set __BuildTypeRelease=0
68
69 set __PgoInstrument=0
70 set __PgoOptimize=1
71 set __EnforcePgo=0
72 set __IbcTuning=
73
74 REM __PassThroughArgs is a set of things that will be passed through to nested calls to build.cmd
75 REM when using "all".
76 set __PassThroughArgs=
77
78 REM __UnprocessedBuildArgs are args that we pass to msbuild (e.g. /p:__BuildArch=x64)
79 set "__args= %*"
80 set processedArgs=
81 set __UnprocessedBuildArgs=
82 set __RunArgs=
83
84 set __BuildCoreLib=1
85 set __BuildSOS=1
86 set __BuildNative=1
87 set __BuildTests=1
88 set __BuildPackages=1
89 set __BuildNativeCoreLib=1
90 set __RestoreOptData=1
91 set __GenerateLayout=0
92 set __CrossgenAltJit=
93
94 @REM CMD has a nasty habit of eating "=" on the argument list, so passing:
95 @REM    -priority=1
96 @REM appears to CMD parsing as "-priority 1". Handle -priority specially to avoid problems,
97 @REM and allow the "-priority=1" syntax.
98 set __Priority=
99
100 :Arg_Loop
101 if "%1" == "" goto ArgsDone
102
103 if /i "%1" == "-?"    goto Usage
104 if /i "%1" == "-h"    goto Usage
105 if /i "%1" == "-help" goto Usage
106 if /i "%1" == "--help" goto Usage
107
108
109 if /i "%1" == "-all"                 (set __BuildAll=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
110 if /i "%1" == "-x64"                 (set __BuildArchX64=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
111 if /i "%1" == "-x86"                 (set __BuildArchX86=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
112 if /i "%1" == "-arm"                 (set __BuildArchArm=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
113 if /i "%1" == "-arm64"               (set __BuildArchArm64=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
114
115 if /i "%1" == "-debug"               (set __BuildTypeDebug=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
116 if /i "%1" == "-checked"             (set __BuildTypeChecked=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
117 if /i "%1" == "-release"             (set __BuildTypeRelease=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
118
119 REM TODO these are deprecated remove them eventually
120 REM don't add more, use the - syntax instead
121 if /i "%1" == "all"                 (set __BuildAll=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
122 if /i "%1" == "x64"                 (set __BuildArchX64=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
123 if /i "%1" == "x86"                 (set __BuildArchX86=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
124 if /i "%1" == "arm"                 (set __BuildArchArm=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
125 if /i "%1" == "arm64"               (set __BuildArchArm64=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
126
127 if /i "%1" == "debug"               (set __BuildTypeDebug=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
128 if /i "%1" == "checked"             (set __BuildTypeChecked=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
129 if /i "%1" == "release"             (set __BuildTypeRelease=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
130
131 if /i "%1" == "-priority"           (set __Priority=%2&shift&set processedArgs=!processedArgs! %1=%2&shift&goto Arg_Loop)
132
133 REM All arguments after this point will be passed through directly to build.cmd on nested invocations
134 REM using the "all" argument, and must be added to the __PassThroughArgs variable.
135 if [!__PassThroughArgs!]==[] (
136     set __PassThroughArgs=%1
137 ) else (
138     set __PassThroughArgs=%__PassThroughArgs% %1
139 )
140
141 if /i "%1" == "-freebsdmscorlib"     (set __BuildSOS=0&set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildOS=FreeBSD&set __SkipNugetPackage=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
142 if /i "%1" == "-linuxmscorlib"       (set __BuildSOS=0&set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildOS=Linux&set __SkipNugetPackage=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
143 if /i "%1" == "-netbsdmscorlib"      (set __BuildSOS=0&set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildOS=NetBSD&set __SkipNugetPackage=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
144 if /i "%1" == "-osxmscorlib"         (set __BuildSOS=0&set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildOS=OSX&set __SkipNugetPackage=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
145 if /i "%1" == "-windowsmscorlib"     (set __BuildSOS=0&set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildOS=Windows_NT&set __SkipNugetPackage=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
146 if /i "%1" == "-nativemscorlib"      (set __BuildNativeCoreLib=1&set __BuildCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
147 if /i "%1" == "-configureonly"       (set __ConfigureOnly=1&set __BuildNative=1&set __BuildNativeCoreLib=0&set __BuildCoreLib=0&set __BuildTests=0&set __BuildPackages=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
148 if /i "%1" == "-skipconfigure"       (set __SkipConfigure=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
149 if /i "%1" == "-skipmscorlib"        (set __BuildCoreLib=0&set __BuildNativeCoreLib=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
150 if /i "%1" == "-skipnative"          (set __BuildNative=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
151 if /i "%1" == "-skiptests"           (set __BuildTests=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
152 if /i "%1" == "-skipbuildpackages"   (set __BuildPackages=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
153 if /i "%1" == "-skiprestoreoptdata"  (set __RestoreOptData=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
154 if /i "%1" == "-usenmakemakefiles"   (set __NMakeMakefiles=1&set __ConfigureOnly=1&set __BuildNative=1&set __BuildNativeCoreLib=0&set __BuildCoreLib=0&set __BuildTests=0&set __BuildPackages=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
155 if /i "%1" == "-pgoinstrument"       (set __PgoInstrument=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
156 if /i "%1" == "-enforcepgo"          (set __EnforcePgo=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
157 if /i "%1" == "-nopgooptimize"       (set __PgoOptimize=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
158 if /i "%1" == "-ibcinstrument"       (set __IbcTuning=/Tuning&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
159 if /i "%1" == "-toolset_dir"         (set __ToolsetDir=%2&set __PassThroughArgs=%__PassThroughArgs% %2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
160 if /i "%1" == "-crossgenaltjit"      (set __CrossgenAltJit=%2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
161
162 REM TODO these are deprecated remove them eventually
163 REM don't add more, use the - syntax instead
164 if /i "%1" == "freebsdmscorlib"     (set __BuildSOS=0&set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildOS=FreeBSD&set __SkipNugetPackage=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
165 if /i "%1" == "linuxmscorlib"       (set __BuildSOS=0&set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildOS=Linux&set __SkipNugetPackage=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
166 if /i "%1" == "netbsdmscorlib"      (set __BuildSOS=0&set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildOS=NetBSD&set __SkipNugetPackage=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
167 if /i "%1" == "osxmscorlib"         (set __BuildSOS=0&set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildOS=OSX&set __SkipNugetPackage=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
168 if /i "%1" == "windowsmscorlib"     (set __BuildSOS=0&set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildOS=Windows_NT&set __SkipNugetPackage=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
169 if /i "%1" == "nativemscorlib"      (set __BuildNativeCoreLib=1&set __BuildCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
170 if /i "%1" == "configureonly"       (set __ConfigureOnly=1&set __BuildNative=1&set __BuildNativeCoreLib=0&set __BuildCoreLib=0&set __BuildTests=0&set __BuildPackages=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
171 if /i "%1" == "skipconfigure"       (set __SkipConfigure=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
172 if /i "%1" == "skipmscorlib"        (set __BuildCoreLib=0&set __BuildNativeCoreLib=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
173 if /i "%1" == "skipnative"          (set __BuildNative=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
174 if /i "%1" == "skiptests"           (set __BuildTests=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
175 if /i "%1" == "skipbuildpackages"   (set __BuildPackages=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
176 if /i "%1" == "skiprestoreoptdata"  (set __RestoreOptData=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
177 if /i "%1" == "generatelayout"      (set __GenerateLayout=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
178 if /i "%1" == "usenmakemakefiles"   (set __NMakeMakefiles=1&set __ConfigureOnly=1&set __BuildNative=1&set __BuildNativeCoreLib=0&set __BuildCoreLib=0&set __BuildTests=0&set __BuildPackages=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
179 if /i "%1" == "pgoinstrument"       (set __PgoInstrument=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
180 if /i "%1" == "nopgooptimize"       (set __PgoOptimize=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
181 if /i "%1" == "enforcepgo"          (set __EnforcePgo=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
182 if /i "%1" == "ibcinstrument"       (set __IbcTuning=/Tuning&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
183 if /i "%1" == "toolset_dir"         (set __ToolsetDir=%2&set __PassThroughArgs=%__PassThroughArgs% %2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
184
185 if [!processedArgs!]==[] (
186   set __UnprocessedBuildArgs=%__args%
187 ) else (
188   set __UnprocessedBuildArgs=%__args%
189   for %%t in (!processedArgs!) do (
190     set __UnprocessedBuildArgs=!__UnprocessedBuildArgs:*%%t=!
191   )
192 )
193
194 :ArgsDone
195
196 @REM Special handling for -priority=N argument.
197 if defined __Priority (
198     if defined __PassThroughArgs (
199         set __PassThroughArgs=%__PassThroughArgs% -priority=%__Priority%
200     ) else (
201         set __PassThroughArgs=-priority=%__Priority%
202     )
203     set __UnprocessedBuildArgs=!__UnprocessedBuildArgs! -priority=%__Priority%
204 )
205
206 if %__PgoOptimize%==0 set __RestoreOptData=0
207
208 if defined __BuildAll goto BuildAll
209
210 set /A __TotalSpecifiedBuildArch=__BuildArchX64 + __BuildArchX86 + __BuildArchArm + __BuildArchArm64
211 if %__TotalSpecifiedBuildArch% GTR 1 (
212     echo Error: more than one build architecture specified, but "all" not specified.
213     goto Usage
214 )
215
216 if %__BuildArchX64%==1      set __BuildArch=x64
217 if %__BuildArchX86%==1      set __BuildArch=x86
218 if %__BuildArchArm%==1 (
219     set __BuildArch=arm
220     set __CrossArch=x86
221 )
222 if %__BuildArchArm64%==1 (
223     set __BuildArch=arm64
224     set __CrossArch=x64
225 )
226
227 set /A __TotalSpecifiedBuildType=__BuildTypeDebug + __BuildTypeChecked + __BuildTypeRelease
228 if %__TotalSpecifiedBuildType% GTR 1 (
229     echo Error: more than one build type specified, but "all" not specified.
230     goto Usage
231 )
232
233 if %__BuildTypeDebug%==1    set __BuildType=Debug
234 if %__BuildTypeChecked%==1  set __BuildType=Checked
235 if %__BuildTypeRelease%==1  set __BuildType=Release
236
237 set __RunArgs=-BuildOS=%__BuildOS% -BuildType=%__BuildType% -BuildArch=%__BuildArch%
238
239 if %__EnforcePgo%==1 (
240     if %__BuildArchArm%==1 (
241         echo NOTICE: enforcepgo does nothing on arm architecture
242     )
243     if %__BuildArchArm64%==1 (
244         echo NOTICE: enforcepgo does nothing on arm64 architecture
245     )
246 )
247
248 REM Determine if this is a cross-arch build
249
250 if /i "%__BuildArch%"=="arm64" (
251     set __DoCrossArchBuild=1
252     )
253
254 if /i "%__BuildArch%"=="arm" (
255     set __DoCrossArchBuild=1
256     )
257
258 :: Set the remaining variables based upon the determined build configuration
259 set "__BinDir=%__RootBinDir%\Product\%__BuildOS%.%__BuildArch%.%__BuildType%"
260 set "__IntermediatesDir=%__RootBinDir%\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
261 if "%__NMakeMakefiles%"=="1" (set "__IntermediatesDir=%__RootBinDir%\nmakeobj\%__BuildOS%.%__BuildArch%.%__BuildType%")
262 set "__PackagesBinDir=%__BinDir%\.nuget"
263 set "__TestRootDir=%__RootBinDir%\tests"
264 set "__TestBinDir=%__TestRootDir%\%__BuildOS%.%__BuildArch%.%__BuildType%"
265 set "__TestIntermediatesDir=%__RootBinDir%\tests\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
266 set "__CrossComponentBinDir=%__BinDir%"
267 set "__CrossCompIntermediatesDir=%__IntermediatesDir%\crossgen"
268
269
270 if NOT "%__CrossArch%" == "" set __CrossComponentBinDir=%__CrossComponentBinDir%\%__CrossArch%
271 set "__CrossGenCoreLibLog=%__LogsDir%\CrossgenCoreLib_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
272 set "__CrossgenExe=%__CrossComponentBinDir%\crossgen.exe"
273
274 :: Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash
275 set "__CMakeBinDir=%__BinDir%"
276 set "__CMakeBinDir=%__CMakeBinDir:\=/%"
277
278 if not exist "%__BinDir%"           md "%__BinDir%"
279 if not exist "%__IntermediatesDir%" md "%__IntermediatesDir%"
280 if not exist "%__LogsDir%"          md "%__LogsDir%"
281
282 REM It is convenient to have your Nuget search path include the location where the build
283 REM will place packages.  However nuget used during the build will fail if that directory
284 REM does not exist.   Avoid this in at least one case by aggressively creating the directory.
285 if not exist "%__BinDir%\.nuget\pkg"           md "%__BinDir%\.nuget\pkg"
286
287 echo %__MsgPrefix%Commencing CoreCLR Repo build
288
289 :: Set the remaining variables based upon the determined build configuration
290
291 echo %__MsgPrefix%Checking prerequisites
292 :: Eval the output from probe-win1.ps1
293 for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& ""%__SourceDir%\pal\tools\probe-win.ps1"""') do %%a
294
295 REM NumberOfCores is an WMI property providing number of physical cores on machine
296 REM processor(s). It is used to set optimal level of CL parallelism during native build step
297 if not defined NumberOfCores (
298 REM Determine number of physical processor cores available on machine
299 for /f "tokens=*" %%I in (
300     'wmic cpu get NumberOfCores /value ^| find "=" 2^>NUL'
301     ) do set %%I
302 )
303 echo %__MsgPrefix%Number of processor cores %NumberOfCores%
304
305 REM =========================================================================================
306 REM ===
307 REM === Start the build steps
308 REM ===
309 REM =========================================================================================
310
311 @if defined _echo @echo on
312
313 @call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\build.proj -generateHeaderWindows -NativeVersionHeaderFile="%__RootBinDir%\obj\_version.h" %__RunArgs% %__UnprocessedBuildArgs%
314
315 REM =========================================================================================
316 REM ===
317 REM === Restore optimization profile data
318 REM ===
319 REM =========================================================================================
320
321 if %__RestoreOptData% EQU 1 if %__BuildTypeRelease% EQU 1 (
322     echo %__MsgPrefix%Restoring the OptimizationData Package
323     @call %__ProjectDir%\run.cmd sync -optdata %__UnprocessedBuildArgs%
324     if not !errorlevel! == 0 (
325         echo %__MsgPrefix%Error: Failed to restore the optimization data package.
326         exit /b 1
327     )
328 )
329
330 REM Parse the optdata package versions out of msbuild so that we can pass them on to CMake
331 set DotNetCli=%__ProjectDir%\Tools\dotnetcli\dotnet.exe
332 if not exist "%DotNetCli%" (
333     echo %__MsgPrefix%Assertion failed: dotnet.exe not found at path "%DotNetCli%"
334     exit /b 1
335 )
336 set OptDataProjectFilePath=%__ProjectDir%\src\.nuget\optdata\optdata.csproj
337 for /f "tokens=*" %%s in ('%DotNetCli% msbuild "%OptDataProjectFilePath%" /t:DumpPgoDataPackageVersion /nologo') do @(
338     set __PgoOptDataVersion=%%s
339 )
340 for /f "tokens=*" %%s in ('%DotNetCli% msbuild "%OptDataProjectFilePath%" /t:DumpIbcDataPackageVersion /nologo') do @(
341     set __IbcOptDataVersion=%%s
342 )
343
344 REM =========================================================================================
345 REM ===
346 REM === Generate source files for eventing
347 REM ===
348 REM =========================================================================================
349
350 set __IntermediatesIncDir=%__IntermediatesDir%\src\inc
351 set __IntermediatesEventingDir=%__IntermediatesDir%\eventing
352
353 REM Find python and set it to the variable PYTHON
354 echo import sys; sys.stdout.write(sys.executable) | (py -3 || py -2 || python3 || python2 || python) > %TEMP%\pythonlocation.txt 2> NUL
355 set /p PYTHON=<%TEMP%\pythonlocation.txt
356
357 if /i "%__BuildNative%"=="1" (
358     if NOT DEFINED PYTHON (
359         echo %__MsgPrefix%Error: Could not find a python installation
360         exit /b 1
361     )
362
363     echo %__MsgPrefix%Laying out dynamically generated files consumed by the native build system
364     echo %__MsgPrefix%Laying out dynamically generated Event test files and etmdummy stub functions
365     "!PYTHON!" -B -Wall  %__SourceDir%\scripts\genEventing.py --inc %__IntermediatesIncDir% --dummy %__IntermediatesIncDir%\etmdummy.h --man %__SourceDir%\vm\ClrEtwAll.man --nonextern --noxplatheader|| exit /b 1
366
367     echo %__MsgPrefix%Laying out dynamically generated EventPipe Implementation
368     "!PYTHON!" -B -Wall %__SourceDir%\scripts\genEventPipe.py --man %__SourceDir%\vm\ClrEtwAll.man --intermediate %__IntermediatesEventingDir%\eventpipe --nonextern || exit /b 1
369
370     echo %__MsgPrefix%Laying out ETW event logging interface
371     "!PYTHON!" -B -Wall %__SourceDir%\scripts\genEtwProvider.py --man %__SourceDir%\vm\ClrEtwAll.man --intermediate %__IntermediatesIncDir% --exc %__SourceDir%\vm\ClrEtwAllMeta.lst || exit /b 1
372 )
373
374 if /i "%__DoCrossArchBuild%"=="1" (
375     if NOT DEFINED PYTHON (
376         echo %__MsgPrefix%Error: Could not find a python installation
377         exit /b 1
378     )
379
380     set __CrossCompIntermediatesIncDir=%__CrossCompIntermediatesDir%\src\inc
381     set __CrossCompIntermediatesEventingDir=%__CrossCompIntermediatesDir%\eventing
382
383     echo %__MsgPrefix%Laying out dynamically generated files consumed by the crossarch build system
384     echo %__MsgPrefix%Laying out dynamically generated Event test files and etmdummy stub functions
385     "!PYTHON!" -B -Wall  %__SourceDir%\scripts\genEventing.py --inc !__CrossCompIntermediatesIncDir! --dummy !__CrossCompIntermediatesIncDir!\etmdummy.h --man %__SourceDir%\vm\ClrEtwAll.man --nonextern || exit /b 1
386
387     echo %__MsgPrefix%Laying out dynamically generated EventPipe Implementation
388     "!PYTHON!" -B -Wall %__SourceDir%\scripts\genEventPipe.py --man %__SourceDir%\vm\ClrEtwAll.man --intermediate !__CrossCompIntermediatesEventingDir!\eventpipe --nonextern || exit /b 1
389
390     echo %__MsgPrefix%Laying out ETW event logging interface
391     "!PYTHON!" -B -Wall %__SourceDir%\scripts\genEtwProvider.py --man %__SourceDir%\vm\ClrEtwAll.man --intermediate !__CrossCompIntermediatesIncDir! --exc %__SourceDir%\vm\ClrEtwAllMeta.lst || exit /b 1
392 )
393
394 REM =========================================================================================
395 REM ===
396 REM === Build the CLR VM
397 REM ===
398 REM =========================================================================================
399
400 if %__BuildNative% EQU 1 (
401     REM Scope environment changes start {
402     setlocal
403
404     echo %__MsgPrefix%Commencing build of native components for %__BuildOS%.%__BuildArch%.%__BuildType%
405
406     set __NativePlatformArgs=-platform=%__BuildArch%
407     if not "%__ToolsetDir%" == "" ( set __NativePlatformArgs=-useEnv )
408
409     if not "%__ToolsetDir%" == "" (
410         rem arm64 builds currently use private toolset which has not been released yet
411         REM TODO, remove once the toolset is open.
412         call :PrivateToolSet
413         goto GenVSSolution
414     )
415
416     :: Set the environment for the native build
417     set __VCBuildArch=x86_amd64
418     if /i "%__BuildArch%" == "x86" ( set __VCBuildArch=x86 )
419     if /i "%__BuildArch%" == "arm" (
420         set __VCBuildArch=x86_arm
421
422         REM Make CMake pick the highest installed version in the 10.0.* range
423         set ___SDKVersion="-DCMAKE_SYSTEM_VERSION=10.0"
424     )
425     if /i "%__BuildArch%" == "arm64" (
426         set __VCBuildArch=x86_arm64
427
428         REM Make CMake pick the highest installed version in the 10.0.* range
429         set ___SDKVersion="-DCMAKE_SYSTEM_VERSION=10.0"
430     )
431
432     echo %__MsgPrefix%Using environment: "%__VCToolsRoot%\vcvarsall.bat" !__VCBuildArch!
433     call                                 "%__VCToolsRoot%\vcvarsall.bat" !__VCBuildArch!
434     @if defined _echo @echo on
435
436     if not defined VSINSTALLDIR (
437         echo %__MsgPrefix%Error: VSINSTALLDIR variable not defined.
438         exit /b 1
439     )
440     if not exist "!VSINSTALLDIR!DIA SDK" goto NoDIA
441
442 :GenVSSolution
443     if defined __SkipConfigure goto SkipConfigure
444
445     echo %__MsgPrefix%Regenerating the Visual Studio solution
446
447     pushd "%__IntermediatesDir%"
448     set __ExtraCmakeArgs=!___SDKVersion! "-DCLR_CMAKE_TARGET_OS=%__BuildOs%" "-DCLR_CMAKE_PACKAGES_DIR=%__PackagesDir%" "-DCLR_CMAKE_PGO_INSTRUMENT=%__PgoInstrument%" "-DCLR_CMAKE_OPTDATA_VERSION=%__PgoOptDataVersion%" "-DCLR_CMAKE_PGO_OPTIMIZE=%__PgoOptimize%"
449     call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" "%__ProjectDir%" %__VSVersion% %__BuildArch% !__ExtraCmakeArgs!
450     @if defined _echo @echo on
451     popd
452
453 :SkipConfigure
454     if defined __ConfigureOnly goto SkipNativeBuild
455
456     if not exist "%__IntermediatesDir%\install.vcxproj" (
457         echo %__MsgPrefix%Error: failed to generate native component build project!
458         exit /b 1
459     )
460
461     set __BuildLogRootName=CoreCLR
462     set __BuildLog="%__LogsDir%\!__BuildLogRootName!_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
463     set __BuildWrn="%__LogsDir%\!__BuildLogRootName!_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
464     set __BuildErr="%__LogsDir%\!__BuildLogRootName!_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
465     set __MsbuildLog=/flp:Verbosity=normal;LogFile=!__BuildLog!
466     set __MsbuildWrn=/flp1:WarningsOnly;LogFile=!__BuildWrn!
467     set __MsbuildErr=/flp2:ErrorsOnly;LogFile=!__BuildErr!
468
469     @call %__ProjectDir%\run.cmd build -Project=%__IntermediatesDir%\install.vcxproj -MsBuildLog=!__MsbuildLog! -MsBuildWrn=!__MsbuildWrn! -MsBuildErr=!__MsbuildErr! -configuration=%__BuildType% %__NativePlatformArgs% %__RunArgs% -MSBuildNodeCount="/m:2" %__UnprocessedBuildArgs%
470
471     if not !errorlevel! == 0 (
472         echo %__MsgPrefix%Error: native component build failed. Refer to the build log files for details:
473         echo     !__BuildLog!
474         echo     !__BuildWrn!
475         echo     !__BuildErr!
476         exit /b 1
477     )
478
479 :SkipNativeBuild
480     REM } Scope environment changes end
481     endlocal
482 )
483
484 REM =========================================================================================
485 REM ===
486 REM === Build Cross-Architecture Native Components (if applicable)
487 REM ===
488 REM =========================================================================================
489
490 if /i "%__DoCrossArchBuild%"=="1" (
491     REM Scope environment changes start {
492     setlocal
493
494     echo %__MsgPrefix%Commencing build of cross architecture native components for %__BuildOS%.%__BuildArch%.%__BuildType%
495
496     :: Set the environment for the native build
497     set __VCBuildArch=x86_amd64
498     if /i "%__CrossArch%" == "x86" ( set __VCBuildArch=x86 )
499
500     echo %__MsgPrefix%Using environment: "%__VCToolsRoot%\vcvarsall.bat" !__VCBuildArch!
501     call                                 "%__VCToolsRoot%\vcvarsall.bat" !__VCBuildArch!
502     @if defined _echo @echo on
503
504     if not exist "%__CrossCompIntermediatesDir%" md "%__CrossCompIntermediatesDir%"
505     if defined __SkipConfigure goto SkipConfigureCrossBuild
506
507     pushd "%__CrossCompIntermediatesDir%"
508     set __CMakeBinDir=%__CrossComponentBinDir%
509     set "__CMakeBinDir=!__CMakeBinDir:\=/!"
510     set __ExtraCmakeArgs="-DCLR_CROSS_COMPONENTS_BUILD=1" "-DCLR_CMAKE_TARGET_ARCH=%__BuildArch%" "-DCLR_CMAKE_TARGET_OS=%__BuildOs%" "-DCLR_CMAKE_PACKAGES_DIR=%__PackagesDir%" "-DCLR_CMAKE_PGO_INSTRUMENT=%__PgoInstrument%" "-DCLR_CMAKE_OPTDATA_VERSION=%__PgoOptDataVersion%" "-DCLR_CMAKE_PGO_OPTIMIZE=%__PgoOptimize%" "-DCMAKE_SYSTEM_VERSION=10.0"
511     call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" "%__ProjectDir%" %__VSVersion% %__CrossArch% !__ExtraCmakeArgs!
512     @if defined _echo @echo on
513     popd
514
515 :SkipConfigureCrossBuild
516     if not exist "%__CrossCompIntermediatesDir%\install.vcxproj" (
517         echo %__MsgPrefix%Error: failed to generate cross-arch components build project!
518         exit /b 1
519     )
520
521     if defined __ConfigureOnly goto SkipCrossCompBuild
522
523     set __BuildLogRootName=Cross
524     set __BuildLog="%__LogsDir%\!__BuildLogRootName!_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
525     set __BuildWrn="%__LogsDir%\!__BuildLogRootName!_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
526     set __BuildErr="%__LogsDir%\!__BuildLogRootName!_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
527     set __MsbuildLog=/flp:Verbosity=normal;LogFile=!__BuildLog!
528     set __MsbuildWrn=/flp1:WarningsOnly;LogFile=!__BuildWrn!
529     set __MsbuildErr=/flp2:ErrorsOnly;LogFile=!__BuildErr!
530
531     @call %__ProjectDir%\run.cmd build -Project=%__CrossCompIntermediatesDir%\install.vcxproj -configuration=%__BuildType% -platform=%__CrossArch% -MsBuildLog=!__MsbuildLog! -MsBuildWrn=!__MsbuildWrn! -MsBuildErr=!__MsbuildErr! %__RunArgs% -MSBuildNodeCount="/m:2" %__UnprocessedBuildArgs%
532
533     if not !errorlevel! == 0 (
534         echo %__MsgPrefix%Error: cross-arch components build failed. Refer to the build log files for details:
535         echo     !__BuildLog!
536         echo     !__BuildWrn!
537         echo     !__BuildErr!
538         exit /b 1
539     )
540
541 :SkipCrossCompBuild
542     REM } Scope environment changes end
543     endlocal
544 )
545
546 REM =========================================================================================
547 REM ===
548 REM === CoreLib and NuGet package build section.
549 REM ===
550 REM =========================================================================================
551
552 if %__BuildCoreLib% EQU 1 (
553     REM Scope environment changes start {
554     setlocal
555
556     echo %__MsgPrefix%Commencing build of System.Private.CoreLib for %__BuildOS%.%__BuildArch%.%__BuildType%
557     rem Explicitly set Platform causes conflicts in CoreLib project files. Clear it to allow building from VS x64 Native Tools Command Prompt
558     set Platform=
559
560     set __ExtraBuildArgs=
561     if not defined __IbcTuning (
562       set __ExtraBuildArgs=!__ExtraBuildArgs! -OptimizationDataDir="%__PackagesDir%/optimization.%__BuildOS%-%__BuildArch%.IBC.CoreCLR/%__IbcOptDataVersion%/data/"
563       set __ExtraBuildArgs=!__ExtraBuildArgs! -EnableProfileGuidedOptimization=true
564     )
565
566     if "%__BuildSOS%" == "0" (
567         set __ExtraBuildArgs=!__ExtraBuildArgs! -SkipSOS=true
568     )
569
570     if /i "%__BuildArch%" == "arm64" (
571         set __nugetBuildArgs=-buildNugetPackage=false
572     ) else if "%__SkipNugetPackage%" == "1" (
573         set __nugetBuildArgs=-buildNugetPackage=false
574     ) else (
575         set __nugetBuildArgs=-buildNugetPackage=true
576     )
577
578     set __BuildLogRootName=System.Private.CoreLib
579     set __BuildLog="%__LogsDir%\!__BuildLogRootName!_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
580     set __BuildWrn="%__LogsDir%\!__BuildLogRootName!_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
581     set __BuildErr="%__LogsDir%\!__BuildLogRootName!_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
582     set __MsbuildLog=/flp:Verbosity=normal;LogFile=!__BuildLog!
583     set __MsbuildWrn=/flp1:WarningsOnly;LogFile=!__BuildWrn!
584     set __MsbuildErr=/flp2:ErrorsOnly;LogFile=!__BuildErr!
585
586     @call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\build.proj -MsBuildLog=!__MsbuildLog! -MsBuildWrn=!__MsbuildWrn! -MsBuildErr=!__MsbuildErr! !__nugetBuildArgs! %__RunArgs% !__ExtraBuildArgs! %__UnprocessedBuildArgs%
587
588     if not !errorlevel! == 0 (
589         echo %__MsgPrefix%Error: System.Private.CoreLib build failed. Refer to the build log files for details:
590         echo     !__BuildLog!
591         echo     !__BuildWrn!
592         echo     !__BuildErr!
593         exit /b 1
594     )
595
596     REM } Scope environment changes end
597     endlocal
598 )
599
600 REM Scope environment changes start {
601 setlocal
602
603 REM Need diasymreader.dll on your path for /CreatePdb
604 set PATH=%PATH%;%WinDir%\Microsoft.Net\Framework64\V4.0.30319;%WinDir%\Microsoft.Net\Framework\V4.0.30319
605
606 if %__BuildNativeCoreLib% EQU 1 (
607     echo %__MsgPrefix%Generating native image of System.Private.CoreLib for %__BuildOS%.%__BuildArch%.%__BuildType%. Logging to "%__CrossGenCoreLibLog%".
608     if exist "%__CrossGenCoreLibLog%" del "%__CrossGenCoreLibLog%"
609
610     REM Need VS native tools environment for the **target** arch when running instrumented binaries
611     if %__PgoInstrument% EQU 1 (
612         set __VCExecArch=%__BuildArch%
613         if /i [%__BuildArch%] == [x64] set __VCExecArch=amd64
614         echo %__MsgPrefix%Using environment: "%__VCToolsRoot%\vcvarsall.bat" !__VCExecArch!
615         call                                 "%__VCToolsRoot%\vcvarsall.bat" !__VCExecArch!
616         @if defined _echo @echo on
617         if NOT !errorlevel! == 0 (
618             echo %__MsgPrefix%Error: Failed to load native tools environment for !__VCExecArch!
619             goto CrossgenFailure
620         )
621
622         REM HACK: Workaround for [dotnet/coreclr#13970](https://github.com/dotnet/coreclr/issues/13970)
623         set __PgoRtPath=
624         for /f "tokens=*" %%f in ('where pgort*.dll') do (
625           if not defined __PgoRtPath set "__PgoRtPath=%%~f"
626         )
627         echo %__MsgPrefix%Copying "!__PgoRtPath!" into "%__BinDir%"
628         copy /y "!__PgoRtPath!" "%__BinDir%" || (
629           echo %__MsgPrefix%Error: copy failed
630           goto CrossgenFailure
631         )
632         REM End HACK
633     )
634
635     if defined __CrossgenAltJit (
636         REM Set altjit flags for the crossgen run. Note that this entire crossgen section is within a setlocal/endlocal scope,
637         REM so we don't need to save or unset these afterwards.
638         echo %__MsgPrefix%Setting altjit environment variables for %__CrossgenAltJit%.
639         echo %__MsgPrefix%Setting altjit environment variables for %__CrossgenAltJit%. >> "%__CrossGenCoreLibLog%"
640         set COMPlus_AltJit=*
641         set COMPlus_AltJitNgen=*
642         set COMPlus_AltJitName=%__CrossgenAltJit%
643         set COMPlus_AltJitAssertOnNYI=1
644         set COMPlus_NoGuiOnAssert=1
645         set COMPlus_ContinueOnAssert=0
646     )
647
648     set NEXTCMD="%__CrossgenExe%" %__IbcTuning% /Platform_Assemblies_Paths "%__BinDir%"\IL /out "%__BinDir%\System.Private.CoreLib.dll" "%__BinDir%\IL\System.Private.CoreLib.dll"
649     echo %__MsgPrefix%!NEXTCMD!
650     echo %__MsgPrefix%!NEXTCMD! >> "%__CrossGenCoreLibLog%"
651     !NEXTCMD! >> "%__CrossGenCoreLibLog%" 2>&1
652     if NOT !errorlevel! == 0 (
653         echo %__MsgPrefix%Error: CrossGen System.Private.CoreLib build failed. Refer to %__CrossGenCoreLibLog%
654         :: Put it in the same log, helpful for Jenkins
655         type %__CrossGenCoreLibLog%
656         goto CrossgenFailure
657     )
658
659     set NEXTCMD="%__CrossgenExe%" /Platform_Assemblies_Paths "%__BinDir%" /CreatePdb "%__BinDir%\PDB" "%__BinDir%\System.Private.CoreLib.dll"
660     echo %__MsgPrefix%!NEXTCMD!
661     echo %__MsgPrefix%!NEXTCMD! >> "%__CrossGenCoreLibLog%"
662     !NEXTCMD! >> "%__CrossGenCoreLibLog%" 2>&1
663     if NOT !errorlevel! == 0 (
664         echo %__MsgPrefix%Error: CrossGen /CreatePdb System.Private.CoreLib build failed. Refer to %__CrossGenCoreLibLog%
665         :: Put it in the same log, helpful for Jenkins
666         type %__CrossGenCoreLibLog%
667         goto CrossgenFailure
668     )
669 )
670
671 REM } Scope environment changes end
672 endlocal
673
674
675 if %__BuildPackages% EQU 1 (
676     REM Scope environment changes start {
677     setlocal
678
679     echo %__MsgPrefix%Building Packages for %__BuildOS%.%__BuildArch%.%__BuildType%
680
681     set __BuildLogRootName=Nuget
682     set __BuildLog="%__LogsDir%\!__BuildLogRootName!_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
683     set __BuildWrn="%__LogsDir%\!__BuildLogRootName!_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
684     set __BuildErr="%__LogsDir%\!__BuildLogRootName!_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
685     set __MsbuildLog=/flp:Verbosity=normal;LogFile=!__BuildLog!
686     set __MsbuildWrn=/flp1:WarningsOnly;LogFile=!__BuildWrn!
687     set __MsbuildErr=/flp2:ErrorsOnly;LogFile=!__BuildErr!
688
689     REM The conditions as to what to build are captured in the builds file.
690     @call %__ProjectDir%\run.cmd build -Project=%__SourceDir%\.nuget\packages.builds -platform=%__BuildArch% -MsBuildLog=!__MsbuildLog! -MsBuildWrn=!__MsbuildWrn! -MsBuildErr=!__MsbuildErr! %__RunArgs% %__UnprocessedBuildArgs%
691
692     if not !errorlevel! == 0 (
693         echo %__MsgPrefix%Error: Nuget package generation failed build failed. Refer to the build log files for details:
694         echo     !__BuildLog!
695         echo     !__BuildWrn!
696         echo     !__BuildErr!
697         exit /b 1
698     )
699
700     REM } Scope environment changes end
701     endlocal
702 )
703
704 REM =========================================================================================
705 REM ===
706 REM === Test build section
707 REM ===
708 REM =========================================================================================
709
710 if %__BuildTests% EQU 1 (
711     echo %__MsgPrefix%Commencing build of tests for %__BuildOS%.%__BuildArch%.%__BuildType%
712
713     REM Construct the arguments to pass to the test build script.
714
715     rem arm64 builds currently use private toolset which has not been released yet
716     REM TODO, remove once the toolset is open.
717     if not "%__ToolsetDir%" == "" call :PrivateToolSet
718
719     set NEXTCMD=call %__ProjectDir%\build-test.cmd %__BuildArch% %__BuildType% %__UnprocessedBuildArgs%
720     echo %__MsgPrefix%!NEXTCMD!
721     !NEXTCMD!
722
723     if not !errorlevel! == 0 (
724         REM buildtest.cmd has already emitted an error message and mentioned the build log file to examine.
725         exit /b 1
726     )
727 ) else if %__GenerateLayout% EQU 1 (
728     echo %__MsgPrefix%Generating layout for %__BuildOS%.%__BuildArch%.%__BuildType%
729
730     REM Construct the arguments to pass to the runtest build script.
731
732     rem arm64 builds currently use private toolset which has not been released yet
733     REM TODO, remove once the toolset is open.
734     if not "%__ToolsetDir%" == "" call :PrivateToolSet
735
736     set NEXTCMD=call %__ProjectDir%\test\runtest.cmd %__BuildArch% %__BuildType% GenerateLayoutOnly %__UnprocessedBuildArgs%
737     echo %__MsgPrefix%!NEXTCMD!
738     !NEXTCMD!
739
740     if not !errorlevel! == 0 (
741         REM runtest.cmd has already emitted an error message and mentioned the build log file to examine.
742         exit /b 1
743     )
744 )
745
746 REM =========================================================================================
747 REM ===
748 REM === All builds complete!
749 REM ===
750 REM =========================================================================================
751
752 echo %__MsgPrefix%Repo successfully built.  Finished at %TIME%
753 echo %__MsgPrefix%Product binaries are available at !__BinDir!
754 if %__BuildTests% EQU 1 (
755     echo %__MsgPrefix%Test binaries are available at !__TestBinDir!
756 )
757 exit /b 0
758
759 REM =========================================================================================
760 REM ===
761 REM === Handle the "all" case.
762 REM ===
763 REM =========================================================================================
764
765 :BuildAll
766
767 set __BuildArchList=
768
769 set /A __TotalSpecifiedBuildArch=__BuildArchX64 + __BuildArchX86 + __BuildArchArm + __BuildArchArm64
770 if %__TotalSpecifiedBuildArch% EQU 0 (
771     REM Nothing specified means we want to build all architectures.
772     set __BuildArchList=x64 x86 arm arm64
773 )
774
775 REM Otherwise, add all the specified architectures to the list.
776
777 if %__BuildArchX64%==1      set __BuildArchList=%__BuildArchList% x64
778 if %__BuildArchX86%==1      set __BuildArchList=%__BuildArchList% x86
779 if %__BuildArchArm%==1      set __BuildArchList=%__BuildArchList% arm
780 if %__BuildArchArm64%==1    set __BuildArchList=%__BuildArchList% arm64
781
782 set __BuildTypeList=
783
784 set /A __TotalSpecifiedBuildType=__BuildTypeDebug + __BuildTypeChecked + __BuildTypeRelease
785 if %__TotalSpecifiedBuildType% EQU 0 (
786     REM Nothing specified means we want to build all build types.
787     set __BuildTypeList=Debug Checked Release
788 )
789
790 if %__BuildTypeDebug%==1    set __BuildTypeList=%__BuildTypeList% Debug
791 if %__BuildTypeChecked%==1  set __BuildTypeList=%__BuildTypeList% Checked
792 if %__BuildTypeRelease%==1  set __BuildTypeList=%__BuildTypeList% Release
793
794 REM Create a temporary file to collect build results. We always build all flavors specified, and
795 REM report a summary of the results at the end.
796
797 set __AllBuildSuccess=true
798 set __BuildResultFile=%TEMP%\build-all-summary-%RANDOM%.txt
799 if exist %__BuildResultFile% del /f /q %__BuildResultFile%
800
801 for %%i in (%__BuildArchList%) do (
802     for %%j in (%__BuildTypeList%) do (
803         call :BuildOne %%i %%j
804     )
805 )
806
807 if %__AllBuildSuccess%==true (
808     echo %__MsgPrefix%All builds succeeded!
809     exit /b 0
810 ) else (
811     echo %__MsgPrefix%Builds failed:
812     type %__BuildResultFile%
813     del /f /q %__BuildResultFile%
814     exit /b 1
815 )
816
817 REM This code is unreachable, but leaving it nonetheless, just in case things change.
818 exit /b 99
819
820 :BuildOne
821 set __BuildArch=%1
822 set __BuildType=%2
823 set __NextCmd=call %__ThisScriptFull% %__BuildArch% %__BuildType% %__PassThroughArgs%
824 echo %__MsgPrefix%Invoking: %__NextCmd%
825 %__NextCmd%
826 if not !errorlevel! == 0 (
827     echo %__MsgPrefix%    %__BuildArch% %__BuildType% %__PassThroughArgs% >> %__BuildResultFile%
828     set __AllBuildSuccess=false
829 )
830 exit /b 0
831
832 REM =========================================================================================
833 REM ===
834 REM === Helper routines
835 REM ===
836 REM =========================================================================================
837
838 :CrossgenFailure
839 exit /b 1
840
841 :Usage
842 echo.
843 echo Build the CoreCLR repo.
844 echo.
845 echo Usage:
846 echo     build.cmd [option1] [option2]
847 echo or:
848 echo     build.cmd all [option1] [option2] -- ...
849 echo.
850 echo All arguments are optional. The options are:
851 echo.
852 echo.-? -h -help --help: view this message.
853 echo -all: Builds all configurations and platforms.
854 echo Build architecture: one of -x64, -x86, -arm, -arm64 ^(default: -x64^).
855 echo Build type: one of -Debug, -Checked, -Release ^(default: -Debug^).
856 echo -- ... : all arguments following this tag will be passed directly to msbuild.
857 echo mscorlib version: one of -freebsdmscorlib, -linuxmscorlib, -netbsdmscorlib, -osxmscorlib,
858 echo     or -windowsmscorlib. If one of these is passed, only System.Private.CoreLib is built,
859 echo     for the specified platform ^(FreeBSD, Linux, NetBSD, OS X or Windows,
860 echo     respectively^).
861 echo     add nativemscorlib to go further and build the native image for designated mscorlib.
862 echo -toolset_dir ^<dir^> : set the toolset directory -- Arm64 use only. Required for Arm64 builds.
863 echo -nopgooptimize: do not use profile guided optimizations.
864 echo -enforcepgo: verify after the build that PGO was used for key DLLs, and fail the build if not
865 echo -pgoinstrument: generate instrumented code for profile guided optimization enabled binaries.
866 echo -ibcinstrument: generate IBC-tuning-enabled native images when invoking crossgen.
867 echo -configureonly: skip all builds; only run CMake ^(default: CMake and builds are run^)
868 echo -skipconfigure: skip CMake ^(default: CMake is run^)
869 echo -skipmscorlib: skip building System.Private.CoreLib ^(default: System.Private.CoreLib is built^).
870 echo -skipnative: skip building native components ^(default: native components are built^).
871 echo -skiptests: skip building tests ^(default: tests are built^).
872 echo -skipbuildpackages: skip building nuget packages ^(default: packages are built^).
873 echo -skiprestoreoptdata: skip restoring optimization data used by profile-based optimizations.
874 echo -skiprestore: skip restoring packages ^(default: packages are restored during build^).
875 echo -disableoss: Disable Open Source Signing for System.Private.CoreLib.
876 echo -priority=^<N^> : specify a set of test that will be built and run, with priority N.
877 echo -officialbuildid=^<ID^>: specify the official build ID to be used by this build.
878 echo -Rebuild: passes /t:rebuild to the build projects.
879 echo -crossgenaltjit ^<JIT dll^>: run crossgen using specified altjit ^(used for JIT testing^).
880 echo portable : build for portable RID.
881 echo.
882 echo If "all" is specified, then all build architectures and types are built. If, in addition,
883 echo one or more build architectures or types is specified, then only those build architectures
884 echo and types are built.
885 echo.
886 echo For example:
887 echo     build -all
888 echo        -- builds all architectures, and all build types per architecture
889 echo     build -all -x86
890 echo        -- builds all build types for x86
891 echo     build -all -x64 -x86 -Checked -Release
892 echo        -- builds x64 and x86 architectures, Checked and Release build types for each
893 exit /b 1
894
895 :NoDIA
896 echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
897 This is due to a bug in the Visual Studio installer. It does not install DIA SDK at "%VSINSTALLDIR%" but rather ^
898 at the install location of previous Visual Studio version. The workaround is to copy the DIA SDK folder from the Visual Studio install location ^
899 of the previous version to "%VSINSTALLDIR%" and then build.
900 :: DIA SDK not included in Express editions
901 echo Visual Studio Express does not include the DIA SDK. ^
902 You need Visual Studio 2015 or 2017 (Community is free).
903 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites
904 exit /b 1
905
906 :PrivateToolSet
907
908 echo %__MsgPrefix%Setting up the usage of __ToolsetDir:%__ToolsetDir%
909
910 if /i "%__ToolsetDir%" == "" (
911     echo %__MsgPrefix%Error: A toolset directory is required for the Arm64 Windows build. Use the toolset_dir argument.
912     exit /b 1
913 )
914
915 if not exist "%__ToolsetDir%"\buildenv_arm64.cmd goto :Not_EWDK
916 call "%__ToolsetDir%"\buildenv_arm64.cmd
917 exit /b 0
918
919 :Not_EWDK
920 set PATH=%__ToolsetDir%\VC_sdk\bin;%PATH%
921 set LIB=%__ToolsetDir%\VC_sdk\lib\arm64;%__ToolsetDir%\sdpublic\sdk\lib\arm64
922 set INCLUDE=^
923 %__ToolsetDir%\VC_sdk\inc;^
924 %__ToolsetDir%\sdpublic\sdk\inc;^
925 %__ToolsetDir%\sdpublic\shared\inc;^
926 %__ToolsetDir%\sdpublic\shared\inc\minwin;^
927 %__ToolsetDir%\sdpublic\sdk\inc\ucrt;^
928 %__ToolsetDir%\sdpublic\sdk\inc\minwin;^
929 %__ToolsetDir%\sdpublic\sdk\inc\mincore;^
930 %__ToolsetDir%\sdpublic\sdk\inc\abi;^
931 %__ToolsetDir%\sdpublic\sdk\inc\clientcore;^
932 %__ToolsetDir%\diasdk\include
933 exit /b 0