peachsim 0.1.1673 → 0.1.1684

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 (213) hide show
  1. package/cli/commands/control.ts +13 -1
  2. package/cli/commands/coverage-swift.ts +83 -27
  3. package/cli/commands/coverage.ts +219 -20
  4. package/cli/commands/detect.ts +10 -6
  5. package/cli/commands/inspect/core.ts +2 -0
  6. package/cli/commands/inspect/settling.ts +37 -4
  7. package/cli/commands/inspect/wait-ready.ts +7 -0
  8. package/cli/outbound-endpoints.ts +12 -0
  9. package/detox/index.ts +11 -1
  10. package/detox/jest-environment.cjs +14 -0
  11. package/dist-lib/agent-daemon-client.cjs +1 -1
  12. package/dist-lib/agent-events.cjs +1 -1
  13. package/dist-lib/attached-projects.cjs +1 -1
  14. package/dist-lib/auth/shared-session.cjs +1 -1
  15. package/dist-lib/backend-origin.cjs +1 -1
  16. package/dist-lib/beta.cjs +1 -1
  17. package/dist-lib/beta.mjs +1 -1
  18. package/dist-lib/bridge-constants.cjs +1 -1
  19. package/dist-lib/bridge-contract-input.cjs +1 -1
  20. package/dist-lib/bridge-contract-input.mjs +1 -1
  21. package/dist-lib/bridge-contract.cjs +1 -1
  22. package/dist-lib/bridge-contract.mjs +1 -1
  23. package/dist-lib/bundle-channel.cjs +3299 -1665
  24. package/dist-lib/capture-contract.cjs +1 -1
  25. package/dist-lib/capture-contract.mjs +1 -1
  26. package/dist-lib/cloud-contract.cjs +1 -1
  27. package/dist-lib/cloud-contract.mjs +1 -1
  28. package/dist-lib/cloud-test-args.cjs +1 -1
  29. package/dist-lib/cloud-test-args.mjs +1 -1
  30. package/dist-lib/cloud.cjs +1 -1
  31. package/dist-lib/cloud.mjs +1 -1
  32. package/dist-lib/config.cjs +1 -1
  33. package/dist-lib/config.mjs +1 -1
  34. package/dist-lib/detox/index.cjs +43 -8
  35. package/dist-lib/detox/jest-environment.cjs +14 -0
  36. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  37. package/dist-lib/expo-swift-bundle.cjs +2432 -1128
  38. package/dist-lib/expo-swift-metadata.cjs +1 -1
  39. package/dist-lib/expo-swift-metadata.mjs +1 -1
  40. package/dist-lib/home-paths.cjs +1 -1
  41. package/dist-lib/host/bridge-host.cjs +2908 -1601
  42. package/dist-lib/host/fetch-proxy-handler.cjs +22 -6
  43. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  44. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  45. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  46. package/dist-lib/host/websocket-proxy.cjs +1 -1
  47. package/dist-lib/index.cjs +1941 -742
  48. package/dist-lib/jump-to-source-babel.cjs +1 -1
  49. package/dist-lib/jump-to-source-native.cjs +1 -1
  50. package/dist-lib/kotlin-host.cjs +1 -1
  51. package/dist-lib/menu.cjs +1 -1
  52. package/dist-lib/menu.mjs +1 -1
  53. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  54. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  55. package/dist-lib/metro-production-bundle.cjs +1 -1
  56. package/dist-lib/metro-production-bundle.mjs +1 -1
  57. package/dist-lib/metro.cjs +6215 -4283
  58. package/dist-lib/native-app-identity-project.cjs +31 -6
  59. package/dist-lib/native-app-identity-project.mjs +31 -6
  60. package/dist-lib/native-app-identity.cjs +1 -1
  61. package/dist-lib/native-app-identity.mjs +1 -1
  62. package/dist-lib/native-firebase-metadata.cjs +1 -1
  63. package/dist-lib/native-firebase-metadata.mjs +1 -1
  64. package/dist-lib/plist.cjs +1 -1
  65. package/dist-lib/plist.mjs +1 -1
  66. package/dist-lib/profiles.cjs +1 -1
  67. package/dist-lib/public-brand.cjs +1 -1
  68. package/dist-lib/public-origins-lib-esm.json +24 -23
  69. package/dist-lib/public-origins-lib-static.json +1 -1
  70. package/dist-lib/public-origins-lib.json +134 -78
  71. package/dist-lib/react-native-host-modules.cjs +1 -1
  72. package/dist-lib/react-native-host-modules.mjs +1 -1
  73. package/dist-lib/reap-browser.cjs +2 -2
  74. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  75. package/dist-lib/sdk.cjs +39 -5
  76. package/dist-lib/sdk.mjs +39 -5
  77. package/dist-lib/skills.cjs +3637 -2168
  78. package/dist-lib/swift-compile.cjs +496 -352
  79. package/dist-lib/swift-compile.mjs +494 -350
  80. package/dist-lib/swift-package.cjs +58 -9
  81. package/dist-lib/swift-package.mjs +57 -9
  82. package/dist-lib/swift-submit.cjs +1 -1
  83. package/dist-lib/swift-submit.mjs +1 -1
  84. package/dist-lib/swift-toolchain.cjs +26 -11
  85. package/dist-lib/swift.cjs +1 -1
  86. package/dist-lib/vite-swift.cjs +2443 -1134
  87. package/dist-lib/vite.cjs +1907 -763
  88. package/dist-lib/worklet-executable.cjs +1 -1
  89. package/dist-lib/worklet-executable.mjs +1 -1
  90. package/dist-types/packages/peach-engine/src/engine/canvaskit-api.d.ts +1 -1
  91. package/dist-types/packages/peach-engine/src/engine/clipboardContract.d.ts +9 -1
  92. package/dist-types/packages/peach-engine/src/engine/paint-boundary.d.ts +1 -0
  93. package/dist-types/packages/peach-engine/src/preview/upload-protocol.d.ts +11 -3
  94. package/dist-types/packages/peach-engine/src/rolldown-bundle-inventory.d.ts +1 -1
  95. package/dist-types/packages/peach-engine/src/webview-automation-host.d.ts +6 -0
  96. package/dist-types/packages/peach-globals/src/clipboardBridgeContract.d.ts +2 -0
  97. package/dist-types/packages/peach-globals/src/compositorBridgeContract.d.ts +10 -1
  98. package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
  99. package/package.json +1 -1
  100. package/runtime-companion.json +1 -1
  101. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h +69 -2
  102. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +44 -4
  103. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFComposeAssistantViewController.h +29 -0
  104. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMailComposeControllerDeferredAction.h +14 -0
  105. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMailComposeViewController.h +162 -0
  106. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMailDraft.h +24 -0
  107. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMessageComposeViewController+UPI.h +31 -0
  108. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMessageComposeViewController.h +169 -0
  109. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MessageUI.h +13 -0
  110. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Modules/module.modulemap +11 -0
  111. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h +10 -0
  112. package/sdk/ios/usr/include/_ctype.h +388 -0
  113. package/sdk/ios/usr/include/_inttypes.h +296 -0
  114. package/sdk/ios/usr/include/_locale.h +83 -0
  115. package/sdk/ios/usr/include/_locale_posix2008.h +65 -0
  116. package/sdk/ios/usr/include/_time.h +207 -0
  117. package/sdk/ios/usr/include/arm/param.h +151 -0
  118. package/sdk/ios/usr/include/ctype.h +70 -0
  119. package/sdk/ios/usr/include/dispatch/dispatch.h +72 -6
  120. package/sdk/ios/usr/include/dlfcn.h +1 -2
  121. package/sdk/ios/usr/include/inttypes.h +35 -0
  122. package/sdk/ios/usr/include/locale.h +59 -0
  123. package/sdk/ios/usr/include/machine/param.h +42 -0
  124. package/sdk/ios/usr/include/net/if.h +1 -2
  125. package/sdk/ios/usr/include/peach/pthread.h +4 -4
  126. package/sdk/ios/usr/include/pthread/qos.h +304 -0
  127. package/sdk/ios/usr/include/runetype.h +118 -0
  128. package/sdk/ios/usr/include/setjmp.h +99 -0
  129. package/sdk/ios/usr/include/sys/_types/_clock_t.h +32 -0
  130. package/sdk/ios/usr/include/sys/_types/_ct_rune_t.h +33 -0
  131. package/sdk/ios/usr/include/sys/_types/_fd_clr.h +31 -0
  132. package/sdk/ios/usr/include/sys/_types/_fd_copy.h +31 -0
  133. package/sdk/ios/usr/include/sys/_types/_fd_def.h +121 -0
  134. package/sdk/ios/usr/include/sys/_types/_fd_isset.h +31 -0
  135. package/sdk/ios/usr/include/sys/_types/_fd_set.h +31 -0
  136. package/sdk/ios/usr/include/sys/_types/_fd_setsize.h +31 -0
  137. package/sdk/ios/usr/include/sys/_types/_fd_zero.h +31 -0
  138. package/sdk/ios/usr/include/sys/_types/_rune_t.h +32 -0
  139. package/sdk/ios/usr/include/sys/_types/_time_t.h +32 -0
  140. package/sdk/ios/usr/include/sys/_types/_wint_t.h +33 -0
  141. package/sdk/ios/usr/include/sys/cdefs.h +5 -0
  142. package/sdk/ios/usr/include/sys/param.h +235 -0
  143. package/sdk/ios/usr/include/sys/proc.h +1 -0
  144. package/sdk/ios/usr/include/sys/qos.h +151 -12
  145. package/sdk/ios/usr/include/time.h +67 -2
  146. package/sdk/ios/wasm/include/__typedef_sigset_t.h +7 -0
  147. package/sdk/ios/wasm/include/fcntl.h +11 -0
  148. package/sdk/ios/wasm/include/mach/machine/boolean.h +2 -0
  149. package/sdk/ios/wasm/include/mach/machine/exception.h +5 -0
  150. package/sdk/ios/wasm/include/mach/machine/kern_return.h +2 -0
  151. package/sdk/ios/wasm/include/mach/machine/processor_info.h +2 -0
  152. package/sdk/ios/wasm/include/mach/machine/rpc.h +2 -0
  153. package/sdk/ios/wasm/include/mach/machine/thread_state.h +3 -0
  154. package/sdk/ios/wasm/include/mach/machine/thread_status.h +3 -0
  155. package/sdk/ios/wasm/include/mach/machine/vm_param.h +3 -0
  156. package/sdk/ios/wasm/include/mach/machine/vm_types.h +18 -0
  157. package/sdk/ios/wasm/include/machine/_types.h +153 -0
  158. package/sdk/ios/wasm/include/machine/endian.h +2 -0
  159. package/sdk/ios/wasm/include/machine/limits.h +2 -0
  160. package/sdk/ios/wasm/include/machine/types.h +30 -0
  161. package/sdk/ios/wasm/include/poll.h +8 -0
  162. package/sdk/ios/wasm/include/pthread.h +50 -0
  163. package/sdk/ios/wasm/include/signal.h +72 -0
  164. package/sdk/ios/wasm/include/stdlib.h +3 -0
  165. package/sdk/ios/wasm/include/string.h +10 -0
  166. package/sdk/ios/wasm/include/sys/_pthread/_pthread_attr_t.h +7 -0
  167. package/sdk/ios/wasm/include/sys/_pthread/_pthread_t.h +7 -0
  168. package/sdk/ios/wasm/include/sys/mman.h +122 -0
  169. package/sdk/ios/wasm/include/sys/select.h +37 -0
  170. package/sdk/ios/wasm/include/sys/signal.h +259 -0
  171. package/sdk/ios/wasm/include/sys/socket.h +8 -0
  172. package/sdk/ios/wasm/include/sys/types.h +14 -0
  173. package/sdk/ios/wasm/include/sys/ucontext.h +1 -0
  174. package/sdk/ios/wasm/include/sys/uio.h +11 -0
  175. package/sdk/ios/wasm/include/sys/wait.h +89 -0
  176. package/sdk/ios/wasm/include/time.h +8 -0
  177. package/sdk/ios/wasm/include/unistd.h +17 -0
  178. package/src/bridge-contract.ts +2 -0
  179. package/src/chromium-admission.ts +10 -5
  180. package/src/device-catalog.ts +4 -4
  181. package/src/host/fetch-proxy-handler.ts +20 -0
  182. package/src/host/rolldown-bundle-forward.ts +4 -1
  183. package/src/metro-plugin.ts +5 -2
  184. package/src/nitro-adapter.lock.json +6 -6
  185. package/src/nitro-compile.ts +63 -2
  186. package/src/numbered-lock.ts +72 -0
  187. package/src/react-native-coverage/capability-reference-resolution.ts +62 -5
  188. package/src/react-native-coverage/capability-source-references.ts +50 -13
  189. package/src/react-native-coverage/native-source-credit.ts +126 -0
  190. package/src/react-native-coverage/native-source-ranges-file.ts +38 -0
  191. package/src/react-native-coverage/native-surface.ts +49 -0
  192. package/src/react-native-coverage/verified-reach.ts +22 -2
  193. package/src/runtime-assets.ts +17 -0
  194. package/src/swift-compile.ts +84 -47
  195. package/src/swift-coverage/indexing.ts +17 -1
  196. package/src/swift-coverage/sdk.ts +71 -0
  197. package/src/swift-coverage/source.ts +74 -2
  198. package/src/swift-coverage/types.ts +6 -0
  199. package/src/swift-distribution.lock.json +12 -12
  200. package/src/swift-host.ts +133 -14
  201. package/src/swift-objc-compile.ts +11 -22
  202. package/src/swift-objc-metadata.ts +2 -8
  203. package/src/swift-objc-platform.ts +53 -0
  204. package/src/swift-objc-standin.ts +49 -0
  205. package/src/swift-package-manifest.ts +48 -3
  206. package/src/swift-package.ts +85 -12
  207. package/src/swift-packages.ts +157 -44
  208. package/src/swift-source-pods.ts +288 -0
  209. package/src/swift-standins.ts +4 -1
  210. package/src/swift-toolchain.ts +32 -10
  211. package/src/vite-plugin-one.ts +5 -4
  212. package/src/worker-system-chunks.ts +7 -1
  213. package/src/xcode-project.ts +40 -11
