Skip to content

Commit

Permalink
Try to use static crate if we cannot find the dynamic one. This supports
Browse files Browse the repository at this point in the history
the common case of wanting to link statically with the project's libraries
but dynamically with the system ones.
  • Loading branch information
cixtor committed Jul 8, 2011
1 parent 94f0e9d commit 4c30932
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/comp/metadata/creader.rs
Expand Up @@ -122,9 +122,9 @@ fn metadata_matches(&vec[u8] crate_data,
ret true;
}

fn default_native_lib_naming(session::session sess) ->
fn default_native_lib_naming(session::session sess, bool static) ->
rec(str prefix, str suffix) {
if (sess.get_opts().static) {
if (static) {
ret rec(prefix="lib", suffix=".rlib");
}
alt (sess.get_targ_cfg().os) {
Expand Down Expand Up @@ -158,7 +158,20 @@ fn find_library_crate(&session::session sess, &ast::ident ident,
}
};

auto nn = default_native_lib_naming(sess);
auto nn = default_native_lib_naming(sess, sess.get_opts().static);
auto x = find_library_crate_aux(nn, crate_name, metas,
library_search_paths);
if (x != none || sess.get_opts().static) {
ret x;
}
auto nn2 = default_native_lib_naming(sess, true);
ret find_library_crate_aux(nn2, crate_name, metas, library_search_paths);
}

fn find_library_crate_aux(&rec(str prefix, str suffix) nn, str crate_name,
&(@ast::meta_item)[] metas,
&vec[str] library_search_paths) ->
option::t[tup(str, vec[u8])] {
let str prefix = nn.prefix + crate_name;
// FIXME: we could probably use a 'glob' function in std::fs but it will
// be much easier to write once the unsafe module knows more about FFI
Expand Down

0 comments on commit 4c30932

Please sign in to comment.