Skip to content

Commit

Permalink
cygwin: symlink together a working libc
Browse files Browse the repository at this point in the history
With enough to cross-compile bash.exe (wow!) although the headers have
a problem which requires disabling fortifying for most uses.
  • Loading branch information
puffnfresh committed Nov 7, 2024
1 parent d7bba20 commit 05826a1
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 54 deletions.
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
'';
});

Expand Down
5 changes: 5 additions & 0 deletions pkgs/development/libraries/ncurses/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ stdenv.mkDerivation (finalAttrs: {
CFLAGS=-D_XOPEN_SOURCE_EXTENDED
'';

# Fortify currently breaks under the nixpkgs' Cygwin with errors such as:
# two or more data types in declaration specifiers
# conflicting types for 'read'
hardeningDisable = lib.optionals stdenv.hostPlatform.isCygwin [ "fortify" ];

enableParallelBuilding = true;

doCheck = false;
Expand Down
6 changes: 4 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 @@ -35,13 +35,15 @@ stdenv.mkDerivation rec {
in
import ./readline-8.2-patches.nix patch);

hardeningDisable = lib.optionals stdenv.hostPlatform.isCygwin [ "fortify" ];

patches = lib.optionals (curses-library.pname == "ncurses") [
./link-against-ncurses.patch
] ++ [
./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
107 changes: 64 additions & 43 deletions pkgs/os-specific/windows/cygwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,77 @@
flex,
perl,
mingw_w64,
symlinkJoin,
}:

stdenv.mkDerivation {
pname = "cygwin";
let
newlib-cygwin = stdenv.mkDerivation {
pname = "cygwin";

inherit (cygwin_headers)
version
src
meta
patches
;
inherit (cygwin_headers)
version
src
meta
patches
;

preConfigure = ''
pushd winsup
aclocal --force
autoconf -f
automake -ac
rm -rf autom4te.cache
popd
patch -p0 -i ${./after-autogen.patch}
'';
preConfigure = ''
pushd winsup
aclocal --force
autoconf -f
automake -ac
rm -rf autom4te.cache
popd
patch -p0 -i ${./after-autogen.patch}
'';

postPatch = ''
patchShebangs --build winsup/cygwin/scripts
'';
postPatch = ''
patchShebangs --build winsup/cygwin/scripts
'';

env.CXXFLAGS_FOR_TARGET = "-Wno-error";
env.CXXFLAGS_FOR_TARGET = "-Wno-error";

depsBuildBuild = [ buildPackages.stdenv.cc ];
nativeBuildInputs = [
autoconf
automake
bison
cocom-tool-set
flex
perl
];
buildInputs = [ mingw_w64 ];
depsBuildBuild = [ buildPackages.stdenv.cc ];
nativeBuildInputs = [
autoconf
automake
bison
cocom-tool-set
flex
perl
];
buildInputs = [ mingw_w64 ];

hardeningDisable = [ "fortify" ];
configurePlatforms = [
"build"
"target"
];
configureFlags = [
"--disable-shared"
"--disable-doc"
"--enable-static"
"--disable-dumper"
"--with-cross-bootstrap"
"ac_cv_prog_CC=gcc"
postInstall = ''
mv $out/x86_64-pc-cygwin/* $out/
rmdir $out/x86_64-pc-cygwin
'';

hardeningDisable = [
"fortify"
"stackprotector"
];
configurePlatforms = [
"build"
"target"
];
configureFlags = [
"--disable-shared"
"--disable-doc"
"--enable-static"
"--disable-dumper"
"--with-cross-bootstrap"
"ac_cv_prog_CC=gcc"
];
};
in
# TODO: Is there something like nix-support which would achieve this better?
symlinkJoin {
pname = "cygwin-and-mingw_w64";
inherit (newlib-cygwin) version;
paths = [
newlib-cygwin
mingw_w64
mingw_w64.dev
];
}
13 changes: 4 additions & 9 deletions pkgs/shells/bash/5.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
, forFHSEnv ? false

, pkgsStatic
, ncurses
}:

let
Expand All @@ -36,7 +37,7 @@ stdenv.mkDerivation rec {
# bionic libc is super weird and has issues with fortify outside of its own libc, check this comment:
# https://github.com/NixOS/nixpkgs/pull/192630#discussion_r978985593
# or you can check libc/include/sys/cdefs.h in bionic source code
++ lib.optional (stdenv.hostPlatform.libc == "bionic") "fortify";
++ lib.optional (stdenv.hostPlatform.libc == "bionic" || stdenv.hostPlatform.isCygwin) "fortify";

outputs = [ "out" "dev" "man" "doc" "info" ];

Expand Down Expand Up @@ -84,10 +85,9 @@ stdenv.mkDerivation rec {
] ++ lib.optionals stdenv.hostPlatform.isCygwin [
"--without-libintl-prefix"
"--without-libiconv-prefix"
"--with-installed-readline"
"--with-curses"
"bash_cv_dev_stdin=present"
"bash_cv_dev_fd=standard"
"bash_cv_termcap_lib=libncurses"
] ++ lib.optionals (stdenv.hostPlatform.libc == "musl") [
"--disable-nls"
] ++ lib.optionals stdenv.hostPlatform.isFreeBSD [
Expand All @@ -103,15 +103,10 @@ stdenv.mkDerivation rec {
++ lib.optional withDocs texinfo
++ lib.optional stdenv.hostPlatform.isDarwin stdenv.cc.bintools;

buildInputs = lib.optional interactive readline;
buildInputs = lib.optional interactive readline ++ lib.optionals stdenv.hostPlatform.isCygwin [ ncurses ];

enableParallelBuilding = true;

makeFlags = lib.optionals stdenv.hostPlatform.isCygwin [
"LOCAL_LDFLAGS=-Wl,--export-all,--out-implib,libbash.dll.a"
"SHOBJ_LIBS=-lbash"
];

nativeCheckInputs = [ util-linux ];
doCheck = false; # dependency cycle, needs to be interactive

Expand Down

0 comments on commit 05826a1

Please sign in to comment.