Skip to content

Commit 6c6f83f

Browse files
lhtgraydon
authored andcommitted
rustc: Refactor and get built on Windows
1 parent ba0649c commit 6c6f83f

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/comp/back/link.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,13 @@ fn link_binary(sess: session::session,
561561
obj_filename: str,
562562
out_filename: str,
563563
lm: link_meta) {
564+
let output = if sess.building_library() {
565+
let long_libname =
566+
std::os::dylib_filename(#fmt("%s-%s-%s",
567+
lm.name, lm.extras_hash, lm.vers));
568+
fs::connect(fs::dirname(out_filename), long_libname)
569+
} else { out_filename };
570+
564571
// The default library location, we need this to find the runtime.
565572
// The location of crates will be determined as needed.
566573
let stage: str = "-L" + sess.filesearch().get_target_lib_path();
@@ -570,9 +577,9 @@ fn link_binary(sess: session::session,
570577

571578
let gcc_args =
572579
[stage] + sess.get_targ_cfg().target_strs.gcc_args +
573-
["-o", out_filename, obj_filename];
574-
let lib_cmd;
580+
["-o", output, obj_filename];
575581

582+
let lib_cmd;
576583
let os = sess.get_targ_cfg().os;
577584
if os == session::os_macos {
578585
lib_cmd = "-dynamiclib";
@@ -620,24 +627,20 @@ fn link_binary(sess: session::session,
620627
let used_libs = cstore::get_used_libraries(cstore);
621628
for l: str in used_libs { gcc_args += ["-l" + l]; }
622629

623-
let long_libname =
624-
std::os::dylib_filename(#fmt("%s-%s-%s",
625-
lm.name, lm.extras_hash, lm.vers));
626-
627630
if sess.building_library() {
628631
gcc_args += [lib_cmd];
629632

630633
// On mac we need to tell the linker to let this library
631634
// be rpathed
632635
if sess.get_targ_cfg().os == session::os_macos {
633-
gcc_args += ["-Wl,-install_name,@rpath/" + long_libname];
636+
gcc_args += ["-Wl,-install_name,@rpath/"
637+
+ fs::basename(output)];
634638
}
635639
} else {
636640
// FIXME: why do we hardcode -lm?
637641
gcc_args += ["-lm"];
638642
}
639643

640-
641644
// Always want the runtime linked in
642645
gcc_args += ["-lrustrt"];
643646

@@ -666,18 +669,13 @@ fn link_binary(sess: session::session,
666669

667670
// Clean up on Darwin
668671
if sess.get_targ_cfg().os == session::os_macos {
669-
run::run_program("dsymutil", [out_filename]);
672+
run::run_program("dsymutil", [output]);
670673
}
671674

672675
// Remove the temporary object file if we aren't saving temps
673676
if !sess.get_opts().save_temps {
674677
run::run_program("rm", [obj_filename]);
675678
}
676-
677-
if sess.building_library() {
678-
let fullname = fs::connect(fs::dirname(out_filename), long_libname);
679-
run::run_program("mv", [out_filename, fullname]);
680-
}
681679
}
682680
//
683681
// Local Variables:

0 commit comments

Comments
 (0)