• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2load("@cui//:defs.bzl", "aliases", "all_crate_deps")
3load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_doc", "rust_doc_test", "rust_library", "rust_test")
4load("//crate_universe:version.bzl", "VERSION")
5
6exports_files(
7    glob([
8        "src/**/*.bzl",
9        "src/**/*.j2",
10        "src/**/*.rs",
11    ]) + [
12        "Cargo.toml",
13        "Cargo.lock",
14        "defs.bzl",
15        "docs.bzl",
16    ],
17    visibility = ["//visibility:public"],
18)
19
20filegroup(
21    name = "bzl_srcs",
22    srcs = glob(["*.bzl"]) + [
23        "//crate_universe/3rdparty:bzl_srcs",
24        "//crate_universe/private:bzl_srcs",
25        "//crate_universe/tools:bzl_srcs",
26    ],
27    visibility = ["//visibility:public"],
28)
29
30bzl_library(
31    name = "bzl_lib",
32    srcs = [":bzl_srcs"],
33    visibility = ["//visibility:public"],
34    deps = ["//rust:bzl_lib"],
35)
36
37filegroup(
38    name = "rust_srcs",
39    srcs = glob([
40        "src/**/*.bzl",
41        "src/**/*.j2",
42        "src/**/*.rs",
43    ]),
44    visibility = ["//:__subpackages__"],
45)
46
47rust_library(
48    name = "cargo_bazel",
49    srcs = glob(
50        include = ["src/**/*.rs"],
51        exclude = ["src/main.rs"],
52    ),
53    aliases = aliases(),
54    compile_data = glob(
55        include = ["src/**"],
56        exclude = ["src/**/*.rs"],
57    ),
58    edition = "2021",
59    proc_macro_deps = all_crate_deps(proc_macro = True),
60    # This target embeds additional, stamping related information (see
61    # https://docs.bazel.build/versions/main/user-manual.html#workspace_status
62    # for more information). Set stamp = -1 to indicate that it should respect
63    # the value of the --stamp comandline flag.
64    stamp = -1,
65    version = VERSION,
66    visibility = ["//visibility:public"],
67    deps = all_crate_deps(normal = True),
68)
69
70rust_binary(
71    name = "cargo_bazel_bin",
72    srcs = ["src/main.rs"],
73    edition = "2021",
74    version = VERSION,
75    visibility = ["//visibility:public"],
76    deps = [":cargo_bazel"],
77)
78
79alias(
80    name = "bin",
81    actual = ":cargo_bazel_bin",
82    visibility = ["//visibility:public"],
83)
84
85rust_test(
86    name = "unit_test",
87    aliases = aliases(),
88    crate = ":cargo_bazel",
89    data = glob(["test_data/**"]) + [
90        "//crate_universe/test_data/serialized_configs",
91        "@rules_rust//rust/toolchain:current_cargo_files",
92        "@rules_rust//rust/toolchain:current_rustc_files",
93    ],
94    proc_macro_deps = all_crate_deps(
95        proc_macro_dev = True,
96    ),
97    rustc_env = {
98        "CARGO": "$(rootpath @rules_rust//rust/toolchain:current_cargo_files)",
99        "RUSTC": "$(rootpath @rules_rust//rust/toolchain:current_rustc_files)",
100    },
101    deps = [
102        "@rules_rust//tools/runfiles",
103    ] + all_crate_deps(
104        normal_dev = True,
105    ),
106)
107
108# Integration tests which invoke cargo and/or rustc as subprocesses.
109rust_test(
110    name = "cargo_integration_test",
111    timeout = "long",
112    srcs = ["tests/cargo_integration_test.rs"],
113    aliases = aliases(),
114    data = glob(["test_data/**"]) + [
115        "//crate_universe/test_data/serialized_configs",
116        "@rules_rust//rust/toolchain:current_cargo_files",
117        "@rules_rust//rust/toolchain:current_rustc_files",
118    ],
119    edition = "2021",
120    env = {
121        "CARGO": "$(rootpath @rules_rust//rust/toolchain:current_cargo_files)",
122        "RUSTC": "$(rootpath @rules_rust//rust/toolchain:current_rustc_files)",
123    },
124    proc_macro_deps = all_crate_deps(
125        proc_macro_dev = True,
126    ),
127    rustc_env = {
128        "CARGO": "$(rootpath @rules_rust//rust/toolchain:current_cargo_files)",
129        "RUSTC": "$(rootpath @rules_rust//rust/toolchain:current_rustc_files)",
130    },
131    deps = [
132        ":cargo_bazel",
133        "@rules_rust//tools/runfiles",
134    ] + all_crate_deps(
135        normal = True,
136    ),
137)
138
139rust_test(
140    name = "versions_test",
141    srcs = ["tests/version_test.rs"],
142    data = [
143        "Cargo.toml",
144        "version.bzl",
145    ],
146    edition = "2021",
147    rustc_env = {
148        "CARGO_TOML": "$(rootpath :Cargo.toml)",
149        "VERSION_BZL": "$(rootpath :version.bzl)",
150    },
151)
152
153rust_doc(
154    name = "rustdoc",
155    crate = ":cargo_bazel",
156    rustdoc_flags = [
157        "--cap-lints=warn",
158        "--document-private-items",
159        "--allow=rustdoc::private_intra_doc_links",
160    ],
161    visibility = ["//visibility:public"],
162)
163
164rust_doc_test(
165    name = "rustdoc_test",
166    crate = ":cargo_bazel",
167)
168