proofmode 0.8.4

Capture, share, and preserve verifiable photos and videos
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
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
[config]
default_to_workspace = false

[env]
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true

# ============================================================================
# CORE BUILD TASKS
# ============================================================================

[tasks.clean]
description = "Clean all build artifacts"
dependencies = ["clean-rust", "clean-mobile", "clean-wasm", "python-clean", "clean-ruby", "npm-clean"]

[tasks.clean-rust]
description = "Clean Rust build artifacts"
command = "cargo"
args = ["clean"]

[tasks.build]
description = "Build Rust CLI and library"
dependencies = ["build-rust"]

[tasks.build-rust]
description = "Build Rust CLI"
command = "cargo"
args = ["build", "--release"]

[tasks.build-debug]
description = "Build Rust CLI in debug mode"
command = "cargo"
args = ["build"]

[tasks.test]
description = "Run all tests"
dependencies = ["test-rust", "test-integration", "test-cli"]

[tasks.test-rust]
description = "Run Rust unit tests"
command = "cargo"
args = ["test"]

[tasks.test-integration]
description = "Run integration tests"
script = '''
echo "Running integration tests..."
cargo test --test integration_tests
'''

[tasks.test-cli]
description = "Test all CLI implementations"
dependencies = ["test-rust-cli", "test-python-cli", "test-ruby-cli", "test-node-cli"]

[tasks.test-rust-cli]
description = "Test Rust CLI"
script = '''
echo "Testing Rust CLI..."
./target/release/proofmode --version
./target/release/proofmode check --help
./target/release/proofmode generate --help
'''
dependencies = ["build-rust"]

[tasks.test-python-cli]
description = "Test Python CLI"
script = '''
echo "Testing Python CLI..."
cd examples/python
if [ -f proofmode-cli ]; then
    ./proofmode-cli version
else
    echo "Python CLI not built. Run 'cargo make setup-python' first."
fi
'''

[tasks.test-ruby-cli]
description = "Test Ruby CLI"
script = '''
echo "Testing Ruby CLI..."
cd examples/ruby
if [ -f proofmode-cli ]; then
    ruby --version
    echo "Ruby CLI wrapper exists. Full test requires ffi gem."
else
    echo "Ruby CLI not built. Run 'cargo make setup-ruby' first."
fi
'''

[tasks.test-node-cli]
description = "Test Node.js CLI"
dependencies = ["wasm-pack-node"]
script = '''
echo "Testing Node.js CLI..."
cd cli/node
node --version
if [ -f cli.js ]; then
    echo "Testing CLI help..."
    node cli.js --help
    echo "Node.js CLI test completed"
else
    echo "Node.js CLI not found."
fi
'''

[tasks.wasm-pack]
description = "Build the WASM version and NPM package"
command = "wasm-pack"
args = [
  "build",
  "--target",
  "web",
  "--scope",
  "guardianproject",
  "--",
  "--no-default-features",
  "--features",
  "wasm"
]

[tasks.wasm-pack-web]
description = "Build WASM for web browsers"
command = "wasm-pack"
args = [
  "build",
  "--target",
  "web",
  "--scope",
  "guardianproject",
  "--out-dir",
  "pkg-web",
  "--",
  "--no-default-features",
  "--features",
  "wasm"
]

[tasks.wasm-pack-node]
description = "Build WASM for Node.js"
command = "wasm-pack"
args = [
  "build",
  "--target",
  "nodejs",
  "--scope",
  "guardianproject",
  "--out-dir",
  "pkg-node",
  "--",
  "--no-default-features",
  "--features",
  "wasm"
]

[tasks.wasm-pack-all]
description = "Build WASM for all targets"
dependencies = ["wasm-pack-web", "wasm-pack-node"]

[tasks.wasm-publish]
description = "Publish WASM package to npm"
dependencies = ["wasm-pack"]
command = "wasm-pack"
args = ["publish"]

[tasks.build-uniffi]
description = "Build Rust library with UniFFI support (no clap)"
command = "cargo"
args = ["build", "--release", "--no-default-features", "--features", "uniffi,sequoia-openpgp,polars,c2pa"]

[tasks.generate-bindings]
description = "Generate UniFFI bindings for all platforms"
dependencies = ["generate-ios-bindings", "generate-android-bindings", "generate-python-bindings", "generate-ruby-bindings"]

