Skip to content

Commit 555da9f

Browse files
[release/9.0-staging] Change assembler to clang in android MonoAOT (#110812)
* Change assembler to clang in android MonoAOT * Disabled NdkToolFinder task * Port changes to sample app * Allowed overwriting AsOptions --------- Co-authored-by: Jeremi Kurdek <jkurdek@gmail.com>
1 parent 9ee881a commit 555da9f

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>
@@ -221,20 +217,23 @@
221217

222218
<MonoAOTCompiler
223219
AotModulesTablePath="$(_AotModuleTablePath)"
224-
AsPrefix="$(_AsPrefixPath)"
220+
AsName="$(_AsName)"
221+
AsOptions="$(_AsOptions)"
225222
Assemblies="@(_AotInputAssemblies)"
226223
CompilerBinaryPath="$(_CompilerBinaryPath)"
227224
DirectPInvokes="@(DirectPInvokes)"
228225
DirectPInvokeLists="@(DirectPInvokeLists)"
229226
EnableUnmanagedCallersOnlyMethodsExport="$(_EnableUnmanagedCallersOnlyMethodsExport)"
230227
IntermediateOutputPath="$(_MobileIntermediateOutputPath)"
228+
LdName="$(_LdName)"
229+
LdOptions="$(_LdOptions)"
231230
LibraryFormat="$(_AotLibraryFormat)"
232231
LLVMPath="$(_MonoLLVMPath)"
233232
MibcProfilePath="@(ProfiledAOTProfilePaths)"
234233
Mode="$(_AOTMode)"
235234
OutputDir="$(_MobileIntermediateOutputPath)"
236235
OutputType="$(_AotOutputType)"
237-
ToolPrefix="$(_ToolPrefixPath)"
236+
Triple="$(_Triple)"
238237
UseAotDataFile="$(_UseAotDataFile)"
239238
UseLLVM="$(MonoEnableLLVM)">
240239
<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;
@@ -230,6 +230,16 @@ public class MonoAOTCompiler : Microsoft.Build.Utilities.Task
230230
/// </summary>
231231
public string? ToolPrefix { get; set; }
232232

233+
/// <summary>
234+
/// Name of the assembler tool ran by the AOT compiler.
235+
/// </summary>
236+
public string? AsName { get; set; }
237+
238+
/// <summary>
239+
/// Passes as-options to the AOT compiler
240+
/// </summary>
241+
public string? AsOptions { get; set; }
242+
233243
/// <summary>
234244
/// Prepends a prefix to the name of the assembler (as) tool ran by the AOT compiler.
235245
/// </summary>
@@ -277,6 +287,11 @@ public class MonoAOTCompiler : Microsoft.Build.Utilities.Task
277287
/// </summary>
278288
public string? LdFlags { get; set; }
279289

290+
/// <summary>
291+
/// Passes ld-options to the AOT compiler
292+
/// </summary>
293+
public string? LdOptions { get; set; }
294+
280295
/// <summary>
281296
/// Specify WorkingDirectory for the AOT compiler
282297
/// </summary>
@@ -741,6 +756,16 @@ private PrecompileArguments GetPrecompileArgumentsFor(ITaskItem assemblyItem, st
741756
aotArgs.Add($"tool-prefix={ToolPrefix}");
742757
}
743758

759+
if (!string.IsNullOrEmpty(AsName))
760+
{
761+
aotArgs.Add($"as-name={AsName}");
762+
}
763+
764+
if (!string.IsNullOrEmpty(AsOptions))
765+
{
766+
aotArgs.Add($"as-options={AsOptions}");
767+
}
768+
744769
if (!string.IsNullOrEmpty(AsPrefix))
745770
{
746771
aotArgs.Add($"as-prefix={AsPrefix}");
@@ -956,6 +981,11 @@ private PrecompileArguments GetPrecompileArgumentsFor(ITaskItem assemblyItem, st
956981
aotArgs.Add($"ld-flags={LdFlags}");
957982
}
958983

984+
if (!string.IsNullOrEmpty(LdOptions))
985+
{
986+
aotArgs.Add($"ld-options={LdOptions}");
987+
}
988+
959989
// we need to quote the entire --aot arguments here to make sure it is parsed
960990
// on Windows as one argument. Otherwise it will be split up into multiple
961991
// 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)