Skip to content

Commit dfebb0f

Browse files
author
eulegang
committed
Ignoring already handled -Wl options, switching to comma split args
1 parent 55cc009 commit dfebb0f

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

src/lib.rs

Lines changed: 20 additions & 15 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 ld_options: Vec<String>,
101+
pub ld_options: Vec<Vec<String>>,
102102
pub defines: HashMap<String, Option<String>>,
103103
pub version: String,
104104
_priv: (),
@@ -673,24 +673,29 @@ impl Library {
673673
}
674674
}
675675

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

687-
true
688-
});
691+
ld_option.push(subopt);
692+
}
689693

690-
while let Some(option) = linker_options.next() {
691-
let meta = format!("rustc-link-arg={}", option);
694+
let meta = format!("rustc-link-arg=-Wl,{}", ld_option.join(","));
692695
config.print_metadata(&meta);
693-
self.ld_options.push(option.to_string());
696+
697+
self.ld_options
698+
.push(ld_option.into_iter().map(String::from).collect());
694699
}
695700
}
696701

tests/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,5 +319,5 @@ fn rpath() {
319319
let lib = find("rpath").unwrap();
320320
assert!(lib
321321
.ld_options
322-
.contains(&"-Wl,-rpath,/usr/local/lib".to_string()));
322+
.contains(&vec!["-rpath".to_string(), "/usr/local/lib".to_string(),]));
323323
}

0 commit comments

Comments
 (0)