Skip to content

Commit 55ac582

Browse files
committed
rustdoc: make html_in_header work
Signed-off-by: Greg Bowyer <[email protected]>
1 parent 1832faa commit 55ac582

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

rust/private/rustdoc.bzl

+31-2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ def rustdoc_compile_action(
8484
rustdoc_flags = rustdoc_flags + lints_info.rustdoc_lint_flags
8585
lint_files = lint_files + lints_info.rustdoc_lint_files
8686

87+
# Collect HTML customization files
88+
html_input_files = []
89+
if hasattr(ctx.file, "html_in_header") and ctx.file.html_in_header:
90+
html_input_files.append(ctx.file.html_in_header)
91+
if hasattr(ctx.file, "html_before_content") and ctx.file.html_before_content:
92+
html_input_files.append(ctx.file.html_before_content)
93+
if hasattr(ctx.file, "html_after_content") and ctx.file.html_after_content:
94+
html_input_files.append(ctx.file.html_after_content)
95+
if hasattr(ctx.files, "markdown_css"):
96+
html_input_files.extend(ctx.files.markdown_css)
97+
8798
cc_toolchain, feature_configuration = find_cc_toolchain(ctx)
8899

89100
dep_info, build_info, _ = collect_deps(
@@ -149,9 +160,12 @@ def rustdoc_compile_action(
149160
if "OUT_DIR" in env:
150161
env.update({"OUT_DIR": "${{pwd}}/{}".format(build_info.out_dir.short_path)})
151162

163+
# Create the combined inputs including HTML customization files
164+
all_inputs = depset([crate_info.output], transitive = [compile_inputs, depset(html_input_files)])
165+
152166
return struct(
153167
executable = ctx.executable._process_wrapper,
154-
inputs = depset([crate_info.output], transitive = [compile_inputs]),
168+
inputs = all_inputs,
155169
env = env,
156170
arguments = args.all,
157171
tools = [toolchain.rust_doc],
@@ -205,6 +219,21 @@ def _rust_doc_impl(ctx):
205219
"--extern",
206220
"{}={}".format(crate_info.name, crate_info.output.path),
207221
]
222+
223+
# Add HTML customization flags if attributes are provided
224+
if ctx.attr.html_in_header:
225+
rustdoc_flags.extend(["--html-in-header", ctx.file.html_in_header.path])
226+
227+
if ctx.attr.html_before_content:
228+
rustdoc_flags.extend(["--html-before-content", ctx.file.html_before_content.path])
229+
230+
if ctx.attr.html_after_content:
231+
rustdoc_flags.extend(["--html-after-content", ctx.file.html_after_content.path])
232+
233+
# Add markdown CSS files if provided
234+
for css_file in ctx.files.markdown_css:
235+
rustdoc_flags.extend(["--markdown-css", css_file.path])
236+
208237
rustdoc_flags.extend(ctx.attr.rustdoc_flags)
209238

210239
action = rustdoc_compile_action(
@@ -239,7 +268,7 @@ def _rust_doc_impl(ctx):
239268
rustdoc_zip = depset([ctx.outputs.rust_doc_zip]),
240269
),
241270
]
242-
271+
243272
rust_doc = rule(
244273
doc = dedent("""\
245274
Generates code documentation.

0 commit comments

Comments
 (0)