peachsim 0.1.1667 → 0.1.1674

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 (204) hide show
  1. package/README.md +1 -1
  2. package/cli/bridge-flow-runner.ts +4 -1
  3. package/cli/commands/coverage-swift.ts +291 -0
  4. package/cli/commands/coverage.ts +168 -24
  5. package/cli/commands/diagnose.ts +1 -19
  6. package/cli/commands/inspect/settling.ts +37 -4
  7. package/cli/commands/react.ts +3 -18
  8. package/cli/commands/screenshot.ts +1 -1
  9. package/cli/commands/screenshots-capture.ts +1 -1
  10. package/cli/drivers/playwright-provisioning.ts +1 -4
  11. package/cli/drivers/playwright.ts +15 -1
  12. package/cli/scene-video.ts +1 -1
  13. package/cli/ui.ts +20 -0
  14. package/cli/ws-bridge.ts +7 -36
  15. package/detox/frame-identity.cjs +21 -0
  16. package/detox/frame-identity.d.cts +6 -0
  17. package/detox/index.ts +39 -33
  18. package/detox/jest-environment.cjs +4 -1
  19. package/detox/jest-setup-after-env.cjs +0 -4
  20. package/detox/navigation-lifecycle.ts +2 -2
  21. package/detox/proof-observer.ts +126 -0
  22. package/dist-lib/agent-daemon-client.cjs +29 -1
  23. package/dist-lib/agent-events.cjs +1 -1
  24. package/dist-lib/attached-projects.cjs +10 -1
  25. package/dist-lib/auth/shared-session.cjs +1 -1
  26. package/dist-lib/backend-origin.cjs +1 -1
  27. package/dist-lib/beta.cjs +1 -1
  28. package/dist-lib/beta.mjs +1 -1
  29. package/dist-lib/bridge-constants.cjs +1 -1
  30. package/dist-lib/bridge-contract-input.cjs +1 -1
  31. package/dist-lib/bridge-contract-input.mjs +1 -1
  32. package/dist-lib/bridge-contract.cjs +1 -1
  33. package/dist-lib/bridge-contract.mjs +1 -1
  34. package/dist-lib/bundle-channel.cjs +557 -158
  35. package/dist-lib/capture-contract.cjs +1 -1
  36. package/dist-lib/capture-contract.mjs +1 -1
  37. package/dist-lib/cloud-contract.cjs +1 -1
  38. package/dist-lib/cloud-contract.mjs +1 -1
  39. package/dist-lib/cloud-test-args.cjs +1 -1
  40. package/dist-lib/cloud-test-args.mjs +1 -1
  41. package/dist-lib/cloud.cjs +1 -1
  42. package/dist-lib/cloud.mjs +1 -1
  43. package/dist-lib/config.cjs +1 -1
  44. package/dist-lib/config.mjs +1 -1
  45. package/dist-lib/detox/index.cjs +5098 -7344
  46. package/dist-lib/detox/jest-environment.cjs +4 -1
  47. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  48. package/dist-lib/expo-swift-bundle.cjs +602 -152
  49. package/dist-lib/expo-swift-metadata.cjs +1 -1
  50. package/dist-lib/expo-swift-metadata.mjs +1 -1
  51. package/dist-lib/home-paths.cjs +1 -1
  52. package/dist-lib/host/bridge-host.cjs +688 -194
  53. package/dist-lib/host/fetch-proxy-handler.cjs +6 -3
  54. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  55. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  56. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  57. package/dist-lib/host/websocket-proxy.cjs +1 -1
  58. package/dist-lib/index.cjs +247 -11
  59. package/dist-lib/jump-to-source-babel.cjs +1 -1
  60. package/dist-lib/jump-to-source-native.cjs +1 -1
  61. package/dist-lib/kotlin-host.cjs +1 -1
  62. package/dist-lib/menu.cjs +1 -1
  63. package/dist-lib/menu.mjs +1 -1
  64. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  65. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  66. package/dist-lib/metro-production-bundle.cjs +10 -1
  67. package/dist-lib/metro-production-bundle.mjs +12 -1
  68. package/dist-lib/metro.cjs +155 -5
  69. package/dist-lib/native-app-identity-project.cjs +43 -5
  70. package/dist-lib/native-app-identity-project.mjs +43 -5
  71. package/dist-lib/native-app-identity.cjs +1 -1
  72. package/dist-lib/native-app-identity.mjs +1 -1
  73. package/dist-lib/native-firebase-metadata.cjs +1 -1
  74. package/dist-lib/native-firebase-metadata.mjs +1 -1
  75. package/dist-lib/plist.cjs +1 -1
  76. package/dist-lib/plist.mjs +1 -1
  77. package/dist-lib/profiles.cjs +21 -1
  78. package/dist-lib/public-brand.cjs +1 -1
  79. package/dist-lib/public-origins-lib-esm.json +73 -27
  80. package/dist-lib/public-origins-lib-static.json +1 -1
  81. package/dist-lib/public-origins-lib.json +563 -183
  82. package/dist-lib/react-native-host-modules.cjs +1 -1
  83. package/dist-lib/react-native-host-modules.mjs +1 -1
  84. package/dist-lib/reap-browser.cjs +964 -0
  85. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  86. package/dist-lib/sdk.cjs +38 -5
  87. package/dist-lib/sdk.mjs +38 -5
  88. package/dist-lib/skills.cjs +1031 -530
  89. package/dist-lib/swift-compile.cjs +298 -86
  90. package/dist-lib/swift-compile.mjs +298 -86
  91. package/dist-lib/swift-package.cjs +53 -4
  92. package/dist-lib/swift-package.mjs +52 -4
  93. package/dist-lib/swift-submit.cjs +2 -2
  94. package/dist-lib/swift-submit.mjs +2 -2
  95. package/dist-lib/swift-toolchain.cjs +25 -44
  96. package/dist-lib/swift.cjs +1 -1
  97. package/dist-lib/vite-swift.cjs +603 -114
  98. package/dist-lib/vite.cjs +65 -3
  99. package/dist-lib/worklet-executable.cjs +1 -1
  100. package/dist-lib/worklet-executable.mjs +1 -1
  101. package/dist-types/packages/peach-engine/src/engine/clipboardContract.d.ts +7 -0
  102. package/dist-types/packages/peach-engine/src/engine/glass-material.d.ts +1 -1
  103. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +2 -0
  104. package/dist-types/packages/peach-engine/src/engine/inspect-outline.d.ts +2 -1
  105. package/dist-types/packages/peach-engine/src/engine/liquid-glass.d.ts +1 -0
  106. package/dist-types/packages/peach-engine/src/engine/paint-boundary.d.ts +4 -1
  107. package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +7 -0
  108. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime-kind.d.ts +24 -0
  109. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +4 -2
  110. package/dist-types/packages/peach-engine/src/rolldown-bundle-inventory.d.ts +1 -1
  111. package/dist-types/packages/peach-engine/src/settings/devices.d.ts +1 -0
  112. package/dist-types/packages/peach-globals/src/clipboardBridgeContract.d.ts +18 -0
  113. package/dist-types/packages/peach-globals/src/compositorBridgeContract.d.ts +10 -1
  114. package/dist-types/packages/peach-globals/src/index.d.ts +2 -2
  115. package/dist-types/packages/peach-globals/src/nodeContract.d.ts +1 -0
  116. package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
  117. package/package.json +1 -1
  118. package/runtime-companion.json +1 -1
  119. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFString.h +2 -0
  120. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h +54 -0
  121. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +23 -4
  122. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStore.h +439 -0
  123. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStoreCopySpecific.h +216 -0
  124. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStoreKey.h +267 -0
  125. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetwork.h +204 -0
  126. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkConfiguration.h +1393 -0
  127. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkConnection.h +568 -0
  128. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkReachability.h +369 -0
  129. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferences.h +473 -0
  130. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferencesPath.h +179 -0
  131. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferencesSetSpecific.h +95 -0
  132. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h +2395 -0
  133. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SystemConfiguration.h +184 -0
  134. package/sdk/ios/usr/include/_ctype.h +388 -0
  135. package/sdk/ios/usr/include/_inttypes.h +296 -0
  136. package/sdk/ios/usr/include/_locale.h +83 -0
  137. package/sdk/ios/usr/include/_locale_posix2008.h +65 -0
  138. package/sdk/ios/usr/include/_time.h +207 -0
  139. package/sdk/ios/usr/include/ctype.h +70 -0
  140. package/sdk/ios/usr/include/dispatch/dispatch.h +69 -6
  141. package/sdk/ios/usr/include/inttypes.h +35 -0
  142. package/sdk/ios/usr/include/libkern/OSByteOrder.h +315 -0
  143. package/sdk/ios/usr/include/libkern/machine/OSByteOrder.h +147 -0
  144. package/sdk/ios/usr/include/locale.h +59 -0
  145. package/sdk/ios/usr/include/runetype.h +118 -0
  146. package/sdk/ios/usr/include/setjmp.h +99 -0
  147. package/sdk/ios/usr/include/sys/_types/_clock_t.h +32 -0
  148. package/sdk/ios/usr/include/sys/_types/_ct_rune_t.h +33 -0
  149. package/sdk/ios/usr/include/sys/_types/_rune_t.h +32 -0
  150. package/sdk/ios/usr/include/sys/_types/_time_t.h +32 -0
  151. package/sdk/ios/usr/include/sys/_types/_wint_t.h +33 -0
  152. package/sdk/ios/usr/include/sys/cdefs.h +2 -0
  153. package/sdk/ios/usr/include/time.h +67 -2
  154. package/src/bridge-contract.ts +42 -0
  155. package/src/chromium-admission.ts +196 -0
  156. package/src/host/bridge-host.ts +6 -43
  157. package/src/host/rolldown-bundle-forward.ts +4 -1
  158. package/src/launch-deadline.ts +74 -0
  159. package/src/nitro-adapter.lock.json +3 -3
  160. package/src/profiles.ts +21 -0
  161. package/src/react-native-coverage/capability-reference-resolution.ts +402 -0
  162. package/src/react-native-coverage/capability-source-references.ts +1296 -0
  163. package/src/react-native-coverage/native-typescript-parser.ts +74 -0
  164. package/src/react-native-coverage/project-aliases.ts +207 -0
  165. package/src/react-native-coverage/verified-reach.ts +47 -0
  166. package/src/reap-browser.ts +1019 -0
  167. package/src/skills/builtin/a11y-review.ts +1 -1
  168. package/src/skills/builtin/perf-profile.ts +1 -1
  169. package/src/skills/builtin/screenshot-all.ts +1 -1
  170. package/src/skills/builtin/visual-diff.ts +1 -1
  171. package/src/swift-compile.ts +109 -57
  172. package/src/swift-coverage/indexdump.ts +80 -0
  173. package/src/swift-coverage/indexing.ts +147 -0
  174. package/src/swift-coverage/package.ts +230 -0
  175. package/src/swift-coverage/provenance.ts +47 -0
  176. package/src/swift-coverage/reader.ts +81 -0
  177. package/src/swift-coverage/source.ts +252 -0
  178. package/src/swift-coverage/types.ts +58 -0
  179. package/src/swift-coverage/xcode-assets.ts +175 -0
  180. package/src/swift-coverage/xcode-bridging.ts +160 -0
  181. package/src/swift-coverage/xcode-packages.ts +251 -0
  182. package/src/swift-coverage/xcode-strings.ts +78 -0
  183. package/src/swift-coverage/xcode.ts +656 -0
  184. package/src/swift-distribution.lock.json +8 -8
  185. package/src/swift-host.ts +21 -1
  186. package/src/swift-objc-compile.ts +7 -3
  187. package/src/swift-objc-import.ts +191 -27
  188. package/src/swift-objc-metadata.ts +2 -2
  189. package/src/swift-objc-standin.ts +9 -2
  190. package/src/swift-package-manifest.ts +134 -13
  191. package/src/swift-package.ts +69 -4
  192. package/src/swift-standins.ts +4 -1
  193. package/src/swift-submit.ts +2 -1
  194. package/src/swift-toolchain.ts +36 -61
  195. package/src/worker-system-chunks.ts +3 -10
  196. package/src/xcode-project.ts +5 -5
  197. package/detox/attempt-events.cjs +0 -914
  198. package/detox/attempt-events.d.cts +0 -113
  199. package/detox/motion-change.cjs +0 -524
  200. package/detox/motion-change.d.cts +0 -140
  201. package/detox/motion-leg-starts.cjs +0 -20
  202. package/detox/motion-leg-starts.d.cts +0 -8
  203. package/detox/proof-frame.cjs +0 -190
  204. package/detox/record-block-execution.cjs +0 -78
