Add FullAOT mode for Simulator to AppleAppBuilder (#36759)
authorEgor Bogatov <egorbo@gmail.com>
Wed, 20 May 2020 17:55:37 +0000 (20:55 +0300)
committerGitHub <noreply@github.com>
Wed, 20 May 2020 17:55:37 +0000 (20:55 +0300)
src/mono/netcore/sample/iOS/Makefile
src/mono/netcore/sample/iOS/Program.csproj
tools-local/tasks/mobile.tasks/AppleAppBuilder/AppleAppBuilder.cs
tools-local/tasks/mobile.tasks/AppleAppBuilder/Templates/CMakeLists.txt.template
tools-local/tasks/mobile.tasks/AppleAppBuilder/Templates/main-console.m
tools-local/tasks/mobile.tasks/AppleAppBuilder/Templates/runtime.m
tools-local/tasks/mobile.tasks/AppleAppBuilder/Xcode.cs

index e59f9ec..36dec2b 100644 (file)
@@ -3,7 +3,7 @@ MONO_ARCH=x64
 DOTNET := ../../../../.././dotnet.sh
 USE_LLVM=True
 
-all: runtimepack app
+all: runtimepack run
 
 TOOLS_DIR=../../../../../tools-local/tasks/mobile.tasks
 appbuilder:
@@ -14,7 +14,8 @@ runtimepack:
        ../../../../.././build.sh Mono+Libs -os iOS -arch $(MONO_ARCH) -c $(MONO_CONFIG)
 
 run: clean appbuilder
-       $(DOTNET) publish -c $(MONO_CONFIG) /p:TargetArchitecture=$(MONO_ARCH) /p:UseLLVM=$(USE_LLVM)
+       $(DOTNET) publish -c $(MONO_CONFIG) /p:TargetArchitecture=$(MONO_ARCH) \
+       /p:UseLLVM=$(USE_LLVM) /p:UseAotForSimulator=true
 
 clean:
        rm -rf bin
index dfb0848..f08d180 100644 (file)
@@ -10,6 +10,7 @@
     <RuntimeIdentifier>ios-$(TargetArchitecture)</RuntimeIdentifier>
     <PublishTrimmed>true</PublishTrimmed>
     <_TrimmerDefaultAction>link</_TrimmerDefaultAction>
+    <Optimized Condition="'$(Configuration)' == 'Release'">True</Optimized>
   </PropertyGroup>
 
   <!-- Redirect 'dotnet publish' to in-tree runtime pack -->
@@ -46,7 +47,7 @@
     </ItemGroup>
 
     <MonoAOTCompiler
-        Condition="'$(IosSimulator)' == ''"
+        Condition="'$(IosSimulator)' == '' or '$(UseAotForSimulator)' == 'true'"
         CompilerBinaryPath="$(RuntimePackDir)\native\cross\mono-aot-cross"
         Mode="Full"
         OutputType="AsmOnly"
@@ -66,7 +67,8 @@
         BuildAppBundle="True"
         DevTeamProvisioning="$(DevTeamProvisioning)"
         OutputDirectory="$(AppDir)"
-        Optimized="False"
+        Optimized="$(Optimized)"
+        UseAotForSimulator="$(UseAotForSimulator)"
         AppDir="$(MSBuildThisFileDirectory)$(PublishDir)">
         <Output TaskParameter="AppBundlePath" PropertyName="AppBundlePath" />
         <Output TaskParameter="XcodeProjectPath" PropertyName="XcodeProjectPath" />
@@ -78,7 +80,7 @@
     <Exec Condition="'$(IosSimulator)' != ''" Command="xcrun simctl shutdown &quot;$(IosSimulator)&quot;" ContinueOnError="WarnAndContinue" />
     <Exec Condition="'$(IosSimulator)' != ''" Command="xcrun simctl boot &quot;$(IosSimulator)&quot;" />
     <Exec Condition="'$(IosSimulator)' != ''" Command="open -a Simulator" />
-    <Exec Condition="'$(IosSimulator)' != ''" Command="xcrun simctl install &quot;$(IosSimulator)&quot; $(ApkDir)/HelloiOS/Debug-iphonesimulator/HelloiOS.app" />
+    <Exec Condition="'$(IosSimulator)' != ''" Command="xcrun simctl install &quot;$(IosSimulator)&quot; $(AppBundlePath)" />
     <Exec Condition="'$(IosSimulator)' != ''" Command="xcrun simctl launch --console booted net.dot.HelloiOS" />
   </Target>
 </Project>
index a1d30a4..4722c7f 100644 (file)
@@ -98,6 +98,11 @@ public class AppleAppBuilderTask : Task
     public string AppBundlePath { get; set; } = ""!;
 
     /// <summary>
+    /// Prefer FullAOT mode for Simulator over JIT
+    /// </summary>
+    public bool UseAotForSimulator { get; set; }
+
+    /// <summary>
     /// Path to xcode project
     /// </summary>
     [Output]
@@ -145,7 +150,7 @@ public class AppleAppBuilderTask : Task
             }
         }
 
