@@ -19,7 +19,7 @@ use failure::err_msg;
19
19
/// all-features = true
20
20
/// no-default-features = true
21
21
/// default-target = "x86_64-unknown-linux-gnu"
22
- /// extra- targets = [ "x86_64-apple-darwin", "x86_64-pc-windows-msvc" ]
22
+ /// targets = [ "x86_64-apple-darwin", "x86_64-pc-windows-msvc" ]
23
23
/// rustc-args = [ "--example-rustc-arg" ]
24
24
/// rustdoc-args = [ "--example-rustdoc-arg" ]
25
25
/// ```
@@ -39,16 +39,22 @@ pub struct Metadata {
39
39
/// Set `no-default-fatures` to `false` if you want to build only certain features.
40
40
pub no_default_features : bool ,
41
41
42
- /// Docs.rs is running on `x86_64-unknown-linux-gnu` target system and default documentation
43
- /// is always built on this target. You can change default target by setting this.
42
+ /// docs.rs runs on `x86_64-unknown-linux-gnu`, which is the default target for documentation by default.
43
+ ///
44
+ /// You can change the default target by setting this.
45
+ ///
46
+ /// If `default_target` is unset and `targets` is non-empty,
47
+ /// the first element of `targets` will be used as the `default_target`.
44
48
pub default_target : Option < String > ,
45
49
46
50
/// If you want a crate to build only for specific targets,
47
- /// set `extra- targets` to the list of targets to build, in addition to `default-target`.
51
+ /// set `targets` to the list of targets to build, in addition to `default-target`.
48
52
///
49
- /// If you do not set `extra_targets`, all of the tier 1 supported targets will be built.
50
- /// If you set `extra_targets` to an empty array, only the default target will be built.
51
- pub extra_targets : Option < Vec < String > > ,
53
+ /// If you do not set `targets`, all of the tier 1 supported targets will be built.
54
+ /// If you set `targets` to an empty array, only the default target will be built.
55
+ /// If you set `targets` to a non-empty array but do not set `default_target`,
56
+ /// the first element will be treated as the default.
57
+ pub targets : Option < Vec < String > > ,
52
58
53
59
/// List of command line arguments for `rustc`.
54
60
pub rustc_args : Option < Vec < String > > ,
@@ -94,7 +100,7 @@ impl Metadata {
94
100
default_target : None ,
95
101
rustc_args : None ,
96
102
rustdoc_args : None ,
97
- extra_targets : None ,
103
+ targets : None ,
98
104
}
99
105
}
100
106
@@ -119,7 +125,7 @@ impl Metadata {
119
125
. and_then ( |v| v. as_bool ( ) ) . unwrap_or ( metadata. all_features ) ;
120
126
metadata. default_target = table. get ( "default-target" )
121
127
. and_then ( |v| v. as_str ( ) ) . map ( |v| v. to_owned ( ) ) ;
122
- metadata. extra_targets = table. get ( "extra-targets" ) . and_then ( |f| f. as_array ( ) )
128
+ metadata. targets = table. get ( "extra-targets" ) . and_then ( |f| f. as_array ( ) )
123
129
. and_then ( |f| f. iter ( ) . map ( |v| v. as_str ( ) . map ( |v| v. to_owned ( ) ) ) . collect ( ) ) ;
124
130
metadata. rustc_args = table. get ( "rustc-args" ) . and_then ( |f| f. as_array ( ) )
125
131
. and_then ( |f| f. iter ( ) . map ( |v| v. as_str ( ) . map ( |v| v. to_owned ( ) ) ) . collect ( ) ) ;
@@ -136,7 +142,7 @@ impl Metadata {
136
142
// Ideally this would use Iterator instead of Vec so I could collect to a `HashSet`,
137
143
// but I had trouble with `chain()` ¯\_(ツ)_/¯
138
144
let mut all_targets: Vec < _ > = self . default_target . as_deref ( ) . into_iter ( ) . collect ( ) ;
139
- match & self . extra_targets {
145
+ match & self . targets {
140
146
Some ( targets) => all_targets. extend ( targets. iter ( ) . map ( |s| s. as_str ( ) ) ) ,
141
147
None if all_targets. is_empty ( ) => {
142
148
// Make sure HOST_TARGET is first
@@ -146,7 +152,7 @@ impl Metadata {
146
152
None => all_targets. extend ( TARGETS . iter ( ) . copied ( ) ) ,
147
153
} ;
148
154
149
- // default_target unset and extra_targets set to `[]`
155
+ // default_target unset and targets set to `[]`
150
156
let landing_page = if all_targets. is_empty ( ) {
151
157
HOST_TARGET
152
158
} else {
@@ -205,10 +211,10 @@ mod test {
205
211
206
212
assert_eq ! ( metadata. default_target. unwrap( ) , "x86_64-unknown-linux-gnu" . to_owned( ) ) ;
207
213
208
- let extra_targets = metadata. extra_targets . expect ( "should have explicit extra target" ) ;
209
- assert_eq ! ( extra_targets . len( ) , 2 ) ;
210
- assert_eq ! ( extra_targets [ 0 ] , "x86_64-apple-darwin" ) ;
211
- assert_eq ! ( extra_targets [ 1 ] , "x86_64-pc-windows-msvc" ) ;
214
+ let targets = metadata. targets . expect ( "should have explicit extra target" ) ;
215
+ assert_eq ! ( targets . len( ) , 2 ) ;
216
+ assert_eq ! ( targets [ 0 ] , "x86_64-apple-darwin" ) ;
217
+ assert_eq ! ( targets [ 1 ] , "x86_64-pc-windows-msvc" ) ;
212
218
213
219
let rustc_args = metadata. rustc_args . unwrap ( ) ;
214
220
assert_eq ! ( rustc_args. len( ) , 1 ) ;
@@ -220,8 +226,8 @@ mod test {
220
226
}
221
227
222
228
#[ test]
223
- fn test_no_extra_targets ( ) {
224
- // metadata section but no extra_targets
229
+ fn test_no_targets ( ) {
230
+ // metadata section but no targets
225
231
let manifest = r#"
226
232
[package]
227
233
name = "test"
@@ -230,24 +236,24 @@ mod test {
230
236
features = [ "feature1", "feature2" ]
231
237
"# ;
232
238
let metadata = Metadata :: from_str ( manifest) ;
233
- assert ! ( metadata. extra_targets . is_none( ) ) ;
239
+ assert ! ( metadata. targets . is_none( ) ) ;
234
240
235
241
// no package.metadata.docs.rs section
236
242
let metadata = Metadata :: from_str ( r#"
237
243
[package]
238
244
name = "test"
239
245
"# ) ;
240
- assert ! ( metadata. extra_targets . is_none( ) ) ;
246
+ assert ! ( metadata. targets . is_none( ) ) ;
241
247
242
248
// extra targets explicitly set to empty array
243
249
let metadata = Metadata :: from_str ( r#"
244
250
[package.metadata.docs.rs]
245
251
extra-targets = []
246
252
"# ) ;
247
- assert ! ( metadata. extra_targets . unwrap( ) . is_empty( ) ) ;
253
+ assert ! ( metadata. targets . unwrap( ) . is_empty( ) ) ;
248
254
}
249
255
#[ test]
250
- fn test_select_extra_targets ( ) {
256
+ fn test_select_targets ( ) {
251
257
use crate :: docbuilder:: rustwide_builder:: { HOST_TARGET , TARGETS } ;
252
258
253
259
let mut metadata = Metadata :: default ( ) ;
@@ -267,26 +273,26 @@ mod test {
267
273
}
268
274
269
275
// unchanged default_target, extra targets specified to be empty
270
- metadata. extra_targets = Some ( Vec :: new ( ) ) ;
276
+ metadata. targets = Some ( Vec :: new ( ) ) ;
271
277
let ( default, others) = metadata. targets ( ) ;
272
278
assert_eq ! ( default , HOST_TARGET ) ;
273
279
assert ! ( others. is_empty( ) ) ;
274
280
275
281
// unchanged default_target, extra targets non-empty
276
- metadata. extra_targets = Some ( vec ! [ "i686-pc-windows-msvc" . into( ) , "i686-apple-darwin" . into( ) ] ) ;
282
+ metadata. targets = Some ( vec ! [ "i686-pc-windows-msvc" . into( ) , "i686-apple-darwin" . into( ) ] ) ;
277
283
let ( default, others) = metadata. targets ( ) ;
278
284
assert_eq ! ( default , "i686-pc-windows-msvc" ) ;
279
285
assert_eq ! ( others. len( ) , 1 ) ;
280
286
assert ! ( others. contains( & "i686-apple-darwin" ) ) ;
281
287
282
288
// make sure that default_target is not built twice
283
- metadata. extra_targets = Some ( vec ! [ HOST_TARGET . into( ) ] ) ;
289
+ metadata. targets = Some ( vec ! [ HOST_TARGET . into( ) ] ) ;
284
290
let ( default, others) = metadata. targets ( ) ;
285
291
assert_eq ! ( default , HOST_TARGET ) ;
286
292
assert ! ( others. is_empty( ) ) ;
287
293
288
294
// make sure that duplicates are removed
289
- metadata. extra_targets = Some ( vec ! [ "i686-pc-windows-msvc" . into( ) , "i686-pc-windows-msvc" . into( ) ] ) ;
295
+ metadata. targets = Some ( vec ! [ "i686-pc-windows-msvc" . into( ) , "i686-pc-windows-msvc" . into( ) ] ) ;
290
296
let ( default, others) = metadata. targets ( ) ;
291
297
assert_eq ! ( default , "i686-pc-windows-msvc" ) ;
292
298
assert ! ( others. is_empty( ) ) ;
@@ -299,13 +305,13 @@ mod test {
299
305
assert ! ( others. contains( & "i686-pc-windows-msvc" ) ) ;
300
306
301
307
// make sure that `default_target` takes priority over `HOST_TARGET`
302
- metadata. extra_targets = Some ( vec ! [ ] ) ;
308
+ metadata. targets = Some ( vec ! [ ] ) ;
303
309
let ( default, others) = metadata. targets ( ) ;
304
310
assert_eq ! ( default , "i686-apple-darwin" ) ;
305
311
assert ! ( others. is_empty( ) ) ;
306
312
307
- // and if `extra_targets ` is unset, it should still be set to `TARGETS`
308
- metadata. extra_targets = None ;
313
+ // and if `targets ` is unset, it should still be set to `TARGETS`
314
+ metadata. targets = None ;
309
315
let ( default, others) = metadata. targets ( ) ;
310
316
assert_eq ! ( default , "i686-apple-darwin" ) ;
311
317
let tier_one_targets_no_default: Vec < _ > = TARGETS . iter ( ) . filter ( |& & t| t != "i686-apple-darwin" ) . copied ( ) . collect ( ) ;
0 commit comments