diff --git a/docs/cross_compilation.md b/docs/cross_compilation.md index 580c4ce3..8851c3b8 100644 --- a/docs/cross_compilation.md +++ b/docs/cross_compilation.md @@ -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 diff --git a/examples/cross-mingw/flake.nix b/examples/cross-mingw/flake.nix new file mode 100644 index 00000000..1a7ca049 --- /dev/null +++ b/examples/cross-mingw/flake.nix @@ -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"; + }) {}; + }; + }; +}