peachsim 0.1.1667 → 0.1.1674

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 (204) 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/inspect/settling.ts +37 -4
  7. package/cli/commands/react.ts +3 -18
  8. package/cli/commands/screenshot.ts +1 -1
  9. package/cli/commands/screenshots-capture.ts +1 -1
  10. package/cli/drivers/playwright-provisioning.ts +1 -4
  11. package/cli/drivers/playwright.ts +15 -1
  12. package/cli/scene-video.ts +1 -1
  13. package/cli/ui.ts +20 -0
  14. package/cli/ws-bridge.ts +7 -36
  15. package/detox/frame-identity.cjs +21 -0
  16. package/detox/frame-identity.d.cts +6 -0
  17. package/detox/index.ts +39 -33
  18. package/detox/jest-environment.cjs +4 -1
  19. package/detox/jest-setup-after-env.cjs +0 -4
  20. package/detox/navigation-lifecycle.ts +2 -2
  21. package/detox/proof-observer.ts +126 -0
  22. package/dist-lib/agent-daemon-client.cjs +29 -1
  23. package/dist-lib/agent-events.cjs +1 -1
  24. package/dist-lib/attached-projects.cjs +10 -1
  25. package/dist-lib/auth/shared-session.cjs +1 -1
  26. package/dist-lib/backend-origin.cjs +1 -1
  27. package/dist-lib/beta.cjs +1 -1
  28. package/dist-lib/beta.mjs +1 -1
  29. package/dist-lib/bridge-constants.cjs +1 -1
  30. package/dist-lib/bridge-contract-input.cjs +1 -1
  31. package/dist-lib/bridge-contract-input.mjs +1 -1
  32. package/dist-lib/bridge-contract.cjs +1 -1
  33. package/dist-lib/bridge-contract.mjs +1 -1
  34. package/dist-lib/bundle-channel.cjs +557 -158
  35. package/dist-lib/capture-contract.cjs +1 -1
  36. package/dist-lib/capture-contract.mjs +1 -1
  37. package/dist-lib/cloud-contract.cjs +1 -1
  38. package/dist-lib/cloud-contract.mjs +1 -1
  39. package/dist-lib/cloud-test-args.cjs +1 -1
  40. package/dist-lib/cloud-test-args.mjs +1 -1
  41. package/dist-lib/cloud.cjs +1 -1
  42. package/dist-lib/cloud.mjs +1 -1
  43. package/dist-lib/config.cjs +1 -1
  44. package/dist-lib/config.mjs +1 -1
  45. package/dist-lib/detox/index.cjs +5098 -7344
  46. package/dist-lib/detox/jest-environment.cjs +4 -1
  47. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  48. package/dist-lib/expo-swift-bundle.cjs +602 -152
  49. package/dist-lib/expo-swift-metadata.cjs +1 -1
  50. package/dist-lib/expo-swift-metadata.mjs +1 -1
  51. package/dist-lib/home-paths.cjs +1 -1
  52. package/dist-lib/host/bridge-host.cjs +688 -194
  53. package/dist-lib/host/fetch-proxy-handler.cjs +6 -3
  54. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  55. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  56. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  57. package/dist-lib/host/websocket-proxy.cjs +1 -1
  58. package/dist-lib/index.cjs +247 -11
  59. package/dist-lib/jump-to-source-babel.cjs +1 -1
  60. package/dist-lib/jump-to-source-native.cjs +1 -1
  61. package/dist-lib/kotlin-host.cjs +1 -1
  62. package/dist-lib/menu.cjs +1 -1
  63. package/dist-lib/menu.mjs +1 -1
  64. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  65. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  66. package/dist-lib/metro-production-bundle.cjs +10 -1
  67. package/dist-lib/metro-production-bundle.mjs +12 -1
  68. package/dist-lib/metro.cjs +155 -5
  69. package/dist-lib/native-app-identity-project.cjs +43 -5
  70. package/dist-lib/native-app-identity-project.mjs +43 -5
  71. package/dist-lib/native-app-identity.cjs +1 -1
  72. package/dist-lib/native-app-identity.mjs +1 -1
  73. package/dist-lib/native-firebase-metadata.cjs +1 -1
  74. package/dist-lib/native-firebase-metadata.mjs +1 -1
  75. package/dist-lib/plist.cjs +1 -1
  76. package/dist-lib/plist.mjs +1 -1
  77. package/dist-lib/profiles.cjs +21 -1
  78. package/dist-lib/public-brand.cjs +1 -1
  79. package/dist-lib/public-origins-lib-esm.json +73 -27
  80. package/dist-lib/public-origins-lib-static.json +1 -1
  81. package/dist-lib/public-origins-lib.json +563 -183
  82. package/dist-lib/react-native-host-modules.cjs +1 -1
  83. package/dist-lib/react-native-host-modules.mjs +1 -1
  84. package/dist-lib/reap-browser.cjs +964 -0
  85. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  86. package/dist-lib/sdk.cjs +38 -5
  87. package/dist-lib/sdk.mjs +38 -5
  88. package/dist-lib/skills.cjs +1031 -530
  89. package/dist-lib/swift-compile.cjs +298 -86
  90. package/dist-lib/swift-compile.mjs +298 -86
  91. package/dist-lib/swift-package.cjs +53 -4
  92. package/dist-lib/swift-package.mjs +52 -4
  93. package/dist-lib/swift-submit.cjs +2 -2
  94. package/dist-lib/swift-submit.mjs +2 -2
  95. package/dist-lib/swift-toolchain.cjs +25 -44
  96. package/dist-lib/swift.cjs +1 -1
  97. package/dist-lib/vite-swift.cjs +603 -114
  98. package/dist-lib/vite.cjs +65 -3
  99. package/dist-lib/worklet-executable.cjs +1 -1
  100. package/dist-lib/worklet-executable.mjs +1 -1
  101. package/dist-types/packages/peach-engine/src/engine/clipboardContract.d.ts +7 -0
  102. package/dist-types/packages/peach-engine/src/engine/glass-material.d.ts +1 -1
  103. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +2 -0
  104. package/dist-types/packages/peach-engine/src/engine/inspect-outline.d.ts +2 -1
  105. package/dist-types/packages/peach-engine/src/engine/liquid-glass.d.ts +1 -0
  106. package/dist-types/packages/peach-engine/src/engine/paint-boundary.d.ts +4 -1
  107. package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +7 -0
  108. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime-kind.d.ts +24 -0
  109. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +4 -2
  110. package/dist-types/packages/peach-engine/src/rolldown-bundle-inventory.d.ts +1 -1
  111. package/dist-types/packages/peach-engine/src/settings/devices.d.ts +1 -0
  112. package/dist-types/packages/peach-globals/src/clipboardBridgeContract.d.ts +18 -0
  113. package/dist-types/packages/peach-globals/src/compositorBridgeContract.d.ts +10 -1
  114. package/dist-types/packages/peach-globals/src/index.d.ts +2 -2
  115. package/dist-types/packages/peach-globals/src/nodeContract.d.ts +1 -0
  116. package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
  117. package/package.json +1 -1
  118. package/runtime-companion.json +1 -1
  119. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFString.h +2 -0
  120. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h +54 -0
  121. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +23 -4
  122. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStore.h +439 -0
  123. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStoreCopySpecific.h +216 -0
  124. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStoreKey.h +267 -0
  125. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetwork.h +204 -0
  126. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkConfiguration.h +1393 -0
  127. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkConnection.h +568 -0
  128. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkReachability.h +369 -0
  129. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferences.h +473 -0
  130. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferencesPath.h +179 -0
  131. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferencesSetSpecific.h +95 -0
  132. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h +2395 -0
  133. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SystemConfiguration.h +184 -0
  134. package/sdk/ios/usr/include/_ctype.h +388 -0
  135. package/sdk/ios/usr/include/_inttypes.h +296 -0
  136. package/sdk/ios/usr/include/_locale.h +83 -0
  137. package/sdk/ios/usr/include/_locale_posix2008.h +65 -0
  138. package/sdk/ios/usr/include/_time.h +207 -0
  139. package/sdk/ios/usr/include/ctype.h +70 -0
  140. package/sdk/ios/usr/include/dispatch/dispatch.h +69 -6
  141. package/sdk/ios/usr/include/inttypes.h +35 -0
  142. package/sdk/ios/usr/include/libkern/OSByteOrder.h +315 -0
  143. package/sdk/ios/usr/include/libkern/machine/OSByteOrder.h +147 -0
  144. package/sdk/ios/usr/include/locale.h +59 -0
  145. package/sdk/ios/usr/include/runetype.h +118 -0
  146. package/sdk/ios/usr/include/setjmp.h +99 -0
  147. package/sdk/ios/usr/include/sys/_types/_clock_t.h +32 -0
  148. package/sdk/ios/usr/include/sys/_types/_ct_rune_t.h +33 -0
  149. package/sdk/ios/usr/include/sys/_types/_rune_t.h +32 -0
  150. package/sdk/ios/usr/include/sys/_types/_time_t.h +32 -0
  151. package/sdk/ios/usr/include/sys/_types/_wint_t.h +33 -0
  152. package/sdk/ios/usr/include/sys/cdefs.h +2 -0
  153. package/sdk/ios/usr/include/time.h +67 -2
  154. package/src/bridge-contract.ts +42 -0
  155. package/src/chromium-admission.ts +196 -0
  156. package/src/host/bridge-host.ts +6 -43
  157. package/src/host/rolldown-bundle-forward.ts +4 -1
  158. package/src/launch-deadline.ts +74 -0
  159. package/src/nitro-adapter.lock.json +3 -3
  160. package/src/profiles.ts +21 -0
  161. package/src/react-native-coverage/capability-reference-resolution.ts +402 -0
  162. package/src/react-native-coverage/capability-source-references.ts +1296 -0
  163. package/src/react-native-coverage/native-typescript-parser.ts +74 -0
  164. package/src/react-native-coverage/project-aliases.ts +207 -0
  165. package/src/react-native-coverage/verified-reach.ts +47 -0
  166. package/src/reap-browser.ts +1019 -0
  167. package/src/skills/builtin/a11y-review.ts +1 -1
  168. package/src/skills/builtin/perf-profile.ts +1 -1
  169. package/src/skills/builtin/screenshot-all.ts +1 -1
  170. package/src/skills/builtin/visual-diff.ts +1 -1
  171. package/src/swift-compile.ts +109 -57
  172. package/src/swift-coverage/indexdump.ts +80 -0
  173. package/src/swift-coverage/indexing.ts +147 -0
  174. package/src/swift-coverage/package.ts +230 -0
  175. package/src/swift-coverage/provenance.ts +47 -0
  176. package/src/swift-coverage/reader.ts +81 -0
  177. package/src/swift-coverage/source.ts +252 -0
  178. package/src/swift-coverage/types.ts +58 -0
  179. package/src/swift-coverage/xcode-assets.ts +175 -0
  180. package/src/swift-coverage/xcode-bridging.ts +160 -0
  181. package/src/swift-coverage/xcode-packages.ts +251 -0
  182. package/src/swift-coverage/xcode-strings.ts +78 -0
  183. package/src/swift-coverage/xcode.ts +656 -0
  184. package/src/swift-distribution.lock.json +8 -8
  185. package/src/swift-host.ts +21 -1
  186. package/src/swift-objc-compile.ts +7 -3
  187. package/src/swift-objc-import.ts +191 -27
  188. package/src/swift-objc-metadata.ts +2 -2
  189. package/src/swift-objc-standin.ts +9 -2
  190. package/src/swift-package-manifest.ts +134 -13
  191. package/src/swift-package.ts +69 -4
  192. package/src/swift-standins.ts +4 -1
  193. package/src/swift-submit.ts +2 -1
  194. package/src/swift-toolchain.ts +36 -61
  195. package/src/worker-system-chunks.ts +3 -10
  196. package/src/xcode-project.ts +5 -5
  197. package/detox/attempt-events.cjs +0 -914
  198. package/detox/attempt-events.d.cts +0 -113
  199. package/detox/motion-change.cjs +0 -524
  200. package/detox/motion-change.d.cts +0 -140
  201. package/detox/motion-leg-starts.cjs +0 -20
  202. package/detox/motion-leg-starts.d.cts +0 -8
  203. package/detox/proof-frame.cjs +0 -190
  204. 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
  '',
