Implement C# AOT process for .NET 7 for Windows platform
This commit is contained in:
@@ -1,25 +1,82 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
#include "PrecompileAssembliesStep.h"
|
||||
#include "Editor/Scripting/ScriptsBuilder.h"
|
||||
#include "Engine/Platform/FileSystem.h"
|
||||
#include "Engine/Core/Config/BuildSettings.h"
|
||||
#include "Engine/Engine/Globals.h"
|
||||
#include "Editor/Scripting/ScriptsBuilder.h"
|
||||
#include "Editor/Cooker/PlatformTools.h"
|
||||
#include "Editor/Utilities/EditorUtilities.h"
|
||||
|
||||
void PrecompileAssembliesStep::OnBuildStarted(CookingData& data)
|
||||
{
|
||||
const DotNetAOTModes aotMode = data.Tools->UseAOT();
|
||||
if (aotMode == DotNetAOTModes::None)
|
||||
return;
|
||||
|
||||
// Redirect C# assemblies to intermediate cooking directory (processed by ILC)
|
||||
data.ManagedCodeOutputPath = data.CacheDirectory / TEXT("AOTAssemblies");
|
||||
}
|
||||
|
||||
bool PrecompileAssembliesStep::Perform(CookingData& data)
|
||||
{
|
||||
// Skip for some platforms
|
||||
if (!data.Tools->UseAOT())
|
||||
const DotNetAOTModes aotMode = data.Tools->UseAOT();
|
||||
if (aotMode == DotNetAOTModes::None)
|
||||
return false;
|
||||
const auto& buildSettings = *BuildSettings::Get();
|
||||
if (buildSettings.SkipDotnetPackaging && data.Tools->UseSystemDotnet())
|
||||
return false;
|
||||
LOG(Info, "Using AOT...");
|
||||
|
||||
// Useful references about AOT:
|
||||
// http://www.mono-project.com/docs/advanced/runtime/docs/aot/
|
||||
// http://www.mono-project.com/docs/advanced/aot/
|
||||
|
||||
const String infoMsg = TEXT("Running AOT");
|
||||
data.StepProgress(infoMsg, 0);
|
||||
|
||||
// Override Newtonsoft.Json with AOT-version (one that doesn't use System.Reflection.Emit)
|
||||
EditorUtilities::CopyFileIfNewer(data.ManagedCodeOutputPath / TEXT("Newtonsoft.Json.dll"), Globals::StartupFolder / TEXT("Source/Platforms/DotNet/AOT/Newtonsoft.Json.dll"));
|
||||
FileSystem::DeleteFile(data.ManagedCodeOutputPath / TEXT("Newtonsoft.Json.xml"));
|
||||
FileSystem::DeleteFile(data.ManagedCodeOutputPath / TEXT("Newtonsoft.Json.pdb"));
|
||||
|
||||
// Run AOT by Flax.Build
|
||||
const Char *platform, *architecture, *configuration = ::ToString(data.Configuration);
|
||||
data.GetBuildPlatformName(platform, architecture);
|
||||
const String logFile = data.CacheDirectory / TEXT("AotLog.txt");
|
||||
const Char* aotModeName = TEXT("");
|
||||
switch (aotMode)
|
||||
{
|
||||
case DotNetAOTModes::ILC:
|
||||
aotModeName = TEXT("ILC");
|
||||
break;
|
||||
case DotNetAOTModes::MonoAOTDynamic:
|
||||
aotModeName = TEXT("MonoAOTDynamic");
|
||||
break;
|
||||
case DotNetAOTModes::MonoAOTStatic:
|
||||
aotModeName = TEXT("MonoAOTStatic");
|
||||
break;
|
||||
}
|
||||
auto args = String::Format(
|
||||
TEXT("-log -logfile=\"{}\" -runDotNetAOT -mutex -platform={} -arch={} -configuration={} -aotMode={} -binaries=\"{}\" -intermediate=\"{}\""),
|
||||
logFile, platform, architecture, configuration, aotModeName, data.DataOutputPath, data.ManagedCodeOutputPath);
|
||||
for (const String& define : data.CustomDefines)
|
||||
{
|
||||
args += TEXT(" -D");
|
||||
args += define;
|
||||
}
|
||||
if (ScriptsBuilder::RunBuildTool(args))
|
||||
{
|
||||
data.Error(TEXT("Failed to precompile game scripts."));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
// Useful references about AOT:
|
||||
// https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/README.md
|
||||
// https://github.com/dotnet/runtime/blob/main/docs/workflow/building/coreclr/nativeaot.md
|
||||
// https://github.com/dotnet/samples/tree/main/core/nativeaot/NativeLibrary
|
||||
// http://www.mono-project.com/docs/advanced/runtime/docs/aot/
|
||||
// http://www.mono-project.com/docs/advanced/aot/
|
||||
|
||||
// Setup
|
||||
// TODO: remove old AotConfig, OnConfigureAOT, OnPerformAOT and OnPostProcessAOT
|
||||
PlatformTools::AotConfig config(data);
|
||||
data.Tools->OnConfigureAOT(data, config);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user