@@ -1,6 +1,6 @@
1
1
  // built-in skill: accessibility audit
2
2
 
3
- import { launchReapedChrome } from '../../../../../scripts/lib/reap-browser'
3
+ import { launchReapedChrome } from '../../reap-browser'
4
4
  import type { RNXSkill } from '../types'
5
5
 
6
6
  export const skill: RNXSkill = {
@@ -1,6 +1,6 @@
1
1
  // built-in skill: performance profiling
2
2
 
3
- import { launchReapedChrome } from '../../../../../scripts/lib/reap-browser'
3
+ import { launchReapedChrome } from '../../reap-browser'
4
4
  import type { RNXSkill } from '../types'
5
5
 
6
6
  interface OverlayProfile {
@@ -1,6 +1,6 @@
1
1
  // built-in skill: capture all screens in light/dark mode
2
2
 
3
- import { launchReapedChrome } from '../../../../../scripts/lib/reap-browser'
3
+ import { launchReapedChrome } from '../../reap-browser'
4
4
  import type { RNXSkill } from '../types'
5
5
 
6
6
  export const skill: RNXSkill = {
@@ -1,6 +1,6 @@
1
1
  // built-in skill: visual diff against baselines
2
2
 
3
- import { launchReapedChrome } from '../../../../../scripts/lib/reap-browser'
3
+ import { launchReapedChrome } from '../../reap-browser'
4
4
  import type { RNXSkill } from '../types'
5
5
 
6
6
  export const skill: RNXSkill = {
@@ -41,7 +41,7 @@ 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 { materializeObjcSdk, objcView, WASI_EMULATION_FLAGS } from './swift-objc-standin'
45
45
  import {
46
46
  OBJC_RESOURCE_ACCESSOR_BODY,
47
47
  OBJC_RESOURCE_ACCESSOR_HEADER,
@@ -51,6 +51,7 @@ import {
51
51
  swiftObjCResourceBundleName,
52
52
  swiftPackagePartition,
53
53
  swiftTargetModuleName,
54
+ clangMacroSetting,
54
55
  type SwiftPackageTarget,
55
56
  } from './swift-package'
56
57
  import { withSwiftRootLock, type SwiftRootLease } from './swift-root-lock'
@@ -912,6 +913,8 @@ interface SwiftNativeTargetPlan {
912
913
  // units that consume a swift-generated header: excluded from the original
913
914
  // target and compiled by the downstream implementation target.
914
915
  lateSources: string[]
916
+ flags?: string[]
917
+ cxxFlags?: string[]
915
918
  mixed?: boolean
916
919
  clang?: {
917
920
  modulemap: string
@@ -1006,6 +1009,10 @@ export function emitSwiftPackageManifest(args: {
1006
1009
  )
1007
1010
  // each target compiles in the language mode and default isolation its
1008
1011
  // author declared, the way xcode builds the same package.
1012
+ // clang receives only the macros its own settings declare; swift
1013
+ // conditions never reach it.
1014
+ const macroSettings = (values: string[] | undefined): string =>
1015
+ (values ?? []).map((value) => ` ${clangMacroSetting(value)},`).join('')
1009
1016
  const stanza = (target: SwiftPackageTarget): string => {
1010
1017
  // system modules keep their upstream module map and resolve headers and
1011
1018
  // libraries from the wasm SDK, never the build host's pkg-config paths.
@@ -1143,12 +1150,17 @@ export function emitSwiftPackageManifest(args: {
1143
1150
  ? `,
1144
1151
  linkerSettings: [${librarySettings.join(', ')}]`
1145
1152
  : ''
1153
+ const cDefines = macroSettings(target.cDefines)
1154
+ const cxxDefines = macroSettings(target.cxxDefines)
1146
1155
  const nativeSettings = native?.clang
1147
1156
  ? [
1148
- `cSettings: [.unsafeFlags(${JSON.stringify([...(args.objcExports?.flags ?? args.nativeFlags ?? []), ...native.clang.flags])})]`,
1149
- `cxxSettings: [${defines} .unsafeFlags(${JSON.stringify(['-fno-cxx-modules', ...(args.objcExports?.flags ?? args.nativeFlags ?? []), ...native.clang.cxxFlags])})]`,
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])})]`,
1159
+ ].join(', ')
1160
+ : [
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 ?? [])])})]`,
1150
1163
  ].join(', ')
1151
- : `${args.objcExports ? `cSettings: [.unsafeFlags(${JSON.stringify(args.objcExports.flags)})], ` : ''}cxxSettings: [${defines} .unsafeFlags(["-fno-cxx-modules"])]`
1152
1164
  return [
1153
1165
  ` ${kind}(`,
1154
1166
  ` name: "${target.name}",`,
@@ -1162,7 +1174,9 @@ export function emitSwiftPackageManifest(args: {
1162
1174
  ` sources: ${JSON.stringify(native.clang.sources.map((source) => path.posix.join(native.path, source)))},`,
1163
1175
  ` publicHeadersPath: ${JSON.stringify(path.posix.dirname(native.clang.modulemap))},`,
1164
1176
  ]
1165
- : []),
1177
+ : native?.flags
1178
+ ? [` sources: ${JSON.stringify(native.sources)},`]
1179
+ : []),
1166
1180
  // the native backend supplies dependency module maps without their
1167
1181
  // compiled modules. textual c++ includes keep those dependencies usable.
1168
1182
  ` ${clang ? nativeSettings : swiftSettings}${link}`,
@@ -1192,12 +1206,14 @@ export function emitSwiftPackageManifest(args: {
1192
1206
  ` cSettings: [.unsafeFlags(${JSON.stringify([...args.objcExports.flags.filter((flag) => flag !== '-fobjc-arc'), '-fno-objc-arc', '-Xclang', '-disable-objc-default-synthesize-properties'])})]),`,
1193
1207
  ]
1194
1208
  : []),
1195
- ...[...(args.native?.entries() ?? [])].flatMap(([name, native]) =>
1196
- native.late
1209
+ ...[...(args.native?.entries() ?? [])].flatMap(([name, native]) => {
1210
+ const late = native.late
1211
+ const owner = targets.find((target) => target.name === name)
1212
+ return late
1197
1213
  ? (
1198
1214
  native.groups ?? [
1199
1215
  {
1200
- name: native.late.name,
1216
+ name: late.name,
1201
1217
  sources: native.lateSources,
1202
1218
  flags: [],
1203
1219
  cxxFlags: [],
@@ -1205,15 +1221,15 @@ export function emitSwiftPackageManifest(args: {
1205
1221
  ]
1206
1222
  ).flatMap((group) => [
1207
1223
  ` .target(name: ${JSON.stringify(group.name)},`,
1208
- ` dependencies: ${JSON.stringify(args.native?.get(name)?.mixed ? [] : [name])},`,
1224
+ ` dependencies: ${JSON.stringify(native.mixed ? [] : [name, ...late.producers])},`,
1209
1225
  ` path: ${JSON.stringify(native.clang ? '.' : native.path)},`,
1210
1226
  ` sources: ${JSON.stringify(native.clang ? group.sources.map((source) => path.posix.join(native.path, source)) : group.sources)},`,
1211
1227
  ` publicHeadersPath: ${JSON.stringify(native.clang ? path.posix.dirname(native.clang.modulemap) : 'include')},`,
1212
- ` cSettings: [.unsafeFlags(${JSON.stringify([...(args.objcExports?.flags ?? args.nativeFlags ?? []), ...group.flags])})],`,
1213
- ` cxxSettings: [.unsafeFlags(${JSON.stringify(['-fno-cxx-modules', '-I', native.includeDirectory, '-I', args.headerDirectory, ...group.cxxFlags])})]),`,
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])})]),`,
1214
1230
  ])
1215
- : [],
1216
- ),
1231
+ : []
1232
+ }),
1217
1233
  args.cxxLanguageStandard
1218
1234
  ? ` ],\n cxxLanguageStandard: .${args.cxxLanguageStandard}`
1219
1235
  : ' ]',
@@ -6095,9 +6111,7 @@ export function writeSwiftProject(
6095
6111
  targetStagedFiles.delete(target.name)
6096
6112
  if (
6097
6113
  entries.some(([file]) => /\.(?:c|cc|cpp|cxx|m|mm)$/.test(file)) &&
6098
- (swift ||
6099
- (input.nativeTargets?.some((value) => value.name === target.name) &&
6100
- entries.some(([file]) => /\.mm?$/.test(file))))
6114
+ (swift || input.nativeTargets?.some((value) => value.name === target.name))
6101
6115
  ) {
6102
6116
  if (!swift) {
6103
6117
  const unprepared = path.join(
@@ -6183,11 +6197,43 @@ export function writeSwiftProject(
6183
6197
  const entries = targetEntries(target)
6184
6198
  const units = entries.filter(([file]) => /\.(?:c|cc|cpp|cxx|m|mm)$/.test(file))
6185
6199
  if (units.length === 0) continue
6200
+ const includes = `${prefix}include/`
6201
+ const consumers = new Map<string, Set<string>>()
6202
+ const reverse = new Map<string, string[]>()
6203
+ for (const [file, contents] of entries) {
6204
+ const producers = new Set<string>()
6205
+ // a block-commented include is not an edge.
6206
+ const source = contents.replace(/\/\*[\s\S]*?\*\//g, '')
6207
+ for (const match of source.matchAll(
6208
+ /^\s*#\s*(?:include|import)\s*[<"]([^>"]+)[>"]/gm,
6209
+ )) {
6210
+ const include = match[1]!
6211
+ const producer = /(?:^|\/)([^/]+)-Swift\.h$/.exec(include)?.[1]
6212
+ if (producer && targets.some((value) => value.name === producer))
6213
+ producers.add(producer)
6214
+ const local = [
6215
+ path.posix.join(path.posix.dirname(file), include),
6216
+ `${includes}${include}`,
6217
+ ].find((candidate) => input.files[candidate] !== undefined)
6218
+ if (local) {
6219
+ reverse.set(local, [...(reverse.get(local) ?? []), file])
6220
+ }
6221
+ }
6222
+ consumers.set(file, producers)
6223
+ }
6224
+ const queue = [...consumers.keys()].filter((file) => consumers.get(file)!.size > 0)
6225
+ for (let index = 0; index < queue.length; index++) {
6226
+ const file = queue[index]!
6227
+ for (const parent of reverse.get(file) ?? []) {
6228
+ const inherited = consumers.get(parent)!
6229
+ const before = inherited.size
6230
+ for (const producer of consumers.get(file)!) inherited.add(producer)
6231
+ if (before !== inherited.size) queue.push(parent)
6232
+ }
6233
+ }
6234
+ const late = units.filter(([file]) => consumers.get(file)!.size > 0)
6186
6235
  const settings = input.nativeTargets?.find((value) => value.name === target.name)
6187
- if (
6188
- entries.some(([file]) => file.endsWith('.swift')) ||
6189
- (settings && units.some(([file]) => /\.mm?$/.test(file)))
6190
- ) {
6236
+ if (settings || entries.some(([file]) => file.endsWith('.swift'))) {
6191
6237
  try {
6192
6238
  if (!settings)
6193
6239
  throw new Error(
@@ -6287,7 +6333,10 @@ export function writeSwiftProject(
6287
6333
  : relative
6288
6334
  }
6289
6335
  const accessorFlags = accessor ? ['-include', accessorHeader] : []
6290
- let nativeC = false
6336
+ let nativeC =
6337
+ !roots.length &&
6338
+ !entries.some(([file]) => file.endsWith('.swift')) &&
6339
+ !units.some(([file]) => /\.mm?$/.test(file))
6291
6340
  if (roots.length) {
6292
6341
  const sourceHeaders = path.join(
6293
6342
  layout.root,
@@ -6399,7 +6448,15 @@ export function writeSwiftProject(
6399
6448
  ]
6400
6449
  const cxx = /\.(?:cc|cpp|cxx|mm)$/.test(file)
6401
6450
  const identity = createHash('sha256')
6402
- .update(JSON.stringify([cxx, perFile]))
6451
+ .update(
6452
+ JSON.stringify([
6453
+ cxx,
6454
+ perFile,
6455
+ ...(nativeC && !roots.length
6456
+ ? [(consumers.get(file)?.size ?? 0) > 0]
6457
+ : []),
6458
+ ]),
6459
+ )
6403
6460
  .digest('hex')
6404
6461
  .slice(0, 12)
6405
6462
  const group = groups.get(identity) ?? {
@@ -6436,6 +6493,35 @@ export function writeSwiftProject(
6436
6493
  accessor.body,
6437
6494
  )
6438
6495
  }
6496
+ if (nativeC && !roots.length) {
6497
+ // a private c target has no imported declaration surface. retain its
6498
+ // original swiftpm header owner and stage every implementation group.
6499
+ const lateSources = new Set(late.map(([file]) => unitSource(file)))
6500
+ const owner = [...groups.values()].find((group) =>
6501
+ group.sources.every((source) => !lateSources.has(source)),
6502
+ )
6503
+ const implementations = [...groups.values()].filter((group) => group !== owner)
6504
+ native.set(target.name, {
6505
+ path: target.path,
6506
+ includeDirectory: include,
6507
+ sources: owner?.sources ?? [],
6508
+ lateSources: implementations.flatMap((group) => group.sources),
6509
+ flags: owner?.flags ?? flags,
6510
+ cxxFlags: owner?.cxxFlags ?? flags,
6511
+ ...(implementations.length
6512
+ ? {
6513
+ groups: implementations,
6514
+ late: {
6515
+ name: `${target.name}NativeImplementation`,
6516
+ producers: [
6517
+ ...new Set(late.flatMap(([file]) => [...consumers.get(file)!])),
6518
+ ].sort(),
6519
+ },
6520
+ }
6521
+ : {}),
6522
+ })
6523
+ continue
6524
+ }
6439
6525
  if (nativeC) {
6440
6526
  const modulemaps = Object.entries(settings.productHeaders).filter(([product]) =>
6441
6527
  product.endsWith('/Modules/module.modulemap'),
@@ -6520,41 +6606,6 @@ export function writeSwiftProject(
6520
6606
  }
6521
6607
  continue
6522
6608
  }
6523
- const includes = `${prefix}include/`
6524
- const consumers = new Map<string, Set<string>>()
6525
- const reverse = new Map<string, string[]>()
6526
- for (const [file, contents] of entries) {
6527
- const producers = new Set<string>()
6528
- // a block-commented include is not an edge.
6529
- const source = contents.replace(/\/\*[\s\S]*?\*\//g, '')
6530
- for (const match of source.matchAll(
6531
- /^\s*#\s*(?:include|import)\s*[<"]([^>"]+)[>"]/gm,
6532
- )) {
6533
- const include = match[1]!
6534
- const producer = /(?:^|\/)([^/]+)-Swift\.h$/.exec(include)?.[1]
6535
- if (producer && targets.some((value) => value.name === producer))
6536
- producers.add(producer)
6537
- const local = [
6538
- path.posix.join(path.posix.dirname(file), include),
6539
- `${includes}${include}`,
6540
- ].find((candidate) => input.files[candidate] !== undefined)
6541
- if (local) {
6542
- reverse.set(local, [...(reverse.get(local) ?? []), file])
6543
- }
6544
- }
6545
- consumers.set(file, producers)
6546
- }
6547
- const queue = [...consumers.keys()].filter((file) => consumers.get(file)!.size > 0)
6548
- for (let index = 0; index < queue.length; index++) {
6549
- const file = queue[index]!
6550
- for (const parent of reverse.get(file) ?? []) {
6551
- const inherited = consumers.get(parent)!
6552
- const before = inherited.size
6553
- for (const producer of consumers.get(file)!) inherited.add(producer)
6554
- if (before !== inherited.size) queue.push(parent)
6555
- }
6556
- }
6557
- const late = units.filter(([file]) => consumers.get(file)!.size > 0)
6558
6609
  native.set(target.name, {
6559
6610
  path: target.path,
6560
6611
  includeDirectory: path.join(layout.root, includes),
@@ -6828,6 +6879,7 @@ export function writeSwiftProject(
6828
6879
  '-fobjc-exceptions',
6829
6880
  '-fexceptions',
6830
6881
  '-fwasm-exceptions',
6882
+ ...WASI_EMULATION_FLAGS,
6831
6883
  '-fobjc-arc',
6832
6884
  '-fblocks',
6833
6885
  '-F',
@@ -0,0 +1,80 @@
1
+ // the canonical native IndexStore reader, embedded for standalone cli builds.
2
+ export const SWIFT_INDEX_READER_SOURCE = String.raw`// prints every symbol occurrence an index store holds for non-system source
3
+ // files, one tab-separated line each:
4
+ // file line col roles kind usr name
5
+ // built by the shared package owner against the installed toolchain's libIndexStore.
6
+ // usage: indexdump <index-store-path>
7
+ #include <indexstore/indexstore.h>
8
+ #include <stdio.h>
9
+ #include <stdlib.h>
10
+ #include <string.h>
11
+
12
+ static indexstore_t store;
13
+ static char file[4096];
14
+
15
+ static void put(indexstore_string_ref_t s) { fwrite(s.data, 1, s.length, stdout); }
16
+
17
+ static bool occurrence(void *ctx, indexstore_occurrence_t occ) {
18
+ indexstore_symbol_t sym = indexstore_occurrence_get_symbol(occ);
19
+ unsigned line, col;
20
+ indexstore_occurrence_get_line_col(occ, &line, &col);
21
+ printf("%s\t%u\t%u\t%llu\t%d\t", file, line, col,
22
+ (unsigned long long)indexstore_occurrence_get_roles(occ),
23
+ (int)indexstore_symbol_get_kind(sym));
24
+ put(indexstore_symbol_get_usr(sym));
25
+ fputc('\t', stdout);
26
+ put(indexstore_symbol_get_name(sym));
27
+ fputc('\n', stdout);
28
+ return true;
29
+ }
30
+
31
+ static bool dependency(void *ctx, indexstore_unit_dependency_t dep) {
32
+ if (indexstore_unit_dependency_get_kind(dep) != INDEXSTORE_UNIT_DEPENDENCY_RECORD) return true;
33
+ if (indexstore_unit_dependency_is_system(dep)) return true;
34
+ indexstore_string_ref_t path = indexstore_unit_dependency_get_filepath(dep);
35
+ indexstore_string_ref_t name = indexstore_unit_dependency_get_name(dep);
36
+ snprintf(file, sizeof file, "%.*s", (int)path.length, path.data);
37
+ char record[1024];
38
+ snprintf(record, sizeof record, "%.*s", (int)name.length, name.data);
39
+ indexstore_error_t err = NULL;
40
+ indexstore_record_reader_t reader = indexstore_record_reader_create(store, record, &err);
41
+ if (!reader) {
42
+ fprintf(stderr, "record %s: %s\n", record, indexstore_error_get_description(err));
43
+ exit(1);
44
+ }
45
+ indexstore_record_reader_occurrences_apply_f(reader, NULL, occurrence);
46
+ indexstore_record_reader_dispose(reader);
47
+ return true;
48
+ }
49
+
50
+ static bool unit(void *ctx, indexstore_string_ref_t name) {
51
+ char unitName[1024];
52
+ snprintf(unitName, sizeof unitName, "%.*s", (int)name.length, name.data);
53
+ indexstore_error_t err = NULL;
54
+ indexstore_unit_reader_t reader = indexstore_unit_reader_create(store, unitName, &err);
55
+ if (!reader) {
56
+ fprintf(stderr, "unit %s: %s\n", unitName, indexstore_error_get_description(err));
57
+ exit(1);
58
+ }
59
+ if (!indexstore_unit_reader_is_system_unit(reader))
60
+ indexstore_unit_reader_dependencies_apply_f(reader, NULL, dependency);
61
+ indexstore_unit_reader_dispose(reader);
62
+ return true;
63
+ }
64
+
65
+ int main(int argc, char **argv) {
66
+ if (argc != 2) {
67
+ fprintf(stderr, "usage: indexdump <index-store-path>\n");
68
+ return 2;
69
+ }
70
+ indexstore_error_t err = NULL;
71
+ store = indexstore_store_create(argv[1], &err);
72
+ if (!store) {
73
+ fprintf(stderr, "%s\n", indexstore_error_get_description(err));
74
+ return 1;
75
+ }
76
+ indexstore_store_units_apply_f(store, 0, NULL, unit);
77
+ indexstore_store_dispose(store);
78
+ return 0;
79
+ }
80
+ `
@@ -0,0 +1,147 @@
1
+ import { execFileSync, spawn } from 'node:child_process'
2
+ import { mkdirSync } from 'node:fs'
3
+ import type { SwiftIndexCommand, SwiftIndexLeg, SwiftIndexRef } from './types'
4
+
5
+ // explicit references only: a reference role without the implicit role.
6
+ const REFERENCE = 1 << 2
7
+ const IMPLICIT = 1 << 8
8
+
9
+ export function exec(
10
+ file: string,
11
+ argv: string[],
12
+ cwd: string,
13
+ ): Promise<{ code: number; out: string }> {
14
+ return new Promise((done, reject) => {
15
+ const child = spawn(file, argv, { cwd })
16
+ let out = ''
17
+ child.stdout.on('data', (chunk) => (out += chunk))
18
+ child.stderr.on('data', (chunk) => (out += chunk))
19
+ child.on('error', reject)
20
+ child.on('close', (code) => done({ code: code ?? 1, out }))
21
+ })
22
+ }
23
+
24
+ export async function pool<T, R>(
25
+ items: T[],
26
+ limit: number,
27
+ work: (item: T) => Promise<R>,
28
+ ): Promise<R[]> {
29
+ const results: R[] = new Array(items.length)
30
+ let next = 0
31
+ await Promise.all(
32
+ Array.from({ length: Math.min(limit, items.length) }, async () => {
33
+ while (next < items.length) {
34
+ const at = next++
35
+ results[at] = await work(items[at]!)
36
+ }
37
+ }),
38
+ )
39
+ return results
40
+ }
41
+
42
+ // shared by the corpus and explicit app inputs; the c reader owns indexstore access.
43
+ export function createSwiftIndexer(indexdump: string, jobs: number, cwd = process.cwd()) {
44
+ if (!Number.isInteger(jobs) || jobs < 1) throw new Error('invalid Swift index jobs')
45
+
46
+ function readIndex(store: string): Map<string, SwiftIndexRef[]> {
47
+ const byFile = new Map<string, SwiftIndexRef[]>()
48
+ const seen = new Set<string>()
49
+ const lines = execFileSync(indexdump, [store], {
50
+ encoding: 'utf8',
51
+ maxBuffer: 1 << 30,
52
+ })
53
+ for (const line of lines.split('\n')) {
54
+ if (!line || seen.has(line)) continue
55
+ seen.add(line)
56
+ const [file, row, col, roles, kind, usr, name, ...extra] = line.split('\t')
57
+ const role = Number(roles)
58
+ if (
59
+ !file ||
60
+ !row ||
61
+ !col ||
62
+ !roles ||
63
+ !kind ||
64
+ !usr ||
65
+ name === undefined ||
66
+ extra.length ||
67
+ ![row, col, kind].every((value) => Number.isSafeInteger(Number(value))) ||
68
+ !Number.isSafeInteger(role) ||
69
+ Number(row) < 1 ||
70
+ Number(col) < 1 ||
71
+ role < 0 ||
72
+ Number(kind) < 0
73
+ )
74
+ throw new Error('malformed Swift index occurrence')
75
+ if (!(role & REFERENCE) || role & IMPLICIT) continue
76
+ const refs = byFile.get(file) ?? []
77
+ refs.push({
78
+ line: Number(row),
79
+ col: Number(col),
80
+ usr,
81
+ name,
82
+ kind: Number(kind),
83
+ })
84
+ byFile.set(file, refs)
85
+ }
86
+ return byFile
87
+ }
88
+
89
+ // a whole-module typecheck can stop before a primary it would otherwise credit.
90
+ // index each primary against the same complete module instead.
91
+ async function indexModule(
92
+ leg: SwiftIndexLeg,
93
+ modules: string,
94
+ moduleName: string,
95
+ files: string[],
96
+ primaries: string[],
97
+ store: string,
98
+ configuration: {
99
+ languageVersion?: string
100
+ cwd?: string
101
+ parseAsLibrary?: boolean
102
+ } = {},
103
+ ) {
104
+ mkdirSync(store, { recursive: true })
105
+ const common = [
106
+ ...leg.flags(modules),
107
+ ...(configuration.parseAsLibrary === false ? [] : ['-parse-as-library']),
108
+ '-module-name',
109
+ moduleName,
110
+ '-swift-version',
111
+ configuration.languageVersion ?? '5',
112
+ ]
113
+ const errors = new Map<string, string>()
114
+ const commands = new Map<string, SwiftIndexCommand>()
115
+ await pool(primaries, jobs, async (file) => {
116
+ const args = [
117
+ '-index-file',
118
+ '-index-file-path',
119
+ file,
120
+ // units are named by output path; one each, or the last overwrites all.
121
+ '-index-unit-output-path',
122
+ `${file}.o`,
123
+ ...common,
124
+ '-index-store-path',
125
+ store,
126
+ '-index-ignore-system-modules',
127
+ ...files,
128
+ ]
129
+ const result = await exec(leg.swiftc, args, configuration.cwd ?? cwd)
130
+ const command: SwiftIndexCommand = {
131
+ arguments: args,
132
+ code: result.code,
133
+ diagnostics: result.out,
134
+ }
135
+ commands.set(file, command)
136
+ if (command.code !== 0)
137
+ errors.set(
138
+ file,
139
+ command.diagnostics.split('\n').find((line) => line.includes(': error:')) ??
140
+ `exit ${command.code}`,
141
+ )
142
+ })
143
+ return { refs: readIndex(store), errors, commands }
144
+ }
145
+
146
+ return { indexModule, readIndex }
147
+ }