Remember the library files we used in rustc and pass them to the "linker".

This avoid the hardcoded -lstd, allows programs to use other crates and avoids
any differences that may exist in the rustc and ld search logic.
This commit is contained in:
Rafael Ávila de Espíndola 2011-06-20 17:36:15 -04:00
parent a2dcd08cc2
commit 3d8a5cb9e6
3 changed files with 21 additions and 3 deletions

View File

@ -271,7 +271,7 @@ fn build_session(@session::options sopts) -> session::session {
auto crate_cache = common::new_int_hash[session::crate_metadata]();
auto target_crate_num = 0;
auto sess =
session::session(target_crate_num, target_cfg, sopts, crate_cache,
session::session(target_crate_num, target_cfg, sopts, crate_cache, [],
front::codemap::new_codemap(), 0u);
ret sess;
}
@ -417,10 +417,13 @@ fn main(vec[str] args) {
gcc_args = common_args;
}
}
gcc_args += sess.get_used_libraries();
if (sopts.shared) {
gcc_args += [shared_cmd];
} else {
gcc_args += ["-Lrustllvm", "-lrustllvm", "-lstd", "-lm", main];
gcc_args += ["-Lrustllvm", "-lrustllvm", "-lm", main];
}
// We run 'gcc' here

View File

@ -66,6 +66,7 @@ obj session(ast::crate_num cnum,
@config targ_cfg,
@options opts,
map::hashmap[int, crate_metadata] crates,
mutable vec[str] used_libraries,
codemap::codemap cm,
mutable uint err_count) {
fn get_targ_cfg() -> @config { ret targ_cfg; }
@ -122,6 +123,19 @@ obj session(ast::crate_num cnum,
crates.insert(num, metadata);
}
fn has_external_crate(int num) -> bool { ret crates.contains_key(num); }
fn add_used_library(&str lib) {
// A program has a small number of libraries, so a vector is probably a
// good data structure in here.
for (str l in used_libraries) {
if (l == lib) {
ret;
}
}
used_libraries += [lib];
}
fn get_used_libraries() -> vec[str] {
ret used_libraries;
}
fn get_codemap() -> codemap::codemap { ret cm; }
fn lookup_pos(uint pos) -> codemap::loc {
ret codemap::lookup_pos(cm, pos);

View File

@ -582,12 +582,13 @@ fn find_library_crate(&session::session sess, &ast::ident ident,
ret none;
}
fn load_library_crate(&session::session sess, &int cnum, &ast::ident ident,
fn load_library_crate(&session::session sess, int cnum, &ast::ident ident,
&vec[@ast::meta_item] metas,
&vec[str] library_search_paths) {
alt (find_library_crate(sess, ident, metas, library_search_paths)) {
case (some(?t)) {
sess.set_external_crate(cnum, rec(name=ident, data=t._1));
sess.add_used_library(t._0);
ret;
}
case (_) { }