]> git.lizzy.rs Git - rust.git/commitdiff
librustc: Add argument to allow choosing "linker"
authorLuqman Aden <me@luqman.ca>
Thu, 2 May 2013 21:12:47 +0000 (14:12 -0700)
committerLuqman Aden <me@luqman.ca>
Fri, 3 May 2013 19:53:01 +0000 (12:53 -0700)
src/librustc/back/link.rs
src/librustc/driver/driver.rs
src/librustc/driver/session.rs

index 87e08a73fcb1c58f347d42a512c89ae919f8ca0c..de6469e81807d679975e06531ee05069541b66d9 100644 (file)
@@ -752,18 +752,26 @@ pub fn link_binary(sess: Session,
     // instead of hard-coded gcc.
     // For win32, there is no cc command,
     // so we add a condition to make it use gcc.
-    let cc_prog: ~str = if sess.targ_cfg.os == session::os_android {
-        match &sess.opts.android_cross_path {
-            &Some(copy path) => {
-                fmt!("%s/bin/arm-linux-androideabi-gcc", path)
-            }
-            &None => {
-                sess.fatal(~"need Android NDK path for linking \
-                             (--android-cross-path)")
+    let cc_prog: ~str = match sess.opts.linker {
+        Some(copy linker) => linker,
+        None => {
+            if sess.targ_cfg.os == session::os_android {
+                match &sess.opts.android_cross_path {
+                    &Some(copy path) => {
+                        fmt!("%s/bin/arm-linux-androideabi-gcc", path)
+                    }
+                    &None => {
+                        sess.fatal(~"need Android NDK path for linking \
+                                     (--android-cross-path)")
+                    }
+                }
+            } else if sess.targ_cfg.os == session::os_win32 {
+                ~"gcc"
+            } else {
+                ~"cc"
             }
         }
-    } else if sess.targ_cfg.os == session::os_win32 { ~"gcc" }
-    else { ~"cc" };
+    };
     // The invocations of cc share some flags across platforms
 
 
index 5e5d0640d808ed43e5bb296293b5372f6c566d37..02940ea9905bacf8ab474e67cb1d001c9abd5936 100644 (file)
@@ -650,7 +650,7 @@ pub fn build_session_options(binary: @~str,
     };
 
     let addl_lib_search_paths = getopts::opt_strs(matches, ~"L").map(|s| Path(*s));
-
+    let linker = getopts::opt_maybe_str(matches, ~"linker");
     let linker_args = getopts::opt_strs(matches, ~"link-args").flat_map( |a| {
         let mut args = ~[];
         for str::each_split_char(*a, ' ') |arg| {
@@ -676,6 +676,7 @@ pub fn build_session_options(binary: @~str,
         jit: jit,
         output_type: output_type,
         addl_lib_search_paths: addl_lib_search_paths,
+        linker: linker,
         linker_args: linker_args,
         maybe_sysroot: sysroot_opt,
         target_triple: target,
@@ -760,6 +761,7 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
   optmulti("L", "",   "Add a directory to the library search path",
                               "PATH"),
   optflag("",  "lib", "Compile a library crate"),
+  optopt("", "linker", "Program to use for linking instead of the default.", "LINKER"),
   optmulti("",  "link-args", "FLAGS is a space-separated list of flags
                             passed to the linker", "FLAGS"),
   optflag("",  "ls",  "List the symbols defined by a library crate"),
index 237b03bc20fb377aa44e837a58c39f2af42c4b64..29cb5a71f31655caa460bb730c86343d1271c54b 100644 (file)
@@ -124,6 +124,7 @@ pub struct options {
     jit: bool,
     output_type: back::link::output_type,
     addl_lib_search_paths: ~[Path],
+    linker: Option<~str>,
     linker_args: ~[~str],
     maybe_sysroot: Option<Path>,
     target_triple: ~str,
@@ -302,7 +303,8 @@ pub fn basic_options() -> @options {
         jit: false,
         output_type: link::output_type_exe,
         addl_lib_search_paths: ~[],
-        linker_args:~[],
+        linker: None,
+        linker_args: ~[],
         maybe_sysroot: None,
         target_triple: host_triple(),
         target_feature: ~"",