Run Windows build tools with Bazel on Linux, macOS and Windows. rules_wine
provides Wine toolchains, an executable wrapper, and an action helper that runs
Windows executables directly when the worker is Windows.
Wine distributions come from hermeticbuild/wine-prebuilt. Downloads are pinned by checksum. You can also register your own distribution.
Native wmc, wrc and widl compile message tables, resources and IDLs directly
on all five executors. Their separate toolchains need no Wine runtime or C++
compiler. See native developer tools.
Add to MODULE.bazel:
bazel_dep(name = "rules_wine", version = "0.1.3")
wine = use_extension("@rules_wine//wine/extension:wine.bzl", "wine")
use_repo(wine, "wine_toolchains")
register_toolchains("@wine_toolchains//:all")For a local checkout, also add
local_path_override(module_name = "rules_wine", path = "../rules_wine").
Requires Bazel 8.5 or newer. On Linux and macOS, the Wine supervisor is built
from source using your C++17 toolchain. Bazel can use an installed compiler;
for hermetic or remote builds, register your own C++ toolchain. rules_wine
does not select one for you. Native Windows actions need no Wine or supervisor.
The default toolchains support these combinations:
| Execution platform | Windows executable CPU |
|---|---|
| Linux x86_64 | x86_64 |
| Linux ARM64 | ARM64, x86_64 through FEX |
| macOS ARM64 | ARM64, x86_64 through FEX |
| Windows x86_64 | x86_64 |
| Windows ARM64 | ARM64 |
CPU translation is included in the ARM64 Wine distributions; no extra setup is needed for x86_64 prebuilts. Linux requires glibc 2.17 or newer and a UTF-8 locale. The macOS runtime declares a 26.5 deployment minimum; it has been tested on later 26.x versions, not on exact 26.5. There is no default Intel macOS distribution. See runtime requirements and limitations.
Register the native tools independently in MODULE.bazel:
wine = use_extension("@rules_wine//wine/extension:wine.bzl", "wine")
use_repo(wine, "wine_tools_toolchains")
register_toolchains("@wine_tools_toolchains//:all")load("@rules_wine//wine:wine_message_file.bzl", "wine_message_file")
load("@rules_wine//wine:wine_resource_file.bzl", "wine_resource_file")
load("@rules_wine//wine:wine_idl_files.bzl", "wine_idl_files")
wine_message_file(name = "messages", src = "messages.mc", out = "messages.rc")
wine_resource_file(name = "message_resources", src = "messages.rc", out = "messages.res")
wine_idl_files(name = "interfaces", src = "interfaces.idl", header = "interfaces.h", typelib = "interfaces.tlb")The message rule also emits messages.h; outputs are ordinary file labels.
WIDL selects the Windows output ABI from the configured target CPU, independently
of the executor. Consumers own C/C++ compilation and linking. The
tools guide covers declared imports/assets, custom toolchains,
low-level actions and optional path mapping. Executable labels
@rules_wine//wine:wmc, :wrc and :widl are also available for bazel run
and bazel_lib's run_binary, using the same registration.
Use windows_binary to run a Windows tool on Linux or macOS:
load("@rules_wine//wine:windows_binary.bzl", "windows_binary")
windows_binary(
name = "generator",
binary = "generator.exe",
)bazel run //:generator -- --helpThe wrapper can also be an executable dependency of another rule. It accepts prebuilt executables or source-built targets; see executable adapters for compilation platforms, runfiles and path arguments.
Rule authors can use windows_actions for actions that work on all five
execution platforms. Wine handles Linux/macOS; Windows runs the tool directly.
Within a rule implementation:
runner = windows_actions.resolve(ctx)
args = ctx.actions.args()
args.add("--output")
windows_actions.add_path(runner, args, output)
windows_actions.run(
ctx,
runner = runner,
executable = ctx.file.tool,
arguments = [args],
outputs = [output],
)The rule declares windows_actions.toolchain_type and configures its tool for
execution. See the action guide for a complete rule, source
compilation, optional path mapping and choosing workers to avoid CPU translation.
- BCR API reference (for releases publishing API docs)
- Custom Wine distributions and toolchains
- Native message, resource and IDL compilers
- Runtime behavior, isolation and limitations
- Tests and contributing
- Maintaining Starlark libraries and API documentation
- Releases and BCR publication
Apache-2.0. Downloaded Wine distributions retain their own licenses and source redistribution material.