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 <brian@brianmckenna.org>
This commit is contained in:
David McFarland 2025-09-21 20:20:41 -03:00
parent a91a232d10
commit 39fd8e4adf
5 changed files with 31 additions and 20 deletions

View file

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

View file

@ -388,6 +388,10 @@ rec {
useLLVM = true;
};
x86_64-cygwin = {
config = "x86_64-pc-cygwin";
};
# BSDs
aarch64-freebsd = {

View file

@ -337,8 +337,7 @@ rec {
kernel = kernels.windows;
};
isCygwin = {
kernel = kernels.windows;
abi = abis.cygnus;
kernel = kernels.cygwin;
};
isMinGW = {
kernel = kernels.windows;

View file

@ -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 =
{

View file

@ -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"