Skip to content

Commit dd1c73e

Browse files
authored
Added crate attribute to rustdoc rules (deprecated dep) (#799)
1 parent 6df87d6 commit dd1c73e

File tree

11 files changed

+92
-64
lines changed

11 files changed

+92
-64
lines changed

docs/flatten.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ rust_clippy(
430430
## rust_doc
431431

432432
<pre>
433-
rust_doc(<a href="#rust_doc-name">name</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>)
433+
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>)
434434
</pre>
435435

436436
Generates code documentation.
@@ -463,7 +463,7 @@ Example:
463463

464464
rust_doc(
465465
name = "hello_lib_doc",
466-
dep = ":hello_lib",
466+
crate = ":hello_lib",
467467
)
468468
```
469469

@@ -476,7 +476,8 @@ Example:
476476
| Name | Description | Type | Mandatory | Default |
477477
| :------------- | :------------- | :------------- | :------------- | :------------- |
478478
| <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 | |
479-
| <a id="rust_doc-dep"></a>dep | 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> | required | |
479+
| <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 |
480+
| <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 |
480481
| <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 |
481482
| <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 |
482483
| <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 |
@@ -488,7 +489,7 @@ Example:
488489
## rust_doc_test
489490

490491
<pre>
491-
rust_doc_test(<a href="#rust_doc_test-name">name</a>, <a href="#rust_doc_test-dep">dep</a>)
492+
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>)
492493
</pre>
493494

494495
Runs Rust documentation tests.
@@ -522,7 +523,7 @@ rust_library(
522523

523524
rust_doc_test(
524525
name = "hello_lib_doc_test",
525-
dep = ":hello_lib",
526+
crate = ":hello_lib",
526527
)
527528
```
528529

@@ -535,7 +536,8 @@ Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation t
535536
| Name | Description | Type | Mandatory | Default |
536537
| :------------- | :------------- | :------------- | :------------- | :------------- |
537538
| <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 | |
538-
| <a id="rust_doc_test-dep"></a>dep | The label of the target to run documentation tests for.<br><br><code>rust_doc_test</code> can run documentation tests 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> | required | |
539+
| <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 |
540+
| <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 |
539541

540542

541543
<a id="#rust_grpc_library"></a>

docs/rust_doc.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
## rust_doc
1010

1111
<pre>
12-
rust_doc(<a href="#rust_doc-name">name</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>)
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>)
1313
</pre>
1414

1515
Generates code documentation.
@@ -42,7 +42,7 @@ Example:
4242

4343
rust_doc(
4444
name = "hello_lib_doc",
45-
dep = ":hello_lib",
45+
crate = ":hello_lib",
4646
)
4747
```
4848

@@ -55,7 +55,8 @@ Example:
5555
| Name | Description | Type | Mandatory | Default |
5656
| :------------- | :------------- | :------------- | :------------- | :------------- |
5757
| <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 | |
58-
| <a id="rust_doc-dep"></a>dep | 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> | required | |
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 |
5960
| <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 |
6061
| <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 |
6162
| <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 |
@@ -67,7 +68,7 @@ Example:
6768
## rust_doc_test
6869

6970
<pre>
70-
rust_doc_test(<a href="#rust_doc_test-name">name</a>, <a href="#rust_doc_test-dep">dep</a>)
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>)
7172
</pre>
7273

7374
Runs Rust documentation tests.
@@ -101,7 +102,7 @@ rust_library(
101102

102103
rust_doc_test(
103104
name = "hello_lib_doc_test",
104-
dep = ":hello_lib",
105+
crate = ":hello_lib",
105106
)
106107
```
107108

@@ -114,6 +115,7 @@ Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation t
114115
| Name | Description | Type | Mandatory | Default |
115116
| :------------- | :------------- | :------------- | :------------- | :------------- |
116117
| <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 | |
117-
| <a id="rust_doc_test-dep"></a>dep | The label of the target to run documentation tests for.<br><br><code>rust_doc_test</code> can run documentation tests 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> | required | |
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 |
118120

119121

