From 39fd8e4adfcd7e7ada156d122e76a29bcd0ae35d Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 21 Sep 2025 20:20:41 -0300 Subject: [PATCH] cygwin: init as a target toolchain The old cygwin support used -pc-windows-cygnus as the config. This is supported by LLVM, but not by GNU. This will change it to -pc-cygwin, which is more generally supported. Because the kernel is now 'cygwin' rather than 'windows', isWindows will return false. There are lots of different reasons isWindows is used in nixpkgs, but in my experience they often have to do with posix compatibility and don't apply to cygwin. Co-authored-by: Brian McKenna --- lib/systems/default.nix | 9 ++++++--- lib/systems/examples.nix | 4 ++++ lib/systems/inspect.nix | 3 +-- lib/systems/parse.nix | 32 +++++++++++++++++++------------- lib/tests/systems.nix | 3 +-- 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/lib/systems/default.nix b/lib/systems/default.nix index 77247d269808..d84cfccd46f6 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -124,6 +124,8 @@ let "ucrt" else if final.isMinGW then "msvcrt" + else if final.isCygwin then + "cygwin" else if final.isWasi then "wasilibc" else if final.isWasm && !final.isWasi then @@ -183,7 +185,7 @@ let sharedLibrary = if final.isDarwin then ".dylib" - else if final.isWindows then + else if (final.isWindows || final.isCygwin) then ".dll" else ".so"; @@ -191,7 +193,7 @@ let // { staticLibrary = if final.isWindows then ".lib" else ".a"; library = if final.isStatic then final.extensions.staticLibrary else final.extensions.sharedLibrary; - executable = if final.isWindows then ".exe" else ""; + executable = if (final.isWindows || final.isCygwin) then ".exe" else ""; }; # Misc boolean options useAndroidPrebuilt = false; @@ -204,6 +206,7 @@ let { linux = "Linux"; windows = "Windows"; + cygwin = "CYGWIN_NT"; darwin = "Darwin"; netbsd = "NetBSD"; freebsd = "FreeBSD"; @@ -603,7 +606,7 @@ let "openbsd" else if final.isSunOS then "sunos" - else if final.isWindows then + else if (final.isWindows || final.isCygwin) then "win32" else null; diff --git a/lib/systems/examples.nix b/lib/systems/examples.nix index 9a53dac073ae..cdd28b1ddde1 100644 --- a/lib/systems/examples.nix +++ b/lib/systems/examples.nix @@ -388,6 +388,10 @@ rec { useLLVM = true; }; + x86_64-cygwin = { + config = "x86_64-pc-cygwin"; + }; + # BSDs aarch64-freebsd = { diff --git a/lib/systems/inspect.nix b/lib/systems/inspect.nix index 65fdb9ee1959..ad6ff2b380a8 100644 --- a/lib/systems/inspect.nix +++ b/lib/systems/inspect.nix @@ -337,8 +337,7 @@ rec { kernel = kernels.windows; }; isCygwin = { - kernel = kernels.windows; - abi = abis.cygnus; + kernel = kernels.cygwin; }; isMinGW = { kernel = kernels.windows; diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 0dfd91b7bb76..bbb0fa9d5582 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -42,6 +42,7 @@ let isLinux isPower64 isWindows + isCygwin ; inherit (lib.types) @@ -617,6 +618,10 @@ rec { execFormat = pe; families = { }; }; + cygwin = { + execFormat = pe; + families = { }; + }; ghcjs = { execFormat = unknown; families = { }; @@ -650,7 +655,6 @@ rec { types.abi = enum (attrValues abis); abis = setTypes types.openAbi { - cygnus = { }; msvc = { }; # Note: eabi is specific to ARM and PowerPC. @@ -783,11 +787,11 @@ rec { throw "system string '${lib.concatStringsSep "-" l}' with 1 component is ambiguous"; "2" = # We only do 2-part hacks for things Nix already supports if elemAt l 1 == "cygwin" then - { - cpu = elemAt l 0; - kernel = "windows"; - abi = "cygnus"; - } + mkSkeletonFromList [ + (elemAt l 0) + "pc" + "cygwin" + ] # MSVC ought to be the default ABI so this case isn't needed. But then it # becomes difficult to handle the gnu* variants for Aarch32 correctly for # minGW. So it's easier to make gnu* the default for the MinGW, but @@ -851,6 +855,13 @@ rec { else elemAt l 2; } + # lots of tools expect a triplet for Cygwin, even though the vendor is just "pc" + else if elemAt l 2 == "cygwin" then + { + cpu = elemAt l 0; + vendor = elemAt l 1; + kernel = "cygwin"; + } else throw "system string '${lib.concatStringsSep "-" l}' with 3 components is ambiguous"; "4" = { @@ -891,7 +902,7 @@ rec { getVendor args.vendor else if isDarwin parsed then vendors.apple - else if isWindows parsed then + else if (isWindows parsed || isCygwin parsed) then vendors.pc else vendors.unknown; @@ -933,12 +944,7 @@ rec { abi, ... }: - if abi == abis.cygnus then - "${cpu.name}-cygwin" - else if kernel.families ? darwin then - "${cpu.name}-darwin" - else - "${cpu.name}-${kernelName kernel}"; + if kernel.families ? darwin then "${cpu.name}-darwin" else "${cpu.name}-${kernelName kernel}"; tripleFromSystem = { diff --git a/lib/tests/systems.nix b/lib/tests/systems.nix index 3bddf78dea19..642339e792fd 100644 --- a/lib/tests/systems.nix +++ b/lib/tests/systems.nix @@ -49,6 +49,7 @@ lib.runTests ( ++ illumos ++ wasi ++ windows + ++ cygwin ++ embedded ++ mmix ++ js @@ -202,8 +203,6 @@ lib.runTests ( "x86_64-openbsd" ]; testwindows = mseteq windows [ - "i686-cygwin" - "x86_64-cygwin" "aarch64-windows" "i686-windows" "x86_64-windows"