Skip to content

Commit 4c30932

Browse files
committed
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.
1 parent 94f0e9d commit 4c30932

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/comp/metadata/creader.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ fn metadata_matches(&vec[u8] crate_data,
122122
ret true;
123123
}
124124

125-
fn default_native_lib_naming(session::session sess) ->
125+
fn default_native_lib_naming(session::session sess, bool static) ->
126126
rec(str prefix, str suffix) {
127-
if (sess.get_opts().static) {
127+
if (static) {
128128
ret rec(prefix="lib", suffix=".rlib");
129129
}
130130
alt (sess.get_targ_cfg().os) {
@@ -158,7 +158,20 @@ fn find_library_crate(&session::session sess, &ast::ident ident,
158158
}
159159
};
160160

161-
auto nn = default_native_lib_naming(sess);
161+
auto nn = default_native_lib_naming(sess, sess.get_opts().static);
162+
auto x = find_library_crate_aux(nn, crate_name, metas,
163+
library_search_paths);
164+
if (x != none || sess.get_opts().static) {
165+
ret x;
166+
}
167+
auto nn2 = default_native_lib_naming(sess, true);
168+
ret find_library_crate_aux(nn2, crate_name, metas, library_search_paths);
169+
}
170+
171+
fn find_library_crate_aux(&rec(str prefix, str suffix) nn, str crate_name,
172+
&(@ast::meta_item)[] metas,
173+
&vec[str] library_search_paths) ->
174+
option::t[tup(str, vec[u8])] {
162175
let str prefix = nn.prefix + crate_name;
163176
// FIXME: we could probably use a 'glob' function in std::fs but it will
164177
// be much easier to write once the unsafe module knows more about FFI

0 commit comments

Comments
 (0)