@geastack/apple 0.2.24 → 0.2.26

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/apple",
3
- "version": "0.2.24",
3
+ "version": "0.2.26",
4
4
  "description": "Generated Apple SDK bindings plus the macOS, iOS and tvOS native build targets for Gea apps.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -119,7 +119,9 @@ function buildOutputs(root, manifest, platform, build, where, log) {
119
119
  if (outputs.some((file) => !fs.existsSync(file))) {
120
120
  log(`[gea] building ${libraries.join(', ')} for ${platform} from ${manifest.name} (once; cached in ${out})`)
121
121
  const runner = /\.sh$/.test(script) ? ['bash', [script, ...command.slice(1), '--out', out]] : [script, [...command.slice(1), '--out', out]]
122
- execFileSync(runner[0], runner[1], { cwd: root, stdio: ['ignore', 'inherit', 'inherit'] })
122
+ // The build's own output goes to stderr: callers read this module's answer
123
+ // from stdout.
124
+ execFileSync(runner[0], runner[1], { cwd: root, stdio: ['ignore', 2, 'inherit'] })
123
125
  for (const file of outputs) mustExist(file, `${where} (after ${command[0]})`)
124
126
  }
125
127
  return {
@@ -590,6 +590,18 @@ generate_app() {
590
590
  done
591
591
  (( alreadySelected != 0 )) || extraArgs+=(--extra-geatsc-plugin "$declaredPluginPath")
592
592
  done < <(node -e 'for(const p of JSON.parse(process.argv[1]).paths)console.log(p)' "$declaredAppPlugins")
593
+ # gea.targets.macos.tsconfig: the TypeScript project the compiler reads the
594
+ # program under, as build-ios.sh passes it. Without it the compiler takes the
595
+ # project nearest the staged entry, and an app that maps modules through
596
+ # `paths` (a three.js app's barrel) is read with those modules untyped -- an
597
+ # analysis that outgrows the compiler's heap.
598
+ local declaredProject
599
+ declaredProject="$(node -e '
600
+ const app = JSON.parse(process.argv[1]);
601
+ const tsconfig = app.targetConfig?.macos?.tsconfig;
602
+ if (tsconfig) console.log(require("node:path").resolve(app.root, tsconfig));
603
+ ' "$declaredAppMetadata")" || return 1
604
+ [[ -z "$declaredProject" ]] || extraArgs+=(--project "$declaredProject")
593
605
  if [[ "$appRuntime" == "apple-native" ]]; then
594
606
  extraArgs+=(--apple-native)
595
607
  fi
@@ -1074,6 +1086,7 @@ MM_SOURCES=(
1074
1086
  # gea::platform::audio — the AVAudioEngine backend, shared verbatim with iOS.
1075
1087
  "$ROOT_DIR/targets/shared/apple_audio.mm"
1076
1088
  "$ROOT_DIR/targets/macos/main/macos_main.mm"
1089
+ "$ROOT_DIR/targets/macos/main/appkit_host.mm"
1077
1090
  "$ROOT_DIR/targets/macos/main/macos_native_shell.mm"
1078
1091
  "$ROOT_DIR/targets/macos/main/macos_display.mm"
1079
1092
  "$ROOT_DIR/targets/macos/main/macos_timers.mm"
@@ -2196,6 +2209,31 @@ if [[ "$APP_ID" == "gea-companion" ]]; then
2196
2209
  if replace_content_stable "$COMPANION_TOOLS_DIR/$(basename "$d")" "$RESOURCE_TMP"; then BUNDLE_CONTENT_CHANGED=1; fi
2197
2210
  done
2198
2211
  fi
2212
+
2213
+ # Libraries the program's packages build for macOS (gea-native.json "macos"
2214
+ # "build", e.g. native-webgl-angle's ANGLE built from WebKit's sources, once and
2215
+ # cached): a dynamic library goes into Contents/Frameworks, where the package's
2216
+ # host loads it, and its notices into Resources.
2217
+ if [[ -n "$SINGLE_APP_DIR" ]]; then
2218
+ PACKAGE_BUILDS="$(node --input-type=module -e "
2219
+ import { readUikitNativePackages } from '$ROOT_DIR/targets/ios/native-packages.mjs'
2220
+ import fs from 'node:fs'
2221
+ const graph = process.argv[2]
2222
+ const found = readUikitNativePackages({ appRoot: process.argv[1], moduleGraphPath: fs.existsSync(graph) ? graph : undefined, target: 'macos' })
2223
+ for (const file of found.libraries) if (file.endsWith('.dylib')) console.log('lib ' + file)
2224
+ for (const file of found.resources) console.log('res ' + file)
2225
+ " "$SINGLE_APP_DIR" "$GENERATED_DIR/module-graph/gea-module-graph.json")" || { echo "Package native builds failed for '$APP_ID'" >&2; exit 1; }
2226
+ while IFS= read -r line; do
2227
+ [[ -n "$line" ]] || continue
2228
+ kind="${line%% *}"; file="${line#* }"
2229
+ if [[ "$kind" == lib ]]; then dest="$APP_BUNDLE/Contents/Frameworks/$(basename "$file")"; else dest="$RES_DIR/$(basename "$file")"; fi
2230
+ mkdir -p "$(dirname "$dest")"
2231
+ if [[ ! -f "$dest" ]] || ! cmp -s "$file" "$dest"; then
2232
+ cp "$file" "$dest"
2233
+ BUNDLE_CONTENT_CHANGED=1
2234
+ fi
2235
+ done <<< "$PACKAGE_BUILDS"
2236
+ fi
2199
2237
  timing_mark resources
2200
2238
 
2201
2239
  # Ad-hoc sign only after an input changed. The completion stamp is deliberately
@@ -0,0 +1,43 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Host extensions: native code a package (or an app) compiles into a macOS
3
+ // build to own part of the window -- typically a rendering surface such as a
4
+ // CAMetalLayer that a GL or GPU layer presents into, which the generated
5
+ // program draws through. The AppKit counterpart of gea_uikit_host.h, so a
6
+ // program that runs on tvOS runs unchanged on macOS.
7
+ //
8
+ // An extension registers itself from a static initializer:
9
+ //
10
+ // static const gea_appkit_host_extension kSurface = {
11
+ // GEA_APPKIT_HOST_EXTENSION_VERSION, "my-surface", attach, layout };
12
+ // static const bool kRegistered = (gea_appkit_register_host_extension(&kSurface), true);
13
+ //
14
+ // Every callback may be null. Sizes are in points; `scale` is device pixels
15
+ // per point.
16
+ #pragma once
17
+
18
+ #ifdef __cplusplus
19
+ extern "C" {
20
+ #endif
21
+
22
+ #define GEA_APPKIT_HOST_EXTENSION_VERSION 1u
23
+
24
+ typedef struct gea_appkit_host_extension {
25
+ unsigned version; // GEA_APPKIT_HOST_EXTENSION_VERSION
26
+ const char *name; // for diagnostics
27
+ // Once, after the window's root view exists and before the app's top level
28
+ // runs. `rootView` is the root NSView (a bridged NSView *): an extension adds
29
+ // its own subviews to it. Returning zero logs an error naming the extension.
30
+ int (*attach)(void *rootView, double width, double height, double scale);
31
+ // The root view's size or scale changed.
32
+ void (*layout)(double width, double height, double scale);
33
+ } gea_appkit_host_extension;
34
+
35
+ void gea_appkit_register_host_extension(const gea_appkit_host_extension *extension);
36
+
37
+ // Called by the target (macos_main.mm).
38
+ void gea_appkit_host_attach(void *rootView, double width, double height, double scale);
39
+ void gea_appkit_host_layout(double width, double height, double scale);
40
+
41
+ #ifdef __cplusplus
42
+ }
43
+ #endif
@@ -0,0 +1,43 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // The registry and life-cycle calls of macOS host extensions (gea_appkit_host.h).
3
+ #include "gea_appkit_host.h"
4
+
5
+ #include <cstdio>
6
+
7
+ namespace {
8
+
9
+ constexpr int kMaxExtensions = 8;
10
+ const gea_appkit_host_extension *gExtensions[kMaxExtensions];
11
+ int gExtensionCount = 0;
12
+
13
+ } // namespace
14
+
15
+ extern "C" void gea_appkit_register_host_extension(const gea_appkit_host_extension *extension)
16
+ {
17
+ if (!extension || extension->version != GEA_APPKIT_HOST_EXTENSION_VERSION) {
18
+ std::fprintf(stderr, "[gea] host extension %s has an unsupported version\n", extension && extension->name ? extension->name : "?");
19
+ return;
20
+ }
21
+ if (gExtensionCount >= kMaxExtensions) {
22
+ std::fprintf(stderr, "[gea] too many host extensions; %s ignored\n", extension->name ? extension->name : "?");
23
+ return;
24
+ }
25
+ gExtensions[gExtensionCount++] = extension;
26
+ }
27
+
28
+ extern "C" void gea_appkit_host_attach(void *rootView, double width, double height, double scale)
29
+ {
30
+ for (int i = 0; i < gExtensionCount; ++i) {
31
+ const auto *extension = gExtensions[i];
32
+ if (extension->attach && !extension->attach(rootView, width, height, scale)) {
33
+ std::fprintf(stderr, "[gea] host extension %s failed to attach\n", extension->name ? extension->name : "?");
34
+ }
35
+ }
36
+ }
37
+
38
+ extern "C" void gea_appkit_host_layout(double width, double height, double scale)
39
+ {
40
+ for (int i = 0; i < gExtensionCount; ++i) {
41
+ if (gExtensions[i]->layout) gExtensions[i]->layout(width, height, scale);
42
+ }
43
+ }
@@ -64,6 +64,7 @@ namespace gea::macos { void installWifiDriver(); int nodeIdForView(NSView *view)
64
64
  #include <cstdio>
65
65
  #include <cstdlib>
66
66
  #include <cstring>
67
+ #include "gea_appkit_host.h"
67
68
 
68
69
  extern "C" int gea_embedded_now_ms(void);
69
70
  // Headless text-input driver used by GEA_MACOS_SYNTH_INPUT (press_bridge.mm).
@@ -534,6 +535,10 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
534
535
  if (gea::macos::thermalright::enabled()) {
535
536
  size = NSMakeSize(gea::platform::display::kWidth, gea::platform::display::kHeight);
536
537
  }
538
+ // Host extensions (a package's rendering surface) attach before the
539
+ // program's top level runs, as on iOS and tvOS.
540
+ gea_appkit_host_attach((__bridge void *)self.rootView, size.width, size.height,
541
+ self.window.backingScaleFactor > 0 ? self.window.backingScaleFactor : 1.0);
537
542
  gea_macos_smoke_log("[gea-macos] before Application::init");
538
543
  gea::framework::app::Application::init(static_cast<int>(size.width), static_cast<int>(size.height));
539
544
  gea_macos_smoke_log("[gea-macos] after Application::init");