peachsim 0.1.1880 → 0.1.1886

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 (154) hide show
  1. package/cli/commands/control.ts +11 -10
  2. package/cli/commands/reset.ts +1 -1
  3. package/cli/outbound-endpoints.ts +1 -1
  4. package/detox/index.ts +62 -1
  5. package/dist-lib/agent-daemon-client.cjs +1 -1
  6. package/dist-lib/agent-events.cjs +1 -1
  7. package/dist-lib/attached-projects.cjs +1 -1
  8. package/dist-lib/auth/shared-session.cjs +1 -1
  9. package/dist-lib/backend-origin.cjs +1 -1
  10. package/dist-lib/beta.cjs +1 -1
  11. package/dist-lib/beta.mjs +1 -1
  12. package/dist-lib/bridge-constants.cjs +1 -1
  13. package/dist-lib/bridge-contract-input.cjs +1 -1
  14. package/dist-lib/bridge-contract-input.mjs +1 -1
  15. package/dist-lib/bridge-contract.cjs +1 -1
  16. package/dist-lib/bridge-contract.mjs +1 -1
  17. package/dist-lib/bundle-channel.cjs +8980 -4279
  18. package/dist-lib/capture-contract.cjs +1 -1
  19. package/dist-lib/capture-contract.mjs +1 -1
  20. package/dist-lib/cloud-contract.cjs +1 -1
  21. package/dist-lib/cloud-contract.mjs +1 -1
  22. package/dist-lib/cloud-test-args.cjs +1 -1
  23. package/dist-lib/cloud-test-args.mjs +1 -1
  24. package/dist-lib/cloud.cjs +1 -1
  25. package/dist-lib/cloud.mjs +1 -1
  26. package/dist-lib/config.cjs +1 -1
  27. package/dist-lib/config.mjs +1 -1
  28. package/dist-lib/detox/index.cjs +35 -2
  29. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  30. package/dist-lib/expo-swift-bundle.cjs +8500 -3912
  31. package/dist-lib/expo-swift-metadata.cjs +5 -1
  32. package/dist-lib/expo-swift-metadata.mjs +5 -1
  33. package/dist-lib/home-paths.cjs +1 -1
  34. package/dist-lib/host/bridge-host.cjs +9744 -5071
  35. package/dist-lib/host/fetch-proxy-handler.cjs +93 -13
  36. package/dist-lib/host/fetch-proxy-overrides.cjs +10 -2
  37. package/dist-lib/host/fetch-proxy-overrides.mjs +8 -2
  38. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  39. package/dist-lib/host/websocket-proxy.cjs +1 -1
  40. package/dist-lib/index.cjs +525 -120
  41. package/dist-lib/jump-to-source-babel.cjs +1 -1
  42. package/dist-lib/jump-to-source-native.cjs +1 -1
  43. package/dist-lib/kotlin-host.cjs +1 -1
  44. package/dist-lib/menu.cjs +1 -1
  45. package/dist-lib/menu.mjs +1 -1
  46. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  47. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  48. package/dist-lib/metro-production-bundle.cjs +1 -1
  49. package/dist-lib/metro-production-bundle.mjs +1 -1
  50. package/dist-lib/metro.cjs +523 -118
  51. package/dist-lib/native-app-identity-project.cjs +395 -72
  52. package/dist-lib/native-app-identity-project.mjs +723 -375
  53. package/dist-lib/native-app-identity.cjs +37 -1
  54. package/dist-lib/native-app-identity.mjs +36 -1
  55. package/dist-lib/native-firebase-metadata.cjs +1 -1
  56. package/dist-lib/native-firebase-metadata.mjs +1 -1
  57. package/dist-lib/pdfium-raster.cjs +1 -1
  58. package/dist-lib/pdfium-raster.mjs +1 -1
  59. package/dist-lib/plist.cjs +1 -1
  60. package/dist-lib/plist.mjs +1 -1
  61. package/dist-lib/profiles.cjs +1 -1
  62. package/dist-lib/public-brand.cjs +1 -1
  63. package/dist-lib/public-origins-lib-esm.json +58 -28
  64. package/dist-lib/public-origins-lib.json +233 -92
  65. package/dist-lib/react-native-host-modules.cjs +1 -1
  66. package/dist-lib/react-native-host-modules.mjs +1 -1
  67. package/dist-lib/reap-browser.cjs +1 -1
  68. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  69. package/dist-lib/sdk.cjs +1 -1
  70. package/dist-lib/sdk.mjs +1 -1
  71. package/dist-lib/skills.cjs +30639 -25833
  72. package/dist-lib/swift-compile.cjs +6823 -2525
  73. package/dist-lib/swift-compile.mjs +6809 -2509
  74. package/dist-lib/swift-package.cjs +20 -3
  75. package/dist-lib/swift-package.mjs +20 -3
  76. package/dist-lib/swift-submit.cjs +2 -2
  77. package/dist-lib/swift-submit.mjs +2 -2
  78. package/dist-lib/swift-toolchain.cjs +19 -1
  79. package/dist-lib/swift.cjs +1 -1
  80. package/dist-lib/vite-swift.cjs +8704 -4124
  81. package/dist-lib/vite.cjs +93 -13
  82. package/dist-lib/worklet-executable.cjs +1 -1
  83. package/dist-lib/worklet-executable.mjs +1 -1
  84. package/dist-types/packages/peach-engine/src/engine/canvaskit-api.d.ts +1 -1
  85. package/dist-types/packages/peach-engine/src/engine/fontDataContract.d.ts +2 -0
  86. package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +3 -0
  87. package/dist-types/packages/peach-engine/src/render-worker/native-ui-protocol.d.ts +1 -0
  88. package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +11 -1
  89. package/dist-types/packages/peach-engine/src/render-worker/shell-tree-wire.d.ts +2 -1
  90. package/dist-types/packages/peach-globals/src/nodeContract.d.ts +1 -0
  91. package/dist-types/packages/peach-globals/src/testBridgeContract.d.ts +10 -1
  92. package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
  93. package/dist-types/packages/peach-kit/src/ui/popover-placement.d.ts +1 -1
  94. package/dist-types/packages/sootsim-swift/src/securityHostContract.d.ts +10 -0
  95. package/package.json +1 -1
  96. package/runtime-companion.json +1 -1
  97. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFHost.h +555 -0
  98. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetwork.h +1 -0
  99. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes +6 -0
  100. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/NSURLProtocol.h +0 -1
  101. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Modules/module.modulemap +6 -0
  102. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIBarButtonItemBadge.h +1 -1
  103. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIBarMinimization.h +1 -1
  104. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIScrollView.h +1 -1
  105. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UISearchTab.h +1 -1
  106. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UITab.h +1 -1
  107. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UITabAccessory.h +2 -2
  108. package/sdk/ios/usr/include/os/activity.h +534 -0
  109. package/sdk/ios/usr/include/os.modulemap +15 -0
  110. package/sdk/ios/wasm/include/fcntl.h +16 -0
  111. package/sdk/ios/wasm/include/string.h +5 -0
  112. package/sdk/native-hashes.json +1 -1
  113. package/src/dns-over-https.ts +61 -9
  114. package/src/expo-swift-host.ts +11 -3
  115. package/src/host/fetch-proxy-handler.ts +51 -2
  116. package/src/host/fetch-proxy-overrides.ts +4 -0
  117. package/src/host/hostname-resolver.ts +9 -5
  118. package/src/native-app-identity-project.ts +13 -2
  119. package/src/native-app-identity.ts +47 -0
  120. package/src/nitro-adapter.lock.json +260 -260
  121. package/src/nitro-superset.lock.json +4 -4
  122. package/src/storageSnapshotContract.ts +20 -1
  123. package/src/swift-compile.ts +534 -136
  124. package/src/swift-compiler-digest.ts +15 -0
  125. package/src/swift-coverage/xcode-packages.ts +3 -2
  126. package/src/swift-distribution.lock.json +12 -12
  127. package/src/swift-guest-archive.ts +153 -0
  128. package/src/swift-guest-compile.ts +449 -0
  129. package/src/swift-guest-image-ledger.ts +656 -0
  130. package/src/swift-guest-link-plan.ts +52 -0
  131. package/src/swift-guest-link.ts +1414 -0
  132. package/src/swift-guest-linked-spans.ts +338 -0
  133. package/src/swift-guest-manifest.ts +141 -0
  134. package/src/swift-guest-projection-storage.ts +310 -0
  135. package/src/swift-guest-projection.ts +252 -0
  136. package/src/swift-guest-runtime-plan.ts +834 -0
  137. package/src/swift-guest-source-inputs.ts +427 -0
  138. package/src/swift-guest-source-plan.ts +279 -0
  139. package/src/swift-host.ts +125 -17
  140. package/src/swift-link-roots.ts +27 -50
  141. package/src/swift-package-manifest.ts +34 -18
  142. package/src/swift-package.ts +32 -2
  143. package/src/swift-packages.ts +138 -17
  144. package/src/swift-runtime-products.ts +73 -0
  145. package/src/swift-shared-sdk.ts +1 -1
  146. package/src/swift-submit.ts +13 -3
  147. package/src/swift-toolchain.ts +18 -0
  148. package/src/swift-wasm-prune.ts +313 -14
  149. package/src/swiftContract.ts +83 -0
  150. package/src/swiftRuntimeProductContract.ts +85 -45
  151. package/src/turbo-runtime.lock.json +23 -23
  152. package/src/turbo-source.ts +4 -1
  153. package/src/wasm-optimize.ts +16 -4
  154. package/src/xcode-project.ts +142 -14
