// SPDX-FileCopyrightText: 2026 Progmasoft // SPDX-License-Identifier: MIT using System; using System.Collections.Generic; using Progmasoft.Tazel.Dsl.Common; namespace Progmasoft.Tazel.Dsl.Build.Prelude; /// What every target has: what it depends on, who may depend on it, and where it builds. public abstract class TargetSettings { /// The targets this one depends on, by label or by the value their declaration returned. public TargetReferences Depends { get; init; } = TargetReferences.None; /// Who may depend on this target; default: . public Visibility Visibility { get; init; } = Visibility.Private; /// /// The platforms this target builds for; default: all. Elsewhere //... skips it, and naming it is an error. /// public IReadOnlyList TargetConstraints { get; init; } = []; /// Words for this target; manual keeps it out of //.... public IReadOnlyList Tags { get; init; } = []; } /// A toolchain feature a target turns on or off. public sealed class FeatureToggle { internal FeatureToggle(string name, bool enabled) { Name = name; Enabled = enabled; } /// The name of the feature. public string Name { get; } /// Whether it is turned on. public bool Enabled { get; } } /// How an executable links the libraries it depends on. public enum LinkingMode { /// Static libraries where a dependency is one; the default. PreferStatic, /// The same, and system libraries as shared libraries. PreferShared, /// Everything static, the C library included (-static). FullyStatic, } /// What C, C++, Objective-C and Objective-C++ targets compile and how. public abstract class CCSettings : TargetSettings { /// The files to compile; the language of each comes from its extension. public Files Sources { get; init; } = Files.None; /// Headers this target and its dependents include. public Files Headers { get; init; } = Files.None; /// Headers that are included but never compiled alone. public Files TextualHeaders { get; init; } = Files.None; /// /// Directories of this target's headers, for it and its dependents: paths below the package, or "." for /// the package's own directory. /// public IReadOnlyList IncludeDirectories { get; init; } = []; /// Options for every file. public IReadOnlyList CompilerOptions { get; init; } = []; /// Options for .c and .m files. public IReadOnlyList CCompilerOptions { get; init; } = []; /// Options for .cpp, .cc, .cxx and .mm files. public IReadOnlyList CppCompilerOptions { get; init; } = []; /// Options for the link; a library's go to the links of what depends on it. public IReadOnlyList LinkerOptions { get; init; } = []; /// Macros for this target and its dependents. public IReadOnlyList PreprocessorDefinitions { get; init; } = []; /// Macros for this target alone. public IReadOnlyList LocalPreprocessorDefinitions { get; init; } = []; /// Toolchain features this target turns on or off. public IReadOnlyList Features { get; init; } = []; /// Frameworks of the SDK to link (-framework). public IReadOnlyList SdkFrameworks { get; init; } = []; /// Frameworks of the SDK to link weakly (-weak_framework). public IReadOnlyList WeakSdkFrameworks { get; init; } = []; /// Libraries of the SDK or the system to link (-l). public IReadOnlyList SdkDynamicLibraries { get; init; } = []; } /// A static library. public class CCStaticLibrarySettings : CCSettings { /// Whether every object goes into what links it, used or not. public bool AlwaysLink { get; init; } } /// A shared library. public class CCSharedLibrarySettings : CCSettings { /// The version of the library, as in libx.so.1.2.0; default: none. public Version? LibraryVersion { get; init; } /// More files for the linker, such as linker scripts. public Files AdditionalLinkerInputs { get; init; } = Files.None; } /// What a program gets when Tazel runs it. public interface IRunSettings { /// The arguments tazel run and tazel test pass. IReadOnlyList Arguments { get; } /// Files the program reads; they sit in its runfiles directory, where it runs. Files RuntimeData { get; } /// The environment of the program. Dictionary EnvironmentVariables { get; } } /// How a test runs. public interface ITestSettings : IRunSettings { /// Variables of Tazel's environment the test sees too. IReadOnlyList InheritedEnvironmentVariables { get; } /// How much the test may take. TestSize TestSize { get; } /// The time the test may take; default: from . TimeSpan? Timeout { get; } /// Whether a failure is retried, up to three times. bool Flaky { get; } /// How many processes share the test (TEST_TOTAL_SHARDS); default: 1. int ShardCount { get; } /// Whether the test runs on this machine even when execution is remote. bool RunLocally { get; } } /// An executable. public class CCExecutableSettings : CCSettings, IRunSettings { /// How the executable links its libraries. public LinkingMode LinkingMode { get; init; } = LinkingMode.PreferStatic; /// public Files RuntimeData { get; init; } = Files.None; /// public IReadOnlyList Arguments { get; init; } = []; /// public Dictionary EnvironmentVariables { get; init; } = new(); /// Whether the label and the module version are compiled in as macros. public bool StampBuildInformation { get; init; } /// More files for the linker. public Files AdditionalLinkerInputs { get; init; } = Files.None; } /// A test: an executable Tazel runs and judges by its exit status. public class CCTestSettings : CCExecutableSettings, ITestSettings { /// public IReadOnlyList InheritedEnvironmentVariables { get; init; } = []; /// public TestSize TestSize { get; init; } = TestSize.Medium; /// public TimeSpan? Timeout { get; init; } /// public bool Flaky { get; init; } /// public int ShardCount { get; init; } = 1; /// public bool RunLocally { get; init; } }