Add .Net Runtime deployment for cooked game

This commit is contained in:
Wojtek Figat
2023-03-13 10:23:42 +01:00
parent e83b8afdd3
commit e00bf92f05
14 changed files with 186 additions and 50 deletions

View File

@@ -194,7 +194,7 @@ public:
API_FIELD(ReadOnly) String OriginalOutputPath;
/// <summary>
/// The output path for data files (Content, Mono, etc.).
/// The output path for data files (Content, Dotnet, Mono, etc.).
/// </summary>
API_FIELD(ReadOnly) String DataOutputPath;
@@ -306,13 +306,11 @@ public:
/// <summary>
/// Gets the absolute path to the Platform Data folder that contains the binary files used by the current build configuration.
/// </summary>
/// <returns>The platform data folder path.</returns>
String GetGameBinariesPath() const;
/// <summary>
/// Gets the absolute path to the platform folder that contains the dependency files used by the current build configuration.
/// </summary>
/// <returns>The platform deps folder path.</returns>
String GetPlatformBinariesRoot() const;
public:

View File

@@ -34,6 +34,11 @@ ArchitectureType LinuxPlatformTools::GetArchitecture() const
return ArchitectureType::x64;
}
bool LinuxPlatformTools::UseSystemDotnet() const
{
return true;
}
bool LinuxPlatformTools::OnDeployBinaries(CookingData& data)
{
const auto gameSettings = GameSettings::Get();

View File

@@ -18,6 +18,7 @@ public:
const Char* GetName() const override;
PlatformType GetPlatform() const override;
ArchitectureType GetArchitecture() const override;
bool UseSystemDotnet() const override;
bool OnDeployBinaries(CookingData& data) override;
};

View File

@@ -59,6 +59,11 @@ ArchitectureType MacPlatformTools::GetArchitecture() const
return _arch;
}
bool MacPlatformTools::UseSystemDotnet() const
{
return true;
}
bool MacPlatformTools::IsNativeCodeFile(CookingData& data, const String& file)
{
String extension = FileSystem::GetExtension(file);

View File

@@ -23,6 +23,7 @@ public:
const Char* GetName() const override;
PlatformType GetPlatform() const override;
ArchitectureType GetArchitecture() const override;
bool UseSystemDotnet() const override;
bool IsNativeCodeFile(CookingData& data, const String& file) override;
void OnBuildStarted(CookingData& data) override;
bool OnPostProcess(CookingData& data) override;

View File

@@ -33,6 +33,11 @@ ArchitectureType WindowsPlatformTools::GetArchitecture() const
return _arch;
}
bool WindowsPlatformTools::UseSystemDotnet() const
{
return true;
}
bool WindowsPlatformTools::OnDeployBinaries(CookingData& data)
{
const auto platformSettings = WindowsPlatformSettings::Get();

View File

@@ -29,6 +29,7 @@ public:
const Char* GetName() const override;
PlatformType GetPlatform() const override;
ArchitectureType GetArchitecture() const override;
bool UseSystemDotnet() const override;
bool OnDeployBinaries(CookingData& data) override;
void OnRun(CookingData& data, String& executableFile, String& commandLineFormat, String& workingDir) override;
};

View File

@@ -24,36 +24,39 @@ public:
/// <summary>
/// Gets the name of the platform for UI and logging.
/// </summary>
/// <returns>The name.</returns>
virtual const Char* GetDisplayName() const = 0;
/// <summary>
/// Gets the name of the platform for filesystem cache directories, deps folder.
/// </summary>
/// <returns>The name.</returns>
virtual const Char* GetName() const = 0;
/// <summary>
/// Gets the type of the platform.
/// </summary>
/// <returns>The platform type.</returns>
virtual PlatformType GetPlatform() const = 0;
/// <summary>
/// Gets the architecture of the platform.
/// </summary>
/// <returns>The architecture type.</returns>
virtual ArchitectureType GetArchitecture() const = 0;
/// <summary>
/// Gets the value indicating whenever platform requires AOT.
/// Gets the value indicating whenever platform requires AOT (needs C# assemblies to be precompiled).
/// </summary>
/// <returns>True if platform uses AOT and needs C# assemblies to be precompiled, otherwise false.</returns>
virtual bool UseAOT() const
{
return false;
}
/// <summary>
/// Gets the value indicating whenever platform supports using system-installed .Net Runtime.
/// </summary>
virtual bool UseSystemDotnet() const
{
return false;
}
/// <summary>
/// Gets the texture format that is supported by the platform for a given texture.
/// </summary>

