peachsim 0.1.1674 → 0.1.1684

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 (190) hide show
  1. package/cli/commands/control.ts +13 -1
  2. package/cli/commands/coverage-swift.ts +83 -27
  3. package/cli/commands/coverage.ts +219 -20
  4. package/cli/commands/detect.ts +10 -6
  5. package/cli/commands/inspect/core.ts +2 -0
  6. package/cli/commands/inspect/wait-ready.ts +7 -0
  7. package/cli/outbound-endpoints.ts +12 -0
  8. package/detox/index.ts +11 -1
  9. package/detox/jest-environment.cjs +14 -0
  10. package/dist-lib/agent-daemon-client.cjs +1 -1
  11. package/dist-lib/agent-events.cjs +1 -1
  12. package/dist-lib/attached-projects.cjs +1 -1
  13. package/dist-lib/auth/shared-session.cjs +1 -1
  14. package/dist-lib/backend-origin.cjs +1 -1
  15. package/dist-lib/beta.cjs +1 -1
  16. package/dist-lib/beta.mjs +1 -1
  17. package/dist-lib/bridge-constants.cjs +1 -1
  18. package/dist-lib/bridge-contract-input.cjs +1 -1
  19. package/dist-lib/bridge-contract-input.mjs +1 -1
  20. package/dist-lib/bridge-contract.cjs +1 -1
  21. package/dist-lib/bridge-contract.mjs +1 -1
  22. package/dist-lib/bundle-channel.cjs +3274 -1663
  23. package/dist-lib/capture-contract.cjs +1 -1
  24. package/dist-lib/capture-contract.mjs +1 -1
  25. package/dist-lib/cloud-contract.cjs +1 -1
  26. package/dist-lib/cloud-contract.mjs +1 -1
  27. package/dist-lib/cloud-test-args.cjs +1 -1
  28. package/dist-lib/cloud-test-args.mjs +1 -1
  29. package/dist-lib/cloud.cjs +1 -1
  30. package/dist-lib/cloud.mjs +1 -1
  31. package/dist-lib/config.cjs +1 -1
  32. package/dist-lib/config.mjs +1 -1
  33. package/dist-lib/detox/index.cjs +6 -4
  34. package/dist-lib/detox/jest-environment.cjs +14 -0
  35. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  36. package/dist-lib/expo-swift-bundle.cjs +2407 -1126
  37. package/dist-lib/expo-swift-metadata.cjs +1 -1
  38. package/dist-lib/expo-swift-metadata.mjs +1 -1
  39. package/dist-lib/home-paths.cjs +1 -1
  40. package/dist-lib/host/bridge-host.cjs +2879 -1598
  41. package/dist-lib/host/fetch-proxy-handler.cjs +18 -5
  42. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  43. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  44. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  45. package/dist-lib/host/websocket-proxy.cjs +1 -1
  46. package/dist-lib/index.cjs +1904 -741
  47. package/dist-lib/jump-to-source-babel.cjs +1 -1
  48. package/dist-lib/jump-to-source-native.cjs +1 -1
  49. package/dist-lib/kotlin-host.cjs +1 -1
  50. package/dist-lib/menu.cjs +1 -1
  51. package/dist-lib/menu.mjs +1 -1
  52. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  53. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  54. package/dist-lib/metro-production-bundle.cjs +1 -1
  55. package/dist-lib/metro-production-bundle.mjs +1 -1
  56. package/dist-lib/metro.cjs +6215 -4283
  57. package/dist-lib/native-app-identity-project.cjs +31 -6
  58. package/dist-lib/native-app-identity-project.mjs +31 -6
  59. package/dist-lib/native-app-identity.cjs +1 -1
  60. package/dist-lib/native-app-identity.mjs +1 -1
  61. package/dist-lib/native-firebase-metadata.cjs +1 -1
  62. package/dist-lib/native-firebase-metadata.mjs +1 -1
  63. package/dist-lib/plist.cjs +1 -1
  64. package/dist-lib/plist.mjs +1 -1
  65. package/dist-lib/profiles.cjs +1 -1
  66. package/dist-lib/public-brand.cjs +1 -1
  67. package/dist-lib/public-origins-lib-esm.json +24 -23
  68. package/dist-lib/public-origins-lib-static.json +1 -1
  69. package/dist-lib/public-origins-lib.json +134 -78
  70. package/dist-lib/react-native-host-modules.cjs +1 -1
  71. package/dist-lib/react-native-host-modules.mjs +1 -1
  72. package/dist-lib/reap-browser.cjs +2 -2
  73. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  74. package/dist-lib/sdk.cjs +2 -1
  75. package/dist-lib/sdk.mjs +2 -1
  76. package/dist-lib/skills.cjs +3570 -2160
  77. package/dist-lib/swift-compile.cjs +473 -351
  78. package/dist-lib/swift-compile.mjs +471 -349
  79. package/dist-lib/swift-package.cjs +36 -6
  80. package/dist-lib/swift-package.mjs +35 -6
  81. package/dist-lib/swift-submit.cjs +1 -1
  82. package/dist-lib/swift-submit.mjs +1 -1
  83. package/dist-lib/swift-toolchain.cjs +26 -11
  84. package/dist-lib/swift.cjs +1 -1
  85. package/dist-lib/vite-swift.cjs +2418 -1132
  86. package/dist-lib/vite.cjs +1907 -766
  87. package/dist-lib/worklet-executable.cjs +1 -1
  88. package/dist-lib/worklet-executable.mjs +1 -1
  89. package/dist-types/packages/peach-engine/src/engine/canvaskit-api.d.ts +1 -1
  90. package/dist-types/packages/peach-engine/src/engine/clipboardContract.d.ts +9 -1
  91. package/dist-types/packages/peach-engine/src/preview/upload-protocol.d.ts +11 -3
  92. package/dist-types/packages/peach-engine/src/webview-automation-host.d.ts +6 -0
  93. package/dist-types/packages/peach-globals/src/clipboardBridgeContract.d.ts +2 -0
  94. package/package.json +1 -1
  95. package/runtime-companion.json +1 -1
  96. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h +51 -2
  97. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +21 -0
  98. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFComposeAssistantViewController.h +29 -0
  99. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMailComposeControllerDeferredAction.h +14 -0
  100. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMailComposeViewController.h +162 -0
  101. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMailDraft.h +24 -0
  102. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMessageComposeViewController+UPI.h +31 -0
  103. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMessageComposeViewController.h +169 -0
  104. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MessageUI.h +13 -0
  105. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Modules/module.modulemap +11 -0
  106. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h +10 -0
  107. package/sdk/ios/usr/include/arm/param.h +151 -0
  108. package/sdk/ios/usr/include/dispatch/dispatch.h +3 -0
  109. package/sdk/ios/usr/include/dlfcn.h +1 -2
  110. package/sdk/ios/usr/include/machine/param.h +42 -0
  111. package/sdk/ios/usr/include/net/if.h +1 -2
  112. package/sdk/ios/usr/include/peach/pthread.h +4 -4
  113. package/sdk/ios/usr/include/pthread/qos.h +304 -0
  114. package/sdk/ios/usr/include/sys/_types/_fd_clr.h +31 -0
  115. package/sdk/ios/usr/include/sys/_types/_fd_copy.h +31 -0
  116. package/sdk/ios/usr/include/sys/_types/_fd_def.h +121 -0
  117. package/sdk/ios/usr/include/sys/_types/_fd_isset.h +31 -0
  118. package/sdk/ios/usr/include/sys/_types/_fd_set.h +31 -0
  119. package/sdk/ios/usr/include/sys/_types/_fd_setsize.h +31 -0
  120. package/sdk/ios/usr/include/sys/_types/_fd_zero.h +31 -0
  121. package/sdk/ios/usr/include/sys/cdefs.h +3 -0
  122. package/sdk/ios/usr/include/sys/param.h +235 -0
  123. package/sdk/ios/usr/include/sys/proc.h +1 -0
  124. package/sdk/ios/usr/include/sys/qos.h +151 -12
  125. package/sdk/ios/wasm/include/__typedef_sigset_t.h +7 -0
  126. package/sdk/ios/wasm/include/fcntl.h +11 -0
  127. package/sdk/ios/wasm/include/mach/machine/boolean.h +2 -0
  128. package/sdk/ios/wasm/include/mach/machine/exception.h +5 -0
  129. package/sdk/ios/wasm/include/mach/machine/kern_return.h +2 -0
  130. package/sdk/ios/wasm/include/mach/machine/processor_info.h +2 -0
  131. package/sdk/ios/wasm/include/mach/machine/rpc.h +2 -0
  132. package/sdk/ios/wasm/include/mach/machine/thread_state.h +3 -0
  133. package/sdk/ios/wasm/include/mach/machine/thread_status.h +3 -0
  134. package/sdk/ios/wasm/include/mach/machine/vm_param.h +3 -0
  135. package/sdk/ios/wasm/include/mach/machine/vm_types.h +18 -0
  136. package/sdk/ios/wasm/include/machine/_types.h +153 -0
  137. package/sdk/ios/wasm/include/machine/endian.h +2 -0
  138. package/sdk/ios/wasm/include/machine/limits.h +2 -0
  139. package/sdk/ios/wasm/include/machine/types.h +30 -0
  140. package/sdk/ios/wasm/include/poll.h +8 -0
  141. package/sdk/ios/wasm/include/pthread.h +50 -0
  142. package/sdk/ios/wasm/include/signal.h +72 -0
  143. package/sdk/ios/wasm/include/stdlib.h +3 -0
  144. package/sdk/ios/wasm/include/string.h +10 -0
  145. package/sdk/ios/wasm/include/sys/_pthread/_pthread_attr_t.h +7 -0
  146. package/sdk/ios/wasm/include/sys/_pthread/_pthread_t.h +7 -0
  147. package/sdk/ios/wasm/include/sys/mman.h +122 -0
  148. package/sdk/ios/wasm/include/sys/select.h +37 -0
  149. package/sdk/ios/wasm/include/sys/signal.h +259 -0
  150. package/sdk/ios/wasm/include/sys/socket.h +8 -0
  151. package/sdk/ios/wasm/include/sys/types.h +14 -0
  152. package/sdk/ios/wasm/include/sys/ucontext.h +1 -0
  153. package/sdk/ios/wasm/include/sys/uio.h +11 -0
  154. package/sdk/ios/wasm/include/sys/wait.h +89 -0
  155. package/sdk/ios/wasm/include/time.h +8 -0
  156. package/sdk/ios/wasm/include/unistd.h +17 -0
  157. package/src/bridge-contract.ts +2 -0
  158. package/src/chromium-admission.ts +10 -5
  159. package/src/device-catalog.ts +4 -4
  160. package/src/host/fetch-proxy-handler.ts +20 -0
  161. package/src/metro-plugin.ts +5 -2
  162. package/src/nitro-adapter.lock.json +6 -6
  163. package/src/nitro-compile.ts +63 -2
  164. package/src/numbered-lock.ts +72 -0
  165. package/src/react-native-coverage/capability-reference-resolution.ts +62 -5
  166. package/src/react-native-coverage/capability-source-references.ts +50 -13
  167. package/src/react-native-coverage/native-source-credit.ts +126 -0
  168. package/src/react-native-coverage/native-source-ranges-file.ts +38 -0
  169. package/src/react-native-coverage/native-surface.ts +49 -0
  170. package/src/react-native-coverage/verified-reach.ts +22 -2
  171. package/src/runtime-assets.ts +17 -0
  172. package/src/swift-compile.ts +84 -48
  173. package/src/swift-coverage/indexing.ts +17 -1
  174. package/src/swift-coverage/sdk.ts +71 -0
  175. package/src/swift-coverage/source.ts +74 -2
  176. package/src/swift-coverage/types.ts +6 -0
  177. package/src/swift-distribution.lock.json +12 -12
  178. package/src/swift-host.ts +133 -14
  179. package/src/swift-objc-compile.ts +6 -21
  180. package/src/swift-objc-metadata.ts +2 -8
  181. package/src/swift-objc-platform.ts +53 -0
  182. package/src/swift-objc-standin.ts +45 -1
  183. package/src/swift-package-manifest.ts +48 -3
  184. package/src/swift-package.ts +59 -9
  185. package/src/swift-packages.ts +157 -44
  186. package/src/swift-source-pods.ts +288 -0
  187. package/src/swift-toolchain.ts +32 -10
  188. package/src/vite-plugin-one.ts +5 -4
  189. package/src/worker-system-chunks.ts +7 -1
  190. package/src/xcode-project.ts +40 -11
