Repository navigation
Expand file tree
/
Copy pathcrane-build.nix
More file actions
184 lines (159 loc) · 4.52 KB
/
Copy pathcrane-build.nix
File metadata and controls
184 lines (159 loc) · 4.52 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
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
{
lib,
pkgs,
stdenvNoCC,
# build time
jq,
pkg-config,
rustPlatform,
rust-bindgen,
versionCheckHook,
# run time
fuse3,
keyutils,
libaio,
libsodium,
libunwind,
liburcu,
libuuid,
lz4,
udev,
zlib,
zstd,
crane,
rustVersion ? "latest",
version,
}:
let
# Use the build-platform toolchain with the target added, so cross builds
# cross-compile with the binary x86_64 rustc + the target's std rather than
# building a cross rustc from source (slow, and trips rustc bootstrap bugs).
# For native builds pkgsBuildHost == pkgs and the target is native, so this is
# a no-op.
craneLib = (crane.mkLib pkgs).overrideToolchain (
_: pkgs.pkgsBuildHost.rust-bin.stable."${rustVersion}".minimal.override {
extensions = [ "clippy" ];
# outer (cross) pkgs: the host platform is the cross target, so we add its
# rust-std to the build-platform toolchain. crane calls this with the
# build-platform pkgs, so taking the target from there would be a no-op.
targets = [ pkgs.stdenv.hostPlatform.rust.rustcTarget ];
}
);
args = {
inherit version;
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.fileFilter ({ hasExt, ... }: !hasExt "nix") ./.;
};
strictDeps = true;
env = {
# bindgen runs at build time, so it must be the build-platform binary;
# referencing the (cross) host package here drags in a from-source cross
# rust toolchain (rustc/cargo/rustfmt-nightly).
BINDGEN = "${pkgs.buildPackages.rust-bindgen}/bin/bindgen";
PKG_CONFIG_SYSTEMD_SYSTEMDSYSTEMUNITDIR = "${placeholder "out"}/lib/systemd/system";
PKG_CONFIG_UDEV_UDEVDIR = "${placeholder "out"}/lib/udev";
};
makeFlags = [
"INITRAMFS_DIR=${placeholder "out"}/etc/initramfs-tools"
"PREFIX=${placeholder "out"}"
"VERSION=${version}"
];
dontStrip = true;
nativeBuildInputs = [
jq
pkg-config
rustPlatform.bindgenHook
rust-bindgen
];
buildInputs = [
keyutils
libaio
libsodium
libunwind
liburcu
libuuid
lz4
udev
zlib
zstd
];
checkFlags = lib.optionals (stdenvNoCC.hostPlatform.isAarch64) [
"--skip=bcachefs::bindgen_test_layout_bch_replicas_padded__bindgen_ty_1"
"--skip=bcachefs::bindgen_test_layout_bch_replicas_padded__bindgen_ty_2"
"--skip=bcachefs::bindgen_test_layout_bch_replicas_padded__bindgen_ty_3"
"--skip=bcachefs::bindgen_test_layout_bch_replicas_padded__bindgen_ty_4"
];
checkPhaseCargoCommand = ''
cargo test --profile release -- --nocapture $checkFlags
'';
};
cargoArtifacts = craneLib.buildDepsOnly args;
package = craneLib.buildPackage (
args
// {
inherit cargoArtifacts;
outputs = [
"out"
"dkms"
];
makeFlags = args.makeFlags ++ [
"DKMSDIR=${placeholder "dkms"}"
];
enableParallelBuilding = true;
buildPhaseCargoCommand = ''
make ''${enableParallelBuilding:+-j''${NIX_BUILD_CORES}} $makeFlags
'';
doNotPostBuildInstallCargoBinaries = true;
enableParallelInstalling = true;
installPhaseCommand = ''
make ''${enableParallelInstalling:+-j''${NIX_BUILD_CORES}} $makeFlags install install_dkms
'';
doInstallCheck = true;
nativeInstallCheckInputs = [ versionCheckHook ];
versionCheckProgramArg = "version";
passthru.kernelModule = import ./module-build.nix package;
meta = {
description = "Userspace tools for bcachefs";
license = lib.licenses.gpl2Only;
mainProgram = "bcachefs";
};
}
);
packageFuse = package.overrideAttrs (
final: prev: {
makeFlags = prev.makeFlags ++ [ "BCACHEFS_FUSE=1" ];
buildInputs = prev.buildInputs ++ [ fuse3 ];
}
);
cargo-clippy = craneLib.cargoClippy (
args
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets --all-features -- --deny warnings";
}
);
# we have to build our own `craneLib.cargoTest`
cargo-test = craneLib.mkCargoDerivation (
args
// {
inherit cargoArtifacts;
doCheck = true;
enableParallelChecking = true;
pnameSuffix = "-test";
buildPhaseCargoCommand = "";
checkPhaseCargoCommand = ''
make ''${enableParallelChecking:+-j''${NIX_BUILD_CORES}} $makeFlags libbcachefs.a
cargo test --profile release -- --nocapture $checkFlags
'';
}
);
in
{
inherit
cargo-clippy
cargo-test
package
packageFuse
;
}