-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
175 lines (146 loc) · 5.21 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Based on https://github.com/nix-community/naersk/blob/master/examples/multi-target/flake.nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
fenix.url = "github:nix-community/fenix";
naersk.url = "github:nix-community/naersk";
};
outputs = { self, fenix, flake-utils, naersk, nixpkgs }:
flake-utils.lib.eachDefaultSystem (system:
let
pname = "gametemplate";
pkgs = (import nixpkgs) { inherit system; };
toolchain = with fenix.packages.${system};
combine [
minimal.rustc
minimal.cargo
complete.clippy
complete.rust-analyzer
complete.rust-src
complete.rustfmt
targets.x86_64-unknown-linux-gnu.latest.rust-std
targets.wasm32-unknown-unknown.latest.rust-std
targets.x86_64-pc-windows-gnu.latest.rust-std
];
naersk' = naersk.lib.${system}.override {
cargo = toolchain;
rustc = toolchain;
};
naerskBuildPackage = target: args:
naersk'.buildPackage
(args // { CARGO_BUILD_TARGET = target; } // cargoConfig);
# All of the CARGO_* configurations which should be used for all
# targets.
#
# Only use this for options which should be universally applied or which
# can be applied to a specific target triple.
#
# This is also merged into the devShell.
cargoConfig = {
# Tells Cargo that it should use Wine to run tests.
# (https://doc.rust-lang.org/cargo/reference/config.html#targettriplerunner)
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUNNER =
pkgs.writeScript "wine-wrapper" ''
export WINEPREFIX="$(mktemp -d)"
exec wine64 $@
'';
};
libPath = with pkgs;
lib.makeLibraryPath [ libGL xorg.libX11 xorg.libXi libxkbcommon alsa-lib ];
in rec {
defaultPackage = packages.${pname};
# For `nix build .#${pname}`
packages.${pname} =
naerskBuildPackage "x86_64-unknown-linux-gnu" {
src = ./.;
pname = "${pname}";
doCheck = true;
nativeBuildInputs = with pkgs; [ makeWrapper ];
release = false;
cargoBuildOptions = (x: x ++ [ "--profile=release-lto" ]);
cargoTestOptions = (x: x ++ [ "--all" ]);
postInstall = ''
wrapProgram "$out/bin/${pname}" --prefix LD_LIBRARY_PATH : "${libPath}"
'';
};
# For `nix build .#${pname}-tty`
packages."${pname}-tty" =
naerskBuildPackage "x86_64-unknown-linux-gnu" {
src = ./.;
pname = "${pname}-tty";
doCheck = true;
release = false;
cargoBuildOptions = (x:
x ++ [
"--profile=release-lto"
"--no-default-features"
"--features=tty"
]);
cargoTestOptions = (x: x ++ [ "--all" ]);
# XXX: Is there a better way to specify target binary should be named differently for this target?
postInstall = ''
mv "$out/bin/${pname}" "$out/bin/${pname}-tty"
'';
};
# For `nix build .#${pname}-wasm`:
packages."${pname}-wasm" =
naerskBuildPackage "wasm32-unknown-unknown" {
src = ./.;
doCheck = false;
strictDeps = true;
release = false;
cargoBuildOptions = (x: x ++ [ "--profile=release-lto" ]);
cargoTestOptions = (x: x ++ [ "--all" ]);
};
# For `nix build .#${pname}-win`:
packages."${pname}-win" =
naerskBuildPackage "x86_64-pc-windows-gnu" {
src = ./.;
# FIXME: Unit test running doesn't work in cross-compile build
#doCheck = true;
strictDeps = true;
release = false;
cargoBuildOptions = (x: x ++ [ "--profile=release-lto" ]);
cargoTestOptions = (x: x ++ [ "--all" ]);
depsBuildBuild = with pkgs; [
pkgsCross.mingwW64.stdenv.cc
pkgsCross.mingwW64.windows.pthreads
];
nativeBuildInputs = with pkgs;
[
# We need Wine to run tests:
wineWowPackages.stable
];
};
devShell = pkgs.mkShell ({
inputsFrom = [ packages."${pname}" packages."${pname}-win" ];
buildInputs = with pkgs; [
cargo-outdated
cargo-udeps
# Needed by miniquad
libGL
xorg.libX11
xorg.libXi
libxkbcommon
alsa-lib
# JS minifier
minify
# Profiling
linuxPackages.perf
hotspot
# Utils
grafx2
just
neovim-qt
optipng
snzip
tiled
];
CARGO_BUILD_TARGET = "x86_64-unknown-linux-gnu";
LD_LIBRARY_PATH = libPath;
RUST_BACKTRACE = "1";
RUST_LOG = "info";
} // cargoConfig);
});
}