This repository has been archived by the owner on Apr 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
flake.nix
231 lines (183 loc) · 7.09 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
{
description = "Javascript bindings for the ACVM";
inputs = {
nixpkgs = {
url = "github:NixOS/nixpkgs/nixos-22.11";
};
flake-utils = {
url = "github:numtide/flake-utils";
};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
# All of these inputs (a.k.a. dependencies) need to align with inputs we
# use so they use the `inputs.*.follows` syntax to reference our inputs
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
crane = {
url = "github:ipetkov/crane";
# All of these inputs (a.k.a. dependencies) need to align with inputs we
# use so they use the `inputs.*.follows` syntax to reference our inputs
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
flake-compat.follows = "flake-compat";
rust-overlay.follows = "rust-overlay";
};
};
};
outputs =
{ self, nixpkgs, crane, flake-utils, rust-overlay, ... }: #, barretenberg
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
rust-overlay.overlays.default
];
};
rustToolchain = pkgs.rust-bin.stable."1.66.0".default.override {
# We include rust-src to ensure rust-analyzer works.
# See https://discourse.nixos.org/t/rust-src-not-found-and-other-misadventures-of-developing-rust-on-nixos/11570/4
extensions = [ "rust-src" ];
targets = [ "wasm32-unknown-unknown" ]
++ pkgs.lib.optional (pkgs.hostPlatform.isx86_64 && pkgs.hostPlatform.isLinux) "x86_64-unknown-linux-gnu"
++ pkgs.lib.optional (pkgs.hostPlatform.isAarch64 && pkgs.hostPlatform.isLinux) "aarch64-unknown-linux-gnu"
++ pkgs.lib.optional (pkgs.hostPlatform.isx86_64 && pkgs.hostPlatform.isDarwin) "x86_64-apple-darwin"
++ pkgs.lib.optional (pkgs.hostPlatform.isAarch64 && pkgs.hostPlatform.isDarwin) "aarch64-apple-darwin";
};
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
crateACVMJSDefinitions = craneLib.crateNameFromCargoToml {
cargoToml = ./acvm_js/Cargo.toml;
};
crateACVMDefinitions = craneLib.crateNameFromCargoToml {
cargoToml = ./acvm/Cargo.toml;
};
sharedEnvironment = {
# Barretenberg fails if tests are run on multiple threads, so we set the test thread
# count to 1 throughout the entire project
#
# Note: Setting this allows for consistent behavior across build and shells, but is mostly
# hidden from the developer - i.e. when they see the command being run via `nix flake check`
# RUST_TEST_THREADS = "1";
BARRETENBERG_ARCHIVE = builtins.fetchurl {
url = "https://github.com/AztecProtocol/barretenberg/releases/download/barretenberg-v0.4.5/acvm_backend.wasm.tar.gz";
sha256 = "sha256:0z24yhvxc0dr13xj7y4xs9p42lzxwpazrmsrdpcgynfajkk6vqy4";
};
};
wasmEnvironment = sharedEnvironment // { };
sourceFilter = path: type:
(craneLib.filterCargoSources path type);
# The `self.rev` property is only available when the working tree is not dirty
GIT_COMMIT = if (self ? rev) then self.rev else "unknown";
GIT_DIRTY = if (self ? rev) then "false" else "true";
extraBuildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin [
# Need libiconv and apple Security on Darwin. See https://github.com/ipetkov/crane/issues/156
pkgs.libiconv
pkgs.darwin.apple_sdk.frameworks.Security
];
commonArgs = {
inherit (crateACVMDefinitions) pname version;
src = pkgs.lib.cleanSourceWith {
src = craneLib.path {
path = ./.;
};
filter = sourceFilter;
};
cargoClippyExtraArgs = "--package acvm_js --all-targets -- -D warnings";
cargoTestExtraArgs = "--workspace";
# We don't want to run checks or tests when just building the project
doCheck = false;
};
# Combine the environment and other configuration needed for crane to build with the wasm feature
acvmjsWasmArgs = wasmEnvironment // commonArgs // {
inherit (crateACVMJSDefinitions) pname version;
cargoExtraArgs = "--package acvm_js --target=wasm32-unknown-unknown";
cargoVendorDir = craneLib.vendorCargoDeps {
src = ./.;
};
buildInputs = [ ] ++ extraBuildInputs;
};
# Build *just* the cargo dependencies, so we can reuse all of that work between runs
cargo-artifacts = craneLib.buildDepsOnly commonArgs;
wasm-bindgen-cli = pkgs.callPackage ./acvm_js/nix/wasm-bindgen-cli/default.nix {
rustPlatform = pkgs.makeRustPlatform {
rustc = rustToolchain;
cargo = rustToolchain;
};
};
in
rec {
checks = {
cargo-clippy = craneLib.cargoClippy (commonArgs // sharedEnvironment // {
inherit GIT_COMMIT GIT_DIRTY;
cargoArtifacts = cargo-artifacts;
doCheck = true;
});
cargo-test = craneLib.cargoTest (commonArgs // sharedEnvironment // {
inherit GIT_COMMIT GIT_DIRTY;
cargoArtifacts = cargo-artifacts;
doCheck = true;
});
cargo-fmt = craneLib.cargoFmt (commonArgs // sharedEnvironment // {
inherit GIT_COMMIT GIT_DIRTY;
cargoArtifacts = cargo-artifacts;
doCheck = true;
});
};
packages = {
default = craneLib.mkCargoDerivation (acvmjsWasmArgs // rec {
cargoArtifacts = cargo-artifacts;
inherit GIT_COMMIT;
inherit GIT_DIRTY;
COMMIT_SHORT = builtins.substring 0 7 GIT_COMMIT;
VERSION_APPENDIX = if GIT_DIRTY == "true" then "-dirty" else "";
src = ./.; #craneLib.cleanCargoSource (craneLib.path ./.);
nativeBuildInputs = with pkgs; [
binaryen
which
git
jq
rustToolchain
wasm-bindgen-cli
];
CARGO_TARGET_DIR = "./target";
buildPhaseCargoCommand = ''
bash ./acvm_js/buildPhaseCargoCommand.sh
'';
installPhase = ''
bash ./acvm_js/installPhase.sh
'';
});
inherit cargo-artifacts;
};
# Setup the environment to match the stdenv from `nix build` & `nix flake check`, and
# combine it with the environment settings, the inputs from our checks derivations,
# and extra tooling via `nativeBuildInputs`
devShells.default = pkgs.mkShell (wasmEnvironment // {
# inputsFrom = builtins.attrValues checks;
nativeBuildInputs = with pkgs; [
starship
nil
nixpkgs-fmt
which
git
jq
toml2json
rustToolchain
wasm-bindgen-cli
nodejs
yarn
];
shellHook = ''
eval "$(starship init bash)"
'';
});
});
}