peachsim 0.1.1673 → 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 (213) 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/settling.ts +37 -4
  7. package/cli/commands/inspect/wait-ready.ts +7 -0
  8. package/cli/outbound-endpoints.ts +12 -0
  9. package/detox/index.ts +11 -1
  10. package/detox/jest-environment.cjs +14 -0
  11. package/dist-lib/agent-daemon-client.cjs +1 -1
  12. package/dist-lib/agent-events.cjs +1 -1
  13. package/dist-lib/attached-projects.cjs +1 -1
  14. package/dist-lib/auth/shared-session.cjs +1 -1
  15. package/dist-lib/backend-origin.cjs +1 -1
  16. package/dist-lib/beta.cjs +1 -1
  17. package/dist-lib/beta.mjs +1 -1
  18. package/dist-lib/bridge-constants.cjs +1 -1
  19. package/dist-lib/bridge-contract-input.cjs +1 -1
  20. package/dist-lib/bridge-contract-input.mjs +1 -1
  21. package/dist-lib/bridge-contract.cjs +1 -1
  22. package/dist-lib/bridge-contract.mjs +1 -1
  23. package/dist-lib/bundle-channel.cjs +3299 -1665
  24. package/dist-lib/capture-contract.cjs +1 -1
  25. package/dist-lib/capture-contract.mjs +1 -1
  26. package/dist-lib/cloud-contract.cjs +1 -1
  27. package/dist-lib/cloud-contract.mjs +1 -1
  28. package/dist-lib/cloud-test-args.cjs +1 -1
  29. package/dist-lib/cloud-test-args.mjs +1 -1
  30. package/dist-lib/cloud.cjs +1 -1
  31. package/dist-lib/cloud.mjs +1 -1
  32. package/dist-lib/config.cjs +1 -1
  33. package/dist-lib/config.mjs +1 -1
  34. package/dist-lib/detox/index.cjs +43 -8
  35. package/dist-lib/detox/jest-environment.cjs +14 -0
  36. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  37. package/dist-lib/expo-swift-bundle.cjs +2432 -1128
  38. package/dist-lib/expo-swift-metadata.cjs +1 -1
  39. package/dist-lib/expo-swift-metadata.mjs +1 -1
  40. package/dist-lib/home-paths.cjs +1 -1
  41. package/dist-lib/host/bridge-host.cjs +2908 -1601
  42. package/dist-lib/host/fetch-proxy-handler.cjs +22 -6
  43. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  44. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  45. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  46. package/dist-lib/host/websocket-proxy.cjs +1 -1
  47. package/dist-lib/index.cjs +1941 -742
  48. package/dist-lib/jump-to-source-babel.cjs +1 -1
  49. package/dist-lib/jump-to-source-native.cjs +1 -1
  50. package/dist-lib/kotlin-host.cjs +1 -1
  51. package/dist-lib/menu.cjs +1 -1
  52. package/dist-lib/menu.mjs +1 -1
  53. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  54. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  55. package/dist-lib/metro-production-bundle.cjs +1 -1
  56. package/dist-lib/metro-production-bundle.mjs +1 -1
  57. package/dist-lib/metro.cjs +6215 -4283
  58. package/dist-lib/native-app-identity-project.cjs +31 -6
  59. package/dist-lib/native-app-identity-project.mjs +31 -6
  60. package/dist-lib/native-app-identity.cjs +1 -1
  61. package/dist-lib/native-app-identity.mjs +1 -1
  62. package/dist-lib/native-firebase-metadata.cjs +1 -1
  63. package/dist-lib/native-firebase-metadata.mjs +1 -1
  64. package/dist-lib/plist.cjs +1 -1
  65. package/dist-lib/plist.mjs +1 -1
  66. package/dist-lib/profiles.cjs +1 -1
  67. package/dist-lib/public-brand.cjs +1 -1
  68. package/dist-lib/public-origins-lib-esm.json +24 -23
  69. package/dist-lib/public-origins-lib-static.json +1 -1
  70. package/dist-lib/public-origins-lib.json +134 -78
  71. package/dist-lib/react-native-host-modules.cjs +1 -1
  72. package/dist-lib/react-native-host-modules.mjs +1 -1
  73. package/dist-lib/reap-browser.cjs +2 -2
  74. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  75. package/dist-lib/sdk.cjs +39 -5
  76. package/dist-lib/sdk.mjs +39 -5
  77. package/dist-lib/skills.cjs +3637 -2168
  78. package/dist-lib/swift-compile.cjs +496 -352
  79. package/dist-lib/swift-compile.mjs +494 -350
  80. package/dist-lib/swift-package.cjs +58 -9
  81. package/dist-lib/swift-package.mjs +57 -9
  82. package/dist-lib/swift-submit.cjs +1 -1
  83. package/dist-lib/swift-submit.mjs +1 -1
  84. package/dist-lib/swift-toolchain.cjs +26 -11
  85. package/dist-lib/swift.cjs +1 -1
  86. package/dist-lib/vite-swift.cjs +2443 -1134
  87. package/dist-lib/vite.cjs +1907 -763
  88. package/dist-lib/worklet-executable.cjs +1 -1
  89. package/dist-lib/worklet-executable.mjs +1 -1
  90. package/dist-types/packages/peach-engine/src/engine/canvaskit-api.d.ts +1 -1
  91. package/dist-types/packages/peach-engine/src/engine/clipboardContract.d.ts +9 -1
  92. package/dist-types/packages/peach-engine/src/engine/paint-boundary.d.ts +1 -0
  93. package/dist-types/packages/peach-engine/src/preview/upload-protocol.d.ts +11 -3
  94. package/dist-types/packages/peach-engine/src/rolldown-bundle-inventory.d.ts +1 -1
  95. package/dist-types/packages/peach-engine/src/webview-automation-host.d.ts +6 -0
  96. package/dist-types/packages/peach-globals/src/clipboardBridgeContract.d.ts +2 -0
  97. package/dist-types/packages/peach-globals/src/compositorBridgeContract.d.ts +10 -1
  98. package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
  99. package/package.json +1 -1
  100. package/runtime-companion.json +1 -1
  101. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h +69 -2
  102. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +44 -4
  103. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFComposeAssistantViewController.h +29 -0
  104. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMailComposeControllerDeferredAction.h +14 -0
  105. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMailComposeViewController.h +162 -0
  106. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMailDraft.h +24 -0
  107. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMessageComposeViewController+UPI.h +31 -0
  108. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMessageComposeViewController.h +169 -0
  109. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MessageUI.h +13 -0
  110. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Modules/module.modulemap +11 -0
  111. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h +10 -0
  112. package/sdk/ios/usr/include/_ctype.h +388 -0
  113. package/sdk/ios/usr/include/_inttypes.h +296 -0
  114. package/sdk/ios/usr/include/_locale.h +83 -0
  115. package/sdk/ios/usr/include/_locale_posix2008.h +65 -0
  116. package/sdk/ios/usr/include/_time.h +207 -0
  117. package/sdk/ios/usr/include/arm/param.h +151 -0
  118. package/sdk/ios/usr/include/ctype.h +70 -0
  119. package/sdk/ios/usr/include/dispatch/dispatch.h +72 -6
  120. package/sdk/ios/usr/include/dlfcn.h +1 -2
  121. package/sdk/ios/usr/include/inttypes.h +35 -0
  122. package/sdk/ios/usr/include/locale.h +59 -0
  123. package/sdk/ios/usr/include/machine/param.h +42 -0
  124. package/sdk/ios/usr/include/net/if.h +1 -2
  125. package/sdk/ios/usr/include/peach/pthread.h +4 -4
  126. package/sdk/ios/usr/include/pthread/qos.h +304 -0
  127. package/sdk/ios/usr/include/runetype.h +118 -0
  128. package/sdk/ios/usr/include/setjmp.h +99 -0
  129. package/sdk/ios/usr/include/sys/_types/_clock_t.h +32 -0
  130. package/sdk/ios/usr/include/sys/_types/_ct_rune_t.h +33 -0
  131. package/sdk/ios/usr/include/sys/_types/_fd_clr.h +31 -0
  132. package/sdk/ios/usr/include/sys/_types/_fd_copy.h +31 -0
  133. package/sdk/ios/usr/include/sys/_types/_fd_def.h +121 -0
  134. package/sdk/ios/usr/include/sys/_types/_fd_isset.h +31 -0
  135. package/sdk/ios/usr/include/sys/_types/_fd_set.h +31 -0
  136. package/sdk/ios/usr/include/sys/_types/_fd_setsize.h +31 -0
  137. package/sdk/ios/usr/include/sys/_types/_fd_zero.h +31 -0
  138. package/sdk/ios/usr/include/sys/_types/_rune_t.h +32 -0
  139. package/sdk/ios/usr/include/sys/_types/_time_t.h +32 -0
  140. package/sdk/ios/usr/include/sys/_types/_wint_t.h +33 -0
  141. package/sdk/ios/usr/include/sys/cdefs.h +5 -0
  142. package/sdk/ios/usr/include/sys/param.h +235 -0
  143. package/sdk/ios/usr/include/sys/proc.h +1 -0
  144. package/sdk/ios/usr/include/sys/qos.h +151 -12
  145. package/sdk/ios/usr/include/time.h +67 -2
  146. package/sdk/ios/wasm/include/__typedef_sigset_t.h +7 -0
  147. package/sdk/ios/wasm/include/fcntl.h +11 -0
  148. package/sdk/ios/wasm/include/mach/machine/boolean.h +2 -0
  149. package/sdk/ios/wasm/include/mach/machine/exception.h +5 -0
  150. package/sdk/ios/wasm/include/mach/machine/kern_return.h +2 -0
  151. package/sdk/ios/wasm/include/mach/machine/processor_info.h +2 -0
  152. package/sdk/ios/wasm/include/mach/machine/rpc.h +2 -0
  153. package/sdk/ios/wasm/include/mach/machine/thread_state.h +3 -0
  154. package/sdk/ios/wasm/include/mach/machine/thread_status.h +3 -0
  155. package/sdk/ios/wasm/include/mach/machine/vm_param.h +3 -0
  156. package/sdk/ios/wasm/include/mach/machine/vm_types.h +18 -0
  157. package/sdk/ios/wasm/include/machine/_types.h +153 -0
  158. package/sdk/ios/wasm/include/machine/endian.h +2 -0
  159. package/sdk/ios/wasm/include/machine/limits.h +2 -0
  160. package/sdk/ios/wasm/include/machine/types.h +30 -0
  161. package/sdk/ios/wasm/include/poll.h +8 -0
  162. package/sdk/ios/wasm/include/pthread.h +50 -0
  163. package/sdk/ios/wasm/include/signal.h +72 -0
  164. package/sdk/ios/wasm/include/stdlib.h +3 -0
  165. package/sdk/ios/wasm/include/string.h +10 -0
  166. package/sdk/ios/wasm/include/sys/_pthread/_pthread_attr_t.h +7 -0
  167. package/sdk/ios/wasm/include/sys/_pthread/_pthread_t.h +7 -0
  168. package/sdk/ios/wasm/include/sys/mman.h +122 -0
  169. package/sdk/ios/wasm/include/sys/select.h +37 -0
  170. package/sdk/ios/wasm/include/sys/signal.h +259 -0
  171. package/sdk/ios/wasm/include/sys/socket.h +8 -0
  172. package/sdk/ios/wasm/include/sys/types.h +14 -0
  173. package/sdk/ios/wasm/include/sys/ucontext.h +1 -0
  174. package/sdk/ios/wasm/include/sys/uio.h +11 -0
  175. package/sdk/ios/wasm/include/sys/wait.h +89 -0
  176. package/sdk/ios/wasm/include/time.h +8 -0
  177. package/sdk/ios/wasm/include/unistd.h +17 -0
  178. package/src/bridge-contract.ts +2 -0
  179. package/src/chromium-admission.ts +10 -5
  180. package/src/device-catalog.ts +4 -4
  181. package/src/host/fetch-proxy-handler.ts +20 -0
  182. package/src/host/rolldown-bundle-forward.ts +4 -1
  183. package/src/metro-plugin.ts +5 -2
  184. package/src/nitro-adapter.lock.json +6 -6
  185. package/src/nitro-compile.ts +63 -2
  186. package/src/numbered-lock.ts +72 -0
  187. package/src/react-native-coverage/capability-reference-resolution.ts +62 -5
  188. package/src/react-native-coverage/capability-source-references.ts +50 -13
  189. package/src/react-native-coverage/native-source-credit.ts +126 -0
  190. package/src/react-native-coverage/native-source-ranges-file.ts +38 -0
  191. package/src/react-native-coverage/native-surface.ts +49 -0
  192. package/src/react-native-coverage/verified-reach.ts +22 -2
  193. package/src/runtime-assets.ts +17 -0
  194. package/src/swift-compile.ts +84 -47
  195. package/src/swift-coverage/indexing.ts +17 -1
  196. package/src/swift-coverage/sdk.ts +71 -0
  197. package/src/swift-coverage/source.ts +74 -2
  198. package/src/swift-coverage/types.ts +6 -0
  199. package/src/swift-distribution.lock.json +12 -12
  200. package/src/swift-host.ts +133 -14
  201. package/src/swift-objc-compile.ts +11 -22
  202. package/src/swift-objc-metadata.ts +2 -8
  203. package/src/swift-objc-platform.ts +53 -0
  204. package/src/swift-objc-standin.ts +49 -0
  205. package/src/swift-package-manifest.ts +48 -3
  206. package/src/swift-package.ts +85 -12
  207. package/src/swift-packages.ts +157 -44
  208. package/src/swift-source-pods.ts +288 -0
  209. package/src/swift-standins.ts +4 -1
  210. package/src/swift-toolchain.ts +32 -10
  211. package/src/vite-plugin-one.ts +5 -4
  212. package/src/worker-system-chunks.ts +7 -1
  213. package/src/xcode-project.ts +40 -11
