From 4d52bd211aeb2b4ddccd1b9c0a0841e03aaaef7c Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 2 Apr 2022 12:02:50 +0300 Subject: [PATCH] Support native library modifiers (RFC 2951) --- src/lib.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 30ebc9212..3282a716c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,6 +114,7 @@ pub struct Build { compiler: Option, archiver: Option, cargo_metadata: bool, + link_lib_modifiers: Vec, pic: Option, use_plt: Option, static_crt: Option, @@ -312,6 +313,7 @@ impl Build { compiler: None, archiver: None, cargo_metadata: true, + link_lib_modifiers: Vec::new(), pic: None, use_plt: None, static_crt: None, @@ -898,6 +900,16 @@ impl Build { self } + /// Adds a native library modifier that will be added to the + /// `rustc-link-lib=static:MODIFIERS=LIBRARY_NAME` metadata line + /// emitted for cargo if `cargo_metadata` is enabled. + /// See https://doc.rust-lang.org/rustc/command-line-arguments.html#-l-link-the-generated-crate-to-a-native-library + /// for the list of modifiers accepted by rustc. + pub fn link_lib_modifier(&mut self, link_lib_modifier: &str) -> &mut Build { + self.link_lib_modifiers.push(link_lib_modifier.to_string()); + self + } + /// Configures whether the compiler will emit position independent code. /// /// This option defaults to `false` for `windows-gnu` and bare metal targets and @@ -1014,7 +1026,12 @@ impl Build { } } - self.print(&format!("cargo:rustc-link-lib=static={}", lib_name)); + if self.link_lib_modifiers.is_empty() { + self.print(&format!("cargo:rustc-link-lib=static={}", lib_name)); + } else { + let m = self.link_lib_modifiers.join(","); + self.print(&format!("cargo:rustc-link-lib=static:{}={}", m, lib_name)); + } self.print(&format!("cargo:rustc-link-search=native={}", dst.display())); // Add specific C++ libraries, if enabled.