[tasks.generate-ios-bindings]
description = "Generate iOS bindings"
dependencies = ["build-uniffi"]
script = '''
echo "Generating iOS bindings..."
mkdir -p bindings/ios bindings/generated

# Build uniffi-bindgen if needed
if [ ! -f target/debug/uniffi-bindgen ] && [ ! -f target/release/uniffi-bindgen ]; then
    echo "Building uniffi-bindgen..."
    cargo build --bin uniffi-bindgen --features uniffi
fi

UNIFFI_BIN="./target/debug/uniffi-bindgen"
if [ ! -f "$UNIFFI_BIN" ]; then
    UNIFFI_BIN="./target/release/uniffi-bindgen"
fi

# Generate Swift bindings
$UNIFFI_BIN generate \
    --library target/release/libproofmode.so \
    --language swift \
    --out-dir bindings/generated \
    --no-format

echo "iOS bindings generated in bindings/generated/"
'''

[tasks.generate-android-bindings]
description = "Generate Android bindings"
dependencies = ["build-uniffi"]
script = '''
echo "Generating Android bindings..."
mkdir -p bindings/android bindings/generated

# Build uniffi-bindgen if needed
if [ ! -f target/debug/uniffi-bindgen ] && [ ! -f target/release/uniffi-bindgen ]; then
    echo "Building uniffi-bindgen..."
    cargo build --bin uniffi-bindgen --features uniffi
fi

UNIFFI_BIN="./target/debug/uniffi-bindgen"
if [ ! -f "$UNIFFI_BIN" ]; then
    UNIFFI_BIN="./target/release/uniffi-bindgen"
fi

# Generate Kotlin bindings
$UNIFFI_BIN generate \
    --library target/release/libproofmode.so \
    --language kotlin \
    --out-dir bindings/generated \
    --no-format

echo "Android bindings generated in bindings/generated/"
'''

[tasks.install-android-targets]
description = "Install Android targets"
script = '''
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
'''

[tasks.install-ios-targets]
description = "Install iOS targets"
script = '''
rustup target add aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim
'''

[tasks.build-android]
description = "Build for Android (all architectures) using cross"
dependencies = ["install-android-targets"]
script = '''
echo "Building Android libraries using cross..."

# Build for all Android architectures using cross with uniffi feature only
echo "Building for Android ARM64..."
cross build --release --target aarch64-linux-android --no-default-features --features uniffi,polars,c2pa

echo "Building for Android ARMv7..."
cross build --release --target armv7-linux-androideabi --no-default-features --features uniffi,polars,c2pa

echo "Building for Android x86..."
cross build --release --target i686-linux-android --no-default-features --features uniffi,polars,c2pa

echo "Building for Android x86_64..."
cross build --release --target x86_64-linux-android --no-default-features --features uniffi,polars,c2pa

# Create JNI directory structure
mkdir -p target/android/jniLibs/arm64-v8a
mkdir -p target/android/jniLibs/armeabi-v7a
mkdir -p target/android/jniLibs/x86
mkdir -p target/android/jniLibs/x86_64

# Copy libraries to JNI structure
cp target/aarch64-linux-android/release/libproofmode.so target/android/jniLibs/arm64-v8a/
cp target/armv7-linux-androideabi/release/libproofmode.so target/android/jniLibs/armeabi-v7a/
cp target/i686-linux-android/release/libproofmode.so target/android/jniLibs/x86/
cp target/x86_64-linux-android/release/libproofmode.so target/android/jniLibs/x86_64/

echo "Android libraries built successfully in target/android/"
'''

[tasks.build-ios]
description = "Build for iOS (all targets)"
dependencies = ["install-ios-targets"]
script = '''
echo "Building iOS libraries..."

# Build for iOS simulator (x86_64)
echo "Building for iOS simulator (x86_64)..."
cargo build --release --target x86_64-apple-ios --no-default-features --features uniffi,polars,c2pa

# Build for iOS simulator (ARM64)
echo "Building for iOS simulator (ARM64)..."
cargo build --release --target aarch64-apple-ios-sim --no-default-features --features uniffi,polars,c2pa

# Build for iOS device (ARM64)
echo "Building for iOS device (ARM64)..."
cargo build --release --target aarch64-apple-ios --no-default-features --features uniffi,polars,c2pa

# Create universal library
echo "Creating universal library..."
mkdir -p target/universal/ios

# Use lipo to create universal binary for simulator
lipo -create \
    target/x86_64-apple-ios/release/libproofmode.a \
    target/aarch64-apple-ios-sim/release/libproofmode.a \
    -output target/universal/ios/libproofmode_sim.a

# Copy device library
cp target/aarch64-apple-ios/release/libproofmode.a target/universal/ios/libproofmode_device.a

echo "iOS libraries built successfully in target/universal/ios/"
'''

