forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crossgen-corelib.cmd
232 lines (190 loc) · 9.48 KB
/
crossgen-corelib.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
@if not defined _echo @echo off
setlocal EnableDelayedExpansion EnableExtensions
:: Define a prefix for most output progress messages that come from this script. That makes
:: it easier to see where these are coming from. Note that there is a trailing space here.
set "__MsgPrefix=CROSSGEN-CORELIB: "
echo %__MsgPrefix%Starting Build at %TIME%
:: Note that the msbuild project files (specifically, dir.proj) will use the following variables, if set:
:: __BuildArch -- default: x64
:: __BuildType -- default: Debug
:: __TargetOS -- default: windows
:: __ProjectDir -- default: directory of the dir.props file
:: __RepoRootDir -- default: directory two levels above the dir.props file
:: __RootBinDir -- default: %__RepoRootDir%\artifacts\
:: __BinDir -- default: %__RootBinDir%\%__TargetOS%.%__BuildArch.%__BuildType%\
:: __IntermediatesDir
:: __PackagesBinDir -- default: %__BinDir%\.nuget
::
:: Thus, these variables are not simply internal to this script!
:: Set the default arguments for build
set __BuildArch=x64
set __BuildType=Debug
set __TargetOS=windows
set "__ProjectDir=%~dp0"
:: remove trailing slash
if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%"
set "__RepoRootDir=%__ProjectDir%\..\.."
set "__RootBinDir=%__RepoRootDir%\artifacts"
set "__LogsDir=%__RootBinDir%\log"
set __BuildArchX64=0
set __BuildArchX86=0
set __BuildArchArm=0
set __BuildArchArm64=0
set __BuildTypeDebug=0
set __BuildTypeChecked=0
set __BuildTypeRelease=0
set __PgoInstrument=0
set __IbcTuning=
REM __PassThroughArgs is a set of things that will be passed through to nested calls to build.cmd
REM when using "all".
set __PassThroughArgs=
set "__args= %*"
set processedArgs=
set __CrossgenAltJit=
set __CrossArch=
:Arg_Loop
if "%1" == "" goto ArgsDone
if /i "%1" == "/?" goto Usage
if /i "%1" == "-?" goto Usage
if /i "%1" == "/h" goto Usage
if /i "%1" == "-h" goto Usage
if /i "%1" == "/help" goto Usage
if /i "%1" == "-help" goto Usage
if /i "%1" == "--help" goto Usage
if /i "%1" == "-x64" (set __BuildArchX64=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
if /i "%1" == "-x86" (set __BuildArchX86=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
if /i "%1" == "-arm" (set __BuildArchArm=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
if /i "%1" == "-arm64" (set __BuildArchArm64=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
if /i "%1" == "-debug" (set __BuildTypeDebug=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
if /i "%1" == "-checked" (set __BuildTypeChecked=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
if /i "%1" == "-release" (set __BuildTypeRelease=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
if /i "%1" == "-ci" (set __ErrMsgPrefix=##vso[task.logissue type=error]&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
REM All arguments after this point will be passed through directly to build.cmd on nested invocations
REM using the "all" argument, and must be added to the __PassThroughArgs variable.
if [!__PassThroughArgs!]==[] (
set __PassThroughArgs=%1
) else (
set __PassThroughArgs=%__PassThroughArgs% %1
)
if /i "%1" == "-ibcinstrument" (set __IbcTuning=/Tuning&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
if /i "%1" == "-pgoinstrument" (set __PgoInstrument=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
if /i "%1" == "-crossgenaltjit" (set __CrossgenAltJit=%2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop)
if /i "%1" == "--" (set processedArgs=!processedArgs! %1&shift&goto Arg_Loop)
:ArgsDone
set /A __TotalSpecifiedBuildArch=__BuildArchX64 + __BuildArchX86 + __BuildArchArm + __BuildArchArm64
if %__TotalSpecifiedBuildArch% GTR 1 (
echo Error: more than one build architecture specified.
goto Usage
)
if %__BuildArchX64%==1 set __BuildArch=x64
if %__BuildArchX86%==1 set __BuildArch=x86
if %__BuildArchArm%==1 (
set __BuildArch=arm
set __CrossArch=x86
)
if %__BuildArchArm64%==1 (
set __BuildArch=arm64
set __CrossArch=x64
)
set /A __TotalSpecifiedBuildType=__BuildTypeDebug + __BuildTypeChecked + __BuildTypeRelease
if %__TotalSpecifiedBuildType% GTR 1 (
echo Error: more than one build type specified.
goto Usage
)
if %__BuildTypeDebug%==1 set __BuildType=Debug
if %__BuildTypeChecked%==1 set __BuildType=Checked
if %__BuildTypeRelease%==1 set __BuildType=Release
set "__BinDir=%__RootBinDir%\bin\coreclr\%__TargetOS%.%__BuildArch%.%__BuildType%"
set "__IntermediatesDir=%__RootBinDir%\obj\coreclr\%__TargetOS%.%__BuildArch%.%__BuildType%"
set "__CrossComponentBinDir=%__BinDir%"
if NOT "%__CrossArch%" == "" set __CrossComponentBinDir=%__CrossComponentBinDir%\%__CrossArch%
set "__CrossGenCoreLibLog=%__LogsDir%\CrossgenCoreLib_%__TargetOS%__%__BuildArch%__%__BuildType%.log"
set "__CrossgenExe=%__CrossComponentBinDir%\crossgen.exe"
if not exist "%__BinDir%" md "%__BinDir%"
if not exist "%__IntermediatesDir%" md "%__IntermediatesDir%"
if not exist "%__LogsDir%" md "%__LogsDir%"
REM Need VC native tools environment for the host arch to find Microsoft.DiaSymReader.Native in the Visual Studio install.
call %__RepoRootDir%\eng\native\init-vs-env.cmd %__BuildArch%
if NOT '%ERRORLEVEL%' == '0' goto ExitWithError
@if defined _echo @echo on
if defined VCINSTALLDIR (
set "__VCToolsRoot=%VCINSTALLDIR%Auxiliary\Build"
)
echo %__MsgPrefix%Generating native image of System.Private.CoreLib for %__TargetOS%.%__BuildArch%.%__BuildType%. Logging to "%__CrossGenCoreLibLog%".
if exist "%__CrossGenCoreLibLog%" del "%__CrossGenCoreLibLog%"
REM Need VS native tools environment for the **target** arch when running instrumented binaries
if %__PgoInstrument% EQU 1 (
set __VCExecArch=%__BuildArch%
if /i [%__BuildArch%] == [x64] set __VCExecArch=amd64
echo %__MsgPrefix%Using environment: "%__VCToolsRoot%\vcvarsall.bat" !__VCExecArch!
call "%__VCToolsRoot%\vcvarsall.bat" !__VCExecArch!
@if defined _echo @echo on
if NOT !errorlevel! == 0 (
echo %__ErrMsgPrefix%%__MsgPrefix%Error: Failed to load native tools environment for !__VCExecArch!
goto ExitWithError
)
REM HACK: Workaround for [dotnet/runtime#8929](https://github.com/dotnet/runtime/issues/8929)
set __PgoRtPath=
for /f "tokens=*" %%f in ('where pgort*.dll') do (
if not defined __PgoRtPath set "__PgoRtPath=%%~f"
)
echo %__MsgPrefix%Copying "!__PgoRtPath!" into "%__BinDir%"
copy /y "!__PgoRtPath!" "%__BinDir%" || (
echo %__ErrMsgPrefix%%__MsgPrefix%Error: copy failed
goto ExitWithError
)
REM End HACK
)
if defined __CrossgenAltJit (
REM Set altjit flags for the crossgen run.
echo %__MsgPrefix%Setting altjit environment variables for %__CrossgenAltJit%.
echo %__MsgPrefix%Setting altjit environment variables for %__CrossgenAltJit%. >> "%__CrossGenCoreLibLog%"
set COMPlus_AltJit=*
set COMPlus_AltJitNgen=*
set COMPlus_AltJitName=%__CrossgenAltJit%
set COMPlus_AltJitAssertOnNYI=1
set COMPlus_NoGuiOnAssert=1
set COMPlus_ContinueOnAssert=0
)
REM Need diasymreader.dll on your path for /CreatePdb
set PATH=%PATH%;%WinDir%\Microsoft.Net\Framework64\V4.0.30319;%WinDir%\Microsoft.Net\Framework\V4.0.30319
for /f "tokens=*" %%f in ('where Microsoft.DiaSymReader.Native.amd64.dll') do (
echo "%%~f"
)
set NEXTCMD="%__CrossgenExe%" /nologo %__IbcTuning% /Platform_Assemblies_Paths "%__BinDir%\IL" /out "%__BinDir%\System.Private.CoreLib.dll" "%__BinDir%\IL\System.Private.CoreLib.dll"
echo %__MsgPrefix%!NEXTCMD!
echo %__MsgPrefix%!NEXTCMD! >> "%__CrossGenCoreLibLog%"
!NEXTCMD! >> "%__CrossGenCoreLibLog%" 2>&1
if NOT !errorlevel! == 0 (
echo %__ErrMsgPrefix%%__MsgPrefix%Error: CrossGen System.Private.CoreLib build failed. Refer to %__CrossGenCoreLibLog%
REM Put it in the same log, helpful for CI
type %__CrossGenCoreLibLog%
goto ExitWithError
)
set NEXTCMD="%__CrossgenExe%" /nologo /Platform_Assemblies_Paths "%__BinDir%" /CreatePdb "%__BinDir%\PDB" "%__BinDir%\System.Private.CoreLib.dll"
echo %__MsgPrefix%!NEXTCMD!
echo %__MsgPrefix%!NEXTCMD! >> "%__CrossGenCoreLibLog%"
!NEXTCMD! >> "%__CrossGenCoreLibLog%" 2>&1
if NOT !errorlevel! == 0 (
echo %__ErrMsgPrefix%%__MsgPrefix%Error: CrossGen /CreatePdb System.Private.CoreLib build failed. Refer to %__CrossGenCoreLibLog%
REM Put it in the same log, helpful for CI
type %__CrossGenCoreLibLog%
goto ExitWithError
)
REM =========================================================================================
REM ===
REM === All builds complete!
REM ===
REM =========================================================================================
echo %__MsgPrefix%Crossgenning of System.Private.CoreLib succeeded. Finished at %TIME%
echo %__MsgPrefix%Product binaries are available at !__BinDir!
exit /b 0
REM =========================================================================================
REM === These two routines are intended for the exit code to propagate to the parent process
REM === Like MSBuild or Powershell. If we directly exit /b 1 from within a if statement in
REM === any of the routines, the exit code is not propagated.
REM =========================================================================================
:ExitWithError
exit /b 1
:ExitWithCode
exit /b !__exitCode!