-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy pathAndroidBuild.targets
More file actions
300 lines (254 loc) · 15.3 KB
/
AndroidBuild.targets
File metadata and controls
300 lines (254 loc) · 15.3 KB
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<Project>
<PropertyGroup>
<AndroidGenerateAppBundle Condition="'$(AndroidGenerateAppBundle)' == '' and '$(GenerateAppBundle)' != ''">$(GenerateAppBundle)</AndroidGenerateAppBundle>
<AndroidGenerateAppBundle Condition="'$(AndroidGenerateAppBundle)' == ''">true</AndroidGenerateAppBundle>
<AndroidGenerateAppBundle Condition="'$(_IsLibraryMode)' == 'true' and '$(ForceLibraryModeGenerateAppBundle)' != 'true'">false</AndroidGenerateAppBundle>
<EnableDefaultAssembliesToBundle Condition="'$(EnableDefaultAssembliesToBundle)' == ''">false</EnableDefaultAssembliesToBundle>
</PropertyGroup>
<UsingTask Condition="'$(AndroidGenerateAppBundle)' == 'true'"
TaskName="AndroidAppBuilderTask"
AssemblyFile="$(AndroidAppBuilderTasksAssemblyPath)" />
<Target Name="AndroidBuild" AfterTargets="$(AndroidBuildAfterThisTarget)" />
<Target Name="_AndroidCoreBuild" BeforeTargets="AndroidBuild" DependsOnTargets="$(AndroidBuildDependsOn)" />
<Target Name="_InitializeCommonProperties">
<Error Condition="'$(IntermediateOutputPath)' == ''" Text="%24(IntermediateOutputPath) property needs to be set" />
<PropertyGroup>
<_MobileIntermediateOutputPath>$([MSBuild]::NormalizeDirectory($(IntermediateOutputPath), 'mobile'))</_MobileIntermediateOutputPath>
<TargetArchitecture Condition="'$(TargetArchitecture)' == ''">$(PlatformTarget)</TargetArchitecture>
<AppName Condition="'$(AppName)' == ''">$(AssemblyName)</AppName>
<StripDebugSymbols Condition="'$(StripDebugSymbols)' == ''">false</StripDebugSymbols>
</PropertyGroup>
<PropertyGroup>
<MicrosoftNetCoreAppRuntimePackDir Condition="'$(MicrosoftNetCoreAppRuntimePackDir)' == ''">%(ResolvedRuntimePack.PackageDirectory)</MicrosoftNetCoreAppRuntimePackDir>
<MicrosoftNetCoreAppRuntimePackRidDir Condition="'$(MicrosoftNetCoreAppRuntimePackRidDir)' == ''">$([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackDir), 'runtimes', '$(TargetOS)-$(TargetArchitecture)'))</MicrosoftNetCoreAppRuntimePackRidDir>
<MicrosoftNetCoreAppRuntimePackRidDir>$([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackRidDir)))</MicrosoftNetCoreAppRuntimePackRidDir>
<MicrosoftNetCoreAppRuntimePackRidNativeDir>$([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackRidDir), 'native'))</MicrosoftNetCoreAppRuntimePackRidNativeDir>
</PropertyGroup>
<PropertyGroup>
<AndroidBuildDir Condition="'$(AndroidBuildDir)' == ''">$([MSBuild]::NormalizeDirectory($(PublishDir)))</AndroidBuildDir>
<AndroidBundleDir Condition="'$(AndroidBundleDir)' == ''">$([MSBuild]::NormalizeDirectory('$(OutDir)', 'AppBundle'))</AndroidBundleDir>
<BundleDir>$(AndroidBundleDir)</BundleDir>
</PropertyGroup>
<ItemGroup>
<RuntimeHeaders Include="$([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackRidNativeDir), 'include', 'mono-2.0'))"
Condition="'$(UseMonoRuntime)' == 'true' and '$(UseNativeAOTRuntime)' != 'true'"/>
<RuntimeHeaders Include="$(CoreClrProjectRoot)hosts\inc"
Condition="'$(UseMonoRuntime)' == 'false' and '$(UseNativeAOTRuntime)' != 'true'" />
<RuntimeHeaders Include="$(SharedNativeRoot)"
Condition="'$(UseMonoRuntime)' == 'false' and '$(UseNativeAOTRuntime)' != 'true'" />
</ItemGroup>
<ItemGroup Condition="'$(UseMonoRuntime)' == 'true' and '$(UseNativeAOTRuntime)' != 'true'">
<RuntimeComponents Condition="'$(UseAllRuntimeComponents)' == 'true'" Include="@(_MonoRuntimeAvailableComponents)" />
<!-- Make sure marshal-ilgen is included in the components list. -->
<RuntimeComponents Condition="'$(UseAllRuntimeComponents)' != 'true'" Include="marshal-ilgen" KeepDuplicates="false" />
</ItemGroup>
<ItemGroup Condition="'$(_IsLibraryMode)' == 'true'">
<_CommonLinkerArgs Include="-l:libz.so" />
<_CommonLinkerArgs Include="-l:liblog.so" />
<_CommonLinkerArgs Include="-l:libc.so" />
<_CommonLinkerArgs Include="-l:libm.so" />
<_CommonLinkerArgs Include="--build-id=sha1" />
<!-- include all libraries except components -->
<_RuntimeLibraries Include="$(AndroidBuildDir)\*.a" Exclude="$(AndroidBuildDir)\libmono-component-*.a" />
<!-- include all component stub libraries -->
<_RuntimeLibraries Include="$(AndroidBuildDir)\libmono-component-*-stub-static.a" />
<!-- if RuntimeComponents is not empty, remove stubs for the required components and include the actual component library -->
<_RuntimeLibraries Condition="'@(RuntimeComponents)' != ''" Remove="$(AndroidBuildDir)\libmono-component-%(RuntimeComponents.Identity)-stub-static.a" />
<_RuntimeLibraries Condition="'@(RuntimeComponents)' != ''" Include="$(AndroidBuildDir)\libmono-component-%(RuntimeComponents.Identity)-static.a" />
<!-- if RuntimeComponents is empty, do nothing as we already included all the component stubs above -->
</ItemGroup>
</Target>
<Target Name="_BeforeAndroidBuild">
<PropertyGroup>
<_AndroidRuntimeConfigFilePath Condition="'$(_AndroidRuntimeConfigFilePath)' == ''">$([MSBuild]::NormalizePath($(AndroidBuildDir), '$(AssemblyName).runtimeconfig.json'))</_AndroidRuntimeConfigFilePath>
<_ParsedRuntimeConfigFilePath Condition="'$(_ParsedRuntimeConfigFilePath)' == ''">$([MSBuild]::NormalizePath($(AndroidBuildDir), 'runtimeconfig.bin'))</_ParsedRuntimeConfigFilePath>
</PropertyGroup>
<RemoveDir Directories="$(AndroidBundleDir)" />
<MakeDir Directories="$(AndroidBundleDir)" />
<!-- Copy static CoreCLR library for static linking scenarios. Tracking issue: https://github.com/dotnet/runtime/issues/116531 -->
<Copy SourceFiles="$(CoreCLRArtifactsPath)libcoreclr_static.a"
DestinationFiles="$(AndroidBuildDir)libcoreclr_static.a"
Condition="'$(RuntimeFlavor)' == 'CoreCLR' and '$(StaticLinkedRuntime)' == 'true' and Exists('$(CoreCLRArtifactsPath)libcoreclr_static.a')" />
</Target>
<Target Name="_AndroidResolveReferences">
<ItemGroup Condition="'$(EnableDefaultAssembliesToBundle)' == 'true'">
<AndroidAssembliesToBundle Remove="@(AndroidAssembliesToBundle)" />
<AndroidAssembliesToBundle Include="$(PublishDir)\**\*.dll" />
</ItemGroup>
<ItemGroup>
<_AssembliesToBundleInternal Remove="@(_AssembliesToBundleInternal)" />
<_AssembliesToBundleInternal Include="@(AndroidAssembliesToBundle)">
<_InternalForceInterpret>%(AndroidAssembliesToBundle._InternalForceInterpret)</_InternalForceInterpret>
<_IsNative>%(AndroidAssembliesToBundle._IsNative)</_IsNative>
</_AssembliesToBundleInternal>
</ItemGroup>
</Target>
<Target Name="_AndroidBeforeAotCompile">
<PropertyGroup>
<_AOTMode Condition="'$(UseMonoJustInterp)' != 'true'">Normal</_AOTMode>
<_AOTMode Condition="'$(UseMonoJustInterp)' == 'true'">JustInterp</_AOTMode>
<_AOTMode Condition="'$(ForceAOT)' == 'true' and '$(AOTWithLibraryFiles)' != 'true'">Full</_AOTMode>
<_AotOutputType>AsmOnly</_AotOutputType>
</PropertyGroup>
<!-- Should consider renaming property to something more appropriate-->
<PropertyGroup Condition="'$(AOTWithLibraryFiles)' == 'true'">
<_AotOutputType>Library</_AotOutputType>
<_AotLibraryFormat>So</_AotLibraryFormat>
</PropertyGroup>
<PropertyGroup Condition="'$(AOTWithLibraryFiles)' != 'true'">
<_AotModuleTablePath>$(AndroidBundleDir)\modules.c</_AotModuleTablePath>
</PropertyGroup>
<PropertyGroup Condition="'$(_IsLibraryMode)' == 'true'">
<_UsesRuntimeInitCallback>$(UsesRuntimeInitCallback)</_UsesRuntimeInitCallback>
<_UsesRuntimeInitCallback Condition="'$(_UsesRuntimeInitCallback)' == ''">true</_UsesRuntimeInitCallback>
<_AotOutputType>ObjectFile</_AotOutputType>
</PropertyGroup>
<!-- Extend default AOT arguments -->
<ItemGroup>
<MonoAOTCompilerDefaultAotArguments Condition="'$(_IsLibraryMode)' == 'true'" Include="direct-icalls" />
<MonoAOTCompilerDefaultAotArguments Condition="'$(_UsesRuntimeInitCallback)' == 'true' and $(CustomRuntimeInitCallback) == ''" Include="runtime-init-callback" />
<MonoAOTCompilerDefaultAotArguments Condition="'$(_UsesRuntimeInitCallback)' == 'true' and $(CustomRuntimeInitCallback) != ''" Include="runtime-init-callback=$(CustomRuntimeInitCallback)" />
</ItemGroup>
<PropertyGroup>
<AotArguments>@(MonoAOTCompilerDefaultAotArguments, ';')</AotArguments>
<ProcessArguments>@(MonoAOTCompilerDefaultProcessArguments, ';')</ProcessArguments>
</PropertyGroup>
<PropertyGroup>
<AndroidLibraryMinApiLevel Condition="'$(AndroidLibraryMinApiLevel)' == ''">24</AndroidLibraryMinApiLevel>
</PropertyGroup>
<ItemGroup>
<_AotInputAssemblies Include="@(_AssembliesToBundleInternal)"
Condition="'%(_AssembliesToBundleInternal._InternalForceInterpret)' != 'true'">
<AotArguments>$(AotArguments)</AotArguments>
<ProcessArguments>$(ProcessArguments)</ProcessArguments>
</_AotInputAssemblies>
<_AOT_InternalForceInterpretAssemblies Include="@(_AssembliesToBundleInternal->WithMetadataValue('_InternalForceInterpret', 'true'))" />
<_AssembliesToBundleInternal Remove="@(_AssembliesToBundleInternal)" />
</ItemGroup>
<MakeDir Directories="$(_MobileIntermediateOutputPath)" />
</Target>
<Target Name="_AndroidPrepareProfiledAot"
Condition="'$(NetTraceFilePath)' != '' and '$(ForceFullAOT)' != 'true'"
DependsOnTargets="_AndroidBeforeAotCompile">
<PropertyGroup>
<_ToolPath>$([System.IO.Path]::GetDirectoryName('$(DotnetPgoToolPath)'))</_ToolPath>
</PropertyGroup>
<NetTraceToMibcConverter
ToolPath="$(_ToolPath)"
Assemblies="@(_AotInputAssemblies)"
NetTraceFilePath="$(NetTraceFilePath)"
OutputDir="$(_MobileIntermediateOutputPath)">
<Output TaskParameter="MibcFilePath" ItemName="ProfiledAOTProfilePaths" />
</NetTraceToMibcConverter>
</Target>
<Target Name="_AndroidAotCompile"
Condition="'$(RunAOTCompilation)' == 'true'"
DependsOnTargets="_AndroidBeforeAotCompile">
<PropertyGroup Condition="'$(_IsLibraryMode)' == 'true'">
<_EnableUnmanagedCallersOnlyMethodsExport>true</_EnableUnmanagedCallersOnlyMethodsExport>
<_UseAotDataFile>$(UseAotDataFile)</_UseAotDataFile>
<_UseAotDataFile Condition="'$(_UseAotDataFile)' == ''">false</_UseAotDataFile>
</PropertyGroup>
<ItemGroup>
<ProfiledAOTProfilePaths Include="$(MibcFilePath)" />
</ItemGroup>
<!--
In order for the runtime to work when static linking, we must supply
a list of direct pinvokes otherwise the runtime will crash
-->
<ItemGroup Condition="'$(_IsLibraryMode)' == 'true'">
<DirectPInvoke Include="libSystem.Native" />
<DirectPInvoke Include="libSystem.IO.Compression.Native" />
<DirectPInvoke Include="libSystem.Security.Cryptography.Native.Android" />
<DirectPInvoke Include="libbrotlienc;libbrotlidec" />
</ItemGroup>
<PropertyGroup>
<_CompilerBinaryPath>@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier','$(TargetOS.ToLowerInvariant())-$(TargetArchitecture.ToLowerInvariant())'))</_CompilerBinaryPath>
<_MonoLLVMPath>$(MonoAotCrossDir)</_MonoLLVMPath>
<_MonoLLVMPath Condition="'$(_MonoLLVMPath)' == '' and '$(MonoEnableLLVM)' == 'true'">$([System.IO.Path]::GetDirectoryName("$(_CompilerBinaryPath)"))</_MonoLLVMPath>
</PropertyGroup>
<MonoAOTCompiler
AotModulesTablePath="$(_AotModuleTablePath)"
AsName="$(_AsName)"
AsOptions="$(_AsOptions)"
Assemblies="@(_AotInputAssemblies)"
CompilerBinaryPath="$(_CompilerBinaryPath)"
DirectPInvokes="@(DirectPInvoke)"
DirectPInvokeLists="@(DirectPInvokeList)"
EnableUnmanagedCallersOnlyMethodsExport="$(_EnableUnmanagedCallersOnlyMethodsExport)"
IntermediateOutputPath="$(_MobileIntermediateOutputPath)"
LdName="$(_LdName)"
LdOptions="$(_LdOptions)"
LibraryFormat="$(_AotLibraryFormat)"
LLVMPath="$(_MonoLLVMPath)"
MibcProfilePath="@(ProfiledAOTProfilePaths)"
Mode="$(_AOTMode)"
OutputDir="$(_MobileIntermediateOutputPath)"
OutputType="$(_AotOutputType)"
Triple="$(_Triple)"
UseAotDataFile="$(_UseAotDataFile)"
UseLLVM="$(MonoEnableLLVM)">
<Output TaskParameter="CompiledAssemblies" ItemName="_AssembliesToBundleInternal" />
</MonoAOTCompiler>
<ItemGroup>
<_AssembliesToBundleInternal Include="@(_AOT_InternalForceInterpretAssemblies)" />
</ItemGroup>
</Target>
<Target Name="_AndroidGenerateAppBundle"
Condition="$(AndroidGenerateAppBundle) == 'true'"
DependsOnTargets="_AndroidGenerateRuntimeConfig">
<ItemGroup Condition="'$(_IsLibraryMode)' == 'true'">
<_NativeDependencies Include="$(LibraryOutputPath)" />
</ItemGroup>
<PropertyGroup>
<!-- TODO: Revisit this.
We are using a private property to determine the target runtime, we should instead unify the resolution with Apple targets instead, (see: https://github.com/dotnet/runtime/issues/111923) -->
<_RuntimeFlavor>Mono</_RuntimeFlavor>
<_RuntimeFlavor Condition="'$(UseMonoRuntime)' == 'false' and '$(UseNativeAOTRuntime)' != 'true'">CoreCLR</_RuntimeFlavor>
<_RuntimeFlavor Condition="'$(UseNativeAOTRuntime)' == 'true'">nativeaot</_RuntimeFlavor>
</PropertyGroup>
<AndroidAppBuilderTask
RuntimeFlavor="$(_RuntimeFlavor)"
AppDir="$(AndroidBuildDir)"
Assemblies="@(_AssembliesToBundleInternal)"
DiagnosticPorts="$(DiagnosticPorts)"
EnvironmentVariables="@(AndroidEnv)"
ExtraLinkerArguments="@(ExtraAppLinkerArgs)"
ForceAOT="$(RunAOTCompilation)"
ForceFullAOT="$(ForceFullAOT)"
ForceInterpreter="$(MonoForceInterpreter)"
IsLibraryMode="$(_IsLibraryMode)"
MainLibraryFileName="$(MainLibraryFileName)"
RuntimeHeaders="@(RuntimeHeaders)"
NativeDependencies="@(_NativeDependencies)"
OutputDir="$(AndroidBundleDir)"
ProjectName="$(AppName)"
RuntimeComponents="@(RuntimeComponents)"
RuntimeIdentifier="$(RuntimeIdentifier)"
StripDebugSymbols="$(StripDebugSymbols)"
StaticLinkedRuntime="$(StaticLinkedRuntime)">
<Output TaskParameter="ApkBundlePath" PropertyName="ApkBundlePath" />
<Output TaskParameter="ApkPackageId" PropertyName="ApkPackageId" />
</AndroidAppBuilderTask>
<Message Importance="High" Text="PackageId: $(ApkPackageId)"/>
<Message Importance="High" Text="Instrumentation: net.dot.MonoRunner"/>
<Message Importance="High" Text="Apk: $(ApkBundlePath)"/>
</Target>
<Target Name="_AfterAndroidBuild">
</Target>
<Target Name="_AndroidGenerateRuntimeConfig"
Inputs="$(_AndroidRuntimeConfigFilePath)"
Outputs="$(_ParsedRuntimeConfigFilePath)"
Condition="Exists('$(_AndroidRuntimeConfigFilePath)')"
BeforeTargets="_GenerateBundle">
<ItemGroup>
<_RuntimeConfigReservedProperties Include="RUNTIME_IDENTIFIER"/>
<_RuntimeConfigReservedProperties Include="APP_CONTEXT_BASE_DIRECTORY"/>
</ItemGroup>
<RuntimeConfigParserTask
RuntimeConfigFile="$(_AndroidRuntimeConfigFilePath)"
OutputFile="$(_ParsedRuntimeConfigFilePath)"
RuntimeConfigReservedProperties="@(_RuntimeConfigReservedProperties)">
</RuntimeConfigParserTask>
</Target>
</Project>