peachsim 0.1.2421 → 0.1.2423

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 (117) hide show
  1. package/cli/command-agent.ts +14 -15
  2. package/cli/commands/box.ts +33 -28
  3. package/cli/commands/canvas.ts +54 -0
  4. package/cli/commands/platform.ts +28 -27
  5. package/cli/commands/preview.ts +2 -1
  6. package/cli/outbound-endpoints.ts +3 -0
  7. package/dist-lib/agent-daemon-client.cjs +1 -1
  8. package/dist-lib/agent-events.cjs +1 -1
  9. package/dist-lib/attached-projects.cjs +1 -1
  10. package/dist-lib/auth/shared-session.cjs +1 -1
  11. package/dist-lib/backend-origin.cjs +1 -1
  12. package/dist-lib/beta.cjs +1 -1
  13. package/dist-lib/beta.mjs +1 -1
  14. package/dist-lib/bridge-constants.cjs +1 -1
  15. package/dist-lib/bridge-contract-input.cjs +1 -1
  16. package/dist-lib/bridge-contract-input.mjs +1 -1
  17. package/dist-lib/bridge-contract.cjs +1 -1
  18. package/dist-lib/bridge-contract.mjs +1 -1
  19. package/dist-lib/bundle-channel.cjs +4318 -3937
  20. package/dist-lib/capture-contract.cjs +1 -1
  21. package/dist-lib/capture-contract.mjs +1 -1
  22. package/dist-lib/cloud-contract.cjs +22 -1
  23. package/dist-lib/cloud-contract.mjs +20 -1
  24. package/dist-lib/cloud-test-args.cjs +1 -1
  25. package/dist-lib/cloud-test-args.mjs +1 -1
  26. package/dist-lib/cloud.cjs +1 -1
  27. package/dist-lib/cloud.mjs +1 -1
  28. package/dist-lib/config.cjs +1 -1
  29. package/dist-lib/config.mjs +1 -1
  30. package/dist-lib/detox/index.cjs +27 -13
  31. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  32. package/dist-lib/expo-swift-bundle.cjs +3343 -2962
  33. package/dist-lib/expo-swift-metadata.cjs +1 -1
  34. package/dist-lib/expo-swift-metadata.mjs +1 -1
  35. package/dist-lib/home-paths.cjs +1 -1
  36. package/dist-lib/host/bridge-host.cjs +4200 -3819
  37. package/dist-lib/host/fetch-proxy-handler.cjs +25 -4
  38. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  39. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  40. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  41. package/dist-lib/host/websocket-proxy.cjs +1 -1
  42. package/dist-lib/index.cjs +88 -53
  43. package/dist-lib/jump-to-source-babel.cjs +1 -1
  44. package/dist-lib/jump-to-source-native.cjs +1 -1
  45. package/dist-lib/kotlin-host.cjs +1 -1
  46. package/dist-lib/menu.cjs +1 -1
  47. package/dist-lib/menu.mjs +1 -1
  48. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  49. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  50. package/dist-lib/metro-production-bundle.cjs +1 -1
  51. package/dist-lib/metro-production-bundle.mjs +1 -1
  52. package/dist-lib/metro.cjs +25 -4
  53. package/dist-lib/native-app-identity-project.cjs +2 -2
  54. package/dist-lib/native-app-identity-project.mjs +231 -212
  55. package/dist-lib/native-app-identity.cjs +1 -1
  56. package/dist-lib/native-app-identity.mjs +1 -1
  57. package/dist-lib/native-firebase-metadata.cjs +1 -1
  58. package/dist-lib/native-firebase-metadata.mjs +1 -1
  59. package/dist-lib/pdfium-raster.cjs +1 -1
  60. package/dist-lib/pdfium-raster.mjs +1 -1
  61. package/dist-lib/plist.cjs +1 -1
  62. package/dist-lib/plist.mjs +1 -1
  63. package/dist-lib/profiles.cjs +1 -1
  64. package/dist-lib/public-brand.cjs +1 -1
  65. package/dist-lib/public-origins-lib-esm.json +30 -25
  66. package/dist-lib/public-origins-lib.json +78 -56
  67. package/dist-lib/react-native-host-modules.cjs +1 -1
  68. package/dist-lib/react-native-host-modules.mjs +1 -1
  69. package/dist-lib/reap-browser.cjs +1 -1
  70. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  71. package/dist-lib/sdk.cjs +1 -1
  72. package/dist-lib/sdk.mjs +1 -1
  73. package/dist-lib/skills.cjs +4990 -4586
  74. package/dist-lib/swift-compile.cjs +1261 -889
  75. package/dist-lib/swift-compile.mjs +1231 -849
  76. package/dist-lib/swift-package.cjs +1 -1
  77. package/dist-lib/swift-package.mjs +1 -1
  78. package/dist-lib/swift-submit.cjs +1 -1
  79. package/dist-lib/swift-submit.mjs +1 -1
  80. package/dist-lib/swift-toolchain.cjs +1 -1
  81. package/dist-lib/swift.cjs +1 -1
  82. package/dist-lib/vite-swift.cjs +2712 -2348
  83. package/dist-lib/vite.cjs +25 -4
  84. package/dist-lib/worklet-executable.cjs +1 -1
  85. package/dist-lib/worklet-executable.mjs +1 -1
  86. package/dist-types/packages/peach-engine/src/engine/native-layout.d.ts +1 -1
  87. package/dist-types/packages/peach-engine/src/ios/apps/canvas-map-data.d.ts +83 -2
  88. package/dist-types/packages/peach-engine/src/remote-stream/cloud-display.d.ts +2 -2
  89. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +0 -10
  90. package/dist-types/packages/peach-engine/src/render-worker/compositor-runtime/layer-claims.d.ts +2 -1
  91. package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +9 -0
  92. package/dist-types/packages/peach-globals/src/canvasAgentContract.d.ts +8 -0
  93. package/dist-types/packages/peach-globals/src/index.d.ts +4 -2
  94. package/dist-types/packages/peach-globals/src/replayBridgeContract.d.ts +12 -0
  95. package/dist-types/packages/peach-globals/src/sceneStreamBridgeContract.d.ts +5 -1
  96. package/kotlin/sdk.tar.gz +0 -0
  97. package/package.json +1 -1
  98. package/runtime-companion.json +1 -1
  99. package/sdk/ios/System/Library/Frameworks/CoreData.framework/Headers/CoreData.apinotes +2 -0
  100. package/sdk/ios/System/Library/Frameworks/CoreData.framework/Headers/NSPersistentStore.h +2 -0
  101. package/sdk/ios/wasm/include/errno.h +10 -0
  102. package/src/agent-daemon-client.ts +1 -1
  103. package/src/agent-prompt.ts +1 -8
  104. package/src/canvas-agent-note-delivery.ts +2 -5
  105. package/src/canvas-groups.ts +11 -3
  106. package/src/cloud-contract.ts +31 -1
  107. package/src/expo-kotlin-bundle.ts +1 -1
  108. package/src/native-static-libraries.ts +51 -4
  109. package/src/swift-compile.ts +184 -108
  110. package/src/swift-compiler-digest.ts +2 -0
  111. package/src/swift-guest-compile.ts +2 -0
  112. package/src/swift-guest-source-inputs.ts +2 -2
  113. package/src/swift-header-compiler.ts +185 -0
  114. package/src/swift-header-dependencies.ts +174 -0
  115. package/src/swift-objc-compile.ts +18 -24
  116. package/src/vite-plugin.ts +4 -1
  117. package/dist-types/packages/peach-engine/src/render-worker/accessibilityHostContract.d.ts +0 -65
