From 15b216c6653767714956d6da1f79e5c2344fe316 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Mon, 20 May 2024 19:44:06 -0500 Subject: [PATCH] Match upstream PCRE2_SYS_STATIC env variable behavior Upstream pcre2-sys crate has tri-state behavior for the PCRE2_SYS_STATIC environment variable, where 0 is force dynamic linking, 1 is force static linking, otherwise it is based off the heuristic. We *do* have the STATIC_PCRE2 feature that upstream doesn't have, but the benefit of an environment variable is that a) it can be set for transitive dependencies, b) it can be set without modifying any code or even locally checking out the project. This does effectively give PCRE2_SYS_STATIC=0 a veto over the STATIC_PCRE2 feature, but that's probably preferable since it gives maximum control to the person ultimately building the downstream app (i.e. fish). --- pcre2-sys/build.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pcre2-sys/build.rs b/pcre2-sys/build.rs index 72dcc6b..96d7eb3 100644 --- a/pcre2-sys/build.rs +++ b/pcre2-sys/build.rs @@ -130,7 +130,8 @@ fn feature_enabled(feature: &str) -> bool { fn main() { let do_utf8 = feature_enabled("UTF8"); let do_utf32 = feature_enabled("UTF32"); - let wants_static = feature_enabled("STATIC_PCRE2"); + let wants_static = + feature_enabled("STATIC_PCRE2") || env::var_os("PCRE2_SYS_STATIC") == Some("1".into()); if !do_utf8 && !do_utf32 { panic!("Must enable at least one of the UTF8 or UTF32 features"); @@ -140,10 +141,11 @@ fn main() { let target = env::var("TARGET").unwrap(); // Don't link to a system library if we want a static build. - let do_static = wants_static + let do_static = (wants_static || target.contains("musl") || (do_utf8 && pkg_config::probe_library("libpcre2-8").is_err()) - || (do_utf32 && pkg_config::probe_library("libpcre2-32").is_err()); + || (do_utf32 && pkg_config::probe_library("libpcre2-32").is_err())) + && env::var_os("PCRE2_SYS_STATIC") != Some("0".into()); if !do_static { return; }