peachsim 0.1.2768 → 0.1.2770

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 (132) hide show
  1. package/dist-lib/agent-daemon-client.cjs +1 -1
  2. package/dist-lib/agent-events.cjs +1 -1
  3. package/dist-lib/attached-projects.cjs +1 -1
  4. package/dist-lib/auth/shared-session.cjs +1 -1
  5. package/dist-lib/backend-origin.cjs +1 -1
  6. package/dist-lib/beta.cjs +1 -1
  7. package/dist-lib/beta.mjs +2 -2
  8. package/dist-lib/bridge-constants.cjs +1 -1
  9. package/dist-lib/bridge-contract-input.cjs +1 -1
  10. package/dist-lib/bridge-contract-input.mjs +5 -5
  11. package/dist-lib/bridge-contract.cjs +1 -1
  12. package/dist-lib/bridge-contract.mjs +3 -3
  13. package/dist-lib/bundle-channel.cjs +356 -77
  14. package/dist-lib/capture-contract.cjs +1 -1
  15. package/dist-lib/capture-contract.mjs +3 -3
  16. package/dist-lib/cloud-contract.cjs +1 -1
  17. package/dist-lib/cloud-contract.mjs +3 -3
  18. package/dist-lib/cloud-test-args.cjs +1 -1
  19. package/dist-lib/cloud-test-args.mjs +2 -2
  20. package/dist-lib/cloud.cjs +1 -1
  21. package/dist-lib/cloud.mjs +7 -7
  22. package/dist-lib/config.cjs +1 -1
  23. package/dist-lib/config.mjs +5 -5
  24. package/dist-lib/detox/index.cjs +1 -1
  25. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  26. package/dist-lib/esm-chunks/{acorn-4DR5UGFN.mjs → acorn-A3J4BCR3.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-P4QFEMNW.mjs → chunk-25CEOCB7.mjs} +1 -1
  28. package/dist-lib/esm-chunks/{chunk-TNCPRFBQ.mjs → chunk-4IOWCCHS.mjs} +1 -1
  29. package/dist-lib/esm-chunks/{chunk-LMELFNFT.mjs → chunk-4LHY3IKU.mjs} +1 -1
  30. package/dist-lib/esm-chunks/{chunk-76RJVPS6.mjs → chunk-5YKVWHMS.mjs} +4 -4
  31. package/dist-lib/esm-chunks/{chunk-SBIBHVCU.mjs → chunk-CFWWQTJ5.mjs} +26 -13
  32. package/dist-lib/esm-chunks/{chunk-OASENKSR.mjs → chunk-CQBPQSRE.mjs} +1 -1
  33. package/dist-lib/esm-chunks/{chunk-LDBKSWMK.mjs → chunk-F3FQZ6SE.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-NRFW2S2E.mjs → chunk-FBVGSJJE.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-UP76RU63.mjs → chunk-FJZINSC2.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-LW6EFCKB.mjs → chunk-JGCIXB77.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-FM4IQKZR.mjs → chunk-JN4WVMT4.mjs} +2 -2
  38. package/dist-lib/esm-chunks/{chunk-IA466TSB.mjs → chunk-KSVTJ3JI.mjs} +1 -1
  39. package/dist-lib/esm-chunks/{chunk-IXCYOMAY.mjs → chunk-NJNU5MPO.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-QS3CSXQR.mjs → chunk-PT3YJZI2.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-K6H2SOFN.mjs → chunk-Q4BHHFX7.mjs} +1 -1
  42. package/dist-lib/esm-chunks/{chunk-FY6GYFKM.mjs → chunk-RBNIOLS5.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-SZC5VUTW.mjs → chunk-RG5UROLK.mjs} +1 -1
  44. package/dist-lib/esm-chunks/{chunk-FSZC4K7L.mjs → chunk-RSRSOEDS.mjs} +5 -5
  45. package/dist-lib/esm-chunks/{chunk-CWLOVTXX.mjs → chunk-TTOBAW65.mjs} +3 -3
  46. package/dist-lib/esm-chunks/{chunk-PYVRYHRN.mjs → chunk-TXTIDFLT.mjs} +1 -1
  47. package/dist-lib/esm-chunks/{chunk-NNHQMYXA.mjs → chunk-USSIX7QH.mjs} +377 -106
  48. package/dist-lib/esm-chunks/{chunk-EP3OX3CJ.mjs → chunk-W4ZOHLQE.mjs} +6 -6
  49. package/dist-lib/esm-chunks/{chunk-MC3T7WXI.mjs → chunk-Y4DWEUO2.mjs} +1 -1
  50. package/dist-lib/esm-chunks/{chunk-6FVNWSDJ.mjs → chunk-YGXQSWWR.mjs} +1 -1
  51. package/dist-lib/esm-chunks/{metro-layout-parser-4TX56S4G.mjs → metro-layout-parser-QXJ7SU7Z.mjs} +3 -3
  52. package/dist-lib/esm-chunks/{swift-package-prebuilt-7PIYWUST.mjs → swift-package-prebuilt-3YL3XSX3.mjs} +12 -12
  53. package/dist-lib/esm-chunks/{swift-sdk-app-module-7NOBYKIE.mjs → swift-sdk-app-module-QSLP6GQS.mjs} +22 -17
  54. package/dist-lib/esm-chunks/{swift-sdk-image-FTSV6Y6Y.mjs → swift-sdk-image-XJV6ZFNG.mjs} +16 -16
  55. package/dist-lib/esm-chunks/{swift-sdk-image-producer-TDBFULDN.mjs → swift-sdk-image-producer-NFE2G4PN.mjs} +5 -5
  56. package/dist-lib/expo-swift-bundle.cjs +356 -77
  57. package/dist-lib/expo-swift-metadata.cjs +1 -1
  58. package/dist-lib/expo-swift-metadata.mjs +7 -7
  59. package/dist-lib/home-paths.cjs +1 -1
  60. package/dist-lib/host/bridge-host.cjs +356 -77
  61. package/dist-lib/host/fetch-proxy-handler.cjs +24 -20
  62. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  63. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
  64. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  65. package/dist-lib/host/websocket-proxy.cjs +1 -1
  66. package/dist-lib/index.cjs +1 -1
  67. package/dist-lib/kotlin-host.cjs +1 -1
  68. package/dist-lib/menu.cjs +1 -1
  69. package/dist-lib/menu.mjs +3 -3
  70. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  71. package/dist-lib/metro-fingerprint-registry.mjs +3 -3
  72. package/dist-lib/metro-production-bundle.cjs +1 -1
  73. package/dist-lib/metro-production-bundle.mjs +4 -4
  74. package/dist-lib/native-app-identity-project.cjs +1 -1
  75. package/dist-lib/native-app-identity-project.mjs +15 -15
  76. package/dist-lib/native-app-identity.cjs +1 -1
  77. package/dist-lib/native-app-identity.mjs +6 -6
  78. package/dist-lib/native-firebase-metadata.cjs +1 -1
  79. package/dist-lib/native-firebase-metadata.mjs +3 -3
  80. package/dist-lib/pdfium-raster.cjs +1 -1
  81. package/dist-lib/pdfium-raster.mjs +2 -2
  82. package/dist-lib/plist.cjs +1 -1
  83. package/dist-lib/plist.mjs +3 -3
  84. package/dist-lib/profiles.cjs +1 -1
  85. package/dist-lib/public-brand.cjs +1 -1
  86. package/dist-lib/public-origins-lib-esm.json +85 -85
  87. package/dist-lib/public-origins-lib.json +64 -64
  88. package/dist-lib/react-native-host-modules.cjs +1 -1
  89. package/dist-lib/react-native-host-modules.mjs +2 -2
  90. package/dist-lib/reap-browser.cjs +1 -1
  91. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  92. package/dist-lib/sdk.cjs +1 -1
  93. package/dist-lib/sdk.mjs +8 -8
  94. package/dist-lib/skills.cjs +356 -77
  95. package/dist-lib/swift-compile.cjs +336 -57
  96. package/dist-lib/swift-compile.mjs +12 -12
  97. package/dist-lib/swift-package.cjs +1 -1
  98. package/dist-lib/swift-package.mjs +3 -3
  99. package/dist-lib/swift-submit.cjs +1 -1
  100. package/dist-lib/swift-submit.mjs +6 -6
  101. package/dist-lib/swift-svg-raster.cjs +1 -1
  102. package/dist-lib/swift-svg-raster.mjs +2 -2
  103. package/dist-lib/swift-toolchain.cjs +1 -1
  104. package/dist-lib/swift.cjs +1 -1
  105. package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
  106. package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
  107. package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
  108. package/dist-lib/vendor/acorn.cjs +1 -1
  109. package/dist-lib/vendor/magic-string.cjs +1 -1
  110. package/dist-lib/vendor/stream-json.cjs +1 -1
  111. package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
  112. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
  113. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
  114. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
  115. package/dist-lib/vendor/sucrase.cjs +1 -1
  116. package/dist-lib/vendor/terser.cjs +1 -1
  117. package/dist-lib/vendor/valibot.cjs +1 -1
  118. package/dist-lib/vendor/ws.cjs +1 -1
  119. package/dist-lib/vendor/zod.cjs +1 -1
  120. package/dist-lib/worklet-executable.cjs +1 -1
  121. package/dist-lib/worklet-executable.mjs +3 -3
  122. package/dist-types/packages/peach-engine/src/render-worker/aux-pointer-native.d.ts +4 -0
  123. package/dist-types/packages/peach-engine/src/render-worker/auxPointerContract.d.ts +4 -0
  124. package/package.json +1 -1
  125. package/src/case-insensitive-header-overlay.ts +9 -1
  126. package/src/native-static-libraries.ts +16 -16
  127. package/src/swift-compile.ts +158 -42
  128. package/src/swift-distribution-mirror.ts +280 -10
  129. package/src/swift-objc-prebuilt.ts +10 -1
  130. package/src/swift-objc-standin.ts +6 -1
  131. package/src/swift-sdk-app-module.ts +10 -3
  132. package/src/swift-sdk-surface.ts +5 -1
