peachsim 0.1.1667 → 0.1.1673

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.
Files changed (178) hide show
  1. package/README.md +1 -1
  2. package/cli/bridge-flow-runner.ts +4 -1
  3. package/cli/commands/coverage-swift.ts +291 -0
  4. package/cli/commands/coverage.ts +168 -24
  5. package/cli/commands/diagnose.ts +1 -19
  6. package/cli/commands/react.ts +3 -18
  7. package/cli/commands/screenshot.ts +1 -1
  8. package/cli/commands/screenshots-capture.ts +1 -1
  9. package/cli/drivers/playwright-provisioning.ts +1 -4
  10. package/cli/drivers/playwright.ts +15 -1
  11. package/cli/scene-video.ts +1 -1
  12. package/cli/ui.ts +20 -0
  13. package/cli/ws-bridge.ts +7 -36
  14. package/detox/frame-identity.cjs +21 -0
  15. package/detox/frame-identity.d.cts +6 -0
  16. package/detox/index.ts +39 -33
  17. package/detox/jest-environment.cjs +4 -1
  18. package/detox/jest-setup-after-env.cjs +0 -4
  19. package/detox/navigation-lifecycle.ts +2 -2
  20. package/detox/proof-observer.ts +126 -0
  21. package/dist-lib/agent-daemon-client.cjs +29 -1
  22. package/dist-lib/agent-events.cjs +1 -1
  23. package/dist-lib/attached-projects.cjs +10 -1
  24. package/dist-lib/auth/shared-session.cjs +1 -1
  25. package/dist-lib/backend-origin.cjs +1 -1
  26. package/dist-lib/beta.cjs +1 -1
  27. package/dist-lib/beta.mjs +1 -1
  28. package/dist-lib/bridge-constants.cjs +1 -1
  29. package/dist-lib/bridge-contract-input.cjs +1 -1
  30. package/dist-lib/bridge-contract-input.mjs +1 -1
  31. package/dist-lib/bridge-contract.cjs +1 -1
  32. package/dist-lib/bridge-contract.mjs +1 -1
  33. package/dist-lib/bundle-channel.cjs +530 -154
  34. package/dist-lib/capture-contract.cjs +1 -1
  35. package/dist-lib/capture-contract.mjs +1 -1
  36. package/dist-lib/cloud-contract.cjs +1 -1
  37. package/dist-lib/cloud-contract.mjs +1 -1
  38. package/dist-lib/cloud-test-args.cjs +1 -1
  39. package/dist-lib/cloud-test-args.mjs +1 -1
  40. package/dist-lib/cloud.cjs +1 -1
  41. package/dist-lib/cloud.mjs +1 -1
  42. package/dist-lib/config.cjs +1 -1
  43. package/dist-lib/config.mjs +1 -1
  44. package/dist-lib/detox/index.cjs +5074 -7353
  45. package/dist-lib/detox/jest-environment.cjs +4 -1
  46. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  47. package/dist-lib/expo-swift-bundle.cjs +578 -151
  48. package/dist-lib/expo-swift-metadata.cjs +1 -1
  49. package/dist-lib/expo-swift-metadata.mjs +1 -1
  50. package/dist-lib/home-paths.cjs +1 -1
  51. package/dist-lib/host/bridge-host.cjs +660 -192
  52. package/dist-lib/host/fetch-proxy-handler.cjs +2 -2
  53. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  54. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  55. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  56. package/dist-lib/host/websocket-proxy.cjs +1 -1
  57. package/dist-lib/index.cjs +206 -6
  58. package/dist-lib/jump-to-source-babel.cjs +1 -1
  59. package/dist-lib/jump-to-source-native.cjs +1 -1
  60. package/dist-lib/kotlin-host.cjs +1 -1
  61. package/dist-lib/menu.cjs +1 -1
  62. package/dist-lib/menu.mjs +1 -1
  63. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  64. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  65. package/dist-lib/metro-production-bundle.cjs +10 -1
  66. package/dist-lib/metro-production-bundle.mjs +12 -1
  67. package/dist-lib/metro.cjs +155 -5
  68. package/dist-lib/native-app-identity-project.cjs +43 -5
  69. package/dist-lib/native-app-identity-project.mjs +43 -5
  70. package/dist-lib/native-app-identity.cjs +1 -1
  71. package/dist-lib/native-app-identity.mjs +1 -1
  72. package/dist-lib/native-firebase-metadata.cjs +1 -1
  73. package/dist-lib/native-firebase-metadata.mjs +1 -1
  74. package/dist-lib/plist.cjs +1 -1
  75. package/dist-lib/plist.mjs +1 -1
  76. package/dist-lib/profiles.cjs +21 -1
  77. package/dist-lib/public-brand.cjs +1 -1
  78. package/dist-lib/public-origins-lib-esm.json +73 -27
  79. package/dist-lib/public-origins-lib-static.json +1 -1
  80. package/dist-lib/public-origins-lib.json +563 -183
  81. package/dist-lib/react-native-host-modules.cjs +1 -1
  82. package/dist-lib/react-native-host-modules.mjs +1 -1
  83. package/dist-lib/reap-browser.cjs +964 -0
  84. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  85. package/dist-lib/sdk.cjs +1 -1
  86. package/dist-lib/sdk.mjs +1 -1
  87. package/dist-lib/skills.cjs +963 -521
  88. package/dist-lib/swift-compile.cjs +276 -86
  89. package/dist-lib/swift-compile.mjs +276 -86
  90. package/dist-lib/swift-package.cjs +34 -4
  91. package/dist-lib/swift-package.mjs +33 -4
  92. package/dist-lib/swift-submit.cjs +2 -2
  93. package/dist-lib/swift-submit.mjs +2 -2
  94. package/dist-lib/swift-toolchain.cjs +25 -44
  95. package/dist-lib/swift.cjs +1 -1
  96. package/dist-lib/vite-swift.cjs +579 -113
  97. package/dist-lib/vite.cjs +61 -2
  98. package/dist-lib/worklet-executable.cjs +1 -1
  99. package/dist-lib/worklet-executable.mjs +1 -1
  100. package/dist-types/packages/peach-engine/src/engine/clipboardContract.d.ts +7 -0
  101. package/dist-types/packages/peach-engine/src/engine/glass-material.d.ts +1 -1
  102. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +2 -0
  103. package/dist-types/packages/peach-engine/src/engine/inspect-outline.d.ts +2 -1
  104. package/dist-types/packages/peach-engine/src/engine/liquid-glass.d.ts +1 -0
  105. package/dist-types/packages/peach-engine/src/engine/paint-boundary.d.ts +3 -1
  106. package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +7 -0
  107. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime-kind.d.ts +24 -0
  108. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +4 -2
  109. package/dist-types/packages/peach-engine/src/settings/devices.d.ts +1 -0
  110. package/dist-types/packages/peach-globals/src/clipboardBridgeContract.d.ts +18 -0
  111. package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
  112. package/dist-types/packages/peach-globals/src/nodeContract.d.ts +1 -0
  113. package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
  114. package/package.json +1 -1
  115. package/runtime-companion.json +1 -1
  116. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFString.h +2 -0
  117. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h +36 -0
  118. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStore.h +439 -0
  119. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStoreCopySpecific.h +216 -0
  120. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStoreKey.h +267 -0
  121. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetwork.h +204 -0
  122. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkConfiguration.h +1393 -0
  123. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkConnection.h +568 -0
  124. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkReachability.h +369 -0
  125. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferences.h +473 -0
  126. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferencesPath.h +179 -0
  127. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferencesSetSpecific.h +95 -0
  128. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h +2395 -0
  129. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SystemConfiguration.h +184 -0
  130. package/sdk/ios/usr/include/libkern/OSByteOrder.h +315 -0
  131. package/sdk/ios/usr/include/libkern/machine/OSByteOrder.h +147 -0
  132. package/src/bridge-contract.ts +42 -0
  133. package/src/chromium-admission.ts +196 -0
  134. package/src/host/bridge-host.ts +6 -43
  135. package/src/launch-deadline.ts +74 -0
  136. package/src/nitro-adapter.lock.json +3 -3
  137. package/src/profiles.ts +21 -0
  138. package/src/react-native-coverage/capability-reference-resolution.ts +402 -0
  139. package/src/react-native-coverage/capability-source-references.ts +1296 -0
  140. package/src/react-native-coverage/native-typescript-parser.ts +74 -0
  141. package/src/react-native-coverage/project-aliases.ts +207 -0
  142. package/src/react-native-coverage/verified-reach.ts +47 -0
  143. package/src/reap-browser.ts +1019 -0
  144. package/src/skills/builtin/a11y-review.ts +1 -1
  145. package/src/skills/builtin/perf-profile.ts +1 -1
  146. package/src/skills/builtin/screenshot-all.ts +1 -1
  147. package/src/skills/builtin/visual-diff.ts +1 -1
  148. package/src/swift-compile.ts +107 -56
  149. package/src/swift-coverage/indexdump.ts +80 -0
  150. package/src/swift-coverage/indexing.ts +147 -0
  151. package/src/swift-coverage/package.ts +230 -0
  152. package/src/swift-coverage/provenance.ts +47 -0
  153. package/src/swift-coverage/reader.ts +81 -0
  154. package/src/swift-coverage/source.ts +252 -0
  155. package/src/swift-coverage/types.ts +58 -0
  156. package/src/swift-coverage/xcode-assets.ts +175 -0
  157. package/src/swift-coverage/xcode-bridging.ts +160 -0
  158. package/src/swift-coverage/xcode-packages.ts +251 -0
  159. package/src/swift-coverage/xcode-strings.ts +78 -0
  160. package/src/swift-coverage/xcode.ts +656 -0
  161. package/src/swift-distribution.lock.json +8 -8
  162. package/src/swift-host.ts +21 -1
  163. package/src/swift-objc-import.ts +191 -27
  164. package/src/swift-objc-standin.ts +4 -2
  165. package/src/swift-package-manifest.ts +134 -13
  166. package/src/swift-package.ts +46 -4
  167. package/src/swift-submit.ts +2 -1
  168. package/src/swift-toolchain.ts +36 -61
  169. package/src/worker-system-chunks.ts +3 -10
  170. package/src/xcode-project.ts +5 -5
  171. package/detox/attempt-events.cjs +0 -914
  172. package/detox/attempt-events.d.cts +0 -113
  173. package/detox/motion-change.cjs +0 -524
  174. package/detox/motion-change.d.cts +0 -140
  175. package/detox/motion-leg-starts.cjs +0 -20
  176. package/detox/motion-leg-starts.d.cts +0 -8
  177. package/detox/proof-frame.cjs +0 -190
  178. package/detox/record-block-execution.cjs +0 -78
