serve-sim 0.1.44-beta.98.1 → 0.1.44

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.swift CHANGED
@@ -23,7 +23,7 @@ let package = Package(
23
23
  .library(
24
24
  name: "serve-sim-native",
25
25
  type: .dynamic,
26
- targets: ["SimNativeModule"]
26
+ targets: ["SimNative"]
27
27
  ),
28
28
  ],
29
29
  dependencies: [
@@ -31,40 +31,19 @@ let package = Package(
31
31
  ],
32
32
  targets: [
33
33
  .target(
34
- name: "SimNativeModule",
34
+ name: "SimNative",
35
35
  dependencies: [
36
36
  .product(name: "NodeAPI", package: "node-swift"),
37
37
  .product(name: "NodeModuleSupport", package: "node-swift"),
38
38
  ],
39
- path: "Sources",
40
- // Sibling targets built by their own build.sh (Obj-C/ObjC++), not
41
- // part of this SwiftPM package.
42
39
  exclude: [
43
- "SimCameraInjector",
44
- "SimCameraHelper",
45
- "SimAXSettings",
46
- "SimNative/build.sh",
47
- ],
48
- sources: [
49
- "SimNative/sim-module.swift",
50
- "SimNative/sim-capture.swift",
51
- "SimStreamHelper/HIDInjector.swift",
52
- "SimStreamHelper/FrameCapture.swift",
53
- "SimStreamHelper/VideoEncoder.swift",
54
- "SimStreamHelper/H264Encoder.swift",
55
- "SimStreamHelper/StreamFormat.swift",
56
- "SimStreamHelper/AccessibilityBridge.swift",
57
- "SimStreamHelper/SimFrameworks.swift",
58
- "SimStreamHelper/Xcode.swift",
40
+ "build.sh",
59
41
  ],
60
42
  linkerSettings: [
61
- .linkedFramework("CoreVideo"),
62
- .linkedFramework("CoreMedia"),
63
- .linkedFramework("IOSurface"),
64
- .linkedFramework("CoreGraphics"),
65
- .linkedFramework("VideoToolbox"),
66
- .linkedFramework("ImageIO"),
67
- .linkedFramework("AppKit"),
43
+ .unsafeFlags([
44
+ "-Xlinker", "-undefined",
45
+ "-Xlinker", "dynamic_lookup",
46
+ ])
68
47
  ]
69
48
  ),
70
49
  ],
@@ -2,6 +2,18 @@ import Foundation
2
2
  import ObjectiveC
3
3
  import Darwin
4
4
 
5
+ /// Per-event HID logging is gated behind `SERVE_SIM_DEBUG_HID`. These lines fire
6
+ /// on every touch/move/button/key/crown event — a single drag emits a dozen —
7
+ /// so by default they flood stdout (and anything mirroring it) for no benefit.
8
+ /// Failure diagnostics ("returned nil", "unavailable", "not found") stay on
9
+ /// `print` so real problems are always visible.
10
+ private let hidDebugEnabled = ProcessInfo.processInfo.environment["SERVE_SIM_DEBUG_HID"] != nil
11
+
12
+ @inline(__always)
13
+ private func hidLog(_ message: @autoclosure () -> String) {
14
+ if hidDebugEnabled { print(message()) }
15
+ }
16
+
5
17
  /// Injects touch, button, and orientation HID events into the iOS Simulator.
6
18
  ///
7
19
  /// Uses IndigoHIDMessageForMouseNSEvent to create touch messages and
@@ -70,28 +82,28 @@ final class HIDInjector {
70
82
 
71
83
  if let buttonPtr = dlsym(UnsafeMutableRawPointer(bitPattern: -2), "IndigoHIDMessageForButton") {
72
84
  self.buttonFunc = unsafeBitCast(buttonPtr, to: IndigoButtonFunc.self)
73
- print("[hid] IndigoHIDMessageForButton loaded")
85
+ hidLog("[hid] IndigoHIDMessageForButton loaded")
74
86
  } else {
75
87
  print("[hid] Warning: IndigoHIDMessageForButton not found")
76
88
  }
77
89
 
78
90
  if let arbPtr = dlsym(UnsafeMutableRawPointer(bitPattern: -2), "IndigoHIDMessageForHIDArbitrary") {
79
91
  self.hidArbitraryFunc = unsafeBitCast(arbPtr, to: IndigoHIDArbitraryFunc.self)
80
- print("[hid] IndigoHIDMessageForHIDArbitrary loaded")
92
+ hidLog("[hid] IndigoHIDMessageForHIDArbitrary loaded")
81
93
  } else {
82
94
  print("[hid] Warning: IndigoHIDMessageForHIDArbitrary not found")
83
95
  }
84
96
 
85
97
  if let keyboardPtr = dlsym(UnsafeMutableRawPointer(bitPattern: -2), "IndigoHIDMessageForKeyboardArbitrary") {
86
98
  self.keyboardFunc = unsafeBitCast(keyboardPtr, to: IndigoKeyboardFunc.self)
87
- print("[hid] IndigoHIDMessageForKeyboardArbitrary loaded")
99
+ hidLog("[hid] IndigoHIDMessageForKeyboardArbitrary loaded")
88
100
  } else {
89
101
  print("[hid] Warning: IndigoHIDMessageForKeyboardArbitrary not found")
90
102
  }
91
103
 
92
104
  if let crownPtr = dlsym(UnsafeMutableRawPointer(bitPattern: -2), "IndigoHIDMessageForDigitalCrownEvent") {
93
105
  self.digitalCrownFunc = unsafeBitCast(crownPtr, to: IndigoDigitalCrownFunc.self)
94
- print("[hid] IndigoHIDMessageForDigitalCrownEvent loaded")
106
+ hidLog("[hid] IndigoHIDMessageForDigitalCrownEvent loaded")
95
107
  } else {
96
108
  print("[hid] Warning: IndigoHIDMessageForDigitalCrownEvent not found")
97
109
  }
@@ -120,8 +132,8 @@ final class HIDInjector {
120
132
 
121
133
  self.hidClient = clientObj
122
134
  self.sendSel = NSSelectorFromString("sendWithMessage:freeWhenDone:completionQueue:completion:")
123
- print("[hid] SimDeviceLegacyHIDClient created")
124
- print("[hid] IndigoHIDMessageForMouseNSEvent loaded (with edge gesture support)")
135
+ hidLog("[hid] SimDeviceLegacyHIDClient created")
136
+ hidLog("[hid] IndigoHIDMessageForMouseNSEvent loaded (with edge gesture support)")
125
137
  }
126
138
 
127
139
  // IndigoHIDEdge values (x4 param to IndigoHIDMessageForMouseNSEvent).
@@ -175,7 +187,7 @@ final class HIDInjector {
175
187
 
176
188
  func sendTouch(type: String, x: Double, y: Double, screenWidth: Int, screenHeight: Int, edge: UInt32 = 0) {
177
189
  guard let msg = touchMessage(type: type, x: x, y: y, edge: edge) else { return }
178
- print("[hid] Sending \(type) at (\(String(format:"%.3f",x)),\(String(format:"%.3f",y)))\(edge > 0 ? " edge=\(edge)" : "")")
190
+ hidLog("[hid] Sending \(type) at (\(String(format:"%.3f",x)),\(String(format:"%.3f",y)))\(edge > 0 ? " edge=\(edge)" : "")")
179
191
  inputQueue.async { [self] in rawSend(msg) }
180
192
  }
181
193
 
@@ -197,7 +209,7 @@ final class HIDInjector {
197
209
  return
198
210
  }
199
211
 
200
- print("[hid] Multi-touch \(type) f1=(\(String(format:"%.3f",x1)),\(String(format:"%.3f",y1))) f2=(\(String(format:"%.3f",x2)),\(String(format:"%.3f",y2)))")
212
+ hidLog("[hid] Multi-touch \(type) f1=(\(String(format:"%.3f",x1)),\(String(format:"%.3f",y1))) f2=(\(String(format:"%.3f",x2)),\(String(format:"%.3f",y2)))")
201
213
  inputQueue.async { [self] in rawSend(rawMsg) }
202
214
  }
203
215
 
@@ -257,7 +269,7 @@ final class HIDInjector {
257
269
  return
258
270
  }
259
271
 
260
- print("[hid] Key \(type) usage=0x\(String(usage, radix: 16))")
272
+ hidLog("[hid] Key \(type) usage=0x\(String(usage, radix: 16))")
261
273
  inputQueue.async { [self] in rawSend(msg) }
262
274
  }
263
275
 
@@ -277,7 +289,7 @@ final class HIDInjector {
277
289
  return
278
290
  }
279
291
 
280
- print("[hid] Digital Crown delta=\(String(format:"%.4f", delta))")
292
+ hidLog("[hid] Digital Crown delta=\(String(format:"%.4f", delta))")
281
293
  inputQueue.async { [self] in rawSend(msg) }
282
294
  }
