Skip to content

Commit 1cf7673

Browse files
UebelAndreddeville
authored andcommitted
Rustdoc rules now share a code path with Rustc rules for more consistency (bazelbuild#1015)
* Rustdoc rules now share a code path with Rustc rules for more consistency * Regenerate documentation * Addressed PR feedback * Addressed PR feedback
1 parent 727eeb3 commit 1cf7673

File tree

9 files changed

+560
-239
lines changed

9 files changed

+560
-239
lines changed

.bazelci/presubmit.yml

-16
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ default_windows_targets: &default_windows_targets
1515
- "-//test/proto/..."
1616
- "-//tools/rust_analyzer/..."
1717
- "-//test/rustfmt/..."
18-
# rust_doc_test targets are currently broken on windows
19-
# see: https://github.com/bazelbuild/rules_rust/issues/887
20-
- "-//test/chained_direct_deps:mod3_doc_test"
2118
tasks:
2219
ubuntu2004:
2320
build_targets: *default_linux_targets
@@ -33,8 +30,6 @@ tasks:
3330
- "//..."
3431
- "//test/..."
3532
- "-//test/conflicting_deps:conflicting_deps_test"
36-
# rust_doc_test is likely not fully sandboxed
37-
- "-//test/chained_direct_deps:mod3_doc_test"
3833
macos:
3934
build_targets: *default_macos_targets
4035
test_targets: *default_macos_targets
@@ -64,8 +59,6 @@ tasks:
6459
- "..."
6560
- "//test/..."
6661
- "-//test/conflicting_deps:conflicting_deps_test"
67-
# rust_doc_test is likely not fully sandboxed
68-
- "-//test/chained_direct_deps:mod3_doc_test"
6962
build_flags: *aspects_flags
7063
rbe_ubuntu1604_rolling_with_aspects:
7164
name: RBE Rolling Bazel Version With Aspects
@@ -79,8 +72,6 @@ tasks:
7972
- "..."
8073
- "//test/..."
8174
- "-//test/conflicting_deps:conflicting_deps_test"
82-
# rust_doc_test is likely not fully sandboxed
83-
- "-//test/chained_direct_deps:mod3_doc_test"
8475
build_flags: *aspects_flags
8576
soft_fail: yes
8677
bazel: "rolling"
@@ -209,9 +200,6 @@ tasks:
209200
- "//..."
210201
# TODO: This requires an updated `rules_foreign_cc`
211202
- "-//sys/..."
212-
# rust_doc_test is likely not fully sandboxed
213-
- "-//fibonacci:fibonacci_doc_test"
214-
- "-//hello_lib:hello_lib_doc_test"
215203
# See https://github.com/bazelbuild/bazel/issues/9987
216204
- "-//ffi/rust_calling_c:matrix_dylib_test"
217205
# The bindgen rules currently do not work on RBE
@@ -255,10 +243,6 @@ tasks:
255243
- "-//proto/..."
256244
# The wasm rules do not work on windows
257245
- "-//wasm/..."
258-
# rust_doc_test targets are currently broken on windows
259-
# see: https://github.com/bazelbuild/rules_rust/issues/887
260-
- "-//hello_lib:hello_lib_doc_test"
261-
- "-//fibonacci:fibonacci_doc_test"
262246
build_targets: *windows_targets
263247
test_targets: *windows_targets
264248
crate_universe_examples_ubuntu2004:

docs/flatten.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation t
546546
| Name | Description | Type | Mandatory | Default |
547547
| :------------- | :------------- | :------------- | :------------- | :------------- |
548548
| <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 | |
549-
| <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 |
549+
| <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 |
550550
| <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 |
551551

552552

docs/rust_doc.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation t
115115
| Name | Description | Type | Mandatory | Default |
116116
| :------------- | :------------- | :------------- | :------------- | :------------- |
117117
| <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 | |
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 |
118+
| <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 |
119119
| <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 |
120120

121121

rust/private/rustc.bzl

+14-5
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,9 @@ def construct_arguments(
460460
build_flags_files,
461461
emit = ["dep-info", "link"],
462462
force_all_deps_direct = False,
463-
stamp = False):
463+
force_link = False,
464+
stamp = False,
465+
remap_path_prefix = "."):
464466
"""Builds an Args object containing common rustc flags
465467
466468
Args:
@@ -482,8 +484,10 @@ def construct_arguments(
482484
emit (list): Values for the --emit flag to rustc.
483485
force_all_deps_direct (bool, optional): Whether to pass the transitive rlibs with --extern
484486
to the commandline as opposed to -L.
487+
force_link (bool, optional): Whether to add link flags to the command regardless of `emit`.
485488
stamp (bool, optional): Whether or not workspace status stamping is enabled. For more details see
486489
https://docs.bazel.build/versions/main/user-manual.html#flag--stamp
490+
remap_path_prefix (str, optional): A value used to remap `${pwd}` to. If set to a falsey value, no prefix will be set.
487491
488492
Returns:
489493
tuple: A tuple of the following items
@@ -576,9 +580,11 @@ def construct_arguments(
576580
rustc_flags.add("--codegen=debuginfo=" + compilation_mode.debug_info)
577581

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

581-
rustc_flags.add("--emit=" + ",".join(emit_with_paths))
586+
if emit:
587+
rustc_flags.add("--emit=" + ",".join(emit_with_paths))
582588
rustc_flags.add("--color=always")
583589
rustc_flags.add("--target=" + toolchain.target_flag_value)
584590
if hasattr(attr, "crate_features"):
@@ -604,11 +610,14 @@ def construct_arguments(
604610
add_edition_flags(rustc_flags, crate_info)
605611

606612
# Link!
607-
if "link" in emit:
613+
if "link" in emit or force_link:
608614
# Rust's built-in linker can handle linking wasm files. We don't want to attempt to use the cc
609615
# linker since it won't understand.
610616
if toolchain.target_arch != "wasm32":
611-
rpaths = _compute_rpaths(toolchain, output_dir, dep_info)
617+
if output_dir:
618+
rpaths = _compute_rpaths(toolchain, output_dir, dep_info)
619+
else:
620+
rpaths = depset([])
612621
ld, link_args, link_env = get_linker_and_args(ctx, attr, cc_toolchain, feature_configuration, rpaths)
613622
env.update(link_env)
614623
rustc_flags.add("--codegen=linker=" + ld)

0 commit comments

Comments
 (0)