peachsim 0.1.2421 → 0.1.2422

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 (94) 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 +1 -1
  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 +1 -1
  11. package/dist-lib/bridge-contract.cjs +1 -1
  12. package/dist-lib/bridge-contract.mjs +1 -1
  13. package/dist-lib/bundle-channel.cjs +4317 -3935
  14. package/dist-lib/capture-contract.cjs +1 -1
  15. package/dist-lib/capture-contract.mjs +1 -1
  16. package/dist-lib/cloud-contract.cjs +1 -1
  17. package/dist-lib/cloud-contract.mjs +1 -1
  18. package/dist-lib/cloud-test-args.cjs +1 -1
  19. package/dist-lib/cloud-test-args.mjs +1 -1
  20. package/dist-lib/cloud.cjs +1 -1
  21. package/dist-lib/cloud.mjs +1 -1
  22. package/dist-lib/config.cjs +1 -1
  23. package/dist-lib/config.mjs +1 -1
  24. package/dist-lib/detox/index.cjs +1 -1
  25. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  26. package/dist-lib/expo-swift-bundle.cjs +3343 -2961
  27. package/dist-lib/expo-swift-metadata.cjs +1 -1
  28. package/dist-lib/expo-swift-metadata.mjs +1 -1
  29. package/dist-lib/home-paths.cjs +1 -1
  30. package/dist-lib/host/bridge-host.cjs +4199 -3817
  31. package/dist-lib/host/fetch-proxy-handler.cjs +24 -3
  32. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  33. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  34. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  35. package/dist-lib/host/websocket-proxy.cjs +1 -1
  36. package/dist-lib/index.cjs +24 -3
  37. package/dist-lib/jump-to-source-babel.cjs +1 -1
  38. package/dist-lib/jump-to-source-native.cjs +1 -1
  39. package/dist-lib/kotlin-host.cjs +1 -1
  40. package/dist-lib/menu.cjs +1 -1
  41. package/dist-lib/menu.mjs +1 -1
  42. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  43. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  44. package/dist-lib/metro-production-bundle.cjs +1 -1
  45. package/dist-lib/metro-production-bundle.mjs +1 -1
  46. package/dist-lib/metro.cjs +24 -3
  47. package/dist-lib/native-app-identity-project.cjs +2 -2
  48. package/dist-lib/native-app-identity-project.mjs +231 -212
  49. package/dist-lib/native-app-identity.cjs +1 -1
  50. package/dist-lib/native-app-identity.mjs +1 -1
  51. package/dist-lib/native-firebase-metadata.cjs +1 -1
  52. package/dist-lib/native-firebase-metadata.mjs +1 -1
  53. package/dist-lib/pdfium-raster.cjs +1 -1
  54. package/dist-lib/pdfium-raster.mjs +1 -1
  55. package/dist-lib/plist.cjs +1 -1
  56. package/dist-lib/plist.mjs +1 -1
  57. package/dist-lib/profiles.cjs +1 -1
  58. package/dist-lib/public-brand.cjs +1 -1
  59. package/dist-lib/public-origins-lib-esm.json +30 -25
  60. package/dist-lib/public-origins-lib.json +77 -56
  61. package/dist-lib/react-native-host-modules.cjs +1 -1
  62. package/dist-lib/react-native-host-modules.mjs +1 -1
  63. package/dist-lib/reap-browser.cjs +1 -1
  64. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  65. package/dist-lib/sdk.cjs +1 -1
  66. package/dist-lib/sdk.mjs +1 -1
  67. package/dist-lib/skills.cjs +4851 -4468
  68. package/dist-lib/swift-compile.cjs +1261 -888
  69. package/dist-lib/swift-compile.mjs +1231 -848
  70. package/dist-lib/swift-package.cjs +1 -1
  71. package/dist-lib/swift-package.mjs +1 -1
  72. package/dist-lib/swift-submit.cjs +1 -1
  73. package/dist-lib/swift-submit.mjs +1 -1
  74. package/dist-lib/swift-toolchain.cjs +1 -1
  75. package/dist-lib/swift.cjs +1 -1
  76. package/dist-lib/vite-swift.cjs +2712 -2347
  77. package/dist-lib/vite.cjs +24 -3
  78. package/dist-lib/worklet-executable.cjs +1 -1
  79. package/dist-lib/worklet-executable.mjs +1 -1
  80. package/dist-types/packages/peach-engine/src/engine/native-layout.d.ts +1 -1
  81. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +0 -10
  82. package/dist-types/packages/peach-engine/src/render-worker/compositor-runtime/layer-claims.d.ts +2 -1
  83. package/kotlin/sdk.tar.gz +0 -0
  84. package/package.json +1 -1
  85. package/src/expo-kotlin-bundle.ts +1 -1
  86. package/src/native-static-libraries.ts +51 -4
  87. package/src/swift-compile.ts +184 -107
  88. package/src/swift-compiler-digest.ts +2 -0
  89. package/src/swift-guest-compile.ts +2 -0
  90. package/src/swift-guest-source-inputs.ts +2 -2
  91. package/src/swift-header-compiler.ts +185 -0
  92. package/src/swift-header-dependencies.ts +174 -0
  93. package/src/swift-objc-compile.ts +18 -24
  94. 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.
