Skip to content

Commit a9fac22

Browse files
Enable R2R compilation for CoreCLR Debug builds
Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
1 parent 214a32a commit a9fac22

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.CoreCLR.targets

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ This file contains the CoreCLR-specific MSBuild logic for .NET for Android.
1313
</PropertyGroup>
1414
<!-- Properties for $(OutputType)=Exe (Android Applications) -->
1515
<PropertyGroup Condition=" '$(AndroidApplication)' == 'true' ">
16-
<!-- Default to R2R Composite for CoreCLR Release mode -->
17-
<PublishReadyToRun Condition=" '$(PublishReadyToRun)' == '' and '$(Configuration)' == 'Release' ">true</PublishReadyToRun>
18-
<PublishReadyToRunComposite Condition=" '$(PublishReadyToRunComposite)' == '' and '$(PublishReadyToRun)' == 'true' ">true</PublishReadyToRunComposite>
16+
<!--
17+
Enable R2R by default for CoreCLR applications:
18+
- Release builds: Use composite R2R for best startup performance
19+
- Debug builds: Use individual R2R to improve runtime performance while debugging
20+
Set PublishReadyToRun=false to disable R2R compilation.
21+
-->
22+
<PublishReadyToRun Condition=" '$(PublishReadyToRun)' == '' ">true</PublishReadyToRun>
23+
<!-- Composite R2R only for Release builds - it's slower to compile but faster at runtime -->
24+
<PublishReadyToRunComposite Condition=" '$(PublishReadyToRunComposite)' == '' and '$(PublishReadyToRun)' == 'true' and '$(Configuration)' == 'Release' ">true</PublishReadyToRunComposite>
1925
<_IsPublishing Condition=" '$(_IsPublishing)' == '' and '$(PublishReadyToRun)' == 'true' ">true</_IsPublishing>
2026
<AllowReadyToRunWithoutRuntimeIdentifier Condition=" '$(PublishReadyToRun)' == 'true' and '$(RuntimeIdentifiers)' != '' ">true</AllowReadyToRunWithoutRuntimeIdentifier>
2127
</PropertyGroup>

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,37 @@ public void BasicApplicationPublishReadyToRun ([Values] bool isComposite, [Value
150150
$"ReadyToRun image not found in {assemblyName}.dll! ManagedNativeHeaderDirectory should not be empty!");
151151
}
152152

153+
[Test]
154+
public void DebugBuildPublishReadyToRun ([Values ("android-x64", "android-arm64")] string rid)
155+
{
156+
var proj = new XamarinAndroidApplicationProject {
157+
IsRelease = false, // Debug build - R2R is now enabled by default for CoreCLR
158+
};
159+
160+
proj.SetRuntime (AndroidRuntime.CoreCLR);
161+
proj.SetProperty ("RuntimeIdentifier", rid);
162+
proj.SetProperty ("AndroidEnableAssemblyCompression", "false");
163+
// Composite R2R should NOT be enabled by default for Debug builds
164+
proj.SetProperty ("PublishReadyToRunComposite", "false");
165+
166+
var b = CreateApkBuilder ();
167+
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
168+
169+
var assemblyName = proj.ProjectName;
170+
var apk = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath, rid, $"{proj.PackageName}-Signed.apk");
171+
FileAssert.Exists (apk);
172+
173+
var helper = new ArchiveAssemblyHelper (apk, true);
174+
var abi = MonoAndroidHelper.RidToAbi (rid);
175+
Assert.IsTrue (helper.Exists ($"assemblies/{abi}/{assemblyName}.dll"), $"{assemblyName}.dll should exist in apk!");
176+
177+
using var stream = helper.ReadEntry ($"assemblies/{assemblyName}.dll");
178+
stream.Position = 0;
179+
using var peReader = new System.Reflection.PortableExecutable.PEReader (stream);
180+
Assert.IsTrue (peReader.PEHeaders.CorHeader.ManagedNativeHeaderDirectory.Size > 0,
181+
$"ReadyToRun image not found in Debug build {assemblyName}.dll! ManagedNativeHeaderDirectory should not be empty!");
182+
}
183+
153184
[Test]
154185
public void NativeAOT ()
155186
{

0 commit comments

Comments
 (0)