Skip to content

Commit 5e52384

Browse files
authored
Change assembler to clang in android MonoAOT (#110393)
* Change assembler to clang in android MonoAOT * Disabled NdkToolFinder task * Port changes to sample app * Allowed overwriting AsOptions
1 parent 237c759 commit 5e52384

File tree

4 files changed

+71
-38
lines changed

4 files changed

+71
-38
lines changed

src/mono/msbuild/android/build/AndroidBuild.targets

+19-20
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,21 @@
112112
<_AotOutputType>ObjectFile</_AotOutputType>
113113
</PropertyGroup>
114114

115-
<ItemGroup>
116-
<MonoAOTCompilerDefaultAotArguments Condition="'$(TargetArchitecture)' == 'arm'" Include="mtriple=armv7-linux-gnueabi" />
117-
<MonoAOTCompilerDefaultAotArguments Condition="'$(TargetArchitecture)' == 'arm64'" Include="mtriple=aarch64-linux-android" />
118-
<MonoAOTCompilerDefaultAotArguments Condition="'$(TargetArchitecture)' == 'x86'" Include="mtriple=i686-linux-android" />
119-
<MonoAOTCompilerDefaultAotArguments Condition="'$(TargetArchitecture)' == 'x64'" Include="mtriple=x86_64-linux-android" />
115+
<PropertyGroup>
116+
<_Triple Condition="'$(TargetArchitecture)' == 'arm'">armv7-linux-gnueabi</_Triple>
117+
<_Triple Condition="'$(TargetArchitecture)' == 'arm64'">aarch64-linux-android</_Triple>
118+
<_Triple Condition="'$(TargetArchitecture)' == 'x86'">i686-linux-android</_Triple>
119+
<_Triple Condition="'$(TargetArchitecture)' == 'x64'">x86_64-linux-android</_Triple>
120+
</PropertyGroup>
121+
122+
<PropertyGroup>
123+
<_AsOptions>-target $(_Triple) -c -x assembler</_AsOptions>
124+
<_LdName>clang</_LdName>
125+
<_LdOptions>-fuse-ld=lld</_LdOptions>
126+
<_AsName>clang</_AsName>
127+
</PropertyGroup>
120128

129+
<ItemGroup>
121130
<MonoAOTCompilerDefaultAotArguments Include="static" />
122131
<MonoAOTCompilerDefaultAotArguments Include="dwarfdebug" />
123132
<MonoAOTCompilerDefaultAotArguments Condition="'$(_IsLibraryMode)' == 'true'" Include="direct-icalls" />
@@ -141,19 +150,6 @@
141150
<AndroidLibraryMinApiLevel Condition="'$(AndroidLibraryMinApiLevel)' == ''">21</AndroidLibraryMinApiLevel>
142151
</PropertyGroup>
143152

144-
<NdkToolFinderTask
145-
Condition="'$(AOTWithLibraryFiles)' == 'true' or '$(_IsLibraryMode)' == 'true'"
146-
Architecture="$(TargetArchitecture)"
147-
HostOS="$(_HostOS)"
148-
MinApiLevel="$(AndroidLibraryMinApiLevel)">
149-
<Output TaskParameter="AsPrefixPath" PropertyName="_AsPrefixPath" />
150-
<Output TaskParameter="ToolPrefixPath" PropertyName="_ToolPrefixPath" />
151-
<Output TaskParameter="Triple" PropertyName="_Triple" />
152-
<Output TaskParameter="LdName" PropertyName="_LdName" />
153-
<Output TaskParameter="LdPath" PropertyName="_LdPath" />
154-
<Output TaskParameter="ClangPath" PropertyName="_ClangPath" />
155-
</NdkToolFinderTask>
156-
157153
<PropertyGroup Condition="'$(AOTWithLibraryFiles)' == 'true' or '$(_IsLibraryMode)' == 'true'">
158154
<_AsPrefixPath>$([MSBuild]::EnsureTrailingSlash('$(_AsPrefixPath)'))</_AsPrefixPath>
159155
<_ToolPrefixPath>$([MSBuild]::EnsureTrailingSlash('$(_ToolPrefixPath)'))</_ToolPrefixPath>
@@ -222,20 +218,23 @@
222218

223219
<MonoAOTCompiler
224220
AotModulesTablePath="$(_AotModuleTablePath)"
225-
AsPrefix="$(_AsPrefixPath)"
221+
AsName="$(_AsName)"
222+
AsOptions="$(_AsOptions)"
226223
Assemblies="@(_AotInputAssemblies)"
227224
CompilerBinaryPath="$(_CompilerBinaryPath)"
228225
DirectPInvokes="@(DirectPInvokes)"
229226
DirectPInvokeLists="@(DirectPInvokeLists)"
230227
EnableUnmanagedCallersOnlyMethodsExport="$(_EnableUnmanagedCallersOnlyMethodsExport)"
231228
IntermediateOutputPath="$(_MobileIntermediateOutputPath)"
229+
LdName="$(_LdName)"
230+
LdOptions="$(_LdOptions)"
232231
LibraryFormat="$(_AotLibraryFormat)"
233232
LLVMPath="$(_MonoLLVMPath)"
234233
MibcProfilePath="@(ProfiledAOTProfilePaths)"
235234
Mode="$(_AOTMode)"
236235
OutputDir="$(_MobileIntermediateOutputPath)"
237236
OutputType="$(_AotOutputType)"
238-
ToolPrefix="$(_ToolPrefixPath)"
237+
Triple="$(_Triple)"
239238
UseAotDataFile="$(_UseAotDataFile)"
240239
UseLLVM="$(MonoEnableLLVM)">
241240
<Output TaskParameter="CompiledAssemblies" ItemName="_AssembliesToBundleInternal" />

src/mono/sample/Android/AndroidSampleApp.csproj

+19-15
Original file line numberDiff line numberDiff line change
@@ -69,36 +69,40 @@
6969
<AndroidLibraryMinApiLevel Condition="'$(AndroidLibraryMinApiLevel)' == ''">21</AndroidLibraryMinApiLevel>
7070
</PropertyGroup>
7171

72-
<NdkToolFinderTask
73-
Condition="'$(AOTWithLibraryFiles)' == 'true'"
74-
Architecture="$(TargetArchitecture)"
75-
HostOS="$(_HostOS)"
76-
MinApiLevel="$(AndroidLibraryMinApiLevel)">
77-
<Output TaskParameter="AsPrefixPath" PropertyName="_AsPrefixPath" />
78-
<Output TaskParameter="ToolPrefixPath" PropertyName="_ToolPrefixPath" />
79-
<Output TaskParameter="Triple" PropertyName="_Triple" />
80-
<Output TaskParameter="LdName" PropertyName="_LdName" />
81-
<Output TaskParameter="LdPath" PropertyName="_LdPath" />
82-
<Output TaskParameter="ClangPath" PropertyName="_ClangPath" />
83-
</NdkToolFinderTask>
84-
8572
<PropertyGroup Condition="'$(AOTWithLibraryFiles)' == 'true'">
8673
<_AsPrefixPath>$([MSBuild]::EnsureTrailingSlash('$(_AsPrefixPath)'))</_AsPrefixPath>
8774
<_ToolPrefixPath>$([MSBuild]::EnsureTrailingSlash('$(_ToolPrefixPath)'))</_ToolPrefixPath>
8875
</PropertyGroup>
8976

77+
<PropertyGroup>
78+
<_Triple Condition="'$(TargetArchitecture)' == 'arm'">armv7-linux-gnueabi</_Triple>
79+
<_Triple Condition="'$(TargetArchitecture)' == 'arm64'">aarch64-linux-android</_Triple>
80+
<_Triple Condition="'$(TargetArchitecture)' == 'x86'">i686-linux-android</_Triple>
81+
<_Triple Condition="'$(TargetArchitecture)' == 'x64'">x86_64-linux-android</_Triple>
82+
</PropertyGroup>
83+
84+
<PropertyGroup>
85+
<_AsOptions>-target $(_Triple) -c -x assembler</_AsOptions>
86+
<_LdName>clang</_LdName>
87+
<_LdOptions>-fuse-ld=lld</_LdOptions>
88+
<_AsName>clang</_AsName>
89+
</PropertyGroup>
90+
9091
<MonoAOTCompiler Condition="'$(ForceAOT)' == 'true'"
9192
AotModulesTablePath="$(_AotModulesTablePath)"
92-
AsPrefix="$(_AsPrefixPath)"
93+
AsName="$(_AsName)"
94+
AsOptions="$(_AsOptions)"
9395
Assemblies="@(AotInputAssemblies)"
9496
CompilerBinaryPath="@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier','$(TargetOS)-$(TargetArchitecture.ToLowerInvariant())'))"
9597
IntermediateOutputPath="$(IntermediateOutputPath)"
98+
LdName="$(_LdName)"
99+
LdOptions="$(_LdOptions)"
96100
LibraryFormat="$(_AotLibraryFormat)"
97101
LLVMPath="$(MonoAotCrossDir)"
98102
Mode="$(_AotMode)"
99103
OutputDir="$(_MobileIntermediateOutputPath)"
100104
OutputType="$(_AotOutputType)"
101-
ToolPrefix="$(_ToolPrefixPath)"
105+
Triple="$(_Triple)"
102106
UseAotDataFile="false"
103107
UseLLVM="$(UseLLVM)">
104108
<Output TaskParameter="CompiledAssemblies" ItemName="BundleAssemblies" />

src/tasks/AotCompilerTask/MonoAOTCompiler.cs

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
@@ -232,6 +232,16 @@ public class MonoAOTCompiler : Microsoft.Build.Utilities.Task
232232
/// </summary>
233233
public string? ToolPrefix { get; set; }
234234

235+
/// <summary>
236+
/// Name of the assembler tool ran by the AOT compiler.
237+
/// </summary>
238+
public string? AsName { get; set; }
239+
240+
/// <summary>
241+
/// Passes as-options to the AOT compiler
242+
/// </summary>
243+
public string? AsOptions { get; set; }
244+
235245
/// <summary>
236246
/// Prepends a prefix to the name of the assembler (as) tool ran by the AOT compiler.
237247
/// </summary>
@@ -279,6 +289,11 @@ public class MonoAOTCompiler : Microsoft.Build.Utilities.Task
279289
/// </summary>
280290
public string? LdFlags { get; set; }
281291

292+
/// <summary>
293+
/// Passes ld-options to the AOT compiler
294+
/// </summary>
295+
public string? LdOptions { get; set; }
296+
282297
/// <summary>
283298
/// Specify WorkingDirectory for the AOT compiler
284299
/// </summary>
@@ -739,6 +754,16 @@ private PrecompileArguments GetPrecompileArgumentsFor(ITaskItem assemblyItem, st
739754
aotArgs.Add($"tool-prefix={ToolPrefix}");
740755
}
741756

757+
if (!string.IsNullOrEmpty(AsName))
758+
{
759+
aotArgs.Add($"as-name={AsName}");
760+
}
761+
762+
if (!string.IsNullOrEmpty(AsOptions))
763+
{
764+
aotArgs.Add($"as-options={AsOptions}");
765+
}
766+
742767
if (!string.IsNullOrEmpty(AsPrefix))
743768
{
744769
aotArgs.Add($"as-prefix={AsPrefix}");
@@ -954,6 +979,11 @@ private PrecompileArguments GetPrecompileArgumentsFor(ITaskItem assemblyItem, st
954979
aotArgs.Add($"ld-flags={LdFlags}");
955980
}
956981

982+
if (!string.IsNullOrEmpty(LdOptions))
983+
{
984+
aotArgs.Add($"ld-options={LdOptions}");
985+
}
986+
957987
// we need to quote the entire --aot arguments here to make sure it is parsed
958988
// on Windows as one argument. Otherwise it will be split up into multiple
959989
// values, which wont work.

src/tasks/MobileBuildTasks/Android/Ndk/NdkTools.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ public string ClangPath
101101

102102
private void ValidateRequiredProps(string hostOS)
103103
{
104-
if (Ndk.NdkVersion.Main.Major != 23)
104+
if (Ndk.NdkVersion.Main.Major != 27)
105105
{
106-
throw new Exception($"NDK 23 is required. An unsupported NDK version was found ({Ndk.NdkVersion.Main.Major}).");
106+
throw new Exception($"NDK 27 is required. An unsupported NDK version was found ({Ndk.NdkVersion.Main.Major}).");
107107
}
108108

109109
try

0 commit comments

Comments
 (0)