Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
1917 lines (1791 loc) · 111 KB
/
Copy pathMakefile
File metadata and controls
1917 lines (1791 loc) · 111 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
# PS5 Upload - Root Makefile
#
# Tree layout (current):
# payload/ — PS5 C payload (FreeBSD 11)
# engine/ — Rust workspace: ava1, ps5upload-core, -ava1, -engine HTTP service,
# -lab CLI, -tests, -pkg
# client/ — Tauri 2 desktop app, cross-platform (Linux/macOS/Windows, x64+arm64)
# tests/ — root integration smoke + tests/lab/ (real-hardware shell scripts)
# bench/ — hardware sweep, golden workloads and profiles
# scripts/ — install + dev helpers (one per OS, plus shared mjs utilities)
JOBS ?= $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || nproc 2>/dev/null || echo 4)
# `npm ci` — NOT `npm install`. The lockfile carries `libc` fields that select
# musl vs glibc native binaries for the Alpine-based web UI image
# (engine/Dockerfile.webui, node:26-alpine). npm 11 writes them; npm 10 does
# not know the field and DELETES it on every `npm install`. Since this target
# runs on every build, an older npm silently stripped that metadata and it had
# to be hand-reverted before each release. `npm ci` installs strictly FROM the
# lockfile and never rewrites it, which is also what CI does.
NPM_INSTALL ?= npm ci --no-audit --no-fund
CARGO ?= cargo
# AVA1 is the third_party/ava1 submodule (github.com/phantomptr/ava1). A clone made without
# --recurse-submodules, or a pull across the change that made it one, leaves it empty: fill it
# rather than fail later with missing-file errors.
ifeq ($(wildcard third_party/ava1/Cargo.toml),)
$(info third_party/ava1 is empty: git submodule update --init third_party/ava1)
$(shell git submodule update --init third_party/ava1 >&2)
endif
PS5_HOST ?= 192.168.137.2
PS5_LOADER_PORT ?= 9021
# Default PS5 payload SDK location — override on the command line if installed
# elsewhere. `setup-payload` validates this path exists before any C build.
PS5_PAYLOAD_SDK ?= /opt/ps5-payload-sdk
export PS5_PAYLOAD_SDK
PS5_SDK_TAG := $(shell sed -n 's/^PS5_SDK_TAG=//p' scripts/ps5-sdk.env 2>/dev/null)
# On macOS the payload SDK's `prospero-clang` wrapper resolves `ld.lld`
# and `clang` through `prospero-llvm-config`. SDK v0.45 supports LLVM 16–23.
# Homebrew exposes the current major as `llvm` (not `llvm@23`), so discover
# its real prefix and retain versioned fallbacks for older installations.
# Linux/WSL picks up `llvm-config-<N>` from apt naturally.
ifeq ($(shell uname -s),Darwin)
MACOS_LLVM_CONFIG := $(shell \
if command -v brew >/dev/null 2>&1; then \
for formula in llvm llvm@23 llvm@22 llvm@18; do \
prefix="$$(brew --prefix "$$formula" 2>/dev/null || true)"; \
if [ -n "$$prefix" ] && [ -x "$$prefix/bin/llvm-config" ]; then \
printf '%s\n' "$$prefix/bin/llvm-config"; \
break; \
fi; \
done; \
fi)
LLVM_CONFIG ?= $(MACOS_LLVM_CONFIG)
export LLVM_CONFIG
endif
PAYLOAD_DIR := payload
PAYLOAD_ELF := $(PAYLOAD_DIR)/ps5upload.elf
# The PS5Upload installer daemon (our own; :9115, FW 11+ pkg installs).
# Built from the same SDK; the engine auto-sends it to the loader port
# (:9021) as a companion image when :9115 isn't already listening.
INSTALLER_DIR := $(PAYLOAD_DIR)/installer
INSTALLER_ELF := $(INSTALLER_DIR)/ps5upload-installer.elf
ENGINE_DIR := engine
CLIENT_DIR := client
# Android (Tauri mobile). The engine is linked in-process (no sidecar);
# only the PS5 payload is bundled. Needs the Android SDK (ANDROID_HOME),
# a JDK 17, an NDK, and the aarch64-linux-android Rust target via rustup
# (Homebrew `rust` ships only the host std and can't cross-compile).
# JDK/NDK are auto-detected where possible — override any on the CLI.
ANDROID_TARGET ?= aarch64
ANDROID_RUST_TARGET ?= aarch64-linux-android
# macOS resolves a JDK 17 via java_home; elsewhere fall back to $JAVA_HOME.
ANDROID_JAVA_HOME ?= $(shell /usr/libexec/java_home -v 17 2>/dev/null || echo "$$JAVA_HOME")
# Newest NDK installed under the SDK.
ANDROID_NDK_HOME ?= $(shell ls -d "$(ANDROID_HOME)"/ndk/* 2>/dev/null | sort -V | tail -1)
ANDROID_GEN_DIR := $(CLIENT_DIR)/src-tauri/gen/android
ANDROID_APK := $(ANDROID_GEN_DIR)/app/build/outputs/apk/universal/debug/app-universal-debug.apk
# Package id (matches tauri.conf.json `identifier`). Used to recover from a
# signature-mismatched prior install during the convenience deploy step.
ANDROID_APP_ID := com.phantomptr.ps5upload
# rustup's *real* toolchain bin (not the ~/.cargo/bin shim). The Android std
# lives only here; Homebrew `rust` ships only the host std. We pin PATH to this
# dir for the android recipes so cross-compilation works even when Homebrew's
# cargo precedes rustup on PATH (otherwise `cargo --target aarch64-linux-android`
# picks Homebrew's cargo and fails with "can't find crate for `core`/`std`").
RUSTUP_CARGO_BIN := $(shell dirname "$$(rustup which cargo 2>/dev/null)" 2>/dev/null)
# Env preamble shared by the android recipes.
# Debug APKs keep line tables only. With full debug info the app library was
# 558 MB, stored uncompressed, so the APK passed 1.1 GB and `adb install`
# failed on an emulator with INSTALL_FAILED_INSUFFICIENT_STORAGE. Line tables
# keep function names and file:line in backtraces. Set here, not in
# Cargo.toml, so the desktop `tauri dev` build keeps its full debug info.
ANDROID_ENV = JAVA_HOME="$(ANDROID_JAVA_HOME)" ANDROID_HOME="$(ANDROID_HOME)" NDK_HOME="$(ANDROID_NDK_HOME)" CARGO_PROFILE_DEV_DEBUG=line-tables-only $(if $(RUSTUP_CARGO_BIN),PATH="$(RUSTUP_CARGO_BIN):$$PATH")
# adb from the SDK (falls back to PATH if a device-only adb is installed).
ADB ?= $(ANDROID_HOME)/platform-tools/adb
.PHONY: all help
.PHONY: install install-ubuntu install-macos install-windows update-sdk
.PHONY: setup setup-engine setup-payload setup-client
.PHONY: build payload installer engine client _engine-release _payload-if-ready _android-build-if-ready
.PHONY: test test-root test-engine test-engine-coverage test-desktop test-payload test-client test-client-coverage
.PHONY: lint lint-scripts lint-client audit-scripts coverage coverage-engine coverage-client
.PHONY: quality quality-full quality-hardware ci ci-full release-check fast-release
.PHONY: clean clean-payload clean-engine clean-client
.PHONY: verify info install-hooks
.PHONY: test-ava1 test-ava1-sanitize ava1-app-gen ava1-version-check check-no-ftx2
.PHONY: fuzz-smoke
.PHONY: run-engine run-client dev start _check-tauri-system-deps
.PHONY: install-engine uninstall-engine
.PHONY: dist dist-win dist-win-arm dist-mac dist-mac-x64 dist-linux dist-linux-arm
.PHONY: ios-init ios-build run-ios android-deps android-init android-build android-deploy _android-install-if-device run-android run-android-background
.PHONY: emu-create emu-start emu-stop emu-status emu-test
.PHONY: send-payload gen-fixtures sweep validate validate-xl
.PHONY: sync-version sync-version-check check-helper-version
.PHONY: docker-engine docker-engine-run
# Default target
all: build
#──────────────────────────────────────────────────────────────────────────────
# Help
#──────────────────────────────────────────────────────────────────────────────
help:
@echo "PS5 Upload - Build System"
@echo ""
@echo "First-time setup (fresh machine):"
@echo " make install - Auto-detect host OS and install all dev deps"
@echo " make install-ubuntu - Ubuntu/Debian/WSL2: apt + rustup + node + PS5 SDK $(PS5_SDK_TAG)"
@echo " make install-macos - macOS: brew + rustup + LLVM + PS5 SDK $(PS5_SDK_TAG)"
@echo " make install-windows - Windows 11: winget + rustup + VS Build Tools + PS5 SDK $(PS5_SDK_TAG)"
@echo " make update-sdk - Move the PS5 SDK pin to the latest release and install it"
@echo " (SDK_TAG=vX.Y for a specific one; SDK_CHECK=1 to only check)"
@echo ""
@echo "Quick start (after install):"
@echo " 1. make setup - Check toolchains, install client deps"
@echo " 2. make build - Build payload ELF + Rust engine + client UI"
@echo " 3. make send-payload - Upload payload ELF to PS5 (PS5_HOST=$(PS5_HOST))"
@echo " 4. make run-client - Start the Tauri desktop app (spawns engine automatically)"
@echo ""
@echo "Validation:"
@echo " make validate - Rebuild + send + smoke + full sweep + timestamped report"
@echo " make validate-xl - Same as validate plus the 200k-file stress profile"
@echo " make sweep - Run sweep against an already-loaded payload"
@echo ""
@echo "Build parts:"
@echo " make payload - Build the PS5 payload in $(PAYLOAD_DIR)/"
@echo " make engine - Build the Rust engine workspace"
@echo " make client - Build the Tauri/React UI"
@echo ""
@echo "Testing:"
@echo " make lint - script syntax + frontend ESLint"
@echo " make lint-scripts - Node/Bash/Python/PowerShell syntax checks"
@echo " make audit-scripts - Inventory script/test utilities"
@echo " make security - Scan dependencies and git history (cargo/npm audit, gitleaks)"
@echo " make quality - Full non-hardware validation gate"
@echo " make quality-full - quality + payload validation"
@echo " make quality-hardware - quality + live PS5 validate"
@echo " make release-check - Before a release: quality, then Playwright e2e, then"
@echo " make fast-release V=X.Y.Z - A small change out now as a pre-release: bare checks, no CI wait"
@echo " test-payload (BUILD_LOCK=<file> serializes the heavy builds)"
@echo " make coverage - Rust + frontend coverage reports"
@echo " make coverage-engine - Rust coverage report only"
@echo " make coverage-client - Frontend coverage report only"
@echo " make test-engine - cargo test --workspace (C interop serial)"
@echo " make test-desktop - Tauri Rust cargo check/clippy/test"
@echo " make test-ava1 - AVA1 Rust + C conformance and interop tests"
@echo " make fuzz-smoke - Fuzz every file reader for 20 s each (needs cargo-fuzz + nightly; skips without)"
@echo " make test-payload - Validate $(PAYLOAD_ELF)"
@echo " make test-client - Type-check + lint + unit tests + build client UI"
@echo ""
@echo "Version:"
@echo " make sync-version - Sync downstream files from VERSION (canonical source)"
@echo " make sync-version-check - Fail if any downstream file drifts from VERSION"
@echo ""
@echo "Packaging:"
@echo " make dist - Tauri bundle for the current OS"
@echo " make dist-win|dist-win-arm"
@echo " make dist-mac|dist-mac-x64"
@echo " make dist-linux|dist-linux-arm"
@echo ""
@echo "Android (Tauri mobile — needs Android SDK + JDK 17 + NDK + rustup):"
@echo " make run-android - Build + run with live reload; emulator in the FOREGROUND (window)"
@echo " make run-android-background - Same, but the emulator runs headless (no window)"
@echo " Both reuse a running emulator instead of booting another; run-android"
@echo " brings its window to the front (and reopens a headless one with a window)."
@echo " make android-deploy - Build APK + install/update it on connected device(s)"
@echo " make android-build - Build a debug APK (no device needed)"
@echo " make android-init - One-time: scaffold src-tauri/gen/android"
@echo " make ios-build - Build an unsigned iPhone .ipa for sideloading (macOS + Xcode)"
@echo " make run-ios - Run the app in the iPhone Simulator with live reload (macOS + Xcode)"
@echo " make android-deps - Check the Android toolchain is ready"
@echo " make emu-test - Build + run the app on a headless emulator, with a screenshot"
@echo " make emu-start - Boot the test emulator (headless); emu-stop to shut it down"
@echo " make emu-status - Show AVDs, whether one is running, and where artifacts go"
@echo " emu-test leaves the emulator up for fast re-runs; PS5UPLOAD_EMU_TEARDOWN=1 stops it"
@echo ""
@echo "Auto-launch (engine starts at OS login):"
@echo " make install-engine - Register systemd/launchd/Task Scheduler job"
@echo " make uninstall-engine - Remove the auto-launch registration"
@echo ""
@echo "Docker (self-hosted engine; CI publishes the same image to GHCR):"
@echo " make docker-engine - Build the engine image locally (scratch + static binary)"
@echo " make docker-engine-run - Run it (PS5_HOST=$(PS5_HOST)); exposes :19113"
@echo ""
@echo "Environment overrides (defaults shown):"
@echo " PS5_HOST=$(PS5_HOST) PS5 IP address"
@echo " PS5_LOADER_PORT=$(PS5_LOADER_PORT) PS5 payload loader port"
@echo " PS5_PAYLOAD_SDK=$(PS5_PAYLOAD_SDK) PS5 C payload SDK install"
ifeq ($(shell uname -s),Darwin)
@echo " LLVM_CONFIG=$(LLVM_CONFIG)"
@echo " Auto-set on macOS (needs Homebrew llvm)"
endif
#──────────────────────────────────────────────────────────────────────────────
# Install — fresh-machine bootstrap (apt/brew/winget + rustup + Node + PS5 SDK)
#
# `setup` only *checks* toolchains and runs `npm install`; `install` actually
# installs everything from scratch. The per-OS scripts live in `scripts/` and
# are idempotent — each step skips if already satisfied — so re-running them
# after a partial setup is safe.
#──────────────────────────────────────────────────────────────────────────────
install:
@os="$$(uname -s)"; \
case "$$os" in \
Linux*) $(MAKE) install-ubuntu ;; \
Darwin*) $(MAKE) install-macos ;; \
MINGW*|MSYS*|CYGWIN*) $(MAKE) install-windows ;; \
*) echo "Unsupported host OS: $$os"; \
echo "Run install-ubuntu / install-macos / install-windows directly."; \
exit 1 ;; \
esac
install-ubuntu:
@bash scripts/install-ubuntu.sh
install-macos:
@bash scripts/install-macos.sh
# On Windows the script is invoked via PowerShell. Tries pwsh (PowerShell 7+)
# first, then falls back to legacy Windows PowerShell. Run from any shell where
# `powershell.exe` or `pwsh` is on PATH (Git Bash, MSYS2, native PowerShell).
install-windows:
@if command -v pwsh >/dev/null 2>&1; then \
pwsh -NoProfile -ExecutionPolicy Bypass -File scripts/install-windows.ps1; \
elif command -v powershell.exe >/dev/null 2>&1; then \
powershell.exe -NoProfile -ExecutionPolicy Bypass -File scripts/install-windows.ps1; \
else \
echo "ERROR: neither pwsh nor powershell.exe on PATH."; \
echo " Run scripts/install-windows.ps1 directly from a PowerShell prompt."; \
exit 1; \
fi
# Bump the PS5 Payload SDK pin (scripts/ps5-sdk.env) to the latest upstream
# release, or SDK_TAG, and install it into $(PS5_PAYLOAD_SDK); the old SDK is
# kept as a backup. SDK_CHECK=1 only reports whether a newer release exists.
update-sdk:
@PS5_SDK_INSTALL_DIR="$(PS5_PAYLOAD_SDK)" bash scripts/update-ps5-sdk.sh \
$(if $(SDK_TAG),--tag $(SDK_TAG)) $(if $(SDK_CHECK),--check)
#──────────────────────────────────────────────────────────────────────────────
# Setup
#──────────────────────────────────────────────────────────────────────────────
setup: setup-payload setup-engine setup-client
@echo ""
@echo "✓ Setup complete"
@echo ""
@echo "Suggested next steps:"
@echo " 1. make build"
@echo " 2. make run-client"
@echo ""
setup-payload:
@echo "Checking PS5 Payload SDK..."
@if [ -z "$(PS5_PAYLOAD_SDK)" ]; then \
echo ""; \
echo "ERROR: PS5_PAYLOAD_SDK is not set."; \
echo "Install the PS5 Payload SDK and export PS5_PAYLOAD_SDK=/opt/ps5-payload-sdk"; \
echo ""; \
exit 1; \
fi
@if [ ! -f "$(PS5_PAYLOAD_SDK)/toolchain/prospero.mk" ]; then \
echo ""; \
echo "ERROR: SDK files not found at $(PS5_PAYLOAD_SDK)"; \
echo ""; \
exit 1; \
fi
@echo "✓ PS5 SDK found: $(PS5_PAYLOAD_SDK)"
ifeq ($(shell uname -s),Darwin)
@if [ -z "$(LLVM_CONFIG)" ] || [ ! -x "$(LLVM_CONFIG)" ]; then \
echo ""; \
echo "ERROR: Homebrew llvm-config was not found."; \
echo "Install it with: brew install llvm"; \
echo "Or export LLVM_CONFIG=/path/to/llvm-config"; \
echo ""; \
exit 1; \
fi
@echo "✓ LLVM found: $(LLVM_CONFIG) ($$($(LLVM_CONFIG) --version))"
endif
setup-engine:
@echo "Checking Rust toolchain..."
@command -v rustc >/dev/null 2>&1 || { \
echo "ERROR: rustc is not installed."; \
echo "Install Rust via https://rustup.rs"; \
exit 1; \
}
@command -v $(CARGO) >/dev/null 2>&1 || { \
echo "ERROR: cargo is not installed."; \
echo "Install Rust via https://rustup.rs"; \
exit 1; \
}
@echo "✓ Rust toolchain found: rustc $$(rustc --version), cargo $$($(CARGO) --version)"
setup-client:
@echo "Checking client toolchain..."
@command -v node >/dev/null 2>&1 || { echo "ERROR: Node.js is not installed."; exit 1; }
@command -v npm >/dev/null 2>&1 || { echo "ERROR: npm is not installed."; exit 1; }
@echo "✓ Node.js toolchain found: node $$(node --version), npm $$(npm --version)"
@# Reinstall only when the lockfile (or Node) changed since the last install. npm ci
@# deletes node_modules first — including Vite's dependency cache — so running it on
@# every make broke any dev server already running (make run-client beside
@# run-android or emu-test): its screens failed with "Importing a module script failed".
@cd $(CLIENT_DIR) && want="$$(node -e "const c=require('crypto'),f=require('fs');process.stdout.write(c.createHash('sha256').update(f.readFileSync('package-lock.json')).update(process.version).digest('hex'))")"; \
if [ -f node_modules/.ps5upload-installed ] && [ "$$(cat node_modules/.ps5upload-installed)" = "$$want" ]; then \
echo "✓ Client dependencies already match package-lock.json"; \
else \
echo "Installing client dependencies..." && $(NPM_INSTALL) && printf '%s' "$$want" > node_modules/.ps5upload-installed && \
echo "✓ Client dependencies installed"; \
fi
#──────────────────────────────────────────────────────────────────────────────
# Build
#──────────────────────────────────────────────────────────────────────────────
# Build the Android APK only when the toolchain is configured; otherwise skip
# with a notice so `make build` still works on machines without the Android
# SDK/NDK/JDK 17 (desktop-only contributors, CI desktop jobs). Uses the same
# vars `android-deps` checks. `android-build` self-depends on `payload`, so the
# embedded ELF is always current.
_android-build-if-ready:
@if command -v rustup >/dev/null 2>&1 && [ -n "$(ANDROID_HOME)" ] && [ -n "$(ANDROID_NDK_HOME)" ] && [ -n "$(ANDROID_JAVA_HOME)" ]; then \
echo "Android toolchain detected — building/refreshing the APK..."; \
$(MAKE) android-build && $(MAKE) _android-install-if-device; \
else \
echo "⚠ Skipping Android APK build — toolchain not configured."; \
echo " Need rustup + ANDROID_HOME + an NDK + JDK 17. Run 'make android-deps' to see what's missing."; \
fi
# Install the freshly-built universal debug APK onto every connected device
# (`adb install -r` updates in place, keeping app data). This is the step that
# actually refreshes the app ON the phone after a build. No-op with a notice
# when no device is attached — so it's safe in CI and on dev machines with no
# phone plugged in.
_android-install-if-device:
@apk="$(ANDROID_APK)"; \
adb="$(ADB)"; command -v "$$adb" >/dev/null 2>&1 || adb="adb"; \
if [ ! -f "$$apk" ]; then echo "⚠ No APK at $$apk — run 'make android-build' first."; exit 0; fi; \
if ! command -v "$$adb" >/dev/null 2>&1; then echo "⚠ adb not found — APK is at $$apk."; exit 0; fi; \
devs=$$("$$adb" devices 2>/dev/null | awk 'NR>1 && $$2=="device"{print $$1}'); \
if [ -z "$$devs" ]; then \
echo "⚠ No Android device connected — APK is at $$apk."; \
echo " Plug in a device (USB debugging on), then: $$adb install -r \"$$apk\""; \
else \
failed=0; \
for d in $$devs; do \
echo "Updating the app on device $$d (adb install -r)..."; \
out=$$("$$adb" -s "$$d" install -r "$$apk" 2>&1); \
if [ $$? -eq 0 ] && ! printf '%s' "$$out" | grep -qi 'Failure'; then \
echo "✓ App updated on $$d"; \
elif printf '%s' "$$out" | grep -qi 'UPDATE_INCOMPATIBLE\|signatures do not match'; then \
echo "⚠ Existing install on $$d was signed with a different key — reinstalling fresh (its app data is cleared)..."; \
"$$adb" -s "$$d" uninstall "$(ANDROID_APP_ID)" >/dev/null 2>&1 || true; \
if "$$adb" -s "$$d" install "$$apk" >/dev/null 2>&1; then \
echo "✓ App reinstalled on $$d"; \
else \
echo "⚠ Could not install on $$d — APK is at $$apk (install manually: $$adb -s $$d install -r \"$$apk\")."; \
failed=1; \
fi; \
elif printf '%s' "$$out" | grep -qi 'INSUFFICIENT_STORAGE' && case "$$d" in emulator-*) true;; *) false;; esac; then \
echo "⚠ $$d is out of space — removing the old install (an emulator's app data is disposable) and retrying..."; \
"$$adb" -s "$$d" uninstall "$(ANDROID_APP_ID)" >/dev/null 2>&1 || true; \
if out=$$("$$adb" -s "$$d" install "$$apk" 2>&1) && ! printf '%s' "$$out" | grep -qi 'Failure'; then \
echo "✓ App reinstalled on $$d"; \
else \
echo "⚠ Still could not install on $$d — free space on it (or wipe it: emulator -avd <name> -wipe-data):"; \
printf '%s\n' "$$out" | sed 's/^/ /'; \
failed=1; \
fi; \
else \
echo "⚠ adb install failed on $$d (build is fine — APK is at $$apk):"; \
printf '%s\n' "$$out" | sed 's/^/ /'; \
if printf '%s' "$$out" | grep -qi 'INSUFFICIENT_STORAGE'; then \
echo " The device is out of space. Free some, then: $$adb -s $$d install -r \"$$apk\""; \
fi; \
failed=1; \
fi; \
done; \
if [ $$failed -eq 0 ]; then echo "✓ Android build deployed to connected device(s)."; \
else echo "⚠ Android build NOT deployed to every device — see above."; fi; \
fi
# Build the Android APK and install/update it on the connected device(s) in
# one step — the simplest "push my latest changes to the phone".
# The install step reports its own outcome: it used to be followed by an
# unconditional "✓ deployed", even straight after a failed install.
android-deploy: android-build _android-install-if-device
# Rebuild the payload only when the PS5 SDK is configured; otherwise skip so a
# frontend-only `make run-client` keeps working without the SDK. The shell
# embeds whatever ps5upload.elf.gz is on disk (build.rs re-embeds on change).
_payload-if-ready:
@if [ -n "$(PS5_PAYLOAD_SDK)" ] && [ -f "$(PS5_PAYLOAD_SDK)/toolchain/prospero.mk" ]; then \
$(MAKE) payload; \
else \
echo "⚠ Skipping payload rebuild (PS5_PAYLOAD_SDK not set) — using existing $(PAYLOAD_ELF) if present."; \
fi
# Build only the release engine binary (the binary Tauri spawns). Skips the
# dev-profile workspace build that the standalone `engine` target does —
# `make build` only needs the release binary, not the dev workspace.
build: sync-version-check payload _engine-release client
@$(MAKE) _android-build-if-ready
@echo ""
@echo "✓ Build complete"
@echo ""
@echo "Outputs:"
@echo " - $(PAYLOAD_ELF)"
@echo " - $(ENGINE_DIR)/target/"
@echo " - $(CLIENT_DIR)/dist/"
@echo " - $(ANDROID_APK) (when the Android toolchain is present)"
@echo ""
# VERSION (repo root) is the canonical source of truth. `sync-version`
# rewrites downstream files (payload config.h macro, client package
# manifests, Tauri conf + Cargo.toml) from it; `sync-version-check`
# fails if any downstream file has drifted — wired into `build` so
# a desync gets caught before we ship an ELF + bundle with mismatched
# version strings.
sync-version:
@node scripts/update-version.js
sync-version-check:
@node scripts/update-version.js --check
payload: setup-payload installer
@echo "Building PS5 payload..."
@$(MAKE) -C $(PAYLOAD_DIR) -j$(JOBS)
@echo "✓ Built $(PAYLOAD_ELF)"
# PS5Upload installer daemon (our own; supersedes the DPI daemon).
installer: setup-payload
@echo "Building PS5Upload installer daemon..."
@$(MAKE) -C $(INSTALLER_DIR) -j$(JOBS)
@echo "✓ Built $(INSTALLER_ELF)"
# The converter as a program for the PS5 itself (engine/crates/ps5upload-convert), built as a PS5
# ELF in Docker: Rust's std is compiled for the console there (payload/convert/Dockerfile), so no
# local PS5 SDK or Rust nightly is needed, only Docker. The script also checks the ELF's shape
# and that the console exports everything it imports. CONVERT_CHECK=1 only checks a built ELF.
.PHONY: console-convert
console-convert:
@echo "Building ps5upload-convert for the PS5 (Docker)..."
@bash payload/convert/build.sh $(if $(CONVERT_CHECK),--check)
@echo "✓ Built payload/convert/ps5upload-convert.elf"
# The patched elfldr the engine sends to replace a console's stock one (see
# third_party/elfldr/README.md). Its ELF is checked in, so a build without the
# SDK still embeds it; rebuild after changing the vendored sources.
.PHONY: elfldr
elfldr: setup-payload
@echo "Building the patched elfldr..."
@$(MAKE) -C third_party/elfldr
@rm -f third_party/elfldr/*.o
@echo "✓ Built third_party/elfldr/elfldr-ps5.elf"
send-payload: payload
@echo "Sending payload to $(PS5_HOST):$(PS5_LOADER_PORT) ..."
@if ! command -v python3 >/dev/null 2>&1; then \
echo "ERROR: python3 not found — required for bounded payload upload"; exit 1; \
fi
@python3 -c 'import pathlib, socket, sys; host, port, payload_path = sys.argv[1], int(sys.argv[2]), pathlib.Path(sys.argv[3]); payload = payload_path.read_bytes(); sock = socket.create_connection((host, port), timeout=5); sock.settimeout(5); sock.sendall(payload); sock.shutdown(socket.SHUT_WR); sock.close()' "$(PS5_HOST)" "$(PS5_LOADER_PORT)" "$(PAYLOAD_ELF)"
@echo "✓ Payload sent — wait for PS5 notification before testing"
engine: setup-engine
@echo "Building Rust engine workspace..."
@cd $(ENGINE_DIR) && $(CARGO) build --workspace
@echo "Building release ps5upload-engine + ps5upload-unrar (the binaries Tauri embeds)..."
@cd $(ENGINE_DIR) && $(CARGO) build --release -p ps5upload-engine -p ps5upload-unrar
@echo "✓ Engine workspace built"
# Internal helper: build the `ps5upload-engine` release binary, which the
# Tauri setup hook (client/src-tauri/src/engine.rs) spawns as a child of
# the window process. `cargo build --release` is itself incremental, so
# this is a cheap no-op when sources are unchanged — and a real rebuild
# the moment they aren't. (An earlier version guarded with
# `[ ! -x binary ]`, which stayed stale through code changes; removed.)
# ps5upload-unrar (the RAR helper; UnRAR is never linked into the engine, see
# LICENSES/UnRAR-exception.md) is built into the same directory: the desktop
# build embeds it next to the engine.
_engine-release: setup-engine
@if [ -n "$(ENGINE_TARGET)" ]; then \
cd $(ENGINE_DIR) && $(CARGO) build --release -p ps5upload-engine -p ps5upload-unrar --target "$(ENGINE_TARGET)"; \
else \
cd $(ENGINE_DIR) && $(CARGO) build --release -p ps5upload-engine -p ps5upload-unrar; \
fi
client: setup-client
@echo "Building client UI..."
@cd $(CLIENT_DIR) && npm run build:vite
@echo "✓ Client UI built"
#──────────────────────────────────────────────────────────────────────────────
# Benchmarking + validation
#
# `make validate` is the single-command flow for "we are still progressing":
# rebuild payload, send to PS5, wait for ready, run smoke + full sweep, write
# a timestamped report under bench/reports/ and print a summary table.
# `make validate-xl` adds the 200k-file stress profile.
#──────────────────────────────────────────────────────────────────────────────
gen-fixtures:
@echo "Generating benchmark fixtures under bench/fixtures/..."
@node scripts/gen-fixtures.mjs
sweep:
@echo "Running the upload sweep against live PS5 at $(PS5_HOST) ..."
@node bench/run-sweep.mjs --spawn-engine --gen-fixtures
# Wait for the payload's runtime port to accept connections after send.
# Retries 15×/2s = 30s ceiling; exits non-zero if the port never opens.
_wait-payload-ready:
@echo "Waiting for the helper's AVA1 port 9120 ..."
@i=0; while [ $$i -lt 15 ]; do \
if nc -z -w 1 "$(PS5_HOST)" 9120 >/dev/null 2>&1; then \
echo "✓ runtime port open"; exit 0; \
fi; \
i=$$((i+1)); sleep 2; \
done; \
echo "ERROR: PS5 AVA1 port 9120 did not open within 30s"; exit 1
#──────────────────────────────────────────────────────────────────────────────
# check-no-ftx2: the retired protocol (FTX2) and its ports (9113 transfer, 9114
# management) must not reappear anywhere in the repository.
#
# The scope is the whole tree, payload and the host C tests included, except the history the
# project keeps on purpose and the files that must name the legacy protocol (listed below). The
# pattern is case-insensitive "ftx2" or a bare port 9113/9114. Digits on either side are excluded
# so the engine's own 19113 is not a match. Binary files and lockfiles are not searched.
#
# Exceptions (each is a path excluded from the search; keep this list to files that must name
# the legacy protocol, and reword anything else to AVA1 terms):
# CHANGELOG.md history keeps FTX2 by design.
# site/releases.json the website's copy of the release notes (same history).
# protocol/ps5upload-ava1/ the method checklist describes the migration from FTX2.
# Makefile, .github/workflows/engine-ci.yml
# name this check and its pattern.
# .../ps5upload-ctest/tests/payload_cutover.rs
# asserts the payload no longer says FTX2 or 9113/9114.
# .../ps5upload-engine/src/ava1_only_tests.rs
# the tests that pin the engine free of the retired symbols.
# client/src/lib/addr.ts,
# client/src/lib/humanizeError.ts tolerate a stale host:9113 / host:9114 a user or an
# older engine message still carries.
# *.test.ts, *.test.tsx use 9113/9114 as fixture addresses for that same tolerance.
# engine .../install/, fakelibs_api.rs, icon_cache.rs, ps5upload-ava1 pool.rs, the lab's
# main.rs and bench.rs old-port strip logic and its fixtures.
# payload/third_party vendored code (zlib's CRC table holds 0x...9113 words).
# scripts/i18n-source-hashes.json generated hashes, which can hold those digits anywhere.
CHECK_NO_FTX2_PATTERN := ftx2|(^|[^0-9])911[34]([^0-9]|$$)
CHECK_NO_FTX2_SCOPE := .
CHECK_NO_FTX2_EXCEPT := \
':!engine/crates/ps5upload-ctest/tests/payload_cutover.rs' \
':!CHANGELOG.md' ':!site/releases.json' \
':!CONTRIBUTING.md' ':!TESTING.md' ':!RELEASING.md' ':!scripts/release/fast-release.sh' \
':!protocol/ps5upload-ava1' ':!third_party/ava1' \
':!Makefile' \
':!.github/workflows/engine-ci.yml' \
':!*Cargo.lock' ':!*package-lock.json' \
':!engine/crates/ps5upload-engine/src/ava1_only_tests.rs' \
':!engine/crates/ps5upload-engine/src/install' \
':!engine/crates/ps5upload-engine/src/fakelibs_api.rs' \
':!engine/crates/ps5upload-engine/src/icon_cache.rs' \
':!engine/crates/ps5upload-ava1/src/pool.rs' \
':!engine/crates/ps5upload-lab/src/main.rs' \
':!engine/crates/ps5upload-lab/src/bench.rs' \
':!client/src/lib/addr.ts' \
':!client/src/lib/humanizeError.ts' \
':!client/src/**/*.test.ts' ':!client/src/**/*.test.tsx' \
':!payload/third_party' ':!scripts/i18n-source-hashes.json'
check-no-ftx2:
@if git grep -n -I -i -E '$(CHECK_NO_FTX2_PATTERN)' -- $(CHECK_NO_FTX2_SCOPE) $(CHECK_NO_FTX2_EXCEPT); then \
echo "ERROR: FTX2 or port 9113/9114 found above (see the check-no-ftx2 notes in the Makefile)"; exit 1; \
else echo "✓ check-no-ftx2: clean"; fi
# The helper this build carries must be this version (12.6.15): a stale payload/ps5upload.elf
# embedded in the app was sent to consoles as "the current helper" and then replaced again and
# again. The helper says its version in a marker (payload/src/main.c); the app and the engine read
# it too and never send a helper of another version by themselves.
check-helper-version:
@want="$$(tr -d '[:space:]' < VERSION)"; \
test -s "$(PAYLOAD_ELF)" || { echo "ERROR: $(PAYLOAD_ELF) is missing"; exit 1; }; \
got="$$(LC_ALL=C grep -a -o 'PS5UPLOAD_HELPER_VERSION=[0-9A-Za-z.+-]*;' "$(PAYLOAD_ELF)" | head -1 | sed 's/^PS5UPLOAD_HELPER_VERSION=//; s/;$$//')"; \
if [ -z "$$got" ]; then echo "ERROR: $(PAYLOAD_ELF) carries no version marker (a build from before 12.6.15, or not the helper)"; exit 1; fi; \
if [ "$$got" != "$$want" ]; then echo "ERROR: $(PAYLOAD_ELF) is helper v$$got but VERSION is $$want: run make payload"; exit 1; fi; \
echo "✓ check-helper-version: $(PAYLOAD_ELF) is v$$got"
validate: check-no-ftx2 send-payload _wait-payload-ready
@echo ""
@echo "── Running smoke suite ────────────────────────────────"
@npm run --silent smoke:hardware
@echo ""
@echo "── Running sweep (default profiles) ────────────────────"
@node bench/run-sweep.mjs --spawn-engine --gen-fixtures
@echo ""
@echo "✓ validate complete — see bench/reports/ for the full report"
validate-xl: send-payload _wait-payload-ready
@echo ""
@echo "── Running smoke suite ────────────────────────────────"
@npm run --silent smoke:hardware
@echo ""
@echo "── Running sweep (INCLUDING XL 200k-file stress) ───────"
@node bench/run-sweep.mjs --spawn-engine --gen-fixtures --xl
@echo ""
@echo "✓ validate-xl complete — see bench/reports/ for the full report"
#──────────────────────────────────────────────────────────────────────────────
# Distribution — all drive `tauri build`, producing ~14 MB .app/.AppImage/.msi
# instead of Electron's ~300 MB bundles. The Rust engine binary is bundled as
# a Tauri resource and discovered at runtime by client/src-tauri/src/engine.rs.
# `payload` and `_engine-release` run first so the bundle includes a current
# ELF and a freshly-built engine.
#──────────────────────────────────────────────────────────────────────────────
dist: payload _engine-release setup-client
@echo "Building desktop distribution (Tauri)..."
@cd $(CLIENT_DIR) && npm run dist
@echo "✓ Distribution packages built: $(CLIENT_DIR)/src-tauri/target/release/bundle/"
dist-win: ENGINE_TARGET := x86_64-pc-windows-msvc
dist-win: payload setup-client
@$(MAKE) _engine-release ENGINE_TARGET=$(ENGINE_TARGET)
@echo "Building Windows distribution (Tauri)..."
@cd $(CLIENT_DIR) && npm run dist:win
@echo "✓ Windows packages built: $(CLIENT_DIR)/src-tauri/target/x86_64-pc-windows-msvc/release/bundle/"
dist-win-arm: ENGINE_TARGET := aarch64-pc-windows-msvc
dist-win-arm: payload setup-client
@$(MAKE) _engine-release ENGINE_TARGET=$(ENGINE_TARGET)
@echo "Building Windows ARM64 distribution (Tauri)..."
@cd $(CLIENT_DIR) && npm run dist:win-arm
@echo "✓ Windows ARM64 packages built: $(CLIENT_DIR)/src-tauri/target/aarch64-pc-windows-msvc/release/bundle/"
dist-mac: ENGINE_TARGET := aarch64-apple-darwin
dist-mac: payload setup-client
@$(MAKE) _engine-release ENGINE_TARGET=$(ENGINE_TARGET)
@echo "Building macOS Apple Silicon distribution (Tauri)..."
@cd $(CLIENT_DIR) && npm run dist:mac
@echo "✓ macOS Apple Silicon packages built: $(CLIENT_DIR)/src-tauri/target/aarch64-apple-darwin/release/bundle/"
dist-mac-x64: ENGINE_TARGET := x86_64-apple-darwin
dist-mac-x64: payload setup-client
@$(MAKE) _engine-release ENGINE_TARGET=$(ENGINE_TARGET)
@echo "Building macOS Intel distribution (Tauri)..."
@cd $(CLIENT_DIR) && npm run dist:mac-x64
@echo "✓ macOS Intel packages built: $(CLIENT_DIR)/src-tauri/target/x86_64-apple-darwin/release/bundle/"
dist-linux: ENGINE_TARGET := x86_64-unknown-linux-gnu
dist-linux: payload setup-client
@$(MAKE) _engine-release ENGINE_TARGET=$(ENGINE_TARGET)
@echo "Building Linux x64 distribution (Tauri)..."
@cd $(CLIENT_DIR) && npm run dist:linux
@echo "✓ Linux x64 packages built: $(CLIENT_DIR)/src-tauri/target/x86_64-unknown-linux-gnu/release/bundle/"
dist-linux-arm: ENGINE_TARGET := aarch64-unknown-linux-gnu
dist-linux-arm: payload setup-client
@$(MAKE) _engine-release ENGINE_TARGET=$(ENGINE_TARGET)
@echo "Building Linux ARM64 distribution (Tauri)..."
@cd $(CLIENT_DIR) && npm run dist:linux-arm
@echo "✓ Linux ARM64 packages built: $(CLIENT_DIR)/src-tauri/target/aarch64-unknown-linux-gnu/release/bundle/"
#──────────────────────────────────────────────────────────────────────────────
# Android (Tauri mobile). Like the `dist` targets but produces an APK. The
# engine is linked in-process (engine_mobile.rs) rather than spawned, and only
# the PS5 payload is bundled — so `payload` runs first to embed a current ELF.
# gen/ is gitignored, so the recipes auto-run `android-init` if it's missing.
#──────────────────────────────────────────────────────────────────────────────
android-deps:
@command -v rustup >/dev/null 2>&1 || { echo "ERROR: rustup is required for Android cross-compilation (Homebrew 'rust' ships only the host std). Install from https://rustup.rs"; exit 1; }
@test -n "$(ANDROID_HOME)" || { echo "ERROR: ANDROID_HOME is not set — point it at your Android SDK (e.g. ~/Library/Android/sdk)"; exit 1; }
@test -n "$(ANDROID_NDK_HOME)" || { echo "ERROR: no NDK under $(ANDROID_HOME)/ndk — install via Android Studio or 'sdkmanager \"ndk;28.0.12916984\"'"; exit 1; }
@test -n "$(ANDROID_JAVA_HOME)" || { echo "ERROR: JDK 17 not found — set JAVA_HOME or install Temurin 17"; exit 1; }
@rustup target list --installed 2>/dev/null | grep -qx '$(ANDROID_RUST_TARGET)' || rustup target add $(ANDROID_RUST_TARGET)
@echo "Android toolchain OK — JDK=$(ANDROID_JAVA_HOME) NDK=$(ANDROID_NDK_HOME) target=$(ANDROID_RUST_TARGET)"
# ─── Headless emulator for testing without a physical device ─────────────
# Lifecycle lives in scripts/android-emu.sh. Artifacts (screenshots, logcat,
# install logs) are written OUTSIDE the repo, to ~/.ps5upload/android-test/ —
# this repo has already leaked debug screenshots into a public repo, and a
# file that is not in the working tree cannot be committed by accident.
emu-create:
@bash scripts/android-emu.sh create
emu-start:
@bash scripts/android-emu.sh start
emu-stop:
@bash scripts/android-emu.sh stop
emu-status:
@bash scripts/android-emu.sh status
# Build the APK, then install + launch it on the emulator and capture proof.
# Depends on android-build so `make emu-test` is the single command.
emu-test: android-build
@bash scripts/android-emu.sh test
android-init: android-deps setup-client
@echo "Scaffolding Android project (tauri android init)..."
@cd $(CLIENT_DIR) && $(ANDROID_ENV) npx tauri android init
@echo "Allowing loopback cleartext so the in-process engine is reachable..."
@bash scripts/release/android-postinit-patch.sh
android-build: android-deps payload setup-client
@test -d $(ANDROID_GEN_DIR) || $(MAKE) android-init
@# Re-apply the (idempotent) post-init patches on every build. They used to
@# run only at init, so an existing gen/ never picked up a new patch step and
@# a local APK silently differed from the CI one, which inits fresh.
@bash scripts/release/android-postinit-patch.sh
@echo "Building Android APK (debug, $(ANDROID_TARGET))..."
@cd $(CLIENT_DIR) && $(ANDROID_ENV) npx tauri android build --debug --apk --target $(ANDROID_TARGET)
@apk=$$(find "$(ANDROID_GEN_DIR)/app/build/outputs/apk" -name 'app-*-debug.apk' -print -quit 2>/dev/null); \
echo "✓ APK built: $${apk:-under $(ANDROID_GEN_DIR)/app/build/outputs/apk}"
# iPhone: an unsigned .ipa for sideloading (AltStore, Sideloadly), as the release
# builds it. macOS with Xcode only; Xcode needs its iOS platform once
# (`xcodebuild -downloadPlatform iOS`).
IOS_GEN_DIR := $(CLIENT_DIR)/src-tauri/gen/apple
ios-init: setup-client
@echo "Scaffolding iOS project (tauri ios init)..."
@cd $(CLIENT_DIR) && npx tauri ios init --ci
@bash scripts/release/ios-postinit-patch.sh
ios-build: payload setup-client
@test -d $(IOS_GEN_DIR) || $(MAKE) ios-init
@bash scripts/release/ios-postinit-patch.sh
@echo "Building unsigned iPhone IPA (arm64)..."
@cd $(CLIENT_DIR) && npx tauri ios build --ci --target aarch64 --no-sign
@python3 scripts/release/verify-ios-ipa.py output/PS5Upload-ios-unsigned.ipa
# iPhone Simulator: see the app on a simulated iPhone, with live reload, like run-android.
# Reuses a booted iPhone simulator or boots one (scripts/ios-sim.sh), pre-grants the app's
# privacy permissions, and on Ctrl-C stops the dev server and shuts down only a simulator it booted. PS5UPLOAD_IOS_SIM="iPhone 17 Pro" picks the device. Needs Xcode's iOS platform once:
# `xcodebuild -downloadPlatform iOS`. For a real iPhone, build the .ipa (make ios-build).
IOS_VITE_PORT ?= 1440
IOS_SIM_RUST_TARGET := $(if $(filter arm64,$(shell uname -m)),aarch64-apple-ios-sim,x86_64-apple-ios)
run-ios: payload setup-client
@command -v xcodebuild >/dev/null 2>&1 || { echo "ERROR: run-ios needs macOS with Xcode"; exit 1; }
@rustup target list --installed 2>/dev/null | grep -qx '$(IOS_SIM_RUST_TARGET)' || rustup target add $(IOS_SIM_RUST_TARGET)
@test -d $(IOS_GEN_DIR) || $(MAKE) ios-init
@bash scripts/release/ios-postinit-patch.sh
@out=$$(bash $(CURDIR)/scripts/ios-sim.sh ensure) || exit 1; \
state=$$(printf '%s' "$$out" | cut -f1); name=$$(printf '%s' "$$out" | cut -f2); udid=$$(printf '%s' "$$out" | cut -f3); \
if [ "$$state" = "booted" ]; then \
trap 'trap - EXIT INT TERM; echo ""; echo "Shutting down the simulator this run booted..."; PS5UPLOAD_IOS_SIM_UDID='"$$udid"' bash $(CURDIR)/scripts/ios-sim.sh stop' EXIT INT TERM; \
else \
echo " (leaving the running simulator up)"; \
fi; \
PS5UPLOAD_IOS_SIM_UDID="$$udid" bash $(CURDIR)/scripts/ios-sim.sh grant; \
echo "Launching on $$name (tauri ios dev)..."; \
cd $(CLIENT_DIR) && PS5UPLOAD_VITE_PORT=$(IOS_VITE_PORT) npx tauri ios dev "$$name" \
--config '{"build":{"devUrl":"http://localhost:$(IOS_VITE_PORT)"}}'
# Boots the headless test emulator when nothing is attached, and shuts down
# ONLY an emulator this invocation booted -- a phone you plugged in, or an
# emulator you already had running, is left alone. The trap covers Ctrl-C,
# which is how `tauri android dev` normally ends.
# run-android: the emulator boots WITH its window (foreground) so the app can be
# seen and used. run-android-background: it boots headless, as emu-test does.
# Either way the dev server stays attached here for live reload.
# Android dev's Vite ports (live reload on the next one up), separate from
# desktop dev's 1420/1421 so `make run-client` and `make run-android` can run
# at the same time.
ANDROID_VITE_PORT ?= 1430
run-android: EMU_WINDOW := 1
run-android-background: EMU_WINDOW := 0
# Ctrl-C ends it cleanly: the dev server and the permission helper stop, any Gradle or Kotlin
# daemon this run started is stopped (by PID; daemons that were already running, such as Android
# Studio's, are left alone), and the emulator is shut down only when this run booted it.
GRADLE_DAEMON_RE := org.gradle.launcher.daemon.bootstrap.GradleDaemon|KotlinCompileDaemon
run-android run-android-background: android-deps payload setup-client
@test -d $(ANDROID_GEN_DIR) || $(MAKE) android-init
@bash scripts/release/android-postinit-patch.sh >/dev/null
@state=$$(PS5UPLOAD_EMU_WINDOW=$(EMU_WINDOW) bash $(CURDIR)/scripts/android-emu.sh ensure) || exit 1; \
grant=""; daemons_before=" $$(pgrep -f '$(GRADLE_DAEMON_RE)' | tr '\n' ' ') "; \
trap 'trap - EXIT INT TERM; [ -n "$$grant" ] && kill $$grant 2>/dev/null; \
for p in $$(pgrep -f "$(GRADLE_DAEMON_RE)"); do case "'"$$daemons_before"'" in *" $$p "*) ;; *) kill $$p 2>/dev/null;; esac; done; \
if [ "'"$$state"'" = booted ]; then echo ""; echo "Shutting down the emulator this run booted..."; bash $(CURDIR)/scripts/android-emu.sh stop; fi' EXIT INT TERM; \
[ "$$state" = booted ] || echo " (leaving the existing device/emulator running)"; \
bash $(CURDIR)/scripts/android-emu.sh grant --wait & grant=$$!; \
echo "Launching on the attached Android device/emulator (tauri android dev)..."; \
cd $(CLIENT_DIR) && PS5UPLOAD_VITE_PORT=$(ANDROID_VITE_PORT) $(ANDROID_ENV) npx tauri android dev \
--config '{"build":{"devUrl":"http://localhost:$(ANDROID_VITE_PORT)"}}'
#──────────────────────────────────────────────────────────────────────────────
# Docker — self-hosted engine image. Mirrors what .github/workflows/
# docker-engine.yml publishes to ghcr.io/<owner>/ps5upload-engine on each
# release tag (multi-arch there; single-arch host build here). The REPO ROOT is
# the build context (the Dockerfile copies payload/ and third_party/ too); the
# Dockerfile is a scratch image wrapping the static binary.
#
# SECURITY: the engine API is unauthenticated. Bind to a LAN interface and set
# PS5UPLOAD_ALLOW_IP only on a trusted network — never expose it to the
# internet. See the header of engine/Dockerfile.
#──────────────────────────────────────────────────────────────────────────────
DOCKER ?= docker
DOCKER_ENGINE_IMAGE ?= ps5upload-engine
# Who may reach the engine through the published port. With `-p` the container
# sees Docker's bridge gateway, not loopback, so without this every request got
# "403 loopback only" (engine/Dockerfile header). 172.17.0.1 is the default
# bridge on Linux, 192.168.65.x the VM gateway on Docker Desktop; override with
# your LAN range (DOCKER_ALLOW_IP=192.168.1.0/24) to use it from other machines.
DOCKER_ALLOW_IP ?= 172.16.0.0/12,192.168.65.0/24
# This host's LAN IP, which the PS5 fetches package bytes from during a stream
# install. Required on Docker Desktop (macOS/Windows), where the container's
# own guess is a NAT address the PS5 cannot reach; on Linux prefer
# `docker run --network host` (engine/compose.yaml) and leave it empty.
DOCKER_PKG_HOST_IP ?=
docker-engine:
@command -v $(DOCKER) >/dev/null 2>&1 || { echo "ERROR: docker not found on PATH."; exit 1; }
@echo "Building $(DOCKER_ENGINE_IMAGE) image (context: repo root, as in CI)..."
@$(DOCKER) build -t $(DOCKER_ENGINE_IMAGE) -f $(ENGINE_DIR)/Dockerfile .
@echo "✓ Built image $(DOCKER_ENGINE_IMAGE) — run with: make docker-engine-run"
# Run the locally-built engine image. Binds the published port and points it at
# the PS5 (AVA1, port 9120). Override PS5_HOST, DOCKER_ALLOW_IP and
# DOCKER_PKG_HOST_IP as needed.
docker-engine-run: docker-engine
@echo "Running $(DOCKER_ENGINE_IMAGE) — engine on :19113, PS5 at $(PS5_HOST), allowed from $(DOCKER_ALLOW_IP) ..."
@$(DOCKER) run --rm -p 19113:19113 -e PS5_ADDR=$(PS5_HOST) \
-e PS5UPLOAD_ALLOW_IP=$(DOCKER_ALLOW_IP) \
$(if $(DOCKER_PKG_HOST_IP),-e PS5UPLOAD_PKG_HOST_IP=$(DOCKER_PKG_HOST_IP),) \
$(DOCKER_ENGINE_IMAGE)
#──────────────────────────────────────────────────────────────────────────────
# Testing
#──────────────────────────────────────────────────────────────────────────────
test: test-root test-engine test-desktop test-payload test-client
@echo ""
@echo "✓ All tests passed"
@echo ""
# Known-vulnerable dependencies and committed secrets (cargo audit, npm audit, gitleaks).
.PHONY: security
security:
@bash scripts/security-scan.sh
lint: lint-scripts lint-client
lint-scripts:
@npm run scripts:check
lint-client:
@cd $(CLIENT_DIR) && npm run lint
audit-scripts:
@npm run scripts:audit
coverage:
@npm run coverage
coverage-engine:
@npm run coverage -- --engine-only
coverage-client:
@npm run coverage -- --client-only
quality:
@npm run validate
quality-full:
@npm run validate:full
# quality, then the e2e suite, then test-payload; see scripts/release/release-check.sh.
release-check:
@bash scripts/release/release-check.sh
# A small change, shipped at once as a pre-release: bare checks, PR merged without waiting for
# CI, tagged with force. See scripts/release/fast-release.sh and RELEASING.md.
fast-release:
@test -n "$(V)" || { echo "usage: make fast-release V=X.Y.Z"; exit 2; }
@bash scripts/release/fast-release.sh "$(V)" $(if $(GATE),--gate)
quality-hardware:
@npm run validate:hardware
ci: quality
ci-full: quality-full
# Root-level tests: syntax-check the node scripts that back the bench + smoke
# harnesses. Hardware smoke coverage lives in `make sweep` / `make validate`.
test-root:
@echo "Syntax-checking root node scripts..."
@node --check tests/smoke-hardware.mjs
@node --check bench/run-sweep.mjs
@node --check scripts/gen-fixtures.mjs
@node --check scripts/check-lockfile.mjs
@node scripts/check-lockfile.mjs --self-test
@echo "Checking the client lockfile kept its libc metadata..."
@node scripts/check-lockfile.mjs
@python3 scripts/release/verify-android-apk.py --self-test
@echo "✓ Root scripts valid"
test-engine: setup-engine
@echo "Running Rust engine tests..."
@# With cargo-nextest installed this runs the same tests the way scripts/validate-repo.mjs
@# does (and CI, except for the C interop suite): test binaries side by side (most sit in
@# network sleeps), each test in its own process, so the C interop tests' one server per
@# process holds without --test-threads=1; engine/.config/nextest.toml serializes the
@# timing-sensitive binaries.
@# nextest skips doctests, so they run separately. Without nextest: cargo test, serially.
@# The RAR tests start the ps5upload-unrar helper from the target directory: build it first.
@cd $(ENGINE_DIR) && $(CARGO) build -p ps5upload-unrar
@if $(CARGO) nextest --version >/dev/null 2>&1; then \
cd $(ENGINE_DIR) && $(CARGO) nextest run --workspace --exclude ps5upload-ctest && \
$(CARGO) test --workspace --exclude ps5upload-ctest --doc && \
$(CARGO) nextest run -p ps5upload-ctest; \
else \
cd $(ENGINE_DIR) && $(CARGO) test --workspace --exclude ps5upload-ctest && \
$(CARGO) test -p ps5upload-ctest -- --test-threads=1; \
fi
@echo "✓ Engine tests passed"
@# Android cross-compile check. The engine cfg's some code out on
@# Android (RAR, which needs the ps5upload-unrar helper program), so a call site added
@# without the matching cfg builds fine on every desktop target and fails
@# ONLY here. That is exactly how v5.31.0 shipped with no APK: every local
@# gate was green on macOS while the Android build was broken, and it was
@# not caught until the release workflow. `cargo check` is enough — this
@# needs to catch a compile error, not produce an artifact.
@if rustup target list --installed 2>/dev/null | grep -q aarch64-linux-android; then \
echo "Checking engine against the Android target..."; \
cd $(ENGINE_DIR) && $(CARGO) check -p ps5upload-engine --target aarch64-linux-android; \
echo "✓ Engine compiles for Android"; \
else \
echo "⚠ aarch64-linux-android target not installed — SKIPPING the Android check."; \
echo " CI still runs it, so a cfg mistake will surface there instead of here."; \
echo " Install with: rustup target add aarch64-linux-android"; \
fi
test-engine-coverage:
@$(MAKE) coverage-engine
test-desktop: setup-engine
@echo "Checking Tauri Rust shell..."
@# No separate `cargo check --all-targets`: clippy --all-targets type-checks the same code
@# (CI and scripts/validate-repo.mjs dropped it for the same reason).
@cd $(CLIENT_DIR)/src-tauri && $(CARGO) clippy --all-targets -- -D warnings
@cd $(CLIENT_DIR)/src-tauri && $(CARGO) test
@echo "✓ Desktop Rust checks passed"
# Each host self-test runs under a time limit (scripts/run-limited.pl): one that hangs fails by
# name with a stack sample instead of silently eating CI's 20 minutes (twice in Oct 2026 a macOS
# runner hung in this target, and a cancelled job keeps no log).
SELFTEST_LIMIT ?= 240
RUN_LIMITED = perl $(CURDIR)/scripts/run-limited.pl $(SELFTEST_LIMIT)
# Binaries and fixtures of the host self-tests: per checkout, so two checkouts (or two users) running
# this at once do not overwrite each other's.
SELFTEST_DIR := $(CURDIR)/$(PAYLOAD_DIR)/build/selftests
test-payload: payload
@echo "Validating payload binaries..."
@for elf in "$(PAYLOAD_ELF)" "$(INSTALLER_ELF)"; do \
if [ ! -s "$$elf" ]; then \
echo "ERROR: $$elf is missing or empty."; \
exit 1; \
fi; \
file "$$elf" | grep -q "ELF.*FreeBSD" || { \
echo "ERROR: $$elf is not a PS5/FreeBSD ELF file."; \
exit 1; \
}; \
if [ ! -s "$$elf.gz" ]; then \
echo "ERROR: $$elf.gz is missing or empty."; \
exit 1; \