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
@@ -5,13 +5,16 @@
5
5
  //
6
6
  // node builtins only: packages/sootsim-swift/scripts/build.sh imports this
7
7
  // file straight from a checkout, with no install.
8
- import { execFile, execFileSync } from 'node:child_process'
8
+ import { execFile, execFileSync, spawn } from 'node:child_process'
9
9
  import { createHash } from 'node:crypto'
10
10
  import fs from 'node:fs'
11
11
  import os from 'node:os'
12
12
  import path from 'node:path'
13
+ import { Readable } from 'node:stream'
14
+ import { pipeline } from 'node:stream/promises'
13
15
  import { fileURLToPath } from 'node:url'
14
16
  import { promisify } from 'node:util'
17
+ import zlib from 'node:zlib'
15
18
 
16
19
  /** the peachsim package directory. source runs sit in packages/peachsim/src,
17
20
  * the bundled cli in dist-cli/chunks and library entries at varying depths
@@ -52,13 +55,19 @@ export function swiftSdkOptions(): string[] {
52
55
  // host archives include the official driver/runtime and the qualified patched frontend.
53
56
  export const SWIFT_HOST_COMPILER_RELEASE = 'swift-6.4.0-RELEASE-custom-81b2c791c27276bf'
54
57
  export const SWIFT_HOST_COMPILER_ID = '81b2c791c27276bf'
55
- // retain qualification for the published distribution while source builds advance.
56
- const compilerArchives: Record<
57
- string,
58
- { identity: string; hosts: Record<string, { checksum: string; manifest: string }> }
59
- > = {
58
+ export interface SwiftHostCompilerPin {
59
+ identity: string
60
+ archive: 'tar.gz' | 'tar.zst'
61
+ hosts: Record<string, { checksum: string; manifest: string }>
62
+ }
63
+
64
+ // retain qualification for the published distribution while source builds
65
+ // advance. an installed CLI adds the compiler its runtime pins
66
+ // (registerSwiftHostCompiler).
67
+ const compilerArchives: Record<string, SwiftHostCompilerPin> = {
60
68
  'swift-6.4.0-RELEASE-custom-0b2d0a9011c88e66': {
61
69
  identity: '0b2d0a9011c88e66',
70
+ archive: 'tar.gz',
62
71
  hosts: {
63
72
  'darwin-arm64': {
64
73
  checksum: 'dc6a494227297ea657e8e5f7c5b4a861cb5e142bdbcfcb028ace2aeb19db90cc',
@@ -76,6 +85,7 @@ const compilerArchives: Record<
76
85
  },
77
86
  'swift-6.4.0-RELEASE-custom-f7c03c3f59ec5d83': {
78
87
  identity: 'f7c03c3f59ec5d83',
88
+ archive: 'tar.gz',
79
89
  hosts: {
80
90
  'darwin-arm64': {
81
91
  checksum: '8946a2d4716d3b0784cef7a85a35f66537bd319c4c5a48c63457d607260df5c5',
@@ -93,6 +103,7 @@ const compilerArchives: Record<
93
103
  },
94
104
  'swift-6.4.0-RELEASE-custom-3e3dca8fd1d82975': {
95
105
  identity: '3e3dca8fd1d82975',
106
+ archive: 'tar.gz',
96
107
  hosts: {
97
108
  'darwin-arm64': {
98
109
  checksum: 'dfad56454f5e1e465071ff708bf485be65b438cf55d02b04d26d17d26df9f54a',
@@ -110,6 +121,7 @@ const compilerArchives: Record<
110
121
  },
111
122
  'swift-6.4.0-RELEASE-custom-b082ac5437336790': {
112
123
  identity: 'b082ac5437336790',
124
+ archive: 'tar.gz',
113
125
  hosts: {
114
126
  'darwin-arm64': {
115
127
  checksum: '85e601982321d3a6f81f05928bc9bbe7a61bc75b27ce24508e79f6b5b537254d',
@@ -127,6 +139,7 @@ const compilerArchives: Record<
127
139
  },
128
140
  'swift-6.4.0-RELEASE-custom-9cdaffdb6b37fb47': {
129
141
  identity: '9cdaffdb6b37fb47',
142
+ archive: 'tar.gz',
130
143
  hosts: {
131
144
  'darwin-arm64': {
132
145
  checksum: 'fdd3f88cf76a8dc2083275d4253255030068a25b5ba68acbf59e0407c45677dd',
@@ -144,6 +157,7 @@ const compilerArchives: Record<
144
157
  },
145
158
  'swift-6.4.0-RELEASE-custom-bd49e2f77434e7b1': {
146
159
  identity: 'bd49e2f77434e7b1',
160
+ archive: 'tar.gz',
147
161
  hosts: {
148
162
  'darwin-arm64': {
149
163
  checksum: 'e815b06394566e8125475afc8f1807f7f465318c845549c5831043cdc28eca64',
@@ -161,6 +175,7 @@ const compilerArchives: Record<
161
175
  },
162
176
  'swift-6.4.0-RELEASE-custom-13450179a7e01c81': {
163
177
  identity: '13450179a7e01c81',
178
+ archive: 'tar.gz',
164
179
  hosts: {
165
180
  'darwin-arm64': {
166
181
  checksum: 'a29be6b722f15c7aafac26ba5703a7392f49ce7ea5e1c56548846b7e458290f7',
@@ -178,6 +193,7 @@ const compilerArchives: Record<
178
193
  },
179
194
  'swift-6.4.0-RELEASE-custom-f6868fa6054e83d6': {
180
195
  identity: 'f6868fa6054e83d6',
196
+ archive: 'tar.gz',
181
197
  hosts: {
182
198
  'darwin-arm64': {
183
199
  checksum: 'bd80c2f35864ec29883dd22001d0165821e80d78002fc12f92406c3c708694a4',
@@ -195,23 +211,25 @@ const compilerArchives: Record<
195
211
  },
196
212
  'swift-6.4.0-RELEASE-custom-a560ff35bf882b5c': {
197
213
  identity: 'a560ff35bf882b5c',
214
+ archive: 'tar.zst',
198
215
  hosts: {
199
216
  'darwin-arm64': {
200
- checksum: 'ec20a41851ac558fe663d78def6b93d0d47c5a0cb69688ee270fd85de637a522',
217
+ checksum: '36c50bcdfba88a4c0989af0bd60371497eb4403aa7b80644b479fa509a2187a9',
201
218
  manifest: '253e891527d2213f54eace768b902de89de5e9495a3c5f4018de1985516bd553',
202
219
  },
203
220
  'linux-x64': {
204
- checksum: 'f0126a2e63d275895036d02d75a901070da0343dbf03bf17342e10cb6f893dee',
221
+ checksum: 'ba25da9182314fc7b7dd2fc041280e1c7b409f80a1fbccdfa5c342669d164c8e',
205
222
  manifest: '6f951cc4071dd0d6054d85711a7c5fe272273658847831b477a8b24be7254ca0',
206
223
  },
207
224
  'linux-arm64': {
208
- checksum: '315fa766559a6e69bfd10dcddf40e04c91155f0db3047d210d74ac87652fb7e6',
225
+ checksum: '5f0f4456e9fe22b5486025db9f679c865841660797d71761245291c2c6811c20',
209
226
  manifest: 'b6f62fca2ec37593e274ee5bac474f21ffc5db14cd82f492ccbc774f8e9b75d8',
210
227
  },
211
228
  },
212
229
  },
213
230
  [SWIFT_HOST_COMPILER_RELEASE]: {
214
231
  identity: SWIFT_HOST_COMPILER_ID,
232
+ archive: 'tar.gz',
215
233
  hosts: {
216
234
  'darwin-arm64': {
217
235
  checksum: 'bc51b83d9e2e01c9873875326544734486d3ff3a868d650379c304045e8838d3',
@@ -362,21 +380,60 @@ export function ensureSwiftLinuxRuntime(release: string): void {
362
380
  linuxHostSdkRoot = root
363
381
  }
364
382
 
383
+ export function swiftHostCompilerPin(release: string): SwiftHostCompilerPin {
384
+ const compiler = compilerArchives[release]
385
+ if (!compiler) throw new Error(`unqualified host compiler ${release}`)
386
+ return compiler
387
+ }
388
+
389
+ export function registerSwiftHostCompiler(release: string, pin: SwiftHostCompilerPin) {
390
+ compilerArchives[release] = pin
391
+ }
392
+
365
393
  export function swiftHostCompilerArchive(
366
394
  release: string,
367
395
  host = `${process.platform}-${process.arch}`,
368
396
  ) {
369
- const compiler = compilerArchives[release]
370
- if (!compiler) throw new Error(`unqualified host compiler ${release}`)
397
+ const compiler = swiftHostCompilerPin(release)
371
398
  const archive = compiler.hosts[host]
372
399
  if (!archive) throw new Error(`unsupported Swift compiler host ${host}`)
373
400
  return {
374
401
  ...archive,
375
402
  identity: compiler.identity,
376
- url: `https://r2.sootsim.com/swift-host-compiler/${compiler.identity}/${release}-${host}.tar.gz`,
403
+ archive: compiler.archive,
404
+ url: `https://r2.sootsim.com/swift-host-compiler/${compiler.identity}/${archive.checksum}.${compiler.archive}`,
377
405
  }
378
406
  }
379
407
 
408
+ // the tar inside a downloaded host compiler archive. zstd archives use a 1 GiB
409
+ // long-distance window (pack-host-compiler.ts).
410
+ export function swiftHostCompilerTar(archive: string, url: string): Readable {
411
+ const file = fs.createReadStream(archive)
412
+ const decoder = url.endsWith('.tar.zst')
413
+ ? zlib.createZstdDecompress({ params: { [zlib.constants.ZSTD_d_windowLogMax]: 30 } })
414
+ : zlib.createGunzip()
415
+ file.on('error', (error) => decoder.destroy(error))
416
+ return file.pipe(decoder)
417
+ }
418
+
419
+ /** unpack a host compiler archive into an existing directory, dropping its top folder. */
420
+ export async function extractSwiftHostCompiler(
421
+ archive: string,
422
+ url: string,
423
+ destination: string,
424
+ ): Promise<void> {
425
+ const tar = spawn('tar', ['-xf', '-', '--strip-components=1', '-C', destination], {
426
+ stdio: ['pipe', 'inherit', 'inherit'],
427
+ })
428
+ const exited = new Promise<number | null>((resolve, reject) => {
429
+ tar.on('error', reject)
430
+ tar.on('close', resolve)
431
+ })
432
+ await pipeline(swiftHostCompilerTar(archive, url), tar.stdin)
433
+ const code = await exited
434
+ if (code !== 0) throw new Error(`tar exited with ${code} unpacking ${archive}`)
435
+ }
436
+
380
437
  // source archives and bootstrap images retain the official release name.
