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