Skip to content

Latest commit

 

History

History
194 lines (118 loc) · 7.64 KB

rules_m4.md

File metadata and controls

194 lines (118 loc) · 7.64 KB

rules_m4

Bazel rules for the m4 macro expander.

m4

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

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
freeze_state Optional output file for GNU M4 frozen state. Must have extension .m4f. Label optional
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 optional
reload_state Optional input file for GNU M4 frozen state. Must have extension .m4f. Label optional None
srcs List of source files to macro-expand. List of labels required

m4_repository

m4_repository(name, extra_copts, 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 []
repo_mapping A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>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). Dictionary: String -> String required
version A supported version of GNU M4. String required

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 A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>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). Dictionary: String -> String required

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

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

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.