Skip to content

Commit 7bb9a54

Browse files
lhtbrson
authored andcommitted
Produce dyn libraries with proper names
Issue #744
1 parent 7dacccd commit 7bb9a54

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

src/comp/back/link.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -502,17 +502,16 @@ fn mangle_internal_name_by_seq(ccx: @crate_ctxt, flav: str) -> str {
502502
// If the user wants an exe generated we need to invoke
503503
// gcc to link the object file with some libs
504504
fn link_binary(sess: session::session,
505-
saved_out_filename: str) {
505+
obj_filename: str,
506+
out_filename: str) {
506507
// The default library location, we need this to find the runtime.
507508
// The location of crates will be determined as needed.
508509
let stage: str = "-L" + sess.filesearch().get_target_lib_path();
509510

510511
let prog: str = "gcc";
511512
// The invocations of gcc share some flags across platforms
512513

513-
let gcc_args =
514-
[stage, "-m32", "-o", saved_out_filename,
515-
saved_out_filename + ".o"];
514+
let gcc_args = [stage, "-m32", "-o", out_filename, obj_filename];
516515
let lib_cmd;
517516

518517
let os = sess.get_targ_cfg().os;
@@ -569,7 +568,7 @@ fn link_binary(sess: session::session,
569568
// be rpathed
570569
if sess.get_targ_cfg().os == session::os_macos {
571570
gcc_args += ["-Wl,-install_name,@rpath/"
572-
+ fs::basename(saved_out_filename)];
571+
+ fs::basename(out_filename)];
573572
}
574573
} else {
575574
// FIXME: why do we hardcode -lm?
@@ -586,7 +585,7 @@ fn link_binary(sess: session::session,
586585
gcc_args += ["-lrt", "-ldl"];
587586
}
588587

589-
gcc_args += rpath::get_rpath_flags(sess, saved_out_filename);
588+
gcc_args += rpath::get_rpath_flags(sess, out_filename);
590589

591590
log #fmt("gcc link args: %s", str::connect(gcc_args, " "));
592591
// We run 'gcc' here
@@ -600,13 +599,13 @@ fn link_binary(sess: session::session,
600599
// Clean up on Darwin
601600

602601
if sess.get_targ_cfg().os == session::os_macos {
603-
run::run_program("dsymutil", [saved_out_filename]);
602+
run::run_program("dsymutil", [out_filename]);
604603
}
605604

606605

607606
// Remove the temporary object file if we aren't saving temps
608607
if !sess.get_opts().save_temps {
609-
run::run_program("rm", [saved_out_filename + ".o"]);
608+
run::run_program("rm", [obj_filename]);
610609
}
611610
}
612611

src/comp/driver/rustc.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ fn main(args: [str]) {
484484
sopts.output_type != link::output_type_exe ||
485485
sopts.static && sopts.library;
486486

487+
let ofile = "";
487488
alt output_file {
488489
none. {
489490
// "-" as input file will cause the parser to read from stdin so we
@@ -494,37 +495,36 @@ fn main(args: [str]) {
494495
str::split(ifile, '.' as u8)
495496
} else { ["default", "rs"] };
496497
vec::pop(parts);
497-
saved_out_filename = str::connect(parts, ".");
498+
let base_filename = str::connect(parts, ".");
498499
let suffix =
499500
alt sopts.output_type {
500501
link::output_type_none. { "none" }
501502
link::output_type_bitcode. { "bc" }
502503
link::output_type_assembly. { "s" }
503-
504-
505-
506-
507504
// Object and exe output both use the '.o' extension here
508505
link::output_type_object. | link::output_type_exe. {
509506
"o"
510507
}
511508
};
512-
let ofile = saved_out_filename + "." + suffix;
513-
compile_input(sess, cfg, ifile, ofile);
509+
ofile = base_filename + "." + suffix;
510+
511+
if sopts.library {
512+
saved_out_filename = std::os::dylib_filename(base_filename);
513+
} else {
514+
saved_out_filename = base_filename;
515+
}
514516
}
515-
some(ofile) {
516-
let ofile = ofile;
517-
// FIXME: what about windows? This will create a foo.exe.o.
518-
saved_out_filename = ofile;
519-
let temp_filename =
520-
if !stop_after_codegen { ofile + ".o" } else { ofile };
521-
compile_input(sess, cfg, ifile, temp_filename);
517+
some(out_file) {
518+
saved_out_filename = out_file;
519+
ofile =
520+
if !stop_after_codegen { out_file + ".o" } else { out_file };
522521
}
523522
}
524523

524+
compile_input(sess, cfg, ifile, ofile);
525525
if stop_after_codegen { ret; }
526526

527-
link::link_binary(sess, saved_out_filename);
527+
link::link_binary(sess, ofile, saved_out_filename);
528528
}
529529

530530
#[cfg(test)]

0 commit comments

Comments
 (0)