Skip to content

Commit

Permalink
Ignoring already handled -Wl options, switching to comma split args
Browse files Browse the repository at this point in the history
  • Loading branch information
eulegang committed Mar 30, 2022
1 parent 55cc009 commit dfebb0f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
35 changes: 20 additions & 15 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 ld_options: Vec<String>,
pub ld_options: Vec<Vec<String>>,
pub defines: HashMap<String, Option<String>>,
pub version: String,
_priv: (),
Expand Down Expand Up @@ -673,24 +673,29 @@ impl Library {
}
}

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;
}
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 matches!(subopt, "-framework" | "-isystem" | "-iquote" | "idirafter") {
pop = true;
continue;
}

true
});
ld_option.push(subopt);
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,5 +319,5 @@ fn rpath() {
let lib = find("rpath").unwrap();
assert!(lib
.ld_options
.contains(&"-Wl,-rpath,/usr/local/lib".to_string()));
.contains(&vec!["-rpath".to_string(), "/usr/local/lib".to_string(),]));
}

0 comments on commit dfebb0f

Please sign in to comment.