peachsim 0.1.1817 → 0.1.1821

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 (144) 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 +14 -4
  5. package/cli/commands/inspect/wait-selector.ts +9 -1
  6. package/cli/commands/maestro-compare.ts +7 -0
  7. package/cli/commands/package.ts +5 -0
  8. package/cli/commands/screenshot-mode.ts +2 -1
  9. package/cli/commands/shell-boolean-mode.ts +7 -3
  10. package/cli/commands/shell-url.ts +4 -0
  11. package/cli/commands/show-touches-mode.ts +2 -1
  12. package/cli/commands/test.ts +3 -2
  13. package/cli/commands/three-mode.ts +2 -1
  14. package/cli/outbound-endpoints.ts +5 -0
  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 +2842 -3830
  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 +2 -2
  39. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  40. package/dist-lib/expo-swift-bundle.cjs +1722 -1580
  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 +2800 -3794
  45. package/dist-lib/host/fetch-proxy-handler.cjs +2 -2
  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 +32 -11
  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 +28 -7
  61. package/dist-lib/native-app-identity-project.cjs +31 -6
  62. package/dist-lib/native-app-identity-project.mjs +295 -259
  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 +100 -80
  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 +8 -6
  80. package/dist-lib/sdk.mjs +8 -6
  81. package/dist-lib/skills.cjs +3192 -4150
  82. package/dist-lib/swift-compile.cjs +136 -29
  83. package/dist-lib/swift-compile.mjs +143 -34
  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 +2206 -2060
  91. package/dist-lib/vite.cjs +2 -2
  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/ios/photoLibraryContract.d.ts +1 -1
  95. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +5 -0
  96. package/dist-types/packages/peach-engine/src/render-worker/map-command-channel.d.ts +41 -0
  97. package/dist-types/packages/peach-engine/src/render-worker/mapServicesContract.d.ts +45 -0
  98. package/package.json +2 -1
  99. package/runtime-companion.json +1 -1
  100. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.apinotes +1 -1
  101. package/sdk/ios/usr/include/module.modulemap +3 -0
  102. package/sdk/ios/usr/include/notify.modulemap +9 -0
  103. package/sdk/ios/usr/lib/swift/Darwin.swiftmodule/arm64-apple-ios-simulator.swiftinterface +4 -0
  104. package/sdk/ios/usr/lib/swift/Dispatch.swiftmodule/arm64-apple-ios-simulator.swiftinterface +1 -1
  105. package/sdk/ios/usr/lib/swift/Foundation.swiftmodule/arm64-apple-ios-simulator.swiftinterface +7 -1
  106. package/sdk/ios/usr/lib/swift/ObjectiveC.swiftmodule/arm64-apple-ios-simulator.swiftinterface +1 -0
  107. package/sdk/ios/usr/lib/swift/SwiftUI.swiftmodule/arm64-apple-ios-simulator.swiftinterface +21 -0
  108. package/sdk/ios/usr/lib/swift/SwiftUICore.swiftmodule/arm64-apple-ios-simulator.swiftinterface +6 -1
  109. package/sdk/ios/wasm/include/__header_time.h +4 -0
  110. package/sdk/ios/wasm/include/pthread.h +2 -0
  111. package/sdk/ios/wasm/include/sys/mman.h +1 -1
  112. package/sdk/ios/wasm/include/sys/resource.h +31 -0
  113. package/sdk/ios/wasm/include/unistd.h +4 -0
  114. package/src/answeredNativePackages.ts +11 -9
  115. package/src/expo-discovery-cache.ts +69 -52
  116. package/src/expo-native-workspace.ts +3 -1
  117. package/src/expo-swift-host.ts +45 -7
  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-compile.ts +45 -16
  122. package/src/nitro-superset.ts +4 -5
  123. package/src/plist-bytes.ts +9 -0
  124. package/src/portable-expo-workspace.ts +4 -3
  125. package/src/react-native-bridge-modules.ts +11 -15
  126. package/src/swift-compile.ts +146 -18
  127. package/src/swift-cxx-reachable.ts +13 -0
  128. package/src/swift-distribution.ts +3 -4
  129. package/src/swift-host.ts +5 -3
  130. package/src/swift-installed-targets.ts +32 -14
  131. package/src/swift-native-pin.ts +45 -0
  132. package/src/swift-objc-compile.ts +23 -1
  133. package/src/swift-objc-standin.ts +4 -1
  134. package/src/swift-package-manifest.ts +2 -2
  135. package/src/swift-root-lock.ts +4 -3
  136. package/src/swift-standins.ts +5 -26
  137. package/src/swift-toolchain.ts +69 -12
  138. package/src/swift-wasm-prune.ts +1 -0
  139. package/src/swift-xcframework.ts +23 -12
  140. package/src/swiftContract.ts +2 -0
  141. package/src/swiftNativePinContract.ts +68 -0
  142. package/src/turbo-bundle.ts +14 -6
  143. package/src/turbo-compile.ts +76 -11
  144. package/src/turbo-source.ts +91 -15
