Merge pull request #7212 from joperezr/FixmscorlibRef
[platform/upstream/coreclr.git] / build.cmd
1 @if not defined __echo @echo off
2 setlocal EnableDelayedExpansion EnableExtensions
3
4 set __ThisScriptFull="%~f0"
5 set __VSToolsRoot=%VS140COMNTOOLS%
6 :: Note that the msbuild project files (specifically, dir.proj) will use the following variables, if set:
7 ::      __BuildArch         -- default: x64
8 ::      __BuildType         -- default: Debug
9 ::      __BuildOS           -- default: Windows_NT
10 ::      __ProjectDir        -- default: directory of the dir.props file
11 ::      __SourceDir         -- default: %__ProjectDir%\src\
12 ::      __PackagesDir       -- default: %__ProjectDir%\packages\
13 ::      __RootBinDir        -- default: %__ProjectDir%\bin\
14 ::      __BinDir            -- default: %__RootBinDir%\%__BuildOS%.%__BuildArch.%__BuildType%\
15 ::      __IntermediatesDir
16 ::      __PackagesBinDir    -- default: %__BinDir%\.nuget
17 ::      __TestWorkingDir    -- default: %__RootBinDir%\tests\%__BuildOS%.%__BuildArch.%__BuildType%\
18 ::
19 :: Thus, these variables are not simply internal to this script!
20
21 :: Set the default arguments for build
22 set __BuildArch=x64
23 set __BuildType=Debug
24 set __BuildOS=Windows_NT
25
26 :: Default to highest Visual Studio version available
27 set __VSVersion=vs2015
28
29 :: Define a prefix for most output progress messages that come from this script. That makes
30 :: it easier to see where these are coming from. Note that there is a trailing space here.
31 set "__MsgPrefix=BUILD: "
32
33 :: Set the various build properties here so that CMake and MSBuild can pick them up
34 set "__ProjectDir=%~dp0"
35 :: remove trailing slash
36 if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%"
37 set "__ProjectFilesDir=%__ProjectDir%"
38 set "__SourceDir=%__ProjectDir%\src"
39 set "__PackagesDir=%__ProjectDir%\packages"
40 set "__RootBinDir=%__ProjectDir%\bin"
41 set "__LogsDir=%__RootBinDir%\Logs"
42
43 set __BuildAll=
44
45 set __BuildArchX64=0
46 set __BuildArchX86=0
47 set __BuildArchArm=0
48 set __BuildArchArm64=0
49
50 set __BuildTypeDebug=0
51 set __BuildTypeChecked=0
52 set __BuildTypeRelease=0
53 set __BuildJit32="-DBUILD_JIT32=0"
54
55 REM __PassThroughArgs is a set of things that will be passed through to nested calls to build.cmd
56 REM when using "all".
57 set __PassThroughArgs=
58
59 REM __UnprocessedBuildArgs are args that we pass to msbuild (e.g. /p:__BuildArch=x64)
60 set "__args= %*"
61 set processedArgs=
62 set __UnprocessedBuildArgs=
63 set __RunArgs=
64
65 set __BuildCoreLib=1
66 set __BuildNative=1
67 set __BuildTests=1
68 set __BuildPackages=1
69 set __BuildNativeCoreLib=1
70
71 :Arg_Loop
72 if "%1" == "" goto ArgsDone
73
74 if /i "%1" == "-?"    goto Usage
75 if /i "%1" == "-h"    goto Usage
76 if /i "%1" == "-help" goto Usage
77
78 if /i "%1" == "all"                 (set __BuildAll=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
79 if /i "%1" == "x64"                 (set __BuildArchX64=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
80 if /i "%1" == "x86"                 (set __BuildArchX86=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
81 if /i "%1" == "arm"                 (set __BuildArchArm=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
82 if /i "%1" == "arm64"               (set __BuildArchArm64=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
83
84 if /i "%1" == "debug"               (set __BuildTypeDebug=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
85 if /i "%1" == "checked"             (set __BuildTypeChecked=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
86 if /i "%1" == "release"             (set __BuildTypeRelease=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
87
88 REM All arguments after this point will be passed through directly to build.cmd on nested invocations
89 REM using the "all" argument, and must be added to the __PassThroughArgs variable.
90 set __PassThroughArgs=%__PassThroughArgs% %1
91
92 if /i "%1" == "freebsdmscorlib"     (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)
93 if /i "%1" == "linuxmscorlib"       (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)
94 if /i "%1" == "netbsdmscorlib"      (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)
95 if /i "%1" == "osxmscorlib"         (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)
96 if /i "%1" == "windowsmscorlib"     (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)
97 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)
98 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)
99 if /i "%1" == "skipconfigure"       (set __SkipConfigure=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
100 if /i "%1" == "skipmscorlib"        (set __BuildCoreLib=0&set __BuildNativeCoreLib=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
101 if /i "%1" == "skipnative"          (set __BuildNative=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
102 if /i "%1" == "skiptests"           (set __BuildTests=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
103 if /i "%1" == "skipbuildpackages"   (set __BuildPackages=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
104 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)
105 if /i "%1" == "buildjit32"          (set __BuildJit32="-DBUILD_JIT32=1"&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
106 if /i "%1" == "toolset_dir"         (set __ToolsetDir=%2&set __PassThroughArgs=%__PassThroughArgs% %2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
107
108 if [!processedArgs!]==[] (
109   call set __UnprocessedBuildArgs=!__args!
110 ) else (
111   call set __UnprocessedBuildArgs=%%__args:*!processedArgs!=%%
112 )
113
114 :ArgsDone
115
116 if defined __BuildAll goto BuildAll
117
118 set /A __TotalSpecifiedBuildArch=__BuildArchX64 + __BuildArchX86 + __BuildArchArm + __BuildArchArm64
119 if %__TotalSpecifiedBuildArch% GTR 1 (
120     echo Error: more than one build architecture specified, but "all" not specified.
121     goto Usage
122 )
123
124 if %__BuildArchX64%==1      set __BuildArch=x64
125 if %__BuildArchX86%==1      set __BuildArch=x86
126 if %__BuildArchArm%==1 (
127     set __BuildArch=arm
128     set __CrossArch=x86
129 )
130 if %__BuildArchArm64%==1 (
131     set __BuildArch=arm64
132     set __CrossArch=x64
133 )
134
135 set /A __TotalSpecifiedBuildType=__BuildTypeDebug + __BuildTypeChecked + __BuildTypeRelease
136 if %__TotalSpecifiedBuildType% GTR 1 (
137     echo Error: more than one build type specified, but "all" not specified.
138     goto Usage
139 )
140
141 if %__BuildTypeDebug%==1    set __BuildType=Debug
142 if %__BuildTypeChecked%==1  set __BuildType=Checked
143 if %__BuildTypeRelease%==1  set __BuildType=Release
144
145 set __RunArgs=-BuildOS=%__BuildOS% -BuildType=%__BuildType% -BuildArch=%__BuildArch%
146
147 :: Set the remaining variables based upon the determined build configuration
148 set "__BinDir=%__RootBinDir%\Product\%__BuildOS%.%__BuildArch%.%__BuildType%"
149 set "__IntermediatesDir=%__RootBinDir%\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
150 if "%__NMakeMakefiles%"=="1" (set "__IntermediatesDir=%__RootBinDir%\nmakeobj\%__BuildOS%.%__BuildArch%.%__BuildType%")
151 set "__PackagesBinDir=%__BinDir%\.nuget"
152 set "__TestRootDir=%__RootBinDir%\tests"
153 set "__TestBinDir=%__TestRootDir%\%__BuildOS%.%__BuildArch%.%__BuildType%"
154 set "__TestIntermediatesDir=%__RootBinDir%\tests\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
155 set "__CrossComponentBinDir=%__BinDir%"
156 set "__CrossCompIntermediatesDir=%__IntermediatesDir%\crossgen"
157
158 if NOT "%__CrossArch%" == "" set __CrossComponentBinDir=%__CrossComponentBinDir%\%__CrossArch%
159 set "__CrossGenCoreLibLog=%__LogsDir%\CrossgenCoreLib_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
160 set "__CrossgenExe=%__CrossComponentBinDir%\crossgen.exe"
161
162 :: Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash
163 set "__CMakeBinDir=%__BinDir%"
164 set "__CMakeBinDir=%__CMakeBinDir:\=/%"
165
166 if not exist "%__BinDir%"           md "%__BinDir%"
167 if not exist "%__IntermediatesDir%" md "%__IntermediatesDir%"
168 if not exist "%__LogsDir%"          md "%__LogsDir%"
169
170 echo %__MsgPrefix%Commencing CoreCLR Repo build
171
172 :: Set the remaining variables based upon the determined build configuration
173
174 echo %__MsgPrefix%Checking prerequisites
175 :: Eval the output from probe-win1.ps1
176 for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy RemoteSigned "& ""%__SourceDir%\pal\tools\probe-win.ps1"""') do %%a
177
178 REM =========================================================================================
179 REM ===
180 REM === Start the build steps
181 REM ===
182 REM =========================================================================================
183
184 echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\VsDevCmd.bat"
185 call                                 "%__VSToolsRoot%\VsDevCmd.bat"
186
187 @call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\build.proj -generateHeaderWindows -NativeVersionHeaderFile="%__RootBinDir%\obj\_version.h" %__RunArgs% %__UnprocessedBuildArgs% 
188
189 REM =========================================================================================
190 REM ===
191 REM === Build the CLR VM
192 REM ===
193 REM =========================================================================================
194
195 if %__BuildNative% EQU 1 ( 
196     echo %__MsgPrefix%Commencing build of native components for %__BuildOS%.%__BuildArch%.%__BuildType%
197
198         set nativePlatfromArgs=-platform=%__BuildArch%
199     if /i "%__BuildArch%" == "arm64" ( set nativePlatfromArgs=-useEnv )
200
201     set __MsbuildLog=/flp:Verbosity=normal;LogFile="%__LogsDir%\CoreCLR_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
202     set __MsbuildWrn=/flp1:WarningsOnly;LogFile="%__LogsDir%\CoreCLR_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
203     set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__LogsDir%\CoreCLR_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
204
205     if /i "%__BuildArch%" == "arm64" ( 
206         rem arm64 builds currently use private toolset which has not been released yet
207         REM TODO, remove once the toolset is open.
208         call :PrivateToolSet
209         goto GenVSSolution
210     )
211
212     :: Set the environment for the native build
213     set __VCBuildArch=x86_amd64
214     if /i "%__BuildArch%" == "x86" ( set __VCBuildArch=x86 )
215     if /i "%__BuildArch%" == "arm" (set __VCBuildArch=x86_arm)
216     echo %__MsgPrefix%Using environment: "%__VSToolsRoot%\..\..\VC\vcvarsall.bat" !__VCBuildArch!
217     call                                 "%__VSToolsRoot%\..\..\VC\vcvarsall.bat" !__VCBuildArch!
218         @if defined __echo @echo on
219
220     if not defined VSINSTALLDIR (
221         echo %__MsgPrefix%Error: VSINSTALLDIR variable not defined.
222         exit /b 1
223     )
224     if not exist "!VSINSTALLDIR!DIA SDK" goto NoDIA
225 :GenVSSolution
226     if defined __SkipConfigure goto SkipConfigure
227
228     echo %__MsgPrefix%Regenerating the Visual Studio solution
229
230     pushd "%__IntermediatesDir%"
231     call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" "%__ProjectDir%" %__VSVersion% %__BuildArch% %__BuildJit32%
232         @if defined __echo @echo on
233     popd
234 :SkipConfigure
235     if defined __ConfigureOnly goto SkipNativeBuild
236
237     if not exist "%__IntermediatesDir%\install.vcxproj" (
238         echo %__MsgPrefix%Error: failed to generate native component build project!
239         exit /b 1
240     )
241
242     @call %__ProjectDir%\run.cmd build -Project=%__IntermediatesDir%\install.vcxproj -MsBuildLog=!__MsbuildLog! -MsBuildWrn=!__MsbuildWrn! -MsBuildErr=!__MsbuildErr! -configuration=%__BuildType% %nativePlatfromArgs% %__RunArgs% %__UnprocessedBuildArgs%
243
244     if not !errorlevel! == 0 (
245         echo %__MsgPrefix%Error: native component build failed. Refer to the build log files for details:
246         echo     "%__LogsDir%\CoreCLR_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
247         echo     "%__LogsDir%\CoreCLR_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
248         echo     "%__LogsDir%\CoreCLR_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
249         exit /b 1
250     )   
251 )
252 :SkipNativeBuild
253
254 REM =========================================================================================
255 REM ===
256 REM === Build Cross-Architecture Native Components (if applicable)
257 REM ===
258 REM =========================================================================================
259
260 if /i "%__BuildArch%"=="arm64" (
261     set __DoCrossArchBuild=1
262     )
263
264 if /i "%__BuildArch%"=="arm" (
265     set __DoCrossArchBuild=1
266     )
267
268 if /i "%__DoCrossArchBuild%"=="1" (
269
270     echo %__MsgPrefix%Commencing build of cross architecture native components for %__BuildOS%.%__BuildArch%.%__BuildType%
271
272     :: Set the environment for the native build
273     set __VCBuildArch=x86_amd64
274     if /i "%__CrossArch%" == "x86" ( set __VCBuildArch=x86 )
275     @call "%__VSToolsRoot%\..\..\VC\vcvarsall.bat" !__VCBuildArch!
276     @if defined __echo @echo on
277
278     if not exist "%__CrossCompIntermediatesDir%" md "%__CrossCompIntermediatesDir%"
279     if defined __SkipConfigure goto SkipConfigureCrossBuild
280
281     pushd "%__CrossCompIntermediatesDir%"
282     set __CMakeBinDir=%__CrossComponentBinDir%
283     set "__CMakeBinDir=!__CMakeBinDir:\=/!"
284     set __ExtraCmakeArgs="-DCLR_CROSS_COMPONENTS_BUILD=1" "-DCLR_CMAKE_TARGET_ARCH=%__BuildArch%"
285     call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" "%__ProjectDir%" %__VSVersion% %__CrossArch% !__ExtraCmakeArgs!
286     @if defined __echo @echo on
287     popd
288 :SkipConfigureCrossBuild
289     if not exist "%__CrossCompIntermediatesDir%\install.vcxproj" (
290         echo %__MsgPrefix%Error: failed to generate cross-arch components build project!
291         exit /b 1
292     )
293
294     if defined __ConfigureOnly goto SkipCrossCompBuild
295
296     echo %__MsgPrefix%Invoking msbuild
297
298     set __MsbuildLog=/flp:Verbosity=normal;LogFile="%__LogsDir%\Cross_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
299     set __MsbuildWrn=/flp1:WarningsOnly;LogFile="%__LogsDir%\Cross_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
300     set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__LogsDir%\Cross_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
301     @call %__ProjectDir%\run.cmd build -Project=%__CrossCompIntermediatesDir%\install.vcxproj -configuration=%__BuildType% -platform=%__CrossArch% -MsBuildLog=!__MsbuildLog! -MsBuildWrn=!__MsbuildWrn! -MsBuildErr=!__MsbuildErr! %__RunArgs% %__UnprocessedBuildArgs%
302     if not !errorlevel! == 0 (
303         echo %__MsgPrefix%Error: cross-arch components build failed. Refer to the build log files for details:
304         echo     "%__LogsDir%\Cross_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
305         echo     "%__LogsDir%\Cross_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
306         echo     "%__LogsDir%\Cross_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
307         exit /b 1
308     )    
309 )
310
311 :SkipCrossCompBuild
312
313 REM =========================================================================================
314 REM ===
315 REM === CoreLib and NuGet package build section.
316 REM ===
317 REM =========================================================================================
318
319 if %__BuildCoreLib% EQU 1 (  
320         
321         echo %__MsgPrefix%Commencing build of System.Private.CoreLib for %__BuildOS%.%__BuildArch%.%__BuildType%
322     rem Explicitly set Platform causes conflicts in CoreLib project files. Clear it to allow building from VS x64 Native Tools Command Prompt
323     set Platform=
324
325     set __MsbuildLog=/flp:Verbosity=normal;LogFile="%__LogsDir%\System.Private.CoreLib_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
326     set __MsbuildWrn=/flp1:WarningsOnly;LogFile="%__LogsDir%\System.Private.CoreLib_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
327     set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__LogsDir%\System.Private.CoreLib_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
328
329     if /i "%__BuildArch%" == "arm64" (
330                 set __nugetBuildArgs=-buildNugetPackage=false
331     ) else if "%__SkipNugetPackage%" == "1" (
332                 set __nugetBuildArgs=-buildNugetPackage=false
333     ) else (
334                 set __nugetBuildArgs=-buildNugetPackage=true
335         )
336
337     @call %__ProjectDir%\run.cmd build -Project=%__ProjectDir%\build.proj -MsBuildLog=!__MsbuildLog! -MsBuildWrn=!__MsbuildWrn! -MsBuildErr=!__MsbuildErr! !__nugetBuildArgs! %__RunArgs% %__UnprocessedBuildArgs% 
338     if not !errorlevel! == 0 (
339         echo %__MsgPrefix%Error: System.Private.CoreLib build failed. Refer to the build log files for details:
340         echo     "%__LogsDir%\System.Private.CoreLib_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
341         echo     "%__LogsDir%\System.Private.CoreLib_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
342         echo     "%__LogsDir%\System.Private.CoreLib_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
343         exit /b 1
344     )
345 )
346
347 if %__BuildNativeCoreLib% EQU 1 (
348     echo %__MsgPrefix%Generating native image of System.Private.CoreLib for %__BuildOS%.%__BuildArch%.%__BuildType%
349         
350     echo "%__CrossgenExe%" /Platform_Assemblies_Paths "%__BinDir%" /out "%__BinDir%\System.Private.CoreLib.ni.dll" "%__BinDir%\System.Private.CoreLib.dll"
351     "%__CrossgenExe%" /Platform_Assemblies_Paths "%__BinDir%" /out "%__BinDir%\System.Private.CoreLib.ni.dll" "%__BinDir%\System.Private.CoreLib.dll" > "%__CrossGenCoreLibLog%" 2>&1
352     if NOT !errorlevel! == 0 (
353         echo %__MsgPrefix%Error: CrossGen System.Private.CoreLib build failed. Refer to the build log file for details:
354         echo     %__CrossGenCoreLibLog%
355         exit /b 1
356     )
357
358     echo %__MsgPrefix%Generating native image of MScorlib facade for %__BuildOS%.%__BuildArch%.%__BuildType%
359
360     set "__CrossGenCoreLibLog=%__LogsDir%\CrossgenMSCoreLib_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
361     set "__CrossgenExe=%__CrossComponentBinDir%\crossgen.exe"
362     "!__CrossgenExe!" /Platform_Assemblies_Paths "%__BinDir%" /out "%__BinDir%\mscorlib.ni.dll" "%__BinDir%\mscorlib.dll" > "!__CrossGenCoreLibLog!" 2>&1
363     if NOT !errorlevel! == 0 (
364         echo %__MsgPrefix%Error: CrossGen mscorlib facade build failed. Refer to the build log file for details:
365         echo     !__CrossGenCoreLibLog!
366         exit /b 1
367     )
368 )
369
370 if %__BuildPackages% EQU 1 (
371     set __MsbuildLog=/flp:Verbosity=normal;LogFile="%__LogsDir%\Nuget_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
372         set __MsbuildWrn=/flp1:WarningsOnly;LogFile="%__LogsDir%\Nuget_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
373         set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__LogsDir%\Nuget_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
374
375     REM The conditions as to what to build are captured in the builds file.
376     @call %__ProjectDir%\run.cmd build -Project=%__SourceDir%\.nuget\packages.builds -platform=%__BuildArch% -MsBuildLog=!__MsbuildLog! -MsBuildWrn=!__MsbuildWrn! -MsBuildErr=!__MsbuildErr! %__RunArgs% %__UnprocessedBuildArgs%
377
378     if not !errorlevel! == 0 (
379         echo %__MsgPrefix%Error: Nuget package generation failed build failed. Refer to the build log files for details:
380         echo     "%__LogsDir%\Nuget_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
381         echo     "%__LogsDir%\Nuget_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn"
382         echo     "%__LogsDir%\Nuget_%__BuildOS%__%__BuildArch%__%__BuildType%.err"
383         exit /b 1
384     )
385 )
386
387 REM =========================================================================================
388 REM ===
389 REM === Test build section
390 REM ===
391 REM =========================================================================================
392
393 if %__BuildTests% EQU 1 (
394     echo %__MsgPrefix%Commencing build of tests for %__BuildOS%.%__BuildArch%.%__BuildType%
395
396     REM Construct the arguments to pass to the test build script.
397
398     rem arm64 builds currently use private toolset which has not been released yet
399     REM TODO, remove once the toolset is open.
400     if /i "%__BuildArch%" == "arm64" call :PrivateToolSet 
401
402     echo "%__ProjectDir%\build-test.cmd %__BuildArch% %__BuildType% %__UnprocessedBuildArgs%"
403     @call %__ProjectDir%\build-test.cmd %__BuildArch% %__BuildType% %__UnprocessedBuildArgs%
404
405     if not !errorlevel! == 0 (
406         REM buildtest.cmd has already emitted an error message and mentioned the build log file to examine.
407         exit /b 1
408     )
409 )
410
411 REM =========================================================================================
412 REM ===
413 REM === All builds complete!
414 REM ===
415 REM =========================================================================================
416
417 echo %__MsgPrefix%Repo successfully built.
418 echo %__MsgPrefix%Product binaries are available at !__BinDir!
419 if %__BuildTests% EQU 1 (
420     echo %__MsgPrefix%Test binaries are available at !__TestBinDir!
421 )
422 exit /b 0
423
424 REM =========================================================================================
425 REM ===
426 REM === Handle the "all" case.
427 REM ===
428 REM =========================================================================================
429
430 :BuildAll
431
432 set __BuildArchList=
433
434 set /A __TotalSpecifiedBuildArch=__BuildArchX64 + __BuildArchX86 + __BuildArchArm + __BuildArchArm64
435 if %__TotalSpecifiedBuildArch% EQU 0 (
436     REM Nothing specified means we want to build all architectures.
437     set __BuildArchList=x64 x86 arm arm64
438 )
439
440 REM Otherwise, add all the specified architectures to the list.
441
442 if %__BuildArchX64%==1      set __BuildArchList=%__BuildArchList% x64
443 if %__BuildArchX86%==1      set __BuildArchList=%__BuildArchList% x86
444 if %__BuildArchArm%==1      set __BuildArchList=%__BuildArchList% arm
445 if %__BuildArchArm64%==1    set __BuildArchList=%__BuildArchList% arm64
446
447 set __BuildTypeList=
448
449 set /A __TotalSpecifiedBuildType=__BuildTypeDebug + __BuildTypeChecked + __BuildTypeRelease
450 if %__TotalSpecifiedBuildType% EQU 0 (
451     REM Nothing specified means we want to build all build types.
452     set __BuildTypeList=Debug Checked Release
453 )
454
455 if %__BuildTypeDebug%==1    set __BuildTypeList=%__BuildTypeList% Debug
456 if %__BuildTypeChecked%==1  set __BuildTypeList=%__BuildTypeList% Checked
457 if %__BuildTypeRelease%==1  set __BuildTypeList=%__BuildTypeList% Release
458
459 REM Create a temporary file to collect build results. We always build all flavors specified, and
460 REM report a summary of the results at the end.
461
462 set __AllBuildSuccess=true
463 set __BuildResultFile=%TEMP%\build-all-summary-%RANDOM%.txt
464 if exist %__BuildResultFile% del /f /q %__BuildResultFile%
465
466 for %%i in (%__BuildArchList%) do (
467     for %%j in (%__BuildTypeList%) do (
468         call :BuildOne %%i %%j
469     )
470 )
471
472 if %__AllBuildSuccess%==true (
473     echo %__MsgPrefix%All builds succeeded!
474     exit /b 0
475 ) else (
476     echo %__MsgPrefix%Builds failed:
477     type %__BuildResultFile%
478     del /f /q %__BuildResultFile%
479     exit /b 1
480 )
481
482 REM This code is unreachable, but leaving it nonetheless, just in case things change.
483 exit /b 99
484
485 :BuildOne
486 set __BuildArch=%1
487 set __BuildType=%2
488 set __NextCmd=call %__ThisScriptFull% %__BuildArch% %__BuildType% %__PassThroughArgs%
489 echo %__MsgPrefix%Invoking: %__NextCmd%
490 %__NextCmd%
491 if not !errorlevel! == 0 (
492     echo %__MsgPrefix%    %__BuildArch% %__BuildType% %__PassThroughArgs% >> %__BuildResultFile%
493     set __AllBuildSuccess=false
494 )
495 exit /b 0
496
497 REM =========================================================================================
498 REM ===
499 REM === Helper routines
500 REM ===
501 REM =========================================================================================
502
503 :Usage
504 echo.
505 echo Build the CoreCLR repo.
506 echo.
507 echo Usage:
508 echo     build.cmd [option1] [option2]
509 echo or:
510 echo     build.cmd all [option1] [option2] -- ...
511 echo.
512 echo All arguments are optional. The options are:
513 echo.
514 echo.-? -h -help: view this message.
515 echo all: Builds all configurations and platforms.
516 echo Build architecture: one of x64, x86, arm, arm64 ^(default: x64^).
517 echo Build type: one of Debug, Checked, Release ^(default: Debug^).
518 echo -- ... : all arguments following this tag will be passed directly to msbuild.
519 echo mscorlib version: one of freebsdmscorlib, linuxmscorlib, netbsdmscorlib, osxmscorlib,
520 echo     or windowsmscorlib. If one of these is passed, only System.Private.CoreLib is built,
521 echo     for the specified platform ^(FreeBSD, Linux, NetBSD, OS X or Windows,
522 echo     respectively^).
523 echo     add nativemscorlib to go further and build the native image for designated mscorlib.
524 echo toolset_dir ^<dir^> : set the toolset directory -- Arm64 use only. Required for Arm64 builds.
525 echo configureonly: skip all builds; only run CMake ^(default: CMake and builds are run^)
526 echo skipconfigure: skip CMake ^(default: CMake is run^)
527 echo skipmscorlib: skip building System.Private.CoreLib ^(default: System.Private.CoreLib is built^).
528 echo skipnative: skip building native components ^(default: native components are built^).
529 echo skiptests: skip building tests ^(default: tests are built^).
530 echo skipbuildpackages: skip building nuget packages ^(default: packages are built^).
531 echo -skiprestore: skip restoring packages ^(default: packages are restored during build^).
532 echo -disableoss: Disable Open Source Signing for System.Private.CoreLib.
533 echo -priority=^<N^> : specify a set of test that will be built and run, with priority N.
534 echo -sequential: force a non-parallel build ^(default is to build in parallel
535 echo     using all processors^).
536 echo -officialbuildid=^<ID^>: specify the official build ID to be used by this build.
537 echo -Rebuild: passes /t:rebuild to the build projects.
538 echo.
539 echo If "all" is specified, then all build architectures and types are built. If, in addition,
540 echo one or more build architectures or types is specified, then only those build architectures
541 echo and types are built.
542 echo.
543 echo For example:
544 echo     build all
545 echo        -- builds all architectures, and all build types per architecture
546 echo     build all x86
547 echo        -- builds all build types for x86
548 echo     build all x64 x86 Checked Release
549 echo        -- builds x64 and x86 architectures, Checked and Release build types for each
550 exit /b 1
551
552 :NoDIA
553 echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
554 This is due to a bug in the Visual Studio installer. It does not install DIA SDK at "%VSINSTALLDIR%" but rather ^
555 at the install location of previous Visual Studio version. The workaround is to copy the DIA SDK folder from the Visual Studio install location ^
556 of the previous version to "%VSINSTALLDIR%" and then build.
557 :: DIA SDK not included in Express editions
558 echo Visual Studio Express does not include the DIA SDK. ^
559 You need Visual Studio 2015+ (Community is free).
560 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites
561 exit /b 1
562
563 :PrivateToolSet
564
565 echo %__MsgPrefix% Setting Up the usage of __ToolsetDir:%__ToolsetDir%
566
567 if /i "%__ToolsetDir%" == "" (
568     echo %__MsgPrefix%Error: A toolset directory is required for the Arm64 Windows build. Use the toolset_dir argument.
569     exit /b 1
570 )
571
572 set PATH=%__ToolsetDir%\VC_sdk\bin;%PATH%
573 set LIB=%__ToolsetDir%\VC_sdk\lib\arm64;%__ToolsetDir%\sdpublic\sdk\lib\arm64
574 set INCLUDE=^
575 %__ToolsetDir%\VC_sdk\inc;^
576 %__ToolsetDir%\sdpublic\sdk\inc;^
577 %__ToolsetDir%\sdpublic\shared\inc;^
578 %__ToolsetDir%\sdpublic\shared\inc\minwin;^
579 %__ToolsetDir%\sdpublic\sdk\inc\ucrt;^
580 %__ToolsetDir%\sdpublic\sdk\inc\minwin;^
581 %__ToolsetDir%\sdpublic\sdk\inc\mincore;^
582 %__ToolsetDir%\sdpublic\sdk\inc\abi;^
583 %__ToolsetDir%\sdpublic\sdk\inc\clientcore;^
584 %__ToolsetDir%\diasdk\include
585 exit /b 0