Merge remote-tracking branch 'origin/master' into 1.7

# Conflicts:
#	Source/Engine/Level/Actors/AnimatedModel.cpp
This commit is contained in:
Wojtek Figat
2023-10-05 10:44:03 +02:00
83 changed files with 1809 additions and 519 deletions

View File

@@ -244,7 +244,19 @@ namespace Flax.Build
/// <returns>The toolchain.</returns>
public Toolchain TryGetToolchain(TargetArchitecture targetArchitecture)
{
return HasRequiredSDKsInstalled ? GetToolchain(targetArchitecture) : null;
Toolchain result = null;
if (HasRequiredSDKsInstalled)
{
try
{
result = GetToolchain(targetArchitecture);
}
catch (Exception ex)
{
Log.Exception(ex);
}
}
return result;
}
/// <summary>
@@ -260,16 +272,12 @@ namespace Flax.Build
if (_toolchains == null)
_toolchains = new Dictionary<TargetArchitecture, Toolchain>();
var key = targetArchitecture;
Toolchain toolchain;
if (_toolchains.TryGetValue(key, out toolchain))
{
if (_toolchains.TryGetValue(targetArchitecture, out toolchain))
return toolchain;
}
toolchain = CreateToolchain(targetArchitecture);
_toolchains.Add(key, toolchain);
_toolchains.Add(targetArchitecture, toolchain);
return toolchain;
}

View File

@@ -39,12 +39,6 @@ namespace Flax.Build
[CommandLine("deploy", "Runs the deploy tool.")]
public static bool Deploy = false;
/// <summary>
/// Compresses deployed files.
/// </summary>
[CommandLine("deployDontCompress", "Skips compressing deployed files, and keeps files.")]
public static bool DontCompress = false;
/// <summary>
/// Builds the targets. Builds all the targets, use <see cref="BuildTargets"/> to select a custom set of targets for the build.
/// </summary>

View File

@@ -9,6 +9,12 @@ namespace Flax.Build
{
public static partial class Configuration
{
/// <summary>
/// Compresses deployed files.
/// </summary>
[CommandLine("deployDontCompress", "Skips compressing deployed files, and keeps files.")]
public static bool DontCompress = false;
/// <summary>
/// Package deployment output path.
/// </summary>
@@ -28,9 +34,9 @@ namespace Flax.Build
public static bool DeployPlatforms;
/// <summary>
/// Certificate file path for binaries signing.
/// Certificate file path for binaries signing. Or sign identity for Apple platforms.
/// </summary>
[CommandLine("deployCert", "Certificate file path for binaries signing.")]
[CommandLine("deployCert", "Certificate file path for binaries signing. Or sign identity for Apple platforms.")]
public static string DeployCert;
/// <summary>

View File

@@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using Flax.Build;
using Flax.Build.Platforms;
@@ -17,11 +18,15 @@ namespace Flax.Deploy
{
if (string.IsNullOrEmpty(Configuration.DeployCert))
return;
Log.Info("Code signing file: " + file);
switch (Platform.BuildTargetPlatform)
{
case TargetPlatform.Windows:
VCEnvironment.CodeSign(file, Configuration.DeployCert, Configuration.DeployCertPass);
break;
case TargetPlatform.Mac:
MacPlatform.CodeSign(file, Configuration.DeployCert);
break;
}
}
@@ -122,6 +127,45 @@ namespace Flax.Deploy
// Deploy project
DeployFile(RootPath, OutputPath, "Flax.flaxproj");
// Package Editor into macOS app
if (Platform.BuildTargetPlatform == TargetPlatform.Mac)
{
var arch = Platform.BuildTargetArchitecture;
Log.Info(string.Empty);
Log.Info("Creating macOS app...");
var appPath = Path.Combine(Deployer.PackageOutputPath, "FlaxEditor.app");
var appContentsPath = Path.Combine(appPath, "Contents");
var appBinariesPath = Path.Combine(appContentsPath, "MacOS");
Utilities.DirectoryDelete(appPath);
Directory.CreateDirectory(appPath);
Directory.CreateDirectory(appContentsPath);
Directory.CreateDirectory(appBinariesPath);
// Copy icons set
Directory.CreateDirectory(Path.Combine(appContentsPath, "Resources"));
Utilities.FileCopy(Path.Combine(Globals.EngineRoot, "Source/Platforms/Mac/Default.icns"), Path.Combine(appContentsPath, "Resources/icon.icns"));
// Create PkgInfo file
File.WriteAllText(Path.Combine(appContentsPath, "PkgInfo"), "APPL???", Encoding.ASCII);
// Create Info.plist
var plist = File.ReadAllText(Path.Combine(Globals.EngineRoot, "Source/Platforms/Mac/Default.plist"));
var flaxProject = EngineTarget.EngineProject;
plist = plist.Replace("{Version}", flaxProject.Version.ToString());
plist = plist.Replace("{Copyright}", flaxProject.Copyright);
plist = plist.Replace("{Executable}", "FlaxEditor");
plist = plist.Replace("{Arch}", arch == TargetArchitecture.ARM64 ? "arm64" : "x86_64");
File.WriteAllText(Path.Combine(appContentsPath, "Info.plist"), plist, Encoding.ASCII);
// Copy output editor files
Utilities.DirectoryCopy(OutputPath, appContentsPath);
// Copy native binaries for app execution
var defaultEditorConfig = "Development";
var ediotrBinariesPath = Path.Combine(appContentsPath, "Binaries/Editor/Mac", defaultEditorConfig);
Utilities.DirectoryCopy(ediotrBinariesPath, appBinariesPath, true, true);
}
// Compress
if (Configuration.DontCompress)
return;
@@ -254,6 +298,10 @@ namespace Flax.Deploy
Utilities.Run("strip", "FlaxEditor", null, dst, Utilities.RunOptions.None);
Utilities.Run("strip", "FlaxEditor.dylib", null, dst, Utilities.RunOptions.None);
Utilities.Run("strip", "libMoltenVK.dylib", null, dst, Utilities.RunOptions.None);
CodeSign(Path.Combine(dst, "FlaxEditor"));
CodeSign(Path.Combine(dst, "FlaxEditor.dylib"));
CodeSign(Path.Combine(dst, "libMoltenVK.dylib"));
}
}
}

