peachsim 0.1.1964 → 0.1.1965

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 (83) 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 +156 -28
  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 +154 -27
  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 +155 -28
  31. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  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 +1 -1
  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 +1 -1
  47. package/dist-lib/native-app-identity-project.cjs +1 -1
  48. package/dist-lib/native-app-identity-project.mjs +1 -1
  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 +24 -24
  60. package/dist-lib/public-origins-lib.json +53 -53
  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 +156 -28
  68. package/dist-lib/swift-compile.cjs +1 -1
  69. package/dist-lib/swift-compile.mjs +1 -1
  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 +153 -26
  77. package/dist-lib/vite.cjs +1 -1
  78. package/dist-lib/worklet-executable.cjs +1 -1
  79. package/dist-lib/worklet-executable.mjs +1 -1
  80. package/package.json +1 -1
  81. package/src/swift-packages.ts +13 -1
  82. package/src/swift-standin-emit.ts +16 -3
  83. package/src/swift-standins.ts +144 -17
@@ -43,10 +43,12 @@ import {
43
43
  type ObjcSurface,
44
44
  } from './swift-objc-standin'
45
45
  import {
46
+ clangImportNames,
46
47
  moduleMapName,
47
48
  swiftManifestDeclarations,
48
49
  swiftTargetModuleName,
49
50
  } from './swift-package'
51
+ import { swiftBinaryOnDisk, type SwiftPackageBinary } from './swift-packages'
50
52
  import { swiftSharedSdkRoot } from './swift-shared-sdk'
51
53
  import { STANDIN_SOURCE_DIGEST, standinSourceDigest } from './swift-standin-digest'
