From 4528cce71c0fdc608511982174f4f010cc15a40b Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 30 Mar 2023 18:38:58 +0200 Subject: [PATCH] Fixes for macOS game building --- Source/Editor/Cooker/Steps/CompileScriptsStep.cpp | 4 ++-- Source/Editor/Cooker/Steps/DeployDataStep.cpp | 2 +- Source/Editor/Windows/GameCookerWindow.cs | 15 ++++++++++++++- Source/Engine/Platform/Mac/MacPlatform.cpp | 2 +- Source/Engine/Scripting/Runtime/DotNet.cpp | 13 ++++++++++--- Source/Engine/Scripting/Scripting.cpp | 9 ++++++--- 6 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Source/Editor/Cooker/Steps/CompileScriptsStep.cpp b/Source/Editor/Cooker/Steps/CompileScriptsStep.cpp index c6b1a824f..4adede952 100644 --- a/Source/Editor/Cooker/Steps/CompileScriptsStep.cpp +++ b/Source/Editor/Cooker/Steps/CompileScriptsStep.cpp @@ -95,8 +95,8 @@ bool CompileScriptsStep::DeployBinaries(CookingData& data, const String& path, c Scripting::ProcessBuildInfoPath(e.NativePath, projectFolderPath); Scripting::ProcessBuildInfoPath(e.ManagedPath, projectFolderPath); - e.NativePath = StringUtils::GetFileName(e.NativePath); - e.ManagedPath = StringUtils::GetFileName(e.ManagedPath); + e.NativePath = String(StringUtils::GetFileName(e.NativePath)); + e.ManagedPath = String(StringUtils::GetFileName(e.ManagedPath)); LOG(Info, "Collecting binary module {0}", e.Name); } diff --git a/Source/Editor/Cooker/Steps/DeployDataStep.cpp b/Source/Editor/Cooker/Steps/DeployDataStep.cpp index 4e4227305..123d356a2 100644 --- a/Source/Editor/Cooker/Steps/DeployDataStep.cpp +++ b/Source/Editor/Cooker/Steps/DeployDataStep.cpp @@ -124,7 +124,7 @@ bool DeployDataStep::Perform(CookingData& data) } for (String& version : versions) { - version = StringUtils::GetFileName(version); + version = String(StringUtils::GetFileName(version)); if (!version.StartsWith(TEXT("7."))) version.Clear(); } diff --git a/Source/Editor/Windows/GameCookerWindow.cs b/Source/Editor/Windows/GameCookerWindow.cs index 8f1edc978..88cb1afe4 100644 --- a/Source/Editor/Windows/GameCookerWindow.cs +++ b/Source/Editor/Windows/GameCookerWindow.cs @@ -109,6 +109,8 @@ namespace FlaxEditor.Windows switch (BuildPlatform) { case BuildPlatform.MacOSx64: + case BuildPlatform.MacOSARM64: + case BuildPlatform.iOSARM64: IsSupported = false; break; default: @@ -130,6 +132,7 @@ namespace FlaxEditor.Windows switch (BuildPlatform) { case BuildPlatform.MacOSx64: + case BuildPlatform.MacOSARM64: case BuildPlatform.AndroidARM64: IsSupported = true; break; @@ -228,7 +231,17 @@ namespace FlaxEditor.Windows class Mac : Platform { - protected override BuildPlatform BuildPlatform => BuildPlatform.MacOSx64; + public enum Archs + { + [EditorDisplay(null, "arm64")] + ARM64, + [EditorDisplay(null, "x64")] + x64, + } + + public Archs CPU = Archs.ARM64; + + protected override BuildPlatform BuildPlatform => CPU == Archs.ARM64 ? BuildPlatform.MacOSARM64 : BuildPlatform.MacOSx64; } class Editor : CustomEditor diff --git a/Source/Engine/Platform/Mac/MacPlatform.cpp b/Source/Engine/Platform/Mac/MacPlatform.cpp index c54e80e72..b1d94bc19 100644 --- a/Source/Engine/Platform/Mac/MacPlatform.cpp +++ b/Source/Engine/Platform/Mac/MacPlatform.cpp @@ -360,7 +360,7 @@ String MacPlatform::GetMainDirectory() if (path.EndsWith(TEXT("/Contents/MacOS"))) { // If running from executable in a package, go up to the Contents - path = StringUtils::GetDirectoryName(path); + path = path.Left(path.Length() - 6); } return path; } diff --git a/Source/Engine/Scripting/Runtime/DotNet.cpp b/Source/Engine/Scripting/Runtime/DotNet.cpp index 420f804d8..4d305ea51 100644 --- a/Source/Engine/Scripting/Runtime/DotNet.cpp +++ b/Source/Engine/Scripting/Runtime/DotNet.cpp @@ -278,11 +278,18 @@ bool MCore::LoadEngine() CallStaticMethodByName(TEXT("Init")); #ifdef MCORE_MAIN_MODULE_NAME // MCORE_MAIN_MODULE_NAME define is injected by Scripting.Build.cs on platforms that use separate shared library for engine symbols - const StringAnsi flaxLibraryPath(Platform::GetMainDirectory() / TEXT(MACRO_TO_STR(MCORE_MAIN_MODULE_NAME))); + ::String flaxLibraryPath(Platform::GetMainDirectory() / TEXT(MACRO_TO_STR(MCORE_MAIN_MODULE_NAME))); #else - const StringAnsi flaxLibraryPath(Platform::GetExecutableFilePath()); + ::String flaxLibraryPath(Platform::GetExecutableFilePath()); #endif - RegisterNativeLibrary("FlaxEngine", flaxLibraryPath.Get()); +#if PLATFORM_MAC + // On some platforms all native binaries are side-by-side with the app in a different folder + if (!FileSystem::FileExists(flaxLibraryPath)) + { + flaxLibraryPath = ::String(StringUtils::GetDirectoryName(Platform::GetExecutableFilePath())) / StringUtils::GetFileName(flaxLibraryPath); + } +#endif + RegisterNativeLibrary("FlaxEngine", StringAnsi(flaxLibraryPath).Get()); MRootDomain = New("Root"); MDomains.Add(MRootDomain); diff --git a/Source/Engine/Scripting/Scripting.cpp b/Source/Engine/Scripting/Scripting.cpp index 906d2b836..8796c7587 100644 --- a/Source/Engine/Scripting/Scripting.cpp +++ b/Source/Engine/Scripting/Scripting.cpp @@ -345,9 +345,12 @@ bool Scripting::LoadBinaryModules(const String& path, const String& projectFolde { // Load library const auto startTime = DateTime::NowUTC(); -#if PLATFORM_ANDROID - // On Android all native binaries are side-by-side with the app - nativePath = String(StringUtils::GetDirectoryName(Platform::GetExecutableFilePath())) / StringUtils::GetFileName(nativePath); +#if PLATFORM_ANDROID || PLATFORM_MAC + // On some platforms all native binaries are side-by-side with the app in a different folder + if (!FileSystem::FileExists(nativePath)) + { + nativePath = String(StringUtils::GetDirectoryName(Platform::GetExecutableFilePath())) / StringUtils::GetFileName(nativePath); + } #endif auto library = Platform::LoadLibrary(nativePath.Get()); if (!library)