Skip to content

Commit 55cc009

Browse files
author
eulegang
committed
Restructuring to support pass through ld options
1 parent 9465edd commit 55cc009

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/lib.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub struct Library {
9898
pub frameworks: Vec<String>,
9999
pub framework_paths: Vec<PathBuf>,
100100
pub include_paths: Vec<PathBuf>,
101-
pub rpaths: Vec<PathBuf>,
101+
pub ld_options: Vec<String>,
102102
pub defines: HashMap<String, Option<String>>,
103103
pub version: String,
104104
_priv: (),
@@ -558,7 +558,7 @@ impl Library {
558558
libs: Vec::new(),
559559
link_paths: Vec::new(),
560560
include_paths: Vec::new(),
561-
rpaths: Vec::new(),
561+
ld_options: Vec::new(),
562562
frameworks: Vec::new(),
563563
framework_paths: Vec::new(),
564564
defines: HashMap::new(),
@@ -669,16 +669,29 @@ impl Library {
669669
self.include_paths.push(PathBuf::from(inc));
670670
}
671671
}
672-
"-rpath" => {
673-
if let Some(rpath) = iter.next() {
674-
let meta = format!("rustc-link-arg=-Wl,-rpath,{}", rpath);
675-
config.print_metadata(&meta);
676-
self.rpaths.push(PathBuf::from(rpath));
677-
}
678-
}
679672
_ => (),
680673
}
681674
}
675+
676+
let mut linker_options = words
677+
.iter()
678+
.filter(|arg| arg.starts_with("-Wl,"))
679+
.filter(|arg| {
680+
let option = &arg[4..];
681+
for handled in &["-framework", "-isystem", "-iquote", "-idirafter"] {
682+
if option.starts_with(handled) {
683+
return false;
684+
}
685+
}
686+
687+
true
688+
});
689+
690+
while let Some(option) = linker_options.next() {
691+
let meta = format!("rustc-link-arg={}", option);
692+
config.print_metadata(&meta);
693+
self.ld_options.push(option.to_string());
694+
}
682695
}
683696

684697
fn parse_modversion(&mut self, output: &str) {

tests/test.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,5 +317,7 @@ fn rpath() {
317317
let _g = LOCK.lock();
318318
reset();
319319
let lib = find("rpath").unwrap();
320-
assert!(lib.rpaths.contains(&PathBuf::from("/usr/local/lib")));
320+
assert!(lib
321+
.ld_options
322+
.contains(&"-Wl,-rpath,/usr/local/lib".to_string()));
321323
}

0 commit comments

Comments
 (0)