peachsim 0.1.1815 → 0.1.1818

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 (147) hide show
  1. package/cli/commands/agent-indicator-mode.ts +2 -1
  2. package/cli/commands/coverage-swift.ts +4 -3
  3. package/cli/commands/flow.ts +7 -0
  4. package/cli/commands/inspect/core.ts +1 -1
  5. package/cli/commands/maestro-compare.ts +7 -0
  6. package/cli/commands/package.ts +87 -31
  7. package/cli/commands/screenshot-mode.ts +2 -1
  8. package/cli/commands/shell-boolean-mode.ts +7 -3
  9. package/cli/commands/shell-url.ts +4 -0
  10. package/cli/commands/show-touches-mode.ts +2 -1
  11. package/cli/commands/test.ts +3 -2
  12. package/cli/commands/three-mode.ts +2 -1
  13. package/cli/outbound-endpoints.ts +1 -1
  14. package/cli/packaged-app-launcher.ts +6 -1
  15. package/dist-lib/agent-daemon-client.cjs +1 -1
  16. package/dist-lib/agent-events.cjs +1 -1
  17. package/dist-lib/attached-projects.cjs +1 -1
  18. package/dist-lib/auth/shared-session.cjs +1 -1
  19. package/dist-lib/backend-origin.cjs +1 -1
  20. package/dist-lib/beta.cjs +1 -1
  21. package/dist-lib/beta.mjs +1 -1
  22. package/dist-lib/bridge-constants.cjs +1 -1
  23. package/dist-lib/bridge-contract-input.cjs +1 -1
  24. package/dist-lib/bridge-contract-input.mjs +1 -1
  25. package/dist-lib/bridge-contract.cjs +1 -1
  26. package/dist-lib/bridge-contract.mjs +1 -1
  27. package/dist-lib/bundle-channel.cjs +5728 -7551
  28. package/dist-lib/capture-contract.cjs +1 -1
  29. package/dist-lib/capture-contract.mjs +1 -1
  30. package/dist-lib/cloud-contract.cjs +1 -1
  31. package/dist-lib/cloud-contract.mjs +1 -1
  32. package/dist-lib/cloud-test-args.cjs +1 -1
  33. package/dist-lib/cloud-test-args.mjs +1 -1
  34. package/dist-lib/cloud.cjs +1 -1
  35. package/dist-lib/cloud.mjs +1 -1
  36. package/dist-lib/config.cjs +1 -1
  37. package/dist-lib/config.mjs +1 -1
  38. package/dist-lib/detox/index.cjs +13 -4
  39. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  40. package/dist-lib/expo-swift-bundle.cjs +5234 -5704
  41. package/dist-lib/expo-swift-metadata.cjs +1 -1
  42. package/dist-lib/expo-swift-metadata.mjs +1 -1
  43. package/dist-lib/home-paths.cjs +1 -1
  44. package/dist-lib/host/bridge-host.cjs +4913 -6811
  45. package/dist-lib/host/fetch-proxy-handler.cjs +13 -4
  46. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  47. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  48. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  49. package/dist-lib/host/websocket-proxy.cjs +1 -1
  50. package/dist-lib/index.cjs +40 -30
  51. package/dist-lib/jump-to-source-babel.cjs +1 -1
  52. package/dist-lib/jump-to-source-native.cjs +1 -1
  53. package/dist-lib/kotlin-host.cjs +1 -1
  54. package/dist-lib/menu.cjs +1 -1
  55. package/dist-lib/menu.mjs +1 -1
  56. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  57. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  58. package/dist-lib/metro-production-bundle.cjs +1 -1
  59. package/dist-lib/metro-production-bundle.mjs +1 -1
  60. package/dist-lib/metro.cjs +39 -29
  61. package/dist-lib/native-app-identity-project.cjs +31 -26
  62. package/dist-lib/native-app-identity-project.mjs +295 -279
  63. package/dist-lib/native-app-identity.cjs +1 -1
  64. package/dist-lib/native-app-identity.mjs +1 -1
  65. package/dist-lib/native-firebase-metadata.cjs +1 -1
  66. package/dist-lib/native-firebase-metadata.mjs +1 -1
  67. package/dist-lib/pdfium-raster.cjs +1 -1
  68. package/dist-lib/pdfium-raster.mjs +1 -1
  69. package/dist-lib/plist.cjs +1 -1
  70. package/dist-lib/plist.mjs +1 -1
  71. package/dist-lib/profiles.cjs +1 -1
  72. package/dist-lib/public-brand.cjs +1 -1
  73. package/dist-lib/public-origins-lib-esm.json +29 -24
  74. package/dist-lib/public-origins-lib.json +121 -93
  75. package/dist-lib/react-native-host-modules.cjs +1 -1
  76. package/dist-lib/react-native-host-modules.mjs +1 -1
  77. package/dist-lib/reap-browser.cjs +1 -1
  78. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  79. package/dist-lib/sdk.cjs +2 -2
  80. package/dist-lib/sdk.mjs +2 -2
  81. package/dist-lib/skills.cjs +64622 -66476
  82. package/dist-lib/swift-compile.cjs +328 -265
  83. package/dist-lib/swift-compile.mjs +335 -270
  84. package/dist-lib/swift-package.cjs +1 -1
  85. package/dist-lib/swift-package.mjs +1 -1
  86. package/dist-lib/swift-submit.cjs +1 -1
  87. package/dist-lib/swift-submit.mjs +1 -1
  88. package/dist-lib/swift-toolchain.cjs +52 -6
  89. package/dist-lib/swift.cjs +1 -1
  90. package/dist-lib/vite-swift.cjs +2405 -2262
  91. package/dist-lib/vite.cjs +13 -4
  92. package/dist-lib/worklet-executable.cjs +1 -1
  93. package/dist-lib/worklet-executable.mjs +1 -1
  94. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +5 -0
  95. package/dist-types/packages/peach-engine/src/render-worker/map-command-channel.d.ts +41 -0
  96. package/dist-types/packages/peach-engine/src/render-worker/mapServicesContract.d.ts +45 -0
  97. package/package.json +2 -1
  98. package/runtime-companion.json +1 -1
  99. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.apinotes +1 -1
  100. package/sdk/ios/usr/include/module.modulemap +3 -0
  101. package/sdk/ios/usr/include/notify.modulemap +9 -0
  102. package/sdk/ios/usr/lib/swift/Darwin.swiftmodule/arm64-apple-ios-simulator.swiftinterface +4 -0
  103. package/sdk/ios/usr/lib/swift/Dispatch.swiftmodule/arm64-apple-ios-simulator.swiftinterface +1 -1
  104. package/sdk/ios/usr/lib/swift/Foundation.swiftmodule/arm64-apple-ios-simulator.swiftinterface +7 -1
  105. package/sdk/ios/usr/lib/swift/ObjectiveC.swiftmodule/arm64-apple-ios-simulator.swiftinterface +1 -0
  106. package/sdk/ios/usr/lib/swift/SwiftUI.swiftmodule/arm64-apple-ios-simulator.swiftinterface +21 -0
  107. package/sdk/ios/usr/lib/swift/SwiftUICore.swiftmodule/arm64-apple-ios-simulator.swiftinterface +6 -1
  108. package/sdk/ios/wasm/include/__header_time.h +4 -0
  109. package/sdk/ios/wasm/include/pthread.h +2 -0
  110. package/sdk/ios/wasm/include/sys/mman.h +1 -1
  111. package/sdk/ios/wasm/include/sys/resource.h +31 -0
  112. package/sdk/ios/wasm/include/unistd.h +4 -0
  113. package/src/answeredNativePackages.ts +43 -0
  114. package/src/cli-runtime.ts +2 -9
  115. package/src/expo-discovery-cache.ts +71 -52
  116. package/src/expo-kotlin-host.ts +11 -9
  117. package/src/expo-swift-host.ts +55 -13
  118. package/src/installed-native-libraries.ts +103 -20
  119. package/src/native-static-libraries.ts +69 -33
  120. package/src/nitro-adapter.ts +0 -9
  121. package/src/nitro-bundle.ts +8 -6
  122. package/src/nitro-compile.ts +45 -16
  123. package/src/nitro-compiler-digest.ts +2 -4
  124. package/src/nitro-superset.lock.json +19 -251
  125. package/src/nitro-superset.ts +63 -68
  126. package/src/plist-bytes.ts +9 -0
  127. package/src/portable-expo-workspace.ts +4 -3
  128. package/src/react-native-bridge-modules.ts +13 -19
  129. package/src/swift-compile.ts +379 -269
  130. package/src/swift-cxx-reachable.ts +13 -0
  131. package/src/swift-distribution.ts +3 -4
  132. package/src/swift-host.ts +5 -3
  133. package/src/swift-installed-targets.ts +32 -14
  134. package/src/swift-native-pin.ts +45 -0
  135. package/src/swift-objc-compile.ts +23 -1
  136. package/src/swift-objc-standin.ts +14 -7
  137. package/src/swift-package-manifest.ts +2 -2
  138. package/src/swift-root-lock.ts +4 -3
  139. package/src/swift-standins.ts +41 -38
  140. package/src/swift-toolchain.ts +69 -12
  141. package/src/swift-wasm-prune.ts +1 -0
  142. package/src/swift-xcframework.ts +23 -12
  143. package/src/swiftContract.ts +2 -0
  144. package/src/swiftNativePinContract.ts +68 -0
  145. package/src/turbo-bundle.ts +14 -6
  146. package/src/turbo-compile.ts +76 -11
  147. package/src/turbo-source.ts +93 -18
