From 9465edd6a2f1c8b5ae4f2e6a8be931b0f7d96d2c Mon Sep 17 00:00:00 2001 From: eulegang Date: Mon, 28 Mar 2022 17:34:30 -0500 Subject: [PATCH 1/7] Adding rpath support --- src/lib.rs | 9 +++++++++ tests/rpath.pc | 7 +++++++ tests/test.rs | 8 ++++++++ 3 files changed, 24 insertions(+) create mode 100644 tests/rpath.pc diff --git a/src/lib.rs b/src/lib.rs index daf5d0c..0d7c0b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -98,6 +98,7 @@ pub struct Library { pub frameworks: Vec, pub framework_paths: Vec, pub include_paths: Vec, + pub rpaths: Vec, pub defines: HashMap>, pub version: String, _priv: (), @@ -557,6 +558,7 @@ impl Library { libs: Vec::new(), link_paths: Vec::new(), include_paths: Vec::new(), + rpaths: Vec::new(), frameworks: Vec::new(), framework_paths: Vec::new(), defines: HashMap::new(), @@ -667,6 +669,13 @@ impl Library { self.include_paths.push(PathBuf::from(inc)); } } + "-rpath" => { + if let Some(rpath) = iter.next() { + let meta = format!("rustc-link-arg=-Wl,-rpath,{}", rpath); + config.print_metadata(&meta); + self.rpaths.push(PathBuf::from(rpath)); + } + } _ => (), } } diff --git a/tests/rpath.pc b/tests/rpath.pc new file mode 100644 index 0000000..7c36c5c --- /dev/null +++ b/tests/rpath.pc @@ -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 diff --git a/tests/test.rs b/tests/test.rs index 333b958..3a09eff 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -311,3 +311,11 @@ fn range_version_full() { .probe("escape") .unwrap(); } + +#[test] +fn rpath() { + let _g = LOCK.lock(); + reset(); + let lib = find("rpath").unwrap(); + assert!(lib.rpaths.contains(&PathBuf::from("/usr/local/lib"))); +} From 55cc009638e95bd1403c073f2dcd21503cf993ff Mon Sep 17 00:00:00 2001 From: eulegang Date: Tue, 29 Mar 2022 18:15:51 -0500 Subject: [PATCH 2/7] Restructuring to support pass through ld options --- src/lib.rs | 31 ++++++++++++++++++++++--------- tests/test.rs | 4 +++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0d7c0b2..6865dd6 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 rpaths: Vec, + pub ld_options: Vec, pub defines: HashMap>, pub version: String, _priv: (), @@ -558,7 +558,7 @@ impl Library { libs: Vec::new(), link_paths: Vec::new(), include_paths: Vec::new(), - rpaths: Vec::new(), + ld_options: Vec::new(), frameworks: Vec::new(), framework_paths: Vec::new(), defines: HashMap::new(), @@ -669,16 +669,29 @@ impl Library { self.include_paths.push(PathBuf::from(inc)); } } - "-rpath" => { - if let Some(rpath) = iter.next() { - let meta = format!("rustc-link-arg=-Wl,-rpath,{}", rpath); - config.print_metadata(&meta); - self.rpaths.push(PathBuf::from(rpath)); - } - } _ => (), } } + + 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; + } + } + + true + }); + + while let Some(option) = linker_options.next() { + let meta = format!("rustc-link-arg={}", option); + config.print_metadata(&meta); + self.ld_options.push(option.to_string()); + } } fn parse_modversion(&mut self, output: &str) { diff --git a/tests/test.rs b/tests/test.rs index 3a09eff..b3efbd7 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -317,5 +317,7 @@ fn rpath() { let _g = LOCK.lock(); reset(); let lib = find("rpath").unwrap(); - assert!(lib.rpaths.contains(&PathBuf::from("/usr/local/lib"))); + assert!(lib + .ld_options + .contains(&"-Wl,-rpath,/usr/local/lib".to_string())); } From dfebb0f72bdbb1df5acf9911c8ad654707238932 Mon Sep 17 00:00:00 2001 From: eulegang Date: Tue, 29 Mar 2022 20:55:54 -0500 Subject: [PATCH 3/7] Ignoring already handled -Wl options, switching to comma split args --- src/lib.rs | 35 ++++++++++++++++++++--------------- tests/test.rs | 2 +- 2 files changed, 21 insertions(+), 16 deletions(-) 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(),])); } From f5731f7a15f2a495e8f3613c4b2302a61975efc4 Mon Sep 17 00:00:00 2001 From: eulegang Date: Tue, 29 Mar 2022 21:00:54 -0500 Subject: [PATCH 4/7] Fixing matches! macro support --- src/lib.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d5980c7..dbd9cce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -683,9 +683,13 @@ impl Library { continue; } - if matches!(subopt, "-framework" | "-isystem" | "-iquote" | "idirafter") { - pop = true; - continue; + match subopt { + "-framework" | "-isystem" | "-iquote" | "idirafter" => { + pop = true; + continue; + } + + _ => (), } ld_option.push(subopt); From 90b9291a5e063c5b9b44c61ad7be1f2d1830bfd7 Mon Sep 17 00:00:00 2001 From: eulegang Date: Tue, 29 Mar 2022 21:05:41 -0500 Subject: [PATCH 5/7] retriggering ci From 337d9a91773a4fb42eeea023f48cc4a90894ef0c Mon Sep 17 00:00:00 2001 From: eulegang Date: Wed, 30 Mar 2022 17:46:37 -0500 Subject: [PATCH 6/7] renaming ld_options -> ld_args --- src/lib.rs | 6 +++--- tests/test.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index dbd9cce..a6603e9 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_args: Vec>, pub defines: HashMap>, pub version: String, _priv: (), @@ -558,7 +558,7 @@ impl Library { libs: Vec::new(), link_paths: Vec::new(), include_paths: Vec::new(), - ld_options: Vec::new(), + ld_args: Vec::new(), frameworks: Vec::new(), framework_paths: Vec::new(), defines: HashMap::new(), @@ -698,7 +698,7 @@ impl Library { let meta = format!("rustc-link-arg=-Wl,{}", ld_option.join(",")); config.print_metadata(&meta); - self.ld_options + self.ld_args .push(ld_option.into_iter().map(String::from).collect()); } } diff --git a/tests/test.rs b/tests/test.rs index e3537b4..4e04ac0 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -318,6 +318,6 @@ fn rpath() { reset(); let lib = find("rpath").unwrap(); assert!(lib - .ld_options + .ld_args .contains(&vec!["-rpath".to_string(), "/usr/local/lib".to_string(),])); } From 225a4a7f359cf4a673cd14a2f8871d52d49cb921 Mon Sep 17 00:00:00 2001 From: eulegang Date: Wed, 30 Mar 2022 17:51:18 -0500 Subject: [PATCH 7/7] Removing header include flags in linker args handler --- src/lib.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a6603e9..a28304e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -683,13 +683,9 @@ impl Library { continue; } - match subopt { - "-framework" | "-isystem" | "-iquote" | "idirafter" => { - pop = true; - continue; - } - - _ => (), + if subopt == "-framework" { + pop = true; + continue; } ld_option.push(subopt);