-
Notifications
You must be signed in to change notification settings - Fork 542
/
Copy pathMicrosoft.Android.Sdk.NativeAOT.targets
114 lines (102 loc) · 6.33 KB
/
Microsoft.Android.Sdk.NativeAOT.targets
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
<!--
***********************************************************************************************
Microsoft.Android.Sdk.NativeAOT.targets
This file contains the NativeAOT-specific MSBuild logic for .NET for Android.
***********************************************************************************************
-->
<Project>
<UsingTask TaskName="Xamarin.Android.Tasks.SetNdkPathForIlc" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" />
<!-- Default property values for NativeAOT -->
<PropertyGroup>
<_AndroidRuntimePackRuntime>NativeAOT</_AndroidRuntimePackRuntime>
<_AndroidCodeGenerationTarget Condition=" '$(_AndroidCodeGenerationTarget)' == '' ">JavaInterop1</_AndroidCodeGenerationTarget>
<!-- NativeAOT's targets currently gives an error about cross-compilation -->
<DisableUnsupportedError Condition=" $([MSBuild]::IsOSPlatform('windows')) and '$(DisableUnsupportedError)' == '' ">true</DisableUnsupportedError>
</PropertyGroup>
<!-- Make IlcCompile depend on the trimmer -->
<PropertyGroup>
<IlcCompileDependsOn>
_AndroidBeforeIlcCompile;
SetupOSSpecificProps;
PrepareForILLink;
ILLink;
ComputeIlcCompileInputs;
_AndroidComputeIlcCompileInputs;
$(IlcCompileDependsOn)
</IlcCompileDependsOn>
</PropertyGroup>
<Target Name="_AndroidBeforeIlcCompile"
DependsOnTargets="_PrepareLinking"
BeforeTargets="SetupProperties">
<!-- Example settings from: https://github.com/jonathanpeppers/Android-NativeAOT/blob/ea69d122cdc7de67aa6a5db14b7e560763c63cdd/DotNet/libdotnet.targets -->
<PropertyGroup>
<_NdkAbi Condition=" '$(RuntimeIdentifier)' == 'android-arm64' ">aarch64</_NdkAbi>
<_NdkAbi Condition=" '$(RuntimeIdentifier)' == 'android-x64' ">x86_64</_NdkAbi>
<_NdkSysrootAbi>$(_NdkAbi)-linux-android</_NdkSysrootAbi>
<_NdkPrebuiltAbi Condition=" $([MSBuild]::IsOSPlatform('windows')) ">windows-x86_64</_NdkPrebuiltAbi>
<_NdkPrebuiltAbi Condition=" $([MSBuild]::IsOSPlatform('osx')) ">darwin-x86_64</_NdkPrebuiltAbi>
<_NdkPrebuiltAbi Condition=" $([MSBuild]::IsOSPlatform('linux')) ">linux-x86_64</_NdkPrebuiltAbi>
<_NdkSysrootDir>$(_AndroidNdkDirectory)toolchains/llvm/prebuilt/$(_NdkPrebuiltAbi)/sysroot/usr/lib/$(_NdkSysrootAbi)/</_NdkSysrootDir>
<_NdkBinDir>$(_AndroidNdkDirectory)toolchains/llvm/prebuilt/$(_NdkPrebuiltAbi)/bin/</_NdkBinDir>
<CppCompilerAndLinker>clang++</CppCompilerAndLinker>
<ObjCopyName>llvm-objcopy</ObjCopyName>
<!-- Example settings from: https://github.com/xamarin/xamarin-macios/blob/c43d4ea40bc777969e3b158cf46446df292d8449/dotnet/targets/Xamarin.Shared.Sdk.targets#L541-L550 -->
<RunILLink>true</RunILLink>
<!--
We want to suppress warnings from trimmer and only show warnings from ILC.
Otherwise, you would get 2x for every warning.
-->
<_OriginalSuppressTrimAnalysisWarnings>$(SuppressTrimAnalysisWarnings)</_OriginalSuppressTrimAnalysisWarnings>
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
<!-- Ensure ILLink respects the value of SuppressTrimAnalysisWarnings -->
<_ExtraTrimmerArgs>$(_ExtraTrimmerArgs) --notrimwarn</_ExtraTrimmerArgs>
<!-- The list of hacks below should go away when we have NativeAOT.android-* packs -->
<!-- HACK: we are android-arm64, so this is required for the right path(s) to be found -->
<_OriginalRuntimeIdentifier>$(RuntimeIdentifier)</_OriginalRuntimeIdentifier>
<RuntimeIdentifier Condition=" '$(RuntimeIdentifier)' == 'android-arm64' ">linux-bionic-arm64</RuntimeIdentifier>
<RuntimeIdentifier Condition=" '$(RuntimeIdentifier)' == 'android-x64' ">linux-bionic-x64</RuntimeIdentifier>
<!-- HACK: -targetos:android results in error, so use linux -->
<_targetOS>linux</_targetOS>
<!-- HACK: prevents libSystem.Net.Security.Native.a from being added -->
<_linuxLibcFlavor>bionic</_linuxLibcFlavor>
<!-- HACK: prevents: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__start___modules" -->
<LinkerFlavor Condition=" '$(LinkerFlavor)' == '' ">lld</LinkerFlavor>
</PropertyGroup>
<SetNdkPathForIlc NdkBinDirectory="$(_NdkBinDir)" />
</Target>
<Target Name="_AndroidComputeIlcCompileInputs">
<PropertyGroup>
<!-- Turn trimmer warnings back to original value -->
<SuppressTrimAnalysisWarnings>$(_OriginalSuppressTrimAnalysisWarnings)</SuppressTrimAnalysisWarnings>
</PropertyGroup>
<ItemGroup>
<!-- Android needs a proper soname property or it will refuse to load the library -->
<LinkerArg Include="-Wl,-soname,lib$(TargetName)$(NativeBinaryExt)" />
<!-- Give ILLink's output to ILC -->
<IlcCompileInput Remove="@(IlcCompileInput)" />
<IlcCompileInput Include="$(IntermediateLinkDir)$(TargetName)$(TargetExt)" />
<_AndroidILLinkAssemblies Include="@(ManagedAssemblyToLink->'$(IntermediateLinkDir)%(Filename)%(Extension)')" Condition="Exists('$(IntermediateLinkDir)%(Filename)%(Extension)')" />
<IlcReference Remove="@(IlcReference)" />
<IlcReference Include="@(PrivateSdkAssemblies)" />
<IlcReference Include="@(_AndroidILLinkAssemblies)" />
<!-- Root *everything* for ILC, as it's already trimmed -->
<TrimmerRootAssembly Include="@(_AndroidILLinkAssemblies->'%(Filename)')" Exclude="System.Private.CoreLib" TrimMode="All" />
<!-- Passes linked assemblies to outer MSBuild tasks/targets -->
<ResolvedFileToPublish Include="@(IlcCompileInput);@(_AndroidILLinkAssemblies)" RuntimeIdentifier="$(_OriginalRuntimeIdentifier)" />
<!-- Include libc++ -->
<ResolvedFileToPublish Include="$(_NdkSysrootDir)libc++_shared.so" RuntimeIdentifier="$(_OriginalRuntimeIdentifier)" />
</ItemGroup>
</Target>
<Target Name="_AndroidAfterLinkNative" AfterTargets="LinkNative">
<PropertyGroup>
<!-- Turn $(RuntimeIdentifier) back to original value -->
<RuntimeIdentifier>$(_OriginalRuntimeIdentifier)</RuntimeIdentifier>
</PropertyGroup>
</Target>
<Target Name="_AndroidFixNativeLibraryFileName" AfterTargets="ComputeFilesToPublish">
<ItemGroup>
<!-- Fix paths to contain lib-prefix -->
<ResolvedFileToPublish Update="@(ResolvedFileToPublish)" ArchiveFileName="lib%(FileName)%(Extension)" Condition=" '%(Filename)%(Extension)' == '$(TargetName)$(NativeBinaryExt)' " />
</ItemGroup>
</Target>
</Project>