@@ -541,7 +541,10 @@ export function swiftModuleInputFiles(root: string): string[] {
541
541
  // app compile. their source inputs also participate in artifact identity.
542
542
  /** the host macro plugin libraries a module root compiles with, and whether a
543
543
  * checkout's must be rebuilt (scripts/build-preview-plugin.sh) first. */
544
- export function swiftMacroPlugins(moduleRoot: string): {
544
+ export function swiftMacroPlugins(
545
+ moduleRoot: string,
546
+ dir = path.join(moduleRoot, '.build/host/RnxPreviewMacros'),
547
+ ): {
545
548
  libraries: string[]
546
549
  executables: string[]
547
550
  stale: boolean
@@ -557,7 +560,6 @@ export function swiftMacroPlugins(moduleRoot: string): {
557
560
  .map((plugin) => path.join(moduleRoot, plugin)),
558
561
  stale: false,
559
562
  }
560
- const dir = path.join(moduleRoot, '.build/host/RnxPreviewMacros')
561
563
  const release = JSON.parse(
562
564
  readFileSync(path.join(moduleRoot, 'toolchain.json'), 'utf8'),
563
565
  ).release
@@ -1127,14 +1129,20 @@ export function swiftAvailableModules(
1127
1129
  for (const match of readFileSync(map, 'utf8').matchAll(/^module\s+([A-Za-z_]\w*)/gm))
1128
1130
  modules.add(match[1]!)
1129
1131
  }
1130
- const libc = path.join(darwin, 'usr/include')
1131
- for (const entry of readdirSync(libc)) {
1132
- if (!entry.endsWith('.modulemap')) continue
1133
- for (const match of readFileSync(path.join(libc, entry), 'utf8').matchAll(
1134
- /^module\s+([A-Za-z_]\w*)/gm,
1135
- ))
1136
- modules.add(match[1]!)
1137
- }
1132
+ for (const libc of [
1133
+ path.join(darwin, 'usr/include'),
1134
+ path.join(
1135
+ swiftSharedSdkRoot(moduleRoot, swiftDistributionAt(moduleRoot) !== null),
1136
+ 'usr/include',
1137
+ ),
1138
+ ])
1139
+ for (const entry of readdirSync(libc)) {
1140
+ if (!entry.endsWith('.modulemap')) continue
1141
+ for (const match of readFileSync(path.join(libc, entry), 'utf8').matchAll(
1142
+ /^module\s+([A-Za-z_]\w*)/gm,
1143
+ ))
1144
+ modules.add(match[1]!)
1145
+ }
1138
1146
  for (const directory of frameworks) {
1139
1147
  for (const entry of readdirSync(directory)) {
1140
1148
  const map = path.join(directory, entry, 'Modules/module.modulemap')
@@ -1553,6 +1561,7 @@ function toolsetOrdersLibcxxBeforeDarwinOverlay(options: readonly string[]): boo
1553
1561
  export function emitSwiftPackageManifest(args: {
1554
1562
  /** the build root holding the linker each executable links with. */
1555
1563
  root: string
1564
+ files: Map<string, string | Buffer>
1556
1565
  targets: SwiftPackageTarget[]
1557
1566
  packages?: ReadonlyMap<string, string>
1558
1567
  cxxLanguageStandard?: string
@@ -1702,6 +1711,16 @@ export function emitSwiftPackageManifest(args: {
1702
1711
  // temporaries in one function; decode the generated strings without changing order.
1703
1712
  const flagArray = (literal: string): string =>
1704
1713
  `peachCompilerArguments(${JSON.stringify(literal.replace(/,\s*]$/, ']'))})`
1714
+ // swiftpm expands target settings into one command; large native import
1715
+ // closures exceed exec's argument limit. keep their ordered bytes on disk.
1716
+ const swiftFlagArray = (literal: string): string => {
1717
+ const flags: string[] = JSON.parse(literal.replace(/,\s*]$/, ']'))
1718
+ const content = flags.map((flag) => JSON.stringify(flag)).join('\n') + '\n'
1719
+ const digest = createHash('sha256').update(content).digest('hex')
1720
+ const file = path.join(args.root, '.peach-swift-arguments', `${digest}.rsp`)
1721
+ args.files.set(file, content)
1722
+ return JSON.stringify([`@${file}`])
1723
+ }
1705
1724
  const declaredClangSettings = (
1706
1725
  target: SwiftPackageTarget | undefined,
1707
1726
  tool: 'c' | 'cxx',
@@ -1822,7 +1841,7 @@ export function emitSwiftPackageManifest(args: {
1822
1841
  ? `, "-emit-objc-header-path", ${JSON.stringify(path.join(args.headerDirectory, `${target.name}-Swift${args.nativeHeaderDeclarations?.[target.name] ? '.original' : ''}.h`))}`
1823
1842
  : ''
1824
1843
  const clangMode = target.cxxInterop ? '' : ', "-Xcc", "-fno-cxx-modules"'
1825
- const swiftSettings = `swiftSettings: [.swiftLanguageMode(.v${target.languageMode}),${isolation}${interoperability}${defines}${features}${upcoming} .unsafeFlags(${flagArray(`["-Osize", "-Xfrontend", "-enable-cross-import-overlays"${overlayFlags}${FOUNDATION_IMPLICIT_FLAGS}${oneModule ? ONE_IMPLICIT_FLAGS : ''}${imports}${nativeImportFlags}${objcFlags}${header}${clangMode}${upstream}]`)})]`
1844
+ const swiftSettings = `swiftSettings: [.swiftLanguageMode(.v${target.languageMode}),${isolation}${interoperability}${defines}${features}${upcoming} .unsafeFlags(${swiftFlagArray(`["-Osize", "-Xfrontend", "-enable-cross-import-overlays"${overlayFlags}${FOUNDATION_IMPLICIT_FLAGS}${oneModule ? ONE_IMPLICIT_FLAGS : ''}${imports}${nativeImportFlags}${objcFlags}${header}${clangMode}${upstream}]`)})]`
1826
1845
  const deps = [
1827
1846
  ...new Set([
1828
1847
  ...(target.dependencies ?? []).flatMap((dependency) =>
@@ -3941,12 +3960,24 @@ function namesLibxml2(input: SwiftCompileInput): boolean {
3941
3960
  return false
3942
3961
  }
3943
3962
 
3963
+ function needsNativeToolset(
3964
+ input: SwiftCompileInput,
3965
+ prebuilt?: SwiftFrameworkProducts,
3966
+ ): boolean {
3967
+ return Boolean(
3968
+ input.packageFiles ||
3969
+ prebuilt ||
3970
+ Object.keys(input.files).some(isSwiftNativeTranslationUnit),
3971
+ )
3972
+ }
3973
+
3944
3974
  export function writeSwiftProject(
3945
3975
  layout: SwiftProjectLayout,
3946
3976
  input: SwiftCompileInput,
3947
3977
  moduleRoot: string,
3948
3978
  prebuilt?: SwiftFrameworkProducts,
3949
3979
  ): SwiftProjectPreparation {
3980
+ const nativeToolset = needsNativeToolset(input, prebuilt)
3950
3981
  if (input.headerAliases !== undefined && !isSwiftHeaderAliases(input.headerAliases))
3951
3982
  throw new Error('swift compile input has invalid original header aliases')
3952
3983
  if (input.nativeTargets !== undefined && !isSwiftNativeTargets(input.nativeTargets))
@@ -4406,7 +4437,15 @@ export function writeSwiftProject(
4406
4437
  importModuleMaps,
4407
4438
  generatedModuleMaps,
4408
4439
  )
4409
- const flags = [...stageFlags(originalFlags, sdkInclude), ...dependencyModuleMaps]
4440
+ // xcode compiles these units without swiftpm's automatic SWIFT_PACKAGE.
4441
+ const flags = [
4442
+ ...stageFlags(originalFlags, sdkInclude),
4443
+ ...dependencyModuleMaps,
4444
+ ...(target.defines?.includes(SWIFT_XCODE_BUILD_CONDITION) &&
4445
+ !target.defines.includes('SWIFT_PACKAGE')
4446
+ ? ['-USWIFT_PACKAGE']
4447
+ : []),
4448
+ ]
4410
4449
  const prefixHeader = settings?.prefixHeader
4411
4450
  ? ['-include', path.join(layout.root, settings.prefixHeader)]
4412
4451
  : []
@@ -4630,7 +4669,8 @@ export function writeSwiftProject(
4630
4669
  .slice(0, 12)
4631
4670
  const name = `${target.name}${nativeC ? 'Native' : 'Swift'}Implementation_${identity}`
4632
4671
  const groupPath = path.posix.join('PeachNativeSources', name)
4633
- const sourceIdentity = `-ffile-prefix-map=${path.join(layout.root, groupPath)}=${path.join(layout.root, target.path)}`
4672
+ const identityRoot = nativeToolset ? '/peach/build' : layout.root
4673
+ const sourceIdentity = `-ffile-prefix-map=${path.join(identityRoot, groupPath)}=${path.join(identityRoot, target.path)}`
4634
4674
  const group = groups.get(identity) ?? {
4635
4675
  name,
4636
4676
  path: groupPath,
@@ -5282,6 +5322,7 @@ export function writeSwiftProject(
5282
5322
  path.join(layout.root, 'Package.swift'),
5283
5323
  emitSwiftPackageManifest({
5284
5324
  root: layout.root,
5325
+ files,
5285
5326
  targets: manifestTargets,
5286
5327
  packages,
5287
5328
  native,
@@ -5348,7 +5389,7 @@ export function writeSwiftProject(
5348
5389
  if (files.has(destination)) continue
5349
5390
  files.set(destination, Buffer.from(bytes, 'base64'))
5350
5391
  }
5351
- if (input.packageFiles || prebuilt) {
5392
+ if (nativeToolset) {
5352
5393
  files.set(
5353
5394
  path.join(layout.root, '.peach-target-toolset.json'),
5354
5395
  JSON.stringify({
@@ -5452,6 +5493,10 @@ export function writeSwiftProject(
5452
5493
  for (const dependency of dependencies.get(producer) ?? []) include(dependency)
5453
5494
  // building a producer also emits its dependency producers' headers.
5454
5495
  return {
5496
+ nativeBuildTargets: [...native].flatMap(([name, plan]) => [
5497
+ ...(!plan.mixed && plan.sources.length > 0 ? [name] : []),
5498
+ ...(plan.groups?.map((group) => group.name) ?? (plan.late ? [plan.late.name] : [])),
5499
+ ]),
5455
5500
  headerProducers: [
5456
5501
  ...new Set([
5457
5502
  ...Object.keys(nativeHeaderDeclarations),
@@ -5477,7 +5522,7 @@ function outputOf(error: unknown): string {
5477
5522
  streamText(Reflect.get(error, 'stderr')),
5478
5523
  ].filter(Boolean)
5479
5524
  // a killed process leaves no error line, so the runner's own message names how it ended.
5480
- if (error instanceof Error) streams.push(error.message)
5525
+ if (error instanceof Error) streams.unshift(error.message)
5481
5526
  if (streams.length > 0) return streams.join('\n')
5482
5527
  }
5483
5528
  return error instanceof Error ? error.message : String(error)
@@ -6207,7 +6252,24 @@ function retireStaleSwiftLink(root: string, stamp: string): boolean {
6207
6252
  }
6208
6253
 
6209
6254
  /** the project compiler shared by route hosts, Vite and source probes. */
6210
- export function compileSwiftProjectUnit(
6255
+ export async function compileSwiftProjectUnit(
6256
+ input: SwiftCompileInput,
6257
+ options: SwiftCompileOptions,
6258
+ ): Promise<SwiftCompileArtifact> {
6259
+ // the shared checkout keeps landing while a builder hop waits in the heavy
6260
+ // window queue, so its sources can move past the hash this caller pinned.
6261
+ // rehashing and requesting again builds the sources that now exist.
6262
+ for (let attempt = 1; ; attempt++) {
6263
+ try {
6264
+ return await compileSwiftProjectOnce(input, options)
6265
+ } catch (error) {
6266
+ if (attempt >= 3 || !outputOf(error).includes('differs from the caller'))
6267
+ throw error
6268
+ }
6269
+ }
6270
+ }
6271
+
6272
+ function compileSwiftProjectOnce(
6211
6273
  input: SwiftCompileInput,
6212
6274
  options: SwiftCompileOptions,
6213
6275
  ): Promise<SwiftCompileArtifact> {
@@ -6351,284 +6413,332 @@ export function compileSwiftProjectUnit(
6351
6413
  `swift-compile: no swift.org toolchain at ${options.toolchainBin}; install ${options.release} and its matching wasm sdk`,
6352
6414
  )
6353
6415
  }
6354
- return withSwiftRootLock(
6355
- swiftFrameworkScratch(frameworkKey),
6356
- async (frameworkLease) => {
6357
- const frameworkRoot = stageFrameworkSource(moduleRoot, frameworkKey)
6358
- report('preparing compiler plugins')
6359
- const macroPlugins = await ensureMacroPlugins(
6416
+ // a distribution is immutable and builds no framework products, so app
6417
+ // roots compiling against it overlap and only its plugin check queues.
6418
+ const frameworkScratch = swiftFrameworkScratch(frameworkKey)
6419
+ const withFrameworkLock = <T>(
6420
+ work: (frameworkLease?: SwiftRootLease) => Promise<T>,
6421
+ ) =>
6422
+ distribution
6423
+ ? work()
6424
+ : withSwiftRootLock(frameworkScratch, work, options.signal)
6425
+ return withFrameworkLock(async (frameworkLease) => {
6426
+ const frameworkRoot = stageFrameworkSource(moduleRoot, frameworkKey)
6427
+ report('preparing compiler plugins')
6428
+ const pluginsFor = (pluginLease?: SwiftRootLease) =>
6429
+ ensureMacroPlugins(
6360
6430
  frameworkRoot,
6361
6431
  options.toolchainBin,
6362
6432
  options.release,
6363
6433
  options.signal,
6364
- frameworkLease,
6434
+ pluginLease,
6365
6435
  )
6366
- // memoized per toolchain, so only a process's first build waits on it,
6367
- // and that one reads and gzips it while swift builds
6368
- const sdk = swiftModuleSdk(frameworkRoot).wasmSdkId
6369
- const icu = swiftIcuAsset(options.toolchainBin, sdk)
6370
- const buildOptions = {
6371
- env: {
6372
- ...(options.project?.env ?? process.env),
6373
- // shipped host plugins resolve against the selected compiler's runtime.
6374
- ...(process.platform === 'linux'
6375
- ? {
6376
- LD_LIBRARY_PATH: [
6377
- path.resolve(options.toolchainBin, '../lib/swift/linux'),
6378
- path.resolve(options.toolchainBin, '../lib/swift/host'),
6379
- process.env.LD_LIBRARY_PATH,
6380
- ]
6381
- .filter(Boolean)
6382
- .join(':'),
6383
- }
6384
- : {}),
6385
- ...(input.lazyDistribution ? { PEACH_DEFER_WASM_LINK: '1' } : {}),
6386
- },
6387
- maxBuffer: 64 * 1024 * 1024,
6388
- timeout: options.timeoutMs,
6389
- signal: options.signal,
6390
- lease,
6391
- frameworkLease,
6392
- }
6393
- let prebuilt: SwiftFrameworkProducts | undefined
6394
- if (!swiftDistributionAt(moduleRoot)) {
6395
- report('compiling framework products')
6396
- prebuilt = await compileFrameworkProducts({
6397
- moduleRoot: frameworkRoot,
6398
- frameworkKey,
6399
- input,
6400
- swift,
6401
- sdk,
6402
- toolchainBin: options.toolchainBin,
6403
- plugins: macroPlugins,
6404
- buildOptions,
6405
- })
6406
- await pruneFrameworkScratches(frameworkKey)
6407
- }
6408
- if (options.project) removeProjectLinks(root)
6409
- if (
6410
- retireStaleSwiftLink(
6411
- root,
6412
- swiftLinkStamp({
6413
- frameworkKey,
6414
- prebuilt,
6415
- }),
6416
- )
6417
- )
6418
- report('framework revision changed; rebuilding the app link')
6419
- const preparation = writeSwiftProject(
6420
- layout,
6436
+ const macroPlugins = distribution
6437
+ ? await withSwiftRootLock(frameworkScratch, pluginsFor, options.signal)
6438
+ : await pluginsFor(frameworkLease)
6439
+ // memoized per toolchain, so only a process's first build waits on it,
6440
+ // and that one reads and gzips it while swift builds
6441
+ const sdk = swiftModuleSdk(frameworkRoot).wasmSdkId
6442
+ const icu = swiftIcuAsset(options.toolchainBin, sdk)
6443
+ const buildOptions = {
6444
+ env: {
6445
+ ...(options.project?.env ?? process.env),
6446
+ // shipped host plugins resolve against the selected compiler's runtime.
6447
+ ...(process.platform === 'linux'
6448
+ ? {
6449
+ LD_LIBRARY_PATH: [
6450
+ path.resolve(options.toolchainBin, '../lib/swift/linux'),
6451
+ path.resolve(options.toolchainBin, '../lib/swift/host'),
6452
+ process.env.LD_LIBRARY_PATH,
6453
+ ]
6454
+ .filter(Boolean)
6455
+ .join(':'),
6456
+ }
6457
+ : {}),
6458
+ ...(input.lazyDistribution ? { PEACH_DEFER_WASM_LINK: '1' } : {}),
6459
+ },
6460
+ maxBuffer: 64 * 1024 * 1024,
6461
+ timeout: options.timeoutMs,
6462
+ signal: options.signal,
6463
+ lease,
6464
+ frameworkLease,
6465
+ }
6466
+ let prebuilt: SwiftFrameworkProducts | undefined
6467
+ if (!distribution) {
6468
+ report('compiling framework products')
6469
+ prebuilt = await compileFrameworkProducts({
6470
+ moduleRoot: frameworkRoot,
6471
+ frameworkKey,
6421
6472
  input,
6422
- frameworkRoot,
6423
- prebuilt,
6473
+ swift,
6474
+ sdk,
6475
+ toolchainBin: options.toolchainBin,
6476
+ plugins: macroPlugins,
6477
+ buildOptions,
6478
+ })
6479
+ await pruneFrameworkScratches(frameworkKey)
6480
+ }
6481
+ if (options.project) removeProjectLinks(root)
6482
+ if (
6483
+ retireStaleSwiftLink(
6484
+ root,
6485
+ swiftLinkStamp({
6486
+ frameworkKey,
6487
+ prebuilt,
6488
+ }),
6424
6489
  )
6425
- writeSwiftAutolinkLinker(root, options.toolchainBin)
6426
- const projectProcess = options.project
6427
- ? prepareSwiftProjectProcess(root, options.project)
6428
- : undefined
6429
- const appOptions = projectProcess
6430
- ? {
6431
- ...buildOptions,
6432
- uid: projectProcess.uid,
6433
- gid: projectProcess.gid,
6434
- confined: projectProcess.env,
6435
- }
6436
- : buildOptions
6437
- const unprepared = preparation.targetFailures.map(
6438
- (failure) => `error: target ${failure}`,
6490
+ )
6491
+ report('framework revision changed; rebuilding the app link')
6492
+ const nativeToolset = needsNativeToolset(input, prebuilt)
6493
+ const preparation = writeSwiftProject(layout, input, frameworkRoot, prebuilt)
6494
+ writeSwiftAutolinkLinker(root, options.toolchainBin)
6495
+ const projectProcess = options.project
6496
+ ? prepareSwiftProjectProcess(root, options.project)
6497
+ : undefined
6498
+ const appOptions = projectProcess
6499
+ ? {
6500
+ ...buildOptions,
6501
+ uid: projectProcess.uid,
6502
+ gid: projectProcess.gid,
6503
+ confined: projectProcess.env,
6504
+ }
6505
+ : buildOptions
6506
+ const unprepared = preparation.targetFailures.map(
6507
+ (failure) => `error: target ${failure}`,
6508
+ )
6509
+ // a forwarder header (`#include "../../x.hpp"`) reaches its target
6510
+ // through `..`, which clang keeps in __FILE__, while the header
6511
+ // alias overlay names the same file directly. mapping each
6512
+ // forwarder spelling to the directory it reaches makes a debug
6513
+ // assert expand alike in every module that includes the header.
6514
+ const forwarders = new Map<string, string>()
6515
+ for (const [file, text] of Object.entries(input.files)) {
6516
+ const parents = /^#include "((?:\.\.\/)+)[^"\n]+"\n$/.exec(text)?.[1]
6517
+ if (!parents) continue
6518
+ const directory = path.posix.dirname(file)
6519
+ forwarders.set(
6520
+ `${path.join(root, directory)}/${parents.slice(0, -1)}`,
6521
+ path.posix.join('build', directory, parents).replace(/\/$/, ''),
6439
6522
  )
6440
- // a forwarder header (`#include "../../x.hpp"`) reaches its target
6441
- // through `..`, which clang keeps in __FILE__, while the header
6442
- // alias overlay names the same file directly. mapping each
6443
- // forwarder spelling to the directory it reaches makes a debug
6444
- // assert expand alike in every module that includes the header.
6445
- const forwarders = new Map<string, string>()
6446
- for (const [file, text] of Object.entries(input.files)) {
6447
- const parents = /^#include "((?:\.\.\/)+)[^"\n]+"\n$/.exec(text)?.[1]
6448
- if (!parents) continue
6449
- const directory = path.posix.dirname(file)
6450
- forwarders.set(
6451
- `${path.join(root, directory)}/${parents.slice(0, -1)}`,
6452
- path.posix.join('build', directory, parents).replace(/\/$/, ''),
6453
- )
6454
- }
6455
- const buildArgs = [
6456
- 'build',
6457
- ...(projectProcess?.cacheOptions ?? swiftPackageCacheOptions()),
6458
- '--build-system',
6459
- 'native',
6460
- '-j',
6461
- BUILD_JOBS,
6462
- '--package-path',
6463
- root,
6464
- ...swiftCompileSdkOptions(frameworkRoot, options.toolchainBin),
6465
- '--swift-sdk',
6466
- sdk,
6467
- ...(input.packageFiles || prebuilt
6468
- ? ['--toolset', path.join(root, '.peach-target-toolset.json')]
6469
- : []),
6470
- '-c',
6471
- 'release',
6523
+ }
6524
+ const buildArgs = [
6525
+ 'build',
6526
+ ...(projectProcess?.cacheOptions ?? swiftPackageCacheOptions()),
6527
+ '--build-system',
6528
+ 'native',
6529
+ '-j',
6530
+ BUILD_JOBS,
6531
+ '--package-path',
6532
+ root,
6533
+ ...swiftCompileSdkOptions(frameworkRoot, options.toolchainBin),
6534
+ '--swift-sdk',
6535
+ sdk,
6536
+ ...(nativeToolset
6537
+ ? ['--toolset', path.join(root, '.peach-target-toolset.json')]
6538
+ : []),
6539
+ '-c',
6540
+ 'release',
6541
+ '-Xswiftc',
6542
+ '-num-threads',
6543
+ '-Xswiftc',
6544
+ BUILD_JOBS,
6545
+ ...swiftReproducibleBuildFlags([
6546
+ [path.dirname(options.toolchainBin), 'toolchain'],
6547
+ [frameworkRoot, 'framework'],
6548
+ [root, 'build'],
6549
+ ...forwarders,
6550
+ ]).flatMap((flag, index, flags) => {
6551
+ if (!nativeToolset || !flag.startsWith('-ffile-prefix-map='))
6552
+ return [flag]
6553
+ const mapped = flag
6554
+ .replaceAll(root, '/peach/build')
6555
+ .replaceAll(frameworkRoot, '/peach/framework')
6556
+ .replaceAll(path.dirname(options.toolchainBin), '/peach/toolchain')
6557
+ // native depscan already maps paths; Swift's importer still
6558
+ // reads the physical filesystem and needs the original map.
6559
+ return flags[index - 1] === '-Xcc'
6560
+ ? [mapped, '-Xswiftc', '-Xcc', '-Xswiftc', flag]
6561
+ : [mapped]
6562
+ }),
6563
+ ...macroPlugins.libraries.flatMap((plugin) => [
6472
6564
  '-Xswiftc',
6473
- '-num-threads',
6565
+ '-load-plugin-library',
6474
6566
  '-Xswiftc',
6475
- BUILD_JOBS,
6476
- ...swiftReproducibleBuildFlags([
6477
- [path.dirname(options.toolchainBin), 'toolchain'],
6478
- [frameworkRoot, 'framework'],
6479
- [root, 'build'],
6480
- ...forwarders,
6481
- ]),
6482
- ...macroPlugins.libraries.flatMap((plugin) => [
6483
- '-Xswiftc',
6484
- '-load-plugin-library',
6485
- '-Xswiftc',
6486
- plugin,
6487
- ]),
6488
- ...macroPlugins.executables.flatMap((plugin) => [
6489
- '-Xswiftc',
6490
- '-load-plugin-executable',
6491
- '-Xswiftc',
6492
- `${plugin}#ExpoModulesMacros`,
6493
- ]),
6494
- ]
6495
- const linked = builtArtifact(layout)
6496
- if (input.lazyDistribution) {
6497
- rmSync(path.join(root, '.peach-link.rsp'), { force: true })
6498
- if (existsSync(linked) && statSync(linked).size <= 8)
6499
- rmSync(linked, { force: true })
6500
- }
6501
- report('compiling and linking Swift modules')
6502
- try {
6503
- // clang consumes the real emitted headers after swift finishes.
6504
- // swiftpm's transitive swift module maps are not C declarations:
6505
- // importing them would shadow SDK modules such as ObjectiveC.
6506
- const headerBuilds = preparation.headerProductTarget
6507
- ? [
6508
- ...Object.keys(preparation.nativeHeaderDeclarations),
6509
- preparation.headerProductTarget,
6510
- ]
6511
- : preparation.headerProducers
6512
- for (const build of headerBuilds) {
6513
- await runCompiler(
6514
- swift,
6515
- [...buildArgs, '--target', build],
6516
- appOptions,
6517
- SWIFTPM_PROGRESS,
6518
- SWIFTPM_NOISE,
6567
+ plugin,
6568
+ ]),
6569
+ ...macroPlugins.executables.flatMap((plugin) => [
6570
+ '-Xswiftc',
6571
+ '-load-plugin-executable',
6572
+ '-Xswiftc',
6573
+ `${plugin}#ExpoModulesMacros`,
6574
+ ]),
6575
+ ]
6576
+ const linked = builtArtifact(layout)
6577
+ if (input.lazyDistribution) {
6578
+ rmSync(path.join(root, '.peach-link.rsp'), { force: true })
6579
+ if (existsSync(linked) && statSync(linked).size <= 8)
6580
+ rmSync(linked, { force: true })
6581
+ }
6582
+ report('compiling and linking Swift modules')
6583
+ try {
6584
+ // clang consumes the real emitted headers after swift finishes.
6585
+ // swiftpm's transitive swift module maps are not C declarations:
6586
+ // importing them would shadow SDK modules such as ObjectiveC.
6587
+ const headerBuilds = preparation.headerProductTarget
6588
+ ? [
6589
+ ...Object.keys(preparation.nativeHeaderDeclarations),
6590
+ preparation.headerProductTarget,
6591
+ ]
6592
+ : preparation.headerProducers
6593
+ for (const build of headerBuilds) {
6594
+ await runCompiler(
6595
+ swift,
6596
+ [...buildArgs, '--target', build],
6597
+ appOptions,
6598
+ SWIFTPM_PROGRESS,
6599
+ SWIFTPM_NOISE,
6600
+ )
6601
+ for (const producer of build === preparation.headerProductTarget
6602
+ ? preparation.headerProducers
6603
+ : [build]) {
6604
+ const emitted = path.join(
6605
+ root,
6606
+ '.build',
6607
+ 'peach-cxx-headers',
6608
+ `${producer}-Swift.h`,
6519
6609
  )
6520
- for (const producer of build === preparation.headerProductTarget
6521
- ? preparation.headerProducers
6522
- : [build]) {
6523
- const emitted = path.join(
6524
- root,
6525
- '.build',
6526
- 'peach-cxx-headers',
6527
- `${producer}-Swift.h`,
6610
+ const original = preparation.nativeHeaderDeclarations[producer]
6611
+ ? emitted.replace(/-Swift\.h$/, '-Swift.original.h')
6612
+ : emitted
6613
+ if (existsSync(original))
6614
+ writeBuildFile(
6615
+ emitted,
6616
+ withoutSwiftDeclarations(
6617
+ clangInterfaceHeader(readFileSync(original, 'utf8')),
6618
+ new Set(preparation.nativeHeaderDeclarations[producer]),
6619
+ `#import <${producer}/${producer}.h>`,
6620
+ ),
6528
6621
  )
6529
- const original = preparation.nativeHeaderDeclarations[producer]
6530
- ? emitted.replace(/-Swift\.h$/, '-Swift.original.h')
6531
- : emitted
6532
- if (existsSync(original))
6533
- writeBuildFile(
6534
- emitted,
6535
- withoutSwiftDeclarations(
6536
- clangInterfaceHeader(readFileSync(original, 'utf8')),
6537
- new Set(preparation.nativeHeaderDeclarations[producer]),
6538
- `#import <${producer}/${producer}.h>`,
6539
- ),
6540
- )
6541
- }
6542
6622
  }
6623
+ }
6624
+ // an interrupted swiftpm build rolls back completed object records.
6625
+ // finish source targets separately so a later interruption retains them.
6626
+ // the final graph checks every output, so the manifest alone keys them.
6627
+ const checkpoints = path.join(
6628
+ root,
6629
+ '.build',
6630
+ 'peach-native-targets',
6631
+ createHash('sha256')
6632
+ .update(readFileSync(path.join(root, 'Package.swift')))
6633
+ .digest('hex'),
6634
+ )
6635
+ mkdirSync(checkpoints, { recursive: true })
6636
+ for (const target of new Set([
6637
+ ...(input.staticClangTargets ?? []),
6638
+ ...preparation.nativeBuildTargets,
6639
+ ])) {
6640
+ const checkpoint = path.join(
6641
+ checkpoints,
6642
+ createHash('sha256').update(target).digest('hex'),
6643
+ )
6644
+ if (existsSync(checkpoint)) continue
6543
6645
  await runCompiler(
6544
6646
  swift,
6545
- buildArgs,
6647
+ [...buildArgs, '--target', target],
6546
6648
  appOptions,
6547
6649
  SWIFTPM_PROGRESS,
6548
6650
  SWIFTPM_NOISE,
6549
6651
  )
6550
- } catch (error) {
6551
- const output = outputOf(error)
6552
- const moduleCache = path.join(
6553
- root,
6554
- '.build',
6555
- WASM_TRIPLE,
6556
- 'release',
6557
- 'ModuleCache',
6558
- )
6559
- if (
6560
- output.includes('was compiled with module cache path') &&
6561
- existsSync(moduleCache)
6562
- ) {
6563
- rmSync(moduleCache, { recursive: true, force: true })
6564
- try {
6565
- await runCompiler(
6566
- swift,
6567
- buildArgs,
6568
- appOptions,
6569
- SWIFTPM_PROGRESS,
6570
- SWIFTPM_NOISE,
6571
- )
6572
- } catch (retryError) {
6573
- throw new Error(
6574
- [
6575
- ...unprepared,
6576
- projectDiagnostic(outputOf(retryError), layout, input.files),
6577
- ].join('\n'),
6578
- { cause: retryError },
6579
- )
6580
- }
6581
- } else {
6652
+ writeFileSync(checkpoint, '')
6653
+ }
6654
+ // always let swiftpm check the full graph, including missing outputs.
6655
+ await runCompiler(
6656
+ swift,
6657
+ buildArgs,
6658
+ appOptions,
6659
+ SWIFTPM_PROGRESS,
6660
+ SWIFTPM_NOISE,
6661
+ )
6662
+ } catch (error) {
6663
+ const output = outputOf(error)
6664
+ const moduleCache = path.join(
6665
+ root,
6666
+ '.build',
6667
+ WASM_TRIPLE,
6668
+ 'release',
6669
+ 'ModuleCache',
6670
+ )
6671
+ if (
6672
+ output.includes('was compiled with module cache path') &&
6673
+ existsSync(moduleCache)
6674
+ ) {
6675
+ rmSync(moduleCache, { recursive: true, force: true })
6676
+ try {
6677
+ await runCompiler(
6678
+ swift,
6679
+ buildArgs,
6680
+ appOptions,
6681
+ SWIFTPM_PROGRESS,
6682
+ SWIFTPM_NOISE,
6683
+ )
6684
+ } catch (retryError) {
6582
6685
  throw new Error(
6583
- [...unprepared, projectDiagnostic(output, layout, input.files)].join(
6584
- '\n',
6585
- ),
6586
- { cause: error },
6686
+ [
6687
+ ...unprepared,
6688
+ projectDiagnostic(outputOf(retryError), layout, input.files),
6689
+ ].join('\n'),
6690
+ { cause: retryError },
6587
6691
  )
6588
6692
  }
6589
- } finally {
6590
- // a manifest, macro or build tool can leave processes behind that
6591
- // outlive the compiler's own group; none runs once the host reads.
6592
- if (options.project) endSwiftProjectProcesses(options.project)
6593
- }
6594
- if (unprepared.length) throw new Error(unprepared.join('\n'))
6595
- if (!existsSync(linked)) {
6596
- const binDir = path.dirname(linked)
6597
- const found = existsSync(binDir)
6598
- ? readdirSync(binDir)
6599
- .filter((name) => name.endsWith('.wasm'))
6600
- .sort()
6601
- : []
6693
+ } else {
6602
6694
  throw new Error(
6603
- `swift-compile: the build produced no ${path.basename(linked)} (found: ${found.join(', ') || 'none'})`,
6604
- )
6605
- }
6606
- if (options.project) removeProjectLinks(root)
6607
- const output = options.project
6608
- ? projectOutputFile(root, linked, options.project)
6609
- : linked
6610
- const optimized = `${output}.optimized`
6611
- if (input.lazyDistribution) {
6612
- pruneSwiftWasmLink(
6613
- root,
6614
- options.toolchainBin,
6615
- frameworkRoot,
6616
- input.staticClangTargets,
6695
+ [...unprepared, projectDiagnostic(output, layout, input.files)].join(
6696
+ '\n',
6697
+ ),
6698
+ { cause: error },
6617
6699
  )
6618
- await optimizeWasm(output, optimized)
6619
- }
6620
- const artifact = {
6621
- hash,
6622
- bytes: readFileSync(input.lazyDistribution ? optimized : output),
6623
- icu: await icu,
6624
6700
  }
6625
- if (!options.project) saveCompiledArtifact(root, artifact)
6626
- saveSharedArtifact(sharedRoot, artifact)
6627
- report('compiled artifact verified')
6628
- return retain(root, artifact)
6629
- },
6630
- options.signal,
6631
- )
6701
+ } finally {
6702
+ // a manifest, macro or build tool can leave processes behind that
6703
+ // outlive the compiler's own group; none runs once the host reads.
6704
+ if (options.project) endSwiftProjectProcesses(options.project)
6705
+ }
6706
+ if (unprepared.length) throw new Error(unprepared.join('\n'))
6707
+ if (!existsSync(linked)) {
6708
+ const binDir = path.dirname(linked)
6709
+ const found = existsSync(binDir)
6710
+ ? readdirSync(binDir)
6711
+ .filter((name) => name.endsWith('.wasm'))
6712
+ .sort()
6713
+ : []
6714
+ throw new Error(
6715
+ `swift-compile: the build produced no ${path.basename(linked)} (found: ${found.join(', ') || 'none'})`,
6716
+ )
6717
+ }
6718
+ if (options.project) removeProjectLinks(root)
6719
+ const output = options.project
6720
+ ? projectOutputFile(root, linked, options.project)
6721
+ : linked
6722
+ const optimized = `${output}.optimized`
6723
+ if (input.lazyDistribution) {
6724
+ pruneSwiftWasmLink(
6725
+ root,
6726
+ options.toolchainBin,
6727
+ frameworkRoot,
6728
+ input.staticClangTargets,
6729
+ )
6730
+ await optimizeWasm(output, optimized)
6731
+ }
6732
+ const artifact = {
6733
+ hash,
6734
+ bytes: readFileSync(input.lazyDistribution ? optimized : output),
6735
+ icu: await icu,
6736
+ }
6737
+ if (!options.project) saveCompiledArtifact(root, artifact)
6738
+ saveSharedArtifact(sharedRoot, artifact)
6739
+ report('compiled artifact verified')
6740
+ return retain(root, artifact)
6741
+ })
6632
6742
  },
6633
6743
  options.signal,
6634
6744
  )