// SPDX-FileCopyrightText: 2026 Progmasoft // SPDX-License-Identifier: MIT using System; using System.Collections.Generic; namespace Progmasoft.Tazel.Dsl.Common; /// /// A platform Tazel builds for. Each member follows its name on the command line /// (--platform linux-amd64 is ). /// public enum Platform { /// linux-amd64. LinuxAmd64, /// linux-aarch64. LinuxAarch64, /// windows-x64. WindowsX64, /// windows-arm64. WindowsArm64, /// macos-x86_64. MacOSX86_64, /// macos-arm64. MacOSArm64, /// freebsd-amd64. FreeBSDAmd64, /// freebsd-aarch64. FreeBSDAarch64, /// openbsd-amd64. OpenBSDAmd64, /// openbsd-aarch64. OpenBSDAarch64, /// dragonfly-bsd-amd64; DragonFly BSD runs on x86-64 only. DragonFlyBSDAmd64, } /// An operating system, as conditions in a project file see it. public enum OS { /// Linux. Linux, /// Windows. Windows, /// macOS. MacOS, /// FreeBSD. FreeBSD, /// OpenBSD. OpenBSD, /// DragonFly BSD. DragonFlyBSD, } /// A processor architecture. public enum Arch { /// x86-64. X64, /// 64-bit ARM. Arm64, } /// How a build compiles: for debugging, or optimized. public enum BuildMode { /// Not optimized, with debug information. Debug, /// Optimized, without assertions. Release, } /// The names, systems and architectures of the platforms. public static class Platforms { private static readonly (Platform Platform, string Name, OS OS, Arch Arch)[] All = [ (Platform.LinuxAmd64, "linux-amd64", OS.Linux, Arch.X64), (Platform.LinuxAarch64, "linux-aarch64", OS.Linux, Arch.Arm64), (Platform.WindowsX64, "windows-x64", OS.Windows, Arch.X64), (Platform.WindowsArm64, "windows-arm64", OS.Windows, Arch.Arm64), (Platform.MacOSX86_64, "macos-x86_64", OS.MacOS, Arch.X64), (Platform.MacOSArm64, "macos-arm64", OS.MacOS, Arch.Arm64), (Platform.FreeBSDAmd64, "freebsd-amd64", OS.FreeBSD, Arch.X64), (Platform.FreeBSDAarch64, "freebsd-aarch64", OS.FreeBSD, Arch.Arm64), (Platform.OpenBSDAmd64, "openbsd-amd64", OS.OpenBSD, Arch.X64), (Platform.OpenBSDAarch64, "openbsd-aarch64", OS.OpenBSD, Arch.Arm64), (Platform.DragonFlyBSDAmd64, "dragonfly-bsd-amd64", OS.DragonFlyBSD, Arch.X64), ]; /// Every platform name, in the order of the enum. public static IReadOnlyList Names { get; } = Array.ConvertAll(All, entry => entry.Name); /// The name of on the command line. public static string Name(this Platform platform) => Find(platform).Name; /// The operating system of . public static OS GetOS(this Platform platform) => Find(platform).OS; /// The architecture of . public static Arch GetArch(this Platform platform) => Find(platform).Arch; /// Whether is a platform name, and which. public static bool TryParse(string name, out Platform platform) { foreach (var entry in All) { if (string.Equals(entry.Name, name, StringComparison.Ordinal)) { platform = entry.Platform; return true; } } platform = default; return false; } private static (Platform Platform, string Name, OS OS, Arch Arch) Find(Platform platform) { foreach (var entry in All) { if (entry.Platform == platform) { return entry; } } throw new ArgumentOutOfRangeException(nameof(platform), platform, "not a platform"); } }