-
Notifications
You must be signed in to change notification settings - Fork 0
1802 lines (1604 loc) · 67.9 KB
/
binsuite.yml
File metadata and controls
1802 lines (1604 loc) · 67.9 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
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
name: SMOL 4. Binsuite
on:
workflow_dispatch:
inputs:
dry_run:
description: 'Dry run (build only, no release)'
type: boolean
default: true
force:
description: 'Force rebuild (ignore cache)'
type: boolean
default: false
build_mode:
description: 'Build mode'
type: choice
options:
- prod
- dev
default: prod
tools:
description: 'Tools to build (comma-separated: binpress,binflate,binject or "all")'
type: string
default: 'all'
debug:
description: 'Debug (0|1|namespace[,...])'
required: false
default: '0'
type: string
workflow_call:
inputs:
dry_run:
type: boolean
default: true
force:
type: boolean
default: false
build_mode:
type: string
default: prod
tools:
type: string
default: 'all'
debug:
type: string
default: '0'
permissions:
contents: read # Read repository contents
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
# Job group 1: binpress
binpress:
permissions:
contents: read # Read repository contents
id-token: write # OIDC authentication for Depot builds
name: binpress / ${{ matrix.platform }}-${{ matrix.arch }}${{ matrix.libc == 'musl' && '-musl' || '' }}
runs-on: ${{ matrix.runner }}
timeout-minutes: 30
if: inputs.tools == 'all' || contains(inputs.tools, 'binpress')
strategy:
fail-fast: false
matrix:
include:
# macOS builds
# Use Depot runner for darwin-arm64: 8 vCPU M2, 24GB RAM
- runner: depot-macos-15
platform: darwin
arch: arm64
os: macos
# Use Intel runner for darwin-x64 (macos-15 is ARM64)
- runner: macos-15-large
platform: darwin
arch: x64
os: macos
# Linux glibc builds
- runner: ubuntu-22.04
platform: linux
arch: x64
os: linux
libc: glibc
- runner: ubuntu-22.04-arm
platform: linux
arch: arm64
os: linux
libc: glibc
# Linux musl builds (Alpine)
- runner: ubuntu-22.04
platform: linux
arch: x64
os: linux
libc: musl
- runner: ubuntu-22.04-arm
platform: linux
arch: arm64
os: linux
libc: musl
# Windows builds
- runner: windows-2022
platform: win32
arch: x64
os: windows
# Windows ARM64: Cross-compile on x64 runner (no ARM64 hosted runners available)
- runner: windows-2022
platform: win32
arch: arm64
os: windows
cross_compile: true
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
submodules: recursive
- name: Setup Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version-file: .node-version
- name: Setup pnpm
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Setup macOS code signing
if: matrix.os == 'macos'
run: |
# Create temporary keychain for code signing.
# Required for ad-hoc signing (codesign --sign -) in CI environment.
security create-keychain -p actions build.keychain
security default-keychain -s build.keychain
security unlock-keychain -p actions build.keychain
security set-keychain-settings -t 3600 -u build.keychain
- name: Setup Depot CLI
if: matrix.os == 'linux'
uses: depot/setup-action@b0b1ea4f69e92ebf5dea3f8713a1b0c37b2126a5 # v1.6.0
with:
oidc: true
- name: Check if tool should be built
id: build-enabled
shell: bash
env:
TOOLS_INPUT: ${{ inputs.tools || 'all' }}
run: |
TOOL="binpress"
if [ "$TOOLS_INPUT" = "all" ]; then
echo "build=true" >> $GITHUB_OUTPUT
echo "√ Building $TOOL (all tools selected)"
elif echo ",$TOOLS_INPUT," | grep -q ",$TOOL,"; then
echo "build=true" >> $GITHUB_OUTPUT
echo "√ Building $TOOL (explicitly selected)"
else
echo "build=false" >> $GITHUB_OUTPUT
echo "⏭ Skipping $TOOL (not selected)"
fi
- name: Setup checkpoint caching
if: steps.build-enabled.outputs.build == 'true'
id: setup-checkpoints
uses: ./.github/actions/setup-checkpoints
with:
package-name: binpress
build-mode: ${{ inputs.build_mode || 'prod' }}
platform: ${{ matrix.platform }}
arch: ${{ matrix.arch }}
libc: ${{ matrix.libc || '' }}
- name: Validate checkpoint binary exists
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'false'
id: validate-checkpoint
shell: bash
working-directory: packages/binpress
env:
BUILD_MODE: ${{ steps.setup-checkpoints.outputs.build-mode }}
OS_TYPE: ${{ matrix.os }}
run: |
BINARY="build/${BUILD_MODE}/out/Final/binpress"
if [ "${OS_TYPE}" = "windows" ]; then
BINARY="${BINARY}.exe"
fi
if [ ! -f "$BINARY" ]; then
echo "⚠️ Checkpoint restored but binary missing at: $BINARY"
echo "force-rebuild=true" >> $GITHUB_OUTPUT
else
echo "✅ Binary exists: $BINARY"
echo "force-rebuild=false" >> $GITHUB_OUTPUT
fi
- name: Install QEMU and Docker (Linux - for cross-compiled binary testing)
if: matrix.os == 'linux' && matrix.runner == 'ubuntu-22.04' && (matrix.arch == 'arm64' || matrix.libc == 'musl')
env:
ARCH: ${{ matrix.arch }}
LIBC: ${{ matrix.libc }}
run: |
sudo apt-get update
# Install QEMU for ARM64 emulation (if ARM64 build)
if [ "${ARCH}" = "arm64" ]; then
echo "Installing QEMU user-mode for ARM64 emulation..."
sudo apt-get install -y qemu-user-static
echo "√ QEMU installed"
fi
# Docker is pre-installed on GitHub Actions runners (for musl testing)
if [ "${LIBC}" = "musl" ]; then
echo "Verifying Docker is available for musl testing..."
docker --version || echo "⚠ Docker not available"
fi
- name: Setup compiler (Linux)
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'true' && matrix.os == 'linux'
run: |
sudo apt-get update
sudo apt-get install -y gcc g++ make
- name: Install dependencies (Linux glibc)
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'true' && matrix.os == 'linux' && matrix.platform == 'linux'
run: |
# Install OpenSSL for Linux builds
sudo apt-get install -y libssl-dev
- name: Install musl toolchain (Linux musl)
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'true' && matrix.os == 'linux' && matrix.libc == 'musl'
env:
ARCH: ${{ matrix.arch }}
run: |
# Install musl cross-compilation toolchain
sudo apt-get install -y musl-tools
# For ARM64, we need the cross-compiler
if [ "${ARCH}" = "arm64" ]; then
sudo apt-get install -y gcc-aarch64-linux-gnu
fi
- name: Setup Windows build tools (x64)
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'true' && matrix.os == 'windows' && !matrix.cross_compile
shell: bash
run: |
# Install MinGW for gcc/g++ (consistent ABI with LIEF library)
# Use retry logic to handle transient GitHub download issues
RETRIES=5
DELAY=10
SUCCESS=false
for i in $(seq 1 $RETRIES); do
echo "Attempt $i/$RETRIES: Installing MinGW..."
if choco install -y mingw --no-progress; then
echo "√ MinGW installed successfully"
SUCCESS=true
break
fi
if [ $i -lt $RETRIES ]; then
echo "⚠ Attempt $i failed, retrying in ${DELAY}s..."
sleep $DELAY
DELAY=$((DELAY * 2)) # Exponential backoff
fi
done
if [ "$SUCCESS" = false ]; then
echo "✗ Failed to install MinGW after $RETRIES attempts"
exit 1
fi
gcc --version
g++ --version
# Ensure make is available
where make || choco install -y make
- name: Setup Windows build tools (ARM64 cross-compile)
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'true' && matrix.os == 'windows' && matrix.cross_compile
shell: bash
run: |
# Download and extract llvm-mingw for ARM64 cross-compilation.
curl -fsSL -o llvm-mingw.zip "https://github.com/mstorsjo/llvm-mingw/releases/download/20250528/llvm-mingw-20250528-ucrt-x86_64.zip"
7z x llvm-mingw.zip -o"C:/llvm-mingw"
echo "C:/llvm-mingw/llvm-mingw-20250528-ucrt-x86_64/bin" >> $GITHUB_PATH
# Ensure make is available
where make || choco install -y make
- name: Select Xcode version (macOS)
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'true' && matrix.os == 'macos'
run: |
# Select appropriate Xcode version for each runner
# depot-macos-15 (ARM64 M2): Use Xcode 16.4 (default on macOS 15)
# macos-15 (Intel x64): Use Xcode 16.4 (default on macOS 15)
# Both macOS 15 runners use Xcode 16.4 by default, but explicitly set for clarity
sudo xcode-select -s /Applications/Xcode_16.4.app
xcodebuild -version
clang --version
- name: Debug build decision
if: steps.build-enabled.outputs.build == 'true'
shell: bash
env:
BUILD_ENABLED: ${{ steps.build-enabled.outputs.build }}
BUILD_REQUIRED: ${{ steps.setup-checkpoints.outputs.build-required }}
CACHE_HIT: ${{ steps.setup-checkpoints.outputs.cache-hit }}
CACHE_VALID: ${{ steps.setup-checkpoints.outputs.cache-valid }}
run: |
echo "🔍 Build decision variables:"
echo " build-enabled: ${BUILD_ENABLED}"
echo " build-required: ${BUILD_REQUIRED}"
echo " cache-hit: ${CACHE_HIT}"
echo " cache-valid: ${CACHE_VALID}"
echo ""
if [ "${BUILD_REQUIRED}" = "true" ]; then
echo "✅ Build will run"
else
echo "⏭️ Build will be skipped (checkpoint restored)"
fi
- name: Load cache version (binpress)
id: cache-version
shell: bash
run: |
echo "version=$(jq -r '.versions["binpress"]' .github/cache-versions.json)" >> $GITHUB_OUTPUT
echo "lief_version=$(jq -r '.versions["lief"]' .github/cache-versions.json)" >> $GITHUB_OUTPUT
echo "stubs_version=$(jq -r '.versions["stubs"]' .github/cache-versions.json)" >> $GITHUB_OUTPUT
- name: Initialize lzfse submodule before Docker build (Linux)
if: |
steps.build-enabled.outputs.build == 'true' &&
steps.setup-checkpoints.outputs.build-required == 'true' &&
matrix.os == 'linux'
shell: bash
run: |
git submodule update --init packages/bin-infra/upstream/lzfse
- name: Initialize libdeflate submodule before Docker build (Linux)
if: |
steps.build-enabled.outputs.build == 'true' &&
steps.setup-checkpoints.outputs.build-required == 'true' &&
matrix.os == 'linux'
shell: bash
run: |
git submodule update --init packages/binject/upstream/libdeflate
- name: Get lzfse submodule SHA (binpress)
if: |
steps.build-enabled.outputs.build == 'true' &&
steps.setup-checkpoints.outputs.build-required == 'true' &&
matrix.os == 'linux'
id: lzfse-sha
shell: bash
run: |
LZFSE_SHA=$(git -C packages/bin-infra/upstream/lzfse rev-parse --short=7 HEAD)
echo "sha=${LZFSE_SHA}" >> $GITHUB_OUTPUT
echo "lzfse submodule SHA: ${LZFSE_SHA}"
- name: Clean LIEF before Docker build (Linux)
if: |
steps.build-enabled.outputs.build == 'true' &&
steps.setup-checkpoints.outputs.build-required == 'true' &&
matrix.os == 'linux'
shell: bash
env:
BUILD_MODE: ${{ steps.setup-checkpoints.outputs.build-mode }}
run: |
rm -rf packages/bin-infra/build/${BUILD_MODE}/out/Final/lief/
- name: Build binpress with Depot (Linux - offloads compute)
if: |
steps.build-enabled.outputs.build == 'true' &&
steps.setup-checkpoints.outputs.build-required == 'true' &&
matrix.os == 'linux'
uses: depot/build-push-action@9785b135c3c76c33db102e45be96a25ab55cd507 # v1.16.2
with:
project: 8fpj9495vw
platforms: linux/${{ matrix.arch == 'x64' && 'amd64' || matrix.arch }}
build-args: |
BUILD_MODE=${{ steps.setup-checkpoints.outputs.build-mode }}
GH_TOKEN=${{ secrets.GITHUB_TOKEN }}
CACHE_VERSION=${{ steps.cache-version.outputs.version }}
LIEF_CACHE_VERSION=${{ steps.cache-version.outputs.lief_version }}
LZFSE_CACHE_VERSION=${{ steps.lzfse-sha.outputs.sha }}
STUBS_CACHE_VERSION=${{ steps.cache-version.outputs.stubs_version }}
file: packages/binpress/Dockerfile.${{ matrix.libc == 'musl' && 'musl' || 'glibc' }}
target: export
outputs: type=local,dest=.docker-export
context: .
- name: Move Docker export to correct locations (binpress)
if: |
steps.build-enabled.outputs.build == 'true' &&
steps.setup-checkpoints.outputs.build-required == 'true' &&
matrix.os == 'linux'
shell: bash
run: |
echo "Moving Docker export to correct locations..."
mv .docker-export/binpress-build packages/binpress/build
mkdir -p packages/build-infra/build
mv .docker-export/build-infra-downloaded packages/build-infra/build/downloaded
rm -rf .docker-export
echo "✅ Docker export moved to correct locations"
- name: Verify Depot build output (binpress)
if: |
steps.build-enabled.outputs.build == 'true' &&
steps.setup-checkpoints.outputs.build-required == 'true' &&
matrix.os == 'linux'
shell: bash
working-directory: packages/binpress
env:
BUILD_MODE: ${{ steps.setup-checkpoints.outputs.build-mode }}
run: |
echo "Verifying Depot build output..."
BINARY="build/${BUILD_MODE}/out/Final/binpress"
if [ ! -f "$BINARY" ]; then
echo "× Binary not found at $BINARY"
echo "Contents of build directory:"
find build/${BUILD_MODE}/ -type f 2>/dev/null || find build/ -type f
exit 1
fi
echo "✅ Depot build output verified"
file "$BINARY"
- name: Validate Depot checkpoints (binpress)
if: |
matrix.os == 'linux' &&
steps.build-enabled.outputs.build == 'true' &&
steps.setup-checkpoints.outputs.build-required == 'true'
uses: ./.github/actions/validate-depot-checkpoints
with:
package-path: packages/binpress
build-mode: ${{ steps.setup-checkpoints.outputs.build-mode }}
package-name: binpress
- name: Build binpress native (macOS/Windows)
if: |
steps.build-enabled.outputs.build == 'true' &&
(steps.setup-checkpoints.outputs.build-required == 'true' || steps.validate-checkpoint.outputs.force-rebuild == 'true') &&
matrix.os != 'linux'
shell: bash
working-directory: packages/binpress
env:
BUILD_MODE: ${{ steps.setup-checkpoints.outputs.build-mode }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PLATFORM: ${{ matrix.platform }}
ARCH: ${{ matrix.arch }}
TARGET_ARCH: ${{ matrix.arch }}
DEBUG: ${{ inputs.debug && '1' || '' }}
run: |
echo "🔨 Building binpress for ${PLATFORM}-${ARCH} (${BUILD_MODE} mode)"
# Use build script with --force to bypass checkpoint check
# (checkpoint restoration is handled by setup-checkpoints action)
pnpm run build -- --force
echo "✅ Build complete"
ls -lh build/${BUILD_MODE}/out/
- name: Verify binary
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'false'
shell: bash
working-directory: packages/binpress
env:
BUILD_MODE: ${{ steps.setup-checkpoints.outputs.build-mode }}
OS_TYPE: ${{ matrix.os }}
run: |
if [ "${OS_TYPE}" = "windows" ]; then
BINARY="build/${BUILD_MODE}/out/Final/binpress.exe"
else
BINARY="build/${BUILD_MODE}/out/Final/binpress"
fi
if [ ! -f "$BINARY" ]; then
echo "× Binary not found: $BINARY"
exit 1
fi
echo "✅ Binary exists: $BINARY"
# Show binary info
if [ "${OS_TYPE}" = "macos" ]; then
file "$BINARY"
otool -L "$BINARY" || true
elif [ "${OS_TYPE}" = "linux" ]; then
file "$BINARY"
ldd "$BINARY" || true
elif [ "${OS_TYPE}" = "windows" ]; then
file "$BINARY" || true
fi
- name: Debug compression test
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'true' && matrix.arch == 'x64' && matrix.libc != 'musl' && runner.os == 'Windows'
shell: bash
working-directory: packages/binpress
env:
BUILD_MODE: ${{ steps.setup-checkpoints.outputs.build-mode }}
run: |
# Run debug compression test to diagnose issues
echo "Running debug compression test..."
bash test/debug-compress.sh || true
- name: Test binary (functional test)
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'true' && matrix.arch == 'x64' && matrix.libc != 'musl'
shell: bash
working-directory: packages/binpress
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Run full functional tests on native x64 platforms
echo "Running functional tests for binpress..."
pnpm run test
- name: Smoke test binary
if: steps.build-enabled.outputs.build == 'true'
shell: bash
working-directory: packages/binpress
env:
BUILD_MODE: ${{ steps.setup-checkpoints.outputs.build-mode }}
OS_TYPE: ${{ matrix.os }}
ARCH: ${{ matrix.arch }}
LIBC: ${{ matrix.libc }}
run: |
# Deterministic smoke test: native execution, Docker, QEMU, or static verification
if [ "${OS_TYPE}" = "windows" ]; then
BINARY="build/${BUILD_MODE}/out/Final/binpress.exe"
else
BINARY="build/${BUILD_MODE}/out/Final/binpress"
fi
# Prepare smoke test options
SMOKE_TEST_ARGS="$BINARY"
if [ "${ARCH}" = "arm64" ]; then
SMOKE_TEST_ARGS="$SMOKE_TEST_ARGS --arch arm64"
fi
if [ "${LIBC}" = "musl" ]; then
SMOKE_TEST_ARGS="$SMOKE_TEST_ARGS --musl"
fi
echo "Running smoke test: node ../../packages/build-infra/scripts/smoke-test-binary.mjs $SMOKE_TEST_ARGS"
node ../../packages/build-infra/scripts/smoke-test-binary.mjs $SMOKE_TEST_ARGS
- name: Set artifact name
shell: bash
env:
PLATFORM: ${{ matrix.platform }}
ARCH: ${{ matrix.arch }}
LIBC: ${{ matrix.libc }}
run: |
# Construct artifact name (musl suffix after arch).
ARTIFACT_NAME="binpress-${PLATFORM}-${ARCH}"
if [ "${LIBC}" = "musl" ]; then
ARTIFACT_NAME="${ARTIFACT_NAME}-musl"
fi
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV
- name: Upload artifacts
if: steps.build-enabled.outputs.build == 'true'
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: ${{ env.ARTIFACT_NAME }}
path: packages/binpress/build/${{ steps.setup-checkpoints.outputs.build-mode }}/out/Final/binpress${{ matrix.os == 'windows' && '.exe' || '' }}
retention-days: 30
if-no-files-found: error
# Job group 2: binflate
binflate:
permissions:
contents: read # Read repository contents
id-token: write # OIDC authentication for Depot builds
name: binflate / ${{ matrix.platform }}-${{ matrix.arch }}${{ matrix.libc == 'musl' && '-musl' || '' }}
runs-on: ${{ matrix.runner }}
timeout-minutes: 30
if: inputs.tools == 'all' || contains(inputs.tools, 'binflate')
strategy:
fail-fast: false
matrix:
include:
# macOS builds
# Use Depot runner for darwin-arm64: 8 vCPU M2, 24GB RAM
- runner: depot-macos-15
platform: darwin
arch: arm64
os: macos
# Use Intel runner for darwin-x64 (macos-15 is ARM64)
- runner: macos-15-large
platform: darwin
arch: x64
os: macos
# Linux glibc builds
- runner: ubuntu-22.04
platform: linux
arch: x64
os: linux
libc: glibc
- runner: ubuntu-22.04-arm
platform: linux
arch: arm64
os: linux
libc: glibc
# Linux musl builds (Alpine)
- runner: ubuntu-22.04
platform: linux
arch: x64
os: linux
libc: musl
- runner: ubuntu-22.04-arm
platform: linux
arch: arm64
os: linux
libc: musl
# Windows builds
- runner: windows-2022
platform: win32
arch: x64
os: windows
# Windows ARM64: Cross-compile on x64 runner (no ARM64 hosted runners available)
- runner: windows-2022
platform: win32
arch: arm64
os: windows
cross_compile: true
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
submodules: recursive
- name: Setup Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version-file: .node-version
- name: Setup pnpm
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Setup macOS code signing
if: matrix.os == 'macos'
run: |
# Create temporary keychain for code signing.
# Required for ad-hoc signing (codesign --sign -) in CI environment.
security create-keychain -p actions build.keychain
security default-keychain -s build.keychain
security unlock-keychain -p actions build.keychain
security set-keychain-settings -t 3600 -u build.keychain
- name: Setup Depot CLI
if: matrix.os == 'linux'
uses: depot/setup-action@b0b1ea4f69e92ebf5dea3f8713a1b0c37b2126a5 # v1.6.0
with:
oidc: true
- name: Install QEMU and Docker (Linux - for cross-compiled binary testing)
if: matrix.os == 'linux' && matrix.runner == 'ubuntu-22.04' && (matrix.arch == 'arm64' || matrix.libc == 'musl')
env:
ARCH: ${{ matrix.arch }}
LIBC: ${{ matrix.libc }}
run: |
sudo apt-get update
# Install QEMU for ARM64 emulation (if ARM64 build)
if [ "${ARCH}" = "arm64" ]; then
echo "Installing QEMU user-mode for ARM64 emulation..."
sudo apt-get install -y qemu-user-static
echo "√ QEMU installed"
fi
# Docker is pre-installed on GitHub Actions runners (for musl testing)
if [ "${LIBC}" = "musl" ]; then
echo "Verifying Docker is available for musl testing..."
docker --version || echo "⚠ Docker not available"
fi
- name: Check if tool should be built
id: build-enabled
shell: bash
env:
TOOLS_INPUT: ${{ inputs.tools || 'all' }}
run: |
TOOL="binflate"
if [ "$TOOLS_INPUT" = "all" ]; then
echo "build=true" >> $GITHUB_OUTPUT
echo "√ Building $TOOL (all tools selected)"
elif echo ",$TOOLS_INPUT," | grep -q ",$TOOL,"; then
echo "build=true" >> $GITHUB_OUTPUT
echo "√ Building $TOOL (explicitly selected)"
else
echo "build=false" >> $GITHUB_OUTPUT
echo "⏭ Skipping $TOOL (not selected)"
fi
- name: Setup checkpoint caching
if: steps.build-enabled.outputs.build == 'true'
id: setup-checkpoints
uses: ./.github/actions/setup-checkpoints
with:
package-name: binflate
build-mode: ${{ inputs.build_mode || 'prod' }}
platform: ${{ matrix.platform }}
arch: ${{ matrix.arch }}
libc: ${{ matrix.libc || '' }}
- name: Validate checkpoint binary exists
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'false'
id: validate-checkpoint
shell: bash
working-directory: packages/binflate
env:
BUILD_MODE: ${{ steps.setup-checkpoints.outputs.build-mode }}
OS_TYPE: ${{ matrix.os }}
run: |
BINARY="build/${BUILD_MODE}/out/Final/binflate"
if [ "${OS_TYPE}" = "windows" ]; then
BINARY="${BINARY}.exe"
fi
if [ ! -f "$BINARY" ]; then
echo "⚠️ Checkpoint restored but binary missing at: $BINARY"
echo "force-rebuild=true" >> $GITHUB_OUTPUT
else
echo "✅ Binary exists: $BINARY"
echo "force-rebuild=false" >> $GITHUB_OUTPUT
fi
- name: Setup compiler (Linux)
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'true' && matrix.os == 'linux'
run: |
sudo apt-get update
sudo apt-get install -y gcc g++ make
- name: Install dependencies (Linux glibc)
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'true' && matrix.os == 'linux' && matrix.platform == 'linux'
run: |
# Install OpenSSL for Linux builds
sudo apt-get install -y libssl-dev
- name: Install musl toolchain (Linux musl)
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'true' && matrix.os == 'linux' && matrix.libc == 'musl'
env:
ARCH: ${{ matrix.arch }}
run: |
# Install musl cross-compilation toolchain
sudo apt-get install -y musl-tools
# For ARM64, we need the cross-compiler
if [ "${ARCH}" = "arm64" ]; then
sudo apt-get install -y gcc-aarch64-linux-gnu
fi
- name: Setup Windows build tools (x64)
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'true' && matrix.os == 'windows' && !matrix.cross_compile
shell: bash
run: |
# Install MinGW for gcc/g++ (consistent ABI with LIEF library)
# Use retry logic to handle transient GitHub download issues
RETRIES=5
DELAY=10
SUCCESS=false
for i in $(seq 1 $RETRIES); do
echo "Attempt $i/$RETRIES: Installing MinGW..."
if choco install -y mingw --no-progress; then
echo "√ MinGW installed successfully"
SUCCESS=true
break
fi
if [ $i -lt $RETRIES ]; then
echo "⚠ Attempt $i failed, retrying in ${DELAY}s..."
sleep $DELAY
DELAY=$((DELAY * 2)) # Exponential backoff
fi
done
if [ "$SUCCESS" = false ]; then
echo "✗ Failed to install MinGW after $RETRIES attempts"
exit 1
fi
gcc --version
g++ --version
# Ensure make is available
where make || choco install -y make
- name: Setup Windows build tools (ARM64 cross-compile)
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'true' && matrix.os == 'windows' && matrix.cross_compile
shell: bash
run: |
# Download and extract llvm-mingw for ARM64 cross-compilation.
curl -fsSL -o llvm-mingw.zip "https://github.com/mstorsjo/llvm-mingw/releases/download/20250528/llvm-mingw-20250528-ucrt-x86_64.zip"
7z x llvm-mingw.zip -o"C:/llvm-mingw"
echo "C:/llvm-mingw/llvm-mingw-20250528-ucrt-x86_64/bin" >> $GITHUB_PATH
# Ensure make is available
where make || choco install -y make
- name: Select Xcode version (macOS)
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'true' && matrix.os == 'macos'
run: |
# Select appropriate Xcode version for each runner
# depot-macos-15 (ARM64 M2): Use Xcode 16.4 (default on macOS 15)
# macos-15 (Intel x64): Use Xcode 16.4 (default on macOS 15)
# Both macOS 15 runners use Xcode 16.4 by default, but explicitly set for clarity
sudo xcode-select -s /Applications/Xcode_16.4.app
xcodebuild -version
clang --version
- name: Debug build decision
if: steps.build-enabled.outputs.build == 'true'
shell: bash
env:
BUILD_ENABLED: ${{ steps.build-enabled.outputs.build }}
BUILD_REQUIRED: ${{ steps.setup-checkpoints.outputs.build-required }}
CACHE_HIT: ${{ steps.setup-checkpoints.outputs.cache-hit }}
CACHE_VALID: ${{ steps.setup-checkpoints.outputs.cache-valid }}
run: |
echo "🔍 Build decision variables:"
echo " build-enabled: ${BUILD_ENABLED}"
echo " build-required: ${BUILD_REQUIRED}"
echo " cache-hit: ${CACHE_HIT}"
echo " cache-valid: ${CACHE_VALID}"
echo ""
if [ "${BUILD_REQUIRED}" = "true" ]; then
echo "✅ Build will run"
else
echo "⏭️ Build will be skipped (checkpoint restored)"
fi
- name: Load cache version (binflate)
id: cache-version
shell: bash
run: |
echo "version=$(jq -r '.versions["binflate"]' .github/cache-versions.json)" >> $GITHUB_OUTPUT
- name: Initialize lzfse submodule before Docker build (Linux)
if: |
steps.build-enabled.outputs.build == 'true' &&
steps.setup-checkpoints.outputs.build-required == 'true' &&
matrix.os == 'linux'
shell: bash
run: |
git submodule update --init packages/bin-infra/upstream/lzfse
- name: Initialize libdeflate submodule before Docker build (Linux)
if: |
steps.build-enabled.outputs.build == 'true' &&
steps.setup-checkpoints.outputs.build-required == 'true' &&
matrix.os == 'linux'
shell: bash
run: |
git submodule update --init packages/binject/upstream/libdeflate
- name: Get lzfse submodule SHA (binflate)
if: |
steps.build-enabled.outputs.build == 'true' &&
steps.setup-checkpoints.outputs.build-required == 'true' &&
matrix.os == 'linux'
id: lzfse-sha
shell: bash
run: |
LZFSE_SHA=$(git -C packages/bin-infra/upstream/lzfse rev-parse --short=7 HEAD)
echo "sha=${LZFSE_SHA}" >> $GITHUB_OUTPUT
echo "lzfse submodule SHA: ${LZFSE_SHA}"
- name: Build binflate with Depot (Linux - offloads compute)
if: |
steps.build-enabled.outputs.build == 'true' &&
steps.setup-checkpoints.outputs.build-required == 'true' &&
matrix.os == 'linux'
uses: depot/build-push-action@9785b135c3c76c33db102e45be96a25ab55cd507 # v1.16.2
with:
project: 8fpj9495vw
platforms: linux/${{ matrix.arch == 'x64' && 'amd64' || matrix.arch }}
build-args: |
BUILD_MODE=${{ steps.setup-checkpoints.outputs.build-mode }}
CACHE_VERSION=${{ steps.cache-version.outputs.version }}
LZFSE_CACHE_VERSION=${{ steps.lzfse-sha.outputs.sha }}
file: packages/binflate/Dockerfile.${{ matrix.libc == 'musl' && 'musl' || 'glibc' }}
target: export
outputs: type=local,dest=packages/binflate/build
context: .
- name: Verify Depot build output (binflate)
if: |
steps.build-enabled.outputs.build == 'true' &&
steps.setup-checkpoints.outputs.build-required == 'true' &&
matrix.os == 'linux'
shell: bash
working-directory: packages/binflate
env:
BUILD_MODE: ${{ steps.setup-checkpoints.outputs.build-mode }}
run: |
echo "Verifying Depot build output..."
BINARY="build/${BUILD_MODE}/out/Final/binflate"
if [ ! -f "$BINARY" ]; then
echo "× Binary not found at $BINARY"
echo "Contents of build directory:"
find build/${BUILD_MODE}/ -type f 2>/dev/null || find build/ -type f
exit 1
fi
echo "✅ Depot build output verified"
file "$BINARY"
- name: Validate Depot checkpoints (binflate)
if: |
matrix.os == 'linux' &&
steps.build-enabled.outputs.build == 'true' &&
steps.setup-checkpoints.outputs.build-required == 'true'
uses: ./.github/actions/validate-depot-checkpoints
with:
package-path: packages/binflate
build-mode: ${{ steps.setup-checkpoints.outputs.build-mode }}
package-name: binflate
- name: Build binflate native (macOS/Windows)
if: |
steps.build-enabled.outputs.build == 'true' &&
(steps.setup-checkpoints.outputs.build-required == 'true' || steps.validate-checkpoint.outputs.force-rebuild == 'true') &&
matrix.os != 'linux'
shell: bash
working-directory: packages/binflate
env:
BUILD_MODE: ${{ steps.setup-checkpoints.outputs.build-mode }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PLATFORM: ${{ matrix.platform }}
ARCH: ${{ matrix.arch }}
TARGET_ARCH: ${{ matrix.arch }}
DEBUG: ${{ inputs.debug && '1' || '' }}
run: |
echo "🔨 Building binflate for ${PLATFORM}-${ARCH} (${BUILD_MODE} mode)"
# Use build script with --force to bypass checkpoint check
# (checkpoint restoration is handled by setup-checkpoints action)
pnpm run build -- --force
echo "✅ Build complete"
ls -lh build/${BUILD_MODE}/out/
- name: Verify binary
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'false'
shell: bash
working-directory: packages/binflate
env:
BUILD_MODE: ${{ steps.setup-checkpoints.outputs.build-mode }}
OS_TYPE: ${{ matrix.os }}
run: |
if [ "${OS_TYPE}" = "windows" ]; then
BINARY="build/${BUILD_MODE}/out/Final/binflate.exe"
else
BINARY="build/${BUILD_MODE}/out/Final/binflate"
fi
if [ ! -f "$BINARY" ]; then
echo "× Binary not found: $BINARY"
exit 1
fi
echo "✅ Binary exists: $BINARY"
# Show binary info
if [ "${OS_TYPE}" = "macos" ]; then
file "$BINARY"
otool -L "$BINARY" || true
elif [ "${OS_TYPE}" = "linux" ]; then
file "$BINARY"
ldd "$BINARY" || true
elif [ "${OS_TYPE}" = "windows" ]; then
file "$BINARY" || true
fi
- name: Test binary (functional test)
if: steps.build-enabled.outputs.build == 'true' && steps.setup-checkpoints.outputs.build-required == 'true' && matrix.arch == 'x64' && matrix.libc != 'musl'
shell: bash
working-directory: packages/binflate
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Run full functional tests on native x64 platforms