|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 |
| -# buildifier: disable=module-docstring |
| 15 | +"""Rules for generating documentation with `rustdoc` for Bazel built crates""" |
| 16 | + |
16 | 17 | load("//rust/private:common.bzl", "rust_common")
|
17 | 18 | load("//rust/private:rustc.bzl", "add_crate_link_flags", "add_edition_flags")
|
18 |
| -load("//rust/private:utils.bzl", "find_toolchain") |
19 |
| - |
20 |
| -_rust_doc_doc = """Generates code documentation. |
21 |
| -
|
22 |
| -Example: |
23 |
| - Suppose you have the following directory structure for a Rust library crate: |
24 |
| -
|
25 |
| - ``` |
26 |
| - [workspace]/ |
27 |
| - WORKSPACE |
28 |
| - hello_lib/ |
29 |
| - BUILD |
30 |
| - src/ |
31 |
| - lib.rs |
32 |
| - ``` |
33 |
| -
|
34 |
| - To build [`rustdoc`][rustdoc] documentation for the `hello_lib` crate, define \ |
35 |
| - a `rust_doc` rule that depends on the the `hello_lib` `rust_library` target: |
36 |
| -
|
37 |
| - [rustdoc]: https://doc.rust-lang.org/book/documentation.html |
38 |
| -
|
39 |
| - ```python |
40 |
| - package(default_visibility = ["//visibility:public"]) |
41 |
| -
|
42 |
| - load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc") |
43 |
| -
|
44 |
| - rust_library( |
45 |
| - name = "hello_lib", |
46 |
| - srcs = ["src/lib.rs"], |
47 |
| - ) |
48 |
| -
|
49 |
| - rust_doc( |
50 |
| - name = "hello_lib_doc", |
51 |
| - crate = ":hello_lib", |
52 |
| - ) |
53 |
| - ``` |
54 |
| -
|
55 |
| - Running `bazel build //hello_lib:hello_lib_doc` will build a zip file containing \ |
56 |
| - the documentation for the `hello_lib` library crate generated by `rustdoc`. |
57 |
| -""" |
| 19 | +load("//rust/private:utils.bzl", "dedent", "find_toolchain") |
58 | 20 |
|
59 | 21 | def _rust_doc_impl(ctx):
|
60 | 22 | """The implementation of the `rust_doc` rule
|
@@ -146,7 +108,45 @@ def _zip_action(ctx, input_dir, output_zip):
|
146 | 108 | )
|
147 | 109 |
|
148 | 110 | rust_doc = rule(
|
149 |
| - doc = _rust_doc_doc, |
| 111 | + doc = dedent("""\ |
| 112 | + Generates code documentation. |
| 113 | +
|
| 114 | + Example: |
| 115 | + Suppose you have the following directory structure for a Rust library crate: |
| 116 | +
|
| 117 | + ``` |
| 118 | + [workspace]/ |
| 119 | + WORKSPACE |
| 120 | + hello_lib/ |
| 121 | + BUILD |
| 122 | + src/ |
| 123 | + lib.rs |
| 124 | + ``` |
| 125 | +
|
| 126 | + To build [`rustdoc`][rustdoc] documentation for the `hello_lib` crate, define \ |
| 127 | + a `rust_doc` rule that depends on the the `hello_lib` `rust_library` target: |
| 128 | +
|
| 129 | + [rustdoc]: https://doc.rust-lang.org/book/documentation.html |
| 130 | +
|
| 131 | + ```python |
| 132 | + package(default_visibility = ["//visibility:public"]) |
| 133 | +
|
| 134 | + load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc") |
| 135 | +
|
| 136 | + rust_library( |
| 137 | + name = "hello_lib", |
| 138 | + srcs = ["src/lib.rs"], |
| 139 | + ) |
| 140 | +
|
| 141 | + rust_doc( |
| 142 | + name = "hello_lib_doc", |
| 143 | + crate = ":hello_lib", |
| 144 | + ) |
| 145 | + ``` |
| 146 | +
|
| 147 | + Running `bazel build //hello_lib:hello_lib_doc` will build a zip file containing \ |
| 148 | + the documentation for the `hello_lib` library crate generated by `rustdoc`. |
| 149 | + """), |
150 | 150 | implementation = _rust_doc_impl,
|
151 | 151 | attrs = {
|
152 | 152 | "crate": attr.label(
|
|
0 commit comments