package/src/swift-host.ts CHANGED
@@ -39,6 +39,7 @@ import {
39
39
  swiftResourceBundleInfoPlist,
40
40
  SWIFT_NATIVE_SOURCE_EXTENSIONS,
41
41
  swiftTargetModuleName,
42
+ clangMacroSetting,
42
43
  type SwiftPackageTarget,
43
44
  } from './swift-package'
44
45
  import { swiftPackageManifest } from './swift-package-manifest'
@@ -534,8 +535,16 @@ function xcodeLayout(root: string): XcodeLayout | null {
534
535
  )
535
536
  throw new Error(`swift input escapes the selected package: ${target.dir}`)
536
537
  const posix = relative.split(path.sep).join(path.posix.sep)
538
+ // swiftpm hands every clang unit of a package SWIFT_PACKAGE=1, and DEBUG=1
539
+ // in its debug configuration
540
+ const packageMacros = [
541
+ 'SWIFT_PACKAGE=1',
542
+ ...(packageConfiguration === 'debug' ? ['DEBUG=1'] : []),
543
+ ]
537
544
  targets.push({
538
545
  ...target,
546
+ cDefines: packageMacros,
547
+ cxxDefines: packageMacros,
539
548
  path: target.remote ? path.posix.join(XCODE_PACKAGES_DIR, posix) : posix,
540
549
  exclude: [],
541
550
  defines: [
@@ -734,6 +743,17 @@ function xcodeManifest(layout: XcodeLayout): string {
734
743
  ...(target.mainActorIsolation ? ['.defaultIsolation(MainActor.self)'] : []),
735
744
  ...(target.defines ?? []).map((name) => `.define(${JSON.stringify(name)})`),
736
745
  ].join(', ')}]`
746
+ const clangSettings = (target: SwiftPackageTarget) =>
747
+ (
748
+ [
749
+ ['cSettings', target.cDefines],
750
+ ['cxxSettings', target.cxxDefines],
751
+ ] as const
752
+ )
753
+ .map(([label, macros]) =>
754
+ macros?.length ? `${label}: [${macros.map(clangMacroSetting).join(', ')}], ` : '',
755
+ )
756
+ .join('')
737
757
  const libraries = (target: SwiftPackageTarget) =>
738
758
  target.linkedLibraries?.length
739
759
  ? `, linkerSettings: [${target.linkedLibraries.map((name) => `.linkedLibrary(${JSON.stringify(name)})`).join(', ')}]`
@@ -746,7 +766,7 @@ function xcodeManifest(layout: XcodeLayout): string {
746
766
  ...layout.targets.map((target) =>
747
767
  target.systemLibrary
748
768
  ? ` .systemLibrary(name: "${target.name}", path: "${target.path}"),`
749
- : ` .target(name: "${target.name}", dependencies: ${JSON.stringify((target.dependencies ?? []).map((dependency) => dependency.name))}, path: "${target.path}", ${target.exclude.length > 0 ? `exclude: ${JSON.stringify(target.exclude)}, ` : ''}${target.resources ? 'resources: [], ' : ''}${settings(target)}${libraries(target)}),`,
769
+ : ` .target(name: "${target.name}", dependencies: ${JSON.stringify((target.dependencies ?? []).map((dependency) => dependency.name))}, path: "${target.path}", ${target.exclude.length > 0 ? `exclude: ${JSON.stringify(target.exclude)}, ` : ''}${target.resources ? 'resources: [], ' : ''}${clangSettings(target)}${settings(target)}${libraries(target)}),`,
750
770
  ),
751
771
  '])',
752
772
  '',
@@ -206,6 +206,7 @@ export function swiftObjCImports(
206
206
  const categories = new Map<string, Node[]>()
207
207
  const functions = new Map<string, Node[]>()
208
208
  const typedefs = new Map<string, string>()
209
+ const wrappedTypedefs = new Map<string, Node[]>()
209
210
  const visit = (node: unknown): void => {
210
211
  if (!record(node)) return
211
212
  if (
@@ -240,6 +241,9 @@ export function swiftObjCImports(
240
241
  ) {
241
242
  const canonical = node.type.desugaredQualType ?? node.type.qualType
242
243
  if (typeof canonical === 'string') typedefs.set(node.name, canonical)
244
+ if (nodes(node.inner).some((attribute) => attribute.kind === 'SwiftNewTypeAttr')) {
245
+ wrappedTypedefs.set(node.name, [...(wrappedTypedefs.get(node.name) ?? []), node])
246
+ }
243
247
  }
244
248
  for (const child of nodes(node.inner)) visit(child)
245
249
  }
@@ -247,15 +251,36 @@ export function swiftObjCImports(
247
251
  fail('declarations', 'expected a complete Clang translation unit AST')
248
252
  visit(options.clangAST)
249
253
 
250
- const symbols = new Map<string, GraphSymbol>()
254
+ const symbols = new Map<string, GraphSymbol[]>()
255
+ const seenSymbols = new Set<string>()
251
256
  for (const graph of graphs) {
252
257
  if (graph.module.name !== options.module)
253
258
  fail('declarations', `symbol graph belongs to ${graph.module.name}`)
254
259
  for (const symbol of graph.symbols) {
255
- const previous = symbols.get(symbol.identifier.precise)
256
- if (previous && JSON.stringify(previous) !== JSON.stringify(symbol))
257
- fail(symbol.identifier.precise, 'ambiguous imported declaration')
258
- symbols.set(symbol.identifier.precise, symbol)
260
+ if (
261
+ symbol.availability?.some(
262
+ (entry) =>
263
+ entry.isUnconditionallyUnavailable &&
264
+ (!entry.domain || entry.domain === 'Swift' || entry.domain === 'iOS'),
265
+ )
266
+ )
267
+ continue
268
+ // callback and async imports share a clang USR. documentation and source
269
+ // locations do not distinguish declarations; their swift signatures do.
270
+ const key = JSON.stringify([
271
+ symbol.identifier.precise,
272
+ symbol.kind.identifier,
273
+ symbol.pathComponents,
274
+ symbol.declarationFragments,
275
+ symbol.functionSignature,
276
+ symbol.accessLevel,
277
+ symbol.availability,
278
+ ])
279
+ if (seenSymbols.has(key)) continue
280
+ seenSymbols.add(key)
281
+ const overloads = symbols.get(symbol.identifier.precise) ?? []
282
+ overloads.push(symbol)
283
+ symbols.set(symbol.identifier.precise, overloads)
259
284
  }
260
285
  }
261
286
  const classes: SwiftObjCImport['classes'] = []
@@ -270,7 +295,10 @@ export function swiftObjCImports(
270
295
  types.set(name, nativeName)
271
296
  }
272
297
  for (const nativeName of [...selected].sort()) {
273
- const symbol = symbols.get(`c:objc(cs)${nativeName}`)
298
+ const candidates = symbols.get(`c:objc(cs)${nativeName}`)
299
+ if (candidates && candidates.length !== 1)
300
+ fail(nativeName, 'ambiguous imported class declaration')
301
+ const symbol = candidates?.[0]
274
302
  const name = symbol?.pathComponents[0]
275
303
  if (!symbol || symbol.kind.identifier !== 'swift.class' || !name || !identifier(name))
276
304
  fail(nativeName, 'missing Swift-imported class declaration')
@@ -286,6 +314,107 @@ export function swiftObjCImports(
286
314
  classes.push({ name, nativeName })
287
315
  }
288
316
 
317
+ const wrapperMembers = new Map<string, GraphSymbol[]>()
318
+ const wrapperConformances = new Map<string, Set<string>>()
319
+ for (const graph of graphs)
320
+ for (const edge of graph.relationships)
321
+ if (edge.kind === 'conformsTo' && edge.source.includes('@T@')) {
322
+ const protocols = wrapperConformances.get(edge.source) ?? new Set<string>()
323
+ protocols.add(edge.target)
324
+ wrapperConformances.set(edge.source, protocols)
325
+ }
326
+ for (const candidates of symbols.values())
327
+ for (const member of candidates)
328
+ if (
329
+ member.pathComponents.length === 2 &&
330
+ ['init(rawValue:)', 'init(_:)'].includes(member.pathComponents[1]!)
331
+ ) {
332
+ const owner = member.pathComponents[0]!
333
+ wrapperMembers.set(owner, [...(wrapperMembers.get(owner) ?? []), member])
334
+ }
335
+ const stringWrappers = new Map<string, string>()
336
+ const wrapperSymbols = [...symbols]
337
+ .filter(
338
+ ([usr, candidates]) =>
339
+ usr.includes('@T@') && candidates[0]?.kind.identifier === 'swift.struct',
340
+ )
341
+ .sort(([left], [right]) => left.localeCompare(right))
342
+ for (const [usr, candidates] of wrapperSymbols) {
343
+ const nativeName = /^c:.*@T@([A-Za-z_]\w*)$/.exec(usr)?.[1]
344
+ if (!nativeName) continue
345
+ const originals = wrappedTypedefs.get(nativeName)
346
+ const declaration = originals?.[0]
347
+ if (!declaration || !record(declaration.type)) continue
348
+ const original = declaration.type.desugaredQualType ?? declaration.type.qualType
349
+ if (typeof original !== 'string' || original.replace(/\s/g, '') !== 'NSString*')
350
+ continue
351
+ const symbol = candidates[0]!
352
+ const name = symbol.pathComponents[0]
353
+ if (
354
+ candidates.length !== 1 ||
355
+ originals?.length !== 1 ||
356
+ symbol.pathComponents.length !== 1 ||
357
+ !name ||
358
+ !identifier(name) ||
359
+ types.has(name) ||
360
+ stringWrappers.has(name) ||
361
+ symbol.accessLevel !== 'public' ||
362
+ text(symbol.declarationFragments ?? []).trim() !== `struct ${name}` ||
363
+ symbol.availability?.length
364
+ )
365
+ fail(usr, 'typed string wrapper identity is unqualified')
366
+ if (
367
+ !['s:SY', 's:SH', 's:SQ', 's:s8SendableP'].every((protocol) =>
368
+ wrapperConformances.get(usr)?.has(protocol),
369
+ )
370
+ )
371
+ fail(usr, 'typed string wrapper conformances are unqualified')
372
+ const members = wrapperMembers.get(name) ?? []
373
+ const initializers = members.filter(
374
+ (member) => member.pathComponents[1] === 'init(rawValue:)',
375
+ )
376
+ if (
377
+ initializers.length !== 1 ||
378
+ initializers[0]!.kind.identifier !== 'swift.init' ||
379
+ initializers[0]!.accessLevel !== 'public' ||
380
+ text(initializers[0]!.declarationFragments ?? []).trim() !==
381
+ 'init(rawValue: String)' ||
382
+ !initializers[0]!.declarationFragments?.some(
383
+ (part) => part.kind === 'typeIdentifier' && part.preciseIdentifier === 's:SS',
384
+ )
385
+ )
386
+ fail(usr, 'typed string wrapper raw initializer is unqualified')
387
+ const unlabelled = members.filter((member) => member.pathComponents[1] === 'init(_:)')
388
+ if (
389
+ unlabelled.length > 1 ||
390
+ (unlabelled.length === 1 &&
391
+ (unlabelled[0]!.kind.identifier !== 'swift.init' ||
392
+ unlabelled[0]!.accessLevel !== 'public' ||
393
+ text(unlabelled[0]!.declarationFragments ?? []).trim() !==
394
+ 'init(_ rawValue: String)' ||
395
+ !unlabelled[0]!.declarationFragments?.some(
396
+ (part) => part.kind === 'typeIdentifier' && part.preciseIdentifier === 's:SS',
397
+ )))
398
+ )
399
+ fail(usr, 'typed string wrapper unlabeled initializer is unqualified')
400
+ stringWrappers.set(
401
+ name,
402
+ [
403
+ `public struct ${swiftName(name)}: Swift.RawRepresentable, Swift.Hashable, Swift.Equatable, Swift._SwiftNewtypeWrapper, Swift._ObjectiveCBridgeable, Swift.Sendable {`,
404
+ ' public typealias RawValue = Swift.String',
405
+ ' public typealias _ObjectiveCType = Foundation.NSString',
406
+ ' private let _rawValue: Swift.String',
407
+ ' public var rawValue: Swift.String { _rawValue }',
408
+ ' public init(rawValue: Swift.String) { _rawValue = rawValue }',
409
+ ...(unlabelled.length
410
+ ? [' public init(_ rawValue: Swift.String) { _rawValue = rawValue }']
411
+ : []),
412
+ '}',
413
+ '',
414
+ ].join('\n'),
415
+ )
416
+ }
417
+
289
418
  const type = (parts: readonly SymbolFragment[], where: string): ImportType => {
290
419
  const written = text(parts).trim()
291
420
  const optional = /[?!]$/.test(written)
@@ -314,7 +443,7 @@ export function swiftObjCImports(
314
443
  (part) =>
315
444
  part.preciseIdentifier?.startsWith('c:') ||
316
445
  (part.preciseIdentifier &&
317
- symbols.get(part.preciseIdentifier)?.kind.identifier === 'swift.class'),
446
+ symbols.get(part.preciseIdentifier)?.[0]?.kind.identifier === 'swift.class'),
318
447
  )
319
448
  )
320
449
  return {
@@ -327,7 +456,7 @@ export function swiftObjCImports(
327
456
  const identifiers = parts.filter((part) => part.kind === 'typeIdentifier')
328
457
  const id = identifiers.length === 1 ? identifiers[0]?.preciseIdentifier : undefined
329
458
  const native = id && nativeClass(id)
330
- const swiftClass = id ? symbols.get(id) : undefined
459
+ const swiftClass = id ? symbols.get(id)?.[0] : undefined
331
460
  const resolved = native
332
461
  ? names.get(native)
333
462
  : swiftClass?.kind.identifier === 'swift.class' &&
@@ -413,7 +542,8 @@ export function swiftObjCImports(
413
542
  )
414
543
  }
415
544
  const membersByClass = new Map<string, GraphSymbol[]>()
416
- for (const symbol of symbols.values()) {
545
+ const importedSymbols = [...symbols.values()].flat()
546
+ for (const symbol of importedSymbols) {
417
547
  const owner = /^c:objc\(cs\)([A-Za-z_]\w*)\(/.exec(symbol.identifier.precise)?.[1]
418
548
  if (owner && selected.has(owner)) {
419
549
  const members = membersByClass.get(owner)
@@ -569,31 +699,58 @@ export function swiftObjCImports(
569
699
  if (
570
700
  member.kind === 'ObjCMethodDecl' &&
571
701
  typeof member.name === 'string' &&
702
+ member.name !== 'init' &&
572
703
  (/^init(?:$|[^a-z])/.test(member.name.replace(/^_+/, '')) ||
573
704
  nodes(member.inner).some(
574
705
  (attribute) =>
575
706
  attribute.kind === 'NSConsumesSelfAttr' ||
576
707
  attribute.kind === 'ObjCDesignatedInitializerAttr',
577
- ))
708
+ )) &&
709
+ !nodes(member.inner).some((attribute) => attribute.kind === 'UnavailableAttr')
578
710
  )
579
711
  fail(
580
712
  `${nativeName}.${member.name}`,
581
713
  'explicit or designated initialization is unqualified',
582
714
  )
583
- if (member.variadic === true)
584
- fail(`${nativeName}.${member.name}`, 'variadic methods are unqualified')
585
715
  }
586
- const constructor = thunk(
587
- `${nativeName}:new`,
588
- raw,
589
- [],
590
- null,
591
- `[[${nativeName} alloc] init]`,
592
- )
593
716
  const body = [
594
717
  `public required init(_objcRetained: Swift.UnsafeMutableRawPointer) { precondition(Self.self == ${swiftName(name)}.self, "Swift subclass construction is unqualified"); super.init(_objcRetained: _objcRetained) }`,
595
- `public init() { precondition(Self.self == ${swiftName(name)}.self, "Swift subclass construction is unqualified"); super.init(_objcRetained: ${constructor}()!) }`,
596
718
  ]
719
+ const defaultInitializer = members.find(
720
+ (member) =>
721
+ member.kind === 'ObjCMethodDecl' &&
722
+ member.instance === true &&
723
+ member.name === 'init',
724
+ )
725
+ const importedInitializer = symbols.get(`c:objc(cs)${nativeName}(im)init`)
726
+ const initializerSpelling = importedInitializer?.[0]
727
+ ? text(importedInitializer[0].declarationFragments ?? []).trim()
728
+ : 'init()'
729
+ if (!/^init[?!]?\(\)$/.test(initializerSpelling))
730
+ fail(`${nativeName}.init`, 'default initializer signature is unqualified')
731
+ if (
732
+ !defaultInitializer ||
733
+ !nodes(defaultInitializer.inner).some(
734
+ (attribute) => attribute.kind === 'UnavailableAttr',
735
+ )
736
+ ) {
737
+ if (
738
+ defaultInitializer &&
739
+ (importedInitializer?.length !== 1 ||
740
+ importedInitializer[0]?.kind.identifier !== 'swift.init')
741
+ )
742
+ fail(`${nativeName}.init`, 'missing Swift-imported default initializer')
743
+ const constructor = thunk(
744
+ `${nativeName}:new`,
745
+ raw,
746
+ [],
747
+ null,
748
+ `[[${nativeName} alloc] init]`,
749
+ )
750
+ body.push(
751
+ `public ${initializerSpelling} { precondition(Self.self == ${swiftName(name)}.self, "Swift subclass construction is unqualified"); ${/^init[?!]/.test(initializerSpelling) ? `guard let _peer = ${constructor}() else { return nil }; super.init(_objcRetained: _peer)` : `super.init(_objcRetained: ${constructor}()!)`} }`,
752
+ )
753
+ }
597
754
  bodies.set(name, body)
598
755
  const prefix = `c:objc(cs)${nativeName}`
599
756
  for (const symbol of membersByClass.get(nativeName) ?? []) {
@@ -614,6 +771,8 @@ export function swiftObjCImports(
614
771
  (property ? (m.class !== true) === instance : m.instance === instance),
615
772
  )
616
773
  if (!decl) fail(usr, 'member absent from original Clang interface')
774
+ if (decl.variadic === true)
775
+ fail(`${nativeName}.${selector}`, 'variadic methods are unqualified')
617
776
  const parts = symbol.declarationFragments ?? []
618
777
  const written = text(parts)
619
778
  if (
@@ -622,13 +781,16 @@ export function swiftObjCImports(
622
781
  )
623
782
  fail(usr, 'availability and asynchronous or throwing imports are unqualified')
624
783
  if (
625
- nodes(decl.inner).some((a) =>
626
- /^(?:Unavailable|SwiftPrivate|SwiftAsync|SwiftError|ObjCRequiresSuper|NSConsumesSelf)Attr$/.test(
627
- String(a.kind),
628
- ),
784
+ nodes(decl.inner).some(
785
+ (a) =>
786
+ /^(?:Unavailable|SwiftPrivate|SwiftAsync|SwiftError|ObjCRequiresSuper)Attr$/.test(
787
+ String(a.kind),
788
+ ) ||
789
+ (a.kind === 'NSConsumesSelfAttr' && selector !== 'init'),
629
790
  )
630
791
  )
631
792
  fail(usr, 'member attributes require a qualified importer path')
793
+ if (selector === 'init' && symbol.kind.identifier === 'swift.init') continue
632
794
  const receiver = instance ? '_object' : nativeName
633
795
  const access = symbol.accessLevel === 'open' ? 'open' : 'public'
634
796
  const memberName = parts.find((part) => part.kind === 'identifier')?.spelling
@@ -713,7 +875,7 @@ export function swiftObjCImports(
713
875
  }
714
876
 
715
877
  const importedFunctions: string[] = []
716
- for (const symbol of symbols.values()) {
878
+ for (const symbol of importedSymbols) {
717
879
  if (symbol.kind.identifier !== 'swift.func') continue
718
880
  const usr = symbol.identifier.precise
719
881
  const native = /^c:@F@([A-Za-z_]\w*)$/.exec(usr)?.[1]
@@ -766,7 +928,7 @@ export function swiftObjCImports(
766
928
  `public func ${swiftName(name)}(${argumentsSwift}) -> ${result.swift} { ${result.c === 'void' ? '' : 'return '}${local}(${parameters.map((p) => swiftName(p.name)).join(', ')}) }`,
767
929
  )
768
930
  }
769
- if (!classes.length && !importedFunctions.length)
931
+ if (!classes.length && !importedFunctions.length && !stringWrappers.size)
770
932
  fail('declarations', 'no represented original Objective-C classes or C functions')
771
933
 
772
934
  const registerFunction = `_peachRegisterObjCImports_${hash(options.module)}`
@@ -781,12 +943,14 @@ export function swiftObjCImports(
781
943
  '',
782
944
  ].join('\n')
783
945
  const swift = [
784
- ...(classes.length ? ['import Foundation', 'import PeachObjC'] : []),
946
+ ...(classes.length || stringWrappers.size ? ['import Foundation'] : []),
947
+ ...(classes.length ? ['import PeachObjC'] : []),
785
948
  '',
786
949
  ...external,
787
950
  '',
788
951
  ...importedFunctions,
789
952
  '',
953
+ ...stringWrappers.values(),
790
954
  ...classes.flatMap((c) => [
791
955
  `open class ${swiftName(c.name)}: PeachObjC._ObjCForeignObject {`,
792
956
  ...bodies.get(c.name)!.map((line) => ` ${line}`),
@@ -41,7 +41,7 @@ export interface ObjcView {
41
41
  }
42
42
 
43
43
  /** bump when importer behavior changes the Swift view independently of SDK headers. */
44
- export const OBJC_IMPORT_VERSION = '3'
44
+ export const OBJC_IMPORT_VERSION = '4'
45
45
 
46
46
  export const NATIVE_GRAPH_SDK_VERSION = '27.1'
47
47
 
@@ -384,7 +384,9 @@ export function objcView(
384
384
  '-module-cache-path',
385
385
  path.join(cacheDir, 'ios-module-cache'),
386
386
  '-minimum-access-level',
387
- 'public',
387
+ // symbol graphs hide public underscored names at the public threshold.
388
+ // original clang headers remain the declaration boundary.
389
+ original ? 'internal' : 'public',
388
390
  '-skip-synthesized-members',
389
391
  '-omit-extension-block-symbols',
390
392
  '-output-dir',
@@ -56,6 +56,9 @@ export interface SwiftManifestTarget {
56
56
  }[]
57
57
  /** true when the target declares `resources:`. */
58
58
  declaresResources: boolean
59
+ /** coverage must not silently omit plugin-generated input or Swift flags. */
60
+ hasPluginUsages: boolean
61
+ unsupportedSwiftSettings: string[]
59
62
  /** public header directory relative to the target, as SwiftPM declares it. */
60
63
  publicHeadersPath: string
61
64
  /** a binary target's archive url; a local one's artifact is `dir`. */
@@ -64,7 +67,15 @@ export interface SwiftManifestTarget {
64
67
  checksum: string | null
65
68
  }
66
69
 
70
+ export interface SwiftManifestToolchain {
71
+ path: string
72
+ realpath: string
73
+ sha256: string
74
+ version: string
75
+ }
76
+
67
77
  export interface SwiftPackageManifest {
78
+ toolchain: SwiftManifestToolchain
68
79
  name: string
69
80
  dir: string
70
81
  /** library product name to the targets it vends. */
@@ -82,23 +93,38 @@ const array = (value: Json | undefined): Json[] => (Array.isArray(value) ? value
82
93
  const string = (value: Json | undefined): string | undefined =>
83
94
  typeof value === 'string' ? value : undefined
84
95
 
85
- function swiftCommand(): { file: string; args: string[] } {
96
+ function swiftCommand(): string {
86
97
  return process.platform === 'darwin'
87
- ? { file: 'xcrun', args: ['swift'] }
88
- : { file: path.join(swiftToolchainBin(lock.release), 'swift'), args: [] }
98
+ ? // runner-toolchain-platform: darwin
99
+ execFileSync('xcrun', ['--find', 'swift'], { encoding: 'utf8' }).trim()
100
+ : path.join(swiftToolchainBin(lock.release), 'swift')
89
101
  }
90
102
 
91
103
  const cacheDir = path.join(peachCacheDir(), 'swift-manifests')
92
104
  const evaluated = new Map<string, SwiftPackageManifest>()
93
105
 
94
- function dump(dir: string): { key: string; raw: Record<string, Json> } {
106
+ function dump(dir: string): {
107
+ key: string
108
+ raw: Record<string, Json>
109
+ toolchain: SwiftManifestToolchain
110
+ } {
95
111
  const manifests = fs
96
112
  .readdirSync(dir)
97
113
  .filter((name) => /^Package(@swift-[\d.]+)?\.swift$/.test(name))
98
114
  .sort()
99
115
  const command = swiftCommand()
116
+ const toolchain: SwiftManifestToolchain = {
117
+ path: command,
118
+ realpath: fs.realpathSync(command),
119
+ sha256: createHash('sha256').update(fs.readFileSync(command)).digest('hex'),
120
+ version: execFileSync(command, ['--version'], {
121
+ encoding: 'utf8',
122
+ env: swiftEnvironment(),
123
+ stdio: ['ignore', 'pipe', 'pipe'],
124
+ }).trim(),
125
+ }
100
126
  const key = createHash('sha256')
101
- .update(JSON.stringify([command, path.resolve(dir)]))
127
+ .update(JSON.stringify([toolchain, path.resolve(dir)]))
102
128
  .update(
103
129
  manifests
104
130
  .map((name) => `${name}\0${fs.readFileSync(path.join(dir, name), 'utf8')}`)
@@ -108,13 +134,12 @@ function dump(dir: string): { key: string; raw: Record<string, Json> } {
108
134
  .slice(0, 32)
109
135
  const cached = path.join(cacheDir, `${key}.json`)
110
136
  if (fs.existsSync(cached))
111
- return { key, raw: record(JSON.parse(fs.readFileSync(cached, 'utf8'))) }
137
+ return { key, toolchain, raw: record(JSON.parse(fs.readFileSync(cached, 'utf8'))) }
112
138
  let output: string
113
139
  try {
114
140
  output = execFileSync(
115
- command.file,
141
+ command,
116
142
  [
117
- ...command.args,
118
143
  'package',
119
144
  ...swiftPackageCacheOptions(),
120
145
  '--package-path',
@@ -140,7 +165,7 @@ function dump(dir: string): { key: string; raw: Record<string, Json> } {
140
165
  }
141
166
  fs.mkdirSync(cacheDir, { recursive: true })
142
167
  fs.writeFileSync(cached, output)
143
- return { key, raw: record(JSON.parse(output)) }
168
+ return { key, toolchain, raw: record(JSON.parse(output)) }
144
169
  }
145
170
 
146
171
  // the traits a consumer gets by default: `default`'s, and what they enable
@@ -175,15 +200,18 @@ function linksOnIOS(condition: Json | undefined, traits: Set<string>): boolean {
175
200
  /** the manifest of the package at `dir`, evaluated once per manifest content. */
176
201
  export function swiftPackageManifest(dir: string): SwiftPackageManifest {
177
202
  dir = fs.realpathSync(dir)
178
- const { key, raw } = dump(dir)
203
+ const { key, raw, toolchain } = dump(dir)
179
204
  const known = evaluated.get(key)
180
205
  if (known) return known
181
206
  const traits = defaultTraits(raw)
182
207
  const tools = Number(
183
208
  /^(\d+)/.exec(string(record(raw.toolsVersion)._version) ?? '5')?.[1] ?? 5,
184
209
  )
185
- const declaredModes = array(raw.swiftLanguageVersions).flatMap((mode) => {
186
- const major = Number(/^(\d+)/.exec(string(mode) ?? '')?.[1])
210
+ const declaredModeValues = array(raw.swiftLanguageVersions).flatMap(
211
+ (mode) => string(mode) ?? [],
212
+ )
213
+ const declaredModes = declaredModeValues.flatMap((mode) => {
214
+ const major = Number(/^(\d+)/.exec(mode)?.[1])
187
215
  return Number.isFinite(major) ? [major] : []
188
216
  })
189
217
  // swiftpm builds in the newest mode a package declares; with none, tools
@@ -258,10 +286,20 @@ export function swiftPackageManifest(dir: string): SwiftPackageManifest {
258
286
  })
259
287
  }
260
288
  let languageMode = packageMode
289
+ let sourceLanguageMode = declaredModeValues.length
290
+ ? declaredModeValues.reduce((highest, mode) =>
291
+ Number(mode) > Number(highest) ? mode : highest,
292
+ )
293
+ : tools >= 6
294
+ ? '6'
295
+ : tools >= 5
296
+ ? '5'
297
+ : (string(record(raw.toolsVersion)._version) ?? 'unknown')
261
298
  let mainActorIsolation = false
262
299
  const defines: SwiftManifestSetting[] = []
263
300
  const libraries: SwiftManifestSetting[] = []
264
301
  const nativeSettings: SwiftManifestTarget['nativeSettings'] = []
302
+ const unsupportedSwiftSettings: string[] = []
265
303
  for (const [tool, standard] of [
266
304
  ['c', string(raw.cLanguageStandard)],
267
305
  ['cxx', string(raw.cxxLanguageStandard)],
@@ -272,6 +310,24 @@ export function swiftPackageManifest(dir: string): SwiftPackageManifest {
272
310
  for (const setting of array(target.settings)) {
273
311
  const { kind: rawKind, tool, condition } = record(setting)
274
312
  const settingKind = record(rawKind)
313
+ if (tool === 'swift') {
314
+ const kinds = Object.keys(settingKind)
315
+ const supported =
316
+ kinds.length === 1 &&
317
+ ((kinds[0] === 'define' &&
318
+ /^[A-Za-z_][A-Za-z0-9_]*$/.test(
319
+ string(record(settingKind.define)._0) ?? '',
320
+ )) ||
321
+ (kinds[0] === 'swiftLanguageMode' &&
322
+ Object.keys(record(condition)).length === 0) ||
323
+ (kinds[0] === 'defaultIsolation' &&
324
+ Object.keys(record(condition)).length === 0 &&
325
+ ['MainActor', 'nonisolated'].includes(
326
+ string(record(settingKind.defaultIsolation)._0) ?? '',
327
+ )))
328
+ if (!supported)
329
+ unsupportedSwiftSettings.push(JSON.stringify({ kind: rawKind, condition }))
330
+ }
275
331
  if ((tool === 'c' || tool === 'cxx') && linksOnIOS(condition, traits)) {
276
332
  const config = string(record(condition).config)
277
333
  const header = string(record(settingKind.headerSearchPath)._0)
@@ -299,6 +355,7 @@ export function swiftPackageManifest(dir: string): SwiftPackageManifest {
299
355
  })
300
356
  }
301
357
  const mode = string(record(settingKind.swiftLanguageMode)._0)
358
+ if (tool === 'swift' && mode) sourceLanguageMode = mode
302
359
  if (mode)
303
360
  languageMode = Math.max(5, Number(/^(\d+)/.exec(mode)?.[1] ?? languageMode))
304
361
  if (string(record(settingKind.defaultIsolation)._0) === 'MainActor')
@@ -325,6 +382,10 @@ export function swiftPackageManifest(dir: string): SwiftPackageManifest {
325
382
  })
326
383
  }
327
384
  }
385
+ if (!['5', '6'].includes(sourceLanguageMode))
386
+ unsupportedSwiftSettings.push(
387
+ `unsupported Swift language mode: ${sourceLanguageMode}`,
388
+ )
328
389
  targets.set(name, {
329
390
  name,
330
391
  type: kind,
@@ -341,6 +402,8 @@ export function swiftPackageManifest(dir: string): SwiftPackageManifest {
341
402
  libraries,
342
403
  nativeSettings,
343
404
  declaresResources: array(target.resources).length > 0,
405
+ hasPluginUsages: array(target.pluginUsages).length > 0,
406
+ unsupportedSwiftSettings,
344
407
  publicHeadersPath: string(target.publicHeadersPath) ?? 'include',
345
408
  url: string(target.url) ?? null,
346
409
  checksum: string(target.checksum) ?? null,
@@ -348,7 +411,7 @@ export function swiftPackageManifest(dir: string): SwiftPackageManifest {
348
411
  }
349
412
  const name = string(raw.name)
350
413
  if (!name) throw new Error(`swiftpm returned no package name for ${dir}`)
351
- const manifest = { name, dir, products, targets, packages }
414
+ const manifest = { name, dir, products, targets, packages, toolchain }
352
415
  evaluated.set(key, manifest)
353
416
  return manifest
354
417
  }
@@ -394,3 +457,61 @@ export function swiftTargetFiles(
394
457
  .filter((file) => !within(file, excluded))
395
458
  .sort()
396
459
  }
460
+
461
+ /** validated membership from SwiftPM's PackageBuilder, never a second directory walker. */
462
+ export function swiftPackageDescription(manifest: SwiftPackageManifest) {
463
+ fs.mkdirSync(cacheDir, { recursive: true })
464
+ const scratch = fs.mkdtempSync(path.join(cacheDir, 'describe-'))
465
+ let output: string
466
+ try {
467
+ output = execFileSync(
468
+ manifest.toolchain.path,
469
+ [
470
+ 'package',
471
+ ...swiftPackageCacheOptions(),
472
+ '--package-path',
473
+ manifest.dir,
474
+ '--scratch-path',
475
+ scratch,
476
+ 'describe',
477
+ '--type',
478
+ 'json',
479
+ ],
480
+ {
481
+ encoding: 'utf8',
482
+ env: swiftEnvironment(),
483
+ stdio: ['ignore', 'pipe', 'pipe'],
484
+ maxBuffer: 64 * 1024 * 1024,
485
+ },
486
+ )
487
+ } finally {
488
+ fs.rmSync(scratch, { recursive: true, force: true })
489
+ }
490
+ const raw = record(JSON.parse(output))
491
+ if (!Array.isArray(raw.targets))
492
+ throw new Error('SwiftPM describe returned no target membership')
493
+ const targets = raw.targets.map((entry) => {
494
+ const target = record(entry)
495
+ const name = string(target.name)
496
+ const moduleName = string(target.c99name)
497
+ const directory = string(target.path)
498
+ const moduleType = string(target.module_type)
499
+ if (
500
+ !name ||
501
+ !moduleName ||
502
+ directory === undefined ||
503
+ !moduleType ||
504
+ !Array.isArray(target.sources) ||
505
+ !target.sources.every((source) => typeof source === 'string')
506
+ )
507
+ throw new Error('SwiftPM describe returned malformed target membership')
508
+ return {
509
+ name,
510
+ moduleName,
511
+ path: directory,
512
+ moduleType,
513
+ sources: target.sources,
514
+ }
515
+ })
516
+ return { sha256: createHash('sha256').update(output).digest('hex'), targets }
517
+ }