json-eval-rs 0.0.95

High-performance JSON Logic evaluator with schema validation and dependency tracking. Built on blazing-fast Rust engine.
Documentation
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
name: Release and Build

permissions:
  contents: write
  discussions: write

on:
  push:
    branches: [main]
    paths-ignore:
      - "docs/**"
      - "./README.md"
      - ".github/workflows/pages.yml"
      - ".github/workflows/publish.yml"
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always
  FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

jobs:
  create-release:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      discussions: write
      id-token: write
    outputs:
      tag: ${{ steps.get_version.outputs.tag }}
      version: ${{ steps.get_version.outputs.version }}

    steps:
      - name: Checkout code
        uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - name: Get version from Cargo.toml
        id: get_version
        run: |
          VERSION=$(grep -m1 '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
          echo "version=$VERSION" >> $GITHUB_OUTPUT
          echo "tag=v$VERSION" >> $GITHUB_OUTPUT
          echo "Version: $VERSION"

      - name: Extract changelog for current version
        id: changelog
        run: |
          VERSION="${{ steps.get_version.outputs.version }}"

          # Extract changelog section for current version
          if [ -f "CHANGELOG.md" ]; then
            # Try to find version section in CHANGELOG
            CHANGELOG_CONTENT=$(awk "/^## \[?$VERSION\]?|^## \[?v?$VERSION\]?/{flag=1; next} /^## /{flag=0} flag" CHANGELOG.md)
            
            # If no specific version found, get the latest section
            if [ -z "$CHANGELOG_CONTENT" ]; then
              CHANGELOG_CONTENT=$(awk '/^## /{if(++count==1){flag=1; next} else {flag=0}} flag' CHANGELOG.md)
            fi
            
            # If still empty, use a default message
            if [ -z "$CHANGELOG_CONTENT" ]; then
              cat > changelog_body.md << EOF
          ## Changes in v$VERSION

          Automatic release from main branch.

          See [CHANGELOG.md](CHANGELOG.md) for full details.
          EOF
            else
              echo "$CHANGELOG_CONTENT" > changelog_body.md
            fi
          else
            cat > changelog_body.md << EOF
          ## Release v$VERSION

          Automatic release from main branch.

          ### Commit
          - $(git log -1 --pretty=format:'%s')
          EOF
          fi

          echo "Changelog extracted successfully"

      - name: Check if tag exists
        id: check_tag
        run: |
          TAG="${{ steps.get_version.outputs.tag }}"
          if git rev-parse "$TAG" >/dev/null 2>&1; then
            echo "exists=true" >> $GITHUB_OUTPUT
            echo "Tag $TAG exists, will be replaced"
          else
            echo "exists=false" >> $GITHUB_OUTPUT
            echo "Tag $TAG does not exist, will be created"
          fi

      - name: Delete existing tag and release
        if: steps.check_tag.outputs.exists == 'true'
        run: |
          TAG="${{ steps.get_version.outputs.tag }}"

          # Delete remote tag
          git push origin :refs/tags/$TAG || true

          # Delete local tag
          git tag -d $TAG || true

          # Delete GitHub release if it exists
          gh release delete $TAG --yes || true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Create new tag
        run: |
          TAG="${{ steps.get_version.outputs.tag }}"
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git tag -a $TAG -m "Release $TAG"
          git push origin $TAG

      - name: Create GitHub Release
        id: create_release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ steps.get_version.outputs.tag }}
          name: ${{ steps.get_version.outputs.tag }}
          body_path: changelog_body.md
          draft: false
          prerelease: false
          generate_release_notes: true
          make_latest: true
          target_commitish: ${{ github.sha }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Wait for release to be created
        run: sleep 5

  check-rn-tests:
    runs-on: ubuntu-latest
    outputs:
      should_run: ${{ steps.check.outputs.should_run }}
    steps:
      - uses: actions/checkout@v6
      - id: check
        name: Check for [RN] flag
        run: |
          SHOULD_RUN=false
          # Check latest changes in CHANGELOG.md for [RN]
          # Extract content between first '## [' and the next '## ['
          if [ -f CHANGELOG.md ]; then
            LATEST_CHANGES=$(awk '/^## \[/ { if (found) exit; found=1; print; next } found { print }' CHANGELOG.md)
            echo "Latest changes analyzed:"
            echo "$LATEST_CHANGES"
            
            if echo "$LATEST_CHANGES" | grep -Fq "[RN]"; then
              echo "Found [RN] in CHANGELOG.md (latest version)"
              SHOULD_RUN=true
            fi
          fi

          # Check commit message for [RN]
          if [[ "${{ github.event.head_commit.message }}" == *"[RN]"* ]]; then
            echo "Found [RN] in commit message"
            SHOULD_RUN=true
          fi
          echo "should_run=$SHOULD_RUN" >> $GITHUB_OUTPUT

  # Build native libraries for all platforms
  build-native:
    strategy:
      fail-fast: false
      matrix:
        include:
          # Linux x86_64
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            artifact_name: libjson_eval_rs.so
            build_features: ffi

          # Linux ARM64
          - os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
            artifact_name: libjson_eval_rs.so
            build_features: ffi

          # Windows x86_64
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            artifact_name: json_eval_rs.dll
            build_features: ffi

          # macOS x86_64
          - os: macos-latest
            target: x86_64-apple-darwin
            artifact_name: libjson_eval_rs.dylib
            build_features: ffi

          # macOS ARM64
          - os: macos-latest
            target: aarch64-apple-darwin
            artifact_name: libjson_eval_rs.dylib
            build_features: ffi

          # iOS ARM64 (device)
          - os: macos-latest
            target: aarch64-apple-ios
            artifact_name: libjson_eval_rs.a
            build_features: ffi

          # iOS ARM64 (simulator - Apple Silicon Mac)
          - os: macos-latest
            target: aarch64-apple-ios-sim
            artifact_name: libjson_eval_rs.a
            build_features: ffi

          # iOS x86_64 (simulator - Intel Mac)
          - os: macos-latest
            target: x86_64-apple-ios
            artifact_name: libjson_eval_rs.a
            build_features: ffi

    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v6

      - name: Setup Rust
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: stable
          target: ${{ matrix.target }}

      - name: Install cross-compilation toolchain (Linux ARM64)
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        run: |
          sudo apt-get update
          sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
          echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV

      - name: Cache cargo build
        uses: actions/cache@v5
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}

      - name: Build native library
        run: cargo build --release --target ${{ matrix.target }} --features ${{ matrix.build_features }}

      - name: Upload native library artifact
        uses: actions/upload-artifact@v7
        with:
          name: native-${{ matrix.target }}
          path: target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
          if-no-files-found: error

  # Build C# NuGet package
  build-csharp:
    needs: build-native
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v6

      - name: Setup .NET
        uses: actions/setup-dotnet@v5
        with:
          dotnet-version: |
            8.0.x
            6.0.x

      - name: Download all native libraries
        uses: actions/download-artifact@v8
        with:
          pattern: native-*
          path: artifacts/
          merge-multiple: false

      - name: Organize native libraries for NuGet
        run: |
          # Create native library directories for C# bindings
          mkdir -p bindings/csharp/runtimes/linux-x64/native
          mkdir -p bindings/csharp/runtimes/linux-arm64/native
          mkdir -p bindings/csharp/runtimes/win-x64/native
          mkdir -p bindings/csharp/runtimes/osx-x64/native
          mkdir -p bindings/csharp/runtimes/osx-arm64/native

          # Copy native libraries to C# native directory
          cp artifacts/native-x86_64-unknown-linux-gnu/*.so bindings/csharp/runtimes/linux-x64/native/ 2>/dev/null || true
          cp artifacts/native-aarch64-unknown-linux-gnu/*.so bindings/csharp/runtimes/linux-arm64/native/ 2>/dev/null || true
          cp artifacts/native-x86_64-pc-windows-msvc/*.dll bindings/csharp/runtimes/win-x64/native/ 2>/dev/null || true
          cp artifacts/native-x86_64-apple-darwin/*.dylib bindings/csharp/runtimes/osx-x64/native/ 2>/dev/null || true
          cp artifacts/native-aarch64-apple-darwin/*.dylib bindings/csharp/runtimes/osx-arm64/native/ 2>/dev/null || true

      - name: Verify native libraries exist
        run: |
          echo "Checking for native libraries in bindings/csharp/runtimes/..."
          echo ""
          echo "Linux x64:"
          ls -lh bindings/csharp/runtimes/linux-x64/native/*.so 2>/dev/null || echo "  Not found"
          echo ""
          echo "Linux ARM64:"
          ls -lh bindings/csharp/runtimes/linux-arm64/native/*.so 2>/dev/null || echo "  Not found"
          echo ""
          echo "Windows x64:"
          ls -lh bindings/csharp/runtimes/win-x64/native/*.dll 2>/dev/null || echo "  Not found"
          echo ""
          echo "macOS x64:"
          ls -lh bindings/csharp/runtimes/osx-x64/native/*.dylib 2>/dev/null || echo "  Not found"
          echo ""
          echo "macOS ARM64:"
          ls -lh bindings/csharp/runtimes/osx-arm64/native/*.dylib 2>/dev/null || echo "  Not found"

      - name: Build NuGet package
        run: |
          cd bindings/csharp
          dotnet pack -c Release

      - name: Verify NuGet package contents
        run: |
          cd bindings/csharp/bin/Release
          NUPKG=$(ls *.nupkg | head -n 1)
          echo "Inspecting NuGet package: $NUPKG"
          unzip -l "$NUPKG" | grep -E '\.(dll|so|dylib)$' || echo "⚠ No native libraries found in package!"

      - name: Upload NuGet package
        uses: actions/upload-artifact@v7
        with:
          name: nuget-package
          path: bindings/csharp/bin/Release/*.nupkg
          if-no-files-found: error

  # Build Web/WASM package
  build-web:
    runs-on: ubuntu-latest

    env:
      RUSTFLAGS: '--cfg=getrandom_backend="wasm_js"'

    steps:
      - uses: actions/checkout@v6

      - name: Setup Rust
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: stable
          target: wasm32-unknown-unknown

      - name: Setup Node.js
        uses: actions/setup-node@v6
        with:
          node-version: "20"

      - name: Install wasm-pack
        run: curl https://wasm-bindgen.github.io/wasm-pack/installer/init.sh -sSf | bash

      - name: Cache cargo build
        uses: actions/cache@v5
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-wasm-${{ hashFiles('**/Cargo.lock') }}

      - name: Build WASM for bundler
        run: wasm-pack build --release --target bundler --out-dir bindings/web/packages/bundler/pkg --features wasm

      - name: Build WASM for Node.js
        run: wasm-pack build --release --target nodejs --out-dir bindings/web/packages/node/pkg --features wasm

      - name: Build WASM for vanilla (web)
        run: wasm-pack build --release --target web --out-dir bindings/web/packages/vanilla/pkg --features wasm

      - name: Build common package
        run: |
          cd bindings/common
          yarn install
          yarn build
          echo "✓ Common package built: dist/index.js exists?"
          ls -lh dist/ || echo "⚠ dist/ missing"

      - name: Install web dependencies
        run: |
          cd bindings/web
          yarn install

      - name: Verify WASM files exist
        run: |
          echo "Bundler WASM files:"
          ls -lh bindings/web/packages/bundler/pkg/ || echo "No bundler pkg directory"
          echo ""
          echo "Node WASM files:"
          ls -lh bindings/web/packages/node/pkg/ || echo "No node pkg directory"
          echo ""
          echo "Vanilla WASM files:"
          ls -lh bindings/web/packages/vanilla/pkg/ || echo "No vanilla pkg directory"

      - name: Remove pkg .gitignore files
        run: |
          # wasm-pack generates .gitignore files that can prevent npm pack from including WASM files
          rm -f bindings/web/packages/bundler/pkg/.gitignore
          rm -f bindings/web/packages/node/pkg/.gitignore
          rm -f bindings/web/packages/vanilla/pkg/.gitignore
          echo "✓ Removed .gitignore files from pkg directories"

      - name: Package core wrapper
        run: |
          cd bindings/web/packages/core
          npm pack

          echo ""
          echo "✅ Core package created:"
          ls -lh *.tgz

          echo ""
          echo "📋 Contents of core package:"
          tar -tzf *.tgz | grep -E '\.(js|ts|json)$'

      - name: Package web binding (bundler)
        run: |
          cd bindings/web/packages/bundler
          npm pack

          echo ""
          echo "✅ Bundler package created:"
          ls -lh *.tgz

          echo ""
          echo "📋 Verifying bundler package contents:"
          tar -tzf *.tgz | head -20

          # Verify key files are included
          tar -tzf *.tgz | grep -E 'package/dist/index\.js$' && echo "✓ index.js included" || echo "❌ index.js missing"
          tar -tzf *.tgz | grep -E 'package/dist/index\.d\.ts$' && echo "✓ index.d.ts included" || echo "❌ index.d.ts missing"
          tar -tzf *.tgz | grep -E '\.wasm$' && echo "✓ WASM files included" || echo "❌ No WASM files"
          tar -tzf *.tgz | grep -E 'package/pkg/.*\.js$' && echo "✓ pkg/*.js files included" || echo "❌ No pkg/*.js files"

      - name: Package web binding (node)
        run: |
          cd bindings/web/packages/node
          npm pack

          echo ""
          echo "✅ Node package created:"
          ls -lh *.tgz

          echo ""
          echo "📋 Verifying node package contents:"
          tar -tzf *.tgz | head -20

          # Verify key files are included
          tar -tzf *.tgz | grep -E 'package/dist/index\.js$' && echo "✓ index.js included" || echo "❌ index.d.ts missing"
          tar -tzf *.tgz | grep -E 'package/dist/index\.d\.ts$' && echo "✓ index.d.ts included" || echo "❌ index.d.ts missing"
          tar -tzf *.tgz | grep -E '\.wasm$' && echo "✓ WASM files included" || echo "❌ No WASM files"
          tar -tzf *.tgz | grep -E 'package/pkg/.*\.js$' && echo "✓ pkg/*.js files included" || echo "❌ No pkg/*.js files"

      - name: Package web binding (vanilla)
        run: |
          cd bindings/web/packages/vanilla
          npm pack

          echo ""
          echo "✅ Vanilla package created:"
          ls -lh *.tgz

          echo ""
          echo "📋 Verifying vanilla package contents:"
          tar -tzf *.tgz | head -20

          # Verify key files are included
          tar -tzf *.tgz | grep -E 'package/dist/index\.js$' && echo "✓ index.js included" || echo "❌ index.js missing"
          tar -tzf *.tgz | grep -E 'package/dist/index\.d\.ts$' && echo "✓ index.d.ts included" || echo "❌ index.d.ts missing"
          tar -tzf *.tgz | grep -E '\.wasm$' && echo "✓ WASM files included" || echo "❌ No WASM files"
          tar -tzf *.tgz | grep -E 'package/pkg/.*\.js$' && echo "✓ pkg/*.js files included" || echo "❌ No pkg/*.js files"

      - name: Package common
        run: |
          cd bindings/common
          npm pack
          echo ""
          echo "✅ Common package created:"
          ls -lh *.tgz

      - name: Upload web packages
        uses: actions/upload-artifact@v7
        with:
          name: web-packages
          path: |
            bindings/web/packages/core/*.tgz
            bindings/web/packages/bundler/*.tgz
            bindings/web/packages/node/*.tgz
            bindings/web/packages/vanilla/*.tgz
            bindings/common/*.tgz
          if-no-files-found: warn

      - name: Upload WASM artifacts
        uses: actions/upload-artifact@v7
        with:
          name: wasm-modules
          path: |
            bindings/web/packages/bundler/pkg/
            bindings/web/packages/node/pkg/

  # Build Android JNI libraries
  build-android-jni:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        target:
          - arm64-v8a
          - armeabi-v7a
          - x86
          - x86_64

    steps:
      - uses: actions/checkout@v6

      - name: Setup Rust
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: stable

      - name: Setup Android NDK
        uses: nttld/setup-ndk@v1
        with:
          ndk-version: r26c
          add-to-path: true
        id: setup-ndk

      - name: Install Android Rust targets
        run: |
          rustup target add \
            aarch64-linux-android \
            armv7-linux-androideabi \
            i686-linux-android \
            x86_64-linux-android

      - name: Add NDK toolchain to PATH
        run: |
          NDK_HOME="${{ steps.setup-ndk.outputs.ndk-path }}"
          echo "$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH
          echo "NDK toolchain added to PATH"

      - name: Cache cargo build
        uses: actions/cache@v5
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-android-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}

      - name: Map Android ABI to Rust target
        id: rust-target
        run: |
          case "${{ matrix.target }}" in
            arm64-v8a)
              echo "target=aarch64-linux-android" >> $GITHUB_OUTPUT
              ;;
            armeabi-v7a)
              echo "target=armv7-linux-androideabi" >> $GITHUB_OUTPUT
              ;;
            x86)
              echo "target=i686-linux-android" >> $GITHUB_OUTPUT
              ;;
            x86_64)
              echo "target=x86_64-linux-android" >> $GITHUB_OUTPUT
              ;;
          esac

      - name: Build Rust shared library
        env:
          ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
        run: |
          cargo build --release --target ${{ steps.rust-target.outputs.target }} --features ffi

      - name: Verify shared library
        run: |
          ls -lh target/${{ steps.rust-target.outputs.target }}/release/libjson_eval_rs.so

      - name: Copy to jniLibs directory
        run: |
          mkdir -p bindings/react-native/packages/react-native/android/src/main/jniLibs/${{ matrix.target }}
          cp target/${{ steps.rust-target.outputs.target }}/release/libjson_eval_rs.so \
             bindings/react-native/packages/react-native/android/src/main/jniLibs/${{ matrix.target }}/
          ls -lh bindings/react-native/packages/react-native/android/src/main/jniLibs/${{ matrix.target }}/

      - name: Upload Android JNI library artifact
        uses: actions/upload-artifact@v7
        with:
          name: android-jni-${{ matrix.target }}
          path: bindings/react-native/packages/react-native/android/src/main/jniLibs/${{ matrix.target }}/
          if-no-files-found: error

  # Build iOS XCFramework (requires macOS)
  build-ios-xcframework:
    needs: [build-native]
    runs-on: macos-latest

    steps:
      - uses: actions/checkout@v6

      - name: Download iOS libraries
        uses: actions/download-artifact@v8
        with:
          pattern: native-*-apple-ios*
          path: ios-artifacts/

      - name: Create XCFramework
        run: |
          # Collect libraries by platform
          DEVICE_LIB=""
          SIM_LIBS=()

          for arch_dir in ios-artifacts/native-*; do
            if [ -d "$arch_dir" ] && [ -f "$arch_dir/libjson_eval_rs.a" ]; then
              arch_name=$(basename "$arch_dir" | sed 's/native-//')
              
              if [[ "$arch_name" == "aarch64-apple-ios" ]]; then
                DEVICE_LIB="$arch_dir/libjson_eval_rs.a"
                echo "✓ Found device library: $arch_name"
              elif [[ "$arch_name" == *"sim"* ]] || [[ "$arch_name" == "x86_64-apple-ios" ]]; then
                SIM_LIBS+=("$arch_dir/libjson_eval_rs.a")
                echo "✓ Found simulator library: $arch_name"
              fi
            fi
          done

          # Create temp directories with identical library names
          mkdir -p /tmp/device /tmp/simulator

          if [ -n "$DEVICE_LIB" ]; then
            cp "$DEVICE_LIB" /tmp/device/libjson_eval_rs.a
            echo "✓ Prepared device library"
          fi

          if [ ${#SIM_LIBS[@]} -gt 0 ]; then
            if [ ${#SIM_LIBS[@]} -eq 1 ]; then
              cp "${SIM_LIBS[0]}" /tmp/simulator/libjson_eval_rs.a
            else
              lipo -create "${SIM_LIBS[@]}" -output /tmp/simulator/libjson_eval_rs.a
            fi
            echo "✓ Created universal simulator library"
          fi

          # Create XCFramework
          if [ -f "/tmp/device/libjson_eval_rs.a" ] && [ -f "/tmp/simulator/libjson_eval_rs.a" ]; then
            xcodebuild -create-xcframework \
              -library /tmp/device/libjson_eval_rs.a \
              -library /tmp/simulator/libjson_eval_rs.a \
              -output JsonEvalRs.xcframework
            
            echo "✓ XCFramework created successfully"
            echo ""
            echo "XCFramework structure:"
            find JsonEvalRs.xcframework -type f
          else
            echo "❌ Missing required libraries"
            exit 1
          fi

      - name: Upload XCFramework
        uses: actions/upload-artifact@v7
        with:
          name: ios-xcframework
          path: JsonEvalRs.xcframework/
          if-no-files-found: error

  # Build React Native package
  build-react-native:
    needs: [build-native, build-android-jni, build-ios-xcframework]
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v6

      - name: Setup Node.js
        uses: actions/setup-node@v6
        with:
          node-version: "20"

      - name: Download Android JNI libraries
        uses: actions/download-artifact@v8
        with:
          pattern: android-jni-*
          path: android-jni-artifacts/

      - name: Organize Android JNI libraries
        run: |
          # Copy Android JNI artifacts to the package structure
          mkdir -p bindings/react-native/packages/react-native/android/src/main/jniLibs

          # Copy each ABI's libraries (contents only, not the directory)
          for abi_dir in android-jni-artifacts/android-jni-*/; do
            if [ -d "$abi_dir" ]; then
              abi=$(basename "$abi_dir" | sed 's/android-jni-//')
              echo "Copying $abi libraries..."
              mkdir -p bindings/react-native/packages/react-native/android/src/main/jniLibs/$abi
              cp "$abi_dir"/*.so bindings/react-native/packages/react-native/android/src/main/jniLibs/$abi/ 2>/dev/null || true
            fi
          done

          # Verify libraries
          echo "Android JNI libraries bundled in package:"
          find bindings/react-native/packages/react-native/android/src/main/jniLibs -name "*.so" -exec ls -lh {} \;

      - name: Download iOS XCFramework
        uses: actions/download-artifact@v8
        with:
          name: ios-xcframework
          path: bindings/react-native/packages/react-native/ios/JsonEvalRs.xcframework/

      - name: Verify XCFramework bundled
        run: |
          echo "iOS XCFramework bundled in package:"
          find bindings/react-native/packages/react-native/ios/JsonEvalRs.xcframework -type f

      - name: Build common package
        run: |
          cd bindings/common
          yarn install
          yarn build
          echo "✓ Common package built"

      - name: Install React Native dependencies
        run: |
          cd bindings/react-native
          yarn install

      - name: Build TypeScript
        run: |
          cd bindings/react-native
          yarn workspace @json-eval-rs/react-native prepare

      - name: Install example dependencies
        run: |
          cd bindings/react-native/examples/rncli
          yarn install || echo "Example dependencies installation skipped"

      - name: Package React Native binding
        run: |
          cd bindings/react-native/packages/react-native
          npm pack

      - name: Upload React Native package
        uses: actions/upload-artifact@v7
        with:
          name: react-native-package
          path: bindings/react-native/packages/react-native/*.tgz
          if-no-files-found: error

  # Run tests
  test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v6

      - name: Setup Rust
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: stable

      - name: Cache cargo build
        uses: actions/cache@v5
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}

      - name: Run tests
        run: cargo test --all-features

  # Test React Native example - Android
  # Integration test to verify the package works on Android
  # Runs in parallel, doesn't block releases
  test-react-native-android:
    needs: [build-android-jni, build-react-native, check-rn-tests]
    if: needs.check-rn-tests.outputs.should_run == 'true'
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v6

      - name: Setup Node.js
        uses: actions/setup-node@v6
        with:
          node-version: "20"

      - name: Setup Java
        uses: actions/setup-java@v5
        with:
          distribution: "zulu"
          java-version: "17"

      - name: Setup Android SDK
        uses: android-actions/setup-android@v3

      - name: Download Android JNI libraries
        uses: actions/download-artifact@v8
        with:
          pattern: android-jni-*
          path: android-artifacts/

      - name: Copy Android JNI libraries to package
        run: |
          mkdir -p bindings/react-native/packages/react-native/android/src/main/jniLibs

          # Map artifact names to Android ABIs
          declare -A abi_map=(
            ["android-jni-arm64-v8a"]="arm64-v8a"
            ["android-jni-armeabi-v7a"]="armeabi-v7a"
            ["android-jni-x86"]="x86"
            ["android-jni-x86_64"]="x86_64"
          )

          for artifact_dir in android-artifacts/android-jni-*; do
            if [ -d "$artifact_dir" ]; then
              artifact_name=$(basename "$artifact_dir")
              abi="${abi_map[$artifact_name]}"
              
              if [ -n "$abi" ]; then
                mkdir -p "bindings/react-native/packages/react-native/android/src/main/jniLibs/$abi"
                cp "$artifact_dir"/*.so "bindings/react-native/packages/react-native/android/src/main/jniLibs/$abi/" 2>/dev/null || true
                echo "✓ Copied $abi libraries"
              fi
            fi
          done

          echo "Android JNI libraries in package:"
          find bindings/react-native/packages/react-native/android/src/main/jniLibs -name "*.so" -exec ls -lh {} \;

      - name: Build common package
        run: |
          cd bindings/common
          yarn install
          yarn build
          echo "✓ Common package built"

      - name: Install monorepo dependencies
        run: |
          cd bindings/react-native
          yarn install

      - name: Build TypeScript (React Native package)
        run: |
          cd bindings/react-native
          yarn workspace @json-eval-rs/react-native prepare

      - name: Install example dependencies
        run: |
          cd bindings/react-native/examples/rncli
          yarn install

      - name: Setup Gradle cache
        uses: actions/cache@v5
        with:
          path: |
            ~/.gradle/caches
            ~/.gradle/wrapper
          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
          restore-keys: |
            ${{ runner.os }}-gradle-

      - name: Verify native files exist
        run: |
          echo "Checking for CMakeLists.txt..."
          ls -la bindings/react-native/packages/react-native/android/CMakeLists.txt
          echo "Checking node_modules link..."
          ls -la bindings/react-native/examples/rncli/node_modules/@json-eval-rs/react-native/android/CMakeLists.txt || echo "Symlink issue detected"

      - name: Build Android library (validation)
        run: |
          cd bindings/react-native/examples/rncli/android
          chmod +x gradlew
          # Only build the React Native library module, not the full app
          # This validates JNI linking without building the entire APK
          ./gradlew :json-eval-rs_react-native:assembleDebug --no-daemon --stacktrace --parallel

          # Verify the library was built
          echo ""
          echo "Checking for built library..."
          find . -name "*.aar" -o -name "*.so" | grep json_eval || echo "⚠ Library artifacts not found"

  # Test React Native example - iOS
  # Integration test to verify the package works on iOS
  # Runs in parallel, doesn't block releases
  test-react-native-ios:
    needs: [build-ios-xcframework, build-react-native, check-rn-tests]
    if: needs.check-rn-tests.outputs.should_run == 'true'
    runs-on: macos-latest

    steps:
      - uses: actions/checkout@v6

      - name: Setup Node.js
        uses: actions/setup-node@v6
        with:
          node-version: "20"

      - name: Download iOS XCFramework
        uses: actions/download-artifact@v8
        with:
          name: ios-xcframework
          path: ios-xcframework-artifacts/

      - name: Copy iOS XCFramework to package
        run: |
          mkdir -p bindings/react-native/packages/react-native/ios/JsonEvalRs.xcframework
          cp -R ios-xcframework-artifacts/* bindings/react-native/packages/react-native/ios/JsonEvalRs.xcframework/

          echo "iOS XCFramework in package:"
          find bindings/react-native/packages/react-native/ios/JsonEvalRs.xcframework -type f

      - name: Build common package
        run: |
          cd bindings/common
          yarn install
          yarn build
          echo "✓ Common package built"

      - name: Install monorepo dependencies
        run: |
          cd bindings/react-native
          yarn install

      - name: Build TypeScript (React Native package)
        run: |
          cd bindings/react-native
          yarn workspace @json-eval-rs/react-native prepare

      - name: Setup CocoaPods cache
        uses: actions/cache@v5
        with:
          path: |
            bindings/react-native/examples/rncli/ios/Pods
            ~/Library/Caches/CocoaPods
            ~/.cocoapods
          key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
          restore-keys: |
            ${{ runner.os }}-pods-

      - name: Install CocoaPods dependencies
        run: |
          cd bindings/react-native/examples/rncli/ios
          pod install

      - name: Build iOS app (validation)
        run: |
          cd bindings/react-native/examples/rncli/ios
          # Build with optimizations for speed
          set -o pipefail && xcodebuild \
            -workspace rncli.xcworkspace \
            -scheme rncli \
            -configuration Debug \
            -sdk iphonesimulator \
            CODE_SIGNING_ALLOWED=NO \
            CODE_SIGNING_REQUIRED=NO \
            ONLY_ACTIVE_ARCH=YES \
            COMPILER_INDEX_STORE_ENABLE=NO \
            -quiet \
            build 2>&1 | tee build.log

          # Verify our library was linked
          echo ""
          echo "Checking if json_eval_rs was linked..."
          grep -i "json_eval_rs\|json-eval-rs" build.log || echo "✓ Build completed"

      - name: Upload iOS build logs
        if: always()
        uses: actions/upload-artifact@v7
        with:
          name: react-native-ios-build-logs
          path: ~/Library/Logs/xcodebuild/

  # Upload artifacts to release
  # Only runs if ALL tests pass (including React Native tests)
  upload-to-release:
    if: |
      always() && 
      !contains(needs.*.result, 'failure') && 
      !contains(needs.*.result, 'cancelled')
    needs:
      [
        create-release,
        build-native,
        build-android-jni,
        build-ios-xcframework,
        build-csharp,
        build-web,
        build-react-native,
        test,
        test-react-native-android,
        test-react-native-ios,
      ]
    runs-on: ubuntu-latest
    permissions:
      contents: write
      discussions: write
      id-token: write

    steps:
      - uses: actions/checkout@v6

      - name: Download all artifacts
        uses: actions/download-artifact@v8
        with:
          path: release-artifacts/

      - name: Create release archives
        run: |
          cd release-artifacts
          ls -R

          # Archive native libraries
          tar -czf native-linux-x64.tar.gz native-x86_64-unknown-linux-gnu/
          tar -czf native-linux-arm64.tar.gz native-aarch64-unknown-linux-gnu/
          tar -czf native-windows-x64.tar.gz native-x86_64-pc-windows-msvc/
          tar -czf native-macos-x64.tar.gz native-x86_64-apple-darwin/
          tar -czf native-macos-arm64.tar.gz native-aarch64-apple-darwin/

          # Archive WASM modules
          tar -czf wasm-modules.tar.gz wasm-modules/

          # Archive iOS XCFramework
          if [ -d "ios-xcframework" ]; then
            tar -czf ios-xcframework.tar.gz ios-xcframework/
          fi

          # Move web packages to root level for upload
          if [ -d "web-packages" ]; then
            find web-packages -name "*.tgz" -type f -exec mv {} . \;
          fi

          # Move NuGet package to root level for upload
          if [ -d "nuget-package" ]; then
            mv nuget-package/*.nupkg . 2>/dev/null || echo "No NuGet package to move"
          fi

          # Move React Native package to root level for upload
          if [ -d "react-native-package" ]; then
            mv react-native-package/*.tgz . 2>/dev/null || echo "No React Native package to move"
          fi

      - name: Verify release assets before upload
        run: |
          cd release-artifacts
          echo "📦 Release assets to be uploaded:"
          echo ""
          echo "All files in release-artifacts root:"
          ls -lh *.tar.gz *.tgz *.nupkg 2>/dev/null || echo "  ⚠️ No release files found!"
          echo ""
          echo "File count breakdown:"
          echo "  .tar.gz files: $(ls -1 *.tar.gz 2>/dev/null | wc -l)"
          echo "  .tgz files: $(ls -1 *.tgz 2>/dev/null | wc -l)"
          echo "  .nupkg files: $(ls -1 *.nupkg 2>/dev/null | wc -l)"

      - name: Upload artifacts to release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ needs.create-release.outputs.tag }}
          target_commitish: ${{ github.sha }}
          files: |
            release-artifacts/*.tar.gz
            release-artifacts/*.tgz
            release-artifacts/*.nupkg
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  # Summary job
  summary:
    if: always()
    needs:
      [
        build-native,
        build-android-jni,
        build-ios-xcframework,
        build-csharp,
        build-web,
        build-react-native,
        test,
        test-react-native-android,
        test-react-native-ios,
      ]
    runs-on: ubuntu-latest

    steps:
      - name: Build Summary
        run: |
          echo "## Build Summary" >> $GITHUB_STEP_SUMMARY
          echo "" >> $GITHUB_STEP_SUMMARY
          echo "### Native Libraries" >> $GITHUB_STEP_SUMMARY
          echo "✅ Desktop platforms (Linux x64/ARM64, Windows, macOS x64/ARM64)" >> $GITHUB_STEP_SUMMARY
          echo "✅ iOS (device & simulator)" >> $GITHUB_STEP_SUMMARY
          echo "✅ Android (arm64-v8a, armeabi-v7a, x86, x86_64)" >> $GITHUB_STEP_SUMMARY
          echo "" >> $GITHUB_STEP_SUMMARY
          echo "### Bindings Packages" >> $GITHUB_STEP_SUMMARY
          echo "✅ C# NuGet package created" >> $GITHUB_STEP_SUMMARY
          echo "✅ Web/WASM package created" >> $GITHUB_STEP_SUMMARY
          echo "✅ React Native package created" >> $GITHUB_STEP_SUMMARY
          echo "✅ iOS XCFramework created" >> $GITHUB_STEP_SUMMARY
          echo "" >> $GITHUB_STEP_SUMMARY
          echo "### Tests" >> $GITHUB_STEP_SUMMARY
          echo "✅ All Rust tests passed" >> $GITHUB_STEP_SUMMARY
          echo "✅ React Native Android example built" >> $GITHUB_STEP_SUMMARY
          echo "✅ React Native iOS example built" >> $GITHUB_STEP_SUMMARY
          echo "" >> $GITHUB_STEP_SUMMARY
          echo "All artifacts are available for download from this workflow run." >> $GITHUB_STEP_SUMMARY