peachsim 0.1.1716 → 0.1.1738

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 (282) hide show
  1. package/README.md +21 -3
  2. package/cli/app-bundle-resources.ts +2 -1
  3. package/cli/app-fonts.ts +4 -4
  4. package/cli/app-splash.ts +4 -4
  5. package/cli/app-stubs.ts +17 -0
  6. package/cli/command-registry.ts +1 -0
  7. package/cli/commands/control.ts +83 -822
  8. package/cli/commands/coverage-swift.ts +112 -4
  9. package/cli/commands/daemon.ts +8 -0
  10. package/cli/commands/detox.ts +3 -0
  11. package/cli/commands/doctor.ts +19 -2
  12. package/cli/commands/inspect/actions.ts +74 -14
  13. package/cli/commands/inspect/core.ts +5 -1
  14. package/cli/commands/inspect/settling.ts +5 -2
  15. package/cli/commands/inspect/wait-ready.ts +6 -0
  16. package/cli/commands/inspect.ts +48 -45
  17. package/cli/commands/kotlin.ts +12 -2
  18. package/cli/commands/package.ts +760 -0
  19. package/cli/commands/serve.ts +6 -0
  20. package/cli/commands/shell-url.ts +838 -0
  21. package/cli/commands/swift.ts +42 -102
  22. package/cli/commands/test.ts +20 -0
  23. package/cli/commands/upload.ts +1 -1
  24. package/cli/device-option.ts +1 -1
  25. package/cli/main.ts +13 -1
  26. package/cli/native-input.ts +199 -0
  27. package/cli/outbound-endpoints.ts +26 -1
  28. package/cli/packaged-app-launcher.ts +95 -0
  29. package/cli/scene-video.ts +36 -12
  30. package/detox/index.ts +196 -24
  31. package/dist-lib/agent-daemon-client.cjs +1 -1
  32. package/dist-lib/agent-events.cjs +1 -1
  33. package/dist-lib/attached-projects.cjs +5 -2
  34. package/dist-lib/auth/shared-session.cjs +5 -2
  35. package/dist-lib/backend-origin.cjs +1 -1
  36. package/dist-lib/beta.cjs +1 -1
  37. package/dist-lib/beta.mjs +1 -1
  38. package/dist-lib/bridge-constants.cjs +1 -1
  39. package/dist-lib/bridge-contract-input.cjs +1 -1
  40. package/dist-lib/bridge-contract-input.mjs +1 -1
  41. package/dist-lib/bridge-contract.cjs +1 -1
  42. package/dist-lib/bridge-contract.mjs +1 -1
  43. package/dist-lib/bundle-channel.cjs +39889 -31873
  44. package/dist-lib/capture-contract.cjs +1 -1
  45. package/dist-lib/capture-contract.mjs +1 -1
  46. package/dist-lib/cloud-contract.cjs +1 -1
  47. package/dist-lib/cloud-contract.mjs +1 -1
  48. package/dist-lib/cloud-test-args.cjs +1 -1
  49. package/dist-lib/cloud-test-args.mjs +1 -1
  50. package/dist-lib/cloud.cjs +1 -1
  51. package/dist-lib/cloud.mjs +1 -1
  52. package/dist-lib/config.cjs +1 -1
  53. package/dist-lib/config.mjs +1 -1
  54. package/dist-lib/detox/index.cjs +195 -63
  55. package/dist-lib/dev-bundle-resolution.cjs +14 -13
  56. package/dist-lib/expo-swift-bundle.cjs +18507 -11835
  57. package/dist-lib/expo-swift-metadata.cjs +4 -1
  58. package/dist-lib/expo-swift-metadata.mjs +3 -1
  59. package/dist-lib/home-paths.cjs +27 -3
  60. package/dist-lib/host/bridge-host.cjs +28373 -24090
  61. package/dist-lib/host/fetch-proxy-handler.cjs +235 -225
  62. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  63. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  64. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  65. package/dist-lib/host/websocket-proxy.cjs +1 -1
  66. package/dist-lib/index.cjs +915 -399
  67. package/dist-lib/jump-to-source-babel.cjs +1 -1
  68. package/dist-lib/jump-to-source-native.cjs +1 -1
  69. package/dist-lib/kotlin-host.cjs +335 -47
  70. package/dist-lib/menu.cjs +13 -1
  71. package/dist-lib/menu.mjs +13 -1
  72. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  73. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  74. package/dist-lib/metro-production-bundle.cjs +1 -1
  75. package/dist-lib/metro-production-bundle.mjs +1 -1
  76. package/dist-lib/metro.cjs +918 -411
  77. package/dist-lib/native-app-identity-project.cjs +703 -283
  78. package/dist-lib/native-app-identity-project.mjs +500 -87
  79. package/dist-lib/native-app-identity.cjs +13 -2
  80. package/dist-lib/native-app-identity.mjs +13 -2
  81. package/dist-lib/native-firebase-metadata.cjs +1 -1
  82. package/dist-lib/native-firebase-metadata.mjs +1 -1
  83. package/dist-lib/plist.cjs +1 -1
  84. package/dist-lib/plist.mjs +1 -1
  85. package/dist-lib/profiles.cjs +5 -2
  86. package/dist-lib/public-brand.cjs +1 -1
  87. package/dist-lib/public-origins-lib-esm.json +28 -23
  88. package/dist-lib/public-origins-lib.json +418 -224
  89. package/dist-lib/react-native-host-modules.cjs +35 -2
  90. package/dist-lib/react-native-host-modules.mjs +35 -2
  91. package/dist-lib/reap-browser.cjs +12 -4
  92. package/dist-lib/scripts/dev-server-scanner.cjs +15 -8
  93. package/dist-lib/sdk.cjs +17 -7
  94. package/dist-lib/sdk.mjs +16 -7
  95. package/dist-lib/skills.cjs +44825 -29141
  96. package/dist-lib/swift-compile.cjs +616 -400
  97. package/dist-lib/swift-compile.mjs +528 -315
  98. package/dist-lib/swift-package.cjs +1 -1
  99. package/dist-lib/swift-package.mjs +1 -1
  100. package/dist-lib/swift-submit.cjs +2 -2
  101. package/dist-lib/swift-submit.mjs +2 -2
  102. package/dist-lib/swift-toolchain.cjs +105 -17
  103. package/dist-lib/swift.cjs +1 -1
  104. package/dist-lib/vite-swift.cjs +4660 -2252
  105. package/dist-lib/vite.cjs +248 -234
  106. package/dist-lib/worklet-executable.cjs +1 -1
  107. package/dist-lib/worklet-executable.mjs +1 -1
  108. package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-cookies.d.ts +17 -8
  109. package/dist-types/packages/peach-engine/src/engine/canvaskit-renderer.d.ts +1 -0
  110. package/dist-types/packages/peach-engine/src/engine/font-config.d.ts +7 -4
  111. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +9 -6
  112. package/dist-types/packages/peach-engine/src/engine/liquid-glass.d.ts +0 -5
  113. package/dist-types/packages/peach-engine/src/engine/memory-counts.d.ts +11 -1
  114. package/dist-types/packages/peach-engine/src/engine/node.d.ts +5 -12
  115. package/dist-types/packages/peach-engine/src/engine/render-damage.d.ts +2 -2
  116. package/dist-types/packages/peach-engine/src/engine/text-first-baseline.d.ts +5 -0
  117. package/dist-types/packages/peach-engine/src/engine/text-paragraph.d.ts +1 -0
  118. package/dist-types/packages/peach-engine/src/engine/types.d.ts +3 -0
  119. package/dist-types/packages/peach-engine/src/native-preview-bundle.d.ts +2 -0
  120. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +9 -0
  121. package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +3 -0
  122. package/dist-types/packages/peach-engine/src/render-worker/native-ui-commandContract.d.ts +1 -1
  123. package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +7 -2
  124. package/dist-types/packages/peach-engine/src/render-worker/shell-protocol.d.ts +5 -0
  125. package/dist-types/packages/peach-engine/src/render-worker/tree-sync-port.d.ts +1 -1
  126. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +36 -2
  127. package/dist-types/packages/peach-engine/src/shell-events.d.ts +1 -0
  128. package/dist-types/packages/peach-globals/src/audioBridgeContract.d.ts +5 -0
  129. package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
  130. package/dist-types/packages/peach-globals/src/keyboardBridgeContract.d.ts +11 -0
  131. package/dist-types/packages/peach-globals/src/shellBridgeContract.d.ts +1 -0
  132. package/dist-types/packages/peach-globals/src/testBridgeContract.d.ts +9 -2
  133. package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
  134. package/kotlin/README.md +3 -0
  135. package/kotlin/sdk.tar.gz +0 -0
  136. package/package.json +1 -1
  137. package/runtime-companion.json +1 -1
  138. package/scripts/dev-server-scanner.ts +12 -25
  139. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccount.h +55 -0
  140. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccountCredential.h +35 -0
  141. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccountStore.h +94 -0
  142. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccountType.h +53 -0
  143. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACError.h +37 -0
  144. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/Accounts.h +13 -0
  145. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/AccountsDefines.h +13 -0
  146. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Modules/module.modulemap +5 -0
  147. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASFoundation.h +52 -0
  148. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASWebAuthenticationSession.h +128 -0
  149. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASWebAuthenticationSessionCallback.h +35 -0
  150. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/AuthenticationServices.h +3 -0
  151. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Modules/module.modulemap +5 -0
  152. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFHTTPMessage.h +724 -0
  153. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetwork.h +4 -0
  154. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetworkDefs.h +27 -0
  155. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Modules/module.modulemap +5 -0
  156. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFURL.h +1301 -0
  157. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h +3 -1
  158. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationManager.h +21 -50
  159. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLRegion.h +6 -6
  160. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes +58 -3
  161. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +711 -46
  162. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h +12 -0
  163. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIInterface.h +23 -0
  164. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h +7 -9
  165. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIOrientation.h +14 -0
  166. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIStringDrawing.h +12 -0
  167. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIView.h +14 -0
  168. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIViewAnimating.h +12 -0
  169. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIViewController.h +16 -0
  170. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIWindow.h +2 -0
  171. package/sdk/ios/usr/include/ConditionalMacros.h +619 -0
  172. package/sdk/ios/usr/include/module.modulemap +1 -0
  173. package/sdk/ios/usr/include/objc/objc-sync.h +59 -0
  174. package/sdk/ios/usr/include/os/signpost.h +414 -0
  175. package/sdk/ios/usr/include/os.modulemap +10 -0
  176. package/sdk/ios/usr/include/sys/cdefs.h +5 -0
  177. package/sdk/ios/usr/include/sys/ioccom.h +99 -0
  178. package/sdk/ios/usr/include/sys/syslog.h +236 -0
  179. package/sdk/ios/usr/include/syslog.h +24 -0
  180. package/sdk/ios/wasm/include/errno.h +4 -20
  181. package/sdk/ios/wasm/include/fcntl.h +4 -2
  182. package/sdk/ios/wasm/include/pthread.h +3 -0
  183. package/sdk/ios/wasm/include/setjmp.h +57 -0
  184. package/sdk/ios/wasm/include/stdio.h +24 -0
  185. package/sdk/ios/wasm/include/stdlib.h +32 -7
  186. package/sdk/ios/wasm/include/sys/file.h +7 -0
  187. package/sdk/ios/wasm/include/sys/ioctl.h +6 -0
  188. package/sdk/ios/wasm/include/sys/resource.h +2 -2
  189. package/sdk/ios/wasm/include/sys/syscall.h +9 -0
  190. package/sdk/ios/wasm/include/sys/time.h +10 -0
  191. package/sdk/ios/wasm/include/unistd.h +12 -3
  192. package/sdk/native-hashes.json +4 -3
  193. package/skills/contrast/SKILL.md +2 -1
  194. package/skills/peach-debug/SKILL.md +0 -1
  195. package/skills/peach-perf/SKILL.md +0 -1
  196. package/skills/peach-setup/SKILL.md +0 -1
  197. package/skills/peach-test/SKILL.md +7 -4
  198. package/skills/peach-visual/SKILL.md +0 -1
  199. package/src/admitted-mac-build.ts +3 -0
  200. package/src/android-app-identity.ts +18 -0
  201. package/src/android-autolinking.ts +1 -0
  202. package/src/android-bridge-packages.ts +279 -0
  203. package/src/android-root-module.ts +9 -9
  204. package/src/appPackageContract.ts +83 -0
  205. package/src/bridge-contract.ts +50 -0
  206. package/src/bundle-channel.mjs +41 -6
  207. package/src/cli-runtime.ts +9 -5
  208. package/src/dev-bundle-resolution.ts +7 -27
  209. package/src/dom-source-reference.ts +15 -0
  210. package/src/expo-discovery-cache.ts +134 -26
  211. package/src/expo-kotlin-host.ts +97 -26
  212. package/src/expo-manifest-body.ts +33 -0
  213. package/src/expo-native-workspace.ts +158 -38
  214. package/src/expo-swift-host.ts +350 -75
  215. package/src/expo-swift-ready.ts +5 -1
  216. package/src/expoKotlinContract.ts +12 -2
  217. package/src/expoSwiftContract.ts +10 -0
  218. package/src/generated/swift-c-predefines.json +1 -1
  219. package/src/home-paths.ts +41 -2
  220. package/src/host/app-package-handler.ts +47 -0
  221. package/src/host/bridge-host.ts +8 -0
  222. package/src/host/fetch-proxy-handler.ts +10 -0
  223. package/src/host/staged-host-files.ts +18 -0
  224. package/src/index.ts +3 -0
  225. package/src/kotlin-host.ts +225 -48
  226. package/src/kotlin-instance-source.ts +126 -0
  227. package/src/kotlinSdkContract.ts +2 -1
  228. package/src/menu.ts +14 -0
  229. package/src/native-app-identity-project.ts +7 -2
  230. package/src/native-app-identity.ts +11 -0
  231. package/src/native-firebase-config.ts +24 -1
  232. package/src/native-prebuilt.ts +154 -0
  233. package/src/nitro-adapter.lock.json +270 -270
  234. package/src/nitro-adapter.ts +56 -50
  235. package/src/nitro-bundle.ts +92 -74
  236. package/src/nitro-compile.ts +45 -14
  237. package/src/nitro-dependencies.ts +63 -46
  238. package/src/nitro-source.ts +64 -26
  239. package/src/nitroAdapterContract.ts +146 -98
  240. package/src/nitroContract.ts +71 -21
  241. package/src/react-native-bridge-modules.ts +70 -42
  242. package/src/react-native-host-modules.ts +34 -1
  243. package/src/reactNativeConfigurationContract.ts +14 -0
  244. package/src/reap-browser.ts +15 -3
  245. package/src/sdk.ts +5 -0
  246. package/src/settingsContract.ts +38 -1
  247. package/src/sim-client.ts +4 -1
  248. package/src/storageSnapshotContract.ts +32 -81
  249. package/src/swift-compile.ts +268 -89
  250. package/src/swift-coverage/indexdump.ts +22 -6
  251. package/src/swift-coverage/indexing.ts +4 -4
  252. package/src/swift-coverage/provenance.ts +1 -0
  253. package/src/swift-coverage/sdk.ts +104 -20
  254. package/src/swift-coverage/types.ts +34 -0
  255. package/src/swift-coverage/xcode-asset-symbols.ts +922 -0
  256. package/src/swift-coverage/xcode-assets.ts +89 -131
  257. package/src/swift-coverage/xcode.ts +10 -2
  258. package/src/swift-cxx-reachable.ts +2 -1
  259. package/src/swift-distribution.lock.json +20 -16
  260. package/src/swift-host.ts +98 -22
  261. package/src/swift-icu.ts +1 -1
  262. package/src/swift-link-roots.ts +118 -0
  263. package/src/swift-objc-compile.ts +144 -22
  264. package/src/swift-objc-import.ts +6 -0
  265. package/src/swift-objc-standin.ts +2 -14
  266. package/src/swift-package-manifest.ts +14 -6
  267. package/src/swift-packages.ts +75 -11
  268. package/src/swift-pdf-raster.ts +1 -0
  269. package/src/swift-root-lock.ts +17 -1
  270. package/src/swift-source-pods.ts +2 -10
  271. package/src/swift-standin-emit.ts +597 -57
  272. package/src/swift-standins.ts +599 -56
  273. package/src/swift-submit.ts +7 -1
  274. package/src/swift-toolchain.ts +140 -17
  275. package/src/turbo-bundle.ts +81 -0
  276. package/src/turbo-codegen-intake.ts +91 -0
  277. package/src/turbo-compile.ts +120 -0
  278. package/src/turbo-runtime.lock.json +69 -0
  279. package/src/turbo-source.ts +754 -0
  280. package/src/vite-plugin-one.ts +17 -12
  281. package/src/vite-plugin.ts +28 -15
  282. package/src/xcode-project.ts +223 -22