[tasks.create-xcframework]
description = "Create XCFramework for iOS"
dependencies = ["build-ios", "generate-ios-bindings"]
script = '''
echo "Creating XCFramework..."

# Create directory structure
mkdir -p ./target/xcframework/headers

# Copy headers from bindings
cp ./bindings/generated/*.h ./target/xcframework/headers/
cp ./bindings/generated/*.modulemap ./target/xcframework/headers/

# Create fat binary for simulator (already created in build-ios)
# Use the universal libraries
cp ./target/universal/ios/libproofmode_sim.a ./target/libproofmode_sim.a

# Create xcframework
xcodebuild -create-xcframework \
    -library ./target/universal/ios/libproofmode_device.a \
    -headers ./target/xcframework/headers \
    -library ./target/libproofmode_sim.a \
    -headers ./target/xcframework/headers \
    -output ./target/xcframework/ProofMode.xcframework

echo "XCFramework created at ./target/xcframework/ProofMode.xcframework"
'''

[tasks.create-aar]
description = "Create AAR for Android"
dependencies = ["build-android", "generate-android-bindings"]
script = '''
echo "Creating AAR structure..."

# Create AAR structure
mkdir -p ./target/aar/src/main/jniLibs/armeabi-v7a
mkdir -p ./target/aar/src/main/jniLibs/arm64-v8a
mkdir -p ./target/aar/src/main/jniLibs/x86
mkdir -p ./target/aar/src/main/jniLibs/x86_64
mkdir -p ./target/aar/src/main/java

# Copy native libraries from JNI structure
cp ./target/android/jniLibs/armeabi-v7a/libproofmode.so ./target/aar/src/main/jniLibs/armeabi-v7a/
cp ./target/android/jniLibs/arm64-v8a/libproofmode.so ./target/aar/src/main/jniLibs/arm64-v8a/
cp ./target/android/jniLibs/x86/libproofmode.so ./target/aar/src/main/jniLibs/x86/
cp ./target/android/jniLibs/x86_64/libproofmode.so ./target/aar/src/main/jniLibs/x86_64/

# Copy Kotlin sources from bindings
cp -r ./bindings/generated/* ./target/aar/src/main/java/

# Create AndroidManifest.xml
cat > ./target/aar/src/main/AndroidManifest.xml << 'EOF'
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.witness.proofmode">
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="34" />
</manifest>
EOF

# Create build.gradle
cat > ./target/aar/build.gradle << 'EOF'
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
    compileSdkVersion 34
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 34
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.0"
    implementation "net.java.dev.jna:jna:5.14.0"
}
EOF

echo "AAR structure created at ./target/aar"
echo "To build the AAR, use Android Studio or Gradle with the generated build.gradle"
'''

[tasks.create-swift-package]
description = "Create Swift Package"
dependencies = ["create-xcframework"]
script = '''
echo "Creating Swift Package..."

# Create Swift Package structure
mkdir -p ./target/ProofMode/Sources/ProofMode
mkdir -p ./target/ProofMode/Sources/ProofModeFFI

# Copy Swift source files from bindings
cp ./bindings/generated/*.swift ./target/ProofMode/Sources/ProofMode/

# Copy headers to FFI module
cp ./bindings/generated/*.h ./target/ProofMode/Sources/ProofModeFFI/
cp ./bindings/generated/*.modulemap ./target/ProofMode/Sources/ProofModeFFI/

# Copy XCFramework
cp -r ./target/xcframework/ProofMode.xcframework ./target/ProofMode/

# Create Package.swift
cat > ./target/ProofMode/Package.swift << 'EOF'
// swift-tools-version:5.5
import PackageDescription

let package = Package(
    name: "ProofMode",
    platforms: [
        .iOS(.v13),
        .macOS(.v11)
    ],
    products: [
        .library(
            name: "ProofMode",
            targets: ["ProofMode", "ProofModeFFI"]
        ),
    ],
    targets: [
        .target(
            name: "ProofMode",
            dependencies: ["ProofModeFFI"],
            path: "Sources/ProofMode"
        ),
        .binaryTarget(
            name: "ProofModeFFI",
            path: "ProofMode.xcframework"
        )
    ]
)
EOF

echo "Swift Package created at ./target/ProofMode"
'''

[tasks.mobile]
description = "Build all mobile targets"
dependencies = ["generate-bindings", "create-aar", "create-swift-package"]

[tasks.clean-mobile]
description = "Clean mobile build artifacts"
script = '''
echo "Cleaning mobile build artifacts..."
rm -rf ./target/android
rm -rf ./target/uniffi
rm -rf ./target/universal
rm -rf ./target/xcframework
rm -rf ./target/aar
rm -rf ./target/ProofMode
rm -rf ./bindings
rm -f ./target/libproofmode_sim.a
echo "Mobile artifacts cleaned"
'''

