I’m trying to cross-compile some Rust code from NixOS to Windows with MinGW.
I have a cursed-feeling issue:
- When I attempted to build my Rust project, it was linked with
x86_64-w64-mingw32-gcc
as expected. I got the errorcannot find -l:libpthread.a
, so I added the library to mybuildPackages
. - After adding the library, for some reason Rust switches to
cc
for linking. This time, the error I get islibpthread.a: error adding symbols: file format not recognized
because it’s using the wrong linker.
I think it’s an issue with pkg-config, but not sure what. I tried adding pkg-config
itself to my buildPackages
but it fails to build.
Here’s my shell.nix
after adding the library:
let
unstable = import (fetchTarball https://nixos.org/channels/nixos-unstable/nixexprs.tar.xz);
pkgs = unstable {
crossSystem = { config = "x86_64-w64-mingw32"; };
overlays = [
(import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz"))
];
};
rust = pkgs.buildPackages.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" "rust-analysis" ];
targets = [ "x86_64-pc-windows-gnu" ];
};
in pkgs.mkShell {
nativeBuildInputs = with pkgs; [
rust
];
buildInputs = with pkgs; [
windows.mingw_w64_pthreads
windows.pthreads
];
}
To reproduce it you’ll also need a dependency like crc32fast = "1.2.0"
.
I’m not sure what next steps to take. Thanks!