View File

@@ -42,19 +42,7 @@ namespace Flax.Build.Platforms
var subdirs = Directory.GetDirectories(Path.Combine(AndroidSdk.Instance.RootPath, "ndk"));
if (subdirs.Length != 0)
{
Array.Sort(subdirs, (a, b) =>
{
Version va, vb;
if (Version.TryParse(a, out va))
{
if (Version.TryParse(b, out vb))
return va.CompareTo(vb);
return 1;
}
if (Version.TryParse(b, out vb))
return -1;
return 0;
});
Utilities.SortVersionDirectories(subdirs);
sdkPath = subdirs.Last();
}
}

View File

@@ -37,7 +37,7 @@ namespace Flax.Build.Platforms
public LinuxPlatform()
{
// Try to use system compiler
if (Platform.BuildTargetPlatform == TargetPlatform.Linux)
if (BuildTargetPlatform == TargetPlatform.Linux)
{
// Pick the newest compiler (overriden by specified in command line)
if (Which(Configuration.Compiler) != null)
@@ -67,7 +67,7 @@ namespace Flax.Build.Platforms
Log.Verbose($"Using native Linux toolchain (compiler {Compiler})");
HasRequiredSDKsInstalled = true;
}
else if (Platform.BuildTargetPlatform != TargetPlatform.Mac)
else if (BuildTargetPlatform != TargetPlatform.Mac)
{
// Check if Linux toolchain is installed
string toolchainName = "v13_clang-7.0.1-centos7";
@@ -76,9 +76,11 @@ namespace Flax.Build.Platforms
{
if (string.IsNullOrEmpty(toolchainsRoot))
{
Log.Warning("Missing Linux Toolchain. Cannot build for Linux platform.");
if (BuildTargetPlatform == TargetPlatform.Linux)
Log.Warning("Missing Linux Toolchain. Cannot build for Linux platform.");
else
Log.Verbose("Missing Linux Toolchain. Cannot build for Linux platform.");
}
return;
}

View File

@@ -1,5 +1,7 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace Flax.Build.Platforms
@@ -44,6 +46,24 @@ namespace Flax.Build.Platforms
}
}
/// <summary>
/// Runs codesign tool on macOS to sign the code with a given identity from local keychain.
/// </summary>
/// <param name="file">Path to file to codesign.</param>
/// <param name="signIdenity">App code signing idenity name (from local Mac keychain). Use 'security find-identity -v -p codesigning' to list possible options.</param>
public static void CodeSign(string file, string signIdenity)
{
if (!File.Exists(file))
throw new FileNotFoundException("Missing file to sign.", file);
string cmdLine = string.Format("--force --timestamp -s \"{0}\" \"{1}\"", signIdenity, file);
if (string.IsNullOrEmpty(Path.GetExtension(file)))
{
// Add entitlements file with some settings for the app execution
cmdLine += string.Format(" --entitlements \"{0}\"", Path.Combine(Globals.EngineRoot, "Source/Platforms/Mac/Default.entitlements"));
}
Utilities.Run("codesign", cmdLine, null, null, Utilities.RunOptions.Default | Utilities.RunOptions.ThrowExceptionOnError);
}
/// <summary>
/// Returns true if running an x64 binary an arm64 host machine.
/// </summary>

