Skip to content

Commit 4d52bd2

Browse files
committed
Support native library modifiers (RFC 2951)
1 parent 53fb72c commit 4d52bd2

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/lib.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ pub struct Build {
114114
compiler: Option<PathBuf>,
115115
archiver: Option<PathBuf>,
116116
cargo_metadata: bool,
117+
link_lib_modifiers: Vec<String>,
117118
pic: Option<bool>,
118119
use_plt: Option<bool>,
119120
static_crt: Option<bool>,
@@ -312,6 +313,7 @@ impl Build {
312313
compiler: None,
313314
archiver: None,
314315
cargo_metadata: true,
316+
link_lib_modifiers: Vec::new(),
315317
pic: None,
316318
use_plt: None,
317319
static_crt: None,
@@ -898,6 +900,16 @@ impl Build {
898900
self
899901
}
900902

903+
/// Adds a native library modifier that will be added to the
904+
/// `rustc-link-lib=static:MODIFIERS=LIBRARY_NAME` metadata line
905+
/// emitted for cargo if `cargo_metadata` is enabled.
906+
/// See https://doc.rust-lang.org/rustc/command-line-arguments.html#-l-link-the-generated-crate-to-a-native-library
907+
/// for the list of modifiers accepted by rustc.
908+
pub fn link_lib_modifier(&mut self, link_lib_modifier: &str) -> &mut Build {
909+
self.link_lib_modifiers.push(link_lib_modifier.to_string());
910+
self
911+
}
912+
901913
/// Configures whether the compiler will emit position independent code.
902914
///
903915
/// This option defaults to `false` for `windows-gnu` and bare metal targets and
@@ -1014,7 +1026,12 @@ impl Build {
10141026
}
10151027
}
10161028

1017-
self.print(&format!("cargo:rustc-link-lib=static={}", lib_name));
1029+
if self.link_lib_modifiers.is_empty() {
1030+
self.print(&format!("cargo:rustc-link-lib=static={}", lib_name));
1031+
} else {
1032+
let m = self.link_lib_modifiers.join(",");
1033+
self.print(&format!("cargo:rustc-link-lib=static:{}={}", m, lib_name));
1034+
}
10181035
self.print(&format!("cargo:rustc-link-search=native={}", dst.display()));
10191036

10201037
// Add specific C++ libraries, if enabled.

0 commit comments

Comments
 (0)