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