@@ -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
  : []
@@ -4559,6 +4598,28 @@ export function writeSwiftProject(
4559
4598
  stageTargetFile(target.name, path.join(layout.root, modulemap), moduleContents, {
4560
4599
  allowExisting: true,
4561
4600
  })
4601
+ // clang resolves a framework map loaded through extern module against
4602
+ // the map directory, not the framework root, so mirror the umbrella there
4603
+ if (modulemap.endsWith('/Modules/module.modulemap')) {
4604
+ const headers = path.posix.join(
4605
+ path.posix.dirname(path.posix.dirname(modulemap)),
4606
+ 'Headers',
4607
+ )
4608
+ const mirrored = path.posix.join(path.posix.dirname(modulemap), 'Headers')
4609
+ for (const [, umbrella] of moduleContents
4610
+ .toString()
4611
+ .matchAll(/\bumbrella\s+header\s+"([^"]+)"/g)) {
4612
+ const source = settings.productHeaders[path.posix.join(headers, umbrella!)]
4613
+ const contents = source === undefined ? undefined : input.files[source]
4614
+ if (contents !== undefined)
4615
+ stageTargetFile(
4616
+ target.name,
4617
+ path.join(layout.root, mirrored, umbrella!),
4618
+ contents,
4619
+ { allowExisting: true },
4620
+ )
4621
+ }
4622
+ }
4562
4623
  if (nativeC && path.posix.basename(modulemap) !== 'module.modulemap') {
4563
4624
  stageTargetFile(
4564
4625
  target.name,
@@ -4630,7 +4691,8 @@ export function writeSwiftProject(
4630
4691
  .slice(0, 12)
4631
4692
  const name = `${target.name}${nativeC ? 'Native' : 'Swift'}Implementation_${identity}`
4632
4693
  const groupPath = path.posix.join('PeachNativeSources', name)
4633
- const sourceIdentity = `-ffile-prefix-map=${path.join(layout.root, groupPath)}=${path.join(layout.root, target.path)}`
4694
+ const identityRoot = nativeToolset ? '/peach/build' : layout.root
4695
+ const sourceIdentity = `-ffile-prefix-map=${path.join(identityRoot, groupPath)}=${path.join(identityRoot, target.path)}`
4634
4696
  const group = groups.get(identity) ?? {
4635
4697
  name,
4636
4698
  path: groupPath,
@@ -5282,6 +5344,7 @@ export function writeSwiftProject(
5282
5344
  path.join(layout.root, 'Package.swift'),
5283
5345
  emitSwiftPackageManifest({
5284
5346
  root: layout.root,
5347
+ files,
5285
5348
  targets: manifestTargets,
5286
5349
  packages,
5287
5350
  native,
@@ -5348,7 +5411,7 @@ export function writeSwiftProject(
5348
5411
  if (files.has(destination)) continue
5349
5412
  files.set(destination, Buffer.from(bytes, 'base64'))
5350
5413
  }
5351
- if (input.packageFiles || prebuilt) {
5414
+ if (nativeToolset) {
5352
5415
  files.set(
5353
5416
  path.join(layout.root, '.peach-target-toolset.json'),
5354
5417
  JSON.stringify({
@@ -5452,6 +5515,10 @@ export function writeSwiftProject(
5452
5515
  for (const dependency of dependencies.get(producer) ?? []) include(dependency)
5453
5516
  // building a producer also emits its dependency producers' headers.
5454
5517
  return {
5518
+ nativeBuildTargets: [...native].flatMap(([name, plan]) => [
5519
+ ...(!plan.mixed && plan.sources.length > 0 ? [name] : []),
5520
+ ...(plan.groups?.map((group) => group.name) ?? (plan.late ? [plan.late.name] : [])),
5521
+ ]),
5455
5522
  headerProducers: [
5456
5523
  ...new Set([
5457
5524
  ...Object.keys(nativeHeaderDeclarations),
@@ -5477,7 +5544,7 @@ function outputOf(error: unknown): string {
5477
5544
  streamText(Reflect.get(error, 'stderr')),
5478
5545
  ].filter(Boolean)
5479
5546
  // 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)
5547
+ if (error instanceof Error) streams.unshift(error.message)
5481
5548
  if (streams.length > 0) return streams.join('\n')
5482
5549
  }
5483
5550
  return error instanceof Error ? error.message : String(error)
@@ -6207,7 +6274,24 @@ function retireStaleSwiftLink(root: string, stamp: string): boolean {
6207
6274
  }
6208
6275
 
6209
6276
  /** the project compiler shared by route hosts, Vite and source probes. */
6210
- export function compileSwiftProjectUnit(
6277
+ export async function compileSwiftProjectUnit(
6278
+ input: SwiftCompileInput,
6279
+ options: SwiftCompileOptions,
6280
+ ): Promise<SwiftCompileArtifact> {
6281
+ // the shared checkout keeps landing while a builder hop waits in the heavy
6282
+ // window queue, so its sources can move past the hash this caller pinned.
6283
+ // rehashing and requesting again builds the sources that now exist.
6284
+ for (let attempt = 1; ; attempt++) {
6285
+ try {
6286
+ return await compileSwiftProjectOnce(input, options)
6287
+ } catch (error) {
6288
+ if (attempt >= 3 || !outputOf(error).includes('differs from the caller'))
6289
+ throw error
6290
+ }
6291
+ }
6292
+ }
6293
+
6294
+ function compileSwiftProjectOnce(
6211
6295
  input: SwiftCompileInput,
6212
6296
  options: SwiftCompileOptions,
6213
6297
  ): Promise<SwiftCompileArtifact> {
@@ -6427,6 +6511,7 @@ export function compileSwiftProjectUnit(
6427
6511
  )
6428
6512
  )
6429
6513
  report('framework revision changed; rebuilding the app link')
6514
+ const nativeToolset = needsNativeToolset(input, prebuilt)
6430
6515
  const preparation = writeSwiftProject(layout, input, frameworkRoot, prebuilt)
6431
6516
  writeSwiftAutolinkLinker(root, options.toolchainBin)
6432
6517
  const projectProcess = options.project
@@ -6470,7 +6555,7 @@ export function compileSwiftProjectUnit(
6470
6555
  ...swiftCompileSdkOptions(frameworkRoot, options.toolchainBin),
6471
6556
  '--swift-sdk',
6472
6557
  sdk,
6473
- ...(input.packageFiles || prebuilt
6558
+ ...(nativeToolset
6474
6559
  ? ['--toolset', path.join(root, '.peach-target-toolset.json')]
6475
6560
  : []),
6476
6561
  '-c',
@@ -6484,7 +6569,19 @@ export function compileSwiftProjectUnit(
6484
6569
  [frameworkRoot, 'framework'],
6485
6570
  [root, 'build'],
6486
6571
  ...forwarders,
6487
- ]),
6572
+ ]).flatMap((flag, index, flags) => {
6573
+ if (!nativeToolset || !flag.startsWith('-ffile-prefix-map='))
6574
+ return [flag]
6575
+ const mapped = flag
6576
+ .replaceAll(root, '/peach/build')
6577
+ .replaceAll(frameworkRoot, '/peach/framework')
6578
+ .replaceAll(path.dirname(options.toolchainBin), '/peach/toolchain')
6579
+ // native depscan already maps paths; Swift's importer still
6580
+ // reads the physical filesystem and needs the original map.
6581
+ return flags[index - 1] === '-Xcc'
6582
+ ? [mapped, '-Xswiftc', '-Xcc', '-Xswiftc', flag]
6583
+ : [mapped]
6584
+ }),
6488
6585
  ...macroPlugins.libraries.flatMap((plugin) => [
6489
6586
  '-Xswiftc',
6490
6587
  '-load-plugin-library',
@@ -6546,6 +6643,37 @@ export function compileSwiftProjectUnit(
6546
6643
  )
6547
6644
  }
6548
6645
  }
6646
+ // an interrupted swiftpm build rolls back completed object records.
6647
+ // finish source targets separately so a later interruption retains them.
6648
+ // the final graph checks every output, so the manifest alone keys them.
6649
+ const checkpoints = path.join(
6650
+ root,
6651
+ '.build',
6652
+ 'peach-native-targets',
6653
+ createHash('sha256')
6654
+ .update(readFileSync(path.join(root, 'Package.swift')))
6655
+ .digest('hex'),
6656
+ )
6657
+ mkdirSync(checkpoints, { recursive: true })
6658
+ for (const target of new Set([
6659
+ ...(input.staticClangTargets ?? []),
6660
+ ...preparation.nativeBuildTargets,
6661
+ ])) {
6662
+ const checkpoint = path.join(
6663
+ checkpoints,
6664
+ createHash('sha256').update(target).digest('hex'),
6665
+ )
6666
+ if (existsSync(checkpoint)) continue
6667
+ await runCompiler(
6668
+ swift,
6669
+ [...buildArgs, '--target', target],
6670
+ appOptions,
6671
+ SWIFTPM_PROGRESS,
6672
+ SWIFTPM_NOISE,
6673
+ )
6674
+ writeFileSync(checkpoint, '')
6675
+ }
6676
+ // always let swiftpm check the full graph, including missing outputs.
6549
6677
  await runCompiler(
6550
6678
  swift,
6551
6679
  buildArgs,
@@ -54,6 +54,19 @@ export async function xcodeCxxReachable(
54
54
  )
55
55
  )
56
56
  return [...binaries]
57
+ // only a binary whose headers sit in one directory has C++ headers to find.
58
+ // preparing the original units compiles dependency Swift against the raw
59
+ // binaries before their stand-ins exist, so skip it when nothing needs it.
60
+ const staged = remoteSwiftCheckouts(app.rootDir)
61
+ if (
62
+ !binaries.some(
63
+ (binary) =>
64
+ binary.publicHeaders === undefined &&
65
+ binary.placeholder === undefined &&
66
+ binaryHeaderSearchPaths(binary, staged).headers.length === 1,
67
+ )
68
+ )
69
+ return [...binaries]
57
70
  const hash = createHash('sha256')
58
71
  hash.update(
59
72
  JSON.stringify([
@@ -13,12 +13,11 @@ import { ensureLinuxBrowserLibraries } from '../cli/drivers/linux-browser-libs'
13
13
  import { rnxHomeDir } from './home-paths'
14
14
  import { swiftDistributionAt, swiftModuleSdk } from './swift-compile'
15
15
  import {
16
- parseSwiftDistributionLock,
17
16
  SWIFT_DISTRIBUTION_MANIFEST,
18
17
  swiftDistributionHost,
19
18
  swiftDistributionKey,
20
19
  } from './swift-distribution-contract'
21
- import lockJson from './swift-distribution.lock.json' with { type: 'json' }
20
+ import { swiftNativePin } from './swift-native-pin'
22
21
  import {
23
22
  confineSwiftScratch,
24
23
  ensureSwiftLinuxRuntime,
@@ -71,7 +70,7 @@ const installs = new Map<
71
70
  * that runs swift before any module compile. */
72
71
  export async function ensureSwiftToolchain(signal?: AbortSignal): Promise<void> {
73
72
  if (privateSwiftDistributionRoot()) return
74
- const lock = parseSwiftDistributionLock(lockJson)
73
+ const lock = swiftNativePin().distribution
75
74
  await installSwiftToolchain(lock.release, lock, signal, true)
76
75
  }
77
76
 
@@ -120,7 +119,7 @@ export async function swiftDistributionRoot(signal?: AbortSignal): Promise<strin
120
119
  return privateRoot
121
120
  }
122
121
  const endpoint = swiftEndpoint()
123
- const lock = parseSwiftDistributionLock(lockJson)
122
+ const lock = swiftNativePin().distribution
124
123
  // the archive is useless without its compiler, so the toolchain installs
125
124
  // or fails before the download
126
125
  await installSwiftToolchain(lock.release, lock, signal)
package/src/swift-host.ts CHANGED
@@ -150,7 +150,9 @@ import type { ServerResponse } from 'node:http'
150
150
  const ARTIFACT_PATH = '/__peach/swift/'
151
151
  const RESOURCE_PATH = '/__peach/swift-res/'
152
152
  const ICU_PATH = '/__peach/swift-icu/'
153
- const SKIP_SOURCE_DIRS = new Set(['node_modules', 'dist', 'types', 'build'])
153
+ // a javascript project around the package keeps its outputs at the root; a
154
+ // target compiles every visible file below it, a build or types directory too.
155
+ const SKIP_ROOT_DIRS = new Set(['dist', 'types', 'build', 'ios', 'android'])
154
156
  const NATIVE_DESCRIPTOR = '.one-native-source.json'
155
157
  const NATIVE_GLUE = '.one-native-source.swift.txt'
156
158
 
@@ -1442,10 +1444,10 @@ function sourceTreeFiles(dir: string, canonicalRoot: string): string[] {
1442
1444
  (entry.name.startsWith('.') &&
1443
1445
  entry.name !== NATIVE_DESCRIPTOR &&
1444
1446
  entry.name !== NATIVE_GLUE) ||
1445
- SKIP_SOURCE_DIRS.has(entry.name) ||
1447
+ entry.name === 'node_modules' ||
1446
1448
  // platform project wrappers are excluded only at the package root;
1447
1449
  // native target sources can contain upstream ios/android directories.
1448
- (dir === canonicalRoot && (entry.name === 'ios' || entry.name === 'android'))
1450
+ (dir === canonicalRoot && SKIP_ROOT_DIRS.has(entry.name))
1449
1451
  )
1450
1452
  continue
1451
1453
  const full = path.join(dir, entry.name)
@@ -57,6 +57,9 @@ export function applyInstalledSwiftTargets(
57
57
  source.file,
58
58
  ]),
59
59
  )
60
+ const originalSources = new Map(
61
+ collection.sources.map((source) => [source.file, source.source]),
62
+ )
60
63
  const viewComponents = new Set(
61
64
  [...(collection.viewComponentSources ?? [])].map((file) =>
62
65
  projectSourceKey(sourceRoots, file),
@@ -139,14 +142,32 @@ export function applyInstalledSwiftTargets(
139
142
  })
140
143
  // a header the installed search paths already supply, and its module covers,
141
144
  // must not also reach the target as a second textual copy
145
+ const prefix = `${generated.path}/include/`
146
+ const supplied = new Map<string, Set<string>>()
147
+ for (const [key, content] of Object.entries(snapshot.input.files)) {
148
+ if (!native.headerSearchPaths.includes(path.posix.dirname(key))) continue
149
+ const name = path.posix.basename(key)
150
+ supplied.set(name, (supplied.get(name) ?? new Set()).add(content))
151
+ }
152
+ // a module map resolves its headers beside itself, so the ones it names stay
153
+ const moduleHeaders = new Set(
154
+ [
155
+ ...(collection.files[`${prefix}module.modulemap`] ?? '').matchAll(
156
+ /\bheader\s+"([^"]+)"/g,
157
+ ),
158
+ ].map((match) => path.posix.join(prefix, match[1]!)),
159
+ )
142
160
  for (const file of Object.keys(collection.files)) {
143
- const prefix = `${generated.path}/include/`
144
- if (!file.startsWith(prefix)) continue
145
- const include = file.slice(prefix.length)
146
- if (
147
- native.headerSearchPaths.some(
148
- (directory) => snapshot.input.files[`${directory}/${include}`] !== undefined,
161
+ if (!file.startsWith(prefix) || moduleHeaders.has(file)) continue
162
+ const target = /^#\s*include "([^"]+)"/m.exec(collection.files[file]!)?.[1]
163
+ const source =
164
+ target &&
165
+ originalSources.get(
166
+ path.posix.normalize(path.posix.join(path.posix.dirname(file), target)),
149
167
  )
168
+ if (
169
+ source &&
170
+ supplied.get(path.posix.basename(file))?.has(fs.readFileSync(source, 'utf8'))
150
171
  )
151
172
  delete collection.files[file]
152
173
  }
@@ -171,18 +192,15 @@ export function applyInstalledSwiftTargets(
171
192
  const original = snapshot.sourcePaths[file]
172
193
  if (original && viewComponents.has(projectSourceKey(sourceRoots, original)))
173
194
  continue
195
+ const previous =
196
+ original && originalKeys.get(projectSourceKey(sourceRoots, original))
197
+ if (!previous) continue
174
198
  const output = `${target.path}/native/${file}`
175
199
  collection.files[output] = snapshot.input.files[file]!
176
200
  sourceDirectories[output] = directory
177
201
  fileFlags[output] = native.fileFlags[file] ?? []
178
- const previous =
179
- original && originalKeys.get(projectSourceKey(sourceRoots, original))
180
- if (previous) {
181
- delete collection.files[previous]
182
- collection.sources = collection.sources.filter(
183
- (source) => source.file !== previous,
184
- )
185
- }
202
+ delete collection.files[previous]
203
+ collection.sources = collection.sources.filter((source) => source.file !== previous)
186
204
  }
187
205
  collection.nativeTargets ??= []
188
206
  collection.nativeTargets.push({
@@ -0,0 +1,45 @@
1
+ // the Swift distribution, compiler and adapter archives this process compiles
2
+ // with. an installed CLI reads them from the runtime it serves
3
+ // (swiftNativePinContract.ts); source scripts, the build container and
4
+ // Contrast's server read this checkout's locks.
5
+ import { readPeachRuntimeJson } from './answeredNativePackages'
6
+ import nitroLockJson from './nitro-adapter.lock.json' with { type: 'json' }
7
+ import { parseAdapterLock } from './nitroAdapterContract'
8
+ import { parseSwiftDistributionLock } from './swift-distribution-contract'
9
+ import lockJson from './swift-distribution.lock.json' with { type: 'json' }
10
+ import { registerSwiftHostCompiler, swiftHostCompilerPin } from './swift-toolchain'
11
+ import {
12
+ parseSwiftNativePin,
13
+ SWIFT_NATIVE_PIN_PATH,
14
+ SWIFT_NATIVE_PIN_SCHEMA,
15
+ type SwiftNativePin,
16
+ } from './swiftNativePinContract'
17
+ import turboLockJson from './turbo-runtime.lock.json' with { type: 'json' }
18
+
19
+ declare const __PEACH_RUNTIME_SWIFT_PIN__: boolean | undefined
20
+
21
+ export function repoSwiftNativePin(): SwiftNativePin {
22
+ const distribution = parseSwiftDistributionLock(lockJson)
23
+ return {
24
+ schema: SWIFT_NATIVE_PIN_SCHEMA,
25
+ distribution,
26
+ compiler: swiftHostCompilerPin(distribution.release),
27
+ adapters: {
28
+ nitro: parseAdapterLock('nitro', nitroLockJson),
29
+ turbo: parseAdapterLock('turbo', turboLockJson),
30
+ },
31
+ }
32
+ }
33
+
34
+ let pin: SwiftNativePin | undefined
35
+
36
+ export function swiftNativePin(): SwiftNativePin {
37
+ if (pin) return pin
38
+ if (typeof __PEACH_RUNTIME_SWIFT_PIN__ === 'boolean') {
39
+ pin = parseSwiftNativePin(readPeachRuntimeJson(SWIFT_NATIVE_PIN_PATH))
40
+ registerSwiftHostCompiler(pin.distribution.release, pin.compiler)
41
+ } else {
42
+ pin = repoSwiftNativePin()
43
+ }
44
+ return pin
45
+ }
@@ -228,6 +228,26 @@ export async function xcodeObjCInputsAsync(
228
228
  }
229
229
  }
230
230
 
231
+ // installed packages a project resolves: its own node_modules, its ancestors'
232
+ // (a monorepo hoists them), and the targets of workspace-linked entries.
233
+ function installedPackageDirs(root: string): string[] {
234
+ const dirs: string[] = []
235
+ for (let dir = root; ; dir = path.dirname(dir)) {
236
+ const modules = path.join(dir, 'node_modules')
237
+ if (fs.existsSync(modules)) {
238
+ dirs.push(fs.realpathSync.native(modules))
239
+ if (dir === root)
240
+ for (const entry of fs.readdirSync(modules, { withFileTypes: true })) {
241
+ const target = path.join(modules, entry.name)
242
+ if (entry.isSymbolicLink() && fs.existsSync(target))
243
+ dirs.push(fs.realpathSync.native(target))
244
+ }
245
+ }
246
+ if (dir === path.dirname(dir)) break
247
+ }
248
+ return dirs.filter((directory) => relativeInside(root, directory) === null)
249
+ }
250
+
231
251
  function* xcodeObjCInputSteps(
232
252
  app: XcodeAppTarget,
233
253
  binaries: readonly SwiftPackageBinary[],
@@ -252,6 +272,8 @@ function* xcodeObjCInputSteps(
252
272
  .map((directory) => fs.realpathSync.native(directory)),
253
273
  ),
254
274
  ].filter((directory) => relativeInside(sourceRoot, directory) === null)
275
+ // installed packages (hoisted or workspace-linked) own the headers pods link to.
276
+ const installedDirs = installedPackageDirs(sourceRoot)
255
277
  const generated = new Map(
256
278
  products?.files.map(({ path: declared, file }) => [declared, file]),
257
279
  )
@@ -278,7 +300,7 @@ function* xcodeObjCInputSteps(
278
300
  const resolved = header ? fs.realpathSync.native(file) : file
279
301
  if (resolved !== file) links[file] = resolved
280
302
  // the project's installed framework directory is its own read boundary.
281
- const external = externalFrameworkDirs.find(
303
+ const external = [...externalFrameworkDirs, ...installedDirs].find(
282
304
  (directory) => relativeInside(directory, resolved) !== null,
283
305
  )
284
306
  const bytes = readPackageFile(
@@ -309,6 +309,9 @@ export function objcSdkIntakeFlags(
309
309
  path.join(headers, 'System/Library/Frameworks'),
310
310
  '-isystem',
311
311
  path.join(headers, 'wasm/include'),
312
+ // compiler intrinsics an arm64 unit includes, ahead of clang's arm-only ones.
313
+ '-isystem',
314
+ path.join(headers, 'wasm/intrinsics'),
312
315
  // libxml2 headers sit one level deeper, as in the iOS sdk: a unit
313
316
  // includes <libxml/parser.h> through usr/include/libxml2, never the parent.
314
317
  '-I',
@@ -742,7 +745,7 @@ export function objcView(
742
745
  }
743
746
  // clang's module import, or a swift interface's
744
747
  const module = /^module '(\w+)' not found$/.exec(message!)
745
- const swiftModule = /^no such module '(\w+)[\w.]*'$/.exec(message!)
748
+ const swiftModule = /^no such module '(\w+)'$/.exec(message!)
746
749
  if (module || swiftModule) {
747
750
  if (stubModule((module ?? swiftModule)![1]!, !module)) progress = true
748
751
  continue
@@ -18,7 +18,7 @@ import path from 'node:path'
18
18
  import { promisify } from 'node:util'
19
19
  import { cacheDir as peachCacheDir } from './home-paths'
20
20
  import { ensureSwiftToolchain, swiftModuleCompiler } from './swift-distribution'
21
- import lock from './swift-distribution.lock.json' with { type: 'json' }
21
+ import { swiftNativePin } from './swift-native-pin'
22
22
  import {
23
23
  isSwiftNativeTranslationUnit,
24
24
  swiftPackageIdentity,
@@ -169,7 +169,7 @@ function swiftCommand(): string {
169
169
  const privateRoot = privateSwiftDistributionRoot()
170
170
  if (privateRoot)
171
171
  return path.join(swiftModuleCompiler(privateRoot).toolchainBin, 'swift')
172
- return path.join(swiftToolchainBin(lock.release), 'swift')
172
+ return path.join(swiftToolchainBin(swiftNativePin().distribution.release), 'swift')
173
173
  }
174
174
 
175
175
  function swiftPackageFailure(error: unknown): string {
@@ -257,12 +257,13 @@ export async function withSwiftRootLock<T>(
257
257
  const children: ChildProcess[] = []
258
258
  const lease: SwiftRootLease = {
259
259
  register(child) {
260
- children.push(child)
260
+ const index = children.push(child)
261
261
  if (child.pid === undefined) throw new Error('could not register compiler process')
262
- const childPending = `${pending}.child.${child.pid}`
262
+ // a long hold outlives the pid space, so a pid can name two children.
263
+ const childPending = `${pending}.child.${index}`
263
264
  try {
264
265
  writeFileSync(childPending, JSON.stringify(ownIdentity(child.pid)))
265
- linkSync(childPending, path.join(directory, name(held, `child.${child.pid}`)))
266
+ linkSync(childPending, path.join(directory, name(held, `child.${index}`)))
266
267
  } finally {
267
268
  rmSync(childPending, { force: true })
268
269
  }
@@ -66,7 +66,7 @@ import {
66
66
  swiftEnvironment,
67
67
  swiftPackageCacheOptions,
68
68
  } from './swift-toolchain'
69
- import { simulatorStaticArchive } from './swift-xcframework'
69
+ import { simulatorNativeLibrary } from './swift-xcframework'
70
70
  import type { SwiftPackageBinary } from './swift-packages'
71
71
 
72
72
  const TRIPLE = 'wasm32-unknown-wasip1'
@@ -669,27 +669,6 @@ function surfaces(
669
669
  const module = moduleMapName(fs.readFileSync(modulemap, 'utf8'))
670
670
  if (module) found.push(headerSurface(module, modulemap, path.dirname(modulemap)))
671
671
  }
672
- // a library slice shipped for header search paths has no modulemap (Xcode
673
- // copies its headers into the build products and a bridging header or
674
- // objective-c unit includes them). its top-level headers form the module
675
- // xcode's swift would see through them, named for the framework.
676
- const roots =
677
- found.length === 0 && !plain ? files(headers, (name) => name.endsWith('.h')) : []
678
- if (roots.length > 0) {
679
- const module = swiftTargetModuleName(path.basename(xcframeworkDir, '.xcframework'))
680
- const text = `module ${module} {\n${roots.map((file) => ` header "${file}"`).join('\n')}\n export *\n}\n`
681
- const modulemap = path.join(
682
- cacheDir,
683
- 'modulemaps',
684
- key(headers, text),
685
- 'module.modulemap',
686
- )
687
- if (!fs.existsSync(modulemap)) {
688
- fs.mkdirSync(path.dirname(modulemap), { recursive: true })
689
- fs.writeFileSync(modulemap, text)
690
- }
691
- found.push(headerSurface(module, modulemap, headers))
692
- }
693
672
  return found
694
673
  }
695
674
 
@@ -2032,8 +2011,8 @@ export function standinLibrary(
2032
2011
  ): string | null {
2033
2012
  if (binary.publicHeaders !== undefined) return null
2034
2013
  const dir = xcframework(binary).dir
2035
- const native = simulatorStaticArchive(dir)
2036
- const library = native?.name
2014
+ const native = simulatorNativeLibrary(dir)
2015
+ const library = native?.kind === 'archive' ? native.name : null
2037
2016
  const supplied = path.join(dir, RUST_TARGET)
2038
2017
  if (fs.existsSync(supplied)) {
2039
2018
  const found = fs.readdirSync(supplied).filter((name) => name.endsWith('.a'))
@@ -2045,11 +2024,11 @@ export function standinLibrary(
2045
2024
  )
2046
2025
  return path.join(supplied, chosen)
2047
2026
  }
2048
- if (!library) return null
2049
2027
  if (native && toolchain && fs.existsSync(native.file)) {
2050
2028
  const recipe = nativeStaticLibraryRecipe(fs.readFileSync(native.file))
2051
2029
  if (recipe) return nativeStaticLibrary(native.file, recipe, toolchain.moduleRoot)
2052
2030
  }
2031
+ if (!library) return null
2053
2032
  for (const [name, recipe] of Object.entries(NATIVE_SLICE_RECIPES)) {
2054
2033
  if (name !== path.basename(dir, '.xcframework') || !toolchain) continue
2055
2034
  const pin = path.join(path.dirname(dir), recipe.pinFile)
@@ -2808,7 +2787,7 @@ export async function swiftStandins(
2808
2787
  siblings.get(binary)!,
2809
2788
  )
2810
2789
  console.error(
2811
- `[swift-standins] ${binary.target} ${typeof result === 'string' ? 'gap' : 'ready'} in ${Date.now() - started}ms`,
2790
+ `[swift-standins] ${binary.target} ${typeof result === 'string' ? `gap: ${result}` : 'ready'} in ${Date.now() - started}ms`,
2812
2791
  )
2813
2792
  if (typeof result === 'string') {
2814
2793
  gaps.set(binary.target, result)