From 493f3430bc043bae6024f4031ea6aa16643c061c Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 3 Apr 2023 13:49:53 +0200 Subject: [PATCH] Improve AOT cache usage when using different build configurations --- .../Cooker/Steps/PrecompileAssembliesStep.cpp | 71 ++----------------- 1 file changed, 4 insertions(+), 67 deletions(-) diff --git a/Source/Editor/Cooker/Steps/PrecompileAssembliesStep.cpp b/Source/Editor/Cooker/Steps/PrecompileAssembliesStep.cpp index 0bc6e3461..c0188ffe2 100644 --- a/Source/Editor/Cooker/Steps/PrecompileAssembliesStep.cpp +++ b/Source/Editor/Cooker/Steps/PrecompileAssembliesStep.cpp @@ -20,7 +20,9 @@ void PrecompileAssembliesStep::OnBuildStarted(CookingData& data) // Reset any AOT cache from previous run if the AOT mode has changed (eg. Mono AOT -> ILC on Desktop) const String aotModeCacheFilePath = data.ManagedCodeOutputPath / TEXT("AOTMode.txt"); - const String aotModeCacheValue = StringUtils::ToString((int32)aotMode); + String aotModeCacheValue = String::Format(TEXT("{};{}"), (int32)aotMode, (int32)data.Configuration); + for (const String& define : data.CustomDefines) + aotModeCacheValue += define; if (FileSystem::DirectoryExists(data.ManagedCodeOutputPath)) { String cachedData; @@ -54,7 +56,7 @@ bool PrecompileAssembliesStep::Perform(CookingData& data) FileSystem::DeleteFile(data.ManagedCodeOutputPath / TEXT("Newtonsoft.Json.xml")); FileSystem::DeleteFile(data.ManagedCodeOutputPath / TEXT("Newtonsoft.Json.pdb")); - // Run AOT by Flax.Build + // Run AOT by Flax.Build (see DotNetAOT) const Char *platform, *architecture, *configuration = ::ToString(data.Configuration); data.GetBuildPlatformName(platform, architecture); const String logFile = data.CacheDirectory / TEXT("AotLog.txt"); @@ -73,69 +75,4 @@ bool PrecompileAssembliesStep::Perform(CookingData& data) } 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); - - // Prepare output directory - config.AotCachePath = data.DataOutputPath / TEXT("Mono/lib/mono/aot-cache"); - switch (data.Tools->GetArchitecture()) - { - case ArchitectureType::x86: - config.AotCachePath /= TEXT("x86"); - break; - case ArchitectureType::x64: - config.AotCachePath /= TEXT("amd64"); - break; - default: - data.Error(TEXT("Not supported AOT architecture")); - return true; - } - if (!FileSystem::DirectoryExists(config.AotCachePath)) - { - if (FileSystem::CreateDirectory(config.AotCachePath)) - { - data.Error(TEXT("Failed to setup AOT output directory.")); - return true; - } - } - - // Collect assemblies for AOT - // TODO: don't perform AOT on all assemblies but only ones used by the game and engine assemblies - for (auto& dir : config.AssembliesSearchDirs) - FileSystem::DirectoryGetFiles(config.Assemblies, dir, TEXT("*.dll"), DirectorySearchOption::TopDirectoryOnly); - for (auto& binaryModule : data.BinaryModules) - if (binaryModule.ManagedPath.HasChars()) - config.Assemblies.Add(data.ManagedCodeOutputPath / binaryModule.ManagedPath); - // TODO: move AOT to Flax.Build and perform it on all C# assemblies used in target build - config.Assemblies.Add(data.ManagedCodeOutputPath / TEXT("Newtonsoft.Json.dll")); - - // Perform AOT for the assemblies - for (int32 i = 0; i < config.Assemblies.Count(); i++) - { - BUILD_STEP_CANCEL_CHECK; - - if (data.Tools->OnPerformAOT(data, config, config.Assemblies[i])) - return true; - - data.StepProgress(infoMsg, static_cast(i) / config.Assemblies.Count()); - } - - BUILD_STEP_CANCEL_CHECK; - - if (data.Tools->OnPostProcessAOT(data, config)) - return true; - - // TODO: maybe remove GAC/assemblies? aot-cache could be only used in the build game - - return false; }