@@ -0,0 +1,279 @@
1
+ import path from 'node:path'
2
+ import { swiftTargetModuleName } from './swift-package'
3
+ import type { GuestCallerScope } from './swift-guest-image-ledger'
4
+ import type { GuestLinkArtifact, GuestLinkPlan } from './swift-guest-link-plan'
5
+ import type { SwiftSourceLinkGraph } from './swiftContract'
6
+
7
+ // memberships come from resolved product kinds. static targets belong to the
8
+ // image that links them; dynamic products and the executable own their image.
9
+ export interface GuestSourceImage {
10
+ readonly id: number
11
+ readonly owner: string
12
+ readonly members: readonly string[]
13
+ }
14
+
15
+ export interface GuestSourceArtifact extends Omit<GuestLinkArtifact, 'image'> {
16
+ readonly sourceTarget: string
17
+ }
18
+
19
+ function swiftPackageLinkage(
20
+ target: SwiftSourceLinkGraph['targets'][number],
21
+ ): 'static' | 'dynamic' {
22
+ const linkage =
23
+ target.machOType === 'staticlib'
24
+ ? 'static'
25
+ : target.machOType === 'mh_dylib'
26
+ ? 'dynamic'
27
+ : null
28
+ if (!linkage) throw new Error(`unresolved SwiftPM library ${target.id}`)
29
+ if (
30
+ target.productType !== 'swiftpm.library.automatic' &&
31
+ target.productType !== `swiftpm.library.${linkage}`
32
+ )
33
+ throw new Error(`conflicting SwiftPM library linkage for ${target.id}`)
34
+ return linkage
35
+ }
36
+
37
+ /** Build image membership from resolved source products and their direct links. */
38
+ export function guestSourceImages(graph: SwiftSourceLinkGraph): GuestSourceImage[] {
39
+ const targets = new Map(graph.targets.map((target) => [target.id, target]))
40
+ const entry = targets.get(graph.entry)
41
+ if (!entry || entry.productType !== 'com.apple.product-type.application')
42
+ throw new Error('source graph has no application entry')
43
+ const images: { id: number; owner: string; members: string[] }[] = [
44
+ { id: 0, owner: entry.id, members: [] },
45
+ ]
46
+ const ownership = new Map<string, number>()
47
+ const active = new Set<string>()
48
+ const visit = (id: string, image: (typeof images)[number]) => {
49
+ if (active.has(id)) throw new Error(`cyclic source links at ${id}`)
50
+ const prior = ownership.get(id)
51
+ if (prior !== undefined) {
52
+ if (prior !== image.id)
53
+ throw new Error(`source target ${id} belongs to multiple images`)
54
+ return
55
+ }
56
+ const target = targets.get(id)
57
+ if (!target) throw new Error(`unknown source target ${id}`)
58
+ ownership.set(id, image.id)
59
+ image.members.push(id)
60
+ active.add(id)
61
+ for (const edge of target.dependencies) {
62
+ if (edge.attributes.length)
63
+ throw new Error(`unsupported link attributes for ${id} -> ${edge.target}`)
64
+ const dependency = targets.get(edge.target)
65
+ if (!dependency) throw new Error(`unknown source target ${edge.target}`)
66
+ const type = dependency.productType
67
+ let dynamic: boolean
68
+ if (type.startsWith('swiftpm.target.')) {
69
+ if (type !== 'swiftpm.target.regular' && type !== 'swiftpm.target.binary')
70
+ throw new Error(`unsupported SwiftPM target ${edge.target}`)
71
+ dynamic = false
72
+ } else if (type.startsWith('swiftpm.library.')) {
73
+ dynamic = swiftPackageLinkage(dependency) === 'dynamic'
74
+ } else if (type === 'com.apple.product-type.library.static') {
75
+ if (dependency.machOType && dependency.machOType !== 'staticlib')
76
+ throw new Error(`conflicting source library linkage for ${edge.target}`)
77
+ dynamic = false
78
+ } else if (type === 'com.apple.product-type.library.dynamic') {
79
+ if (dependency.machOType && dependency.machOType !== 'mh_dylib')
80
+ throw new Error(`conflicting source library linkage for ${edge.target}`)
81
+ dynamic = true
82
+ } else if (dependency.machOType === 'staticlib') dynamic = false
83
+ else if (dependency.machOType === 'mh_dylib') dynamic = true
84
+ else throw new Error(`unresolved source product ${edge.target}`)
85
+ if (!dynamic) visit(edge.target, image)
86
+ else {
87
+ const existing = ownership.get(edge.target)
88
+ const next =
89
+ existing === undefined
90
+ ? { id: images.length, owner: edge.target, members: [] }
91
+ : images[existing]!
92
+ if (existing === undefined) images.push(next)
93
+ visit(edge.target, next)
94
+ }
95
+ }
96
+ active.delete(id)
97
+ }
98
+ visit(entry.id, images[0]!)
99
+ return images
100
+ }
101
+
102
+ /** Resolve actual SwiftPM object paths to the source targets that built them. */
103
+ /** the binary target a `.peach-libraries/lib<target>-<digest>.a` archive belongs to. */
104
+ export function libraryArchiveTarget(file: string): string | null {
105
+ const match = /^lib(.+)-[0-9a-f]{64}\.a$/.exec(path.basename(file))
106
+ return match && path.basename(path.dirname(file)) === '.peach-libraries'
107
+ ? match[1]!
108
+ : null
109
+ }
110
+
111
+ export function guestSourceObjects(
112
+ graph: SwiftSourceLinkGraph,
113
+ buildDirectory: string,
114
+ objects: readonly string[],
115
+ generatedOwners: ReadonlyMap<string, string>,
116
+ ): { owned: GuestSourceArtifact[]; unowned: string[] } {
117
+ const names = new Set(
118
+ graph.targets.flatMap((target) =>
119
+ target.sourceTarget === null ? [] : [target.sourceTarget],
120
+ ),
121
+ )
122
+ // swiftpm names each build directory by its target's c99 module name
123
+ const owners = new Map(
124
+ [...generatedOwners].map(([name, owner]) => [swiftTargetModuleName(name), owner]),
125
+ )
126
+ // a binary target's prebuilt WebAssembly library is named for the target
127
+ const libraries = new Map(
128
+ graph.targets.flatMap((target) =>
129
+ target.productType === 'swiftpm.target.binary' && target.sourceTarget !== null
130
+ ? [[target.productName, target.sourceTarget] as const]
131
+ : [],
132
+ ),
133
+ )
134
+ const owned: GuestSourceArtifact[] = []
135
+ const unowned: string[] = []
136
+ for (const object of objects) {
137
+ const library = libraryArchiveTarget(object)
138
+ const libraryOwner = library === null ? undefined : libraries.get(library)
139
+ if (libraryOwner !== undefined) {
140
+ owned.push({
141
+ path: object,
142
+ kind: 'archive',
143
+ sourceTarget: libraryOwner,
144
+ instrumentDynamicLookups: false,
145
+ })
146
+ continue
147
+ }
148
+ const relative = path.relative(buildDirectory, object)
149
+ const [directory] = relative.split(path.sep)
150
+ const generated = directory?.endsWith('.build') ? directory.slice(0, -6) : ''
151
+ const target = owners.get(generated)
152
+ if (target && names.has(target) && object.endsWith('.o')) {
153
+ owned.push({
154
+ path: object,
155
+ kind: 'object',
156
+ sourceTarget: target,
157
+ instrumentDynamicLookups: true,
158
+ })
159
+ } else unowned.push(object)
160
+ }
161
+ return { owned, unowned }
162
+ }
163
+
164
+ // normal load dependencies are searched depth first, once per image. the
165
+ // caller must leave upward, delayed and other nonordinary links out of these
166
+ // edges; reexports that rename symbols need separate resolution metadata.
167
+ export function ordinaryGuestCallerScopes(
168
+ images: GuestLinkPlan['images'],
169
+ ): GuestCallerScope[] {
170
+ const byId = new Map(images.map((image) => [image.id, image]))
171
+ return images.map((caller) => {
172
+ const visited = new Set([caller.id])
173
+ const next: number[] = []
174
+ const visit = (id: number) => {
175
+ if (visited.has(id)) return
176
+ const image = byId.get(id)
177
+ if (!image) throw new Error(`unknown linked image ${id}`)
178
+ visited.add(id)
179
+ next.push(id)
180
+ for (const dependency of image.dependencies) visit(dependency)
181
+ }
182
+ for (const dependency of caller.dependencies) visit(dependency)
183
+ return { image: caller.id, next }
184
+ })
185
+ }
186
+
187
+ export function planGuestSourceLink(
188
+ graph: SwiftSourceLinkGraph,
189
+ images: readonly GuestSourceImage[],
190
+ callers: readonly GuestCallerScope[],
191
+ artifacts: readonly GuestSourceArtifact[],
192
+ symbols: readonly string[],
193
+ ): GuestLinkPlan {
194
+ const targets = new Map(graph.targets.map((target) => [target.id, target]))
195
+ const ownerByTarget = new Map<string, number>()
196
+ const imageIds = new Set<number>()
197
+ for (const image of images) {
198
+ if (imageIds.has(image.id)) throw new Error(`duplicate guest image ${image.id}`)
199
+ imageIds.add(image.id)
200
+ if (!targets.has(image.owner) || !image.members.includes(image.owner))
201
+ throw new Error(`image ${image.id} has no source owner`)
202
+ for (const id of image.members) {
203
+ const target = targets.get(id)
204
+ if (!target) throw new Error(`unknown source target ${id}`)
205
+ if (target.productType.startsWith('swiftpm.library.')) {
206
+ const linkage = swiftPackageLinkage(target)
207
+ if (linkage === 'dynamic' && id !== image.owner)
208
+ throw new Error(`dynamic SwiftPM library ${id} cannot be part of another image`)
209
+ if (linkage === 'static' && id === image.owner)
210
+ throw new Error(`static SwiftPM library ${id} cannot own an image`)
211
+ }
212
+ if (ownerByTarget.has(id))
213
+ throw new Error(`source target ${id} belongs to multiple images`)
214
+ if (
215
+ id !== image.owner &&
216
+ (target.machOType === 'mh_dylib' ||
217
+ target.machOType === 'mh_execute' ||
218
+ target.productType === 'com.apple.product-type.library.dynamic')
219
+ )
220
+ throw new Error(`dynamic source target ${id} cannot be part of another image`)
221
+ ownerByTarget.set(id, image.id)
222
+ }
223
+ }
224
+ if (!ownerByTarget.has(graph.entry)) throw new Error('source entry has no guest image')
225
+ const plannedImages = images.map((image) => {
226
+ const dependencies: number[] = []
227
+ const visited = new Set<string>()
228
+ const active = new Set<string>()
229
+ const visit = (id: string) => {
230
+ if (active.has(id)) throw new Error(`cyclic static source links at ${id}`)
231
+ if (visited.has(id)) return
232
+ visited.add(id)
233
+ active.add(id)
234
+ const target = targets.get(id)!
235
+ if (
236
+ target.linkerFlags.some((flag) =>
237
+ /(?:^|,)-(?:weak|reexport|upward|lazy)(?:[_-]|$)/.test(flag),
238
+ )
239
+ )
240
+ throw new Error(`unsupported special link flag for ${id}`)
241
+ for (const edge of target.dependencies) {
242
+ if (edge.attributes.length)
243
+ throw new Error(`unsupported link attributes for ${id} -> ${edge.target}`)
244
+ const dependencyImage = ownerByTarget.get(edge.target)
245
+ if (dependencyImage === undefined)
246
+ throw new Error(`linked target ${edge.target} has no guest image`)
247
+ if (dependencyImage === image.id) visit(edge.target)
248
+ else if (!dependencies.includes(dependencyImage))
249
+ dependencies.push(dependencyImage)
250
+ }
251
+ active.delete(id)
252
+ }
253
+ visit(image.owner)
254
+ for (const member of image.members)
255
+ if (!visited.has(member))
256
+ throw new Error(`source target ${member} is not linked into image ${image.id}`)
257
+ return { id: image.id, name: targets.get(image.owner)!.productName, dependencies }
258
+ })
259
+ const sourceTargets = new Map<string, number>()
260
+ for (const target of graph.targets) {
261
+ if (target.sourceTarget === null) continue
262
+ const image = ownerByTarget.get(target.id)
263
+ if (image === undefined) continue
264
+ if (sourceTargets.has(target.sourceTarget))
265
+ throw new Error(`ambiguous source target ${target.sourceTarget}`)
266
+ sourceTargets.set(target.sourceTarget, image)
267
+ }
268
+ return {
269
+ images: plannedImages,
270
+ callers,
271
+ artifacts: artifacts.map(({ sourceTarget, ...artifact }) => {
272
+ const image = sourceTargets.get(sourceTarget)
273
+ if (image === undefined)
274
+ throw new Error(`unowned link artifact ${artifact.path} (${sourceTarget})`)
275
+ return { ...artifact, image }
276
+ }),
277
+ symbols,
278
+ }
279
+ }
package/src/swift-host.ts CHANGED
@@ -115,6 +115,7 @@ import {
115
115
  import { privateSwiftDistributionRoot, swiftCacheDir } from './swift-toolchain'
116
116
  import { swiftProjectFileProblem } from './swiftContract'
117
117
  import {
118
+ type SwiftSourceLinkGraph,
118
119
  SWIFT_NATIVE_INPUT_ROOT,
119
120
  SWIFT_NATIVE_SDK_INCLUDE,
120
121
  SWIFT_XCODE_BUILD_CONDITION,
@@ -319,7 +320,7 @@ interface XcodeProjectEntry {
319
320
  target?: string
320
321
  /** the build configuration a selected scheme runs; xcode's default otherwise. */
321
322
  configuration?: string
322
- /** peach's own modules: a remote product named one links it, never its source. */
323
+ /** the selected distribution's modules, including metadata-only native intake. */
323
324
  provided: ReadonlySet<string> | null
324
325
  /** the module root a local compile links, which builds binary stand-ins. */
325
326
  moduleRoot: string | null
@@ -476,12 +477,13 @@ export function openXcodeProject(
476
477
  nativeModules,
477
478
  })
478
479
  const root = app.rootDir
480
+ const distribution = moduleRoot ?? interfaceRoot
479
481
  xcodeProjects().set(root, {
480
482
  xcodeproj,
481
483
  nativeModules,
482
484
  target: app.name,
483
485
  configuration: app.configuration,
484
- provided: moduleRoot ? new Set(swiftPeachModules(moduleRoot)) : null,
486
+ provided: distribution ? new Set(swiftPeachModules(distribution)) : null,
485
487
  moduleRoot: moduleRoot ?? null,
486
488
  interfaceRoot: interfaceRoot ?? null,
487
489
  })
@@ -701,6 +703,7 @@ function xcodeInputKey(
701
703
 
702
704
  interface XcodeLayout {
703
705
  app: XcodeAppTarget
706
+ appSwiftFlags: string[]
704
707
  checkouts: string
705
708
  /** framework and package targets, with root-relative paths and the nested target directories they exclude. */
706
709
  targets: (SwiftPackageTarget & { exclude: string[] })[]
@@ -718,6 +721,7 @@ interface XcodeLayout {
718
721
  /** the symbol sources xcode generates from package target catalogs, by input key. */
719
722
  generatedSources: Record<string, string>
720
723
  nativeTargets: SwiftNativeTarget[]
724
+ sourceLinkGraph: SwiftSourceLinkGraph
721
725
  headerAliases: SwiftHeaderAliases
722
726
  nativeFiles: Map<string, Buffer>
723
727
  files: string[]
@@ -921,12 +925,24 @@ async function buildXcodeLayout(root: string): Promise<XcodeLayout | null> {
921
925
  files.add(file)
922
926
  }
923
927
  }
928
+ const standinModules = new Set(standins.map((standin) => standin.module))
924
929
  for (const standin of standins)
925
930
  targets.push({
926
931
  name: standin.module,
927
932
  path: path.posix.join(SWIFT_STANDINS_DIR, standin.module),
928
933
  publicHeadersPath: standin.publicHeadersPath,
929
- dependencies: standin.dependencies?.map((name) => ({ kind: 'target', name })),
934
+ dependencies: [
935
+ ...new Set([
936
+ ...(standin.dependencies ?? []),
937
+ ...Object.entries(standin.files).flatMap(([file, contents]) =>
938
+ file.endsWith('.swift')
939
+ ? swiftImportNames(contents).filter(
940
+ (name) => name !== standin.module && standinModules.has(name),
941
+ )
942
+ : [],
943
+ ),
944
+ ]),
945
+ ].map((name) => ({ kind: 'target', name })),
930
946
  executable: false,
931
947
  resources: false,
932
948
  exclude: [],
@@ -976,7 +992,7 @@ async function buildXcodeLayout(root: string): Promise<XcodeLayout | null> {
976
992
  cDefines: packageMacros,
977
993
  cxxDefines: packageMacros,
978
994
  path: target.remote ? path.posix.join(XCODE_PACKAGES_DIR, posix) : posix,
979
- exclude: [],
995
+ exclude: target.exclude ?? [],
980
996
  defines: [
981
997
  ...(packageConfiguration === 'debug' ? ['DEBUG'] : []),
982
998
  ...target.packageDefines
@@ -1079,9 +1095,12 @@ async function buildXcodeLayout(root: string): Promise<XcodeLayout | null> {
1079
1095
  // swiftpm assigns a file to one target: a target directory nested in
1080
1096
  // another's is that one's exclusion
1081
1097
  for (const target of targets) {
1082
- target.exclude = targets
1083
- .filter((other) => other.path.startsWith(`${target.path}/`))
1084
- .map((other) => other.path.slice(target.path.length + 1))
1098
+ target.exclude = [
1099
+ ...target.exclude,
1100
+ ...targets
1101
+ .filter((other) => other.path.startsWith(`${target.path}/`))
1102
+ .map((other) => other.path.slice(target.path.length + 1)),
1103
+ ]
1085
1104
  }
1086
1105
  // a search path some pod xcconfigs stringify from an array embeds the
1087
1106
  // workspace's absolute path, which names the host: key it by the input root
@@ -1266,9 +1285,7 @@ async function buildXcodeLayout(root: string): Promise<XcodeLayout | null> {
1266
1285
  if (!settings.publicHeaders) continue
1267
1286
  const target = packages.targets.find((value) => value.name === settings.name)
1268
1287
  if (!target) continue
1269
- const prefixHeader = path.posix.join(target.path, 'PeachPodPrefix.pch')
1270
- generatedSources[prefixHeader] =
1271
- '#ifdef __OBJC__\n#import <UIKit/UIKit.h>\n#import <Foundation/Foundation.h>\n#endif\n'
1288
+ // a SwiftPM clang target has no prefix header: SwiftPM never injects one.
1272
1289
  nativeTargets.push({
1273
1290
  name: target.name,
1274
1291
  deploymentTarget: settings.deploymentTarget,
@@ -1282,7 +1299,7 @@ async function buildXcodeLayout(root: string): Promise<XcodeLayout | null> {
1282
1299
  .map(relative),
1283
1300
  flattensPublicHeaders: false,
1284
1301
  bridgingHeader: null,
1285
- prefixHeader,
1302
+ prefixHeader: null,
1286
1303
  headerSearchPaths: settings.includes.map(relative),
1287
1304
  moduleMaps: settings.moduleMaps.map((map) => ({
1288
1305
  module: map.module,
@@ -1301,8 +1318,21 @@ async function buildXcodeLayout(root: string): Promise<XcodeLayout | null> {
1301
1318
  ),
1302
1319
  })
1303
1320
  }
1321
+ const graphTargets = [...app.sourceLinkGraph.targets, ...packages.sourceLinks.targets]
1322
+ const binaryTargets = new Set(
1323
+ graphTargets.flatMap((target) =>
1324
+ target.productType === 'swiftpm.target.binary' ? [target.productName] : [],
1325
+ ),
1326
+ )
1327
+ const vendoredNames = new Set(app.binaryFrameworks.map((binary) => binary.name))
1328
+ const vendoredModules = standins.flatMap((standin) =>
1329
+ vendoredNames.has(standin.target) && !binaryTargets.has(standin.target)
1330
+ ? [standin.module]
1331
+ : [],
1332
+ )
1304
1333
  return {
1305
1334
  app,
1335
+ appSwiftFlags: nativeFlags(app.swift?.flags ?? []),
1306
1336
  checkouts,
1307
1337
  targets,
1308
1338
  packages,
@@ -1315,6 +1345,73 @@ async function buildXcodeLayout(root: string): Promise<XcodeLayout | null> {
1315
1345
  resourceBundles,
1316
1346
  generatedSources,
1317
1347
  nativeTargets,
1348
+ sourceLinkGraph: {
1349
+ entry: relative(app.sourceLinkGraph.entry),
1350
+ targets: graphTargets.flatMap((target) => {
1351
+ // a binary target builds from the source modules that stand in for
1352
+ // its xcframework; the first names the target, the rest link behind it.
1353
+ const standinModules =
1354
+ target.productType === 'swiftpm.target.binary'
1355
+ ? standins
1356
+ .filter((standin) => standin.target === target.productName)
1357
+ .map((standin) => standin.module)
1358
+ : []
1359
+ const original =
1360
+ target.id === app.id
1361
+ ? app
1362
+ : app.frameworks.find((framework) => framework.id === target.id)
1363
+ const products = original
1364
+ ? (packages.sourceLinks.owners.find(
1365
+ (owner) => owner.module === original.moduleName,
1366
+ )?.products ?? [])
1367
+ : []
1368
+ const buildVersion = {
1369
+ ...target.buildVersion,
1370
+ sdk: target.buildVersion.sdk ?? iosSdk.sdk,
1371
+ }
1372
+ const [first, ...rest] = standinModules
1373
+ const standinId = (module: string) => `${target.id}/#standin/${module}`
1374
+ // a framework the project vendors links into the app target itself
1375
+ const vendoredLinks = target.id === app.id ? vendoredModules : []
1376
+ return [
1377
+ {
1378
+ ...target,
1379
+ id: relative(target.id),
1380
+ sourceTarget:
1381
+ target.sourceTarget === null
1382
+ ? (first ?? null)
1383
+ : original
1384
+ ? (frameworkNames.get(original) ?? original.moduleName)
1385
+ : target.sourceTarget,
1386
+ buildVersion,
1387
+ dependencies: [
1388
+ ...target.dependencies,
1389
+ ...products,
1390
+ ...rest.map((module) => ({ target: standinId(module), attributes: [] })),
1391
+ ...vendoredLinks.map((module) => ({
1392
+ target: standinId(module),
1393
+ attributes: [],
1394
+ })),
1395
+ ].map((link) => ({
1396
+ ...link,
1397
+ target: relative(link.target),
1398
+ })),
1399
+ },
1400
+ ...[...rest, ...vendoredLinks].map((module) => ({
1401
+ ...target,
1402
+ id: relative(standinId(module)),
1403
+ sourceTarget: module,
1404
+ productName: module,
1405
+ productType: 'swiftpm.target.binary',
1406
+ machOType: null,
1407
+ installName: null,
1408
+ buildVersion,
1409
+ linkerFlags: [],
1410
+ dependencies: [],
1411
+ })),
1412
+ ]
1413
+ }),
1414
+ },
1318
1415
  headerAliases,
1319
1416
  nativeFiles,
1320
1417
  files: [...files].sort(),
@@ -1379,20 +1476,22 @@ function xcodeManifest(layout: XcodeLayout): string {
1379
1476
  ...layout.app,
1380
1477
  defines: [...layout.app.defines, SWIFT_XCODE_BUILD_CONDITION],
1381
1478
  cxxInterop: appSwift?.cxxInterop,
1382
- swiftFlags:
1383
- appSwift?.cxxInterop && appSwift.cxxStandard
1479
+ swiftFlags: [
1480
+ ...layout.appSwiftFlags,
1481
+ ...(appSwift?.cxxInterop && appSwift.cxxStandard
1384
1482
  ? ['-Xcc', `-std=${appSwift.cxxStandard}`]
1385
- : undefined,
1483
+ : []),
1484
+ ],
1386
1485
  })
1387
1486
  return [
1388
1487
  '// swift-tools-version: 6.2',
1389
1488
  'import PackageDescription',
1390
1489
  `let package = Package(name: "app", ${layout.app.iosDeploymentTarget ? `platforms: [.iOS(${JSON.stringify(layout.app.iosDeploymentTarget)})], ` : ''}dependencies: [${[...nativePaths].map(([name, directory]) => `.package(name: ${JSON.stringify(name)}, path: ${JSON.stringify(directory)})`).join(', ')}], targets: [`,
1391
- ` .executableTarget(name: "${layout.app.moduleName}", dependencies: [${[...appProducts, ...sdkProducts].join(', ')}], path: "${XCODE_APP_DIR}", ${appSettings}),`,
1490
+ ` .executableTarget(name: "${layout.app.moduleName}", dependencies: [${[...appProducts, ...layout.targets.map((target) => JSON.stringify(target.name)), ...sdkProducts].join(', ')}], path: "${XCODE_APP_DIR}", ${appSettings}),`,
1392
1491
  ...layout.targets.map((target) =>
1393
1492
  target.systemLibrary
1394
1493
  ? ` .systemLibrary(name: "${target.name}", path: "${target.path}"),`
1395
- : ` .target(name: "${target.name}", dependencies: [${dependencies(target)}], path: "${target.path}", ${target.exclude.length > 0 ? `exclude: ${JSON.stringify(target.exclude)}, ` : ''}${target.resources ? 'resources: [], ' : ''}${target.publicHeadersPath === undefined ? '' : `publicHeadersPath: ${JSON.stringify(target.publicHeadersPath)}, `}${clangSettings(target)}${swiftManifestSettings(target)}${libraries(target)}),`,
1494
+ : ` .target(name: "${target.name}", ${target.dependencies === undefined ? '' : `dependencies: [${dependencies(target)}], `}path: "${target.path}", ${target.exclude.length > 0 ? `exclude: ${JSON.stringify(target.exclude)}, ` : ''}${target.resources ? 'resources: [], ' : ''}${target.publicHeadersPath === undefined ? '' : `publicHeadersPath: ${JSON.stringify(target.publicHeadersPath)}, `}${clangSettings(target)}${swiftManifestSettings(target)}${libraries(target)}),`,
1396
1495
  ),
1397
1496
  '])',
1398
1497
  '',
@@ -1474,6 +1573,7 @@ function sourceTreeFiles(dir: string, canonicalRoot: string): string[] {
1474
1573
  walk(full)
1475
1574
  } else if (stat.isFile()) {
1476
1575
  found.push(full)
1576
+ if (found.length > 4096) throw new Error('swift package exceeds 4096 input files')
1477
1577
  }
1478
1578
  }
1479
1579
  ancestors.delete(realDirectory)
@@ -2244,6 +2344,7 @@ interface SwiftPackageSnapshot {
2244
2344
  packageGuestImports?: string[]
2245
2345
  files: Record<string, string>
2246
2346
  nativeTargets?: SwiftNativeTarget[]
2347
+ sourceLinkGraph?: SwiftSourceLinkGraph
2247
2348
  headerAliases?: SwiftHeaderAliases
2248
2349
  defaultLocalization?: string
2249
2350
  entry: string
@@ -2361,7 +2462,12 @@ function packageSnapshot(
2361
2462
  ...((project.nativeTargets ?? layout?.nativeTargets)?.length
2362
2463
  ? { nativeTargets: project.nativeTargets ?? layout?.nativeTargets }
2363
2464
  : {}),
2364
- ...(layout ? { defaultLocalization: layout.app.developmentRegion } : {}),
2465
+ ...(layout
2466
+ ? {
2467
+ sourceLinkGraph: layout.sourceLinkGraph,
2468
+ defaultLocalization: layout.app.developmentRegion,
2469
+ }
2470
+ : {}),
2365
2471
  entry: layout
2366
2472
  ? xcodeInputKey(layout, path.resolve(project.packagePath, entry), entry)
2367
2473
  : entry,
@@ -2424,6 +2530,7 @@ function snapshotCompileInput(snapshot: SwiftPackageSnapshot): SwiftCompileInput
2424
2530
  : {}),
2425
2531
  ...(snapshot.projectFiles ? { projectFiles: snapshot.projectFiles } : {}),
2426
2532
  ...(snapshot.nativeTargets ? { nativeTargets: snapshot.nativeTargets } : {}),
2533
+ ...(snapshot.sourceLinkGraph ? { sourceLinkGraph: snapshot.sourceLinkGraph } : {}),
2427
2534
  ...(snapshot.headerAliases ? { headerAliases: snapshot.headerAliases } : {}),
2428
2535
  ...(snapshot.defaultLocalization
2429
2536
  ? { defaultLocalization: snapshot.defaultLocalization }
@@ -2807,6 +2914,7 @@ async function compileRemote(
2807
2914
  }
2808
2915
  : {}),
2809
2916
  ...(snapshot.nativeTargets ? { nativeTargets: snapshot.nativeTargets } : {}),
2917
+ ...(snapshot.sourceLinkGraph ? { sourceLinkGraph: snapshot.sourceLinkGraph } : {}),
2810
2918
  ...(snapshot.headerAliases ? { headerAliases: snapshot.headerAliases } : {}),
2811
2919
  ...(snapshot.defaultLocalization
2812
2920
  ? { defaultLocalization: snapshot.defaultLocalization }