Skip to content

Commit

Permalink
sys: permit disabling static linking
Browse files Browse the repository at this point in the history
This commit makes it so that if PCRE2_SYS_STATIC is explicitly set to 0,
then no static linking will occur. If PCRE2_SYS_STATIC isn't set, then
static linking will continue to be automatically enabled on MUSL
targets.

Fixes #7
  • Loading branch information
BurntSushi committed Jun 9, 2019
1 parent cef0bf2 commit 47f886d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 3 additions & 1 deletion pcre2-sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ PCRE2 system library. If that isn't available or if static linking is desired,
then PCRE2 is built from source and statically linked.

Static linking will automatically happen for MUSL targets, but can be forced by
setting the `PCRE2_SYS_STATIC` environment variable to `1`.
setting the `PCRE2_SYS_STATIC` environment variable to `1`. Similarly, if
`PCRE2_SYS_STATIC` is set to `0`, then static linking will be forcefully
disabled, even for MUSL targets.

Currently, this crate only supports `libpcre-8` where
`PCRE2_CODE_UNIT_WIDTH=8`.
Expand Down
19 changes: 16 additions & 3 deletions pcre2-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ fn main() {
let out = PathBuf::from(env::var_os("OUT_DIR").unwrap());

// Don't link to a system library if we want a static build.
let want_static =
env::var("PCRE2_SYS_STATIC").unwrap_or(String::new()) == "1"
|| target.contains("musl");
let want_static = pcre2_sys_static().unwrap_or(target.contains("musl"));
if !want_static && pkg_config::probe_library("libpcre2-8").is_ok() {
return;
}
Expand Down Expand Up @@ -138,3 +136,18 @@ fn has_git() -> bool {
.map(|s| s.success())
.unwrap_or(false)
}

fn pcre2_sys_static() -> Option<bool> {
match env::var("PCRE2_SYS_STATIC") {
Err(_) => None,
Ok(s) => {
if s == "1" {
Some(true)
} else if s == "0" {
Some(false)
} else {
None
}
}
}
}

0 comments on commit 47f886d

Please sign in to comment.