@@ -51,6 +51,14 @@ import {
51
51
  import { foundationCategoryObjects } from './swift-foundation'
52
52
  import { compileGuestLink } from './swift-guest-compile'
53
53
  import { CLANG_TARGET_MODULE_WRAPPER } from './swift-guest-source-inputs'
54
+ import {
55
+ SWIFT_HEADER_COMPILER_WRAPPER,
56
+ withSwiftHeaderCompiler,
57
+ } from './swift-header-compiler'
58
+ import {
59
+ nativeHeaderIncludes,
60
+ swiftHeaderDependencies,
61
+ } from './swift-header-dependencies'
54
62
  import {
55
63
  brotliCompressQ11,
56
64
  brotliCompressQ4,
@@ -1784,7 +1792,7 @@ const darwinRecordsRegion = (quoted: readonly string[]): string[] =>
1784
1792
  const REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n'
1785
1793
 
1786
1794
  /** bump with any change to the emitted multi-target manifest text. */
1787
- export const MULTI_MANIFEST_VERSION = 71
1795
+ export const MULTI_MANIFEST_VERSION = 72
1788
1796
  const SWIFT_HEADER_PRODUCTS_TARGET = 'PeachHeaderProducts'
1789
1797
 
1790
1798
  // build-cli replaces this in every bundle; source runs read the files directly.
@@ -3045,7 +3053,6 @@ const FOUNDATION_OVERLAY_TYPES = new Set([
3045
3053
  'NSSwappedDouble',
3046
3054
  'NSSwappedFloat',
3047
3055
  'NSUbiquitousKeyValueStore',
3048
- 'NSValueTransformerName',
3049
3056
  'NSXPCCoder',
3050
3057
  'NSXPCConnection',
3051
3058
  'NSXPCInterface',
@@ -3070,7 +3077,6 @@ const FOUNDATION_OVERLAY_TYPES = new Set([
3070
3077
  // existing overlay globals retain their declaration and runtime owner.
3071
3078
  const FOUNDATION_OVERLAY_GLOBALS = new Set([
3072
3079
  'CFBridgingRetain',
3073
- 'NSASCIIStringEncoding',
3074
3080
  'NSAllHashTableObjects',
3075
3081
  'NSAllMapTableKeys',
3076
3082
  'NSAllMapTableValues',
@@ -3149,21 +3155,16 @@ const FOUNDATION_OVERLAY_GLOBALS = new Set([
3149
3155
  'NSHashTableWeakMemory',
3150
3156
  'NSHebrewCalendar',
3151
3157
  'NSHostByteOrder',
3152
- 'NSISO2022JPStringEncoding',
3153
3158
  'NSISO8601Calendar',
3154
- 'NSISOLatin1StringEncoding',
3155
- 'NSISOLatin2StringEncoding',
3156
3159
  'NSIndianCalendar',
3157
3160
  'NSIslamicCalendar',
3158
3161
  'NSIslamicCivilCalendar',
3159
3162
  'NSItemProviderPreferredImageSizeKey',
3160
3163
  'NSJapaneseCalendar',
3161
- 'NSJapaneseEUCStringEncoding',
3162
3164
  'NSLoadedClasses',
3163
3165
  'NSLocalizedFailureErrorKey',
3164
3166
  'NSLogPageSize',
3165
3167
  'NSMACHOperatingSystem',
3166
- 'NSMacOSRomanStringEncoding',
3167
3168
  'NSMapGet',
3168
3169
  'NSMapInsert',
3169
3170
  'NSMapInsertIfAbsent',
@@ -3175,10 +3176,8 @@ const FOUNDATION_OVERLAY_GLOBALS = new Set([
3175
3176
  'NSMapTableStrongMemory',
3176
3177
  'NSMapTableWeakMemory',
3177
3178
  'NSMultipleUnderlyingErrorsKey',
3178
- 'NSNEXTSTEPStringEncoding',
3179
3179
  'NSNextHashEnumeratorItem',
3180
3180
  'NSNextMapEnumeratorPair',
3181
- 'NSNonLossyASCIIStringEncoding',
3182
3181
  'NSNonOwnedPointerHashCallBacks',
3183
3182
  'NSNonOwnedPointerMapKeyCallBacks',
3184
3183
  'NSNonOwnedPointerMapValueCallBacks',
@@ -3200,12 +3199,10 @@ const FOUNDATION_OVERLAY_GLOBALS = new Set([
3200
3199
  'NSPointerToStructHashCallBacks',
3201
3200
  'NSPropertyListErrorMaximum',
3202
3201
  'NSPropertyListErrorMinimum',
3203
- 'NSProprietaryStringEncoding',
3204
3202
  'NSProtocolFromString',
3205
3203
  'NSRepublicOfChinaCalendar',
3206
3204
  'NSResetHashTable',
3207
3205
  'NSResetMapTable',
3208
- 'NSShiftJISStringEncoding',
3209
3206
  'NSSolarisOperatingSystem',
3210
3207
  'NSStringFromHashTable',
3211
3208
  'NSStringFromMapTable',
@@ -3241,7 +3238,6 @@ const FOUNDATION_OVERLAY_GLOBALS = new Set([
3241
3238
  'NSSwapLong',
3242
3239
  'NSSwapLongLong',
3243
3240
  'NSSwapShort',
3244
- 'NSSymbolStringEncoding',
3245
3241
  'NSTextCheckingAllCustomTypes',
3246
3242
  'NSTextCheckingAllSystemTypes',
3247
3243
  'NSTextCheckingAllTypes',
@@ -3259,13 +3255,6 @@ const FOUNDATION_OVERLAY_GLOBALS = new Set([
3259
3255
  'NSURLProtectionSpaceHTTPSProxy',
3260
3256
  'NSURLProtectionSpaceSOCKSProxy',
3261
3257
  'NSURLSessionUploadTaskResumeData',
3262
- 'NSUTF16BigEndianStringEncoding',
3263
- 'NSUTF16LittleEndianStringEncoding',
3264
- 'NSUTF16StringEncoding',
3265
- 'NSUTF32BigEndianStringEncoding',
3266
- 'NSUTF32LittleEndianStringEncoding',
3267
- 'NSUTF32StringEncoding',
3268
- 'NSUTF8StringEncoding',
3269
3258
  'NSUbiquitousFileErrorMaximum',
3270
3259
  'NSUbiquitousFileErrorMinimum',
3271
3260
  'NSUbiquitousKeyValueStoreAccountChange',
@@ -3277,17 +3266,11 @@ const FOUNDATION_OVERLAY_GLOBALS = new Set([
3277
3266
  'NSUndefinedDateComponent',
3278
3267
  'NSUndoCloseGroupingRunLoopOrdering',
3279
3268
  'NSUndoManagerGroupIsDiscardableKey',
3280
- 'NSUnicodeStringEncoding',
3281
3269
  'NSUserActivityErrorMaximum',
3282
3270
  'NSUserActivityErrorMinimum',
3283
3271
  'NSValidationErrorMaximum',
3284
3272
  'NSValidationErrorMinimum',
3285
3273
  'NSWindows95OperatingSystem',
3286
- 'NSWindowsCP1250StringEncoding',
3287
- 'NSWindowsCP1251StringEncoding',
3288
- 'NSWindowsCP1252StringEncoding',
3289
- 'NSWindowsCP1253StringEncoding',
3290
- 'NSWindowsCP1254StringEncoding',
3291
3274
  'NSWindowsNTOperatingSystem',
3292
3275
  'NSWrapCalendarComponents',
3293
3276
  'NSXPCConnectionCodeSigningRequirementFailure',
@@ -4225,6 +4208,19 @@ type Lexical =
4225
4208
  | { kind: 'block'; depth: number }
4226
4209
  | { kind: 'string'; hashes: number; multiline: boolean }
4227
4210
  | { kind: 'regex'; hashes: number }
4211
+ const SWIFT_SCAN_KEYWORDS: Readonly<Record<string, string>> = {
4212
+ c: 'class',
4213
+ e: 'extension',
4214
+ o: 'override',
4215
+ i: 'import',
4216
+ f: 'func',
4217
+ U: 'UIApplicationMain',
4218
+ F: 'Foundation',
4219
+ C: 'CoreFoundation',
4220
+ O: 'ObjectiveC',
4221
+ _: '_LocationEssentials',
4222
+ }
4223
+
4228
4224
  function swiftCodeScan(source: string): {
4229
4225
  lineStarts: Set<number>
4230
4226
  tokens: number[]
@@ -4310,29 +4306,10 @@ function swiftCodeScan(source: string): {
4310
4306
  else top.parens--
4311
4307
  i++
4312
4308
  } else {
4313
- const keyword = source.startsWith('class', i)
4314
- ? 'class'
4315
- : source.startsWith('extension', i)
4316
- ? 'extension'
4317
- : source.startsWith('override', i)
4318
- ? 'override'
4319
- : source.startsWith('import', i)
4320
- ? 'import'
4321
- : source.startsWith('func', i)
4322
- ? 'func'
4323
- : source.startsWith('UIApplicationMain', i)
4324
- ? 'UIApplicationMain'
4325
- : source.startsWith('Foundation', i)
4326
- ? 'Foundation'
4327
- : source.startsWith('CoreFoundation', i)
4328
- ? 'CoreFoundation'
4329
- : source.startsWith('ObjectiveC', i)
4330
- ? 'ObjectiveC'
4331
- : source.startsWith('_LocationEssentials', i)
4332
- ? '_LocationEssentials'
4333
- : null
4309
+ const keyword = SWIFT_SCAN_KEYWORDS[char!]
4334
4310
  if (
4335
4311
  keyword &&
4312
+ source.startsWith(keyword, i) &&
4336
4313
  !/[\w$]/.test(source[i - 1] ?? '') &&
4337
4314
  !/[\w$]/.test(source[i + keyword.length] ?? '')
4338
4315
  ) {
@@ -4530,9 +4507,11 @@ export function writeSwiftProject(
4530
4507
  input: SwiftCompileInput,
4531
4508
  moduleRoot: string,
4532
4509
  prebuilt?: SwiftFrameworkProducts,
4510
+ allowHeaderCompiler = false,
4533
4511
  ): SwiftProjectPreparation & {
4534
4512
  generatedOwners: Map<string, string>
4535
4513
  targetToolset: boolean
4514
+ headerCompiler: boolean
4536
4515
  } {
4537
4516
  const nativeToolset = needsNativeToolset(input, prebuilt)
4538
4517
  if (input.headerAliases !== undefined && !isSwiftHeaderAliases(input.headerAliases))
@@ -4921,12 +4900,8 @@ export function writeSwiftProject(
4921
4900
  const reverse = new Map<string, string[]>()
4922
4901
  for (const [file, contents] of entries) {
4923
4902
  const producers = new Set<string>()
4924
- // a block-commented include is not an edge.
4925
4903
  const source = contents.replace(/\/\*[\s\S]*?\*\//g, '')
4926
- for (const match of source.matchAll(
4927
- /^\s*#\s*(?:include|import)\s*[<"]([^>"]+)[>"]/gm,
4928
- )) {
4929
- const include = match[1]!
4904
+ for (const include of nativeHeaderIncludes(contents)) {
4930
4905
  const producer = /(?:^|\/)([^/]+)-Swift\.h$/.exec(include)?.[1]
4931
4906
  if (producer && swiftTargets.has(producer)) producers.add(producer)
4932
4907
  const local = [
@@ -6347,12 +6322,13 @@ export function writeSwiftProject(
6347
6322
  }
6348
6323
  const manifestPath = path.join(layout.root, 'Package.swift')
6349
6324
  let manifest = files.get(manifestPath)!.toString()
6325
+ const manifestTargets = swiftManifestTargets(manifest, [], (file) => {
6326
+ const contents = files.get(file)
6327
+ if (contents === undefined) throw new Error(`missing compiler arguments ${file}`)
6328
+ return contents.toString()
6329
+ })
6350
6330
  const dependencies = new Map(
6351
- swiftManifestTargets(manifest, [], (file) => {
6352
- const contents = files.get(file)
6353
- if (contents === undefined) throw new Error(`missing compiler arguments ${file}`)
6354
- return contents.toString()
6355
- }).map((target) => [
6331
+ manifestTargets.map((target) => [
6356
6332
  target.name,
6357
6333
  (target.dependencies ?? []).flatMap((dependency) =>
6358
6334
  dependency.kind === 'target' ? [dependency.name] : [],
@@ -6360,6 +6336,66 @@ export function writeSwiftProject(
6360
6336
  ]),
6361
6337
  )
6362
6338
  const producerSet = new Set([...Object.keys(nativeHeaderDeclarations), ...producers])
6339
+ let headerCompiler = allowHeaderCompiler && packages.size === 0 && producerSet.size > 0
6340
+ if (headerCompiler) {
6341
+ const clang = new Set(
6342
+ manifestTargets
6343
+ .filter(
6344
+ (target) =>
6345
+ target.systemLibrary ||
6346
+ (!swiftTargets.has(target.name) && native.has(target.name)),
6347
+ )
6348
+ .map(({ name }) => name),
6349
+ )
6350
+ const headers = swiftHeaderDependencies(
6351
+ layout.root,
6352
+ files,
6353
+ manifestTargets,
6354
+ nativeTargets,
6355
+ producerSet,
6356
+ input.headerAliases ?? {},
6357
+ )
6358
+ const nativeEdges = new Map<string, string[]>()
6359
+ const dependsOn = (from: string, to: string, seen = new Set<string>()): boolean => {
6360
+ if (from === to) return true
6361
+ if (seen.has(from)) return false
6362
+ seen.add(from)
6363
+ return [...(dependencies.get(from) ?? []), ...(nativeEdges.get(from) ?? [])].some(
6364
+ (dependency) => dependsOn(dependency, to, seen),
6365
+ )
6366
+ }
6367
+ for (const target of manifestTargets) {
6368
+ if (target.systemLibrary) continue
6369
+ const required = new Set(headers.get(target.name))
6370
+ const visited = new Set<string>()
6371
+ const imports = (name: string): void => {
6372
+ if (!clang.has(name) || visited.has(name)) return
6373
+ visited.add(name)
6374
+ for (const header of headers.get(name) ?? []) required.add(header)
6375
+ for (const dependency of dependencies.get(name) ?? []) imports(dependency)
6376
+ }
6377
+ for (const dependency of dependencies.get(target.name) ?? []) imports(dependency)
6378
+ for (const producer of required) {
6379
+ if (dependsOn(target.name, producer)) continue
6380
+ if (dependsOn(producer, target.name)) {
6381
+ headerCompiler = false
6382
+ break
6383
+ }
6384
+ const edges = nativeEdges.get(target.name) ?? []
6385
+ edges.push(producer)
6386
+ nativeEdges.set(target.name, edges)
6387
+ }
6388
+ if (!headerCompiler) break
6389
+ }
6390
+ if (headerCompiler)
6391
+ for (const [target, producers] of nativeEdges) {
6392
+ const additions = producers
6393
+ .map((producer) => `.target(name: ${JSON.stringify(producer)})`)
6394
+ .join(', ')
6395
+ manifest += `\npackage.targets.first(where: { $0.name == ${JSON.stringify(target)} })!.dependencies += [${additions}]\n`
6396
+ dependencies.get(target)!.push(...producers)
6397
+ }
6398
+ }
6363
6399
  const depths = new Map<string, number>()
6364
6400
  const orderedProducers: string[] = []
6365
6401
  const depth = (name: string): number => {
@@ -6396,12 +6432,19 @@ export function writeSwiftProject(
6396
6432
  }
6397
6433
  // normalize a dependency header before its consumers, while swiftpm schedules
6398
6434
  // independent producers together within the admitted job budget.
6399
- const headerBuilds = [...stages]
6400
- .sort(([left], [right]) => left - right)
6401
- .map(([level, producers]) => ({
6402
- target: buildProduct(`${SWIFT_HEADER_PRODUCTS_TARGET}${level}`, producers),
6403
- producers,
6404
- }))
6435
+ const headerBuilds = headerCompiler
6436
+ ? [
6437
+ {
6438
+ target: buildProduct(SWIFT_HEADER_PRODUCTS_TARGET, orderedProducers),
6439
+ producers: orderedProducers,
6440
+ },
6441
+ ]
6442
+ : [...stages]
6443
+ .sort(([left], [right]) => left - right)
6444
+ .map(([level, producers]) => ({
6445
+ target: buildProduct(`${SWIFT_HEADER_PRODUCTS_TARGET}${level}`, producers),
6446
+ producers,
6447
+ }))
6405
6448
  const nativeBuildTargets = [
6406
6449
  ...new Set([
6407
6450
  ...(input.staticClangTargets ?? []),
@@ -6430,6 +6473,7 @@ export function writeSwiftProject(
6430
6473
  targetFailures,
6431
6474
  generatedOwners,
6432
6475
  targetToolset,
6476
+ headerCompiler,
6433
6477
  }
6434
6478
  }
6435
6479
 
@@ -7666,6 +7710,7 @@ function compileSwiftProjectOnce(
7666
7710
  input,
7667
7711
  frameworkRoot,
7668
7712
  prebuilt,
7713
+ !options.project,
7669
7714
  )
7670
7715
  // the framework objects link as inputs, so the product name its
7671
7716
  // modules autolink has no archive to load
@@ -7898,7 +7943,42 @@ function compileSwiftProjectOnce(
7898
7943
  )
7899
7944
  return value
7900
7945
  }
7901
- const compileApp = async () => {
7946
+ const headerPaths = (producer: string) => {
7947
+ const stem = path.join(
7948
+ root,
7949
+ '.build',
7950
+ 'peach-cxx-headers',
7951
+ `${producer}-Swift`,
7952
+ )
7953
+ return { producer, original: `${stem}.original.h`, emitted: `${stem}.h` }
7954
+ }
7955
+ const publishHeader = ({
7956
+ producer,
7957
+ original,
7958
+ emitted,
7959
+ }: ReturnType<typeof headerPaths>) => {
7960
+ const generated = clangInterfaceHeader(readFileSync(original, 'utf8'))
7961
+ writeBuildFile(
7962
+ emitted,
7963
+ withoutSwiftDeclarations(
7964
+ swiftHeaderWithSuperclassImports(generated, frameworkInterface),
7965
+ new Set([
7966
+ ...(preparation.nativeHeaderDeclarations[producer] ?? []),
7967
+ ...nativelyDeclaredFunctions(generated, nativeHeaders),
7968
+ ]),
7969
+ `#import <${producer}/${producer}.h>`,
7970
+ ),
7971
+ )
7972
+ }
7973
+ const recipe = createHash('sha256')
7974
+ .update(hash)
7975
+ .update(readFileSync(path.join(root, 'Package.swift')))
7976
+ .update(JSON.stringify(buildArgs))
7977
+ .digest('hex')
7978
+ const runApp = async (compiler?: Record<string, string>) => {
7979
+ const optionsWithCompiler = compiler
7980
+ ? { ...appOptions, env: { ...appOptions.env, ...compiler } }
7981
+ : appOptions
7902
7982
  // clang consumes the real emitted headers after swift finishes.
7903
7983
  // swiftpm's transitive swift module maps are not C declarations:
7904
7984
  // importing them would shadow SDK modules such as ObjectiveC.
@@ -7909,33 +7989,16 @@ function compileSwiftProjectOnce(
7909
7989
  : []),
7910
7990
  ]
7911
7991
  const checkpoints = path.join(root, '.build', 'peach-product-checkpoints')
7912
- const recipe = createHash('sha256')
7913
- .update(hash)
7914
- .update(readFileSync(path.join(root, 'Package.swift')))
7915
- .update(JSON.stringify(buildArgs))
7916
- .digest('hex')
7917
7992
  for (const { target, producers } of stages) {
7918
7993
  const receipt = path.join(
7919
7994
  checkpoints,
7920
7995
  createHash('sha256').update(target).digest('hex'),
7921
7996
  )
7922
- const headers = producers.map((producer) => {
7923
- const stem = path.join(
7924
- root,
7925
- '.build',
7926
- 'peach-cxx-headers',
7927
- `${producer}-Swift`,
7928
- )
7929
- return {
7930
- producer,
7931
- original: `${stem}.original.h`,
7932
- emitted: `${stem}.h`,
7933
- }
7934
- })
7997
+ const headers = producers.map(headerPaths)
7935
7998
  const fingerprint = (): string | undefined => {
7936
7999
  const digest = createHash('sha256').update(recipe)
7937
- for (const { emitted } of headers) {
7938
- if (!existsSync(emitted)) return
8000
+ for (const { original, emitted } of headers) {
8001
+ if (!existsSync(original) || !existsSync(emitted)) return
7939
8002
  digest.update(
7940
8003
  createHash('sha256').update(readFileSync(emitted)).digest(),
7941
8004
  )
@@ -7950,43 +8013,32 @@ function compileSwiftProjectOnce(
7950
8013
  continue
7951
8014
  if (!options.project) rmSync(receipt, { force: true })
7952
8015
  // swiftpm doesn't track custom objc header paths as outputs.
7953
- for (const { producer, original } of headers)
7954
- if (!existsSync(original))
8016
+ for (const header of headers) {
8017
+ if (compiler && existsSync(header.original)) publishHeader(header)
8018
+ if (!existsSync(header.original))
7955
8019
  rmSync(
7956
8020
  path.join(
7957
- root,
7958
- '.build',
7959
- WASM_TRIPLE,
7960
- 'release',
8021
+ path.dirname(linked),
7961
8022
  'Modules',
7962
- `${swiftTargetModuleName(producer)}.swiftmodule`,
8023
+ `${swiftTargetModuleName(header.producer)}.swiftmodule`,
7963
8024
  ),
7964
8025
  { force: true },
7965
8026
  )
8027
+ }
7966
8028
  await runCompiler(
7967
8029
  swift,
7968
8030
  [...buildArgs, '--target', target],
7969
- appOptions,
8031
+ optionsWithCompiler,
7970
8032
  SWIFTPM_PROGRESS,
7971
8033
  SWIFTPM_NOISE,
7972
8034
  )
7973
- for (const { producer, original, emitted } of headers) {
7974
- const generated = clangInterfaceHeader(readFileSync(original, 'utf8'))
7975
- writeBuildFile(
7976
- emitted,
7977
- withoutSwiftDeclarations(
7978
- swiftHeaderWithSuperclassImports(generated, frameworkInterface),
7979
- new Set([
7980
- ...(preparation.nativeHeaderDeclarations[producer] ?? []),
7981
- ...nativelyDeclaredFunctions(generated, nativeHeaders),
7982
- ]),
7983
- `#import <${producer}/${producer}.h>`,
7984
- ),
7985
- )
7986
- }
8035
+ if (!compiler) for (const header of headers) publishHeader(header)
7987
8036
  if (!options.project) {
8037
+ const checkpoint = fingerprint()
8038
+ if (checkpoint === undefined)
8039
+ throw new Error(`missing Swift headers after building ${target}`)
7988
8040
  mkdirSync(checkpoints, { recursive: true })
7989
- writeFileSync(`${receipt}.partial`, fingerprint()!)
8041
+ writeFileSync(`${receipt}.partial`, checkpoint)
7990
8042
  renameSync(`${receipt}.partial`, receipt)
7991
8043
  }
7992
8044
  }
@@ -7994,11 +8046,32 @@ function compileSwiftProjectOnce(
7994
8046
  await runCompiler(
7995
8047
  swift,
7996
8048
  buildArgs,
7997
- appOptions,
8049
+ optionsWithCompiler,
7998
8050
  SWIFTPM_PROGRESS,
7999
8051
  SWIFTPM_NOISE,
8000
8052
  )
8001
8053
  }
8054
+ const compileApp = () =>
8055
+ preparation.headerCompiler
8056
+ ? withSwiftHeaderCompiler(
8057
+ root,
8058
+ options.toolchainBin,
8059
+ recipe,
8060
+ new Map(
8061
+ preparation.headerBuilds[0]!.producers.map((producer) => {
8062
+ const paths = headerPaths(producer)
8063
+ return [
8064
+ swiftTargetModuleName(producer),
8065
+ {
8066
+ header: paths.original,
8067
+ publish: () => publishHeader(paths),
8068
+ },
8069
+ ]
8070
+ }),
8071
+ ),
8072
+ runApp,
8073
+ )
8074
+ : runApp()
8002
8075
  try {
8003
8076
  await compileApp()
8004
8077
  } catch (error) {
@@ -8083,6 +8156,9 @@ function compileSwiftProjectOnce(
8083
8156
  releaseDirectory: path.dirname(linked),
8084
8157
  moduleRoot: frameworkRoot,
8085
8158
  toolchainBin: options.toolchainBin,
8159
+ swiftCompiler: preparation.headerCompiler
8160
+ ? path.join(root, SWIFT_HEADER_COMPILER_WRAPPER)
8161
+ : path.join(options.toolchainBin, 'swiftc'),
8086
8162
  sysroot: swiftSdkPaths(frameworkRoot, options.toolchainBin).sysroot,
8087
8163
  sdk: swiftModuleSdk(frameworkRoot),
8088
8164
  staticClangTargets: input.staticClangTargets ?? [],
@@ -11,6 +11,8 @@ import { readIosSdkTree } from './swift-objc-sdk-tree'
11
11
  // digest.
12
12
  export const SWIFT_DIGEST_SOURCES = [
13
13
  'swift-compile.ts',
14
+ 'swift-header-compiler.ts',
15
+ 'swift-header-dependencies.ts',
14
16
  'swift-reproducible.ts',
15
17
  'write-build-file.ts',
16
18
  'xcode-header-search.ts',
@@ -55,6 +55,7 @@ export async function compileGuestLink(options: {
55
55
  readonly releaseDirectory: string
56
56
  readonly moduleRoot: string
57
57
  readonly toolchainBin: string
58
+ readonly swiftCompiler: string
58
59
  readonly sysroot: string
59
60
  readonly sdk: { readonly wasmSdkId: string; readonly wasmSdkChecksum: string }
60
61
  readonly staticClangTargets: readonly string[]
@@ -263,6 +264,7 @@ export async function compileGuestLink(options: {
263
264
  buildDirectory: options.buildDirectory,
264
265
  directory,
265
266
  toolchainBin: options.toolchainBin,
267
+ swiftCompiler: options.swiftCompiler,
266
268
  objects: selectedSource.map((artifact) => artifact.path),
267
269
  })
268
270
  const links = sourceGuestRuntimeLinks({
@@ -51,6 +51,7 @@ export function sourceGuestClangLinkOptions(options: {
51
51
  buildDirectory: string
52
52
  directory: string
53
53
  toolchainBin: string
54
+ swiftCompiler: string
54
55
  objects: readonly string[]
55
56
  }): Map<string, string[]> {
56
57
  const wanted = new Set(options.objects.map((file) => path.resolve(file)))
@@ -95,8 +96,7 @@ export function sourceGuestClangLinkOptions(options: {
95
96
  if (command.tool === 'shell') {
96
97
  if (
97
98
  !command.args.length ||
98
- realpathSync(command.args[0]!) !==
99
- realpathSync(path.join(options.toolchainBin, 'swiftc'))
99
+ realpathSync(command.args[0]!) !== realpathSync(options.swiftCompiler)
100
100
  )
101
101
  throw new Error(`unsupported source object producer ${file}`)
102
102
  continue