rules_ada
Bazel rules for building Ada with GNAT.
Install
bazel_dep(name = "rules_ada", version = "{version}")
Getting started
- Add
rules_adatoMODULE.bazel. - Define Ada targets with rules from
//ada:defs.bzl. - Build or test with Bazel:
bazel build //:your_target
bazel test //:your_test
Features
- Ada libraries, binaries, and tests
- Static and shared library outputs
- Coverage support via
bazel coverage - Interop with C/C++/Rust via
CcInfo - GNAT toolchain registration support
Example
load("//ada:defs.bzl", "ada_binary", "ada_library", "ada_test")
ada_library(
name = "math_utils",
srcs = [
"math_utils.ads",
"math_utils.adb",
],
)
ada_binary(
name = "calculator",
srcs = ["main.adb"],
deps = [":math_utils"],
)
ada_test(
name = "math_test",
srcs = ["math_test.adb"],
deps = [":math_utils"],
)
Rule reference
See Rules.
Rules
ada_binary
Rules
ada_binary
load("@rules_ada//ada:ada_binary.bzl", "ada_binary")
ada_binary(name, deps, srcs, data, compile_data, copts, linkopts, linkstatic, main)
Compiles Ada source files, binds them, and links into an executable.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | Dependencies. Can be Ada targets (AdaInfo) or C/C++ targets (CcInfo). | List of labels | optional | [] |
| srcs | Ada source files (.ads specs and .adb bodies). | List of labels | optional | [] |
| data | Additional files needed at runtime. | List of labels | optional | [] |
| compile_data | Additional Ada source files needed during compilation but not compiled independently (e.g., subunit bodies referenced via 'separate'). | List of labels | optional | [] |
| copts | Additional compiler flags for Ada compilation (e.g., -gnatwa, -O2). | List of strings | optional | [] |
| linkopts | Additional linker flags. | List of strings | optional | [] |
| linkstatic | Prefer static linking for dependencies. | Boolean | optional | True |
| main | Main Ada source file containing the entry point procedure. If not set, the first .adb file in srcs is used. | Label | optional | None |
ada_info
Providers
Functions
AdaInfo
load("@rules_ada//ada:ada_info.bzl", "AdaInfo")
AdaInfo(cc_info, direct_body_alis, direct_objects, direct_spec_alis, transitive_body_alidirs,
transitive_body_alis, transitive_exported_bodies, transitive_objects, transitive_spec_alidirs,
transitive_spec_alis, transitive_specs, transitive_srcdirs, units)
Carries the spec/body ALI/object/source closure of an Ada compilation target.
FIELDS
merge_ada_infos
load("@rules_ada//ada:ada_info.bzl", "merge_ada_infos")
merge_ada_infos(deps)
Combine AdaInfo from deps into an aggregate view used by action helpers.
PARAMETERS
ada_library
Rules
ada_library
load("@rules_ada//ada:ada_library.bzl", "ada_library")
ada_library(name, deps, srcs, data, compile_data, copts, exports_bodies, linkopts, subunits)
Compiles Ada source files into a library. This is the primary rule for Ada-to-Ada dependencies and cross-language interop via CcInfo. Use ada_static_library or ada_shared_library when you need to produce a specific artifact type for external consumption.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | Dependencies. Can be Ada targets (AdaInfo) or C/C++ targets (CcInfo). | List of labels | optional | [] |
| srcs | Ada source files (.ads specs and .adb bodies). | List of labels | optional | [] |
| data | Additional files needed at runtime. | List of labels | optional | [] |
| compile_data | Additional Ada source files needed during compilation but not compiled independently (e.g., subunit bodies referenced via 'separate'). | List of labels | optional | [] |
| copts | Additional compiler flags for Ada compilation (e.g., -gnatwa, -O2). | List of strings | optional | [] |
| exports_bodies | If True, this library's body sources flow into downstream compile inputs. Set this on libraries whose public API exposes generics, since cross-unit generic instantiation requires the generic body at the instantiation site's compile time. | Boolean | optional | False |
| linkopts | Additional linker flags. | List of strings | optional | [] |
| subunits | Body files that are separate subunits, listed explicitly to bypass the hyphen-stem heuristic. Files listed here MUST also appear in srcs. They flow as inputs to their parent unit's compile but get no standalone compile action. | List of labels | optional | [] |
ada_shared_library
Rules
ada_shared_library
load("@rules_ada//ada:ada_shared_library.bzl", "ada_shared_library")
ada_shared_library(name, deps, srcs, data, compile_data, copts, lib_name, linkopts)
Compiles Ada source files into a shared (dynamic) library.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | Dependencies. Can be Ada targets (AdaInfo) or C/C++ targets (CcInfo). | List of labels | optional | [] |
| srcs | Ada source files (.ads specs and .adb bodies). | List of labels | optional | [] |
| data | Additional files needed at runtime. | List of labels | optional | [] |
| compile_data | Additional Ada source files needed during compilation but not compiled independently (e.g., subunit bodies referenced via 'separate'). | List of labels | optional | [] |
| copts | Additional compiler flags for Ada compilation (e.g., -gnatwa, -O2). | List of strings | optional | [] |
| lib_name | Library name for gnatbind -L (unique elaboration namespace). Defaults to the target name. | String | optional | "" |
| linkopts | Additional linker flags. | List of strings | optional | [] |
ada_static_library
Rules
ada_static_library
load("@rules_ada//ada:ada_static_library.bzl", "ada_static_library")
ada_static_library(name, deps, srcs, data, compile_data, copts, lib_name, linkopts)
Compiles Ada source files into a static archive (.a) for external consumption.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | Dependencies. Can be Ada targets (AdaInfo) or C/C++ targets (CcInfo). | List of labels | optional | [] |
| srcs | Ada source files (.ads specs and .adb bodies). | List of labels | optional | [] |
| data | Additional files needed at runtime. | List of labels | optional | [] |
| compile_data | Additional Ada source files needed during compilation but not compiled independently (e.g., subunit bodies referenced via 'separate'). | List of labels | optional | [] |
| copts | Additional compiler flags for Ada compilation (e.g., -gnatwa, -O2). | List of strings | optional | [] |
| lib_name | Library name for gnatbind -L (unique elaboration namespace). Defaults to the target name. | String | optional | "" |
| linkopts | Additional linker flags. | List of strings | optional | [] |
ada_test
Rules
ada_test
load("@rules_ada//ada:ada_test.bzl", "ada_test")
ada_test(name, deps, srcs, data, compile_data, copts, env, env_inherit, linkopts, linkstatic, main)
Compiles Ada source files, binds them, and links into a test executable. Run with bazel test.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | Dependencies. Can be Ada targets (AdaInfo) or C/C++ targets (CcInfo). | List of labels | optional | [] |
| srcs | Ada source files (.ads specs and .adb bodies). | List of labels | optional | [] |
| data | Additional files needed at runtime. | List of labels | optional | [] |
| compile_data | Additional Ada source files needed during compilation but not compiled independently (e.g., subunit bodies referenced via 'separate'). | List of labels | optional | [] |
| copts | Additional compiler flags for Ada compilation (e.g., -gnatwa, -O2). | List of strings | optional | [] |
| env | Environment variables to set when running the test. | Dictionary: String -> String | optional | {} |
| env_inherit | Environment variables to inherit from the host environment. | List of strings | optional | [] |
| linkopts | Additional linker flags. | List of strings | optional | [] |
| linkstatic | Prefer static linking for dependencies. | Boolean | optional | True |
| main | Main Ada source file containing the entry point procedure. If not set, the first .adb file in srcs is used. | Label | optional | None |
ada_toolchain
Rules
ada_toolchain
load("@rules_ada//ada:ada_toolchain.bzl", "ada_toolchain")
ada_toolchain(name, ada_std, ar, bind_flags, binder, compile_flags, compiler, compiler_id,
compiler_lib, gcov, link_flags, target_triple)
Defines an Ada toolchain providing the GNAT compiler (gcc), binder (gnatbind), archiver (ar), and compilation/linking flags.
Example:
load("@rules_ada//ada:ada_toolchain.bzl", "ada_toolchain")
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"],
link_flags = ["-lgnat"],
)
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| ada_std | The Ada standard library (adalib and adainclude). | Label | optional | None |
| ar | The archiver executable (ar or gcc-ar). If not set, the CC toolchain's archiver is used. | Label | optional | None |
| bind_flags | Additional flags for gnatbind. | List of strings | optional | [] |
| binder | The gnatbind executable for elaboration ordering and consistency checking. | Label | optional | None |
| compile_flags | Additional compiler flags for Ada compilation. | List of strings | optional | [] |
| compiler | The Ada compiler executable (gcc with GNAT support). | Label | optional | None |
| compiler_id | Identifier for the Ada compiler. Currently only 'gnat' is supported. | String | optional | "gnat" |
| compiler_lib | GCC support files (backends, shared libs, runtime libs like libgcc.a, libatomic.a). | Label | optional | None |
| gcov | The gcov executable for coverage support. | Label | optional | None |
| link_flags | Additional linker flags (e.g., -lgnat, -lgnarl). | List of strings | optional | [] |
| target_triple | GCC target triple (e.g., 'aarch64-apple-darwin23.6.0', 'x86_64-pc-linux-gnu'). | String | optional | "" |