peachsim 0.1.2440 → 0.1.2441

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 (135) 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 +8154 -8386
  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-B27MTHKJ.mjs → acorn-FRQNHKFC.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-H6QIEJRC.mjs → chunk-4BZ3Z3IQ.mjs} +2 -2
  28. package/dist-lib/esm-chunks/{chunk-HIK3VREC.mjs → chunk-4HEUXQGM.mjs} +4 -4
  29. package/dist-lib/esm-chunks/{chunk-EATI62W3.mjs → chunk-4ZRMJ5YO.mjs} +1 -1
  30. package/dist-lib/esm-chunks/{chunk-5CZQZKYU.mjs → chunk-6A6JEVIF.mjs} +1 -1
  31. package/dist-lib/esm-chunks/{chunk-HP7DHONL.mjs → chunk-ABMB3G7I.mjs} +3 -3
  32. package/dist-lib/esm-chunks/{chunk-D4Z36DQQ.mjs → chunk-BAYRN7ZL.mjs} +1 -1
  33. package/dist-lib/esm-chunks/{chunk-R5FNLCBO.mjs → chunk-DJMWTW2B.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-X6UKJ5AX.mjs → chunk-IRMC5BCX.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-6HFWZJ6C.mjs → chunk-NPLEBOWJ.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-ADE23YGG.mjs → chunk-O4EOBXAP.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-WQISIGIX.mjs → chunk-ORYS5CC4.mjs} +1 -1
  38. package/dist-lib/esm-chunks/{chunk-PRZI3CFF.mjs → chunk-PMGJ7FLI.mjs} +1 -1
  39. package/dist-lib/esm-chunks/{chunk-ZXNBC3PZ.mjs → chunk-QUBR7LHU.mjs} +2025 -1915
  40. package/dist-lib/esm-chunks/{chunk-4U7IGWPB.mjs → chunk-QYYJESMK.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-SJFNKW3W.mjs → chunk-VAQJQDWI.mjs} +1 -1
  42. package/dist-lib/esm-chunks/{chunk-6JGALQD5.mjs → chunk-VCAJFWZD.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-RVMUQQWC.mjs → chunk-XO5GX4PI.mjs} +1 -1
  44. package/dist-lib/esm-chunks/{chunk-QECVPSP3.mjs → chunk-ZCMAKWHN.mjs} +1 -1
  45. package/dist-lib/esm-chunks/{metro-layout-parser-ZOI5PO4E.mjs → metro-layout-parser-AUAVE5VL.mjs} +3 -3
  46. package/dist-lib/expo-swift-bundle.cjs +5558 -5761
  47. package/dist-lib/expo-swift-metadata.cjs +1 -1
  48. package/dist-lib/expo-swift-metadata.mjs +7 -7
  49. package/dist-lib/home-paths.cjs +1 -1
  50. package/dist-lib/host/bridge-host.cjs +6305 -6490
  51. package/dist-lib/host/fetch-proxy-handler.cjs +13890 -13918
  52. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  53. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
  54. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  55. package/dist-lib/host/websocket-proxy.cjs +1 -1
  56. package/dist-lib/index.cjs +1 -1
  57. package/dist-lib/jump-to-source-babel.cjs +1 -1
  58. package/dist-lib/jump-to-source-native.cjs +1 -1
  59. package/dist-lib/kotlin-host.cjs +1 -1
  60. package/dist-lib/menu.cjs +1 -1
  61. package/dist-lib/menu.mjs +3 -3
  62. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  63. package/dist-lib/metro-fingerprint-registry.mjs +3 -3
  64. package/dist-lib/metro-production-bundle.cjs +1 -1
  65. package/dist-lib/metro-production-bundle.mjs +4 -4
  66. package/dist-lib/native-app-identity-project.cjs +784 -536
  67. package/dist-lib/native-app-identity-project.mjs +543 -408
  68. package/dist-lib/native-app-identity.cjs +1 -1
  69. package/dist-lib/native-app-identity.mjs +6 -6
  70. package/dist-lib/native-firebase-metadata.cjs +1 -1
  71. package/dist-lib/native-firebase-metadata.mjs +3 -3
  72. package/dist-lib/pdfium-raster.cjs +1 -1
  73. package/dist-lib/pdfium-raster.mjs +2 -2
  74. package/dist-lib/plist.cjs +1 -1
  75. package/dist-lib/plist.mjs +3 -3
  76. package/dist-lib/profiles.cjs +1 -1
  77. package/dist-lib/public-brand.cjs +1 -1
  78. package/dist-lib/public-origins-lib-esm.json +72 -70
  79. package/dist-lib/public-origins-lib.json +176 -186
  80. package/dist-lib/react-native-host-modules.cjs +1 -1
  81. package/dist-lib/react-native-host-modules.mjs +2 -2
  82. package/dist-lib/reap-browser.cjs +1 -1
  83. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  84. package/dist-lib/sdk.cjs +1 -1
  85. package/dist-lib/sdk.mjs +7 -7
  86. package/dist-lib/skills.cjs +7542 -7739
  87. package/dist-lib/swift-compile.cjs +1967 -1919
  88. package/dist-lib/swift-compile.mjs +8 -8
  89. package/dist-lib/swift-package.cjs +1 -1
  90. package/dist-lib/swift-package.mjs +3 -3
  91. package/dist-lib/swift-submit.cjs +1 -1
  92. package/dist-lib/swift-submit.mjs +5 -5
  93. package/dist-lib/swift-toolchain.cjs +3 -1
  94. package/dist-lib/swift.cjs +1 -1
  95. package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
  96. package/dist-lib/vendor/acorn.cjs +1 -1
  97. package/dist-lib/vendor/bplist-parser.cjs +1 -1
  98. package/dist-lib/vendor/ignore.cjs +1 -1
  99. package/dist-lib/vendor/magic-string.cjs +1 -1
  100. package/dist-lib/vendor/plist.cjs +1 -1
  101. package/dist-lib/vendor/smol-toml.cjs +1 -1
  102. package/dist-lib/vendor/stream-json.cjs +1 -1
  103. package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
  104. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
  105. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
  106. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
  107. package/dist-lib/vendor/sucrase.cjs +1 -1
  108. package/dist-lib/vendor/terser.cjs +1 -1
  109. package/dist-lib/vendor/valibot.cjs +1 -1
  110. package/dist-lib/vendor/zod.cjs +1 -1
  111. package/dist-lib/worklet-executable.cjs +1 -1
  112. package/dist-lib/worklet-executable.mjs +3 -3
  113. package/package.json +1 -1
  114. package/src/expo-discovery-cache.ts +9 -45
  115. package/src/expo-native-compiler-digest.ts +8 -0
  116. package/src/expo-native-prebuilt.ts +1 -10
  117. package/src/expo-native-workspace.ts +5 -120
  118. package/src/expo-pod-prebuilt.ts +1 -1
  119. package/src/expo-swift-host.ts +48 -35
  120. package/src/installed-native-libraries.ts +10 -20
  121. package/src/pod-graph-specifications.ts +11 -0
  122. package/src/pods-install.ts +10 -7
  123. package/src/podspec-cocoapods.ts +8 -3
  124. package/src/podspec-sources.ts +19 -15
  125. package/src/swift-clang-type-ownership.ts +118 -0
  126. package/src/swift-compile.ts +7 -5
  127. package/src/swift-guest-image-ledger.ts +48 -0
  128. package/src/swift-guest-link.ts +11 -1
  129. package/src/swift-host.ts +5 -8
  130. package/src/swift-packages.ts +0 -5
  131. package/src/swift-toolchain.ts +1 -1
  132. package/src/xcode-project.ts +64 -46
  133. package/src/portable-expo-contract.ts +0 -108
  134. package/src/portable-expo-workspace.ts +0 -100
  135. package/src/prepared-xcode-phases.ts +0 -194