[tasks.docs]
description = "Generate documentation"
command = "cargo"
args = ["doc", "--open"]

[tasks.generate-makefile]
description = "Generate Makefile from Makefile.toml"
command = "cargo"
args = ["run", "--bin", "generate_makefile"]

[tasks.python-dev]
description = "Build Python package for development"
script = '''
echo "Building Python package for development..."
pip install -e . --force-reinstall
echo "Python package installed in development mode"
'''

[tasks.python-build]
description = "Build Python wheels using maturin"
script = '''
echo "Building Python wheels..."
pip install maturin
maturin build --release
echo "Python wheels built in target/wheels/"
'''

[tasks.python-build-dev]
description = "Build Python package in debug mode"
script = '''
echo "Building Python package in debug mode..."
pip install maturin
maturin develop
echo "Python package built and installed"
'''

[tasks.python-test]
description = "Run Python tests"
dependencies = ["python-build-dev"]
script = '''
echo "Running Python tests..."
pip install pytest pytest-asyncio
pytest python/tests -v
'''

[tasks.python-lint]
description = "Lint Python code"
script = '''
echo "Linting Python code..."
pip install black ruff mypy
black python/
ruff check python/
mypy python/proofmode/
'''

[tasks.python-publish]
description = "Publish Python package to PyPI"
dependencies = ["python-build"]
script = '''
echo "Publishing Python package to PyPI..."
pip install twine
twine upload target/wheels/*
'''

[tasks.python-clean]
description = "Clean Python build artifacts"
script = '''
echo "Cleaning Python build artifacts..."
rm -rf target/wheels
rm -rf python/proofmode/__pycache__
rm -rf python/proofmode.egg-info
rm -rf build/
rm -rf dist/
find . -name "*.pyc" -delete
find . -name "__pycache__" -type d -delete
echo "Python artifacts cleaned"
'''

[tasks.npm-install]
description = "Install NPM CLI dependencies"
cwd = "cli/node"
command = "npm"
args = ["install"]

[tasks.npm-install-web]
description = "Install web example dependencies"
cwd = "examples/web"
command = "pnpm"
args = ["install"]

[tasks.npm-test]
description = "Run NPM CLI tests"
dependencies = ["wasm-pack-node", "npm-install"]
cwd = "cli/node"
command = "npm"
args = ["test"]

[tasks.npm-pack]
description = "Create NPM tarball for testing"
dependencies = ["wasm-pack", "npm-install"]
cwd = "examples/node"
command = "npm"
args = ["pack"]

[tasks.npm-publish]
description = "Publish NPM CLI package"
dependencies = ["wasm-pack", "npm-test"]
cwd = "examples/node"
script = '''
echo "Ready to publish NPM CLI package!"
echo ""
echo "Steps to publish:"
echo "1. cd npm"
echo "2. npm login (if not already logged in)"
echo "3. npm publish --access public"
echo ""
echo "To test locally first:"
echo "1. npm pack"
echo "2. npm install -g guardianproject-proofmode-cli-*.tgz"
echo "3. proofmode --help"
'''

[tasks.npm-link]
description = "Link NPM CLI package for local development"
dependencies = ["wasm-pack", "npm-install"]
cwd = "examples/node"
command = "npm"
args = ["link"]

[tasks.npm-clean]
description = "Clean NPM artifacts"
script = '''
echo "Cleaning NPM artifacts..."
rm -rf cli/node/node_modules
rm -f cli/node/package-lock.json
rm -f cli/node/*.tgz
rm -rf examples/web/node_modules
rm -f examples/web/pnpm-lock.yaml
rm -rf examples/web/.next
echo "NPM artifacts cleaned"
'''

[tasks.clean-ruby]
description = "Clean Ruby artifacts"
script = '''
echo "Cleaning Ruby artifacts..."
rm -rf examples/ruby/.bundle
rm -rf examples/ruby/vendor
rm -f examples/ruby/Gemfile.lock
rm -f examples/ruby/*.gem
echo "Ruby artifacts cleaned"
'''

[tasks.clean-wasm]
description = "Clean WASM build artifacts"
script = '''
echo "Cleaning WASM artifacts..."
rm -rf pkg/
rm -rf pkg-web/
rm -rf pkg-node/
rm -rf target/wasm32-unknown-unknown/
echo "WASM artifacts cleaned"
'''

[tasks.docker-build]
description = "Build Docker image for current architecture"
command = "docker"
args = ["build", "-t", "proofmode-rust:local", "."]

