peachsim 0.1.1881 → 0.1.1887

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 (160) hide show
  1. package/cli/commands/control.ts +11 -10
  2. package/cli/commands/reset.ts +1 -1
  3. package/cli/native-input.ts +1 -1
  4. package/cli/outbound-endpoints.ts +1 -1
  5. package/detox/index.ts +62 -1
  6. package/dist-lib/agent-daemon-client.cjs +1 -1
  7. package/dist-lib/agent-events.cjs +1 -1
  8. package/dist-lib/attached-projects.cjs +1 -1
  9. package/dist-lib/auth/shared-session.cjs +1 -1
  10. package/dist-lib/backend-origin.cjs +1 -1
  11. package/dist-lib/beta.cjs +1 -1
  12. package/dist-lib/beta.mjs +1 -1
  13. package/dist-lib/bridge-constants.cjs +1 -1
  14. package/dist-lib/bridge-contract-input.cjs +1 -1
  15. package/dist-lib/bridge-contract-input.mjs +1 -1
  16. package/dist-lib/bridge-contract.cjs +1 -1
  17. package/dist-lib/bridge-contract.mjs +1 -1
  18. package/dist-lib/bundle-channel.cjs +9079 -4305
  19. package/dist-lib/capture-contract.cjs +1 -1
  20. package/dist-lib/capture-contract.mjs +1 -1
  21. package/dist-lib/cloud-contract.cjs +1 -1
  22. package/dist-lib/cloud-contract.mjs +1 -1
  23. package/dist-lib/cloud-test-args.cjs +1 -1
  24. package/dist-lib/cloud-test-args.mjs +1 -1
  25. package/dist-lib/cloud.cjs +1 -1
  26. package/dist-lib/cloud.mjs +1 -1
  27. package/dist-lib/config.cjs +1 -1
  28. package/dist-lib/config.mjs +1 -1
  29. package/dist-lib/detox/index.cjs +35 -2
  30. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  31. package/dist-lib/expo-swift-bundle.cjs +8609 -3976
  32. package/dist-lib/expo-swift-metadata.cjs +5 -1
  33. package/dist-lib/expo-swift-metadata.mjs +5 -1
  34. package/dist-lib/home-paths.cjs +1 -1
  35. package/dist-lib/host/bridge-host.cjs +9894 -5149
  36. package/dist-lib/host/fetch-proxy-handler.cjs +93 -13
  37. package/dist-lib/host/fetch-proxy-overrides.cjs +10 -2
  38. package/dist-lib/host/fetch-proxy-overrides.mjs +8 -2
  39. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  40. package/dist-lib/host/websocket-proxy.cjs +1 -1
  41. package/dist-lib/index.cjs +538 -120
  42. package/dist-lib/jump-to-source-babel.cjs +1 -1
  43. package/dist-lib/jump-to-source-native.cjs +1 -1
  44. package/dist-lib/kotlin-host.cjs +1 -1
  45. package/dist-lib/menu.cjs +1 -1
  46. package/dist-lib/menu.mjs +1 -1
  47. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  48. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  49. package/dist-lib/metro-production-bundle.cjs +1 -1
  50. package/dist-lib/metro-production-bundle.mjs +1 -1
  51. package/dist-lib/metro.cjs +536 -118
  52. package/dist-lib/native-app-identity-project.cjs +408 -72
  53. package/dist-lib/native-app-identity-project.mjs +739 -375
  54. package/dist-lib/native-app-identity.cjs +37 -1
  55. package/dist-lib/native-app-identity.mjs +36 -1
  56. package/dist-lib/native-firebase-metadata.cjs +1 -1
  57. package/dist-lib/native-firebase-metadata.mjs +1 -1
  58. package/dist-lib/pdfium-raster.cjs +1 -1
  59. package/dist-lib/pdfium-raster.mjs +1 -1
  60. package/dist-lib/plist.cjs +1 -1
  61. package/dist-lib/plist.mjs +1 -1
  62. package/dist-lib/profiles.cjs +1 -1
  63. package/dist-lib/public-brand.cjs +1 -1
  64. package/dist-lib/public-origins-lib-esm.json +61 -28
  65. package/dist-lib/public-origins-lib.json +250 -92
  66. package/dist-lib/react-native-host-modules.cjs +1 -1
  67. package/dist-lib/react-native-host-modules.mjs +1 -1
  68. package/dist-lib/reap-browser.cjs +1 -1
  69. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  70. package/dist-lib/sdk.cjs +1 -1
  71. package/dist-lib/sdk.mjs +1 -1
  72. package/dist-lib/skills.cjs +16568 -11674
  73. package/dist-lib/swift-compile.cjs +6874 -2537
  74. package/dist-lib/swift-compile.mjs +6207 -1866
  75. package/dist-lib/swift-package.cjs +20 -3
  76. package/dist-lib/swift-package.mjs +20 -3
  77. package/dist-lib/swift-submit.cjs +2 -2
  78. package/dist-lib/swift-submit.mjs +2 -2
  79. package/dist-lib/swift-toolchain.cjs +19 -1
  80. package/dist-lib/swift.cjs +1 -1
  81. package/dist-lib/vite-swift.cjs +8753 -4124
  82. package/dist-lib/vite.cjs +93 -13
  83. package/dist-lib/worklet-executable.cjs +1 -1
  84. package/dist-lib/worklet-executable.mjs +1 -1
  85. package/dist-types/packages/peach-engine/src/engine/canvaskit-api.d.ts +1 -1
  86. package/dist-types/packages/peach-engine/src/engine/fontDataContract.d.ts +2 -0
  87. package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +3 -0
  88. package/dist-types/packages/peach-engine/src/render-worker/native-ui-protocol.d.ts +1 -0
  89. package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +11 -1
  90. package/dist-types/packages/peach-engine/src/render-worker/shell-tree-wire.d.ts +2 -1
  91. package/dist-types/packages/peach-globals/src/nodeContract.d.ts +1 -0
  92. package/dist-types/packages/peach-globals/src/testBridgeContract.d.ts +10 -1
  93. package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
  94. package/dist-types/packages/peach-kit/src/ui/popover-placement.d.ts +1 -1
  95. package/dist-types/packages/sootsim-swift/src/securityHostContract.d.ts +10 -0
  96. package/package.json +1 -1
  97. package/runtime-companion.json +1 -1
  98. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFHost.h +555 -0
  99. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetwork.h +1 -0
  100. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes +6 -0
  101. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/NSURLProtocol.h +0 -1
  102. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Modules/module.modulemap +6 -0
  103. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIBarButtonItemBadge.h +1 -1
  104. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIBarMinimization.h +1 -1
  105. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIScrollView.h +1 -1
  106. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UISearchTab.h +1 -1
  107. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UITab.h +1 -1
  108. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UITabAccessory.h +2 -2
  109. package/sdk/ios/usr/include/os/activity.h +534 -0
  110. package/sdk/ios/usr/include/os.modulemap +15 -0
  111. package/sdk/ios/wasm/include/fcntl.h +16 -0
  112. package/sdk/ios/wasm/include/string.h +5 -0
  113. package/sdk/native-hashes.json +1 -1
  114. package/src/dns-over-https.ts +61 -9
  115. package/src/expo-swift-bundle.ts +2 -7
  116. package/src/expo-swift-host.ts +11 -3
  117. package/src/host/fetch-proxy-handler.ts +51 -2
  118. package/src/host/fetch-proxy-overrides.ts +4 -0
  119. package/src/host/hostname-resolver.ts +9 -5
  120. package/src/native-app-identity-project.ts +13 -2
  121. package/src/native-app-identity.ts +47 -0
  122. package/src/nitro-adapter.lock.json +260 -260
  123. package/src/nitro-bundle.ts +7 -10
  124. package/src/nitro-superset.lock.json +4 -4
  125. package/src/podspec-sources.ts +20 -0
  126. package/src/storageSnapshotContract.ts +20 -1
  127. package/src/swift-compile.ts +409 -77
  128. package/src/swift-compiler-digest.ts +15 -0
  129. package/src/swift-coverage/xcode-packages.ts +3 -2
  130. package/src/swift-distribution.lock.json +12 -12
  131. package/src/swift-guest-archive.ts +153 -0
  132. package/src/swift-guest-compile.ts +449 -0
  133. package/src/swift-guest-image-ledger.ts +656 -0
  134. package/src/swift-guest-link-plan.ts +52 -0
  135. package/src/swift-guest-link.ts +1414 -0
  136. package/src/swift-guest-linked-spans.ts +338 -0
  137. package/src/swift-guest-manifest.ts +141 -0
  138. package/src/swift-guest-projection-storage.ts +310 -0
  139. package/src/swift-guest-projection.ts +252 -0
  140. package/src/swift-guest-runtime-plan.ts +834 -0
  141. package/src/swift-guest-source-inputs.ts +427 -0
  142. package/src/swift-guest-source-plan.ts +279 -0
  143. package/src/swift-host.ts +157 -36
  144. package/src/swift-icu.ts +60 -18
  145. package/src/swift-link-roots.ts +27 -50
  146. package/src/swift-package-manifest.ts +34 -18
  147. package/src/swift-package.ts +32 -2
  148. package/src/swift-packages.ts +138 -17
  149. package/src/swift-runtime-products.ts +73 -0
  150. package/src/swift-shared-sdk.ts +1 -1
  151. package/src/swift-submit.ts +15 -3
  152. package/src/swift-toolchain.ts +18 -0
  153. package/src/swift-wasm-prune.ts +313 -14
  154. package/src/swiftContract.ts +83 -0
  155. package/src/swiftRuntimeProductContract.ts +85 -45
  156. package/src/turbo-bundle.ts +1 -1
  157. package/src/turbo-codegen-intake.ts +10 -3
  158. package/src/turbo-runtime.lock.json +23 -23
  159. package/src/wasm-optimize.ts +16 -4
  160. package/src/xcode-project.ts +142 -14
