Skip to content

Commit

Permalink
Restructuring to support pass through ld options
Browse files Browse the repository at this point in the history
  • Loading branch information
eulegang committed Mar 29, 2022
1 parent 9465edd commit 55cc009
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
31 changes: 22 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub struct Library {
pub frameworks: Vec<String>,
pub framework_paths: Vec<PathBuf>,
pub include_paths: Vec<PathBuf>,
pub rpaths: Vec<PathBuf>,
pub ld_options: Vec<String>,
pub defines: HashMap<String, Option<String>>,
pub version: String,
_priv: (),
Expand Down Expand Up @@ -558,7 +558,7 @@ impl Library {
libs: Vec::new(),
link_paths: Vec::new(),
include_paths: Vec::new(),
rpaths: Vec::new(),
ld_options: Vec::new(),
frameworks: Vec::new(),
framework_paths: Vec::new(),
defines: HashMap::new(),
Expand Down Expand Up @@ -669,16 +669,29 @@ impl Library {
self.include_paths.push(PathBuf::from(inc));
}
}
"-rpath" => {
if let Some(rpath) = iter.next() {
let meta = format!("rustc-link-arg=-Wl,-rpath,{}", rpath);
config.print_metadata(&meta);
self.rpaths.push(PathBuf::from(rpath));
}
}
_ => (),
}
}

let mut linker_options = words
.iter()
.filter(|arg| arg.starts_with("-Wl,"))
.filter(|arg| {
let option = &arg[4..];
for handled in &["-framework", "-isystem", "-iquote", "-idirafter"] {
if option.starts_with(handled) {
return false;
}
}

true
});

while let Some(option) = linker_options.next() {
let meta = format!("rustc-link-arg={}", option);
config.print_metadata(&meta);
self.ld_options.push(option.to_string());
}
}

fn parse_modversion(&mut self, output: &str) {
Expand Down
4 changes: 3 additions & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,5 +317,7 @@ fn rpath() {
let _g = LOCK.lock();
reset();
let lib = find("rpath").unwrap();
assert!(lib.rpaths.contains(&PathBuf::from("/usr/local/lib")));
assert!(lib
.ld_options
.contains(&"-Wl,-rpath,/usr/local/lib".to_string()));
}

0 comments on commit 55cc009

Please sign in to comment.