-
Notifications
You must be signed in to change notification settings - Fork 5
/
flake.nix
291 lines (245 loc) · 12 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
{
description = "Flake for development workflows.";
inputs = {
rainix.url = "github:rainlanguage/rainix";
rain.url = "github:rainlanguage/rain.cli";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {self, flake-utils, rainix, rain }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = rainix.pkgs.${system};
in rec {
packages = rec {
tauri-release-env = rainix.tauri-release-env.${system};
raindex-prelude = rainix.mkTask.${system} {
name = "raindex-prelude";
body = ''
set -euxo pipefail
mkdir -p meta;
forge script --silent ./script/BuildAuthoringMeta.sol;
rain meta build \
-i <(cat ./meta/OrderBookSubParserAuthoringMeta.rain.meta) \
-m authoring-meta-v2 \
-t cbor \
-e deflate \
-l none \
-o meta/OrderBookSubParser.rain.meta \
;
'';
};
ob-rs-test = rainix.mkTask.${system} {
name = "ob-rs-test";
body = ''
set -euxo pipefail
cargo test --workspace
'';
};
tauri-rs-test = rainix.mkTask.${system} {
name = "tauri-rs-test";
body = ''
set -euxo pipefail
cd tauri-app/src-tauri
cargo test
'';
};
ob-tauri-prelude = rainix.mkTask.${system} {
name = "ob-tauri-prelude";
body = ''
set -euxo pipefail
# Generate Typescript types from rust types
mkdir -p tauri-app/src/lib/typeshare
export CARGO_HOME=$(mktemp -d)
cargo install --git https://github.com/tomjw64/typeshare --rev 556b44aafd5304eedf17206800f69834e3820b7c
export PATH=$PATH:$CARGO_HOME/bin
typeshare crates/subgraph/src/types/common.rs crates/subgraph/src/types/order.rs crates/subgraph/src/types/vault.rs crates/subgraph/src/types/order_trade.rs crates/common/src/types/order_detail_extended.rs crates/subgraph/src/vol.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/subgraphTypes.ts;
typeshare crates/settings/src/parse.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/appSettings.ts;
typeshare lib/rain.interpreter/crates/eval/src/trace.rs crates/common/src/fuzz/mod.rs crates/settings/src/config_source.rs crates/settings/src/config.rs crates/settings/src/plot_source.rs crates/settings/src/chart.rs crates/settings/src/deployer.rs crates/settings/src/network.rs crates/settings/src/order.rs crates/settings/src/orderbook.rs crates/settings/src/scenario.rs crates/settings/src/blocks.rs crates/settings/src/token.rs crates/settings/src/deployment.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/config.ts;
typeshare crates/common/src/dotrain_order/mod.rs lib/rain.interpreter/lib/rain.metadata/crates/cli/src/meta/types/authoring/v2.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/authoringMeta.ts;
typeshare crates/quote/src/order_quotes.rs crates/quote/src/quote.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/orderQuote.ts;
typeshare tauri-app/src-tauri/src/toast.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/toast.ts;
typeshare tauri-app/src-tauri/src/transaction_status.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/transactionStatus.ts;
# Fix linting of generated types
cd tauri-app && npm i && npm run lint
'';
additionalBuildInputs = [
pkgs.wasm-bindgen-cli
rainix.rust-toolchain.${system}
rainix.rust-build-inputs.${system}
];
};
ob-tauri-unit-test = rainix.mkTask.${system} {
name = "ob-tauri-unit-test";
body = ''
set -euxo pipefail
cd tauri-app && npm i && npm run test
'';
};
ob-tauri-before-release = rainix.mkTask.${system} {
name = "ob-tauri-before-release";
body = ''
# Idempotently, create new 'release' on sentry for the current commit
sentry-cli releases new -p ''${SENTRY_PROJECT} ''${COMMIT_SHA}
sentry-cli releases set-commits --auto ''${COMMIT_SHA}
# Overwrite env variables with release values
echo SENTRY_AUTH_TOKEN=''${SENTRY_AUTH_TOKEN} >> .env
echo SENTRY_ORG=''${SENTRY_ORG} >> .env
echo SENTRY_PROJECT=''${SENTRY_PROJECT} >> .env
echo VITE_SENTRY_RELEASE=''${COMMIT_SHA} >> .env
echo VITE_SENTRY_ENVIRONMENT=release >> .env
echo VITE_SENTRY_FORCE_DISABLED=false >> .env
echo VITE_SENTRY_DSN=''${SENTRY_DSN} >> .env
echo COMMIT_SHA=''${COMMIT_SHA} >> .env
'';
additionalBuildInputs = [
pkgs.sentry-cli
];
};
ob-tauri-before-build-ci = rainix.mkTask.${system} {
name = "ob-tauri-before-build-ci";
body = ''
# Create env file with working defaults
ENV_FILE=".env"
ENV_EXAMPLE_FILE=".env.example"
cp $ENV_EXAMPLE_FILE $ENV_FILE
# Add walletconnect project id from github action env to .env file
echo VITE_WALLETCONNECT_PROJECT_ID=''${WALLETCONNECT_PROJECT_ID} >> $ENV_FILE
'';
};
ob-tauri-before-build = rainix.mkTask.${system} {
name = "ob-tauri-before-build";
body = ''
set -euxo pipefail
# Source .env file if it exists
ENV_FILE=.env
if [ -f "$ENV_FILE" ]; then
source $ENV_FILE
fi
# Exit if required env variables are not defined
if [ -z "$VITE_WALLETCONNECT_PROJECT_ID" ]; then
echo "Cancelling build: VITE_WALLETCONNECT_PROJECT_ID is not defined"
exit 1
fi
if [ "$VITE_SENTRY_FORCE_DISABLED" != "true" ] &&
(
[ -z "$VITE_SENTRY_DSN" ] ||
[ -z "$VITE_SENTRY_ENVIRONMENT" ] ||
[ -z "$VITE_SENTRY_RELEASE" ]
); then
echo "Cancelling build: EITHER env variable VITE_SENTRY_FORCE_DISABLED=true OR all env variables VITE_SENTRY_DSN, VITE_SENTRY_ENVIRONMENT and VITE_SENTRY_RELEASE must be defined"
exit 1
fi
npm i && npm run build
rm -rf lib
mkdir -p lib
if [ ${if pkgs.stdenv.isDarwin then "1" else "0" } -eq 1 ]; then
cp ${pkgs.libiconv}/lib/libcharset.1.dylib lib/libcharset.1.dylib
chmod +w lib/libcharset.1.dylib
install_name_tool -id @executable_path/../Frameworks/libcharset.1.dylib lib/libcharset.1.dylib
otool -L lib/libcharset.1.dylib
cp ${pkgs.libiconv}/lib/libiconv.2.dylib lib/libiconv.2.dylib
chmod +w lib/libiconv.2.dylib
install_name_tool -id @executable_path/../Frameworks/libiconv.2.dylib lib/libiconv.2.dylib
install_name_tool -change ${pkgs.libiconv}/lib/libcharset.1.dylib @executable_path/../Frameworks/libcharset.1.dylib lib/libiconv.2.dylib
otool -L lib/libiconv.2.dylib
cp ${pkgs.gettext}/lib/libintl.8.dylib lib/libintl.8.dylib
chmod +w lib/libintl.8.dylib
install_name_tool -id @executable_path/../Frameworks/libintl.8.dylib lib/libintl.8.dylib
install_name_tool -change ${pkgs.libiconv}/lib/libiconv.2.dylib @executable_path/../Frameworks/libiconv.2.dylib lib/libintl.8.dylib
otool -L lib/libintl.8.dylib
cp ${pkgs.libusb}/lib/libusb-1.0.0.dylib lib/libusb-1.0.0.dylib
chmod +w lib/libusb-1.0.0.dylib
install_name_tool -id @executable_path/../Frameworks/libusb-1.0.0.dylib lib/libusb-1.0.0.dylib
otool -L lib/libusb-1.0.0.dylib
fi
'';
};
ob-tauri-before-bundle = rainix.mkTask.${system} {
name = "ob-tauri-before-bundle";
body = ''
set -euxo pipefail
ls src-tauri/target/release
if [ ${if pkgs.stdenv.isDarwin then "1" else "0" } -eq 1 ]; then
install_name_tool -change ${pkgs.libiconv}/lib/libiconv.2.dylib @executable_path/../Frameworks/libiconv.2.dylib src-tauri/target/release/Raindex
install_name_tool -change ${pkgs.gettext}/lib/libintl.8.dylib @executable_path/../Frameworks/libintl.8.dylib src-tauri/target/release/Raindex
install_name_tool -change ${pkgs.libusb}/lib/libusb-1.0.0.dylib @executable_path/../Frameworks/libusb-1.0.0.dylib src-tauri/target/release/Raindex
otool -L src-tauri/target/release/Raindex
grep_exit_code=0
otool -L src-tauri/target/release/Raindex | grep -q /nix/store || grep_exit_code=$?
if [ $grep_exit_code -eq 0 ]; then
exit 1
fi
fi
'';
};
rainix-wasm-artifacts = rainix.mkTask.${system} {
name = "rainix-wasm-artifacts";
body = ''
set -euxo pipefail
cargo build -r --target wasm32-unknown-unknown --lib --workspace --exclude rain_orderbook_cli --exclude rain-orderbook-env --exclude rain_orderbook_integration_tests
'';
};
rainix-wasm-test = rainix.mkTask.${system} {
name = "rainix-wasm-test";
body = ''
set -euxo pipefail
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER='wasm-bindgen-test-runner' cargo test --target wasm32-unknown-unknown --lib -p rain_orderbook_quote -p rain_orderbook_bindings
'';
};
js-install = rainix.mkTask.${system} {
name = "js-install";
body = ''
set -euxo pipefail
npm install --no-check
'';
};
build-js-bindings = rainix.mkTask.${system} {
name = "build-js-bindings";
body = ''
set -euxo pipefail
npm run build
'';
};
test-js-bindings = rainix.mkTask.${system} {
name = "test-js-bindings";
body = ''
set -euxo pipefail
npm install --no-check
npm run build
npm test
'';
};
} // rainix.packages.${system};
devShells.default = pkgs.mkShell {
packages = [
packages.raindex-prelude
packages.ob-rs-test
packages.rainix-wasm-artifacts
packages.rainix-wasm-test
packages.js-install
packages.build-js-bindings
packages.test-js-bindings
rain.defaultPackage.${system}
];
shellHook = rainix.devShells.${system}.default.shellHook;
buildInputs = rainix.devShells.${system}.default.buildInputs;
nativeBuildInputs = rainix.devShells.${system}.default.nativeBuildInputs;
};
devShells.tauri-shell = pkgs.mkShell {
packages = [
packages.raindex-prelude
packages.ob-tauri-prelude
packages.ob-tauri-unit-test
packages.ob-tauri-before-build-ci
packages.ob-tauri-before-build
packages.ob-tauri-before-bundle
packages.ob-tauri-before-release
packages.tauri-rs-test
];
shellHook = rainix.devShells.${system}.tauri-shell.shellHook;
buildInputs = rainix.devShells.${system}.tauri-shell.buildInputs ++ [pkgs.clang-tools];
nativeBuildInputs = rainix.devShells.${system}.tauri-shell.nativeBuildInputs;
};
}
);
}