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.
This commit is contained in:
Johannes Altmanninger
2025-04-01 17:22:11 +02:00
parent ec1c2473c2
commit 2719ae443b
6 changed files with 16 additions and 10 deletions

View File

@@ -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<bool, Box<dyn Error>> {
Ok(cfg!(any(target_os = "ios", target_os = "macos")))
}
#[allow(unexpected_cfgs)]
fn detect_cygwin(_: &Target) -> Result<bool, Box<dyn Error>> {
Ok(cfg!(target_os = "cygwin"))
}
/// Detect if we're being compiled for a BSD-derived OS, allowing targeting code conditionally with
/// `#[cfg(bsd)]`.
///

View File

@@ -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 <https://github.com/Microsoft/BashOnWindows/issues/545>
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)

View File

@@ -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);

View File

@@ -32,7 +32,7 @@
static WC_LOOKUP_TABLE: Lazy<WcLookupTable> = 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

View File

@@ -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();

View File

@@ -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;
}