peachsim 0.1.1808 → 0.1.1812

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 (236) hide show
  1. package/README.md +4 -2
  2. package/cli/app-bundle-resources.ts +15 -2
  3. package/cli/cloud-box-artifact.ts +115 -0
  4. package/cli/cloud-client.ts +148 -76
  5. package/cli/cloud-dispatch.ts +4 -4
  6. package/cli/cloud-session.ts +60 -22
  7. package/cli/commands/box.ts +8 -2
  8. package/cli/commands/compat.ts +7 -4
  9. package/cli/commands/control.ts +69 -3
  10. package/cli/commands/coverage.ts +14 -4
  11. package/cli/commands/daemon.ts +41 -0
  12. package/cli/commands/no-bridge-hint.ts +9 -0
  13. package/cli/commands/package.ts +31 -56
  14. package/cli/commands/platform.ts +71 -60
  15. package/cli/commands/preview.ts +73 -24
  16. package/cli/commands/record.ts +10 -2
  17. package/cli/commands/screenshot.ts +17 -60
  18. package/cli/commands/setup.ts +3 -1
  19. package/cli/commands/three-mode.ts +22 -12
  20. package/cli/commands/upload.ts +2 -1
  21. package/cli/desktop-companion.ts +6 -1
  22. package/cli/drivers/desktop.ts +4 -1
  23. package/cli/main.ts +12 -2
  24. package/cli/metro-bundle-assets.ts +14 -4
  25. package/cli/outbound-endpoints.ts +7 -3
  26. package/cli/output-redaction.ts +38 -0
  27. package/cli/privacy.ts +2 -2
  28. package/cli/recording-access.ts +5 -0
  29. package/cli/remote-project-bundle.ts +83 -0
  30. package/cli/shell-init.ts +7 -11
  31. package/cli/telemetry.ts +41 -4
  32. package/cli/usage-error.ts +3 -0
  33. package/cli/ws-bridge.ts +42 -6
  34. package/dist-lib/agent-daemon-client.cjs +1 -1
  35. package/dist-lib/agent-events.cjs +1 -1
  36. package/dist-lib/attached-projects.cjs +1 -1
  37. package/dist-lib/auth/shared-session.cjs +1 -1
  38. package/dist-lib/backend-origin.cjs +1 -1
  39. package/dist-lib/beta.cjs +1 -1
  40. package/dist-lib/beta.mjs +1 -1
  41. package/dist-lib/bridge-constants.cjs +1 -1
  42. package/dist-lib/bridge-contract-input.cjs +1 -1
  43. package/dist-lib/bridge-contract-input.mjs +1 -1
  44. package/dist-lib/bridge-contract.cjs +1 -1
  45. package/dist-lib/bridge-contract.mjs +1 -1
  46. package/dist-lib/bundle-channel.cjs +42897 -40755
  47. package/dist-lib/capture-contract.cjs +7 -8
  48. package/dist-lib/capture-contract.mjs +7 -8
  49. package/dist-lib/cloud-contract.cjs +1 -1
  50. package/dist-lib/cloud-contract.mjs +1 -1
  51. package/dist-lib/cloud-test-args.cjs +1 -1
  52. package/dist-lib/cloud-test-args.mjs +1 -1
  53. package/dist-lib/cloud.cjs +1 -1
  54. package/dist-lib/cloud.mjs +1 -1
  55. package/dist-lib/config.cjs +1 -1
  56. package/dist-lib/config.mjs +1 -1
  57. package/dist-lib/detox/index.cjs +13 -7
  58. package/dist-lib/dev-bundle-resolution.cjs +10 -4
  59. package/dist-lib/expo-swift-bundle.cjs +15889 -15553
  60. package/dist-lib/expo-swift-metadata.cjs +2 -1
  61. package/dist-lib/expo-swift-metadata.mjs +2 -1
  62. package/dist-lib/home-paths.cjs +2 -33
  63. package/dist-lib/host/bridge-host.cjs +20891 -18714
  64. package/dist-lib/host/fetch-proxy-handler.cjs +10 -11
  65. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  66. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  67. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  68. package/dist-lib/host/websocket-proxy.cjs +1 -1
  69. package/dist-lib/index.cjs +620 -553
  70. package/dist-lib/jump-to-source-babel.cjs +1 -1
  71. package/dist-lib/jump-to-source-native.cjs +1 -1
  72. package/dist-lib/kotlin-host.cjs +1 -1
  73. package/dist-lib/menu.cjs +1 -1
  74. package/dist-lib/menu.mjs +1 -1
  75. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  76. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  77. package/dist-lib/metro-production-bundle.cjs +1 -1
  78. package/dist-lib/metro-production-bundle.mjs +1 -1
  79. package/dist-lib/metro.cjs +57 -28
  80. package/dist-lib/native-app-identity-project.cjs +47 -14
  81. package/dist-lib/native-app-identity-project.mjs +55 -20
  82. package/dist-lib/native-app-identity.cjs +1 -1
  83. package/dist-lib/native-app-identity.mjs +1 -1
  84. package/dist-lib/native-firebase-metadata.cjs +1 -1
  85. package/dist-lib/native-firebase-metadata.mjs +1 -1
  86. package/dist-lib/pdfium-raster.cjs +1 -1
  87. package/dist-lib/pdfium-raster.mjs +1 -1
  88. package/dist-lib/plist.cjs +1 -1
  89. package/dist-lib/plist.mjs +1 -1
  90. package/dist-lib/profiles.cjs +1 -1
  91. package/dist-lib/public-brand.cjs +1 -1
  92. package/dist-lib/public-origins-lib-esm.json +27 -26
  93. package/dist-lib/public-origins-lib.json +104 -81
  94. package/dist-lib/react-native-host-modules.cjs +1 -1
  95. package/dist-lib/react-native-host-modules.mjs +1 -1
  96. package/dist-lib/reap-browser.cjs +1 -1
  97. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  98. package/dist-lib/sdk.cjs +1 -1
  99. package/dist-lib/sdk.mjs +1 -1
  100. package/dist-lib/skills.cjs +30700 -24410
  101. package/dist-lib/swift-compile.cjs +336 -222
  102. package/dist-lib/swift-compile.mjs +378 -263
  103. package/dist-lib/swift-package.cjs +19 -7
  104. package/dist-lib/swift-package.mjs +16 -6
  105. package/dist-lib/swift-submit.cjs +1 -1
  106. package/dist-lib/swift-submit.mjs +1 -1
  107. package/dist-lib/swift-toolchain.cjs +49 -1
  108. package/dist-lib/swift.cjs +1 -1
  109. package/dist-lib/vite-swift.cjs +19213 -18937
  110. package/dist-lib/vite.cjs +11 -12
  111. package/dist-lib/worklet-executable.cjs +1 -1
  112. package/dist-lib/worklet-executable.mjs +1 -1
  113. package/dist-types/packages/peach-engine/src/engine/animated.d.ts +4 -0
  114. package/dist-types/packages/peach-engine/src/engine/animation-graph.d.ts +1 -0
  115. package/dist-types/packages/peach-engine/src/engine/expo-manifest.d.ts +1 -0
  116. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +1 -1
  117. package/dist-types/packages/peach-engine/src/preview/upload-protocol.d.ts +1 -0
  118. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +8 -1
  119. package/dist-types/packages/peach-globals/src/electronBridgeContract.d.ts +2 -1
  120. package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
  121. package/kotlin/sdk.tar.gz +0 -0
  122. package/package.json +1 -1
  123. package/runtime-companion.json +1 -1
  124. package/sdk/ios/System/Library/Frameworks/CoreTelephony.framework/Headers/CTCall.h +1 -1
  125. package/sdk/ios/System/Library/Frameworks/CoreTelephony.framework/Headers/CTCallCenter.h +1 -1
  126. package/sdk/ios/System/Library/Frameworks/CoreTelephony.framework/Headers/CTCarrier.h +1 -1
  127. package/sdk/ios/System/Library/Frameworks/CoreTelephony.framework/Headers/CTSubscriber.h +1 -1
  128. package/sdk/ios/System/Library/Frameworks/CoreTelephony.framework/Headers/CTSubscriberInfo.h +1 -1
  129. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/NSArray.h +1 -1
  130. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/NSDictionary.h +1 -1
  131. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/NSExtensionItem.h +1 -1
  132. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/AVFoundation+MPNowPlayingInfoLanguageOptionAdditions.h +39 -0
  133. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/AVPlayerItem+MediaPlayerAdditions.h +26 -0
  134. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPContentItem.h +67 -0
  135. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPError.h +33 -0
  136. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaEntity.h +53 -0
  137. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaItem.h +346 -0
  138. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaItemCollection.h +42 -0
  139. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaLibrary.h +76 -0
  140. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaPickerController.h +64 -0
  141. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaPlayback.h +47 -0
  142. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaPlaylist.h +82 -0
  143. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaQuery.h +120 -0
  144. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaQuerySection.h +26 -0
  145. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMoviePlayerController.h +444 -0
  146. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMoviePlayerViewController.h +43 -0
  147. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMusicPlayerApplicationController.h +47 -0
  148. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMusicPlayerController.h +147 -0
  149. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMusicPlayerQueueDescriptor.h +75 -0
  150. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPNowPlayingInfoCenter.h +197 -0
  151. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPNowPlayingInfoLanguageOption.h +107 -0
  152. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPNowPlayingSession.h +89 -0
  153. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPPlayableContentDataSource.h +59 -0
  154. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPPlayableContentDelegate.h +64 -0
  155. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPPlayableContentManager.h +46 -0
  156. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPPlayableContentManagerContext.h +32 -0
  157. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPRemoteCommand.h +143 -0
  158. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPRemoteCommandCenter.h +66 -0
  159. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPRemoteCommandEvent.h +128 -0
  160. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPRemoteControlTypes.h +27 -0
  161. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPVolumeSettings.h +20 -0
  162. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPVolumeView.h +82 -0
  163. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MediaPlayer.apinotes +74 -0
  164. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MediaPlayer.h +40 -0
  165. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MediaPlayerDefines.h +84 -0
  166. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/NSUserActivity+MediaPlayerAdditions.h +20 -0
  167. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Modules/module.modulemap +5 -0
  168. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIAccessibilityCustomRotor.h +2 -2
  169. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIAction.h +1 -1
  170. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIBackgroundConfiguration.h +1 -1
  171. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIButtonConfiguration.h +1 -1
  172. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIContextMenuConfiguration.h +1 -1
  173. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIContextMenuInteraction.h +1 -1
  174. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIDeferredMenuElement.h +1 -1
  175. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIMenu.h +1 -1
  176. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIPointerStyle.h +5 -5
  177. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UISlider.h +1 -1
  178. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UISplitViewController.h +12 -50
  179. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UISplitViewControllerLayoutEnvironment.h +2 -8
  180. package/sdk/ios/System/Library/Frameworks/UIKitTypes.framework/Headers/UIKitTypes.h +62 -0
  181. package/sdk/ios/usr/include/dispatch.modulemap +22 -0
  182. package/sdk/ios/usr/include/module.modulemap +8 -3
  183. package/sdk/ios/usr/include/net/if.h +24 -0
  184. package/sdk/ios/usr/include/sys/time.h +1 -1
  185. package/sdk/ios/usr/lib/swift/Foundation.swiftmodule/arm64-apple-ios-simulator.swiftinterface +265 -0
  186. package/sdk/ios/usr/lib/swift/ObjectiveC.swiftmodule/arm64-apple-ios-simulator.swiftinterface +2 -0
  187. package/sdk/ios/wasm/include/fcntl.h +2 -0
  188. package/sdk/ios/wasm/include/pthread.h +3 -0
  189. package/sdk/ios/wasm/include/stdlib.h +2 -0
  190. package/sdk/ios/wasm/include/unistd.h +2 -2
  191. package/skills/contrast/SKILL.md +2 -2
  192. package/src/bundle-channel.mjs +9 -72
  193. package/src/capture-contract.ts +12 -9
  194. package/src/desktop-host-delivery.ts +16 -2
  195. package/src/dev-bundle-resolution.ts +12 -3
  196. package/src/expo-native-workspace.ts +113 -46
  197. package/src/expo-swift-host.ts +17 -12
  198. package/src/expo-swift-ready.ts +4 -1
  199. package/src/expoSwiftContract.ts +1 -0
  200. package/src/home-paths.ts +4 -48
  201. package/src/host/bridge-host.ts +1 -0
  202. package/src/installed-native-libraries.ts +2 -8
  203. package/src/metro-project-root.ts +2 -1
  204. package/src/native-bundles.ts +122 -0
  205. package/src/native-static-libraries.ts +65 -8
  206. package/src/nitro-adapter.lock.json +272 -272
  207. package/src/nitro-bundle.ts +2 -2
  208. package/src/nitro-compile.ts +68 -28
  209. package/src/nitro-source.ts +24 -6
  210. package/src/nitro-superset.lock.json +94 -34
  211. package/src/nitroContract.ts +3 -0
  212. package/src/podspec-sources.ts +1966 -0
  213. package/src/storageSnapshotContract.ts +40 -0
  214. package/src/swift-compile.ts +77 -26
  215. package/src/swift-design-time.ts +18 -1
  216. package/src/swift-distribution.lock.json +12 -12
  217. package/src/swift-distribution.ts +9 -6
  218. package/src/swift-host.ts +1 -2
  219. package/src/swift-link-roots.ts +13 -2
  220. package/src/swift-objc-compile.ts +12 -0
  221. package/src/swift-objc-standin.ts +321 -114
  222. package/src/swift-package-manifest.ts +4 -3
  223. package/src/swift-package.ts +31 -4
  224. package/src/swift-root-lock.ts +11 -0
  225. package/src/swift-shared-sdk.ts +10 -9
  226. package/src/swift-source-pods.ts +2 -2
  227. package/src/swift-standins.ts +40 -143
  228. package/src/swift-toolchain.ts +59 -0
  229. package/src/swift-wasm-prune.ts +53 -21
  230. package/src/turbo-bundle.ts +4 -5
  231. package/src/turbo-codegen-intake.ts +111 -108
  232. package/src/turbo-compile.ts +63 -33
  233. package/src/turbo-runtime.lock.json +22 -22
  234. package/src/turbo-source.ts +171 -76
  235. package/src/wasm-optimize.ts +31 -2
  236. package/src/xcode-project.ts +65 -15
