rules_dAPI docs @0.8.2

@rules_d//d:d_tool.bzl

Helper rule to export compiler and dub executables from the toolchain.

Rules

d_tool
AttributeTypeDescription
*namename

A unique name for this target.

*whichstring

@rules_d//d:defs.bzl

Public API of D rules.

Rules

d_binary
AttributeTypeDescription
*namename

A unique name for this target.

srcslist of labels

List of D '.d' or '.di' source files.

Default: []
depslist of labels

List of dependencies.

Default: []
doptslist of strings

Compiler flags.

Default: []
importslist of strings

List of import paths. Default is the package directory.

Default: []
linkoptslist of strings

Linker flags passed via -L flags.

Default: []
string_importslist of strings

List of string import paths.

Default: []
string_srcslist of labels

List of string import source files.

Default: []
versionslist of strings

List of version identifiers.

Default: []
envdictionary: String → String

Environment variables for the binary at runtime. Subject of location and make variable expansion.

Default: {}
datalist of labels

List of files to be made available at runtime.

Default: []
d_library
AttributeTypeDescription
*namename

A unique name for this target.

srcslist of labels

List of D '.d' or '.di' source files.

Default: []
depslist of labels

List of dependencies.

Default: []
doptslist of strings

Compiler flags.

Default: []
importslist of strings

List of import paths. Default is the package directory.

Default: []
linkoptslist of strings

Linker flags passed via -L flags.

Default: []
string_importslist of strings

List of string import paths.

Default: []
string_srcslist of labels

List of string import source files.

Default: []
versionslist of strings

List of version identifiers.

Default: []
source_onlyboolean

If true, the source files are compiled, but not library is produced.

Default: False
d_test
AttributeTypeDescription
*namename

A unique name for this target.

srcslist of labels

List of D '.d' or '.di' source files.

Default: []
depslist of labels

List of dependencies.

Default: []
doptslist of strings

Compiler flags.

Default: []
importslist of strings

List of import paths. Default is the package directory.

Default: []
linkoptslist of strings

Linker flags passed via -L flags.

Default: []
string_importslist of strings

List of string import paths.

Default: []
string_srcslist of labels

List of string import source files.

Default: []
versionslist of strings

List of version identifiers.

Default: []
envdictionary: String → String

Environment variables for the binary at runtime. Subject of location and make variable expansion.

Default: {}
datalist of labels

List of files to be made available at runtime.

Default: []

@rules_d//d:extensions.bzl

Extensions for bzlmod.

Installs a d toolchain.
Every module can define a toolchain version under the default name, "d".
The latest of those versions will be selected (the rest discarded),
and will always be registered by rules_d.

Additionally, the root module can define arbitrarily many more toolchain versions under different
names (the latest version will be picked for each name) and can register them as it sees fit,
effectively overriding the default named toolchain due to toolchain resolution precedence.

Module Extensions

d
Tag Classes
toolchain
AttributeTypeDescription
namename

Base name for generated repositories, allowing more than one d toolchain to be registered.
Overriding the default is only permitted in the root module.

Default: "d"
*d_versionstring

Fully qualified compiler version, for example "dmd-2.111.0" or "ldc-1.41.0".
The extension selects the first supplied version compatible with the current platform
and fails if none match.

@rules_d//d:repositories.bzl

Declare runtime dependencies

These are needed for local dev, and users must install them as well.
See https://docs.bazel.build/versions/main/skylark/deploying.html#dependencies

Functions & Macros

http_archive
Parameters
*name
kwargs
rules_d_dependencies
d_register_toolchains

Convenience macro for users which does typical setup.

  • create a repository for each built-in platform like "d_linux_amd64"
  • TODO: create a convenience repository for the host platform like "d_host"
  • create a repository exposing toolchains for each platform like "d_platforms"
  • register a toolchain pointing at each platform
    Users can avoid this macro and do these steps themselves, if they want more control.
Parameters
*name

base name for all created repositories

register

whether to call through to native.register_toolchains.
Should be True for WORKSPACE users, but false when used under bzlmod extension

