cocotb_ghdl_sim

Rules

cocotb_ghdl_sim

load("@rules_cocotb//cocotb:cocotb_ghdl_sim.bzl", "cocotb_ghdl_sim")

cocotb_ghdl_sim(name, env, ghdl, ghdl_coverage, ghdl_prefix, vhdl_libs)

A simulator configuration for running GHDL simulations in cocotb tests.

Status

Working against the BCR ghdl module from version 6.0.0.bcr.1 onward, which links the ghdl binary with -Wl,--export-dynamic and the upstream src/grt/grt.ver version script so cocotb's libcocotbvpi_ghdl.so can resolve unprefixed vpi_* symbols at dlopen time. Earlier ghdl@6.0.0 is missing those linker flags and fails at sim time with undefined symbol: vpi_register_cb.

The backend is selectable with --@ghdl//:backend={mcode, llvm-jit} (default mcode on x86_64, llvm-jit elsewhere).

Notes

GHDL only supports VHDL (VhdlInfo); pair it with a vhdl_library target as the module. The integration is build-at-test-time: cocotb's runner runs ghdl -a/-m in a writable build_dir via Runner.build(). Pre-compiling at Bazel time isn't viable because the JIT backends bake absolute sandbox paths into the .cf files.

The vhdl_libs attribute should point at the pre-compiled IEEE/std libraries from the BCR ghdl module — most projects want ["@ghdl//:vhdl_libs_v08"].

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
envEnvironment variables to set when the cocotb runner invokes this simulator at test time (license-server pointers, install root vars, …). Precedence: toolchain env < sim env < rule-level cocotb_test(env = ...).Dictionary: String -> Stringoptional{}
ghdlThe ghdl binary.Labelrequired
ghdl_coverageThe ghdl binary to invoke at test time under bazel coverage to translate *.cov files to lcov via ghdl coverage --format=lcov. Defaults to the same ghdl binary (target config so the runtime wrapper can invoke it). NOTE: requires a gcc-backed ghdl; the BCR mcode/llvm-jit backends don't produce coverage data.LabeloptionalNone
ghdl_prefixLiteral value to set as GHDL_PREFIX at simulation time. Use this for ghdl installs where the prefix is a stable absolute path on disk — typically a system/.deb/Homebrew install (e.g. "/usr/lib/ghdl").

When unset (default), GHDL_PREFIX is auto-derived from vhdl_libs if it's populated (BCR-shaped layout), otherwise left unset so ghdl falls back to its own compiled-in search paths.
Stringoptional""
vhdl_libsPre-compiled VHDL standard libraries (e.g. @ghdl//:vhdl_libs_v08). Assumes the BCR ghdl module's layout<root>/{std,ieee}/v<XX>/<name>-objXX.cf — from which GHDL_PREFIX is derived. If you ship ghdl differently and the IEEE/std libs are already discoverable by the binary, leave this empty and (optionally) set ghdl_prefix to a literal path, or skip both for a system install that uses its compiled-in defaults.List of labelsoptional[]