File tree Expand file tree Collapse file tree 4 files changed +17
-0
lines changed Expand file tree Collapse file tree 4 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ CrateInfo = provider(
36
36
"rustc_rmeta_output" : "File: The rmeta file produced for this crate. It is optional." ,
37
37
"srcs" : "depset[File]: All source Files that are part of the crate." ,
38
38
"std_dylib" : "File: libstd.so file" ,
39
+ "crate_features" : "[str]: A list of feature enabled for this crate." ,
39
40
"type" : (
40
41
"str: The type of this crate " +
41
42
"(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))."
Original file line number Diff line number Diff line change @@ -206,6 +206,7 @@ def _rust_library_common(ctx, crate_type):
206
206
compile_data = depset (compile_data ),
207
207
compile_data_targets = depset (ctx .attr .compile_data ),
208
208
owner = ctx .label ,
209
+ crate_features = ctx .attr .crate_features ,
209
210
),
210
211
)
211
212
Original file line number Diff line number Diff line change @@ -236,6 +236,9 @@ def _rust_doc_impl(ctx):
236
236
237
237
rustdoc_flags .extend (ctx .attr .rustdoc_flags )
238
238
239
+ if ctx .attr .include_features :
240
+ rustdoc_flags .extend (["--cfg=feature=\" {}\" " .format (feature ) for feature in crate_info .crate_features ])
241
+
239
242
action = rustdoc_compile_action (
240
243
ctx = ctx ,
241
244
toolchain = find_toolchain (ctx ),
@@ -350,6 +353,10 @@ rust_doc = rule(
350
353
file of arguments to rustc: `@$(location //package:target)`.
351
354
""" ),
352
355
),
356
+ "include_features" : attr .bool (
357
+ doc = "Include the features defined by `crate_features` when building the doc tests." ,
358
+ default = True ,
359
+ ),
353
360
"_dir_zipper" : attr .label (
354
361
doc = "A tool that orchestrates the creation of zip archives for rustdoc outputs." ,
355
362
default = Label ("//rust/private/rustdoc/dir_zipper" ),
Original file line number Diff line number Diff line change @@ -129,6 +129,7 @@ def _rust_doc_test_impl(ctx):
129
129
compile_data = crate .compile_data ,
130
130
compile_data_targets = crate .compile_data_targets ,
131
131
wrapped_crate_type = crate .type ,
132
+ crate_features = crate .crate_features ,
132
133
owner = ctx .label ,
133
134
)
134
135
@@ -150,6 +151,9 @@ def _rust_doc_test_impl(ctx):
150
151
"--test" ,
151
152
]
152
153
154
+ if ctx .attr .include_features :
155
+ rustdoc_flags .extend (["--cfg=feature=\" {}\" " .format (feature ) for feature in crate_info .crate_features ])
156
+
153
157
action = rustdoc_compile_action (
154
158
ctx = ctx ,
155
159
toolchain = toolchain ,
@@ -228,6 +232,10 @@ rust_doc_test = rule(
228
232
default = Label ("//rust/private/rustdoc:rustdoc_test_writer" ),
229
233
executable = True ,
230
234
),
235
+ "include_features" : attr .bool (
236
+ doc = "Include the features defined by `crate_features` when building the doc tests." ,
237
+ default = True ,
238
+ ),
231
239
},
232
240
test = True ,
233
241
fragments = ["cpp" ],
You can’t perform that action at this time.
0 commit comments