@@ -16,6 +16,7 @@ import {
16
16
  renameSync,
17
17
  rmSync,
18
18
  statSync,
19
+ symlinkSync,
19
20
  utimesSync,
20
21
  writeFileSync,
21
22
  } from 'node:fs'
@@ -23,7 +24,7 @@ import os from 'node:os'
23
24
  import path from 'node:path'
24
25
  import { admittedMacBuilderSlot } from './admitted-mac-build'
25
26
  import cPredefinesJson from './generated/swift-c-predefines.json' with { type: 'json' }
26
- import { rnxHomeDir, swiftPackageCacheOptions } from './home-paths'
27
+ import { swiftCacheDir, swiftPackageCacheOptions } from './home-paths'
27
28
  import { terminateProcessGroup } from './process-group'
28
29
  import { swiftCompilerSourceDigest } from './swift-compiler-digest'
29
30
  import { designTimeDiagnostic, designTimeSource } from './swift-design-time'
@@ -33,7 +34,12 @@ import {
33
34
  type SwiftDistributionManifest,
34
35
  } from './swift-distribution-contract'
35
36
  import { swiftIcuAsset, type SwiftIcuAsset } from './swift-icu'
36
- import { SWIFT_OBJC_INTEROP_FLAGS, swiftObjCModuleMap } from './swift-objc-import'
37
+ import { swiftObjcRootObjects } from './swift-link-roots'
38
+ import {
39
+ SWIFT_OBJC_INTEROP_FLAGS,
40
+ swiftClangImporterFlags,
41
+ swiftObjCModuleMap,
42
+ } from './swift-objc-import'
37
43
  import { swiftObjCRuntimeFlags } from './swift-objc-runtime'
