Toolchain for the Xilinx Vivado tool.
Defines VivadoToolchainInfo and the vivado_toolchain rule. Users register a
vivado_toolchain instance via register_toolchains(...) against the
//vivado:toolchain_type toolchain type so every vivado_* rule automatically
resolves the Xilinx environment.
Quickstart
-
Author a small bash shim that
execs your Vivado install. The shim is the file Bazel tracks; it hard-codes the install path (typically a fixed location baked into a container image):#!/usr/bin/env bash # tools/vivado/vivado.sh exec /opt/Xilinx/Vivado/2024.2/bin/vivado "$@"Mark it executable:
chmod +x tools/vivado/vivado.sh. -
Declare a
vivado_toolchainand atoolchain()wrapper in BUILD, pointing at the shim. Put your license server and any extra env inenv:load("@rules_vivado//vivado:toolchain.bzl", "vivado_toolchain") vivado_toolchain( name = "vivado_local", vivado = "vivado.sh", env = { "XILINXD_LICENSE_FILE": "2100@license.example.com", "HOME": "/tmp", }, ) toolchain( name = "vivado_toolchain", toolchain = ":vivado_local", toolchain_type = "@rules_vivado//vivado:toolchain_type", ) -
Register it from MODULE.bazel:
register_toolchains("//tools/vivado:vivado_toolchain")
Every vivado_* rule resolves this toolchain automatically.
xilinx_env is an optional escape hatch — a shell script sourced inside the
action immediately before vivado runs — for shell-side env composition
neither env nor the shim itself covers. Prefer env and the shim's own
preamble first.
Constraining toolchains
Register multiple vivado_toolchain instances side-by-side and let Bazel pick
one per action via exec_compatible_with against the per-version
constraint_values in //vivado/constraints/BUILD.bazel. Each constraint
corresponds to one entry in //vivado/private:versions.bzl VIVADO_VERSIONS.
load("@rules_vivado//vivado:toolchain.bzl", "vivado_toolchain")
vivado_toolchain(
name = "vivado_2024_2",
vivado = "vivado_2024_2.sh",
)
toolchain(
name = "vivado_toolchain_2024_2",
exec_compatible_with = ["@rules_vivado//vivado/constraints/version:2024.2"],
toolchain = ":vivado_2024_2",
toolchain_type = "@rules_vivado//vivado:toolchain_type",
)
platform(
name = "vivado_2024_2_platform",
constraint_values = ["@rules_vivado//vivado/constraints/version:2024.2"],
exec_properties = {
"container-image": "docker://your.registry/vivado:2024.2",
},
parents = ["@platforms//host"],
)
Register both the toolchain and the platform from MODULE.bazel:
register_toolchains("//tools/vivado:vivado_toolchain_2024_2")
register_execution_platforms("//tools/vivado:vivado_2024_2_platform")
The first registered exec platform becomes the default. Switch versions per
build with --platforms=//tools/vivado:vivado_2024_2_platform (which also lets
target_compatible_with = ["@rules_vivado//vivado/constraints/version:2024.2"]
on a target evaluate against the right constraint), or use a wrapper rule with
cfg = transition(...) to switch per target. See
//tests/transition.bzl for an example with_vivado_version wrapper.
Rules
Providers
vivado_toolchain
load("@rules_vivado//vivado:toolchain.bzl", "vivado_toolchain")
vivado_toolchain(name, env, requires_network, version, vivado, xilinx_env)
Declares a Vivado toolchain.
Wrap with toolchain(...) and register via register_toolchains(...) in
MODULE.bazel so every vivado_* rule resolves it automatically. Multiple
instances can be registered side-by-side and selected via target_settings
(flag-driven) or exec_compatible_with (platform-driven). See the
//vivado:toolchain.bzl module docstring and the rules_vivado README for full
walkthroughs.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| env | Environment variables passed to every Vivado action. | Dictionary: String -> String | optional | {} |
| requires_network | Whether Vivado actions need network access. True (the default) is correct for a floating/network license server (XILINXD_LICENSE_FILE=PORT@HOST). Set to False for license-free editions (Vivado ML Standard / WebPACK) or node-locked .lic files read from disk. Controls whether the requires-network execution requirement is set on every vivado_* action. | Boolean | optional | True |
| version | The version of Vivado associated with this toolchain. | String | optional | "" |
| vivado | The Vivado executable. Typically a small bash shim that execs the real vivado out of a known install path (e.g. baked into a container image), but any *_binary rule works too — runfiles travel along. Defaults to a stock shim that calls vivado from the exec platform's PATH as a migration aid; production toolchains should pin the install path with their own shim. | Label | optional | "@rules_vivado//vivado/private:vivado.sh" |
| xilinx_env | Optional escape hatch — a shell script sourced inside the action shell immediately before vivado runs, for shell-side env composition env cannot express. Prefer env. | Label | optional | None |
VivadoToolchainInfo
load("@rules_vivado//vivado:toolchain.bzl", "VivadoToolchainInfo")
VivadoToolchainInfo(env, requires_network, version, vivado, xilinx_env)
Toolchain info for the Xilinx Vivado tool.
FIELDS