ModernUO/Projects/BuildTool/Prerequisites/PrerequisiteChecker.cs
Kamron Batman ec4d6a7a85
feat: Adds Build Tool for Publishing/Setup (#2392)
## Summary

Replaces the basic `publish.cmd`/`publish.sh` scripts with an interactive **BuildTool** — a C# console app using [Spectre.Console](https://spectreconsole.net/) that guides users through publishing, prerequisite checking, and cross-compilation.

### Why
The community found the existing publish scripts unhelpful for newcomers. They worked but didn't walk users through the process, didn't check prerequisites, and provided no feedback when things went wrong.

### What's New

**Interactive BuildTool** (`Projects/BuildTool/`)
- NativeAOT-compiled C# console app with true-color ASCII logo and ModernUO brand gold/silver palette
- Guided publish wizard with step-by-step back navigation (Ctrl+C or menu "Back" to go to previous step)
- Prerequisite checking: .NET SDK version, VC++ Redistributable (Windows), native libraries (Linux/macOS)
- .NET SDK auto-install offer via Microsoft's official install scripts
- Platform detection: Windows 10 vs 11 (build number), macOS codenames, Linux distro + kernel version
- Cross-compilation support: skips native library checks, shows target prerequisites after build
- Non-interactive mode for CI: `--config Release --skip-prereqs`
- Backward-compatible positional args: `publish.cmd release win x64` still works

**Shell Wrappers** (`publish.cmd`, `publish.ps1`, `publish.sh`)
- Try native BuildTool binary first (downloaded from GitHub Releases)
- Fall back to `dotnet run --project Projects/BuildTool` if unavailable
- SDK bootstrapping: offer to install .NET if not found

**CI/CD Updates**
- Build/test workflows target `Projects/Application/Application.csproj` instead of the solution (excludes BuildTool and test projects from publish)
- New `build-tool-release.yml` workflow builds NativeAOT binaries for win-x64, win-arm64, osx-arm64, linux-x64, linux-arm64
- Minimum SDK bumped to 10.0.201 (required for Serialization Generator 2.14.3 / Roslyn 5.3.0)

**Other Changes**
- Solution converted from `.sln` to `.slnx`
- Updated README with interactive mode instructions and deployment guidance

## Screenshots

<img width="320" height="378" alt="image" src="https://github.com/user-attachments/assets/83c057c5-3992-4dbd-99fa-0e3c24ef6428" />

<img width="749" height="554" alt="image" src="https://github.com/user-attachments/assets/e4ee4d6f-71d4-47f9-86b6-8fd1ca3c3e7a" />
2026-03-28 21:21:50 -07:00

165 lines
5 KiB
C#

using BuildTool.Platform;
using Spectre.Console;
namespace BuildTool.Prerequisites;
public static class PrerequisiteChecker
{
/// <summary>
/// Runs all prerequisite checks (SDK + native libraries) and displays results.
/// Returns true if all critical prerequisites pass.
/// </summary>
public static bool CheckAll(PlatformInfo platform, string repoRoot, bool interactive)
{
var panel = new Panel("[bold]Checking prerequisites[/]")
.Border(BoxBorder.Rounded)
.BorderColor(Branding.Gold)
.Padding(1, 0);
AnsiConsole.Write(panel);
AnsiConsole.WriteLine();
if (!CheckSdkInternal(platform, repoRoot, interactive))
{
return false;
}
return CheckNativeLibrariesInternal(platform, interactive);
}
/// <summary>
/// Checks only the .NET SDK (sufficient for cross-compilation).
/// Returns true if the SDK is available.
/// </summary>
public static bool CheckSdk(PlatformInfo platform, string repoRoot, bool interactive)
{
var panel = new Panel("[bold]Checking .NET SDK[/]")
.Border(BoxBorder.Rounded)
.BorderColor(Branding.Gold)
.Padding(1, 0);
AnsiConsole.Write(panel);
AnsiConsole.WriteLine();
var passed = CheckSdkInternal(platform, repoRoot, interactive);
AnsiConsole.WriteLine();
return passed;
}
/// <summary>
/// Checks native libraries for the current platform.
/// Call this only when the publish target matches the current OS.
/// Returns true if all pass or the user chose to continue.
/// </summary>
public static bool CheckNativeLibraries(PlatformInfo platform, bool interactive)
{
AnsiConsole.Write(new Panel("[bold]Checking native libraries[/]")
.Border(BoxBorder.Rounded)
.BorderColor(Branding.Gold)
.Padding(1, 0));
AnsiConsole.WriteLine();
var passed = CheckNativeLibrariesInternal(platform, interactive);
AnsiConsole.WriteLine();
return passed;
}
private static bool CheckSdkInternal(PlatformInfo platform, string repoRoot, bool interactive)
{
var sdkResult = DotNetSdkManager.CheckSdk(repoRoot);
DisplayResult(sdkResult);
if (!sdkResult.Passed)
{
var installed = DotNetSdkManager.OfferInstall(platform, interactive);
if (!installed)
{
return false;
}
sdkResult = DotNetSdkManager.CheckSdk(repoRoot);
if (!sdkResult.Passed)
{
AnsiConsole.MarkupLine("[red]SDK installation may require a terminal restart.[/]");
return false;
}
DisplayResult(sdkResult);
}
return true;
}
private static bool CheckNativeLibrariesInternal(PlatformInfo platform, bool interactive)
{
var nativeResults = NativeLibraryChecker.Check(platform);
var hasMissing = false;
foreach (var result in nativeResults)
{
if (result.IsWarning)
{
continue;
}
DisplayResult(result);
if (!result.Passed)
{
hasMissing = true;
}
}
if (hasMissing)
{
AnsiConsole.WriteLine();
foreach (var result in nativeResults)
{
if (!result.IsWarning)
{
continue;
}
if (result.InstallCommand is not null)
{
AnsiConsole.MarkupLine($" [yellow]:warning: {result.Details}[/]");
AnsiConsole.MarkupLine($" [white on grey23] {result.InstallCommand} [/]");
AnsiConsole.WriteLine();
}
}
if (interactive)
{
var continueAnyway = AnsiConsole.Confirm(
"[yellow]Some prerequisites are missing. Continue anyway?[/]",
defaultValue: false
);
if (!continueAnyway)
{
return false;
}
}
return interactive; // In interactive mode, user chose to continue
}
AnsiConsole.MarkupLine("[green]:check_mark_button: All prerequisites satisfied.[/]");
return true;
}
private static void DisplayResult(PrerequisiteResult result)
{
if (result.IsWarning)
{
return;
}
var icon = result.Passed ? "[green]:check_mark:[/]" : "[red]:cross_mark:[/]";
var details = result.Details is not null ? $" [grey]({Markup.Escape(result.Details)})[/]" : "";
AnsiConsole.MarkupLine($" {icon} {Markup.Escape(result.Name)}{details}");
if (!result.Passed && result.DownloadUrl is not null)
{
AnsiConsole.MarkupLine($" [grey]Download: {result.DownloadUrl}[/]");
}
}
}