1"""bazelbuild/rules_rust - bzlmod example""" 2 3module( 4 name = "hello_world_example", 5 version = "0.0.0", 6) 7 8bazel_dep(name = "platforms", version = "0.0.8") 9bazel_dep( 10 name = "bazel_skylib", 11 version = "1.5.0", 12) 13bazel_dep( 14 name = "rules_rust", 15 version = "0.0.0", 16) 17local_path_override( 18 module_name = "rules_rust", 19 path = "../../..", 20) 21 22rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") 23rust.toolchain(edition = "2021") 24use_repo( 25 rust, 26 "rust_toolchains", 27) 28 29register_toolchains("@rust_toolchains//:all") 30 31# To do third party dependencies, you have multiple options: 32 33# Option 1: Fully transient (Cargo.toml / Cargo.lock as source of truth). 34crate = use_extension( 35 "@rules_rust//crate_universe:extension.bzl", 36 "crate", 37) 38crate.from_cargo( 39 name = "crates", 40 cargo_lockfile = "//third-party:Cargo.lock", 41 manifests = ["//third-party:Cargo.toml"], 42) 43use_repo(crate, "crates") 44crate.annotation( 45 additive_build_file = "//:anyhow.BUILD.bazel", 46 crate = "anyhow", 47 # Defined in additive_build_file. 48 data = [":cargo_toml"], 49 # Optional, you probably don't need this. Defaults to all from_cargo 50 # invocations in this module. 51 repositories = ["crates"], 52 # Optional, you probably don't need this, defaults to "*". 53 version = "*", 54) 55 56# Option 2: Vendored crates 57crate_repositories = use_extension("//third-party:extension.bzl", "crate_repositories") 58use_repo(crate_repositories, "vendor__anyhow-1.0.77") 59