rules_powershell
Bazel rules for PowerShell.
Setup
To begin using the rules, add the following to your MODULE.bazel file:
# Available versions can be found here: https://github.com/periareon/rules_powershell/releases
bazel_dep(name = "rules_powershell", version = "{version}")
Toolchains
By default no toolchain is registered for the rules. To register toolchains, see the module extension powershell.toolchain
Powershell rules
Rules
Providers
pwsh_binary
load("@rules_powershell//powershell:defs.bzl", "pwsh_binary")
pwsh_binary(name, deps, srcs, data, env)
The pwsh_binary rule is used to declare executable powershell scripts.
(pwsh_binary is a misnomer: its outputs aren't necessarily binaries.) This rule ensures
that all dependencies are built, and appear in the runfiles area at execution time.
We recommend that you name your pwsh_binary() rules after the name of the script minus
the extension (e.g. .ps1); the rule name and the file name must be distinct.
For a simple Powershell script with no dependencies and some data files:
pwsh_binary(
name = "foo",
srcs = ["foo.ps1"],
data = glob(["datafiles/*.txt"]),
)
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | The list of "library" targets to be aggregated into this target. See general comments about deps at Typical attributes defined by most build rules. This attribute should be used to list other sh_library rules that provide interpreted program source code depended on by the code in srcs. The files provided by these rules will be present among the runfiles of this target. | List of labels | optional | [] |
| srcs | The list of source (.ps1) files that are processed to create the target. | List of labels | optional | [] |
| 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 | {} |
pwsh_library
load("@rules_powershell//powershell:defs.bzl", "pwsh_library")
pwsh_library(name, deps, srcs, data)
The main use for this rule is to aggregate together a logical "library" consisting of related scripts and modules.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | The list of "library" targets to be aggregated into this target. See general comments about deps at Typical attributes defined by most build rules. This attribute should be used to list other sh_library rules that provide interpreted program source code depended on by the code in srcs. The files provided by these rules will be present among the runfiles of this target. | List of labels | optional | [] |
| srcs | The list of source files that are processed to create the target. | List of labels | optional | [] |
| data | Files needed by this rule at runtime. May list file or rule targets. Generally allows any target. | List of labels | optional | [] |
pwsh_test
load("@rules_powershell//powershell:defs.bzl", "pwsh_test")
pwsh_test(name, deps, srcs, data, env, env_inherit)
A pwsh_test rule creates a test written as a Powershell script.
pwsh_test(
name = "foo_integration_test",
size = "small",
srcs = ["foo_integration_test.ps1"],
deps = [":foo_sh_lib"],
data = glob(["testdata/*.txt"]),
)
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | The list of "library" targets to be aggregated into this target. See general comments about deps at Typical attributes defined by most build rules. This attribute should be used to list other sh_library rules that provide interpreted program source code depended on by the code in srcs. The files provided by these rules will be present among the runfiles of this target. | List of labels | optional | [] |
| srcs | The list of source (.ps1) files that are processed to create the target. | List of labels | optional | [] |
| 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 | {} |
| env_inherit | Specifies additional environment variables to inherit from the external environment when the test is executed by bazel test. | List of strings | optional | [] |
PwshInfo
load("@rules_powershell//powershell:defs.bzl", "PwshInfo")
PwshInfo(imports, srcs)
A provider for Powershell rules.
FIELDS
Powershell bzlmod extensions
Module Extensions
powershell
powershell = use_extension("@rules_powershell//powershell:extensions.bzl", "powershell")
powershell.toolchain(name, urls, version)
Bzlmod extensions for Powershell
TAG CLASSES
toolchain
An extension for defining a pwsh_toolchain from a download archive.
An example of defining and registering toolchains:
powershell = use_extension("//powershell:extensions.bzl", "powershell", dev_dependency = True)
powershell.toolchain(
name = "powershell_toolchains",
version = "7.5.3",
)
use_repo(powershell, "powershell_toolchains")
register_toolchains(
"@powershell_toolchains//:all",
dev_dependency = True,
)
Attributes
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | The name of the toolchain. | Name | required | |
| urls | Url templates to use for downloading Powershell. | List of strings | optional | ["https://github.com/PowerShell/PowerShell/releases/download/v{semver}/{artifact}"] |
| version | The version of Powershell to download. | String | optional | "7.5.4" |