@@ -1,25 +1,47 @@
1
1
  import { randomUUID } from 'node:crypto'
2
2
  import {
3
+ chmodSync,
3
4
  constants,
4
5
  copyFileSync,
5
6
  existsSync,
7
+ lstatSync,
6
8
  mkdirSync,
7
9
  readdirSync,
8
10
  readFileSync,
11
+ readlinkSync,
9
12
  renameSync,
10
13
  rmSync,
14
+ statSync,
15
+ symlinkSync,
11
16
  writeFileSync,
12
17
  } from 'node:fs'
13
18
  import path from 'node:path'
19
+ import { clearCaseInsensitiveHeaderOverlayCache } from './case-insensitive-header-overlay'
14
20
  import { isRecord } from './is-record'
15
21
  import {
16
22
  SWIFT_DISTRIBUTION_MANIFEST,
17
23
  type SwiftDistributionManifest,
18
24
  } from './swift-distribution-contract'
19
- import { SWIFT_DISTRIBUTION_MIRROR_RECORD } from './swift-shared-sdk'
25
+ import {
26
+ SWIFT_DISTRIBUTION_MIRROR_RECORD,
27
+ swiftSharedSdkViewOptions,
28
+ } from './swift-shared-sdk'
20
29
  import { isSwiftResourcePath } from './swiftContract'