[tasks.docker-buildx]
description = "Build multi-architecture Docker image"
script = '''
echo "Building multi-architecture Docker image..."
docker buildx create --use --name proofmode-builder || true
docker buildx build --platform linux/amd64,linux/arm64 -t proofmode:multiarch --load .
docker buildx rm proofmode-builder
echo "Multi-architecture image built"
'''

[tasks.docker-test]
description = "Test Docker image"
dependencies = ["docker-build"]
script = '''
echo "Testing Docker image..."
docker run --rm proofmode-rust:local --version
docker run --rm proofmode-rust:local --help
docker run --rm -e RUST_LOG=debug proofmode-rust:local check --help
echo "Docker image tests passed"
'''

[tasks.docker-run]
description = "Run Docker container interactively"
dependencies = ["docker-build"]
command = "docker"
args = ["run", "-it", "--rm", "--user", "$(id -u):$(id -g)", "-v", "${PWD}/media:/app/input", "-v", "${PWD}/proofs:/app/output", "proofmode-rust:local"]

[tasks.docker-examples]
description = "Run Docker examples"
dependencies = ["docker-build"]
script = '''
echo "Running Docker examples..."
cd examples/docker
./run-example.sh all
echo "Docker examples completed"
'''

[tasks.docker-compose-up]
description = "Start services with docker-compose"
command = "docker-compose"
args = ["up", "-d"]

[tasks.docker-compose-down]
description = "Stop services with docker-compose"
command = "docker-compose"
args = ["down"]

[tasks.docker-compose-logs]
description = "View docker-compose logs"
command = "docker-compose"
args = ["logs", "-f"]

[tasks.docker-push]
description = "Push Docker image to registry"
script = '''
echo "To push Docker images:"
echo "1. docker tag proofmode:local guardianproject/proofmode:latest"
echo "2. docker push guardianproject/proofmode:latest"
echo ""
echo "For automated builds, use GitHub Actions workflow"
'''

[tasks.docker-clean]
description = "Clean Docker build cache"
script = '''
echo "Cleaning Docker build cache..."
docker system prune -f
docker builder prune -f
echo "Docker cache cleaned"
'''
# ============================================================================
# SETUP AND DEVELOPMENT ENVIRONMENT
# ============================================================================

[tasks.setup]
description = "Complete development environment setup"
dependencies = ["install-tools", "install-targets", "setup-python", "setup-ruby", "setup-node"]

[tasks.install-tools]
description = "Install required development tools"
script = '''
echo "Installing development tools..."

# Check for wasm-pack
if ! command -v wasm-pack &> /dev/null; then
    echo "Installing wasm-pack..."
    curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
fi

# Check for cross (for Android builds)
if ! command -v cross &> /dev/null; then
    echo "Installing cross..."
    cargo install cross --git https://github.com/cross-rs/cross
fi

# Build uniffi-bindgen
echo "Building uniffi-bindgen..."
cargo build --bin uniffi-bindgen --features uniffi

echo "All tools installed!"
'''

[tasks.install-targets]
description = "Install all compilation targets"
dependencies = ["install-android-targets", "install-ios-targets", "install-wasm-target"]

[tasks.install-wasm-target]
description = "Install WASM target"
command = "rustup"
args = ["target", "add", "wasm32-unknown-unknown"]

[tasks.setup-python]
description = "Setup Python CLI environment"
script = '''
cd examples/python
if [ -f setup_python_cli.sh ]; then
    bash setup_python_cli.sh
else
    echo "Creating Python virtual environment..."
    python3 -m venv venv
    source venv/bin/activate
    pip install click rich
fi
'''

[tasks.setup-ruby]
description = "Setup Ruby CLI environment"
script = '''
cd examples/ruby
if [ -f setup.sh ]; then
    bash setup.sh
else
    echo "Ruby setup requires bundler and ffi gem"
fi
'''

[tasks.setup-node]
description = "Setup Node.js CLI environment"
dependencies = ["wasm-pack-node"]
script = '''
cd cli/node
npm install
echo "Node.js CLI environment setup completed"
'''

# ============================================================================
# COMPREHENSIVE BUILD TASKS
# ============================================================================

[tasks.build-all]
description = "Build everything"
dependencies = ["build-rust", "wasm-pack-all", "build-mobile", "generate-bindings"]

[tasks.build-mobile]
description = "Build all mobile targets"
dependencies = ["build-android", "build-ios-sim"]

[tasks.build-ios-sim]
description = "Build iOS for simulator (Linux-compatible check)"
script = '''
if [[ "$OSTYPE" == "darwin"* ]]; then
    cargo make build-ios
else
    echo "iOS builds require macOS. Skipping on Linux."
fi
'''

