Use MinGW-w64 GCC with other threading library

I hope this problem isn’t too obscure. I’ve recently looked into cross-compiling Windows programs from NixOS and the whole experience has so far been way more pleasant than I initially feared. However, I’ve noticed something a bit strange with the way that MinGW-w64 compilers are build.

When building GCC, you select a thread-library that is used in the backend whenever something like C++11-threads are used. This is done during the configuration step of the compiler itself. In Nixpkgs, we pull in special patches for a MCF thread model and select the MCF-gthreads library by default. Now, I do not want to shit on MCF and I am sure it is solid software, but having this as a default choice seems a bit weird to me. Searching for MCF threads does not yield a lot of results besides the GitHub page of the project itself. So it leaves me wondering why we select this implementation as default instead of, e.g., pthreads or win32 which seems to be the default for most other MinGW based GCC distributions. Actually, default is too weak, since it is not (as far as I can see) switchable without editing Nixpkgs itself.

It seems to be hardcoded into the GCC derivations here:

Also, the GCC derivation uses the threadsCross top-level package to install the actual library alongside of GCC. Its definition looks like this:

  threadsCross =
    if stdenv.targetPlatform.isMinGW && !(stdenv.targetPlatform.useLLVM or false)
    then or windows.mcfgthreads
    else null;

I was wondering if an effort to change this and make it more flexible so that a pthreads or win32 based solution can be chosen would have a chance to be merged.

I am currently seeing three ways on how this could be changed:

  1. Change threadsCross into an attribute set. threadsCross.package then gets to hold the threading package and threadsCross.option becomes the value that is configured for GCC (e.g. mcf, win32, posix)
  2. Add an attribute to all derivations that are valid as threadsCross. Give them a, e.g., config_option field that holds the value mcf, …
  3. Add a check inside configure-flags.nix to see which packet is selected in threadsCross. If it is MCF, make the string mcf. If it is pthreads, make the string posix. If it is something else, make it win32.


1 Like

I also agree this should be configurable.