Skip to content

Conversation

@rolfbjarne
Copy link
Member

@rolfbjarne rolfbjarne commented Dec 12, 2025

Description

This PR adds ReadyToRun support for CoreCLR.

Changes

  • Introduce ReadyToRun configuration in Xamarin.Shared.Sdk.props.
  • Add ReadyToRun targets to Microsoft.Shared.R2R.targets (a new file).
  • Update bundler environment variables in Xamarin.Shared.Sdk.targets to support ReadyToRun
  • Add host_runtime_contract.h to the build process in Makefile
  • Update coreclr-bridge.m and runtime.m for R2R image handling and logging
  • Update runtime.h to reflect changes in the xamarin_pinvoke_override function signature
  • Add support in the CompileAppManifest target to create the Info.plist for frameworks.
  • Enable CoreCLR tests run R2R.
  • Add a test variation for CoreCLR for the app size test.

Fixes dotnet/runtime#120052.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds ReadyToRun (R2R) support for CoreCLR on Apple mobile platforms (iOS, tvOS). ReadyToRun is an ahead-of-time (AOT) compilation technology that improves app startup performance by pre-compiling managed assemblies to native code. The implementation involves integrating CoreCLR's R2R infrastructure through a new host runtime contract interface, generating composite R2R images into frameworks or dynamic libraries, and enabling the feature by default for non-macOS CoreCLR builds.

Key Changes

  • Added infrastructure to pass PublishReadyToRun configuration through the build pipeline
  • Implemented native code integration for R2R via the host_runtime_contract interface
  • Created MSBuild targets to build R2R composite images and link them into frameworks or dylibs
  • Removed libclrjit.dylib dependency when R2R is enabled (replaced with R2R interpretation)

Reviewed changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tools/dotnet-linker/LinkerConfiguration.cs Adds parsing for PublishReadyToRun configuration property
tools/common/Target.cs Generates extern declarations for RTR_HEADER symbol in generated main.m file
tools/common/Application.cs Adds PublishReadyToRun nullable boolean property to Application class
runtime/xamarin/runtime.h Changes xamarin_pinvoke_override return type to const void*
runtime/xamarin/main.h Declares xamarin_rtr_header global variable
runtime/runtime.m Implements R2R integration via host_runtime_contract and adds dyld image size calculation
runtime/coreclr-bridge.m Fixes logging bug where wrong variable was being accessed
runtime/Makefile Updates to download host_runtime_contract.h header from dotnet/runtime
runtime/.gitignore Ignores the downloaded host_runtime_contract.h file
msbuild/Xamarin.MacDev.Tasks/Tasks/CompileAppManifest.cs Adds IsFramework property and CFBundlePackageType support for frameworks
dotnet/targets/Xamarin.Shared.Sdk.targets Passes PublishReadyToRun to linker, removes libclrjit.dylib, imports R2R targets
dotnet/targets/Xamarin.Shared.Sdk.props Sets R2R as default for CoreCLR mobile builds, adds environment variable fallback
dotnet/targets/Microsoft.Sdk.R2R.targets New file implementing R2R composite image building and framework/dylib creation
dotnet/Makefile Includes new Microsoft.Sdk.R2R.targets in SDK package
tests/dotnet/UnitTests/AppSizeTest.cs Removes test ignore attribute and fixes assertion message logic
tests/dotnet/UnitTests/expected/iOS-CoreCLR-R2R-size.txt New baseline for R2R app sizes
tests/dotnet/UnitTests/expected/iOS-CoreCLR-Interpreter-size.txt Updated baseline reflecting removal of libclrjit.dylib

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #55f9501] Tests on macOS M1 - Mac Ventura (13) passed 💻

All tests on macOS M1 - Mac Ventura (13) passed.

Pipeline on Agent
Hash: 55f95010f0e7d43d3303265aa29fff58fd313896 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

rolfbjarne and others added 2 commits January 8, 2026 09:30
…dyToRun compiler's composite output.

And then link with and bundle the .framework or .dylib we created.
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne rolfbjarne force-pushed the dev/rolf/coreclr-r2r branch from f5899ab to 8824e4e Compare January 8, 2026 11:54
@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #8824e4e] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 8824e4ed9abae37f54396ae756c0193a5fbe6bc6 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build #8824e4e] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 8824e4ed9abae37f54396ae756c0193a5fbe6bc6 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🔥 Failed to compare API and create generator diff 🔥

