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 targetPackages.windows.mcfgthreads 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:
- Change
threadsCross
into an attribute set.threadsCross.package
then gets to hold the threading package andthreadsCross.option
becomes the value that is configured for GCC (e.g.mcf
,win32
,posix
) - Add an attribute to all derivations that are valid as
threadsCross
. Give them a, e.g.,config_option
field that holds the valuemcf
, … - Add a check inside
configure-flags.nix
to see which packet is selected inthreadsCross
. If it is MCF, make the stringmcf
. If it is pthreads, make the stringposix
. If it is something else, make itwin32
.
Opinions?