-
Notifications
You must be signed in to change notification settings - Fork 561
[net11.0] Support multiple R2R images for ios/tvos apps #25077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: net11.0
Are you sure you want to change the base?
Changes from 3 commits
af34218
f2445b2
1e817d0
a926910
df29933
955b20c
8cea1fd
96ec7b6
a1aec4b
550f56d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| using System.IO; | ||
| using System.Text; | ||
|
|
||
| using Microsoft.Build.Framework; | ||
|
|
||
| #nullable enable | ||
|
|
||
| namespace Xamarin.MacDev.Tasks { | ||
| public class GenerateR2RModuleRegistration : XamarinTask { | ||
|
|
||
| #region Inputs | ||
| [Required] | ||
| public ITaskItem [] R2RModules { get; set; } = []; | ||
|
|
||
| [Required] | ||
| public string OutputFile { get; set; } = ""; | ||
| #endregion | ||
|
|
||
| public override bool Execute () | ||
| { | ||
| var sb = new StringBuilder (); | ||
|
|
||
| sb.AppendLine ("#include \"xamarin/xamarin.h\""); | ||
| sb.AppendLine (); | ||
|
|
||
| foreach (var module in R2RModules) { | ||
| var symbolName = module.GetMetadata ("SymbolName"); | ||
| sb.AppendLine ($"extern void* {symbolName};"); | ||
| } | ||
|
|
||
| sb.AppendLine (); | ||
| sb.AppendLine ("static struct xamarin_r2r_module r2r_module_entries [] = {"); | ||
|
|
||
| foreach (var module in R2RModules) { | ||
| var moduleName = module.GetMetadata ("ModuleName"); | ||
| var symbolName = module.GetMetadata ("SymbolName"); | ||
| sb.AppendLine ($"\t{{ \"{moduleName}\", &{symbolName} }},"); | ||
| } | ||
|
|
||
| sb.AppendLine ("};"); | ||
| sb.AppendLine (); | ||
|
|
||
| sb.AppendLine ("__attribute__ ((constructor))"); | ||
| sb.AppendLine ("static void xamarin_register_r2r_modules ()"); | ||
| sb.AppendLine ("{"); | ||
| sb.AppendLine ("\txamarin_r2r_modules = r2r_module_entries;"); | ||
| sb.AppendLine ("\txamarin_r2r_module_count = sizeof (r2r_module_entries) / sizeof (r2r_module_entries [0]);"); | ||
| sb.AppendLine ("}"); | ||
|
|
||
| var content = sb.ToString (); | ||
| var outputDir = Path.GetDirectoryName (OutputFile); | ||
| if (!string.IsNullOrEmpty (outputDir)) | ||
| Directory.CreateDirectory (outputDir); | ||
|
|
||
| if (!File.Exists (OutputFile) || File.ReadAllText (OutputFile) != content) | ||
| File.WriteAllText (OutputFile, content); | ||
|
|
||
| return !Log.HasLoggedErrors; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,6 +81,8 @@ | |
| enum XamarinNativeLinkMode xamarin_libmono_native_link_mode = XamarinNativeLinkModeStaticObject; | ||
| const char **xamarin_runtime_libraries = NULL; | ||
| void *xamarin_rtr_header = NULL; | ||
| struct xamarin_r2r_module *xamarin_r2r_modules = NULL; | ||
| int xamarin_r2r_module_count = 0; | ||
|
|
||
| /* Callbacks */ | ||
|
|
||
|
|
@@ -2439,9 +2441,25 @@ -(struct NSObjectData*) xamarinGetNSObjectData; | |
| if (!context || !data || !context->assembly_path || !context->owner_composite_name) | ||
| return false; | ||
|
|
||
| void* r2r_header = xamarin_rtr_header; | ||
| void* r2r_header = NULL; | ||
|
|
||
| // Multi-module: look up by owner_composite_name | ||
| if (xamarin_r2r_modules != NULL && xamarin_r2r_module_count > 0) { | ||
| for (int i = 0; i < xamarin_r2r_module_count; i++) { | ||
| if (strcmp (xamarin_r2r_modules [i].name, context->owner_composite_name) == 0) { | ||
| r2r_header = xamarin_r2r_modules [i].header; | ||
| break; | ||
| } | ||
| } | ||
| if (r2r_header == NULL) | ||
| return false; | ||
| } else { | ||
| // Single-module fallback for backward compatibility | ||
| r2r_header = xamarin_rtr_header; | ||
| } | ||
|
||
|
|
||
| if (r2r_header == NULL) | ||
| xamarin_assertion_message ("Failed to find the RTR_HEADER symbol."); | ||
| return false; | ||
|
|
||
| Dl_info info; | ||
| if (dladdr (r2r_header, &info) == 0) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,14 @@ | ||
| AppBundleSize: 3,617,184 bytes (3,532.4 KB = 3.4 MB) | ||
| AppBundleSize: 3,622,195 bytes (3,537.3 KB = 3.5 MB) | ||
| # The following list of files and their sizes is just informational / for review, and isn't used in the test: | ||
| _CodeSignature/CodeResources: 3,997 bytes (3.9 KB = 0.0 MB) | ||
| archived-expanded-entitlements.xcent: 384 bytes (0.4 KB = 0.0 MB) | ||
| Info.plist: 1,134 bytes (1.1 KB = 0.0 MB) | ||
| Microsoft.iOS.dll: 153,088 bytes (149.5 KB = 0.1 MB) | ||
| Info.plist: 1,161 bytes (1.1 KB = 0.0 MB) | ||
| Microsoft.iOS.dll: 154,112 bytes (150.5 KB = 0.1 MB) | ||
| PkgInfo: 8 bytes (0.0 KB = 0.0 MB) | ||
| runtimeconfig.bin: 1,405 bytes (1.4 KB = 0.0 MB) | ||
| SizeTestApp: 2,391,264 bytes (2,335.2 KB = 2.3 MB) | ||
| SizeTestApp: 2,391,632 bytes (2,335.6 KB = 2.3 MB) | ||
| SizeTestApp.dll: 7,680 bytes (7.5 KB = 0.0 MB) | ||
| System.Private.CoreLib.aotdata.arm64: 41,392 bytes (40.4 KB = 0.0 MB) | ||
| System.Private.CoreLib.dll: 1,003,520 bytes (980.0 KB = 1.0 MB) | ||
| System.Private.CoreLib.aotdata.arm64: 41,400 bytes (40.4 KB = 0.0 MB) | ||
| System.Private.CoreLib.dll: 1,007,104 bytes (983.5 KB = 1.0 MB) | ||
| System.Runtime.dll: 5,120 bytes (5.0 KB = 0.0 MB) | ||
| System.Runtime.InteropServices.dll: 8,192 bytes (8.0 KB = 0.0 MB) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| AppBundleSize: 2,486,550 bytes (2,428.3 KB = 2.4 MB) | ||
| AppBundleSize: 2,486,702 bytes (2,428.4 KB = 2.4 MB) | ||
| # The following list of files and their sizes is just informational / for review, and isn't used in the test: | ||
| _CodeSignature/CodeResources: 2,589 bytes (2.5 KB = 0.0 MB) | ||
| archived-expanded-entitlements.xcent: 384 bytes (0.4 KB = 0.0 MB) | ||
| Info.plist: 1,169 bytes (1.1 KB = 0.0 MB) | ||
| Info.plist: 1,161 bytes (1.1 KB = 0.0 MB) | ||
| PkgInfo: 8 bytes (0.0 KB = 0.0 MB) | ||
| runtimeconfig.bin: 1,808 bytes (1.8 KB = 0.0 MB) | ||
| SizeTestApp: 2,480,592 bytes (2,422.5 KB = 2.4 MB) | ||
| SizeTestApp: 2,480,752 bytes (2,422.6 KB = 2.4 MB) |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -344,11 +344,6 @@ void GenerateMainImpl (StringWriter sw, Abi abi) | |||||||||
| sw.WriteLine (); | ||||||||||
| sw.WriteLine (assembly_externs); | ||||||||||
|
|
||||||||||
| if (app.PublishReadyToRun == true) { | ||||||||||
| sw.WriteLine ("extern void* RTR_HEADER;"); | ||||||||||
| sw.WriteLine (); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| sw.WriteLine ("void xamarin_register_modules_impl ()"); | ||||||||||
| sw.WriteLine ("{"); | ||||||||||
| sw.WriteLine (assembly_aot_modules); | ||||||||||
|
|
@@ -440,8 +435,6 @@ void GenerateMainImpl (StringWriter sw, Abi abi) | |||||||||
| sw.WriteLine ("\txamarin_runtime_configuration_name = {0};", string.IsNullOrEmpty (app.RuntimeConfigurationFile) ? "NULL" : $"\"{app.RuntimeConfigurationFile}\""); | ||||||||||
| if (app.Registrar == RegistrarMode.ManagedStatic) | ||||||||||
| sw.WriteLine ("\txamarin_set_is_managed_static_registrar (true);"); | ||||||||||
|
||||||||||
| sw.WriteLine ("\txamarin_set_is_managed_static_registrar (true);"); | |
| sw.WriteLine ("\txamarin_set_is_managed_static_registrar (true);"); | |
| if (app.XamarinRuntime == XamarinRuntime.NativeAOT) | |
| sw.WriteLine ("\txamarin_rtr_header = &RTR_HEADER;"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This task writes out C/C++ code using MSBuild item metadata without validating or escaping it. If
ModuleNameorSymbolNamemetadata is missing/empty, the generated file will contain invalid declarations/initializers, and ifModuleNamecontains characters that need escaping in a C string literal (e.g.\or"), the generated source will not compile. Consider validating required metadata for every item (and logging an MSBuild error when missing) and C-escapingmoduleNamebefore embedding it into the string literal.