# ============================================================================
# CLI SPECIFIC TASKS
# ============================================================================

[tasks.cli-python]
description = "Run Python CLI"
script = '''
cd examples/python
if [ -f proofmode-cli ]; then
    ./proofmode-cli "$@"
else
    echo "Python CLI not setup. Run: cargo make setup-python"
fi
'''

[tasks.cli-ruby]
description = "Run Ruby CLI"
script = '''
cd examples/ruby
if [ -f proofmode-cli ]; then
    ./proofmode-cli "$@"
else
    echo "Ruby CLI not setup. Run: cargo make setup-ruby"
fi
'''

[tasks.cli-node]
description = "Run Node.js CLI"
script = '''
cd examples/node
node cli.js "$@"
'''

[tasks.cli-rust]
description = "Run Rust CLI"
command = "cargo"
args = ["run", "--release", "--"]

# ============================================================================
# WEB APPLICATION TASKS
# ============================================================================

[tasks.web-dev]
description = "Start web development server"
dependencies = ["wasm-pack-web", "npm-install-web"]
cwd = "examples/web"
command = "pnpm"
args = ["dev"]

[tasks.web-build]
description = "Build web application for production"
dependencies = ["wasm-pack-web", "npm-install-web"]
cwd = "examples/web"
command = "pnpm"
args = ["build"]

[tasks.web-test]
description = "Build and serve web application locally"
dependencies = ["web-build"]
script = '''
echo "Web application built successfully"
echo "To serve locally: cd examples/web && pnpm start"
'''

# ============================================================================
# TESTING TASKS
# ============================================================================

[tasks.test-all]
description = "Run all tests including CLI tests"
dependencies = ["test", "test-cli", "test-examples"]

[tasks.test-examples]
description = "Test all example CLIs"
script = '''
echo "Testing example CLIs..."

# Test Python
echo "Testing Python CLI..."
cd examples/python
if [ -f proofmode-cli ]; then
    ./proofmode-cli version
fi
cd ../..

# Test Ruby
echo "Testing Ruby CLI..."
cd examples/ruby
if [ -f proofmode-cli ]; then
    echo "Ruby CLI exists (requires ffi gem for full test)"
fi
cd ../..

# Test Node
echo "Testing Node.js CLI..."
cd examples/node
if [ -f cli.js ]; then
    echo "Node.js CLI exists (requires WASM module)"
fi
cd ../..

echo "Example tests complete!"
'''

# ============================================================================
# RELEASE AND DISTRIBUTION
# ============================================================================

[tasks.dist]
description = "Create distribution packages for all platforms"
dependencies = ["dist-rust", "dist-python", "dist-ruby", "dist-npm", "dist-mobile"]

[tasks.dist-rust]
description = "Create Rust binary distribution"
script = '''
cargo build --release
mkdir -p dist/rust
cp target/release/proofmode dist/rust/
cp README.md LICENSE dist/rust/
echo "Rust distribution created in dist/rust/"
'''

[tasks.dist-python]
description = "Create Python wheel distribution"
dependencies = ["generate-python-bindings"]
script = '''
cd examples/python
if [ -f ../../target/release/libproofmode.so ]; then
    cp ../../target/release/libproofmode.so python/proofmode/
fi
python3 -m build
mkdir -p ../../dist/python
cp dist/*.whl ../../dist/python/
echo "Python distribution created in dist/python/"
'''

[tasks.dist-ruby]
description = "Create Ruby gem distribution"
dependencies = ["generate-ruby-bindings"]
script = '''
cd examples/ruby
if [ -f ../../target/release/libproofmode.so ]; then
    cp ../../target/release/libproofmode.so lib/
fi
gem build proofmode.gemspec
mkdir -p ../../dist/ruby
cp *.gem ../../dist/ruby/
echo "Ruby distribution created in dist/ruby/"
'''

[tasks.dist-npm]
description = "Create NPM package distribution"
dependencies = ["wasm-pack-all"]
script = '''
mkdir -p dist/npm-web dist/npm-node
cp -r pkg-web/* dist/npm-web/
cp -r pkg-node/* dist/npm-node/
echo "NPM distributions created in dist/npm-web/ and dist/npm-node/"
'''

[tasks.dist-mobile]
description = "Create mobile distributions"
dependencies = ["create-aar", "create-xcframework"]
script = '''
mkdir -p dist/android dist/ios
if [ -d target/aar ]; then
    cp -r target/aar/* dist/android/
fi
if [ -d target/xcframework ]; then
    cp -r target/xcframework/* dist/ios/
fi
echo "Mobile distributions created in dist/android/ and dist/ios/"
'''

# ============================================================================
# BINDINGS GENERATION
# ============================================================================

