Skip to content

Commit 7b731c2

Browse files
committed
add rustdoc feature support
1 parent 4d14035 commit 7b731c2

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

rust/private/providers.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ CrateInfo = provider(
3636
"rustc_rmeta_output": "File: The rmeta file produced for this crate. It is optional.",
3737
"srcs": "depset[File]: All source Files that are part of the crate.",
3838
"std_dylib": "File: libstd.so file",
39+
"crate_features": "[str]: A list of feature enabled for this crate.",
3940
"type": (
4041
"str: The type of this crate " +
4142
"(see [rustc --crate-type](https://doc.rust-lang.org/rustc/command-line-arguments.html#--crate-type-a-list-of-types-of-crates-for-the-compiler-to-emit))."

rust/private/rust.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ def _rust_library_common(ctx, crate_type):
206206
compile_data = depset(compile_data),
207207
compile_data_targets = depset(ctx.attr.compile_data),
208208
owner = ctx.label,
209+
crate_features = ctx.attr.crate_features,
209210
),
210211
)
211212

rust/private/rustdoc.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ def _rust_doc_impl(ctx):
236236

237237
rustdoc_flags.extend(ctx.attr.rustdoc_flags)
238238

239+
if ctx.attr.include_features:
240+
rustdoc_flags.extend(["--cfg=feature=\"{}\"".format(feature) for feature in crate_info.crate_features])
241+
239242
action = rustdoc_compile_action(
240243
ctx = ctx,
241244
toolchain = find_toolchain(ctx),
@@ -350,6 +353,10 @@ rust_doc = rule(
350353
file of arguments to rustc: `@$(location //package:target)`.
351354
"""),
352355
),
356+
"include_features": attr.bool(
357+
doc = "Include the features defined by `crate_features` when building the doc tests.",
358+
default = True,
359+
),
353360
"_dir_zipper": attr.label(
354361
doc = "A tool that orchestrates the creation of zip archives for rustdoc outputs.",
355362
default = Label("//rust/private/rustdoc/dir_zipper"),

rust/private/rustdoc_test.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def _rust_doc_test_impl(ctx):
129129
compile_data = crate.compile_data,
130130
compile_data_targets = crate.compile_data_targets,
131131
wrapped_crate_type = crate.type,
132+
crate_features = crate.crate_features,
132133
owner = ctx.label,
133134
)
134135

@@ -150,6 +151,9 @@ def _rust_doc_test_impl(ctx):
150151
"--test",
151152
]
152153

154+
if ctx.attr.include_features:
155+
rustdoc_flags.extend(["--cfg=feature=\"{}\"".format(feature) for feature in crate_info.crate_features])
156+
153157
action = rustdoc_compile_action(
154158
ctx = ctx,
155159
toolchain = toolchain,
@@ -228,6 +232,10 @@ rust_doc_test = rule(
228232
default = Label("//rust/private/rustdoc:rustdoc_test_writer"),
229233
executable = True,
230234
),
235+
"include_features": attr.bool(
236+
doc = "Include the features defined by `crate_features` when building the doc tests.",
237+
default = True,
238+
),
231239
},
232240
test = True,
233241
fragments = ["cpp"],

0 commit comments

Comments
 (0)