peachsim 0.1.2608 → 0.1.2610

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 (151) hide show
  1. package/cli/commands/perf-native.ts +120 -6
  2. package/cli/drivers/playwright-provisioning.ts +4 -1
  3. package/dist-lib/agent-daemon-client.cjs +1 -1
  4. package/dist-lib/agent-events.cjs +1 -1
  5. package/dist-lib/attached-projects.cjs +1 -1
  6. package/dist-lib/auth/shared-session.cjs +1 -1
  7. package/dist-lib/backend-origin.cjs +1 -1
  8. package/dist-lib/beta.cjs +1 -1
  9. package/dist-lib/beta.mjs +2 -2
  10. package/dist-lib/bridge-constants.cjs +1 -1
  11. package/dist-lib/bridge-contract-input.cjs +1 -1
  12. package/dist-lib/bridge-contract-input.mjs +5 -5
  13. package/dist-lib/bridge-contract.cjs +1 -1
  14. package/dist-lib/bridge-contract.mjs +3 -3
  15. package/dist-lib/bundle-channel.cjs +60485 -60177
  16. package/dist-lib/capture-contract.cjs +1 -1
  17. package/dist-lib/capture-contract.mjs +3 -3
  18. package/dist-lib/cloud-contract.cjs +1 -1
  19. package/dist-lib/cloud-contract.mjs +3 -3
  20. package/dist-lib/cloud-test-args.cjs +1 -1
  21. package/dist-lib/cloud-test-args.mjs +2 -2
  22. package/dist-lib/cloud.cjs +1 -1
  23. package/dist-lib/cloud.mjs +7 -7
  24. package/dist-lib/config.cjs +1 -1
  25. package/dist-lib/config.mjs +5 -5
  26. package/dist-lib/detox/index.cjs +1 -1
  27. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  28. package/dist-lib/esm-chunks/{acorn-4QDEL7IO.mjs → acorn-L2SFCOHG.mjs} +3 -3
  29. package/dist-lib/esm-chunks/{chunk-4C57RZXG.mjs → chunk-2LJTZ2KG.mjs} +17 -328
  30. package/dist-lib/esm-chunks/{chunk-X6CONUT6.mjs → chunk-42NDD4R7.mjs} +1 -1
  31. package/dist-lib/esm-chunks/{chunk-F724FZHJ.mjs → chunk-73NIGS7D.mjs} +1490 -3950
  32. package/dist-lib/esm-chunks/{chunk-KNCWQQZG.mjs → chunk-CUBTZPSZ.mjs} +1 -1
  33. package/dist-lib/esm-chunks/chunk-EU5WMP5O.mjs +322 -0
  34. package/dist-lib/esm-chunks/{chunk-NXG27NGU.mjs → chunk-EYSNLE5V.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-IKFFQXJN.mjs → chunk-FP447MCW.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-JIW4PICV.mjs → chunk-HMTSU22Q.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-7KU5ROOE.mjs → chunk-KTAGV5U6.mjs} +14 -12
  38. package/dist-lib/esm-chunks/{chunk-3DUFAH5J.mjs → chunk-MJP4WOSX.mjs} +1 -1
  39. package/dist-lib/esm-chunks/{chunk-H3QASOKR.mjs → chunk-MK4DOEDN.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-ZFI5OF6U.mjs → chunk-N3M5KT33.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-F2FHFORX.mjs → chunk-N7XU2WWO.mjs} +1 -1
  42. package/dist-lib/esm-chunks/{chunk-UHYHEJ3N.mjs → chunk-RN73P2DY.mjs} +34 -28
  43. package/dist-lib/esm-chunks/{chunk-VICI67J5.mjs → chunk-VDLPNJ6P.mjs} +1 -1
  44. package/dist-lib/esm-chunks/chunk-W3LNUIUA.mjs +2655 -0
  45. package/dist-lib/esm-chunks/{chunk-R25MOOFS.mjs → chunk-WBQFHIGS.mjs} +1 -1
  46. package/dist-lib/esm-chunks/{chunk-YBMBAXAZ.mjs → chunk-WZHEW7Z7.mjs} +1 -1
  47. package/dist-lib/esm-chunks/{chunk-RTXAZMTP.mjs → chunk-X74N3K5N.mjs} +4 -4
  48. package/dist-lib/esm-chunks/{chunk-IJX7PBNG.mjs → chunk-XN74REO2.mjs} +1 -1
  49. package/dist-lib/esm-chunks/{chunk-RZLGVWHK.mjs → chunk-YLUD2UET.mjs} +1 -1
  50. package/dist-lib/esm-chunks/{chunk-BEWJL2LY.mjs → chunk-YVLXYLNV.mjs} +1 -1
  51. package/dist-lib/esm-chunks/{chunk-W5EHCHDD.mjs → chunk-YYGSN3BN.mjs} +3 -3
  52. package/dist-lib/esm-chunks/{chunk-GPPOU5DO.mjs → chunk-ZZB2LFYV.mjs} +1 -1
  53. package/dist-lib/esm-chunks/{metro-layout-parser-YWPJI3L6.mjs → metro-layout-parser-VDPXJ7LW.mjs} +3 -3
  54. package/dist-lib/esm-chunks/{swift-package-prebuilt-MWTLCMQD.mjs → swift-package-prebuilt-HRPDLN2P.mjs} +14 -11
  55. package/dist-lib/esm-chunks/{swift-sdk-app-module-PF5QMK5X.mjs → swift-sdk-app-module-5DOGMU3M.mjs} +16 -14
  56. package/dist-lib/esm-chunks/{swift-sdk-image-5IMAACRF.mjs → swift-sdk-image-W3UU4H4L.mjs} +16 -14
  57. package/dist-lib/esm-chunks/{swift-sdk-image-producer-JPIJI25U.mjs → swift-sdk-image-producer-OJWD6ZOH.mjs} +8 -6
  58. package/dist-lib/expo-swift-bundle.cjs +42524 -42216
  59. package/dist-lib/expo-swift-metadata.cjs +1 -1
  60. package/dist-lib/expo-swift-metadata.mjs +7 -7
  61. package/dist-lib/home-paths.cjs +1 -1
  62. package/dist-lib/host/bridge-host.cjs +43716 -43244
  63. package/dist-lib/host/fetch-proxy-handler.cjs +670 -645
  64. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  65. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
  66. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  67. package/dist-lib/host/websocket-proxy.cjs +1 -1
  68. package/dist-lib/index.cjs +1 -1
  69. package/dist-lib/kotlin-host.cjs +1 -1
  70. package/dist-lib/menu.cjs +1 -1
  71. package/dist-lib/menu.mjs +3 -3
  72. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  73. package/dist-lib/metro-fingerprint-registry.mjs +3 -3
  74. package/dist-lib/metro-production-bundle.cjs +1 -1
  75. package/dist-lib/metro-production-bundle.mjs +4 -4
  76. package/dist-lib/native-app-identity-project.cjs +1499 -2889
  77. package/dist-lib/native-app-identity-project.mjs +317 -339
  78. package/dist-lib/native-app-identity.cjs +1 -1
  79. package/dist-lib/native-app-identity.mjs +6 -6
  80. package/dist-lib/native-firebase-metadata.cjs +1 -1
  81. package/dist-lib/native-firebase-metadata.mjs +3 -3
  82. package/dist-lib/pdfium-raster.cjs +1 -1
  83. package/dist-lib/pdfium-raster.mjs +2 -2
  84. package/dist-lib/plist.cjs +1 -1
  85. package/dist-lib/plist.mjs +3 -3
  86. package/dist-lib/profiles.cjs +1 -1
  87. package/dist-lib/public-brand.cjs +1 -1
  88. package/dist-lib/public-origins-lib-esm.json +166 -154
  89. package/dist-lib/public-origins-lib.json +141 -198
  90. package/dist-lib/react-native-host-modules.cjs +1 -1
  91. package/dist-lib/react-native-host-modules.mjs +2 -2
  92. package/dist-lib/reap-browser.cjs +1 -1
  93. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  94. package/dist-lib/sdk.cjs +1 -1
  95. package/dist-lib/sdk.mjs +8 -8
  96. package/dist-lib/skills.cjs +38979 -38507
  97. package/dist-lib/swift-compile.cjs +12239 -12121
  98. package/dist-lib/swift-compile.mjs +36 -33
  99. package/dist-lib/swift-package.cjs +1 -1
  100. package/dist-lib/swift-package.mjs +3 -3
  101. package/dist-lib/swift-submit.cjs +1 -1
  102. package/dist-lib/swift-submit.mjs +6 -6
  103. package/dist-lib/swift-svg-raster.cjs +1 -1
  104. package/dist-lib/swift-svg-raster.mjs +2 -2
  105. package/dist-lib/swift-toolchain.cjs +1 -1
  106. package/dist-lib/swift.cjs +1 -1
  107. package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
  108. package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
  109. package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
  110. package/dist-lib/vendor/acorn.cjs +1 -1
  111. package/dist-lib/vendor/magic-string.cjs +1 -1
  112. package/dist-lib/vendor/stream-json.cjs +1 -1
  113. package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
  114. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
  115. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
  116. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
  117. package/dist-lib/vendor/sucrase.cjs +1 -1
  118. package/dist-lib/vendor/terser.cjs +1 -1
  119. package/dist-lib/vendor/valibot.cjs +1 -1
  120. package/dist-lib/vendor/ws.cjs +1 -1
  121. package/dist-lib/vendor/zod.cjs +1 -1
  122. package/dist-lib/worklet-executable.cjs +1 -1
  123. package/dist-lib/worklet-executable.mjs +3 -3
  124. package/dist-types/packages/peach-engine/src/ios/apps/canvas-map-data.d.ts +13 -0
  125. package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +3 -0
  126. package/package.json +1 -1
  127. package/src/agent-prompt.ts +15 -2
  128. package/src/binaryen.lock.json +3 -3
  129. package/src/genrule-archives.ts +5 -2
  130. package/src/native-framework-compiler.ts +1 -1
  131. package/src/native-static-libraries.ts +2 -3
  132. package/src/native-swift-slices.ts +1 -1
  133. package/src/nitro-dependencies.ts +3 -7
  134. package/src/one-native-controls-package.ts +165 -11
  135. package/src/oneNativeControlsContract.ts +1 -0
  136. package/src/rive-runtime-dependencies.ts +1 -2
  137. package/src/swift-compile.ts +165 -1796
  138. package/src/swift-compiler-digest.ts +2 -0
  139. package/src/swift-distribution.ts +39 -15
  140. package/src/swift-objc-compile.ts +194 -32
  141. package/src/swift-package-manifest.ts +6 -29
  142. package/src/swift-packages.ts +6 -14
  143. package/src/swift-sdk-surface.ts +1811 -0
  144. package/src/swift-standin-digest.ts +28 -5
  145. package/src/swift-standins.ts +16 -19
  146. package/src/swift-wasm-archive.ts +200 -0
  147. package/src/swift-wasm-prune.ts +3 -93
  148. package/src/swift-wasm64-native-source.ts +4 -2
  149. package/src/swiftWasm64ConfigContract.ts +10 -0
  150. package/src/wasm-optimize.ts +18 -14
  151. package/src/xcode-project.ts +2 -4
