Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added crate attribute to rustdoc rules (deprecated dep) #799

Merged
merged 4 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions docs/flatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ rust_clippy(
## rust_doc

<pre>
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>)
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>)
</pre>

Generates code documentation.
Expand Down Expand Up @@ -463,7 +463,7 @@ Example:

rust_doc(
name = "hello_lib_doc",
dep = ":hello_lib",
crate = ":hello_lib",
)
```

Expand All @@ -476,7 +476,8 @@ Example:
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <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 | |
| <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 | |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
Expand All @@ -488,7 +489,7 @@ Example:
## rust_doc_test

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

Runs Rust documentation tests.
Expand Down Expand Up @@ -522,7 +523,7 @@ rust_library(

rust_doc_test(
name = "hello_lib_doc_test",
dep = ":hello_lib",
crate = ":hello_lib",
)
```

Expand All @@ -535,7 +536,8 @@ Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation t
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <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 | |
| <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 | |
| <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 |
| <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 |


<a id="#rust_grpc_library"></a>
Expand Down
14 changes: 8 additions & 6 deletions docs/rust_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
## rust_doc

<pre>
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>)
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>)
</pre>

Generates code documentation.
Expand Down Expand Up @@ -42,7 +42,7 @@ Example:

rust_doc(
name = "hello_lib_doc",
dep = ":hello_lib",
crate = ":hello_lib",
)
```

Expand All @@ -55,7 +55,8 @@ Example:
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <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 | |
| <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 | |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
Expand All @@ -67,7 +68,7 @@ Example:
## rust_doc_test

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

Runs Rust documentation tests.
Expand Down Expand Up @@ -101,7 +102,7 @@ rust_library(

rust_doc_test(
name = "hello_lib_doc_test",
dep = ":hello_lib",
crate = ":hello_lib",
)
```

Expand All @@ -114,6 +115,7 @@ Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation t
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <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 | |
| <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 | |
| <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 |
| <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 |


4 changes: 2 additions & 2 deletions examples/ffi/rust_calling_c/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ rust_test(

rust_doc(
name = "matrix_doc",
dep = ":matrix",
crate = ":matrix",
)

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

rust_doc(
name = "matrix_dylib_doc",
dep = ":matrix_dynamically_linked",
crate = ":matrix_dynamically_linked",
)
4 changes: 2 additions & 2 deletions examples/fibonacci/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ rust_benchmark(

rust_doc(
name = "fibonacci_doc",
dep = ":fibonacci",
crate = ":fibonacci",
)

rust_doc_test(
name = "fibonacci_doc_test",
dep = ":fibonacci",
crate = ":fibonacci",
)
4 changes: 2 additions & 2 deletions examples/hello_lib/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ rust_test(

rust_doc(
name = "hello_lib_doc",
dep = ":hello_lib",
crate = ":hello_lib",
)

rust_doc_test(
name = "hello_lib_doc_test",
dep = ":hello_lib",
crate = ":hello_lib",
)

rust_analyzer(
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ rust_binary(

rust_doc(
name = "hello_world_doc",
dep = ":hello_world",
crate = ":hello_world",
)
4 changes: 2 additions & 2 deletions examples/proc_macro/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ rust_test(

rust_doc(
name = "proc_macro_lib_doc",
dep = ":proc_macro_lib",
crate = ":proc_macro_lib",
)

rust_doc_test(
name = "doc_test",
dep = ":proc_macro_lib",
crate = ":proc_macro_lib",
)
43 changes: 29 additions & 14 deletions rust/private/rustdoc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Example:

rust_doc(
name = "hello_lib_doc",
dep = ":hello_lib",
crate = ":hello_lib",
)
```

Expand All @@ -62,34 +62,41 @@ def _rust_doc_impl(ctx):
Args:
ctx (ctx): The rule's context object
"""
if rust_common.crate_info not in ctx.attr.dep:
fail("Expected rust_library or rust_binary.", "dep")

crate = ctx.attr.dep[rust_common.crate_info]
dep_info = ctx.attr.dep[rust_common.dep_info]
if ctx.attr.crate and ctx.attr.dep:
fail("{} should only use the `crate` attribute. `dep` is deprecated".format(
ctx.label,
))

crate = ctx.attr.crate or ctx.attr.dep
if not crate:
fail("{} is missing the `crate` attribute".format(ctx.label))

crate_info = crate[rust_common.crate_info]
dep_info = crate[rust_common.dep_info]

toolchain = find_toolchain(ctx)

rustdoc_inputs = depset(
[c.output for c in dep_info.transitive_crates.to_list()] +
[toolchain.rust_doc],
transitive = [
crate.srcs,
crate_info.srcs,
toolchain.rustc_lib.files,
toolchain.rust_lib.files,
],
)

output_dir = ctx.actions.declare_directory(ctx.label.name)
args = ctx.actions.args()
args.add(crate.root.path)
args.add("--crate-name", crate.name)
args.add("--crate-type", crate.type)
if crate.type == "proc-macro":
args.add(crate_info.root.path)
args.add("--crate-name", crate_info.name)
args.add("--crate-type", crate_info.type)
if crate_info.type == "proc-macro":
args.add("--extern")
args.add("proc_macro")
args.add("--output", output_dir.path)
add_edition_flags(args, crate)
add_edition_flags(args, crate_info)

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

# This rule does nothing without a single-file output, though the directory should've sufficed.
Expand Down Expand Up @@ -139,14 +149,19 @@ rust_doc = rule(
doc = _rust_doc_doc,
implementation = _rust_doc_impl,
attrs = {
"dep": attr.label(
"crate": attr.label(
doc = (
"The label of the target to generate code documentation for.\n" +
"\n" +
"`rust_doc` can generate HTML code documentation for the source files of " +
"`rust_library` or `rust_binary` targets."
),
mandatory = True,
providers = [rust_common.crate_info],
# TODO: Make this attribute mandatory once `dep` is removed
),
"dep": attr.label(
doc = "__deprecated__: use `crate`",
providers = [rust_common.crate_info],
),
"html_after_content": attr.label(
doc = "File to add in `<body>`, after content.",
Expand Down
Loading