From 9a9998bbdb3b4f9e099b09868592a8acf9da7709 Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Mon, 4 Nov 2024 19:37:51 +1100 Subject: [PATCH] cygwin: symlink together a working libc With enough to cross-compile bash.exe (wow!) although the headers have a problem which requires disabling fortifying for most uses. --- pkgs/build-support/cc-wrapper/default.nix | 1 + .../development/libraries/ncurses/default.nix | 5 + pkgs/development/libraries/readline/8.2.nix | 6 +- pkgs/os-specific/windows/cygwin/default.nix | 107 +++++++++++------- pkgs/shells/bash/5.nix | 13 +-- 5 files changed, 78 insertions(+), 54 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 085f64d37dd4ba..8a0c9ab0787b9b 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -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 ''; }); diff --git a/pkgs/development/libraries/ncurses/default.nix b/pkgs/development/libraries/ncurses/default.nix index 0ee09d2416cd8e..8dc98c70bdb83d 100644 --- a/pkgs/development/libraries/ncurses/default.nix +++ b/pkgs/development/libraries/ncurses/default.nix @@ -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; diff --git a/pkgs/development/libraries/readline/8.2.nix b/pkgs/development/libraries/readline/8.2.nix index 7bf5caf4060f18..40833dec2533d8 100644 --- a/pkgs/development/libraries/readline/8.2.nix +++ b/pkgs/development/libraries/readline/8.2.nix @@ -3,7 +3,7 @@ , updateAutotoolsGnuConfigScriptsHook , ncurses, termcap , curses-library ? - if stdenv.hostPlatform.isWindows + if stdenv.hostPlatform.isWindows && !stdenv.hostPlatform.isUnix then termcap else ncurses }: @@ -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"; diff --git a/pkgs/os-specific/windows/cygwin/default.nix b/pkgs/os-specific/windows/cygwin/default.nix index a5b95f2b5b902c..6f2ed2cf3729f2 100644 --- a/pkgs/os-specific/windows/cygwin/default.nix +++ b/pkgs/os-specific/windows/cygwin/default.nix @@ -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 ]; } diff --git a/pkgs/shells/bash/5.nix b/pkgs/shells/bash/5.nix index 1e1fe340dcda17..ae2c7742abc62b 100644 --- a/pkgs/shells/bash/5.nix +++ b/pkgs/shells/bash/5.nix @@ -14,6 +14,7 @@ , forFHSEnv ? false , pkgsStatic +, ncurses }: let @@ -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" ]; @@ -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 [ @@ -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