Skip to content

Conversation

@js6pak
Copy link
Member

@js6pak js6pak commented Dec 23, 2024

This is the default used by MSYS21, ArchLinux2 and probably everyone else.
This is required to compile Rust programs as it doesn't support SJLJ3.

Effectively a continuation of #89582, but for x86-32.

I also moved the EH flags out of the withoutTargetLibc check, which I believe to be a mistake introduced by the previous PR: #89582 (comment)

I've tested it with a rust hello world cross compiled for mingw32/mingwW64 with mcf/win32 threading.
For some reason -lmcfgthread doesn't get automatically added with buildRustPackage but that's a separate issue.

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/)
  • 25.05 Release Notes (or backporting 24.11 and 25.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.

Footnotes

  1. https://github.com/msys2/MINGW-packages/blob/725f262e9f6313e3ee04327a33c16614c970a110/mingw-w64-gcc/PKGBUILD#L185-L186

  2. https://gitlab.archlinux.org/archlinux/packaging/packages/mingw-w64-gcc/-/blob/14.2.0-3/PKGBUILD#L62

  3. https://github.com/rust-lang/rust/pull/55444#issuecomment-434044002

@github-actions github-actions bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels Dec 23, 2024
@js6pak js6pak requested review from Ericson2314 and emilazy February 2, 2025 23:27
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 2, 2025
@js6pak js6pak force-pushed the gcc/fix-x32-mingw branch from 734f2cc to 4c39db4 Compare April 19, 2025 17:07
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 19, 2025
@github-actions github-actions bot added 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. and removed 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. labels Apr 19, 2025
@js6pak
Copy link
Member Author

js6pak commented Apr 19, 2025

To add more context to this PR, mingw gcc has 3 exception handling methods:

  1. SJLJ: works on both x64/x32, slow, not supported by rust
  2. DWARF2: works only on x32, faster but bloats file size a bit
  3. SEH: works only on x64, fast, interoperable with msvc

(source: https://wiki.qt.io/MinGW-64-bit#Exception_handling:_SJLJ,_DWARF,_and_SEH)

Before #89582, both x64 and x32 used SJLJ which is the worst option.
That PR made x64 use SEH (which is normally the default) by deleting the --enable-sjlj-exception flag.

This PR makes x32 use DWARF2 EH, by disabling SJLJ. I think --with-dwarf2 is not strictly necessary, but that's what MSYS2 and ArchLinux do.

You can find the source for how GCC picks the EH method here: https://github.com/gcc-mirror/gcc/blob/releases/gcc-14.2.0/gcc/common/config/i386/i386-common.cc#L2072-L2089
DWARF2_UNWIND_INFO on x32 is defined here: https://github.com/gcc-mirror/gcc/blob/releases/gcc-14.2.0/gcc/config/i386/cygming.h#L355-L366
As a side note, x64 enables dwarf2 here https://github.com/gcc-mirror/gcc/blob/releases/gcc-14.2.0/gcc/config/i386/x86-64.h#L78-L82

@Ericson2314 As the person who merged #89582, can you look into this?

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jun 9, 2025
@nixpkgs-ci nixpkgs-ci bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 17, 2025
@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 1 This PR was reviewed and approved by one person. and removed 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md labels Oct 20, 2025
@Sewer56
Copy link
Contributor

Sewer56 commented Oct 20, 2025

@Ericson2314
@emilazy

I ran into this issue independently, while writing some documentation on testing Rust code built for Windows in Wine.

I can confirm, this fix is needed to be able to build at all for i686-pc-windows-gnu; and after some digging, what I'm seeing here is sound.

The use case/motivation here is to run cross compiled packages against local Wine.
The local part is important- as it should be the current development build- not latest release.

By testing my projects against Wine, I am able to occasionally report issues such as #56357 and #56362. However, being unable to build for i686-pc-windows-gnu is a bit of a blocker given my switch from Arch to NixOS.

In any case, it is still somewhat possible by linking against msvc with cargo-xwin; but it introduces unnecessary complexity.
e.g. If I put it as part of docs, now the user has to install Visual C++ redist into their WINEPREFIX, etc. It's undesireable here.

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: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 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.

3 participants