rules_dx gives you one dx command to build, test, lint, typecheck,
format, generate, audit and release code in many languages. It runs on
Bazel, a build tool that caches every step, and it fetches each language's
toolchain for you, so you install nothing per language.
You need Bazelisk, the launcher that downloads the right Bazel version, on
your PATH as bazel. Download dx-<os>-<cpu> for your platform
(.exe on Windows) from the
latest release and
put it on your PATH as dx.
In an empty directory, set the project up and run its tests:
dx init --apply
tools/dx test //...On Windows, set it up with the Visual Studio Build Tools license accepted instead:
dx init --apply --accept-license visual-studio-build-toolsdx init --apply writes MODULE.bazel, which depends on rules_dx,
.bazelversion, the tools/dx launcher, CI and editor files. //... means
every target in the project. From now on, run dx through the launcher:
tools/dx --help
tools/dx build //...On a fresh clone, run tools/dx once first. Any dx command writes the
gitignored .dx/bazelrc files that plain bazel reads.
Behind a proxy or a company CA? See Corporate proxy and custom CA.
- Follow the tutorial. It takes you from an empty
directory to two tested packages and
dx test --affected. - Read Bazel for dx users for the Bazel terms and messages you meet in your first hour.
- Find your task in the docs index, or look up a command in the command reference.
Already have a Bazel repo? Read adopting rules_dx in an existing Bazel repo. New to Bazel and moving an existing project? Read adopting rules_dx without Bazel experience. You can also browse the examples, set up CI, check the support matrix, or read everything on the docs site.
You get:
- One
dxCLI instead of per-language scripts. - Pinned toolchains, so nobody installs tools per machine.
- Lint, format, and typecheck locally and in CI.
- Security and license audits with
dx securityanddx license; see audit and update. - A CI workflow from
dx init --apply; see init. - It replaces hand-picked rule-set versions, a Makefile or shell wrapper around Bazel, and CI config per language.
It costs:
- Bazel and its learning curve: BUILD files and
MODULE.bazel. - The files
dx initwrites: launcher, editor, devcontainer, CI and agent files; see init. - Following the pinned rule and tool versions. You move when you run
dx upgrade.
In your module, @rules_dx//:dx runs the dx binary for your platform. It
is checked against the sha256 in cli/prebuilt/pins.bzl. A release pins
binaries for linux x86_64, linux aarch64, macos aarch64, windows x86_64 and
windows aarch64.
- A version with no pinned sha256 builds
dxfrom source, with the Rust and C toolchainsdx initsets up. - Once some binary is pinned, a platform with no release binary fails the build.
To pick a binary yourself, add this to your root MODULE.bazel:
dx_prebuilt = use_extension("@rules_dx//core:extensions.bzl", "dx_prebuilt")
dx_prebuilt.asset(name = "dx", os = "linux", cpu = "x86_64", url = "https://...", sha256 = "...")name is the tool, and os and cpu are the @platforms values the binary
runs on. A jar tool such as javac_check takes os = "any" and
cpu = "any". Or build dx from source with dx_prebuilt.from_source(). That needs
Rust and C toolchains. Only the root module's tags count.
cli/prebuilt/tools.bzl lists every tool a release ships prebuilt, and
pins.bzl holds their sha256s under PINS, keyed by tool and then by
<os>_<cpu>.
The Gazelle binary behind dx generate works the same way. Each release
ships a pure-Go dx-gazelle-<os>-<cpu> per platform, pinned under
PINS["gazelle"] with the same DX_VERSION, so the first dx generate
fetches no Go SDK. It builds from source instead when:
rules_dxis the root module,- no gazelle binary is pinned, or
- a module other than
rules_dxadds adx_gazelle.language, because the release binary holds only the languagesrules_dxregisters.
The root module can override it:
dx_gazelle = use_extension("@rules_dx//core:extensions.bzl", "dx_gazelle")
dx_gazelle.asset(name = "gazelle", os = "linux", cpu = "x86_64", url = "https://...", sha256 = "...")or build it with dx_gazelle.from_source(), which needs a Go toolchain.
A global dx shim for your PATH is built from //cli/shim. It runs the
version in .dx/pins without Bazel. See
Global Shim.
- Microsoft
cl.exe(--//cc:compiler=msvc): the Visual Studio Build Tools come from the hermetic@dx_msvcrepo, not an installed Visual Studio. The download needs the Visual Studio Build Tools license, accepted withdx_licenses.accept(ids = ["visual-studio-build-tools"]). See the support matrix. - GCC (
--//cc:compiler=gcc): GCC 16.2.0 onlinux_x86_64andlinux_arm64, with no install.
See Contributing for the current workflow.
rules_dx is licensed under Apache-2.0.