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**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/concepts/labels#target-names">Name</a> | required | | 58| <a id="rust_doc-crate"></a>crate | The label of the target to generate code documentation for.<br><br>`rust_doc` can generate HTML code documentation for the source files of `rust_library` or `rust_binary` targets. | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 59| <a id="rust_doc-html_after_content"></a>html_after_content | File to add in `<body>`, after content. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 60| <a id="rust_doc-html_before_content"></a>html_before_content | File to add in `<body>`, before content. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 61| <a id="rust_doc-html_in_header"></a>html_in_header | File to add to `<head>`. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 62| <a id="rust_doc-markdown_css"></a>markdown_css | CSS files to include via `<link>` in a rendered Markdown file. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 63| <a id="rust_doc-rustc_flags"></a>rustc_flags | **Deprecated**: use `rustdoc_flags` instead | List of strings | optional | `[]` | 64| <a id="rust_doc-rustdoc_flags"></a>rustdoc_flags | List of flags passed to `rustdoc`.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like `$location`, `$execpath`, and `$rootpath`. This expansion is useful if you wish to pass a generated file of arguments to rustc: `@$(location //package:target)`. | List of strings | optional | `[]` | 65 66 67<a id="rust_doc_test"></a> 68 69## rust_doc_test 70 71<pre> 72rust_doc_test(<a href="#rust_doc_test-name">name</a>, <a href="#rust_doc_test-deps">deps</a>, <a href="#rust_doc_test-crate">crate</a>) 73</pre> 74 75Runs Rust documentation tests. 76 77Example: 78 79Suppose you have the following directory structure for a Rust library crate: 80 81```output 82[workspace]/ 83WORKSPACE 84hello_lib/ 85 BUILD 86 src/ 87 lib.rs 88``` 89 90To 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: 91 92[doc-test]: https://doc.rust-lang.org/book/documentation.html#documentation-as-tests 93 94```python 95package(default_visibility = ["//visibility:public"]) 96 97load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc_test") 98 99rust_library( 100 name = "hello_lib", 101 srcs = ["src/lib.rs"], 102) 103 104rust_doc_test( 105 name = "hello_lib_doc_test", 106 crate = ":hello_lib", 107) 108``` 109 110Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation tests for the `hello_lib` library crate. 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/concepts/labels#target-names">Name</a> | required | | 118| <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 `rust_library` targets or `cc_library` targets if linking a native library. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 119| <a id="rust_doc_test-crate"></a>crate | The label of the target to generate code documentation for. `rust_doc_test` can generate HTML code documentation for the source files of `rust_library` or `rust_binary` targets. | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 120 121 122