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
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | Other Tcl packages to link to the current target. | List of labels | optional | [] |
| srcs | The list of source (.tcl) files that are processed to create the target. | List of labels | required | |
| data | Files needed by this rule at runtime. May list file or rule targets. Generally allows any target. | List of labels | optional | [] |
| env | Dictionary of strings; values are subject to $(location) and "Make variable" substitution. | Dictionary: String -> String | optional | {} |
| main | The 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. | Label | optional | None |
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
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | Other Tcl packages to link to the current target. | List of labels | optional | [] |
| srcs | The list of source (.tcl) files that are processed to create the target. | List of labels | required | |
| data | Files needed by this rule at runtime. May list file or rule targets. Generally allows any target. | List of labels | optional | [] |
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