feature/extend-tauri-generated-xcode-project-for-tvos-target
text 203 lines 8.11 KB
Raw
1 # =============================================================================
2 # gen/apple/Makefile
3 #
4 # Bridges the Tauri code-generation lifecycle with Tuist project generation.
5 #
6 # WHY THIS FILE EXISTS
7 # --------------------
8 # `cargo tauri ios init` regenerates project.yml (XcodeGen format) but does
9 # NOT touch Project.swift (our Tuist manifest). We use Tuist as the single
10 # source of truth for the Xcode project, so every time Tauri regenerates the
11 # scaffold we must follow up with `tuist generate`.
12 #
13 # WORKFLOW
14 # --------
15 # First-time setup or after pulling fresh:
16 # make setup
17 #
18 # After `cargo tauri ios init` (Tauri regenerated the scaffold):
19 # make generate
20 #
21 # Open Xcode to work on iOS or tvOS:
22 # make open
23 #
24 # Full reset (nuclear option — re-scaffolds Tauri then regenerates Tuist):
25 # make reset
26 # =============================================================================
27
28 # Resolve the src-tauri root regardless of where make is invoked from.
29 # This file lives at src-tauri/gen/apple/Makefile.
30 SRC_TAURI := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))../..)
31
32 # Workspace root (two levels above src-tauri)
33 APP_ROOT := $(abspath $(SRC_TAURI)/../..)
34
35 .DEFAULT_GOAL := help
36
37 # -----------------------------------------------------------------------------
38 # help — print usage
39 # -----------------------------------------------------------------------------
40 .PHONY: help
41 help:
42 @echo ""
43 @echo " Tauri + Tuist iOS/tvOS project targets"
44 @echo " ======================================="
45 @echo ""
46 @echo " make setup — first-time: install tuist (via mise) then generate"
47 @echo " make generate — run 'tuist generate' to rebuild the Xcode project"
48 @echo " make open — generate then open the workspace in Xcode"
49 @echo " make ios — generate then build the iOS target (simulator)"
50 @echo " make tvos — generate then build the tvOS target (simulator)"
51 @echo " make clean — remove Xcode-derived data for this project"
52 @echo " make reset — re-scaffold via Tauri then re-generate via Tuist"
53 @echo " make lint — run tuist lint on Project.swift"
54 @echo ""
55 @echo " Advanced:"
56 @echo " make tauri-init — run 'cargo tauri ios init' (re-generates project.yml)"
57 @echo " NOTE: follow up with 'make generate'"
58 @echo ""
59
60 # -----------------------------------------------------------------------------
61 # setup — install tooling (mise activates tuist) then generate the project
62 # -----------------------------------------------------------------------------
63 .PHONY: setup
64 setup: _require_mise _tuist_install generate
65 @echo "✅ Setup complete. Run 'make open' to launch Xcode."
66
67 # -----------------------------------------------------------------------------
68 # generate — the core step: (re)build *.xcodeproj from Project.swift
69 #
70 # Called after:
71 # • first checkout
72 # • `cargo tauri ios init` (which only regenerates project.yml, not Project.swift)
73 # • any edit to Project.swift
74 # -----------------------------------------------------------------------------
75 .PHONY: generate
76 generate: _require_tuist
77 @echo "▶ tuist generate …"
78 cd "$(dir $(abspath $(lastword $(MAKEFILE_LIST))))" && tuist generate --no-open
79 @echo "✅ Xcode project regenerated from Project.swift"
80
81 # -----------------------------------------------------------------------------
82 # open — generate the project then open the workspace in Xcode
83 # -----------------------------------------------------------------------------
84 .PHONY: open
85 open: _require_tuist
86 @echo "▶ tuist generate + open …"
87 cd "$(dir $(abspath $(lastword $(MAKEFILE_LIST))))" && tuist generate
88
89 # -----------------------------------------------------------------------------
90 # ios — build the iOS target against the default simulator
91 # -----------------------------------------------------------------------------
92 .PHONY: ios
93 ios: generate
94 @echo "▶ Building tauri-app_iOS (simulator) …"
95 xcodebuild \
96 -workspace "$(dir $(abspath $(lastword $(MAKEFILE_LIST))))tauri-app.xcworkspace" \
97 -scheme tauri-app_iOS \
98 -destination "generic/platform=iOS Simulator" \
99 -configuration Debug \
100 build \
101 | xcbeautify || xcodebuild \
102 -workspace "$(dir $(abspath $(lastword $(MAKEFILE_LIST))))tauri-app.xcworkspace" \
103 -scheme tauri-app_iOS \
104 -destination "generic/platform=iOS Simulator" \
105 -configuration Debug \
106 build
107
108 # -----------------------------------------------------------------------------
109 # tvos — build the tvOS target against the default simulator
110 # -----------------------------------------------------------------------------
111 .PHONY: tvos
112 tvos: generate
113 @echo "▶ Building tauri-app_tvOS (simulator) …"
114 xcodebuild \
115 -workspace "$(dir $(abspath $(lastword $(MAKEFILE_LIST))))tauri-app.xcworkspace" \
116 -scheme tauri-app_tvOS \
117 -destination "generic/platform=tvOS Simulator" \
118 -configuration Debug \
119 build \
120 | xcbeautify || xcodebuild \
121 -workspace "$(dir $(abspath $(lastword $(MAKEFILE_LIST))))tauri-app.xcworkspace" \
122 -scheme tauri-app_tvOS \
123 -destination "generic/platform=tvOS Simulator" \
124 -configuration Debug \
125 build
126
127 # -----------------------------------------------------------------------------
128 # clean — wipe derived data for this workspace
129 # -----------------------------------------------------------------------------
130 .PHONY: clean
131 clean:
132 @echo "▶ Cleaning Xcode derived data …"
133 xcodebuild \
134 -workspace "$(dir $(abspath $(lastword $(MAKEFILE_LIST))))tauri-app.xcworkspace" \
135 -scheme tauri-app_iOS \
136 clean 2>/dev/null || true
137 xcodebuild \
138 -workspace "$(dir $(abspath $(lastword $(MAKEFILE_LIST))))tauri-app.xcworkspace" \
139 -scheme tauri-app_tvOS \
140 clean 2>/dev/null || true
141 @echo "✅ Clean complete."
142
143 # -----------------------------------------------------------------------------
144 # lint — validate Project.swift with tuist
145 # -----------------------------------------------------------------------------
146 .PHONY: lint
147 lint: _require_tuist
148 @echo "▶ tuist lint …"
149 cd "$(dir $(abspath $(lastword $(MAKEFILE_LIST))))" && tuist lint project
150
151 # -----------------------------------------------------------------------------
152 # tauri-init — re-run Tauri's iOS scaffold (regenerates project.yml only)
153 #
154 # This intentionally does NOT call `make generate` automatically because
155 # you may want to inspect what Tauri changed in project.yml before letting
156 # Tuist regenerate the Xcode project. Run `make generate` when ready.
157 # -----------------------------------------------------------------------------
158 .PHONY: tauri-init
159 tauri-init:
160 @echo "▶ cargo tauri ios init …"
161 cd "$(SRC_TAURI)" && cargo tauri ios init
162 @echo ""
163 @echo "⚠️ project.yml has been regenerated by Tauri."
164 @echo " project.yml is intentionally git-ignored — Project.swift is the"
165 @echo " Xcode project source of truth. Run 'make generate' to rebuild"
166 @echo " the Xcode project from Project.swift."
167 @echo ""
168
169 # -----------------------------------------------------------------------------
170 # reset — full nuclear reset: re-scaffold via Tauri, then regenerate via Tuist
171 # -----------------------------------------------------------------------------
172 .PHONY: reset
173 reset: tauri-init generate
174 @echo "✅ Full reset complete."
175
176 # =============================================================================
177 # Private helpers
178 # =============================================================================
179
180 # Check mise is available (used to activate the pinned tuist version)
181 .PHONY: _require_mise
182 _require_mise:
183 @command -v mise >/dev/null 2>&1 || { \
184 echo "❌ mise not found. Install it from https://mise.jdx.dev/"; \
185 exit 1; \
186 }
187
188 # Install the pinned tuist version via mise (reads mise.toml)
189 .PHONY: _tuist_install
190 _tuist_install: _require_mise
191 @echo "▶ Installing tuist (via mise) …"
192 cd "$(dir $(abspath $(lastword $(MAKEFILE_LIST))))" && mise install
193
194 # Check tuist is available after mise activation
195 .PHONY: _require_tuist
196 _require_tuist:
197 @command -v tuist >/dev/null 2>&1 || { \
198 echo "❌ tuist not found."; \
199 echo " Run 'make setup' to install it, or activate mise in your shell:"; \
200 echo " eval \"\$$(mise activate \$$SHELL)\""; \
201 echo " then re-run this target."; \
202 exit 1; \
203 }