Skip to content

Commit 66404f9

Browse files
authored
Merge pull request #131 from eulegang/master
Adding rpath support
2 parents d442626 + 225a4a7 commit 66404f9

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

src/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ pub struct Library {
9898
pub frameworks: Vec<String>,
9999
pub framework_paths: Vec<PathBuf>,
100100
pub include_paths: Vec<PathBuf>,
101+
pub ld_args: Vec<Vec<String>>,
101102
pub defines: HashMap<String, Option<String>>,
102103
pub version: String,
103104
_priv: (),
@@ -557,6 +558,7 @@ impl Library {
557558
libs: Vec::new(),
558559
link_paths: Vec::new(),
559560
include_paths: Vec::new(),
561+
ld_args: Vec::new(),
560562
frameworks: Vec::new(),
561563
framework_paths: Vec::new(),
562564
defines: HashMap::new(),
@@ -670,6 +672,31 @@ impl Library {
670672
_ => (),
671673
}
672674
}
675+
676+
let mut linker_options = words.iter().filter(|arg| arg.starts_with("-Wl,"));
677+
while let Some(option) = linker_options.next() {
678+
let mut pop = false;
679+
let mut ld_option = vec![];
680+
for subopt in option[4..].split(',') {
681+
if pop {
682+
pop = false;
683+
continue;
684+
}
685+
686+
if subopt == "-framework" {
687+
pop = true;
688+
continue;
689+
}
690+
691+
ld_option.push(subopt);
692+
}
693+
694+
let meta = format!("rustc-link-arg=-Wl,{}", ld_option.join(","));
695+
config.print_metadata(&meta);
696+
697+
self.ld_args
698+
.push(ld_option.into_iter().map(String::from).collect());
699+
}
673700
}
674701

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

tests/rpath.pc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
prefix=/usr/local
2+
3+
Name: rpath
4+
Version: 4.2.0
5+
Description: RPath example library
6+
Libs: -L${prefix}/lib -Wl,-rpath,${prefix}/lib -lrpath
7+
Cflags: -I${prefix}/include

tests/test.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,13 @@ fn range_version_full() {
311311
.probe("escape")
312312
.unwrap();
313313
}
314+
315+
#[test]
316+
fn rpath() {
317+
let _g = LOCK.lock();
318+
reset();
319+
let lib = find("rpath").unwrap();
320+
assert!(lib
321+
.ld_args
322+
.contains(&vec!["-rpath".to_string(), "/usr/local/lib".to_string(),]));
323+
}

0 commit comments

Comments
 (0)