Skip to content

Commit

Permalink
Support native library modifiers (RFC 2951)
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed May 17, 2022
1 parent fba7fed commit 9efa25c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ pub struct Build {
compiler: Option<PathBuf>,
archiver: Option<PathBuf>,
cargo_metadata: bool,
link_lib_modifiers: Option<String>,
pic: Option<bool>,
use_plt: Option<bool>,
static_crt: Option<bool>,
Expand Down Expand Up @@ -312,6 +313,7 @@ impl Build {
compiler: None,
archiver: None,
cargo_metadata: true,
link_lib_modifiers: None,
pic: None,
use_plt: None,
static_crt: None,
Expand Down Expand Up @@ -898,6 +900,16 @@ impl Build {
self
}

/// Configures native library modifiers 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_modifiers(&mut self, link_lib_modifiers: Option<&str>) -> &mut Build {
self.link_lib_modifiers = link_lib_modifiers.map(ToString::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
Expand Down Expand Up @@ -1014,7 +1026,10 @@ impl Build {
}
}

self.print(&format!("cargo:rustc-link-lib=static={}", lib_name));
match &self.link_lib_modifiers {
Some(m) => self.print(&format!("cargo:rustc-link-lib=static:{}={}", m, lib_name)),
None => self.print(&format!("cargo:rustc-link-lib=static={}", lib_name)),
}
self.print(&format!("cargo:rustc-link-search=native={}", dst.display()));

// Add specific C++ libraries, if enabled.
Expand Down

0 comments on commit 9efa25c

Please sign in to comment.