Skip to content

Latest commit

 

History

History
344 lines (225 loc) · 16.6 KB

rules_bison.md

File metadata and controls

344 lines (225 loc) · 16.6 KB

rules_bison

Bazel rules for GNU Bison.

bison

load("@rules_bison//bison:bison.bzl", "bison")

bison(name, src, bison_options, language, skeleton)

Generate source code for a Bison parser.

This rule exists for special cases where the build needs to perform further modification of the generated .c / .h before compilation. Most users will find the bison_cc_library rule more convenient.

Example

load("@rules_bison//bison:bison.bzl", "bison")

bison(
    name = "hello",
    src = "hello.y",
)

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
src A Bison source file.

Unless language is set, the source's file extension determines whether Bison operates in C or C++ mode:
  • Inputs with file extension .y generate outputs {name}.c and {name}.h.
  • Inputs with file extension .yy, .y++, .yxx, or .ypp generate outputs {name}.cc and {name}.h.
Label required
bison_options Additional options to pass to the bison command.

These will be added to the command args immediately before the source file.
List of strings optional []
language Which language to generate the parser in. String optional ""
skeleton Specify the skeleton to use.

This file is used as a template for rendering the generated parser. See the Bison documentation regarding the %skeleton directive for more details.
Label optional None

bison_cc_library

load("@rules_bison//bison:bison.bzl", "bison_cc_library")

bison_cc_library(name, deps, src, bison_options, conlyopts, copts, cxxopts, include_prefix,
                 language, linkstatic, skeleton, strip_include_prefix)

Generate a C/C++ library for a Bison parser.

Verbose descriptions of the parser are available in output group bison_report.

Example

load("@rules_bison//bison:bison.bzl", "bison_cc_library")

bison_cc_library(
    name = "hello_lib",
    src = "hello.y",
)

cc_binary(
    name = "hello",
    srcs = ["hello_main.c"],
    deps = [":hello_lib"],
)

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
deps A list of other C/C++ libraries to depend on. List of labels optional []
src A Bison source file.

Unless language is set, the source's file extension determines whether Bison operates in C or C++ mode:
  • Inputs with file extension .y generate outputs {name}.c and {name}.h.
  • Inputs with file extension .yy, .y++, .yxx, or .ypp generate outputs {name}.cc and {name}.h.
Label required
bison_options Additional options to pass to the bison command.

These will be added to the command args immediately before the source file.
List of strings optional []
conlyopts Add these options to the C compilation command.

See cc_library.conlyopts for more details.
List of strings optional []
copts Add these options to the C/C++ compilation command.

See cc_library.copts for more details.
List of strings optional []
cxxopts Add these options to the C++ compilation command.

See cc_library.cxxopts for more details.
List of strings optional []
include_prefix A prefix to add to the path of the generated header.

See cc_library.include_prefix for more details.
String optional ""
language Which language to generate the parser in. String optional ""
linkstatic Disable creation of a shared library output.

See cc_library.linkstatic for more details.
Boolean optional False
skeleton Specify the skeleton to use.

This file is used as a template for rendering the generated parser. See the Bison documentation regarding the %skeleton directive for more details.
Label optional None
strip_include_prefix A prefix to strip from the path of the generated header.

See cc_library.strip_include_prefix for more details.
String optional ""

bison_java_library

load("@rules_bison//bison:bison.bzl", "bison_java_library")

bison_java_library(name, deps, src, bison_options, skeleton)

Generate a Java library for a Bison parser.

Verbose descriptions of the parser are available in output group bison_report.

Example

load("@rules_bison//bison:bison.bzl", "bison_java_library")

bison_java_library(
    name = "HelloParser",
    src = "hello.y",
)

java_binary(
    name = "HelloMain",
    srcs = ["HelloMain.java"],
    main_class = "HelloMain",
    deps = [":HelloParser"],
)

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
deps A list of other Java libraries to depend on. List of labels optional []
src A Bison source file. Label required
bison_options Additional options to pass to the bison command.

These will be added to the command args immediately before the source file.
List of strings optional []
skeleton Specify the skeleton to use.

This file is used as a template for rendering the generated parser. See the Bison documentation regarding the %skeleton directive for more details.
Label optional None

BisonToolchainInfo

load("@rules_bison//bison:bison.bzl", "BisonToolchainInfo")

BisonToolchainInfo(all_files, bison_tool, bison_env)

Provider for a Bison toolchain.

FIELDS

Name Description
all_files A depset containing all files comprising this Bison toolchain.
bison_tool A FilesToRunProvider for the bison binary.
bison_env Additional environment variables to set when running bison_tool.

bison_register_toolchains

load("@rules_bison//bison:bison.bzl", "bison_register_toolchains")

bison_register_toolchains(version, extra_copts)

A helper function for Bison toolchains registration.

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

PARAMETERS

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

bison_toolchain

load("@rules_bison//bison:bison.bzl", "bison_toolchain")

bison_toolchain(ctx)

Returns the current BisonToolchainInfo.

PARAMETERS

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

RETURNS

A BisonToolchainInfo.

bison_repository

load("@rules_bison//bison:bison.bzl", "bison_repository")

bison_repository(name, extra_copts, repo_mapping, version)

Repository rule for GNU Bison.

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

Example

load("@rules_bison//bison:bison.bzl", "bison_repository")

bison_repository(
    name = "bison_v3.3.2",
    version = "3.3.2",
)

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 Bison. 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 Bison. String required

bison_toolchain_repository

load("@rules_bison//bison:bison.bzl", "bison_toolchain_repository")

bison_toolchain_repository(name, bison_repository, repo_mapping)

Toolchain repository rule for Bison 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:bison (an alias into the underlying [bison_repository] (#bison_repository))
  • //:toolchain, which can be registered with Bazel.

Example

load(
    "@rules_bison//bison:bison.bzl",
    "bison_repository",
    "bison_toolchain_repository",
)

bison_repository(
    name = "bison_v3.3.2",
    version = "3.3.2",
)

bison_toolchain_repository(
    name = "bison",
    bison_repository = "@bison_v3.3.2",
)

register_toolchains("@bison//:toolchain")

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this repository. Name required
bison_repository The name of a bison_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

bison_repository_ext

bison_repository_ext = use_extension("@rules_bison//bison/extensions:bison_repository_ext.bzl", "bison_repository_ext")
bison_repository_ext.repository(name, extra_copts, version)

Module extension for declaring dependencies on GNU Bison.

The resulting repository will have the following targets:

  • //bin:bison (an alias into the underlying [bison_repository] (#bison_repository))
  • //:toolchain, which can be registered with Bazel.

Example

bison = use_extension(
    "@rules_bison//bison/extensions:bison_repository_ext.bzl",
    "bison_repository_ext",
)

bison.repository(name = "bison", version = "3.3.2")
use_repo(bison, "bison")
register_toolchains("@bison//: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 "bison_v{version}".
Name optional ""
extra_copts Additional C compiler options to use when building GNU Bison. List of strings optional []
version A supported version of GNU Bison. String optional "3.3.2"