@@ -3,6 +3,9 @@ import * as ts from 'typescript/ast'
3
3
  import type { TypeScriptSourceParser } from './native-typescript-parser'
4
4
  import type { Symbol as NativeSymbol } from 'typescript/async'
5
5
 
6
+ export const NESTED_ROOT_CONTAINER_EXCLUSION =
7
+ 'nested root container; member chains counted at use sites'
8
+
6
9
  export type CapabilityReferenceKind =
7
10
  | 'export'
8
11
  | 'member'
@@ -62,8 +65,14 @@ export async function collectCapabilityReferences(
62
65
  path: string,
63
66
  packageNames: ReadonlySet<string> | null,
64
67
  corpus = 'fixture',
65
- nestedRoots: readonly { exportName: string | null; module: string }[] = [],
68
+ sourceRoots: readonly { exportName: string | null; module: string }[] = [],
66
69
  ): Promise<CapabilityReferenceCandidate[]> {
70
+ // native namespaces are export containers but retain one-level member identities.
71
+ const nestedRoots = [
72
+ ...sourceRoots.map((root) => ({ ...root, nestedMembers: true })),
73
+ { module: 'react-native', exportName: 'Platform', nestedMembers: false },
74
+ { module: 'react-native', exportName: 'StyleSheet', nestedMembers: false },
75
+ ]
67
76
  // an escaped module name needs decoding. otherwise a package-bound literal
68
77
  // must contain its package name before opening a native compiler program.
69
78
  if (
@@ -192,7 +201,7 @@ export async function collectCapabilityReferences(
192
201
  (root) =>
193
202
  root.module === binding.module && root.exportName === binding.exportName,
194
203
  )
195
- ? 'nested root container; member chains counted at use sites'
204
+ ? NESTED_ROOT_CONTAINER_EXCLUSION
196
205
  : null)),