@@ -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 } 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,25 +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
- '-fobjc-arc',
6883
- '-fblocks',
6884
- '-F',
6885
- path.join(headers, 'System/Library/Frameworks'),
6886
- '-idirafter',
6887
- path.join(headers, 'usr/include'),
6888
- '-I',
6889
- headerDirectory,
6890
- ]
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
+ )
6891
6938
  })()
6892
6939
  let objcExports: Parameters<typeof emitSwiftPackageManifest>[0]['objcExports']
6893
6940
  if (rootOwner && input.objcPeerStartup)
@@ -6950,17 +6997,7 @@ public func __peachObjcExportRoot() { _objcRegisterPeerClass(NSObject.self, nati
6950
6997
  '',
6951
6998
  ].join('\n'),
6952
6999
  )
6953
- objcExports = {
6954
- modules: objcModules,
6955
- rootModule,
6956
- flags: [
6957
- ...nativeFlags!,
6958
- ...[...objcModules].map(
6959
- (name) =>
6960
- `-fmodule-map-file=${path.join(headerModuleDirectory, name, 'module.modulemap')}`,
6961
- ),
6962
- ],
6963
- }
7000
+ objcExports = { modules: objcModules, rootModule }
6964
7001
  }
6965
7002
  if (targets.length === 0) {
6966
7003
  for (const [file, contents] of Object.entries(input.files)) {
@@ -1,7 +1,23 @@
1
1
  import { execFileSync, spawn } from 'node:child_process'
2
- import { mkdirSync } from 'node:fs'
2
+ import { createHash } from 'node:crypto'
3
+ import { mkdirSync, readFileSync, realpathSync } from 'node:fs'
4
+ import { join } from 'node:path'
3
5
  import type { SwiftIndexCommand, SwiftIndexLeg, SwiftIndexRef } from './types'
4
6
 
7
+ export function swiftSdkIdentity(swiftc: string, sdk: string, target: string) {
8
+ const sha256 = (bytes: Buffer) => createHash('sha256').update(bytes).digest('hex')
9
+ return {
10
+ sdk: realpathSync(sdk),
11
+ settings: sha256(readFileSync(join(sdk, 'SDKSettings.json'))),
12
+ build: sha256(
13
+ readFileSync(join(sdk, 'System/Library/CoreServices/SystemVersion.plist')),
14
+ ),
15
+ compiler: realpathSync(swiftc),
16
+ version: execFileSync(swiftc, ['--version'], { encoding: 'utf8' }).trim(),
17
+ target,
18
+ }
19
+ }
20
+
5
21
  // explicit references only: a reference role without the implicit role.
6
22
  const REFERENCE = 1 << 2
7
23
  const IMPLICIT = 1 << 8
@@ -0,0 +1,71 @@
1
+ import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
2
+ import { homedir } from 'node:os'
3
+ import { dirname, join } from 'node:path'
4
+ import type { SwiftSdkSymbolSnapshot } from './types'
5
+
6
+ export function swiftSdkSymbolCachePath(fingerprint: string) {
7
+ if (!/^[a-f0-9]{64}$/.test(fingerprint))
8
+ throw new Error('invalid Swift SDK fingerprint')
9
+ return join(
10
+ homedir(),
11
+ '.cache/contrast-swift-yet/native/sdk-symbols',
12
+ `${fingerprint}.json`,
13
+ )
14
+ }
15
+
16
+ export function writeSwiftSdkSymbolCache(snapshot: SwiftSdkSymbolSnapshot) {
17
+ const path = swiftSdkSymbolCachePath(snapshot.sdk.fingerprint)
18
+ mkdirSync(dirname(path), { recursive: true })
19
+ const temporary = `${path}.${process.pid}.tmp`
20
+ writeFileSync(temporary, JSON.stringify(snapshot) + '\n')
21
+ renameSync(temporary, path)
22
+ return path
23
+ }
24
+
25
+ export function readSwiftSdkSymbolCache(fingerprint: string): SwiftSdkSymbolSnapshot {
26
+ const path = swiftSdkSymbolCachePath(fingerprint)
27
+ let value: unknown
28
+ try {
29
+ value = JSON.parse(readFileSync(path, 'utf8'))
30
+ } catch {
31
+ throw new Error(
32
+ `native Swift SDK symbols are not cached for this compiler and SDK; run swift:yet --front-doors <artifact-path> on this host (${fingerprint})`,
33
+ )
34
+ }
35
+ if (
36
+ typeof value !== 'object' ||
37
+ value === null ||
38
+ !('schemaVersion' in value) ||
39
+ value.schemaVersion !== 1 ||
40
+ !('sdk' in value) ||
41
+ typeof value.sdk !== 'object' ||
42
+ value.sdk === null ||
43
+ !('version' in value.sdk) ||
44
+ typeof value.sdk.version !== 'string' ||
45
+ !('fingerprint' in value.sdk) ||
46
+ value.sdk.fingerprint !== fingerprint ||
47
+ !('symbols' in value) ||
48
+ !Array.isArray(value.symbols)
49
+ )
50
+ throw new Error('invalid native Swift SDK symbol cache')
51
+ const symbols: SwiftSdkSymbolSnapshot['symbols'] = value.symbols.map(
52
+ (entry: unknown) => {
53
+ if (
54
+ !Array.isArray(entry) ||
55
+ entry.length !== 4 ||
56
+ !entry.every((field: unknown) => typeof field === 'string' && field.length > 0)
57
+ )
58
+ throw new Error('invalid native Swift SDK symbol tuple')
59
+ const [module, usr, path, kind]: unknown[] = entry
60
+ if (
61
+ typeof module !== 'string' ||
62
+ typeof usr !== 'string' ||
63
+ typeof path !== 'string' ||
64
+ typeof kind !== 'string'
65
+ )
66
+ throw new Error('invalid native Swift SDK symbol tuple')
67
+ return [module, usr, path, kind]
68
+ },
69
+ )
70
+ return { schemaVersion: 1, sdk: { version: value.sdk.version, fingerprint }, symbols }
71
+ }
@@ -3,10 +3,82 @@ import { createHash } from 'node:crypto'
3
3
  import { mkdtempSync, readFileSync, realpathSync, rmSync, statSync } from 'node:fs'
4
4
  import { tmpdir } from 'node:os'
5
5
  import { basename, isAbsolute, join, relative, resolve, sep } from 'node:path'
6
+ import {
7
+ fileReachesFeature,
8
+ referenceFeatures,
9
+ } from '../react-native-coverage/verified-reach'
6
10
  import { SWIFT_INDEX_READER_SOURCE } from './indexdump'
7
11
  import { createSwiftIndexer } from './indexing'
8
12
  import { swiftCoverageProvenance } from './provenance'
9
- import type { SwiftIndexRef, SwiftSourceInput, SwiftSourceLeg } from './types'
13
+ import type { CapabilityInventoryRow } from '../../../peach-compat/src/capability-inventory-types'
14
+ import type { VerifiedFeature } from '../../../peach-compat/src/verified-map-types'
15
+ import type {
16
+ SwiftIndexRef,
17
+ SwiftSourceInput,
18
+ SwiftSourceLeg,
19
+ SwiftSdkSymbolSnapshot,
20
+ } from './types'
21
+
22
+ // the inventory owns SDK identities, and the existing reach rules own feature
23
+ // attribution. a compiler reference establishes possible reach, never proof.
24
+ export function resolveSwiftFrontDoors(
25
+ index: Awaited<ReturnType<typeof indexSwiftApp>>,
26
+ rows: readonly Pick<
27
+ CapabilityInventoryRow,
28
+ 'id' | 'packageName' | 'sourceFingerprint' | 'publicReferencePaths' | 'subsystem'
29
+ >[],
30
+ sdkFingerprint: string,
31
+ features: readonly VerifiedFeature[],
32
+ sdk: SwiftSdkSymbolSnapshot,
33
+ ) {
34
+ const mappedRows = new Set<string>()
35
+ for (const row of rows) {
36
+ if (row.packageName !== 'swift-sdk' || row.sourceFingerprint !== sdkFingerprint)
37
+ continue
38
+ mappedRows.add(row.id)
39
+ }
40
+ const sdkMatched = sdk.sdk.fingerprint === sdkFingerprint
41
+ const byUSR = new Map<string, Set<string>>()
42
+ if (sdkMatched)
43
+ for (const [module, usr] of sdk.symbols) {
44
+ const modules = byUSR.get(usr) ?? new Set<string>()
45
+ modules.add(module)
46
+ byUSR.set(usr, modules)
47
+ }
48
+ const sites = index.sites.map((site) => {
49
+ const modules = site.nativeTypechecked ? [...(byUSR.get(site.usr) ?? [])] : []
50
+ const frontDoorIds = modules.map((module) => `swift:${module}:${site.usr}`)
51
+ const capabilityIds = frontDoorIds.filter((id) => mappedRows.has(id))
52
+ return {
53
+ ...site,
54
+ declarationModules: modules,
55
+ declarationModule: modules.length === 1 ? modules[0]! : null,
56
+ origin: modules.length ? 'sdk' : 'unknown',
57
+ frontDoorIds,
58
+ capabilityIds,
59
+ features: [
60
+ ...new Set(capabilityIds.flatMap((id) => referenceFeatures(features, id, null))),
61
+ ],
62
+ mapping: capabilityIds.length
63
+ ? 'attributed'
64
+ : modules.length
65
+ ? 'unmapped'
66
+ : 'unknown',
67
+ verification: 'unknown',
68
+ }
69
+ })
70
+ const reached = new Set<string>()
71
+ for (const file of index.input.sources) {
72
+ const references = sites
73
+ .filter((site) => site.file === file.path)
74
+ .flatMap((site) =>
75
+ site.capabilityIds.map((capabilityId) => ({ capabilityId, value: null })),
76
+ )
77
+ for (const feature of features)
78
+ if (fileReachesFeature(feature, references)) reached.add(feature.id)
79
+ }
80
+ return { sites, features: [...reached].sort(), sdkMatched }
81
+ }
10
82
 
11
83
  const sha256 = (bytes: string | Buffer) =>
12
84
  createHash('sha256').update(bytes).digest('hex')
@@ -239,7 +311,7 @@ export async function indexSwiftApp(input: SwiftSourceInput) {
239
311
  'The caller supplies source membership and compiler flags; project discovery and dependency closure are unknown.',
240
312
  'Flags and compiler versions are recorded; SDK versions, dependency module contents and IndexStore library provenance are unknown.',
241
313
  'The reader source hash identifies this repository source only; its binding to the caller-supplied reader binary is unknown.',
242
- 'USR sites include app and library symbols; declaration modules, front doors, features and native proof are unknown.',
314
+ 'USR sites alone establish no SDK origin, front door, feature or native proof. Attribution requires a matching SDK inventory.',
243
315
  'Missing sites do not establish platform inactivity. Failed primaries may omit references; partial indexes establish no coverage percentage.',
244
316
  ...(peach
245
317
  ? []
@@ -1,5 +1,11 @@
1
1
  import type { SwiftCompileInput } from '../swift-compile'
2
2
 
3
+ export type SwiftSdkSymbolSnapshot = {
4
+ schemaVersion: 1
5
+ sdk: { version: string; fingerprint: string }
6
+ symbols: [module: string, usr: string, path: string, kind: string][]
7
+ }
8
+
3
9
  export type SwiftIndexRef = {
4
10
  line: number
5
11
  col: number
@@ -1,10 +1,10 @@
1
1
  {
2
- "id": "433f607a19978269",
3
- "release": "swift-6.4.0-RELEASE-custom-0d775d32d7c74eae",
4
- "wasmSdkId": "swift-6.4.0-RELEASE_wasm-peach-f02bd198",
5
- "wasmSdkUrl": "https://r2.sootsim.com/swift-wasm-sdk/swift-6.4.0-RELEASE_wasm-peach-f02bd198.artifactbundle.tar.gz",
6
- "wasmSdkChecksum": "1e19ea768fd4e821aae34b8966c4ddcee45615c4b3cf018979b061aee2fb5504",
7
- "source": "f52d21b43f5cba9bd52f1665697284e46d16c0d9",
2
+ "id": "2a88c78372024d5a",
3
+ "release": "swift-6.4.0-RELEASE-custom-8be2e4a7a393b003",
4
+ "wasmSdkId": "swift-6.4.0-RELEASE_wasm-peach-2d2602d0",
5
+ "wasmSdkUrl": "https://r2.sootsim.com/swift-wasm-sdk/swift-6.4.0-RELEASE_wasm-peach-2d2602d0.artifactbundle.tar.gz",
6
+ "wasmSdkChecksum": "05181637294f73285610478231c04d79c9710648198f5423ed26b718da6d3df6",
7
+ "source": "392c8e4f247fd9ee304313a94a1b3f56e60e3ac2",
8
8
  "targets": [
9
9
  "ImagePlayground",
10
10
  "QuickLookThumbnailing",
@@ -193,16 +193,16 @@
193
193
  },
194
194
  "hosts": {
195
195
  "darwin-arm64": {
196
- "sha256": "0b814aa2ced56e4452c82227c4251036346015ba6445e742070ee221c53fc575",
197
- "size": 71080069
196
+ "sha256": "890c0d4887c063bccd8597dd6c32f04266015fb3f2b059cc10fcfca752a8430b",
197
+ "size": 71192522
198
198
  },
199
199
  "linux-x64": {
200
- "sha256": "62e67740951c7972fde15bc074fe8838f308432a8521e93691035e7fc105b716",
201
- "size": 71085950
200
+ "sha256": "67bd5c088204b0ac93c364b3c46bc1d3626d7c2680e0c0c03f367069c0fc28f6",
201
+ "size": 71198414
202
202
  },
203
203
  "linux-arm64": {
204
- "sha256": "f900ab5b6a4823966cebe291c91710e6323185df971c667c25ddcc1427935b52",
205
- "size": 71084016
204
+ "sha256": "a0cb72050f4256a2d89cff92210f39a2d3e6adeef763b327bb45cdec15b957d7",
205
+ "size": 71196672
206
206
  }
207
207
  }
208
208
  }