ada_toolchain

Rules

Providers

ada_toolchain

load("@rules_ada//ada:ada_toolchain.bzl", "ada_toolchain")

ada_toolchain(name, ada_std, ar, args, artifact_name_patterns, bind_flags, binder, compile_flags,
              compiler, compiler_id, compiler_lib, dynamic_runtime_lib, enabled_features, gcov,
              known_features, static_runtime_lib, target_triple)

Defines an Ada toolchain: the GNAT compiler (gcc), binder (gnatbind) and archiver (ar), the runtime libraries, and the arguments every action is built from.

The hermetic-gnat toolchains shipped with rules_ada are created and registered by its module extension; this rule is only needed to define a custom toolchain around a GNAT installation that rules_ada does not ship.

How the toolchain builds its command lines is declared with ada_args targets listed in args; rules_ada ships complete link lines per platform family under @rules_ada//ada/toolchains/args/... that can be reused, extended or replaced. The GNAT runtime archives are listed in static_runtime_lib, tasking runtime first:

load("@rules_ada//ada:ada_toolchain.bzl", "ada_toolchain")
load("@rules_ada//ada/toolchains:defs.bzl", "LINK_ACTIONS", "ada_args")

ada_args(
    name = "system_libs",
    actions = LINK_ACTIONS,
    args = ["-lm", "-lpthread", "-ldl", "-lrt"],
)

ada_toolchain(
    name = "gnat_toolchain",
    compiler = "@gnat//:bin/gcc",
    binder = "@gnat//:bin/gnatbind",
    ar = "@gnat//:bin/ar",
    ada_std = "@gnat//:ada_std",
    compiler_lib = "@gnat//:compiler_lib",
    gcov = "@gnat//:bin/gcov",
    compile_flags = ["-O2"],
    static_runtime_lib = [
        "@gnat//:lib/gcc/x86_64-pc-linux-gnu/16.1.0/adalib/libgnarl.a",
        "@gnat//:lib/gcc/x86_64-pc-linux-gnu/16.1.0/adalib/libgnat.a",
        "@gnat//:lib/gcc/x86_64-pc-linux-gnu/16.1.0/libgcc.a",
    ],
    args = [
        "@rules_ada//ada/toolchains/args/elf:link_line",
        ":system_libs",
    ],
    known_features = ["@rules_ada//ada/toolchains/features:static_libgcc"],
    target_triple = "x86_64-pc-linux-gnu",
)

See the toolchains documentation for the variables available to ada_args, the shipped link lines, features and dynamic_runtime_lib.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
ada_stdThe Ada standard library (adalib and adainclude).LabeloptionalNone
arThe archiver executable (ar or gcc-ar). If not set, the CC toolchain's archiver is used.LabeloptionalNone
argsada_args and ada_args_list targets expanded, in this order, into every action they apply to. A link line is built entirely from these; see @rules_ada//ada/toolchains/args/... for the shipped ones.List of labelsoptional[]
artifact_name_patternsOutput file name per category with %{name} standing for the target name. Categories: executable (default %{name}), shared_library (lib%{name}.so), static_library (lib%{name}.a).Dictionary: String -> Stringoptional{}
bind_flagsAdditional flags for gnatbind.List of stringsoptional[]
binderThe gnatbind executable for elaboration ordering and consistency checking.LabeloptionalNone
compile_flagsAdditional compiler flags for Ada compilation.List of stringsoptional[]
compilerThe Ada compiler executable (gcc with GNAT support).LabeloptionalNone
compiler_idIdentifier for the Ada compiler. Currently only 'gnat' is supported.Stringoptional"gnat"
compiler_libGCC support files (backends, shared libs, runtime libs like libgcc.a, libatomic.a).LabeloptionalNone
dynamic_runtime_libShared runtime libraries the compiler driver links implicitly when the static_libgcc feature is disabled (e.g. macOS libgcc_s.1.1.dylib). They are staged next to each linked output with a relative rpath and carried in its runfiles. Leave empty where the system provides them, as on Linux.List of labelsoptional[]
enabled_featuresada_feature targets on by default for every target using this toolchain; each must also be in known_features. A target turns one off with features = ["-name"].List of labelsoptional[]
gcovThe gcov executable for coverage support.LabeloptionalNone
known_featuresada_feature targets the toolchain understands. The arguments of enabled ones are emitted after args, in this order. @rules_ada//ada/toolchains/features:static_libgcc is the one the rules themselves know.List of labelsoptional[]
static_runtime_libRuntime archives linked, in this order, after the dependency libraries into every executable and (on Windows) shared library: libgnarl.a first, then libgnat.a, libgcc.a, and libatomic.a where needed. GNU ld scans archives once, so the order matters.List of labelsoptional[]
target_tripleGCC target triple (e.g., 'aarch64-apple-darwin24.6.0', 'x86_64-pc-linux-gnu').Stringoptional""

AdaToolchainInfo

load("@rules_ada//ada:ada_toolchain.bzl", "AdaToolchainInfo")

AdaToolchainInfo(ada_std, ar, args, args_files, artifact_name_patterns, bind_flags, binder,
                 compile_flags, compiler, compiler_id, compiler_lib, dynamic_runtime_lib,
                 enabled_features, gcov, known_features, label, process_wrapper, static_runtime_lib,
                 target_triple)

Information about a configured Ada toolchain.

FIELDS

NameDescription
ada_stddepset[File]: Ada standard library (adalib .ali and .a files, adainclude specs).
arFile or None: The archiver executable. None when the GNAT archive does not include one; the CC toolchain's archiver is used as a fallback.
argstuple[AdaArgsInfo]: Arguments expanded into every action, in command-line order.
args_filesdepset[File]: Files referenced by args, added to every action's inputs.
artifact_name_patternsdict[str, str]: Output file name pattern per category (executable, shared_library, static_library) with %{name} for the target name.
bind_flagslist[str]: Toolchain-level binder flags.
binderFile: The gnatbind executable for elaboration ordering.
compile_flagslist[str]: Toolchain-level compile flags.
compilerFile: The Ada compiler executable (gcc with GNAT support).
compiler_idstr: Compiler identifier (e.g., 'gnat').
compiler_libdepset[File]: GCC support files (backends, shared libs, runtime libs).
dynamic_runtime_liblist[File]: Shared runtime libraries staged beside each linked output when the static_libgcc feature is disabled (e.g. libgcc_s.1.1.dylib).
enabled_featurestuple[AdaFeatureInfo]: Features on by default for every target using this toolchain.
gcovFile: The gcov executable for coverage, or None.
known_featurestuple[AdaFeatureInfo]: Features the toolchain understands, in the order their arguments are emitted.
labelLabel: The label of the toolchain target.
process_wrapperFile: The process wrapper executable for build actions.
static_runtime_liblist[File]: Runtime archives in link order (libgnarl.a, libgnat.a, libgcc.a, ...), linked into executables and Windows shared libraries after the dependency libraries.
target_triplestr: GCC target triple (e.g., 'aarch64-apple-darwin24.6.0', 'x86_64-pc-linux-gnu'). Informational; no rule behaviour depends on it.