peachsim 0.1.2742 → 0.1.2744

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 (126) 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 +137 -119
  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-I6YLE7RH.mjs → acorn-3G2P6SLD.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-YQSNOLNM.mjs → chunk-2XVKKP7C.mjs} +1 -1
  28. package/dist-lib/esm-chunks/{chunk-RC3JQV7D.mjs → chunk-3N3NWKOV.mjs} +1 -1
  29. package/dist-lib/esm-chunks/{chunk-GMFZTGVJ.mjs → chunk-3R76QB7G.mjs} +6 -6
  30. package/dist-lib/esm-chunks/{chunk-OXFGIZC4.mjs → chunk-4BSH2PJJ.mjs} +2 -2
  31. package/dist-lib/esm-chunks/{chunk-VWRLBFID.mjs → chunk-4J7M5ABU.mjs} +1 -1
  32. package/dist-lib/esm-chunks/{chunk-QDTQYGJB.mjs → chunk-4SL6WT5R.mjs} +1 -1
  33. package/dist-lib/esm-chunks/{chunk-CFPPESX7.mjs → chunk-5EMHE44C.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-4CNYVYQW.mjs → chunk-6HF6522F.mjs} +4 -4
  35. package/dist-lib/esm-chunks/{chunk-MHRTZ6I7.mjs → chunk-7PZCYBRZ.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-FKC5RBXR.mjs → chunk-CWTZZ5PW.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-Y4Q3W36I.mjs → chunk-EP64ATYX.mjs} +6 -6
  38. package/dist-lib/esm-chunks/{chunk-PLXC42XF.mjs → chunk-ESGH55PU.mjs} +1 -1
  39. package/dist-lib/esm-chunks/{chunk-NWGCI4JC.mjs → chunk-FZCF4XKV.mjs} +3 -3
  40. package/dist-lib/esm-chunks/{chunk-VH5KY2GM.mjs → chunk-MHWKZ233.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-IVVVYJKG.mjs → chunk-MK5GDI4J.mjs} +1 -1
  42. package/dist-lib/esm-chunks/{chunk-6LMI5DE3.mjs → chunk-NA3WRJON.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-MXADGMSE.mjs → chunk-OYGAP4IB.mjs} +1 -1
  44. package/dist-lib/esm-chunks/{chunk-U262IRGM.mjs → chunk-Q3AUIPF2.mjs} +1 -1
  45. package/dist-lib/esm-chunks/{chunk-2SC45KUK.mjs → chunk-QNMAUXAH.mjs} +145 -127
  46. package/dist-lib/esm-chunks/{chunk-G44GUBAL.mjs → chunk-SI55AJTD.mjs} +1 -1
  47. package/dist-lib/esm-chunks/{chunk-HJBL2ND3.mjs → chunk-U6INDDV4.mjs} +1 -1
  48. package/dist-lib/esm-chunks/{chunk-GPVGYC45.mjs → chunk-V6QXWGYS.mjs} +1 -1
  49. package/dist-lib/esm-chunks/{chunk-ZRA35GYC.mjs → chunk-XRGF7PWG.mjs} +5 -5
  50. package/dist-lib/esm-chunks/{chunk-6QTRZNLH.mjs → chunk-YPT6XQJX.mjs} +1 -1
  51. package/dist-lib/esm-chunks/{metro-layout-parser-QGTUKU6T.mjs → metro-layout-parser-IISMSHQ6.mjs} +3 -3
  52. package/dist-lib/esm-chunks/{swift-package-prebuilt-M2IXDM7B.mjs → swift-package-prebuilt-VA4DWCFB.mjs} +12 -12
  53. package/dist-lib/esm-chunks/{swift-sdk-app-module-4KYBNEBW.mjs → swift-sdk-app-module-3UUKIQI6.mjs} +16 -16
  54. package/dist-lib/esm-chunks/{swift-sdk-image-Z37PPINV.mjs → swift-sdk-image-XJURAHAQ.mjs} +16 -16
  55. package/dist-lib/esm-chunks/{swift-sdk-image-producer-7KFCU6Y6.mjs → swift-sdk-image-producer-HF3NTKWX.mjs} +5 -5
  56. package/dist-lib/expo-swift-bundle.cjs +137 -119
  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 +160 -143
  61. package/dist-lib/host/fetch-proxy-handler.cjs +5 -5
  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 +85 -85
  87. package/dist-lib/public-origins-lib.json +64 -64
  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 +160 -143
  95. package/dist-lib/swift-compile.cjs +133 -115
  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/engine/native-font-dataContract.d.ts +1 -0
  123. package/dist-types/packages/peach-kit/src/ui/hosting-safe-area.d.ts +17 -1
  124. package/package.json +1 -1
  125. package/src/one-direct-host-source.ts +23 -24
  126. package/src/swift-compile.ts +171 -152
