Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cygwin: add as a cross-compilation target, and get bash.exe to compile #354137

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
5 changes: 5 additions & 0 deletions lib/systems/examples.nix
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ rec {
useLLVM = true;
};

x86_64-cygwin = {
config = "x86_64-pc-cygwin";
libc = "cygwin"; # cygwin (posix) toolchain
};

# BSDs

x86_64-freebsd = {
Expand Down
9 changes: 8 additions & 1 deletion lib/systems/parse.nix
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ rec {
else throw "Target specification with 1 components 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"; }
then mkSkeletonFromList [ (elemAt l 0) "pc" "cygwin" ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is purely a matter of style, not behavior, right?

(I kinda wonder if we can just drop this case, as the older cygwin stuff is bit-rotted for years at this point.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in favour of getting rid of all the older Cygwin support, since it just doesn't work anymore (I tried).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's well over a decade old

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a go at removing the hack altogether: puffnfresh@16e9e8b

It feels a little bit wrong to add Cygwin as a "kernel" but it does seem to work. Let me know what you think.

# 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
Expand Down Expand Up @@ -479,6 +479,13 @@ rec {
then "windows" # autotools breaks on -gnu for window
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;
kernel = "windows";
abi = "cygnus";
}
else throw "Target specification with 3 components is ambiguous";
"4" = { cpu = elemAt l 0; vendor = elemAt l 1; kernel = elemAt l 2; abi = elemAt l 3; };
}.${toString (length l)}
Expand Down
2 changes: 2 additions & 0 deletions pkgs/build-support/bintools-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
, defaultHardeningFlags ? [
"bindnow"
"format"
] ++ lib.optionals (!stdenvNoCC.targetPlatform.isCygwin) [
"fortify"
"fortify3"
] ++ [
"pic"
"relro"
"stackprotector"
Expand Down
1 change: 1 addition & 0 deletions pkgs/build-support/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ stdenvNoCC.mkDerivation {
echo addToSearchPath "LINK_DLL_FOLDERS" "${cc_solib}/lib" > $out
echo addToSearchPath "LINK_DLL_FOLDERS" "${cc_solib}/lib64" >> $out
echo addToSearchPath "LINK_DLL_FOLDERS" "${cc_solib}/lib32" >> $out
echo addToSearchPath "LINK_DLL_FOLDERS" "${libc_bin}/bin" > $out
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit surprising that it's in bin — is that definitely right?

'';
});

Expand Down
28 changes: 28 additions & 0 deletions pkgs/by-name/co/cocom-tool-set/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
lib,
stdenv,
fetchgit,
bison,
}:
stdenv.mkDerivation {
pname = "cocom";
version = "0.996";

src = fetchgit {
url = "https://git.code.sf.net/p/cocom/git";
sha256 = "sha256-utLafkznMC4LrZgF6vKehtIGMwNMwLP9M9Nwu/RyWio=";
rev = "64ee80224aa13f9944d439f3f90862ca76158705";
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not the release tarball?


nativeBuildInputs = [ bison ];

patches = [ ./remove-lto.patch ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could do with some explanation, ideally in the patch file.


meta = {
description = "Tool set oriented towards the creation of compilers";
homepage = "https://cocom.sourceforge.net/";
license = lib.licenses.gpl2Plus;
maintainers = with lib.maintainers; [ puffnfresh ];
platforms = lib.platforms.linux;
};
}
42 changes: 42 additions & 0 deletions pkgs/by-name/co/cocom-tool-set/remove-lto.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
diff --git a/configure b/configure
index 574cbe9..0dc2aa0 100755
--- a/configure
+++ b/configure
@@ -5858,37 +5858,6 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CXXFLAGS="`echo $CXXFLAGS|sed s/-O2//` -O3"
fi

- my_save_cflags="$CFLAGS"
- CFLAGS=-flto
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether CC supports -flto" >&5
-$as_echo_n "checking whether CC supports -flto... " >&6; }
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-
-int
-main ()
-{
-
- ;
- return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
- lto=yes
-else
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
- CFLAGS="$my_save_cflags"
- if test "$lto" = yes; then
- CFLAGS="`echo $CFLAGS` -flto"
- CXXFLAGS="`echo $CXXFLAGS` -flto"
- fi
-
system=`uname -m`
case $system in
i386*|i486*|i586*|i686*)
4 changes: 4 additions & 0 deletions pkgs/development/compilers/gcc/common/configure-flags.nix
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ let
# cc1: error: fp software completion requires '-mtrap-precision=i' [-Werror]
"--disable-werror"
]
++ lib.optionals targetPlatform.isCygwin [
# doesn't cross-compile under Cygwin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean "for Cygwin" (when running under some other platform)? Otherwise the check is wrong.

"--disable-libvtv"
]
;

in configureFlags
7 changes: 6 additions & 1 deletion pkgs/development/compilers/gcc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,12 @@ pipe ((callFile ./common/builder.nix {}) ({
'-s' # workaround for hitting hydra log limit
'LIMITS_H_TEST=false'
)
'');
'')
+ optionalString targetPlatform.isCygwin (''
substituteInPlace gcc/config/i386/cygwin.h \
--replace '../../include/w32api' "${libcCross}/include/w32api" \
--replace '../include/w32api' "${libcCross}/include/w32api"
'');

inherit noSysDirs staticCompiler withoutTargetLibc
libcCross crossMingw;
Expand Down
4 changes: 2 additions & 2 deletions pkgs/development/libraries/readline/8.2.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
, updateAutotoolsGnuConfigScriptsHook
, ncurses, termcap
, curses-library ?
if stdenv.hostPlatform.isWindows
if stdenv.hostPlatform.isWindows && !stdenv.hostPlatform.isUnix
then termcap
else ncurses
}:
Expand Down Expand Up @@ -41,7 +41,7 @@ stdenv.mkDerivation rec {
./no-arch_only-8.2.patch
]
++ upstreamPatches
++ lib.optionals stdenv.hostPlatform.isWindows [
++ lib.optionals (stdenv.hostPlatform.isWindows && !stdenv.hostPlatform.isUnix) [
(fetchpatch {
name = "0001-sigwinch.patch";
url = "https://github.com/msys2/MINGW-packages/raw/90e7536e3b9c3af55c336d929cfcc32468b2f135/mingw-w64-readline/0001-sigwinch.patch";
Expand Down
158 changes: 158 additions & 0 deletions pkgs/os-specific/windows/cygwin/after-autogen.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
--- winsup/configure.old 2024-11-01 22:38:21.005768397 +1100
+++ winsup/configure 2024-11-01 22:39:33.247435255 +1100
@@ -3970,155 +3970,6 @@
_ACEOF
ac_clean_files_save=$ac_clean_files
ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out"
-# Try to create an executable without -o first, disregard a.out.
-# It will help us diagnose broken compilers, and finding out an intuition
-# of exeext.
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5
-printf %s "checking whether the C compiler works... " >&6; }
-ac_link_default=`printf "%s\n" "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
-
-# The possible output files:
-ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*"
-
-ac_rmfiles=
-for ac_file in $ac_files
-do
- case $ac_file in
- *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
- * ) ac_rmfiles="$ac_rmfiles $ac_file";;
- esac
-done
-rm -f $ac_rmfiles
-
-if { { ac_try="$ac_link_default"
-case "(($ac_try" in
- *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
- *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-printf "%s\n" "$ac_try_echo"; } >&5
- (eval "$ac_link_default") 2>&5
- ac_status=$?
- printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
- test $ac_status = 0; }
-then :
- # Autoconf-2.13 could set the ac_cv_exeext variable to 'no'.
-# So ignore a value of 'no', otherwise this would lead to 'EXEEXT = no'
-# in a Makefile. We should not override ac_cv_exeext if it was cached,
-# so that the user can short-circuit this test for compilers unknown to
-# Autoconf.
-for ac_file in $ac_files ''
-do
- test -f "$ac_file" || continue
- case $ac_file in
- *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj )
- ;;
- [ab].out )
- # We found the default executable, but exeext='' is most
- # certainly right.
- break;;
- *.* )
- if test ${ac_cv_exeext+y} && test "$ac_cv_exeext" != no;
- then :; else
- ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
- fi
- # We set ac_cv_exeext here because the later test for it is not
- # safe: cross compilers may not add the suffix if given an '-o'
- # argument, so we may need to know it at that point already.
- # Even if this section looks crufty: it has the advantage of
- # actually working.
- break;;
- * )
- break;;
- esac
-done
-test "$ac_cv_exeext" = no && ac_cv_exeext=
-
-else case e in #(
- e) ac_file='' ;;
-esac
-fi
-if test -z "$ac_file"
-then :
- { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
-printf "%s\n" "no" >&6; }
-printf "%s\n" "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
-printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
-as_fn_error 77 "C compiler cannot create executables
-See 'config.log' for more details" "$LINENO" 5; }
-else case e in #(
- e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-printf "%s\n" "yes" >&6; } ;;
-esac
-fi
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
-printf %s "checking for C compiler default output file name... " >&6; }
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
-printf "%s\n" "$ac_file" >&6; }
-ac_exeext=$ac_cv_exeext
-
-rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out
-ac_clean_files=$ac_clean_files_save
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5
-printf %s "checking for suffix of executables... " >&6; }
-if { { ac_try="$ac_link"
-case "(($ac_try" in
- *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
- *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-printf "%s\n" "$ac_try_echo"; } >&5
- (eval "$ac_link") 2>&5
- ac_status=$?
- printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
- test $ac_status = 0; }
-then :
- # If both 'conftest.exe' and 'conftest' are 'present' (well, observable)
-# catch 'conftest.exe'. For instance with Cygwin, 'ls conftest' will
-# work properly (i.e., refer to 'conftest.exe'), while it won't with
-# 'rm'.
-for ac_file in conftest.exe conftest conftest.*; do
- test -f "$ac_file" || continue
- case $ac_file in
- *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
- *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
- break;;
- * ) break;;
- esac
-done
-else case e in #(
- e) { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
-printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
-as_fn_error $? "cannot compute suffix of executables: cannot compile and link
-See 'config.log' for more details" "$LINENO" 5; } ;;
-esac
-fi
-rm -f conftest conftest$ac_cv_exeext
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
-printf "%s\n" "$ac_cv_exeext" >&6; }
-
-rm -f conftest.$ac_ext
-EXEEXT=$ac_cv_exeext
-ac_exeext=$EXEEXT
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-#include <stdio.h>
-int
-main (void)
-{
-FILE *f = fopen ("conftest.out", "w");
- if (!f)
- return 1;
- return ferror (f) || fclose (f) != 0;
-
- ;
- return 0;
-}
-_ACEOF
-ac_clean_files="$ac_clean_files conftest.out"
# Check that the compiler produces executables we can run. If not, either
# the compiler is broken, or we cross compile.
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
Loading