examples/ffi/rust_calling_c/BUILD.bazel

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ rust_test(
2121

2222
rust_doc(
2323
name = "matrix_doc",
24-
dep = ":matrix",
24+
crate = ":matrix",
2525
)
2626

2727
## Do the same as above, but with a dynamic c library.
@@ -46,5 +46,5 @@ rust_test(
4646

4747
rust_doc(
4848
name = "matrix_dylib_doc",
49-
dep = ":matrix_dynamically_linked",
49+
crate = ":matrix_dynamically_linked",
5050
)

examples/fibonacci/BUILD.bazel

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ rust_benchmark(
2929

3030
rust_doc(
3131
name = "fibonacci_doc",
32-
dep = ":fibonacci",
32+
crate = ":fibonacci",
3333
)
3434

3535
rust_doc_test(
3636
name = "fibonacci_doc_test",
37-
dep = ":fibonacci",
37+
crate = ":fibonacci",
3838
)

examples/hello_lib/BUILD.bazel

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ rust_test(
7979

8080
rust_doc(
8181
name = "hello_lib_doc",
82-
dep = ":hello_lib",
82+
crate = ":hello_lib",
8383
)
8484

8585
rust_doc_test(
8686
name = "hello_lib_doc_test",
87-
dep = ":hello_lib",
87+
crate = ":hello_lib",
8888
)
8989

9090
rust_analyzer(

examples/hello_world/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ rust_binary(
1414

1515
rust_doc(
1616
name = "hello_world_doc",
17-
dep = ":hello_world",
17+
crate = ":hello_world",
1818
)

examples/proc_macro/BUILD.bazel

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ rust_test(
3838

3939
rust_doc(
4040
name = "proc_macro_lib_doc",
41-
dep = ":proc_macro_lib",
41+
crate = ":proc_macro_lib",
4242
)
4343

4444
rust_doc_test(
4545
name = "doc_test",
46-
dep = ":proc_macro_lib",
46+
crate = ":proc_macro_lib",
4747
)

rust/private/rustdoc.bzl

+29-14
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Example:
4848
4949
rust_doc(
5050
name = "hello_lib_doc",
51-
dep = ":hello_lib",
51+
crate = ":hello_lib",
5252
)
5353
```
5454
@@ -62,34 +62,41 @@ def _rust_doc_impl(ctx):
6262
Args:
6363
ctx (ctx): The rule's context object
6464
"""
65-
if rust_common.crate_info not in ctx.attr.dep:
66-
fail("Expected rust_library or rust_binary.", "dep")
6765

68-
crate = ctx.attr.dep[rust_common.crate_info]
69-
dep_info = ctx.attr.dep[rust_common.dep_info]
66+
if ctx.attr.crate and ctx.attr.dep:
67+
fail("{} should only use the `crate` attribute. `dep` is deprecated".format(
68+
ctx.label,
69+
))
70+
71+
crate = ctx.attr.crate or ctx.attr.dep
72+
if not crate:
73+
fail("{} is missing the `crate` attribute".format(ctx.label))
74+
75+
crate_info = crate[rust_common.crate_info]
76+
dep_info = crate[rust_common.dep_info]
7077

7178
toolchain = find_toolchain(ctx)
7279

7380
rustdoc_inputs = depset(
7481
[c.output for c in dep_info.transitive_crates.to_list()] +
7582
[toolchain.rust_doc],
7683
transitive = [
77-
crate.srcs,
84+
crate_info.srcs,
7885
toolchain.rustc_lib.files,
7986
toolchain.rust_lib.files,
8087
],
8188
)
8289

8390
output_dir = ctx.actions.declare_directory(ctx.label.name)
8491
args = ctx.actions.args()
85-
args.add(crate.root.path)
86-
args.add("--crate-name", crate.name)
87-
args.add("--crate-type", crate.type)
88-
if crate.type == "proc-macro":
92+
args.add(crate_info.root.path)
93+
args.add("--crate-name", crate_info.name)
94+
args.add("--crate-type", crate_info.type)
95+
if crate_info.type == "proc-macro":
8996
args.add("--extern")
9097
args.add("proc_macro")
9198
args.add("--output", output_dir.path)
92-
add_edition_flags(args, crate)
99+
add_edition_flags(args, crate_info)
93100

94101
# nb. rustdoc can't do anything with native link flags; we must omit them.
95102
add_crate_link_flags(args, dep_info)
@@ -108,7 +115,10 @@ def _rust_doc_impl(ctx):
108115
outputs = [output_dir],
109116
arguments = [args],
110117
mnemonic = "Rustdoc",
111-
progress_message = "Generating rustdoc for {} ({} files)".format(crate.name, len(crate.srcs.to_list())),
118+
progress_message = "Generating rustdoc for {} ({} files)".format(
119+
crate_info.name,
120+
len(crate_info.srcs.to_list()),
121+
),
112122
)
113123

114124
# This rule does nothing without a single-file output, though the directory should've sufficed.
@@ -139,14 +149,19 @@ rust_doc = rule(
139149
doc = _rust_doc_doc,
140150
implementation = _rust_doc_impl,
141151
attrs = {
142-
"dep": attr.label(
152+
"crate": attr.label(
143153
doc = (
144154
"The label of the target to generate code documentation for.\n" +
145155
"\n" +
146156
"`rust_doc` can generate HTML code documentation for the source files of " +
147157
"`rust_library` or `rust_binary` targets."
148158
),
149-
mandatory = True,
159+
providers = [rust_common.crate_info],
160+
# TODO: Make this attribute mandatory once `dep` is removed
161+
),
162+
"dep": attr.label(
163+
doc = "__deprecated__: use `crate`",
164+
providers = [rust_common.crate_info],
150165
),
151166
"html_after_content": attr.label(
152167
doc = "File to add in `<body>`, after content.",

0 commit comments

Comments
 (0)