Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/cross_compilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,12 @@ To try it,
2. `nix develop` to enter the development environment.
3. `make run` to build and run the program in an emulator.

Alternatively, you may use the common `import nixpkgs`-approach instead of `mkRustBin`, especially if you only plan to `import nixpkgs` once. This is probably the case for a typical simple and small project. An example of this can be seen in
[`examples/cross-mingw/flake.nix`](../examples/cross-mingw/flake.nix) (cross-compiling to Windows).
To try it,
1. `cd` into `examples/cross-mingw`.
2. `nix develop` to enter the development environment.
3. `make run` to build and run the program with Wine.

[wiki-cross]: https://wiki.nixos.org/wiki/Cross_Compiling#How_to_specify_dependencies
[flake-cross-issue]: https://github.com/NixOS/nix/issues/5157
38 changes: 38 additions & 0 deletions examples/cross-mingw/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Example flake for `nix develop`.
# See docs/cross_compilation.md for details.
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, rust-overlay, ... }:
let
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
overlays = [ rust-overlay.overlays.default ];
crossSystem.config = "x86_64-w64-mingw32";
};
in
{
devShells.${system} = {
default = pkgs.callPackage (
{ mkShell, stdenv, rust-bin, windows, wine64 }:
mkShell {
nativeBuildInputs = [
rust-bin.stable.latest.minimal
];

depsBuildBuild = [ wine64 ];
buildInputs = [ windows.pthreads ];

CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER = "${stdenv.cc.targetPrefix}cc";
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUNNER = "wine64";
}) {};
};
};
}