@@ -2508,7 +2508,6 @@ function compiledSwiftSources(
2508
2508
  targets: SwiftPackageTarget[],
2509
2509
  overlayFrameworks: () => ReadonlySet<string>,
2510
2510
  headers: (target: SwiftPackageTarget) => Iterable<string>,
2511
- nativeSourceGlue = false,
2512
2511
  ): Map<string, string> {
2513
2512
  const ordered = [...targets].sort((a, b) => b.path.length - a.path.length)
2514
2513
  const byDir = indexTargetsByDirectory(ordered)
@@ -2539,10 +2538,7 @@ function compiledSwiftSources(
2539
2538
  return new Map(
2540
2539
  [...owners].map(([file, { source, owner }]) => {
2541
2540
  // generated transport must keep its wasi exports while app code emulates ios.
2542
- if (
2543
- nativeSourceGlue &&
2544
- path.posix.basename(file) === 'OneNativeSource.generated.swift'
2545
- )
2541
+ if (path.posix.basename(file) === 'OneNativeSource.generated.swift')
2546
2542
  return [file, source]
2547
2543
  const manifest = /(?:^|\/)Package(?:@swift-[\d.]+)?\.swift$/.test(file)
2548
2544
  if (manifest && (!owner || /^Package(?:@swift-[\d.]+)?\.swift$/.test(file)))
@@ -4749,7 +4745,6 @@ export function writeSwiftProject(
4749
4745
  .filter(([file]) => file.startsWith(`${directory}/`))
4750
4746
  .map(([, contents]) => contents)
4751
4747
  },
4752
- input.oneModule,
4753
4748
  )
4754
4749
  // an application's swift module must precede its native implementations.
4755
4750
  // the tiny executable calls the original typed entry after both are linked.
@@ -6355,9 +6350,11 @@ const frameworkProductsReceiptSchema = v.object({
6355
6350
  function readFrameworkProductsReceipt(
6356
6351
  scratch: string,
6357
6352
  receiptKey: string,
6353
+ planChangedAt = 0n,
6358
6354
  ): SwiftFrameworkProducts | null {
6359
6355
  const receiptFile = path.join(scratch, 'products-ready', `${receiptKey}.json`)
6360
- if (!existsSync(receiptFile)) return null
6356
+ const receiptStat = statSync(receiptFile, { bigint: true, throwIfNoEntry: false })
6357
+ if (!receiptStat || receiptStat.mtimeNs < planChangedAt) return null
6361
6358
  let parsed: v.InferOutput<typeof frameworkProductsReceiptSchema>
6362
6359
  try {
6363
6360
  parsed = v.parse(
@@ -6502,129 +6499,157 @@ async function buildFrameworkProducts(
6502
6499
  const unoptimized = args.input.unoptimized === true
6503
6500
  const sdkOptions = swiftCompileSdkOptions(args.moduleRoot, args.toolchainBin)
6504
6501
  const selectorOptions = swiftObjCSelectorOptions(args.moduleRoot)
6505
- const receiptKey = createHash('sha256')
6506
- .update(
6507
- JSON.stringify([
6508
- 'framework-products/v2',
6509
- args.frameworkKey,
6510
- unoptimized,
6511
- args.sdk,
6512
- args.toolchainBin,
6513
- [...linkedTargets.products].sort(),
6514
- darwinRecordsMinimum(),
6515
- args.plugins,
6516
- sdkOptions,
6517
- selectorOptions,
6518
- ]),
6519
- )
6520
- .digest('hex')
6521
- .slice(0, 32)
6502
+ const receiptKeyFor = (products: readonly string[]) =>
6503
+ createHash('sha256')
6504
+ .update(
6505
+ JSON.stringify([
6506
+ 'framework-products/v2',
6507
+ args.frameworkKey,
6508
+ unoptimized,
6509
+ args.sdk,
6510
+ args.toolchainBin,
6511
+ [...products].sort(),
6512
+ darwinRecordsMinimum(),
6513
+ args.plugins,
6514
+ sdkOptions,
6515
+ selectorOptions,
6516
+ ]),
6517
+ )
6518
+ .digest('hex')
6519
+ .slice(0, 32)
6520
+ const receiptKey = receiptKeyFor(linkedTargets.products)
6522
6521
  const ready = readFrameworkProductsReceipt(scratch, receiptKey)
6523
6522
  if (ready) return ready
6524
6523
  if (!allowWrite) return
6525
6524
 
6526
6525
  const linkRoot = path.join(scratch, 'link')
6527
- writeFrameworkLinkPackage(linkRoot, args.moduleRoot, linkedTargets.products)
6528
- const frameworkTmp = path.join(scratch, 'peach-compiler-tmp')
6529
- mkdirSync(frameworkTmp, { recursive: true })
6530
- const jobs = swiftCompilerJobs()
6531
- // keep cores available for the batch frontends inside large framework targets.
6532
- const targetJobs = jobs >= 4 ? 2 : 1
6533
- const driverJobs = Math.max(1, Math.floor(jobs / targetJobs))
6534
- const cache = unoptimized
6535
- ? null
6536
- : prepareFrameworkCompileCache(
6537
- scratch,
6538
- args.moduleRoot,
6539
- args.toolchainBin,
6540
- sdkOptions,
6541
- linkedTargets.products,
6542
- )
6543
- await runCompiler(
6544
- args.swift,
6545
- [
6546
- 'build',
6547
- ...swiftPackageCacheOptions(),
6548
- '--build-system',
6549
- 'native',
6550
- '-j',
6551
- String(targetJobs),
6552
- '--package-path',
6553
- linkRoot,
6554
- '--scratch-path',
6526
+ const manifest = path.join(linkRoot, 'Package.swift')
6527
+ const manifestStat = statSync(manifest, { bigint: true, throwIfNoEntry: false })
6528
+ const planStat = statSync(path.join(scratch, 'release.yaml'), {
6529
+ bigint: true,
6530
+ throwIfNoEntry: false,
6531
+ })
6532
+ const builtProducts =
6533
+ manifestStat && planStat
6534
+ ? [
6535
+ ...readFileSync(manifest, 'utf8').matchAll(
6536
+ /^\s*\.product\(name: "([^"]+)", package:/gm,
6537
+ ),
6538
+ ].map((match) => match[1]!)
6539
+ : []
6540
+ // a plan rewritten by a later build cannot borrow an older product receipt.
6541
+ const reusePlan =
6542
+ manifestStat &&
6543
+ planStat &&
6544
+ linkedTargets.products.every((product) => builtProducts.includes(product)) &&
6545
+ readFrameworkProductsReceipt(
6555
6546
  scratch,
6556
- '--target',
6557
- FRAMEWORK_LINK_TARGET,
6558
- ...sdkOptions,
6559
- ...selectorOptions,
6560
- '--swift-sdk',
6561
- args.sdk,
6562
- '-c',
6563
- 'release',
6564
- ...(cache
6565
- ? ['-Xswiftc', '-driver-use-frontend-path', '-Xswiftc', cache.wrapper]
6566
- : []),
6567
- '-Xswiftc',
6568
- unoptimized ? '-Onone' : '-Osize',
6569
- '-Xswiftc',
6570
- '-no-whole-module-optimization',
6571
- // optimized batches can move specialized definitions between object files.
6572
- ...(unoptimized ? ['-Xswiftc', '-incremental'] : []),
6573
- '-Xswiftc',
6574
- '-enable-batch-mode',
6575
- // each batch repeats the same framework diagnostics.
6576
- ...(unoptimized ? [] : ['-Xswiftc', '-suppress-warnings']),
6577
- '-Xswiftc',
6578
- '-j',
6579
- '-Xswiftc',
6580
- String(driverJobs),
6581
- // the release link strips all debug info, so none is generated.
6582
- '-Xswiftc',
6583
- '-gnone',
6584
- '-Xcc',
6585
- '-g0',
6586
- '-Xcxx',
6587
- '-g0',
6588
- '-Xswiftc',
6589
- '-num-threads',
6590
- '-Xswiftc',
6591
- '1',
6592
- ...swiftReproducibleBuildFlags([
6593
- [path.dirname(args.toolchainBin), 'toolchain'],
6594
- [args.moduleRoot, 'framework'],
6595
- [scratch, 'framework-scratch'],
6596
- ]),
6597
- ...args.plugins.libraries.flatMap((plugin) => [
6547
+ receiptKeyFor(builtProducts),
6548
+ manifestStat.ctimeNs > planStat.ctimeNs ? manifestStat.ctimeNs : planStat.ctimeNs,
6549
+ )
6550
+ if (!reusePlan) {
6551
+ writeFrameworkLinkPackage(linkRoot, args.moduleRoot, linkedTargets.products)
6552
+ const frameworkTmp = path.join(scratch, 'peach-compiler-tmp')
6553
+ mkdirSync(frameworkTmp, { recursive: true })
6554
+ const jobs = swiftCompilerJobs()
6555
+ // keep cores available for the batch frontends inside large framework targets.
6556
+ const targetJobs = jobs >= 4 ? 2 : 1
6557
+ const driverJobs = Math.max(1, Math.floor(jobs / targetJobs))
6558
+ const cache = unoptimized
6559
+ ? null
6560
+ : prepareFrameworkCompileCache(
6561
+ scratch,
6562
+ args.moduleRoot,
6563
+ args.toolchainBin,
6564
+ sdkOptions,
6565
+ linkedTargets.products,
6566
+ )
6567
+ await runCompiler(
6568
+ args.swift,
6569
+ [
6570
+ 'build',
6571
+ ...swiftPackageCacheOptions(),
6572
+ '--build-system',
6573
+ 'native',
6574
+ '-j',
6575
+ String(targetJobs),
6576
+ '--package-path',
6577
+ linkRoot,
6578
+ '--scratch-path',
6579
+ scratch,
6580
+ '--target',
6581
+ FRAMEWORK_LINK_TARGET,
6582
+ ...sdkOptions,
6583
+ ...selectorOptions,
6584
+ '--swift-sdk',
6585
+ args.sdk,
6586
+ '-c',
6587
+ 'release',
6588
+ ...(cache
6589
+ ? ['-Xswiftc', '-driver-use-frontend-path', '-Xswiftc', cache.wrapper]
6590
+ : []),
6598
6591
  '-Xswiftc',
6599
- '-load-plugin-library',
6592
+ unoptimized ? '-Onone' : '-Osize',
6600
6593
  '-Xswiftc',
6601
- plugin,
6602
- ]),
6603
- ...args.plugins.executables.flatMap((plugin) => [
6594
+ '-no-whole-module-optimization',
6595
+ // optimized batches can move specialized definitions between object files.
6596
+ ...(unoptimized ? ['-Xswiftc', '-incremental'] : []),
6604
6597
  '-Xswiftc',
6605
- '-load-plugin-executable',
6598
+ '-enable-batch-mode',
6599
+ // each batch repeats the same framework diagnostics.
6600
+ ...(unoptimized ? [] : ['-Xswiftc', '-suppress-warnings']),
6606
6601
  '-Xswiftc',
6607
- `${plugin}#ExpoModulesMacros`,
6608
- ]),
6609
- ],
6610
- // swiftpm hashes TMPDIR into its plan; keep one stable compiler scratch inside the locked slot.
6611
- // the framework build's warnings alone pass the default 1 MiB cap, which kills
6612
- // the build one step from the end.
6613
- {
6614
- ...args.buildOptions,
6615
- temporaryDirectory: frameworkTmp,
6616
- maxBuffer: 64 * 1024 * 1024,
6617
- },
6618
- SWIFTPM_PROGRESS,
6619
- SWIFTPM_NOISE,
6620
- )
6621
- .catch((error: unknown) => {
6622
- // the compiler's diagnostics ride on the error's streams, not its message
6623
- throw new Error(outputOf(error), { cause: error })
6624
- })
6625
- .finally(() => {
6626
- if (cache) reportFrameworkCompileCacheStats(scratch, cache.statsFile)
6627
- })
6602
+ '-j',
6603
+ '-Xswiftc',
6604
+ String(driverJobs),
6605
+ // the release link strips all debug info, so none is generated.
6606
+ '-Xswiftc',
6607
+ '-gnone',
6608
+ '-Xcc',
6609
+ '-g0',
6610
+ '-Xcxx',
6611
+ '-g0',
6612
+ '-Xswiftc',
6613
+ '-num-threads',
6614
+ '-Xswiftc',
6615
+ '1',
6616
+ ...swiftReproducibleBuildFlags([
6617
+ [path.dirname(args.toolchainBin), 'toolchain'],
6618
+ [args.moduleRoot, 'framework'],
6619
+ [scratch, 'framework-scratch'],
6620
+ ]),
6621
+ ...args.plugins.libraries.flatMap((plugin) => [
6622
+ '-Xswiftc',
6623
+ '-load-plugin-library',
6624
+ '-Xswiftc',
6625
+ plugin,
6626
+ ]),
6627
+ ...args.plugins.executables.flatMap((plugin) => [
6628
+ '-Xswiftc',
6629
+ '-load-plugin-executable',
6630
+ '-Xswiftc',
6631
+ `${plugin}#ExpoModulesMacros`,
6632
+ ]),
6633
+ ],
6634
+ // swiftpm hashes TMPDIR into its plan; keep one stable compiler scratch inside the locked slot.
6635
+ // the framework build's warnings alone pass the default 1 MiB cap, which kills
6636
+ // the build one step from the end.
6637
+ {
6638
+ ...args.buildOptions,
6639
+ temporaryDirectory: frameworkTmp,
6640
+ maxBuffer: 64 * 1024 * 1024,
6641
+ },
6642
+ SWIFTPM_PROGRESS,
6643
+ SWIFTPM_NOISE,
6644
+ )
6645
+ .catch((error: unknown) => {
6646
+ // the compiler's diagnostics ride on the error's streams, not its message
6647
+ throw new Error(outputOf(error), { cause: error })
6648
+ })
6649
+ .finally(() => {
6650
+ if (cache) reportFrameworkCompileCacheStats(scratch, cache.statsFile)
6651
+ })
6652
+ }
6628
6653
  const release = path.join(scratch, WASM_TRIPLE, 'release')
6629
6654
  const linked = frameworkLinkClosure(scratch, linkedTargets.targets)
6630
6655
  const objects = linked.objects
@@ -6800,6 +6825,7 @@ const SWIFT_FRAMEWORK_UNOPTIMIZED_SLOTS = 4
6800
6825
  const SWIFT_FRAMEWORK_SLOT_KEY = '.peach-framework-key'
6801
6826
  const SWIFT_FRAMEWORK_SLOT_ORIGIN = '.peach-framework-origin'
6802
6827
  const SWIFT_FRAMEWORK_SLOT_RELEASE = '.peach-framework-release'
6828
+ const SWIFT_FRAMEWORK_SLOT_HANDOFF = '.peach-framework-handoff'
6803
6829
 
6804
6830
  const SWIFT_BUILD_ROOT_SLOTS = 4
6805
6831
  const SWIFT_BUILD_ROOT_SHAPE = '.peach-build-shape'
@@ -6844,20 +6870,7 @@ function swiftFrameworkSlotRelease(slot: string): string | null {
6844
6870
  return swiftFrameworkSlotRecord(slot, SWIFT_FRAMEWORK_SLOT_RELEASE)
6845
6871
  }
6846
6872
 
6847
- // protect another caller's verified framework receipt long enough for a
6848
- // producer's caller or iterative guest build to reuse it before restaging.
6849
- const SWIFT_FRAMEWORK_HOT_RECEIPT_MS = 15 * 60 * 1000
6850
-
6851
- function swiftFrameworkSlotHasReceipt(slot: string): boolean {
6852
- try {
6853
- return readdirSync(path.join(slot, 'products-ready')).some((entry) =>
6854
- entry.endsWith('.json'),
6855
- )
6856
- } catch (error) {
6857
- if (vanished(error)) return false
6858
- throw error
6859
- }
6860
- }
6873
+ const SWIFT_FRAMEWORK_HANDOFF_MS = 15 * 60 * 1000
6861
6874
 
6862
6875
  async function withSwiftFrameworkSlot<T>(
6863
6876
  frameworkKey: string,
@@ -6869,7 +6882,8 @@ async function withSwiftFrameworkSlot<T>(
6869
6882
  lease: SwiftRootLease,
6870
6883
  allowWrite: boolean,
6871
6884
  ) => Promise<T | undefined>,
6872
- unoptimized = false,
6885
+ unoptimized: boolean,
6886
+ linkOnly: boolean,
6873
6887
  ): Promise<T> {
6874
6888
  const slotCount = swiftFrameworkSlotCount(unoptimized)
6875
6889
  const slotsDir = swiftFrameworksDir(unoptimized)
@@ -6888,15 +6902,20 @@ async function withSwiftFrameworkSlot<T>(
6888
6902
  throw error
6889
6903
  }
6890
6904
  }
6891
- const isRecentForeignReceipt = (slot: string, now: number) =>
6892
- !own(slot) &&
6893
- swiftFrameworkSlotHasReceipt(slot) &&
6894
- now - slotMtimeMs(slot) < SWIFT_FRAMEWORK_HOT_RECEIPT_MS
6905
+ const handoffFile = (slot: string) => path.join(slot, SWIFT_FRAMEWORK_SLOT_HANDOFF)
6906
+ const hasPendingForeignHandoff = (slot: string, now: number) => {
6907
+ const stamp = statSync(handoffFile(slot), { throwIfNoEntry: false })
6908
+ return (
6909
+ stamp !== undefined &&
6910
+ !own(slot) &&
6911
+ now - stamp.mtimeMs < SWIFT_FRAMEWORK_HANDOFF_MS
6912
+ )
6913
+ }
6895
6914
  const trySlot = (
6896
6915
  slot: string,
6897
6916
  mode: 'reuse' | 'extend' | 'restage',
6898
6917
  logSelection?: () => void,
6899
- allowHotForeign = true,
6918
+ allowPendingHandoff = true,
6900
6919
  ) => {
6901
6920
  return withSwiftRootLock(
6902
6921
  slot,
@@ -6905,13 +6924,12 @@ async function withSwiftFrameworkSlot<T>(
6905
6924
  if (mode !== 'restage' && !matches) return
6906
6925
  const allowWrite = mode !== 'reuse'
6907
6926
  if (allowWrite && (await hasLiveSwiftRootReaders(slot, signal))) return
6908
- // re-check recency under the lock so a queued stale rank cannot evict
6909
- // a foreign receipt written while waiting when cold/empty slots exist.
6927
+ // an image producer can finish preparing this slot after we ranked it.
6910
6928
  if (
6911
6929
  mode === 'restage' &&
6912
6930
  !matches &&
6913
- !allowHotForeign &&
6914
- isRecentForeignReceipt(slot, Date.now())
6931
+ !allowPendingHandoff &&
6932
+ hasPendingForeignHandoff(slot, Date.now())
6915
6933
  )
6916
6934
  return
6917
6935
  if (!matches) logSelection?.()
@@ -6926,6 +6944,8 @@ async function withSwiftFrameworkSlot<T>(
6926
6944
  `[swift-framework-cache] ${path.basename(slot)} hit=products release=${release}`,
6927
6945
  )
6928
6946
  const now = new Date()
6947
+ if (linkOnly) writeFileSync(handoffFile(slot), '')
6948
+ else rmSync(handoffFile(slot), { force: true })
6929
6949
  utimesSync(slot, now, now)
6930
6950
  return { value }
6931
6951
  },
@@ -6975,10 +6995,10 @@ async function withSwiftFrameworkSlot<T>(
6975
6995
  }
6976
6996
  // swiftc's swift-version hash invalidates every framework target when a slot
6977
6997
  // switches compiler release. keep each compiler release in its own slot and
6978
- // preserve recent foreign verified receipts while cold or empty slots exist:
6979
- // tier 0: own or cold same-release slot (nearest source, own first, LRU ties),
6998
+ // protect a foreign producer's products until an app has reused them.
6999
+ // tier 0: available same-release slot (nearest source, own first, LRU ties),
6980
7000
  // tier 1: empty slot,
6981
- // tier 2: recent foreign verified receipt (LRU first, immediate restage if all hot),
7001
+ // tier 2: pending foreign handoff (LRU first),
6982
7002
  // tier 3: another release (LRU).
6983
7003
  const rankSlots = (now: number) =>
6984
7004
  slots
@@ -6991,11 +7011,8 @@ async function withSwiftFrameworkSlot<T>(
6991
7011
  return { slot, index, tier: 3, changes: Infinity, own: false, mtimeMs }
6992
7012
  const changes = changedInputsFor(slot, slotKey)
6993
7013
  const isOwn = own(slot)
6994
- const hotForeign =
6995
- !isOwn &&
6996
- swiftFrameworkSlotHasReceipt(slot) &&
6997
- now - mtimeMs < SWIFT_FRAMEWORK_HOT_RECEIPT_MS
6998
- return { slot, index, tier: hotForeign ? 2 : 0, changes, own: isOwn, mtimeMs }
7014
+ const tier = hasPendingForeignHandoff(slot, now) ? 2 : 0
7015
+ return { slot, index, tier, changes, own: isOwn, mtimeMs }
6999
7016
  })
7000
7017
  .sort((left, right) => {
7001
7018
  if (left.tier !== right.tier) return left.tier - right.tier
@@ -7170,6 +7187,7 @@ function stageFrameworkSource(
7170
7187
  // an interrupted restage must not look like a finished one
7171
7188
  rmSync(path.join(slot, SWIFT_FRAMEWORK_SLOT_KEY), { force: true })
7172
7189
  rmSync(path.join(slot, SWIFT_FRAMEWORK_SLOT_RELEASE), { force: true })
7190
+ rmSync(path.join(slot, SWIFT_FRAMEWORK_SLOT_HANDOFF), { force: true })
7173
7191
  rmSync(path.join(slot, 'products-ready'), { recursive: true, force: true })
7174
7192
  rmSync(path.join(slot, 'products-lib'), { recursive: true, force: true })
7175
7193
  rmSync(path.join(slot, 'lib'), { recursive: true, force: true })
@@ -7625,6 +7643,7 @@ async function compileSwiftProjectOnce(
7625
7643
  budget.signal,
7626
7644
  prepareFrameworks,
7627
7645
  unoptimized,
7646
+ options.linkOnly === true,
7628
7647
  )
7629
7648
  if (!frameworks)
7630
7649
  throw new Error('Swift distribution did not provide its frameworks')