197
206
  importForm,
198
207
  }
@@ -207,13 +216,38 @@ export async function collectCapabilityReferences(
207
216
  bindings.set(symbol.id, binding)
208
217
  bindingNames.set(symbol.id, name)
209
218
  }
219
+ // the global require: absent, or the declaration-less symbol the binder gives it in
220
+ // JavaScript files. a local binding of the name has declarations and is not it.
221
+ function isGlobalRequire(node: ts.Expression): node is ts.Identifier {
222
+ if (!ts.isIdentifier(node) || node.text !== 'require') return false
223
+ const symbol = symbols.get(node)
224
+ return !symbol || symbol.declarations.length === 0
225
+ }
226
+ // `require('m')` as the owner of a member read, whose members are the module's
227
+ // exports like a namespace import's
228
+ function requireModuleBinding(node: ts.Node): SourceBinding | undefined {
229
+ if (
230
+ !ts.isCallExpression(node) ||
231
+ !isGlobalRequire(node.expression) ||
232
+ !node.arguments[0] ||
233
+ !ts.isStringLiteralLikeNode(node.arguments[0])
234
+ )
235
+ return undefined
236
+ const module = node.arguments[0].text
237
+ const packageName = packageFor(module)
238
+ return packageName
239
+ ? { packageName, module, exportName: '*', typeOnly: false }
240
+ : undefined
241
+ }
210
242
  function bindingFor(node: ts.Node, nestedMembers = false): SourceBinding | undefined {
211
243
  if (ts.isIdentifier(node)) {
212
244
  const symbol = symbols.get(node)
213
245
  return symbol ? bindings.get(symbol.id) : undefined
214
246
  }
215
247
  if (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) {
216
- const owner = bindingFor(node.expression, nestedMembers)
248
+ const owner =
249
+ requireModuleBinding(node.expression) ??
250
+ bindingFor(node.expression, nestedMembers)
217
251
  if (!owner || owner.typeOnly) return undefined
218
252
  const member = ts.isPropertyAccessExpression(node)
219
253
  ? node.name.text
@@ -232,7 +266,9 @@ export async function collectCapabilityReferences(
232
266
  member &&
233
267
  nestedRoots.some(
234
268
  (root) =>
235
- root.module === owner.module && root.exportName === owner.exportName,
269
+ root.nestedMembers &&
270
+ root.module === owner.module &&
271
+ root.exportName === owner.exportName,
236
272
  )
237
273
  )
238
274
  return { ...owner, memberPath: [...(owner.memberPath ?? []), member] }
@@ -260,7 +296,9 @@ export async function collectCapabilityReferences(
260
296
  !binding.typeOnly &&
261
297
  nestedRoots.some(
262
298
  (root) =>
263
- root.module === binding.module && root.exportName === binding.exportName,
299
+ root.nestedMembers &&
300
+ root.module === binding.module &&
301
+ root.exportName === binding.exportName,
264
302
  )
265
303
  ? { binding, names: [...(binding.memberPath ?? []), name] }
266
304
  : undefined
@@ -406,9 +444,7 @@ export async function collectCapabilityReferences(
406
444
  ) {
407
445
  const call = node.initializer
408
446
  if (
409
- ts.isIdentifier(call.expression) &&
410
- call.expression.text === 'require' &&
411
- !symbols.get(call.expression) &&
447
+ isGlobalRequire(call.expression) &&
412
448
  call.arguments[0] &&
413
449
  ts.isStringLiteralLikeNode(call.arguments[0])
414
450
  ) {
@@ -459,9 +495,7 @@ export async function collectCapabilityReferences(
459
495
  if (
460
496
  ts.isCallExpression(node) &&
461
497
  ts.isExpressionStatement(node.parent) &&
462
- ts.isIdentifier(node.expression) &&
463
- node.expression.text === 'require' &&
464
- !symbols.get(node.expression) &&
498
+ isGlobalRequire(node.expression) &&
465
499
  node.arguments[0] &&
466
500
  ts.isStringLiteralLikeNode(node.arguments[0])
467
501
  ) {
@@ -488,6 +522,7 @@ export async function collectCapabilityReferences(
488
522
  !binding.typeOnly &&
489
523
  nestedRoots.some(
490
524
  (root) =>
525
+ root.nestedMembers &&
491
526
  root.module === binding.module &&
492
527
  (binding.exportName === '*' || root.exportName === binding.exportName),
493
528
  )
@@ -621,7 +656,9 @@ export async function collectCapabilityReferences(
621
656
  ts.isIdentifier(node.name) &&
622
657
  (!nestedRoots.some(
623
658
  (root) =>
624
- root.module === owner.module && root.exportName === owner.exportName,
659
+ root.nestedMembers &&
660
+ root.module === owner.module &&
661
+ root.exportName === owner.exportName,
625
662
  ) ||
626
663
  (safeNamespaceBinding(node.name) &&
627
664
  ts.isIdentifier(root) &&
@@ -1133,7 +1170,7 @@ export async function collectCapabilityReferences(
1133
1170
  ts.isPropertyAccessExpression(node) ||
1134
1171
  ts.isElementAccessExpression(node)
1135
1172
  ) {
1136
- const owner = bindingFor(node.expression)
1173
+ const owner = requireModuleBinding(node.expression) ?? bindingFor(node.expression)
1137
1174
  if (owner && !owner.typeOnly) {
1138
1175
  const member = ts.isPropertyAccessExpression(node)
1139
1176
  ? node.name.text
@@ -0,0 +1,126 @@
1
+ import {
2
+ compareReleases,
3
+ isRelease,
4
+ nativeSourceRelease,
5
+ nativeSourceVerdict,
6
+ } from '../../../peach-compat/src/native-source-ranges'
7
+ import { NATIVE_SOURCE_RANGES } from './native-source-ranges-file'
8
+ import type { NativeSourcePackage } from '../../../peach-compat/src/native-source-ranges-types'
9
+
10
+ // what an app declares about the iOS renderer, read from its project files.
11
+ // unreadable: the project builds its configuration in code, so a missing
12
+ // declaration says nothing.
13
+ export type ArchitectureSetting =
14
+ | { renderer: 'fabric' | 'paper' | undefined }
15
+ | { unreadable: string }
16
+
17
+ export type FeatureCredit =
18
+ | { status: 'credited'; verifiedRelease: string }
19
+ | {
20
+ status: 'unknown'
21
+ reason: string
22
+ // per group whose native source differs from the closest verified release
23
+ differs: readonly {
24
+ group: string
25
+ verifiedRelease: string
26
+ files: readonly string[]
27
+ }[]
28
+ }
29
+
30
+ const unknown = (reason: string): FeatureCredit => ({
31
+ status: 'unknown',
32
+ reason,
33
+ differs: [],
34
+ })
35
+
36
+ // the React Native release an app installs and the package that defines which
37
+ // releases build which architecture
38
+ export type ReactNativeHost = {
39
+ config: NativeSourcePackage
40
+ version: string | undefined
41
+ }
42
+
43
+ /**
44
+ * a verified cell holds on another release when the native source behind the
45
+ * feature is byte identical there, and the app builds the architecture that
46
+ * source describes. a library builds the architecture its React Native release
47
+ * builds.
48
+ */
49
+ export function creditFeature(
50
+ config: NativeSourcePackage,
51
+ featureId: string,
52
+ version: string,
53
+ architecture: ArchitectureSetting,
54
+ host: ReactNativeHost,
55
+ ): FeatureCredit {
56
+ const groups = config.features[featureId]
57
+ if (!groups) return unknown(`no native source is mapped for feature ${featureId}`)
58
+ const verdict = nativeSourceVerdict(
59
+ NATIVE_SOURCE_RANGES,
60
+ config.packageName,
61
+ groups,
62
+ version,
63
+ )
64
+ if (verdict.status === 'unknown') return unknown(verdict.reason)
65
+ if (verdict.status === 'differs')
66
+ return {
67
+ status: 'unknown',
68
+ reason: `${config.packageName} ${version} changed native source this feature executes: ${verdict.changed.map((entry) => `${entry.group} (${entry.files.length})`).join(', ')}`,
69
+ differs: verdict.changed,
70
+ }
71
+ const release = nativeSourceRelease(NATIVE_SOURCE_RANGES, config.packageName, version)
72
+ const legacy =
73
+ release && !release.onlyArchitecture
74
+ ? legacyArchitectureReason(architecture, host)
75
+ : undefined
76
+ if (legacy) return unknown(legacy)
77
+ return { status: 'credited', verifiedRelease: verdict.verifiedRelease }
78
+ }
79
+
80
+ /**
81
+ * why the app may build the legacy iOS architecture, which runs different
82
+ * native code than the new one every verified cell is captured on. undefined
83
+ * when it builds the new one.
84
+ */
85
+ export function legacyArchitectureReason(
86
+ architecture: ArchitectureSetting,
87
+ host: ReactNativeHost,
88
+ ): string | undefined {
89
+ if (host.version === undefined || !isRelease(host.version))
90
+ return `the ${host.config.packageName} release is unknown, so the iOS architecture is too`
91
+ const forced = host.config.onlyArchitectureFrom
92
+ if (forced && compareReleases(host.version, forced.version) >= 0) return undefined
93
+ if ('unreadable' in architecture) return architecture.unreadable
94
+ const renderer =
95
+ architecture.renderer ??
96
+ (host.config.newArchitectureDefaultFrom &&
97
+ compareReleases(host.version, host.config.newArchitectureDefaultFrom.version) >= 0
98
+ ? 'fabric'
99
+ : 'paper')
100
+ return renderer === 'paper'
101
+ ? `the app builds the legacy iOS architecture on ${host.config.packageName} ${host.version}; verified cells are captured on the new one`
102
+ : undefined
103
+ }
104
+
105
+ /**
106
+ * releases that would credit a feature if a cell were captured on them. the
107
+ * architecture is not considered: it depends on each app.
108
+ */
109
+ export function creditingReleases(
110
+ config: NativeSourcePackage,
111
+ featureId: string,
112
+ version: string,
113
+ ): string[] {
114
+ const groups = config.features[featureId]
115
+ const entry = NATIVE_SOURCE_RANGES.packages[config.packageName]
116
+ if (!groups || !entry) return []
117
+ return entry.releases
118
+ .map((release) => release.version)
119
+ .filter(
120
+ (release) =>
121
+ !entry.verifiedReleases.includes(release) &&
122
+ nativeSourceVerdict(NATIVE_SOURCE_RANGES, config.packageName, groups, version, [
123
+ release,
124
+ ]).status === 'identical',
125
+ )
126
+ }
@@ -0,0 +1,38 @@
1
+ import { z } from 'zod'
2
+ import rangesData from '../../../peach-compat/src/generated/native-source-ranges.json'
3
+ import type { NativeSourceRangesFile } from '../../../peach-compat/src/native-source-ranges-types'
4
+
5
+ const run = z.object({
6
+ from: z.string(),
7
+ to: z.string(),
8
+ digest: z.string(),
9
+ changed: z.array(z.tuple([z.number(), z.string()])),
10
+ files: z.number(),
11
+ })
12
+
13
+ const schema = z.object({
14
+ schemaVersion: z.literal(1),
15
+ packages: z.record(
16
+ z.string(),
17
+ z.object({
18
+ repository: z.string(),
19
+ reference: z.string(),
20
+ referenceCommit: z.string(),
21
+ verifiedReleases: z.array(z.string()),
22
+ definitionDigest: z.string(),
23
+ releases: z.array(z.object({ version: z.string(), onlyArchitecture: z.boolean() })),
24
+ groups: z.record(
25
+ z.string(),
26
+ z.object({
27
+ files: z.number(),
28
+ referenceDigest: z.string(),
29
+ keys: z.array(z.string()),
30
+ runs: z.array(run),
31
+ }),
32
+ ),
33
+ }),
34
+ ),
35
+ })
36
+
37
+ // the checked-in output of scripts/generate/native-source-ranges.ts
38
+ export const NATIVE_SOURCE_RANGES: NativeSourceRangesFile = schema.parse(rangesData)
@@ -0,0 +1,49 @@
1
+ import { existsSync, readFileSync, readdirSync } from 'node:fs'
2
+ import { dirname, join } from 'node:path'
3
+
4
+ export type NativeSurface =
5
+ | { kind: 'none' }
6
+ | { kind: 'native'; evidence: string }
7
+ | { kind: 'unread'; reason: string }
8
+
9
+ // whether an installed package ships native iOS code of its own: a podspec, an
10
+ // ios directory, an Expo module manifest, an Expo config plugin (it edits the
11
+ // native project at prebuild) or a React Native codegen config. a
12
+ // package without any is pure JavaScript; the React Native it renders through
13
+ // stays attributed to react-native itself, which the scan does not follow into
14
+ // library source.
15
+ export function installedNativeSurface(from: string, packageName: string): NativeSurface {
16
+ let directory = from
17
+ while (true) {
18
+ const root = join(directory, 'node_modules', packageName)
19
+ if (existsSync(join(root, 'package.json'))) return surfaceOf(root)
20
+ const parent = dirname(directory)
21
+ if (parent === directory) break
22
+ directory = parent
23
+ }
24
+ return {
25
+ kind: 'unread',
26
+ reason: `${packageName} is not installed, so its files were not read`,
27
+ }
28
+ }
29
+
30
+ function surfaceOf(root: string): NativeSurface {
31
+ try {
32
+ const podspec = readdirSync(root).find((name) => name.endsWith('.podspec'))
33
+ if (podspec) return { kind: 'native', evidence: podspec }
34
+ if (existsSync(join(root, 'ios'))) return { kind: 'native', evidence: 'ios/' }
35
+ if (existsSync(join(root, 'expo-module.config.json')))
36
+ return { kind: 'native', evidence: 'expo-module.config.json' }
37
+ if (existsSync(join(root, 'app.plugin.js')))
38
+ return { kind: 'native', evidence: 'app.plugin.js' }
39
+ const manifest: unknown = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'))
40
+ if (typeof manifest === 'object' && manifest !== null && 'codegenConfig' in manifest)
41
+ return { kind: 'native', evidence: 'package.json codegenConfig' }
42
+ return { kind: 'none' }
43
+ } catch (error) {
44
+ return {
45
+ kind: 'unread',
46
+ reason: error instanceof Error ? error.message : String(error),
47
+ }
48
+ }
49
+ }
@@ -13,8 +13,28 @@ function conditionAllows(
13
13
  ): boolean {
14
14
  if (!condition.anyOf.includes(door)) return false
15
15
  const rule = condition.values?.[door]
16
- if (!rule || value === null) return true
17
- return 'only' in rule ? rule.only.includes(value) : !rule.except.includes(value)
16
+ if (!rule) return true
17
+ if (value === null) return condition.unknownValue !== 'exclude' && !('kind' in rule)
18
+ if ('only' in rule) return rule.only.includes(value)
19
+ if ('except' in rule) return !rule.except.includes(value)
20
+ switch (rule.kind) {
21
+ case 'nonnegative-number':
22
+ return typeof value === 'number' && Number.isFinite(value) && value >= 0
23
+ case 'negative-number':
24
+ return typeof value === 'number' && Number.isFinite(value) && value < 0
25
+ case 'percentage':
26
+ return (
27
+ typeof value === 'string' &&
28
+ /^(?:\d+(?:\.\d+)?|\.\d+)%$/.test(value) &&
29
+ Number.isFinite(Number(value.slice(0, -1)))
30
+ )
31
+ case 'opaque-hex-color':
32
+ return typeof value === 'string' && /^#(?:[\da-f]{3}|[\da-f]{6})$/i.test(value)
33
+ case 'unit-interval':
34
+ return typeof value === 'number' && value >= 0 && value <= 1
35
+ case 'integer':
36
+ return typeof value === 'number' && Number.isSafeInteger(value)
37
+ }
18
38
  }
19
39
 
20
40
  // features a reference can take part in: a front door, and for a feature that
@@ -224,7 +224,24 @@ export function resolveRuntimeFilePath(
224
224
  return fullPath
225
225
  }
226
226
 
227
+ // the shell page, its workers and every runtime file are one cross-origin
228
+ // isolated surface: Swift timed waits block with Atomics.wait on a
229
+ // SharedArrayBuffer, which exists only when the document and its workers are
230
+ // isolated. require-corp because Safari does not isolate under credentialless.
231
+ export function setRuntimeIsolationHeaders(res: ServerResponse) {
232
+ res.setHeader('cross-origin-opener-policy', 'same-origin')
233
+ res.setHeader('cross-origin-embedder-policy', 'require-corp')
234
+ res.setHeader('cross-origin-resource-policy', 'cross-origin')
235
+ }
236
+
237
+ export function sendShellHtml(res: ServerResponse, html: string) {
238
+ setRuntimeIsolationHeaders(res)
239
+ res.setHeader('content-type', 'text/html')
240
+ res.end(html)
241
+ }
242
+
227
243
  export function serveRuntimeFile(req: any, res: any, fullPath: string) {
244
+ setRuntimeIsolationHeaders(res)
228
245
  const ext = path.extname(fullPath)
229
246
  const stat = fs.statSync(fullPath)
230
247
  const lastModified = stat.mtime.toUTCString()
@@ -41,7 +41,12 @@ import {
41
41
  swiftObjCPrivateImports,
42
42
  } from './swift-objc-import'
43
43
  import { validateObjcPeerStartupLibraries } from './swift-objc-metadata'
44
- import { materializeObjcSdk, objcView, WASI_EMULATION_FLAGS } from './swift-objc-standin'
44
+ import {
45
+ iosDeploymentMinimum,
46
+ materializeObjcSdk,
47
+ objcSdkIntakeFlags,
48
+ objcView,
49
+ } from './swift-objc-standin'
45
50
  import {
46
51
  OBJC_RESOURCE_ACCESSOR_BODY,
47
52
  OBJC_RESOURCE_ACCESSOR_HEADER,
@@ -723,16 +728,22 @@ export function swiftAvailableModules(
723
728
  * `available`) that nothing available provides, each with the files
724
729
  * importing it. the compiler stops at the first
725
730
  * missing module; this names all of them at once.
731
+ * `providedByFile` names the compiler modules each file's own target
732
+ * settings provide, which no sdk ships: Builtin, which the compiler
733
+ * synthesizes when the target enables the BuiltinModule feature.
726
734
  */
727
735
  export function missingSwiftModules(
728
736
  files: Record<string, string>,
729
737
  available: ReadonlySet<string>,
738
+ providedByFile: (file: string) => readonly string[] = () => [],
730
739
  ): Map<string, string[]> {
731
740
  const missing = new Map<string, string[]>()
732
741
  for (const [file, contents] of Object.entries(files)) {
733
742
  if (!file.endsWith('.swift') || file === 'Package.swift') continue
734
- for (const name of new Set(swiftImportNames(contents, available))) {
735
- if (available.has(name)) continue
743
+ const extra = providedByFile(file)
744
+ const scoped = extra.length === 0 ? available : new Set([...available, ...extra])
745
+ for (const name of new Set(swiftImportNames(contents, scoped))) {
746
+ if (scoped.has(name)) continue
736
747
  missing.set(name, [...(missing.get(name) ?? []), file])
737
748
  }
738
749
  }
@@ -934,9 +945,9 @@ export function emitSwiftPackageManifest(args: {
934
945
  cxxLanguageStandard?: string
935
946
  native?: Map<string, SwiftNativeTargetPlan>
936
947
  headerDirectory?: string
937
- objcExports?: { modules: Set<string>; flags: string[]; rootModule: string }
938
- /** the objective-c runtime and sdk flags every original native unit compiles with. */
939
- nativeFlags?: string[]
948
+ objcExports?: { modules: Set<string>; rootModule: string }
949
+ /** the objective-c runtime, sdk and platform flags each target's original native units compile with. */
950
+ nativeFlags?: Map<string, string[]>
940
951
  siblings: Map<string, string[]>
941
952
  moduleRoot: string
942
953
  oneModule?: boolean
@@ -1030,6 +1041,17 @@ export function emitSwiftPackageManifest(args: {
1030
1041
  const defines = (target.defines ?? [])
1031
1042
  .map((name) => ` .define(${JSON.stringify(name)}),`)
1032
1043
  .join('')
1044
+ const features = (target.experimentalFeatures ?? [])
1045
+ .map((name) => ` .enableExperimentalFeature(${JSON.stringify(name)}),`)
1046
+ .join('')
1047
+ const upcoming = (target.upcomingFeatures ?? [])
1048
+ .map((name) => ` .enableUpcomingFeature(${JSON.stringify(name)}),`)
1049
+ .join('')
1050
+ // the manifest's own raw flags last, where swiftpm puts a target's
1051
+ // settings: after the build's defaults, so they win as they do in xcode.
1052
+ const upstream = (target.swiftFlags ?? [])
1053
+ .map((flag) => `, ${JSON.stringify(flag)}`)
1054
+ .join('')
1033
1055
  // a distribution's modules import from its modules/ directory, and its
1034
1056
  // objects link as inputs, exactly as a source build links every object it
1035
1057
  // compiled: whole, and ahead of the sdk libraries, so PeachICU's
@@ -1073,7 +1095,7 @@ export function emitSwiftPackageManifest(args: {
1073
1095
  )
1074
1096
  ? `, "-emit-objc-header-path", ${JSON.stringify(path.join(args.headerDirectory, `${target.name}-${args.objcExports?.modules.has(target.name) ? 'Cxx' : 'Swift'}.h`))}`
1075
1097
  : ''
1076
- const swiftSettings = `swiftSettings: [.swiftLanguageMode(.v${target.languageMode}),${isolation}${interoperability}${defines}${exports} .unsafeFlags(["-Osize", "-Xfrontend", "-enable-cross-import-overlays"${overlayFlags}${FOUNDATION_IMPLICIT_FLAGS}${oneModule ? ONE_IMPLICIT_FLAGS : ''}${imports}${nativeImports}${nativeImportFlags}${header}])]`
1098
+ const swiftSettings = `swiftSettings: [.swiftLanguageMode(.v${target.languageMode}),${isolation}${interoperability}${defines}${features}${upcoming}${exports} .unsafeFlags(["-Osize", "-Xfrontend", "-enable-cross-import-overlays"${overlayFlags}${FOUNDATION_IMPLICIT_FLAGS}${oneModule ? ONE_IMPLICIT_FLAGS : ''}${imports}${nativeImports}${nativeImportFlags}${header}${upstream}])]`
1077
1099
  const deps = [
1078
1100
  ...new Set([
1079
1101
  ...(target.executable
@@ -1154,12 +1176,12 @@ export function emitSwiftPackageManifest(args: {
1154
1176
  const cxxDefines = macroSettings(target.cxxDefines)
1155
1177
  const nativeSettings = native?.clang
1156
1178
  ? [
1157
- `cSettings: [${cDefines} .unsafeFlags(${JSON.stringify([...(args.objcExports?.flags ?? args.nativeFlags ?? []), ...native.clang.flags])})]`,
1158
- `cxxSettings: [${cxxDefines} .unsafeFlags(${JSON.stringify(['-fno-cxx-modules', ...(args.objcExports?.flags ?? args.nativeFlags ?? []), ...native.clang.cxxFlags])})]`,
1179
+ `cSettings: [${cDefines} .unsafeFlags(${JSON.stringify([...(args.nativeFlags?.get(target.name) ?? []), ...native.clang.flags])})]`,
1180
+ `cxxSettings: [${cxxDefines} .unsafeFlags(${JSON.stringify(['-fno-cxx-modules', ...(args.nativeFlags?.get(target.name) ?? []), ...native.clang.cxxFlags])})]`,
1159
1181
  ].join(', ')
1160
1182
  : [
1161
- `cSettings: [${cDefines} .unsafeFlags(${JSON.stringify([...(args.objcExports?.flags ?? args.nativeFlags ?? []), ...(native?.flags ?? [])])})]`,
1162
- `cxxSettings: [${cxxDefines} .unsafeFlags(${JSON.stringify(['-fno-cxx-modules', ...(args.objcExports?.flags ?? args.nativeFlags ?? []), ...(native?.cxxFlags ?? [])])})]`,
1183
+ `cSettings: [${cDefines} .unsafeFlags(${JSON.stringify([...(args.nativeFlags?.get(target.name) ?? []), ...(native?.flags ?? [])])})]`,
1184
+ `cxxSettings: [${cxxDefines} .unsafeFlags(${JSON.stringify(['-fno-cxx-modules', ...(args.nativeFlags?.get(target.name) ?? []), ...(native?.cxxFlags ?? [])])})]`,
1163
1185
  ].join(', ')
1164
1186
  return [
1165
1187
  ` ${kind}(`,
@@ -1203,7 +1225,7 @@ export function emitSwiftPackageManifest(args: {
1203
1225
  ' path: "PeachObjCExports",',
1204
1226
  ` sources: ${JSON.stringify(['root.m', ...[...args.objcExports.modules].map((name) => `${name}.m`)])},`,
1205
1227
  ' publicHeadersPath: "include",',
1206
- ` cSettings: [.unsafeFlags(${JSON.stringify([...args.objcExports.flags.filter((flag) => flag !== '-fobjc-arc'), '-fno-objc-arc', '-Xclang', '-disable-objc-default-synthesize-properties'])})]),`,
1228
+ ` cSettings: [.unsafeFlags(${JSON.stringify([...args.nativeFlags!.get(args.objcExports.rootModule)!.filter((flag) => flag !== '-fobjc-arc'), '-fno-objc-arc', '-Xclang', '-disable-objc-default-synthesize-properties'])})]),`,
1207
1229
  ]
1208
1230
  : []),
1209
1231
  ...[...(args.native?.entries() ?? [])].flatMap(([name, native]) => {
@@ -1225,8 +1247,8 @@ export function emitSwiftPackageManifest(args: {
1225
1247
  ` path: ${JSON.stringify(native.clang ? '.' : native.path)},`,
1226
1248
  ` sources: ${JSON.stringify(native.clang ? group.sources.map((source) => path.posix.join(native.path, source)) : group.sources)},`,
1227
1249
  ` publicHeadersPath: ${JSON.stringify(native.clang ? path.posix.dirname(native.clang.modulemap) : 'include')},`,
1228
- ` cSettings: [${macroSettings(owner?.cDefines)} .unsafeFlags(${JSON.stringify([...(args.objcExports?.flags ?? args.nativeFlags ?? []), ...group.flags])})],`,
1229
- ` cxxSettings: [${macroSettings(owner?.cxxDefines)} .unsafeFlags(${JSON.stringify(['-fno-cxx-modules', ...(args.objcExports?.flags ?? args.nativeFlags ?? []), '-I', native.includeDirectory, '-I', args.headerDirectory, ...group.cxxFlags])})]),`,
1250
+ ` cSettings: [${macroSettings(owner?.cDefines)} .unsafeFlags(${JSON.stringify([...(args.nativeFlags?.get(name) ?? []), ...group.flags])})],`,
1251
+ ` cxxSettings: [${macroSettings(owner?.cxxDefines)} .unsafeFlags(${JSON.stringify(['-fno-cxx-modules', ...(args.nativeFlags?.get(name) ?? []), '-I', native.includeDirectory, '-I', args.headerDirectory, ...group.cxxFlags])})]),`,
1230
1252
  ])
1231
1253
  : []
1232
1254
  }),
@@ -6062,6 +6084,18 @@ export function writeSwiftProject(
6062
6084
  }
6063
6085
  >()
6064
6086
  const objcProducers = new Set<string>()
6087
+ // the pinned toolchain, checked once for every original target.
6088
+ let checkedToolchain: string | undefined
6089
+ const nativeToolchain = () => {
6090
+ if (checkedToolchain) return checkedToolchain
6091
+ const pin: { release: string } =
6092
+ distribution ??
6093
+ JSON.parse(readFileSync(path.join(moduleRoot, 'toolchain.json'), 'utf8'))
6094
+ checkedToolchain = swiftToolchain(pin.release, swiftModuleSdk(moduleRoot))
6095
+ return checkedToolchain
6096
+ }
6097
+ const deploymentTarget = (name: string) =>
6098
+ input.nativeTargets?.find((value) => value.name === name)?.deploymentTarget ?? '16.0'
6065
6099
  const targetStagedFiles = new Map<string, Map<string, string | Buffer | undefined>>()
6066
6100
  const stageTargetFile = (
6067
6101
  target: string,
@@ -6257,11 +6291,7 @@ export function writeSwiftProject(
6257
6291
  ...headers.map((file) => path.posix.dirname(file)),
6258
6292
  ]),
6259
6293
  ].flatMap((dir) => ['-I', path.join(layout.root, dir)])
6260
- const pin: { release: string } =
6261
- distribution ??
6262
- JSON.parse(readFileSync(path.join(moduleRoot, 'toolchain.json'), 'utf8'))
6263
- const release = pin.release
6264
- const toolchainBin = swiftToolchain(release, swiftModuleSdk(moduleRoot))
6294
+ const toolchainBin = nativeToolchain()
6265
6295
  const sdkHeaders = materializeObjcSdk(
6266
6296
  path.join(layout.root, '.build', 'peach-objc-sdk'),
6267
6297
  )
@@ -6362,7 +6392,7 @@ export function writeSwiftProject(
6362
6392
  path.join(layout.root, '.build', 'peach-objc-imports', target.name),
6363
6393
  {
6364
6394
  flags: stageFlags(originalFlags, path.join(sdkHeaders, 'usr/include')),
6365
- target: `arm64-apple-ios${settings?.deploymentTarget ?? '16.0'}-simulator`,
6395
+ target: `arm64-apple-ios${deploymentTarget(target.name)}-simulator`,
6366
6396
  },
6367
6397
  )
6368
6398
  const defined = new Set<string>()
@@ -6869,26 +6899,42 @@ export function writeSwiftProject(
6869
6899
  `import ${swiftTargetModuleName(target.name)}\n@main struct __PeachApplicationEntry { @MainActor static func main() { __peachRunApplication() } }\n`,
6870
6900
  )
6871
6901
  }
6872
- // original units compile on the objective-c runtime whether or not swift
6873
- // exports anything to them.
6902
+ // original units compile on the objective-c runtime, at their target's
6903
+ // deployment minimum, whether or not swift exports anything to them.
6874
6904
  const nativeFlags = (() => {
6875
6905
  if (native.size === 0) return undefined
6876
6906
  const headers = materializeObjcSdk(path.join(layout.root, '.build', 'peach-objc-sdk'))
6877
- return [
6878
- '-fobjc-runtime=gnustep-2.2',
6879
- '-fobjc-exceptions',
6880
- '-fexceptions',
6881
- '-fwasm-exceptions',
6882
- ...WASI_EMULATION_FLAGS,
6883
- '-fobjc-arc',
6884
- '-fblocks',
6885
- '-F',
6886
- path.join(headers, 'System/Library/Frameworks'),
6887
- '-idirafter',
6888
- path.join(headers, 'usr/include'),
6889
- '-I',
6890
- headerDirectory,
6891
- ]
6907
+ const moduleMaps = rootOwner
6908
+ ? [...objcModules].map(
6909
+ (name) =>
6910
+ `-fmodule-map-file=${path.join(headerModuleDirectory, name, 'module.modulemap')}`,
6911
+ )
6912
+ : []
6913
+ return new Map(
6914
+ targets.map((target) => {
6915
+ const version = deploymentTarget(target.name)
6916
+ const minimum = iosDeploymentMinimum(version)
6917
+ if (minimum === undefined)
6918
+ throw new Error(
6919
+ `${target.name}: unsupported IPHONEOS_DEPLOYMENT_TARGET ${JSON.stringify(version)}`,
6920
+ )
6921
+ return [
6922
+ target.name,
6923
+ [
6924
+ '-fobjc-runtime=gnustep-2.2',
6925
+ '-fobjc-exceptions',
6926
+ '-fexceptions',
6927
+ '-fwasm-exceptions',
6928
+ '-fobjc-arc',
6929
+ '-fblocks',
6930
+ ...objcSdkIntakeFlags(headers, nativeToolchain(), minimum),
6931
+ '-I',
6932
+ headerDirectory,
6933
+ ...moduleMaps,
6934
+ ],
6935
+ ]
6936
+ }),
6937
+ )
6892
6938
  })()
6893
6939
  let objcExports: Parameters<typeof emitSwiftPackageManifest>[0]['objcExports']
6894
6940
  if (rootOwner && input.objcPeerStartup)
@@ -6951,17 +6997,7 @@ public func __peachObjcExportRoot() { _objcRegisterPeerClass(NSObject.self, nati
6951
6997
  '',
6952
6998
  ].join('\n'),
6953
6999
  )
6954
- objcExports = {
6955
- modules: objcModules,
6956
- rootModule,
6957
- flags: [
6958
- ...nativeFlags!,
6959
- ...[...objcModules].map(
6960
- (name) =>
6961
- `-fmodule-map-file=${path.join(headerModuleDirectory, name, 'module.modulemap')}`,
6962
- ),
6963
- ],
6964
- }
7000
+ objcExports = { modules: objcModules, rootModule }
6965
7001
  }
6966
7002
  if (targets.length === 0) {
6967
7003
  for (const [file, contents] of Object.entries(input.files)) {