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 @@ -207,6 +207,9 @@ def _rust_doc_impl(ctx):
207
207
]
208
208
rustdoc_flags .extend (ctx .attr .rustdoc_flags )
209
209
210
+ if ctx .attr .include_features :
211
+ rustdoc_flags .extend (["--cfg=feature=\" {}\" " .format (feature ) for feature in crate_info .crate_features ])
212
+
210
213
action = rustdoc_compile_action (
211
214
ctx = ctx ,
212
215
toolchain = find_toolchain (ctx ),
@@ -321,6 +324,10 @@ rust_doc = rule(
321
324
file of arguments to rustc: `@$(location //package:target)`.
322
325
""" ),
323
326
),
327
+ "include_features" : attr .bool (
328
+ doc = "Include the features defined by `crate_features` when building the doc tests."
329
+ default = True
330
+ ),
324
331
"_dir_zipper" : attr .label (
325
332
doc = "A tool that orchestrates the creation of zip archives for rustdoc outputs." ,
326
333
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