Default: True
kwargs

passed to each d_repositories call

select_compiler_by_os

Select the most appropriate compiler version for the given OS.

Parameters
*versions

list of compiler versions

*os

repository_os information

Repository Rules

d_repositories

Fetch external tools needed for d toolchain

AttributeTypeDescription
*namename

A unique name for this repository.

repo_mappingdictionary: String → String

In WORKSPACE context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.

For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target).

This attribute is not supported in MODULE.bazel context (when invoking a repository rule inside a module extension's implementation function).

*d_versionstring
*platformstring

@rules_d//d:toolchain.bzl

This module implements the D toolchain rule.

Rules

d_toolchain

Defines a d compiler/runtime toolchain.

For usage see https://docs.bazel.build/versions/main/toolchains.html#defining-toolchains.

AttributeTypeDescription
*namename

A unique name for this target.

compiler_flagslist of strings

Compiler flags.

Default: []
*d_compilerlabel

The D compiler.

druntimelabel

The D runtime library.

Default: None
dub_toollabel

The dub package manager.

Default: None
libphoboslabel

The Phobos library.

Default: None
linker_flagslist of strings

Linker flags.

Default: []
rdmd_toollabel

The rdmd compile and execute utility.

Default: None

Providers

DToolchainInfo

D compiler information.

Fields
compiler_flags

Default compiler flags.

d_compiler

The D compiler executable.

druntime

The D runtime library. (LDC only)

dub_tool

The dub package manager executable.

libphobos

The Phobos library.

linker_flags

Default linker flags.

rdmd_tool

The rdmd compile and execute utility.

@rules_d//dub:defs.bzl

Public API for DUB rules.

Functions & Macros

dub_lock_dependencies

Generates a dub dependencies lock file suitable for bazel use.

Parameters
*name

The dub dependencies target.

src

file containing the dub dependencies. Supported inputs are:

  • dub.sdl
  • dub.json
  • dub.selections.json
Default: None
dub_selections_lock

The output lock file. If not specified, defaults to {name}.lock.json.

Default: None
skip_ssl_verification

If true, SSL certificate verification will be skipped when downloading dependencies. Use with caution!

Default: False
verbose

If true, verbose output will be displayed during the generation process.

Default: False
kwargs

Additional keyword arguments passed to the _test rule.

@rules_d//dub:extensions.bzl

Module extension for integrating dub package manager with Bazel.

Module Extensions

dub
Tag Classes
from_dub_selections
AttributeTypeDescription
namename

Name of the packages repository.

Default: "dub"
*dub_selections_locklabel

Path to the dub package lock file, relative to the module root.

@rules_d//dub:repositories.bzl

WORKSPACE APIs for integrating dub package manager with Bazel.

Functions & Macros

d_register_dub_repository

Registers a repository containing packages from dub.selections.lock.json.

Parameters
*dub_selections_lock

Path to the dub package lock file.

name

Name of the generated repository. Defaults to "dub".

Default: "dub"

Repository Rules

dub_repository
AttributeTypeDescription
*namename

A unique name for this repository.

repo_mappingdictionary: String → String

In WORKSPACE context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.

For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target).

This attribute is not supported in MODULE.bazel context (when invoking a repository rule inside a module extension's implementation function).

*dub_selections_locklabel

@rules_d//dub/selections_lock:selections_lock.bzl

Rule/macro to manage the dub dependencies lock file.

Functions & Macros

dub_lock_dependencies

Generates a dub dependencies lock file suitable for bazel use.

Parameters
*name

The dub dependencies target.

src

file containing the dub dependencies. Supported inputs are:

  • dub.sdl
  • dub.json
  • dub.selections.json
Default: None
dub_selections_lock

The output lock file. If not specified, defaults to {name}.lock.json.

Default: None
skip_ssl_verification

If true, SSL certificate verification will be skipped when downloading dependencies. Use with caution!

Default: False
verbose

If true, verbose output will be displayed during the generation process.

Default: False
kwargs

Additional keyword arguments passed to the _test rule.