From 2719ae443b8f908cc7e83d9475d8c8ddda8973fa Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 1 Apr 2025 17:22:11 +0200 Subject: [PATCH] Silence unexpected_cfgs error about unknown cygwin target Extract our own cfg value, to avoid noisy warnings like: warning: unexpected `cfg` condition value: `cygwin` --> src/fallback.rs:78:23 | 78 | #[cfg(not(target_os = "cygwin"))] | ^^^^^^^^^^^^^^^^^^^^ | The cygwin target will be added to Rust 1.86, so we can get rid of this after some time. --- build.rs | 6 ++++++ src/common.rs | 2 +- src/env_dispatch.rs | 4 ++-- src/fallback.rs | 8 ++++---- src/tests/topic_monitor.rs | 2 +- src/wutil/encoding.rs | 4 ++-- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/build.rs b/build.rs index 4a7fe027e..c9fc8814e 100644 --- a/build.rs +++ b/build.rs @@ -90,6 +90,7 @@ fn detect_cfgs(target: &mut Target) { ), ("apple", &detect_apple), ("bsd", &detect_bsd), + ("cygwin", &detect_cygwin), ("gettext", &have_gettext), ("small_main_stack", &has_small_stack), // See if libc supports the thread-safe localeconv_l(3) alternative to localeconv(3). @@ -128,6 +129,11 @@ fn detect_apple(_: &Target) -> Result> { Ok(cfg!(any(target_os = "ios", target_os = "macos"))) } +#[allow(unexpected_cfgs)] +fn detect_cygwin(_: &Target) -> Result> { + Ok(cfg!(target_os = "cygwin")) +} + /// Detect if we're being compiled for a BSD-derived OS, allowing targeting code conditionally with /// `#[cfg(bsd)]`. /// diff --git a/src/common.rs b/src/common.rs index 60468fdfc..2457691e7 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1072,7 +1072,7 @@ pub fn get_obfuscation_read_char() -> char { /// the multiline prompt usable. See [#2859](https://github.com/fish-shell/fish-shell/issues/2859) /// and pub fn has_working_tty_timestamps() -> bool { - if cfg!(any(target_os = "windows", target_os = "cygwin")) { + if cfg!(any(target_os = "windows", cygwin)) { false } else if cfg!(target_os = "linux") { !is_windows_subsystem_for_linux(WSL::V1) diff --git a/src/env_dispatch.rs b/src/env_dispatch.rs index 0a8caad06..ba9cf8756 100644 --- a/src/env_dispatch.rs +++ b/src/env_dispatch.rs @@ -199,9 +199,9 @@ fn guess_emoji_width(vars: &EnvStack) { } else { // Default to whatever the system's wcwidth gives for U+1F603, but only if it's at least // 1 and at most 2. - #[cfg(not(target_os = "cygwin"))] + #[cfg(not(cygwin))] let width = crate::fallback::wcwidth('😃').clamp(1, 2); - #[cfg(target_os = "cygwin")] + #[cfg(cygwin)] let width = 2_isize; FISH_EMOJI_WIDTH.store(width, Ordering::Relaxed); FLOG!(term_support, "default emoji width:", width); diff --git a/src/fallback.rs b/src/fallback.rs index a93da3e57..f39b2e22f 100644 --- a/src/fallback.rs +++ b/src/fallback.rs @@ -32,7 +32,7 @@ static WC_LOOKUP_TABLE: Lazy = Lazy::new(WcLookupTable::new); /// A safe wrapper around the system `wcwidth()` function -#[cfg(not(target_os = "cygwin"))] +#[cfg(not(cygwin))] pub fn wcwidth(c: char) -> isize { extern "C" { pub fn wcwidth(c: libc::wchar_t) -> libc::c_int; @@ -49,7 +49,7 @@ pub fn fish_wcwidth(c: char) -> isize { // The system version of wcwidth should accurately reflect the ability to represent characters // in the console session, but knows nothing about the capabilities of other terminal emulators // or ttys. Use it from the start only if we are logged in to the physical console. - #[cfg(not(target_os = "cygwin"))] + #[cfg(not(cygwin))] if crate::common::is_console_session() { return wcwidth(c); } @@ -75,12 +75,12 @@ pub fn fish_wcwidth(c: char) -> isize { let width = WC_LOOKUP_TABLE.classify(c); match width { WcWidth::NonCharacter | WcWidth::NonPrint | WcWidth::Combining | WcWidth::Unassigned => { - #[cfg(not(target_os = "cygwin"))] + #[cfg(not(cygwin))] { // Fall back to system wcwidth in this case. wcwidth(c) } - #[cfg(target_os = "cygwin")] + #[cfg(cygwin)] { // No system wcwidth for UTF-32 on cygwin. 0 diff --git a/src/tests/topic_monitor.rs b/src/tests/topic_monitor.rs index 32b9936ad..333c7c03c 100644 --- a/src/tests/topic_monitor.rs +++ b/src/tests/topic_monitor.rs @@ -38,7 +38,7 @@ fn test_topic_monitor() { #[test] // FIXME: Does not compile on NetBSD & Cygwin // "`*mut sem` cannot be sent between threads safely" -#[cfg(not(any(target_os = "netbsd", target_os = "cygwin")))] +#[cfg(not(any(target_os = "netbsd", cygwin)))] #[serial] fn test_topic_monitor_torture() { let _cleanup = test_init(); diff --git a/src/wutil/encoding.rs b/src/wutil/encoding.rs index 66384ae12..6400cd78b 100644 --- a/src/wutil/encoding.rs +++ b/src/wutil/encoding.rs @@ -1,7 +1,7 @@ extern "C" { - #[cfg_attr(target_os = "cygwin", link_name = "c32rtomb")] + #[cfg_attr(cygwin, link_name = "c32rtomb")] pub fn wcrtomb(s: *mut libc::c_char, wc: u32, ps: *mut mbstate_t) -> usize; - #[cfg_attr(target_os = "cygwin", link_name = "mbrtoc32")] + #[cfg_attr(cygwin, link_name = "mbrtoc32")] pub fn mbrtowc(pwc: *mut u32, s: *const libc::c_char, n: usize, p: *mut mbstate_t) -> usize; }