package/src/swift-icu.ts CHANGED
@@ -5,7 +5,14 @@ import { mkdir, readFile, rename, writeFile } from 'node:fs/promises'
5
5
  import os from 'node:os'
6
6
  import path from 'node:path'
7
7
  import { promisify } from 'node:util'
8
- import { brotliCompress, constants as zlibConstants, gunzip, gzip } from 'node:zlib'
8
+ import {
9
+ brotliCompress,
10
+ constants as zlibConstants,
11
+ deflateRawSync,
12
+ gunzip,
13
+ gzip,
14
+ } from 'node:zlib'
15
+ import { SWIFT_ICU_PACKED, swiftIcuPack } from '../../sootsim-swift/src/icuData.ts'
9
16
  import { swiftEnvironment, swiftSdkOptions } from './swift-toolchain.ts'
10
17
 
11
18
  /**
@@ -15,11 +22,11 @@ import { swiftEnvironment, swiftSdkOptions } from './swift-toolchain.ts'
15
22
  * leaves out, so it is exactly the bytes the linker used to place: one blob
16
23
  * per toolchain release.
17
24
  *
18
- * node builtins only: the fixture harnesses import this file straight from
19
- * the checkout.
25
+ * node builtins and plain typescript only: the fixture harnesses import this
26
+ * file straight from the checkout.
20
27
  */
