Continuation from my previous post: I want to cross-compile a windows binary from my NixOS system. I’ve spent this morning looking at tutorials and previous help posts, but haven’t ended up with anything that works yet. Here’s the repo for the project: https://gitgud.io/neropatti/peanuts
I’m trying to compile with the command cargo build --target x86_64-pc-windows-gnu using this shell.nix:
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
# nativeBuildInputs is usually what you want -- tools you need to run
nativeBuildInputs = with pkgs.buildPackages; [
gcc
#python3
rust-analyzer
cargo
rustfmt
];
LD_LIBRARY_PATH = with pkgs; lib.makeLibraryPath [
libGL
libxkbcommon
wayland
vulkan-loader
];
}
And got this output:
error[E0463]: can't find crate for `core`
|
= note: the `x86_64-pc-windows-gnu` target may not be installed
= help: consider downloading the target with `rustup target add x86_64-pc-windows-gnu`
For more information about this error, try `rustc --explain E0463`.
error: could not compile `equivalent` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `cfg-if` (lib) due to 1 previous error
error: could not compile `windows-link` (lib) due to 1 previous error
error[E0463]: can't find crate for `std`
|
= note: the `x86_64-pc-windows-gnu` target may not be installed
= help: consider downloading the target with `rustup target add x86_64-pc-windows-gnu`
error: could not compile `bitflags` (lib) due to 1 previous error
error: could not compile `foldhash` (lib) due to 1 previous error
error: could not compile `log` (lib) due to 1 previous error
error: could not compile `allocator-api2` (lib) due to 1 previous error
error: could not compile `unicode-width` (lib) due to 1 previous error
error: could not compile `libm` (lib) due to 1 previous error
I tried using rustup instead and installed the windows toolchain with rustup target add x86_64-pc-windows-gnu, but then got hit with this:
error: error calling dlltool 'x86_64-w64-mingw32-dlltool': No such file or directory (os error 2)
error: could not compile `windows-threading` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `libloading` (lib) due to 1 previous error
error: could not compile `windows-result` (lib) due to 1 previous error
error: could not compile `windows-strings` (lib) due to 1 previous error
I’m assuming I need to somehow provide mingw (if I choose to use rustup), but I have no idea how. I’m also curious how I would provide the cross-compilation toolchain for cargo without using rustup by specifying things in the shell.nix instead!