peachsim 0.1.2773 → 0.1.2775

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 (148) hide show
  1. package/dist-lib/agent-daemon-client.cjs +1 -1
  2. package/dist-lib/agent-events.cjs +1 -1
  3. package/dist-lib/attached-projects.cjs +1 -1
  4. package/dist-lib/auth/shared-session.cjs +1 -1
  5. package/dist-lib/backend-origin.cjs +1 -1
  6. package/dist-lib/beta.cjs +1 -1
  7. package/dist-lib/beta.mjs +2 -2
  8. package/dist-lib/bridge-constants.cjs +1 -1
  9. package/dist-lib/bridge-contract-input.cjs +1 -1
  10. package/dist-lib/bridge-contract-input.mjs +5 -5
  11. package/dist-lib/bridge-contract.cjs +1 -1
  12. package/dist-lib/bridge-contract.mjs +3 -3
  13. package/dist-lib/bundle-channel.cjs +318 -199
  14. package/dist-lib/capture-contract.cjs +1 -1
  15. package/dist-lib/capture-contract.mjs +3 -3
  16. package/dist-lib/cloud-contract.cjs +1 -1
  17. package/dist-lib/cloud-contract.mjs +3 -3
  18. package/dist-lib/cloud-test-args.cjs +1 -1
  19. package/dist-lib/cloud-test-args.mjs +2 -2
  20. package/dist-lib/cloud.cjs +1 -1
  21. package/dist-lib/cloud.mjs +7 -7
  22. package/dist-lib/config.cjs +1 -1
  23. package/dist-lib/config.mjs +5 -5
  24. package/dist-lib/detox/index.cjs +1 -1
  25. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  26. package/dist-lib/esm-chunks/{acorn-3SGU25AX.mjs → acorn-CTIC3GCU.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-KMMFDGYA.mjs → chunk-2YTHEKWJ.mjs} +1 -1
  28. package/dist-lib/esm-chunks/{chunk-2HWUPAOD.mjs → chunk-3WU4YTJR.mjs} +205 -166
  29. package/dist-lib/esm-chunks/{chunk-ORGP6SSO.mjs → chunk-4B46TF64.mjs} +1 -1
  30. package/dist-lib/esm-chunks/{chunk-QMI7ECNF.mjs → chunk-C5EU2DRL.mjs} +1 -1
  31. package/dist-lib/esm-chunks/{chunk-DFVWY2BW.mjs → chunk-CFNSLWMQ.mjs} +4 -4
  32. package/dist-lib/esm-chunks/{chunk-HN7CHPZK.mjs → chunk-E6ULRDAP.mjs} +1 -1
  33. package/dist-lib/esm-chunks/{chunk-IQF674WE.mjs → chunk-ESP2U4IX.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-5DQRSOJ5.mjs → chunk-ESWEEZZP.mjs} +2 -2
  35. package/dist-lib/esm-chunks/{chunk-4FVDW5QX.mjs → chunk-FBN2C43P.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-NH3CEIBN.mjs → chunk-FVUN2533.mjs} +3 -3
  37. package/dist-lib/esm-chunks/{chunk-IM2IAOAZ.mjs → chunk-GKKZLYBA.mjs} +1 -1
  38. package/dist-lib/esm-chunks/{chunk-SZ7TVJHH.mjs → chunk-H5TBKFDB.mjs} +1 -1
  39. package/dist-lib/esm-chunks/{chunk-GSZLZNZM.mjs → chunk-ITTQHQD5.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-XXLSXSUK.mjs → chunk-JERE5CAK.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-WBPJJXMA.mjs → chunk-MJSKVK7E.mjs} +1 -1
  42. package/dist-lib/esm-chunks/{chunk-Q2EEH42W.mjs → chunk-NV5NLKKN.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-G5TS3L6A.mjs → chunk-RGOPQX37.mjs} +6 -6
  44. package/dist-lib/esm-chunks/{chunk-KEVJJ3QT.mjs → chunk-S47B7YHJ.mjs} +1 -1
  45. package/dist-lib/esm-chunks/{chunk-FRPS6V6P.mjs → chunk-SK4FQLNJ.mjs} +1 -1
  46. package/dist-lib/esm-chunks/{chunk-YZRKIUVZ.mjs → chunk-TE3WHBF3.mjs} +1 -1
  47. package/dist-lib/esm-chunks/{chunk-ANTOZ3UC.mjs → chunk-W42DUKWD.mjs} +1 -1
  48. package/dist-lib/esm-chunks/{chunk-DYKZYFHH.mjs → chunk-WB5OWF4G.mjs} +5 -5
  49. package/dist-lib/esm-chunks/{chunk-KZ2NH7C4.mjs → chunk-XMBGLLON.mjs} +1 -1
  50. package/dist-lib/esm-chunks/{chunk-MRQ72NMR.mjs → chunk-YRKGWASL.mjs} +6 -6
  51. package/dist-lib/esm-chunks/{metro-layout-parser-5MEY33AK.mjs → metro-layout-parser-2RQ3WC37.mjs} +3 -3
  52. package/dist-lib/esm-chunks/{swift-package-prebuilt-3FLCNBQT.mjs → swift-package-prebuilt-L5SWVH6U.mjs} +12 -12
  53. package/dist-lib/esm-chunks/{swift-sdk-app-module-PPJ4LUOW.mjs → swift-sdk-app-module-5SWDBTBY.mjs} +107 -25
  54. package/dist-lib/esm-chunks/{swift-sdk-image-L5MERITP.mjs → swift-sdk-image-OOSMI47A.mjs} +16 -16
  55. package/dist-lib/esm-chunks/{swift-sdk-image-producer-IILRYXVN.mjs → swift-sdk-image-producer-DL4VEBXN.mjs} +5 -5
  56. package/dist-lib/expo-swift-bundle.cjs +318 -199
  57. package/dist-lib/expo-swift-metadata.cjs +1 -1
  58. package/dist-lib/expo-swift-metadata.mjs +7 -7
  59. package/dist-lib/home-paths.cjs +1 -1
  60. package/dist-lib/host/bridge-host.cjs +4327 -4209
  61. package/dist-lib/host/fetch-proxy-handler.cjs +343 -340
  62. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  63. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
  64. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  65. package/dist-lib/host/websocket-proxy.cjs +1 -1
  66. package/dist-lib/index.cjs +1 -1
  67. package/dist-lib/kotlin-host.cjs +1 -1
  68. package/dist-lib/menu.cjs +1 -1
  69. package/dist-lib/menu.mjs +3 -3
  70. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  71. package/dist-lib/metro-fingerprint-registry.mjs +3 -3
  72. package/dist-lib/metro-production-bundle.cjs +1 -1
  73. package/dist-lib/metro-production-bundle.mjs +4 -4
  74. package/dist-lib/native-app-identity-project.cjs +1 -1
  75. package/dist-lib/native-app-identity-project.mjs +15 -15
  76. package/dist-lib/native-app-identity.cjs +1 -1
  77. package/dist-lib/native-app-identity.mjs +6 -6
  78. package/dist-lib/native-firebase-metadata.cjs +1 -1
  79. package/dist-lib/native-firebase-metadata.mjs +3 -3
  80. package/dist-lib/pdfium-raster.cjs +1 -1
  81. package/dist-lib/pdfium-raster.mjs +2 -2
  82. package/dist-lib/plist.cjs +1 -1
  83. package/dist-lib/plist.mjs +3 -3
  84. package/dist-lib/profiles.cjs +1 -1
  85. package/dist-lib/public-brand.cjs +1 -1
  86. package/dist-lib/public-origins-lib-esm.json +86 -86
  87. package/dist-lib/public-origins-lib.json +96 -96
  88. package/dist-lib/react-native-host-modules.cjs +1 -1
  89. package/dist-lib/react-native-host-modules.mjs +2 -2
  90. package/dist-lib/reap-browser.cjs +1 -1
  91. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  92. package/dist-lib/sdk.cjs +1 -1
  93. package/dist-lib/sdk.mjs +8 -8
  94. package/dist-lib/skills.cjs +2912 -2794
  95. package/dist-lib/swift-compile.cjs +314 -195
  96. package/dist-lib/swift-compile.mjs +12 -12
  97. package/dist-lib/swift-package.cjs +1 -1
  98. package/dist-lib/swift-package.mjs +3 -3
  99. package/dist-lib/swift-submit.cjs +1 -1
  100. package/dist-lib/swift-submit.mjs +6 -6
  101. package/dist-lib/swift-svg-raster.cjs +1 -1
  102. package/dist-lib/swift-svg-raster.mjs +2 -2
  103. package/dist-lib/swift-toolchain.cjs +1 -1
  104. package/dist-lib/swift.cjs +1 -1
  105. package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
  106. package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
  107. package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
  108. package/dist-lib/vendor/acorn.cjs +1 -1
  109. package/dist-lib/vendor/magic-string.cjs +1 -1
  110. package/dist-lib/vendor/stream-json.cjs +1 -1
  111. package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
  112. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
  113. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
  114. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
  115. package/dist-lib/vendor/sucrase.cjs +1 -1
  116. package/dist-lib/vendor/terser.cjs +1 -1
  117. package/dist-lib/vendor/valibot.cjs +1 -1
  118. package/dist-lib/vendor/ws.cjs +1 -1
  119. package/dist-lib/vendor/zod.cjs +1 -1
  120. package/dist-lib/worklet-executable.cjs +1 -1
  121. package/dist-lib/worklet-executable.mjs +3 -3
  122. package/dist-types/packages/peach-engine/src/ios/duo-vertical-bar-geometry.d.ts +0 -15
  123. package/dist-types/packages/peach-engine/src/ios/flex-interaction.d.ts +0 -1
  124. package/dist-types/packages/peach-engine/src/react-native/AppState.d.ts +0 -1
  125. package/dist-types/packages/peach-engine/src/react-native/Keyboard.d.ts +0 -1
  126. package/dist-types/packages/peach-kit/src/ring-mode-state.d.ts +0 -1
  127. package/dist-types/packages/peach-kit/src/transitions/screen-transition-math.d.ts +0 -31
  128. package/package.json +1 -1
  129. package/src/assetCatalogContract.ts +0 -6
  130. package/src/expo-pod-prebuilt.ts +0 -63
  131. package/src/native-package-slice.ts +0 -2
  132. package/src/podfile-cocoapods.ts +0 -5
  133. package/src/runtime-assets.ts +0 -9
  134. package/src/sfSymbolMetricsContract.ts +51 -23
  135. package/src/swift-compile.ts +9 -6
  136. package/src/swift-distribution-mirror.ts +16 -5
  137. package/src/swift-guest-compile.ts +18 -7
  138. package/src/swift-guest-link.ts +0 -9
  139. package/src/swift-guest-projection-storage.ts +15 -2
  140. package/src/swift-guest-projection.ts +1 -46
  141. package/src/swift-guest-runtime-plan.ts +4 -80
  142. package/src/swift-header-compiler.ts +24 -9
  143. package/src/swift-sdk-app-module.ts +113 -10
  144. package/src/swift-wasm-prune.ts +0 -5
  145. package/src/swiftRuntimeProductContract.ts +1 -0
  146. package/src/swiftSdkLinkContract.ts +10 -0
  147. package/src/wasm-narrow-boundary.ts +0 -13
  148. package/src/wasm-lazy-split-tool.ts +0 -210
