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

Wine (with mingw support) #103102

Closed
cawilliamson opened this issue Nov 7, 2020 · 21 comments · Fixed by #113146
Closed

Wine (with mingw support) #103102

cawilliamson opened this issue Nov 7, 2020 · 21 comments · Fixed by #113146
Labels
0.kind: packaging request Request for a new package to be added

Comments

@cawilliamson
Copy link
Member

Project description
There is a great wine package currently in NixOS but it lacks mingw support for the DLLs.

This is needed for a few games including World of Warcraft it seems. Basically we need to build WINE with "--with-mingw" compile flag. The problem I have here is - I have no idea how to actually include the mingw compiler as a dependency to WINE.

Any help here would be appreciated.

Metadata

@cawilliamson cawilliamson added the 0.kind: packaging request Request for a new package to be added label Nov 7, 2020
@veprbl
Copy link
Member

veprbl commented Nov 9, 2020

cc @avnik @bendlas @7c6f434c

@kira-bruneau
Copy link
Contributor

kira-bruneau commented Nov 9, 2020

@cawilliamson I think something like this should work:

{ wine, pkgsCross }:

wine.overrideAttrs (attrs: {
  nativeBuildInputs = attrs.nativeBuildInputs ++ [
    # Needed if building with wine32 or wineWow
    pkgsCross.mingw32.buildPackages.gcc
    
    # Needed if building with wine64 or wineWow
    pkgsCross.mingwW64.buildPackages.gcc
  ];

  # Fixes -Werror=format-security
  hardeningDisable = attrs.hardeningDisable ++ [ "format" ];
})

You should see something like this in your build output:

checking for i686-w64-mingw32-gcc... i686-w64-mingw32-gcc
checking whether i686-w64-mingw32-gcc works... yes

I've had to do something similar when trying build Guy1524's Easy Anti-Cheat fork:
https://github.com/MetaDark/nur-packages/blob/6d867e5b3c14027981a2772d0a8b937120fe24e3/pkgs/misc/emulators/wine-eac/default.nix

@kira-bruneau
Copy link
Contributor

@avnik @bendlas @7c6f434c Maybe it would make sense to add a mingwSupport parameter to handle this?

@7c6f434c
Copy link
Member

7c6f434c commented Nov 9, 2020

I am not sure what it actually does, but maybe

@cawilliamson
Copy link
Member Author

@Metadark Thanks a lot for that - I also faced another problem which your linked code sorted - the "compiler cannot create executables" error - strictDeps looks to have solved it though. 👍

@7c6f434c I can tell you - it uses the mingw compiler to compile "PE DLLs" (I believe this is in reference to Windows PE DLLs but could be wrong.) It then uses these in place of the normal fake builtin DLLs it uses. This enables a much more convincing Windows environment which some apps / games appear to need.

@7c6f434c
Copy link
Member

7c6f434c commented Nov 9, 2020 via email

@cawilliamson
Copy link
Member Author

cawilliamson commented Nov 9, 2020

@7c6f434c I'm not too sure what closure means in this context D: What I will say, however, is that this is OFF by default in most distros so I think it should be added as an option and not enabled by default - just as you suggested.

@Metadark Your changes got me a lot further in to the build but I believe I am missing one critical change - the build runs correctly and starts building DLLs via mingw but then fails out with:

/build/wine-5.20/dlls/msvcp60/tests/ios.c:1470:9: error: format not a string literal and no format arguments [-Werror=format-security]

Actual overlay pkg (including the fix for exactly this error from your code linked above.) I wonder if mingw is ignoring the hardeningDisable flag or is using defaults somewhere? We're so close to fixing this I can feel it! 👍 :

self: super:

{
  wine-mingw = super.wineWowPackages.full.overrideDerivation (oldAttrs: rec {
    name = "wine-${version}";
    version = "5.20";

    src = super.fetchurl {
      url = "https://dl.winehq.org/wine/source/5.x/wine-${version}.tar.xz";
      sha256 = "0746j29six9cjgxp9pxfw1r67xhi39kvmqaq5yhvmgdyrvw24mcg";
    };

    # Fixes "Compiler cannot create executables" building with wineWow
    strictDeps = true;

    # Intended to fix: -Werror=format-security - ignored by mingw
    hardeningDisable = oldAttrs.hardeningDisable ++ [ "format" ];

    nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [
      # needed for wine32 or wineWow
      super.pkgsCross.mingw32.windows.crossThreadsStdenv.cc

      # needed for wine64 or wineWow
      super.pkgsCross.mingwW64.windows.crossThreadsStdenv.cc
    ];
  });
}