381
438
  export function swiftUpstreamRelease(release: string): string {
382
439
  return release.replace(/-custom-[a-f0-9]{16}$/, '')
@@ -1821,6 +1821,7 @@ export function pruneSwiftWasmLink(
1821
1821
  fs.writeFileSync(prunedRspPath, outTokens.map((t) => JSON.stringify(t)).join(' '))
1822
1822
  execFileSync(path.join(toolchainBin, 'wasm-ld'), [`@${prunedRspPath}`], {
1823
1823
  stdio: 'pipe',
1824
+ maxBuffer: Infinity,
1824
1825
  })
1825
1826
  fs.rmSync(rspPath, { force: true })
1826
1827
  }
@@ -1,17 +1,17 @@
1
- // the original static archive declared for an iOS simulator slice.
1
+ // the original library declared for an iOS simulator slice.
2
2
  import fs from 'node:fs'
3
3
  import path from 'node:path'
4
4
  import { isRecord } from './is-record'
5
- import { parsePlistSource } from './plist'
5
+ import { parsePlistBytes } from './plist-bytes'
6
6
 
7
- export function simulatorStaticArchive(
7
+ export function simulatorNativeLibrary(
8
8
  dir: string,
9
- ): { name: string; file: string } | null {
9
+ ): { name: string; file: string; kind: 'archive' | 'framework' } | null {
10
10
  if (!dir.endsWith('.xcframework')) return null
11
- const info = parsePlistSource(fs.readFileSync(path.join(dir, 'Info.plist'), 'utf8'))
11
+ const info = parsePlistBytes(fs.readFileSync(path.join(dir, 'Info.plist')))
12
12
  if (!isRecord(info) || !Array.isArray(info.AvailableLibraries))
13
13
  throw new Error(`${dir}: invalid XCFramework library declarations`)
14
- const matches: { name: string; file: string }[] = []
14
+ const matches: { name: string; file: string; kind: 'archive' | 'framework' }[] = []
15
15
  for (const entry of info.AvailableLibraries) {
16
16
  if (!isRecord(entry)) throw new Error(`${dir}: invalid XCFramework library entry`)
17
17
  if (
@@ -23,15 +23,26 @@ export function simulatorStaticArchive(
23
23
  typeof entry.LibraryPath !== 'string' ||
24
24
  typeof entry.LibraryIdentifier !== 'string'
25
25
  )
26
- throw new Error(`${dir}: invalid simulator static archive paths`)
27
- if (!/^lib.+\.a$/.test(entry.LibraryPath)) continue
28
- const file = path.resolve(dir, entry.LibraryIdentifier, entry.LibraryPath)
26
+ throw new Error(`${dir}: invalid simulator library paths`)
27
+ const archive = /^lib.+\.a$/.test(entry.LibraryPath)
28
+ const framework = /\.framework$/.test(entry.LibraryPath)
29
+ if (!archive && !framework) continue
30
+ const bundle = path.resolve(dir, entry.LibraryIdentifier, entry.LibraryPath)
31
+ const bundleRelative = path.relative(dir, bundle)
32
+ if (bundleRelative.startsWith('..') || path.isAbsolute(bundleRelative))
33
+ throw new Error(`${dir}: library escapes its XCFramework`)
34
+ let name = entry.LibraryPath
35
+ let file = bundle
36
+ if (framework) {
37
+ name = path.basename(bundle, '.framework')
38
+ file = path.join(bundle, name)
39
+ }
29
40
  const relative = path.relative(dir, file)
30
41
  if (relative.startsWith('..') || path.isAbsolute(relative))
31
- throw new Error(`${dir}: archive escapes its XCFramework`)
32
- matches.push({ name: entry.LibraryPath, file })
42
+ throw new Error(`${dir}: library escapes its XCFramework`)
43
+ matches.push({ name, file, kind: framework ? 'framework' : 'archive' })
33
44
  }
34
45
  if (matches.length === 0) return null
35
- if (matches.length !== 1) throw new Error(`${dir}: ambiguous simulator static archive`)
46
+ if (matches.length !== 1) throw new Error(`${dir}: ambiguous simulator library`)
36
47
  return matches[0]!
37
48
  }
@@ -132,6 +132,8 @@ export function isSwiftHeaderAliases(value: unknown): value is SwiftHeaderAliase
132
132
 
133
133
  export interface SwiftProjectPreparation {
134
134
  headerProducers: string[]
135
+ /** completed native targets commit their object records before the app build. */
136
+ nativeBuildTargets: string[]
135
137
  /** original binary C and Objective-C declarations retained beside a local Swift surface. */
136
138
  nativeHeaderDeclarations: Record<string, string[]>
137
139
  /** one SwiftPM build schedules independent header producers together. */
@@ -0,0 +1,68 @@
1
+ // the runtime names the Swift distribution its engine links, that
2
+ // distribution's compiler and the adapter archives built against it, so an
3
+ // installed CLI compiles app Swift against what the runtime it serves can run
4
+ // and neither release waits on the other. a pin change the CLI's compile code
5
+ // must understand bumps the schema, which the other side refuses by name.
6
+ import { isRecord } from './is-record'
7
+ import {
8
+ type AdapterFamily,
9
+ type AdapterLock,
10
+ parseAdapterLock,
11
+ } from './nitroAdapterContract'
12
+ import {
13
+ parseSwiftDistributionLock,
14
+ type SwiftDistributionLock,
15
+ } from './swift-distribution-contract'
16
+ import type { SwiftHostCompilerPin } from './swift-toolchain'
17
+
18
+ export const SWIFT_NATIVE_PIN_PATH = 'node/swift-native.json'
19
+ export const SWIFT_NATIVE_PIN_SCHEMA = 2
20
+
21
+ export interface SwiftNativePin {
22
+ schema: typeof SWIFT_NATIVE_PIN_SCHEMA
23
+ distribution: SwiftDistributionLock
24
+ compiler: SwiftHostCompilerPin
25
+ adapters: Record<AdapterFamily, AdapterLock>
26
+ }
27
+
28
+ const DIGEST = /^[a-f0-9]{64}$/
29
+
30
+ export function parseSwiftNativePin(value: unknown): SwiftNativePin {
31
+ if (!isRecord(value)) throw new Error('invalid Swift native pin')
32
+ if (value.schema !== SWIFT_NATIVE_PIN_SCHEMA)
33
+ throw new Error(
34
+ typeof value.schema === 'number' && value.schema > SWIFT_NATIVE_PIN_SCHEMA
35
+ ? 'the active Peach runtime pins Swift for a newer peach CLI; update peach'
36
+ : 'the active Peach runtime pins Swift for an older peach CLI; run `peach runtime install`',
37
+ )
38
+ const { compiler, adapters } = value
39
+ if (
40
+ !isRecord(compiler) ||
41
+ typeof compiler.identity !== 'string' ||
42
+ (compiler.archive !== 'tar.gz' && compiler.archive !== 'tar.zst') ||
43
+ !isRecord(compiler.hosts) ||
44
+ !isRecord(adapters)
45
+ )
46
+ throw new Error('invalid Swift native pin')
47
+ const hosts: SwiftHostCompilerPin['hosts'] = {}
48
+ for (const [host, archive] of Object.entries(compiler.hosts)) {
49
+ if (
50
+ !isRecord(archive) ||
51
+ typeof archive.checksum !== 'string' ||
52
+ !DIGEST.test(archive.checksum) ||
53
+ typeof archive.manifest !== 'string' ||
54
+ !DIGEST.test(archive.manifest)
55
+ )
56
+ throw new Error(`invalid Swift native pin compiler entry for ${host}`)
57
+ hosts[host] = { checksum: archive.checksum, manifest: archive.manifest }
58
+ }
59
+ return {
60
+ schema: SWIFT_NATIVE_PIN_SCHEMA,
61
+ distribution: parseSwiftDistributionLock(value.distribution),
62
+ compiler: { identity: compiler.identity, archive: compiler.archive, hosts },
63
+ adapters: {
64
+ nitro: parseAdapterLock('nitro', adapters.nitro),
65
+ turbo: parseAdapterLock('turbo', adapters.turbo),
66
+ },
67
+ }
68
+ }
@@ -18,8 +18,16 @@ export const TURBO_ROUTE = '/__peach/turbo'
18
18
 
19
19
  /** the installed C++ TurboModule providers an app compiles: every one Peach
20
20
  * does not answer itself (a seam resolves before the original module). */
21
- export async function compiledTurboProviders(appRoot: string) {
22
- return discoverTurboProviders(appRoot)
21
+ export async function compiledTurboProviders(
22
+ appRoot: string,
23
+ projectRoot?: string,
24
+ iosTarget?: string,
25
+ ) {
26
+ return discoverTurboProviders(
27
+ appRoot,
28
+ projectRoot ?? (await prepareNativeAppRoot(appRoot)),
29
+ iosTarget,
30
+ )
23
31
  }
24
32
 
25
33
  // every installed iOS pod that registers a C++ TurboModule compiles from its
@@ -32,14 +40,14 @@ export async function compileTurboApp(
32
40
  moduleRoot?: string,
33
41
  iosTarget?: string,
34
42
  ): Promise<{ metadata: TurboCompiledModule; artifact: SwiftArtifact } | null> {
35
- const providers = await compiledTurboProviders(appRoot)
43
+ // the app's own committed ios directory has no installed pods: discovery and
44
+ // the compile read the prepared workspace, as the Nitro compile does
45
+ const projectRoot = await prepareNativeAppRoot(appRoot)
46
+ const providers = await compiledTurboProviders(appRoot, projectRoot, iosTarget)
36
47
  if (providers.length === 0) return null
37
48
  // the runtime archive is built against the published distribution, as the
38
49
  // Nitro adapter is
39
50
  const module = moduleRoot ?? (await swiftDistributionRoot())
40
- // the app's own committed ios directory has no installed pods: the compile
41
- // reads the prepared workspace, as the Nitro compile does
42
- const projectRoot = await prepareNativeAppRoot(appRoot)
43
51
  const installed = installedXcodeWorkspace(projectRoot)
44
52
  ? installedNativeLibraries(providers, projectRoot, module, iosTarget)
45
53
  : null
@@ -1,13 +1,10 @@
1
1
  import { createHash } from 'node:crypto'
2
2
  import fs from 'node:fs'
3
+ import { createRequire } from 'node:module'
3
4
  import os from 'node:os'
4
5
  import path from 'node:path'
5
6
  import { readIosAppTarget } from './native-app-identity-project'
6
- import {
7
- committedAdapterLocks,
8
- resolveAdapterArchive,
9
- type AdapterArchive,
10
- } from './nitro-adapter'
7
+ import { resolveAdapterArchive, type AdapterArchive } from './nitro-adapter'
11
8
  import {
12
9
  missingSwiftModules,
13
10
  swiftAvailableModules,
@@ -24,8 +21,10 @@ import {
24
21
  type SwiftArtifact,
25
22
  } from './swift-host'
26
23
  import { applyInstalledSwiftTargets } from './swift-installed-targets'
24
+ import { swiftNativePin } from './swift-native-pin'
27
25
  import {
28
26
  clangSettingEntries,
27
+ isSwiftNativeTranslationUnit,
29
28
  manifestCalls,
30
29
  swiftManifestCxxLanguageStandard,
31
30
  swiftManifestSettings,
@@ -75,13 +74,24 @@ export function collectTurboCompileInput(
75
74
  if (file.startsWith(`${target.path}/`)) delete files[file]
76
75
  return false
77
76
  })
77
+ const headerAliases = { ...dependencies?.headerAliases, ...collection.headerAliases }
78
78
  for (const [file, source] of Object.entries(dependencies?.files ?? {})) {
79
79
  if (file === 'Package.swift') continue
80
80
  const alias = collection.headerAliases?.[file]
81
81
  if (alias && collection.files[alias] === source) continue
82
- if (Object.hasOwn(files, file) && files[file] !== source)
82
+ if (Object.hasOwn(files, file) && files[file] !== source && !headerAliases[file])
83
83
  throw new Error(`TurboModule dependency source collision: ${file}`)
84
- files[file] = source
84
+ files[file] ??= source
85
+ }
86
+ // the installed ReactCodegen pod compiles its own copy of the files the
87
+ // collector generated from the same codegen
88
+ const installedCodegen = (dependencies?.nativeTargets ?? []).flatMap((native) =>
89
+ Object.keys(native.sourceDirectories).filter((file) => /\.(?:c|m|mm)$/.test(file)),
90
+ )
91
+ for (const copy of Object.keys(files)) {
92
+ const tail = /\/upstream\/ReactCodegen\/(.+)$/.exec(copy)?.[1]
93
+ if (tail && installedCodegen.some((file) => file.endsWith(`/ReactCodegen/${tail}`)))
94
+ delete files[copy]
85
95
  }
86
96
  if (parsedTargets.length !== dependencyTargets.length)
87
97
  throw new Error(
@@ -149,9 +159,11 @@ export function collectTurboCompileInput(
149
159
  ...(dependencies?.nativeTargets ?? []).filter(
150
160
  ({ name }) => !providerNames.has(name),
151
161
  ),
152
- ...(collection.nativeTargets ?? []),
162
+ ...(collection.nativeTargets ?? []).filter(
163
+ ({ name }) => !podModules.has(name) || !externalModules.has(name),
164
+ ),
153
165
  ],
154
- headerAliases: { ...dependencies?.headerAliases, ...collection.headerAliases },
166
+ headerAliases,
155
167
  resourceBundles: [
156
168
  ...new Map(
157
169
  [
@@ -242,7 +254,39 @@ export async function compileTurboModule(options: {
242
254
  ]
243
255
  }
244
256
  // Swift dependencies retain their installed mixed-language targets;
245
- // other React Native implementations already belong to TurboCore.
257
+ // other React Native implementations already belong to TurboCore. the
258
+ // codegen pod its scripts generate under build/generated/ios keeps each
259
+ // library's spec, without the units a turbo target already compiles.
260
+ const reactNative = [options.appRoot, options.projectRoot].map(
261
+ (root) =>
262
+ path.dirname(
263
+ fs.realpathSync(
264
+ createRequire(path.join(root, 'package.json')).resolve(
265
+ 'react-native/package.json',
266
+ ),
267
+ ),
268
+ ) + path.sep,
269
+ )
270
+ const generated = `${path.sep}build${path.sep}generated${path.sep}ios${path.sep}`
271
+ const supportFiles = `${path.sep}Target Support Files${path.sep}`
272
+ const reactOwned = new Set<string>()
273
+ const codegenTargets = new Set<string>()
274
+ for (const { name, sourceDirectories } of snapshot.input.nativeTargets ?? []) {
275
+ if (names.has(name)) continue
276
+ const units = Object.keys(sourceDirectories).flatMap((file) => {
277
+ const original = snapshot.sourcePaths[file]
278
+ return original && !original.includes(supportFiles)
279
+ ? [fs.realpathSync(original)]
280
+ : []
281
+ })
282
+ if (units.length === 0) continue
283
+ if (units.every((file) => file.includes(generated))) codegenTargets.add(name)
284
+ else if (
285
+ units.every((file) => reactNative.some((root) => file.startsWith(root)))
286
+ )
287
+ reactOwned.add(name)
288
+ }
289
+ for (const name of codegenTargets) names.add(name)
246
290
  snapshot.input.nativeTargets = snapshot.input.nativeTargets?.filter(({ name }) =>
247
291
  names.has(name),
248
292
  )
@@ -257,6 +301,27 @@ export async function compileTurboModule(options: {
257
301
  { source: options.appRoot, installed: options.projectRoot },
258
302
  ['-DNDEBUG'],
259
303
  )
304
+ const turboUnits = collection.targets.flatMap(({ path: root }) => {
305
+ const codegen = `${root}/upstream/ReactCodegen/`
306
+ return Object.keys(collection.files).flatMap((file) =>
307
+ file.startsWith(codegen) && isSwiftNativeTranslationUnit(file)
308
+ ? [file.slice(codegen.length)]
309
+ : [],
310
+ )
311
+ })
312
+ for (const native of collection.nativeTargets ?? []) {
313
+ if (!codegenTargets.has(native.name)) continue
314
+ for (const file of Object.keys(native.sourceDirectories))
315
+ if (turboUnits.some((unit) => file.endsWith(`/${unit}`))) {
316
+ delete native.sourceDirectories[file]
317
+ delete native.fileFlags[file]
318
+ delete collection.files[file]
319
+ }
320
+ }
321
+ for (const target of collection.targets)
322
+ target.dependencies = target.dependencies?.filter(
323
+ ({ name }) => !reactOwned.has(name),
324
+ )
260
325
  },
261
326
  )
262
327
  }
@@ -321,7 +386,7 @@ export async function compileTurboModule(options: {
321
386
  'turbo',
322
387
  { reactNative: collection.reactNative.root },
323
388
  options.moduleRoot,
324
- committedAdapterLocks.turbo,
389
+ swiftNativePin().adapters.turbo,
325
390
  ),
326
391
  iosDeploymentTarget,
327
392
  dependencies,