forked from wizardsardine/liana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
199 lines (169 loc) · 6.57 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
{
description = "Dev shell to help contributing to liana";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
crane.url = "github:ipetkov/crane";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
lipo.url = "github:edouardparis/lipo-flake";
};
outputs = { self, nixpkgs, flake-utils, crane, fenix, lipo, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; config = { allowUnfree = true; };};
inherit (pkgs) lib;
toolchain = with fenix.packages.${system};
combine [
minimal.rustc
minimal.cargo
targets.x86_64-pc-windows-gnu.latest.rust-std
targets.aarch64-apple-darwin.latest.rust-std
targets.x86_64-apple-darwin.latest.rust-std
];
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
commonBuildSettings = {
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
(craneLib.fileset.commonCargoSources ./.)
(lib.fileset.maybeMissing ./liana-ui/static)
];
};
strictDeps = true;
doCheck = false;
};
x86_64-pc-windows-gnu = craneLib.buildPackage {
inherit (commonBuildSettings) src strictDeps doCheck;
CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu";
CARGO_BUILD_RUSTFLAGS = "-C link-arg=-Wl,--no-insert-timestamp";
TARGET_CC = "${pkgs.pkgsCross.mingwW64.stdenv.cc}/bin/${pkgs.pkgsCross.mingwW64.stdenv.cc.targetPrefix}cc";
pname = "liana-gui";
cargoExtraArgs = "-p liana-gui";
depsBuildBuild = with pkgs; [
pkgsCross.mingwW64.stdenv.cc
pkgsCross.mingwW64.windows.pthreads
];
installPhaseCommand = ''
mkdir -p $out/x86_64-pc-windows-gnu
cp target/x86_64-pc-windows-gnu/release/liana-gui.exe $out/x86_64-pc-windows-gnu
'';
};
x86_64-apple-darwin = craneLib.buildPackage {
inherit (commonBuildSettings) src strictDeps doCheck;
CARGO_BUILD_TARGET = "x86_64-apple-darwin";
buildPhaseCargoCommand = "cargo zigbuild --release --message-format json-render-diagnostics";
depsBuildBuild = [
pkgs.zig
pkgs.cargo-zigbuild
pkgs.darwin.xcode_12_2
];
preBuild = ''
export SDKROOT=${pkgs.darwin.xcode_12_2}/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
export XDG_CACHE_HOME=$TMPDIR/xdg_cache
mkdir -p $XDG_CACHE_HOME
export CARGO_ZIGBUILD_CACHE_DIR=$TMPDIR/cargo-zigbuild-cache
mkdir -p $CARGO_ZIGBUILD_CACHE_DIR
export CC=zigcc
export CXX=zigc++
# rcodesign needs place to sign binary
export RUSTFLAGS="-C link-arg=-Wl,-headerpad_max_install_names"
'';
installPhaseCommand = ''
mkdir -p $out/x86_64-apple-darwin
cp target/x86_64-apple-darwin/release/liana-gui $out/x86_64-apple-darwin
cp target/x86_64-apple-darwin/release/lianad $out/x86_64-apple-darwin
cp target/x86_64-apple-darwin/release/liana-cli $out/x86_64-apple-darwin
'';
};
aarch64-apple-darwin = craneLib.buildPackage {
inherit (commonBuildSettings) src strictDeps doCheck;
CARGO_BUILD_TARGET = "aarch64-apple-darwin";
buildPhaseCargoCommand = "cargo zigbuild --release --message-format json-render-diagnostics";
depsBuildBuild = [
pkgs.zig
pkgs.cargo-zigbuild
pkgs.darwin.xcode_12_2
];
preBuild = ''
export SDKROOT=${pkgs.darwin.xcode_12_2}/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
export XDG_CACHE_HOME=$TMPDIR/xdg_cache
mkdir -p $XDG_CACHE_HOME
export CARGO_ZIGBUILD_CACHE_DIR=$TMPDIR/cargo-zigbuild-cache
mkdir -p $CARGO_ZIGBUILD_CACHE_DIR
export CC=zigcc
export CXX=zigc++
'';
installPhaseCommand = ''
mkdir -p $out/aarch64-apple-darwin
cp target/aarch64-apple-darwin/release/liana-gui $out/aarch64-apple-darwin
cp target/aarch64-apple-darwin/release/lianad $out/aarch64-apple-darwin
cp target/aarch64-apple-darwin/release/liana-cli $out/aarch64-apple-darwin
'';
};
universal2-apple-darwin = pkgs.runCommand "universal2-apple-darwin" {
buildInputs = [ lipo.packages.${system}.lipo ];
# Declare dependencies by referencing them in the command
# No need to include x86_64-apple-darwin and aarch64-apple-darwin in buildInputs
# because they are referenced directly
} ''
mkdir -p $out/universal2-apple-darwin
# Combine liana-gui binaries
lipo -output $out/universal2-apple-darwin/liana-gui -create \
${x86_64-apple-darwin}/x86_64-apple-darwin/liana-gui \
${aarch64-apple-darwin}/aarch64-apple-darwin/liana-gui
'';
devShell = pkgs.mkShell rec {
buildInputs = with pkgs; [
expat
fontconfig
freetype
freetype.dev
libGL
pkg-config
udev
wayland
libxkbcommon
xorg.libX11
xorg.libXcursor
xorg.libXi
xorg.libXrandr
];
LD_LIBRARY_PATH =
builtins.foldl' (a: b: "${a}:${b}/lib") "${pkgs.vulkan-loader}/lib" buildInputs;
};
releaseShell = pkgs.mkShell {
buildInputs = [
pkgs.zip
pkgs.unzip
pkgs.gnutar
pkgs.dpkg
pkgs.rcodesign
];
};
in {
packages = {
x86_64-pc-windows-gnu = x86_64-pc-windows-gnu;
x86_64-apple-darwin = x86_64-apple-darwin;
aarch64-apple-darwin = aarch64-apple-darwin;
universal2-apple-darwin = universal2-apple-darwin;
release = pkgs.buildEnv {
name = "release";
paths = [
x86_64-pc-windows-gnu
x86_64-apple-darwin
aarch64-apple-darwin
universal2-apple-darwin
];
};
};
devShells = {
dev = devShell;
release = releaseShell;
default = devShell;
};
}
);
}