Skip to content

Commit 47f886d

Browse files
committed
sys: permit disabling static linking
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
1 parent cef0bf2 commit 47f886d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

pcre2-sys/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ PCRE2 system library. If that isn't available or if static linking is desired,
4444
then PCRE2 is built from source and statically linked.
4545

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

4951
Currently, this crate only supports `libpcre-8` where
5052
`PCRE2_CODE_UNIT_WIDTH=8`.

pcre2-sys/build.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ fn main() {
6363
let out = PathBuf::from(env::var_os("OUT_DIR").unwrap());
6464

6565
// Don't link to a system library if we want a static build.
66-
let want_static =
67-
env::var("PCRE2_SYS_STATIC").unwrap_or(String::new()) == "1"
68-
|| target.contains("musl");
66+
let want_static = pcre2_sys_static().unwrap_or(target.contains("musl"));
6967
if !want_static && pkg_config::probe_library("libpcre2-8").is_ok() {
7068
return;
7169
}
@@ -138,3 +136,18 @@ fn has_git() -> bool {
138136
.map(|s| s.success())
139137
.unwrap_or(false)
140138
}
139+
140+
fn pcre2_sys_static() -> Option<bool> {
141+
match env::var("PCRE2_SYS_STATIC") {
142+
Err(_) => None,
143+
Ok(s) => {
144+
if s == "1" {
145+
Some(true)
146+
} else if s == "0" {
147+
Some(false)
148+
} else {
149+
None
150+
}
151+
}
152+
}
153+
}

0 commit comments

Comments
 (0)