Openblas crosscompilation issue with MinGW

Hi,

Openblas (https://www.openblas.net/) is a widely used BLAS library for scientific computing. The library builds just fine with MinGW on windows & arch linux.

Unfortunately, the Nix package does not support the x86_64-windows platform, so my first idea (knowing that it should work fine) was to just manually add that platform and try to build it. However, this pulls mingw-w64-gcc with gfortran enabled, which fails to build: libgfortran error: unknown type name 'pthread_t'.

Some additional digging seems to indicate some problem with the threads implementation used by MinGW (or maybe some configuration clash in the specific case of libgfortran).

A solution which has been working great for me would be to use a fully binary MinGW release, for example the precompiled stuff from https://sourceforge.net/projects/mingw-w64-builds/. But trying to package this for Nix seems over my head with my current knowledge of the Nix system.

Any ideas how to get this going on Nix so I won’t have to keep other distros/containers around just for crosscompilation?

EDIT: a minimal shell.nix:

let
  pkgs = import <nixpkgs> {
    crossSystem = {
      config = "x86_64-w64-mingw32";
      libc = "msvcrt"; # This distinguishes the mingw (non posix) toolchain
    };
  }; 
  openblas = pkgs.callPackage ./openblas.nix{}; # added windows platform
in
  pkgs.stdenv.mkDerivation {
    name = "test";
    hardeningDisable = [ "all" ]; 
    buildInputs = with pkgs; [ openblas ];
  }

There is pkgs.pkgsCross.mingwW64 to have a nixpkgs configured for cross compilation to mingwW64 compilation.

Else, it seem that pkgsCross.mingwW64.windows.pthreads come with the pthreads library, but it seem to have error with the linker when I want to compile a rust program (or the rust compiler with windows as a target).

I otherwise don’t have a good knowledge with windows cross compiling, so I will also be interested by an answer here.