@@ -14,12 +14,13 @@ use std::path::{Path, PathBuf};
14
14
use std:: fs:: { self , DirEntry } ;
15
15
use std:: collections:: HashSet ;
16
16
17
- use core:: { compiler, Edition , Target } ;
18
- use util:: errors:: CargoResult ;
17
+ use core:: { compiler, Edition , Feature , Features , Target } ;
18
+ use util:: errors:: { CargoResult , CargoResultExt } ;
19
19
use super :: { LibKind , PathValue , StringOrBool , TomlBenchTarget , TomlBinTarget , TomlExampleTarget ,
20
20
TomlLibTarget , TomlManifest , TomlTarget , TomlTestTarget } ;
21
21
22
22
pub fn targets (
23
+ features : & Features ,
23
24
manifest : & TomlManifest ,
24
25
package_name : & str ,
25
26
package_root : & Path ,
@@ -33,6 +34,7 @@ pub fn targets(
33
34
let has_lib;
34
35
35
36
if let Some ( target) = clean_lib (
37
+ features,
36
38
manifest. lib . as_ref ( ) ,
37
39
package_root,
38
40
package_name,
@@ -52,6 +54,7 @@ pub fn targets(
52
54
. ok_or_else ( || format_err ! ( "manifest has no `package` (or `project`)" ) ) ?;
53
55
54
56
targets. extend ( clean_bins (
57
+ features,
55
58
manifest. bin . as_ref ( ) ,
56
59
package_root,
57
60
package_name,
@@ -63,6 +66,7 @@ pub fn targets(
63
66
) ?) ;
64
67
65
68
targets. extend ( clean_examples (
69
+ features,
66
70
manifest. example . as_ref ( ) ,
67
71
package_root,
68
72
edition,
@@ -72,6 +76,7 @@ pub fn targets(
72
76
) ?) ;
73
77
74
78
targets. extend ( clean_tests (
79
+ features,
75
80
manifest. test . as_ref ( ) ,
76
81
package_root,
77
82
edition,
@@ -81,6 +86,7 @@ pub fn targets(
81
86
) ?) ;
82
87
83
88
targets. extend ( clean_benches (
89
+ features,
84
90
manifest. bench . as_ref ( ) ,
85
91
package_root,
86
92
edition,
@@ -108,6 +114,7 @@ pub fn targets(
108
114
}
109
115
110
116
fn clean_lib (
117
+ features : & Features ,
111
118
toml_lib : Option < & TomlLibTarget > ,
112
119
package_root : & Path ,
113
120
package_name : & str ,
@@ -183,11 +190,12 @@ fn clean_lib(
183
190
} ;
184
191
185
192
let mut target = Target :: lib_target ( & lib. name ( ) , crate_types, path) ;
186
- configure ( lib, & mut target) ;
193
+ configure ( features , lib, & mut target, edition ) ? ;
187
194
Ok ( Some ( target) )
188
195
}
189
196
190
197
fn clean_bins (
198
+ features : & Features ,
191
199
toml_bins : Option < & Vec < TomlBinTarget > > ,
192
200
package_root : & Path ,
193
201
package_name : & str ,
@@ -263,7 +271,7 @@ fn clean_bins(
263
271
} ;
264
272
265
273
let mut target = Target :: bin_target ( & bin. name ( ) , path, bin. required_features . clone ( ) ) ;
266
- configure ( bin, & mut target) ;
274
+ configure ( features , bin, & mut target, edition ) ? ;
267
275
result. push ( target) ;
268
276
}
269
277
return Ok ( result) ;
@@ -289,6 +297,7 @@ fn clean_bins(
289
297
}
290
298
291
299
fn clean_examples (
300
+ features : & Features ,
292
301
toml_examples : Option < & Vec < TomlExampleTarget > > ,
293
302
package_root : & Path ,
294
303
edition : Edition ,
@@ -324,14 +333,15 @@ fn clean_examples(
324
333
path,
325
334
toml. required_features . clone ( ) ,
326
335
) ;
327
- configure ( & toml, & mut target) ;
336
+ configure ( features , & toml, & mut target, edition ) ? ;
328
337
result. push ( target) ;
329
338
}
330
339
331
340
Ok ( result)
332
341
}
333
342
334
343
fn clean_tests (
344
+ features : & Features ,
335
345
toml_tests : Option < & Vec < TomlTestTarget > > ,
336
346
package_root : & Path ,
337
347
edition : Edition ,
@@ -357,13 +367,14 @@ fn clean_tests(
357
367
let mut result = Vec :: new ( ) ;
358
368
for ( path, toml) in targets {
359
369
let mut target = Target :: test_target ( & toml. name ( ) , path, toml. required_features . clone ( ) ) ;
360
- configure ( & toml, & mut target) ;
370
+ configure ( features , & toml, & mut target, edition ) ? ;
361
371
result. push ( target) ;
362
372
}
363
373
Ok ( result)
364
374
}
365
375
366
376
fn clean_benches (
377
+ features : & Features ,
367
378
toml_benches : Option < & Vec < TomlBenchTarget > > ,
368
379
package_root : & Path ,
369
380
edition : Edition ,
@@ -410,7 +421,7 @@ fn clean_benches(
410
421
let mut result = Vec :: new ( ) ;
411
422
for ( path, toml) in targets {
412
423
let mut target = Target :: bench_target ( & toml. name ( ) , path, toml. required_features . clone ( ) ) ;
413
- configure ( & toml, & mut target) ;
424
+ configure ( features , & toml, & mut target, edition ) ? ;
414
425
result. push ( target) ;
415
426
}
416
427
@@ -682,7 +693,12 @@ fn validate_unique_names(targets: &[TomlTarget], target_kind: &str) -> CargoResu
682
693
Ok ( ( ) )
683
694
}
684
695
685
- fn configure ( toml : & TomlTarget , target : & mut Target ) {
696
+ fn configure (
697
+ features : & Features ,
698
+ toml : & TomlTarget ,
699
+ target : & mut Target ,
700
+ edition : Edition ,
701
+ ) -> CargoResult < ( ) > {
686
702
let t2 = target. clone ( ) ;
687
703
target
688
704
. set_tested ( toml. test . unwrap_or_else ( || t2. tested ( ) ) )
@@ -694,7 +710,15 @@ fn configure(toml: &TomlTarget, target: &mut Target) {
694
710
( None , None ) => t2. for_host ( ) ,
695
711
( Some ( true ) , _) | ( _, Some ( true ) ) => true ,
696
712
( Some ( false ) , _) | ( _, Some ( false ) ) => false ,
713
+ } )
714
+ . set_edition ( match toml. edition . clone ( ) {
715
+ None => edition,
716
+ Some ( s) => {
717
+ features. require ( Feature :: edition ( ) ) . chain_err ( || "editions are unstable" ) ?;
718
+ s. parse ( ) . chain_err ( || "failed to parse the `edition` key" ) ?
719
+ } ,
697
720
} ) ;
721
+ Ok ( ( ) )
698
722
}
699
723
700
724
fn target_path (
0 commit comments