-        if (isDevice && !assemblerFiles.Any())
+        if ((isDevice || UseAotForSimulator) && !assemblerFiles.Any())
         {
             throw new InvalidOperationException("Need list of AOT files for device builds.");
         }
@@ -158,7 +163,7 @@ public class AppleAppBuilderTask : Task
         if (GenerateXcodeProject)
         {
             XcodeProjectPath = Xcode.GenerateXCode(ProjectName, MainLibraryFileName, assemblerFiles,
-                AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, NativeMainSource);
+                AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, UseAotForSimulator, NativeMainSource);
 
             if (BuildAppBundle)
             {
@@ -202,7 +207,7 @@ public class AppleAppBuilderTask : Task
             .AppendLine("#include <mono/jit/jit.h>")
             .AppendLine("#include <TargetConditionals.h>")
             .AppendLine()
-            .AppendLine("#if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR")
+            .AppendLine("#if TARGET_OS_IPHONE && (!TARGET_IPHONE_SIMULATOR || USE_AOT_FOR_SIMULATOR)")
             .AppendLine();
 
         var lsUsage = new StringBuilder();
index 65dedbe..847d578 100644 (file)
@@ -48,7 +48,7 @@ UITextView* logLabel;
     summaryLabel.font = [UIFont boldSystemFontOfSize: 12];
     summaryLabel.numberOfLines = 2;
     summaryLabel.textAlignment = NSTextAlignmentLeft;
-#ifdef TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
+#ifdef TARGET_OS_IPHONE && (!TARGET_IPHONE_SIMULATOR || USE_AOT_FOR_SIMULATOR)
     summaryLabel.text = @"Loading...";
 #else
     summaryLabel.text = @"Jitting...";
index b575aa2..45b2773 100644 (file)
@@ -197,7 +197,7 @@ register_dllmap (void)
 //%DllMap%
 }
 
-#if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
+#if TARGET_OS_IPHONE && (!TARGET_IPHONE_SIMULATOR || USE_AOT_FOR_SIMULATOR)
 void mono_jit_set_aot_mode (MonoAotMode mode);
 void mono_ios_register_modules (void);
 #endif
@@ -229,7 +229,7 @@ mono_ios_runtime_init (void)
     // TODO: set TRUSTED_PLATFORM_ASSEMBLIES, APP_PATHS and NATIVE_DLL_SEARCH_DIRECTORIES
     monovm_initialize(0, NULL, NULL);
 
-#if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
+#if TARGET_OS_IPHONE && (!TARGET_IPHONE_SIMULATOR || USE_AOT_FOR_SIMULATOR)
     register_dllmap ();
     // register modules
     mono_ios_register_modules ();
@@ -250,7 +250,7 @@ mono_ios_runtime_init (void)
     }
     mono_jit_init_version ("dotnet.ios", "mobile");
 
-#if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
+#if TARGET_OS_IPHONE && (!TARGET_IPHONE_SIMULATOR || USE_AOT_FOR_SIMULATOR)
     // device runtimes are configured to use lazy gc thread creation
     MONO_ENTER_GC_UNSAFE;
     mono_gc_init_finalizer_thread ();
index c0db9d1..821f267 100644 (file)
@@ -21,6 +21,7 @@ internal class Xcode
         string monoInclude,
         bool preferDylibs,
         bool useConsoleUiTemplate,
+        bool useAotForSimulator,
         string? nativeMainSource = null)
     {
         // bundle everything as resources excluding native files
@@ -80,6 +81,8 @@ internal class Xcode
 
         cmakeLists = cmakeLists.Replace("%NativeLibrariesToLink%", toLink);
         cmakeLists = cmakeLists.Replace("%AotSources%", aotSources);
+        cmakeLists = cmakeLists.Replace("%Defines%", 
+            useAotForSimulator ? "add_definitions(-DUSE_AOT_FOR_SIMULATOR=1)" : "");
 
         string plist = Utils.GetEmbeddedResource("Info.plist.template")
             .Replace("%BundleIdentifier%", projectName);