diff --git a/OpenDreamPackageTool/Program.cs b/OpenDreamPackageTool/Program.cs index 2c56bc54e6..5da86d3830 100644 --- a/OpenDreamPackageTool/Program.cs +++ b/OpenDreamPackageTool/Program.cs @@ -9,18 +9,18 @@ public class Options { } public class ServerOptions : Options { - public PlatformReg? Platform; + public string? Platform; public bool HybridAcz; public bool InPlatformSubDir = true; public bool TgsEngineBuild; } public class ClientOptions : Options { - public PlatformReg? Platform; + } public class TgsOptions : Options { - public PlatformReg? Platform; + // Avoid adding arguments for TGS, to give us more flexibility while keeping compatibility } public static readonly string[] SharedIgnoredResources = { @@ -97,21 +97,13 @@ private static bool TryParseArgs(string[] args, [NotNullWhen(true)] out Options? return false; } - var platformRId = args[++i]; - - serverOptions.Platform = - ServerPackaging.Platforms.First(p => p.RId == platformRId); - if (serverOptions.Platform == null) { - Console.Error.WriteLine($"Invalid platform '{platformRId}'"); - return false; - } - + serverOptions.Platform = args[++i]; break; case "--hybrid-acz": serverOptions.HybridAcz = true; break; default: - Console.Error.WriteLine($"Unknown argument '{arg}'"); + Console.Error.WriteLine($"Invalid argument '{arg}'"); return false; } } @@ -135,7 +127,7 @@ private static bool TryParseArgs(string[] args, [NotNullWhen(true)] out Options? clientOptions.SkipBuild = true; break; default: - Console.Error.WriteLine($"Unknown argument '{arg}'"); + Console.Error.WriteLine($"Invalid argument '{arg}'"); return false; } } @@ -157,35 +149,13 @@ private static bool TryParseArgs(string[] args, [NotNullWhen(true)] out Options? break; case "--skip-build": tgsOptions.SkipBuild = true; - break; - case "--platform": - case "-p": - if (i + 1 >= args.Length) { - Console.Error.WriteLine("No platform given"); - return false; - } - - var platformRId = args[++i]; - - tgsOptions.Platform = - ServerPackaging.Platforms.First(p => p.RId == platformRId); - if (tgsOptions.Platform == null) { - Console.Error.WriteLine($"Invalid platform '{platformRId}'"); - return false; - } - break; default: - Console.Error.WriteLine($"Unknown argument '{arg}'"); + Console.Error.WriteLine($"Invalid argument '{arg}'"); return false; } } - if (tgsOptions.Platform == null) { - Console.Error.WriteLine("A '--platform' argument is required for a tgs package"); - return false; - } - return true; } diff --git a/OpenDreamPackageTool/ServerPackaging.cs b/OpenDreamPackageTool/ServerPackaging.cs index fdc83c4023..5517f8ae10 100644 --- a/OpenDreamPackageTool/ServerPackaging.cs +++ b/OpenDreamPackageTool/ServerPackaging.cs @@ -5,7 +5,7 @@ namespace OpenDreamPackageTool; public static class ServerPackaging { - public static readonly PlatformReg[] Platforms = { + private static readonly PlatformReg[] Platforms = { new("win-x64", "Windows", true), new("linux-x64", "Linux", true), new("linux-arm64", "Linux", true), @@ -64,16 +64,17 @@ public static class ServerPackaging { "zh-Hant" }; - public static IEnumerable PlatformRIds => Platforms.Select(platform => platform.RId); - - public static IEnumerable PlatformsDefault => Platforms.Where(platform => platform.BuildByDefault); + private static IEnumerable PlatformsDefault => Platforms.Where(platform => platform.BuildByDefault); public static void Package(Program.ServerOptions options) { - IEnumerable platforms = (options.Platform != null) ? new[] {options.Platform} : PlatformsDefault; + IEnumerable platforms = PlatformsDefault; + if (options.Platform != null) { + platforms = new[] { GetPlatform(options.Platform) }; + } if (!options.InPlatformSubDir && options.Platform == null) { Console.Error.WriteLine( - "Packaging the server without a platform subdirectory requires selecting a single platform"); + "Packaging the server without a platform subdirectory requires a '--platform' argument"); } if (Directory.Exists(options.OutputDir)) { @@ -99,6 +100,14 @@ public static void Package(Program.ServerOptions options) { } } + public static PlatformReg GetPlatform(string rId) { + var platform = Platforms.FirstOrDefault(p => p.RId == rId); + if (platform == null) + throw new NotSupportedException($"Platform \"{rId}\" is not supported"); + + return platform; + } + private static void BuildPlatform(PlatformReg platform, Program.ServerOptions options) { Console.WriteLine($"Building project for {platform.RId}"); diff --git a/OpenDreamPackageTool/TgsPackaging.cs b/OpenDreamPackageTool/TgsPackaging.cs index cab39c5923..78a5a90894 100644 --- a/OpenDreamPackageTool/TgsPackaging.cs +++ b/OpenDreamPackageTool/TgsPackaging.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Runtime.InteropServices; using Robust.Packaging.Utility; namespace OpenDreamPackageTool; @@ -10,17 +11,18 @@ public static void Package(Program.TgsOptions options) { Directory.Delete(options.OutputDir, true); } + var platform = DeterminePlatform(); + // Package the server to /bin/server ServerPackaging.Package(new Program.ServerOptions { OutputDir = Path.Combine(options.OutputDir, "bin", "server"), - Platform = options.Platform, + Platform = platform.RId, HybridAcz = true, // Force Hybrid ACZ with TGS SkipBuild = options.SkipBuild, InPlatformSubDir = false, TgsEngineBuild = true }); - var platform = options.Platform!; if (!options.SkipBuild) { ProcessHelpers.RunCheck(new ProcessStartInfo { FileName = "dotnet", @@ -57,4 +59,32 @@ private static void PublishCompiler(string platformRId, string targetOs) { } }).Wait(); } + + /// + /// Determine what platform to package for, based on what OS we're currently running on + /// + /// The platform + private static PlatformReg DeterminePlatform() { + string rId; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { + rId = "win"; + } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { + rId = "linux"; + } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { + rId = "osx"; + } else { + throw new NotSupportedException("Your OS is not supported"); + } + + rId += RuntimeInformation.OSArchitecture switch { + Architecture.X64 => "-x64", + Architecture.X86 => "-x86", + Architecture.Arm64 => "-arm64", + Architecture.Arm => "-arm", + _ => throw new NotSupportedException( + $"Your architecture ({RuntimeInformation.OSArchitecture}) is not supported") + }; + + return ServerPackaging.GetPlatform(rId); + } }