@wedens
Copy link

wedens commented Nov 9, 2020

What I will say, however, is that this is OFF by default in most distros

I think Arch builds wine with mingw: https://github.com/archlinux/svntogit-community/blob/packages/wine-staging/trunk/PKGBUILD#L52 (mingw-w64-gcc)

In official wine repos for fedora (https://dl.winehq.org/wine-builds/fedora/33/x86_64/) there are lines:

BuildRequires:  mingw32-gcc
BuildRequires:  mingw64-gcc

and for Ubuntu (https://dl.winehq.org/wine-builds/ubuntu/dists/bionic/main/source/wine-staging_5.21~bionic.dsc), there is mingw-w64 in Build-Depends.

So, if it doesn't increase closure size by too much, I'd say it's a good idea to enable it by default.

@7c6f434c
Copy link
Member

7c6f434c commented Nov 9, 2020 via email

@kira-bruneau
Copy link
Contributor

@Metadark Your changes got me a lot further in to the build but I believe I am missing one critical change - the build runs correctly and starts building DLLs via mingw but then fails out with:

/build/wine-5.20/dlls/msvcp60/tests/ios.c:1470:9: error: format not a string literal and no format arguments [-Werror=format-security]

Actual overlay pkg (including the fix for exactly this error from your code linked above.) I wonder if mingw is ignoring the hardeningDisable flag or is using defaults somewhere? We're so close to fixing this I can feel it! 👍

@cawilliamson Hmm, it worked for me when specifying hardeningDisable. Maybe there is a problem with using overrideDerivation? The Nixpkgs manual strongly recommends using overrideAttrs instead of overrideDerivation. I think it's very likely that's the cause: https://nixos.org/manual/nixpkgs/stable/#sec-pkg-overrideDerivation

@7c6f434c I'll gather information about the closure sizes for each configuration (wine32, wine64, wineWow) and I'll also look into creating a PR that adds a new support flag.

@cawilliamson
Copy link
Member Author

cawilliamson commented Nov 9, 2020

@Metadark I hadn't noticed that little difference - changed it to overrideAttrs and it's now building properly from the looks of things. Thanks again for all of your help on this - that's super helpful! 👍

@7c6f434c It looks like it was disabled by default in Gentoo (in: https://gitweb.gentoo.org/repo/gentoo.git/tree/app-emulation/wine-vanilla/wine-vanilla-5.21.ebuild) due to the following bug: https://bugs.gentoo.org/685172

^ This may not be all that relevant to NixOS - just wanted to bring it to your attention.

@7c6f434c
Copy link
Member

@cawilliamson Hm, interesting. We'll see.

@Metadark if it is default-off, feel free to skip the closure-measuring step for anything you are not going to use anyway. No need to build something just for that.

@kira-bruneau
Copy link
Contributor

kira-bruneau commented Nov 10, 2020

@7c6f434c I noticed that runtime closures were dramatically increased with this option:

  • wine32 (minimal): 829.3M -> 2.6G
  • wine64 (minimal): 912.5M -> 2.6G
  • wineWow (minimal): 1.5G -> 4.9G

It looks like development header files from mingw-64-gcc are being referenced in all DLLS under lib/wine. For example, these paths are referenced in the wine32 build:

/nix/store/4pif79nqpcigcrq3934p0jaijq24dy3v-i686-w64-mingw32-stage-final-gcc-debug-9.3.0/i686-w64-mingw32/sys-include
/nix/store/lwlaj95fph6gbvvcnnzg1pws9vqa1np7-mingw-w64-6.0.0-i686-w64-mingw32-dev/include
/nix/store/xrswl3dhfjb3zi4dri7ijwzp2ql4zjkv-mingw-w64-6.0.0-i686-w64-mingw32-headers/include
/nix/store/xrswl3dhfjb3zi4dri7ijwzp2ql4zjkv-mingw-w64-6.0.0-i686-w64-mingw32-headers/include/psdk_inc

Right now I'm looking into why they're being added and if they can be removed / reduced.

@wedens
Copy link

wedens commented Nov 11, 2020

If mingw is disabled by default, perhaps it could be added as a new attribute so that it's cached?

Considering it's enabled by default in (at least) Arch and official wine repos, some users may expect it to be enabled by default in NixOS too. Having to override wine for e.g. lutris and also build wine (which takes a pretty long time) is a lot of friction for an unexperienced NixOS user (or someone with not so powerful hardware).

@kira-bruneau
Copy link
Contributor

kira-bruneau commented Nov 12, 2020

@wedens Preferably we would enable it by default. Once, binutils 2.34 is merged to nixpkgs which contains the bugfix for stripping wine DLLS we can re-enable stripping to avoid the closure increase caused by the header references.

@wedens
Copy link

wedens commented Nov 13, 2020

Considering the OP mentioned specifically games, I'll just mention that lutris now ships (via its "runners" machinery) wine 5.21 with mingw.

@kira-bruneau
Copy link
Contributor

kira-bruneau commented Nov 14, 2020

@cawilliamson Now that #103358 has been merged you can just use:

wine.override {
  mingwSupport = true;
}

This isn't currently enabled by default or cached, but does this solve your issue? Hopefully we can enable this on the base build once #89793 is merged, and after stripping is enabled.

@mweinelt
Copy link
Member

mweinelt commented Dec 22, 2020

I don't seem to be able to overwrite wineWowPackages.staging to enable mingwSupport. It does work for wineWowPackages.full though. It complains about a missing hexdump dependency and a patch that it is unable to apply.

patching script interpreter paths in gitapply.sh
gitapply.sh: interpreter directive changed from "/usr/bin/env bash" to "/nix/store/4l7wsi6h6283194r6fqy1731qxlagq62-bash-4.4-p23/bin/bash"
Applying /build/wine-5.22/patches/Compiler_Warnings/0001-windowscodecs-Avoid-implicit-cast-of-interface-point.patch
Missing dependency: hexdump - please install this program and try again.
ERROR: Failed to apply patch, aborting!
builder for '/nix/store/imwnnnbdvp0p297984fj9n15yljb3r3c-wine-wow-5.22-staging.drv' failed with exit code 1

@mweinelt
Copy link
Member

mweinelt commented Dec 22, 2020

@cawilliamson Did you eventually get WoW 9.0.2 running? Starting Wow.exe ends in an Access Violation popup for me.

https://gist.github.com/mweinelt/241d77476daf8efa2439731a398add82

This is on wine 5.22:

      (wineWowPackages.unstable.override {
        mingwSupport = true;
        vulkanSupport = true;
      })

@kira-bruneau
Copy link
Contributor

kira-bruneau commented Jan 5, 2021

Just a heads up, I noticed a regression running Cities: Skylines (specifically the Paradox Launcher) with mingwSupport = true:

[0105/131817.525:ERROR:dxva_video_decode_accelerator_win.cc(1431)] DXVAVDA fatal error: could not LoadLibrary: msmpeg2vdec.dll: Module not found. (0x7E)
[0105/131817.527:ERROR:dxva_video_decode_accelerator_win.cc(1439)] DXVAVDA fatal error: could not LoadLibrary: msvproc.dll: Module not found. (0x7E)

It looks like this is a problem upstream (I have the exact same problem with Lutris wine), but for now I'm just forcing it to launch with a wine built with mingwSupport = false.

kira-bruneau added a commit to kira-bruneau/nixpkgs that referenced this issue Feb 15, 2021
With mingwSupport enabled, Wine uses MinGW builds of GCC (compiled for
the i686-w64-mingw32 & x86_64-w64-mingw32 targets) to cross compile
system DLLs as PE executables.

This is used to workaround some basic anticheat software. (See NixOS#103102)

Fedora & Arch Linux also have this enabled by default in their Wine builds:
- Fedora: https://src.fedoraproject.org/rpms/wine/blob/8e216ca407b6c0f78f65f36c5b068c6452701e55/f/wine.spec#_116
- Arch Linux: https://github.com/archlinux/svntogit-community/blob/2435e762eacd989c588200d7cf57d8f4fb2e0cf3/trunk/PKGBUILD#L44
@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/wine-installing-mingw32-compiler/19944/2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: packaging request Request for a new package to be added
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants