-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMakefile.toml
More file actions
578 lines (492 loc) · 19.2 KB
/
Makefile.toml
File metadata and controls
578 lines (492 loc) · 19.2 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
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
[config]
skip_core_tasks = true
default_to_workspace = false
[env]
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS = ["contracts/room-contract", "contracts/web-container-contract", "delegates/chat-delegate", "ui"]
CONTRACT_TARGET = "wasm32-unknown-unknown"
CONTRACT_NAME = "room_contract"
DELEGATE_NAME = "chat_delegate"
BUILD_PROFILE = "release"
# Comma-separated list of features to enable
UI_FEATURES = ""
[tasks.clean]
description = "Clean build artifacts"
command = "cargo"
args = ["clean"]
[tasks.build-tailwind]
description = "Build Tailwind CSS"
command = "npm"
args = ["run", "build:css"]
cwd = "./ui"
[tasks.watch-tailwind]
description = "Watch and rebuild Tailwind CSS"
command = "npm"
args = ["run", "watch:css"]
cwd = "./ui"
[tasks.build-room-contract]
description = "Build the room contract WASM"
command = "cargo"
args = ["build", "--profile", "${BUILD_PROFILE}", "--target", "${CONTRACT_TARGET}", "-p", "room-contract", "--target-dir", "target"]
[tasks.sync-cli-wasm]
description = "Sync room contract WASM to CLI package for crates.io publishing"
dependencies = ["build-room-contract"]
script = '''
#!/bin/bash
set -e
# Source and destination paths
SOURCE_WASM="ui/public/contracts/room_contract.wasm"
DEST_WASM="cli/contracts/room_contract.wasm"
# Check if source exists
if [ ! -f "$SOURCE_WASM" ]; then
echo "Error: Source WASM not found at $SOURCE_WASM"
echo "Please run 'cargo make build-room-contract' first"
exit 1
fi
# Create destination directory if it doesn't exist
mkdir -p cli/contracts
# Copy the WASM file
cp "$SOURCE_WASM" "$DEST_WASM"
echo "✓ Synced room_contract.wasm to CLI package"
# Check if the files differ (useful for CI)
if ! cmp -s "$SOURCE_WASM" "$DEST_WASM"; then
echo "Warning: WASM files were out of sync!"
exit 1
fi
'''
[tasks.publish-cli-dry-run]
description = "Test publishing River CLI to crates.io (dry run)"
dependencies = ["sync-cli-wasm"]
command = "cargo"
args = ["publish", "--dry-run", "--allow-dirty"]
cwd = "./cli"
[tasks.publish-cli]
description = "Publish River CLI to crates.io"
dependencies = ["sync-cli-wasm"]
script = '''
#!/bin/bash
set -e
echo "⚠️ About to publish River CLI to crates.io!"
echo "Have you:"
echo " 1. Updated the version in cli/Cargo.toml?"
echo " 2. Committed all changes?"
echo " 3. Created a git tag?"
echo ""
read -p "Continue? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Aborted."
exit 1
fi
cd cli
cargo publish
'''
[tasks.build-chat-delegate]
description = "Build the chat delegate WASM"
command = "cargo"
args = ["build", "--profile", "${BUILD_PROFILE}", "--target", "${CONTRACT_TARGET}", "-p", "chat-delegate", "--target-dir", "target"]
[tasks.build-web-container]
description = "Build the web container contract WASM"
command = "cargo"
args = ["build", "--profile", "${BUILD_PROFILE}", "--target", "${CONTRACT_TARGET}", "-p", "web-container-contract", "--target-dir", "target"]
[tasks.build-web-container-tool]
description = "Build the web container tool for native platform"
dependencies = ["build-web-container"]
command = "cargo"
args = ["build", "--profile", "${BUILD_PROFILE}", "--package", "web-container-tool", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu"]
[tasks.build-ui]
description = "Build the Dioxus UI"
# build-chat-delegate is required because UI includes delegate WASM via include_bytes!
dependencies = ["build-chat-delegate", "build-tailwind", "uncomment-base-path"]
command = "dx"
args = ["build", "--${BUILD_PROFILE}", "--features", "${UI_FEATURES}"]
cwd = "./ui"
[tasks.uncomment-base-path]
private = true
script = '''
# Match lines starting with optional whitespace, '#', optional whitespace, 'base_path', optional whitespace, '=', and the rest.
# Replace with the leading whitespace and 'base_path = ...', effectively removing the '#' and the space after it.
sed -i 's/^\([[:space:]]*\)#[[:space:]]*\(base_path[[:space:]]*=.*\)/\1\2/' ui/Dioxus.toml
'''
[tasks.comment-base-path]
private = true
script = '''
# Match lines starting with optional whitespace, 'base_path', optional whitespace, '=', and the rest.
# Replace with the leading whitespace, '#', then 'base_path = ...'.
sed -i 's/^\([[:space:]]*\)\(base_path[[:space:]]*=.*\)/\1#\2/' ui/Dioxus.toml
'''
[tasks.touch-ui-files]
private = true
script = '''
# Touch main.rs to force rebuild
touch ui/src/main.rs
'''
[tasks.clean-stale-assets]
private = true
description = "Remove stale hashed assets from dx output to prevent bloated webapp archives"
script = '''
ASSETS_DIR="target/dx/river-ui/${BUILD_PROFILE}/web/public/assets"
if [ -d "$ASSETS_DIR" ]; then
rm -rf "$ASSETS_DIR"
fi
'''
[tasks.build-ui-with-cleanup]
description = "Build the Dioxus UI and clean up afterwards"
dependencies = ["clean-stale-assets", "touch-ui-files", "build-ui", "comment-base-path"]
[tasks.compress-webapp]
description = "Compress the built webapp into tar.xz"
dependencies = ["build-ui-with-cleanup"]
script = '''
mkdir -p target/webapp
cd target/dx/river-ui/${BUILD_PROFILE}/web/public && \
tar -cJf ../../../../../webapp/webapp.tar.xz *
'''
[tasks.sign-webapp]
description = "Sign the compressed webapp"
dependencies = ["compress-webapp", "build-web-container-tool", "build-web-container"]
script = '''
seconds=$(date +%s)
version=$(( seconds / 60 ))
target/native/x86_64-unknown-linux-gnu/${BUILD_PROFILE}/web-container-tool sign \
--input target/webapp/webapp.tar.xz \
--output target/webapp/webapp.metadata \
--parameters target/webapp/webapp.parameters \
--version $version
'''
[tasks.build-ui-example]
description = "Build the Dioxus UI with example data"
env = { UI_FEATURES = "example-data" }
# build-chat-delegate is required because UI includes delegate WASM via include_bytes!
dependencies = ["build-chat-delegate"]
command = "dx"
args = ["build", "--${BUILD_PROFILE}", "--features", "${UI_FEATURES}"]
cwd = "./ui"
[tasks.build-ui-no-sync]
description = "Build the Dioxus UI without Freenet sync"
env = { UI_FEATURES = "no-sync" }
# build-chat-delegate is required because UI includes delegate WASM via include_bytes!
dependencies = ["build-chat-delegate"]
command = "dx"
args = ["build", "--${BUILD_PROFILE}", "--features", "${UI_FEATURES}"]
cwd = "./ui"
[tasks.build-ui-example-no-sync]
description = "Build the Dioxus UI with example data and no Freenet sync"
env = { UI_FEATURES = "example-data,no-sync" }
# build-chat-delegate is required because UI includes delegate WASM via include_bytes!
dependencies = ["build-chat-delegate"]
command = "dx"
args = ["build", "--${BUILD_PROFILE}", "--features", "${UI_FEATURES}"]
cwd = "./ui"
[tasks.test-web-container]
description = "Run tests for web-container-contract"
command = "cargo"
args = ["test", "--package", "web-container-contract", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu", "--lib", "--bins"]
[tasks.test-web-container-integration]
description = "Run integration tests for web-container-contract"
command = "cargo"
args = ["test", "--package", "web-container-contract", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu", "--test", "integration_tests"]
[tasks.test-room-contract]
description = "Run tests for room-contract"
command = "cargo"
args = ["test", "--package", "room-contract", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu"]
[tasks.test-scaffold]
description = "Run tests for scaffold crate"
command = "cargo"
args = ["test", "--package", "freenet-scaffold", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu"]
[tasks.test-common]
description = "Run tests for common crate"
command = "cargo"
args = ["test", "--package", "river-core", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu"]
[tasks.test-chat-delegate]
description = "Run tests for chat-delegate"
command = "cargo"
args = ["test", "--package", "chat-delegate", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu"]
[tasks.test]
description = "Run all tests"
dependencies = ["test-web-container", "test-web-container-integration", "test-room-contract", "test-scaffold", "test-common", "test-chat-delegate"]
[tasks.test-ui-playwright]
description = "Run Playwright UI tests (requires dx serve on port 8082)"
script = '''
cd ui/tests && npx playwright test "$@"
'''
[tasks.test-ui-playwright-setup]
description = "Install Playwright browsers and dependencies"
script = '''
cd ui/tests && npm install && npx playwright install --with-deps chromium firefox webkit
'''
[tasks.update-published-contract]
description = "Build, publish, and update the published contract files"
dependencies = ["sign-webapp"]
script = '''
# Get the contract ID without publishing
contract_id=$(fdev get-contract-id \
--code target/wasm32-unknown-unknown/release/web_container_contract.wasm \
--parameters target/webapp/webapp.parameters)
# Update published files
mkdir -p published-contract
cp target/wasm32-unknown-unknown/release/web_container_contract.wasm published-contract/
cp target/webapp/webapp.parameters published-contract/
echo "$contract_id" > published-contract/contract-id.txt
echo "Published contract updated with ID: $contract_id"
echo "Please commit the changes to git"
'''
[tasks.publish-river]
description = "Publish River to Freenet using the committed contract version"
dependencies = ["sign-webapp"]
script = '''
if [ ! -f "published-contract/contract-id.txt" ]; then
echo "No published contract found"
exit 1
fi
contract_id=$(cat published-contract/contract-id.txt)
echo "Publishing using committed contract: $contract_id"
fdev network publish \
--code published-contract/web_container_contract.wasm \
--parameters published-contract/webapp.parameters \
contract \
--webapp-archive target/webapp/webapp.tar.xz \
--webapp-metadata target/webapp/webapp.metadata
'''
[tasks.publish-river-debug]
description = "Publish River to Freenet in debug mode"
env = { BUILD_PROFILE = "dev" }
dependencies = ["sign-webapp"]
script = '''
if [ ! -f "published-contract/contract-id.txt" ]; then
echo "No published contract found"
exit 1
fi
contract_id=$(cat published-contract/contract-id.txt)
echo "Publishing using committed contract in debug mode: $contract_id"
fdev network publish \
--code published-contract/web_container_contract.wasm \
--parameters published-contract/webapp.parameters \
contract \
--webapp-archive target/webapp/webapp.tar.xz \
--webapp-metadata target/webapp/webapp.metadata
'''
# Test publishing tasks - use separate keypair to avoid affecting production
[tasks.generate-test-keys]
description = "Generate test keypair for publishing (one-time)"
dependencies = ["build-web-container-tool"]
script = '''
mkdir -p test-contract
target/native/x86_64-unknown-linux-gnu/${BUILD_PROFILE}/web-container-tool generate \
--output test-contract/test-keys.toml
echo "Test keys generated in test-contract/test-keys.toml"
echo "Run 'cargo make sign-webapp-test' to sign with test keys"
'''
[tasks.compress-webapp-test]
description = "Retarget and compress webapp for test contract"
dependencies = ["build-ui-with-cleanup", "build-web-container"]
script = '''
PROD_ID="raAqMhMG7KUpXBU2SxgCQ3Vh4PYjttxdSWd9ftV7RLv"
# Compute test contract ID from test parameters
if [ -f "target/webapp/webapp-test.parameters" ]; then
TEST_ID=$(fdev get-contract-id \
--code target/wasm32-unknown-unknown/release/web_container_contract.wasm \
--parameters target/webapp/webapp-test.parameters 2>/dev/null)
elif [ -f "test-contract/contract-id.txt" ]; then
TEST_ID=$(cat test-contract/contract-id.txt)
else
echo "ERROR: Cannot determine test contract ID"
exit 1
fi
echo "Retargeting webapp: $PROD_ID → $TEST_ID"
# Copy build output to temp dir
TEMP_DIR=$(mktemp -d)
cp -r target/dx/river-ui/${BUILD_PROFILE}/web/public/* "$TEMP_DIR/"
# Replace contract ID in all files (HTML, JS, WASM - all same byte length)
find "$TEMP_DIR" -type f \( -name "*.html" -o -name "*.js" -o -name "*.wasm" \) \
-exec sed -i "s|$PROD_ID|$TEST_ID|g" {} +
# Compress
mkdir -p target/webapp
(cd "$TEMP_DIR" && tar -cJf "$OLDPWD/target/webapp/webapp-test.tar.xz" *)
rm -rf "$TEMP_DIR"
echo "Test webapp: target/webapp/webapp-test.tar.xz"
'''
[tasks.sign-webapp-test]
description = "Sign webapp with test keypair"
dependencies = ["compress-webapp-test", "build-web-container-tool", "build-web-container"]
script = '''
if [ ! -f "test-contract/test-keys.toml" ]; then
echo "No test keys found. Run 'cargo make generate-test-keys' first"
exit 1
fi
seconds=$(date +%s)
version=$(( seconds / 60 ))
target/native/x86_64-unknown-linux-gnu/${BUILD_PROFILE}/web-container-tool sign \
--input target/webapp/webapp-test.tar.xz \
--output target/webapp/webapp-test.metadata \
--parameters target/webapp/webapp-test.parameters \
--version $version \
--key-file test-contract/test-keys.toml
'''
[tasks.update-test-contract]
description = "Update test contract files without publishing"
dependencies = ["sign-webapp-test"]
script = '''
contract_id=$(fdev get-contract-id \
--code target/wasm32-unknown-unknown/release/web_container_contract.wasm \
--parameters target/webapp/webapp-test.parameters)
mkdir -p test-contract
cp target/wasm32-unknown-unknown/release/web_container_contract.wasm test-contract/
cp target/webapp/webapp-test.parameters test-contract/webapp.parameters
echo "$contract_id" > test-contract/contract-id.txt
echo "Test contract updated with ID: $contract_id"
'''
[tasks.publish-river-test]
description = "Publish River to test contract (separate from production)"
dependencies = ["sign-webapp-test"]
script = '''
if [ ! -f "test-contract/test-keys.toml" ]; then
echo "No test keys found. Run 'cargo make generate-test-keys' first"
exit 1
fi
contract_id=$(fdev get-contract-id \
--code target/wasm32-unknown-unknown/release/web_container_contract.wasm \
--parameters target/webapp/webapp-test.parameters)
echo "Publishing TEST contract: $contract_id"
fdev network publish \
--code target/wasm32-unknown-unknown/release/web_container_contract.wasm \
--parameters target/webapp/webapp-test.parameters \
contract \
--webapp-archive target/webapp/webapp-test.tar.xz \
--webapp-metadata target/webapp/webapp-test.metadata
echo ""
echo "Test River available at: http://127.0.0.1:7509/v1/contract/web/$contract_id/"
echo "Test contract ID: $contract_id"
'''
[tasks.bump-cli-version]
description = "Auto-increment riverctl patch version in cli/Cargo.toml"
script = '''
#!/bin/bash
set -e
CARGO_TOML="cli/Cargo.toml"
CURRENT=$(grep '^version' "$CARGO_TOML" | head -1 | sed 's/.*"\(.*\)".*/\1/')
MAJOR=$(echo "$CURRENT" | cut -d. -f1)
MINOR=$(echo "$CURRENT" | cut -d. -f2)
PATCH=$(echo "$CURRENT" | cut -d. -f3)
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
sed -i "0,/^version = \"$CURRENT\"/s//version = \"$NEW_VERSION\"/" "$CARGO_TOML"
echo "Bumped riverctl: $CURRENT → $NEW_VERSION"
'''
[tasks.publish-all]
description = "Publish both River UI and riverctl together (keeps WASM in sync)"
dependencies = ["sync-cli-wasm"]
script = '''
#!/bin/bash
set -e
echo "========================================="
echo " River Publish-All"
echo "========================================="
echo ""
# Step 1: Build and publish River UI
echo "▶ Step 1/5: Building River UI..."
cargo make compress-webapp
cargo make sign-webapp
echo ""
echo "▶ Step 2/5: Publishing River UI to Freenet..."
cargo make publish-river
# Step 2: Bump riverctl version
echo ""
echo "▶ Step 3/5: Bumping riverctl version..."
cargo make bump-cli-version
NEW_VERSION=$(grep '^version' cli/Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
# Step 3: Commit the version bump
echo ""
echo "▶ Step 4/5: Committing version bump..."
git add cli/Cargo.toml
git commit -m "chore: bump riverctl to v${NEW_VERSION} (WASM sync)"
# Step 4: Publish to crates.io
echo ""
echo "▶ Step 5/5: Publishing riverctl v${NEW_VERSION} to crates.io..."
cd cli
cargo publish
cd ..
echo ""
echo "========================================="
echo " ✅ Publish complete!"
echo " River UI: published to Freenet"
echo " riverctl: v${NEW_VERSION} on crates.io"
echo "========================================="
echo ""
echo "Don't forget to: git push origin main"
'''
# =============================================================================
# Migration & WASM sync tasks
# =============================================================================
[tasks.check-migration]
description = "Check if delegate WASM changed and migration entry is needed"
script = ["scripts/check-migration.sh"]
[tasks.add-migration]
description = "Add migration entry for currently committed delegate WASM"
script = '''
#!/bin/bash
set -e
# Auto-detect next version number from TOML
LAST_VERSION=$(grep '^version' legacy_delegates.toml | tail -1 | sed 's/.*"V\([0-9]*\)".*/\1/')
NEXT_VERSION="V$((LAST_VERSION + 1))"
echo "Next version: $NEXT_VERSION"
read -p "Description of what changed: " DESCRIPTION
scripts/add-migration.sh "$NEXT_VERSION" "$DESCRIPTION"
'''
[tasks.sync-wasm]
description = "Build all WASMs and copy to committed locations"
script = ["scripts/sync-wasm.sh"]
# ─── Developer Setup ───────────────────────────────────────────────────────────
#
# Run `cargo make setup` after cloning to enable git hooks that prevent
# accidental WASM commits (which break delegate key continuity and cause
# data loss). See .githooks/pre-commit and .claude/rules/wasm-safety.md.
[tasks.setup]
description = "One-time repo setup: configures git hooks for WASM safety"
script = '''
#!/bin/bash
set -e
echo "Configuring git hooks path → .githooks/"
git config core.hooksPath .githooks
echo ""
echo "✓ Git hooks enabled. The pre-commit hook will now block commits that"
echo " stage WASM files (ui/public/contracts/, cli/contracts/) without a"
echo " corresponding migration entry in legacy_delegates.toml."
echo ""
echo " This prevents accidental delegate key changes that break room data."
echo " See .claude/rules/wasm-safety.md for details."
echo ""
echo " To intentionally update WASMs:"
echo " 1. cargo make add-migration"
echo " 2. cargo make sync-wasm"
echo " 3. Stage legacy_delegates.toml alongside the WASMs"
'''
[tasks.clippy]
description = "Run clippy on all packages"
command = "cargo"
args = ["clippy", "--manifest-path", "./Cargo.toml", "--workspace", "--all-targets", "--", "-D", "warnings"]
[tasks.build]
description = "Build everything in release mode (optimized)"
dependencies = ["build-ui-with-cleanup", "build-web-container"]
[tasks.dev-example]
description = "Development build with example data"
env = { UI_FEATURES = "example-data", BUILD_PROFILE = "dev" }
# build-chat-delegate is required because UI includes delegate WASM via include_bytes!
dependencies = ["build-chat-delegate", "build-tailwind"]
command = "dx"
args = ["serve", "--features", "${UI_FEATURES}"]
cwd = "./ui"
[tasks.build-example]
description = "Build everything in release mode with example data"
dependencies = ["build-ui-example"]
[tasks.build-debug]
description = "Build everything in debug mode (faster builds)"
env = { BUILD_PROFILE = "dev" }
dependencies = ["build-ui"]
[tasks.dev]
description = "Development build"
env = { UI_FEATURES = "" }
# build-chat-delegate is required because UI includes delegate WASM via include_bytes!
dependencies = ["build-chat-delegate"]
command = "dx"
args = ["serve"]
cwd = "./ui"