@@ -21,8 +21,7 @@ use std::path::PathBuf;
21
21
use std:: process;
22
22
23
23
use num_cpus;
24
- use rustc_serialize:: Decodable ;
25
- use toml:: { Parser , Decoder , Value } ;
24
+ use toml;
26
25
use util:: { exe, push_exe_path} ;
27
26
28
27
/// Global configuration for the entire build and/or bootstrap.
@@ -138,7 +137,9 @@ pub struct Target {
138
137
/// This structure uses `Decodable` to automatically decode a TOML configuration
139
138
/// file into this format, and then this is traversed and written into the above
140
139
/// `Config` structure.
141
- #[ derive( RustcDecodable , Default ) ]
140
+ #[ derive( Deserialize , Default ) ]
141
+ #[ serde( deny_unknown_fields) ]
142
+ #[ serde( rename_all = "kebab-case" ) ]
142
143
struct TomlConfig {
143
144
build : Option < Build > ,
144
145
install : Option < Install > ,
@@ -149,10 +150,14 @@ struct TomlConfig {
149
150
}
150
151
151
152
/// TOML representation of various global build decisions.
152
- #[ derive( RustcDecodable , Default , Clone ) ]
153
+ #[ derive( Deserialize , Default , Clone ) ]
154
+ #[ serde( deny_unknown_fields) ]
155
+ #[ serde( rename_all = "kebab-case" ) ]
153
156
struct Build {
154
157
build : Option < String > ,
158
+ #[ serde( default ) ]
155
159
host : Vec < String > ,
160
+ #[ serde( default ) ]
156
161
target : Vec < String > ,
157
162
cargo : Option < String > ,
158
163
rustc : Option < String > ,
@@ -174,7 +179,9 @@ struct Build {
174
179
}
175
180
176
181
/// TOML representation of various global install decisions.
177
- #[ derive( RustcDecodable , Default , Clone ) ]
182
+ #[ derive( Deserialize , Default , Clone ) ]
183
+ #[ serde( deny_unknown_fields) ]
184
+ #[ serde( rename_all = "kebab-case" ) ]
178
185
struct Install {
179
186
prefix : Option < String > ,
180
187
sysconfdir : Option < String > ,
@@ -185,7 +192,9 @@ struct Install {
185
192
}
186
193
187
194
/// TOML representation of how the LLVM build is configured.
188
- #[ derive( RustcDecodable , Default ) ]
195
+ #[ derive( Deserialize , Default ) ]
196
+ #[ serde( deny_unknown_fields) ]
197
+ #[ serde( rename_all = "kebab-case" ) ]
189
198
struct Llvm {
190
199
ccache : Option < StringOrBool > ,
191
200
ninja : Option < bool > ,
@@ -200,15 +209,18 @@ struct Llvm {
200
209
clean_rebuild : Option < bool > ,
201
210
}
202
211
203
- #[ derive( RustcDecodable , Default , Clone ) ]
212
+ #[ derive( Deserialize , Default , Clone ) ]
213
+ #[ serde( deny_unknown_fields) ]
214
+ #[ serde( rename_all = "kebab-case" ) ]
204
215
struct Dist {
205
216
sign_folder : Option < String > ,
206
217
gpg_password_file : Option < String > ,
207
218
upload_addr : Option < String > ,
208
219
src_tarball : Option < bool > ,
209
220
}
210
221
211
- #[ derive( RustcDecodable ) ]
222
+ #[ derive( Deserialize ) ]
223
+ #[ serde( untagged) ]
212
224
enum StringOrBool {
213
225
String ( String ) ,
214
226
Bool ( bool ) ,
@@ -221,7 +233,9 @@ impl Default for StringOrBool {
221
233
}
222
234
223
235
/// TOML representation of how the Rust build is configured.
224
- #[ derive( RustcDecodable , Default ) ]
236
+ #[ derive( Deserialize , Default ) ]
237
+ #[ serde( deny_unknown_fields) ]
238
+ #[ serde( rename_all = "kebab-case" ) ]
225
239
struct Rust {
226
240
optimize : Option < bool > ,
227
241
codegen_units : Option < u32 > ,
@@ -243,7 +257,9 @@ struct Rust {
243
257
}
244
258
245
259
/// TOML representation of how each build target is configured.
246
- #[ derive( RustcDecodable , Default ) ]
260
+ #[ derive( Deserialize , Default ) ]
261
+ #[ serde( deny_unknown_fields) ]
262
+ #[ serde( rename_all = "kebab-case" ) ]
247
263
struct TomlTarget {
248
264
llvm_config : Option < String > ,
249
265
jemalloc : Option < String > ,
@@ -273,27 +289,13 @@ impl Config {
273
289
274
290
let toml = file. map ( |file| {
275
291
let mut f = t ! ( File :: open( & file) ) ;
276
- let mut toml = String :: new ( ) ;
277
- t ! ( f. read_to_string( & mut toml) ) ;
278
- let mut p = Parser :: new ( & toml) ;
279
- let table = match p. parse ( ) {
280
- Some ( table) => table,
281
- None => {
282
- println ! ( "failed to parse TOML configuration '{}':" , file. to_str( ) . unwrap( ) ) ;
283
- for err in p. errors . iter ( ) {
284
- let ( loline, locol) = p. to_linecol ( err. lo ) ;
285
- let ( hiline, hicol) = p. to_linecol ( err. hi ) ;
286
- println ! ( "{}:{}-{}:{}: {}" , loline, locol, hiline,
287
- hicol, err. desc) ;
288
- }
289
- process:: exit ( 2 ) ;
290
- }
291
- } ;
292
- let mut d = Decoder :: new ( Value :: Table ( table) ) ;
293
- match Decodable :: decode ( & mut d) {
294
- Ok ( cfg) => cfg,
295
- Err ( e) => {
296
- println ! ( "failed to decode TOML: {}" , e) ;
292
+ let mut contents = String :: new ( ) ;
293
+ t ! ( f. read_to_string( & mut contents) ) ;
294
+ match toml:: from_str ( & contents) {
295
+ Ok ( table) => table,
296
+ Err ( err) => {
297
+ println ! ( "failed to parse TOML configuration '{}': {}" ,
298
+ file. display( ) , err) ;
297
299
process:: exit ( 2 ) ;
298
300
}
299
301
}
0 commit comments