View File

@@ -1,19 +1,22 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#include "DeployDataStep.h"
#include "Engine/Platform/File.h"
#include "Engine/Platform/FileSystem.h"
#include "Editor/Cooker/PlatformTools.h"
#include "Engine/Core/Collections/Sorting.h"
#include "Engine/Core/Config/BuildSettings.h"
#include "Engine/Core/Config/GameSettings.h"
#include "Engine/Renderer/ReflectionsPass.h"
#include "Engine/Renderer/AntiAliasing/SMAA.h"
#include "Engine/Engine/Globals.h"
#include "Editor/Cooker/PlatformTools.h"
bool DeployDataStep::Perform(CookingData& data)
{
data.StepProgress(TEXT("Deploying engine data"), 0);
const String depsRoot = data.GetPlatformBinariesRoot();
const auto gameSettings = GameSettings::Get();
const auto& gameSettings = *GameSettings::Get();
const auto& buildSettings = *BuildSettings::Get();
// Setup output folders and copy required data
const auto contentDir = data.DataOutputPath / TEXT("Content");
@@ -26,24 +29,24 @@ bool DeployDataStep::Perform(CookingData& data)
Platform::Sleep(10);
}
FileSystem::CreateDirectory(contentDir);
const String dstMono = data.DataOutputPath / TEXT("Mono");
#if USE_NETCORE
// TODO: Optionally copy all files needed for self-contained deployment
{
// Remove old Mono files
FileSystem::DeleteDirectory(data.DataOutputPath / TEXT("Mono"));
FileSystem::DeleteDirectory(dstMono);
FileSystem::DeleteFile(data.DataOutputPath / TEXT("MonoPosixHelper.dll"));
}
#else
const auto srcMono = depsRoot / TEXT("Mono");
const auto dstMono = data.DataOutputPath / TEXT("Mono");
if (!FileSystem::DirectoryExists(dstMono))
{
// Deploy Mono files (from platform data folder)
const String srcMono = depsRoot / TEXT("Mono");
if (!FileSystem::DirectoryExists(srcMono))
{
data.Error(TEXT("Missing Mono runtime data files."));
return true;
}
if (FileSystem::CopyDirectory(dstMono, srcMono, true))
{
data.Error(TEXT("Failed to copy Mono runtime data files."));
@@ -51,6 +54,101 @@ bool DeployDataStep::Perform(CookingData& data)
}
}
#endif
const String dstDotnet = data.DataOutputPath / TEXT("Dotnet");
if (buildSettings.SkipDotnetPackaging && data.Tools->UseSystemDotnet())
{
// Use system-installed .Net Runtime
FileSystem::DeleteDirectory(dstDotnet);
}
else
{
// Deploy .Net Runtime files
FileSystem::CreateDirectory(dstDotnet);
String srcDotnet = depsRoot / TEXT("Dotnet");
if (FileSystem::DirectoryExists(srcDotnet))
{
// Use prebuilt .Net installation for that platform
if (FileSystem::CopyDirectory(dstMono, srcDotnet, true))
{
data.Error(TEXT("Failed to copy .Net runtime data files."));
return true;
}
}
else
{
bool canUseSystemDotnet = false;
switch (data.Platform)
{
case BuildPlatform::Windows32:
case BuildPlatform::Windows64:
canUseSystemDotnet = PLATFORM_TYPE == PlatformType::Windows;
break;
case BuildPlatform::LinuxX64:
canUseSystemDotnet = PLATFORM_TYPE == PlatformType::Linux;
break;
case BuildPlatform::MacOSx64:
case BuildPlatform::MacOSARM64:
canUseSystemDotnet = PLATFORM_TYPE == PlatformType::Mac;
break;
}
if (!canUseSystemDotnet)
{
data.Error(TEXT("Missing .Net files for a target platform."));
return true;
}
// Ask Flax.Build to provide .Net SDK location for current platform (assuming there are no prebuilt dotnet files)
String sdks;
bool failed = ScriptsBuilder::RunBuildTool(TEXT("-log -printSDKs -logfile=SDKs.txt"), data.CacheDirectory);
failed |= File::ReadAllText(data.CacheDirectory / TEXT("SDKs.txt"), sdks);
int32 idx = sdks.Find(TEXT("] DotNetSdk, "), StringSearchCase::CaseSensitive);
if (idx != -1)
{
idx = sdks.Find(TEXT(", "), StringSearchCase::CaseSensitive, idx + 14);
idx += 2;
int32 end = sdks.Find(TEXT("\n"), StringSearchCase::CaseSensitive, idx);
if (sdks[end] == '\r')
end--;
srcDotnet = String(sdks.Get() + idx, end - idx).TrimTrailing();
}
if (failed || !FileSystem::DirectoryExists(srcDotnet))
{
data.Error(TEXT("Failed to get .Net SDK location for a current platform."));
return true;
}
// Select version to use
Array<String> versions;
FileSystem::GetChildDirectories(versions, srcDotnet / TEXT("host/fxr"));
if (versions.Count() == 0)
{
data.Error(TEXT("Failed to get .Net SDK location for a current platform."));
return true;
}
for (String& version : versions)
{
version = StringUtils::GetFileName(version);
if (!version.StartsWith(TEXT("7.")))
version.Clear();
}
Sorting::QuickSort(versions.Get(), versions.Count());
const String version = versions.Last();
LOG(Info, "Using .Net Runtime {} at {}", version, srcDotnet);
// Deploy runtime files
FileSystem::CopyFile(dstDotnet / TEXT("LICENSE.TXT"), srcDotnet / TEXT("LICENSE.txt"));
FileSystem::CopyFile(dstDotnet / TEXT("LICENSE.TXT"), srcDotnet / TEXT("LICENSE.TXT"));
FileSystem::CopyFile(dstDotnet / TEXT("THIRD-PARTY-NOTICES.TXT"), srcDotnet / TEXT("ThirdPartyNotices.txt"));
FileSystem::CopyFile(dstDotnet / TEXT("THIRD-PARTY-NOTICES.TXT"), srcDotnet / TEXT("THIRD-PARTY-NOTICES.TXT"));
failed |= FileSystem::CopyDirectory(dstDotnet / TEXT("host/fxr") / version, srcDotnet / TEXT("host/fxr") / version, true);
failed |= FileSystem::CopyDirectory(dstDotnet / TEXT("shared/Microsoft.NETCore.App") / version, srcDotnet / TEXT("shared/Microsoft.NETCore.App") / version, true);
if (failed)
{
data.Error(TEXT("Failed to copy .Net runtime data files."));
return true;
}
}
}
// Deploy engine data for the target platform
if (data.Tools->OnDeployBinaries(data))
@@ -91,7 +189,7 @@ bool DeployDataStep::Perform(CookingData& data)
data.AddRootEngineAsset(TEXT("Engine/DefaultMaterial"));
data.AddRootEngineAsset(TEXT("Engine/DefaultDeformableMaterial"));
data.AddRootEngineAsset(TEXT("Engine/DefaultTerrainMaterial"));
if (!gameSettings->NoSplashScreen && !gameSettings->SplashScreen.IsValid())
if (!gameSettings.NoSplashScreen && !gameSettings.SplashScreen.IsValid())
data.AddRootEngineAsset(TEXT("Engine/Textures/Logo"));
data.AddRootEngineAsset(TEXT("Engine/Textures/NormalTexture"));
data.AddRootEngineAsset(TEXT("Engine/Textures/BlackTexture"));
@@ -121,7 +219,6 @@ bool DeployDataStep::Perform(CookingData& data)
// Register game assets
data.StepProgress(TEXT("Deploying game data"), 50);
auto& buildSettings = *BuildSettings::Get();
for (auto& e : buildSettings.AdditionalAssets)
data.AddRootAsset(e.GetID());
for (auto& e : buildSettings.AdditionalScenes)