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