@@ -21,8 +21,7 @@ use std::path::PathBuf;
2121use std:: process;
2222
2323use num_cpus;
24- use rustc_serialize:: Decodable ;
25- use toml:: { Parser , Decoder , Value } ;
24+ use toml;
2625use util:: { exe, push_exe_path} ;
2726
2827/// Global configuration for the entire build and/or bootstrap.
@@ -138,7 +137,9 @@ pub struct Target {
138137/// This structure uses `Decodable` to automatically decode a TOML configuration
139138/// file into this format, and then this is traversed and written into the above
140139/// `Config` structure.
141- #[ derive( RustcDecodable , Default ) ]
140+ #[ derive( Deserialize , Default ) ]
141+ #[ serde( deny_unknown_fields) ]
142+ #[ serde( rename_all = "kebab-case" ) ]
142143struct TomlConfig {
143144 build : Option < Build > ,
144145 install : Option < Install > ,
@@ -149,10 +150,14 @@ struct TomlConfig {
149150}
150151
151152/// 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" ) ]
153156struct Build {
154157 build : Option < String > ,
158+ #[ serde( default ) ]
155159 host : Vec < String > ,
160+ #[ serde( default ) ]
156161 target : Vec < String > ,
157162 cargo : Option < String > ,
158163 rustc : Option < String > ,
@@ -174,7 +179,9 @@ struct Build {
174179}
175180
176181/// 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" ) ]
178185struct Install {
179186 prefix : Option < String > ,
180187 sysconfdir : Option < String > ,
@@ -185,7 +192,9 @@ struct Install {
185192}
186193
187194/// 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" ) ]
189198struct Llvm {
190199 ccache : Option < StringOrBool > ,
191200 ninja : Option < bool > ,
@@ -200,15 +209,18 @@ struct Llvm {
200209 clean_rebuild : Option < bool > ,
201210}
202211
203- #[ derive( RustcDecodable , Default , Clone ) ]
212+ #[ derive( Deserialize , Default , Clone ) ]
213+ #[ serde( deny_unknown_fields) ]
214+ #[ serde( rename_all = "kebab-case" ) ]
204215struct Dist {
205216 sign_folder : Option < String > ,
206217 gpg_password_file : Option < String > ,
207218 upload_addr : Option < String > ,
208219 src_tarball : Option < bool > ,
209220}
210221
211- #[ derive( RustcDecodable ) ]
222+ #[ derive( Deserialize ) ]
223+ #[ serde( untagged) ]
212224enum StringOrBool {
213225 String ( String ) ,
214226 Bool ( bool ) ,
@@ -221,7 +233,9 @@ impl Default for StringOrBool {
221233}
222234
223235/// 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" ) ]
225239struct Rust {
226240 optimize : Option < bool > ,
227241 codegen_units : Option < u32 > ,
@@ -243,7 +257,9 @@ struct Rust {
243257}
244258
245259/// 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" ) ]
247263struct TomlTarget {
248264 llvm_config : Option < String > ,
249265 jemalloc : Option < String > ,
@@ -273,27 +289,13 @@ impl Config {
273289
274290 let toml = file. map ( |file| {
275291 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) ;
297299 process:: exit ( 2 ) ;
298300 }
299301 }
0 commit comments