Error: 'make' failed for the hash aced0a1.

Pipeline on Agent
Hash: 8824e4ed9abae37f54396ae756c0193a5fbe6bc6 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #8824e4e] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 8824e4ed9abae37f54396ae756c0193a5fbe6bc6 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #8824e4e] Tests on macOS X64 - Mac Sonoma (14) passed 💻

All tests on macOS X64 - Mac Sonoma (14) passed.

Pipeline on Agent
Hash: 8824e4ed9abae37f54396ae756c0193a5fbe6bc6 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #8824e4e] Tests on macOS arm64 - Mac Sequoia (15) passed 💻

All tests on macOS arm64 - Mac Sequoia (15) passed.

Pipeline on Agent
Hash: 8824e4ed9abae37f54396ae756c0193a5fbe6bc6 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [CI Build #8824e4e] Tests on macOS arm64 - Mac Tahoe (26) failed ❌

Tests on macOS arm64 - Mac Tahoe (26) failed for unknown reasons.

Pipeline on Agent
Hash: 8824e4ed9abae37f54396ae756c0193a5fbe6bc6 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🔥 [CI Build #8824e4e] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 1 tests failed, 116 tests passed.

Failures

❌ monotouch tests (MacCatalyst)

1 tests failed, 10 tests passed.

Failed tests

  • monotouch-test/Mac Catalyst/Release (managed static registrar): Failed (Test run failed.
    Tests run: 3493 Passed: 3291 Inconclusive: 13 Failed: 1 Ignored: 201)

Html Report (VSDrops) Download

Successes

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 9 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 9 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 9 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 8824e4ed9abae37f54396ae756c0193a5fbe6bc6 [PR build]

<CreateR2RFramework Condition="'$(CreateR2RFramework)' == '' ">true</CreateR2RFramework>
<CreateR2RDylib Condition="'$(CreateR2RDylib)' == '' And '$(CreateR2RFramework)' != 'true'">true</CreateR2RDylib>

<FilterReadyToRunAssemblies Condition="'$(FilterReadyToRunAssemblies)' == '' And '$(Configuration)' == 'Release'">true</FilterReadyToRunAssemblies>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think user assemblies should be excluded in Debug build to allow for debugging, not in Release build.

BeforeTargets="ResolveReadyToRunCompilers">
<ItemGroup>
<_ResolvedAssembliesToPublish Include="@(ResolvedFileToPublish)" Condition="'%(Extension)' == '.dll' And '%(ResolvedFileToPublish.Culture)' == '' And '%(ResolvedFileToPublish.DestinationSubDirectory)' == ''" />
<_NonUserAssemblies
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this include iOS SDK and MAUI assemblies?

<_LibMonoLinkMode Condition="'$(_LibMonoLinkMode)' == ''">static</_LibMonoLinkMode>
<_LibMonoLinkMode Condition="'$(_LibMonoLinkMode)' == '' And '$(_PlatformName)' == 'MacCatalyst' And '$(UseMonoRuntime)' == 'true'">static</_LibMonoLinkMode>
<!-- we can't use dylibs for mobile apps when building for device, because the App Store won't allow it -->
<_LibMonoLinkMode Condition="'$(_LibMonoLinkMode)' == '' And '$(ComputedPlatform)' == 'iPhone'">static</_LibMonoLinkMode>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it convert dylib to a framework instead of static linking?

archived-expanded-entitlements.xcent: 384 bytes (0.4 KB = 0.0 MB)
Frameworks/libclrjit.framework/_CodeSignature/CodeResources: 1,798 bytes (1.8 KB = 0.0 MB)
Frameworks/libclrjit.framework/Info.plist: 808 bytes (0.8 KB = 0.0 MB)
Frameworks/libclrjit.framework/libclrjit: 3,157,152 bytes (3,083.2 KB = 3.0 MB)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be excluded from the app bundle.

<_R2RFrameworkSymlinks Include="$(_R2RFrameworkPath)/Versions/Current" SymlinkTo="A" />
</ItemGroup>

<!-- write a hash of all the relevant input so that we can force a re-link if necessary -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc: @simonrozsival Caching of R2R image on iOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants