cocotb_toolchain
Rules
cocotb_toolchain
load("@rules_cocotb//cocotb:cocotb_toolchain.bzl", "cocotb_toolchain")
cocotb_toolchain(name, cocotb, default_sim, env, simulators)
Define a toolchain for cocotb_* rules.
The toolchain bundles a cocotb Python library with a set of HDL
simulators that cocotb_test targets can select between via their sim
attribute. Register an instance with the standard toolchain(...)
wrapper to make it discoverable.
Registering simulators
Each entry in simulators is a cocotb_*_sim target keyed by the
string name that cocotb_test(sim = ...) will use to select it.
Names are user-chosen — common conventions are "verilator",
"icarus", "ghdl". Each name must be unique within the dict.
load("@rules_cocotb//cocotb:cocotb_ghdl_sim.bzl", "cocotb_ghdl_sim")
load("@rules_cocotb//cocotb:cocotb_icarus_sim.bzl", "cocotb_icarus_sim")
load("@rules_cocotb//cocotb:cocotb_toolchain.bzl", "cocotb_toolchain")
load("@rules_cocotb//cocotb:cocotb_verilator_sim.bzl", "cocotb_verilator_sim")
# Instantiate the sim rules you want to ship.
cocotb_verilator_sim(
name = "cocotb_verilator",
# ... (see //cocotb/toolchain:BUILD.bazel for the full attr set)
)
cocotb_ghdl_sim(
name = "cocotb_ghdl",
ghdl = "@ghdl",
vhdl_libs = ["@ghdl//:vhdl_libs_v08"],
)
cocotb_icarus_sim(
name = "cocotb_icarus",
iverilog = "@iverilog//:iverilog",
vvp = "@iverilog//:vvp",
ivl_files = {
"@iverilog//:ivl": "ivl",
# ... (see //cocotb/toolchain:BUILD.bazel for the full map)
},
)
cocotb_toolchain(
name = "my_cocotb_toolchain",
cocotb = "//path/to:cocotb_py_library",
default_sim = "verilator",
simulators = {
":cocotb_ghdl": "ghdl",
":cocotb_icarus": "icarus",
":cocotb_verilator": "verilator",
},
)
toolchain(
name = "my_toolchain",
toolchain = ":my_cocotb_toolchain",
toolchain_type = "@rules_cocotb//cocotb:toolchain_type",
)
Add register_toolchains("//path/to:my_toolchain") to MODULE.bazel
ahead of //cocotb/toolchain to override the default. default_sim
chooses which simulator runs when a cocotb_test omits its own sim
attribute; it's optional, but if set must name one of the keys in
simulators.
Per-simulator API and wiring details live in the Simulators section.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| cocotb | The cocotb python library. | Label | required | |
| default_sim | An optional default simulator to use. | String | optional | "" |
| env | Environment variables to set whenever the toolchain invokes a simulator. Applied to every sim registered in simulators; for sim-specific vars (license server, install root, etc.) prefer the per-cocotb_*_sim env attr instead. Precedence at test time: toolchain env < sim env < rule-level cocotb_test(env = ...). | Dictionary: String -> String | optional | {} |
| simulators | A mapping of cocotb_*_sim targets to their matching simulator names. Every target must provide CocotbSimInfo. | Dictionary: Label -> String | required |