Alex Eagle | 971ff66 | 2021-05-17 09:13:00 -0700 | [diff] [blame] | 1 | <!-- Generated with Stardoc: http://skydoc.bazel.build --> |
UebelAndre | 2ccd2bc | 2021-04-27 07:39:30 -0700 | [diff] [blame] | 2 | # Rust Doc |
| 3 | |
Damien Martin-Guillerez | a37e0f4 | 2020-06-30 12:05:23 +0200 | [diff] [blame] | 4 | * [rust_doc](#rust_doc) |
| 5 | * [rust_doc_test](#rust_doc_test) |
| 6 | |
| 7 | <a id="#rust_doc"></a> |
| 8 | |
| 9 | ## rust_doc |
| 10 | |
| 11 | <pre> |
UebelAndre | dd1c73e | 2021-07-06 14:00:37 -0700 | [diff] [blame] | 12 | rust_doc(<a href="#rust_doc-name">name</a>, <a href="#rust_doc-crate">crate</a>, <a href="#rust_doc-dep">dep</a>, <a href="#rust_doc-html_after_content">html_after_content</a>, <a href="#rust_doc-html_before_content">html_before_content</a>, <a href="#rust_doc-html_in_header">html_in_header</a>, <a href="#rust_doc-markdown_css">markdown_css</a>) |
Damien Martin-Guillerez | a37e0f4 | 2020-06-30 12:05:23 +0200 | [diff] [blame] | 13 | </pre> |
| 14 | |
UebelAndre | 82fdfd9 | 2020-10-14 11:54:44 -0700 | [diff] [blame] | 15 | Generates code documentation. |
| 16 | |
| 17 | Example: |
| 18 | Suppose you have the following directory structure for a Rust library crate: |
| 19 | |
| 20 | ``` |
| 21 | [workspace]/ |
| 22 | WORKSPACE |
| 23 | hello_lib/ |
| 24 | BUILD |
| 25 | src/ |
| 26 | lib.rs |
| 27 | ``` |
| 28 | |
| 29 | To build [`rustdoc`][rustdoc] documentation for the `hello_lib` crate, define a `rust_doc` rule that depends on the the `hello_lib` `rust_library` target: |
| 30 | |
| 31 | [rustdoc]: https://doc.rust-lang.org/book/documentation.html |
| 32 | |
| 33 | ```python |
| 34 | package(default_visibility = ["//visibility:public"]) |
| 35 | |
UebelAndre | 1fe2315 | 2021-01-27 02:30:05 -0800 | [diff] [blame] | 36 | load("@rules_rust//rust:rust.bzl", "rust_library", "rust_doc") |
UebelAndre | 82fdfd9 | 2020-10-14 11:54:44 -0700 | [diff] [blame] | 37 | |
| 38 | rust_library( |
| 39 | name = "hello_lib", |
| 40 | srcs = ["src/lib.rs"], |
| 41 | ) |
| 42 | |
| 43 | rust_doc( |
| 44 | name = "hello_lib_doc", |
UebelAndre | dd1c73e | 2021-07-06 14:00:37 -0700 | [diff] [blame] | 45 | crate = ":hello_lib", |
UebelAndre | 82fdfd9 | 2020-10-14 11:54:44 -0700 | [diff] [blame] | 46 | ) |
| 47 | ``` |
| 48 | |
| 49 | Running `bazel build //hello_lib:hello_lib_doc` will build a zip file containing the documentation for the `hello_lib` library crate generated by `rustdoc`. |
Damien Martin-Guillerez | a37e0f4 | 2020-06-30 12:05:23 +0200 | [diff] [blame] | 50 | |
| 51 | |
| 52 | **ATTRIBUTES** |
| 53 | |
| 54 | |
| 55 | | Name | Description | Type | Mandatory | Default | |
| 56 | | :------------- | :------------- | :------------- | :------------- | :------------- | |
| 57 | | <a id="rust_doc-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | | |
UebelAndre | dd1c73e | 2021-07-06 14:00:37 -0700 | [diff] [blame] | 58 | | <a id="rust_doc-crate"></a>crate | The label of the target to generate code documentation for.<br><br><code>rust_doc</code> can generate HTML code documentation for the source files of <code>rust_library</code> or <code>rust_binary</code> targets. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None | |
| 59 | | <a id="rust_doc-dep"></a>dep | __deprecated__: use <code>crate</code> | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None | |
UebelAndre | 82fdfd9 | 2020-10-14 11:54:44 -0700 | [diff] [blame] | 60 | | <a id="rust_doc-html_after_content"></a>html_after_content | File to add in <code><body></code>, after content. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None | |
| 61 | | <a id="rust_doc-html_before_content"></a>html_before_content | File to add in <code><body></code>, before content. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None | |
| 62 | | <a id="rust_doc-html_in_header"></a>html_in_header | File to add to <code><head></code>. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None | |
| 63 | | <a id="rust_doc-markdown_css"></a>markdown_css | CSS files to include via <code><link></code> in a rendered Markdown file. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] | |
Damien Martin-Guillerez | a37e0f4 | 2020-06-30 12:05:23 +0200 | [diff] [blame] | 64 | |
| 65 | |
| 66 | <a id="#rust_doc_test"></a> |
| 67 | |
| 68 | ## rust_doc_test |
| 69 | |
| 70 | <pre> |
UebelAndre | dd1c73e | 2021-07-06 14:00:37 -0700 | [diff] [blame] | 71 | rust_doc_test(<a href="#rust_doc_test-name">name</a>, <a href="#rust_doc_test-crate">crate</a>, <a href="#rust_doc_test-dep">dep</a>) |
Damien Martin-Guillerez | a37e0f4 | 2020-06-30 12:05:23 +0200 | [diff] [blame] | 72 | </pre> |
| 73 | |
Damien Martin-Guillerez | a37e0f4 | 2020-06-30 12:05:23 +0200 | [diff] [blame] | 74 | Runs Rust documentation tests. |
| 75 | |
| 76 | Example: |
| 77 | |
| 78 | Suppose you have the following directory structure for a Rust library crate: |
| 79 | |
UebelAndre | 82fdfd9 | 2020-10-14 11:54:44 -0700 | [diff] [blame] | 80 | ```output |
Damien Martin-Guillerez | a37e0f4 | 2020-06-30 12:05:23 +0200 | [diff] [blame] | 81 | [workspace]/ |
| 82 | WORKSPACE |
| 83 | hello_lib/ |
| 84 | BUILD |
| 85 | src/ |
| 86 | lib.rs |
| 87 | ``` |
| 88 | |
UebelAndre | 82fdfd9 | 2020-10-14 11:54:44 -0700 | [diff] [blame] | 89 | To run [documentation tests][doc-test] for the `hello_lib` crate, define a `rust_doc_test` target that depends on the `hello_lib` `rust_library` target: |
Damien Martin-Guillerez | a37e0f4 | 2020-06-30 12:05:23 +0200 | [diff] [blame] | 90 | |
| 91 | [doc-test]: https://doc.rust-lang.org/book/documentation.html#documentation-as-tests |
| 92 | |
| 93 | ```python |
| 94 | package(default_visibility = ["//visibility:public"]) |
| 95 | |
UebelAndre | 1fe2315 | 2021-01-27 02:30:05 -0800 | [diff] [blame] | 96 | load("@rules_rust//rust:rust.bzl", "rust_library", "rust_doc_test") |
Damien Martin-Guillerez | a37e0f4 | 2020-06-30 12:05:23 +0200 | [diff] [blame] | 97 | |
| 98 | rust_library( |
| 99 | name = "hello_lib", |
| 100 | srcs = ["src/lib.rs"], |
| 101 | ) |
| 102 | |
| 103 | rust_doc_test( |
| 104 | name = "hello_lib_doc_test", |
UebelAndre | dd1c73e | 2021-07-06 14:00:37 -0700 | [diff] [blame] | 105 | crate = ":hello_lib", |
Damien Martin-Guillerez | a37e0f4 | 2020-06-30 12:05:23 +0200 | [diff] [blame] | 106 | ) |
| 107 | ``` |
| 108 | |
| 109 | Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation tests for the `hello_lib` library crate. |
| 110 | |
| 111 | |
| 112 | **ATTRIBUTES** |
| 113 | |
| 114 | |
| 115 | | Name | Description | Type | Mandatory | Default | |
| 116 | | :------------- | :------------- | :------------- | :------------- | :------------- | |
| 117 | | <a id="rust_doc_test-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | | |
UebelAndre | dd1c73e | 2021-07-06 14:00:37 -0700 | [diff] [blame] | 118 | | <a id="rust_doc_test-crate"></a>crate | The label of the target to generate code documentation for.<br><br><code>rust_doc_test</code> can generate HTML code documentation for the source files of <code>rust_library</code> or <code>rust_binary</code> targets. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None | |
| 119 | | <a id="rust_doc_test-dep"></a>dep | __deprecated__: use <code>crate</code> | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None | |
Damien Martin-Guillerez | a37e0f4 | 2020-06-30 12:05:23 +0200 | [diff] [blame] | 120 | |
| 121 | |