Skip to content

Latest commit

 

History

History
246 lines (155 loc) · 10.4 KB

rules_m4.md

File metadata and controls

246 lines (155 loc) · 10.4 KB

rules_m4

Bazel rules for the m4 macro expander.

m4

load("@rules_m4//m4:m4.bzl", "m4")

m4(name, srcs, freeze_state, m4_options, output, reload_state)

Perform macro expansion to produce an output file.

This rule blocks the of execution shell commands (such as syscmd) by default. To enable expansion of a file containing shell commands, set the m4_syscmd target feature.

Example

load("@rules_m4//m4:m4.bzl", "m4")

m4(
    name = "m4_example.txt",
    srcs = ["m4_example.in.txt"],
)

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
srcs List of source files to macro-expand. List of labels required
freeze_state Optional output file for GNU M4 frozen state. Must have extension .m4f. Label; nonconfigurable optional None
m4_options Additional options to pass to the m4 command.

These will be added to the command args immediately before the source files.
List of strings optional []
output File to write output to. If unset, defaults to the rule name. Label; nonconfigurable optional None
reload_state Optional input file for GNU M4 frozen state. Must have extension .m4f. Label optional None

M4ToolchainInfo

load("@rules_m4//m4:m4.bzl", "M4ToolchainInfo")

M4ToolchainInfo(all_files, m4_tool, m4_env)

Provider for an m4 toolchain.

FIELDS

Name Description
all_files A depset containing all files comprising this m4 toolchain.
m4_tool A FilesToRunProvider for the m4 binary.
m4_env Additional environment variables to set when running m4_tool.

m4_register_toolchains

load("@rules_m4//m4:m4.bzl", "m4_register_toolchains")

m4_register_toolchains(version, extra_copts)

A helper function for m4 toolchains registration.

This workspace macro will create a m4_repository named m4_v{version} and register it as a Bazel toolchain.

PARAMETERS

Name Description Default Value
version A supported version of GNU M4. "1.4.18"
extra_copts Additional C compiler options to use when building GNU M4. []

m4_toolchain

load("@rules_m4//m4:m4.bzl", "m4_toolchain")

m4_toolchain(ctx)

Returns the current M4ToolchainInfo.

PARAMETERS

Name Description Default Value
ctx A rule context, where the rule has a toolchain dependency on M4_TOOLCHAIN_TYPE. none

RETURNS

An M4ToolchainInfo.

m4_repository

load("@rules_m4//m4:m4.bzl", "m4_repository")

m4_repository(name, extra_copts, extra_linkopts, repo_mapping, version)

Repository rule for GNU M4.

The resulting repository will have a //bin:m4 executable target.

Example

load("@rules_m4//m4:m4.bzl", "m4_repository")

m4_repository(
    name = "m4_v1.4.18",
    version = "1.4.18",
)

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this repository. Name required
extra_copts Additional C compiler options to use when building GNU M4. List of strings optional []
extra_linkopts Additional linker options to use when building GNU M4. List of strings optional []
repo_mapping 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).
Dictionary: String -> String optional
version A supported version of GNU M4. String required

m4_toolchain_repository

load("@rules_m4//m4:m4.bzl", "m4_toolchain_repository")

m4_toolchain_repository(name, m4_repository, repo_mapping)

Toolchain repository rule for m4 toolchains.

Toolchain repositories add a layer of indirection so that Bazel can resolve toolchains without downloading additional dependencies.

The resulting repository will have the following targets:

  • //bin:m4 (an alias into the underlying m4_repository)
  • //:toolchain, which can be registered with Bazel.

Example

load("@rules_m4//m4:m4.bzl", "m4_repository", "m4_toolchain_repository")

m4_repository(
    name = "m4_v1.4.18",
    version = "1.4.18",
)

m4_toolchain_repository(
    name = "m4",
    m4_repository = "@m4_v1.4.18",
)

register_toolchains("@m4//:toolchain")

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this repository. Name required
m4_repository The name of an m4_repository. String required
repo_mapping 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).
Dictionary: String -> String optional

m4_repository_ext

m4_repository_ext = use_extension("@rules_m4//m4/extensions:m4_repository_ext.bzl", "m4_repository_ext")
m4_repository_ext.repository(name, extra_copts, extra_linkopts, version)

Module extension for declaring dependencies on GNU M4.

The resulting repository will have the following targets:

  • //bin:m4 (an alias into the underlying m4_repository)
  • //:toolchain, which can be registered with Bazel.

Example

m4 = use_extension(
    "@rules_m4//m4/extensions:m4_repository_ext.bzl",
    "m4_repository_ext",
)

m4.repository(name = "m4", version = "1.4.18")
use_repo(m4, "m4")
register_toolchains("@m4//:toolchain")

TAG CLASSES

repository

Attributes

Name Description Type Mandatory Default
name An optional name for the repository.

The name must be unique within the set of names registered by this extension. If unset, the repository name will default to "m4_v{version}".
Name optional ""
extra_copts Additional C compiler options to use when building GNU M4. List of strings optional []
extra_linkopts Additional linker options to use when building GNU M4. List of strings optional []
version A supported version of GNU M4. String optional "1.4.18"