Skip to content

Commit 0eb65e6

Browse files
EtomicBombCQ Bot
authored andcommitted
[rust][build] flags from rust-lang/rfcs#3662
* Now that rust-lang/rfc#3662 the implementation PR have landed, we can enable this once we roll the toolchain * Adds mergeable cross-crate info to fx rustdoc-link * Use the `--parts-out-dir`, `--include-parts-dir`, and `--merge` flags from the rfc in rust_auxiliary.gni and rustdoc-link.py * Tested change with rust toolchain defined in rust-lang/rust@b529e27 Bug: 360942359 Fixed: 360942359 Change-Id: Iea9b0243f96394c87c66290c58ced55d791b5495 Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1100827 Commit-Queue: Ethan Williams <[email protected]> Reviewed-by: Julia Ryan <[email protected]> Reviewed-by: Jay Zhuang <[email protected]>
1 parent ae6942f commit 0eb65e6

File tree

5 files changed

+47
-12
lines changed

5 files changed

+47
-12
lines changed

BUILD.gn

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,57 +1790,67 @@ group("rbe_config.metadata") {
17901790
# Type: list(scope)
17911791
#
17921792
# actual_label
1793-
# - Required: Label for target that invokes rustc
1793+
# - Description: label for target that invokes rustc
17941794
# - Type: label_with_toolchain
17951795
# - Example: //src/lib/fuchsia-async:fuchsia-async.actual(//build/toolchain:host_x64)
17961796
# disable_clippy
1797-
# - Required: whether the clippy target is put into the build graph
1797+
# - Description: whether the clippy target is put into the build graph
17981798
# - Type: boolean
17991799
# disable_rustdoc
1800-
# - Required: whether the rustdoc target is put into the build graph
1800+
# - Whether the rustdoc target is put into the build graph
18011801
# - Type: boolean
18021802
# clippy_label(optional)
1803-
# - Required: Label for target that invokes clippy
1803+
# - Description: Label for target that invokes clippy
18041804
# - Present: this field is only guaranteed for !disable_clippy
18051805
# - Type: label_with_toolchain
18061806
# - Example: //src/lib/fuchsia-async:fuchsia-async.actual.clippy(//build/toolchain:host_x64)
18071807
# clippy_output(optional)
1808-
# - Required: file that contains the clippy output
1808+
# - Description: file that contains the clippy output
18091809
# - Present: this field is only guaranteed for !disable_clippy
18101810
# - Type: path relative to $root_build_dir
18111811
# - Example: host_x64/gen/src/lib/fuchsia-async/fuchsia-async.actual.clippy
18121812
# original_label
1813-
# - Required: The original target name before a possible .actual suffix is added.
1813+
# - Description: The original target name before a possible .actual suffix is added.
18141814
# May refer to a group.
18151815
# - Type: label_with_toolchain
18161816
# - Example: //src/lib/fuchsia-async:fuchsia-async(//build/toolchain:host_x64)
18171817
# rustdoc_label(optional)
1818-
# - Required: The label of the rustdoc target
1818+
# - Description: The label of the rustdoc target
18191819
# - Present: this field is only guaranteed for !disable_rustdoc
18201820
# - Type: label_with_toolchain
18211821
# - Example: //src/lib/fuchsia-async:fuchsia-async.actual.rustdoc(//build/toolchain:host_x64)
18221822
# rustdoc_out_dir(optional)
1823-
# - Required: directory in which rustdoc output is written
1823+
# - Description: directory in which rustdoc output is written
18241824
# - Present: this field is only guaranteed for !disable_rustdoc
18251825
# - Type: path relative to $root_build_dir
18261826
# - Example: host_x64/gen/src/lib/fuchsia-async/fuchsia-async.aux.doc
1827+
# rustdoc_parts_dir(optional)
1828+
# - Description: directory in which rustdoc cross-crate linking information is written
1829+
# - Present: this field is only guaranteed for !disable_rustdoc
1830+
# - Type: path relative to $root_build_dir
1831+
# - Example: host_x64/gen/src/lib/fuchsia-async/fuchsia-async.aux.doc.parts
1832+
# target_is_fuchsia(optional)
1833+
# - Description: whether this is a Fuchsia target (as opposed to a host target)
1834+
# - Present: always
1835+
# - Type: boolean
1836+
# - Example: true
18271837
# rustdoc_stamp_output(optional)
1828-
# - Required: this file's mtime is updated when rustdoc is successfully built for a target
1838+
# - Description: this file's mtime is updated when rustdoc is successfully built for a target
18291839
# - Present: this field is only guaranteed for !disable_rustdoc
18301840
# - Type: path relative to $root_build_dir
18311841
# - Example: host_x64/gen/src/lib/fuchsia-async/fuchsia-async.aux.touch
18321842
# extern(optional)
1833-
# - Required: command line argument needed to pass to rustc to depend on this target.
1843+
# - Description: command line argument needed to pass to rustc to depend on this target.
18341844
# - Present: this field is not present on bin targets
18351845
# - Type: command line argument
18361846
# - Example: --extern=fuchsia_async=host_x64/obj/src/lib/fuchsia-async/fuchsia-async.actual/libfuchsia_async.rlib
18371847
# searchdir(optional)
1838-
# - Required: command line argument needed to pass to rustc to transitively depend on this target.
1848+
# - Description: command line argument needed to pass to rustc to transitively depend on this target.
18391849
# - Present: this field is not present on bin targets
18401850
# - Type: command line argument
18411851
# - Example: -Ldependency=host_x64/obj/src/lib/fuchsia-async/fuchsia-async.actual
18421852
# src(optional)
1843-
# - Required: list of rust source code files, relative to $root_build_dir
1853+
# - Description: list of rust source code files, relative to $root_build_dir
18441854
# - Present: this field is only guaranteed for !disable_clippy
18451855
# - Type: list(str)
18461856
# - Example: [ "../../src/lib/fuchsia-async/src/lib.rs", ... ]

build/rust/rust_auxiliary.gni

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ template("rust_auxiliary") {
155155
"clippy targets should have an original name")
156156
_original_target_name = target_name
157157
}
158+
if (defined(invoker.rustdoc_parts_dir)) {
159+
_rustdoc_parts_dir = invoker.rustdoc_parts_dir
160+
} else {
161+
_rustdoc_parts_dir = "$target_gen_dir/${target_name}.doc.parts"
162+
}
158163