@@ -11,6 +11,8 @@ import { readIosSdkTree } from './swift-objc-sdk-tree'
11
11
  // digest.
12
12
  export const SWIFT_DIGEST_SOURCES = [
13
13
  'swift-compile.ts',
14
+ 'swift-sdk-surface.ts',
15
+ 'swift-wasm-archive.ts',
14
16
  'swift-lexical.ts',
15
17
  'swift-header-compiler.ts',
16
18
  'swift-header-dependencies.ts',
@@ -5,22 +5,34 @@
5
5
  // unset, verifies it against the lock this build carries, and unpacks it under
6
6
  // the swift cache
7
7
  // (docs/peach/swift/distribution.md). no path here asks Contrast to compile.
8
+ import { execFile } from 'node:child_process'
8
9
  import fs from 'node:fs'
9
10
  import os from 'node:os'
10
11
  import path from 'node:path'
12
+ import { promisify } from 'node:util'
11
13
  import { installVerifiedTarball } from '@contrast/runtime-delivery'
12
14
  import {
13
15
  ensureLinuxBrowserLibraries,
14
16
  missingLinuxLibraries,
15
17
  } from '../cli/drivers/linux-browser-libs'
16
18
  import { rnxHomeDir } from './home-paths'
17
- import { swiftDistributionAt, swiftModuleSdk } from './swift-compile'
18
19
  import {
19
20
  SWIFT_DISTRIBUTION_MANIFEST,
20
21
  swiftDistributionHost,
21
22
  swiftDistributionKey,
22
23
  } from './swift-distribution-contract'
23
24
  import { swiftNativePin } from './swift-native-pin'
25
+ import {
26
+ swiftManifestCommand,
27
+ swiftManifestResolveRequest,
28
+ type SwiftRemoteRequirement,
29
+ } from './swift-package-manifest'
30
+ import {
31
+ swiftDistributionAt,
32
+ swiftModuleCompiler,
33
+ swiftModuleSdk,
34
+ swiftModuleToolchain,
35
+ } from './swift-sdk-surface'
24
36
  import {
25
37
  confineSwiftScratch,
26
38
  ensureSwiftLinuxRuntime,
@@ -372,19 +384,31 @@ export async function resolveSwiftModule({
372
384
  return { root, ...swiftModuleToolchain(root) }
373
385
  }
374
386
 
375
- /** the host compiler selected by a module root, without requiring a guest SDK. */
376
- export function swiftModuleCompiler(root: string): Omit<SwiftModule, 'root'> {
377
- const pin: { release: string } =
378
- swiftDistributionAt(root) ??
379
- JSON.parse(fs.readFileSync(path.join(root, 'toolchain.json'), 'utf8'))
380
- return {
381
- release: pin.release,
382
- toolchainBin: swiftCompiler(pin.release),
383
- }
384
- }
387
+ export { swiftModuleCompiler, swiftModuleToolchain }
385
388
 
386
- /** the release a module root was built for and its installed toolchain. */
387
- export function swiftModuleToolchain(root: string): Omit<SwiftModule, 'root'> {
388
- const { release } = swiftModuleCompiler(root)
389
- return { release, toolchainBin: swiftToolchain(release, swiftModuleSdk(root)) }
389
+ /**
390
+ * resolves remote package requirements with swiftpm, the resolver xcode uses,
391
+ * and writes the graph to `destination` as Package.resolved. a project with
392
+ * no lock does this itself; an existing lock stays authoritative. the locked
393
+ * compiler is installed first, so any host resolves, and the process stays
394
+ * free to serve requests while swiftpm runs.
395
+ */
396
+ export async function resolveSwiftPackageRequirementsAsync(
397
+ requirements: readonly SwiftRemoteRequirement[],
398
+ destination: string,
399
+ signal?: AbortSignal,
400
+ ): Promise<void> {
401
+ await ensureSwiftToolchain(signal)
402
+ const { dir, args, options, failed, publish } =
403
+ swiftManifestResolveRequest(requirements)
404
+ try {
405
+ try {
406
+ await promisify(execFile)(swiftManifestCommand(), args, { ...options, signal })
407
+ } catch (error) {
408
+ throw failed(error)
409
+ }
410
+ publish(destination)
411
+ } finally {
412
+ fs.rmSync(dir, { recursive: true, force: true })
413
+ }
390
414
  }
@@ -1,19 +1,10 @@
1
1
  import { spawn, spawnSync } from 'node:child_process'
2
- import { createHash } from 'node:crypto'
2
+ import { createHash, randomUUID } from 'node:crypto'
3
3
  import fs from 'node:fs'
4
4
  import path from 'node:path'
5
5
  import { mapLimit } from '../../../src/helpers/mapLimit.ts'
6
6
  import { cacheDir } from './home-paths'
7
7
  import { isRecord } from './is-record'
8
- import {
9
- swiftBuildJobs,
10
- swiftSdkPaths,
11
- swiftModuleSdk,
12
- swiftCompileSurfaceDigest,
13
- swiftPeachModules,
14
- withFrameworkCompanionImports,
15
- } from './swift-compile'
16
- import { swiftModuleToolchain } from './swift-distribution'
17
8
  import { swiftClangImporterFlags } from './swift-objc-import'
18
9
  import { swiftObjCRuntimeFlags } from './swift-objc-runtime'
19
10
  import { iosDeploymentMinimum, objcSdkIntakeFlags } from './swift-objc-standin'
@@ -27,8 +18,14 @@ import { swiftPackageManifest, swiftTargetFiles } from './swift-package-manifest
27
18
  import {
28
19
  remoteSwiftCheckouts,
29
20
  swiftBinaryOnDisk,
30
- type SwiftPackageBinary,
31
- } from './swift-packages'
21
+ swiftBuildJobs,
22
+ swiftSdkPaths,
23
+ swiftModuleSdk,
24
+ swiftModuleToolchain,
25
+ swiftCompileSurfaceDigest,
26
+ swiftPeachModules,
27
+ withFrameworkCompanionImports,
28
+ } from './swift-sdk-surface'
32
29
  import { readPackageFile, relativeInside, replaceRoot } from './swift-source-file'
33
30
  import { STANDIN_SOURCE_DIGEST } from './swift-standin-digest'
34
31
  import { binaryHeaderSearchPaths, isBinaryLibraryFile } from './swift-standins'
@@ -36,6 +33,7 @@ import { swiftEnvironment } from './swift-toolchain'
36
33
  import { deriveWasm64NativeSource } from './swift-wasm64-native-source'
37
34
  import { SWIFT_WASM_TRIPLE, wasmThreadFlags } from './swiftTargetContract.ts'
38
35
  import { writeXcodeHeaderSearch } from './xcode-header-search'
36
+ import type { SwiftPackageBinary } from './swift-packages'
39
37
  import type {
40
38
  SwiftNativeHeaderMap,
41
39
  SwiftObjCImplementationPreparation,
@@ -255,23 +253,175 @@ function compiledFrameworkImports(
255
253
  return imports
256
254
  }
257
255
 
256
+ function sha256Hex(bytes: Buffer | string): string {
257
+ if (typeof Bun !== 'undefined')
258
+ return new Bun.CryptoHasher('sha256').update(bytes).digest('hex')
259
+ return createHash('sha256').update(bytes).digest('hex')
260
+ }
261
+
262
+ function regularFileStamp(file: string): string | null {
263
+ const stat = fs.lstatSync(file, { bigint: true, throwIfNoEntry: false })
264
+ if (!stat || !stat.isFile()) return null
265
+ return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`
266
+ }
267
+
268
+ function verifyRetainedFile(
269
+ work: string,
270
+ file: string,
271
+ hash: unknown,
272
+ stamps: Record<string, unknown> | null,
273
+ ): boolean {
274
+ if (typeof hash !== 'string') return false
275
+ const resolved = path.resolve(work, file)
276
+ if (relativeInside(work, resolved) === null) return false
277
+ const expectedStamp = stamps?.[file]
278
+ if (typeof expectedStamp === 'string' && regularFileStamp(resolved) === expectedStamp)
279
+ return true
280
+ if (!fs.existsSync(resolved)) return false
281
+ return sha256Hex(readPackageFile(work, resolved, Infinity)) === hash
282
+ }
283
+
284
+ function recordRetainedStamps(
285
+ work: string,
286
+ files: readonly string[],
287
+ ): Record<string, string> {
288
+ const stamps: Record<string, string> = {}
289
+ for (const file of files) {
290
+ const stamp = regularFileStamp(file)
291
+ if (stamp !== null) stamps[path.relative(work, file)] = stamp
292
+ }
293
+ return stamps
294
+ }
295
+
296
+ const binaryFileDigests = new Map<string, { stamp: string; digest: string }>()
297
+
298
+ // clang and swift-frontend are 150-250 MB binaries hashed on every build;
299
+ // cache their digest by stat identity in memory and under the local cache.
300
+ function cachedBinaryFileDigest(file: string): string {
301
+ const real = fs.realpathSync(file)
302
+ const stat = fs.statSync(real, { bigint: true })
303
+ const stamp = `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`
304
+ const memory = binaryFileDigests.get(real)
305
+ if (memory?.stamp === stamp) return memory.digest
306
+ const dir = path.join(cacheDir(), 'swift-binary-digests')
307
+ const record = path.join(dir, `${sha256Hex(real)}.json`)
308
+ if (fs.existsSync(record)) {
309
+ const saved: unknown = JSON.parse(fs.readFileSync(record, 'utf8'))
310
+ if (isRecord(saved) && saved.stamp === stamp && typeof saved.digest === 'string') {
311
+ binaryFileDigests.set(real, { stamp, digest: saved.digest })
312
+ return saved.digest
313
+ }
314
+ }
315
+ const digest = sha256Hex(fs.readFileSync(real))
316
+ binaryFileDigests.set(real, { stamp, digest })
317
+ fs.mkdirSync(dir, { recursive: true })
318
+ const partial = `${record}.${process.pid}.${randomUUID()}`
319
+ fs.writeFileSync(partial, JSON.stringify({ stamp, digest }))
320
+ fs.renameSync(partial, record)
321
+ return digest
322
+ }
323
+
324
+ type XcodeObjCInputSnapshot =
325
+ ReturnType<typeof xcodeObjCInputSteps> extends Generator<unknown, infer Result>
326
+ ? Result
327
+ : never
328
+
329
+ interface CachedObjCInputs {
330
+ readonly binaries: readonly SwiftPackageBinary[]
331
+ readonly moduleRoot: string | null
332
+ readonly products: SwiftXcodeSwiftProducts | undefined
333
+ readonly sourceRoot: string
334
+ readonly snapshot: XcodeObjCInputSnapshot
335
+ }
336
+
337
+ const objcInputSnapshots = new WeakMap<XcodeAppTarget, CachedObjCInputs[]>()
338
+
339
+ function cloneObjCInputSnapshot(
340
+ snapshot: XcodeObjCInputSnapshot,
341
+ ): XcodeObjCInputSnapshot {
342
+ return {
343
+ sources: new Map(snapshot.sources),
344
+ links: { ...snapshot.links },
345
+ derivations: { ...snapshot.derivations },
346
+ targets: snapshot.targets,
347
+ externalFrameworkDirs: snapshot.externalFrameworkDirs,
348
+ }
349
+ }
350
+
351
+ function sameBinaries(
352
+ left: readonly SwiftPackageBinary[],
353
+ right: readonly SwiftPackageBinary[],
354
+ ): boolean {
355
+ if (left === right) return true
356
+ if (left.length !== right.length) return false
357
+ for (let i = 0; i < left.length; i++) if (left[i] !== right[i]) return false
358
+ return true
359
+ }
360
+
361
+ function cachedObjCInputs(
362
+ app: XcodeAppTarget,
363
+ binaries: readonly SwiftPackageBinary[],
364
+ moduleRoot: string | null,
365
+ products: SwiftXcodeSwiftProducts | undefined,
366
+ sourceRoot: string,
367
+ ): XcodeObjCInputSnapshot | undefined {
368
+ const entries = objcInputSnapshots.get(app)
369
+ if (!entries) return undefined
370
+ const hit = entries.find(
371
+ (entry) =>
372
+ entry.moduleRoot === moduleRoot &&
373
+ entry.products === products &&
374
+ entry.sourceRoot === sourceRoot &&
375
+ sameBinaries(entry.binaries, binaries),
376
+ )
377
+ return hit ? cloneObjCInputSnapshot(hit.snapshot) : undefined
378
+ }
379
+
380
+ function recordObjCInputs(
381
+ app: XcodeAppTarget,
382
+ binaries: readonly SwiftPackageBinary[],
383
+ moduleRoot: string | null,
384
+ products: SwiftXcodeSwiftProducts | undefined,
385
+ sourceRoot: string,
386
+ snapshot: XcodeObjCInputSnapshot,
387
+ ): XcodeObjCInputSnapshot {
388
+ const entries = objcInputSnapshots.get(app) ?? []
389
+ entries.push({
390
+ binaries: [...binaries],
391
+ moduleRoot,
392
+ products,
393
+ sourceRoot,
394
+ snapshot: cloneObjCInputSnapshot(snapshot),
395
+ })
396
+ objcInputSnapshots.set(app, entries)
397
+ return snapshot
398
+ }
399
+
258
400
  /** one original source snapshot serves declaration import and implementation compile. */
259
401
  export function xcodeObjCInputs(...args: Parameters<typeof xcodeObjCInputSteps>) {
402
+ const [app, binaries, moduleRoot, products, sourceRoot = app.rootDir] = args
403
+ const cached = cachedObjCInputs(app, binaries, moduleRoot, products, sourceRoot)
404
+ if (cached) return cached
260
405
  const steps = xcodeObjCInputSteps(...args)
261
406
  while (true) {
262
407
  const step = steps.next()
263
- if (step.done) return step.value
408
+ if (step.done)
409
+ return recordObjCInputs(app, binaries, moduleRoot, products, sourceRoot, step.value)
264
410
  }
265
411
  }
266
412
 
267
413
  export async function xcodeObjCInputsAsync(
268
414
  ...args: Parameters<typeof xcodeObjCInputSteps>
269
415
  ) {
416
+ const [app, binaries, moduleRoot, products, sourceRoot = app.rootDir] = args
417
+ const cached = cachedObjCInputs(app, binaries, moduleRoot, products, sourceRoot)
418
+ if (cached) return cached
270
419
  const steps = xcodeObjCInputSteps(...args)
271
420
  await new Promise<void>((resolve) => setImmediate(resolve))
272
421
  while (true) {
273
422
  const step = steps.next()
274
- if (step.done) return step.value
423
+ if (step.done)
424
+ return recordObjCInputs(app, binaries, moduleRoot, products, sourceRoot, step.value)
275
425
  await new Promise<void>((resolve) => setImmediate(resolve))
276
426
  }
277
427
  }
@@ -907,8 +1057,7 @@ export function prepareXcodeSwiftProducts(
907
1057
  const staged = withFrameworkCompanionImports(original)
908
1058
  if (staged !== original) sources.set(file, Buffer.from(staged))
909
1059
  }
910
- const digest = (bytes: string | Buffer) =>
911
- createHash('sha256').update(bytes).digest('hex')
1060
+ const digest = sha256Hex
912
1061
  const providers = new Map<string, string>()
913
1062
  for (const target of targets) {
914
1063
  if (!supplied.has(target.moduleName)) continue
@@ -946,7 +1095,7 @@ export function prepareXcodeSwiftProducts(
946
1095
  version: 5,
947
1096
  sdk: swiftModuleSdk(moduleRoot),
948
1097
  distribution: swiftCompileSurfaceDigest(moduleRoot).toString('hex'),
949
- compiler: digest(fs.readFileSync(frontend)),
1098
+ compiler: cachedBinaryFileDigest(frontend),
950
1099
  toolset: digest(fs.readFileSync(toolsetFile)),
951
1100
  targets,
952
1101
  externalFrameworkDirs,
@@ -1021,6 +1170,8 @@ export function prepareXcodeSwiftProducts(
1021
1170
  path.join(preparation.modules, `${target.moduleName}.swiftmodule`),
1022
1171
  ),
1023
1172
  ]
1173
+ const stamps =
1174
+ isRecord(retained) && isRecord(retained.stamps) ? retained.stamps : null
1024
1175
  if (
1025
1176
  isRecord(retained) &&
1026
1177
  retained.key === key &&
@@ -1029,11 +1180,8 @@ export function prepareXcodeSwiftProducts(
1029
1180
  (file) =>
1030
1181
  isRecord(retained.files) && path.relative(work, file) in retained.files,
1031
1182
  ) &&
1032
- Object.entries(retained.files).every(
1033
- ([file, hash]) =>
1034
- typeof hash === 'string' &&
1035
- fs.existsSync(path.join(work, file)) &&
1036
- digest(fs.readFileSync(path.join(work, file))) === hash,
1183
+ Object.entries(retained.files).every(([file, hash]) =>
1184
+ verifyRetainedFile(work, file, hash, stamps),
1037
1185
  )
1038
1186
  )
1039
1187
  return preparation
@@ -1281,6 +1429,7 @@ export function prepareXcodeSwiftProducts(
1281
1429
  digest(fs.readFileSync(file)),
1282
1430
  ]),
1283
1431
  ),
1432
+ stamps: recordRetainedStamps(work, outputs),
1284
1433
  },
1285
1434
  null,
1286
1435
  2,
@@ -1325,8 +1474,7 @@ async function prepareXcodeNativeInputs(
1325
1474
  products,
1326
1475
  )
1327
1476
  const checkouts = remoteSwiftCheckouts(app.rootDir)
1328
- const digest = (bytes: Buffer | string) =>
1329
- createHash('sha256').update(bytes).digest('hex')
1477
+ const digest = sha256Hex
1330
1478
  const inputs = Object.fromEntries(
1331
1479
  [...sources].map(([file, bytes]) => [file, digest(bytes)]),
1332
1480
  )
@@ -1348,7 +1496,7 @@ async function prepareXcodeNativeInputs(
1348
1496
  intake[index] ?? [`invalid-minimum:${deploymentTarget}`],
1349
1497
  ),
1350
1498
  release: toolchain.release,
1351
- compiler: digest(fs.readFileSync(path.join(toolchain.toolchainBin, 'clang'))),
1499
+ compiler: cachedBinaryFileDigest(path.join(toolchain.toolchainBin, 'clang')),
1352
1500
  sdk: swiftModuleSdk(moduleRoot),
1353
1501
  targets,
1354
1502
  externalFrameworkDirs,
@@ -1409,11 +1557,9 @@ async function prepareXcodeNativeInputs(
1409
1557
  !('receipt.json' in result.files)
1410
1558
  )
1411
1559
  throw new Error('invalid completed receipt')
1560
+ const stamps = record(result.stamps) ? result.stamps : null
1412
1561
  for (const [file, hash] of Object.entries(result.files)) {
1413
- if (
1414
- typeof hash !== 'string' ||
1415
- digest(readPackageFile(work, path.resolve(work, file), Infinity)) !== hash
1416
- )
1562
+ if (!verifyRetainedFile(work, file, hash, stamps))
1417
1563
  throw new Error(`retained file changed: ${file}`)
1418
1564
  }
1419
1565
  if (result.prepared) {
@@ -1524,8 +1670,11 @@ async function prepareXcodeNativeInputs(
1524
1670
  )
1525
1671
  const complete = (status: string, message: string, reusable = true): void => {
1526
1672
  save(status)
1527
- const files = [
1528
- ...[...sources.keys()].map(staged),
1673
+ const stagedSources = [...sources.keys()].map((file) => ({
1674
+ stagedFile: staged(file),
1675
+ hash: inputs[file]!,
1676
+ }))
1677
+ const generatedFiles = [
1529
1678
  ...moduleMapFiles,
1530
1679
  ...headerSearch.files,
1531
1680
  receipt,
@@ -1535,14 +1684,27 @@ async function prepareXcodeNativeInputs(
1535
1684
  ...(command.dependencies ? [command.dependencies] : []),
1536
1685
  ]),
1537
1686
  ]
1687
+ const generatedSet = new Set(generatedFiles)
1688
+ const knownHashes = new Map<string, string>()
1689
+ for (const { stagedFile, hash } of stagedSources) {
1690
+ if (!generatedSet.has(stagedFile)) knownHashes.set(stagedFile, hash)
1691
+ }
1692
+ const files = [
1693
+ ...stagedSources.map(({ stagedFile }) => stagedFile),
1694
+ ...generatedFiles,
1695
+ ]
1538
1696
  const result = {
1539
1697
  key,
1540
1698
  message,
1541
1699
  reusable,
1542
1700
  prepared: status === 'prepared',
1543
1701
  files: Object.fromEntries(
1544
- files.map((file) => [path.relative(work, file), digest(fs.readFileSync(file))]),
1702
+ files.map((file) => [
1703
+ path.relative(work, file),
1704
+ knownHashes.get(file) ?? digest(fs.readFileSync(file)),
1705
+ ]),
1545
1706
  ),
1707
+ stamps: recordRetainedStamps(work, files),
1546
1708
  }
1547
1709
  fs.writeFileSync(`${resultFile}.pending`, JSON.stringify(result, null, 2))
1548
1710
  fs.renameSync(`${resultFile}.pending`, resultFile)
@@ -18,7 +18,6 @@ import path from 'node:path'
18
18
  import { promisify } from 'node:util'
19
19
  import { UNATTENDED_GIT_ENV } from './git-repo-env'
20
20
  import { cacheDir as peachCacheDir } from './home-paths'
21
- import { ensureSwiftToolchain, swiftModuleCompiler } from './swift-distribution'
22
21
  import { mapSwiftConditionalLines, swiftCodeScan } from './swift-lexical'
23
22
  import { swiftNativePin } from './swift-native-pin'
24
23
  import {
@@ -26,6 +25,7 @@ import {
26
25
  swiftPackageIdentity,
27
26
  type SwiftTargetDependency,
28
27
  } from './swift-package'
28
+ import { swiftModuleCompiler } from './swift-sdk-surface'
29
29
  import {
30
30
  privateSwiftDistributionRoot,
31
31
  swiftEnvironment,
@@ -178,12 +178,13 @@ const array = (value: Json | undefined): Json[] => (Array.isArray(value) ? value
178
178
  const string = (value: Json | undefined): string | undefined =>
179
179
  typeof value === 'string' ? value : undefined
180
180
 
181
- function swiftCommand(): string {
181
+ export function swiftManifestCommand(): string {
182
182
  const privateRoot = privateSwiftDistributionRoot()
183
183
  if (privateRoot)
184
184
  return path.join(swiftModuleCompiler(privateRoot).toolchainBin, 'swift')
185
185
  return path.join(swiftToolchainBin(swiftNativePin().distribution.release), 'swift')
186
186
  }
187
+ const swiftCommand = swiftManifestCommand
187
188
 
188
189
  function swiftPackageFailure(error: unknown): string {
189
190
  if (!(error instanceof Error)) return String(error)
@@ -863,7 +864,9 @@ const requirementClause = (item: SwiftRemoteRequirement): string => {
863
864
  return `.package(url: ${url}, revision: ${JSON.stringify(requirement.revision)})`
864
865
  }
865
866
 
866
- function resolveRequest(requirements: readonly SwiftRemoteRequirement[]) {
867
+ export function swiftManifestResolveRequest(
868
+ requirements: readonly SwiftRemoteRequirement[],
869
+ ) {
867
870
  const repository = (url: string) => url.replace(/(?:\.git)?\/?$/, '')
868
871
  const chosen = new Map<string, SwiftRemoteRequirement>()
869
872
  for (const item of requirements) {
@@ -930,32 +933,6 @@ let package = Package(
930
933
  return { dir, args, options, failed, publish }
931
934
  }
932
935
 
933
- /**
934
- * resolves remote package requirements with swiftpm, the resolver xcode uses,
935
- * and writes the graph to `destination` as Package.resolved. a project with
936
- * no lock does this itself; an existing lock stays authoritative. the locked
937
- * compiler is installed first, so any host resolves, and the process stays
938
- * free to serve requests while swiftpm runs.
939
- */
940
- export async function resolveSwiftPackageRequirementsAsync(
941
- requirements: readonly SwiftRemoteRequirement[],
942
- destination: string,
943
- signal?: AbortSignal,
944
- ): Promise<void> {
945
- await ensureSwiftToolchain(signal)
946
- const { dir, args, options, failed, publish } = resolveRequest(requirements)
947
- try {
948
- try {
949
- await promisify(execFile)(swiftCommand(), args, { ...options, signal })
950
- } catch (error) {
951
- throw failed(error)
952
- }
953
- publish(destination)
954
- } finally {
955
- fs.rmSync(dir, { recursive: true, force: true })
956
- }
957
- }
958
-
959
936
  /** original resource bytes are independent of the target's explicit sources. */
960
937
  export function swiftTargetResourceFiles(
961
938
  manifest: SwiftPackageManifest,
@@ -10,17 +10,14 @@
10
10
  // compile.
11
11
 
12
12
  import { execFile } from 'node:child_process'
13
- import { createHash } from 'node:crypto'
14
13
  import fs from 'node:fs'
15
14
  import path from 'node:path'
16
15
  import { setTimeout as sleep } from 'node:timers/promises'
17
16
  import { promisify } from 'node:util'
18
17
  import { UNATTENDED_GIT_ENV, withoutGitRepositoryEnv } from './git-repo-env'
19
- import { cacheDir } from './home-paths'
20
18
  import { requireNativeGit } from './native-git'
21
19
  import { tryAcquireNumberedLock } from './numbered-lock'
22
20
  import { buildRiveRuntimeDependencies } from './rive-runtime-dependencies'
23
- import { swiftCTakesReturnAddress } from './swift-compile'
24
21
  import {
25
22
  isSwiftNativeTranslationUnit,
26
23
  swiftImplicitResourcePaths,
@@ -38,6 +35,11 @@ import {
38
35
  type SwiftManifestTarget,
39
36
  type SwiftPackageManifest,
40
37
  } from './swift-package-manifest'
38
+ import {
39
+ remoteSwiftCheckouts,
40
+ swiftBinaryOnDisk,
41
+ swiftCTakesReturnAddress,
42
+ } from './swift-sdk-surface'
41
43
  import { shippedBinaryDiffers } from './swift-shipped-binaries'
42
44
  import type { GenruleArchiveDeclaration } from './genrule-archives'
43
45
  import type { SwiftSourceLinkGraph } from './swiftContract'
@@ -167,8 +169,7 @@ export interface SwiftPackageBinary {
167
169
  moduleSources?: { sources: string[]; flags: string[]; resources: boolean }
168
170
  }
169
171
 
170
- export const swiftBinaryOnDisk = (binary: SwiftPackageBinary): boolean =>
171
- binary.url !== null || fs.existsSync(binary.dir)
172
+ export { remoteSwiftCheckouts, swiftBinaryOnDisk }
172
173
 
173
174
  // sdks that send telemetry, by package identity, that peach's swift cannot
174
175
  // compile yet, each with the compiler gap that forces it. their swift targets
@@ -236,15 +237,6 @@ const sourceFrameworkRecipes = new Map<
236
237
  ])
237
238
 
238
239
  /** dependency checkouts belong to peach, isolated by the canonical app root. */
239
- export function remoteSwiftCheckouts(root: string): string {
240
- const key = createHash('sha256')
241
- .update(fs.realpathSync(root))
242
- .digest('hex')
243
- .slice(0, 32)
244
- fs.mkdirSync(cacheDir(), { recursive: true })
245
- return path.join(fs.realpathSync(cacheDir()), 'swift-packages', key, 'checkouts')
246
- }
247
-
248
240
  // assembly requires its own target lowering; objective-c keeps its original bodies.
249
241
  const UNSUPPORTED_NATIVE = /\.(s|S)$/
250
242