21
28
  export interface SwiftIcuAsset {
22
- /** sha256 of `gzip`, the address a host serves it at. */
29
+ /** sha256 of `gzip`: the blob's content address (swiftIcuAddress). */
23
30
  sha256: string
24
31
  /**
25
32
  * the blob gzipped, for local artifact receipts and clients without brotli
@@ -84,20 +91,6 @@ export function brotliCompressQ4(bytes: Buffer, cacheKey?: string): Promise<Buff
84
91
  return cachedBrotli(bytes, 4, cacheKey)
85
92
  }
86
93
 
87
- export async function swiftIcuBrotli(icu: SwiftIcuAsset): Promise<Buffer> {
88
- return (
89
- brotliMemoryCache.get(`11:${icu.sha256}`) ??
90
- brotliCompressQ11(await inflateGzip(icu.gzip), icu.sha256)
91
- )
92
- }
93
-
94
- export async function swiftIcuBrotliQ4(icu: SwiftIcuAsset): Promise<Buffer> {
95
- return (
96
- brotliMemoryCache.get(`4:${icu.sha256}`) ??
97
- brotliCompressQ4(await inflateGzip(icu.gzip), icu.sha256)
98
- )
99
- }
100
-
101
94
  async function memo<T>(
102
95
  cache: Map<string, T>,
103
96
  key: string,
@@ -219,3 +212,52 @@ function icuSegment(object: Buffer): Buffer {
219
212
  throw new Error(`swift-icu: expected one icu data segment, found ${found.length}`)
220
213
  return found[0]
221
214
  }
215
+
216
+ /**
217
+ * the packed file's name under a host's icu root: the blob's content address
218
+ * and the packed format (packages/sootsim-swift/src/icuData.ts).
219
+ */
220
+ export function swiftIcuAddress(icu: SwiftIcuAsset): string {
221
+ return `${icu.sha256}.${SWIFT_ICU_PACKED}`
222
+ }
223
+
224
+ const packedFiles = new Map<string, Buffer>()
225
+
226
+ /**
227
+ * the blob packed for on-demand reads: an index, the deflated table of
228
+ * contents and each deflated pack. a host serves it as is and answers range
229
+ * requests, so it carries no content encoding.
230
+ */
231
+ export function swiftIcuPacked(icu: SwiftIcuAsset): Promise<Buffer> {
232
+ return memo(packedFiles, icu.sha256, async () => {
233
+ const file = path.join(
234
+ os.homedir(),
235
+ '.peach',
236
+ 'cache',
237
+ 'swift-brotli',
238
+ swiftIcuAddress(icu),
239
+ )
240
+ if (existsSync(file)) return readFile(file)
241
+ const packed = Buffer.from(
242
+ swiftIcuPack(await inflateGzip(icu.gzip), (bytes) =>
243
+ deflateRawSync(bytes, { level: 9 }),
244
+ ),
245
+ )
246
+ await mkdir(path.dirname(file), { recursive: true })
247
+ const tmp = `${file}.${randomUUID()}.tmp`
248
+ await writeFile(tmp, packed)
249
+ await rename(tmp, file)
250
+ return packed
251
+ })
252
+ }
253
+
254
+ /** the packed icu file a bundle carries beside its wasm, at the path its icu url names. */
255
+ export async function swiftIcuBundleAsset(
256
+ icu: SwiftIcuAsset,
257
+ ): Promise<{ path: string; bytes: Buffer; contentType: string }> {
258
+ return {
259
+ path: `__peach/swift-icu/${swiftIcuAddress(icu)}`,
260
+ bytes: await swiftIcuPacked(icu),
261
+ contentType: 'application/octet-stream',
262
+ }
263
+ }
@@ -8,7 +8,10 @@ import path from 'node:path'
8
8
  // symbol reachability (swift-wasm-prune.ts).
9
9
  import { foundationCategoryObjects } from './swift-foundation'
10
10
 
11
- const OBJC_SEGMENTS = ['__objc_cats', '__objc_class_aliases']
11
+ const OBJC_SENTINELS = new Map([
12
+ ['__objc_cats', '.objc_null_category'],
13
+ ['__objc_class_aliases', '.objc_null_class_alias'],
14
+ ])
12
15
 
13
16
  const leb = (bytes: Uint8Array, at: { offset: number }): number => {
14
17
  let value = 0
@@ -21,17 +24,14 @@ const leb = (bytes: Uint8Array, at: { offset: number }): number => {
21
24
  }
22
25
  }
23
26
 
24
- // data segment name to its summed size in one wasm object, plus sentinels when
25
- // the object defines a wasm-exported symbol or a named ObjC category. a Swift
26
- // extension's category fills its segment's empty-terminator size exactly, so
27
- // only its symbol shows it. the linking section names each
28
- // segment and the data section sizes them in the same order.
29
- function objcSegmentSizes(bytes: Uint8Array): Map<string, number> {
27
+ // category and alias definitions share their segments with weak null records.
28
+ // read the actual data symbols so a single category is not mistaken for the
29
+ // equally sized null record.
30
+ function objcRootInfo(bytes: Uint8Array): { registration: boolean; exported: boolean } {
30
31
  const at = { offset: 8 }
31
32
  const names: string[] = []
32
- const sizes: number[] = []
33
+ const dataSymbols: { segment: number; name: string }[] = []
33
34
  let hasExportedSymbol = false
34
- let definesCategory = false
35
35
  while (at.offset < bytes.length) {
36
36
  const id = bytes[at.offset++]!
37
37
  const size = leb(bytes, at)
@@ -71,18 +71,15 @@ function objcSegmentSizes(bytes: Uint8Array): Map<string, number> {
71
71
  }
72
72
  } else if (symKind === 1) {
73
73
  const sLen = leb(bytes, at)
74
- if (
75
- !isUndef &&
76
- Buffer.from(bytes.subarray(at.offset, at.offset + sLen))
77
- .toString()
78
- .startsWith('.objc_category_')
79
- )
80
- definesCategory = true
74
+ const symbol = Buffer.from(
75
+ bytes.subarray(at.offset, at.offset + sLen),
76
+ ).toString()
81
77
  at.offset += sLen
82
78
  if (!isUndef) {
79
+ const segment = leb(bytes, at)
83
80
  leb(bytes, at)
84
81
  leb(bytes, at)
85
- leb(bytes, at)
82
+ dataSymbols.push({ segment, name: symbol })
86
83
  }
87
84
  } else if (symKind === 3) {
88
85
  leb(bytes, at)
@@ -92,40 +89,25 @@ function objcSegmentSizes(bytes: Uint8Array): Map<string, number> {
92
89
  at.offset = next
93
90
  }
94
91
  }
95
- } else if (id === 11) {
96
- for (let count = leb(bytes, at); count > 0; count--) {
97
- const flags = leb(bytes, at)
98
- if (flags === 2) leb(bytes, at)
99
- if (flags !== 1) {
100
- // an active segment's offset is one i32.const expression
101
- at.offset++
102
- leb(bytes, at)
103
- at.offset++
104
- }
105
- const length = leb(bytes, at)
106
- sizes.push(length)
107
- at.offset += length
108
- }
109
92
  }
110
93
  at.offset = end
111
94
  }
112
- const result = new Map<string, number>()
113
- names.forEach((name, index) => {
114
- if (OBJC_SEGMENTS.includes(name))
115
- result.set(name, (result.get(name) ?? 0) + (sizes[index] ?? 0))
116
- })
117
- result.set('__wasm_exported', hasExportedSymbol ? 1 : 0)
118
- result.set('__objc_category', definesCategory ? 1 : 0)
119
- return result
95
+ return {
96
+ registration: dataSymbols.some(({ segment, name }) => {
97
+ if (name.startsWith('.objc_category_')) return true
98
+ const sentinel = OBJC_SENTINELS.get(names[segment]!)
99
+ return sentinel !== undefined && name !== sentinel
100
+ }),
101
+ exported: hasExportedSymbol,
102
+ }
120
103
  }
