Add support for NativeAOT on macOS (#18765)

Co-authored-by: Filip Navara <navara@emclient.com>
This commit is contained in:
Rolf Bjarne Kvinge 2023-08-30 10:38:43 +02:00 коммит произвёл GitHub
Родитель f2349d0f50
Коммит d50f52df06
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 38 добавлений и 6 удалений

Просмотреть файл

@ -621,6 +621,12 @@ namespace ObjCRuntime {
// For XM it will also register all assemblies loaded in the current appdomain.
internal static void RegisterAssemblies ()
{
#if NET
if (IsNativeAOT) {
return;
}
#endif
#if PROFILE
var watch = new Stopwatch ();
#endif

Просмотреть файл

@ -194,11 +194,13 @@ namespace ObjCRuntime {
FrameworksPath = Path.Combine (basePath, "Frameworks");
}
#if !NET
[Preserve]
static IntPtr GetNullableType (IntPtr type)
{
return AllocGCHandle (Registrar.GetNullableType ((Type) GetGCHandleTarget (type)!));
}
#endif // !NET
#endif // !COREBUILD
}
}

Просмотреть файл

@ -2246,7 +2246,8 @@ namespace MonoTouchFixtures.ObjCRuntime {
}
}
#if __MACOS__
// This test uses Assembly.LoadFrom, which isn't supported with NativeAOT
#if __MACOS__ && !NATIVEAOT
[Test]
public void CustomUserTypeWithDynamicallyLoadedAssembly ()
{

Просмотреть файл

@ -18,7 +18,11 @@ namespace Xamarin {
static Cache ()
{
#if NATIVEAOT
root = Path.Combine (Path.GetDirectoryName (Environment.ProcessPath)!, "tmp-test-dir");
#else
root = Path.Combine (Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly ().Location)!, "tmp-test-dir");
#endif
if (Directory.Exists (root)) {
var movedRoot = root + DateTime.UtcNow.Ticks.ToString () + "-deletion-in-progress";
// The temporary directory can be big, and it can take a while to clean it out.

Просмотреть файл

@ -169,9 +169,8 @@ namespace Xharness.Jenkins {
if (test.Platform != TestPlatform.MacCatalyst) {
yield return new TestData { Variation = "Debug (static registrar)", Registrar = "static", Debug = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.Mac), };
yield return new TestData { Variation = "Debug (static registrar, ARM64)", Registrar = "static", Debug = true, Profiling = false, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.Mac) || !mac_supports_arm64, RuntimeIdentifier = arm64_runtime_identifier, };
// Pending: We need the NativeAOT's runtime bits to ship using runtime packs for macOS (https://github.com/dotnet/runtime/issues/87060) before we can enable this
// yield return new TestData { Variation = "Release (NativeAOT)", Debug = false, PublishAot = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.Mac), Defines = "NATIVEAOT", LinkMode = "Full" };
// yield return new TestData { Variation = "Release (NativeAOT, ARM64)", Debug = false, PublishAot = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.Mac) || !mac_supports_arm64, Defines = "NATIVEAOT", RuntimeIdentifier = arm64_runtime_identifier, LinkMode = "Full" };
yield return new TestData { Variation = "Release (NativeAOT, ARM64)", Debug = false, PublishAot = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.Mac) || !mac_supports_arm64, Defines = "NATIVEAOT", RuntimeIdentifier = arm64_runtime_identifier, LinkMode = "Full" };
yield return new TestData { Variation = "Release (NativeAOT, x64)", Debug = false, PublishAot = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.Mac), Defines = "NATIVEAOT", RuntimeIdentifier = "osx-x64", LinkMode = "Full" };
}
if (test.Platform == TestPlatform.MacCatalyst) {
yield return new TestData { Variation = "Release (ARM64, LLVM)", Debug = false, UseLlvm = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.MacCatalyst) || !mac_supports_arm64, RuntimeIdentifier = arm64_runtime_identifier };

Просмотреть файл

@ -188,7 +188,7 @@ namespace Xamarin.Bundler {
// This means it won't be listed in --help, and it won't be enabled if all optimizations
// are enabled. Yet we still might want to enable it manually, and this condition
// allows us to manually pass --optimize=remove-dynamic-registrar and enable it that way.
if (app.Platform == ApplePlatform.MacOSX && (Opt) i == Opt.RemoveDynamicRegistrar)
if (app.Platform == ApplePlatform.MacOSX && app.XamarinRuntime != XamarinRuntime.NativeAOT && (Opt) i == Opt.RemoveDynamicRegistrar)
continue;
// check if the optimization is valid for the current platform
@ -264,7 +264,7 @@ namespace Xamarin.Bundler {
// We will register protocols if the static registrar is enabled and loading assemblies is not possible
if (!RegisterProtocols.HasValue) {
if (app.Platform != ApplePlatform.MacOSX) {
if (app.Platform != ApplePlatform.MacOSX || app.XamarinRuntime == XamarinRuntime.NativeAOT) {
RegisterProtocols = (app.Registrar == RegistrarMode.Static || app.Registrar == RegistrarMode.ManagedStatic) && !app.UseInterpreter;
} else {
RegisterProtocols = false;

Просмотреть файл

@ -3442,6 +3442,12 @@ namespace Registrar {
sb.AppendLine ("}");
return true;
case Trampoline.CopyWithZone2:
#if NET
// Managed Static Registrar handles CopyWithZone2 in GenerateCallToUnmanagedCallersOnlyMethod
if (LinkContext.App.Registrar == RegistrarMode.ManagedStatic) {
return false;
}
#endif
sb.AppendLine ("-(id) copyWithZone: (NSZone *) zone");
sb.AppendLine ("{");
sb.AppendLine ("return xamarin_copyWithZone_trampoline2 (self, _cmd, zone);");
@ -3490,6 +3496,7 @@ namespace Registrar {
case Trampoline.X86_DoubleABI_StretTrampoline:
case Trampoline.StaticStret:
case Trampoline.Stret:
case Trampoline.CopyWithZone2:
switch (method.NativeReturnType.FullName) {
case "System.Int64":
rettype = "long long";
@ -4369,6 +4376,14 @@ namespace Registrar {
sb.WriteLine ($"bool call_super = false;");
if (hasReturnType)
sb.WriteLine ($"{callbackReturnType} rv = {{ 0 }};");
if (method.CurrentTrampoline == Trampoline.CopyWithZone2) {
sb.WriteLine ("id p0 = (id)zone;");
sb.WriteLine ("GCHandle gchandle;");
sb.WriteLine ("enum XamarinGCHandleFlags flags = XamarinGCHandleFlags_None;");
sb.WriteLine ("gchandle = xamarin_get_gchandle_with_flags (self, &flags);");
sb.WriteLine ("if (gchandle != INVALID_GCHANDLE)");
sb.Indent ().WriteLine ("xamarin_set_gchandle_with_flags (self, INVALID_GCHANDLE, XamarinGCHandleFlags_None);").Unindent ();
}
if (!staticCall) {
sb.WriteLine ($"static {ucoEntryPoint}_function {ucoEntryPoint};");
@ -4392,6 +4407,11 @@ namespace Registrar {
GenerateCallToSuperForConstructor (sb, method, exceptions);
}
if (method.CurrentTrampoline == Trampoline.CopyWithZone2) {
sb.WriteLine ("if (gchandle != INVALID_GCHANDLE)");
sb.Indent ().WriteLine ("xamarin_set_gchandle_with_flags (self, gchandle, flags);").Unindent ();
}
if (hasReturnType)
sb.WriteLine ("return rv;");