Tcl Bazel rules

Rules

tcl_binary

load("@rules_tcl//tcl:defs.bzl", "tcl_binary")

tcl_binary(name, deps, srcs, data, env, main)

A tcl_binary is an executable Tcl program consisting of a collection of .tcl source files (possibly belonging to other tcl_library rules), a *.runfiles directory tree containing all the code and data needed by the program at run-time, and a stub script that starts up the program with the correct initial environment and data.

load("@rules_tcl//tcl:defs.bzl", "tcl_binary")

tcl_binary(
    name = "foo",
    srcs = ["foo.tcl"],
    deps = [
        ":bar",  # a tcl_library
    ],
)

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsOther Tcl packages to link to the current target.List of labelsoptional[]
srcsThe list of source (.tcl) files that are processed to create the target.List of labelsrequired
dataFiles needed by this rule at runtime. May list file or rule targets. Generally allows any target.List of labelsoptional[]
envDictionary of strings; values are subject to $(location) and "Make variable" substitution.Dictionary: String -> Stringoptional{}
mainThe name of the source file that is the main entry point of the application. This file must also be listed in srcs. If left unspecified, name is used instead. If name does not match any filename in srcs, main must be specified.LabeloptionalNone

tcl_library

load("@rules_tcl//tcl:defs.bzl", "tcl_library")

tcl_library(name, deps, srcs, data)

A Tcl library that can be depended upon by other Tcl targets.

A tcl_library represents a Tcl package that can be imported using Tcl's package require command. The library must include a pkgIndex.tcl file in its srcs attribute, which defines the package metadata and how to load the package.

Important: The pkgIndex.tcl file must be included in the srcs attribute. This file is used by Tcl's package system to locate and load the package.

Example:

load("@rules_tcl//tcl:defs.bzl", "tcl_library")

tcl_library(
    name = "mylib",
    srcs = [
        "mylib.tcl",
        "pkgIndex.tcl",
    ],
    deps = [
        ":otherlib",  # Another tcl_library
    ],
    visibility = ["//visibility:public"],
)

The library can then be used as a dependency in other targets:

tcl_binary(
    name = "app",
    srcs = ["app.tcl"],
    deps = [":mylib"],
)

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsOther Tcl packages to link to the current target.List of labelsoptional[]
srcsThe list of source (.tcl) files that are processed to create the target.List of labelsrequired
dataFiles needed by this rule at runtime. May list file or rule targets. Generally allows any target.List of labelsoptional[]

tcl_toolchain

load("@rules_tcl//tcl:defs.bzl", "tcl_toolchain")

tcl_toolchain(name, tclcore, tcllib, tclsh)

A toolchain rule that defines the Tcl interpreter and libraries for building Tcl targets.

The tcl_toolchain rule configures the Tcl environment used by all tcl_binary, tcl_library, and tcl_test targets. It specifies:

  • The Tcl interpreter (tclsh) to use for execution
  • The Tcl core library files (tclcore)
  • The Tcl standard library (tcllib)

Typically, you don't need to create a tcl_toolchain directly. The rules provide a default toolchain that you register in your MODULE.bazel:

register_toolchains("@rules_tcl//tcl/toolchain")

If you need a custom toolchain (e.g., a different Tcl version), you can define your own:

load("@rules_tcl//tcl:tcl_toolchain.bzl", "tcl_toolchain")

tcl_toolchain(
    name = "my_tcl_toolchain",
    tclsh = "@tcl_8_6//:tclsh",
    tclcore = "@tcl_8_6//:tclcore",
    tcllib = "@tcllib//:tcllib",
)

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
tclcoreA label to the tclcore files.Labelrequired
tcllibA label to the tcllib files.Labelrequired
tclshThe path to a tclsh binary.Labelrequired