@@ -20,6 +20,7 @@ use back::write;
2020use back:: target_strs;
2121use back:: { arm, x86, x86_64, mips, mipsel} ;
2222use lint;
23+ use metadata:: cstore;
2324
2425use syntax:: abi;
2526use syntax:: ast;
@@ -78,6 +79,7 @@ pub struct Options {
7879 // parsed code. It remains mutable in case its replacements wants to use
7980 // this.
8081 pub addl_lib_search_paths : RefCell < Vec < Path > > ,
82+ pub libs : Vec < ( String , cstore:: NativeLibaryKind ) > ,
8183 pub maybe_sysroot : Option < Path > ,
8284 pub target_triple : String ,
8385 // User-specified cfg meta items. The compiler itself will add additional
@@ -130,6 +132,7 @@ pub fn basic_options() -> Options {
130132 externs : HashMap :: new ( ) ,
131133 crate_name : None ,
132134 alt_std_name : None ,
135+ libs : Vec :: new ( ) ,
133136 }
134137}
135138
@@ -575,6 +578,10 @@ pub fn optgroups() -> Vec<getopts::OptGroup> {
575578 optflag( "h" , "help" , "Display this message" ) ,
576579 optmulti( "" , "cfg" , "Configure the compilation environment" , "SPEC" ) ,
577580 optmulti( "L" , "" , "Add a directory to the library search path" , "PATH" ) ,
581+ optmulti( "l" , "" , "Link the generated crate(s) to the specified native
582+ library NAME. The optional KIND can be one of,
583+ static, dylib, or framework. If omitted, dylib is
584+ assumed." , "NAME[:KIND]" ) ,
578585 optmulti( "" , "crate-type" , "Comma separated list of types of crates
579586 for the compiler to emit" ,
580587 "[bin|lib|rlib|dylib|staticlib]" ) ,
@@ -767,6 +774,23 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
767774 Path :: new ( s. as_slice ( ) )
768775 } ) . collect ( ) ;
769776
777+ let libs = matches. opt_strs ( "l" ) . into_iter ( ) . map ( |s| {
778+ let mut parts = s. as_slice ( ) . rsplitn ( 1 , ':' ) ;
779+ let kind = parts. next ( ) . unwrap ( ) ;
780+ let ( name, kind) = match ( parts. next ( ) , kind) {
781+ ( None , name) |
782+ ( Some ( name) , "dylib" ) => ( name, cstore:: NativeUnknown ) ,
783+ ( Some ( name) , "framework" ) => ( name, cstore:: NativeFramework ) ,
784+ ( Some ( name) , "static" ) => ( name, cstore:: NativeStatic ) ,
785+ ( _, s) => {
786+ early_error ( format ! ( "unknown library kind `{}`, expected \
787+ one of dylib, framework, or static",
788+ s) . as_slice ( ) ) ;
789+ }
790+ } ;
791+ ( name. to_string ( ) , kind)
792+ } ) . collect ( ) ;
793+
770794 let cfg = parse_cfgspecs ( matches. opt_strs ( "cfg" ) ) ;
771795 let test = matches. opt_present ( "test" ) ;
772796 let write_dependency_info = ( matches. opt_present ( "dep-info" ) ,
@@ -843,7 +867,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
843867 color : color,
844868 externs : externs,
845869 crate_name : crate_name,
846- alt_std_name : None
870+ alt_std_name : None ,
871+ libs : libs,
847872 }
848873}
849874
0 commit comments