38
44
  import { iosDeploymentMinimum, objcSdkIntakeFlags } from './swift-objc-standin'
39
45
  import {
@@ -56,7 +62,7 @@ import {
56
62
  type SwiftPackageTarget,
57
63
  } from './swift-package'
58
64
  import { withSwiftRootLock, type SwiftRootLease } from './swift-root-lock'
59
- import { swiftSharedSdkInputFiles } from './swift-shared-sdk'
65
+ import { swiftSharedSdkInputFiles, swiftSharedSdkRoot } from './swift-shared-sdk'
60
66
  import {
61
67
  sourceSwiftCheckout,
62
68
  SWIFT_AUTOLINK_LINKER,
@@ -215,6 +221,8 @@ export interface SwiftCompileInput {
215
221
  projectFiles?: Record<string, string>
216
222
  packageGuestImports?: string[]
217
223
  nativeTargets?: SwiftNativeTarget[]
224
+ /** the Xcode app project's development region, for the emitted manifest's default localization. */
225
+ defaultLocalization?: string
218
226
  metalSources?: Record<string, string>
219
227
  resources?: Record<string, string>
220
228
  /** project-relative resource paths retained before the bundle namespace flattens. */
@@ -234,6 +242,11 @@ export interface SwiftCompileInput {
234
242
  * replace the stand-in's traps.
235
243
  */
236
244
  libraries?: Record<string, string>
245
+ /**
246
+ * link the distribution as an archive: only the objects the program
247
+ * references by symbol, plus those that register ObjC classes at load.
248
+ */
249
+ lazyDistribution?: boolean
237
250
  }
238
251
 
239
252
  // the builder hop wraps the compiler's own timeout with admission, transfer and
@@ -305,6 +318,7 @@ export function swiftModuleInputFiles(root: string): string[] {
305
318
  ...swiftSharedSdkInputFiles(root),
306
319
  '../peachsim/src/swift-shared-sdk.ts',
307
320
  '../../scripts/generate/swift-sdk-module/darwin-mach.json',
321
+ '../../scripts/ops/swift-distribution-publish.ts',
308
322
  'Package.swift',
309
323
  'scripts/contrast-app-Package.swift',
310
324
  'scripts/build-distribution.ts',
@@ -505,6 +519,8 @@ export function withNativeSourceGlue(
505
519
 
506
520
  // optional families link only into an app whose sources import them, each
507
521
  // with the optional families it depends on (packages/sootsim-swift/Package.swift).
522
+ // a family a base framework depends on is base too: CoreGraphics decodes
523
+ // through PeachCodec, so PeachCodec links into every app.
508
524
  const OPTIONAL_FRAMEWORK_DEPENDENCIES: Record<string, string[]> = {
509
525
  GameplayKit: [],
510
526
  simd: [],
@@ -516,9 +532,8 @@ const OPTIONAL_FRAMEWORK_DEPENDENCIES: Record<string, string[]> = {
516
532
  ImagePlayground: [],
517
533
  QuickLookThumbnailing: [],
518
534
  libxml2: [],
519
- Compression: ['PeachCodec'],
520
- zlib: ['PeachCodec'],
521
- PeachCodec: [],
535
+ Compression: [],
536
+ zlib: [],
522
537
  TikTokBusinessSDK: [],
523
538
  nSure: [],
524
539
  Statsig: [],
@@ -893,6 +908,80 @@ export function missingSwiftModules(
893
908
  return new Map([...missing].sort(([left], [right]) => left.localeCompare(right)))
894
909
  }
895
910
 
911
+ /**
912
+ * the clang module names and plain C headers a package's `.systemLibrary`
913
+ * targets own. a system target's clang module name need not match its SwiftPM
914
+ * target name, and its headers need not be provided by the distribution.
915
+ */
916
+ export function swiftSystemLibrarySurface(
917
+ files: Record<string, string>,
918
+ targets: readonly Pick<SwiftPackageTarget, 'path' | 'systemLibrary'>[],
919
+ ): { modules: Set<string>; headers: Set<string> } {
920
+ const modules = new Set<string>()
921
+ const headers = new Set<string>()
922
+ for (const target of targets) {
923
+ if (!target.systemLibrary) continue
924
+ const prefix = target.path === '.' ? '' : `${target.path.replace(/\/+$/, '')}/`
925
+ for (const [file, contents] of Object.entries(files)) {
926
+ if (!file.startsWith(prefix) || !file.endsWith('.modulemap')) continue
927
+ for (const match of contents.matchAll(/^\s*module\s+([A-Za-z_]\w*)/gm))
928
+ modules.add(match[1]!)
929
+ for (const match of contents.matchAll(/^\s*(?:umbrella\s+)?header\s+"([^"]+)"/gm)) {
930
+ const header = files[`${prefix}${match[1]}`]
931
+ if (header === undefined) continue
932
+ for (const include of header.matchAll(/#\s*(?:include|import)\s*<([^>/]+)>/g))
933
+ headers.add(include[1]!.replace(/\.h$/, ''))
934
+ }
935
+ }
936
+ }
937
+ return { modules, headers }
938
+ }
939
+
940
+ /**
941
+ * distribution modules a local system library must win over. a distribution
942
+ * module or a header it owns would otherwise satisfy the system target's
943
+ * `#include`, replacing the target SDK's declarations with the distribution's.
944
+ */
945
+ export function swiftSystemLibraryExclusions(
946
+ files: Record<string, string>,
947
+ targets: readonly Pick<SwiftPackageTarget, 'path' | 'systemLibrary'>[],
948
+ distributionModules: readonly string[],
949
+ ): Set<string> {
950
+ const surface = swiftSystemLibrarySurface(files, targets)
951
+ return new Set(
952
+ distributionModules.filter(
953
+ (name) => surface.modules.has(name) || surface.headers.has(name),
954
+ ),
955
+ )
956
+ }
957
+
958
+ /** a distribution modules path without the modules a local system library owns. */
959
+ function distributionModulesPath(
960
+ root: string,
961
+ moduleRoot: string,
962
+ excluded: ReadonlySet<string> | undefined,
963
+ ): string {
964
+ const modules = path.join(moduleRoot, 'modules')
965
+ if (!excluded || excluded.size === 0) return modules
966
+ const key = createHash('sha256')
967
+ .update([...excluded].sort().join('\0'))
968
+ .digest('hex')
969
+ .slice(0, 16)
970
+ const directory = path.join(root, `.peach-modules-${key}`)
971
+ const complete = path.join(directory, '.complete')
972
+ if (!existsSync(complete)) {
973
+ mkdirSync(directory, { recursive: true })
974
+ for (const entry of readdirSync(directory))
975
+ rmSync(path.join(directory, entry), { recursive: true, force: true })
976
+ for (const entry of readdirSync(modules)) {
977
+ if (excluded.has(entry.replace(/\.swiftmodule$/, ''))) continue
978
+ symlinkSync(path.join(modules, entry), path.join(directory, entry))
979
+ }
980
+ writeFileSync(complete, '')
981
+ }
982
+ return directory
983
+ }
984
+
896
985
  export function swiftTargetDependencies(
897
986
  files: Record<string, string>,
898
987
  targets: Pick<SwiftPackageTarget, 'name' | 'path' | 'dependencies'>[],
@@ -978,11 +1067,13 @@ const executableLinkFlags = (root: string) => ` "-Xclang-linker", "-O0"
978
1067
  "-Xlinker", "--stack-first",
979
1068
  "-Xlinker", "--global-base=8372224",
980
1069
  "-Xlinker", "-lsetjmp",
1070
+ "-Xlinker", "--export-table",
1071
+ "-Xlinker", "--growable-table",
981
1072
  `
982
1073
  const REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n'
983
1074
 
984
1075
  /** bump with any change to the emitted multi-target manifest text. */
985
- export const MULTI_MANIFEST_VERSION = 46
1076
+ export const MULTI_MANIFEST_VERSION = 50
986
1077
 
987
1078
  // build-cli replaces this in every bundle; source runs read the files directly.
988
1079
  declare const __SWIFT_COMPILER_DIGEST__: string | undefined
@@ -1001,6 +1092,7 @@ export function swiftArtifactHash(
1001
1092
  hash.update(compilerSourceDigest)
1002
1093
  if (input.oneModule) hash.update('one-module\n')
1003
1094
  hash.update(swiftModuleDigest(moduleRoot))
1095
+ if (input.lazyDistribution) hash.update('lazy-distribution\n')
1004
1096
  for (const file of Object.keys(input.files).sort()) {
1005
1097
  hash.update(createHash('sha256').update(file).digest())
1006
1098
  hash.update(createHash('sha256').update(input.files[file]).digest())
@@ -1040,6 +1132,8 @@ export function swiftArtifactHash(
1040
1132
  )
1041
1133
  hash.update(JSON.stringify(input.nativeTargets ?? []))
1042
1134
  hash.update(JSON.stringify(input.packageGuestImports ?? []))
1135
+ if (input.defaultLocalization)
1136
+ hash.update(`default-localization\n${input.defaultLocalization}\n`)
1043
1137
  for (const file of Object.keys(input.packageFiles ?? {}).sort()) {
1044
1138
  hash.update(`package-file\0${file}\0`)
1045
1139
  hash.update(createHash('sha256').update(input.packageFiles![file]!).digest())
@@ -1161,8 +1255,16 @@ export function emitSwiftPackageManifest(args: {
1161
1255
  spriteKit?: boolean
1162
1256
  /** link the prebuilt distribution at moduleRoot instead of its sources. */
1163
1257
  distribution?: SwiftDistributionManifest
1164
- /** ordered distribution objects, read by the linker without expanding argv. */
1258
+ /** distribution modules a local system library must win over. */
1259
+ distributionExcludes?: ReadonlySet<string>
1260
+ /**
1261
+ * ordered distribution objects, read by the linker without expanding argv.
1262
+ * absent when no source reaches a distribution framework: the executable
1263
+ * then links only the stdlib and system archives its sources reference.
1264
+ */
1165
1265
  distributionLink?: { path: string; files: Map<string, string | Buffer> }
1266
+ /** link the distribution objects other than its ObjC registrants lazily. */
1267
+ lazyDistribution?: boolean
1166
1268
  /**
1167
1269
  * framework products already built in their own scratch. objects link whole,
1168
1270
  * and modules import from that scratch, so this package's targets never
@@ -1173,6 +1275,8 @@ export function emitSwiftPackageManifest(args: {
1173
1275
  libraries?: Map<string, string>
1174
1276
  /** the sdk toolset already searches libc++ before the darwin overlay. */
1175
1277
  deferDarwinOverlay?: boolean
1278
+ /** the development region SwiftPM needs as defaultLocalization beside localized resources. */
1279
+ defaultLocalization?: string
1176
1280
  }): string {
1177
1281
  const { targets, siblings, moduleRoot, oneModule, spriteKit, distribution } = args
1178
1282
  const prebuilt = args.prebuilt
@@ -1196,26 +1300,37 @@ export function emitSwiftPackageManifest(args: {
1196
1300
  }
1197
1301
  // the distribution builder names each object lib/<target>-<file>.o.
1198
1302
  // preserve link order while leaving unreached optional module objects out.
1303
+ // the list is named by its content: SwiftPM relinks when the linker
1304
+ // command changes, never when a file the command reads does.
1305
+ let distributionLinkPath: string | undefined
1199
1306
  const distributionLink = args.distributionLink
1200
- if (distribution && !distributionLink)
1201
- throw new Error(
1202
- 'swift-compile: distribution linking requires its object response file',
1203
- )
1204
1307
  if (distribution && distributionLink) {
1205
1308
  const objects = distribution.objects.filter((object) =>
1206
1309
  [...OPTIONAL_FRAMEWORKS, 'SpriteKit', 'PeachBox2D'].every(
1207
1310
  (name) => !object.startsWith(`lib/${name}-`) || reachedFrameworks.has(name),
1208
1311
  ),
1209
1312
  )
1210
- distributionLink.files.set(
1211
- distributionLink.path,
1212
- objects
1213
- .map(
1214
- (object) =>
1215
- `"${path.join(moduleRoot, object).replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"`,
1216
- )
1217
- .join('\n') + '\n',
1313
+ const quoted = (object: string) =>
1314
+ `"${path.join(moduleRoot, object).replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"`
1315
+ const roots = args.lazyDistribution
1316
+ ? swiftObjcRootObjects(distribution.id, moduleRoot, distribution.objects)
1317
+ : null
1318
+ // an archive region loads an object only when a loaded one references it
1319
+ const list =
1320
+ (roots
1321
+ ? [
1322
+ ...objects.filter((object) => roots.has(object)).map(quoted),
1323
+ '-Wl,--start-lib',
1324
+ ...objects.filter((object) => !roots.has(object)).map(quoted),
1325
+ '-Wl,--end-lib',
1326
+ ]
1327
+ : objects.map(quoted)
1328
+ ).join('\n') + '\n'
1329
+ distributionLinkPath = distributionLink.path.replace(
1330
+ /\.rsp$/,
1331
+ `-${createHash('sha256').update(list).digest('hex').slice(0, 12)}.rsp`,
1218
1332
  )
1333
+ distributionLink.files.set(distributionLinkPath, list)
1219
1334
  }
1220
1335
  const overlayFlags = swiftCrossImportFlags(moduleRoot, Boolean(distribution))
1221
1336
  .map((flag) => `, ${JSON.stringify(flag)}`)
@@ -1265,7 +1380,9 @@ export function emitSwiftPackageManifest(args: {
1265
1380
  // the file opaquely so swift neither expands it nor scans every framework
1266
1381
  // object for autolinks; distribution.link supplies those libraries.
1267
1382
  const imports = distribution
1268
- ? `, "-I", ${JSON.stringify(path.join(moduleRoot, 'modules'))}`
1383
+ ? `, "-I", ${JSON.stringify(
1384
+ distributionModulesPath(args.root, moduleRoot, args.distributionExcludes),
1385
+ )}`
1269
1386
  : prebuilt
1270
1387
  ? `, "-I", ${JSON.stringify(prebuilt.modules)}${prebuilt.moduleMaps
1271
1388
  .map((map) => `, "-Xcc", ${JSON.stringify(`-fmodule-map-file=${map}`)}`)
@@ -1378,16 +1495,20 @@ export function emitSwiftPackageManifest(args: {
1378
1495
  ),
1379
1496
  ]),
1380
1497
  ].join(', ')
1381
- const library =
1382
- distribution && distributionLink
1383
- ? ['-Xclang-linker', `--config=${distributionLink.path}`, ...distribution.link]
1498
+ const library = distribution
1499
+ ? [
1500
+ ...(distributionLinkPath
1501
+ ? ['-Xclang-linker', `--config=${distributionLinkPath}`]
1502
+ : []),
1503
+ ...distribution.link,
1504
+ ]
1505
+ .map((flag) => `, ${JSON.stringify(flag)}`)
1506
+ .join('')
1507
+ : prebuilt
1508
+ ? ['-Xclang-linker', `--config=${prebuilt.linkFile}`, ...prebuilt.link]
1384
1509
  .map((flag) => `, ${JSON.stringify(flag)}`)
1385
1510
  .join('')
1386
- : prebuilt
1387
- ? ['-Xclang-linker', `--config=${prebuilt.linkFile}`, ...prebuilt.link]
1388
- .map((flag) => `, ${JSON.stringify(flag)}`)
1389
- .join('')
1390
- : ''
1511
+ : ''
1391
1512
  const kind = target.executable ? '.executableTarget' : '.target'
1392
1513
  const linkedLibraries = (target.linkedLibraries ?? []).map(
1393
1514
  (name) => `.linkedLibrary(${JSON.stringify(name)})`,
@@ -1464,6 +1585,9 @@ export function emitSwiftPackageManifest(args: {
1464
1585
  '// generated by swift-compile from the project package partition.',
1465
1586
  'let package = Package(',
1466
1587
  ' name: "app",',
1588
+ ...(args.defaultLocalization
1589
+ ? [` defaultLocalization: ${JSON.stringify(args.defaultLocalization)},`]
1590
+ : []),
1467
1591
  ` products: [.executable(name: "${executable.name}", targets: ["${executable.name}"])],`,
1468
1592
  ` dependencies: [${[
1469
1593
  ...(linkedObjects ? [] : [`.package(path: ${JSON.stringify(moduleRoot)})`]),
@@ -1521,6 +1645,7 @@ export function syncSwiftTree(base: string, files: Map<string, string | Buffer>)
1521
1645
  if (
1522
1646
  dir === base &&
1523
1647
  (entry.name === '.build' ||
1648
+ entry.name.startsWith('.peach-modules-') ||
1524
1649
  entry.name === SWIFT_LINK_STAMP ||
1525
1650
  entry.name === SWIFT_FRAMEWORK_KEY)
1526
1651
  )
@@ -1566,7 +1691,7 @@ const DELEGATE_CLASS =
1566
1691
  // init(style:reuseIdentifier:) and the header footer view's
1567
1692
  // init(reuseIdentifier:).
1568
1693
  const REUSABLE_INIT =
1569
- /^override(?=\s+init\s*\(\s*(?:style\s*:[^,)]*,\s*reuseIdentifier|reuseIdentifier)\s*:)/
1694
+ /^override(?=\s+(?:(?:public|open|internal)\s+)?init\s*\(\s*(?:style\s*:[^,)]*,\s*reuseIdentifier|reuseIdentifier)\s*:)/
1570
1695
  // a collection view makes its cells and supplementary views with
1571
1696
  // init(frame:), so inside a class that inherits from one, directly or
1572
1697
  // through a class declared earlier in the file, an override of it says
@@ -1770,34 +1895,12 @@ export function swiftCodeMask(source: string): string {
1770
1895
 
1771
1896
  // darwin declares these in Foundation; the guest networking module owns them.
1772
1897
  const FOUNDATION_NETWORKING_TYPES = new Set([
1773
- 'CachedURLResponse',
1774
- 'HTTPCookieStorage',
1775
- 'NSMutableURLRequest',
1776
1898
  'NSURLConnection',
1777
1899
  'NSURLConnectionDataDelegate',
1778
1900
  'NSURLConnectionDelegate',
1779
1901
  'NSURLConnectionDownloadDelegate',
1780
- 'URLCache',
1781
- 'URLCredentialStorage',
1782
1902
  'URLProtocol',
1783
1903
  'URLProtocolClient',
1784
- 'URLRequest',
1785
- 'URLSession',
1786
- 'URLSessionConfiguration',
1787
- 'URLSessionDataDelegate',
1788
- 'URLSessionDataTask',
1789
- 'URLSessionDelegate',
1790
- 'URLSessionDownloadDelegate',
1791
- 'URLSessionDownloadTask',
1792
- 'URLSessionStreamDelegate',
1793
- 'URLSessionStreamTask',
1794
- 'URLSessionTask',
1795
- 'URLSessionTaskDelegate',
1796
- 'URLSessionTaskMetrics',
1797
- 'URLSessionTaskTransactionMetrics',
1798
- 'URLSessionUploadTask',
1799
- 'URLSessionWebSocketDelegate',
1800
- 'URLSessionWebSocketTask',
1801
1904
  ])
1802
1905
 
1803
1906
  // Foundation overlay declarations live in the shared guest overlay module.
@@ -1825,6 +1928,7 @@ const FOUNDATION_OVERLAY_TYPES = new Set([
1825
1928
  'NSCollectionChangeType',
1826
1929
  'NSConditionLock',
1827
1930
  'NSDataDetector',
1931
+ 'NSErrorPointer',
1828
1932
  'NSException',
1829
1933
  'NSExtensionContext',
1830
1934
  'NSExtensionItem',
@@ -2466,6 +2570,26 @@ const CORE_FOUNDATION_HANDLE_IMPORTS = [
2466
2570
  ])
2467
2571
  .join('; ')
2468
2572
 
2573
+ // the guest module that owns a name darwin's Foundation declares
2574
+ export function foundationOwnerOf(name: string): string | undefined {
2575
+ if (
2576
+ name === 'NSClassFromString' ||
2577
+ name === 'NSKeyValueChange' ||
2578
+ name === 'NSKeyValueObservedChange' ||
2579
+ name === 'NSKeyValueObservation'
2580
+ )
2581
+ return 'PeachObjC'
2582
+ if (name === 'DispatchData') return 'Dispatch'
2583
+ if (FOUNDATION_NETWORKING_TYPES.has(name)) return 'FoundationNetworking'
2584
+ if (
2585
+ FOUNDATION_OVERLAY_TYPES.has(name) ||
2586
+ FOUNDATION_OVERLAY_GLOBALS.has(name) ||
2587
+ CORE_FOUNDATION_OVERLAY_GLOBALS.has(name)
2588
+ )
2589
+ return 'PeachFoundation'
2590
+ return undefined
2591
+ }
2592
+
2469
2593
  export function swiftSourceAsIOS(source: string): string {
2470
2594
  const { lineStarts, tokens } = swiftCodeScan(source)
2471
2595
  let offset = 0
@@ -2541,25 +2665,8 @@ export function swiftSourceAsIOS(source: string): string {
2541
2665
  const foundationMember =
2542
2666
  /^Foundation\s*\.\s*(?:`([A-Za-z_]\w*)`|([A-Za-z_]\w*)\b)/.exec(rest)
2543
2667
  const foundationName = foundationMember?.[1] ?? foundationMember?.[2]
2544
- let foundationOwner: string | undefined
2545
- if (foundationName !== undefined) {
2546
- if (
2547
- foundationName === 'NSClassFromString' ||
2548
- foundationName === 'NSKeyValueChange' ||
2549
- foundationName === 'NSKeyValueObservedChange' ||
2550
- foundationName === 'NSKeyValueObservation'
2551
- )
2552
- foundationOwner = 'PeachObjC'
2553
- else if (foundationName === 'DispatchData') foundationOwner = 'Dispatch'
2554
- else if (FOUNDATION_NETWORKING_TYPES.has(foundationName))
2555
- foundationOwner = 'FoundationNetworking'
2556
- else if (
2557
- FOUNDATION_OVERLAY_TYPES.has(foundationName) ||
2558
- FOUNDATION_OVERLAY_GLOBALS.has(foundationName) ||
2559
- CORE_FOUNDATION_OVERLAY_GLOBALS.has(foundationName)
2560
- )
2561
- foundationOwner = 'PeachFoundation'
2562
- }
2668
+ const foundationOwner =
2669
+ foundationName === undefined ? undefined : foundationOwnerOf(foundationName)
2563
2670
  if (foundationOwner !== undefined) {
2564
2671
  out += conditioned.slice(copied, at) + foundationOwner
2565
2672
  copied = at + 'Foundation'.length
@@ -2705,6 +2812,18 @@ export function swiftApplicationEntry(file: string, source: string): boolean {
2705
2812
  return false
2706
2813
  }
2707
2814
 
2815
+ // a typed entry: @main on a struct, class or enum in a branch the wasm
2816
+ // compile reaches. inactive #if branches cannot introduce an entry.
2817
+ export function swiftTypedApplicationEntry(
2818
+ source: string,
2819
+ ): { index: number; name: string } | null {
2820
+ const code = [...swiftConditionalLines(swiftCodeMask(source))]
2821
+ .map(({ line, active }) => (active === false ? ' '.repeat(line.length) : line))
2822
+ .join('\n')
2823
+ const match = /@main\b[\s\S]*?\b(?:struct|class|enum)\s+([A-Za-z_]\w*)/.exec(code)
2824
+ return match ? { index: match.index, name: match[1]! } : null
2825
+ }
2826
+
2708
2827
  // a main.swift entry calls UIApplicationMain at file scope. a mixed target
2709
2828
  // becomes a library, which cannot run that statement as process entry, so the
2710
2829
  // call moves into the function the generated executable runs after linking.
@@ -3307,6 +3426,9 @@ export function writeSwiftProject(
3307
3426
  },
3308
3427
  ]
3309
3428
  : compileTargets(input)
3429
+ const distributionExcludes = distribution
3430
+ ? swiftSystemLibraryExclusions(input.files, targets, distribution.modules)
3431
+ : undefined
3310
3432
  const files = new Map<string, string | Buffer>()
3311
3433
  const native = new Map<string, SwiftNativeTargetPlan>()
3312
3434
  const targetFailures: string[] = []
@@ -3324,15 +3446,23 @@ export function writeSwiftProject(
3324
3446
  // swiftpm builds a clang target's module only for an importer: a swift
3325
3447
  // import, or a framework-style include or @import in any original source.
3326
3448
  const importedModules = new Set<string>()
3449
+ const swiftImportedModules = new Set<string>()
3450
+ const clangImportedModules = new Set<string>()
3327
3451
  for (const [file, contents] of Object.entries(input.files)) {
3328
3452
  if (file.endsWith('.swift'))
3329
- for (const name of swiftImportNames(contents)) importedModules.add(name)
3453
+ for (const name of swiftImportNames(contents)) {
3454
+ importedModules.add(name)
3455
+ swiftImportedModules.add(name)
3456
+ }
3330
3457
  else if (
3331
3458
  SWIFT_NATIVE_SOURCE_EXTENSIONS.some(
3332
3459
  (extension) => extension !== '.modulemap' && file.endsWith(extension),
3333
3460
  )
3334
3461
  )
3335
- for (const name of clangImportNames(contents)) importedModules.add(name)
3462
+ for (const name of clangImportNames(contents)) {
3463
+ importedModules.add(name)
3464
+ clangImportedModules.add(name)
3465
+ }
3336
3466
  }
3337
3467
  const headerDirectory = path.join(layout.root, '.build', 'peach-cxx-headers')
3338
3468
  let checkedToolchain: string | undefined
@@ -3758,7 +3888,7 @@ export function writeSwiftProject(
3758
3888
  allowExisting: true,
3759
3889
  })
3760
3890
  const importFlags = [
3761
- ...stageFlags(importOriginalFlags, sdkInclude),
3891
+ ...swiftClangImporterFlags(stageFlags(importOriginalFlags, sdkInclude)),
3762
3892
  '-fmodule-map-file=' + path.join(layout.root, modulemap),
3763
3893
  ...clangImportModuleMapFlags(settings, layout.root, importModuleMaps),
3764
3894
  ]
@@ -4047,10 +4177,8 @@ export function writeSwiftProject(
4047
4177
  ),
4048
4178
  )
4049
4179
  const mains = entries.flatMap(([file, source]) => {
4050
- const match = /@main\b[\s\S]*?\b(?:struct|class|enum)\s+([A-Za-z_]\w*)/.exec(
4051
- swiftCodeMask(source),
4052
- )
4053
- return match ? [{ file, source, match }] : []
4180
+ const entry = swiftTypedApplicationEntry(source)
4181
+ return entry ? [{ file, source, ...entry }] : []
4054
4182
  })
4055
4183
  let entryFile: string
4056
4184
  let entrySource: string
@@ -4058,10 +4186,10 @@ export function writeSwiftProject(
4058
4186
  const main = mains[0]!
4059
4187
  entryFile = main.file
4060
4188
  entrySource =
4061
- main.source.slice(0, main.match.index) +
4189
+ main.source.slice(0, main.index) +
4062
4190
  ' ' +
4063
- main.source.slice(main.match.index + 5) +
4064
- `\n@MainActor public func __peachRunApplication() { ${main.match[1]}.main() }\n`
4191
+ main.source.slice(main.index + 5) +
4192
+ `\n@MainActor public func __peachRunApplication() { ${main.name}.main() }\n`
4065
4193
  } else if (mains.length === 0) {
4066
4194
  const procedural = entries.filter(
4067
4195
  ([file, source]) =>
@@ -4126,6 +4254,10 @@ export function writeSwiftProject(
4126
4254
  '-fobjc-exceptions',
4127
4255
  '-fexceptions',
4128
4256
  '-fwasm-exceptions',
4257
+ // the backend lowers direct setjmp-family calls; -lsetjmp is already
4258
+ // linked. no-op for units without setjmp calls (byte-identical).
4259
+ '-mllvm',
4260
+ '-wasm-enable-sjlj',
4129
4261
  '-fobjc-arc',
4130
4262
  ...intake,
4131
4263
  ])
@@ -4189,8 +4321,10 @@ export function writeSwiftProject(
4189
4321
  const base = layout.multi ? layout.root : layout.sources
4190
4322
  const libraries = new Map<string, string>()
4191
4323
  for (const [target, data] of Object.entries(input.libraries ?? {})) {
4192
- const file = path.join(layout.root, '.peach-libraries', `lib${target}.a`)
4193
- files.set(file, Buffer.from(data, 'base64'))
4324
+ const bytes = Buffer.from(data, 'base64')
4325
+ const digest = createHash('sha256').update(bytes).digest('hex')
4326
+ const file = path.join(layout.root, '.peach-libraries', `lib${target}-${digest}.a`)
4327
+ files.set(file, bytes)
4194
4328
  libraries.set(target, file)
4195
4329
  }
4196
4330
  for (const [file, contents] of Object.entries(input.files)) {
@@ -4212,6 +4346,33 @@ export function writeSwiftProject(
4212
4346
  resources: false,
4213
4347
  },
4214
4348
  ]
4349
+ // a package reaches the distribution's frameworks through any Swift source
4350
+ // but its entry (every target compiles with implicit framework imports),
4351
+ // through Objective-C, or by importing a distribution module. a C include
4352
+ // of a libsystem header family such as <os/log.h> links libsystem only. C that calls
4353
+ // libdispatch needs the run loop UIKit's host drives (rnx_tick). an entry
4354
+ // that only calls other C and C++ targets links none of the frameworks'
4355
+ // objects, so it carries no UIKit host and reserves no icu data.
4356
+ const reachesFrameworks =
4357
+ !distribution ||
4358
+ Object.entries(input.files).some(
4359
+ ([file, source]) =>
4360
+ (file.endsWith('.swift') && file !== input.entry && file !== 'Package.swift') ||
4361
+ /\.mm?$/.test(file) ||
4362
+ source.includes('dispatch_'),
4363
+ ) ||
4364
+ [...importedModules].some(
4365
+ (name) =>
4366
+ distribution.modules.includes(name) &&
4367
+ !targets.some((target) => target.name === name) &&
4368
+ !(
4369
+ clangImportedModules.has(name) &&
4370
+ !swiftImportedModules.has(name) &&
4371
+ existsSync(
4372
+ path.join(swiftSharedSdkRoot(moduleRoot, true), 'usr/include', name),
4373
+ )
4374
+ ),
4375
+ )
4215
4376
  const frameworkLink = prebuilt
4216
4377
  ? path.join(layout.root, '.peach-framework-objects.rsp')
4217
4378
  : undefined
@@ -4258,15 +4419,21 @@ export function writeSwiftProject(
4258
4419
  oneModule: input.oneModule,
4259
4420
  spriteKit: importsSpriteKit(input.files),
4260
4421
  distribution: distribution ?? undefined,
4422
+ distributionExcludes,
4261
4423
  deferDarwinOverlay:
4262
4424
  native.size > 0 &&
4263
4425
  toolsetOrdersLibcxxBeforeDarwinOverlay(
4264
4426
  swiftSdkPaths(moduleRoot, nativeToolchain()).cFlags,
4265
4427
  ),
4266
- distributionLink: {
4267
- path: path.join(layout.root, '.peach-distribution-objects.rsp'),
4268
- files,
4269
- },
4428
+ ...(reachesFrameworks
4429
+ ? {
4430
+ distributionLink: {
4431
+ path: path.join(layout.root, '.peach-distribution-objects.rsp'),
4432
+ files,
4433
+ },
4434
+ lazyDistribution: input.lazyDistribution,
4435
+ }
4436
+ : {}),
4270
4437
  ...(prebuilt && frameworkLink
4271
4438
  ? {
4272
4439
  prebuilt: {
@@ -4278,6 +4445,9 @@ export function writeSwiftProject(
4278
4445
  }
4279
4446
  : {}),
4280
4447
  libraries,
4448
+ ...(input.defaultLocalization
4449
+ ? { defaultLocalization: input.defaultLocalization }
4450
+ : {}),
4281
4451
  }) + moduleFiles,
4282
4452
  )
4283
4453
  }
@@ -4297,7 +4467,7 @@ export function writeSwiftProject(
4297
4467
  extraCLIOptions: [
4298
4468
  '-I',
4299
4469
  distribution
4300
- ? path.join(moduleRoot, 'modules')
4470
+ ? distributionModulesPath(layout.root, moduleRoot, distributionExcludes)
4301
4471
  : prebuilt
4302
4472
  ? prebuilt.modules
4303
4473
  : path.join(layout.root, '.build', WASM_TRIPLE, 'release', 'Modules'),
@@ -4923,6 +5093,15 @@ async function compileFrameworkProducts(args: {
4923
5093
  .split('\n')
4924
5094
  .map((line) => line.trim())
4925
5095
  .filter((flag, index, all) => flag.length > 0 && all.indexOf(flag) === index)
5096
+ // category-only archive members have no symbol reference to pull them in.
5097
+ // source consumers need the same direct Foundation input as distributions.
5098
+ if (link.includes('-lFoundation'))
5099
+ objects.push(
5100
+ path.join(
5101
+ swiftSdkPaths(args.moduleRoot, args.toolchainBin).resources,
5102
+ 'wasi/NSStringFormatting.objc.o',
5103
+ ),
5104
+ )
4926
5105
  return {
4927
5106
  modules: path.join(release, 'Modules'),
4928
5107
  objects,
@@ -5021,7 +5200,7 @@ export function compileSwiftProjectUnit(
5021
5200
  }
5022
5201
  const hash = swiftArtifactHash(input, options.release, moduleRoot)
5023
5202
  const frameworkKey = swiftProjectBuildKey(moduleRoot, options.release)
5024
- const sharedRoot = path.join(rnxHomeDir(), 'cache', 'swift-projects', hash)
5203
+ const sharedRoot = path.join(swiftCacheDir(), 'swift-projects', hash)
5025
5204
  const report = (message: string) => {
5026
5205
  console.error(`[swift-project ${hash.slice(0, 16)}] ${message}`)
5027
5206
  options.onStage?.(message)