This repository provides Bazel rules for building Mojo projects.
rules_mojo requires Bzlmod and Bazel 8 or later.
In MODULE.bazel, replace <rules_mojo_version> with a published version from
the Bazel Central Registry and
<mojo_version> with the Mojo version you want to use:
bazel_dep(name = "rules_mojo", version = "<rules_mojo_version>")
mojo = use_extension("@rules_mojo//mojo:extensions.bzl", "mojo")
mojo.toolchain(version = "<mojo_version>")Omit version from mojo.toolchain() to use the default Mojo toolchain. See the
toolchain definitions for the default version and pinned
releases. Unlisted nightly versions are downloaded without pinned checksums.
Then define a mojo_binary target in BUILD.bazel:
load("@rules_mojo//mojo:mojo_binary.bzl", "mojo_binary")
mojo_binary(
name = "hello_mojo",
srcs = ["hello_mojo.mojo"],
)See the tests directory for more examples.