From 4c309321e0979552f8c9230c6425c96b59ac80da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Fri, 8 Jul 2011 15:33:00 -0400 Subject: [PATCH] Try to use static crate if we cannot find the dynamic one. This supports the common case of wanting to link statically with the project's libraries but dynamically with the system ones. --- src/comp/metadata/creader.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/comp/metadata/creader.rs b/src/comp/metadata/creader.rs index 498b44fbfc3e3..7268516873198 100644 --- a/src/comp/metadata/creader.rs +++ b/src/comp/metadata/creader.rs @@ -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) { @@ -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