1<!-- Generated with Stardoc: http://skydoc.bazel.build --> 2# Rust Doc 3 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> 12rust_doc(<a href="#rust_doc-name">name</a>, <a href="#rust_doc-crate">crate</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>, 13 <a href="#rust_doc-rustc_flags">rustc_flags</a>, <a href="#rust_doc-rustdoc_flags">rustdoc_flags</a>) 14</pre> 15 16Generates code documentation. 17 18Example: 19Suppose you have the following directory structure for a Rust library crate: 20 21``` 22[workspace]/ 23 WORKSPACE 24 hello_lib/ 25 BUILD 26 src/ 27 lib.rs 28``` 29 30To build [`rustdoc`][rustdoc] documentation for the `hello_lib` crate, define a `rust_doc` rule that depends on the the `hello_lib` `rust_library` target: 31 32[rustdoc]: https://doc.rust-lang.org/book/documentation.html 33 34```python 35package(default_visibility = ["//visibility:public"]) 36 37load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc") 38 39rust_library( 40 name = "hello_lib", 41 srcs = ["src/lib.rs"], 42) 43 44rust_doc( 45 name = "hello_lib_doc", 46 crate = ":hello_lib", 47) 48``` 49 50Running `bazel build //hello_lib:hello_lib_doc` will build a zip file containing the documentation for the `hello_lib` library crate generated by `rustdoc`. 51 52 53**ATTRIBUTES** 54 55 56| Name | Description | Type | Mandatory | Default | 57| :------------- | :------------- | :------------- | :------------- | :------------- | 58| <a id="rust_doc-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 59| <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/concepts/labels">Label</a> | required | | 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/concepts/labels">Label</a> | optional | <code>None</code> | 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/concepts/labels">Label</a> | optional | <code>None</code> | 62| <a id="rust_doc-html_in_header"></a>html_in_header | File to add to <code><head></code>. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> | 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/concepts/labels">List of labels</a> | optional | <code>[]</code> | 64| <a id="rust_doc-rustc_flags"></a>rustc_flags | **Deprecated**: use <code>rustdoc_flags</code> instead | List of strings | optional | <code>[]</code> | 65| <a id="rust_doc-rustdoc_flags"></a>rustdoc_flags | List of flags passed to <code>rustdoc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>. | List of strings | optional | <code>[]</code> | 66 67 68<a id="rust_doc_test"></a> 69 70## rust_doc_test 71 72<pre> 73rust_doc_test(<a href="#rust_doc_test-name">name</a>, <a href="#rust_doc_test-crate">crate</a>, <a href="#rust_doc_test-deps">deps</a>) 74</pre> 75 76Runs Rust documentation tests. 77 78Example: 79 80Suppose you have the following directory structure for a Rust library crate: 81 82```output 83[workspace]/ 84WORKSPACE 85hello_lib/ 86 BUILD 87 src/ 88 lib.rs 89``` 90 91To 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: 92 93[doc-test]: https://doc.rust-lang.org/book/documentation.html#documentation-as-tests 94 95```python 96package(default_visibility = ["//visibility:public"]) 97 98load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc_test") 99 100rust_library( 101 name = "hello_lib", 102 srcs = ["src/lib.rs"], 103) 104 105rust_doc_test( 106 name = "hello_lib_doc_test", 107 crate = ":hello_lib", 108) 109``` 110 111Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation tests for the `hello_lib` library crate. 112 113 114**ATTRIBUTES** 115 116 117| Name | Description | Type | Mandatory | Default | 118| :------------- | :------------- | :------------- | :------------- | :------------- | 119| <a id="rust_doc_test-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 120| <a id="rust_doc_test-crate"></a>crate | The label of the target to generate code documentation for. <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/concepts/labels">Label</a> | required | | 121| <a id="rust_doc_test-deps"></a>deps | List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | <code>[]</code> | 122 123 124