159164
_define_rustdoc =
160165
!(defined(invoker.disable_rustdoc) && invoker.disable_rustdoc) &&
@@ -423,6 +428,13 @@ template("rust_auxiliary") {
423428
# rustdoc will receive remaining arguments
424429
rebase_path(crate_root, root_build_dir),
425430
"-Zunstable-options",
431+
432+
# Do not attempt to append to existing files in the documentation destination.
433+
"--merge=none",
434+
435+
# Output information to be consumed by `fx rustdoc-link`.
436+
"--parts-out-dir",
437+
rebase_path(_rustdoc_parts_dir, root_build_dir),
426438
"--out-dir",
427439
rebase_path(_rustdoc_out_dir, root_build_dir),
428440
"@" + rebase_path(_transdeps_output, root_build_dir),
@@ -454,6 +466,7 @@ template("rust_auxiliary") {
454466
not_needed([
455467
"_crate_name",
456468
"_invoker_deps",
469+
"_rustdoc_parts_dir",
457470
"rustflags",
458471
"aliased_deps",
459472
])
@@ -528,6 +541,8 @@ template("rust_auxiliary") {
528541
extern = "--extern=${_crate_name}=${_rlib_path}"
529542
searchdir = "-Ldependency=${_searchdir_path}"
530543
}
544+
rustdoc_parts_dir = rebase_path(_rustdoc_parts_dir, root_build_dir)
545+
target_is_fuchsia = is_fuchsia
531546
target = current_target_tuple
532547
clippy_output = rebase_path(_clippy_output, root_build_dir)
533548
src = []

build/rust/rustc_artifact.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ template("rustc_artifact") {
206206
"sources",
207207
"testonly",
208208
"visibility",
209+
"rustdoc_parts_dir",
209210
"zip_rustdoc_to",
210211
])
211212

build/rust/rustc_library.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ template("rustc_library") {
258258
"configs",
259259
"data_deps",
260260
"define_rustdoc_test_override",
261+
"rustdoc_parts_dir",
261262
"disable_clippy",
262263
"disable_rbe",
263264
"edition",

tools/devshell/contrib/lib/rust/rustdoc-link.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Metadata:
3838
rustdoc_label: str
3939
target: str
4040
rustdoc_out_dir: Path
41+
rustdoc_parts_dir: Path
4142
touch: Path
4243
searchdir: str
4344
extern: str # looks like --extern=CRATE_NAME=PATH
@@ -64,6 +65,7 @@ def parse(m: dict[str, Any], args: Namespace) -> Optional["Metadata"]:
6465
target=m["target"],
6566
touch=Path(f"{rustdoc_out_dir}.touch"),
6667
rustdoc_out_dir=rustdoc_out_dir,
68+
rustdoc_parts_dir=Path(args.build_dir, m["rustdoc_parts_dir"]),
6769
extern=m["extern"],
6870
searchdir=m["searchdir"],
6971
disable_rustdoc=m["disable_rustdoc"],
@@ -201,13 +203,17 @@ def rustdoc_link(meta: list[Metadata], args: Namespace):
201203
if "fuchsia" in target
202204
else args.destination / "host"
203205
)
206+
204207
extern = set(m.extern_arg_as_rmeta for m in meta)
205208

206209
if not args.quiet:
207210
print("running rustdoc to document index for", target, file=stderr)
208211
with TemporaryDirectory() as tmp:
209212
crate_root = Path(tmp, "lib.rs")
210213
crate_names = [f"extern crate {m.crate_name};" for m in meta]
214+
rustdoc_parts_dir = [
215+
f"--include-parts-dir={m.rustdoc_parts_dir}" for m in meta
216+
]
211217
crate_root.write_text("\n".join(crate_names))
212218
argfile = Path(tmp, "argfile")
213219
flags = [
@@ -220,6 +226,8 @@ def rustdoc_link(meta: list[Metadata], args: Namespace):
220226
f"--target={target}",
221227
"-Zunstable-options",
222228
f"--out-dir={dst}",
229+
"--merge=finalize",
230+
*rustdoc_parts_dir,
223231
"--enable-index-page",
224232
*extra_rustdoc_args,
225233
]

0 commit comments

Comments
 (0)