diff --git a/src/ObjCRuntime/Runtime.cs b/src/ObjCRuntime/Runtime.cs index ddf2240c1bdd..38abcc97c069 100644 --- a/src/ObjCRuntime/Runtime.cs +++ b/src/ObjCRuntime/Runtime.cs @@ -621,6 +621,12 @@ static IntPtr PrintAllExceptions (IntPtr exception_gchandle) // 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 diff --git a/src/ObjCRuntime/Runtime.mac.cs b/src/ObjCRuntime/Runtime.mac.cs index 9f092f860e95..caaad538a4f5 100644 --- a/src/ObjCRuntime/Runtime.mac.cs +++ b/src/ObjCRuntime/Runtime.mac.cs @@ -194,11 +194,13 @@ unsafe static void InitializePlatform (InitializationOptions* options) FrameworksPath = Path.Combine (basePath, "Frameworks"); } +#if !NET [Preserve] static IntPtr GetNullableType (IntPtr type) { return AllocGCHandle (Registrar.GetNullableType ((Type) GetGCHandleTarget (type)!)); } +#endif // !NET #endif // !COREBUILD } } diff --git a/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs b/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs index dd17244c45c2..ae30163d06d2 100644 --- a/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs +++ b/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs @@ -2246,7 +2246,8 @@ public void TestCtors () } } -#if __MACOS__ + // This test uses Assembly.LoadFrom, which isn't supported with NativeAOT +#if __MACOS__ && !NATIVEAOT [Test] public void CustomUserTypeWithDynamicallyLoadedAssembly () { diff --git a/tests/mtouch/Cache.cs b/tests/mtouch/Cache.cs index c44910246f15..5e93b130ed48 100644 --- a/tests/mtouch/Cache.cs +++ b/tests/mtouch/Cache.cs @@ -18,7 +18,11 @@ public static class Cache // Not really a cache (since the root directory is cle 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. diff --git a/tests/xharness/Jenkins/TestVariationsFactory.cs b/tests/xharness/Jenkins/TestVariationsFactory.cs index 9954bb966ae2..636ffdacd748 100644 --- a/tests/xharness/Jenkins/TestVariationsFactory.cs +++ b/tests/xharness/Jenkins/TestVariationsFactory.cs @@ -169,9 +169,8 @@ IEnumerable GetTestData (RunTestTask test) 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 }; diff --git a/tools/common/Optimizations.cs b/tools/common/Optimizations.cs index 16e40bdf4c4d..b6ea74fdc497 100644 --- a/tools/common/Optimizations.cs +++ b/tools/common/Optimizations.cs @@ -188,7 +188,7 @@ public void Initialize (Application app, out List messages) // 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 @@ public void Initialize (Application app, out List messages) // 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; diff --git a/tools/common/StaticRegistrar.cs b/tools/common/StaticRegistrar.cs index 1977fec031b9..b907dedd6bdf 100644 --- a/tools/common/StaticRegistrar.cs +++ b/tools/common/StaticRegistrar.cs @@ -3424,6 +3424,12 @@ bool SpecializeTrampoline (AutoIndentStringBuilder sb, ObjCMethod method, List