// SPDX-FileCopyrightText: 2026 Progmasoft // SPDX-License-Identifier: MIT using System.Collections.Generic; using System.Runtime.CompilerServices; using Progmasoft.Tazel.Dsl.Common; namespace Progmasoft.Tazel.Dsl.Build.Toolchain.Prelude; /// The actions of a C-family build, as Bazel names them, for the flags of a feature. public enum CCAction { /// Compiling a .c file. CCompile, /// Compiling a .cpp, .cc or .cxx file. CppCompile, /// Compiling a .m file. ObjectiveCCompile, /// Compiling a .mm file. ObjectiveCppCompile, /// Assembling a .s or .S file. Assemble, /// Linking an executable. CppLinkExecutable, /// Linking a shared library. CppLinkSharedLibrary, /// Making a static library with the archiver. CppLinkStaticLibrary, } /// Flags that go to the tool of some actions. public sealed class FlagSet { /// The actions the flags go to. public IReadOnlyList Actions { get; init; } = []; /// The flags, as written. public IReadOnlyList Flags { get; init; } = []; } /// What a feature does and whether it is on by default. public sealed class FeatureSettings { /// Whether the feature is on unless a target or the command line turns it off. public bool Enabled { get; init; } /// The flags of the feature. public IReadOnlyList FlagSets { get; init; } = []; } /// A named set of flags of a toolchain. public sealed class Feature { internal Feature(string name, FeatureSettings settings) { Name = name; Settings = settings; } /// The name targets and --feature use. public string Name { get; } /// What the feature does. public FeatureSettings Settings { get; } } /// The programs of a C-family toolchain; a bare name is looked up on PATH. public sealed class CCTools { /// The C compiler, for .c and .m files. public string? CCompiler { get; init; } /// The C++ compiler, for .cpp and .mm files. public string? CppCompiler { get; init; } /// The program that links; default: the C++ compiler. public string? Linker { get; init; } /// The archiver of static libraries. public string? Archiver { get; init; } } /// A C-family toolchain: the platform it runs on, the one it builds for, its tools and features. public sealed class CCToolchainSettings { /// The platform the tools run on. public Platform ExecutionPlatform { get; init; } /// The platform the tools build for. public Platform TargetPlatform { get; init; } /// The tools. public CCTools Tools { get; init; } = new(); /// The features targets may turn on and off. public IReadOnlyList Features { get; init; } = []; } /// The programs of a Zig toolchain. public sealed class ZigTools { /// The zig program; a bare name is looked up on PATH. public string? Zig { get; init; } } /// A Zig toolchain. public sealed class ZigToolchainSettings { /// The platform zig runs on. public Platform ExecutionPlatform { get; init; } /// The platform zig builds for. public Platform TargetPlatform { get; init; } /// The tools. public ZigTools Tools { get; init; } = new(); } /// C and C++ toolchains and their features. public static class CC { /// A feature, for the Features of toolchains. public static Feature Feature(string name, FeatureSettings settings) { Names.Check(name, "feature name", "a feature"); return new Feature(name, settings); } /// Declares a toolchain; MODULE.csx registers it by its label. public static void Toolchain( string name, CCToolchainSettings settings, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) => Declarations.DeclareToolchain(Family.CC, name, settings, file, line); } /// Objective-C toolchains. public static class ObjectiveC { /// Declares a toolchain; MODULE.csx registers it by its label. public static void Toolchain( string name, CCToolchainSettings settings, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) => Declarations.DeclareToolchain(Family.ObjectiveC, name, settings, file, line); } /// Zig toolchains. public static class Zig { /// Declares a toolchain; MODULE.csx registers it by its label. public static void Toolchain( string name, ZigToolchainSettings settings, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) => Declarations.DeclareToolchain(Family.Zig, name, settings, file, line); }