Skip to content

Commit

Permalink
Add just enough logic to the driver so that we can link std statically.
Browse files Browse the repository at this point in the history
  • Loading branch information
cixtor committed Jul 8, 2011
1 parent 0864a22 commit 94f0e9d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/comp/driver/rustc.rs
Expand Up @@ -436,6 +436,10 @@ fn main(vec[str] args) {
metadata::creader::list_file_metadata(ifile, std::io::stdout());
ret;
}

auto stop_after_codegen = sopts.output_type != link::output_type_exe ||
(sopts.static && sopts.library);

alt (output_file) {
case (none) {
let vec[str] parts = str::split(ifile, '.' as u8);
Expand All @@ -460,7 +464,7 @@ fn main(vec[str] args) {

saved_out_filename = ofile;
auto temp_filename;
if (sopts.output_type == link::output_type_exe && !sopts.static) {
if (!stop_after_codegen) {
temp_filename = ofile + ".o";
} else {
temp_filename = ofile;
Expand All @@ -473,7 +477,7 @@ fn main(vec[str] args) {
// gcc to link the object file with some libs
//
// TODO: Factor this out of main.
if (sopts.output_type != link::output_type_exe || sopts.static) {
if (stop_after_codegen) {
ret;
}

Expand Down Expand Up @@ -521,6 +525,10 @@ fn main(vec[str] args) {

auto cstore = sess.get_cstore();
for (str cratepath in cstore::get_used_crate_files(cstore)) {
if (str::ends_with(cratepath, ".rlib")) {
gcc_args += [cratepath];
cont;
}
auto dir = fs::dirname(cratepath);
if (dir != "") {
gcc_args += ["-L" + dir];
Expand Down
3 changes: 3 additions & 0 deletions src/comp/metadata/creader.rs
Expand Up @@ -124,6 +124,9 @@ fn metadata_matches(&vec[u8] crate_data,

fn default_native_lib_naming(session::session sess) ->
rec(str prefix, str suffix) {
if (sess.get_opts().static) {
ret rec(prefix="lib", suffix=".rlib");
}
alt (sess.get_targ_cfg().os) {
case (session::os_win32) { ret rec(prefix="", suffix=".dll"); }
case (session::os_macos) { ret rec(prefix="lib", suffix=".dylib"); }
Expand Down
3 changes: 3 additions & 0 deletions src/comp/middle/trans.rs
Expand Up @@ -9263,6 +9263,9 @@ fn create_module_map(&@crate_ctxt ccx) -> ValueRef {
auto maptype = T_array(elttype, ccx.module_data.size() + 1u);
auto map =
llvm::LLVMAddGlobal(ccx.llmod, maptype, str::buf("_rust_mod_map"));
llvm::LLVMSetLinkage(map,
lib::llvm::LLVMInternalLinkage as
llvm::Linkage);
let ValueRef[] elts = ~[];
for each (@tup(str, ValueRef) item in ccx.module_data.items()) {
auto elt = C_struct(~[p2i(C_cstr(ccx, item._0)), p2i(item._1)]);
Expand Down

0 comments on commit 94f0e9d

Please sign in to comment.