30
+ import { SWIFT_WASM_TRIPLE } from './swiftTargetContract'
21
31
 
22
32
  export const SWIFT_DISTRIBUTION_MIRROR = '.peach-distribution'
33
+ export const SWIFT_SDK_MIRROR = '.peach-sdk'
34
+ export const SWIFT_SDK_MIRROR_ID = 'peach-wasm-sdk'
35
+
36
+ const SWIFT_SDK_MIRROR_RECORD = '.peach-sdk-mirror.json'
37
+ const SWIFT_SDK_MIRROR_SYNCING = '.peach-sdk-syncing'
38
+ const SWIFT_SDK_MIRROR_BUNDLE = 'peach-wasm.artifactbundle'
39
+
40
+ export interface SwiftMirrorSdk {
41
+ id: string
42
+ options: string[]
43
+ toolsetChanged: boolean
44
+ }
23
45
 
24
46
  /**
25
47
  * the build root's own copy of a distribution, at one path for every
@@ -61,10 +83,245 @@ export function syncSwiftDistributionMirror(
61
83
  const partial = `${record}.${randomUUID()}`
62
84
  writeFileSync(partial, JSON.stringify(manifest.files))
63
85
  renameSync(partial, record)
86
+ if (
87
+ [...changed, ...removed].some(
88
+ (file) => !file.startsWith('lib/') && !file.startsWith('modules/'),
89
+ )
90
+ ) {
91
+ clearCaseInsensitiveHeaderOverlayCache(mirror)
92
+ clearCaseInsensitiveHeaderOverlayCache(path.join(root, SWIFT_SDK_MIRROR))
93
+ }
64
94
  }
65
95
  return mirror
66
96
  }
67
97
 
98
+ /**
99
+ * the build root's own WASI SDK view at one fixed path and SDK id across
100
+ * distribution SDK bumps. files with unchanged bytes keep their inode and
101
+ * mtime, so a WASI SDK cut that updates only Darwin/Dispatch/Foundation
102
+ * swiftmodules and static archives keeps every Clang object and build.db warm.
103
+ */
104
+ export function syncSwiftSdkMirror(
105
+ root: string,
106
+ frameworkRoot: string,
107
+ toolchainBin: string,
108
+ sourceSdkId: string,
109
+ ): SwiftMirrorSdk {
110
+ const viewOptions = swiftSharedSdkViewOptions(
111
+ frameworkRoot,
112
+ true,
113
+ toolchainBin,
114
+ sourceSdkId,
115
+ )
116
+ const sourceView = viewOptions[1]!
117
+ return syncSwiftSdkMirrorFromView(root, frameworkRoot, sourceView, sourceSdkId)
118
+ }
119
+
120
+ export function syncSwiftSdkMirrorFromView(
121
+ root: string,
122
+ frameworkRoot: string,
123
+ sourceView: string,
124
+ sourceSdkId: string,
125
+ ): SwiftMirrorSdk {
126
+ const mirror = path.join(root, SWIFT_SDK_MIRROR)
127
+ const bundle = path.join(mirror, SWIFT_SDK_MIRROR_BUNDLE)
128
+ const destTriple = path.join(bundle, 'sdk', SWIFT_WASM_TRIPLE)
129
+ const bundleInfo = path.join(bundle, 'info.json')
130
+ const recordFile = path.join(mirror, SWIFT_SDK_MIRROR_RECORD)
131
+ const syncingMarker = path.join(mirror, SWIFT_SDK_MIRROR_SYNCING)
132
+ const options = ['--swift-sdks-path', mirror]
133
+ const interrupted = existsSync(syncingMarker)
134
+ const previous = interrupted ? null : readSdkRecord(recordFile)
135
+ if (
136
+ previous &&
137
+ previous.sourceView === sourceView &&
138
+ previous.sourceSdkId === sourceSdkId &&
139
+ existsSync(bundleInfo) &&
140
+ existsSync(path.join(destTriple, 'swift-sdk.json'))
141
+ ) {
142
+ return { id: SWIFT_SDK_MIRROR_ID, options, toolsetChanged: false }
143
+ }
144
+ const sourceTriple = resolveSdkViewTripleDir(sourceView, sourceSdkId)
145
+ if (!previous) {
146
+ if (!interrupted) rmSync(mirror, { recursive: true, force: true })
147
+ rmSync(path.join(root, '.build'), { recursive: true, force: true })
148
+ }
149
+ // persist an in-progress marker before mutating the mirror so a kill or I/O
150
+ // error before invalidation completes discards .build on the next retry.
151
+ mkdirSync(mirror, { recursive: true })
152
+ writeFileSync(syncingMarker, '1\n')
153
+ const changed: string[] = []
154
+ const removed: string[] = []
155
+ const distributionPrefix = `${frameworkRoot}${path.sep}`
156
+ syncSdkTree(sourceTriple, destTriple, '', distributionPrefix, changed, removed)
157
+ const infoText =
158
+ JSON.stringify(
159
+ {
160
+ artifacts: {
161
+ [SWIFT_SDK_MIRROR_ID]: {
162
+ type: 'swiftSDK',
163
+ variants: [{ path: `sdk/${SWIFT_WASM_TRIPLE}/swift-sdk.json` }],
164
+ version: '0.0.1',
165
+ },
166
+ },
167
+ schemaVersion: '1.0',
168
+ },
169
+ null,
170
+ 2,
171
+ ) + '\n'
172
+ if (!existsSync(bundleInfo) || readFileSync(bundleInfo, 'utf8') !== infoText) {
173
+ mkdirSync(bundle, { recursive: true })
174
+ const partial = `${bundleInfo}.${randomUUID()}`
175
+ writeFileSync(partial, infoText)
176
+ renameSync(partial, bundleInfo)
177
+ }
178
+ const touched = [...changed, ...removed]
179
+ const toolsetChanged =
180
+ !previous ||
181
+ touched.some(
182
+ (file) =>
183
+ file === 'toolset.json' ||
184
+ file === 'swift-sdk.json' ||
185
+ file.startsWith('swift.xctoolchain/usr/bin/'),
186
+ )
187
+ if (previous) {
188
+ if (toolsetChanged) {
189
+ rmSync(path.join(root, '.build'), { recursive: true, force: true })
190
+ } else {
191
+ const compileTouched = touched.filter(
192
+ (file) =>
193
+ !file.endsWith('.a') &&
194
+ !file.endsWith('.o') &&
195
+ !file.startsWith('rust/') &&
196
+ file !== 'runtime-products.json',
197
+ )
198
+ const headersChanged = compileTouched.some(
199
+ (file) =>
200
+ !file.endsWith('.swiftmodule') &&
201
+ !file.endsWith('.swiftdoc') &&
202
+ !file.endsWith('.swiftsourceinfo') &&
203
+ !file.endsWith('.abi.json'),
204
+ )
205
+ if (compileTouched.length > 0) {
206
+ invalidateBuildDependents(
207
+ root,
208
+ [[Buffer.from(`${escapeDepPath(destTriple)}/`), '']],
209
+ new Set(compileTouched),
210
+ headersChanged,
211
+ )
212
+ }
213
+ if (headersChanged) clearCaseInsensitiveHeaderOverlayCache(mirror)
214
+ }
215
+ } else {
216
+ clearCaseInsensitiveHeaderOverlayCache(mirror)
217
+ }
218
+ const partialRecord = `${recordFile}.${randomUUID()}`
219
+ writeFileSync(partialRecord, JSON.stringify({ version: 1, sourceView, sourceSdkId }))
220
+ renameSync(partialRecord, recordFile)
221
+ rmSync(syncingMarker, { force: true })
222
+ return { id: SWIFT_SDK_MIRROR_ID, options, toolsetChanged }
223
+ }
224
+
225
+ function readSdkRecord(
226
+ file: string,
227
+ ): { version: number; sourceView: string; sourceSdkId: string } | null {
228
+ if (!existsSync(file)) return null
229
+ const value: unknown = JSON.parse(readFileSync(file, 'utf8'))
230
+ if (
231
+ !isRecord(value) ||
232
+ value.version !== 1 ||
233
+ typeof value.sourceView !== 'string' ||
234
+ typeof value.sourceSdkId !== 'string'
235
+ )
236
+ return null
237
+ return {
238
+ version: value.version,
239
+ sourceView: value.sourceView,
240
+ sourceSdkId: value.sourceSdkId,
241
+ }
242
+ }
243
+
244
+ function resolveSdkViewTripleDir(sourceView: string, sourceSdkId: string): string {
245
+ for (const entry of readdirSync(sourceView, { withFileTypes: true })) {
246
+ if (!entry.name.endsWith('.artifactbundle')) continue
247
+ const bundleDir = path.join(sourceView, entry.name)
248
+ const infoPath = path.join(bundleDir, 'info.json')
249
+ if (!existsSync(infoPath)) continue
250
+ const info: unknown = JSON.parse(readFileSync(infoPath, 'utf8'))
251
+ if (!isRecord(info) || !isRecord(info.artifacts)) continue
252
+ const artifact = info.artifacts[sourceSdkId]
253
+ if (!isRecord(artifact) || !Array.isArray(artifact.variants)) continue
254
+ const first = artifact.variants[0]
255
+ if (!isRecord(first) || typeof first.path !== 'string') continue
256
+ return path.dirname(path.join(bundleDir, first.path))
257
+ }
258
+ throw new Error(`Swift SDK ${sourceSdkId} not found in view ${sourceView}`)
259
+ }
260
+
261
+ function collectRemovedFiles(dir: string, prefix: string, out: string[]): void {
262
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
263
+ const rel = prefix ? `${prefix}/${entry.name}` : entry.name
264
+ const full = path.join(dir, entry.name)
265
+ if (entry.isDirectory()) collectRemovedFiles(full, rel, out)
266
+ else out.push(rel)
267
+ }
268
+ }
269
+
270
+ function syncSdkTree(
271
+ sourceDir: string,
272
+ destDir: string,
273
+ prefix: string,
274
+ distributionPrefix: string,
275
+ changed: string[],
276
+ removed: string[],
277
+ ): void {
278
+ mkdirSync(destDir, { recursive: true })
279
+ const wanted = new Set<string>()
280
+ for (const entry of readdirSync(sourceDir, { withFileTypes: true })) {
281
+ wanted.add(entry.name)
282
+ const rel = prefix ? `${prefix}/${entry.name}` : entry.name
283
+ const src = path.join(sourceDir, entry.name)
284
+ const dest = path.join(destDir, entry.name)
285
+ const destLstat = lstatSync(dest, { throwIfNoEntry: false })
286
+ if (entry.isSymbolicLink()) {
287
+ const target = readlinkSync(src)
288
+ if (target.startsWith(distributionPrefix)) {
289
+ if (destLstat?.isSymbolicLink() && readlinkSync(dest) === target) continue
290
+ if (destLstat) rmSync(dest, { recursive: true, force: true })
291
+ symlinkSync(target, dest)
292
+ changed.push(rel)
293
+ continue
294
+ }
295
+ }
296
+ const srcStat = statSync(src, { throwIfNoEntry: false })
297
+ if (!srcStat) continue
298
+ if (srcStat.isDirectory()) {
299
+ if (destLstat && (!destLstat.isDirectory() || destLstat.isSymbolicLink()))
300
+ rmSync(dest, { recursive: true, force: true })
301
+ syncSdkTree(src, dest, rel, distributionPrefix, changed, removed)
302
+ continue
303
+ }
304
+ if (
305
+ destLstat?.isFile() &&
306
+ !destLstat.isSymbolicLink() &&
307
+ destLstat.size === srcStat.size &&
308
+ readFileSync(src).equals(readFileSync(dest))
309
+ )
310
+ continue
311
+ if (destLstat?.isDirectory()) rmSync(dest, { recursive: true, force: true })
312
+ place(src, dest, (srcStat.mode & 0o111) !== 0 ? srcStat.mode & 0o777 : undefined)
313
+ changed.push(rel)
314
+ }
315
+ for (const entry of readdirSync(destDir, { withFileTypes: true })) {
316
+ if (wanted.has(entry.name)) continue
317
+ const rel = prefix ? `${prefix}/${entry.name}` : entry.name
318
+ const dest = path.join(destDir, entry.name)
319
+ if (entry.isDirectory()) collectRemovedFiles(dest, rel, removed)
320
+ else removed.push(rel)
321
+ rmSync(dest, { recursive: true, force: true })
322
+ }
323
+ }
324
+
68
325
  function readRecord(file: string): Record<string, string> | null {
69
326
  if (!existsSync(file)) return null
70
327
  const value: unknown = JSON.parse(readFileSync(file, 'utf8'))
@@ -77,13 +334,20 @@ function readRecord(file: string): Record<string, string> | null {
77
334
  return files
78
335
  }
79
336
 
80
- function place(from: string, to: string): void {
337
+ function place(from: string, to: string, mode?: number): void {
81
338
  mkdirSync(path.dirname(to), { recursive: true })
82
339
  const partial = `${to}.${randomUUID()}`
83
340
  copyFileSync(from, partial, constants.COPYFILE_FICLONE)
341
+ if (mode !== undefined) chmodSync(partial, mode)
84
342
  renameSync(partial, to)
85
343
  }
86
344
 
345
+ function escapeDepPath(directory: string): string {
346
+ return directory.replace(/[\\ #$]/g, (character) =>
347
+ character === '$' ? '$$' : `\\${character}`,
348
+ )
349
+ }
350
+
87
351
  function invalidateDependents(root: string, mirror: string, files: string[]): void {
88
352
  // objects only reach the link
89
353
  const read = new Set(files.filter((file) => !file.startsWith('lib/')))
@@ -91,14 +355,24 @@ function invalidateDependents(root: string, mirror: string, files: string[]): vo
91
355
  // compiles name a distribution file under the mirror, and an sdk header
92
356
  // through the sdk view's darwin tree; another darwin tree's file of the same
93
357
  // name can over-match, which only rebuilds.
94
- const escapedMirror = mirror.replace(/[\\ #$]/g, (character) =>
95
- character === '$' ? '$$' : `\\${character}`,
96
- )
97
358
  const spellings: [prefix: Buffer, base: string][] = [
98
- [Buffer.from(`${escapedMirror}/`), ''],
359
+ [Buffer.from(`${escapeDepPath(mirror)}/`), ''],
99
360
  ]
100
361
  if (files.some((file) => file.startsWith('sdk/ios/')))
101
362
  spellings.push([Buffer.from('/darwin/'), 'sdk/ios/'])
363
+ // clang validates neither system headers nor the modules built from them
364
+ const headersChanged = files.some(
365
+ (file) => !file.startsWith('lib/') && !file.startsWith('modules/'),
366
+ )
367
+ invalidateBuildDependents(root, spellings, read, headersChanged)
368
+ }
369
+
370
+ function invalidateBuildDependents(
371
+ root: string,
372
+ spellings: readonly [prefix: Buffer, base: string][],
373
+ read: ReadonlySet<string>,
374
+ headersChanged: boolean,
375
+ ): void {
102
376
  const names = (text: Buffer) =>
103
377
  spellings.some(([prefix, base]) => {
104
378
  let end = 0
@@ -114,10 +388,6 @@ function invalidateDependents(root: string, mirror: string, files: string[]): vo
114
388
  })
115
389
  const scratch = path.join(root, '.build')
116
390
  if (!existsSync(scratch)) return
117
- // clang validates neither system headers nor the modules built from them
118
- const headersChanged = files.some(
119
- (file) => !file.startsWith('lib/') && !file.startsWith('modules/'),
120
- )
121
391
  for (const triple of readdirSync(scratch, { withFileTypes: true })) {
122
392
  const products = path.join(scratch, triple.name, 'release')
123
393
  if (!triple.isDirectory() || !existsSync(products)) continue
@@ -8,7 +8,9 @@ import {
8
8
  } from '../cli/internal-child-contract'
9
9
  import { rnxSelfInvocation } from '../cli/self-invocation'
10
10
  import { fetchNativeEntry, nativeEntryKey } from './native-prebuilt'
11
+ import { SWIFT_SDK_MIRROR } from './swift-distribution-mirror'
11
12
  import { swiftObjCPrebuiltPackages } from './swift-objc-prebuilt-catalog'
13
+ import { SWIFT_SDK_HEADER_CASE_OVERLAY } from './swift-objc-standin'
12
14
  import { swiftCacheDir } from './swift-toolchain'
13
15
 
14
16
  export const SWIFT_OBJC_PREBUILT_OBJECT = 'unit.o'
@@ -136,6 +138,11 @@ export function runSwiftObjCPrebuiltCompiler([
136
138
  JSON.stringify(normalize(file)),
137
139
  )
138
140
  const sdkCaseOverlay = path.join(swiftCacheDir(), 'swift-header-case') + path.sep
141
+ const mirroredSdkCaseOverlay = path.join(
142
+ root,
143
+ SWIFT_SDK_MIRROR,
144
+ SWIFT_SDK_HEADER_CASE_OVERLAY,
145
+ )
139
146
  const xcodeCaseOverlay = path.join(
140
147
  root,
141
148
  '.build',
@@ -180,7 +187,9 @@ export function runSwiftObjCPrebuiltCompiler([
180
187
  commandFlags.map((arg, index) => {
181
188
  if (
182
189
  commandFlags[index - 1] === '-ivfsoverlay' &&
183
- (arg.startsWith(sdkCaseOverlay) || arg.startsWith(xcodeCaseOverlay))
190
+ (arg.startsWith(sdkCaseOverlay) ||
191
+ arg === mirroredSdkCaseOverlay ||
192
+ arg.startsWith(xcodeCaseOverlay))
184
193
  ) {
185
194
  const overlay = normalizeQuotedPaths(fs.readFileSync(arg, 'utf8'))
186
195
  return createHash('sha256').update(overlay).digest('hex')
@@ -291,6 +291,8 @@ export function materializeObjcSdk(cacheDir: string): string {
291
291
  return sdk
292
292
  }
293
293
 
294
+ export const SWIFT_SDK_HEADER_CASE_OVERLAY = 'sdk-header-case.yaml'
295
+
294
296
  /** the libc intake of every original c and objective-c unit over the sdk at
295
297
  * `headers`: the iOS platform predefines for its deployment minimum, the
296
298
  * installed libc's emulated surfaces that every app links, the sdk
@@ -300,15 +302,18 @@ export function objcSdkIntakeFlags(
300
302
  headers: string,
301
303
  toolchainBin: string,
302
304
  minimum: number,
305
+ overlayDirectory?: string,
303
306
  ): string[] {
304
307
  const caseOverlay = caseInsensitiveHeaderOverlay(
305
- path.join(swiftCacheDir(), 'swift-header-case'),
308
+ overlayDirectory ?? path.join(swiftCacheDir(), 'swift-header-case'),
306
309
  [
307
310
  path.join(headers, 'System/Library/Frameworks'),
308
311
  path.join(headers, 'wasm/include'),
309
312
  path.join(headers, 'wasm/intrinsics'),
310
313
  path.join(headers, 'usr/include'),
311
314
  ],
315
+ undefined,
316
+ overlayDirectory ? SWIFT_SDK_HEADER_CASE_OVERLAY : undefined,
312
317
  )
313
318
  return [
314
319
  ...swiftObjCPlatformFlags(toolchainBin, minimum),
@@ -31,6 +31,7 @@ import {
31
31
  NATIVE_SDK_IMPORT_MODULE,
32
32
  NATIVE_SDK_THUNK_SECTION,
33
33
  } from '../../peach-kit/src/nativeWasmContract'
34
+ import { SWIFT_DISTRIBUTION_MIRROR, SWIFT_SDK_MIRROR } from './swift-distribution-mirror'
34
35
  import { guestLazyExports, placeGuestLazyFunctions } from './swift-guest-dyld-functions'
35
36
  import { guestWasmDataSegments, type GuestLinkedSpan } from './swift-guest-linked-spans'
36
37
  import { projectOutputFile, type SwiftProjectUser } from './swift-project-user'
@@ -243,9 +244,15 @@ export function swiftAppModuleInputs(
243
244
  buildRoot: string,
244
245
  sdkLibraries: readonly string[],
245
246
  ): string[] {
246
- const owned = (token: string) =>
247
- path.resolve(token).startsWith(`${buildRoot}/`) &&
248
- (!token.includes('/.peach-pruned-objs/') || token.endsWith('/swiftrt-patched.o'))
247
+ const owned = (token: string) => {
248
+ const resolved = path.resolve(token)
249
+ return (
250
+ resolved.startsWith(`${buildRoot}/`) &&
251
+ !resolved.startsWith(`${buildRoot}/${SWIFT_DISTRIBUTION_MIRROR}/`) &&
252
+ !resolved.startsWith(`${buildRoot}/${SWIFT_SDK_MIRROR}/`) &&
253
+ (!token.includes('/.peach-pruned-objs/') || token.endsWith('/swiftrt-patched.o'))
254
+ )
255
+ }
249
256
  const inputs: string[] = []
250
257
  for (const [index, token] of tokens.entries()) {
251
258
  if (token === '--start-lib') inputs.push(token)
@@ -920,12 +920,17 @@ const sdkPaths = new Map<
920
920
  }
921
921
  >()
922
922
 
923
+ export function clearSwiftSdkPathsCache(sdkDir: string): void {
924
+ for (const key of sdkPaths.keys()) if (key.includes(sdkDir)) sdkPaths.delete(key)
925
+ }
926
+
923
927
  /** the wasm SDK's sysroot, swift resource directory, and clang intake.
924
928
  * raw swiftc does not read the toolset, so stand-in compiles pass cFlags. */
925
929
  export function swiftSdkPaths(
926
930
  moduleRoot: string,
927
931
  toolchainBin: string,
928
932
  options = swiftCompileSdkOptions(moduleRoot, toolchainBin),
933
+ sdk = swiftModuleSdk(moduleRoot).wasmSdkId,
929
934
  ): {
930
935
  sysroot: string
931
936
  darwin: string
@@ -933,7 +938,6 @@ export function swiftSdkPaths(
933
938
  frameworks: string[]
934
939
  cFlags: string[]
935
940
  } {
936
- const sdk = swiftModuleSdk(moduleRoot).wasmSdkId
937
941
  const key = JSON.stringify([toolchainBin, sdk, options])
938
942
  const cached = sdkPaths.get(key)
939
943
  if (cached) return cached