52
54
  import {
@@ -68,7 +70,6 @@ import {
68
70
  swiftPackageCacheOptions,
69
71
  } from './swift-toolchain'
70
72
  import { simulatorNativeLibrary } from './swift-xcframework'
71
- import type { SwiftPackageBinary } from './swift-packages'
72
73
 
73
74
  const TRIPLE = 'wasm32-unknown-wasip1'
74
75
  // every stand-in artifact and temporary workspace belongs to peach.
@@ -106,6 +107,7 @@ interface Toolchain {
106
107
  interface NativeFrameworkInputs {
107
108
  dirs: string[]
108
109
  digest: string
110
+ surfaces: Map<string, ObjcSurface>
109
111
  }
110
112
 
111
113
  function exec(file: string, args: string[], cwd?: string): string {
@@ -398,13 +400,13 @@ export function binaryHeaderSearchPaths(
398
400
  ): { frameworks: string[]; headers: string[] } {
399
401
  const artifact = xcframework(binary)
400
402
  const slice = simulatorSlice(artifact.dir)
401
- const found = surfaces(artifact.dir, slice)
403
+ const found = surfaces(artifact.dir, binary.target, slice)
402
404
  const frameworks = [
403
405
  ...new Set(
404
406
  found.flatMap((surface) =>
405
407
  'modulemap' in surface &&
406
408
  path.basename(path.dirname(surface.modulemap)) === 'Modules'
407
- ? [path.dirname(path.dirname(surface.modulemap))]
409
+ ? [path.dirname(surface.headers)]
408
410
  : [],
409
411
  ),
410
412
  ),
@@ -497,8 +499,21 @@ export function binaryHeaderSearchPaths(
497
499
  path.join(pending, 'frameworks', path.basename(framework), part),
498
500
  { recursive: true, dereference: true },
499
501
  )
502
+ const surface = found.find(
503
+ (item) => 'headers' in item && path.dirname(item.headers) === framework,
504
+ )
505
+ if (surface && 'modulemap' in surface) {
506
+ const modules = path.join(
507
+ pending,
508
+ 'frameworks',
509
+ path.basename(framework),
510
+ 'Modules',
511
+ )
512
+ fs.mkdirSync(modules, { recursive: true })
513
+ fs.copyFileSync(surface.modulemap, path.join(modules, 'module.modulemap'))
514
+ }
500
515
  }
501
- for (const [index, directory] of headers.entries())
516
+ for (const [index, directory] of headers.entries()) {
502
517
  fs.cpSync(directory, path.join(pending, 'headers', String(index)), {
503
518
  recursive: true,
504
519
  dereference: true,
@@ -512,6 +527,15 @@ export function binaryHeaderSearchPaths(
512
527
  }
513
528
  : {}),
514
529
  })
530
+ const surface = found.find(
531
+ (item) => 'headers' in item && item.headers === directory,
532
+ )
533
+ if (surface && 'modulemap' in surface)
534
+ fs.copyFileSync(
535
+ surface.modulemap,
536
+ path.join(pending, 'headers', String(index), 'module.modulemap'),
537
+ )
538
+ }
515
539
  const contents = createHash('sha256')
516
540
  for (const relative of fs
517
541
  .readdirSync(pending, { recursive: true, encoding: 'utf8' })
@@ -600,6 +624,7 @@ function simulatorSlice(xcframeworkDir: string): string | null {
600
624
 
601
625
  function surfaces(
602
626
  xcframeworkDir: string,
627
+ target: string,
603
628
  slice = simulatorSlice(xcframeworkDir),
604
629
  ): SliceSurface[] {
605
630
  const standaloneMap = path.join(xcframeworkDir, 'module.modulemap')
@@ -628,7 +653,20 @@ function surfaces(
628
653
  )
629
654
  const chosen =
630
655
  interfaces.find((name) => name.startsWith('arm64-')) ?? interfaces[0] ?? null
631
- const modulemap = path.join(framework, 'Modules', 'module.modulemap')
656
+ let modulemap = path.join(framework, 'Modules', 'module.modulemap')
657
+ const headers = path.join(framework, 'Headers')
658
+ if (
659
+ !fs.existsSync(modulemap) &&
660
+ files(headers, (name) => name.endsWith('.h')).length
661
+ ) {
662
+ const umbrella = fs.existsSync(path.join(headers, `${module}.h`))
663
+ ? `umbrella header "${module}.h"`
664
+ : 'umbrella "Headers"'
665
+ modulemap = generatedModuleMap(
666
+ `framework module ${module} { ${umbrella} export * module * { export * } }\n`,
667
+ true,
668
+ )
669
+ }
632
670
  if (chosen) {
633
671
  const privateInterface = path.join(
634
672
  swiftmodule,
@@ -667,9 +705,34 @@ function surfaces(
667
705
  const module = moduleMapName(fs.readFileSync(modulemap, 'utf8'))
668
706
  if (module) found.push(headerSurface(module, modulemap, path.dirname(modulemap)))
669
707
  }
708
+ if (found.length === 0 && files(headers, (name) => name.endsWith('.h')).length) {
709
+ const module = swiftTargetModuleName(target)
710
+ const modulemap = generatedModuleMap(
711
+ `module ${module} { umbrella "." export * }\n`,
712
+ false,
713
+ )
714
+ found.push(headerSurface(module, modulemap, headers))
715
+ }
670
716
  return found
671
717
  }
672
718
 
719
+ function generatedModuleMap(text: string, framework: boolean): string {
720
+ const dir = path.join(
721
+ cacheDir,
722
+ 'modulemaps',
723
+ key(text),
724
+ framework ? 'Modules' : 'Headers',
725
+ )
726
+ fs.mkdirSync(dir, { recursive: true })
727
+ const file = path.join(dir, 'module.modulemap')
728
+ if (!fs.existsSync(file)) {
729
+ const pending = `${file}.${process.pid}.tmp`
730
+ fs.writeFileSync(pending, text)
731
+ fs.renameSync(pending, file)
732
+ }
733
+ return file
734
+ }
735
+
673
736
  // the peach modules an interface imports, compiled for wasm: a distribution
674
737
  // ships them; a checkout builds the ones named into its own build directory,
675
738
  // with the flags scripts/build.sh uses, so the two share one build.
@@ -1253,6 +1316,8 @@ function objcStandin(
1253
1316
  toolchain: Toolchain,
1254
1317
  work: string,
1255
1318
  behavior: ReadonlyMap<string, StandinBehavior>,
1319
+ frameworks: NativeFrameworkInputs,
1320
+ siblings: ReadonlySet<string>,
1256
1321
  ): SwiftStandin {
1257
1322
  const view = objcView(
1258
1323
  surface,
@@ -1260,13 +1325,35 @@ function objcStandin(
1260
1325
  path.join(toolchain.moduleRoot, 'ios-simulator-stdlib'),
1261
1326
  cacheDir,
1262
1327
  path.join(work, 'objc'),
1328
+ undefined,
1329
+ frameworks.dirs,
1263
1330
  )
1264
1331
  // the modules its headers import carry the types its declarations name; a
1265
1332
  // module peach does not ship stays unimported and drops what needs it
1266
1333
  const provided = new Set(swiftPeachModules(toolchain.moduleRoot))
1267
1334
  const headerModules = view.imports.filter(
1268
- (name) => !STANDIN_IMPORTS.includes(name) && provided.has(name),
1335
+ (name) =>
1336
+ !STANDIN_IMPORTS.includes(name) && (provided.has(name) || siblings.has(name)),
1269
1337
  )
1338
+ const dependencyGraphs = headerModules.flatMap((module) => {
1339
+ const dependency = frameworks.surfaces.get(module)
1340
+ if (!dependency || module === surface.module) return []
1341
+ return objcView(
1342
+ {
1343
+ module: dependency.module,
1344
+ modulemap: dependency.modulemap,
1345
+ headers: dependency.headers,
1346
+ },
1347
+ toolchain.toolchainBin,
1348
+ path.join(toolchain.moduleRoot, 'ios-simulator-stdlib'),
1349
+ cacheDir,
1350
+ path.join(work, 'dependencies', module),
1351
+ undefined,
1352
+ frameworks.dirs.filter(
1353
+ (dir) => !fs.existsSync(path.join(dir, `${module}.framework`)),
1354
+ ),
1355
+ ).graphs
1356
+ })
1270
1357
  return graphStandin(
1271
1358
  surface.module,
1272
1359
  view.graphs,
@@ -1284,6 +1371,12 @@ function objcStandin(
1284
1371
  ) ?? []),
1285
1372
  ]),
1286
1373
  ],
1374
+ false,
1375
+ new Map(),
1376
+ null,
1377
+ new Map(),
1378
+ new Map(),
1379
+ dependencyGraphs,
1287
1380
  )
1288
1381
  }
1289
1382
 
@@ -1312,6 +1405,7 @@ function graphStandin(
1312
1405
  placeholder: { peachImports: string[]; exported: string[] } | null = null,
1313
1406
  inheritedConformances: ReadonlyMap<string, ReadonlySet<string>> = new Map(),
1314
1407
  projections: ReadonlyMap<string, string> = new Map(),
1408
+ dependencyGraphs: SymbolGraph[] = [],
1315
1409
  ): SwiftStandin {
1316
1410
  const paths = new Set(
1317
1411
  graphs.flatMap((graph) =>
@@ -1381,6 +1475,7 @@ function graphStandin(
1381
1475
  objcProperties,
1382
1476
  inheritedConformances,
1383
1477
  projections,
1478
+ dependencyGraphs,
1384
1479
  ...(placeholder
1385
1480
  ? { exported: placeholder.exported, placeholder: binary.placeholder!.gap }
1386
1481
  : {}),
@@ -2203,6 +2298,11 @@ async function sourceStandins(
2203
2298
  })),
2204
2299
  })
2205
2300
  } else {
2301
+ const absent = missingArtifactGap(binary)
2302
+ if (absent !== null) {
2303
+ gaps.set(binary.target, absent)
2304
+ continue
2305
+ }
2206
2306
  const resolved = xcframework(binary)
2207
2307
  const dir = path.join(artifact, String(index), path.basename(resolved.dir))
2208
2308
  fs.cpSync(resolved.dir, dir, { recursive: true, dereference: true })
@@ -2390,7 +2490,9 @@ export function standinGenerationInputs(
2390
2490
  try {
2391
2491
  return binary.publicHeaders !== undefined || binary.placeholder !== undefined
2392
2492
  ? [swiftTargetModuleName(binary.target)]
2393
- : surfaces(xcframework(binary).dir).map((surface) => surface.module)
2493
+ : surfaces(xcframework(binary).dir, binary.target).map(
2494
+ (surface) => surface.module,
2495
+ )
2394
2496
  } catch {
2395
2497
  return []
2396
2498
  }
@@ -2434,7 +2536,9 @@ export function standinGenerationInputs(
2434
2536
  try {
2435
2537
  if (
2436
2538
  binary.publicHeaders === undefined &&
2437
- surfaces(xcframework(binary).dir).some((surface) => surface.kind === 'swift')
2539
+ surfaces(xcframework(binary).dir, binary.target).some(
2540
+ (surface) => surface.kind === 'swift',
2541
+ )
2438
2542
  )
2439
2543
  parts.push(`interface-emulation/${WASI_EMULATION.join(',')}`)
2440
2544
  parts.push(
@@ -2468,6 +2572,14 @@ export function standinGenerationInputs(
2468
2572
  return createHash('sha256').update(parts.join('\0')).digest('hex')
2469
2573
  }
2470
2574
 
2575
+ // a local artifact a script downloads or builds is absent from a fresh
2576
+ // checkout. Xcode fails on it too, and its headers alone say what the app
2577
+ // calls, so peach names the path and asks for the artifact
2578
+ function missingArtifactGap(binary: SwiftPackageBinary): string | null {
2579
+ if (swiftBinaryOnDisk(binary)) return null
2580
+ return `${path.relative(process.cwd(), binary.dir) || binary.dir} is not on disk, and Xcode fails without it too; run the script that downloads or builds it, then run again`
2581
+ }
2582
+
2471
2583
  // one binary target's stand-ins, or why it has none, cached by what they are
2472
2584
  // generated from. surfaces peach already ships (by target name or by the
2473
2585
  // module names the slice carries, which differ: _FirebaseCore vends
@@ -2482,11 +2594,8 @@ async function binaryStandins(
2482
2594
  siblings: ReadonlySet<string>,
2483
2595
  ): Promise<SwiftStandin[] | string> {
2484
2596
  if (provided.has(binary.target)) return []
2485
- // a local artifact a script downloads or builds is absent from a fresh
2486
- // checkout. Xcode fails on it too, and its headers alone say what the app
2487
- // calls, so peach names the path and asks for the artifact
2488
- if (!binary.url && !fs.existsSync(binary.dir))
2489
- return `${path.relative(process.cwd(), binary.dir) || binary.dir} is not on disk, and Xcode fails without it too; run the script that downloads or builds it, then run again`
2597
+ const absent = missingArtifactGap(binary)
2598
+ if (absent !== null) return absent
2490
2599
  fs.mkdirSync(cacheDir, { recursive: true })
2491
2600
  const work = fs.mkdtempSync(path.join(cacheDir, 'work-'))
2492
2601
  let all: Surface[]
@@ -2539,7 +2648,7 @@ async function binaryStandins(
2539
2648
  ].join('\0')
2540
2649
  } else {
2541
2650
  const artifact = xcframework(binary)
2542
- all = surfaces(artifact.dir)
2651
+ all = surfaces(artifact.dir, binary.target)
2543
2652
  digest = artifact.digest
2544
2653
  }
2545
2654
  } catch (error) {
@@ -2559,7 +2668,8 @@ async function binaryStandins(
2559
2668
  )
2560
2669
  hash.update(digest)
2561
2670
  hash.update([...siblings].sort().join('\0'))
2562
- if (found.some((surface) => surface.kind === 'mixed')) hash.update(frameworks.digest)
2671
+ if (found.some((surface) => surface.kind === 'mixed' || surface.kind === 'objc'))
2672
+ hash.update(frameworks.digest)
2563
2673
  for (const surface of found) {
2564
2674
  hash.update(`${surface.kind}\0${surface.module}\0`)
2565
2675
  for (const file of surface.kind === 'swift'
@@ -2652,6 +2762,8 @@ async function binaryStandins(
2652
2762
  toolchain,
2653
2763
  dir,
2654
2764
  new Map(Object.entries(configured.get(surface.module) ?? {})),
2765
+ frameworks,
2766
+ siblings,
2655
2767
  )
2656
2768
  : binary.cxxHeaders
2657
2769
  ? await cxxStandin(surface, binary, toolchain, dir)
@@ -2738,6 +2850,7 @@ async function buildStandins(
2738
2850
  fs.mkdirSync(cacheDir, { recursive: true })
2739
2851
  const modules = fs.mkdtempSync(path.join(cacheDir, 'modules-'))
2740
2852
  const frameworkDirs = new Set<string>()
2853
+ const frameworkSurfaces = new Map<string, ObjcSurface>()
2741
2854
  const frameworkInputs: string[] = []
2742
2855
  const byModule = new Map(
2743
2856
  binaries.map((binary) => [swiftTargetModuleName(binary.target), binary]),
@@ -2762,18 +2875,31 @@ async function buildStandins(
2762
2875
  frameworkInputs.push(`${binary.target}\0${artifact.digest}`)
2763
2876
  const imports = new Set<string>()
2764
2877
  interfaceImports.set(binary, imports)
2765
- for (const surface of surfaces(artifact.dir)) {
2878
+ for (const surface of surfaces(artifact.dir, binary.target)) {
2766
2879
  byModule.set(surface.module, binary)
2767
2880
  if (surface.kind === 'swift' || surface.kind === 'mixed')
2768
2881
  for (const module of swiftImportNames(
2769
2882
  fs.readFileSync(surface.interface, 'utf8'),
2770
2883
  ))
2771
2884
  imports.add(module)
2885
+ if (surface.kind === 'objc' || surface.kind === 'mixed')
2886
+ for (const file of files(surface.headers, (name) => name.endsWith('.h')))
2887
+ for (const module of clangImportNames(
2888
+ fs.readFileSync(path.join(surface.headers, file), 'utf8'),
2889
+ ))
2890
+ imports.add(module)
2772
2891
  if (surface.kind === 'c') continue
2892
+ if (surface.kind === 'objc' || surface.kind === 'mixed')
2893
+ frameworkSurfaces.set(surface.module, surface)
2894
+ if (
2895
+ surface.kind !== 'swift' &&
2896
+ path.basename(path.dirname(surface.modulemap)) !== 'Modules'
2897
+ )
2898
+ continue
2773
2899
  frameworkDirs.add(
2774
2900
  surface.kind === 'swift'
2775
2901
  ? path.resolve(surface.interface, '../../../..')
2776
- : path.resolve(surface.modulemap, '../../..'),
2902
+ : path.resolve(surface.headers, '../..'),
2777
2903
  )
2778
2904
  }
2779
2905
  } catch {
@@ -2784,6 +2910,7 @@ async function buildStandins(
2784
2910
  const frameworks: NativeFrameworkInputs = {
2785
2911
  dirs: [...frameworkDirs].sort(),
2786
2912
  digest: createHash('sha256').update(frameworkInputs.sort().join('\0')).digest('hex'),
2913
+ surfaces: frameworkSurfaces,
2787
2914
  }
2788
2915
  // another binary's module a swift interface imports: its stand-in is built
2789
2916
  // first and imported, as the vendor framework imports the other framework