Skip to content

Commit 832f7b7

Browse files
committed
librustc: Add argument to allow choosing "linker"
1 parent 9a31cdb commit 832f7b7

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

src/librustc/back/link.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -752,18 +752,26 @@ pub fn link_binary(sess: Session,
752752
// instead of hard-coded gcc.
753753
// For win32, there is no cc command,
754754
// so we add a condition to make it use gcc.
755-
let cc_prog: ~str = if sess.targ_cfg.os == session::os_android {
756-
match &sess.opts.android_cross_path {
757-
&Some(copy path) => {
758-
fmt!("%s/bin/arm-linux-androideabi-gcc", path)
759-
}
760-
&None => {
761-
sess.fatal(~"need Android NDK path for linking \
762-
(--android-cross-path)")
755+
let cc_prog: ~str = match sess.opts.linker {
756+
Some(copy linker) => linker,
757+
None => {
758+
if sess.targ_cfg.os == session::os_android {
759+
match &sess.opts.android_cross_path {
760+
&Some(copy path) => {
761+
fmt!("%s/bin/arm-linux-androideabi-gcc", path)
762+
}
763+
&None => {
764+
sess.fatal(~"need Android NDK path for linking \
765+
(--android-cross-path)")
766+
}
767+
}
768+
} else if sess.targ_cfg.os == session::os_win32 {
769+
~"gcc"
770+
} else {
771+
~"cc"
763772
}
764773
}
765-
} else if sess.targ_cfg.os == session::os_win32 { ~"gcc" }
766-
else { ~"cc" };
774+
};
767775
// The invocations of cc share some flags across platforms
768776
769777

src/librustc/driver/driver.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ pub fn build_session_options(binary: @~str,
650650
};
651651
652652
let addl_lib_search_paths = getopts::opt_strs(matches, ~"L").map(|s| Path(*s));
653-
653+
let linker = getopts::opt_maybe_str(matches, ~"linker");
654654
let linker_args = getopts::opt_strs(matches, ~"link-args").flat_map( |a| {
655655
let mut args = ~[];
656656
for str::each_split_char(*a, ' ') |arg| {
@@ -676,6 +676,7 @@ pub fn build_session_options(binary: @~str,
676676
jit: jit,
677677
output_type: output_type,
678678
addl_lib_search_paths: addl_lib_search_paths,
679+
linker: linker,
679680
linker_args: linker_args,
680681
maybe_sysroot: sysroot_opt,
681682
target_triple: target,
@@ -760,6 +761,7 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
760761
optmulti("L", "", "Add a directory to the library search path",
761762
"PATH"),
762763
optflag("", "lib", "Compile a library crate"),
764+
optopt("", "linker", "Program to use for linking instead of the default.", "LINKER"),
763765
optmulti("", "link-args", "FLAGS is a space-separated list of flags
764766
passed to the linker", "FLAGS"),
765767
optflag("", "ls", "List the symbols defined by a library crate"),

src/librustc/driver/session.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ pub struct options {
124124
jit: bool,
125125
output_type: back::link::output_type,
126126
addl_lib_search_paths: ~[Path],
127+
linker: Option<~str>,
127128
linker_args: ~[~str],
128129
maybe_sysroot: Option<Path>,
129130
target_triple: ~str,
@@ -302,7 +303,8 @@ pub fn basic_options() -> @options {
302303
jit: false,
303304
output_type: link::output_type_exe,
304305
addl_lib_search_paths: ~[],
305-
linker_args:~[],
306+
linker: None,
307+
linker_args: ~[],
306308
maybe_sysroot: None,
307309
target_triple: host_triple(),
308310
target_feature: ~"",

0 commit comments

Comments
 (0)