@@ -3070,7 +3078,6 @@ const FOUNDATION_OVERLAY_TYPES = new Set([
3070
3078
  // existing overlay globals retain their declaration and runtime owner.
3071
3079
  const FOUNDATION_OVERLAY_GLOBALS = new Set([
3072
3080
  'CFBridgingRetain',
3073
- 'NSASCIIStringEncoding',
3074
3081
  'NSAllHashTableObjects',
3075
3082
  'NSAllMapTableKeys',
3076
3083
  'NSAllMapTableValues',
@@ -3149,21 +3156,16 @@ const FOUNDATION_OVERLAY_GLOBALS = new Set([
3149
3156
  'NSHashTableWeakMemory',
3150
3157
  'NSHebrewCalendar',
3151
3158
  'NSHostByteOrder',
3152
- 'NSISO2022JPStringEncoding',
3153
3159
  'NSISO8601Calendar',
3154
- 'NSISOLatin1StringEncoding',
3155
- 'NSISOLatin2StringEncoding',
3156
3160
  'NSIndianCalendar',
3157
3161
  'NSIslamicCalendar',
3158
3162
  'NSIslamicCivilCalendar',
3159
3163
  'NSItemProviderPreferredImageSizeKey',
3160
3164
  'NSJapaneseCalendar',
3161
- 'NSJapaneseEUCStringEncoding',
3162
3165
  'NSLoadedClasses',
3163
3166
  'NSLocalizedFailureErrorKey',
3164
3167
  'NSLogPageSize',
3165
3168
  'NSMACHOperatingSystem',
3166
- 'NSMacOSRomanStringEncoding',
3167
3169
  'NSMapGet',
3168
3170
  'NSMapInsert',
3169
3171
  'NSMapInsertIfAbsent',
@@ -3175,10 +3177,8 @@ const FOUNDATION_OVERLAY_GLOBALS = new Set([
3175
3177
  'NSMapTableStrongMemory',
3176
3178
  'NSMapTableWeakMemory',
3177
3179
  'NSMultipleUnderlyingErrorsKey',
3178
- 'NSNEXTSTEPStringEncoding',
3179
3180
  'NSNextHashEnumeratorItem',
3180
3181
  'NSNextMapEnumeratorPair',
3181
- 'NSNonLossyASCIIStringEncoding',
3182
3182
  'NSNonOwnedPointerHashCallBacks',
3183
3183
  'NSNonOwnedPointerMapKeyCallBacks',
3184
3184
  'NSNonOwnedPointerMapValueCallBacks',
@@ -3200,12 +3200,10 @@ const FOUNDATION_OVERLAY_GLOBALS = new Set([
3200
3200
  'NSPointerToStructHashCallBacks',
3201
3201
  'NSPropertyListErrorMaximum',
3202
3202
  'NSPropertyListErrorMinimum',
3203
- 'NSProprietaryStringEncoding',
3204
3203
  'NSProtocolFromString',
3205
3204
  'NSRepublicOfChinaCalendar',
3206
3205
  'NSResetHashTable',
3207
3206
  'NSResetMapTable',
3208
- 'NSShiftJISStringEncoding',
3209
3207
  'NSSolarisOperatingSystem',
3210
3208
  'NSStringFromHashTable',
3211
3209
  'NSStringFromMapTable',
@@ -3241,7 +3239,6 @@ const FOUNDATION_OVERLAY_GLOBALS = new Set([
3241
3239
  'NSSwapLong',
3242
3240
  'NSSwapLongLong',
3243
3241
  'NSSwapShort',
3244
- 'NSSymbolStringEncoding',
3245
3242
  'NSTextCheckingAllCustomTypes',
3246
3243
  'NSTextCheckingAllSystemTypes',
3247
3244
  'NSTextCheckingAllTypes',
@@ -3259,13 +3256,6 @@ const FOUNDATION_OVERLAY_GLOBALS = new Set([
3259
3256
  'NSURLProtectionSpaceHTTPSProxy',
3260
3257
  'NSURLProtectionSpaceSOCKSProxy',
3261
3258
  'NSURLSessionUploadTaskResumeData',
3262
- 'NSUTF16BigEndianStringEncoding',
3263
- 'NSUTF16LittleEndianStringEncoding',
3264
- 'NSUTF16StringEncoding',
3265
- 'NSUTF32BigEndianStringEncoding',
3266
- 'NSUTF32LittleEndianStringEncoding',
3267
- 'NSUTF32StringEncoding',
3268
- 'NSUTF8StringEncoding',
3269
3259
  'NSUbiquitousFileErrorMaximum',
3270
3260
  'NSUbiquitousFileErrorMinimum',
3271
3261
  'NSUbiquitousKeyValueStoreAccountChange',
@@ -3277,17 +3267,11 @@ const FOUNDATION_OVERLAY_GLOBALS = new Set([
3277
3267
  'NSUndefinedDateComponent',
3278
3268
  'NSUndoCloseGroupingRunLoopOrdering',
3279
3269
  'NSUndoManagerGroupIsDiscardableKey',
3280
- 'NSUnicodeStringEncoding',
3281
3270
  'NSUserActivityErrorMaximum',
3282
3271
  'NSUserActivityErrorMinimum',
3283
3272
  'NSValidationErrorMaximum',
3284
3273
  'NSValidationErrorMinimum',
3285
3274
  'NSWindows95OperatingSystem',
3286
- 'NSWindowsCP1250StringEncoding',
3287
- 'NSWindowsCP1251StringEncoding',
3288
- 'NSWindowsCP1252StringEncoding',
3289
- 'NSWindowsCP1253StringEncoding',
3290
- 'NSWindowsCP1254StringEncoding',
3291
3275
  'NSWindowsNTOperatingSystem',
3292
3276
  'NSWrapCalendarComponents',
3293
3277
  'NSXPCConnectionCodeSigningRequirementFailure',
@@ -4225,6 +4209,19 @@ type Lexical =
4225
4209
  | { kind: 'block'; depth: number }
4226
4210
  | { kind: 'string'; hashes: number; multiline: boolean }
4227
4211
  | { kind: 'regex'; hashes: number }
4212
+ const SWIFT_SCAN_KEYWORDS: Readonly<Record<string, string>> = {
4213
+ c: 'class',
4214
+ e: 'extension',
4215
+ o: 'override',
4216
+ i: 'import',
4217
+ f: 'func',
4218
+ U: 'UIApplicationMain',
4219
+ F: 'Foundation',
4220
+ C: 'CoreFoundation',
4221
+ O: 'ObjectiveC',
4222
+ _: '_LocationEssentials',
4223
+ }
4224
+
4228
4225
  function swiftCodeScan(source: string): {
4229
4226
  lineStarts: Set<number>
4230
4227
  tokens: number[]
@@ -4310,29 +4307,10 @@ function swiftCodeScan(source: string): {
4310
4307
  else top.parens--
4311
4308
  i++
4312
4309
  } 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
4310
+ const keyword = SWIFT_SCAN_KEYWORDS[char!]
4334
4311
  if (
4335
4312
  keyword &&
4313
+ source.startsWith(keyword, i) &&
4336
4314
  !/[\w$]/.test(source[i - 1] ?? '') &&
4337
4315
  !/[\w$]/.test(source[i + keyword.length] ?? '')
4338
4316
  ) {
@@ -4530,9 +4508,11 @@ export function writeSwiftProject(
4530
4508
  input: SwiftCompileInput,
4531
4509
  moduleRoot: string,
4532
4510
  prebuilt?: SwiftFrameworkProducts,
4511
+ allowHeaderCompiler = false,
4533
4512
  ): SwiftProjectPreparation & {
4534
4513
  generatedOwners: Map<string, string>
4535
4514
  targetToolset: boolean
4515
+ headerCompiler: boolean
4536
4516
  } {
4537
4517
  const nativeToolset = needsNativeToolset(input, prebuilt)
4538
4518
  if (input.headerAliases !== undefined && !isSwiftHeaderAliases(input.headerAliases))
@@ -4921,12 +4901,8 @@ export function writeSwiftProject(
4921
4901
  const reverse = new Map<string, string[]>()
4922
4902
  for (const [file, contents] of entries) {
4923
4903
  const producers = new Set<string>()
4924
- // a block-commented include is not an edge.
4925
4904
  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]!
4905
+ for (const include of nativeHeaderIncludes(contents)) {
4930
4906
  const producer = /(?:^|\/)([^/]+)-Swift\.h$/.exec(include)?.[1]
4931
4907
  if (producer && swiftTargets.has(producer)) producers.add(producer)
4932
4908
  const local = [
@@ -6347,12 +6323,13 @@ export function writeSwiftProject(
6347
6323
  }
6348
6324
  const manifestPath = path.join(layout.root, 'Package.swift')
6349
6325
  let manifest = files.get(manifestPath)!.toString()
6326
+ const manifestTargets = swiftManifestTargets(manifest, [], (file) => {
6327
+ const contents = files.get(file)
6328
+ if (contents === undefined) throw new Error(`missing compiler arguments ${file}`)
6329
+ return contents.toString()
6330
+ })
6350
6331
  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) => [
6332
+ manifestTargets.map((target) => [
6356
6333
  target.name,
6357
6334
  (target.dependencies ?? []).flatMap((dependency) =>
6358
6335
  dependency.kind === 'target' ? [dependency.name] : [],
@@ -6360,6 +6337,66 @@ export function writeSwiftProject(
6360
6337
  ]),
6361
6338
  )
6362
6339
  const producerSet = new Set([...Object.keys(nativeHeaderDeclarations), ...producers])
6340
+ let headerCompiler = allowHeaderCompiler && packages.size === 0 && producerSet.size > 0
6341
+ if (headerCompiler) {
6342
+ const clang = new Set(
6343
+ manifestTargets
6344
+ .filter(
6345
+ (target) =>
6346
+ target.systemLibrary ||
6347
+ (!swiftTargets.has(target.name) && native.has(target.name)),
6348
+ )
6349
+ .map(({ name }) => name),
6350
+ )
6351
+ const headers = swiftHeaderDependencies(
6352
+ layout.root,
6353
+ files,
6354
+ manifestTargets,
6355
+ nativeTargets,
6356
+ producerSet,
6357
+ input.headerAliases ?? {},
6358
+ )
6359
+ const nativeEdges = new Map<string, string[]>()
6360
+ const dependsOn = (from: string, to: string, seen = new Set<string>()): boolean => {
6361
+ if (from === to) return true
6362
+ if (seen.has(from)) return false
6363
+ seen.add(from)
6364
+ return [...(dependencies.get(from) ?? []), ...(nativeEdges.get(from) ?? [])].some(
6365
+ (dependency) => dependsOn(dependency, to, seen),
6366
+ )
6367
+ }
6368
+ for (const target of manifestTargets) {
6369
+ if (target.systemLibrary) continue
6370
+ const required = new Set(headers.get(target.name))
6371
+ const visited = new Set<string>()
6372
+ const imports = (name: string): void => {
6373
+ if (!clang.has(name) || visited.has(name)) return
6374
+ visited.add(name)
6375
+ for (const header of headers.get(name) ?? []) required.add(header)
6376
+ for (const dependency of dependencies.get(name) ?? []) imports(dependency)
6377
+ }
6378
+ for (const dependency of dependencies.get(target.name) ?? []) imports(dependency)
6379
+ for (const producer of required) {
6380
+ if (dependsOn(target.name, producer)) continue
6381
+ if (dependsOn(producer, target.name)) {
6382
+ headerCompiler = false
6383
+ break
6384
+ }
6385
+ const edges = nativeEdges.get(target.name) ?? []
6386
+ edges.push(producer)
6387
+ nativeEdges.set(target.name, edges)
6388
+ }
6389
+ if (!headerCompiler) break
6390
+ }
6391
+ if (headerCompiler)
6392
+ for (const [target, producers] of nativeEdges) {
6393
+ const additions = producers
6394
+ .map((producer) => `.target(name: ${JSON.stringify(producer)})`)
6395
+ .join(', ')
6396
+ manifest += `\npackage.targets.first(where: { $0.name == ${JSON.stringify(target)} })!.dependencies += [${additions}]\n`
6397
+ dependencies.get(target)!.push(...producers)
6398
+ }
6399
+ }
6363
6400
  const depths = new Map<string, number>()
6364
6401
  const orderedProducers: string[] = []
6365
6402
  const depth = (name: string): number => {
@@ -6396,12 +6433,19 @@ export function writeSwiftProject(
6396
6433
  }
6397
6434
  // normalize a dependency header before its consumers, while swiftpm schedules
6398
6435
  // 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
- }))
6436
+ const headerBuilds = headerCompiler
6437
+ ? [
6438
+ {
6439
+ target: buildProduct(SWIFT_HEADER_PRODUCTS_TARGET, orderedProducers),
6440
+ producers: orderedProducers,
6441
+ },
6442
+ ]
6443
+ : [...stages]
6444
+ .sort(([left], [right]) => left - right)
6445
+ .map(([level, producers]) => ({
6446
+ target: buildProduct(`${SWIFT_HEADER_PRODUCTS_TARGET}${level}`, producers),
6447
+ producers,
6448
+ }))
6405
6449
  const nativeBuildTargets = [
6406
6450
  ...new Set([
6407
6451
  ...(input.staticClangTargets ?? []),
@@ -6430,6 +6474,7 @@ export function writeSwiftProject(
6430
6474
  targetFailures,
6431
6475
  generatedOwners,
6432
6476
  targetToolset,
6477
+ headerCompiler,
6433
6478
  }
6434
6479
  }
6435
6480
 
@@ -7666,6 +7711,7 @@ function compileSwiftProjectOnce(
7666
7711
  input,
7667
7712
  frameworkRoot,
7668
7713
  prebuilt,
7714
+ !options.project,
7669
7715
  )
7670
7716
  // the framework objects link as inputs, so the product name its
7671
7717
  // modules autolink has no archive to load
@@ -7898,7 +7944,42 @@ function compileSwiftProjectOnce(
7898
7944
  )
7899
7945
  return value
7900
7946
  }
7901
- const compileApp = async () => {
7947
+ const headerPaths = (producer: string) => {
7948
+ const stem = path.join(
7949
+ root,
7950
+ '.build',
7951
+ 'peach-cxx-headers',
7952
+ `${producer}-Swift`,
7953
+ )
7954
+ return { producer, original: `${stem}.original.h`, emitted: `${stem}.h` }
7955
+ }
7956
+ const publishHeader = ({
7957
+ producer,
7958
+ original,
7959
+ emitted,
7960
+ }: ReturnType<typeof headerPaths>) => {
7961
+ const generated = clangInterfaceHeader(readFileSync(original, 'utf8'))
7962
+ writeBuildFile(
7963
+ emitted,
7964
+ withoutSwiftDeclarations(
7965
+ swiftHeaderWithSuperclassImports(generated, frameworkInterface),
7966
+ new Set([
7967
+ ...(preparation.nativeHeaderDeclarations[producer] ?? []),
7968
+ ...nativelyDeclaredFunctions(generated, nativeHeaders),
7969
+ ]),
7970
+ `#import <${producer}/${producer}.h>`,
7971
+ ),
7972
+ )
7973
+ }
7974
+ const recipe = createHash('sha256')
7975
+ .update(hash)
7976
+ .update(readFileSync(path.join(root, 'Package.swift')))
7977
+ .update(JSON.stringify(buildArgs))
7978
+ .digest('hex')
7979
+ const runApp = async (compiler?: Record<string, string>) => {
7980
+ const optionsWithCompiler = compiler
7981
+ ? { ...appOptions, env: { ...appOptions.env, ...compiler } }
7982
+ : appOptions
7902
7983
  // clang consumes the real emitted headers after swift finishes.
7903
7984
  // swiftpm's transitive swift module maps are not C declarations:
7904
7985
  // importing them would shadow SDK modules such as ObjectiveC.
@@ -7909,33 +7990,16 @@ function compileSwiftProjectOnce(
7909
7990
  : []),
7910
7991
  ]
7911
7992
  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
7993
  for (const { target, producers } of stages) {
7918
7994
  const receipt = path.join(
7919
7995
  checkpoints,
7920
7996
  createHash('sha256').update(target).digest('hex'),
7921
7997
  )
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
- })
7998
+ const headers = producers.map(headerPaths)
7935
7999
  const fingerprint = (): string | undefined => {
7936
8000
  const digest = createHash('sha256').update(recipe)
7937
- for (const { emitted } of headers) {
7938
- if (!existsSync(emitted)) return
8001
+ for (const { original, emitted } of headers) {
8002
+ if (!existsSync(original) || !existsSync(emitted)) return
7939
8003
  digest.update(
7940
8004
  createHash('sha256').update(readFileSync(emitted)).digest(),
7941
8005
  )
@@ -7950,43 +8014,32 @@ function compileSwiftProjectOnce(
7950
8014
  continue
7951
8015
  if (!options.project) rmSync(receipt, { force: true })
7952
8016
  // swiftpm doesn't track custom objc header paths as outputs.
7953
- for (const { producer, original } of headers)
7954
- if (!existsSync(original))
8017
+ for (const header of headers) {
8018
+ if (compiler && existsSync(header.original)) publishHeader(header)
8019
+ if (!existsSync(header.original))
7955
8020
  rmSync(
7956
8021
  path.join(
7957
- root,
7958
- '.build',
7959
- WASM_TRIPLE,
7960
- 'release',
8022
+ path.dirname(linked),
7961
8023
  'Modules',
7962
- `${swiftTargetModuleName(producer)}.swiftmodule`,
8024
+ `${swiftTargetModuleName(header.producer)}.swiftmodule`,
7963
8025
  ),
7964
8026
  { force: true },
7965
8027
  )
8028
+ }
7966
8029
  await runCompiler(
7967
8030
  swift,
7968
8031
  [...buildArgs, '--target', target],
7969
- appOptions,
8032
+ optionsWithCompiler,
7970
8033
  SWIFTPM_PROGRESS,
7971
8034
  SWIFTPM_NOISE,
7972
8035
  )
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
- }
8036
+ if (!compiler) for (const header of headers) publishHeader(header)
7987
8037
  if (!options.project) {
8038
+ const checkpoint = fingerprint()
8039
+ if (checkpoint === undefined)
8040
+ throw new Error(`missing Swift headers after building ${target}`)
7988
8041
  mkdirSync(checkpoints, { recursive: true })
7989
- writeFileSync(`${receipt}.partial`, fingerprint()!)
8042
+ writeFileSync(`${receipt}.partial`, checkpoint)
7990
8043
  renameSync(`${receipt}.partial`, receipt)
7991
8044
  }
7992
8045
  }
@@ -7994,11 +8047,32 @@ function compileSwiftProjectOnce(
7994
8047
  await runCompiler(
7995
8048
  swift,
7996
8049
  buildArgs,
7997
- appOptions,
8050
+ optionsWithCompiler,
7998
8051
  SWIFTPM_PROGRESS,
7999
8052
  SWIFTPM_NOISE,
8000
8053
  )
8001
8054
  }
8055
+ const compileApp = () =>
8056
+ preparation.headerCompiler
8057
+ ? withSwiftHeaderCompiler(
8058
+ root,
8059
+ options.toolchainBin,
8060
+ recipe,
8061
+ new Map(
8062
+ preparation.headerBuilds[0]!.producers.map((producer) => {
8063
+ const paths = headerPaths(producer)
8064
+ return [
8065
+ swiftTargetModuleName(producer),
8066
+ {
8067
+ header: paths.original,
8068
+ publish: () => publishHeader(paths),
8069
+ },
8070
+ ]
8071
+ }),
8072
+ ),
8073
+ runApp,
8074
+ )
8075
+ : runApp()
8002
8076
  try {
8003
8077
  await compileApp()
8004
8078
  } catch (error) {
@@ -8083,6 +8157,9 @@ function compileSwiftProjectOnce(
8083
8157
  releaseDirectory: path.dirname(linked),
8084
8158
  moduleRoot: frameworkRoot,
8085
8159
  toolchainBin: options.toolchainBin,
8160
+ swiftCompiler: preparation.headerCompiler
8161
+ ? path.join(root, SWIFT_HEADER_COMPILER_WRAPPER)
8162
+ : path.join(options.toolchainBin, 'swiftc'),
8086
8163
  sysroot: swiftSdkPaths(frameworkRoot, options.toolchainBin).sysroot,
8087
8164
  sdk: swiftModuleSdk(frameworkRoot),
8088
8165
  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