xref: /aosp_15_r20/external/bazelbuild-rules_rust/docs/BUILD.bazel (revision d4726bddaa87cc4778e7472feed243fa4b6c267f)
1*d4726bddSHONG Yifanload("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2*d4726bddSHONG Yifanload("@stardoc//stardoc:stardoc.bzl", "stardoc")
3*d4726bddSHONG Yifanload("//:page.bzl", "gen_header", "page")
4*d4726bddSHONG Yifan
5*d4726bddSHONG Yifanpackage(default_visibility = ["//visibility:private"])
6*d4726bddSHONG Yifan
7*d4726bddSHONG Yifanbzl_library(
8*d4726bddSHONG Yifan    name = "docs_deps",
9*d4726bddSHONG Yifan    srcs = [
10*d4726bddSHONG Yifan        "@bazel_tools//tools:bzl_srcs",
11*d4726bddSHONG Yifan        "@com_google_protobuf//:bzl_srcs",
12*d4726bddSHONG Yifan    ],
13*d4726bddSHONG Yifan    deps = [
14*d4726bddSHONG Yifan        "@bazel_features//:deps",
15*d4726bddSHONG Yifan        "@bazel_features//:features",
16*d4726bddSHONG Yifan        "@bazel_skylib//lib:paths",
17*d4726bddSHONG Yifan        "@bazel_skylib//lib:selects",
18*d4726bddSHONG Yifan        "@bazel_skylib//lib:structs",
19*d4726bddSHONG Yifan        "@bazel_skylib//rules:common_settings",
20*d4726bddSHONG Yifan        "@rules_proto//proto:defs",
21*d4726bddSHONG Yifan        "@rules_proto//proto:repositories",
22*d4726bddSHONG Yifan    ],
23*d4726bddSHONG Yifan)
24*d4726bddSHONG Yifan
25*d4726bddSHONG Yifanbzl_library(
26*d4726bddSHONG Yifan    name = "all_docs",
27*d4726bddSHONG Yifan    deps = [
28*d4726bddSHONG Yifan        ":docs_deps",
29*d4726bddSHONG Yifan        "@rules_rust//:bzl_lib",
30*d4726bddSHONG Yifan        "@rules_rust//bindgen:bzl_lib",
31*d4726bddSHONG Yifan        "@rules_rust//cargo:bzl_lib",
32*d4726bddSHONG Yifan        "@rules_rust//crate_universe:bzl_lib",
33*d4726bddSHONG Yifan        "@rules_rust//crate_universe/private/module_extensions:bzl_lib",
34*d4726bddSHONG Yifan        "@rules_rust//proto:bzl_lib",
35*d4726bddSHONG Yifan        "@rules_rust//rust:bzl_lib",
36*d4726bddSHONG Yifan        "@rules_rust//wasm_bindgen:bzl_lib",
37*d4726bddSHONG Yifan    ],
38*d4726bddSHONG Yifan)
39*d4726bddSHONG Yifan
40*d4726bddSHONG YifanPAGES = dict([
41*d4726bddSHONG Yifan    page(
42*d4726bddSHONG Yifan        name = "cargo",
43*d4726bddSHONG Yifan        symbols = [
44*d4726bddSHONG Yifan            "cargo_bootstrap_repository",
45*d4726bddSHONG Yifan            "cargo_build_script",
46*d4726bddSHONG Yifan            "cargo_dep_env",
47*d4726bddSHONG Yifan            "cargo_env",
48*d4726bddSHONG Yifan        ],
49*d4726bddSHONG Yifan    ),
50*d4726bddSHONG Yifan    page(
51*d4726bddSHONG Yifan        name = "defs",
52*d4726bddSHONG Yifan        symbols = [
53*d4726bddSHONG Yifan            "rust_binary",
54*d4726bddSHONG Yifan            "rust_library",
55*d4726bddSHONG Yifan            "rust_library_group",
56*d4726bddSHONG Yifan            "rust_static_library",
57*d4726bddSHONG Yifan            "rust_shared_library",
58*d4726bddSHONG Yifan            "rust_proc_macro",
59*d4726bddSHONG Yifan            "rust_test",
60*d4726bddSHONG Yifan            "rust_test_suite",
61*d4726bddSHONG Yifan            "error_format",
62*d4726bddSHONG Yifan            "extra_rustc_flag",
63*d4726bddSHONG Yifan            "extra_rustc_flags",
64*d4726bddSHONG Yifan            "capture_clippy_output",
65*d4726bddSHONG Yifan        ],
66*d4726bddSHONG Yifan    ),
67*d4726bddSHONG Yifan    page(
68*d4726bddSHONG Yifan        name = "providers",
69*d4726bddSHONG Yifan        symbols = [
70*d4726bddSHONG Yifan            "CrateInfo",
71*d4726bddSHONG Yifan            "DepInfo",
72*d4726bddSHONG Yifan            "StdLibInfo",
73*d4726bddSHONG Yifan        ],
74*d4726bddSHONG Yifan    ),
75*d4726bddSHONG Yifan    page(
76*d4726bddSHONG Yifan        name = "rust_analyzer",
77*d4726bddSHONG Yifan        header_template = ":rust_analyzer.vm",
78*d4726bddSHONG Yifan        symbols = [
79*d4726bddSHONG Yifan            "rust_analyzer_aspect",
80*d4726bddSHONG Yifan            "rust_analyzer_toolchain",
81*d4726bddSHONG Yifan        ],
82*d4726bddSHONG Yifan    ),
83*d4726bddSHONG Yifan    page(
84*d4726bddSHONG Yifan        name = "rust_bindgen",
85*d4726bddSHONG Yifan        header_template = ":rust_bindgen.vm",
86*d4726bddSHONG Yifan        symbols = [
87*d4726bddSHONG Yifan            "rust_bindgen_library",
88*d4726bddSHONG Yifan            "rust_bindgen",
89*d4726bddSHONG Yifan            "rust_bindgen_toolchain",
90*d4726bddSHONG Yifan            "rust_bindgen_dependencies",
91*d4726bddSHONG Yifan            "rust_bindgen_register_toolchains",
92*d4726bddSHONG Yifan        ],
93*d4726bddSHONG Yifan    ),
94*d4726bddSHONG Yifan    page(
95*d4726bddSHONG Yifan        name = "rust_clippy",
96*d4726bddSHONG Yifan        header_template = ":rust_clippy.vm",
97*d4726bddSHONG Yifan        symbols = [
98*d4726bddSHONG Yifan            "rust_clippy",
99*d4726bddSHONG Yifan            "rust_clippy_aspect",
100*d4726bddSHONG Yifan        ],
101*d4726bddSHONG Yifan    ),
102*d4726bddSHONG Yifan    page(
103*d4726bddSHONG Yifan        name = "rust_doc",
104*d4726bddSHONG Yifan        symbols = [
105*d4726bddSHONG Yifan            "rust_doc",
106*d4726bddSHONG Yifan            "rust_doc_test",
107*d4726bddSHONG Yifan        ],
108*d4726bddSHONG Yifan    ),
109*d4726bddSHONG Yifan    page(
110*d4726bddSHONG Yifan        name = "rust_fmt",
111*d4726bddSHONG Yifan        header_template = ":rust_fmt.vm",
112*d4726bddSHONG Yifan        symbols = [
113*d4726bddSHONG Yifan            "rustfmt_aspect",
114*d4726bddSHONG Yifan            "rustfmt_test",
115*d4726bddSHONG Yifan            "rustfmt_toolchain",
116*d4726bddSHONG Yifan        ],
117*d4726bddSHONG Yifan    ),
118*d4726bddSHONG Yifan    page(
119*d4726bddSHONG Yifan        name = "rust_proto",
120*d4726bddSHONG Yifan        header_template = ":rust_proto.vm",
121*d4726bddSHONG Yifan        symbols = [
122*d4726bddSHONG Yifan            "rust_prost_library",
123*d4726bddSHONG Yifan            "rust_prost_toolchain",
124*d4726bddSHONG Yifan            "rust_prost_dependencies",
125*d4726bddSHONG Yifan            "rust_prost_transitive_repositories",
126*d4726bddSHONG Yifan        ] + [
127*d4726bddSHONG Yifan            "rust_proto_library",
128*d4726bddSHONG Yifan            "rust_grpc_library",
129*d4726bddSHONG Yifan            "rust_proto_protobuf_toolchain",
130*d4726bddSHONG Yifan            "rust_proto_protobuf_dependencies",
131*d4726bddSHONG Yifan            "rust_proto_protobuf_register_toolchains",
132*d4726bddSHONG Yifan            "rust_proto_protobuf_transitive_repositories",
133*d4726bddSHONG Yifan        ],
134*d4726bddSHONG Yifan    ),
135*d4726bddSHONG Yifan    page(
136*d4726bddSHONG Yifan        name = "rust_repositories",
137*d4726bddSHONG Yifan        symbols = [
138*d4726bddSHONG Yifan            "rules_rust_dependencies",
139*d4726bddSHONG Yifan            "rust_analyzer_toolchain_repository",
140*d4726bddSHONG Yifan            "rust_register_toolchains",
141*d4726bddSHONG Yifan            "rust_repositories",
142*d4726bddSHONG Yifan            "rust_repository_set",
143*d4726bddSHONG Yifan            "rust_stdlib_filegroup",
144*d4726bddSHONG Yifan            "rust_toolchain_repository_proxy",
145*d4726bddSHONG Yifan            "rust_toolchain_repository",
146*d4726bddSHONG Yifan            "rust_toolchain_tools_repository",
147*d4726bddSHONG Yifan            "rust_toolchain",
148*d4726bddSHONG Yifan        ],
149*d4726bddSHONG Yifan    ),
150*d4726bddSHONG Yifan    page(
151*d4726bddSHONG Yifan        name = "rust_wasm_bindgen",
152*d4726bddSHONG Yifan        header_template = ":rust_wasm_bindgen.vm",
153*d4726bddSHONG Yifan        symbols = [
154*d4726bddSHONG Yifan            "rust_wasm_bindgen_dependencies",
155*d4726bddSHONG Yifan            "rust_wasm_bindgen_register_toolchains",
156*d4726bddSHONG Yifan            "rust_wasm_bindgen_toolchain",
157*d4726bddSHONG Yifan            "rust_wasm_bindgen",
158*d4726bddSHONG Yifan            "RustWasmBindgenInfo",
159*d4726bddSHONG Yifan        ],
160*d4726bddSHONG Yifan    ),
161*d4726bddSHONG Yifan    page(
162*d4726bddSHONG Yifan        name = "settings",
163*d4726bddSHONG Yifan        symbols = [
164*d4726bddSHONG Yifan            "incompatible_flag",
165*d4726bddSHONG Yifan            "fail_when_enabled",
166*d4726bddSHONG Yifan        ],
167*d4726bddSHONG Yifan    ),
168*d4726bddSHONG Yifan])
169*d4726bddSHONG Yifan
170*d4726bddSHONG Yifan# Generate headers for each page
171*d4726bddSHONG Yifan[gen_header(page = p) for p in PAGES.values()]
172*d4726bddSHONG Yifan
173*d4726bddSHONG Yifan[
174*d4726bddSHONG Yifan    stardoc(
175*d4726bddSHONG Yifan        name = "%s_md" % k,
176*d4726bddSHONG Yifan        out = "%s.md" % k,
177*d4726bddSHONG Yifan        header_template = ":%s_gen_header_vm" % k,
178*d4726bddSHONG Yifan        input = ":symbols.bzl",
179*d4726bddSHONG Yifan        symbol_names = PAGES[k].symbols,
180*d4726bddSHONG Yifan        deps = [":all_docs"],
181*d4726bddSHONG Yifan    )
182*d4726bddSHONG Yifan    for k in PAGES.keys()
183*d4726bddSHONG Yifan]
184*d4726bddSHONG Yifan
185*d4726bddSHONG Yifangenrule(
186*d4726bddSHONG Yifan    name = "flatten_header_vm",
187*d4726bddSHONG Yifan    outs = ["flatten_header.vm"],
188*d4726bddSHONG Yifan    cmd = ">$@ echo '# Rust rules\n\n%s\n'" % "\n".join(
189*d4726bddSHONG Yifan        sorted(["* [{rule}](#{rule})".format(rule = v) for k in PAGES.keys() for v in PAGES[k].symbols]),
190*d4726bddSHONG Yifan    ),
191*d4726bddSHONG Yifan    output_to_bindir = True,
192*d4726bddSHONG Yifan)
193*d4726bddSHONG Yifan
194*d4726bddSHONG Yifanstardoc(
195*d4726bddSHONG Yifan    name = "flatten_md",
196*d4726bddSHONG Yifan    out = "flatten.md",
197*d4726bddSHONG Yifan    header_template = ":flatten_header_vm",
198*d4726bddSHONG Yifan    input = ":symbols.bzl",
199*d4726bddSHONG Yifan    symbol_names = sorted([symbol for k in PAGES.keys() for symbol in PAGES[k].symbols]),
200*d4726bddSHONG Yifan    deps = [":all_docs"],
201*d4726bddSHONG Yifan)
202*d4726bddSHONG Yifan
203*d4726bddSHONG Yifanstardoc(
204*d4726bddSHONG Yifan    name = "crate_universe_workspace",
205*d4726bddSHONG Yifan    out = "crate_universe.md",
206*d4726bddSHONG Yifan    input = "@rules_rust//crate_universe:docs_workspace.bzl",
207*d4726bddSHONG Yifan    deps = [":all_docs"],
208*d4726bddSHONG Yifan)
209*d4726bddSHONG Yifan
210*d4726bddSHONG Yifanstardoc(
211*d4726bddSHONG Yifan    name = "crate_universe_bzlmod",
212*d4726bddSHONG Yifan    out = "crate_universe_bzlmod.md",
213*d4726bddSHONG Yifan    input = "@rules_rust//crate_universe:docs_bzlmod.bzl",
214*d4726bddSHONG Yifan    deps = [":all_docs"],
215*d4726bddSHONG Yifan)
216*d4726bddSHONG Yifan
217*d4726bddSHONG Yifansh_binary(
218*d4726bddSHONG Yifan    name = "update_docs",
219*d4726bddSHONG Yifan    srcs = ["update_docs.sh"],
220*d4726bddSHONG Yifan)
221*d4726bddSHONG Yifan
222*d4726bddSHONG Yifansh_binary(
223*d4726bddSHONG Yifan    name = "test_docs",
224*d4726bddSHONG Yifan    srcs = ["test_docs.sh"],
225*d4726bddSHONG Yifan)
226