peachsim 0.1.1817 → 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 (140) 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 +5 -0
  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/dist-lib/agent-daemon-client.cjs +1 -1
  14. package/dist-lib/agent-events.cjs +1 -1
  15. package/dist-lib/attached-projects.cjs +1 -1
  16. package/dist-lib/auth/shared-session.cjs +1 -1
  17. package/dist-lib/backend-origin.cjs +1 -1
  18. package/dist-lib/beta.cjs +1 -1
  19. package/dist-lib/beta.mjs +1 -1
  20. package/dist-lib/bridge-constants.cjs +1 -1
  21. package/dist-lib/bridge-contract-input.cjs +1 -1
  22. package/dist-lib/bridge-contract-input.mjs +1 -1
  23. package/dist-lib/bridge-contract.cjs +1 -1
  24. package/dist-lib/bridge-contract.mjs +1 -1
  25. package/dist-lib/bundle-channel.cjs +2823 -3829
  26. package/dist-lib/capture-contract.cjs +1 -1
  27. package/dist-lib/capture-contract.mjs +1 -1
  28. package/dist-lib/cloud-contract.cjs +1 -1
  29. package/dist-lib/cloud-contract.mjs +1 -1
  30. package/dist-lib/cloud-test-args.cjs +1 -1
  31. package/dist-lib/cloud-test-args.mjs +1 -1
  32. package/dist-lib/cloud.cjs +1 -1
  33. package/dist-lib/cloud.mjs +1 -1
  34. package/dist-lib/config.cjs +1 -1
  35. package/dist-lib/config.mjs +1 -1
  36. package/dist-lib/detox/index.cjs +2 -2
  37. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  38. package/dist-lib/expo-swift-bundle.cjs +1703 -1579
  39. package/dist-lib/expo-swift-metadata.cjs +1 -1
  40. package/dist-lib/expo-swift-metadata.mjs +1 -1
  41. package/dist-lib/home-paths.cjs +1 -1
  42. package/dist-lib/host/bridge-host.cjs +2781 -3793
  43. package/dist-lib/host/fetch-proxy-handler.cjs +2 -2
  44. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  45. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  46. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  47. package/dist-lib/host/websocket-proxy.cjs +1 -1
  48. package/dist-lib/index.cjs +29 -8
  49. package/dist-lib/jump-to-source-babel.cjs +1 -1
  50. package/dist-lib/jump-to-source-native.cjs +1 -1
  51. package/dist-lib/kotlin-host.cjs +1 -1
  52. package/dist-lib/menu.cjs +1 -1
  53. package/dist-lib/menu.mjs +1 -1
  54. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  55. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  56. package/dist-lib/metro-production-bundle.cjs +1 -1
  57. package/dist-lib/metro-production-bundle.mjs +1 -1
  58. package/dist-lib/metro.cjs +28 -7
  59. package/dist-lib/native-app-identity-project.cjs +31 -6
  60. package/dist-lib/native-app-identity-project.mjs +295 -259
  61. package/dist-lib/native-app-identity.cjs +1 -1
  62. package/dist-lib/native-app-identity.mjs +1 -1
  63. package/dist-lib/native-firebase-metadata.cjs +1 -1
  64. package/dist-lib/native-firebase-metadata.mjs +1 -1
  65. package/dist-lib/pdfium-raster.cjs +1 -1
  66. package/dist-lib/pdfium-raster.mjs +1 -1
  67. package/dist-lib/plist.cjs +1 -1
  68. package/dist-lib/plist.mjs +1 -1
  69. package/dist-lib/profiles.cjs +1 -1
  70. package/dist-lib/public-brand.cjs +1 -1
  71. package/dist-lib/public-origins-lib-esm.json +29 -24
  72. package/dist-lib/public-origins-lib.json +100 -80
  73. package/dist-lib/react-native-host-modules.cjs +1 -1
  74. package/dist-lib/react-native-host-modules.mjs +1 -1
  75. package/dist-lib/reap-browser.cjs +1 -1
  76. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  77. package/dist-lib/sdk.cjs +2 -2
  78. package/dist-lib/sdk.mjs +2 -2
  79. package/dist-lib/skills.cjs +3166 -4142
  80. package/dist-lib/swift-compile.cjs +118 -29
  81. package/dist-lib/swift-compile.mjs +125 -34
  82. package/dist-lib/swift-package.cjs +1 -1
  83. package/dist-lib/swift-package.mjs +1 -1
  84. package/dist-lib/swift-submit.cjs +1 -1
  85. package/dist-lib/swift-submit.mjs +1 -1
  86. package/dist-lib/swift-toolchain.cjs +52 -6
  87. package/dist-lib/swift.cjs +1 -1
  88. package/dist-lib/vite-swift.cjs +2188 -2060
  89. package/dist-lib/vite.cjs +2 -2
  90. package/dist-lib/worklet-executable.cjs +1 -1
  91. package/dist-lib/worklet-executable.mjs +1 -1
  92. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +5 -0
  93. package/dist-types/packages/peach-engine/src/render-worker/map-command-channel.d.ts +41 -0
  94. package/dist-types/packages/peach-engine/src/render-worker/mapServicesContract.d.ts +45 -0
  95. package/package.json +2 -1
  96. package/runtime-companion.json +1 -1
  97. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.apinotes +1 -1
  98. package/sdk/ios/usr/include/module.modulemap +3 -0
  99. package/sdk/ios/usr/include/notify.modulemap +9 -0
  100. package/sdk/ios/usr/lib/swift/Darwin.swiftmodule/arm64-apple-ios-simulator.swiftinterface +4 -0
  101. package/sdk/ios/usr/lib/swift/Dispatch.swiftmodule/arm64-apple-ios-simulator.swiftinterface +1 -1
  102. package/sdk/ios/usr/lib/swift/Foundation.swiftmodule/arm64-apple-ios-simulator.swiftinterface +7 -1
  103. package/sdk/ios/usr/lib/swift/ObjectiveC.swiftmodule/arm64-apple-ios-simulator.swiftinterface +1 -0
  104. package/sdk/ios/usr/lib/swift/SwiftUI.swiftmodule/arm64-apple-ios-simulator.swiftinterface +21 -0
  105. package/sdk/ios/usr/lib/swift/SwiftUICore.swiftmodule/arm64-apple-ios-simulator.swiftinterface +6 -1
  106. package/sdk/ios/wasm/include/__header_time.h +4 -0
  107. package/sdk/ios/wasm/include/pthread.h +2 -0
  108. package/sdk/ios/wasm/include/sys/mman.h +1 -1
  109. package/sdk/ios/wasm/include/sys/resource.h +31 -0
  110. package/sdk/ios/wasm/include/unistd.h +4 -0
  111. package/src/answeredNativePackages.ts +11 -9
  112. package/src/expo-discovery-cache.ts +69 -52
  113. package/src/expo-swift-host.ts +45 -7
  114. package/src/installed-native-libraries.ts +103 -20
  115. package/src/native-static-libraries.ts +69 -33
  116. package/src/nitro-adapter.ts +0 -9
  117. package/src/nitro-compile.ts +45 -16
  118. package/src/nitro-superset.ts +4 -5
  119. package/src/plist-bytes.ts +9 -0
  120. package/src/portable-expo-workspace.ts +4 -3
  121. package/src/react-native-bridge-modules.ts +11 -15
  122. package/src/swift-compile.ts +124 -18
  123. package/src/swift-cxx-reachable.ts +13 -0
  124. package/src/swift-distribution.ts +3 -4
  125. package/src/swift-host.ts +5 -3
  126. package/src/swift-installed-targets.ts +32 -14
  127. package/src/swift-native-pin.ts +45 -0
  128. package/src/swift-objc-compile.ts +23 -1
  129. package/src/swift-objc-standin.ts +4 -1
  130. package/src/swift-package-manifest.ts +2 -2
  131. package/src/swift-root-lock.ts +4 -3
  132. package/src/swift-standins.ts +5 -26
  133. package/src/swift-toolchain.ts +69 -12
  134. package/src/swift-wasm-prune.ts +1 -0
  135. package/src/swift-xcframework.ts +23 -12
  136. package/src/swiftContract.ts +2 -0
  137. package/src/swiftNativePinContract.ts +68 -0
  138. package/src/turbo-bundle.ts +14 -6
  139. package/src/turbo-compile.ts +76 -11
  140. package/src/turbo-source.ts +91 -15
