From 4072796e541616fbc4672160b3a74e95277bf7bf Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 11 Mar 2021 17:22:06 +0100 Subject: [PATCH] Switch impl progress --- Source/ThirdParty/vorbis/vorbis.Build.cs | 2 +- .../Flax.Build/Deps/Dependencies/PhysX.cs | 13 ++++++++ .../Flax.Build/Deps/Dependencies/freetype.cs | 12 +++++++ .../Tools/Flax.Build/Deps/Dependencies/ogg.cs | 15 +++++++++ .../Flax.Build/Deps/Dependencies/vorbis.cs | 31 ++++++++++++++++++- Source/Tools/Flax.Build/Deps/Dependency.cs | 7 ++++- Source/Tools/Flax.Build/Deps/DepsBuilder.cs | 3 +- 7 files changed, 79 insertions(+), 4 deletions(-) diff --git a/Source/ThirdParty/vorbis/vorbis.Build.cs b/Source/ThirdParty/vorbis/vorbis.Build.cs index 0d95d621a..33580959c 100644 --- a/Source/ThirdParty/vorbis/vorbis.Build.cs +++ b/Source/ThirdParty/vorbis/vorbis.Build.cs @@ -40,12 +40,12 @@ public class vorbis : DepsModule break; case TargetPlatform.Linux: case TargetPlatform.Android: + case TargetPlatform.Switch: options.OutputFiles.Add(Path.Combine(depsRoot, "libvorbis.a")); options.OutputFiles.Add(Path.Combine(depsRoot, "libvorbisenc.a")); options.OutputFiles.Add(Path.Combine(depsRoot, "libvorbisfile.a")); break; case TargetPlatform.PS4: - case TargetPlatform.Switch: options.OutputFiles.Add(Path.Combine(depsRoot, "libvorbis.a")); break; default: throw new InvalidPlatformException(options.Platform.Target); diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/PhysX.cs b/Source/Tools/Flax.Build/Deps/Dependencies/PhysX.cs index 32a408828..ddafc8cf4 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/PhysX.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/PhysX.cs @@ -33,6 +33,7 @@ namespace Flax.Deps.Dependencies TargetPlatform.PS4, TargetPlatform.XboxScarlett, TargetPlatform.Android, + TargetPlatform.Switch, }; case TargetPlatform.Linux: return new[] @@ -166,6 +167,12 @@ namespace Flax.Deps.Dependencies binariesPrefix = "lib"; suppressBitsPostfix = true; break; + case TargetPlatform.Switch: + binariesSubDir = "switch64"; + buildPlatform = "NX64"; + suppressBitsPostfix = true; + binariesPrefix = "lib"; + break; default: throw new InvalidPlatformException(targetPlatform); } @@ -354,6 +361,12 @@ namespace Flax.Deps.Dependencies Build(options, "android", platform, TargetArchitecture.ARM64); break; } + case TargetPlatform.Switch: + { + Utilities.DirectoryCopy(Path.Combine(options.PlatformsFolder, "Switch", "Data", "PhysX"), root, true, true); + Build(options, "switch64", platform, TargetArchitecture.ARM64); + break; + } } } diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/freetype.cs b/Source/Tools/Flax.Build/Deps/Dependencies/freetype.cs index 2cd229e40..3790c3f49 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/freetype.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/freetype.cs @@ -31,6 +31,7 @@ namespace Flax.Deps.Dependencies TargetPlatform.PS4, TargetPlatform.XboxScarlett, TargetPlatform.Android, + TargetPlatform.Switch, }; case TargetPlatform.Linux: return new[] @@ -209,6 +210,17 @@ namespace Flax.Deps.Dependencies Utilities.FileCopy(Path.Combine(buildDir, libraryFileName), Path.Combine(depsFolder, libraryFileName)); break; } + case TargetPlatform.Switch: + { + // Build for Switch + var buildDir = Path.Combine(root, "build"); + SetupDirectory(buildDir, true); + RunCmake(buildDir, platform, TargetArchitecture.ARM64, ".. -DCMAKE_BUILD_TYPE=Release"); + Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.None); + var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.ARM64); + Utilities.FileCopy(Path.Combine(buildDir, libraryFileName), Path.Combine(depsFolder, libraryFileName)); + break; + } } } diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/ogg.cs b/Source/Tools/Flax.Build/Deps/Dependencies/ogg.cs index 899fefd88..8bd8e4d95 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/ogg.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/ogg.cs @@ -30,6 +30,7 @@ namespace Flax.Deps.Dependencies TargetPlatform.PS4, TargetPlatform.XboxScarlett, TargetPlatform.Android, + TargetPlatform.Switch, }; case TargetPlatform.Linux: return new[] @@ -180,6 +181,20 @@ namespace Flax.Deps.Dependencies Utilities.FileCopy(Path.Combine(buildDir, libraryFileName), Path.Combine(depsFolder, libraryFileName)); break; } + case TargetPlatform.Switch: + { + // Get the build data files + Utilities.DirectoryCopy(Path.Combine(options.PlatformsFolder, "Switch", "Data", "ogg"), root, true, true); + + // Build for Switch + var buildDir = Path.Combine(root, "build"); + SetupDirectory(buildDir, true); + RunCmake(buildDir, platform, TargetArchitecture.ARM64, ".. -DCMAKE_BUILD_TYPE=Release"); + Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.None); + var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.ARM64); + Utilities.FileCopy(Path.Combine(buildDir, libraryFileName), Path.Combine(depsFolder, libraryFileName)); + break; + } } } diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/vorbis.cs b/Source/Tools/Flax.Build/Deps/Dependencies/vorbis.cs index 714a14630..8146c4dc0 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/vorbis.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/vorbis.cs @@ -31,6 +31,7 @@ namespace Flax.Deps.Dependencies TargetPlatform.PS4, TargetPlatform.XboxScarlett, TargetPlatform.Android, + TargetPlatform.Switch, }; case TargetPlatform.Linux: return new[] @@ -291,7 +292,8 @@ namespace Flax.Deps.Dependencies // Get the source CloneGitRepoFast(root, "https://github.com/xiph/vorbis.git"); - CloneGitRepoFast(oggRoot, "https://github.com/xiph/ogg.git"); + CloneGitRepo(oggRoot, "https://github.com/xiph/ogg.git"); + GitCheckout(oggRoot, "master", "4380566a44b8d5e85ad511c9c17eb04197863ec5"); // Build for Android SetupDirectory(oggBuildDir, true); @@ -305,6 +307,33 @@ namespace Flax.Deps.Dependencies Utilities.FileCopy(Path.Combine(buildDir, file.SrcFolder, file.Filename), Path.Combine(depsFolder, file.Filename)); break; } + case TargetPlatform.Switch: + { + var oggRoot = Path.Combine(root, "ogg"); + var oggBuildDir = Path.Combine(oggRoot, "build"); + var buildDir = Path.Combine(root, "build"); + + // Get the source + CloneGitRepo(root, "https://github.com/xiph/vorbis.git"); + GitCheckout(root, "master", "98eddc72d36e3421519d54b101c09b57e4d4d10d"); + CloneGitRepo(oggRoot, "https://github.com/xiph/ogg.git"); + GitCheckout(oggRoot, "master", "4380566a44b8d5e85ad511c9c17eb04197863ec5"); + Utilities.DirectoryCopy(Path.Combine(options.PlatformsFolder, "Switch", "Data", "ogg"), oggRoot, true, true); + Utilities.DirectoryCopy(Path.Combine(options.PlatformsFolder, "Switch", "Data", "vorbis"), buildDir, true, true); + + // Build for Switch + SetupDirectory(oggBuildDir, true); + RunCmake(oggBuildDir, platform, TargetArchitecture.ARM64, ".. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=\"../install\""); + Utilities.Run("cmake", "--build . --target install", null, oggBuildDir, Utilities.RunOptions.None); + Utilities.FileCopy(Path.Combine(options.PlatformsFolder, "Switch", "Data", "ogg", "include", "ogg", "config_types.h"), Path.Combine(oggRoot, "install", "include", "ogg", "config_types.h")); + SetupDirectory(buildDir, true); + RunCmake(buildDir, platform, TargetArchitecture.ARM64, string.Format(".. -DCMAKE_BUILD_TYPE=Release -DOGG_INCLUDE_DIR=\"{0}/install/include\" -DOGG_LIBRARY=\"{0}/install/lib\"", oggRoot)); + Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.None); + var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.ARM64); + foreach (var file in binariesToCopyUnix) + Utilities.FileCopy(Path.Combine(buildDir, file.SrcFolder, file.Filename), Path.Combine(depsFolder, file.Filename)); + break; + } } } diff --git a/Source/Tools/Flax.Build/Deps/Dependency.cs b/Source/Tools/Flax.Build/Deps/Dependency.cs index 7b85a29be..c19687c2a 100644 --- a/Source/Tools/Flax.Build/Deps/Dependency.cs +++ b/Source/Tools/Flax.Build/Deps/Dependency.cs @@ -1,5 +1,6 @@ // Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. +using System; using System.Collections.Generic; using System.IO; using Flax.Build; @@ -237,11 +238,15 @@ namespace Flax.Deps } case TargetPlatform.Linux: case TargetPlatform.PS4: - case TargetPlatform.Switch: { cmdLine = "CMakeLists.txt"; break; } + case TargetPlatform.Switch: + { + cmdLine = string.Format("-DCMAKE_TOOLCHAIN_FILE=\"{1}\\Source\\Platforms\\Switch\\Data\\Switch.cmake\" -G \"NMake Makefiles\" -DCMAKE_MAKE_PROGRAM=\"{0}..\\..\\VC\\bin\\nmake.exe\"", Environment.GetEnvironmentVariable("VS140COMNTOOLS"), Globals.EngineRoot); + break; + } case TargetPlatform.Android: { var ndk = AndroidNdk.Instance.RootPath; diff --git a/Source/Tools/Flax.Build/Deps/DepsBuilder.cs b/Source/Tools/Flax.Build/Deps/DepsBuilder.cs index 6d6eaf5b3..0b254195d 100644 --- a/Source/Tools/Flax.Build/Deps/DepsBuilder.cs +++ b/Source/Tools/Flax.Build/Deps/DepsBuilder.cs @@ -85,7 +85,8 @@ namespace Flax.Deps continue; } - Dependency.SetupDirectory(options.IntermediateFolder, true); + var forceEmpty = Configuration.ReBuildDeps; + Dependency.SetupDirectory(options.IntermediateFolder, forceEmpty); dependency.Build(options); }