Skip to content

Commit

Permalink
Merge pull request #131 from eulegang/master
Browse files Browse the repository at this point in the history
Adding rpath support
  • Loading branch information
sdroege committed Mar 31, 2022
2 parents d442626 + 225a4a7 commit 66404f9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub struct Library {
pub frameworks: Vec<String>,
pub framework_paths: Vec<PathBuf>,
pub include_paths: Vec<PathBuf>,
pub ld_args: Vec<Vec<String>>,
pub defines: HashMap<String, Option<String>>,
pub version: String,
_priv: (),
Expand Down Expand Up @@ -557,6 +558,7 @@ impl Library {
libs: Vec::new(),
link_paths: Vec::new(),
include_paths: Vec::new(),
ld_args: Vec::new(),
frameworks: Vec::new(),
framework_paths: Vec::new(),
defines: HashMap::new(),
Expand Down Expand Up @@ -670,6 +672,31 @@ impl Library {
_ => (),
}
}

let mut linker_options = words.iter().filter(|arg| arg.starts_with("-Wl,"));
while let Some(option) = linker_options.next() {
let mut pop = false;
let mut ld_option = vec![];
for subopt in option[4..].split(',') {
if pop {
pop = false;
continue;
}

if subopt == "-framework" {
pop = true;
continue;
}

ld_option.push(subopt);
}

let meta = format!("rustc-link-arg=-Wl,{}", ld_option.join(","));
config.print_metadata(&meta);

self.ld_args
.push(ld_option.into_iter().map(String::from).collect());
}
}

fn parse_modversion(&mut self, output: &str) {
Expand Down
7 changes: 7 additions & 0 deletions tests/rpath.pc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
prefix=/usr/local

Name: rpath
Version: 4.2.0
Description: RPath example library
Libs: -L${prefix}/lib -Wl,-rpath,${prefix}/lib -lrpath
Cflags: -I${prefix}/include
10 changes: 10 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,13 @@ fn range_version_full() {
.probe("escape")
.unwrap();
}

#[test]
fn rpath() {
let _g = LOCK.lock();
reset();
let lib = find("rpath").unwrap();
assert!(lib
.ld_args
.contains(&vec!["-rpath".to_string(), "/usr/local/lib".to_string(),]));
}

0 comments on commit 66404f9

Please sign in to comment.