diff --git a/src/lib.rs b/src/lib.rs index 6865dd6..d5980c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -98,7 +98,7 @@ pub struct Library { pub frameworks: Vec, pub framework_paths: Vec, pub include_paths: Vec, - pub ld_options: Vec, + pub ld_options: Vec>, pub defines: HashMap>, pub version: String, _priv: (), @@ -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()); } } diff --git a/tests/test.rs b/tests/test.rs index b3efbd7..e3537b4 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -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(),])); }