121
104
 
122
105
  const rootsByDistribution = new Map<string, ReadonlySet<string>>()
123
106
 
124
107
  /**
125
108
  * the objects (relative to root) that define an ObjC category, class alias or
126
- * wasm-exported entrypoint. every object carries each section's empty
127
- * terminator, so a segment holds a definition when it outgrows the smallest one
128
- * the distribution has.
109
+ * wasm-exported entrypoint. real registration symbols are distinct from
110
+ * the runtime's empty category and alias terminators.
129
111
  */
130
112
  export function swiftObjcRootObjects(
131
113
  id: string,
@@ -135,24 +117,19 @@ export function swiftObjcRootObjects(
135
117
  const cached = rootsByDistribution.get(id)
136
118
  if (cached) return cached
137
119
  const measured = objects.map(
138
- (object) =>
139
- [object, objcSegmentSizes(fs.readFileSync(path.join(root, object)))] as const,
120
+ (object) => [object, objcRootInfo(fs.readFileSync(path.join(root, object)))] as const,
140
121
  )
141
- const empty = new Map<string, number>()
142
- for (const [, sizes] of measured)
143
- for (const [name, size] of sizes)
144
- empty.set(name, Math.min(empty.get(name) ?? size, size))
145
122
  const roots = new Set(
146
123
  measured
147
124
  .filter(
148
- ([object, sizes]) =>
125
+ ([object, info]) =>
149
126
  !foundationCategoryObjects.some(
150
127
  (name) => object === `lib/Foundation-${name}.o`,
151
128
  ) &&
152
129
  object !== 'lib/FoundationNetworking-Session.o' &&
153
130
  object !== 'lib/SwiftUI-MetalExecution.o' &&
154
131
  object !== 'lib/UIKitCore-NativeStub.o' &&
155
- [...sizes].some(([name, size]) => size > (empty.get(name) ?? 0)),
132
+ (info.registration || info.exported),
156
133
  )
157
134
  .map(([object]) => object),
158
135
  )
@@ -66,6 +66,7 @@ export interface SwiftManifestTarget {
66
66
  mainActorIsolation: boolean
67
67
  defines: SwiftManifestSetting[]
68
68
  libraries: SwiftManifestSetting[]
69
+ frameworks: SwiftManifestSetting[]
69
70
  experimentalFeatures: SwiftManifestSetting[]
70
71
  upcomingFeatures: SwiftManifestSetting[]
71
72
  swiftFlags: { flags: string[]; configuration: 'debug' | 'release' | null }[]
@@ -98,6 +99,11 @@ export interface SwiftManifestToolchain {
98
99
  version: string
99
100
  }
100
101
 
102
+ export interface SwiftManifestProduct {
103
+ targets: string[]
104
+ linkage: 'automatic' | 'static' | 'dynamic'
105
+ }
106
+
101
107
  export interface SwiftPackageManifest {
102
108
  toolchain: SwiftManifestToolchain
103
109
  name: string
@@ -105,8 +111,8 @@ export interface SwiftPackageManifest {
105
111
  dir: string
106
112
  /** the iOS version the manifest declares in platforms, null when it declares none. */
107
113
  iosDeployment: string | null
108
- /** library product name to the targets it vends. */
109
- products: Map<string, string[]>
114
+ /** evaluated library kind and the targets it vends. */
115
+ products: Map<string, SwiftManifestProduct>
110
116
  targets: Map<string, SwiftManifestTarget>
111
117
  /** package dependencies by identity and by any `name:` they carry. */
112
118
  packages: Map<string, { url: string } | { dir: string }>
@@ -441,14 +447,17 @@ export function swiftPackageManifest(
441
447
  if (alias) packages.set(alias.toLowerCase(), value)
442
448
  }
443
449
 
444
- const products = new Map<string, string[]>()
450
+ const products = new Map<string, SwiftManifestProduct>()
445
451
  for (const product of array(raw.products)) {
446
452
  const { name, targets, type } = record(product)
447
453
  if (!string(name) || !('library' in record(type))) continue
448
- products.set(
449
- string(name)!,
450
- array(targets).flatMap((target) => string(target) ?? []),
451
- )
454
+ const linkage = string(array(record(type).library)[0])
455
+ if (linkage !== 'automatic' && linkage !== 'static' && linkage !== 'dynamic')
456
+ throw new Error(`unsupported SwiftPM library linkage for ${String(name)}`)
457
+ products.set(string(name)!, {
458
+ targets: array(targets).flatMap((target) => string(target) ?? []),
459
+ linkage,
460
+ })
452
461
  }
453
462
 
454
463
  const targets = new Map<string, SwiftManifestTarget>()
@@ -503,6 +512,7 @@ export function swiftPackageManifest(
503
512
  let mainActorIsolation = false
504
513
  const defines: SwiftManifestSetting[] = []
505
514
  const libraries: SwiftManifestSetting[] = []
515
+ const frameworks: SwiftManifestSetting[] = []
506
516
  const experimentalFeatures: SwiftManifestSetting[] = []
507
517
  const upcomingFeatures: SwiftManifestSetting[] = []
508
518
  const swiftFlags: SwiftManifestTarget['swiftFlags'] = []
@@ -624,17 +634,22 @@ export function swiftPackageManifest(
624
634
  configuration,
625
635
  })
626
636
  }
627
- const library = string(record(settingKind.linkedLibrary)._0)
628
- if (
629
- library &&
630
- string(tool) === 'linker' &&
631
- linksOnPlatform(condition, traits, platforms)
632
- ) {
633
- const config = string(record(condition).config)
634
- libraries.push({
635
- name: library,
636
- configuration: config === 'debug' || config === 'release' ? config : null,
637
- })
637
+ for (const [kind, into] of [
638
+ ['linkedLibrary', libraries],
639
+ ['linkedFramework', frameworks],
640
+ ] as const) {
641
+ const name = string(record(settingKind[kind])._0)
642
+ if (
643
+ name &&
644
+ string(tool) === 'linker' &&
645
+ linksOnPlatform(condition, traits, platforms)
646
+ ) {
647
+ const config = string(record(condition).config)
648
+ into.push({
649
+ name,
650
+ configuration: config === 'debug' || config === 'release' ? config : null,
651
+ })
652
+ }
638
653
  }
639
654
  }
640
655
  if (!['5', '6'].includes(sourceLanguageMode))
@@ -655,6 +670,7 @@ export function swiftPackageManifest(
655
670
  mainActorIsolation,
656
671
  defines,
657
672
  libraries,
673
+ frameworks,
658
674
  experimentalFeatures,
659
675
  upcomingFeatures,
660
676
  swiftFlags,
@@ -42,8 +42,10 @@ export interface SwiftPackageTarget {
42
42
  linkedLibraries?: string[]
43
43
  /** true when declared or implicit resources give the target `Bundle.module`. */
44
44
  resources: boolean
45
- /** declared dependencies on other targets in the same package. */
45
+ /** declared dependencies; an explicit empty list also owns the local graph. */
46
46
  dependencies?: SwiftTargetDependency[]
47
+ /** explicit target-relative source files or directories, when declared. */
48
+ sources?: string[]
47
49
  /** explicit target-relative exclusions retained for resource discovery. */
48
50
  exclude?: string[]
49
51
  }
@@ -661,6 +663,29 @@ export function swiftManifestTargets(
661
663
  (match) => match[1]!,
662
664
  )
663
665
  const targetArguments = splitManifestArguments(call.slice(0, -1))
666
+ const sourceArgument = targetArguments.find((argument) =>
667
+ /^sources\s*:/.test(argument),
668
+ )
669
+ const sourceList = sourceArgument?.replace(/^sources\s*:\s*/, '').trim()
670
+ if (
671
+ sourceList &&
672
+ sourceList !== 'nil' &&
673
+ !(sourceList.startsWith('[') && sourceList.endsWith(']'))
674
+ )
675
+ throw new Error(`Unsupported sources expression in target ${name}: ${sourceList}`)
676
+ const sources =
677
+ sourceList?.startsWith('[') && sourceList.endsWith(']')
678
+ ? splitManifestArguments(sourceList.slice(1, -1)).map((source) => {
679
+ const literal = /^"((?:[^"\\]|\\.)*)"$/.exec(source)
680
+ if (!literal)
681
+ throw new Error(
682
+ `Unsupported source expression in target ${name}: ${source}`,
683
+ )
684
+ return swiftStringValue(literal[1]!, `a source of target ${name}`)
685
+ .replace(/^\.\//, '')
686
+ .replace(/\/+$/, '')
687
+ })
688
+ : undefined
664
689
  const dependencyArgument = targetArguments.find((argument) =>
665
690
  /^dependencies\s*:/.test(argument),
666
691
  )
@@ -702,7 +727,10 @@ export function swiftManifestTargets(
702
727
  ...(clangSettings.length === 0 ? {} : { clangSettings }),
703
728
  ...(linkedLibraries.length === 0 ? {} : { linkedLibraries }),
704
729
  resources,
705
- ...(dependencies.length === 0 ? {} : { dependencies }),
730
+ ...(dependencyList?.startsWith('[') && dependencyList.endsWith(']')
731
+ ? { dependencies }
732
+ : {}),
733
+ ...(sources === undefined ? {} : { sources }),
706
734
  ...(excluded.length === 0 ? {} : { exclude: excluded }),
707
735
  })
708
736
  }
@@ -784,6 +812,7 @@ export function swiftObjCResourceAccessor(bundleName: string): {
784
812
  const finder = `${accessorName}_SWIFTPM_MODULE_BUNDLER_FINDER`
785
813
  return {
786
814
  header: [
815
+ '#ifdef __OBJC__',
787
816
  '#import <Foundation/Foundation.h>',
788
817
  '',
789
818
  '__BEGIN_DECLS',
@@ -793,6 +822,7 @@ export function swiftObjCResourceAccessor(bundleName: string): {
793
822
  `#define SWIFTPM_MODULE_BUNDLE ${symbol}()`,
794
823
  '',
795
824
  '__END_DECLS',
825
+ '#endif',
796
826
  ].join('\n'),
797
827
  body: [
798
828
  '#import <Foundation/Foundation.h>',
@@ -35,6 +35,7 @@ import {
35
35
  type SwiftManifestTarget,
36
36
  type SwiftPackageManifest,
37
37
  } from './swift-package-manifest'
38
+ import type { SwiftSourceLinkGraph } from './swiftContract'
38
39
 
39
40
  // which machine a package target is built for
40
41
  type BuildSide = 'guest' | 'host'
@@ -47,6 +48,8 @@ export type SwiftPackageSource =
47
48
  | { kind: 'unnamed'; remoteUrls: string[] }
48
49
 
49
50
  export interface SwiftLinkedProduct {
51
+ /** attributes of the original frameworks-phase product edge. */
52
+ attributes?: string[]
50
53
  product: string
51
54
  source: SwiftPackageSource
52
55
  }
@@ -76,6 +79,10 @@ export interface SwiftPackageGap {
76
79
  }
77
80
 
78
81
  export interface SwiftPackages {
82
+ sourceLinks: {
83
+ targets: SwiftSourceLinkGraph['targets']
84
+ owners: { module: string; products: { target: string; attributes: string[] }[] }[]
85
+ }
79
86
  targets: SwiftPackageSourceTarget[]
80
87
  /** packages whose original graph builds both guest libraries and host macros. */
81
88
  nativePackages: {
@@ -126,12 +133,10 @@ export interface SwiftPackageBinary {
126
133
  // stand in from their own public interface with inert bodies, so an app's
127
134
  // calls compile and run and nothing is sent. an entry goes once the real sdk
128
135
  // compiles.
129
- export const SWIFT_PLACEHOLDER_PACKAGES: ReadonlyMap<string, string> = new Map([
130
- [
131
- 'dd-sdk-ios',
132
- "DatadogInternal's NetworkInstrumentation names URLSessionDataDelegate, URLSessionTaskDelegate and URLSessionTaskMetrics, which FoundationNetworking and the SDK's Objective-C Foundation headers both declare",
133
- ],
134
- ])
136
+ export const SWIFT_PLACEHOLDER_PACKAGES: ReadonlyMap<string, string> = new Map<
137
+ string,
138
+ string
139
+ >()
135
140
  const placeholderPackage = (pkg: LoadedPackage) =>
136
141
  SWIFT_PLACEHOLDER_PACKAGES.get(swiftPackageIdentity(pkg.manifest.dir))
137
142
 
@@ -491,7 +496,8 @@ export async function resolveSwiftPackagesAsync(
491
496
 
492
497
  /**
493
498
  * resolves `products` to the source targets that build them. products named
494
- * in `provided` are peach modules and link as those instead. without
499
+ * in `provided` link as peach modules unless explicitly linked source owns
500
+ * their target closure. without
495
501
  * `provided` (a hosted compile has no local module list) remote products
496
502
  * stay unresolved and only local packages compile.
497
503
  */
@@ -513,8 +519,9 @@ export function resolveSwiftPackages(options: {
513
519
  requirePrepared?: boolean
514
520
  }): SwiftPackages {
515
521
  const { rootDir, resolved, products, localDirs } = options
516
- const provided = options.provided ?? new Set<string>()
522
+ const provided = new Set(options.provided ?? [])
517
523
  const result: SwiftPackages = {
524
+ sourceLinks: { targets: [], owners: [] },
518
525
  targets: [],
519
526
  nativePackages: [],
520
527
  nativeProducts: [],
@@ -617,7 +624,7 @@ export function resolveSwiftPackages(options: {
617
624
  if (!nested) return []
618
625
  if (typeof nested === 'string') return [nested]
619
626
  const nestedManifest = manifestFor(nested, side)
620
- const roots = nestedManifest.products.get(dependency.name)
627
+ const roots = nestedManifest.products.get(dependency.name)?.targets
621
628
  return roots
622
629
  ? preservePackage(nested, roots, side)
623
630
  : [`${nestedManifest.name} has no library ${dependency.name}`]
@@ -673,6 +680,7 @@ export function resolveSwiftPackages(options: {
673
680
  path: '',
674
681
  dir: target.dir,
675
682
  files,
683
+ exclude: target.exclude,
676
684
  packageDir: pkg.manifest.dir,
677
685
  remote: pkg.remote,
678
686
  iosDeployment: pkg.manifest.iosDeployment,
@@ -701,7 +709,7 @@ export function resolveSwiftPackages(options: {
701
709
  const productOutcomes = new Map<string, { pkg: LoadedPackage; reason: string[] }>()
702
710
  const resolveProduct = (pkg: LoadedPackage, product: string): string[] => {
703
711
  if (provided.has(product)) return []
704
- const roots = pkg.manifest.products.get(product)
712
+ const roots = pkg.manifest.products.get(product)?.targets
705
713
  const reason = !roots
706
714
  ? [`${path.basename(pkg.manifest.dir)} has no library ${product}`]
707
715
  : blockers(roots.map((name) => resolveTarget(pkg, name)))
@@ -746,6 +754,35 @@ export function resolveSwiftPackages(options: {
746
754
  unnamedProducts.set(key, pkg)
747
755
  return pkg
748
756
  }
757
+ // linked source owns its regular targets and their source dependencies.
758
+ // binary and placeholder targets retain their existing providers.
759
+ const claimed = new Set<string>()
760
+ const claimTarget = (pkg: LoadedPackage, name: string): boolean => {
761
+ const key = `${pkg.manifest.dir}\0${name}`
762
+ if (claimed.has(key)) return true
763
+ const target = pkg.manifest.targets.get(name)
764
+ if (!target || target.type !== 'regular' || placeholderPackage(pkg)) return false
765
+ claimed.add(key)
766
+ provided.delete(name)
767
+ for (const dependency of target.dependencies) {
768
+ if (dependency.kind === 'target') claimTarget(pkg, dependency.name)
769
+ else {
770
+ const nested = dependencyPackage(pkg, dependency)
771
+ if (nested && typeof nested !== 'string') claimProduct(nested, dependency.name)
772
+ }
773
+ }
774
+ return true
775
+ }
776
+ const claimProduct = (pkg: LoadedPackage, product: string): void => {
777
+ const roots = pkg.manifest.products.get(product)?.targets ?? []
778
+ if (roots.map((name) => claimTarget(pkg, name)).some(Boolean))
779
+ provided.delete(product)
780
+ }
781
+ for (const { product, source } of products) {
782
+ if (source.kind === 'remote' && !options.provided) continue
783
+ const pkg = source.kind === 'unnamed' ? unnamed(source, product) : load(source)
784
+ if (pkg && typeof pkg !== 'string') claimProduct(pkg, product)
785
+ }
749
786
  for (const { product, source } of products) {
750
787
  if (provided.has(product)) continue
751
788
  if (source.kind === 'remote' && !options.provided) continue
@@ -870,7 +907,8 @@ export function resolveSwiftPackages(options: {
870
907
  else {
871
908
  const nested = dependencyPackage(pkg, dependency)
872
909
  if (nested && typeof nested !== 'string')
873
- for (const root of nested.manifest.products.get(dependency.name) ?? [])
910
+ for (const root of nested.manifest.products.get(dependency.name)?.targets ??
911
+ [])
874
912
  visit(nested, root)
875
913
  }
876
914
  }
@@ -881,7 +919,8 @@ export function resolveSwiftPackages(options: {
881
919
  ? unnamed(source, product)
882
920
  : packages.get(sourceKey(source))
883
921
  if (!pkg || typeof pkg === 'string') continue
884
- for (const root of pkg.manifest.products.get(product) ?? []) visit(pkg, root)
922
+ for (const root of pkg.manifest.products.get(product)?.targets ?? [])
923
+ visit(pkg, root)
885
924
  }
886
925
  return found
887
926
  }
@@ -910,7 +949,8 @@ export function resolveSwiftPackages(options: {
910
949
  else {
911
950
  const nested = dependencyPackage(owner, dependency)
912
951
  if (nested && typeof nested !== 'string')
913
- for (const root of nested.manifest.products.get(dependency.name) ?? [])
952
+ for (const root of nested.manifest.products.get(dependency.name)?.targets ??
953
+ [])
914
954
  visit(nested, root)
915
955
  }
916
956
  }
@@ -974,13 +1014,94 @@ export function resolveSwiftPackages(options: {
974
1014
  package: swiftPackageIdentity(nested.manifest.dir),
975
1015
  },
976
1016
  ]
977
- return (nested.manifest.products.get(dependency.name) ?? []).map((name) => ({
978
- kind: 'target',
979
- name,
980
- }))
1017
+ return (nested.manifest.products.get(dependency.name)?.targets ?? []).map(
1018
+ (name) => ({
1019
+ kind: 'target',
1020
+ name,
1021
+ }),
1022
+ )
981
1023
  },
982
1024
  )
983
1025
  }
1026
+ // retain the evaluated product boundary before targets are flattened into
1027
+ // the generated package. automatic products remain automatic here.
1028
+ const targetId = (pkg: LoadedPackage, name: string) =>
1029
+ path.join(pkg.manifest.dir, '#target', name)
1030
+ const productId = (pkg: LoadedPackage, name: string) =>
1031
+ path.join(pkg.manifest.dir, '#product', name)
1032
+ const emitted = new Set<string>()
1033
+ const addProduct = (pkg: LoadedPackage, name: string): string => {
1034
+ const id = productId(pkg, name)
1035
+ if (emitted.has(id)) return id
1036
+ emitted.add(id)
1037
+ const product = pkg.manifest.products.get(name)
1038
+ if (!product) throw new Error(`missing resolved library product ${name}`)
1039
+ result.sourceLinks.targets.push({
1040
+ id,
1041
+ sourceTarget: null,
1042
+ productName: name,
1043
+ productType: `swiftpm.library.${product.linkage}`,
1044
+ machOType: product.linkage === 'dynamic' ? 'mh_dylib' : 'staticlib',
1045
+ installName: null,
1046
+ buildVersion: { platform: null, minimumOS: pkg.manifest.iosDeployment, sdk: null },
1047
+ linkerFlags: [],
1048
+ dependencies: product.targets.map((name) => ({
1049
+ target: addTarget(pkg, name),
1050
+ attributes: [],
1051
+ })),
1052
+ })
1053
+ return id
1054
+ }
1055
+ const addTarget = (pkg: LoadedPackage, name: string): string => {
1056
+ const id = targetId(pkg, name)
1057
+ if (emitted.has(id)) return id
1058
+ emitted.add(id)
1059
+ const target = pkg.manifest.targets.get(name)
1060
+ if (!target) throw new Error(`missing resolved package target ${name}`)
1061
+ const dependencies =
1062
+ target.type === 'macro'
1063
+ ? []
1064
+ : target.dependencies.flatMap((dependency) => {
1065
+ if (dependency.kind === 'target')
1066
+ return pkg.manifest.targets.get(dependency.name)?.type === 'macro'
1067
+ ? []
1068
+ : [{ target: addTarget(pkg, dependency.name), attributes: [] }]
1069
+ const provider = dependencyPackage(pkg, dependency)
1070
+ if (!provider || typeof provider === 'string') return []
1071
+ return [{ target: addProduct(provider, dependency.name), attributes: [] }]
1072
+ })
1073
+ result.sourceLinks.targets.push({
1074
+ id,
1075
+ sourceTarget: target.type === 'regular' && !provided.has(name) ? name : null,
1076
+ productName: name,
1077
+ productType: `swiftpm.target.${target.type}`,
1078
+ machOType: null,
1079
+ installName: null,
1080
+ buildVersion: { platform: null, minimumOS: pkg.manifest.iosDeployment, sdk: null },
1081
+ linkerFlags: [
1082
+ ...target.libraries
1083
+ .filter((setting) => setting.configuration !== 'debug')
1084
+ .map((setting) => `-l${setting.name}`),
1085
+ ...target.frameworks
1086
+ .filter((setting) => setting.configuration !== 'debug')
1087
+ .flatMap((setting) => ['-framework', setting.name]),
1088
+ ],
1089
+ dependencies,
1090
+ })
1091
+ return id
1092
+ }
1093
+ for (const owner of options.owners ?? []) {
1094
+ const links: { target: string; attributes: string[] }[] = []
1095
+ for (const { product, source, attributes } of owner.products) {
1096
+ const pkg =
1097
+ source.kind === 'unnamed'
1098
+ ? unnamed(source, product)
1099
+ : packages.get(sourceKey(source))
1100
+ if (pkg && typeof pkg !== 'string' && pkg.manifest.products.has(product))
1101
+ links.push({ target: addProduct(pkg, product), attributes: attributes ?? [] })
1102
+ }
1103
+ result.sourceLinks.owners.push({ module: owner.module, products: links })
1104
+ }
984
1105
  result.nativePackages = [...nativePackages.values()].map(({ manifest, remote }) => ({
985
1106
  manifest,
986
1107
  remote,