Be more strategic about linking to rust crates
Instead of linking directly to the rust crate, try to figure out the location and name of the library from the file name, then call gcc with appropriate -L, -l flags. This will allow dynamic linking to be more forgiving about where it loads the library from at runtime - currently a stage3 compiler can't run correctly from the stage0 directory. Only tested on Linux. Fingers crossed.
This commit is contained in:
parent
e130e7b598
commit
190644063e
@ -419,12 +419,37 @@ fn main(vec[str] args) {
|
||||
}
|
||||
}
|
||||
|
||||
// Converts a library file name into a gcc -l argument
|
||||
fn unlib(@session::config config, str filename) -> str {
|
||||
auto rmlib = bind fn(@session::config config,
|
||||
str filename) -> str {
|
||||
if (config.os == session::os_macos
|
||||
|| config.os == session::os_linux
|
||||
&& str::find(filename, "lib") == 0) {
|
||||
ret str::slice(filename, 3u, str::byte_len(filename));
|
||||
} else {
|
||||
ret filename;
|
||||
}
|
||||
} (config, _);
|
||||
fn rmext(str filename) -> str {
|
||||
auto parts = str::split(filename, '.' as u8);
|
||||
vec::pop(parts);
|
||||
ret str::connect(parts, ".");
|
||||
}
|
||||
ret alt (config.os) {
|
||||
case (session::os_macos) { rmext(rmlib(filename)) }
|
||||
case (session::os_linux) { rmext(rmlib(filename)) }
|
||||
case (_) { rmext(filename) }
|
||||
};
|
||||
}
|
||||
|
||||
for (str cratepath in sess.get_used_crate_files()) {
|
||||
auto dir = fs::dirname(cratepath);
|
||||
if (dir != "") {
|
||||
gcc_args += ["-L" + dir];
|
||||
}
|
||||
gcc_args += [fs::basename(cratepath)];
|
||||
auto libarg = unlib(sess.get_targ_cfg(), fs::basename(cratepath));
|
||||
gcc_args += ["-l" + libarg];
|
||||
}
|
||||
|
||||
auto used_libs = sess.get_used_libraries();
|
||||
|
@ -83,7 +83,9 @@ fn find_library_crate(&session::session sess, &ast::ident ident,
|
||||
// manually filtering fs::list_dir here.
|
||||
|
||||
for (str library_search_path in library_search_paths) {
|
||||
log #fmt("searching %s", library_search_path);
|
||||
for (str path in fs::list_dir(library_search_path)) {
|
||||
log #fmt("searching %s", path);
|
||||
let str f = fs::basename(path);
|
||||
if (!(str::starts_with(f, prefix) &&
|
||||
str::ends_with(f, nn.suffix))) {
|
||||
|
Loading…
Reference in New Issue
Block a user