fork/rules_rust

git clone https://git.julia.blue/fork/rules_rust

UebelAndreAdded bzlmod support to core rules_rust (#3034)69ddb09d

main
1.7 KiB60 linesraw
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.10")
9bazel_dep(
10    name = "bazel_skylib",
11    version = "1.7.1",
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
22# To do third party dependencies, you have multiple options:
23
24# Option 1: Fully transient (Cargo.toml / Cargo.lock as source of truth).
25crate = use_extension(
26    "@rules_rust//crate_universe:extensions.bzl",
27    "crate",
28)
29crate.from_cargo(
30    name = "crates_in_workspace",
31    cargo_lockfile = "//third-party-in-workspace:Cargo.lock",
32    manifests = ["//third-party-in-workspace:Cargo.toml"],
33)
34use_repo(crate, "crates_in_workspace")
35crate.annotation(
36    additive_build_file = "//:BUILD.anyhow.bazel",
37    crate = "anyhow",
38    # Defined in additive_build_file.
39    data = [":cargo_toml"],
40    # Optional, you probably don't need this. Defaults to all from_cargo
41    # invocations in this module.
42    repositories = [
43        "crates_in_workspace",
44        "crates_without_workspace",
45    ],
46    # Optional, you probably don't need this, defaults to "*".
47    version = "*",
48)
49
50# Option 2: Vendored crates
51crate_repositories = use_extension("//third-party-in-workspace:extension.bzl", "crate_repositories")
52use_repo(crate_repositories, "vendor__anyhow-1.0.77")
53
54# Another example of Option 1, but where the Cargo.toml file isn't a [workspace]
55crate.from_cargo(
56    name = "crates_without_workspace",
57    cargo_lockfile = "//third-party-without-workspace:Cargo.lock",
58    manifests = ["//third-party-without-workspace:Cargo.toml"],
59)
60use_repo(crate, "crates_without_workspace")