[tasks.generate-python-bindings]
description = "Generate Python UniFFI bindings"
dependencies = ["build-uniffi"]
script = '''
echo "Generating Python bindings..."
mkdir -p bindings/generated

# Build uniffi-bindgen if needed
if [ ! -f target/debug/uniffi-bindgen ] && [ ! -f target/release/uniffi-bindgen ]; then
    echo "Building uniffi-bindgen..."
    cargo build --bin uniffi-bindgen --features uniffi
fi

UNIFFI_BIN="./target/debug/uniffi-bindgen"
if [ ! -f "$UNIFFI_BIN" ]; then
    UNIFFI_BIN="./target/release/uniffi-bindgen"
fi

$UNIFFI_BIN generate \
    --library target/release/libproofmode.so \
    --language python \
    --out-dir bindings/generated

echo "Python bindings generated in bindings/generated/"
'''

[tasks.generate-ruby-bindings]
description = "Generate Ruby UniFFI bindings"
dependencies = ["build-uniffi"]
script = '''
echo "Generating Ruby bindings..."
mkdir -p bindings/generated

# Build uniffi-bindgen if needed
if [ ! -f target/debug/uniffi-bindgen ] && [ ! -f target/release/uniffi-bindgen ]; then
    echo "Building uniffi-bindgen..."
    cargo build --bin uniffi-bindgen --features uniffi
fi

UNIFFI_BIN="./target/debug/uniffi-bindgen"
if [ ! -f "$UNIFFI_BIN" ]; then
    UNIFFI_BIN="./target/release/uniffi-bindgen"
fi

$UNIFFI_BIN generate \
    --library target/release/libproofmode.so \
    --language ruby \
    --out-dir bindings/generated

echo "Ruby bindings generated in bindings/generated/"
'''

[tasks.ruby-build]
description = "Build Ruby gem with native library"
dependencies = ["build-uniffi", "generate-ruby-bindings"]
script = '''
echo "Building Ruby gem..."

# Copy native library and generated bindings into ruby/lib/
cp target/release/libproofmode.so ruby/lib/
cp bindings/generated/proofmode.rb ruby/lib/

# Build the gem
cd ruby
gem build proofmode.gemspec

echo "Ruby gem built in ruby/"
'''

# ============================================================================
# DOCUMENTATION
# ============================================================================

[tasks.docs-all]
description = "Generate all documentation"
dependencies = ["docs", "docs-examples"]

[tasks.docs-examples]
description = "Generate documentation for examples"
script = '''
echo "Generating example documentation..."
for example in examples/*; do
    if [ -d "$example" ]; then
        echo "Documentation for $example"
        if [ -f "$example/README.md" ]; then
            echo "  README.md exists"
        fi
    fi
done
'''

# ============================================================================
# QUALITY AND MAINTENANCE
# ============================================================================

[tasks.lint]
description = "Run all linters"
dependencies = ["fmt-check", "clippy", "python-lint"]

[tasks.fmt]
description = "Format Rust code"
command = "cargo"
args = ["fmt"]

[tasks.fmt-all]
description = "Format all code"
dependencies = ["fmt", "fmt-python"]

[tasks.fmt-check]
description = "Check Rust formatting"
command = "cargo"
args = ["fmt", "--", "--check"]

[tasks.clippy]
description = "Run Rust linter"
command = "cargo"
args = ["clippy", "--", "-D", "warnings"]

[tasks.fmt-python]
description = "Format Python code"
script = '''
if command -v black &> /dev/null; then
    black examples/python/
else
    echo "black not installed. Skipping Python formatting."
fi
'''

[tasks.update]
description = "Update all dependencies"
script = '''
echo "Updating Rust dependencies..."
cargo update

echo "Updating Node.js CLI dependencies..."
cd cli/node && npm update

echo "Updating web example dependencies..."
cd ../../examples/web && pnpm update

echo "Dependencies updated!"
'''

# ============================================================================
# UTILITIES AND HELPERS
# ============================================================================

[tasks.serve-docs]
description = "Serve documentation locally"
dependencies = ["docs"]
script = '''
echo "Serving documentation at http://localhost:8000"
python3 -m http.server 8000 --directory target/doc
'''

[tasks.size]
description = "Show binary sizes"
script = '''
echo "Binary sizes:"
ls -lh target/release/proofmode 2>/dev/null || echo "Rust binary not built"
ls -lh target/release/*.so 2>/dev/null || echo "Shared libraries not built"
ls -lh pkg/*.wasm 2>/dev/null || echo "WASM not built"
'''

