From 6fded249cd191fdd19f41148adc3792960499dbf Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Sun, 8 Dec 2024 21:47:43 +0100 Subject: [PATCH] Enable gettext without the _nl_msg_cat_cntr gnuism This should allow e.g. musl to be translated. --- build.rs | 10 ++++++++-- src/env_dispatch.rs | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/build.rs b/build.rs index a81e1d07a..6aae715f1 100644 --- a/build.rs +++ b/build.rs @@ -84,6 +84,13 @@ fn detect_cfgs(target: &mut Target) { ), ("bsd", &detect_bsd), ("gettext", &have_gettext), + ("HAVE_NL_MSG_CAT_CNTR", &|target| { + Ok( + target.has_symbol_in("_nl_msg_cat_cntr", &["intl"]) + || + target.has_symbol_in("_nl_msg_cat_cntr", &["gettextlib"]) + ) + }), ("small_main_stack", &has_small_stack), // See if libc supports the thread-safe localeconv_l(3) alternative to localeconv(3). ("localeconv_l", &|target| { @@ -159,7 +166,7 @@ fn have_gettext(target: &Target) -> Result> { // symbol _nl_msg_cat_cntr, we cannot use gettext even if we find it. let mut libraries = Vec::new(); let mut found = 0; - let symbols = ["gettext", "_nl_msg_cat_cntr"]; + let symbols = ["gettext"]; for symbol in &symbols { // Historically, libintl was required in order to use gettext() and co, but that // functionality was subsumed by some versions of libc. @@ -178,7 +185,6 @@ fn have_gettext(target: &Target) -> Result> { } match found { 0 => Ok(false), - 1 => Err(format!("gettext found but cannot be used without {}", symbols[1]).into()), _ => { rsconf::link_libraries(&libraries, LinkType::Default); Ok(true) diff --git a/src/env_dispatch.rs b/src/env_dispatch.rs index 6a63b9bfe..2de631656 100644 --- a/src/env_dispatch.rs +++ b/src/env_dispatch.rs @@ -751,7 +751,7 @@ fn init_locale(vars: &EnvStack) { new_msg_locale.to_string_lossy() ); - #[cfg(gettext)] + #[cfg(all(gettext, HAVE_NL_MSG_CAT_CNTR))] { if old_msg_locale.as_c_str() != new_msg_locale { // Make change known to GNU gettext.