@@ -67,6 +67,46 @@ export const RESET_ASYNC_STORAGE_PREFIXES = [
67
67
  export const RESET_MMKV_STORAGE_PREFIX = '@sootsim_mmkv:'
68
68
  export const RESET_USER_DEFAULTS_PREFIX = 'rn-default-preference:'
69
69
 
70
+ // the record behind one UserDefaults key. Swift Foundation, PeachPreferences
71
+ // and every seam that fronts an app-group suite address it through this key,
72
+ // so a write from either side is the other side's read.
73
+ export function swiftPreferenceStorageKey(suiteName: string | null, key: string): string {
74
+ return RESET_USER_DEFAULTS_PREFIX + 'peach-swift:' + JSON.stringify([suiteName, key])
75
+ }
76
+
77
+ // app-group defaults were once kept per suite and key under this prefix as the
78
+ // raw string (`<encoded group>:<encoded key>`), outside the Swift record. Each
79
+ // storage object moves them into the record the first time a seam or the
80
+ // Swift host reaches it, so values persisted before the shared record stay
81
+ // readable. A value already in the record wins; the legacy copy is dropped
82
+ // either way. encodeURIComponent escapes ':', so the split is exact. A storage
83
+ // counts as migrated only after every legacy key moved, so a failed storage
84
+ // operation leaves the remaining copies in place and the next call retries
85
+ // them; the record-wins rule makes the retry safe after a partial pass.
86
+ const LEGACY_APP_GROUP_PREFIX = '@sootsim:shared-group-preferences:'
87
+ const legacyAppGroupMigrated = new WeakSet<Storage>()
88
+
89
+ export function migrateLegacyAppGroupDefaults(storage: Storage): void {
90
+ if (legacyAppGroupMigrated.has(storage)) return
91
+ const legacyKeys: string[] = []
92
+ for (let index = 0; index < storage.length; index++) {
93
+ const key = storage.key(index)
94
+ if (key?.startsWith(LEGACY_APP_GROUP_PREFIX)) legacyKeys.push(key)
95
+ }
96
+ for (const legacyKey of legacyKeys) {
97
+ const parts = legacyKey.slice(LEGACY_APP_GROUP_PREFIX.length).split(':')
98
+ if (parts.length !== 2) continue
99
+ const [group, key] = parts.map(decodeURIComponent)
100
+ const value = storage.getItem(legacyKey)
101
+ const recordKey = swiftPreferenceStorageKey(group, key)
102
+ if (value !== null && storage.getItem(recordKey) === null) {
103
+ storage.setItem(recordKey, JSON.stringify({ kind: 'string', string: value }))
104
+ }
105
+ storage.removeItem(legacyKey)
106
+ }
107
+ legacyAppGroupMigrated.add(storage)
108
+ }
109
+
70
110
  export type ResetStorageKind =
71
111
  | 'async-storage'
72
112
  | 'mmkv'
@@ -24,7 +24,6 @@ import os from 'node:os'
24
24
  import path from 'node:path'
25
25
  import { windowAdmission } from './admitted-mac-build'
26
26
  import cPredefinesJson from './generated/swift-c-predefines.json' with { type: 'json' }
27
- import { swiftCacheDir, swiftPackageCacheOptions } from './home-paths'
28
27
  import { terminateProcessGroup } from './process-group'
29
28
  import {
30
29
  reapRetiredCacheDirectory,
@@ -78,6 +77,8 @@ import {
78
77
  clangImportNames,
79
78
  clangMacroSetting,
80
79
  clangSettingEntries,
80
+ fmtConstantInterpreterFlags,
81
+ withoutGlogModuleMap,
81
82
  SWIFT_NATIVE_SOURCE_EXTENSIONS,
82
83
  type SwiftPackageTarget,
83
84
  } from './swift-package'
@@ -98,7 +99,9 @@ import {
98
99
  import {
99
100
  sourceSwiftCheckout,
100
101
  SWIFT_AUTOLINK_LINKER,
102
+ swiftCacheDir,
101
103
  swiftEnvironment,
104
+ swiftPackageCacheOptions,
102
105
  swiftSdkOptions,
103
106
  swiftSourceSdk,
104
107
  swiftToolchain,
@@ -363,8 +366,9 @@ export function swiftDistributionAt(root: string): SwiftDistributionManifest | n
363
366
  /**
364
367
  * the Objective-C interface an SDK module defines: the names Swift owns and
365
368
  * its generated header. a distribution ships the header; a source checkout
366
- * names them by `@objc(Name)` and builds the header with the module
367
- * (`.build/host`), so it stands as an empty header until that build.
369
+ * names them by `@objc(Name)` and reads the header its module build emitted
370
+ * (`.build/host`). a module with no emitted header has no interface in either,
371
+ * so its original Objective-C headers keep their declarations.
368
372
  */
369
373
  export function swiftModuleInterface(
370
374
  moduleRoot: string,
@@ -381,22 +385,21 @@ export function swiftModuleInterface(
381
385
  return { declared: swiftInterfaceDeclarations(header), header }
382
386
  }
383
387
  const sources = path.join(moduleRoot, 'Sources', name)
384
- if (!existsSync(sources)) return null
388
+ const built = path.join(moduleRoot, '.build/host', `${name}-Swift.h`)
389
+ if (!existsSync(sources) || !existsSync(built)) return null
385
390
  const declared = new Set<string>()
386
391
  for (const file of readdirSync(sources, { recursive: true, encoding: 'utf8' }))
387
392
  if (file.endsWith('.swift'))
388
- for (const [, objc] of readFileSync(path.join(sources, file), 'utf8').matchAll(
389
- /@objc\((\w+)\)\s+(?:\w+\s+)*?(?:protocol|class)\s/g,
393
+ // an NSObject subclass is an Objective-C class named as it is in Swift
394
+ for (const [, objc, subclass] of readFileSync(
395
+ path.join(sources, file),
396
+ 'utf8',
397
+ ).matchAll(
398
+ /@objc\((\w+)\)\s+(?:\w+\s+)*?(?:protocol|class)\s|^(?:public|open)\s+(?:final\s+)?class\s+(\w+)\s*:\s*NSObject\b/gm,
390
399
  ))
391
- declared.add(objc!)
400
+ declared.add((objc ?? subclass)!)
392
401
  if (declared.size === 0) return null
393
- const built = path.join(moduleRoot, '.build/host', `${name}-Swift.h`)
394
- return {
395
- declared,
396
- header: existsSync(built)
397
- ? clangInterfaceHeader(readFileSync(built, 'utf8'))
398
- : `// ${name}-Swift.h is generated when ${name} builds\n`,
399
- }
402
+ return { declared, header: clangInterfaceHeader(readFileSync(built, 'utf8')) }
400
403
  }
401
404
 
402
405
  // the compiler imports the module that defines a type, and UIKit's declarations
@@ -697,14 +700,16 @@ export function swiftProjectBuildKey(moduleRoot: string, release: string): strin
697
700
  // clang autolinks the library a system module map names when a unit imports
698
701
  // one of its headers, so an ios target links it without declaring it. swiftpm
699
702
  // on wasm reads no clang autolinks, so the target declares the library the ios
700
- // module map names: SQLite3 links sqlite3, which the wasm sdk ships.
703
+ // module map names: SQLite3 links sqlite3 and bzlib.h links bz2, which the wasm
704
+ // sdk ships.
701
705
  const SYSTEM_MODULE_LIBRARIES: Record<string, string> = {
702
706
  'sqlite3.h': 'sqlite3',
703
707
  'sqlite3ext.h': 'sqlite3',
708
+ 'bzlib.h': 'bz2',
704
709
  SQLite3: 'sqlite3',
705
710
  }
706
711
  const SYSTEM_MODULE_IMPORT =
707
- /^\s*(?:#\s*(?:import|include)\s*<(sqlite3(?:ext)?\.h)>|@import\s+(SQLite3)\b)/gm
712
+ /^\s*(?:#\s*(?:import|include)\s*<(sqlite3(?:ext)?\.h|bzlib\.h)>|@import\s+(SQLite3)\b)/gm
708
713
 
709
714
  export function compileTargets(input: SwiftCompileInput): SwiftPackageTarget[] {
710
715
  const manifest = input.files['Package.swift']
@@ -1251,6 +1256,17 @@ export function swiftTargetDependencies(
1251
1256
  const siblings = new Map<string, string[]>()
1252
1257
  for (const target of targets) {
1253
1258
  const prefix = target.path === '.' ? '' : `${target.path}/`
1259
+ const ownsHeader = (header: string) =>
1260
+ [`${prefix}${header}`, `${prefix}include/${header}`].some(
1261
+ (file) =>
1262
+ Object.hasOwn(files, file) &&
1263
+ !targets.some(
1264
+ (candidate) =>
1265
+ candidate.name !== target.name &&
1266
+ candidate.path !== '.' &&
1267
+ file.startsWith(`${candidate.path}/`),
1268
+ ),
1269
+ )
1254
1270
  const deps = new Set(
1255
1271
  (target.dependencies ?? []).flatMap((dependency) =>
1256
1272
  dependency.kind === 'target' &&
@@ -1275,7 +1291,7 @@ export function swiftTargetDependencies(
1275
1291
  const imports = file.endsWith('.swift')
1276
1292
  ? swiftImportNames(contents)
1277
1293
  : SWIFT_NATIVE_SOURCE_EXTENSIONS.some((extension) => file.endsWith(extension))
1278
- ? clangImportNames(contents)
1294
+ ? clangImportNames(contents, ownsHeader)
1279
1295
  : []
1280
1296
  for (const name of imports) {
1281
1297
  if (names.has(name) && name !== target.name) deps.add(name)
@@ -1344,7 +1360,7 @@ const darwinRecordsRegion = (quoted: readonly string[]): string[] =>
1344
1360
  const REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n'
1345
1361
 
1346
1362
  /** bump with any change to the emitted multi-target manifest text. */
1347
- export const MULTI_MANIFEST_VERSION = 64
1363
+ export const MULTI_MANIFEST_VERSION = 65
1348
1364
  const SWIFT_HEADER_PRODUCTS_TARGET = 'PeachHeaderProducts'
1349
1365
 
1350
1366
  // build-cli replaces this in every bundle; source runs read the files directly.
@@ -1440,6 +1456,18 @@ export function swiftArtifactHash(
1440
1456
  return hash.digest('hex')
1441
1457
  }
1442
1458
 
1459
+ const nativeCxxCompilerFlags = ['-fno-cxx-modules']
1460
+
1461
+ // swiftpm gives every clang unit, c++ included, the target's cSettings flags.
1462
+ const cFlagArray = (flags: readonly string[]): string =>
1463
+ JSON.stringify(withoutGlogModuleMap(flags))
1464
+ const cxxFlagArray = (flags: readonly string[]): string =>
1465
+ JSON.stringify([
1466
+ ...nativeCxxCompilerFlags,
1467
+ ...fmtConstantInterpreterFlags(flags),
1468
+ ...withoutGlogModuleMap(flags),
1469
+ ])
1470
+
1443
1471
  interface SwiftNativeTargetPlan {
1444
1472
  path: string
1445
1473
  includeDirectory: string
@@ -1896,16 +1924,16 @@ export function emitSwiftPackageManifest(args: {
1896
1924
  )
1897
1925
  const nativeSettings = native?.clang
1898
1926
  ? [
1899
- `cSettings: [${cDefines} .unsafeFlags(${flagArray(JSON.stringify([...nativeFlags, ...native.clang.flags]))})]`,
1927
+ `cSettings: [${cDefines} .unsafeFlags(${flagArray(cFlagArray([...nativeFlags, ...native.clang.flags]))})]`,
1900
1928
  ...(nativeCxx
1901
1929
  ? [
1902
- `cxxSettings: [${cxxDefines} .unsafeFlags(${flagArray(JSON.stringify(['-fno-cxx-modules', ...cxxFlagsFor(nativeFlags), ...native.clang.cxxFlags]))})]`,
1930
+ `cxxSettings: [${cxxDefines} .unsafeFlags(${flagArray(cxxFlagArray([...cxxFlagsFor(nativeFlags), ...native.clang.cxxFlags]))})]`,
1903
1931
  ]
1904
1932
  : []),
1905
1933
  ].join(', ')
1906
1934
  : [
1907
- `cSettings: [${cDefines}${declaredClangSettings(target, 'c')} .unsafeFlags(${flagArray(JSON.stringify([...nativeFlags, ...(native?.flags ?? [])]))})]`,
1908
- `cxxSettings: [${cxxDefines}${declaredClangSettings(target, 'cxx')} .unsafeFlags(${flagArray(JSON.stringify(['-fno-cxx-modules', ...cxxFlagsFor(nativeFlags), ...(native?.cxxFlags ?? [])]))})]`,
1935
+ `cSettings: [${cDefines}${declaredClangSettings(target, 'c')} .unsafeFlags(${flagArray(cFlagArray([...nativeFlags, ...(native?.flags ?? [])]))})]`,
1936
+ `cxxSettings: [${cxxDefines}${declaredClangSettings(target, 'cxx')} .unsafeFlags(${flagArray(cxxFlagArray([...cxxFlagsFor(nativeFlags), ...(native?.cxxFlags ?? [])]))})]`,
1909
1937
  ].join(', ')
1910
1938
  const exclusions = native?.clang
1911
1939
  ? []
@@ -1992,10 +2020,10 @@ export function emitSwiftPackageManifest(args: {
1992
2020
  ` path: ${JSON.stringify(group.path)},`,
1993
2021
  ` sources: ${JSON.stringify(group.sources)},`,
1994
2022
  ' publicHeadersPath: "include",',
1995
- ` cSettings: [${macroSettings(owner?.cDefines)}${declaredClangSettings(owner, 'c')} .unsafeFlags(${flagArray(JSON.stringify([...nativeFlags, '-I', native.includeDirectory, '-I', args.headerDirectory, ...group.flags]))})],`,
2023
+ ` cSettings: [${macroSettings(owner?.cDefines)}${declaredClangSettings(owner, 'c')} .unsafeFlags(${flagArray(cFlagArray([...nativeFlags, '-I', native.includeDirectory, ...(args.headerDirectory ? ['-I', args.headerDirectory] : []), ...group.flags]))})],`,
1996
2024
  ...(group.sources.some((source) => /\.(?:cc|cpp|cxx|mm)$/.test(source))
1997
2025
  ? [
1998
- ` cxxSettings: [${macroSettings(owner?.cxxDefines)}${declaredClangSettings(owner, 'cxx')} .unsafeFlags(${flagArray(JSON.stringify(['-fno-cxx-modules', ...cxxFlagsFor(nativeFlags), ...group.cxxFlags]))})]),`,
2026
+ ` cxxSettings: [${macroSettings(owner?.cxxDefines)}${declaredClangSettings(owner, 'cxx')} .unsafeFlags(${flagArray(cxxFlagArray([...cxxFlagsFor(nativeFlags), ...group.cxxFlags]))})]),`,
1999
2027
  ]
2000
2028
  : [' ),']),
2001
2029
  ])
@@ -4113,6 +4141,22 @@ export function writeSwiftProject(
4113
4141
  moduleInterfaces.set(name, value)
4114
4142
  return value
4115
4143
  }
4144
+ const podHeaders = new Map<string, { owner: string; content: unknown }[]>()
4145
+ for (const settings of input.nativeTargets ?? [])
4146
+ for (const file of settings.headers) {
4147
+ const owner = /\/Headers\/(?:Public|Private)\/([\w+-]+)\/(?:\1\/)?[^/]+\.h$/.exec(
4148
+ file,
4149
+ )?.[1]
4150
+ if (owner)
4151
+ podHeaders.set(path.basename(file), [
4152
+ ...(podHeaders.get(path.basename(file)) ?? []),
4153
+ { owner, content: input.files[file] },
4154
+ ])
4155
+ }
4156
+ const podHeaderOwner = (file: string, content: unknown): string | undefined =>
4157
+ /\/Headers\/(?:Public|Private)\/([\w+-]+)\//.exec(file)?.[1] ??
4158
+ podHeaders.get(path.basename(file))?.find((header) => header.content === content)
4159
+ ?.owner
4116
4160
  // headers keep their original project paths. an xcode target's product
4117
4161
  // headers additionally occupy the flat Module/Header.h namespace it
4118
4162
  // publishes; a swiftpm target's stay under its public headers directory.
@@ -4126,7 +4170,14 @@ export function writeSwiftProject(
4126
4170
  const frameworkHeader =
4127
4171
  !interfaceModule &&
4128
4172
  /(?:^|\/)(\w+)\.framework\/Headers\/[\w+.-]+\.h$/.exec(file)?.[1]
4129
- const frameworkInterface = frameworkHeader ? moduleInterface(frameworkHeader) : null
4173
+ // a source pod whose module the distribution provides as Swift takes
4174
+ // the declarations Swift owns from the module's interface header. a pod
4175
+ // header is owned by the pod whose public header directory holds it, and
4176
+ // its original source by the same content there.
4177
+ const interfaceOwner =
4178
+ frameworkHeader ||
4179
+ (interfaceModule ? undefined : podHeaderOwner(file, input.files[file]))
4180
+ const frameworkInterface = interfaceOwner ? moduleInterface(interfaceOwner) : null
4130
4181
  const rawContents =
4131
4182
  (interfaceModule && moduleInterface(interfaceModule)?.header) || input.files[file]
4132
4183
  if (rawContents === undefined)
@@ -4136,7 +4187,7 @@ export function writeSwiftProject(
4136
4187
  ? withoutSwiftDeclarations(
4137
4188
  rawContents,
4138
4189
  frameworkInterface.declared,
4139
- `#import <${frameworkHeader}/${frameworkHeader}-Swift.h>`,
4190
+ `#import <${interfaceOwner}/${interfaceOwner}-Swift.h>`,
4140
4191
  )
4141
4192
  : rawContents
4142
4193
  writeBuildFile(destination, contents)
@@ -291,7 +291,24 @@ export function designTimeSites(source: string): DesignTimeSite[] {
291
291
  while (t < to && tokens[t]!.kind !== 'newline') t++
292
292
  continue
293
293
  }
294
- t = text(source, tokens[t + 1]) === '(' ? skipGroup(t + 1) : t + 1
294
+ const availability = word === '#available' || word === '#unavailable'
295
+ t++
296
+ // expression macros may have generic arguments and a trailing closure.
297
+ // their expansion sees syntax, so keep all of that syntax intact.
298
+ if (
299
+ !availability &&
300
+ text(source, tokens[t]) === '<' &&
301
+ tokens[t]!.start === token.end
302
+ ) {
303
+ let depth = 0
304
+ do {
305
+ const p = text(source, tokens[t++])
306
+ if (p === '<') depth++
307
+ else if (p === '>') depth--
308
+ } while (t < to && depth > 0)
309
+ }
310
+ if (text(source, tokens[t]) === '(') t = skipGroup(t)
311
+ if (!availability && text(source, tokens[t]) === '{') t = skipGroup(t)
295
312
  continue
296
313
  }
297
314
  if (token.kind === 'at') {
@@ -1,10 +1,10 @@
1
1
  {
2
- "id": "2b51e77cc1e7cba5",
3
- "release": "swift-6.4.0-RELEASE-custom-f6868fa6054e83d6",
4
- "wasmSdkId": "swift-6.4.0-RELEASE_wasm-peach-9f75fa45",
5
- "wasmSdkUrl": "https://r2.sootsim.com/swift-wasm-sdk/swift-6.4.0-RELEASE_wasm-peach-9f75fa45.artifactbundle.tar.gz",
6
- "wasmSdkChecksum": "8bc5b9435ec5a2b68869fcab354263b2751cc10e8ff02f650e8cd92309e9f82c",
7
- "source": "7751b9cbc577167acb0d74260f74f28bdf0b2419",
2
+ "id": "af69e0877dcfc948",
3
+ "release": "swift-6.4.0-RELEASE-custom-a560ff35bf882b5c",
4
+ "wasmSdkId": "swift-6.4.0-RELEASE_wasm-peach-5d385b68",
5
+ "wasmSdkUrl": "https://r2.sootsim.com/swift-wasm-sdk/swift-6.4.0-RELEASE_wasm-peach-5d385b68.artifactbundle.tar.gz",
6
+ "wasmSdkChecksum": "d91882af99821a296c3db4459896b46ceaef37e9a30caad14e5f24cf6b964ae9",
7
+ "source": "85e7a5155755f4400d2bd7010abdd09f62dd6f34",
8
8
  "targets": [
9
9
  "ImagePlayground",
10
10
  "QuickLookThumbnailing",
@@ -230,16 +230,16 @@
230
230
  },
231
231
  "hosts": {
232
232
  "darwin-arm64": {
233
- "sha256": "2ab6250d5b253169362652ae727832312da92f71d68010e7fca7bd36223dfa48",
234
- "size": 98426889
233
+ "sha256": "dd96208b7ea40e1d8e93d61a716e30191a5e57800074e65837222c042617b96e",
234
+ "size": 99097618
235
235
  },
236
236
  "linux-x64": {
237
- "sha256": "022ed342f51a6c668572a8a1f75d94a91383cf1d28183d0cc79fac4e9229cee8",
238
- "size": 101144410
237
+ "sha256": "bd0ef2a7d0fab414a415a9c2619c0c8c890b792856b1cbdb158a6f74b8d75502",
238
+ "size": 101817050
239
239
  },
240
240
  "linux-arm64": {
241
- "sha256": "cba6d2931a69ba006577bea6111af6bd3a6656d06d0a746af15546fe7181d77a",
242
- "size": 100638534
241
+ "sha256": "37006a7363e6af15a31c65afaa3d6e0480bdd59c5d835f923e44e69dcae81e53",
242
+ "size": 101308927
243
243
  }
244
244
  }
245
245
  }
@@ -319,16 +319,19 @@ export async function resolveSwiftModule({
319
319
  return { root, ...swiftModuleToolchain(root) }
320
320
  }
321
321
 
322
- /** the release a module root was built for and its installed toolchain. */
323
- export function swiftModuleToolchain(root: string): {
324
- release: string
325
- toolchainBin: string
326
- } {
322
+ /** the host compiler selected by a module root, without requiring a guest SDK. */
323
+ export function swiftModuleCompiler(root: string): Omit<SwiftModule, 'root'> {
327
324
  const pin: { release: string } =
328
325
  swiftDistributionAt(root) ??
329
326
  JSON.parse(fs.readFileSync(path.join(root, 'toolchain.json'), 'utf8'))
330
327
  return {
331
328
  release: pin.release,
332
- toolchainBin: swiftToolchain(pin.release, swiftModuleSdk(root)),
329
+ toolchainBin: swiftCompiler(pin.release),
333
330
  }
334
331
  }
332
+
333
+ /** the release a module root was built for and its installed toolchain. */
334
+ export function swiftModuleToolchain(root: string): Omit<SwiftModule, 'root'> {
335
+ const { release } = swiftModuleCompiler(root)
336
+ return { release, toolchainBin: swiftToolchain(release, swiftModuleSdk(root)) }
337
+ }
package/src/swift-host.ts CHANGED
@@ -14,7 +14,6 @@ import {
14
14
  resolveSwiftImageResourceUrls,
15
15
  } from '../../sootsim-swift/src/bundleAssets'
16
16
  import { compileStringCatalog } from '../../sootsim-swift/src/stringCatalog'
17
- import { swiftCacheDir } from './home-paths'
18
17
  import iosSdk from './ios-sdk-frameworks.json' with { type: 'json' }
19
18
  import { type NativeAppIdentity } from './native-app-identity'
20
19
  import { readNativeAppIdentityFromXcodeTarget } from './native-app-identity-project'
@@ -112,7 +111,7 @@ import {
112
111
  type SwiftImageUpload,
113
112
  type SwiftNativeModules,
114
113
  } from './swift-submit'
115
- import { privateSwiftDistributionRoot } from './swift-toolchain'
114
+ import { privateSwiftDistributionRoot, swiftCacheDir } from './swift-toolchain'
116
115
  import { swiftProjectFileProblem } from './swiftContract'
117
116
  import {
118
117
  SWIFT_NATIVE_INPUT_ROOT,
@@ -21,14 +21,17 @@ const leb = (bytes: Uint8Array, at: { offset: number }): number => {
21
21
  }
22
22
  }
23
23
 
24
- // data segment name to its summed size in one wasm object, plus a sentinel when
25
- // the object defines a wasm-exported symbol. the linking section names each
24
+ // data segment name to its summed size in one wasm object, plus sentinels when
25
+ // the object defines a wasm-exported symbol or a named ObjC category. a Swift
26
+ // extension's category fills its segment's empty-terminator size exactly, so
27
+ // only its symbol shows it. the linking section names each
26
28
  // segment and the data section sizes them in the same order.
27
29
  function objcSegmentSizes(bytes: Uint8Array): Map<string, number> {
28
30
  const at = { offset: 8 }
29
31
  const names: string[] = []
30
32
  const sizes: number[] = []
31
33
  let hasExportedSymbol = false
34
+ let definesCategory = false
32
35
  while (at.offset < bytes.length) {
33
36
  const id = bytes[at.offset++]!
34
37
  const size = leb(bytes, at)
@@ -68,6 +71,13 @@ function objcSegmentSizes(bytes: Uint8Array): Map<string, number> {
68
71
  }
69
72
  } else if (symKind === 1) {
70
73
  const sLen = leb(bytes, at)
74
+ if (
75
+ !isUndef &&
76
+ Buffer.from(bytes.subarray(at.offset, at.offset + sLen))
77
+ .toString()
78
+ .startsWith('.objc_category_')
79
+ )
80
+ definesCategory = true
71
81
  at.offset += sLen
72
82
  if (!isUndef) {
73
83
  leb(bytes, at)
@@ -105,6 +115,7 @@ function objcSegmentSizes(bytes: Uint8Array): Map<string, number> {
105
115
  result.set(name, (result.get(name) ?? 0) + (sizes[index] ?? 0))
106
116
  })
107
117
  result.set('__wasm_exported', hasExportedSymbol ? 1 : 0)
118
+ result.set('__objc_category', definesCategory ? 1 : 0)
108
119
  return result
109
120
  }
110
121
 
@@ -12,6 +12,8 @@ import {
12
12
  swiftModuleSdk,
13
13
  swiftModuleDigest,
14
14
  swiftPeachModules,
15
+ swiftDistributionAt,
16
+ FOUNDATION_IMPLICIT_MODULES,
15
17
  } from './swift-compile'
16
18
  import { swiftModuleToolchain } from './swift-distribution'
17
19
  import { swiftClangImporterFlags } from './swift-objc-import'
@@ -22,6 +24,7 @@ import {
22
24
  SWIFT_NATIVE_SOURCE_EXTENSIONS,
23
25
  swiftTargetModuleName,
24
26
  } from './swift-package'
27
+ import { fmtConstantInterpreterFlags } from './swift-package'
25
28
  import { swiftPackageManifest, swiftTargetFiles } from './swift-package-manifest'
26
29
  import { remoteSwiftCheckouts, type SwiftPackageBinary } from './swift-packages'
27
30
  import { readPackageFile, relativeInside } from './swift-source-file'
@@ -808,6 +811,11 @@ export function prepareXcodeSwiftProducts(
808
811
  const sdk = swiftSdkPaths(moduleRoot, toolchain.toolchainBin)
809
812
  const frontend = path.join(toolchain.toolchainBin, 'swift-frontend')
810
813
  const supplied = new Set(swiftPeachModules(moduleRoot))
814
+ // every iOS source sees what darwin's Foundation re-exports, String: CVarArg
815
+ // included. a source checkout builds none of these modules.
816
+ const implicitImports = swiftDistributionAt(moduleRoot)
817
+ ? FOUNDATION_IMPLICIT_MODULES.flatMap((module) => ['-import-module', module])
818
+ : []
811
819
  const modules = path.join(moduleRoot, 'modules')
812
820
  const {
813
821
  sources,
@@ -1100,6 +1108,7 @@ export function prepareXcodeSwiftProducts(
1100
1108
  ...target.swift!.includePaths.flatMap((file) => ['-I', remap(file)]),
1101
1109
  ...clangFlags.flatMap((flag) => ['-Xcc', flag]),
1102
1110
  ...target.defines.flatMap((flag) => ['-D', flag]),
1111
+ ...implicitImports,
1103
1112
  ...(target.mainActorIsolation ? ['-default-isolation', 'MainActor'] : []),
1104
1113
  ...(target.swift!.cxxInterop ? ['-cxx-interoperability-mode=default'] : []),
1105
1114
  ...swiftFlags,
@@ -1520,6 +1529,9 @@ export async function prepareXcodeObjCImplementations(
1520
1529
  ...(objc ? [...swiftObjCRuntimeFlags, '-fobjc-exceptions'] : []),
1521
1530
  ...objcSdkIntakeFlags(headers, toolchain.toolchainBin, minimum),
1522
1531
  ...headerSearch.flags[index]!,
1532
+ ...(cxx
1533
+ ? fmtConstantInterpreterFlags([...flags, ...headerSearch.flags[index]!])
1534
+ : []),
1523
1535
  ...target.includes.flatMap((include) => ['-I', staged(include)]),
1524
1536
  ...target.frameworks.flatMap((framework) => ['-F', staged(framework)]),
1525
1537
  ...moduleMaps[index]!,