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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsThe list of other libraries to be linked.List of labelsoptional[]
srcsVerilog or SystemVerilog sources.List of labelsoptional[]
hdrsVerilog or SystemVerilog headers.List of labelsoptional[]
compile_dataTODOList of labelsoptional[]
topThe top of the module. If unset, a file must be found matching the name of the target.LabeloptionalNone

VerilogInfo

load("@rules_verilog//verilog:defs.bzl", "VerilogInfo")

VerilogInfo(compile_data, deps, hdrs, srcs, top)

Verilog provider

FIELDS

NameDescription
compile_dataDepset[File]: Files required at compile time.
depsDepset[VerilogInfo]: Transitive Verilog dependencies.
hdrsDepset[File]: Verilog/SystemVerilog header files.
srcsDepset[File]: Verilog/SystemVerilog source files.
topFile: The source file that represents the module top. The file name is expected to match the module name.

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
dataData used at runtime by the libraryList of labelsoptional[]
linkoptsList of additional C++ linker flagsList of stringsoptional[]
moduleThe top level Verilog module target to compile with Verilator.Labelrequired

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
moduleThe Verilog module to lint.Labelrequired

verilator_toolchain

load("@rules_verilog//verilator:defs.bzl", "verilator_toolchain")

verilator_toolchain(name, deps, copts, libverilator, linkopts, verilator, vopts)

Define a Verilator toolchain.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsGlobal Verilator dependencies to link into downstream targets.List of labelsoptional[]
coptsExtra compiler flags to pass when compiling Verilator outputs.List of stringsoptional[]
libverilatorThe Verilator library.Labelrequired
linkoptsExtra linker flags to pass when linking Verilator outputs.List of stringsoptional[]
verilatorThe Verilator binary.Labelrequired
voptsExtra flags to pass to Verilate actions.List of stringsoptional[]

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsAdditional system_rdl_library dependencies.List of labelsoptional[]
srcsSource files which define the entire SystemRDL dag.List of labelsrequired
exporter_argsA mapping of exporter names to arguments.Dictionary: String -> List of stringsoptional{}
rootThe top source file of the SystemRDL library.LabeloptionalNone

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
exporter_argsA pair of exporters keys to a list of default exporter args to apply to all rules.Dictionary: String -> List of stringsoptional{}
exportersA mapping of exporters to expected output file formats.Dictionary: String -> Stringoptional{"html": "_html", "regblock": ".sv"}
peakrdlThe python library for the peakrdl package.LabeloptionalNone
peakrdl_configThe peakrdl config file.Labelrequired

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
libThe system_rdl_library to extract Verilog from.Labelrequired

SystemRdlInfo

load("@rules_verilog//system_rdl:defs.bzl", "SystemRdlInfo")

SystemRdlInfo(root, srcs)

Info for SystemRDL targets.

FIELDS

NameDescription
rootFile: The top level source file for a library.
srcsDepset[File]: All (including transitive) source files.