rules_ghdl 1.2.1Latest published 1.9mo ago
MODULE.bazel
bazel_dep(name = "rules_ghdl", version = "1.2.1")
README

Bazel rules for GHDL

Test status Publish BCR status Publish status Tag and Release status

This repository contains a bazel rule set for running ghdl, the VHDL simulator and synthesizer.

Prerequisites

  • bazel installation via bazelisk. I recommend downloading bazelisk and placing it somewhere in your $PATH under the name bazel.

Everything else will be downloaded for use the first time you run the build.

Documentation

See rules.md for the generated rule documentation.

Architecture & Integration with rules_vhdl

This workspace is fully integrated with the foundational rules_vhdl graph module. VHDL dependency graphs are declared once using vhdl_library, and the GHDL backend translates this metadata into compilation, elaboration, and test execution steps.

  • vhdl_library (from @rules_vhdl): Groups VHDL source files and describes dependencies. It generates a transitive VHDLLibraryProvider.
  • ghdl_analyze: Consumes vhdl_library targets and compiles VHDL files using ghdl -a into an isolated, hermetic GHDL object directory.
  • ghdl_elaborate: Takes compiled GHDL object targets and elaborates them using ghdl -e.
  • ghdl_test: Groups compilation, elaboration, and execution into an executable test rule using ghdl -r inside a sandboxed test runner.

Hermeticity

This rule set is completely hermetic. All dependencies are set up automatically by bazel. In addition, ghdl_analyze automatically rewrites absolute sandbox execution paths inside generated .cf library indexes into relative paths, enabling robust compilation across different sandboxed actions.

Examples

In general, see integration/ for example use.

The module is available through my bazel registry at https://github.com/filmil/bazel-registry.

Declaring a VHDL Library and Compile Target

load("@rules_vhdl//vhdl:defs.bzl", "vhdl_library")
load("@rules_ghdl//:rules.bzl", "ghdl_analyze")

# 1. Group the sources
vhdl_library(
    name = "lib_src",
    srcs = ["hello.vhdl"],
    library = "lib",
)

# 2. Analyze the library
ghdl_analyze(
    name = "lib",
    library = ":lib_src",
    args = ["--ieee=synopsys"],
)

Running VHDL Tests

load("@rules_ghdl//:rules.bzl", "ghdl_test")

ghdl_test(
    name = "hello_world_test",
    srcs = ["test.vhdl"],
    entity = "hello_world",
)

To run tests in the integration/ directory:

cd integration && bazel test //...

Notes

  • Only Linux host and target are supported for now, although it should be straightforward (but not necessarily trivial) to add support for other archs.

References

About

Bazel build rules for GHDL

@filmil/bazel_rules_ghdl@filmil

Languages

VHDL16.8%
Shell1.8%

Maintainers

@filmil

Compatibility

Versions

1.2.1 +1d2026-06-13
1.2.02026-06-12