Skip to content

zlib: use default configure script on windows#428871

Open
greg-hellings wants to merge 1 commit intoNixOS:stagingfrom
greg-hellings:ucrt/zlib
Open

zlib: use default configure script on windows#428871
greg-hellings wants to merge 1 commit intoNixOS:stagingfrom
greg-hellings:ucrt/zlib

Conversation

@greg-hellings
Copy link
Copy Markdown
Contributor

@greg-hellings greg-hellings commented Jul 27, 2025

This avoids the pitfalls of win32/Makefile.gcc (which prevents building
on compilers other than gcc without patching and has non-standard
installation behavior) and fixes cross compilation for ucrtAarch64

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels Jul 27, 2025
@acid-bong
Copy link
Copy Markdown
Contributor

acid-bong commented Jul 27, 2025

Change target branch to staging (and also rebase your branch onto it), mass rebuilds go there

@greg-hellings greg-hellings force-pushed the ucrt/zlib branch 2 times, most recently from 4099757 to 54692b1 Compare July 27, 2025 17:22
@greg-hellings
Copy link
Copy Markdown
Contributor Author

Change target branch to staging (and also rebase your branch onto it), mass rebuilds go there

Done

@nix-owners
Copy link
Copy Markdown

nix-owners bot commented Jul 27, 2025

The PR's base branch is set to master, but 259 commits from the staging branch are included. Make sure you know the right base branch for your changes, then:

  • If the changes should go to the staging branch, change the base branch to staging
  • If the changes should go to the master branch, rebase your PR onto the merge base with the master branch:
    # git rebase --onto $(git merge-base upstream/master HEAD) $(git merge-base upstream/staging HEAD)
    git rebase --onto 6a506984e35eedbcc7381d2353a1f0625a5cc183 b72dfdf5d87e1ad9a8982d9ccc77abffb6e177fb
    git push --force-with-lease

@greg-hellings greg-hellings changed the base branch from master to staging July 27, 2025 17:24
@nixpkgs-ci nixpkgs-ci bot closed this Jul 27, 2025
@nixpkgs-ci nixpkgs-ci bot reopened this Jul 27, 2025
Copy link
Copy Markdown
Member

@Ericson2314 Ericson2314 Jul 28, 2025

Choose a reason for hiding this comment

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

Can this be a symlink instead like before?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have written about the details of why extensively in other PRs related to Windows cross builds, but the short answer is no. DLL files properly belong under the bin/ folder on Windows, not symlinked there.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I thought there was a setup hook that did this for you, but I guess not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought there was a setup hook that did this for you, but I guess not.

Most packages seem to have it automatically done, but I believe that is because of updates to autotools over the years and setting the destination folders properly nowadays. In the early days of MinGW, the post fixup had to be done to every single package as autotools didn't have any real knowledge of DLL files. However, zlib uses its own homegrown system so as not to rely on autotools, so I think that's why it is not handled by the standard scripts and options. If there is an automatic hook that would handle this properly, then I would be happy to use it, instead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It happens with my Rust projects, which do not use autotools. Looks like it's called win-dll-link

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If it's fine to symlink transitive DLLs I don't get why it's not fine to symlink DLLs from lib.

I would but the static libs / stub libs in $dev/lib, and the DLLs in $out/lib.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can also change the hook (in a future PR)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

DLLs properly belong in the bin/ folder on Windows targets. This is because Windows has an extremely limited search path for loading dynamic libraries, but it will always look in the same directory alongside the executing binary. Therefore, the DLLs do not belong in $out/lib but instead belong in $out/bin. This has been established practice for the MinGW packages due to the limitations in Windows search paths and it is how every other package in pkgsCross.mingwW64 handles it, it's how autotools handles it, it's how CMake handles it. The final target's $out/bin when building a .exe gets the dependency and transitive dependency DLL files symlinked into place because there is no equivalent to setting LD paths for Windows. There simply is no precedent anywhere else, including in other nixpkgs Windows targets, for putting the DLL file in lib/. It doesn't belong there. It is not a linker-related file, it is a binary executable on Windows.

Stub libraries and fully static libraries end up in lib/ because they are used at link time but are not necessary to distribute alongside binary files unless you are intentionally distributing build products to enable a downstream dev environment. They could live in $dev/lib or $out/lib depending on the purpose of the parent package, but that's a moot discussion here.

The only reason this difference is exposed here is because zlib has a custom, hand-rolled build system instead of using something like autotools. This change is just maintaining how the library already works, but enabling it to be built for Windows with LLVM compilers. This move is not introducing anything new or altering existing behavior. Here is the current output of building pkgsCross.mingwW64.zlib without this patch:

image

We really should put this information up in the packaging guidelines somewhere so it doesn't need to be reiterated on every pull request.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am very aware how windows search paths work. I am just wondering out loud if we can automate it, because us devs who care about Windows is a much much smaller population than the other major platforms.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

#431820

I am opening a separate issue for this point, which is a general disagreement on policy separate from zlib in particular.

Comment on lines 46 to 47
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fwiw you can probably reduce the # of rebuilds if you gate the patch.

Suggested change
patches = [
./mingw-shared.patch
];
patches = lib.optional stdenv.hostPlatform.isMingw ./mingw-shared.patch;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unsure if it really matters.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That has been suggested before on other cross build package fixes and was found to still cause rebuilds. I believe this is because previously it was null and the conditional will return an empty array when false. If there was already a list of patches, gating it like that would prevent rebuilds but when adding a new patches field it doesn't seem to have any beneficial effect, sadly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If that's the case then you could try it as an optionalAttrs instead, or an if ... then ... else null

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is that preferred? At other times I've been suggested to leave it in place if the patch file is cross-platform friendly, but if you want it conditional then I'm happy to change it here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looking through the code this doesn't really improve anything in terms of the rebuilds. The three differences are still going to all result in a change - the unconditional list, the conditional list, or the conditional null will all be read as different inputs for the simple fact that they have a key defined at all, even if it is defined as null.

However, now that the code is in with the conditional, it at least reduces the likelihood of a breakage to other targets resulting from this patch having unwanted side effects.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've been told that conditionally applied patches are generally not desired in nixpkgs since we want to catch the breakage if a patch no longer applies to a new version of the source as soon as possible. Conditional patches are acceptable if the patch's behavior would affect other systems' behavior in undesirable ways.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That is consistent with what I have been told in the past, but I haven't kept pace with the latest in the guidelines for that. Seeing as this commit has been languishing since December when it was first submitted and it keeps getting the the point of consensus and then ignored and not merged, I will do absolutely anything a reviewer says which might finally convince one of them to merge it at this point, though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would merge it if I could

This avoids the pitfalls of win32/Makefile.gcc (which prevents building
on compilers other than gcc without patching and has non-standard
installation behavior) and fixes cross compilation for ucrtAarch64
@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Aug 7, 2025
@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Dec 8, 2025
@nixpkgs-ci nixpkgs-ci bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Feb 6, 2026
@doronbehar
Copy link
Copy Markdown
Contributor

I'm sorry @greg-hellings that this has been held up so long, and now there are merge conflicts. There are issues with zlib on Windows now which are more urgent, and should be fixed here:

I think we can look into this patch of yours afterwards. FYI, see also:

@nixpkgs-ci nixpkgs-ci bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Feb 16, 2026
@doronbehar doronbehar mentioned this pull request Feb 16, 2026
9 tasks
@alexfmpe
Copy link
Copy Markdown
Member

This is unblocked now, right?

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 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants