Add Mono AOT for iOS to run C#
This commit is contained in:
@@ -218,6 +218,7 @@ bool MacPlatformTools::OnPostProcess(CookingData& data)
|
||||
LSMinimumSystemVersionByArchitecture.append_child(PUGIXML_TEXT("string")).set_child_value(PUGIXML_TEXT("10.15"));
|
||||
|
||||
#undef ADD_ENTRY
|
||||
#undef ADD_ENTRY_STR
|
||||
|
||||
if (!doc.save_file(*StringAnsi(plistPath)))
|
||||
{
|
||||
|
||||
@@ -54,6 +54,11 @@ ArchitectureType iOSPlatformTools::GetArchitecture() const
|
||||
return ArchitectureType::ARM64;
|
||||
}
|
||||
|
||||
DotNetAOTModes iOSPlatformTools::UseAOT() const
|
||||
{
|
||||
return DotNetAOTModes::MonoAOTDynamic;
|
||||
}
|
||||
|
||||
bool iOSPlatformTools::IsNativeCodeFile(CookingData& data, const String& file)
|
||||
{
|
||||
String extension = FileSystem::GetExtension(file);
|
||||
@@ -170,6 +175,9 @@ bool iOSPlatformTools::OnPostProcess(CookingData& data)
|
||||
plist.append_attribute(PUGIXML_TEXT("version")).set_value(PUGIXML_TEXT("1.0"));
|
||||
xml_node dict = plist.child_or_append(PUGIXML_TEXT("dict"));
|
||||
|
||||
dict.append_child(PUGIXML_TEXT("key")).set_child_value(PUGIXML_TEXT("LSRequiresIPhoneOS"));
|
||||
dict.append_child(PUGIXML_TEXT("true"));
|
||||
|
||||
#define ADD_ENTRY(key, value) \
|
||||
dict.append_child(PUGIXML_TEXT("key")).set_child_value(PUGIXML_TEXT(key)); \
|
||||
dict.append_child(PUGIXML_TEXT("string")).set_child_value(PUGIXML_TEXT(value))
|
||||
@@ -192,16 +200,18 @@ bool iOSPlatformTools::OnPostProcess(CookingData& data)
|
||||
ADD_ENTRY("UIRequiresFullScreen", "true");
|
||||
ADD_ENTRY("UIStatusBarHidden", "true");
|
||||
|
||||
dict.append_child(PUGIXML_TEXT("key")).set_child_value(PUGIXML_TEXT("CFBundleSupportedPlatforms"));
|
||||
xml_node CFBundleSupportedPlatforms = dict.append_child(PUGIXML_TEXT("array"));
|
||||
CFBundleSupportedPlatforms.append_child(PUGIXML_TEXT("string")).set_child_value(PUGIXML_TEXT("iPhoneOS"));
|
||||
dict.append_child(PUGIXML_TEXT("key")).set_child_value(PUGIXML_TEXT("UIRequiredDeviceCapabilities"));
|
||||
xml_node UIRequiredDeviceCapabilities = dict.append_child(PUGIXML_TEXT("array"));
|
||||
UIRequiredDeviceCapabilities.append_child(PUGIXML_TEXT("string")).set_child_value(PUGIXML_TEXT("arm64"));
|
||||
|
||||
dict.append_child(PUGIXML_TEXT("key")).set_child_value(PUGIXML_TEXT("UISupportedInterfaceOrientations"));
|
||||
xml_node UISupportedInterfaceOrientations = dict.append_child(PUGIXML_TEXT("array"));
|
||||
UISupportedInterfaceOrientations.append_child(PUGIXML_TEXT("string")).set_child_value(PUGIXML_TEXT("UIInterfaceOrientationPortrait"));
|
||||
UISupportedInterfaceOrientations.append_child(PUGIXML_TEXT("string")).set_child_value(PUGIXML_TEXT("UIInterfaceOrientationLandscapeLeft"));
|
||||
UISupportedInterfaceOrientations.append_child(PUGIXML_TEXT("string")).set_child_value(PUGIXML_TEXT("UIInterfaceOrientationLandscapeRight"));
|
||||
|
||||
dict.append_child(PUGIXML_TEXT("key")).set_child_value(PUGIXML_TEXT("LSMinimumSystemVersionByArchitecture"));
|
||||
xml_node LSMinimumSystemVersionByArchitecture = dict.append_child(PUGIXML_TEXT("dict"));
|
||||
LSMinimumSystemVersionByArchitecture.append_child(PUGIXML_TEXT("key")).set_child_value(PUGIXML_TEXT("arm64"));
|
||||
LSMinimumSystemVersionByArchitecture.append_child(PUGIXML_TEXT("string")).set_child_value(PUGIXML_TEXT("10.15"));
|
||||
|
||||
#undef ADD_ENTRY
|
||||
#undef ADD_ENTRY_STR
|
||||
|
||||
if (!doc.save_file(*StringAnsi(plistPath)))
|
||||
{
|
||||
|
||||
@@ -17,6 +17,7 @@ public:
|
||||
const Char* GetName() const override;
|
||||
PlatformType GetPlatform() const override;
|
||||
ArchitectureType GetArchitecture() const override;
|
||||
DotNetAOTModes UseAOT() const override;
|
||||
bool IsNativeCodeFile(CookingData& data, const String& file) override;
|
||||
void OnBuildStarted(CookingData& data) override;
|
||||
bool OnPostProcess(CookingData& data) override;
|
||||
|
||||
@@ -174,7 +174,7 @@ bool DeployDataStep::Perform(CookingData& data)
|
||||
String packFolder = srcDotnet / TEXT("../../../");
|
||||
String dstDotnetLibs = dstDotnet, srcDotnetLibs = srcDotnet;
|
||||
StringUtils::PathRemoveRelativeParts(packFolder);
|
||||
if (usAOT)
|
||||
if (usAOT && srcDotnetFromEngine)
|
||||
{
|
||||
// AOT runtime files inside Engine Platform folder
|
||||
packFolder /= TEXT("Dotnet");
|
||||
@@ -202,8 +202,8 @@ bool DeployDataStep::Perform(CookingData& data)
|
||||
failed |= EditorUtilities::CopyFileIfNewer(dstDotnetLibs / corlibPrivateName, srcDotnet / corlibPrivateName);
|
||||
switch (data.Platform)
|
||||
{
|
||||
case BuildPlatform::AndroidARM64:
|
||||
#define DEPLOY_NATIVE_FILE(filename) failed |= FileSystem::CopyFile(data.NativeCodeOutputPath / TEXT(filename), srcDotnet / TEXT(filename));
|
||||
case BuildPlatform::AndroidARM64:
|
||||
if (data.Configuration != BuildConfiguration::Release)
|
||||
{
|
||||
DEPLOY_NATIVE_FILE("libmono-component-debugger.so");
|
||||
@@ -214,8 +214,15 @@ bool DeployDataStep::Perform(CookingData& data)
|
||||
DEPLOY_NATIVE_FILE("libSystem.IO.Compression.Native.so");
|
||||
DEPLOY_NATIVE_FILE("libSystem.Native.so");
|
||||
DEPLOY_NATIVE_FILE("libSystem.Security.Cryptography.Native.Android.so");
|
||||
#undef DEPLOY_NATIVE_FILE
|
||||
break;
|
||||
case BuildPlatform::iOSARM64:
|
||||
DEPLOY_NATIVE_FILE("libmonosgen-2.0.dylib");
|
||||
DEPLOY_NATIVE_FILE("libSystem.IO.Compression.Native.dylib");
|
||||
DEPLOY_NATIVE_FILE("libSystem.Native.dylib");
|
||||
DEPLOY_NATIVE_FILE("libSystem.Net.Security.Native.dylib");
|
||||
DEPLOY_NATIVE_FILE("libSystem.Security.Cryptography.Native.Apple.dylib");
|
||||
break;
|
||||
#undef DEPLOY_NATIVE_FILE
|
||||
default: ;
|
||||
}
|
||||
if (failed)
|
||||
|
||||
@@ -14,4 +14,8 @@
|
||||
#define PLATFORM_CACHE_LINE_SIZE 128
|
||||
#define PLATFORM_DEBUG_BREAK __builtin_trap()
|
||||
|
||||
// Use AOT for Mono
|
||||
#define USE_MONO_AOT 1
|
||||
#define USE_MONO_AOT_MODE MONO_AOT_MODE_FULL
|
||||
|
||||
#endif
|
||||
|
||||
@@ -407,6 +407,13 @@ namespace Flax.Build
|
||||
return exists;
|
||||
}
|
||||
|
||||
internal static string SelectVersionFolder(string root)
|
||||
{
|
||||
var versions = GetVersions(root);
|
||||
var version = GetVersion(versions);
|
||||
return Path.Combine(root, version);
|
||||
}
|
||||
|
||||
private static Version ParseVersion(string version)
|
||||
{
|
||||
// Give precedence to final releases over release candidate / beta releases
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using Flax.Build.NativeCpp;
|
||||
|
||||
@@ -61,5 +62,37 @@ namespace Flax.Build.Platforms
|
||||
|
||||
args.Add("-miphoneos-version-min=" + Configuration.iOSMinVer);
|
||||
}
|
||||
|
||||
public override bool CompileCSharp(ref CSharpOptions options)
|
||||
{
|
||||
switch (options.Action)
|
||||
{
|
||||
case CSharpOptions.ActionTypes.GetPlatformTools:
|
||||
options.PlatformToolsPath = Path.Combine(DotNetSdk.SelectVersionFolder(Path.Combine(DotNetSdk.Instance.RootPath, "packs/Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.ios-arm64")), "tools");
|
||||
return false;
|
||||
case CSharpOptions.ActionTypes.MonoCompile:
|
||||
{
|
||||
var aotCompilerPath = Path.Combine(options.PlatformToolsPath, "mono-aot-cross");
|
||||
return true; // TODO: impl this (output assembly from aot cross-compiler and manually compile into shared library for ios)
|
||||
// Setup options
|
||||
var monoAotMode = "full";
|
||||
var monoDebugMode = options.EnableDebugSymbols ? "soft-debug" : "nodebug";
|
||||
var aotCompilerArgs = $"--aot={monoAotMode},verbose,stats,print-skipped,{monoDebugMode} -O=all";
|
||||
if (options.EnableDebugSymbols || options.EnableToolDebug)
|
||||
aotCompilerArgs = "--debug " + aotCompilerArgs;
|
||||
var envVars = new Dictionary<string, string>();
|
||||
envVars["MONO_PATH"] = options.AssembliesPath + ";" + options.ClassLibraryPath;
|
||||
if (options.EnableToolDebug)
|
||||
{
|
||||
envVars["MONO_LOG_LEVEL"] = "debug";
|
||||
}
|
||||
|
||||
// Run cross-compiler compiler
|
||||
int result = Utilities.Run(aotCompilerPath, $"{aotCompilerArgs} \"{options.InputFiles[0]}\"", null, options.PlatformToolsPath, Utilities.RunOptions.AppMustExist | Utilities.RunOptions.ConsoleLogOutput, envVars);
|
||||
return result != 0;
|
||||
}
|
||||
}
|
||||
return base.CompileCSharp(ref options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user