rustc: Add search paths to dylib load paths
When a syntax extension is loaded by the compiler, the dylib that is opened may have other dylibs that it depends on. The dynamic linker must be able to find these libraries on the system or else the library will fail to load. Currently, unix gets by with the use of rpaths. This relies on the dylib not moving around too drastically relative to its dependencies. For windows, however, this is no rpath available, and in theory unix should work without rpaths as well. This modifies the compiler to add all -L search directories to the dynamic linker's set of load paths. This is currently managed through environment variables for each platform. Closes #13848
This commit is contained in:
parent
a1ad41b93d
commit
1a367c62cd
7 changed files with 114 additions and 3 deletions
|
|
@ -15,12 +15,16 @@ Dynamic library facilities.
|
|||
A simple wrapper over the platform's dynamic library facilities
|
||||
|
||||
*/
|
||||
|
||||
use c_str::ToCStr;
|
||||
use cast;
|
||||
use path;
|
||||
use ops::*;
|
||||
use option::*;
|
||||
use os;
|
||||
use path::GenericPath;
|
||||
use path;
|
||||
use result::*;
|
||||
use str;
|
||||
|
||||
pub struct DynamicLibrary { handle: *u8}
|
||||
|
||||
|
|
@ -59,6 +63,20 @@ impl DynamicLibrary {
|
|||
}
|
||||
}
|
||||
|
||||
/// Appends a path to the system search path for dynamic libraries
|
||||
pub fn add_search_path(path: &path::Path) {
|
||||
let (envvar, sep) = if cfg!(windows) {
|
||||
("PATH", ';' as u8)
|
||||
} else if cfg!(target_os = "macos") {
|
||||
("DYLD_LIBRARY_PATH", ':' as u8)
|
||||
} else {
|
||||
("LD_LIBRARY_PATH", ':' as u8)
|
||||
};
|
||||
let newenv = os::getenv_as_bytes(envvar).unwrap_or(~[]);
|
||||
let newenv = newenv + &[sep] + path.as_vec();
|
||||
os::setenv(envvar, str::from_utf8(newenv).unwrap());
|
||||
}
|
||||
|
||||
/// Access the value at the symbol of the dynamic library
|
||||
pub unsafe fn symbol<T>(&self, symbol: &str) -> Result<T, ~str> {
|
||||
// This function should have a lifetime constraint of 'a on
|
||||
|
|
@ -237,7 +255,6 @@ pub mod dl {
|
|||
FreeLibrary(handle as *libc::c_void); ()
|
||||
}
|
||||
|
||||
#[link_name = "kernel32"]
|
||||
extern "system" {
|
||||
fn SetLastError(error: libc::size_t);
|
||||
fn LoadLibraryW(name: *libc::c_void) -> *libc::c_void;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue