Skip to content

Commit

Permalink
Rustdoc rules now share a code path with Rustc rules for more consist…
Browse files Browse the repository at this point in the history
…ency (#1015)

* Rustdoc rules now share a code path with Rustc rules for more consistency

* Regenerate documentation

* Addressed PR feedback

* Addressed PR feedback
  • Loading branch information
UebelAndre committed Nov 15, 2021
1 parent fd5d10a commit e7b1e5a
Show file tree
Hide file tree
Showing 9 changed files with 560 additions and 239 deletions.
16 changes: 0 additions & 16 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ default_windows_targets: &default_windows_targets
- "-//test/proto/..."
- "-//tools/rust_analyzer/..."
- "-//test/rustfmt/..."
# rust_doc_test targets are currently broken on windows
# see: https://github.com/bazelbuild/rules_rust/issues/887
- "-//test/chained_direct_deps:mod3_doc_test"
tasks:
ubuntu2004:
build_targets: *default_linux_targets
Expand All @@ -33,8 +30,6 @@ tasks:
- "//..."
- "//test/..."
- "-//test/conflicting_deps:conflicting_deps_test"
# rust_doc_test is likely not fully sandboxed
- "-//test/chained_direct_deps:mod3_doc_test"
macos:
build_targets: *default_macos_targets
test_targets: *default_macos_targets
Expand Down Expand Up @@ -64,8 +59,6 @@ tasks:
- "..."
- "//test/..."
- "-//test/conflicting_deps:conflicting_deps_test"
# rust_doc_test is likely not fully sandboxed
- "-//test/chained_direct_deps:mod3_doc_test"
build_flags: *aspects_flags
rbe_ubuntu1604_rolling_with_aspects:
name: RBE Rolling Bazel Version With Aspects
Expand All @@ -79,8 +72,6 @@ tasks:
- "..."
- "//test/..."
- "-//test/conflicting_deps:conflicting_deps_test"
# rust_doc_test is likely not fully sandboxed
- "-//test/chained_direct_deps:mod3_doc_test"
build_flags: *aspects_flags
soft_fail: yes
bazel: "rolling"
Expand Down Expand Up @@ -209,9 +200,6 @@ tasks:
- "//..."
# TODO: This requires an updated `rules_foreign_cc`
- "-//sys/..."
# rust_doc_test is likely not fully sandboxed
- "-//fibonacci:fibonacci_doc_test"
- "-//hello_lib:hello_lib_doc_test"
# See https://github.com/bazelbuild/bazel/issues/9987
- "-//ffi/rust_calling_c:matrix_dylib_test"
# The bindgen rules currently do not work on RBE
Expand Down Expand Up @@ -255,10 +243,6 @@ tasks:
- "-//proto/..."
# The wasm rules do not work on windows
- "-//wasm/..."
# rust_doc_test targets are currently broken on windows
# see: https://github.com/bazelbuild/rules_rust/issues/887
- "-//hello_lib:hello_lib_doc_test"
- "-//fibonacci:fibonacci_doc_test"
build_targets: *windows_targets
test_targets: *windows_targets
crate_universe_examples_ubuntu2004:
Expand Down
2 changes: 1 addition & 1 deletion docs/flatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,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-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-crate"></a>crate | The label of the target to generate code documentation for. <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 |


Expand Down
2 changes: 1 addition & 1 deletion docs/rust_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +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-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-crate"></a>crate | The label of the target to generate code documentation for. <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 |


19 changes: 14 additions & 5 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,9 @@ def construct_arguments(
build_flags_files,
emit = ["dep-info", "link"],
force_all_deps_direct = False,
stamp = False):
force_link = False,
stamp = False,
remap_path_prefix = "."):
"""Builds an Args object containing common rustc flags
Args:
Expand All @@ -482,8 +484,10 @@ def construct_arguments(
emit (list): Values for the --emit flag to rustc.
force_all_deps_direct (bool, optional): Whether to pass the transitive rlibs with --extern
to the commandline as opposed to -L.
force_link (bool, optional): Whether to add link flags to the command regardless of `emit`.
stamp (bool, optional): Whether or not workspace status stamping is enabled. For more details see
https://docs.bazel.build/versions/main/user-manual.html#flag--stamp
remap_path_prefix (str, optional): A value used to remap `${pwd}` to. If set to a falsey value, no prefix will be set.
Returns:
tuple: A tuple of the following items
Expand Down Expand Up @@ -576,9 +580,11 @@ def construct_arguments(
rustc_flags.add("--codegen=debuginfo=" + compilation_mode.debug_info)

# For determinism to help with build distribution and such
rustc_flags.add("--remap-path-prefix=${pwd}=.")
if remap_path_prefix:
rustc_flags.add("--remap-path-prefix=${{pwd}}={}".format(remap_path_prefix))

rustc_flags.add("--emit=" + ",".join(emit_with_paths))
if emit:
rustc_flags.add("--emit=" + ",".join(emit_with_paths))
rustc_flags.add("--color=always")
rustc_flags.add("--target=" + toolchain.target_flag_value)
if hasattr(attr, "crate_features"):
Expand All @@ -604,11 +610,14 @@ def construct_arguments(
add_edition_flags(rustc_flags, crate_info)

# Link!
if "link" in emit:
if "link" in emit or force_link:
# Rust's built-in linker can handle linking wasm files. We don't want to attempt to use the cc
# linker since it won't understand.
if toolchain.target_arch != "wasm32":
rpaths = _compute_rpaths(toolchain, output_dir, dep_info)
if output_dir:
rpaths = _compute_rpaths(toolchain, output_dir, dep_info)
else:
rpaths = depset([])
ld, link_args, link_env = get_linker_and_args(ctx, attr, cc_toolchain, feature_configuration, rpaths)
env.update(link_env)
rustc_flags.add("--codegen=linker=" + ld)
Expand Down
Loading

0 comments on commit e7b1e5a

Please sign in to comment.