@@ -24,7 +24,6 @@ import {
24
24
  import { prebuiltExpoNative, prebuiltExpoSwiftResult } from './expo-native-prebuilt'
25
25
  import {
26
26
  hashExpoWorkspace,
27
- nativeWorkspaceAvailable,
28
27
  prepareExpoNativeWorkspace,
29
28
  preparedExpoWorkspacesDir,
30
29
  } from './expo-native-workspace'
@@ -41,13 +40,13 @@ import {
41
40
  NATIVE_PREPARE_QUERY_PARAM,
42
41
  NATIVE_PREPARED_QUERY_PARAM,
43
42
  } from './nativePreparationContract'
44
- import { preparedXcodeInterfaces } from './prepared-xcode-phases'
45
43
  import {
46
44
  BRIDGE_MODULE_FILE_PREFIX,
47
45
  collectBridgeModuleSources,
48
46
  } from './react-native-bridge-modules'
49
47
  import { prebuiltReactNativeCore } from './react-native-core'
50
48
  import { swiftBinaryModules } from './swift-binary-modules'
49
+ import { clangTypeOwnership } from './swift-clang-type-ownership'
51
50
  import {
52
51
  swiftAvailableModules,
53
52
  swiftCodeMask,
@@ -452,8 +451,7 @@ async function discoveryKey(
452
451
  iosTarget: string | undefined,
453
452
  moduleRoot?: string,
454
453
  ): Promise<string> {
455
- const preparesWorkspace =
456
- prepareNative && !installedWorkspace && nativeWorkspaceAvailable()
454
+ const preparesWorkspace = prepareNative && !installedWorkspace
457
455
  const [config, expoConfig, workspace] = await Promise.all([
458
456
  loadRNXAppConfig(resolveAppProject(root)),
459
457
  readExpoConfigAsync(root),
@@ -719,7 +717,6 @@ function enrichInstalledUnits(
719
717
  moduleRoot: string,
720
718
  appRoot: string,
721
719
  bridgeNamespaces: ReadonlySet<string> = new Set(),
722
- interfaceRoot?: string,
723
720
  ): void {
724
721
  const { input, binaryFrameworks } = installed
725
722
  // each unit generates its own binary stand-ins, so the workspace's are not re-mapped
@@ -769,6 +766,44 @@ function enrichInstalledUnits(
769
766
  : `Sources/${target.name}/${file.slice(target.path.length + 1).replace(/^(?:.*\/)?node_modules\//, '')}`
770
767
  : file
771
768
  }
769
+ const supportFiles = Object.fromEntries(
770
+ Object.entries(swiftNativeSupportFiles(input.files, installedTargets)).map(
771
+ ([file, source]) => [map(file), source],
772
+ ),
773
+ )
774
+ const headerAliases = Object.fromEntries(
775
+ Object.entries(input.headerAliases ?? {}).map(([alias, file]) => [
776
+ map(alias),
777
+ map(file),
778
+ ]),
779
+ )
780
+ // frameworks supplied by the runtime or the React Native provider still publish headers.
781
+ for (const target of input.nativeTargets ?? []) {
782
+ const runtimeModule = provided.has(target.name)
783
+ if (!runtimeModule && !reactTargets.has(target.name)) continue
784
+ const swift = runtimeModule ? swiftModuleInterface(moduleRoot, target.name) : null
785
+ const refineClangTypes = clangTypeOwnership(moduleRoot, target.name)
786
+ const interfaceName = `${target.name}-Swift.h`
787
+ for (const [product, file] of Object.entries(target.productHeaders)) {
788
+ if (!product.includes('.framework/Headers/')) continue
789
+ const original = map(file)
790
+ const source = supportFiles[original]
791
+ if (source === undefined) continue
792
+ const alias = map(product)
793
+ if (alias !== original) headerAliases[alias] = original
794
+ if (!swift) continue
795
+ const refined = refineClangTypes(source)
796
+ const contents = withoutSwiftDeclarations(
797
+ refined,
798
+ swift.declared,
799
+ `#import <${target.name}/${interfaceName}>`,
800
+ )
801
+ supportFiles[original] = contents
802
+ if (contents !== refined)
803
+ supportFiles[path.posix.join(path.posix.dirname(alias), interfaceName)] =
804
+ swift.header
805
+ }
806
+ }
772
807
  for (const unit of units) {
773
808
  if (bridgeNamespaces.size > 0 && !bridgeNamespaces.has(unit.namespace)) continue
774
809
  // native modules resolve the installed workspace resource products through Bundle.
@@ -873,23 +908,8 @@ function enrichInstalledUnits(
873
908
  )
874
909
  delete unit.files[file]
875
910
  }
876
- unit.nativeFiles = {
877
- ...unit.nativeFiles,
878
- ...Object.fromEntries(
879
- Object.entries(swiftNativeSupportFiles(input.files, installedTargets)).map(
880
- ([file, source]) => [map(file), source],
881
- ),
882
- ),
883
- }
884
- unit.headerAliases = {
885
- ...unit.headerAliases,
886
- ...Object.fromEntries(
887
- Object.entries(input.headerAliases ?? {}).map(([alias, file]) => [
888
- map(alias),
889
- map(file),
890
- ]),
891
- ),
892
- }
911
+ unit.nativeFiles = { ...unit.nativeFiles, ...supportFiles }
912
+ unit.headerAliases = { ...unit.headerAliases, ...headerAliases }
893
913
  const podspecTargets = unit.nativeTargets ?? []
894
914
  unit.nativeTargets = (input.nativeTargets ?? [])
895
915
  .filter((native) => included.has(native.name))
@@ -989,7 +1009,7 @@ function enrichInstalledUnits(
989
1009
  }
990
1010
  for (const map of maps) {
991
1011
  if (!map.reached.size) continue
992
- const swift = swiftModuleInterface(moduleRoot, map.name, interfaceRoot)
1012
+ const swift = swiftModuleInterface(moduleRoot, map.name)
993
1013
  const mapDirectory = path.posix.dirname(map.file)
994
1014
  if (swift) {
995
1015
  const header = `${map.name}-Swift.h`
@@ -1382,8 +1402,6 @@ async function collectExpoSwiftSourcesUncached(
1382
1402
  moduleRoot = module.root
1383
1403
  provided = new Set(swiftPeachModules(module.root))
1384
1404
  await prepareXcodeSwiftPackages(installedWorkspace, iosTarget, undefined, signal)
1385
- moduleRoot = module.root
1386
- provided = new Set(swiftPeachModules(module.root))
1387
1405
  const snapshot = await withXcodeProject(
1388
1406
  installedWorkspace,
1389
1407
  {
@@ -1560,8 +1578,7 @@ async function collectExpoSwiftSourcesUncached(
1560
1578
  // pod source membership comes from CocoaPods, including packages whose
1561
1579
  // Apple sources live outside an ios directory or exclude sibling sources.
1562
1580
  if (deferredToWorkspace) {
1563
- // every selected pod uses its real prepared graph. non-Mac hosts intake
1564
- // the portable workspace instead of silently dropping its registration.
1581
+ // each selected pod uses the generated workspace's target membership.
1565
1582
  needsNativeWorkspace = true
1566
1583
  continue
1567
1584
  }
@@ -1573,7 +1590,7 @@ async function collectExpoSwiftSourcesUncached(
1573
1590
  if (!prepareNative) {
1574
1591
  if (!answered)
1575
1592
  report(
1576
- `${packageName}: ${namespaces.join(', ')} need CocoaPods target membership, which only a Mac prepares; not compiled`,
1593
+ `${packageName}: ${namespaces.join(', ')} need prepared pod target membership`,
1577
1594
  )
1578
1595
  continue
1579
1596
  }
@@ -2045,7 +2062,6 @@ async function collectExpoSwiftSourcesUncached(
2045
2062
  moduleRoot,
2046
2063
  appRoot,
2047
2064
  new Set(),
2048
- installedWorkspace ? preparedXcodeInterfaces(installedWorkspace) : undefined,
2049
2065
  )
2050
2066
  const allFiles: Record<string, string> = Object.assign(
2051
2067
  {},
@@ -2468,7 +2484,7 @@ async function compileExpoSwiftModulesTraced(
2468
2484
  root,
2469
2485
  signal,
2470
2486
  options.installedWorkspace,
2471
- nativeWorkspaceAvailable() && !options.only,
2487
+ !options.only,
2472
2488
  options.iosTarget,
2473
2489
  { moduleRoot: options.moduleRoot },
2474
2490
  )
@@ -2496,7 +2512,6 @@ async function compileExpoSwiftModulesTraced(
2496
2512
  ? null
2497
2513
  : await collectBridgeModuleSources(fs.realpathSync(root), signal)
2498
2514
  if (
2499
- nativeWorkspaceAvailable() &&
2500
2515
  fs.existsSync(path.join(root, 'ios', 'Podfile')) &&
2501
2516
  bridge?.units.some((unit) =>
2502
2517
  unit.nativeTargets?.some((target) => target.bridgingHeader),
@@ -2518,8 +2533,7 @@ async function compileExpoSwiftModulesTraced(
2518
2533
  bridge &&
2519
2534
  (bridge.installedNamespaces.length > 0 ||
2520
2535
  (bridge.units.length > 0 &&
2521
- (options.installedWorkspace ||
2522
- (nativeWorkspaceAvailable() && fs.existsSync(path.join(ios, 'Podfile'))))))
2536
+ (options.installedWorkspace || fs.existsSync(path.join(ios, 'Podfile')))))
2523
2537
  ) {
2524
2538
  const workspace =
2525
2539
  options.installedWorkspace ??
@@ -2558,7 +2572,6 @@ async function compileExpoSwiftModulesTraced(
2558
2572
  module.root,
2559
2573
  root,
2560
2574
  new Set(bridge.units.map((unit) => unit.namespace)),
2561
- preparedXcodeInterfaces(workspace),
2562
2575
  )
2563
2576
  },
2564
2577
  )
@@ -3085,7 +3098,7 @@ async function compileExpoSwiftModulesTraced(
3085
3098
  )
3086
3099
  const diagnostic = [
3087
3100
  error instanceof SwiftMissingModulesError && unit.workspaceSources?.length
3088
- ? `${unit.workspaceSources.map((name) => `${name} needs a Mac-prepared workspace`).join('; ')}; unresolved imports: ${missingImports.join(', ')}`
3101
+ ? `${unit.workspaceSources.map((name) => `${name} needs a prepared workspace`).join('; ')}; unresolved imports: ${missingImports.join(', ')}`
3089
3102
  : message,
3090
3103
  ...(gaps.get(unit) ?? []),
3091
3104
  ].join('\n')
@@ -98,12 +98,9 @@ export function installedNativeLibraries(
98
98
  if (providers.length === 0) return result
99
99
  projectRoot = fs.realpathSync(projectRoot)
100
100
  const { app, targets } = installedProviderTargets(providers, projectRoot, iosTarget)
101
- const podsRoot = app.cocoapods && path.dirname(app.cocoapods.manifestLock)
102
- const localPods = new Set(
103
- (app.cocoapods?.localPodspecs ?? []).map((file) =>
104
- path.basename(file, '.podspec.json'),
105
- ),
106
- )
101
+ if (!app.cocoapods) throw new Error(`${projectRoot}: no installed pod graph`)
102
+ const podsRoot = path.dirname(app.cocoapods.manifestLock)
103
+ const localPods = app.cocoapods.localPodspecs
107
104
  const reactNativeRoot = path.dirname(
108
105
  createRequire(path.join(projectRoot, 'package.json')).resolve(
109
106
  'react-native/package.json',
@@ -125,13 +122,11 @@ export function installedNativeLibraries(
125
122
  : combineNativeStaticLibraries([firstShared, ...otherShared], moduleRoot)
126
123
  for (const provider of providers) {
127
124
  const name = path.basename(provider.podspecPath, '.podspec')
128
- const specFile = app.cocoapods?.localPodspecs.find(
129
- (file) => path.basename(file) === `${name}.podspec.json`,
130
- )
131
- if (!specFile) throw new Error(`${name}: no installed CocoaPods specification`)
132
- const spec: unknown = JSON.parse(fs.readFileSync(specFile, 'utf8'))
125
+ const json = localPods.get(name)
126
+ if (!json) throw new Error(`${name}: no installed pod specification`)
127
+ const spec: unknown = JSON.parse(json)
133
128
  if (!isRecord(spec) || spec.name !== name)
134
- throw new Error(`${specFile}: invalid installed specification`)
129
+ throw new Error(`${name}: invalid installed pod specification`)
135
130
  const platform = isRecord(spec.ios) ? spec.ios : {}
136
131
  const paths = [
137
132
  spec.vendored_libraries,
@@ -143,7 +138,7 @@ export function installedNativeLibraries(
143
138
  if (typeof value === 'string') return [value]
144
139
  if (Array.isArray(value) && value.every((item) => typeof item === 'string'))
145
140
  return value
146
- throw new Error(`${specFile}: invalid vendored native paths`)
141
+ throw new Error(`${name}: invalid vendored native paths`)
147
142
  })
148
143
  const target = targets.get(provider.name)!
149
144
  const { root, files } = installedTargetSources(target)
@@ -172,7 +167,7 @@ export function installedNativeLibraries(
172
167
  ...(isRecord(platform.dependencies) ? platform.dependencies : {}),
173
168
  }).flatMap((dependency) => {
174
169
  const pod = dependency.split('/')[0]!
175
- if (!podsRoot || localPods.has(pod)) return []
170
+ if (localPods.has(pod)) return []
176
171
  return installedPodBinaries(path.join(podsRoot, pod)).map((file) =>
177
172
  path.relative(path.dirname(podsRoot), file),
178
173
  )
@@ -205,12 +200,7 @@ export function installedNativeLibraries(
205
200
  )
206
201
  const published: { file: string; relative: string }[] = []
207
202
  for (const visibility of ['Public', 'Private']) {
208
- const directory = path.join(
209
- path.dirname(path.dirname(specFile)),
210
- 'Headers',
211
- visibility,
212
- name,
213
- )
203
+ const directory = path.join(podsRoot, 'Headers', visibility, name)
214
204
  if (!fs.existsSync(directory)) continue
215
205
  for (const entry of fs.readdirSync(directory, {
216
206
  recursive: true,
@@ -0,0 +1,11 @@
1
+ import fs from 'node:fs'
2
+ import { isRecord } from './is-record'
3
+
4
+ export const POD_GRAPH_SPECIFICATIONS = '.peach-podspecs.json'
5
+
6
+ export function readPodGraphSpecifications(file: string): Map<string, string> {
7
+ const value: unknown = JSON.parse(fs.readFileSync(file, 'utf8'))
8
+ if (!isRecord(value) || !Object.values(value).every((item) => typeof item === 'string'))
9
+ throw new Error(`${file}: invalid pod graph specifications`)
10
+ return new Map(Object.entries(value).map(([name, json]) => [name, String(json)]))
11
+ }
@@ -1,12 +1,14 @@
1
1
  // what `pod install` leaves in an app's ios directory, made without CocoaPods or Ruby: the Podfile
2
2
  // is evaluated and resolved on Peach's Ruby interpreter, pod sources come from Peach's cache, and
3
- // the Pods project, support files, header links, integrated app project, workspace, Local Podspecs
3
+ // the Pods project, support files, header links, integrated app project, workspace
4
4
  // and lockfiles are written as CocoaPods 1.17 writes them. the lockfile writer follows
5
5
  // cocoapods-core's YAMLHelper (MIT).
6
6
  import fs from 'node:fs'
7
7
  import path from 'node:path'
8
8
  import { isDict, list, parseOpenStepPlist, str, type PlistDict } from './openstep-plist'
9
9
  import { PbxTable, serializePbxproj } from './pbx-table'
10
+ import { POD_GRAPH_SPECIFICATIONS } from './pod-graph-specifications'
11
+ import { podPrepareEnvironment } from './pod-prepare-toolchain'
10
12
  import { cleanInstalledPod, podSourceRoot } from './pod-sources'
11
13
  import { evaluatePodfile, resolvePodfile } from './podfile-cocoapods'
12
14
  import { analyzePods } from './pods-analysis'
@@ -341,7 +343,8 @@ export async function installPods(
341
343
  timings[label] = Math.round(now - started)
342
344
  started = now
343
345
  }
344
- const resolved = await resolvePodfile(evaluatePodfile(app, env, workspace))
346
+ const prepareEnv = await podPrepareEnvironment({ ...process.env, ...env })
347
+ const resolved = await resolvePodfile(evaluatePodfile(app, prepareEnv, workspace))
345
348
  const { interp, file, podfile, sandbox: rubySandbox, resolver } = resolved
346
349
  const iosRoot = path.dirname(file)
347
350
  const call = (source: string, label: string) =>
@@ -370,17 +373,17 @@ export async function installPods(
370
373
  const spec: unknown = JSON.parse(json)
371
374
  if (!isRecord(spec)) throw new Error(`${name}: the specification is no JSON object`)
372
375
  downloaded.set(name, spec)
373
- fs.cpSync(await podSourceRoot(spec), path.join(podsRoot, name), {
376
+ fs.cpSync(await podSourceRoot(spec, prepareEnv), path.join(podsRoot, name), {
374
377
  recursive: true,
375
378
  mode: fs.constants.COPYFILE_FICLONE,
376
379
  verbatimSymlinks: true,
377
380
  })
378
381
  }),
379
382
  )
380
- const specifications = path.join(podsRoot, 'Local Podspecs')
381
- fs.mkdirSync(specifications, { recursive: true })
382
- for (const [name, json] of inputs.stored)
383
- fs.writeFileSync(path.join(specifications, `${name}.podspec.json`), json)
383
+ fs.writeFileSync(
384
+ path.join(podsRoot, POD_GRAPH_SPECIFICATIONS),
385
+ JSON.stringify(Object.fromEntries(inputs.stored)),
386
+ )
384
387
  lap('download')
385
388
 
386
389
  const [definition, ...others] = inputs.definitions
@@ -1184,14 +1184,19 @@ export function evaluatePodspec(
1184
1184
  app: string,
1185
1185
  writable: string,
1186
1186
  env: Host,
1187
+ installed?: string,
1187
1188
  ): unknown {
1188
1189
  return rubyFailures(file, () => {
1189
1190
  const { interp, pod } = cocoapodsInterpreter(app, [writable], env)
1190
1191
  const call = (receiver: Value, name: string, args: Value[] = []) =>
1191
1192
  interp.callMethod(receiver, name, args, null, null, null, null)
1192
- const spec = call(interp.constIn(pod, 'Specification', null, '-'), 'from_file', [
1193
- str(file),
1194
- ])
1193
+ const specification = interp.constIn(pod, 'Specification', null, '-')
1194
+ const spec =
1195
+ installed === undefined
1196
+ ? call(specification, 'from_file', [str(file)])
1197
+ : call(specification, 'from_hash', [
1198
+ call(interp.object.consts.get('JSON') ?? null, 'parse', [str(installed)]),
1199
+ ])
1195
1200
  return toJson(interp, call(pod, 'peach_evaluated', [spec]))
1196
1201
  })
1197
1202
  }
@@ -1,11 +1,15 @@
1
1
  // native membership comes from evaluating each podspec with CocoaPods' own DSL
2
2
  // in Peach's Ruby interpreter, the same on every host. evaluations restored
3
- // from a compiled key artifact or a prepared workspace manifest skip it.
3
+ // from a compiled key artifact skip it.
4
4
  import { createHash, randomUUID } from 'node:crypto'
5
5
  import fs from 'node:fs'
6
6
  import path from 'node:path'
7
7
  import { z } from 'zod'
8
8
  import { cacheDir } from './home-paths'
9
+ import {
10
+ POD_GRAPH_SPECIFICATIONS,
11
+ readPodGraphSpecifications,
12
+ } from './pod-graph-specifications'
9
13
  import { evaluatePodspec } from './podspec-cocoapods'
10
14
  import { findWorkspaceRoot } from './workspace-root'
11
15
 
@@ -51,17 +55,11 @@ const packageContexts = new Map<string, Map<string, string>>()
51
55
  const installedSpecs = new Map<string, Map<string, string>>()
52
56
 
53
57
  export function readInstalledPodspecs(appRoot: string, projectRoot: string) {
54
- const directory = path.join(projectRoot, 'ios/Pods/Local Podspecs')
55
- const files = fs.readdirSync(directory).filter((name) => name.endsWith('.podspec.json'))
56
- installedSpecs.set(
57
- fs.realpathSync(appRoot),
58
- new Map(
59
- files.map((name) => [
60
- name.slice(0, -'.podspec.json'.length),
61
- path.join(directory, name),
62
- ]),
63
- ),
58
+ const specifications = readPodGraphSpecifications(
59
+ path.join(projectRoot, 'ios/Pods', POD_GRAPH_SPECIFICATIONS),
64
60
  )
61
+ installedSpecs.set(fs.realpathSync(appRoot), specifications)
62
+ installedSpecs.set(fs.realpathSync(projectRoot), specifications)
65
63
  }
66
64
 
67
65
  export function beginPodspecEvaluation(appRoot: string) {
@@ -139,7 +137,7 @@ interface PodspecPlan {
139
137
  app: string
140
138
  key: string
141
139
  environment: string
142
- source: string
140
+ installed?: string
143
141
  receipt?: PodspecReceipt
144
142
  }
145
143
 
@@ -232,7 +230,7 @@ export function podspecReceiptIdentity(file: string, appRoot: string | null = nu
232
230
  const installed = reactNative
233
231
  ? undefined
234
232
  : installedSpecs.get(app)?.get(path.basename(file, '.podspec'))
235
- if (installed) environmentHash.update(fs.readFileSync(installed))
233
+ if (installed) environmentHash.update(installed)
236
234
  const environment = environmentHash.digest('hex')
237
235
  return { file, app, ios, env, installed, key, environment }
238
236
  }
@@ -259,7 +257,7 @@ function planPodspec(podspec: string, appRoot: string | null): PodspecPlan {
259
257
  receipts.set(key, receipt)
260
258
  }
261
259
  }
262
- return { file, app, key, environment, source: installed ?? file, receipt }
260
+ return { file, app, key, environment, installed, receipt }
263
261
  }
264
262
 
265
263
  function podspecEnv(): NodeJS.ProcessEnv {
@@ -295,7 +293,13 @@ export function loadPodspecs(
295
293
  environment: plan.environment,
296
294
  app: appIdentity(plan.app),
297
295
  spec: evaluatedSpecSchema.parse(
298
- evaluatePodspec(plan.source, plan.app, packageRoot(plan.file), podspecEnv()),
296
+ evaluatePodspec(
297
+ plan.file,
298
+ plan.app,
299
+ packageRoot(plan.file),
300
+ podspecEnv(),
301
+ plan.installed,
302
+ ),
299
303
  ),
300
304
  }
301
305
  receipts.set(plan.key, plan.receipt)
@@ -0,0 +1,118 @@
1
+ import { execFileSync } from 'node:child_process'
2
+ import { createHash } from 'node:crypto'
3
+ import fs from 'node:fs'
4
+ import path from 'node:path'
5
+ import { isRecord } from './is-record'
6
+ import { WASM_TRIPLE, swiftSdkPaths } from './swift-compile'
7
+ import { swiftModuleToolchain } from './swift-distribution'
8
+ import { swiftCacheDir, swiftEnvironment, withoutCoreDump } from './swift-toolchain'
9
+
10
+ const blockTypedef = /(^[ \t]*typedef\b[^\n]*?\^\s*)(\w+)([ \t]*\)[^;\n]*;)/gm
11
+ const enumTypedef = /(^[ \t]*typedef\s+enum\s+)(\w+)(\s*\{)([^}]*)(}\s*)(\w+)(\s*;)/gm
12
+ const enumConstant = /(^[ \t]*)(\w+)(?=[ \t]*(?:=|,|$))/gm
13
+ const swiftPrivate = ' __attribute__((swift_private))'
14
+
15
+ function exportedNames(moduleRoot: string, name: string): Set<string> {
16
+ const modules = path.join(moduleRoot, 'modules')
17
+ const module = path.join(modules, `${name}.swiftmodule`)
18
+ if (!fs.existsSync(module)) return new Set()
19
+ const key = createHash('sha256').update(fs.readFileSync(module)).digest('hex')
20
+ const directory = path.join(swiftCacheDir(), 'swift-public-names')
21
+ const receipt = path.join(directory, `${key}.json`)
22
+ if (fs.existsSync(receipt)) {
23
+ const names: unknown = JSON.parse(fs.readFileSync(receipt, 'utf8'))
24
+ if (Array.isArray(names) && names.every((value) => typeof value === 'string'))
25
+ return new Set(names)
26
+ }
27
+ const { toolchainBin } = swiftModuleToolchain(moduleRoot)
28
+ const { cFlags, darwin, resources, sysroot } = swiftSdkPaths(moduleRoot, toolchainBin)
29
+ fs.mkdirSync(directory, { recursive: true })
30
+ const scratch = fs.mkdtempSync(path.join(directory, '.extract-'))
31
+ try {
32
+ execFileSync(
33
+ ...withoutCoreDump(path.join(toolchainBin, 'swift-symbolgraph-extract'), [
34
+ '-module-name',
35
+ name,
36
+ '-target',
37
+ WASM_TRIPLE,
38
+ '-enable-objc-interop',
39
+ '-sdk',
40
+ sysroot,
41
+ '-resource-dir',
42
+ resources,
43
+ '-I',
44
+ modules,
45
+ '-I',
46
+ path.join(darwin, 'usr/include'),
47
+ ...cFlags.flatMap((flag) => ['-Xcc', flag]),
48
+ '-Xcc',
49
+ '-fobjc-runtime=gnustep-2.2',
50
+ '-Xcc',
51
+ '-Xclang',
52
+ '-Xcc',
53
+ '-fmodule-format=raw',
54
+ '-skip-synthesized-members',
55
+ '-output-dir',
56
+ scratch,
57
+ ]),
58
+ { env: swiftEnvironment(), stdio: ['ignore', 'pipe', 'pipe'] },
59
+ )
60
+ const graph: unknown = JSON.parse(
61
+ fs.readFileSync(path.join(scratch, `${name}.symbols.json`), 'utf8'),
62
+ )
63
+ if (!isRecord(graph) || !Array.isArray(graph.symbols))
64
+ throw new Error(`${name}: invalid Swift symbol graph`)
65
+ const names = new Set(
66
+ graph.symbols.flatMap((symbol: unknown) => {
67
+ if (!isRecord(symbol) || !Array.isArray(symbol.pathComponents)) return []
68
+ const [declaration] = symbol.pathComponents
69
+ return symbol.pathComponents.length === 1 && typeof declaration === 'string'
70
+ ? [declaration]
71
+ : []
72
+ }),
73
+ )
74
+ const temporary = path.join(scratch, 'names.json')
75
+ fs.writeFileSync(temporary, JSON.stringify([...names].sort()))
76
+ fs.renameSync(temporary, receipt)
77
+ return names
78
+ } finally {
79
+ fs.rmSync(scratch, { recursive: true, force: true })
80
+ }
81
+ }
82
+
83
+ export function clangTypeOwnership(moduleRoot: string, module: string) {
84
+ let names: Set<string> | undefined
85
+ const privateName = (name: string) => {
86
+ names ??= exportedNames(moduleRoot, module)
87
+ return names.has(name) ? swiftPrivate : ''
88
+ }
89
+ return (source: string) =>
90
+ source
91
+ .replace(
92
+ blockTypedef,
93
+ (_match, prefix: string, name: string, suffix: string) =>
94
+ `${prefix}${name}${suffix.slice(0, -1)}${privateName(name)};`,
95
+ )
96
+ .replace(
97
+ enumTypedef,
98
+ (
99
+ _match,
100
+ prefix: string,
101
+ tag: string,
102
+ open: string,
103
+ body: string,
104
+ close: string,
105
+ type: string,
106
+ suffix: string,
107
+ ) => {
108
+ const attribute = privateName(tag).trimStart()
109
+ const tagged = attribute ? `${attribute} ${tag}` : tag
110
+ const cases = body.replace(
111
+ enumConstant,
112
+ (_match, indent: string, name: string) =>
113
+ `${indent}${name}${privateName(name)}`,
114
+ )
115
+ return `${prefix}${tagged}${open}${cases}${close}${type}${privateName(type)}${suffix}`
116
+ },
117
+ )
118
+ }
@@ -405,14 +405,10 @@ export const REACH_STAGED_FRAMEWORKS: ReadonlySet<string> = new Set(['React'])
405
405
  export function swiftModuleInterface(
406
406
  moduleRoot: string,
407
407
  name: string,
408
- interfaceRoot?: string,
409
408
  ): { declared: ReadonlySet<string>; header: string } | null {
410
409
  if (REACH_STAGED_FRAMEWORKS.has(name)) return null
411
410
  if (swiftDistributionAt(moduleRoot)) {
412
- const file = path.join(
413
- interfaceRoot ?? path.join(moduleRoot, 'modules'),
414
- `${name}-Swift.h`,
415
- )
411
+ const file = path.join(moduleRoot, 'modules', `${name}-Swift.h`)
416
412
  if (!existsSync(file)) return null
417
413
  const header = clangInterfaceHeader(readFileSync(file, 'utf8'))
418
414
  return { declared: swiftInterfaceDeclarations(header), header }
@@ -5497,6 +5493,12 @@ export function writeSwiftProject(
5497
5493
  includeDirectory: path.join(layout.root, includes),
5498
5494
  sources: units.map(([file]) => file.slice(prefix.length)),
5499
5495
  lateSources: late.map(([file]) => file.slice(prefix.length)),
5496
+ exclude: [
5497
+ ...late.map(([file]) => file.slice(prefix.length)),
5498
+ ...entries
5499
+ .filter(([file]) => /\.(?:inc|inl|ipp|def)$/.test(file))
5500
+ .map(([file]) => file.slice(prefix.length)),
5501
+ ],
5500
5502
  ...(late.length > 0
5501
5503
  ? {
5502
5504
  late: {
@@ -779,3 +779,51 @@ export function createGuestImageLedger(input: GuestImageLedgerInput): GuestImage
779
779
  llvmIR: ir.join('\n') + '\n',
780
780
  }
781
781
  }
782
+
783
+ // a linked module that keeps its name section names each ledger alias by the
784
+ // symbol it stands for, so a trap stack reads as the original link would.
785
+ export function nameGuestImageAliases(
786
+ wasm: Uint8Array,
787
+ symbols: readonly string[],
788
+ ): Buffer {
789
+ const alias = /^__peach_image_\d+_symbol_(\d+)$/
790
+ const parts: Uint8Array[] = [wasm.subarray(0, 8)]
791
+ let position = 8
792
+ while (position < wasm.length) {
793
+ const [size, start] = readNumber(wasm, position + 1)
794
+ const end = start + size
795
+ const custom = wasm[position] === 0 ? readString(wasm, start) : undefined
796
+ if (custom?.[0] !== 'name') {
797
+ parts.push(wasm.subarray(position, end))
798
+ position = end
799
+ continue
800
+ }
801
+ const subsections: Uint8Array[] = [encodedString('name')]
802
+ let at = custom[1]
803
+ while (at < end) {
804
+ const [subSize, subStart] = readNumber(wasm, at + 1)
805
+ const subEnd = subStart + subSize
806
+ if (wasm[at] !== 1) {
807
+ subsections.push(wasm.subarray(at, subEnd))
808
+ at = subEnd
809
+ continue
810
+ }
811
+ let [count, cursor] = readNumber(wasm, subStart)
812
+ const entries: Buffer[] = [encodeNumber(count)]
813
+ for (; count > 0; count--) {
814
+ const [index, next] = readNumber(wasm, cursor)
815
+ const [name, after] = readString(wasm, next)
816
+ cursor = after
817
+ const symbol = symbols[Number(alias.exec(name)?.[1] ?? -1)]
818
+ entries.push(encodeNumber(index), encodedString(symbol ?? name))
819
+ }
820
+ const content = Buffer.concat(entries)
821
+ subsections.push(Buffer.from([1]), encodeNumber(content.length), content)
822
+ at = subEnd
823
+ }
824
+ const section = Buffer.concat(subsections)
825
+ parts.push(Buffer.from([0]), encodeNumber(section.length), section)
826
+ position = end
827
+ }
828
+ return Buffer.concat(parts)
829
+ }
@@ -11,7 +11,11 @@ import {
11
11
  originalGuestArchiveSelections,
12
12
  type AliasedGuestArchive,
13
13
  } from './swift-guest-archive'
14
- import { createGuestImageLedger, type GuestImageObject } from './swift-guest-image-ledger'
14
+ import {
15
+ createGuestImageLedger,
16
+ nameGuestImageAliases,
17
+ type GuestImageObject,
18
+ } from './swift-guest-image-ledger'
15
19
  import {
16
20
  selectedGuestInputImage,
17
21
  type GuestLinkArtifact,
@@ -41,6 +45,7 @@ import {
41
45
  guestWasmSymbols,
42
46
  type SwiftPrunedSdkInputs,
43
47
  } from './swift-wasm-prune'
48
+ import { KEEP_WASM_NAMES } from './wasm-optimize'
44
49
  import type { SwiftGuestImageManifest } from './swiftGuestImageContract'
45
50
  import type {
46
51
  SwiftFrameworkProduct,
@@ -613,6 +618,11 @@ export function linkGuestImages(
613
618
  `guest link selected different inputs after rewriting:\n${changed.join('\n')}`,
614
619
  )
615
620
  fs.renameSync(finalOutput, outputPath(args))
621
+ if (KEEP_WASM_NAMES)
622
+ fs.writeFileSync(
623
+ outputPath(args),
624
+ nameGuestImageAliases(fs.readFileSync(outputPath(args)), plan.symbols),
625
+ )
616
626
  if (projectionStorage && projectionObject)
617
627
  options.projection!.onReserved(projectionStorage, projectionObject)
618
628
  options.onLinkedOwners?.(linkedOwners)