rules_verilog
Overview
Bazel rules for Verilog and SystemVerilog.
Setup
bazel_dep(name = "rules_verilog", version = "{version}")
verilog rules
Bazel rules for Verilog / SystemVerilog.
Setup
bazel_dep(name = "rules_verilog", version = "{version}")
Rules
Providers
verilog_library
load("@rules_verilog//verilog:defs.bzl", "verilog_library")
verilog_library(name, deps, srcs, hdrs, compile_data, top)
TODO
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | The list of other libraries to be linked. | List of labels | optional | [] |
| srcs | Verilog or SystemVerilog sources. | List of labels | optional | [] |
| hdrs | Verilog or SystemVerilog headers. | List of labels | optional | [] |
| compile_data | TODO | List of labels | optional | [] |
| top | The top of the module. If unset, a file must be found matching the name of the target. | Label | optional | None |
VerilogInfo
load("@rules_verilog//verilog:defs.bzl", "VerilogInfo")
VerilogInfo(compile_data, deps, hdrs, srcs, top)
Verilog provider
FIELDS
Verilator rules.
Bazel rules for Verilator
Setup
bazel_dep(name = "rules_verilog", version = "{version}")
register_toolchain(
# Define a custom toolchain or use the `rules_verilog` provided toolchain.
"@rules_verilog//verilator/toolchain",
)
Rules
Aspects
verilator_cc_library
load("@rules_verilog//verilator:defs.bzl", "verilator_cc_library")
verilator_cc_library(name, data, linkopts, module)
Compiles a Verilog module to a C++ library using Verilator.
This rule uses an aspect to compile each Verilog module in the dependency tree to C++ object files using Verilator's hierarchical compilation mode, then links them all together into a single static library.
Example:
verilog_library(
name = "my_module",
srcs = ["my_module.sv"],
)
verilator_cc_library(
name = "my_module_cc",
module = ":my_module",
)
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| data | Data used at runtime by the library | List of labels | optional | [] |
| linkopts | List of additional C++ linker flags | List of strings | optional | [] |
| module | The top level Verilog module target to compile with Verilator. | Label | required |
verilator_lint_test
load("@rules_verilog//verilator:defs.bzl", "verilator_lint_test")
verilator_lint_test(name, module)
Test rule that runs Verilator lint on a Verilog module.
This rule runs Verilator in lint-only mode on the specified module and all its transitive dependencies. The test passes if linting succeeds.
Example: verilog_library( name = "my_module", srcs = ["my_module.sv"], )
verilator_lint_test(
name = "my_module_lint_test",
module = ":my_module",
)
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| module | The Verilog module to lint. | Label | required |
verilator_toolchain
load("@rules_verilog//verilator:defs.bzl", "verilator_toolchain")
verilator_toolchain(name, deps, copts, libverilator, linkopts, verilator, vopts)
Define a Verilator toolchain.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | Global Verilator dependencies to link into downstream targets. | List of labels | optional | [] |
| copts | Extra compiler flags to pass when compiling Verilator outputs. | List of strings | optional | [] |
| libverilator | The Verilator library. | Label | required | |
| linkopts | Extra linker flags to pass when linking Verilator outputs. | List of strings | optional | [] |
| verilator | The Verilator binary. | Label | required | |
| vopts | Extra flags to pass to Verilate actions. | List of strings | optional | [] |
verilator_lint_aspect
load("@rules_verilog//verilator:defs.bzl", "verilator_lint_aspect")
verilator_lint_aspect()
Aspect for linting Verilog modules with Verilator.
ASPECT ATTRIBUTES
ATTRIBUTES
SystemRDL rules.
Bazel rules for SystemRDL
Setup
bazel_dep(name = "rules_verilog", version = "{version}")
register_toolchain(
# Define a custom toolchain or use the `rules_verilog` provided toolchain.
"@rules_verilog//system_rdl/toolchain",
)
Rules
Providers
system_rdl_library
load("@rules_verilog//system_rdl:defs.bzl", "system_rdl_library")
system_rdl_library(name, deps, srcs, exporter_args, root)
A SystemRDL library.
Outputs of these rules are generally extracted via a filegroup.
load("@rules_verilog//system_rdl:system_rdl_library.bzl", "system_rdl_library")
system_rdl_library(
name = "atxmega_spi",
srcs = ["atxmega_spi.rdl"],
exporter_args = {
"regblock": [
"--cpuif",
"axi4-lite-flat",
],
},
)
filegroup(
name = "atxmega_spi.sv",
srcs = ["atxmega_spi"],
output_group = "system_rdl_regblock",
)
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | Additional system_rdl_library dependencies. | List of labels | optional | [] |
| srcs | Source files which define the entire SystemRDL dag. | List of labels | required | |
| exporter_args | A mapping of exporter names to arguments. | Dictionary: String -> List of strings | optional | {} |
| root | The top source file of the SystemRDL library. | Label | optional | None |
system_rdl_toolchain
load("@rules_verilog//system_rdl:defs.bzl", "system_rdl_toolchain")
system_rdl_toolchain(name, exporter_args, exporters, peakrdl, peakrdl_config)
A SystemRDL toolchain.
Plugins:
Additional exporters
are supported via a combination of the peakrdl and peakrdl_config attributes.
load("@rules_venv//python:py_library.bzl", "py_library")
load("//system_rdl:system_rdl_toolchain.bzl", "system_rdl_toolchain")
py_library(
name = "peakrdl_toml",
srcs = ["peakrdl_toml.py"],
deps = [
"@pip_deps//peakrdl",
"@pip_deps//tomli",
],
)
PLUGINS = [
":peakrdl_toml
]
py_library(
name = "peakrdl",
deps = [
"@pip_deps//peakrdl",
] + PLUGINS,
)
system_rdl_toolchain(
name = "system_rdl_toolchain",
peakrdl = ":peakrdl",
peakrdl_config = "peakrdl.toml",
exporters = {
"html": "_html",
"regblock": ".sv",
"toml": ".toml",
},
)
toolchain(
name = "toolchain",
toolchain = ":system_rdl_toolchain",
toolchain_type = "@rules_verilog//system_rdl:toolchain_type",
visibility = ["//visibility:public"],
)
peakrdl.toml:
# https://peakrdl.readthedocs.io/en/latest/configuring.html
[peakrdl]
# The import path should be the repo realtive import path of the plugin.
plugins.exporters.toml = "tools.system_rdl.peakrdl_toml:TomlExporter"
Now with the toolchain configured. all system_rdl_library targets built
in the same configuration as the registered toolchain will have an additional
output group system_rdl_toml that is the output of the custom exporter.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| exporter_args | A pair of exporters keys to a list of default exporter args to apply to all rules. | Dictionary: String -> List of strings | optional | {} |
| exporters | A mapping of exporters to expected output file formats. | Dictionary: String -> String | optional | {"html": "_html", "regblock": ".sv"} |
| peakrdl | The python library for the peakrdl package. | Label | optional | None |
| peakrdl_config | The peakrdl config file. | Label | required |
verilog_system_rdl_library
load("@rules_verilog//system_rdl:defs.bzl", "verilog_system_rdl_library")
verilog_system_rdl_library(name, lib)
A rule which extracts a verilog_library from a system_rdl_library.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| lib | The system_rdl_library to extract Verilog from. | Label | required |
SystemRdlInfo
load("@rules_verilog//system_rdl:defs.bzl", "SystemRdlInfo")
SystemRdlInfo(root, srcs)
Info for SystemRDL targets.
FIELDS