@geastack/apple 0.2.18 → 0.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,7 +44,7 @@ resolve_gea_package() {
44
44
  fi
45
45
  done
46
46
  }
47
- GEA_CORE="$(resolve_gea_package @geastack/core)"
47
+ GEA_CORE="${GEA_CORE:-$(resolve_gea_package @geastack/core)}"
48
48
  [ -n "$GEA_CORE" ] && [ -f "$GEA_CORE/package.json" ] || { echo "Cannot resolve @geastack/core from $BUILD_INVOCATION_CWD — add @geastack/apple to the app's dependencies and run 'npm install' there" >&2; exit 1; }
49
49
  GEA_COMPILER="$(resolve_gea_package @geastack/compiler)"
50
50
  [ -n "$GEA_COMPILER" ] && [ -f "$GEA_COMPILER/package.json" ] || { echo "Cannot resolve @geastack/compiler from $BUILD_INVOCATION_CWD — add @geastack/apple to the app's dependencies and run 'npm install' there" >&2; exit 1; }
@@ -87,9 +87,23 @@ export GEA_FW_C_SOURCES="$(gea_fw_c_sources)"
87
87
  export GEA_FW_INCLUDE_DIRS="$(gea_fw_include_flags | sed "s/^-I//")"
88
88
  APP_ID="${1:-bouncing-balls-jsx}"
89
89
  DESTINATION="${2:-simulator}"
90
+ export GEA_APPLE_UIKIT_PLATFORM="${3:-ios}"
91
+ PLATFORM_NAME=iOS
92
+ DEVICE_NAME=iPhone
93
+ SIMULATOR_SDK=iphonesimulator
94
+ DEVICE_SDK=iphoneos
95
+ FONT_WIDTHS=750,828,1125,1170,1290
96
+ if [[ "$GEA_APPLE_UIKIT_PLATFORM" == tvos ]]; then
97
+ PLATFORM_NAME=tvOS
98
+ DEVICE_NAME="Apple TV"
99
+ SIMULATOR_SDK=appletvsimulator
100
+ DEVICE_SDK=appletvos
101
+ FONT_WIDTHS=1920,3840
102
+ fi
90
103
 
91
- if [[ "$DESTINATION" != "simulator" && "$DESTINATION" != "device" ]]; then
92
- echo "usage: targets/ios/build-ios.sh [app-id] [simulator|device]" >&2
104
+ if [[ "$DESTINATION" != "simulator" && "$DESTINATION" != "device" ]] ||
105
+ [[ "$GEA_APPLE_UIKIT_PLATFORM" != ios && "$GEA_APPLE_UIKIT_PLATFORM" != tvos ]]; then
106
+ echo "usage: targets/ios/build-ios.sh [app-id] [simulator|device] [ios|tvos]" >&2
93
107
  exit 2
94
108
  fi
95
109
 
