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