-
Notifications
You must be signed in to change notification settings - Fork 0
/
deeper.nix
125 lines (108 loc) · 3.09 KB
/
deeper.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
{
pkgs,
nixpkgs,
system,
craneLib,
craneLibWasm,
rustToolchain,
rustToolchainWasm,
wasmTarget,
nix-gitignore,
std,
}:
let
# Cleaned source
src = nix-gitignore.lib.gitignoreSource ./.;
# some helpful utilities
isLinux = std.string.hasInfix "linux";
isDarwin = std.string.hasInfix "darwin";
isArm64 = std.string.hasInfix "aarch64";
linker =
if isDarwin system
then pkgs.zld
else if isArm64 system
then pkgs.lld
else pkgs.mold;
commonArgs = {
inherit src;
buildInputs = [
pkgs.libclang.lib
pkgs.libiconv
pkgs.shaderc
pkgs.shaderc.lib
pkgs.SDL2
pkgs.vulkan-loader
pkgs.makeWrapper
] ++ std.list.optionals (isLinux system) [
pkgs.alsaLib
pkgs.xorg.libX11
pkgs.xorg.libXcursor
pkgs.xorg.libXrandr
pkgs.xorg.libXi
pkgs.libxkbcommon
pkgs.mesa
pkgs.udev
#pkgs.vulkan-headers
#pkgs.vulkan-tools
pkgs.vulkan-validation-layers
] ++ std.list.optionals (isDarwin system) [
pkgs.darwin.apple_sdk.frameworks.AppKit
];
nativeBuildInputs = [
pkgs.pkgconfig
pkgs.gdb
linker
] ++ std.list.optionals (isLinux system) [
pkgs.valgrind
pkgs.renderdoc
];
};
# Helper simply to prevent annoying indentation.
# Justification for its existence may be dubious.
withCommonArgs = x: commonArgs // x;
cargoArtifacts = craneLib.buildDepsOnly (withCommonArgs {});
in
rec {
inherit rustToolchain;
inherit rustToolchainWasm;
inherit commonArgs;
inherit linker;
app = craneLib.buildPackage (withCommonArgs ({
inherit cargoArtifacts;
postInstall = ''
# Make sure assets are findable
cp -r assets/ $out/bin/
# Needed for graphics
wrapProgram $out/bin/deeper \
--prefix LD_LIBRARY_PATH : "${pkgs.lib.makeLibraryPath [ pkgs.vulkan-loader ]}"
'';
}) // (if isLinux system && !(isArm64 system) then {
CARGO_LINKER = "clang";
CARGO_RUSTFLAGS = "-Clink-arg=-fuse-ld=${pkgs.mold}/bin/mold";
} else {}));
wasm = craneLibWasm.buildPackage (withCommonArgs {
inherit cargoArtifacts;
cargoExtraArgs = "--target ${wasmTarget}";
# Override crane's use of --workspace, which tries to build everything
cargoCheckCommand = "cargo check --release";
cargoBuildCommand = "cargo build --release";
# https://github.com/gfx-rs/wgpu/discussions/1776
# https://github.com/gfx-rs/wgpu/wiki/Running-on-the-Web-with-WebGPU-and-WebGL
RUSTFLAGS = "--cfg=web_sys_unstable_apis";
# Tests currently need to be run via `cargo wasi` which
# isn't packaged in nixpkgs yet
doCheck = false;
});
wasmRunner = pkgs.writeShellApplication {
name = "run-deeper-wasm";
text = ''
export CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN="wasm-server-runner"
export WASM_SERVER_RUNNER_ADDRESS="127.0.0.1"
export WASM_SERVER_RUNNER_DIRECTORY="."
export WASM_SERVER_RUNNER_HTTPS="true"
export WASM_SERVER_RUNNER_NO_MODULE="false"
wasm-server-runner ${wasm}/bin/deeper.wasm
'';
runtimeInputs = [pkgs.wasm-server-runner];
};
}