283
295
 
@@ -397,7 +409,7 @@ final class HIDInjector {
397
409
  }
398
410
  rawSend(msg)
399
411
  }
400
- print("[hid] HID button page=\(page) usage=\(usage) phase=\(phase)")
412
+ hidLog("[hid] HID button page=\(page) usage=\(usage) phase=\(phase)")
401
413
  inputQueue.async {
402
414
  switch phase {
403
415
  case "down": emit(1)
@@ -411,7 +423,7 @@ final class HIDInjector {
411
423
  }
412
424
 
413
425
  func sendButton(button: String, deviceUDID: String) {
414
- print("[hid] Sending button: \(button)")
426
+ hidLog("[hid] Sending button: \(button)")
415
427
 
416
428
  switch button {
417
429
  case "home":
@@ -490,7 +502,7 @@ final class HIDInjector {
490
502
  let imp = device.method(for: sel)
491
503
  let fn = unsafeBitCast(imp, to: Fn.self)
492
504
  let result = fn(device, sel, name as NSString, ObjCBool(enabled))
493
- print("[sim] setCADebugOption(\(name), \(enabled)) → \(result.boolValue)")
505
+ hidLog("[sim] setCADebugOption(\(name), \(enabled)) → \(result.boolValue)")
494
506
  return result.boolValue
495
507
  }
496
508
 
@@ -523,7 +535,7 @@ final class HIDInjector {
523
535
  return
524
536
  }
525
537
  _ = device.perform(sel)
526
- print("[sim] simulateMemoryWarning dispatched")
538
+ hidLog("[sim] simulateMemoryWarning dispatched")
527
539
  }
528
540
 
529
541
  /// Synthesize a swipe-up-from-bottom gesture (Face ID "go home" gesture).
@@ -629,7 +641,7 @@ final class HIDInjector {
629
641
  fputs("[hid] sendOrientation: mach_msg_send failed (\(kr))\n", stderr)
630
642
  return false
631
643
  } else {
632
- print("[hid] Orientation set to \(orientation)")
644
+ hidLog("[hid] Orientation set to \(orientation)")
633
645
  return true
634
646
  }
635
647
  }
@@ -3,15 +3,11 @@
3
3
  # spawned serve-sim-bin helper. The JS bindings are written in Swift with
4
4
  # node-swift (see ../../Package.swift and sim-module.swift).
5
5
  #
6
- # Host-arch only (arm64 on Apple Silicon / CI). We use a plain `swift build`,
7
- # i.e. the NATIVE SwiftPM build system, because that is the only mode that
8
- # resolves node-swift's #NodeModule macro plugin: both `--arch X --arch Y`
9
- # (universal) and `--triple <other-arch>` force Xcode's XCBuild, which fails to
10
- # resolve the NodeAPIMacros plugin on stock toolchains ("missing target
11
- # NodeAPIMacros" / "unable to resolve module SwiftSyntax"). Cross-compiling the
12
- # x86_64 slice would therefore require an x86_64-native toolchain (Rosetta),
13
- # which isn't available everywhere; serve-sim targets Apple Silicon. napi_* stay
14
- # undefined and resolve against the host (Node/Bun) at dlopen via
6
+ # We opt into the new `swiftbuild` build system, because it supports building universal
7
+ # binaries with macros, which neither the legacy `native` build system nor the
8
+ # perennially-janky legacy `xcode` build system had support for.
9
+ #
10
+ # napi_* stay undefined and resolve against the host (Node/Bun) at dlopen via
15
11
  # `-undefined dynamic_lookup`.
16
12
  set -euo pipefail
17
13
  HERE="$(cd "$(dirname "$0")" && pwd)"
@@ -26,25 +22,23 @@ if [ ! -d "$PKG/node_modules/node-swift" ]; then
26
22
  exit 1
27
23
  fi
28
24
 
29
- swift build \
30
- -c release \
31
- --product "$PRODUCT" \
32
- --package-path "$PKG" \
33
- --build-path "$BUILD_DIR" \
34
- -Xlinker -undefined -Xlinker dynamic_lookup
35
-
36
- # `-print -quit` (not `| head`): under `pipefail`, head closing the pipe early
37
- # would SIGPIPE find and fail the script. Match by name rather than a fixed
38
- # subpath: the product dir varies by toolchain (native SwiftPM emits
39
- # .build/release/, the Xcode build system emits .build/out/Products/Release/).
40
- DYLIB="$(find "$BUILD_DIR" -name "lib${PRODUCT}.dylib" -type f -not -path '*.dSYM*' -print -quit)"
41
- if [ -z "$DYLIB" ]; then
42
- echo "Build succeeded but lib${PRODUCT}.dylib was not found under $BUILD_DIR" >&2
25
+ build_flags=(
26
+ -c release
27
+ --product "$PRODUCT"
28
+ --package-path "$PKG"
29
+ --build-path "$BUILD_DIR"
30
+ --build-system swiftbuild
31
+ )
32
+ swift build "${build_flags[@]}" >&2
33
+ DYLIB="$(swift build --show-bin-path "${build_flags[@]}")/lib${PRODUCT}.dylib"
34
+ if [ ! -f "$DYLIB" ]; then
35
+ echo "Expected build product not found at $DYLIB" >&2
43
36
  exit 1
44
37
  fi
45
38
 
46
39
  OUT="$OUT_DIR/${PRODUCT}.node"
47
- cp "$DYLIB" "$OUT"
40
+ cp -a "$DYLIB" "$OUT"
41
+ strip -x "$OUT"
48
42
  codesign -s - -f "$OUT" 2>/dev/null || true
49
43
 
50
44
  echo "Built: $OUT"