package/src/swift-host.ts CHANGED
@@ -44,6 +44,7 @@ import {
44
44
  } from './swift-package'
45
45
  import { swiftPackageManifest } from './swift-package-manifest'
46
46
  import {
47
+ prefetchSwiftCheckouts,
47
48
  remoteSwiftCheckouts,
48
49
  resolveSwiftPackages,
49
50
  type SwiftPackageBinary,
@@ -189,6 +190,8 @@ export interface SwiftProject {
189
190
  hosted?: SwiftHostedCompileOptions
190
191
  signal?: AbortSignal
191
192
  libraries?: Record<string, string>
193
+ nativeTargets?: SwiftNativeTarget[]
194
+ resourceBundles?: SwiftResourceBundle[]
192
195
  }
193
196
 
194
197
  // a project is its swiftpm package: the build, the artifact, and the dev
@@ -257,6 +260,55 @@ interface XcodeProjectEntry {
257
260
 
258
261
  const xcodeProjects = new Map<string, XcodeProjectEntry>()
259
262
 
263
+ // run script phases read SourcePackages/checkouts from disk, but the pins
264
+ // and the checkout root only exist after a first read. read once without
265
+ // running scripts, fetch the pins the way xcode's resolution does, link
266
+ // each used project's derived-data sibling at them, then read for real.
267
+ // once per project per process: the checkouts persist and the link is
268
+ // idempotent, and a later re-resolve refetches through the same writer.
269
+ const preparedScriptInputs = new Set<string>()
270
+ function readXcodeAppTargetPrepared(
271
+ input: string,
272
+ target: string | undefined,
273
+ configuration: string | undefined,
274
+ options: {
275
+ requireSources?: boolean
276
+ prepareGeneratedSources?: boolean
277
+ installedPods?: boolean
278
+ },
279
+ ): XcodeAppTarget {
280
+ if (options.prepareGeneratedSources !== true)
281
+ return readXcodeAppTarget(input, target, configuration, options)
282
+ const key = JSON.stringify([input, target, configuration])
283
+ if (!preparedScriptInputs.has(key)) {
284
+ const probe = readXcodeAppTarget(input, target, configuration, {
285
+ ...options,
286
+ prepareGeneratedSources: false,
287
+ requireSources: false,
288
+ })
289
+ prefetchSwiftCheckouts(probe.rootDir, probe.packageResolved)
290
+ const checkouts = remoteSwiftCheckouts(probe.rootDir)
291
+ for (const projectDir of probe.projectDirs) {
292
+ const packages = path.join(projectDir, '.build', 'peach-xcode', 'SourcePackages')
293
+ fs.mkdirSync(packages, { recursive: true })
294
+ const link = path.join(packages, 'checkouts')
295
+ let linked: string | null = null
296
+ try {
297
+ linked = fs.lstatSync(link).isSymbolicLink() ? fs.readlinkSync(link) : null
298
+ } catch {
299
+ linked = null
300
+ }
301
+ if (linked !== null) {
302
+ if (path.resolve(packages, linked) === checkouts) continue
303
+ fs.unlinkSync(link)
304
+ } else if (fs.existsSync(link)) continue
305
+ fs.symlinkSync(checkouts, link)
306
+ }
307
+ preparedScriptInputs.add(key)
308
+ }
309
+ return readXcodeAppTarget(input, target, configuration, options)
310
+ }
311
+
260
312
  /**
261
313
  * registers an xcode project's application target as a compile unit and
262
314
  * returns the package path that names it. compiling locally against
@@ -269,7 +321,7 @@ export function openXcodeProject(
269
321
  moduleRoot: string | undefined,
270
322
  configuration?: string,
271
323
  ): string {
272
- const app = readXcodeAppTarget(xcodeproj, target, configuration, {
324
+ const app = readXcodeAppTargetPrepared(xcodeproj, target, configuration, {
273
325
  prepareGeneratedSources: true,
274
326
  installedPods: true,
275
327
  })
@@ -459,7 +511,7 @@ interface XcodeLayout {
459
511
  function xcodeLayout(root: string): XcodeLayout | null {
460
512
  const registered = xcodeProjects.get(root)
461
513
  if (!registered) return null
462
- const app = readXcodeAppTarget(
514
+ const app = readXcodeAppTargetPrepared(
463
515
  registered.xcodeproj,
464
516
  registered.target,
465
517
  registered.configuration,
@@ -557,6 +609,27 @@ function xcodeLayout(root: string): XcodeLayout | null {
557
609
  )
558
610
  .map((define) => define.name),
559
611
  ],
612
+ experimentalFeatures: target.packageExperimentalFeatures
613
+ .filter(
614
+ (feature) =>
615
+ feature.configuration === null ||
616
+ feature.configuration === packageConfiguration,
617
+ )
618
+ .map((feature) => feature.name),
619
+ upcomingFeatures: target.packageUpcomingFeatures
620
+ .filter(
621
+ (feature) =>
622
+ feature.configuration === null ||
623
+ feature.configuration === packageConfiguration,
624
+ )
625
+ .map((feature) => feature.name),
626
+ swiftFlags: target.packageSwiftFlags
627
+ .filter(
628
+ (setting) =>
629
+ setting.configuration === null ||
630
+ setting.configuration === packageConfiguration,
631
+ )
632
+ .flatMap((setting) => setting.flags),
560
633
  linkedLibraries: target.packageLibraries
561
634
  .filter(
562
635
  (library) =>
@@ -737,11 +810,25 @@ function xcodeManifest(layout: XcodeLayout): string {
737
810
  languageMode: number
738
811
  mainActorIsolation: boolean
739
812
  defines?: string[]
813
+ experimentalFeatures?: string[]
814
+ upcomingFeatures?: string[]
815
+ swiftFlags?: string[]
740
816
  }) =>
741
817
  `swiftSettings: [${[
742
818
  `.swiftLanguageMode(.v${target.languageMode})`,
743
819
  ...(target.mainActorIsolation ? ['.defaultIsolation(MainActor.self)'] : []),
744
820
  ...(target.defines ?? []).map((name) => `.define(${JSON.stringify(name)})`),
821
+ ...(target.experimentalFeatures ?? []).map(
822
+ (name) => `.enableExperimentalFeature(${JSON.stringify(name)})`,
823
+ ),
824
+ ...(target.upcomingFeatures ?? []).map(
825
+ (name) => `.enableUpcomingFeature(${JSON.stringify(name)})`,
826
+ ),
827
+ ...(target.swiftFlags?.length
828
+ ? [
829
+ `.unsafeFlags([${target.swiftFlags.map((flag) => JSON.stringify(flag)).join(', ')}])`,
830
+ ]
831
+ : []),
745
832
  ].join(', ')}]`
746
833
  const clangSettings = (target: SwiftPackageTarget) =>
747
834
  (
@@ -1010,7 +1097,10 @@ export function buildSwiftResourceTable(
1010
1097
  )
1011
1098
  }
1012
1099
  const layout = xcodeLayout(project.packagePath)
1013
- const bundles = layout?.resourceBundles ?? swiftResourceBundles(inputs, relative)
1100
+ const bundles =
1101
+ project.resourceBundles ??
1102
+ layout?.resourceBundles ??
1103
+ swiftResourceBundles(inputs, relative)
1014
1104
  const catalogFiles = relative.filter((file) => {
1015
1105
  const disk = byRelative.get(file)
1016
1106
  return !disk || !layout?.targetDirs.get(disk)?.startsWith(`${XCODE_FRAMEWORKS_DIR}/`)
@@ -1144,6 +1234,7 @@ export function buildSwiftBundleFiles(
1144
1234
  packagePath: string,
1145
1235
  hosted: boolean,
1146
1236
  inputs?: Record<string, string>,
1237
+ resourceBundles?: SwiftResourceBundle[],
1147
1238
  ): SwiftBundlePack {
1148
1239
  packagePath = fs.realpathSync(packagePath)
1149
1240
  const limits = inputLimits(hosted)
@@ -1158,6 +1249,7 @@ export function buildSwiftBundleFiles(
1158
1249
  let total = 0
1159
1250
  const xcode = xcodeLayout(packagePath)
1160
1251
  const bundles =
1252
+ resourceBundles ??
1161
1253
  xcode?.resourceBundles ??
1162
1254
  swiftResourceBundles(inputs ?? packageSources(packagePath, hosted), relative)
1163
1255
  const addFile = (key: string, bytes: Buffer) => {
@@ -1267,6 +1359,8 @@ export function sourceStamp(
1267
1359
  hash.update(JSON.stringify(xcodeProjects.get(packagePath)?.behavior ?? {}))
1268
1360
  const libraries = projects.get(packagePath)?.libraries
1269
1361
  if (libraries) hash.update(JSON.stringify(libraries))
1362
+ hash.update(JSON.stringify(projects.get(packagePath)?.nativeTargets ?? []))
1363
+ hash.update(JSON.stringify(projects.get(packagePath)?.resourceBundles ?? []))
1270
1364
  const projectInputs = new Set(packageFiles(packagePath))
1271
1365
  for (const file of [...projectInputs].sort()) {
1272
1366
  hash.update(path.relative(packagePath, file))
@@ -1287,6 +1381,8 @@ export function sourceContentStamp(
1287
1381
  hash.update(JSON.stringify(xcodeProjects.get(packagePath)?.behavior ?? {}))
1288
1382
  const libraries = projects.get(packagePath)?.libraries
1289
1383
  if (libraries) hash.update(JSON.stringify(libraries))
1384
+ hash.update(JSON.stringify(projects.get(packagePath)?.nativeTargets ?? []))
1385
+ hash.update(JSON.stringify(projects.get(packagePath)?.resourceBundles ?? []))
1290
1386
  for (const file of [...new Set(packageFiles(packagePath))].sort()) {
1291
1387
  hash.update(path.relative(packagePath, file))
1292
1388
  hash.update(fs.readFileSync(file))
@@ -1429,7 +1525,9 @@ function packageSnapshot(project: SwiftProject, entry: string): SwiftPackageSnap
1429
1525
  const native = nativeSourceDescriptor(project.packagePath)
1430
1526
  return {
1431
1527
  files,
1432
- ...(layout?.nativeTargets.length ? { nativeTargets: layout.nativeTargets } : {}),
1528
+ ...((project.nativeTargets ?? layout?.nativeTargets)?.length
1529
+ ? { nativeTargets: project.nativeTargets ?? layout?.nativeTargets }
1530
+ : {}),
1433
1531
  entry: layout
1434
1532
  ? xcodeInputKey(layout, path.resolve(project.packagePath, entry), entry)
1435
1533
  : entry,
@@ -1447,6 +1545,7 @@ function packageSnapshot(project: SwiftProject, entry: string): SwiftPackageSnap
1447
1545
  project.packagePath,
1448
1546
  Boolean(project.hosted),
1449
1547
  files,
1548
+ project.resourceBundles,
1450
1549
  ),
1451
1550
  native,
1452
1551
  ...(linked.size > 0 || project.libraries
@@ -1542,9 +1641,18 @@ async function compile(
1542
1641
  module: moduleStamp(packagePath, moduleRootOverride, false),
1543
1642
  }
1544
1643
  // targets are imported by their module names
1545
- const targets = compileTargets(input).map((target) =>
1546
- swiftTargetModuleName(target.name),
1547
- )
1644
+ const parsed = compileTargets(input)
1645
+ const targets = parsed.map((target) => swiftTargetModuleName(target.name))
1646
+ // the compiler synthesizes Builtin for a file whose own target enables the
1647
+ // feature, exactly when its import compiles. longest path first, so a
1648
+ // nested target's files read its own settings.
1649
+ const byPath = [...parsed].sort((left, right) => right.path.length - left.path.length)
1650
+ const providedByFile = (file: string): readonly string[] => {
1651
+ const owner = byPath.find((target) =>
1652
+ target.path === '.' ? true : file.startsWith(`${target.path}/`),
1653
+ )
1654
+ return owner?.experimentalFeatures?.includes('BuiltinModule') ? ['Builtin'] : []
1655
+ }
1548
1656
  const missing = missingSwiftModules(
1549
1657
  input.files,
1550
1658
  new Set([
@@ -1552,6 +1660,7 @@ async function compile(
1552
1660
  // a project without a manifest compiles as the template's one App target
1553
1661
  ...(targets.length > 0 ? targets : ['App']),
1554
1662
  ]),
1663
+ providedByFile,
1555
1664
  )
1556
1665
  if (missing.size > 0)
1557
1666
  throw new SwiftMissingModulesError(await missingModulesMessage(packagePath, missing))
@@ -1969,13 +2078,23 @@ export async function swiftPackageMetadata(
1969
2078
  packagePath = fs.realpathSync(packagePath)
1970
2079
  const project = projectFor(packagePath, hosted, signal)
1971
2080
  const limits = inputLimits(Boolean(project.hosted))
1972
- const mains = sourceFiles(packagePath).filter(
1973
- (file) =>
1974
- file.endsWith('.swift') &&
1975
- swiftApplicationEntry(
1976
- file,
1977
- readPackageFile(packagePath, file, limits.sourceBytes).toString('utf8'),
1978
- ),
2081
+ // an xcode project runs its selected application target: the entry is one
2082
+ // of the target's own swift sources, never a framework, package or sibling
2083
+ // target's @main elsewhere in the inputs. a plain package scans its tree.
2084
+ const registered = xcodeProjects.get(packagePath)
2085
+ const candidates = registered
2086
+ ? readXcodeAppTargetPrepared(
2087
+ registered.xcodeproj,
2088
+ registered.target,
2089
+ registered.configuration,
2090
+ { prepareGeneratedSources: true, installedPods: true },
2091
+ ).sources
2092
+ : sourceFiles(packagePath).filter((file) => file.endsWith('.swift'))
2093
+ const mains = candidates.filter((file) =>
2094
+ swiftApplicationEntry(
2095
+ file,
2096
+ readPackageFile(packagePath, file, limits.sourceBytes).toString('utf8'),
2097
+ ),
1979
2098
  )
1980
2099
  const native = nativeSourceDescriptor(packagePath)
1981
2100
  if (mains.length > 1 || (mains.length === 0 && !native)) {
@@ -11,7 +11,13 @@ 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
+ iosDeploymentMinimum,
17
+ materializeObjcSdk,
18
+ OBJC_IMPORT_VERSION,
19
+ objcSdkIntakeFlags,
20
+ } from './swift-objc-standin'
15
21
  import { SWIFT_NATIVE_SOURCE_EXTENSIONS, swiftTargetModuleName } from './swift-package'
16
22
  import { swiftPackageManifest, swiftTargetFiles } from './swift-package-manifest'
17
23
  import { remoteSwiftCheckouts, type SwiftPackageBinary } from './swift-packages'
@@ -239,7 +245,7 @@ export function prepareXcodeObjCImplementations(
239
245
  [...sources].map(([file, bytes]) => [file, digest(bytes)]),
240
246
  )
241
247
  const identity = {
242
- version: 13,
248
+ version: 16,
243
249
  importer: OBJC_IMPORT_VERSION,
244
250
  peers,
245
251
  metadataDeploymentTarget: peers ? app.iosDeploymentTarget : undefined,
@@ -476,19 +482,13 @@ export function prepareXcodeObjCImplementations(
476
482
  name: string
477
483
  deploymentTarget: string | null
478
484
  }): number => {
479
- const version = /^(\d{1,2})(?:\.(\d{1,2}))?(?:\.(\d{1,2}))?$/.exec(
480
- target.deploymentTarget ?? '',
481
- )
482
- if (!version) {
485
+ const minimum = iosDeploymentMinimum(target.deploymentTarget)
486
+ if (minimum === undefined) {
483
487
  return finish(
484
488
  'unsupported-deployment-target',
485
489
  `${target.name}: Objective-C compilation requires an explicit numeric IPHONEOS_DEPLOYMENT_TARGET; received ${JSON.stringify(target.deploymentTarget)}. Inputs: ${receipt}`,
486
490
  )
487
491
  }
488
- const minimum =
489
- Number(version[1]) * 10_000 +
490
- Number(version[2] ?? 0) * 100 +
491
- Number(version[3] ?? 0)
492
492
  return minimum
493
493
  }
494
494
  if (targets.length === 0)
@@ -554,21 +554,10 @@ export function prepareXcodeObjCImplementations(
554
554
  `--sysroot=${sdk.sysroot}`,
555
555
  '-fwasm-exceptions',
556
556
  '-fexceptions',
557
- '-D_WASI_EMULATED_SIGNAL',
558
- '-D_WASI_EMULATED_MMAN',
559
- `-D__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__=${minimum}`,
560
- `-D__IPHONE_OS_VERSION_MIN_REQUIRED=${minimum}`,
561
557
  ...(objc
562
558
  ? ['-fobjc-runtime=gnustep-2.2', '-fobjc-exceptions', '-fblocks']
563
559
  : []),
564
- '-iframework',
565
- path.join(headers, 'System/Library/Frameworks'),
566
- // the extension headers include the installed libc before adding darwin declarations.
567
- '-isystem',
568
- path.join(headers, 'wasm/include'),
569
- // installed libc and objc runtime headers own the target ABI.
570
- '-idirafter',
571
- path.join(headers, 'usr/include'),
560
+ ...objcSdkIntakeFlags(headers, toolchain.toolchainBin, minimum),
572
561
  ...headerSearch.flags[index]!,
573
562
  ...target.includes.flatMap((include) => ['-I', staged(include)]),
574
563
  ...target.frameworks.flatMap((framework) => ['-F', staged(framework)]),
@@ -8,6 +8,7 @@ import {
8
8
  IOS_SDK_ID,
9
9
  materializeObjcSdk,
10
10
  OBJC_IMPORT_VERSION,
11
+ objcSdkIntakeFlags,
11
12
  objcView,
12
13
  type ObjcView,
13
14
  } from './swift-objc-standin'
@@ -433,10 +434,6 @@ 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',
438
- `-D__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__=${args.minimum}`,
439
- `-D__IPHONE_OS_VERSION_MIN_REQUIRED=${args.minimum}`,
440
437
  '-fobjc-runtime=gnustep-2.2',
441
438
  '-fobjc-exceptions',
442
439
  '-fobjc-arc',
@@ -445,10 +442,7 @@ export function compileObjcPeerMetadata(args: {
445
442
  '-Xclang',
446
443
  '-disable-objc-default-synthesize-properties',
447
444
  '-Werror=objc-root-class',
448
- '-iframework',
449
- path.join(headers, 'System/Library/Frameworks'),
450
- '-idirafter',
451
- path.join(headers, 'usr/include'),
445
+ ...objcSdkIntakeFlags(headers, args.toolchainBin, args.minimum),
452
446
  '-Os',
453
447
  '-c',
454
448
  source,
@@ -0,0 +1,53 @@
1
+ import { spawnSync } from 'node:child_process'
2
+ import path from 'node:path'
3
+ import { swiftEnvironment } from './swift-toolchain'
4
+
5
+ const platforms = new Map<string, readonly string[]>()
6
+
7
+ /** iOS source selection with the implementation compiler's wasm storage and runtime. */
8
+ export function swiftObjCPlatformFlags(
9
+ toolchainBin: string,
10
+ minimum: number,
11
+ ): readonly string[] {
12
+ const key = `${toolchainBin}:${minimum}`
13
+ const cached = platforms.get(key)
14
+ if (cached) return cached
15
+ const version = [
16
+ Math.floor(minimum / 10_000),
17
+ Math.floor((minimum % 10_000) / 100),
18
+ minimum % 100,
19
+ ].join('.')
20
+ const result = spawnSync(
21
+ path.join(toolchainBin, 'clang'),
22
+ [
23
+ '-target',
24
+ `arm64-apple-ios${version}-simulator`,
25
+ '-dM',
26
+ '-E',
27
+ '-x',
28
+ 'objective-c',
29
+ '-',
30
+ ],
31
+ {
32
+ input: '',
33
+ encoding: 'utf8',
34
+ env: swiftEnvironment(),
35
+ timeout: 30_000,
36
+ maxBuffer: 1024 * 1024,
37
+ },
38
+ )
39
+ if (result.error || result.status !== 0)
40
+ throw new Error(
41
+ `could not read iOS compiler platform predefines: ${result.error?.message ?? result.stderr}`,
42
+ )
43
+ // copy OS and vendor identity, never arm64 widths, instructions or Apple's objc ABI.
44
+ const flags = [
45
+ ...result.stdout.matchAll(
46
+ /^#define (TARGET_OS_\w+|TARGET_IPHONE_SIMULATOR|__APPLE\w*__|__MACH__|__ENVIRONMENT_\w+) (.*)$/gm,
47
+ ),
48
+ ].map(([, name, value]) => `-D${name}=${value}`)
49
+ if (!flags.includes('-D__APPLE__=1') || !flags.includes('-D__MACH__=1'))
50
+ throw new Error('iOS compiler platform predefines lack Apple and Mach identity')
51
+ platforms.set(key, flags)
52
+ return flags
53
+ }
@@ -17,6 +17,7 @@ import { execFileSync, spawnSync } from 'node:child_process'
17
17
  import { createHash } from 'node:crypto'
18
18
  import fs from 'node:fs'
19
19
  import path from 'node:path'
20
+ import { swiftObjCPlatformFlags } from './swift-objc-platform'
20
21
  import { IOS_SDK_HEADERS, IOS_SDK_OVERLAYS, IOS_SDK_TARGET } from './swift-objc-sdk'
21
22
  import { swiftEnvironment } from './swift-toolchain'
22
23
  import type { SymbolGraph } from './swift-standin-emit'
@@ -45,6 +46,15 @@ export const OBJC_IMPORT_VERSION = '4'
45
46
 
46
47
  export const NATIVE_GRAPH_SDK_VERSION = '27.1'
47
48
 
49
+ /** the installed libc's emulated surfaces: its signal.h is an #error without them,
50
+ * so every clang that builds original c or objective-c for wasm passes them. */
51
+ export const WASI_EMULATION = [
52
+ '_WASI_EMULATED_SIGNAL',
53
+ '_WASI_EMULATED_MMAN',
54
+ '_WASI_EMULATED_PROCESS_CLOCKS',
55
+ ]
56
+ export const WASI_EMULATION_FLAGS = WASI_EMULATION.map((name) => `-D${name}`)
57
+
48
58
  const NATIVE_GRAPH_INPUTS = {
49
59
  sdk: NATIVE_GRAPH_SDK_VERSION,
50
60
  settings: 'e68503e5e534e9194af5efe8c636ca8b824e2d8237c5f38ec84aa4d155bc8418',
@@ -180,6 +190,45 @@ export function materializeObjcSdk(cacheDir: string): string {
180
190
  return sdk
181
191
  }
182
192
 
193
+ /** the libc intake of every original c and objective-c unit over the sdk at
194
+ * `headers`: the iOS platform predefines for its deployment minimum, the
195
+ * installed libc's emulated surfaces that every app links, the sdk
196
+ * frameworks, the darwin extension headers in front of the installed libc,
197
+ * and the installed libc and objc runtime headers owning the target abi. */
198
+ export function objcSdkIntakeFlags(
199
+ headers: string,
200
+ toolchainBin: string,
201
+ minimum: number,
202
+ ): string[] {
203
+ return [
204
+ ...swiftObjCPlatformFlags(toolchainBin, minimum),
205
+ // AvailabilityInternal.h derives this through __is_target_os(ios), which
206
+ // is false for wasm32.
207
+ `-D__IPHONE_OS_VERSION_MIN_REQUIRED=${minimum}`,
208
+ // apple's build setting for a 32-bit target to keep NSInteger and
209
+ // NSUInteger long, the nominal types they have on arm64.
210
+ '-DNS_BUILD_32_LIKE_64=1',
211
+ // the installed libc's default feature set otherwise defines
212
+ // _XOPEN_SOURCE, which darwin's sys/cdefs.h turns into a strict posix
213
+ // level; iOS compiles at darwin's full level with neither defined.
214
+ '-D_BSD_SOURCE',
215
+ ...WASI_EMULATION_FLAGS,
216
+ '-iframework',
217
+ path.join(headers, 'System/Library/Frameworks'),
218
+ '-isystem',
219
+ path.join(headers, 'wasm/include'),
220
+ '-idirafter',
221
+ path.join(headers, 'usr/include'),
222
+ ]
223
+ }
224
+
225
+ /** an IPHONEOS_DEPLOYMENT_TARGET as clang's version number (16.4 is 160400). */
226
+ export function iosDeploymentMinimum(version: string | null): number | undefined {
227
+ const parts = /^(\d{1,2})(?:\.(\d{1,2}))?(?:\.(\d{1,2}))?$/.exec(version ?? '')
228
+ if (!parts) return undefined
229
+ return Number(parts[1]) * 10_000 + Number(parts[2] ?? 0) * 100 + Number(parts[3] ?? 0)
230
+ }
231
+
183
232
  const headerFiles = (dir: string): string[] =>
184
233
  fs
185
234
  .readdirSync(dir, { recursive: true, encoding: 'utf8' })
@@ -49,6 +49,9 @@ export interface SwiftManifestTarget {
49
49
  mainActorIsolation: boolean
50
50
  defines: SwiftManifestSetting[]
51
51
  libraries: SwiftManifestSetting[]
52
+ experimentalFeatures: SwiftManifestSetting[]
53
+ upcomingFeatures: SwiftManifestSetting[]
54
+ swiftFlags: { flags: string[]; configuration: 'debug' | 'release' | null }[]
52
55
  nativeSettings: {
53
56
  tool: 'c' | 'cxx'
54
57
  flags: string[]
@@ -298,6 +301,9 @@ export function swiftPackageManifest(dir: string): SwiftPackageManifest {
298
301
  let mainActorIsolation = false
299
302
  const defines: SwiftManifestSetting[] = []
300
303
  const libraries: SwiftManifestSetting[] = []
304
+ const experimentalFeatures: SwiftManifestSetting[] = []
305
+ const upcomingFeatures: SwiftManifestSetting[] = []
306
+ const swiftFlags: SwiftManifestTarget['swiftFlags'] = []
301
307
  const nativeSettings: SwiftManifestTarget['nativeSettings'] = []
302
308
  const unsupportedSwiftSettings: string[] = []
303
309
  for (const [tool, standard] of [
@@ -312,6 +318,12 @@ export function swiftPackageManifest(dir: string): SwiftPackageManifest {
312
318
  const settingKind = record(rawKind)
313
319
  if (tool === 'swift') {
314
320
  const kinds = Object.keys(settingKind)
321
+ // a feature is a name with an optional =value (StrictConcurrency=complete).
322
+ const feature = (kind: string) =>
323
+ /^[A-Za-z_][A-Za-z0-9_]*(?:=[A-Za-z_][A-Za-z0-9_.-]*)?$/.test(
324
+ string(record(settingKind[kind])._0) ?? '',
325
+ )
326
+ const unsafe = record(settingKind.unsafeFlags)._0
315
327
  const supported =
316
328
  kinds.length === 1 &&
317
329
  ((kinds[0] === 'define' &&
@@ -324,7 +336,13 @@ export function swiftPackageManifest(dir: string): SwiftPackageManifest {
324
336
  Object.keys(record(condition)).length === 0 &&
325
337
  ['MainActor', 'nonisolated'].includes(
326
338
  string(record(settingKind.defaultIsolation)._0) ?? '',
327
- )))
339
+ )) ||
340
+ (kinds[0] === 'enableExperimentalFeature' &&
341
+ feature('enableExperimentalFeature')) ||
342
+ (kinds[0] === 'enableUpcomingFeature' && feature('enableUpcomingFeature')) ||
343
+ (kinds[0] === 'unsafeFlags' &&
344
+ Array.isArray(unsafe) &&
345
+ unsafe.every((flag) => typeof flag === 'string')))
328
346
  if (!supported)
329
347
  unsupportedSwiftSettings.push(JSON.stringify({ kind: rawKind, condition }))
330
348
  }
@@ -373,6 +391,27 @@ export function swiftPackageManifest(dir: string): SwiftPackageManifest {
373
391
  configuration: config === 'debug' || config === 'release' ? config : null,
374
392
  })
375
393
  }
394
+ // experimental and upcoming features and raw swift flags ride the same
395
+ // conditions a define does; a target that needs BuiltinModule or library
396
+ // evolution compiles with it exactly as swiftpm builds it.
397
+ if (string(tool) === 'swift' && linksOnIOS(condition, traits)) {
398
+ const config = string(record(condition).config)
399
+ const configuration = config === 'debug' || config === 'release' ? config : null
400
+ for (const [kind, into] of [
401
+ ['enableExperimentalFeature', experimentalFeatures],
402
+ ['enableUpcomingFeature', upcomingFeatures],
403
+ ] as const) {
404
+ const name = string(record(settingKind[kind])._0)
405
+ if (name && /^[A-Za-z_][A-Za-z0-9_]*(?:=[A-Za-z_][A-Za-z0-9_.-]*)?$/.test(name))
406
+ into.push({ name, configuration })
407
+ }
408
+ const flags = record(settingKind.unsafeFlags)._0
409
+ if (Array.isArray(flags) && flags.every((flag) => typeof flag === 'string'))
410
+ swiftFlags.push({
411
+ flags: flags.filter((flag): flag is string => typeof flag === 'string'),
412
+ configuration,
413
+ })
414
+ }
376
415
  const library = string(record(settingKind.linkedLibrary)._0)
377
416
  if (library && string(tool) === 'linker' && linksOnIOS(condition, traits)) {
378
417
  const config = string(record(condition).config)
@@ -400,6 +439,9 @@ export function swiftPackageManifest(dir: string): SwiftPackageManifest {
400
439
  mainActorIsolation,
401
440
  defines,
402
441
  libraries,
442
+ experimentalFeatures,
443
+ upcomingFeatures,
444
+ swiftFlags,
403
445
  nativeSettings,
404
446
  declaresResources: array(target.resources).length > 0,
405
447
  hasPluginUsages: array(target.pluginUsages).length > 0,
@@ -425,6 +467,9 @@ function walk(dir: string): string[] {
425
467
  const out: string[] = []
426
468
  for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
427
469
  if (entry.name.startsWith('.')) continue
470
+ // swiftpm never assigns a documentation catalog's contents to a target
471
+ // (`swift package describe` omits them; other dotted directories stay).
472
+ if (entry.isDirectory() && entry.name.endsWith('.docc')) continue
428
473
  const full = path.join(dir, entry.name)
429
474
  if (entry.isDirectory()) out.push(...walk(full))
430
475
  else if (entry.isFile()) out.push(full)
@@ -434,8 +479,8 @@ function walk(dir: string): string[] {
434
479
 
435
480
  /**
436
481
  * the files swiftpm assigns a target, absolute and sorted: its `sources:`
437
- * (else its whole directory), less its `exclude:` and the directories of
438
- * the package's other targets nested inside it.
482
+ * (else its whole directory), less its `exclude:`, documentation catalogs
483
+ * and the directories of the package's other targets nested inside it.
439
484
  */
440
485
  export function swiftTargetFiles(
441
486
  manifest: SwiftPackageManifest,