@@ -57,6 +57,23 @@ fn default_configuration(session::session sess, str argv0, str input) ->
57
57
mk ( "build_input" , input) ] ;
58
58
}
59
59
60
+ fn build_configuration ( session:: session sess, str argv0 ,
61
+ str input ) -> ast:: crate_cfg {
62
+ // Combine the configuration requested by the session (command line) with
63
+ // some default configuration items
64
+ ret sess. get_opts ( ) . cfg + default_configuration ( sess, argv0, input) ;
65
+ }
66
+
67
+ // Convert strings provided as --cfg [cfgspec] into a crate_cfg
68
+ fn parse_cfgspecs ( & vec[ str] cfgspecs ) -> ast:: crate_cfg {
69
+ // FIXME: It would be nice to use the parser to parse all varieties of
70
+ // meta_item here. At the moment we just support the meta_word variant.
71
+ fn to_meta_word ( & str cfgspec ) -> @ast:: meta_item {
72
+ attr:: mk_word_item ( cfgspec)
73
+ }
74
+ ret vec:: map ( to_meta_word, cfgspecs) ;
75
+ }
76
+
60
77
fn parse_input ( session:: session sess, parser:: parser p, str input ) ->
61
78
@ast:: crate {
62
79
ret if ( str:: ends_with ( input, ".rc" ) ) {
@@ -160,6 +177,7 @@ options:
160
177
--emit-llvm produce an LLVM bitcode file
161
178
--save-temps write intermediate files in addition to normal output
162
179
--stats gather and report various compilation statistics
180
+ --cfg [cfgspec] configure the compilation environment
163
181
--time-passes time the individual phases of the compiler
164
182
--time-llvm-passes time the individual phases of the LLVM backend
165
183
--sysroot <path> override the system root (default: rustc's directory)
@@ -257,6 +275,7 @@ fn build_session_options(str binary, getopts::match match, str binary_dir) ->
257
275
case ( none) { get_default_sysroot ( binary) }
258
276
case ( some ( ?s) ) { s }
259
277
} ;
278
+ auto cfg = parse_cfgspecs( getopts:: opt_strs( match , "cfg" ) ) ;
260
279
let @session:: options sopts =
261
280
@rec ( shared=shared,
262
281
optimize=opt_level,
@@ -269,7 +288,8 @@ fn build_session_options(str binary, getopts::match match, str binary_dir) ->
269
288
time_llvm_passes=time_llvm_passes,
270
289
output_type=output_type,
271
290
library_search_paths=library_search_paths,
272
- sysroot=sysroot) ;
291
+ sysroot=sysroot,
292
+ cfg=cfg) ;
273
293
ret sopts;
274
294
}
275
295
@@ -302,7 +322,7 @@ fn main(vec[str] args) {
302
322
optflag ( "c" ) , optopt ( "o" ) , optflag ( "g" ) , optflag ( "save-temps" ) ,
303
323
optopt ( "sysroot" ) , optflag ( "stats" ) , optflag ( "time-passes" ) ,
304
324
optflag ( "time-llvm-passes" ) , optflag ( "no-typestate" ) ,
305
- optflag ( "noverify" ) ] ;
325
+ optflag ( "noverify" ) , optmulti ( "cfg" ) ] ;
306
326
auto binary = vec:: shift[ str] ( args) ;
307
327
auto binary_dir = fs:: dirname ( binary) ;
308
328
auto match =
@@ -341,7 +361,7 @@ fn main(vec[str] args) {
341
361
}
342
362
auto ifile = match . free . ( 0 ) ;
343
363
let str saved_out_filename = "" ;
344
- auto cfg = default_configuration ( sess, binary, ifile) ;
364
+ auto cfg = build_configuration ( sess, binary, ifile) ;
345
365
auto pretty =
346
366
option:: map[ str,
347
367
pp_mode] ( bind parse_pretty ( sess, _) ,
0 commit comments