@@ -18,7 +18,6 @@ import {
18
18
  nativeEntryKey,
19
19
  nativeEntryPrefix,
20
20
  } from './native-prebuilt'
21
- import { committedAdapterLocks } from './nitro-adapter'
22
21
  import { nitroCompilerSourceDigest } from './nitro-compiler-digest'
23
22
  import supersetLockJson from './nitro-superset.lock.json' with { type: 'json' }
24
23
  import {
@@ -26,8 +25,7 @@ import {
26
25
  type NitroBuildConfiguration,
27
26
  type NitroCompiledModule,
28
27
  } from './nitroContract'
29
- import { parseSwiftDistributionLock } from './swift-distribution-contract'
30
- import swiftLockJson from './swift-distribution.lock.json' with { type: 'json' }
28
+ import { swiftNativePin } from './swift-native-pin'
31
29
  import { STANDIN_SOURCE_DIGEST } from './swift-standin-digest'
32
30
 
33
31
  export const NITRO_SUPERSET_ENTRY_NAME = 'superset'
@@ -66,12 +64,13 @@ export function nitroSupersetInputs(options: {
66
64
  providers: readonly { name: string; root: string }[]
67
65
  }): Record<string, string> {
68
66
  const resolve = createRequire(join(options.appRoot, 'package.json')).resolve
67
+ const pin = swiftNativePin()
69
68
  const inputs: Record<string, string> = {
70
69
  configuration: options.configuration,
71
70
  'ios-deployment-target': options.iosDeploymentTarget,
72
71
  'react-native': packageVersion(dirname(resolve('react-native/package.json'))),
73
- 'swift-distribution': parseSwiftDistributionLock(swiftLockJson).id,
74
- 'nitro-runtime': JSON.stringify(committedAdapterLocks.nitro),
72
+ 'swift-distribution': pin.distribution.id,
73
+ 'nitro-runtime': JSON.stringify(pin.adapters.nitro),
75
74
  }
76
75
  const nitroModules = dirname(resolve('react-native-nitro-modules/package.json'))
77
76
  for (const { name, root } of [
@@ -0,0 +1,9 @@
1
+ import binaryPlist from 'bplist-parser'
2
+ import { parsePlistSource } from './plist'
3
+
4
+ export function parsePlistBytes(source: Uint8Array): unknown {
5
+ const bytes = Buffer.from(source)
6
+ return bytes.subarray(0, 8).toString('ascii') === 'bplist00'
7
+ ? binaryPlist.parseBuffer<unknown>(bytes)[0]
8
+ : parsePlistSource(bytes.toString('utf8'))
9
+ }
@@ -6,7 +6,7 @@ import { readExpoConfigAsync } from './native-firebase-config'
6
6
  import { portableInterfaceHash, readPortableExpoManifest } from './portable-expo-contract'
7
7
  import { preparedNativeInventory } from './prepared-native-inventory'
8
8
  import { registerPreparedXcodePhases } from './prepared-xcode-phases'
9
- import lock from './swift-distribution.lock.json' with { type: 'json' }
9
+ import { swiftNativePin } from './swift-native-pin'
10
10
 
11
11
  function stable(value: unknown, app: string): string {
12
12
  if (typeof value === 'string') return JSON.stringify(value.split(app).join('$APP'))
@@ -61,9 +61,10 @@ export async function portableExpoWorkspace(
61
61
  )
62
62
  continue
63
63
  }
64
- if (value.swiftDistribution !== lock.id) {
64
+ const { id } = swiftNativePin().distribution
65
+ if (value.swiftDistribution !== id) {
65
66
  mismatches.push(
66
- `${name}: Swift distribution ${lock.id} differs from ${value.swiftDistribution}`,
67
+ `${name}: Swift distribution ${id} differs from ${value.swiftDistribution}`,
67
68
  )
68
69
  continue
69
70
  }
@@ -476,15 +476,17 @@ export function collectBridgeModuleSources(
476
476
  if (bridgingHeader && target.objc && app) {
477
477
  nativeInputs ??= xcodeObjCInputs(app, [], null, undefined, projectRoot)
478
478
  const native = target.objc
479
+ // an installed package a monorepo hoists above the project keeps its
480
+ // absolute path under one reserved prefix.
479
481
  const key = (file: string) => {
480
482
  const relative = path.relative(projectRoot, file)
481
- if (
483
+ const outside =
482
484
  relative === '..' ||
483
485
  relative.startsWith(`..${path.sep}`) ||
484
486
  path.isAbsolute(relative)
485
- )
486
- throw new Error(`Xcode native input outside ${projectRoot}: ${file}`)
487
- return path.posix.join('__peach_xcode', relative.split(path.sep).join('/'))
487
+ return outside
488
+ ? path.posix.join('__peach_xcode/__outside', file.split(path.sep).join('/'))
489
+ : path.posix.join('__peach_xcode', relative.split(path.sep).join('/'))
488
490
  }
489
491
  const headerFiles = [...nativeInputs.sources].filter(([file]) =>
490
492
  /\.(?:h|hh|hpp|hxx|pch|inc|inl|modulemap)$/.test(file),
@@ -493,17 +495,11 @@ export function collectBridgeModuleSources(
493
495
  headerFiles.map(([file, bytes]) => [key(file), bytes.toString('utf8')]),
494
496
  )
495
497
  const directories = (files: string[]) =>
496
- files.flatMap((file) => {
497
- const relative = path.relative(projectRoot, file)
498
- if (
499
- relative !== '..' &&
500
- !relative.startsWith(`..${path.sep}`) &&
501
- !path.isAbsolute(relative)
502
- )
503
- return [key(file)]
504
- if (!fs.existsSync(file)) return []
505
- throw new Error(`Xcode native search path outside ${projectRoot}: ${file}`)
506
- })
498
+ files.flatMap((file) =>
499
+ key(file).startsWith('__peach_xcode/__outside/') && !fs.existsSync(file)
500
+ ? []
501
+ : [key(file)],
502
+ )
507
503
  const nativePath = (file: string) => {
508
504
  const absolute = path.resolve(app.rootDir, file)
509
505
  return absolute === '/usr/include' || absolute.startsWith('/usr/include/')
@@ -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> {
@@ -6427,6 +6489,7 @@ export function compileSwiftProjectUnit(
6427
6489
  )
6428
6490
  )
6429
6491
  report('framework revision changed; rebuilding the app link')
6492
+ const nativeToolset = needsNativeToolset(input, prebuilt)
6430
6493
  const preparation = writeSwiftProject(layout, input, frameworkRoot, prebuilt)
6431
6494
  writeSwiftAutolinkLinker(root, options.toolchainBin)
6432
6495
  const projectProcess = options.project
@@ -6470,7 +6533,7 @@ export function compileSwiftProjectUnit(
6470
6533
  ...swiftCompileSdkOptions(frameworkRoot, options.toolchainBin),
6471
6534
  '--swift-sdk',
6472
6535
  sdk,
6473
- ...(input.packageFiles || prebuilt
6536
+ ...(nativeToolset
6474
6537
  ? ['--toolset', path.join(root, '.peach-target-toolset.json')]
6475
6538
  : []),
6476
6539
  '-c',
@@ -6484,7 +6547,19 @@ export function compileSwiftProjectUnit(
6484
6547
  [frameworkRoot, 'framework'],
6485
6548
  [root, 'build'],
6486
6549
  ...forwarders,
6487
- ]),
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
+ }),
6488
6563
  ...macroPlugins.libraries.flatMap((plugin) => [
6489
6564
  '-Xswiftc',
6490
6565
  '-load-plugin-library',
@@ -6546,6 +6621,37 @@ export function compileSwiftProjectUnit(
6546
6621
  )
6547
6622
  }
6548
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
6645
+ await runCompiler(
6646
+ swift,
6647
+ [...buildArgs, '--target', target],
6648
+ appOptions,
6649
+ SWIFTPM_PROGRESS,
6650
+ SWIFTPM_NOISE,
6651
+ )
6652
+ writeFileSync(checkpoint, '')
6653
+ }
6654
+ // always let swiftpm check the full graph, including missing outputs.
6549
6655
  await runCompiler(
6550
6656
  swift,
6551
6657
  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