Skip to content

Commit

Permalink
Document private items by default for binaries
Browse files Browse the repository at this point in the history
Summary: This matches Cargo's behavior. See [rust-lang/cargo#7593](rust-lang/cargo#7593). Documentation for `rust_binary` targets is otherwise useless, since usually there is nothing in them declared `pub`.

Reviewed By: zertosh

Differential Revision: D36563393

fbshipit-source-id: 9ee64fb3f77caf7376a93eabfb309dc0adc1b45d
  • Loading branch information
David Tolnay authored and facebook-github-bot committed May 20, 2022
1 parent 35c6533 commit bbe61f9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
6 changes: 5 additions & 1 deletion prelude/rust/build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def generate_rustdoc(
# link style doesn't matter, but caller should pass in build params
# with static-pic (to get best cache hits for deps)
params: BuildParams.type,
default_roots: [str.type]) -> "artifact":
default_roots: [str.type],
document_private_items: bool.type) -> "artifact":
toolchain_info = ctx_toolchain_info(ctx)

common_args = _compute_common_args(
Expand Down Expand Up @@ -122,6 +123,9 @@ def generate_rustdoc(
common_args.args,
)

if document_private_items:
rustdoc_cmd.add("--document-private-items")

url_prefix = toolchain_info.extern_html_root_url_prefix
for rust_dependency in resolve_deps(ctx):
dep = rust_dependency.dep
Expand Down
9 changes: 8 additions & 1 deletion prelude/rust/rust_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ def _rust_binary_common(
)

extra_targets += [
("doc", generate_rustdoc(ctx, compile_ctx, crate, style_param[LinkStyle("static_pic")], default_roots)),
("doc", generate_rustdoc(
ctx = ctx,
compile_ctx = compile_ctx,
crate = crate,
params = style_param[LinkStyle("static_pic")],
default_roots = default_roots,
document_private_items = True,
)),
("expand", expand.outputs[Emit("expand")]),
]
sub_targets = {k: [DefaultInfo(default_outputs = [v])] for k, v in extra_targets}
Expand Down
11 changes: 6 additions & 5 deletions prelude/rust/rust_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,12 @@ def rust_library_impl(ctx: "context") -> ["provider"]:
fail("Unhandled lang {}".format(lang))

rustdoc = generate_rustdoc(
ctx,
compile_ctx,
crate,
lang_style_param[(LinkageLang("rust"), LinkStyle("static_pic"))],
["lib.rs"],
ctx = ctx,
compile_ctx = compile_ctx,
crate = crate,
params = lang_style_param[(LinkageLang("rust"), LinkStyle("static_pic"))],
default_roots = ["lib.rs"],
document_private_items = False,
)

expand = rust_compile(
Expand Down

0 comments on commit bbe61f9

Please sign in to comment.