rules_bison
April 27, 2026 ยท View on GitHub
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.
When generating a C/C++ parser the output groups cc_srcs and cc_hdrs
provide access to the generated {name}.c / {name}.cc source and
{name}.h header.
When generating a Java parser the output group java_srcs provides access
to the generated {name}.java source.
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:
| 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:
| 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 |
bison_toolchain_info
load("@rules_bison//bison:bison.bzl", "bison_toolchain_info")
bison_toolchain_info(name, bison_env, bison_tool)
Provides ToolchainInfo and TemplateVariableInfo for the Bison toolchain.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| bison_env | Additional environment variables to set when running bison_tool. | Dictionary: String -> String | optional | {} |
| bison_tool | A FilesToRunProvider for the bison binary. | Label | required |
BisonToolchainInfo
load("@rules_bison//bison:bison.bzl", "BisonToolchainInfo")
BisonToolchainInfo(all_files, bison_tool, bison_env)
Provider for a Bison toolchain.
FIELDS
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
bison_repository
load("@rules_bison//bison:bison.bzl", "bison_repository")
bison_repository(name, extra_copts, extra_http_mirrors, extra_linkopts, http_mirrors, 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 | [] |
| extra_http_mirrors | Additional HTTP mirrors of the GNU Bison source archives. These mirrors will be appended to the list of default GNU mirrors. | List of strings | optional | [] |
| extra_linkopts | Additional linker options to use when building GNU Bison. | List of strings | optional | [] |
| http_mirrors | If set then this value will be used instead of the default HTTP mirror list. The extra_http_mirrors attribute will be appended to this list. | List of strings | 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)
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 |
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, extra_http_mirrors, extra_linkopts, http_mirrors,
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 | [] |
| extra_http_mirrors | Additional HTTP mirrors of the GNU Bison source archives. These mirrors will be appended to the list of default GNU mirrors. | List of strings | optional | [] |
| extra_linkopts | Additional linker options to use when building GNU Bison. | List of strings | optional | [] |
| http_mirrors | If set then this value will be used instead of the default HTTP mirror list. The extra_http_mirrors attribute will be appended to this list. | List of strings | optional | [] |
| version | A supported version of GNU Bison. | String | optional | "3.3.2" |
bison_toolchains_ext
bison_toolchains_ext = use_extension("@rules_bison//bison/extensions:bison_toolchains_ext.bzl", "bison_toolchains_ext")
bison_toolchains_ext.toolchain(name, bison_env, bison_tool)
Module extension for declaring Bison toolchains with custom target binaries.
The resulting repository will have one subdirectory per named module tag, which
contains a :toolchain target that can be registered with Bazel.
Example
bison_toolchains = use_extension(
"@rules_bison//bison/extensions:bison_toolchains_ext.bzl",
"bison_toolchain_ext",
)
bison_toolchains.toolchain(
name = "custom",
bison_tool = "//custom_bison:bison",
)
use_repo(bison_toolchains, "bison_toolchains")
register_toolchains("@bison_toolchains//custom:toolchain")
TAG CLASSES
toolchain
Attributes
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | The name of the toolchain repository to create. | Name | required | |
| bison_env | Additional environment variables to set when running bison_tool. | Dictionary: String -> String | optional | {} |
| bison_tool | The label of an bison executable target. | Label | required |