-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathflake.nix
More file actions
141 lines (131 loc) · 4.74 KB
/
Copy pathflake.nix
File metadata and controls
141 lines (131 loc) · 4.74 KB
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
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default";
rust-overlay.url = "github:oxalica/rust-overlay";
crane.url = "github:ipetkov/crane";
};
outputs =
inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;
perSystem =
{
self',
system,
...
}:
let
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
inputs.rust-overlay.overlays.default
];
};
lib = pkgs.lib;
# Keep in sync with `rust-version` in Cargo.toml.
rustToolchain = pkgs.rust-bin.stable."1.89.0".default.override {
extensions = [
"rust-src"
"rust-analyzer"
"clippy"
];
};
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rustToolchain;
# Libraries that Blitz loads at runtime via `dlopen` (winit + wgpu).
# They are not needed to *build*, but a Blitz app needs them on
# `LD_LIBRARY_PATH` to open a window and talk to the GPU.
runtimeLibs = lib.optionals pkgs.stdenv.isLinux [
pkgs.wayland
pkgs.libxkbcommon
pkgs.libGL
pkgs.vulkan-loader
pkgs.libx11
pkgs.libxcursor
pkgs.libxi
pkgs.libxrandr
pkgs.libxcb
];
# Dependencies needed to build Blitz:
# * openssl -> openssl-sys, via reqwest in blitz-net
# * fontconfig -> yeslogic-fontconfig-sys, via parley/fontique
rustBuildInputs = [
pkgs.openssl
]
++ lib.optionals pkgs.stdenv.isLinux (
[ pkgs.fontconfig ] ++ runtimeLibs
)
++ lib.optionals pkgs.stdenv.isDarwin [
pkgs.apple-sdk
pkgs.libiconv
];
# `python3` is required at build time to generate code for `stylo`.
rustNativeBuildInputs = [
pkgs.pkg-config
pkgs.python3
];
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
fullSrc = pkgs.lib.cleanSource ./.;
commonArgs = {
src = fullSrc;
strictDeps = true;
buildInputs = rustBuildInputs;
nativeBuildInputs = rustNativeBuildInputs;
};
rustPackage =
package:
{
binary ? package,
features ? [ ],
}:
craneLib.buildPackage (
commonArgs
// {
pname = package;
version = cargoToml.workspace.package.version;
# Blitz's workspace root is a *virtual* manifest (no root
# `[package]`), so build deps and the crate together in one
# derivation instead of crane's dummy deps-only layer.
cargoArtifacts = null;
cargoExtraArgs = "--locked --package ${package} ${
lib.concatStringsSep " " (map (f: "--features ${f}") features)
}";
doCheck = false; # Disable tests to avoid building deps for them
nativeBuildInputs = rustNativeBuildInputs ++ [ pkgs.makeWrapper ];
installPhaseCommand = ''
mkdir -p $out/bin
cp target/release/${binary} $out/bin/
''
+ lib.optionalString pkgs.stdenv.isLinux ''
wrapProgram $out/bin/${binary} \
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath runtimeLibs}
'';
}
);
in
{
# The example browser app (`apps/browser`), whose binary is `blitz`.
packages.browser = rustPackage "browser" {
binary = "blitz";
};
packages.default = self'.packages.browser;
devShells.default = pkgs.mkShell {
name = "blitz-dev";
buildInputs = rustBuildInputs;
nativeBuildInputs = rustNativeBuildInputs ++ [
rustToolchain
];
shellHook = ''
# For rust-analyzer 'hover' tooltips to work.
export RUST_SRC_PATH="${rustToolchain}/lib/rustlib/src/rust/library";
''
+ lib.optionalString pkgs.stdenv.isLinux ''
# Blitz dlopen's these at runtime; make them discoverable when
# running examples/apps from inside the dev shell.
export LD_LIBRARY_PATH="${lib.makeLibraryPath runtimeLibs}:$LD_LIBRARY_PATH"
'';
};
};
};
}