blob: 12f54846ed15afe167cb10d5b045353d347560e4 [file] [log] [blame] [view]
Alex Eagle971ff662021-05-17 09:13:00 -07001<!-- Generated with Stardoc: http://skydoc.bazel.build -->
UebelAndre2ccd2bc2021-04-27 07:39:30 -07002# Rust Doc
3
Damien Martin-Guillereza37e0f42020-06-30 12:05:23 +02004* [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>
UebelAndredd1c73e2021-07-06 14:00:37 -070012rust_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-Guillereza37e0f42020-06-30 12:05:23 +020013</pre>
14
UebelAndre82fdfd92020-10-14 11:54:44 -070015Generates code documentation.
16
17Example:
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
UebelAndre1fe23152021-01-27 02:30:05 -080036 load("@rules_rust//rust:rust.bzl", "rust_library", "rust_doc")
UebelAndre82fdfd92020-10-14 11:54:44 -070037
38 rust_library(
39 name = "hello_lib",
40 srcs = ["src/lib.rs"],
41 )
42
43 rust_doc(
44 name = "hello_lib_doc",
UebelAndredd1c73e2021-07-06 14:00:37 -070045 crate = ":hello_lib",
UebelAndre82fdfd92020-10-14 11:54:44 -070046 )
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-Guillereza37e0f42020-06-30 12:05:23 +020050
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 | |
UebelAndredd1c73e2021-07-06 14:00:37 -070058| <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 |
UebelAndre82fdfd92020-10-14 11:54:44 -070060| <a id="rust_doc-html_after_content"></a>html_after_content | File to add in <code>&lt;body&gt;</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>&lt;body&gt;</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>&lt;head&gt;</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>&lt;link&gt;</code> in a rendered Markdown file. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
Damien Martin-Guillereza37e0f42020-06-30 12:05:23 +020064
65
66<a id="#rust_doc_test"></a>
67
68## rust_doc_test
69
70<pre>
UebelAndredd1c73e2021-07-06 14:00:37 -070071rust_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-Guillereza37e0f42020-06-30 12:05:23 +020072</pre>
73
Damien Martin-Guillereza37e0f42020-06-30 12:05:23 +020074Runs Rust documentation tests.
75
76Example:
77
78Suppose you have the following directory structure for a Rust library crate:
79
UebelAndre82fdfd92020-10-14 11:54:44 -070080```output
Damien Martin-Guillereza37e0f42020-06-30 12:05:23 +020081[workspace]/
82 WORKSPACE
83 hello_lib/
84 BUILD
85 src/
86 lib.rs
87```
88
UebelAndre82fdfd92020-10-14 11:54:44 -070089To 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-Guillereza37e0f42020-06-30 12:05:23 +020090
91[doc-test]: https://doc.rust-lang.org/book/documentation.html#documentation-as-tests
92
93```python
94package(default_visibility = ["//visibility:public"])
95
UebelAndre1fe23152021-01-27 02:30:05 -080096load("@rules_rust//rust:rust.bzl", "rust_library", "rust_doc_test")
Damien Martin-Guillereza37e0f42020-06-30 12:05:23 +020097
98rust_library(
99 name = "hello_lib",
100 srcs = ["src/lib.rs"],
101)
102
103rust_doc_test(
104 name = "hello_lib_doc_test",
UebelAndredd1c73e2021-07-06 14:00:37 -0700105 crate = ":hello_lib",
Damien Martin-Guillereza37e0f42020-06-30 12:05:23 +0200106)
107```
108
109Running `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 | |
UebelAndredd1c73e2021-07-06 14:00:37 -0700118| <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-Guillereza37e0f42020-06-30 12:05:23 +0200120
121