Add .NET 7 support to Xbox

This commit is contained in:
Wojtek Figat
2023-04-04 14:46:08 +02:00
parent e48e15f02f
commit 0c4a608b65
7 changed files with 68 additions and 123 deletions

View File

@@ -304,14 +304,9 @@ namespace Flax.Build
}
else if (aotMode == DotNetAOTModes.MonoAOTDynamic || aotMode == DotNetAOTModes.MonoAOTStatic)
{
var platformToolsRoot = Path.Combine(Globals.EngineRoot, "Source/Platforms", platform.ToString(), "Binaries/Tools");
if (!Directory.Exists(platformToolsRoot))
throw new Exception("Missing platform tools " + platformToolsRoot);
var dotnetLibPath = Path.Combine(aotAssembliesPath, "lib/net7.0");
var monoAssembliesOutputPath = aotMode == DotNetAOTModes.MonoAOTDynamic ? dotnetOutputPath : null;
// TODO: impl Mono AOT more generic way, not just Windows-only case
// Build list of assemblies to process (use game assemblies as root to walk over used references from stdlib)
var assembliesPaths = new List<string>();
if (Configuration.SkipUnusedDotnetLibsPackaging)
@@ -371,25 +366,16 @@ namespace Flax.Build
Log.Info("");
Log.Info("");
}
// Setup options
var aotCompilerPath = Path.Combine(platformToolsRoot, "mono-aot-cross.exe");
var monoAotMode = "full";
var debugMode = useDebug ? "soft-debug" : "nodebug";
var aotCompilerArgs = $"--aot={monoAotMode},verbose,stats,print-skipped,{debugMode} -O=all";
if (useDebug || dotnetAotDebug)
aotCompilerArgs = "--debug " + aotCompilerArgs;
var envVars = new Dictionary<string, string>();
envVars["MONO_PATH"] = aotAssembliesPath + ";" + dotnetLibPath;
if (dotnetAotDebug)
{
envVars["MONO_LOG_LEVEL"] = "debug";
}
// Run cross-compiler compiler
Log.Info(" * " + assemblyPath);
int result = Utilities.Run(aotCompilerPath, $"{aotCompilerArgs} \"{assemblyPath}\"", null, platformToolsRoot, Utilities.RunOptions.AppMustExist | Utilities.RunOptions.ConsoleLogOutput, envVars);
if (result != 0)
var options = new Toolchain.CSharpOptions
{
InputFile = assemblyPath,
AssembliesFolder = aotAssembliesPath,
ClassLibraryPath = dotnetLibPath,
EnableDebugSymbols = useDebug,
EnableToolDebug = dotnetAotDebug,
};
if (buildToolchain.CompileCSharp(options))
{
Log.Error("Failed to run AOT on assembly " + assemblyPath);
failed = true;

View File

@@ -274,6 +274,14 @@ namespace Flax.Build
Log.Verbose($" - Host Runtime for {e.Key.Key} {e.Key.Value}");
}
/// <summary>
/// Initializes platforms which can register custom host runtime location
/// </summary>
private static void InitPlatforms()
{
Platform.GetPlatform(TargetPlatform.Windows, true);
}
/// <summary>
/// Gets the host runtime identifier for a given platform (eg. linux-arm64).
/// </summary>
@@ -338,6 +346,7 @@ namespace Flax.Build
/// </summary>
public void PrintRuntimes()
{
InitPlatforms();
foreach (var e in _hostRuntimes)
{
// Filter with input commandline
@@ -357,6 +366,7 @@ namespace Flax.Build
/// </summary>
public bool GetHostRuntime(TargetPlatform platform, TargetArchitecture arch, out HostRuntime hostRuntime)
{
InitPlatforms();
return _hostRuntimes.TryGetValue(new KeyValuePair<TargetPlatform, TargetArchitecture>(platform, arch), out hostRuntime);
}

View File

@@ -133,5 +133,27 @@ namespace Flax.Build
/// <param name="options">The build options with linking environment.</param>
/// <param name="outputFilePath">The output file path (result linked file).</param>
public abstract void LinkFiles(TaskGraph graph, BuildOptions options, string outputFilePath);
/// <summary>
/// C# compilation options container.
/// </summary>
public struct CSharpOptions
{
public string InputFile;
public string AssembliesFolder;
public string ClassLibraryPath;
public bool EnableDebugSymbols;
public bool EnableToolDebug;
}
/// <summary>
/// Compiles the C# assembly with AOT cross-compiler.
/// </summary>
/// <param name="options">The options.</param>
/// <returns>True if failed, or not supported.</returns>
public virtual bool CompileCSharp(CSharpOptions options)
{
return true;
}
}
}

View File

@@ -1024,5 +1024,31 @@ namespace Flax.Build.Platforms
priNewFile.ProducedFiles.Add(priFile);
}
}
/// <inheritdoc />
public override bool CompileCSharp(CSharpOptions options)
{
var platformToolsRoot = Path.Combine(Globals.EngineRoot, "Source/Platforms", Platform.Target.ToString(), "Binaries/Tools");
if (!Directory.Exists(platformToolsRoot))
throw new Exception("Missing platform tools " + platformToolsRoot);
var aotCompilerPath = Path.Combine(platformToolsRoot, "mono-aot-cross.exe");
// Setup options
var monoAotMode = "full";
var debugMode = options.EnableDebugSymbols ? "soft-debug" : "nodebug";
var aotCompilerArgs = $"--aot={monoAotMode},verbose,stats,print-skipped,{debugMode} -O=all";
if (options.EnableDebugSymbols || options.EnableToolDebug)
aotCompilerArgs = "--debug " + aotCompilerArgs;
var envVars = new Dictionary<string, string>();
envVars["MONO_PATH"] = options.AssembliesFolder + ";" + options.ClassLibraryPath;
if (options.EnableToolDebug)
{
envVars["MONO_LOG_LEVEL"] = "debug";
}
// Run cross-compiler compiler
int result = Utilities.Run(aotCompilerPath, $"{aotCompilerArgs} \"{options.InputFile}\"", null, platformToolsRoot, Utilities.RunOptions.AppMustExist | Utilities.RunOptions.ConsoleLogOutput, envVars);
return result != 0;
}
}
}