[tasks.todo]
description = "Show TODO items in code"
script = '''
echo "TODO items in code:"
grep -r "TODO" src/ --exclude-dir=target || echo "No TODOs found"
'''

[tasks.verify-setup]
description = "Verify development setup"
script = '''
echo "Verifying development setup..."
echo ""
echo "Rust: $(rustc --version)"
echo "Cargo: $(cargo --version)"
echo "Python: $(python3 --version 2>/dev/null || echo 'not found')"
echo "Ruby: $(ruby --version 2>/dev/null || echo 'not found')"
echo "Node.js: $(node --version 2>/dev/null || echo 'not found')"
echo "pnpm: $(pnpm --version 2>/dev/null || echo 'not found')"
echo "wasm-pack: $(wasm-pack --version 2>/dev/null || echo 'not found')"
echo "cross: $(cross --version 2>/dev/null || echo 'not found')"
echo "Docker: $(docker --version 2>/dev/null || echo 'not found')"
echo ""
echo "Checking targets..."
rustup target list --installed

echo ""
echo "Checking WASM packages..."
ls -la pkg-web/ 2>/dev/null || echo "Web WASM package not built"
ls -la pkg-node/ 2>/dev/null || echo "Node WASM package not built"
'''

# ============================================================================
# DEVELOPMENT WORKFLOWS
# ============================================================================

[tasks.dev-web]
description = "Full web development setup"
dependencies = ["wasm-pack-web", "web-dev"]

[tasks.dev-cli]
description = "CLI development setup"
dependencies = ["build-rust", "wasm-pack-node", "setup-node"]

[tasks.dev-mobile]
description = "Mobile development setup"
dependencies = ["install-targets", "build-mobile", "generate-bindings"]

[tasks.quick-test]
description = "Quick test suite for development"
dependencies = ["test-rust", "test-cli"]

# ============================================================================
# COMMON WORKFLOWS
# ============================================================================

[tasks.dev]
description = "Start development (build and watch)"
dependencies = ["build-debug"]
script = '''
echo "Development build complete. Use 'cargo make watch' for auto-rebuild."
'''

[tasks.ci]
description = "Run full CI pipeline"
dependencies = ["fmt-check", "clippy", "test", "build", "wasm-pack-all", "docker-test"]

[tasks.publish-all]
description = "Publish to all package registries"
script = '''
echo "Publishing packages..."
echo "1. Rust: cargo publish"
echo "2. Python: cargo make python-publish"
echo "3. Ruby: cd examples/ruby && gem push *.gem"
echo "4. NPM: cargo make wasm-publish"
echo ""
echo "Run each command when ready to publish."
'''

# ============================================================================
# VERSION MANAGEMENT
# ============================================================================

[tasks.set-version]
description = "Set version across all packages. Usage: cargo make set-version 0.9.0"
script = '''
VERSION="${@}"
if [ -z "$VERSION" ]; then
    echo "Usage: cargo make set-version <version>"
    echo "Example: cargo make set-version 0.9.0"
    exit 1
fi

echo "Setting version to ${VERSION}..."

# Cargo.toml (line 3: version = "...")
sed -i "0,/^version = \".*\"/s//version = \"${VERSION}\"/" Cargo.toml

# pyproject.toml files
sed -i "s/^version = \".*\"/version = \"${VERSION}\"/" pyproject.toml
sed -i "s/^version = \".*\"/version = \"${VERSION}\"/" cli/python/pyproject.toml
sed -i "s/^version = \".*\"/version = \"${VERSION}\"/" scripts/pyproject.toml

# Ruby gemspec
sed -i "s/s\.version     = \".*\"/s.version     = \"${VERSION}\"/" ruby/proofmode.gemspec

# Node package.json files
for f in cli/node/package.json; do
    sed -i "s/\"version\": \".*\"/\"version\": \"${VERSION}\"/" "$f"
done

# GitLab CI
sed -i "s/PACKAGE_VERSION: \".*\"/PACKAGE_VERSION: \"${VERSION}\"/" .gitlab-ci.yml

# Update Cargo.lock
cargo generate-lockfile 2>/dev/null

echo "Version updated to ${VERSION} in all packages."
echo ""
echo "Files updated:"
echo "  - Cargo.toml"
echo "  - Cargo.lock"
echo "  - pyproject.toml"
echo "  - cli/python/pyproject.toml"
echo "  - scripts/pyproject.toml"
echo "  - ruby/proofmode.gemspec"
echo "  - cli/node/package.json"
echo "  - .gitlab-ci.yml"
'''

# Aliases for convenience
[tasks.b]
alias = "build"

[tasks.t]
alias = "test"

[tasks.r]
alias = "run"

[tasks.c]
alias = "check"