Bazel rules for Flex, the Fast Lexical Analyzer.
flex(name, flex_options, src)
Generate C/C++ source code for a Flex lexical analyzer.
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 flex_cc_library
rule more convenient.
load("@rules_flex//flex:flex.bzl", "flex")
flex(
name = "hello",
src = "hello.l",
)
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
flex_options | Additional options to pass to the flex command.These will be added to the command args immediately before the source file. |
List of strings | optional | [] |
src | A Flex source file. The source's file extension will determine whether Flex operates in C or C++ mode:
FlexLexer.h , which is part of the Flex source distribution and may be obtained from the Flex toolchain. |
Label | required |
flex_cc_library(name, deps, flex_options, include_prefix, linkstatic, src, strip_include_prefix)
Generate a C/C++ library for a Flex lexical analyzer.
load("@rules_flex//flex:flex.bzl", "flex_cc_library")
flex_cc_library(
name = "hello_lib",
src = "hello.l",
)
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 | [] |
flex_options | Additional options to pass to the flex command.These will be added to the command args immediately before the source file. |
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 | "" |
linkstatic | Disable creation of a shared library output. See cc_library.linkstatic for more details. |
Boolean | optional | False |
src | A Flex source file. The source's file extension will determine whether Flex operates in C or C++ mode:
FlexLexer.h , which is part of the Flex source distribution and may be obtained from the Flex toolchain. |
Label | required | |
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 | "" |
flex_repository(name, extra_copts, repo_mapping, version)
Repository rule for Flex.
The resulting repository will have a //bin:flex
executable target.
load("@rules_flex//flex:flex.bzl", "flex_repository")
flex_repository(
name = "flex_v2.6.4",
version = "2.6.4",
)
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 Flex. | 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 Flex. | String | required |
flex_toolchain_repository(name, flex_repository, repo_mapping)
Toolchain repository rule for Flex 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:flex
(an alias into the underlying [flex_repository
] (#flex_repository))//:toolchain
, which can be registered with Bazel.
load(
"@rules_flex//flex:flex.bzl",
"flex_repository",
"flex_toolchain_repository",
)
flex_repository(
name = "flex_v2.6.4",
version = "2.6.4",
)
flex_toolchain_repository(
name = "flex",
flex_repository = "@flex_v2.6.4",
)
register_toolchains("@flex//:toolchain")
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this repository. | Name | required | |
flex_repository | The name of a flex_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 |
FlexToolchainInfo(all_files, flex_tool, flex_env, flex_lexer_h)
Provider for a Flex toolchain.
FIELDS
flex_register_toolchains(version, extra_copts)
A helper function for Flex toolchains registration.
This workspace macro will create a flex_repository
named flex_v{version}
and register it as a Bazel toolchain.
PARAMETERS
Name | Description | Default Value |
---|---|---|
version | A supported version of Flex. | "2.6.4" |
extra_copts | Additional C compiler options to use when building Flex. | [] |
flex_toolchain(ctx)
Returns the current FlexToolchainInfo
.
PARAMETERS
Name | Description | Default Value |
---|---|---|
ctx | A rule context, where the rule has a toolchain dependency on FLEX_TOOLCHAIN_TYPE . |
none |
RETURNS