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