How to add mcfgthreads to devshell for building a windows target

Hello there :slight_smile:

I am trying to make a dev shell for building Godot GDExtension libraries using C++. This requires me to build to a windows target from, of course, either a Linux host using the nix package manager or on NixOS. The recommended and documented way of building these libraries is using Scons and by default this uses mingw-gcc to build windows target binaries. The problem now is that, judging by the

error message
$ scons platform=windows
scons: Reading SConscript files ...
Auto-detected 24 CPU cores available for build parallelism. Using 23 cores by default. You can override it with the -j argument.
Building for architecture x86_64 on platform windows
scons: done reading SConscript files.
scons: Building targets ...
Compiling godot-cpp/src/godot.cpp ...
Compiling godot-cpp/src/classes/low_level.cpp ...
Compiling godot-cpp/src/classes/editor_plugin_registration.cpp ...
Compiling godot-cpp/src/classes/wrapped.cpp ...
Compiling godot-cpp/src/core/object.cpp ...
Compiling godot-cpp/src/core/memory.cpp ...
Compiling godot-cpp/src/core/class_db.cpp ...
Compiling godot-cpp/src/core/error_macros.cpp ...
Compiling godot-cpp/src/core/method_bind.cpp ...
Compiling godot-cpp/src/variant/callable_custom.cpp ...
Compiling godot-cpp/src/variant/rect2.cpp ...
Compiling godot-cpp/src/variant/projection.cpp ...
Compiling godot-cpp/src/variant/basis.cpp ...
Compiling godot-cpp/src/variant/transform2d.cpp ...
Compiling godot-cpp/src/variant/transform3d.cpp ...
In file included from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/x86_64-w64-mingw32/bits/gthr.h:148,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ext/atomicity.h:35,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/bits/ios_base.h:39,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ios:44,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ostream:40,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/iostream:41,
                 from godot-cpp/include/godot_cpp/core/method_bind.hpp:46,
                 from godot-cpp/include/godot_cpp/core/class_db.hpp:38,
                 from godot-cpp/gen/include/godot_cpp/classes/ref_counted.hpp:39,
                 from godot-cpp/include/godot_cpp/classes/ref.hpp:37,
                 from godot-cpp/gen/include/godot_cpp/classes/file_access.hpp:39,
                 from godot-cpp/src/classes/low_level.cpp:31:
/nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/x86_64-w64-mingw32/bits/gthr-default.h:34:10: fatal error: mcfgthread/gthr.h: No such file or directory
   34 | #include <mcfgthread/gthr.h>
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
Compiling godot-cpp/src/variant/variant.cpp ...
In file included from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/x86_64-w64-mingw32/bits/gthr.h:148,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ext/atomicity.h:35,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/bits/ios_base.h:39,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ios:44,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ostream:40,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/iostream:41,
                 from godot-cpp/include/godot_cpp/core/method_bind.hpp:46,
                 from godot-cpp/include/godot_cpp/core/class_db.hpp:38,
                 from godot-cpp/src/classes/wrapped.cpp:39:
/nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/x86_64-w64-mingw32/bits/gthr-default.h:34:10: fatal error: mcfgthread/gthr.h: No such file or directory
   34 | #include <mcfgthread/gthr.h>
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
Compiling godot-cpp/src/variant/aabb.cpp ...
scons: *** [godot-cpp/src/classes/low_level.windows.template_debug.x86_64.o] Error 1
scons: *** [godot-cpp/src/classes/wrapped.windows.template_debug.x86_64.o] Error 1
In file included from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/x86_64-w64-mingw32/bits/gthr.h:148,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ext/atomicity.h:35,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/bits/ios_base.h:39,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ios:44,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ostream:40,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/iostream:41,
                 from godot-cpp/include/godot_cpp/core/method_bind.hpp:46,
                 from godot-cpp/include/godot_cpp/core/class_db.hpp:38,
                 from godot-cpp/src/godot.cpp:35:
/nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/x86_64-w64-mingw32/bits/gthr-default.h:34:10: fatal error: mcfgthread/gthr.h: No such file or directory
   34 | #include <mcfgthread/gthr.h>
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
scons: *** [godot-cpp/src/godot.windows.template_debug.x86_64.o] Error 1
In file included from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/x86_64-w64-mingw32/bits/gthr.h:148,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ext/atomicity.h:35,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/bits/ios_base.h:39,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ios:44,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ostream:40,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/iostream:41,
                 from godot-cpp/include/godot_cpp/core/method_bind.hpp:46,
                 from godot-cpp/include/godot_cpp/core/class_db.hpp:38,
                 from godot-cpp/src/core/object.cpp:33:
/nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/x86_64-w64-mingw32/bits/gthr-default.h:34:10: fatal error: mcfgthread/gthr.h: No such file or directory
   34 | #include <mcfgthread/gthr.h>
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
scons: *** [godot-cpp/src/core/object.windows.template_debug.x86_64.o] Error 1
In file included from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/x86_64-w64-mingw32/bits/gthr.h:148,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ext/atomicity.h:35,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/bits/ios_base.h:39,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ios:44,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ostream:40,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/iostream:41,
                 from godot-cpp/include/godot_cpp/core/method_bind.hpp:46,
                 from godot-cpp/include/godot_cpp/core/class_db.hpp:38,
                 from godot-cpp/src/core/class_db.cpp:31:
/nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/x86_64-w64-mingw32/bits/gthr-default.h:34:10: fatal error: mcfgthread/gthr.h: No such file or directory
   34 | #include <mcfgthread/gthr.h>
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
scons: *** [godot-cpp/src/core/class_db.windows.template_debug.x86_64.o] Error 1
In file included from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/x86_64-w64-mingw32/bits/gthr.h:148,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ext/atomicity.h:35,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/bits/ios_base.h:39,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ios:44,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ostream:40,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/iostream:41,
                 from godot-cpp/include/godot_cpp/core/method_bind.hpp:46,
                 from godot-cpp/src/core/method_bind.cpp:31:
/nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/x86_64-w64-mingw32/bits/gthr-default.h:34:10: fatal error: mcfgthread/gthr.h: No such file or directory
   34 | #include <mcfgthread/gthr.h>
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
scons: *** [godot-cpp/src/core/method_bind.windows.template_debug.x86_64.o] Error 1
In file included from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/x86_64-w64-mingw32/bits/gthr.h:148,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ext/atomicity.h:35,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/bits/ios_base.h:39,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ios:44,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/ostream:40,
                 from /nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/iostream:41,
                 from godot-cpp/include/godot_cpp/core/method_bind.hpp:46,
                 from godot-cpp/include/godot_cpp/core/class_db.hpp:38,
                 from godot-cpp/src/variant/variant.cpp:36:
/nix/store/17iax51h3dgabmd819hcygpw86dn2wj4-x86_64-w64-mingw32-gcc-13.3.0/include/c++/13.3.0/x86_64-w64-mingw32/bits/gthr-default.h:34:10: fatal error: mcfgthread/gthr.h: No such file or directory
   34 | #include <mcfgthread/gthr.h>
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
scons: *** [godot-cpp/src/variant/variant.windows.template_debug.x86_64.o] Error 1
scons: building terminated because of errors.

when trying to build, Godot requires mcfgthread, which is missing. This is where my problem lies right now. I don’t know how to make mcfgthread available in the dev shell for use in the compilation process, even though I have come across it inside nixpkgs.

So in my setup so far I have added pkgs.pkgsCross.mingwW64.buildPackages.gcc to the packages available in my dev shell. This evidently works and Scons can use it to build, it just fails because of the still missing mcfgthread (from what I have gathered).

I have explored nixpkgs using nix repl aswell as just the source on GitHub for a bit now and have found that
a) mcfgthread is available as a windows package (???) and that
b) a patch adding the mcfgthread functionality to gcc also exists in nixpkgs
Now I tried adding the mcfgthreads windows package (pkgs.pkgsBuildTarget.windows.mcfgtheads), but - not really surprisingly - the dev shell could not activate like this, because of the platform mismatch. Just on the side, I did not know that windows packages somehow exist in nixpkgs, so some explanation on that would be helpful aswell.
However, with the patch for gcc, that is somehow available in nixpkgs, I don’t know how one would be able to access this. I could not really find out if there is an override in the gcc package or how to get the patches to be included in my “install” of gcc. Would I have to make an overlay? Also is this maybe only available for the regular linux gcc and not for mingw?

Any help and explanation on this is much appreciated. Even without any experience using Scons (which I don’t have either) or Godot.
Thanks in advance!