[net11.0] Support multiple R2R images for ios/tvos apps#25077
[net11.0] Support multiple R2R images for ios/tvos apps#25077rolfbjarne merged 34 commits intonet11.0from
Conversation
Instead of linking all R2R .o files into a single large dylib/framework, create a separate framework (or dylib) for each R2R .o file. This way, when only one R2R input changes, only that module's framework needs to be relinked — significantly improving incremental build times. Each R2R .o file exports an RTR_HEADER symbol. To avoid collisions when multiple modules are loaded, each module's dylib uses the linker flags -Wl,-alias,_RTR_HEADER,_RTR_HEADER_<module> and -Wl,-unexported_symbol,_RTR_HEADER to export a uniquely-named alias. A new MSBuild task (GenerateR2RModuleRegistration) generates a native registration file (r2r_modules.mm) that maps module names to their header pointers. The file is compiled into the main executable and uses __attribute__((constructor)) to register the modules before main(). The runtime's xamarin_get_native_code_data callback now iterates the module table to find the correct R2R header for each owner_composite_name, with a fallback to the single xamarin_rtr_header for backward compat. Changes: - runtime/xamarin/main.h: Add struct xamarin_r2r_module and externs - runtime/runtime.m: Multi-module lookup in get_native_code_data - tools/common/Target.cs: Remove single RTR_HEADER from generated main.mm - msbuild/.../GenerateR2RModuleRegistration.cs: New task - dotnet/targets/Microsoft.Sdk.R2R.targets: Per-module framework/dylib creation with symbol renaming - dotnet/targets/Xamarin.Shared.Sdk.targets: Handle multiple R2R frameworks in post-processing Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR changes the ReadyToRun (R2R) packaging/linking pipeline so iOS/tvOS (framework) and macOS/Mac Catalyst (dylib) builds produce one native image per R2R object file, enabling faster incremental relinks, and adds runtime/MSBuild plumbing to register and resolve per-module R2R headers safely.
Changes:
- Introduce a per-module R2R registration table (
xamarin_r2r_modules) and look it up at runtime when CoreCLR requests native code data. - Add an MSBuild task to generate a native registration source file (
r2r_modules.mm) and update targets to create per-module frameworks/dylibs withRTR_HEADERsymbol aliasing. - Update post-processing collection to handle multiple R2R frameworks.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/common/Target.cs | Removes legacy single-module RTR_HEADER extern/assignment from generated main. |
| runtime/xamarin/main.h | Adds xamarin_r2r_module struct and externs for module table + count. |
| runtime/runtime.m | Implements per-module lookup for xamarin_get_native_code_data with a single-module fallback path. |
| msbuild/Xamarin.MacDev.Tasks/Tasks/GenerateR2RModuleRegistration.cs | New MSBuild task to generate r2r_modules.mm registration source. |
| dotnet/targets/Microsoft.Sdk.R2R.targets | Updates R2R targets to create one framework/dylib per module and generate registration file. |
| dotnet/targets/Xamarin.Shared.Sdk.targets | Updates post-processing item collection to include per-module R2R frameworks. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
/review |
|
✅ .NET for Apple Platforms PR Reviewer completed successfully! Code review complete. The PR successfully addresses the multi-module R2R implementation. Previous review concerns have been resolved: incremental build Inputs/Outputs are now properly configured (lines 243-244, 323-324 in Microsoft.Sdk.R2R.targets), metadata validation has been added to GenerateR2RModuleRegistration.cs (lines 36-39, 49-54), and the BundleStructureTest has been updated to handle per-module R2R frameworks. CI failures appear to be test infrastructure issues unrelated to the code changes (dotnettests_ios and dotnettests_tvos failures). The implementation correctly generates per-module frameworks with unique symbols, registers them via constructor, and provides proper runtime lookup. No critical issues found that would block merging. |
…CLR iOS/tvOS The app assembly framework changed from MySimpleApp.framework/MySimpleApp to MySimpleApp.r2r.framework/MySimpleApp.r2r for CoreCLR on iOS and tvOS, matching the existing MacCatalyst convention. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
✅ [CI Build #3a66d43] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #3a66d43] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [CI Build #3a66d43] Build passed (Build macOS tests) ✅Pipeline on Agent |
🔥 [CI Build #3a66d43] Test results 🔥Test results❌ Tests failed on VSTS: test results 0 tests crashed, 24 tests failed, 137 tests passed. Failures❌ linker tests22 tests failed, 22 tests passed.Failed tests
|
🚀 [CI Build #3a66d43] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 161 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Note
This PR was generated with the help of GitHub Copilot.
Instead of linking all R2R .o files into a single large dylib/framework, create a separate framework (or dylib) for each R2R .o file. This way, when only one R2R input changes, only that module's framework needs to be relinked — significantly improving incremental build times.
Each R2R .o file exports an RTR_HEADER symbol. To avoid collisions when multiple modules are loaded, each module's dylib uses the linker flags
-Wl,-alias,_RTR_HEADER,_RTR_HEADER_<module>and-Wl,-unexported_symbol,_RTR_HEADERto export a uniquely-named alias.A new MSBuild task (GenerateR2RModuleRegistration) generates a native registration file (r2r_modules.mm) that maps module names to their header pointers. The file is compiled into the main executable and uses
__attribute__((constructor))to register the modules before main().The runtime's xamarin_get_native_code_data callback now iterates the module table to find the correct R2R header for each owner_composite_name, with a fallback to the single xamarin_rtr_header for backward compat.
Changes:
Contributes to dotnet/runtime#126194
This is a recreation of #25072 from origin (due to CI requirements).