/// <summary>
/// Path to Mono public headers (*.h)
/// </summary>
- [Required]
public string MonoRuntimeHeaders { get; set; } = ""!;
/// <summary>
/// </summary>
public bool StripSymbolTable { get; set; }
+ /// <summary>
+ /// Bundles the application for NativeAOT runtime. Default runtime is Mono.
+ /// </summary>
+ public bool UseNativeAOTRuntime { get; set; }
+
+ public void ValidateRuntimeSelection()
+ {
+ if (UseNativeAOTRuntime)
+ {
+ if (!string.IsNullOrEmpty(MonoRuntimeHeaders))
+ throw new ArgumentException($"Property \"{nameof(MonoRuntimeHeaders)}\" is not supported with NativeAOT runtime and will be ignored.");
+
+ if (!string.IsNullOrEmpty(MainLibraryFileName))
+ throw new ArgumentException($"Property \"{nameof(MainLibraryFileName)}\" is not supported with NativeAOT runtime and will be ignored.");
+
+ if (UseConsoleUITemplate)
+ throw new ArgumentException($"Property \"{nameof(UseConsoleUITemplate)}\" is not supported with NativeAOT runtime and will be ignored.");
+
+ if (ForceInterpreter)
+ throw new ArgumentException($"Property \"{nameof(ForceInterpreter)}\" is not supported with NativeAOT runtime and will be ignored.");
+
+ if (ForceAOT)
+ throw new ArgumentException($"Property \"{nameof(ForceAOT)}\" is not supported with NativeAOT runtime and will be ignored.");
+
+ if (!string.IsNullOrEmpty(RuntimeComponents))
+ throw new ArgumentException($"Property \"{nameof(RuntimeComponents)}\" is not supported with NativeAOT runtime and will be ignored.");
+
+ if (!string.IsNullOrEmpty(DiagnosticPorts))
+ throw new ArgumentException($"Property \"{nameof(DiagnosticPorts)}\" is not supported with NativeAOT runtime and will be ignored.");
+
+ if (EnableRuntimeLogging)
+ throw new ArgumentException($"Property \"{nameof(EnableRuntimeLogging)}\" is not supported with NativeAOT runtime and will be ignored.");
+ }
+ else
+ {
+ if (string.IsNullOrEmpty(MonoRuntimeHeaders))
+ throw new ArgumentException($"The \"{nameof(AppleAppBuilderTask)}\" task was not given a value for the required parameter \"{nameof(MonoRuntimeHeaders)}\" when using Mono runtime.");
+ }
+ }
+
public override bool Execute()
{
bool isDevice = (TargetOS == TargetNames.iOS || TargetOS == TargetNames.tvOS);
+ ValidateRuntimeSelection();
+
if (!string.IsNullOrEmpty(MainLibraryFileName))
{
if (!File.Exists(Path.Combine(AppDir, MainLibraryFileName)))
}
}
- if (!ForceInterpreter && (isDevice || ForceAOT) && assemblerFiles.Count == 0)
+ if (!ForceInterpreter && (isDevice || ForceAOT) && (assemblerFiles.Count == 0 && !UseNativeAOTRuntime))
{
throw new InvalidOperationException("Need list of AOT files for device builds.");
}
if (GenerateXcodeProject)
{
XcodeProjectPath = generator.GenerateXCode(ProjectName, MainLibraryFileName, assemblerFiles, assemblerDataFiles, assemblerFilesToLink,
- AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource);
+ AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource, UseNativeAOTRuntime);
if (BuildAppBundle)
{
else if (GenerateCMakeProject)
{
generator.GenerateCMake(ProjectName, MainLibraryFileName, assemblerFiles, assemblerDataFiles, assemblerFilesToLink,
- AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource);
+ AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource, UseNativeAOTRuntime);
}
return true;
bool enableRuntimeLogging,
bool enableAppSandbox,
string? diagnosticPorts,
- string? runtimeComponents=null,
- string? nativeMainSource = null)
+ string? runtimeComponents = null,
+ string? nativeMainSource = null,
+ bool useNativeAOTRuntime = false)
{
- var cmakeDirectoryPath = GenerateCMake(projectName, entryPointLib, asmFiles, asmDataFiles, asmLinkFiles, workspace, binDir, monoInclude, preferDylibs, useConsoleUiTemplate, forceAOT, forceInterpreter, invariantGlobalization, optimized, enableRuntimeLogging, enableAppSandbox, diagnosticPorts, runtimeComponents, nativeMainSource);
+ var cmakeDirectoryPath = GenerateCMake(projectName, entryPointLib, asmFiles, asmDataFiles, asmLinkFiles, workspace, binDir, monoInclude, preferDylibs, useConsoleUiTemplate, forceAOT, forceInterpreter, invariantGlobalization, optimized, enableRuntimeLogging, enableAppSandbox, diagnosticPorts, runtimeComponents, nativeMainSource, useNativeAOTRuntime);
CreateXcodeProject(projectName, cmakeDirectoryPath);
return Path.Combine(binDir, projectName, projectName + ".xcodeproj");
}
bool enableRuntimeLogging,
bool enableAppSandbox,
string? diagnosticPorts,
- string? runtimeComponents=null,
- string? nativeMainSource = null)
+ string? runtimeComponents = null,
+ string? nativeMainSource = null,
+ bool useNativeAOTRuntime = false)
{
// bundle everything as resources excluding native files
var excludes = new List<string> { ".dll.o", ".dll.s", ".dwarf", ".m", ".h", ".a", ".bc", "libmonosgen-2.0.dylib", "libcoreclr.dylib" };
appResources += string.Join(Environment.NewLine, resources.Where(r => !r.EndsWith("-llvm.o")).Select(r => " " + Path.GetRelativePath(binDir, r)));
string cmakeLists = Utils.GetEmbeddedResource("CMakeLists.txt.template")
+ .Replace("%UseNativeAOTRuntime%", useNativeAOTRuntime ? "TRUE" : "FALSE")
.Replace("%ProjectName%", projectName)
.Replace("%AppResources%", appResources)
.Replace("%MainSource%", nativeMainSource)
// libmono must always be statically linked, for other librarires we can use dylibs
bool dylibExists = libName != "libmonosgen-2.0" && dylibs.Any(dylib => Path.GetFileName(dylib) == libName + ".dylib");
- if (forceAOT || !(preferDylibs && dylibExists))
+ if (useNativeAOTRuntime)
+ {
+ // link NativeAOT framework libs without '-force_load'
+ toLink += $" {lib}{Environment.NewLine}";
+ }
+ else if (forceAOT || !(preferDylibs && dylibExists))
{
// these libraries are pinvoked
// -force_load will be removed once we enable direct-pinvokes for AOT
defines.AppendLine($"\nadd_definitions(-DDIAGNOSTIC_PORTS=\"{diagnosticPorts}\")");
}
+ if (useNativeAOTRuntime)
+ {
+ defines.AppendLine("add_definitions(-DUSE_NATIVE_AOT=1)");
+ }
+
cmakeLists = cmakeLists.Replace("%Defines%", defines.ToString());
string plist = Utils.GetEmbeddedResource("Info.plist.template")
File.WriteAllText(Path.Combine(binDir, "app.entitlements"), entitlementsTemplate.Replace("%Entitlements%", ent.ToString()));
}
- File.WriteAllText(Path.Combine(binDir, "runtime.h"),
- Utils.GetEmbeddedResource("runtime.h"));
-
- // forward pinvokes to "__Internal"
- var dllMap = new StringBuilder();
- foreach (string aFile in Directory.GetFiles(workspace, "*.a"))
+ if (!useNativeAOTRuntime)
{
- string aFileName = Path.GetFileNameWithoutExtension(aFile);
- dllMap.AppendLine($" mono_dllmap_insert (NULL, \"{aFileName}\", NULL, \"__Internal\", NULL);");
+ File.WriteAllText(Path.Combine(binDir, "runtime.h"),
+ Utils.GetEmbeddedResource("runtime.h"));
- // also register with or without "lib" prefix
- aFileName = aFileName.StartsWith("lib") ? aFileName.Remove(0, 3) : "lib" + aFileName;
- dllMap.AppendLine($" mono_dllmap_insert (NULL, \"{aFileName}\", NULL, \"__Internal\", NULL);");
- }
+ // forward pinvokes to "__Internal"
+ var dllMap = new StringBuilder();
+ foreach (string aFile in Directory.GetFiles(workspace, "*.a"))
+ {
+ string aFileName = Path.GetFileNameWithoutExtension(aFile);
+ dllMap.AppendLine($" mono_dllmap_insert (NULL, \"{aFileName}\", NULL, \"__Internal\", NULL);");
- dllMap.AppendLine($" mono_dllmap_insert (NULL, \"System.Globalization.Native\", NULL, \"__Internal\", NULL);");
+ // also register with or without "lib" prefix
+ aFileName = aFileName.StartsWith("lib") ? aFileName.Remove(0, 3) : "lib" + aFileName;
+ dllMap.AppendLine($" mono_dllmap_insert (NULL, \"{aFileName}\", NULL, \"__Internal\", NULL);");
+ }
- File.WriteAllText(Path.Combine(binDir, "runtime.m"),
- Utils.GetEmbeddedResource("runtime.m")
- .Replace("//%DllMap%", dllMap.ToString())
- .Replace("//%APPLE_RUNTIME_IDENTIFIER%", RuntimeIdentifier)
- .Replace("%EntryPointLibName%", Path.GetFileName(entryPointLib)));
+ dllMap.AppendLine($" mono_dllmap_insert (NULL, \"System.Globalization.Native\", NULL, \"__Internal\", NULL);");
+
+ File.WriteAllText(Path.Combine(binDir, "runtime.m"),
+ Utils.GetEmbeddedResource("runtime.m")
+ .Replace("//%DllMap%", dllMap.ToString())
+ .Replace("//%APPLE_RUNTIME_IDENTIFIER%", RuntimeIdentifier)
+ .Replace("%EntryPointLibName%", Path.GetFileName(entryPointLib)));
+ }
return binDir;
}