@@ -68,13 +68,6 @@ export function sfSymbolMetricRow(drawing: SfSymbolImageMetadata): SfSymbolMetri
68
68
  }
69
69
  }
70
70
 
71
- function variantIndex(scale: SfSymbolScale, weight: SfSymbolWeight): number {
72
- return (
73
- SF_SYMBOL_SCALES.indexOf(scale) * SF_SYMBOL_WEIGHTS.length +
74
- SF_SYMBOL_WEIGHTS.indexOf(weight)
75
- )
76
- }
77
-
78
71
  function knotIndex(scale: SfSymbolScale, knot: SfSymbolWeight) {
79
72
  let before = 0
80
73
  for (const earlier of SF_SYMBOL_SCALES) {
@@ -179,6 +172,33 @@ function variantKey(scale: SfSymbolScale, weight: SfSymbolWeight): string {
179
172
  return `${scale}-${weight}`
180
173
  }
181
174
 
175
+ interface VariantLayout {
176
+ lowBase: number
177
+ highBase: number
178
+ t: number
179
+ constBase: number
180
+ }
181
+
182
+ const VARIANT_LAYOUTS = new Map<SfSymbolScale, Map<SfSymbolWeight, VariantLayout>>(
183
+ SF_SYMBOL_SCALES.map((scale, si) => [
184
+ scale,
185
+ new Map(
186
+ SF_SYMBOL_WEIGHTS.map((weight, wi) => {
187
+ const { lowKnot, highKnot, t } = bracket(scale, weight)
188
+ return [
189
+ weight,
190
+ {
191
+ lowBase: knotIndex(scale, lowKnot) * COLUMNS.length,
192
+ highBase: knotIndex(scale, highKnot) * COLUMNS.length,
193
+ t,
194
+ constBase: (si * SF_SYMBOL_WEIGHTS.length + wi) * CONSTANTS.length,
195
+ },
196
+ ]
197
+ }),
198
+ ),
199
+ ]),
200
+ )
201
+
182
202
  export class SfSymbolMetrics {
183
203
  private readonly nameBytes: Uint8Array
184
204
  private readonly indices: Uint32Array
@@ -267,25 +287,33 @@ export class SfSymbolMetrics {
267
287
  row(name: string, scale: SfSymbolScale, weight: SfSymbolWeight) {
268
288
  const at = this.lookupRow(name)
269
289
  if (at < 0) return undefined
270
- const { lowKnot, highKnot, t } = bracket(scale, weight)
290
+ const layout = VARIANT_LAYOUTS.get(scale)?.get(weight)
291
+ if (!layout) return undefined
292
+ const { lowBase, highBase, t, constBase } = layout
271
293
  const count = this.rowCount
272
- const read = (knot: SfSymbolWeight, column: number) =>
273
- this.columns[(knotIndex(scale, knot) * COLUMNS.length + column) * count + at]!
274
- const value = (column: number) => {
275
- const low = read(lowKnot, column)
276
- return t === 0 ? low : low + (read(highKnot, column) - low) * t
294
+ const columns = this.columns
295
+ const constants = this.constants
296
+ const lowOffset = lowBase * count + at
297
+ let w = columns[lowOffset]!
298
+ let h = columns[lowOffset + count]!
299
+ let left = columns[lowOffset + count * 2]!
300
+ let right = columns[lowOffset + count * 3]!
301
+ let baseline = columns[lowOffset + count * 4]!
302
+ if (t !== 0) {
303
+ const highOffset = highBase * count + at
304
+ w += (columns[highOffset]! - w) * t
305
+ h += (columns[highOffset + count]! - h) * t
306
+ left += (columns[highOffset + count * 2]! - left) * t
307
+ right += (columns[highOffset + count * 3]! - right) * t
308
+ baseline += (columns[highOffset + count * 4]! - baseline) * t
277
309
  }
278
- const constant = (key: (typeof CONSTANTS)[number]) =>
279
- this.constants[
280
- variantIndex(scale, weight) * CONSTANTS.length + CONSTANTS.indexOf(key)
281
- ]!
282
310
  const metadata: SfSymbolImageMetadata = {
283
- referencePointSize: constant('referencePointSize'),
284
- basePointSize: constant('basePointSize'),
285
- baselineOffsetUnrounded: value(4),
286
- capHeightUnrounded: constant('cap'),
287
- referenceCanvasSize: [value(0), value(1)],
288
- insets: [value(2), constant('top'), value(3), constant('bottom')],
311
+ referencePointSize: constants[constBase]!,
312
+ basePointSize: constants[constBase + 1]!,
313
+ baselineOffsetUnrounded: baseline,
314
+ capHeightUnrounded: constants[constBase + 4]!,
315
+ referenceCanvasSize: [w, h],
316
+ insets: [left, constants[constBase + 2]!, right, constants[constBase + 3]!],
289
317
  layers: [],
290
318
  }
291
319
  return metadata
@@ -7934,7 +7934,10 @@ async function compileSwiftProjectOnce(
7934
7934
  !options.project &&
7935
7935
  !input.optimize &&
7936
7936
  !input.unoptimized
7937
- const perFile = input.unoptimized || incrementalPreview
7937
+ const batchGuest =
7938
+ guestGraph !== undefined && !options.project && !input.unoptimized
7939
+ const batch = incrementalPreview || batchGuest
7940
+ const perFile = input.unoptimized || batch
7938
7941
  const reproducibleFrameworkRoot = mirrorDistribution
7939
7942
  ? frameworkRoot
7940
7943
  : compileFrameworkRoot
@@ -7964,12 +7967,12 @@ async function compileSwiftProjectOnce(
7964
7967
  '-Xswiftc',
7965
7968
  '-j',
7966
7969
  '-Xswiftc',
7967
- String(jobs),
7970
+ String(batchGuest ? Math.min(8, jobs) : jobs),
7968
7971
  ]
7969
7972
  : []),
7970
- ...(incrementalPreview
7971
- ? ['-Xswiftc', '-incremental', '-Xswiftc', '-enable-batch-mode']
7972
- : []),
7973
+ // optimized batches can move specialized definitions between objects.
7974
+ ...(incrementalPreview ? ['-Xswiftc', '-incremental'] : []),
7975
+ ...(batch ? ['-Xswiftc', '-enable-batch-mode'] : []),
7973
7976
  // the mirror finds a changed sdk header's readers in their
7974
7977
  // dependency files, which omit system headers by default
7975
7978
  ...(mirrorDistribution ? ['-Xswiftc', '-track-system-dependencies'] : []),
@@ -7983,7 +7986,7 @@ async function compileSwiftProjectOnce(
7983
7986
  '-g0',
7984
7987
  '-Xcxx',
7985
7988
  '-g0',
7986
- ...(incrementalPreview
7989
+ ...(batch
7987
7990
  ? []
7988
7991
  : [
7989
7992
  '-Xswiftc',
@@ -27,6 +27,10 @@ import {
27
27
  swiftSharedSdkViewOptions,
28
28
  } from './swift-shared-sdk'
29
29
  import { isSwiftResourcePath } from './swiftContract'
30
+ import {
31
+ SWIFT_SDK_PRODUCT_DIRECTORY,
32
+ SWIFT_SDK_PRODUCT_FILE,
33
+ } from './swiftRuntimeProductContract'
30
34
  import { SWIFT_WASM_TRIPLE } from './swiftTargetContract'
31
35
 
32
36
  export const SWIFT_DISTRIBUTION_MIRROR = '.peach-distribution'
@@ -37,6 +41,7 @@ const SWIFT_SDK_MIRROR_RECORD = '.peach-sdk-mirror.json'
37
41
  const SWIFT_SDK_MIRROR_SYNCING = '.peach-sdk-syncing'
38
42
  const SWIFT_SDK_MIRROR_BUNDLE = 'peach-wasm.artifactbundle'
39
43
  const SWIFT_DISTRIBUTION_MIRROR_SYNCING = '.peach-distribution-syncing'
44
+ const SDK_PRODUCT_CATALOG = `${SWIFT_SDK_PRODUCT_DIRECTORY}/${SWIFT_SDK_PRODUCT_FILE}`
40
45
 
41
46
  export interface SwiftMirrorSdk {
42
47
  id: string
@@ -139,16 +144,20 @@ export function syncSwiftSdkMirrorFromView(
139
144
  const options = ['--swift-sdks-path', mirror]
140
145
  const interrupted = existsSync(syncingMarker)
141
146
  const previous = interrupted ? null : readSdkRecord(recordFile)
147
+ const sourceTriple = resolveSdkViewTripleDir(sourceView, sourceSdkId)
148
+ const catalog = path.join(destTriple, SDK_PRODUCT_CATALOG)
149
+ const sourceCatalog = path.join(sourceTriple, SDK_PRODUCT_CATALOG)
142
150
  if (
143
151
  previous &&
144
152
  previous.sourceView === sourceView &&
145
153
  previous.sourceSdkId === sourceSdkId &&
146
154
  existsSync(bundleInfo) &&
147
- existsSync(path.join(destTriple, 'swift-sdk.json'))
155
+ existsSync(path.join(destTriple, 'swift-sdk.json')) &&
156
+ (!lstatSync(sourceCatalog, { throwIfNoEntry: false })?.isSymbolicLink() ||
157
+ lstatSync(catalog, { throwIfNoEntry: false })?.isSymbolicLink())
148
158
  ) {
149
159
  return { id: SWIFT_SDK_MIRROR_ID, options, toolsetChanged: false }
150
160
  }
151
- const sourceTriple = resolveSdkViewTripleDir(sourceView, sourceSdkId)
152
161
  if (!previous) {
153
162
  if (!interrupted) rmSync(mirror, { recursive: true, force: true })
154
163
  rmSync(path.join(root, '.build'), { recursive: true, force: true })
@@ -200,7 +209,8 @@ export function syncSwiftSdkMirrorFromView(
200
209
  !file.endsWith('.a') &&
201
210
  !file.endsWith('.o') &&
202
211
  !file.startsWith('rust/') &&
203
- file !== 'runtime-products.json',
212
+ file !== SWIFT_SDK_PRODUCT_FILE &&
213
+ file !== SDK_PRODUCT_CATALOG,
204
214
  )
205
215
  const headersChanged = compileTouched.some(
206
216
  (file) =>
@@ -291,8 +301,9 @@ function syncSdkTree(
291
301
  const dest = path.join(destDir, entry.name)
292
302
  const destLstat = lstatSync(dest, { throwIfNoEntry: false })
293
303
  if (entry.isSymbolicLink()) {
294
- const target = readlinkSync(src)
295
- if (target.startsWith(distributionPrefix)) {
304
+ const target = path.resolve(sourceDir, readlinkSync(src))
305
+ // the guest linker uses the catalog's real path to locate original archives.
306
+ if (target.startsWith(distributionPrefix) || rel === SDK_PRODUCT_CATALOG) {
296
307
  if (destLstat?.isSymbolicLink() && readlinkSync(dest) === target) continue
297
308
  if (destLstat) rmSync(dest, { recursive: true, force: true })
298
309
  symlinkSync(target, dest)
@@ -547,7 +547,6 @@ export async function compileGuestLink(options: {
547
547
  linkSwiftAppModule,
548
548
  readSwiftSdkUsage,
549
549
  swiftAppModuleThunkSection,
550
- swiftSdkProjectionDigest,
551
550
  swiftSdkProjectionSpans,
552
551
  writeSwiftSdkAppLink,
553
552
  } = await import('./swift-sdk-app-module')
@@ -721,17 +720,29 @@ export async function compileGuestLink(options: {
721
720
  if (project) return binding
722
721
  const replayDirectory = path.join(options.buildDirectory, '.peach-sdk-module')
723
722
  mkdirSync(replayDirectory, { recursive: true })
723
+ const directValues = new Set(link.globalValues)
724
+ for (const values of [data, linkage.tls])
725
+ for (let index = 2; index < values.length; index += 3)
726
+ directValues.add(values[index]!)
724
727
  const appLink = writeSwiftSdkAppLink(
725
728
  path.join(replayDirectory, 'app-link.json.gz'),
726
729
  {
727
- linkage,
730
+ linkage: {
731
+ ...linkage,
732
+ replayProjection: {
733
+ sdk: sdk.key,
734
+ staticEnd: link.staticEnd,
735
+ countAddresses: finalized.countAddresses,
736
+ images: finalized.appImages,
737
+ objects: [...sdkObjectImages],
738
+ products: [...sdkProductImages],
739
+ lookupValues: [...new Set(bindingRows.values())].filter(
740
+ (index) => !directValues.has(index),
741
+ ),
742
+ },
743
+ },
728
744
  usage,
729
745
  scopedLookups: true,
730
- sdkProjection: {
731
- objects: [...sdkObjectImages],
732
- products: [...sdkProductImages],
733
- layoutSha256: swiftSdkProjectionDigest(sdkSpans),
734
- },
735
746
  },
736
747
  )
737
748
  return { ...binding, appLink }
@@ -256,15 +256,6 @@ export function guestLinkInputFiles(args: readonly string[]): string[] {
256
256
  return guestLinkInputFilesWithKind(args).map((item) => item.path)
257
257
  }
258
258
 
259
- /** Actual object and archive inputs that have not been assigned to an image. */
260
- export function unownedGuestLinkInputs(
261
- plan: GuestLinkPlan,
262
- args: readonly string[],
263
- ): string[] {
264
- const owned = new Set(plan.artifacts.map((artifact) => path.resolve(artifact.path)))
265
- return guestLinkInputFiles(args).filter((file) => !owned.has(file))
266
- }
267
-
268
259
  function occurrences(plan: GuestLinkPlan, args: readonly string[]): InputOccurrence[] {
269
260
  const dirs: string[] = []
270
261
  for (let i = 0; i < args.length; i++) {
@@ -275,7 +275,7 @@ export function finalizeGuestProjectionStorage(options: {
275
275
  readonly projectionObject: string
276
276
  readonly reserved: ReservedGuestProjectionStorage
277
277
  readonly sdkSpans?: readonly GuestLinkedSpan[]
278
- }): { readonly wasm: Uint8Array; readonly images: readonly SwiftGuestImageManifest[] } {
278
+ }) {
279
279
  const owner = options.owners.get(options.projectionObject)
280
280
  if (owner === undefined) throw new Error('guest projection object has no image owner')
281
281
  const ranges: GuestLinkedSpan[] = []
@@ -306,6 +306,7 @@ export function finalizeGuestProjectionStorage(options: {
306
306
  const result = Buffer.from(options.optimized)
307
307
  const locations = new Map<number, number>()
308
308
  const counts = new Map<number, number>()
309
+ const countAddresses: number[] = []
309
310
  const uuids = new Map<number, number>()
310
311
  const markers = new Map(
311
312
  options.reserved.countMarkers.map((marker, index) => [marker, index]),
@@ -338,6 +339,7 @@ export function finalizeGuestProjectionStorage(options: {
338
339
  if (counts.has(count))
339
340
  throw new Error('duplicate guest projection count marker')
340
341
  counts.set(count, offset)
342
+ countAddresses[count] = segment.address + offset - segment.offset
341
343
  }
342
344
  if (
343
345
  offset > end - 8 ||
@@ -392,5 +394,16 @@ export function finalizeGuestProjectionStorage(options: {
392
394
  result.writeUInt32LE(region?.initialProtection ?? 0, offset + 8)
393
395
  result.writeUInt32LE(region?.maximumProtection ?? 0, offset + 12)
394
396
  }
395
- return { wasm: result, images }
397
+ return {
398
+ wasm: result,
399
+ images,
400
+ countAddresses,
401
+ appImages: options.sdkSpans
402
+ ? planGuestProjectionRegions(
403
+ options.reserved.images,
404
+ options.reserved.capacities,
405
+ spans,
406
+ )
407
+ : images,
408
+ }
396
409
  }
@@ -1,8 +1,4 @@
1
- import {
2
- guestLinkedSpans,
3
- guestWasmDataSegments,
4
- type GuestLinkedSpan,
5
- } from './swift-guest-linked-spans'
1
+ import { guestWasmDataSegments } from './swift-guest-linked-spans'
6
2
  import {
7
3
  isSwiftGuestImageManifest,
8
4
  type SwiftGuestImageManifest,
@@ -169,47 +165,6 @@ export function finalizeGuestImageProjection(
169
165
  return result
170
166
  }
171
167
 
172
- /** Bind manifests to the final map and optimized module, then fill their ranges. */
173
- export function finalizeLinkedGuestImages(options: {
174
- readonly map: string
175
- readonly linked: Uint8Array
176
- readonly optimized: Uint8Array
177
- readonly owners: ReadonlyMap<string, number>
178
- readonly sectionOwners: ReadonlyMap<string, number>
179
- readonly projectionObject: string
180
- readonly reserved: ReservedGuestImageProjection
181
- readonly manifests: (
182
- spans: readonly GuestLinkedSpan[],
183
- ) => readonly SwiftGuestImageManifest[]
184
- }): { readonly wasm: Uint8Array; readonly images: readonly SwiftGuestImageManifest[] } {
185
- const image = options.owners.get(options.projectionObject)
186
- if (image === undefined) throw new Error('guest projection object has no image owner')
187
- const projectionData: GuestLinkedSpan[] = []
188
- const spans = guestLinkedSpans(
189
- options.map,
190
- options.linked,
191
- options.optimized,
192
- options.owners,
193
- options.sectionOwners,
194
- false,
195
- {
196
- trackedObject: options.projectionObject,
197
- trackedObjectOwner: image,
198
- trackedLinearSpans: projectionData,
199
- },
200
- )
201
- const images = options.manifests(spans)
202
- return {
203
- images,
204
- wasm: finalizeGuestImageProjection(
205
- options.optimized,
206
- options.reserved,
207
- images,
208
- projectionData,
209
- ),
210
- }
211
- }
212
-
213
168
  // emit exact utf8 bytes; octal escapes have fixed width even before a digit.
214
169
  function cString(value: string): string {
215
170
  return `"${[...Buffer.from(value, 'utf8')]
@@ -15,6 +15,7 @@ import {
15
15
  } from './swift-wasm-prune'
16
16
  import {
17
17
  SWIFT_FRAMEWORK_PRODUCT_FILE,
18
+ SWIFT_SDK_PRODUCT_DIRECTORY,
18
19
  SWIFT_SDK_PRODUCT_FILE,
19
20
  swiftFrameworkProductSchema,
20
21
  swiftSdkProductsSchema,
@@ -28,7 +29,6 @@ import type {
28
29
  GuestLinkSelection,
29
30
  } from './swift-guest-link-plan'
30
31
 
31
- const SDK_CATALOG_DIRECTORY = 'swift.xctoolchain/usr/lib/swift_static/wasi'
32
32
  export const SDK_CONTAINING_IMAGE = 'wasi/containing-image'
33
33
 
34
34
  function canonicalArchivePath(file: string): string {
@@ -44,10 +44,10 @@ function sdkArtifactBytes(root: string, artifact: SwiftSdkProduct['artifacts'][n
44
44
  if (hash(linked) === artifact.sha256) return { source: linked, linked }
45
45
  if (
46
46
  artifact.kind !== 'archive' ||
47
- artifact.path !== `${SDK_CATALOG_DIRECTORY}/libFoundation.a`
47
+ artifact.path !== `${SWIFT_SDK_PRODUCT_DIRECTORY}/libFoundation.a`
48
48
  )
49
49
  throw new Error(`SDK product artifact changed ${file}`)
50
- const catalog = path.join(root, SDK_CATALOG_DIRECTORY, SWIFT_SDK_PRODUCT_FILE)
50
+ const catalog = path.join(root, SWIFT_SDK_PRODUCT_DIRECTORY, SWIFT_SDK_PRODUCT_FILE)
51
51
  const sourceDirectory = path.dirname(realpathSync(catalog))
52
52
  const source = readFileSync(path.join(sourceDirectory, 'libFoundation.a'))
53
53
  if (hash(source) !== artifact.sha256)
@@ -108,13 +108,7 @@ export function readGuestRuntimeCatalogs(
108
108
  )
109
109
  const sdk = v.parse(
110
110
  swiftSdkProductsSchema,
111
- read(
112
- path.join(
113
- sdkRoot,
114
- 'swift.xctoolchain/usr/lib/swift_static/wasi',
115
- SWIFT_SDK_PRODUCT_FILE,
116
- ),
117
- ),
111
+ read(path.join(sdkRoot, SWIFT_SDK_PRODUCT_DIRECTORY, SWIFT_SDK_PRODUCT_FILE)),
118
112
  )
119
113
  const distribution = v.parse(
120
114
  swiftSdkProductsSchema,
@@ -798,73 +792,3 @@ export function guestCxxMemberOwners(
798
792
  return { origin: match.original, image: owner.image, sha256: match.sha256 }
799
793
  })
800
794
  }
801
-
802
- /** Own runtime archives and unpacked SDK members actually supplied to the link. */
803
- export function guestCxxLinkArtifacts(
804
- sdk: SwiftPrunedSdkInputs,
805
- linkedArchives: readonly string[],
806
- products: GuestCxxProducts,
807
- ): GuestLinkArtifact[] {
808
- const runtimeArchives = new Set(
809
- [products.libcxx, products.libcxxabi, products.unwind].map((product) =>
810
- path.resolve(product.archive),
811
- ),
812
- )
813
- const objects = [...sdk.objectOrigins.values()].filter((origin) =>
814
- runtimeArchives.has(path.resolve(origin.archive)),
815
- )
816
- const archives = linkedArchives.filter((archive) =>
817
- runtimeArchives.has(path.resolve(archive)),
818
- )
819
- const origins: SwiftSdkObjectOrigin[] = [...objects]
820
- for (const archive of archives) {
821
- const members = readArMembers(readFileSync(archive))
822
- const names = new Set<string>()
823
- for (const member of members) {
824
- if (names.has(member.name)) throw new Error(`ambiguous runtime archive ${archive}`)
825
- names.add(member.name)
826
- origins.push({ archive, member: member.name, ordinal: 1 })
827
- }
828
- }
829
- const owners = guestCxxMemberOwners(origins, products)
830
- const byOrigin = new Map(
831
- owners.map(({ origin, image }) => [
832
- JSON.stringify([path.resolve(origin.archive), origin.member, origin.ordinal]),
833
- image,
834
- ]),
835
- )
836
- const imageOf = (origin: SwiftSdkObjectOrigin) => {
837
- const image = byOrigin.get(
838
- JSON.stringify([path.resolve(origin.archive), origin.member, origin.ordinal]),
839
- )
840
- if (image === undefined) throw new Error(`unowned runtime object ${origin.member}`)
841
- return image
842
- }
843
- return [
844
- ...objects.map(
845
- (origin) =>
846
- ({
847
- path: origin.original,
848
- kind: 'object',
849
- image: imageOf(origin),
850
- instrumentDynamicLookups: false,
851
- }) satisfies GuestLinkArtifact,
852
- ),
853
- ...archives.map(
854
- (archive) =>
855
- ({
856
- path: archive,
857
- kind: 'archive',
858
- image: null,
859
- memberImages: new Map(
860
- owners
861
- .filter(
862
- ({ origin }) => path.resolve(origin.archive) === path.resolve(archive),
863
- )
864
- .map(({ origin, image }) => [origin.member, image]),
865
- ),
866
- instrumentDynamicLookups: false,
867
- }) satisfies GuestLinkArtifact,
868
- ),
869
- ]
870
- }
@@ -64,19 +64,34 @@ function compilerCheckpoint(
64
64
  }
65
65
  const outputMap = value('-output-file-map')
66
66
  const module = value('-emit-module-path')
67
- if (!outputMap || !module || !args.includes('-whole-module-optimization')) return
67
+ const wholeModule =
68
+ args.lastIndexOf('-whole-module-optimization') >
69
+ args.lastIndexOf('-no-whole-module-optimization')
70
+ const batch = args.includes('-enable-batch-mode') && !args.includes('-incremental')
71
+ if (!outputMap || !module || (!wholeModule && !batch)) return
68
72
  const mapText = readFileSync(outputMap, 'utf8')
69
73
  const map: unknown = JSON.parse(mapText)
70
- if (!isRecord(map) || !isRecord(map['']) || typeof map[''].dependencies !== 'string')
71
- return
72
- const objects: string[] = []
73
- for (const [source, outputs] of Object.entries(map)) {
74
+ if (!isRecord(map)) return
75
+ const outputs = [module, header]
76
+ if (wholeModule) {
77
+ if (!isRecord(map['']) || typeof map[''].dependencies !== 'string') return
78
+ outputs.push(map[''].dependencies)
79
+ }
80
+ let objects = 0
81
+ for (const [source, fileOutputs] of Object.entries(map)) {
74
82
  if (!source) continue
75
- if (!isRecord(outputs) || typeof outputs.object !== 'string') return
76
- objects.push(outputs.object)
83
+ if (!isRecord(fileOutputs) || typeof fileOutputs.object !== 'string') return
84
+ objects++
85
+ const object = fileOutputs.object
86
+ outputs.push(object)
87
+ if (!wholeModule) {
88
+ const dependencies = fileOutputs.dependencies
89
+ if (typeof dependencies === 'string') outputs.push(dependencies)
90
+ else if (object.endsWith('.o')) outputs.push(`${object.slice(0, -2)}.d`)
91
+ else return
92
+ }
77
93
  }
78
- if (!objects.length) return
79
- const outputs = [module, header, map[''].dependencies, ...objects]
94
+ if (objects === 0) return
80
95
  const digest = createHash('sha256')
81
96
  .update(recipe)
82
97
  .update(JSON.stringify(args))