@@ -100,7 +114,7 @@ APP_INFO="$(node "$GEA_CLI" apps inspect "$APP_ID" --format shell)" || {
100
114
 
101
115
  IFS=$'\t' read -r APP_ROOT APP_ENTRY APP_RUNTIME APP_DISPLAY_NAME <<< "$APP_INFO"
102
116
  if [[ "$APP_RUNTIME" != "gea" ]]; then
103
- echo "iOS target only supports runtime=gea apps for now: $APP_ID is runtime=$APP_RUNTIME" >&2
117
+ echo "$PLATFORM_NAME target only supports runtime=gea apps for now: $APP_ID is runtime=$APP_RUNTIME" >&2
104
118
  exit 1
105
119
  fi
106
120
  APP_NAME="$(node -e "
@@ -114,7 +128,7 @@ BUNDLE_ID="${GEA_IOS_BUNDLE_IDENTIFIER:-com.gea.${APP_ID//[^A-Za-z0-9]/-}}"
114
128
  # next install. The invocation directory is the app the CLI resolved, so output
115
129
  # sources, the Xcode project and DerivedData land next to the app's source.
116
130
  # GEA_IOS_OUTPUT_DIR overrides the root for a caller that wants it elsewhere.
117
- IOS_OUTPUT_ROOT="${GEA_IOS_OUTPUT_DIR:-$BUILD_INVOCATION_CWD/dist/ios}"
131
+ IOS_OUTPUT_ROOT="${GEA_IOS_OUTPUT_DIR:-$BUILD_INVOCATION_CWD/dist/$GEA_APPLE_UIKIT_PLATFORM}"
118
132
  case "$IOS_OUTPUT_ROOT" in
119
133
  /*) ;;
120
134
  *) IOS_OUTPUT_ROOT="$(pwd -P)/$IOS_OUTPUT_ROOT" ;;
@@ -129,7 +143,7 @@ mkdir -p "$GENERATED_DIR"
129
143
 
130
144
  build_font_args=(
131
145
  --font-device-pixel-ratio "${GEA_IOS_FONT_DEVICE_PIXEL_RATIOS:-2,3}"
132
- --font-viewport-width "${GEA_IOS_FONT_VIEWPORT_WIDTHS:-750,828,1125,1170,1290}"
146
+ --font-viewport-width "${GEA_IOS_FONT_VIEWPORT_WIDTHS:-$FONT_WIDTHS}"
133
147
  )
134
148
 
135
149
  generate_app() {
@@ -142,7 +156,7 @@ generate_app() {
142
156
  info="$(node "$GEA_CLI" apps inspect "$app_id" --format shell)" || return 1
143
157
  IFS=$'\t' read -r root entry runtime _name <<< "$info"
144
158
  if [[ "$runtime" != "gea" ]]; then
145
- echo "iOS target only supports runtime=gea apps: $app_id is runtime=$runtime" >&2
159
+ echo "$PLATFORM_NAME target only supports runtime=gea apps: $app_id is runtime=$runtime" >&2
146
160
  return 1
147
161
  fi
148
162
  local args=(
@@ -162,7 +176,41 @@ generate_app() {
162
176
  --out-dir "$out_dir"
163
177
  "${build_font_args[@]}"
164
178
  )
165
- local native_plugin="$root/ios/geatsc-native-plugin.mjs"
179
+ local plugin_paths
180
+ local plugin_path
181
+ plugin_paths="$(node "$GEA_CLI" apps inspect "$app_id" --json | node -e '
182
+ const app = JSON.parse(require("node:fs").readFileSync(0, "utf8"));
183
+ for (const plugin of app.compilerPlugins || [])
184
+ console.log(require("node:path").resolve(app.root, plugin));
185
+ ')" || return 1
186
+ while IFS= read -r plugin_path; do
187
+ [[ -z "$plugin_path" ]] || args+=(--extra-geatsc-plugin "$plugin_path")
188
+ done <<< "$plugin_paths"
189
+ # gea.targets.<ios|tvos>.tsconfig: the TypeScript project the compiler reads
190
+ # the program under, as build-windows.mjs passes it. Without it the compiler
191
+ # takes the project nearest the staged entry, and an app that maps modules
192
+ # through `paths` (a three.js app's barrel) is read with those modules untyped.
193
+ local project
194
+ project="$(node "$GEA_CLI" apps inspect "$app_id" --json | node -e '
195
+ const app = JSON.parse(require("node:fs").readFileSync(0, "utf8"));
196
+ const tsconfig = app.targetConfig?.[process.argv[1]]?.tsconfig;
197
+ if (tsconfig) console.log(require("node:path").resolve(app.root, tsconfig));
198
+ ' "$GEA_APPLE_UIKIT_PLATFORM")" || return 1
199
+ [[ -z "$project" ]] || args+=(--project "$project")
200
+ # The compiler plugins this app's packages ship, resolved by `gea build`
201
+ # (src/macos/adapter.mjs) exactly as for macOS -- a three.js app's WebGL
202
+ # lowering arrives this way.
203
+ if [[ -n "${GEA_EXTRA_GEATSC_PLUGINS:-}" ]]; then
204
+ while IFS= read -r plugin_path; do
205
+ [[ -z "$plugin_path" ]] || args+=(--extra-geatsc-plugin "$plugin_path")
206
+ done <<< "${GEA_EXTRA_GEATSC_PLUGINS//:/$'\n'}"
207
+ fi
208
+ # <app>/<ios|tvos>/geatsc-native-plugin.mjs, or the app's own root when the
209
+ # app already is that folder (an app kept under a tvos/ directory).
210
+ local native_plugin="$root/$GEA_APPLE_UIKIT_PLATFORM/geatsc-native-plugin.mjs"
211
+ if [[ ! -f "$native_plugin" && "$(basename "$root")" == "$GEA_APPLE_UIKIT_PLATFORM" ]]; then
212
+ native_plugin="$root/geatsc-native-plugin.mjs"
213
+ fi
166
214
  if [[ -f "$native_plugin" ]]; then
167
215
  args+=(--extra-geatsc-plugin "$native_plugin")
168
216
  fi
@@ -180,12 +228,12 @@ pick_simulator_device() {
180
228
  const input = fs.readFileSync(0, 'utf8');
181
229
  if (!input.trim()) process.exit(0);
182
230
  const data = JSON.parse(input);
183
- const devices = Object.values(data.devices || {}).flat();
184
- const iphones = devices.filter((d) => d.isAvailable && /^iPhone/.test(d.name));
185
- const booted = iphones.find((d) => d.state === 'Booted');
186
- const preferred = booted || iphones[iphones.length - 1];
231
+ const devices = Object.entries(data.devices || {}).filter(([runtime]) => runtime.includes('.' + process.argv[1] + '-')).flatMap(([, list]) => list);
232
+ const matching = devices.filter((d) => d.isAvailable && d.deviceTypeIdentifier?.includes(process.argv[2]));
233
+ const booted = matching.find((d) => d.state === 'Booted');
234
+ const preferred = booted || matching.find((d) => d.deviceTypeIdentifier?.endsWith('-4K')) || matching[matching.length - 1];
187
235
  if (preferred) console.log(preferred.udid);
188
- " <<< "$devices_json"
236
+ " "$PLATFORM_NAME" "${DEVICE_NAME// /-}" <<< "$devices_json"
189
237
  }
190
238
 
191
239
  # Build an xcodebuild -destination string for a simulator UDID using its
@@ -222,9 +270,9 @@ show_simulator_device() {
222
270
  /usr/bin/open -a Simulator --args -CurrentDeviceUDID "$udid"
223
271
  }
224
272
 
225
- pick_ios_device() {
273
+ pick_device() {
226
274
  local output_json
227
- output_json="$(mktemp "${TMPDIR:-/tmp}/gea-ios-devices.XXXXXX.json")"
275
+ output_json="$(mktemp "${TMPDIR:-/tmp}/gea-ios-devices.XXXXXX")"
228
276
  if ! xcrun devicectl list devices --timeout "${GEA_IOS_DEVICECTL_TIMEOUT:-30}" --json-output "$output_json" >/dev/null; then
229
277
  rm -f "$output_json"
230
278
  return 0
@@ -235,24 +283,33 @@ pick_ios_device() {
235
283
  const devices = data.result?.devices || [];
236
284
  const usable = devices.filter((device) => {
237
285
  const hardware = device.hardwareProperties || {};
286
+ const connection = device.connectionProperties || {};
287
+ if (process.argv[2] === 'tvOS') {
288
+ return hardware.platform === 'tvOS' &&
289
+ hardware.reality !== 'simulated' &&
290
+ connection.pairingState === 'paired';
291
+ }
238
292
  const props = device.deviceProperties || {};
239
293
  const capabilities = device.capabilities || [];
240
294
  const features = new Set(capabilities.map((capability) => capability.featureIdentifier));
241
- return hardware.platform === 'iOS' &&
295
+ return hardware.platform === process.argv[2] &&
242
296
  hardware.deviceType === 'iPhone' &&
243
297
  props.developerModeStatus === 'enabled' &&
244
- device.connectionProperties?.tunnelState === 'connected' &&
298
+ connection.tunnelState === 'connected' &&
245
299
  features.has('com.apple.coredevice.feature.installapp') &&
246
300
  features.has('com.apple.coredevice.feature.launchapplication');
247
301
  });
248
302
  usable.sort((a, b) => {
303
+ const aConnected = a.connectionProperties?.tunnelState === 'connected';
304
+ const bConnected = b.connectionProperties?.tunnelState === 'connected';
305
+ if (aConnected !== bConnected) return Number(aConnected) - Number(bConnected);
249
306
  const aDate = Date.parse(a.connectionProperties?.lastConnectionDate || '') || 0;
250
307
  const bDate = Date.parse(b.connectionProperties?.lastConnectionDate || '') || 0;
251
308
  return aDate - bDate;
252
309
  });
253
310
  const picked = usable[usable.length - 1];
254
311
  if (picked) console.log(picked.identifier || picked.hardwareProperties?.udid || picked.deviceProperties?.name || '');
255
- " "$output_json"
312
+ " "$output_json" "$PLATFORM_NAME"
256
313
  rm -f "$output_json"
257
314
  }
258
315
 
@@ -269,44 +326,43 @@ GEA_CLI_BIN="$GEA_CLI" node "$IOS_DIR/generate-xcode-project.mjs" \
269
326
  --generated-dir "$GENERATED_DIR" \
270
327
  --project-path "$PROJECT_PATH"
271
328
 
272
- SDK="iphonesimulator"
329
+ SDK="$SIMULATOR_SDK"
273
330
  SIMULATOR_DEVICE_ID="${GEA_IOS_SIMULATOR_UDID:-}"
274
- XCODE_DESTINATION="${GEA_IOS_SIMULATOR_DESTINATION:-generic/platform=iOS Simulator}"
275
- if [[ "$DESTINATION" == "simulator" ]]; then
276
- if [[ "$SKIP_LAUNCH" == "1" ]]; then
277
- XCODE_DESTINATION="${GEA_IOS_SIMULATOR_DESTINATION:-generic/platform=iOS Simulator}"
278
- else
279
- if [[ -z "$SIMULATOR_DEVICE_ID" ]]; then
280
- SIMULATOR_DEVICE_ID="$(pick_simulator_device)"
281
- fi
282
- if [[ -z "$SIMULATOR_DEVICE_ID" ]]; then
283
- echo "No available iPhone simulator found." >&2
284
- exit 1
285
- fi
286
- # Resolve a name+OS destination (robust against the poisoned enumeration that
287
- # a connected real iPhone causes); fall back to id= if the lookup fails.
288
- XCODE_DESTINATION="${GEA_IOS_SIMULATOR_DESTINATION:-}"
289
- if [[ -z "$XCODE_DESTINATION" ]]; then
290
- XCODE_DESTINATION="$(sim_destination_for_udid "$SIMULATOR_DEVICE_ID")"
291
- [[ -z "$XCODE_DESTINATION" ]] && XCODE_DESTINATION="platform=iOS Simulator,id=$SIMULATOR_DEVICE_ID"
292
- fi
331
+ XCODE_DESTINATION="${GEA_IOS_SIMULATOR_DESTINATION:-generic/platform=$PLATFORM_NAME Simulator}"
332
+ if [[ "$DESTINATION" == "simulator" && "$SKIP_LAUNCH" != "1" ]]; then
333
+ if [[ -z "$SIMULATOR_DEVICE_ID" ]]; then
334
+ SIMULATOR_DEVICE_ID="$(pick_simulator_device)"
335
+ fi
336
+ if [[ -z "$SIMULATOR_DEVICE_ID" ]]; then
337
+ echo "No available $DEVICE_NAME simulator found." >&2
338
+ exit 1
339
+ fi
340
+ XCODE_DESTINATION="${GEA_IOS_SIMULATOR_DESTINATION:-}"
341
+ if [[ -z "$XCODE_DESTINATION" && "$GEA_APPLE_UIKIT_PLATFORM" == ios ]]; then
342
+ XCODE_DESTINATION="$(sim_destination_for_udid "$SIMULATOR_DEVICE_ID")"
343
+ fi
344
+ if [[ -z "$XCODE_DESTINATION" ]]; then
345
+ XCODE_DESTINATION="platform=$PLATFORM_NAME Simulator,id=$SIMULATOR_DEVICE_ID"
293
346
  fi
294
347
  fi
295
348
  EXTRA_BUILD_SETTINGS=()
296
349
  EXTRA_XCODEBUILD_ARGS=()
297
350
  IOS_DEVICE_ID="${GEA_IOS_DEVICE_ID:-}"
298
351
  if [[ "$DESTINATION" == "device" ]]; then
299
- SDK="iphoneos"
300
- XCODE_DESTINATION="${GEA_IOS_DEVICE_DESTINATION:-generic/platform=iOS}"
352
+ SDK="$DEVICE_SDK"
353
+ XCODE_DESTINATION="${GEA_IOS_DEVICE_DESTINATION:-generic/platform=$PLATFORM_NAME}"
301
354
  if [[ -z "$IOS_DEVICE_ID" && "$SKIP_LAUNCH" != "1" ]]; then
302
- IOS_DEVICE_ID="$(pick_ios_device)"
355
+ IOS_DEVICE_ID="$(pick_device)"
303
356
  if [[ -n "$IOS_DEVICE_ID" ]]; then
304
- echo "Using iOS device $IOS_DEVICE_ID. Override with GEA_IOS_DEVICE_ID." >&2
357
+ echo "Using $PLATFORM_NAME device $IOS_DEVICE_ID. Override with GEA_IOS_DEVICE_ID." >&2
305
358
  fi
306
359
  fi
307
360
  if [[ -z "$IOS_DEVICE_ID" && "$SKIP_LAUNCH" != "1" ]]; then
308
- echo "No available iPhone device found for install or launch." >&2
309
- echo "Connect an iPhone with Developer Mode enabled, or set GEA_IOS_DEVICE_ID." >&2
361
+ echo "No available $DEVICE_NAME device found for install or launch." >&2
362
+ echo "Pair your $DEVICE_NAME with Xcode, or set GEA_IOS_DEVICE_ID." >&2
363
+ if [[ "$GEA_APPLE_UIKIT_PLATFORM" == ios ]]; then
364
+ echo "Enable Developer Mode on the iPhone before launching." >&2
365
+ fi
310
366
  exit 1
311
367
  fi
312
368
  DEVELOPMENT_TEAM="${GEA_IOS_DEVELOPMENT_TEAM:-}"
@@ -321,15 +377,26 @@ if [[ "$DESTINATION" == "device" ]]; then
321
377
  if [[ "$SKIP_LAUNCH" != "1" ]]; then
322
378
  echo "Device builds require GEA_IOS_DEVELOPMENT_TEAM for Xcode automatic signing." >&2
323
379
  echo "The script also checks Xcode preferences and installed provisioning profiles, but no unambiguous team was found." >&2
324
- echo "Example: GEA_IOS_DEVELOPMENT_TEAM=ABCDE12345 targets/ios/build-ios.sh $APP_ID device" >&2
380
+ echo "Example: GEA_IOS_DEVELOPMENT_TEAM=ABCDE12345 gea run --target $GEA_APPLE_UIKIT_PLATFORM --mode device --app $APP_ID" >&2
325
381
  exit 1
326
382
  fi
327
- echo "GEA_IOS_DEVELOPMENT_TEAM is not set; building an unsigned iphoneos binary." >&2
328
- echo "Set GEA_IOS_DEVELOPMENT_TEAM to install or launch on an iPhone." >&2
383
+ echo "GEA_IOS_DEVELOPMENT_TEAM is not set; building an unsigned $DEVICE_SDK binary." >&2
384
+ echo "Set GEA_IOS_DEVELOPMENT_TEAM to install or launch on your $DEVICE_NAME." >&2
329
385
  EXTRA_BUILD_SETTINGS+=("CODE_SIGNING_ALLOWED=NO")
330
386
  EXTRA_BUILD_SETTINGS+=("CODE_SIGNING_REQUIRED=NO")
331
387
  EXTRA_BUILD_SETTINGS+=("CODE_SIGN_IDENTITY=")
332
388
  else
389
+ if [[ "$GEA_APPLE_UIKIT_PLATFORM" == tvos && -n "$IOS_DEVICE_ID" && -z "${GEA_IOS_DEVICE_DESTINATION:-}" ]]; then
390
+ DEVICE_UDID="$(xcrun devicectl device info details --device "$IOS_DEVICE_ID" \
391
+ --quiet --timeout "${GEA_IOS_DEVICECTL_TIMEOUT:-30}" --json-output /dev/stdout | node -e '
392
+ const device = JSON.parse(require("node:fs").readFileSync(0, "utf8")).result;
393
+ if (device.hardwareProperties?.platform !== "tvOS" || device.hardwareProperties.reality === "simulated") {
394
+ throw new Error("Select a physical Apple TV with GEA_IOS_DEVICE_ID.");
395
+ }
396
+ process.stdout.write(device.hardwareProperties.udid);
397
+ ')"
398
+ XCODE_DESTINATION="platform=tvOS,id=$DEVICE_UDID"
399
+ fi
333
400
  EXTRA_BUILD_SETTINGS+=("DEVELOPMENT_TEAM=$DEVELOPMENT_TEAM")
334
401
  EXTRA_BUILD_SETTINGS+=("CODE_SIGN_STYLE=Automatic")
335
402
  ALLOW_PROVISIONING_UPDATES="${GEA_IOS_ALLOW_PROVISIONING_UPDATES:-}"
@@ -337,9 +404,12 @@ if [[ "$DESTINATION" == "device" ]]; then
337
404
  ALLOW_PROVISIONING_UPDATES="1"
338
405
  fi
339
406
  if [[ "$ALLOW_PROVISIONING_UPDATES" == "1" ]]; then
340
- echo "Allowing Xcode to create or update iOS provisioning profiles." >&2
407
+ echo "Allowing Xcode to create or update $PLATFORM_NAME provisioning profiles." >&2
341
408
  echo "Set GEA_IOS_ALLOW_PROVISIONING_UPDATES=0 to disable this." >&2
342
409
  EXTRA_XCODEBUILD_ARGS+=("-allowProvisioningUpdates")
410
+ if [[ "$GEA_APPLE_UIKIT_PLATFORM" == tvos && "$XCODE_DESTINATION" != generic/* ]]; then
411
+ EXTRA_XCODEBUILD_ARGS+=("-allowProvisioningDeviceRegistration")
412
+ fi
343
413
  fi
344
414
  fi
345
415
  fi
@@ -348,7 +418,7 @@ fi
348
418
  # real iPhone lacks its device-support platform — even an explicit simulator
349
419
  # destination then fails to match. Retry on that specific flake (re-settling the
350
420
  # sim first); any other failure breaks out immediately.
351
- XCODEBUILD_LOG="$(mktemp "${TMPDIR:-/tmp}/gea-ios-xcodebuild.XXXXXX.log")"
421
+ XCODEBUILD_LOG="$(mktemp "${TMPDIR:-/tmp}/gea-ios-xcodebuild.XXXXXX")"
352
422
  XCODEBUILD_ATTEMPTS="${GEA_IOS_BUILD_ATTEMPTS:-3}"
353
423
  xcodebuild_status=1
354
424
  for ((xcodebuild_attempt = 1; xcodebuild_attempt <= XCODEBUILD_ATTEMPTS; xcodebuild_attempt++)); do
@@ -388,7 +458,7 @@ if [[ "$DESTINATION" == "simulator" && "$SKIP_LAUNCH" != "1" ]]; then
388
458
  SIMULATOR_DEVICE_ID="$(pick_simulator_device)"
389
459
  fi
390
460
  if [[ -z "$SIMULATOR_DEVICE_ID" ]]; then
391
- echo "No available iPhone simulator found; build succeeded without launch." >&2
461
+ echo "No available $DEVICE_NAME simulator found; build succeeded without launch." >&2
392
462
  exit 0
393
463
  fi
394
464
  show_simulator_device "$SIMULATOR_DEVICE_ID"
@@ -400,10 +470,10 @@ fi
400
470
 
401
471
  if [[ "$DESTINATION" == "device" && "$SKIP_LAUNCH" != "1" ]]; then
402
472
  if [[ -z "$IOS_DEVICE_ID" ]]; then
403
- IOS_DEVICE_ID="$(pick_ios_device)"
473
+ IOS_DEVICE_ID="$(pick_device)"
404
474
  fi
405
475
  if [[ -z "$IOS_DEVICE_ID" ]]; then
406
- echo "No available iPhone device found; build succeeded without launch." >&2
476
+ echo "No available $DEVICE_NAME device found; build succeeded without launch." >&2
407
477
  exit 0
408
478
  fi
409
479
  xcrun devicectl --timeout "${GEA_IOS_DEVICECTL_TIMEOUT:-60}" device install app --device "$IOS_DEVICE_ID" "$APP_PRODUCT"
@@ -59,14 +59,22 @@ const appIconAssetsDir = path.join(generatedDir, 'Assets.xcassets')
59
59
  // compile a catalog unless an installed simulator runtime's build matches the SDK
60
60
  // exactly (e.g. SDK 23F81a needs a 23F81a runtime, not a 23F73 one) — a skew that
61
61
  // blocks otherwise-fine builds. Skipping it yields an app with the default icon.
62
- const skipAppIcon = process.env.GEA_IOS_SKIP_APP_ICON === '1'
62
+ const tvos = process.env.GEA_APPLE_UIKIT_PLATFORM === 'tvos'
63
+ const buildConfig = process.env.GEA_BUILD_CONFIG_JSON
64
+ ? JSON.parse(fs.readFileSync(process.env.GEA_BUILD_CONFIG_JSON, 'utf8'))
65
+ : {}
66
+ const viewport = buildConfig.settings?.display || {}
67
+ if ((viewport.width === undefined) !== (viewport.height === undefined))
68
+ fail('Set both display.width and display.height for the UIKit rendering resolution.')
69
+
70
+ const skipAppIcon = tvos || process.env.GEA_IOS_SKIP_APP_ICON === '1'
63
71
 
64
72
  fs.rmSync(projectPath, { recursive: true, force: true })
65
73
  fs.mkdirSync(path.join(projectPath, 'project.xcworkspace'), { recursive: true })
66
74
  fs.mkdirSync(path.join(projectPath, 'xcshareddata/xcschemes'), { recursive: true })
67
75
  if (!skipAppIcon) gea(['apps', 'apple-icons', appId, '--platform', 'ios', '--assets-dir', appIconAssetsDir])
68
76
 
69
- const plistTemplate = fs.readFileSync(path.join(iosDir, 'Info.plist.in'), 'utf8')
77
+ const plistTemplate = fs.readFileSync(path.join(iosDir, tvos ? 'Info-tvOS.plist.in' : 'Info.plist.in'), 'utf8')
70
78
  fs.writeFileSync(
71
79
  plistOut,
72
80
  plistTemplate
@@ -118,7 +126,7 @@ function nativeSourceKind(file) {
118
126
  }
119
127
 
120
128
  function findAppNativeSources() {
121
- const dir = path.join(appRoot, 'ios')
129
+ const dir = path.join(appRoot, tvos ? 'tvos' : 'ios')
122
130
  if (!fs.existsSync(dir)) return []
123
131
  const out = []
124
132
  const visit = (current) => {
@@ -157,12 +165,22 @@ const rendererSources = [
157
165
  'renderer/native_scroll_container.mm',
158
166
  'renderer/view_reconciler.mm',
159
167
  ].map((file) => source(path.join(iosDir, 'main', file), 'sourcecode.cpp.objcpp'))
160
- const appNativeSources = findAppNativeSources()
168
+ // gea.targets.<ios|tvos>: per-target native sources, static archives, system
169
+ // frameworks and include directories (validated by the CLI's nativeLink), and
170
+ // resource directories staged into the app bundle (nativeResources).
171
+ const uikitTarget = tvos ? 'tvos' : 'ios'
172
+ const appNativeLink = appMeta.nativeLink?.[uikitTarget] || {}
173
+ const appNativeSources = [...new Map([
174
+ ...findAppNativeSources(),
175
+ ...(appMeta.nativeSourcePaths || []).map((file) => source(file, nativeSourceKind(file))),
176
+ ...(appMeta.targetNativeSourcePaths?.[uikitTarget] || []).map((file) => source(file, nativeSourceKind(file))),
177
+ ].map((entry) => [entry.file, entry])).values()]
161
178
  const sources = [
162
179
  source(path.join(iosDir, 'main/ios_main.mm'), 'sourcecode.cpp.objcpp'),
163
180
  source(path.join(iosDir, 'main/ios_root_background.cpp')),
164
181
  ...rendererSources,
165
182
  source(path.join(iosDir, 'main/canvas_view.mm'), 'sourcecode.cpp.objcpp'),
183
+ source(path.join(iosDir, 'main/uikit_host.mm'), 'sourcecode.cpp.objcpp'),
166
184
  source(path.join(iosDir, 'main/color_convert.mm'), 'sourcecode.cpp.objcpp'),
167
185
  source(path.join(iosDir, 'main/image_bridge.mm'), 'sourcecode.cpp.objcpp'),
168
186
  source(path.join(iosDir, 'main/font_registry.mm'), 'sourcecode.cpp.objcpp'),
@@ -197,10 +215,16 @@ if (existing(assetsGenerated)) sources.push(assetsGenerated)
197
215
  const hasGeneratedFonts = sources.some((entry) => path.basename(entry.file) === 'gea_embedded_font_generated.cpp')
198
216
 
199
217
  const fontResources = findFontResources().map((file) => resource(file))
218
+ // Each nativeResources destination becomes a folder of the same name in the
219
+ // bundle: stage them under the generated directory, then reference the folders.
220
+ const nativeResourceDir = path.join(generatedDir, 'native-resources')
221
+ const nativeResourceNames = Object.keys(appMeta.nativeResources?.[uikitTarget] || {})
222
+ if (nativeResourceNames.length) gea(['apps', 'sync-native-resources', appId, '--target', uikitTarget, '--output', nativeResourceDir])
223
+ const folderResources = nativeResourceNames.map((name) => resource(path.join(nativeResourceDir, name), 'folder'))
200
224
  const appIconAssets = resource(appIconAssetsDir, 'folder.assetcatalog')
201
225
  const appIconResources = skipAppIcon ? [] : [appIconAssets]
202
226
  const uiTestSource = source(path.join(iosDir, 'test/GeaIosRubberBandUITests.swift'), 'sourcecode.swift')
203
- const uiTestSources = existing(uiTestSource) ? [uiTestSource] : []
227
+ const uiTestSources = tvos ? [] : existing(uiTestSource) ? [uiTestSource] : []
204
228
  const hasUiTests = uiTestSources.length > 0
205
229
 
206
230
  const frameworks = [
@@ -208,20 +232,25 @@ const frameworks = [
208
232
  'QuartzCore.framework',
209
233
  'CoreGraphics.framework',
210
234
  'CoreText.framework',
211
- 'CoreMotion.framework',
235
+ tvos ? 'GameController.framework' : 'CoreMotion.framework',
212
236
  'CoreLocation.framework',
213
237
  'CoreMedia.framework',
214
238
  'CoreVideo.framework',
239
+ 'IOSurface.framework',
215
240
  'ImageIO.framework',
216
241
  'MapKit.framework',
217
242
  'AVFoundation.framework',
218
243
  'Photos.framework',
219
244
  'Security.framework',
220
245
  'UserNotifications.framework',
246
+ ...(!tvos ? ['EventKit.framework'] : []),
221
247
  'Metal.framework',
222
248
  'MetalKit.framework',
223
249
  'Foundation.framework',
224
250
  ]
251
+ for (const name of appNativeLink.frameworks || []) {
252
+ if (!frameworks.includes(`${name}.framework`)) frameworks.push(`${name}.framework`)
253
+ }
225
254
 
226
255
  const productId = id('product')
227
256
  const targetId = id('target')
@@ -265,6 +294,12 @@ for (const r of fontResources) {
265
294
  buildFiles.push(`${id(`build:${label}`)} /* ${path.basename(r.file)} in Resources */ = {isa = PBXBuildFile; fileRef = ${id(`file:${label}`)} /* ${path.basename(r.file)} */; };`)
266
295
  }
267
296
 
297
+ for (const r of folderResources) {
298
+ const label = rel(r.file)
299
+ fileRefs.push(`${id(`file:${label}`)} /* ${path.basename(r.file)} */ = {isa = PBXFileReference; lastKnownFileType = folder; path = ${q(r.file)}; sourceTree = "<absolute>"; };`)
300
+ buildFiles.push(`${id(`build:${label}`)} /* ${path.basename(r.file)} in Resources */ = {isa = PBXBuildFile; fileRef = ${id(`file:${label}`)} /* ${path.basename(r.file)} */; };`)
301
+ }
302
+
268
303
  for (const a of appIconResources) {
269
304
  const label = rel(a.file)
270
305
  fileRefs.push(`${id(`file:${label}`)} /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = ${a.kind}; path = ${q(a.file)}; sourceTree = "<absolute>"; };`)
@@ -293,7 +328,9 @@ const uiTestProductRef = hasUiTests
293
328
  const includePaths = [
294
329
  path.join(iosDir, 'main'),
295
330
  generatedDir,
296
- path.join(appRoot, 'ios'),
331
+ path.join(appRoot, tvos ? 'tvos' : 'ios'),
332
+ ...new Set(appNativeSources.map(({ file }) => path.dirname(file))),
333
+ ...(appNativeLink.nativeIncludeDirectories || []),
297
334
  // Framework include roots (core/host/engine includes + vendor/stb + AnimatedGIF)
298
335
  // from the shared manifest gea_sources.sh, passed by build-ios.sh via env.
299
336
  ...(process.env.GEA_FW_INCLUDE_DIRS || '').split('\n').filter(Boolean),
@@ -306,6 +343,10 @@ const includePaths = [
306
343
  function buildSettings(configuration) {
307
344
  const preprocessorDefinitions = [
308
345
  'GEA_EMBEDDED_GIF_C_API=1',
346
+ ...(viewport.width === undefined ? [] : [
347
+ `GEA_UIKIT_VIEWPORT_WIDTH=${viewport.width}`,
348
+ `GEA_UIKIT_VIEWPORT_HEIGHT=${viewport.height}`,
349
+ ]),
309
350
  'GEA_EMBEDDED_ENABLE_NATIVE_TEXT_INPUT=1',
310
351
  'GEA_EMBEDDED_ENABLE_VIRTUAL_KEYBOARD=0',
311
352
  'GEA_CPP_USE_TO_CHARS_DOUBLE=0',
@@ -317,6 +358,8 @@ function buildSettings(configuration) {
317
358
  // native pixel with no runtime format branch and no colour conversion.
318
359
  'GEA_EMBEDDED_PIXEL_FORMAT=1',
319
360
  ...(hasGeneratedFonts ? ['GEA_EMBEDDED_HAS_GENERATED_FONTS=1'] : []),
361
+ // gea.defines and the resolved build settings' macros.
362
+ ...(buildConfig.defines || []),
320
363
  ]
321
364
  return `{
322
365
  ALWAYS_SEARCH_USER_PATHS = NO;${skipAppIcon ? '' : `
@@ -332,16 +375,16 @@ function buildSettings(configuration) {
332
375
  GCC_PREPROCESSOR_DEFINITIONS = (${preprocessorDefinitions.map(q).join(', ')});
333
376
  HEADER_SEARCH_PATHS = (${includePaths.map(q).join(', ')});
334
377
  INFOPLIST_FILE = ${q(plistOut)};
335
- IPHONEOS_DEPLOYMENT_TARGET = 16.0;
378
+ ${tvos ? 'TVOS_DEPLOYMENT_TARGET = 17.0;' : 'IPHONEOS_DEPLOYMENT_TARGET = 16.0;'}
336
379
  LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
337
380
  ONLY_ACTIVE_ARCH = ${configuration === 'Debug' ? 'YES' : 'NO'};
338
- OTHER_LDFLAGS = ("$(inherited)", "-Wl,-no_deduplicate");
381
+ OTHER_LDFLAGS = (${['$(inherited)', '-Wl,-no_deduplicate', ...(appNativeLink.nativeLibraries || [])].map(q).join(', ')});
339
382
  PRODUCT_BUNDLE_IDENTIFIER = ${q(bundleId)};
340
383
  PRODUCT_NAME = ${q(appName)};
341
- SDKROOT = iphoneos;
342
- SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
384
+ SDKROOT = ${tvos ? 'appletvos' : 'iphoneos'};
385
+ SUPPORTED_PLATFORMS = "${tvos ? 'appletvos appletvsimulator' : 'iphoneos iphonesimulator'}";
343
386
  SUPPORTS_MACCATALYST = NO;
344
- TARGETED_DEVICE_FAMILY = "1,2";
387
+ TARGETED_DEVICE_FAMILY = "${tvos ? '3' : '1,2'}";
345
388
  }`
346
389
  }
347
390
 
@@ -370,6 +413,7 @@ const sourceChildren = sources.map((s) => `${id(`file:${rel(s.file)}`)} /* ${pat
370
413
  const uiTestSourceChildren = uiTestSources.map((s) => `${id(`file:${rel(s.file)}`)} /* ${path.basename(s.file)} */`)
371
414
  const resourceChildren = [
372
415
  ...fontResources.map((r) => `${id(`file:${rel(r.file)}`)} /* ${path.basename(r.file)} */`),
416
+ ...folderResources.map((r) => `${id(`file:${rel(r.file)}`)} /* ${path.basename(r.file)} */`),
373
417
  ...appIconResources.map((a) => `${id(`file:${rel(a.file)}`)} /* Assets.xcassets */`),
374
418
  ]
375
419
  const frameworkChildren = frameworks.map((fw) => `${id(`file:${fw}`)} /* ${fw} */`)
@@ -385,6 +429,7 @@ const sourceBuildRefs = sources.map((s) => `${id(`build:${rel(s.file)}`)} /* ${p
385
429
  const uiTestSourceBuildRefs = uiTestSources.map((s) => `${id(`build:${rel(s.file)}`)} /* ${path.basename(s.file)} in Sources */`)
386
430
  const resourceBuildRefs = [
387
431
  ...fontResources.map((r) => `${id(`build:${rel(r.file)}`)} /* ${path.basename(r.file)} in Resources */`),
432
+ ...folderResources.map((r) => `${id(`build:${rel(r.file)}`)} /* ${path.basename(r.file)} in Resources */`),
388
433
  ...appIconResources.map((a) => `${id(`build:${rel(a.file)}`)} /* Assets.xcassets in Resources */`),
389
434
  ]
390
435
  const frameworkBuildRefs = frameworks.map((fw) => `${id(`build:${fw}`)} /* ${fw} in Frameworks */`)
@@ -4,4 +4,6 @@
4
4
 
5
5
  @interface GeaCanvasView : UIView
6
6
  @property(nonatomic, assign) int nodeId;
7
+ // Shows the canvas node's current pixels.
8
+ - (void)present;
7
9
  @end