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.