@@ -11,7 +11,12 @@ import {
11
11
  ObjcPeerMetadataError,
12
12
  validateObjcPeerClasses,
13
13
  } from './swift-objc-metadata'
14
- import { IOS_SDK_ID, materializeObjcSdk, OBJC_IMPORT_VERSION } from './swift-objc-standin'
14
+ import {
15
+ IOS_SDK_ID,
16
+ materializeObjcSdk,
17
+ OBJC_IMPORT_VERSION,
18
+ WASI_EMULATION_FLAGS,
19
+ } from './swift-objc-standin'
15
20
  import { SWIFT_NATIVE_SOURCE_EXTENSIONS, swiftTargetModuleName } from './swift-package'
16
21
  import { swiftPackageManifest, swiftTargetFiles } from './swift-package-manifest'
17
22
  import { remoteSwiftCheckouts, type SwiftPackageBinary } from './swift-packages'
@@ -554,8 +559,7 @@ export function prepareXcodeObjCImplementations(
554
559
  `--sysroot=${sdk.sysroot}`,
555
560
  '-fwasm-exceptions',
556
561
  '-fexceptions',
557
- '-D_WASI_EMULATED_SIGNAL',
558
- '-D_WASI_EMULATED_MMAN',
562
+ ...WASI_EMULATION_FLAGS,
559
563
  `-D__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__=${minimum}`,
560
564
  `-D__IPHONE_OS_VERSION_MIN_REQUIRED=${minimum}`,
561
565
  ...(objc
@@ -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}`),
@@ -8,6 +8,7 @@ import {
8
8
  IOS_SDK_ID,
9
9
  materializeObjcSdk,
10
10
  OBJC_IMPORT_VERSION,
11
+ WASI_EMULATION_FLAGS,
11
12
  objcView,
12
13
  type ObjcView,
13
14
  } from './swift-objc-standin'
@@ -433,8 +434,7 @@ export function compileObjcPeerMetadata(args: {
433
434
  `--sysroot=${args.sysroot}`,
434
435
  '-fwasm-exceptions',
435
436
  '-fexceptions',
436
- '-D_WASI_EMULATED_SIGNAL',
437
- '-D_WASI_EMULATED_MMAN',
437
+ ...WASI_EMULATION_FLAGS,
438
438
  `-D__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__=${args.minimum}`,
439
439
  `-D__IPHONE_OS_VERSION_MIN_REQUIRED=${args.minimum}`,
440
440
  '-fobjc-runtime=gnustep-2.2',
@@ -41,10 +41,15 @@ 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
 
48
+ /** the installed libc's emulated surfaces: its signal.h is an #error without them,
49
+ * so every clang that builds original c or objective-c for wasm passes them. */
50
+ export const WASI_EMULATION = ['_WASI_EMULATED_SIGNAL', '_WASI_EMULATED_MMAN']
51
+ export const WASI_EMULATION_FLAGS = WASI_EMULATION.map((name) => `-D${name}`)
52
+
48
53
  const NATIVE_GRAPH_INPUTS = {
49
54
  sdk: NATIVE_GRAPH_SDK_VERSION,
50
55
  settings: 'e68503e5e534e9194af5efe8c636ca8b824e2d8237c5f38ec84aa4d155bc8418',
@@ -384,7 +389,9 @@ export function objcView(
384
389
  '-module-cache-path',
385
390
  path.join(cacheDir, 'ios-module-cache'),
386
391
  '-minimum-access-level',
387
- 'public',
392
+ // symbol graphs hide public underscored names at the public threshold.
393
+ // original clang headers remain the declaration boundary.
394
+ original ? 'internal' : 'public',
388
395
  '-skip-synthesized-members',
389
396
  '-omit-extension-block-symbols',
390
397
  '-output-dir',