View File

@@ -24,6 +24,13 @@ namespace Flax.Build.Projects.VisualStudio
/// <inheritdoc />
public override void Generate(string solutionPath)
{
// Try to reuse the existing project guid from existing files
ProjectGuid = GetProjectGuid(Path, Name);
if (ProjectGuid == Guid.Empty)
ProjectGuid = GetProjectGuid(solutionPath, Name);
if (ProjectGuid == Guid.Empty)
ProjectGuid = Guid.NewGuid();
var gen = (VisualStudioProjectGenerator)Generator;
var projectFileToolVersion = gen.ProjectFileToolVersion;
var vcProjectFileContent = new StringBuilder();
@@ -500,7 +507,15 @@ namespace Flax.Build.Projects.VisualStudio
firstEditorMatch = i;
}
}
if (firstFullMatch != -1)
if (project is AndroidProject)
{
// Utility Android deploy project only for exact match
if (firstFullMatch != -1)
projectConfiguration = configuration;
else
projectConfiguration = new SolutionConfiguration(project.Configurations[0]);
}
else if (firstFullMatch != -1)
{
projectConfiguration = configuration;
build = solution.MainProject == project || (solution.MainProject == null && project.Name == solution.Name);
@@ -588,8 +603,8 @@ namespace Flax.Build.Projects.VisualStudio
{
var profiles = new Dictionary<string, string>();
var profile = new StringBuilder();
var editorPath = Utilities.NormalizePath(Path.Combine(Globals.EngineRoot, Platform.GetEditorBinaryDirectory(), $"Development/FlaxEditor{Utilities.GetPlatformExecutableExt()}"));
var workspacePath = Utilities.NormalizePath(solutionDirectory);
var editorPath = Utilities.NormalizePath(Path.Combine(Globals.EngineRoot, Platform.GetEditorBinaryDirectory(), $"Development/FlaxEditor{Utilities.GetPlatformExecutableExt()}")).Replace('\\', '/');
var workspacePath = Utilities.NormalizePath(solutionDirectory).Replace('\\', '/');
foreach (var project in projects)
{
if (project.Type == TargetType.DotNetCore)

View File

@@ -758,8 +758,30 @@ namespace Flax.Build
{
extEnding = "";
}
return extEnding;
}
/// <summary>
/// Sorts the directories by name assuming they contain version text. Sorted from lowest to the highest version.
/// </summary>
/// <param name="paths">The paths array to sort.</param>
public static void SortVersionDirectories(string[] paths)
{
if (paths == null || paths.Length == 0)
return;
Array.Sort(paths, (a, b) =>
{
Version va, vb;
if (Version.TryParse(a, out va))
{
if (Version.TryParse(b, out vb))
return va.CompareTo(vb);
return 1;
}
if (Version.TryParse(b, out vb))
return -1;
return 0;
});
}
}
}