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

Conversation

puffnfresh
Copy link
Member

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added the 6.topic: lib The Nixpkgs function library label Nov 7, 2024
pkgs/os-specific/windows/cygwin/headers.nix Outdated Show resolved Hide resolved
Comment on lines +37 to +39
meta = {
platforms = lib.platforms.windows;
};
Copy link
Member

Choose a reason for hiding this comment

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

Could be folded to just meta.platforms but it might be good to fill in the rest of the typical metadata.

Copy link
Member

Choose a reason for hiding this comment

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

This had been marked as resolved but doesn't seem to have actually been?

pkgs/by-name/co/cocom-tool-set/package.nix Outdated Show resolved Hide resolved
@@ -3,7 +3,7 @@
, updateAutotoolsGnuConfigScriptsHook
, ncurses, termcap
, curses-library ?
if stdenv.hostPlatform.isWindows
if stdenv.hostPlatform.isMinGW
Copy link
Member

Choose a reason for hiding this comment

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

What's the exact reason for changing from checking for windows in general to mingw? Would isWindows || isMinGW work better?

Copy link
Member Author

Choose a reason for hiding this comment

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

isWindows includes Cygwin. Under Cygwin we want to use ncurses, not termcap.

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.isMinGW [
Copy link
Member

Choose a reason for hiding this comment

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

What's the exact reason for changing from checking for windows in general to mingw? Would isWindows || isMinGW work better?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't want to apply these patches under Cygwin. Cywin provides a POSIX API under Windows, so we want to use the normal POSIX calls which readline would usually make.

Copy link
Member

@emilazy emilazy Nov 7, 2024

Choose a reason for hiding this comment

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

I guess this could be something like (stdenv.hostPlatform.isWindows && !stdenv.hostPlatform.isUnix) if we wanted to mark Cygwin as the technically‐correct Windows + Unix and confuse everyone for the rest of time?

(Because after all there could theoretically be e.g. an MSVC platform too…)

Copy link
Member Author

Choose a reason for hiding this comment

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

@emilazy yeah really good point, MSVC is on its way. I actually like the suggestion of isWindows && !isUnix.

Copy link
Member

@emilazy emilazy Nov 7, 2024

Choose a reason for hiding this comment

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

Just be prepared for the fact that there’s probably a lot of things in the tree that assume the two are disjoint. But it’d be great to deconfuse that along the way.

And hey, it’ll prepare us for when midipix releases in 2038…

Copy link
Member

@RossComputerGuy RossComputerGuy left a comment

Choose a reason for hiding this comment

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

Please squash specific changes amongst your commits. You can make several commits and use git rebase -i to do that. Also, please format your nix files so CI can pass.

@Artturin
Copy link
Member

Artturin commented Nov 7, 2024

Please squash specific changes amongst your commits. You can make several commits and use git rebase -i to do that. Also, please format your nix files so CI can pass.

Check out git-absorb for this @puffnfresh
You can git reset --soft HEAD and then run it to absorb the changes you already committed

@@ -99,6 +99,8 @@ stdenv.mkDerivation (finalAttrs: {
CFLAGS=-D_XOPEN_SOURCE_EXTENDED
'';

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

Choose a reason for hiding this comment

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

What's the error? Include it as a ~1 line verbatim comment

Copy link
Member

Choose a reason for hiding this comment

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

If this needs to be set for every package, why not globally disable fortify for cygwin?

Copy link
Member Author

Choose a reason for hiding this comment

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

@alyssais I wanted to, but I'm not sure where the best place to do that would be. Should it be an additional condition in the default value of defaultHardeningFlags in pkgs/build-support/bintools-wrapper?

Copy link
Member

Choose a reason for hiding this comment

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

This will also have the added benefit of making it not a mass rebuild, I think

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've moved this to bintools-wrapper and added a few things to avoid the mass rebuild.

Copy link
Member

Choose a reason for hiding this comment

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

Great!

Copy link
Member

Choose a reason for hiding this comment

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

The commits that set it individually for packages need to be updated then.

@ofborg ofborg bot added 6.topic: cross-compilation Building packages on a different platform than they will be used on 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild 10.rebuild-linux-stdenv This PR causes stdenv to rebuild 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 501+ 10.rebuild-darwin: 5001+ 10.rebuild-linux: 501+ 10.rebuild-linux: 5001+ labels Nov 7, 2024
@puffnfresh puffnfresh force-pushed the cygwin/target branch 3 times, most recently from 9a9998b to 05826a1 Compare November 7, 2024 11:55
Copy link
Member

@alyssais alyssais left a comment

Choose a reason for hiding this comment

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

This needs to be more than two commits. One logical change at a time, that gets it a bit further.

@@ -99,6 +99,8 @@ stdenv.mkDerivation (finalAttrs: {
CFLAGS=-D_XOPEN_SOURCE_EXTENDED
'';

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

Choose a reason for hiding this comment

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

If this needs to be set for every package, why not globally disable fortify for cygwin?

@github-actions github-actions bot added the 6.topic: windows Running, or buiding, packages on Windows label Nov 8, 2024
@puffnfresh
Copy link
Member Author

This needs to be more than two commits. One logical change at a time, that gets it a bit further.

I've split this into 10 commits now. Also resolved conflicts.

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.

Copy link
Member

Choose a reason for hiding this comment

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

Could we instead patch configure.ac and regen with autoreconfHook?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe. This was copied from Microsoft's Windows-on-ARM-Experiments repository. Not sure why it was done that way.

Copy link
Member

Choose a reason for hiding this comment

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

oh probably because they are lazy af lol

Copy link
Member

Choose a reason for hiding this comment

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

Why copied and not fetched? If you used fetchpatch you could even use extraPrefix to make it so you can just put it in patches.

The size of various things don't line up when enabling fortification.
This might be able to be fixed by looking at the Cywin builds, because
I think they don't generally disable fortify.
@Ericson2314
Copy link
Member

Oh is this ofborg-eval-darwin failure spurious?

@emilazy
Copy link
Member

emilazy commented Nov 18, 2024

error: cannot connect to socket at '/nix/var/nix/gc-socket/socket': No such file or directory, looks like it needs a retry.

@ofborg eval

@Ericson2314
Copy link
Member

OK this is evaluating now!

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/dropping-cygwin-support/3425/19

@puffnfresh puffnfresh requested a review from alyssais November 30, 2024 10:03
@@ -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.

};

patches = [
(fetchpatch {
Copy link
Member

Choose a reason for hiding this comment

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

This is a static file, so there's no need for patch normalization and fetchurl can be used.

Comment on lines +37 to +39
meta = {
platforms = lib.platforms.windows;
};
Copy link
Member

Choose a reason for hiding this comment

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

This had been marked as resolved but doesn't seem to have actually been?


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.

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?

ln -fs w32api/libpsapi.a .
ln -fs w32api/libuserenv.a .
ln -fs w32api/libnetapi32.a .
ln -fs w32api/libdbghelp.a .
Copy link
Member

Choose a reason for hiding this comment

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

Would w32api/*.a be wrong?

Changing directory without changing back at the end also makes me worry about fixupPhase not working.

];
};
in
# TODO: Is there something like nix-support which would achieve this better?
Copy link
Member

Choose a reason for hiding this comment

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

Could you just link the appropriate paths in postInstall in the main derivation?

@@ -99,6 +99,8 @@ stdenv.mkDerivation (finalAttrs: {
CFLAGS=-D_XOPEN_SOURCE_EXTENDED
'';

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

Choose a reason for hiding this comment

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

The commits that set it individually for packages need to be updated then.

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

@@ -107,6 +107,8 @@ stdenv.mkDerivation rec {

enableParallelBuilding = true;

makeFlags = [ ];
Copy link
Member

Choose a reason for hiding this comment

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

Please don't make the code more complicated just to avoid a mass rebuild. Mass rebuilds are fine. The bash changes can do to staging separately from the rest of this if you want.

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: lib The Nixpkgs function library 6.topic: windows Running, or buiding, packages on Windows 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1-10 10.rebuild-linux: 11-100 11.by: package-maintainer This PR was created by the maintainer of the package it changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants