peachsim 0.1.1684 → 0.1.1692

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 (254) hide show
  1. package/cli/commands/coverage-swift.ts +72 -5
  2. package/cli/commands/inspect/actions.ts +1 -0
  3. package/cli/commands/screenshot.ts +12 -0
  4. package/dist-lib/agent-daemon-client.cjs +1 -1
  5. package/dist-lib/agent-events.cjs +1 -1
  6. package/dist-lib/attached-projects.cjs +1 -1
  7. package/dist-lib/auth/shared-session.cjs +1 -1
  8. package/dist-lib/backend-origin.cjs +1 -1
  9. package/dist-lib/beta.cjs +1 -1
  10. package/dist-lib/beta.mjs +1 -1
  11. package/dist-lib/bridge-constants.cjs +1 -1
  12. package/dist-lib/bridge-contract-input.cjs +1 -1
  13. package/dist-lib/bridge-contract-input.mjs +1 -1
  14. package/dist-lib/bridge-contract.cjs +1 -1
  15. package/dist-lib/bridge-contract.mjs +1 -1
  16. package/dist-lib/bundle-channel.cjs +2252 -1462
  17. package/dist-lib/capture-contract.cjs +1 -1
  18. package/dist-lib/capture-contract.mjs +1 -1
  19. package/dist-lib/cloud-contract.cjs +1 -1
  20. package/dist-lib/cloud-contract.mjs +1 -1
  21. package/dist-lib/cloud-test-args.cjs +1 -1
  22. package/dist-lib/cloud-test-args.mjs +1 -1
  23. package/dist-lib/cloud.cjs +1 -1
  24. package/dist-lib/cloud.mjs +1 -1
  25. package/dist-lib/config.cjs +1 -1
  26. package/dist-lib/config.mjs +1 -1
  27. package/dist-lib/detox/index.cjs +1 -1
  28. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  29. package/dist-lib/expo-swift-bundle.cjs +1762 -995
  30. package/dist-lib/expo-swift-metadata.cjs +1 -1
  31. package/dist-lib/expo-swift-metadata.mjs +1 -1
  32. package/dist-lib/home-paths.cjs +1 -1
  33. package/dist-lib/host/bridge-host.cjs +2184 -1417
  34. package/dist-lib/host/fetch-proxy-handler.cjs +3 -3
  35. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  36. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  37. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  38. package/dist-lib/host/websocket-proxy.cjs +1 -1
  39. package/dist-lib/index.cjs +175 -69
  40. package/dist-lib/jump-to-source-babel.cjs +1 -1
  41. package/dist-lib/jump-to-source-native.cjs +1 -1
  42. package/dist-lib/kotlin-host.cjs +1 -1
  43. package/dist-lib/menu.cjs +1 -1
  44. package/dist-lib/menu.mjs +1 -1
  45. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  46. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  47. package/dist-lib/metro-production-bundle.cjs +1 -1
  48. package/dist-lib/metro-production-bundle.mjs +1 -1
  49. package/dist-lib/metro.cjs +174 -68
  50. package/dist-lib/native-app-identity-project.cjs +163 -51
  51. package/dist-lib/native-app-identity-project.mjs +206 -82
  52. package/dist-lib/native-app-identity.cjs +1 -1
  53. package/dist-lib/native-app-identity.mjs +1 -1
  54. package/dist-lib/native-firebase-metadata.cjs +1 -1
  55. package/dist-lib/native-firebase-metadata.mjs +1 -1
  56. package/dist-lib/plist.cjs +1 -1
  57. package/dist-lib/plist.mjs +1 -1
  58. package/dist-lib/profiles.cjs +1 -1
  59. package/dist-lib/public-brand.cjs +1 -1
  60. package/dist-lib/public-origins-lib-esm.json +26 -23
  61. package/dist-lib/public-origins-lib.json +74 -61
  62. package/dist-lib/react-native-host-modules.cjs +1 -1
  63. package/dist-lib/react-native-host-modules.mjs +1 -1
  64. package/dist-lib/reap-browser.cjs +1 -1
  65. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  66. package/dist-lib/sdk.cjs +2 -2
  67. package/dist-lib/sdk.mjs +2 -2
  68. package/dist-lib/skills.cjs +2633 -1840
  69. package/dist-lib/swift-compile.cjs +2478 -100
  70. package/dist-lib/swift-compile.mjs +2475 -100
  71. package/dist-lib/swift-package.cjs +108 -50
  72. package/dist-lib/swift-package.mjs +104 -50
  73. package/dist-lib/swift-submit.cjs +1 -1
  74. package/dist-lib/swift-submit.mjs +1 -1
  75. package/dist-lib/swift-toolchain.cjs +1 -1
  76. package/dist-lib/swift.cjs +1 -1
  77. package/dist-lib/vite-swift.cjs +3979 -985
  78. package/dist-lib/vite.cjs +12 -18
  79. package/dist-lib/worklet-executable.cjs +7 -4
  80. package/dist-lib/worklet-executable.mjs +7 -4
  81. package/dist-types/packages/peach-engine/src/engine/clipboardContract.d.ts +15 -1
  82. package/dist-types/packages/peach-globals/src/clipboardBridgeContract.d.ts +6 -0
  83. package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
  84. package/dist-types/packages/peach-globals/src/nodeContract.d.ts +3 -2
  85. package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
  86. package/package.json +1 -1
  87. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h +9 -0
  88. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLAvailability.h +22 -0
  89. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLBackgroundActivitySession.h +145 -0
  90. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLBeaconIdentityCondition.h +113 -0
  91. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLBeaconIdentityConstraint.h +34 -0
  92. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLBeaconRegion.h +225 -0
  93. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLBody.h +26 -0
  94. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLCircularGeographicCondition.h +59 -0
  95. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLCircularRegion.h +64 -0
  96. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLCondition.h +48 -0
  97. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLError.h +52 -0
  98. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLErrorDomain.h +24 -0
  99. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLGeocoder.h +55 -0
  100. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLHeading.h +117 -0
  101. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocation.h +9 -0
  102. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationManager+CLVisitExtensions.h +45 -0
  103. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationManager.h +877 -0
  104. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationManagerDelegate.h +225 -0
  105. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationPushServiceError.h +33 -0
  106. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationPushServiceExtension.h +28 -0
  107. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationUpdater.h +250 -0
  108. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLMonitor.h +140 -0
  109. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLMonitorConfiguration.h +77 -0
  110. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLMonitoringEvent.h +184 -0
  111. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLMonitoringRecord.h +57 -0
  112. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLPlacemark.h +98 -0
  113. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLRegion.h +123 -0
  114. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLServiceSession.h +211 -0
  115. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLVisit.h +66 -0
  116. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CoreLocation.h +46 -0
  117. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Modules/module.modulemap +7 -0
  118. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +96 -2
  119. package/sdk/ios/System/Library/Frameworks/IOSurface.framework/Headers/IOSurfaceBase.h +52 -0
  120. package/sdk/ios/System/Library/Frameworks/IOSurface.framework/Headers/IOSurfaceObjC.h +240 -0
  121. package/sdk/ios/System/Library/Frameworks/IOSurface.framework/Headers/IOSurfaceRef.h +474 -0
  122. package/sdk/ios/System/Library/Frameworks/IOSurface.framework/Headers/IOSurfaceTypes.h +66 -0
  123. package/sdk/ios/System/Library/Frameworks/IOSurface.framework/Modules/module.modulemap +10 -0
  124. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4AccelerationStructure.h +9 -0
  125. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4Archive.h +16 -0
  126. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4ArgumentTable.h +17 -0
  127. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4BinaryFunction.h +13 -0
  128. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4BinaryFunctionDescriptor.h +14 -0
  129. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4BufferRange.h +79 -0
  130. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4CommandAllocator.h +15 -0
  131. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4CommandBuffer.h +17 -0
  132. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4CommandEncoder.h +16 -0
  133. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4CommandQueue.h +19 -0
  134. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4CommitFeedback.h +15 -0
  135. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4Compiler.h +13 -0
  136. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4CompilerTask.h +13 -0
  137. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4ComputeCommandEncoder.h +19 -0
  138. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4ComputePipeline.h +13 -0
  139. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4Counters.h +19 -0
  140. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4FunctionDescriptor.h +13 -0
  141. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4LibraryDescriptor.h +13 -0
  142. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4LibraryFunctionDescriptor.h +13 -0
  143. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4LinkingDescriptor.h +13 -0
  144. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4MachineLearningCommandEncoder.h +17 -0
  145. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4MachineLearningPipeline.h +13 -0
  146. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4MeshRenderPipeline.h +13 -0
  147. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4PipelineDataSetSerializer.h +13 -0
  148. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4PipelineState.h +13 -0
  149. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4RenderCommandEncoder.h +17 -0
  150. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4RenderPass.h +17 -0
  151. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4RenderPipeline.h +13 -0
  152. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4SpecializedFunctionDescriptor.h +13 -0
  153. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4StitchedFunctionDescriptor.h +13 -0
  154. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4TileRenderPipeline.h +13 -0
  155. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLAccelerationStructure.h +1212 -0
  156. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLAccelerationStructureCommandEncoder.h +322 -0
  157. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLAccelerationStructureTypes.h +224 -0
  158. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLAllocation.h +22 -0
  159. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLArgument.h +279 -0
  160. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLArgumentEncoder.h +199 -0
  161. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLBinaryArchive.h +142 -0
  162. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLBlitCommandEncoder.h +266 -0
  163. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLBlitPass.h +82 -0
  164. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLBuffer.h +94 -0
  165. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLCaptureManager.h +113 -0
  166. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLCaptureScope.h +43 -0
  167. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLCommandBuffer.h +449 -0
  168. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLCommandEncoder.h +148 -0
  169. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLCommandQueue.h +102 -0
  170. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLComputeCommandEncoder.h +350 -0
  171. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLComputePass.h +90 -0
  172. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLComputePipeline.h +274 -0
  173. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLCounters.h +225 -0
  174. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLDataType.h +232 -0
  175. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLDefines.h +39 -0
  176. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLDepthStencil.h +93 -0
  177. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLDevice.h +1122 -0
  178. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLDeviceCertification.h +29 -0
  179. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLDrawable.h +36 -0
  180. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLDynamicLibrary.h +81 -0
  181. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLEvent.h +79 -0
  182. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLFence.h +22 -0
  183. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLFunctionConstantValues.h +30 -0
  184. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLFunctionDescriptor.h +95 -0
  185. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLFunctionHandle.h +29 -0
  186. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLFunctionLog.h +37 -0
  187. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLFunctionStitching.h +131 -0
  188. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLGPUAddress.h +19 -0
  189. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLHeap.h +284 -0
  190. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLIOCommandBuffer.h +10 -0
  191. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLIOCommandQueue.h +11 -0
  192. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLIOCompressor.h +10 -0
  193. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLIndirectCommandBuffer.h +157 -0
  194. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLIndirectCommandEncoder.h +110 -0
  195. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLIntersectionFunctionTable.h +186 -0
  196. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLLibrary.h +549 -0
  197. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLLinkedFunctions.h +57 -0
  198. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLLogState.h +65 -0
  199. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLParallelRenderCommandEncoder.h +77 -0
  200. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLPipeline.h +57 -0
  201. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLPixelFormat.h +342 -0
  202. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLRasterizationRate.h +323 -0
  203. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLRenderCommandEncoder.h +1068 -0
  204. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLRenderPass.h +411 -0
  205. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLRenderPipeline.h +788 -0
  206. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLResidencySet.h +141 -0
  207. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLResource.h +307 -0
  208. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLResourceStateCommandEncoder.h +125 -0
  209. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLResourceStatePass.h +85 -0
  210. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLResourceViewPool.h +22 -0
  211. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLSampler.h +252 -0
  212. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLStageInputOutputDescriptor.h +158 -0
  213. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLTensor.h +17 -0
  214. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLTexture.h +460 -0
  215. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLTextureViewPool.h +18 -0
  216. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLTypes.h +125 -0
  217. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLVertexDescriptor.h +153 -0
  218. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLVisibleFunctionTable.h +45 -0
  219. package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/Metal.h +94 -0
  220. package/sdk/ios/System/Library/Frameworks/Metal.framework/Modules/module.modulemap +6 -0
  221. package/sdk/ios/System/Library/Frameworks/UniformTypeIdentifiers.framework/Headers/UTDefines.h +35 -0
  222. package/sdk/ios/System/Library/Frameworks/UniformTypeIdentifiers.framework/Headers/UTTagClass.h +33 -0
  223. package/sdk/ios/System/Library/Frameworks/UniformTypeIdentifiers.framework/Headers/UTType.h +504 -0
  224. package/sdk/ios/System/Library/Frameworks/_LocationEssentials.framework/Headers/CLEssentialsAvailability.h +14 -0
  225. package/sdk/ios/System/Library/Frameworks/_LocationEssentials.framework/Headers/CLLocationEssentials.h +444 -0
  226. package/sdk/ios/System/Library/Frameworks/_LocationEssentials.framework/Headers/LocationEssentials.h +14 -0
  227. package/sdk/ios/System/Library/Frameworks/_LocationEssentials.framework/Modules/module.modulemap +14 -0
  228. package/sdk/ios/usr/include/complex.h +167 -0
  229. package/sdk/ios/usr/include/dispatch/dispatch.h +5 -0
  230. package/sdk/ios/usr/include/mach/mach_types.h +1 -0
  231. package/sdk/ios/usr/include/math.h +835 -2
  232. package/sdk/ios/usr/include/sys/cdefs.h +0 -1
  233. package/src/generated/swift-c-predefines.json +1988 -0
  234. package/src/nitro-bundle.ts +1 -0
  235. package/src/nitro-compile.ts +4 -0
  236. package/src/nitroContract.ts +18 -2
  237. package/src/swift-compile.ts +446 -49
  238. package/src/swift-coverage/package.ts +3 -1
  239. package/src/swift-coverage/xcode-assets.ts +62 -2
  240. package/src/swift-coverage/xcode-packages.ts +11 -6
  241. package/src/swift-host.ts +333 -57
  242. package/src/swift-objc-compile.ts +20 -5
  243. package/src/swift-objc-standin.ts +21 -11
  244. package/src/swift-package-manifest.ts +151 -28
  245. package/src/swift-package.ts +134 -58
  246. package/src/swift-packages.ts +141 -44
  247. package/src/swift-source-file.ts +10 -15
  248. package/src/swift-standins.ts +87 -13
  249. package/src/swift-submit.ts +5 -0
  250. package/src/swiftContract.ts +160 -75
  251. package/src/target-matcher.ts +15 -2
  252. package/src/worklet-executable.ts +7 -3
  253. package/src/xcode-json-project.ts +14 -2
  254. package/src/xcode-project.ts +154 -59
@@ -23,6 +23,7 @@ import os from 'node:os'
23
23
  import path from 'node:path'
24
24
  import yaml from 'yaml'
25
25
  import { admittedMacBuilderSlot } from './admitted-mac-build'
26
+ import cPredefinesJson from './generated/swift-c-predefines.json' with { type: 'json' }
26
27
  import { rnxHomeDir, swiftPackageCacheOptions } from './home-paths'
27
28
  import { isRecord } from './is-record'
28
29
  import { terminateProcessGroup } from './process-group'
@@ -48,10 +49,13 @@ import {
48
49
  objcView,
49
50
  } from './swift-objc-standin'
50
51
  import {
52
+ isSwiftNativeTranslationUnit,
51
53
  OBJC_RESOURCE_ACCESSOR_BODY,
52
54
  OBJC_RESOURCE_ACCESSOR_HEADER,
53
55
  swiftManifestCxxLanguageStandard,
56
+ swiftManifestDeclarations,
54
57
  swiftManifestTargets,
58
+ swiftManifestPackages,
55
59
  swiftObjCResourceAccessor,
56
60
  swiftObjCResourceBundleName,
57
61
  swiftPackagePartition,
@@ -70,10 +74,13 @@ import {
70
74
  } from './swift-toolchain'
71
75
  import {
72
76
  isSwiftNativeTargets,
77
+ isSwiftPackageFiles,
73
78
  isSwiftObjCPeerStartup,
74
79
  isSwiftResourceBundles,
80
+ isSwiftResourcePath,
75
81
  SWIFT_NATIVE_INPUT_ROOT,
76
82
  SWIFT_NATIVE_SDK_INCLUDE,
83
+ type SwiftPackageFiles,
77
84
  type SwiftNativeTarget,
78
85
  type SwiftObjCPeerStartup,
79
86
  type SwiftProjectPreparation,
@@ -205,6 +212,8 @@ const BUILD_JOBS = String(
205
212
 
206
213
  export interface SwiftCompileInput {
207
214
  files: Record<string, string>
215
+ packageFiles?: SwiftPackageFiles
216
+ packageGuestImports?: string[]
208
217
  objcPeerStartup?: SwiftObjCPeerStartup
209
218
  nativeTargets?: SwiftNativeTarget[]
210
219
  metalSources?: Record<string, string>
@@ -541,7 +550,7 @@ const SWIFT_IMPORT =
541
550
  // through `!`, `&&` and `||`.
542
551
  function swiftCondition(
543
552
  text: string,
544
- available: ReadonlySet<string>,
553
+ available?: ReadonlySet<string>,
545
554
  ): boolean | undefined {
546
555
  const tokens = text.match(/\w+\s*\([^()]*\)|&&|\|\||!|\(|\)|\w+/g) ?? []
547
556
  let index = 0
@@ -562,8 +571,8 @@ function swiftCondition(
562
571
  if (!call) return undefined
563
572
  const [, name, argument] = call
564
573
  if (name === 'os') return argument === 'iOS' || argument === 'WASI'
565
- if (name === 'canImport') return available.has(argument!)
566
- if (name === 'targetEnvironment') return false
574
+ if (name === 'canImport') return available?.has(argument!)
575
+ if (name === 'targetEnvironment') return argument === 'simulator'
567
576
  if (name === 'arch') return argument === 'wasm32'
568
577
  return undefined
569
578
  }
@@ -593,24 +602,18 @@ function swiftCondition(
593
602
  return either()
594
603
  }
595
604
 
596
- /**
597
- * the modules a source imports, in order. with `available`, only imports the
598
- * wasm compile certainly reaches: those outside every `#if`, or in a branch
599
- * whose condition holds there, `os(iOS)` included since the compile rewrites
600
- * it to true. a branch the scan cannot decide may compile out, so its
601
- * imports stay out of the list.
602
- */
603
- export function swiftImportNames(
605
+ // each line's branch state under the app's wasm compilation conditions.
606
+ // directives themselves are not executable source.
607
+ function* swiftConditionalLines(
604
608
  contents: string,
605
609
  available?: ReadonlySet<string>,
606
- ): string[] {
607
- const names: string[] = []
610
+ ): Generator<{ line: string; active: boolean | undefined }> {
608
611
  // per open `#if`: whether its current branch is active, and whether an
609
612
  // earlier branch was taken (or may have been)
610
613
  const frames: { active: boolean | undefined; taken: boolean | undefined }[] = []
611
614
  for (const line of contents.split('\n')) {
612
615
  const directive = /^\s*#(if|elseif|else|endif)\b(.*)$/.exec(line)
613
- if (directive && available) {
616
+ if (directive) {
614
617
  const [, kind, rest] = directive
615
618
  const condition = (rest ?? '').replace(/\/\/.*$/, '').trim()
616
619
  if (kind === 'if') {
@@ -633,9 +636,34 @@ export function swiftImportNames(
633
636
  ? holds
634
637
  : undefined
635
638
  }
639
+ yield { line, active: false }
636
640
  continue
637
641
  }
638
- if (available && frames.some((frame) => frame.active !== true)) continue
642
+ yield {
643
+ line,
644
+ active: frames.some((frame) => frame.active === false)
645
+ ? false
646
+ : frames.every((frame) => frame.active === true)
647
+ ? true
648
+ : undefined,
649
+ }
650
+ }
651
+ }
652
+
653
+ /**
654
+ * the modules a source imports, in order. with `available`, only imports the
655
+ * wasm compile certainly reaches: those outside every `#if`, or in a branch
656
+ * whose condition holds there, `os(iOS)` included since the compile rewrites
657
+ * it to true. a branch the scan cannot decide may compile out, so its
658
+ * imports stay out of the list.
659
+ */
660
+ export function swiftImportNames(
661
+ contents: string,
662
+ available?: ReadonlySet<string>,
663
+ ): string[] {
664
+ const names: string[] = []
665
+ for (const { line, active } of swiftConditionalLines(contents, available)) {
666
+ if (available && active !== true) continue
639
667
  const name = SWIFT_IMPORT.exec(line)?.[1]
640
668
  if (name) names.push(name)
641
669
  }
@@ -650,11 +678,11 @@ export function swiftPeachModules(moduleRoot: string): string[] {
650
678
  const distribution = swiftDistributionAt(moduleRoot)
651
679
  return distribution
652
680
  ? distribution.modules
653
- : [
654
- ...readFileSync(path.join(moduleRoot, 'Package.swift'), 'utf8').matchAll(
655
- /\.(?:target|systemLibrary)\(\s*name:\s*"([^"]+)"/g,
656
- ),
657
- ].map((match) => match[1]!)
681
+ : swiftManifestDeclarations(
682
+ readFileSync(path.join(moduleRoot, 'Package.swift'), 'utf8'),
683
+ )
684
+ .filter((target) => !target.executable)
685
+ .map((target) => target.name)
658
686
  }
659
687
 
660
688
  const sdkPaths = new Map<string, { sysroot: string; resources: string }>()
@@ -836,7 +864,7 @@ const EXECUTABLE_LINK_FLAGS = ` "-Xclang-linker", "-O0",
836
864
  const REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n'
837
865
 
838
866
  /** bump with any change to the emitted multi-target manifest text. */
839
- export const MULTI_MANIFEST_VERSION = 40
867
+ export const MULTI_MANIFEST_VERSION = 43
840
868
 
841
869
  // build-cli replaces this in every bundle; source runs read the files directly.
842
870
  declare const __SWIFT_COMPILER_DIGEST__: string | undefined
@@ -893,6 +921,11 @@ export function swiftArtifactHash(
893
921
  ),
894
922
  )
895
923
  hash.update(JSON.stringify(input.nativeTargets ?? []))
924
+ hash.update(JSON.stringify(input.packageGuestImports ?? []))
925
+ for (const file of Object.keys(input.packageFiles ?? {}).sort()) {
926
+ hash.update(`package-file\0${file}\0`)
927
+ hash.update(createHash('sha256').update(input.packageFiles![file]!).digest())
928
+ }
896
929
  hash.update(JSON.stringify(input.objcPeerStartup ?? null))
897
930
  for (const target of Object.keys(input.libraries ?? {}).sort()) {
898
931
  hash.update(`library\n${target}\n`)
@@ -940,8 +973,27 @@ interface SwiftNativeTargetPlan {
940
973
  late?: { name: string; producers: string[] }
941
974
  }
942
975
 
976
+ function swiftCrossImportFlags(moduleRoot: string, distribution: boolean): string[] {
977
+ const overlayRoot = path.join(
978
+ moduleRoot,
979
+ distribution ? 'modules' : 'cross-import-overlays',
980
+ )
981
+ return readdirSync(overlayRoot, { encoding: 'utf8', recursive: true })
982
+ .filter((file) => file.endsWith('.swiftoverlay'))
983
+ .sort((left, right) => left.localeCompare(right))
984
+ .flatMap((file) => [
985
+ '-Xfrontend',
986
+ '-swift-module-cross-import',
987
+ '-Xfrontend',
988
+ path.basename(path.dirname(file), '.swiftcrossimport'),
989
+ '-Xfrontend',
990
+ path.join(overlayRoot, file),
991
+ ])
992
+ }
993
+
943
994
  export function emitSwiftPackageManifest(args: {
944
995
  targets: SwiftPackageTarget[]
996
+ packages?: ReadonlyMap<string, string>
945
997
  cxxLanguageStandard?: string
946
998
  native?: Map<string, SwiftNativeTargetPlan>
947
999
  headerDirectory?: string
@@ -996,21 +1048,7 @@ export function emitSwiftPackageManifest(args: {
996
1048
  .join('\n') + '\n',
997
1049
  )
998
1050
  }
999
- const overlayRoot = path.join(
1000
- moduleRoot,
1001
- distribution ? 'modules' : 'cross-import-overlays',
1002
- )
1003
- const overlayFlags = readdirSync(overlayRoot, { encoding: 'utf8', recursive: true })
1004
- .filter((file) => file.endsWith('.swiftoverlay'))
1005
- .sort((left, right) => left.localeCompare(right))
1006
- .flatMap((file) => [
1007
- '-Xfrontend',
1008
- '-swift-module-cross-import',
1009
- '-Xfrontend',
1010
- path.basename(path.dirname(file), '.swiftcrossimport'),
1011
- '-Xfrontend',
1012
- path.join(overlayRoot, file),
1013
- ])
1051
+ const overlayFlags = swiftCrossImportFlags(moduleRoot, Boolean(distribution))
1014
1052
  .map((flag) => `, ${JSON.stringify(flag)}`)
1015
1053
  .join('')
1016
1054
  const executable = targets.find((target) => target.executable)
@@ -1098,6 +1136,13 @@ export function emitSwiftPackageManifest(args: {
1098
1136
  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}])]`
1099
1137
  const deps = [
1100
1138
  ...new Set([
1139
+ ...(target.dependencies ?? []).flatMap((dependency) =>
1140
+ dependency.kind === 'product'
1141
+ ? [
1142
+ `.product(name: ${JSON.stringify(dependency.name)}, package: ${JSON.stringify(dependency.package)})`,
1143
+ ]
1144
+ : [],
1145
+ ),
1101
1146
  ...(target.executable
1102
1147
  ? [
1103
1148
  ...new Set([
@@ -1199,6 +1244,9 @@ export function emitSwiftPackageManifest(args: {
1199
1244
  : native?.flags
1200
1245
  ? [` sources: ${JSON.stringify(native.sources)},`]
1201
1246
  : []),
1247
+ ...(!native?.clang && target.publicHeadersPath !== undefined
1248
+ ? [` publicHeadersPath: ${JSON.stringify(target.publicHeadersPath)},`]
1249
+ : []),
1202
1250
  // the native backend supplies dependency module maps without their
1203
1251
  // compiled modules. textual c++ includes keep those dependencies usable.
1204
1252
  ` ${clang ? nativeSettings : swiftSettings}${link}`,
@@ -1215,7 +1263,13 @@ export function emitSwiftPackageManifest(args: {
1215
1263
  'let package = Package(',
1216
1264
  ' name: "app",',
1217
1265
  ` products: [.executable(name: "${executable.name}", targets: ["${executable.name}"])],`,
1218
- ` dependencies: [${distribution ? '' : `.package(path: "${moduleRoot}")`}],`,
1266
+ ` dependencies: [${[
1267
+ ...(distribution ? [] : [`.package(path: ${JSON.stringify(moduleRoot)})`]),
1268
+ ...[...(args.packages ?? [])].map(
1269
+ ([name, directory]) =>
1270
+ `.package(name: ${JSON.stringify(name)}, path: ${JSON.stringify(directory)})`,
1271
+ ),
1272
+ ].join(', ')}],`,
1219
1273
  ' targets: [',
1220
1274
  ...targets.map(stanza),
1221
1275
  ...(args.objcExports
@@ -5744,9 +5798,12 @@ export function swiftSourceClosure(
5744
5798
  return Object.fromEntries(Object.entries(files).filter(([file]) => included.has(file)))
5745
5799
  }
5746
5800
 
5747
- /** Swift's application entry declarations, ignoring comments and strings. */
5801
+ /** application entries, excluding comments, strings and inactive branches. */
5748
5802
  export function swiftApplicationEntry(file: string, source: string): boolean {
5749
- const { tokens } = swiftCodeScan(source)
5803
+ const code = [...swiftConditionalLines(swiftCodeMask(source))]
5804
+ .map(({ line, active }) => (active === false ? ' '.repeat(line.length) : line))
5805
+ .join('\n')
5806
+ const { tokens } = swiftCodeScan(code)
5750
5807
  let depth = 0
5751
5808
  for (const at of tokens) {
5752
5809
  if (source[at] === '{') depth++
@@ -5763,6 +5820,287 @@ export function swiftApplicationEntry(file: string, source: string): boolean {
5763
5820
  return false
5764
5821
  }
5765
5822
 
5823
+ // a c-family entry: a main definition outside comments and strings. headers
5824
+ // never compile, so only sources are scanned.
5825
+ /** the macro environment a c-family entry guard evaluates against. */
5826
+ export interface SwiftCMacroEnvironment {
5827
+ /** the target's -D set, with values where given. */
5828
+ defines: ReadonlyMap<string, string | undefined>
5829
+ /** the compiler's own predefines for the unit's language. */
5830
+ predefines: ReadonlyMap<string, string | undefined>
5831
+ /** names any of the target's own sources or headers defines. */
5832
+ targetDefined: ReadonlySet<string>
5833
+ }
5834
+
5835
+ const emptyMacroEnvironment: SwiftCMacroEnvironment = {
5836
+ defines: new Map(),
5837
+ predefines: new Map(),
5838
+ targetDefined: new Set(),
5839
+ }
5840
+
5841
+ // whether the environment defines the name: -D and predefines decide,
5842
+ // a name only the target's own sources define is undecided (order and
5843
+ // conditions are not evaluated), and a name nowhere visible is absent.
5844
+ function cMacroDefined(name: string, env: SwiftCMacroEnvironment): boolean | undefined {
5845
+ if (env.defines.has(name) || env.predefines.has(name)) return true
5846
+ if (env.targetDefined.has(name)) return undefined
5847
+ return false
5848
+ }
5849
+
5850
+ function cMacroIntOrTrue(value: string | undefined): boolean | undefined {
5851
+ if (value === undefined) return true
5852
+ if (/^0[xX][0-9a-fA-F]+[uUlL]*$/.test(value) || /^\d+[uUlL]*$/.test(value))
5853
+ return Number.parseInt(value) !== 0
5854
+ return undefined
5855
+ }
5856
+
5857
+ function cMacroBareValue(name: string, env: SwiftCMacroEnvironment): boolean | undefined {
5858
+ if (env.defines.has(name)) return cMacroIntOrTrue(env.defines.get(name))
5859
+ if (env.predefines.has(name)) return cMacroIntOrTrue(env.predefines.get(name))
5860
+ if (env.targetDefined.has(name)) return undefined
5861
+ return false
5862
+ }
5863
+
5864
+ function cMacroNegated(name: string, env: SwiftCMacroEnvironment): boolean | undefined {
5865
+ const value = cMacroDefined(name, env)
5866
+ return value === undefined ? undefined : !value
5867
+ }
5868
+
5869
+ // a preprocessor condition the macro environment decides, or undefined when
5870
+ // the text needs the real preprocessor (comparisons, function-like macros,
5871
+ // __has_include and the like). only defined-ness, boolean operators and
5872
+ // integer literals evaluate; the rest is undecided.
5873
+ function cConditionValue(
5874
+ expression: string,
5875
+ env: SwiftCMacroEnvironment,
5876
+ ): boolean | undefined {
5877
+ let i = 0
5878
+ const skipSpaces = () => {
5879
+ while (i < expression.length && /\s/.test(expression[i]!)) i++
5880
+ }
5881
+ const parseOr = (): boolean | undefined => {
5882
+ let value = parseAnd()
5883
+ for (;;) {
5884
+ skipSpaces()
5885
+ if (!expression.startsWith('||', i)) return value
5886
+ i += 2
5887
+ const right = parseAnd()
5888
+ value = value === undefined || right === undefined ? undefined : value || right
5889
+ }
5890
+ }
5891
+ const parseAnd = (): boolean | undefined => {
5892
+ let value = parseUnary()
5893
+ for (;;) {
5894
+ skipSpaces()
5895
+ if (!expression.startsWith('&&', i)) return value
5896
+ i += 2
5897
+ const right = parseUnary()
5898
+ value = value === undefined || right === undefined ? undefined : value && right
5899
+ }
5900
+ }
5901
+ const parseUnary = (): boolean | undefined => {
5902
+ skipSpaces()
5903
+ if (expression[i] === '!') {
5904
+ i++
5905
+ const value = parseUnary()
5906
+ return value === undefined ? undefined : !value
5907
+ }
5908
+ if (expression[i] === '(') {
5909
+ i++
5910
+ const value = parseOr()
5911
+ skipSpaces()
5912
+ return expression[i] === ')' ? (i++, value) : undefined
5913
+ }
5914
+ const defined = /^defined\b/.exec(expression.slice(i))
5915
+ if (defined) {
5916
+ i += defined[0].length
5917
+ skipSpaces()
5918
+ const parenthesized = expression[i] === '('
5919
+ if (parenthesized) {
5920
+ i++
5921
+ skipSpaces()
5922
+ }
5923
+ const name = /^\w+/.exec(expression.slice(i))?.[0]
5924
+ if (!name) return undefined
5925
+ i += name.length
5926
+ skipSpaces()
5927
+ if (parenthesized) {
5928
+ if (expression[i] !== ')') return undefined
5929
+ i++
5930
+ }
5931
+ return cMacroDefined(name, env)
5932
+ }
5933
+ const literal = /^(0[xX][0-9a-fA-F]+|\d+)[uUlL]*/.exec(expression.slice(i))
5934
+ if (literal) {
5935
+ i += literal[0].length
5936
+ return Number(literal[1]) !== 0
5937
+ }
5938
+ const name = /^\w+/.exec(expression.slice(i))?.[0]
5939
+ if (!name) return undefined
5940
+ i += name.length
5941
+ return cMacroBareValue(name, env)
5942
+ }
5943
+ const value = parseOr()
5944
+ skipSpaces()
5945
+ return i === expression.length ? value : undefined
5946
+ }
5947
+
5948
+ // the lines xcode's preprocessor keeps: conditional directives evaluated
5949
+ // against the macro environment, with undecided branches kept, so an entry
5950
+ // guard the text cannot decide still counts.
5951
+ function cActiveCode(code: string, env: SwiftCMacroEnvironment): string {
5952
+ const kept: string[] = []
5953
+ const stack: { parent: boolean; taken: boolean }[] = []
5954
+ let active = true
5955
+ for (const line of code.replace(/\\\r?\n/g, '').split('\n')) {
5956
+ const directive =
5957
+ /^\s*#\s*(if|ifdef|ifndef|elif|elifdef|elifndef|else|endif)\b(.*)$/.exec(line)
5958
+ if (!directive) {
5959
+ if (active) kept.push(line)
5960
+ continue
5961
+ }
5962
+ const keyword = directive[1]!
5963
+ const rest = directive[2]!.trim()
5964
+ if (keyword === 'if' || keyword === 'ifdef' || keyword === 'ifndef') {
5965
+ const name = /^\w+$/.exec(rest)?.[0]
5966
+ const value =
5967
+ keyword === 'if'
5968
+ ? cConditionValue(rest, env)
5969
+ : name === undefined
5970
+ ? undefined
5971
+ : keyword === 'ifdef'
5972
+ ? cMacroDefined(name, env)
5973
+ : cMacroNegated(name, env)
5974
+ stack.push({ parent: active, taken: value === true })
5975
+ active = active && value !== false
5976
+ } else if (keyword === 'endif') {
5977
+ active = stack.pop()?.parent ?? true
5978
+ } else if (stack.length === 0) {
5979
+ continue
5980
+ } else {
5981
+ const frame = stack[stack.length - 1]!
5982
+ if (keyword === 'else') {
5983
+ active = frame.parent && !frame.taken
5984
+ frame.taken = true
5985
+ } else {
5986
+ const name = /^\w+$/.exec(rest)?.[0]
5987
+ const value =
5988
+ keyword === 'elif'
5989
+ ? cConditionValue(rest, env)
5990
+ : name === undefined
5991
+ ? undefined
5992
+ : keyword === 'elifdef'
5993
+ ? cMacroDefined(name, env)
5994
+ : cMacroNegated(name, env)
5995
+ const branch = !frame.taken && value !== false
5996
+ if (branch && value === true) frame.taken = true
5997
+ active = frame.parent && branch
5998
+ }
5999
+ }
6000
+ }
6001
+ return kept.join('\n')
6002
+ }
6003
+
6004
+ // the source with comments and string and character literals removed,
6005
+ // newlines kept so directive lines stay intact.
6006
+ function stripCCode(source: string): string {
6007
+ let code = ''
6008
+ let i = 0
6009
+ while (i < source.length) {
6010
+ if (source.startsWith('//', i)) {
6011
+ const end = source.indexOf('\n', i)
6012
+ i = end === -1 ? source.length : end
6013
+ } else if (source.startsWith('/*', i)) {
6014
+ const end = source.indexOf('*/', i + 2)
6015
+ i = end === -1 ? source.length : end + 2
6016
+ } else if (source[i] === '"' || source[i] === "'") {
6017
+ const quote = source[i]!
6018
+ i++
6019
+ while (i < source.length && source[i] !== quote) i += source[i] === '\\' ? 2 : 1
6020
+ i++
6021
+ } else {
6022
+ code += source[i]
6023
+ i++
6024
+ }
6025
+ }
6026
+ return code
6027
+ }
6028
+
6029
+ // every name the given sources define. order and conditions are not
6030
+ // evaluated: a name defined anywhere makes its guards undecided.
6031
+ export function swiftCDefinedNames(sources: Iterable<string>): Set<string> {
6032
+ const names = new Set<string>()
6033
+ for (const source of sources)
6034
+ for (const line of stripCCode(source).split('\n')) {
6035
+ const name = /^\s*#\s*define\s+([A-Za-z_]\w*)/.exec(line)?.[1]
6036
+ if (name) names.add(name)
6037
+ }
6038
+ return names
6039
+ }
6040
+
6041
+ type SwiftCPredefinesTable = {
6042
+ release: string
6043
+ languages: Record<string, Record<string, string | null>>
6044
+ }
6045
+ const cPredefineTable: SwiftCPredefinesTable = cPredefinesJson
6046
+ const cPredefineCache = new Map<string, Map<string, string | undefined>>()
6047
+
6048
+ // the compiler's own macros for the language xcode compiles the unit with:
6049
+ // the pinned toolchain clang's `-dM -E -target arm64-apple-ios` predefines,
6050
+ // committed in generated/swift-c-predefines.json and held at the pinned
6051
+ // release by scripts/check/swift-c-predefines-generated.ts. a table, not a
6052
+ // spawn, so the scan works hosted, on linux and without xcode. the triple
6053
+ // is the arm64-apple-ios device triple (TARGET_OS_SIMULATOR is 0 there; it
6054
+ // is 1 for the simulator SDK), matching the shipping configuration.
6055
+ export function swiftCPredefines(
6056
+ language: 'c' | 'c++' | 'objective-c' | 'objective-c++',
6057
+ ): Map<string, string | undefined> {
6058
+ const cached = cPredefineCache.get(language)
6059
+ if (cached) return cached
6060
+ const predefines = new Map<string, string | undefined>()
6061
+ for (const [name, value] of Object.entries(cPredefineTable.languages[language]))
6062
+ predefines.set(name, value ?? undefined)
6063
+ cPredefineCache.set(language, predefines)
6064
+ return predefines
6065
+ }
6066
+
6067
+ export function swiftCMainEntry(
6068
+ file: string,
6069
+ source: string,
6070
+ env: SwiftCMacroEnvironment = emptyMacroEnvironment,
6071
+ ): boolean {
6072
+ if (!isSwiftNativeTranslationUnit(file)) return false
6073
+ const code = cActiveCode(stripCCode(source), env)
6074
+ for (const match of code.matchAll(/^\s*(?:int\s+|void\s+)?main\s*\(/gm)) {
6075
+ // a definition opens its body after the parameter list and any
6076
+ // trailing declarators (noexcept, attributes); a declaration or a
6077
+ // call ends with a semicolon instead.
6078
+ let depth = 1
6079
+ let index = match.index + match[0].length
6080
+ for (; index < code.length && depth > 0; index++) {
6081
+ if (code[index] === '(') depth++
6082
+ else if (code[index] === ')') depth--
6083
+ }
6084
+ if (depth > 0) continue
6085
+ for (; index < code.length; index++) {
6086
+ const char = code[index]
6087
+ if (char === '{') return true
6088
+ if (char === ';' || char === '}') break
6089
+ // a trailing declarator group (noexcept(...), attributes);
6090
+ // braces inside it belong to the declarator, not a body.
6091
+ if (char === '(' || char === '[') {
6092
+ const closer = char === '(' ? ')' : ']'
6093
+ let nested = 1
6094
+ while (nested > 0 && ++index < code.length) {
6095
+ if (code[index] === char) nested++
6096
+ else if (code[index] === closer) nested--
6097
+ }
6098
+ }
6099
+ }
6100
+ }
6101
+ return false
6102
+ }
6103
+
5766
6104
  // swift's executable entry runs after the reactor's _initialize has completed.
5767
6105
  // global swift values remain lazy; native application initializers need separate
5768
6106
  // object evidence and are refused here rather than running the registry early.
@@ -5778,7 +6116,7 @@ function installObjcPeerStartup(
5778
6116
  }
5779
6117
  if (
5780
6118
  (input.nativeTargets?.length ?? 0) > 0 ||
5781
- Object.keys(input.files).some((file) => /\.(?:c|cc|cpp|cxx|m|mm)$/.test(file))
6119
+ Object.keys(input.files).some(isSwiftNativeTranslationUnit)
5782
6120
  )
5783
6121
  fail('original native source targets require constructor provenance before admission')
5784
6122
  validateObjcPeerStartupLibraries(input.libraries ?? {})
@@ -6029,6 +6367,19 @@ export function writeSwiftProject(
6029
6367
  throw new Error('swift compile input has invalid Objective-C peer startup metadata')
6030
6368
  if (input.nativeTargets !== undefined && !isSwiftNativeTargets(input.nativeTargets))
6031
6369
  throw new Error('swift compile input has invalid original clang target inputs')
6370
+ if (input.packageFiles !== undefined && !isSwiftPackageFiles(input.packageFiles))
6371
+ throw new Error('swift compile input has invalid original package files')
6372
+ const packages = input.packageFiles
6373
+ ? swiftManifestPackages(input.files['Package.swift'] ?? '')
6374
+ : new Map<string, string>()
6375
+ for (const directory of packages.values())
6376
+ if (
6377
+ !isSwiftResourcePath(directory) ||
6378
+ !Object.hasOwn(input.packageFiles ?? {}, `${directory}/Package.swift`)
6379
+ )
6380
+ throw new Error(
6381
+ `swift compile input has no transported package manifest for ${directory}`,
6382
+ )
6032
6383
  if (
6033
6384
  input.resourceBundles !== undefined &&
6034
6385
  !isSwiftResourceBundles(input.resourceBundles)
@@ -6144,7 +6495,7 @@ export function writeSwiftProject(
6144
6495
  }
6145
6496
  targetStagedFiles.delete(target.name)
6146
6497
  if (
6147
- entries.some(([file]) => /\.(?:c|cc|cpp|cxx|m|mm)$/.test(file)) &&
6498
+ entries.some(([file]) => isSwiftNativeTranslationUnit(file)) &&
6148
6499
  (swift || input.nativeTargets?.some((value) => value.name === target.name))
6149
6500
  ) {
6150
6501
  if (!swift) {
@@ -6229,7 +6580,7 @@ export function writeSwiftProject(
6229
6580
  for (const target of targets) {
6230
6581
  const prefix = target.path === '.' ? '' : `${target.path}/`
6231
6582
  const entries = targetEntries(target)
6232
- const units = entries.filter(([file]) => /\.(?:c|cc|cpp|cxx|m|mm)$/.test(file))
6583
+ const units = entries.filter(([file]) => isSwiftNativeTranslationUnit(file))
6233
6584
  if (units.length === 0) continue
6234
6585
  const includes = `${prefix}include/`
6235
6586
  const consumers = new Map<string, Set<string>>()
@@ -6285,12 +6636,13 @@ export function writeSwiftProject(
6285
6636
  mkdirSync(path.dirname(destination), { recursive: true })
6286
6637
  writeFileSync(destination, input.files[file]!)
6287
6638
  }
6288
- const search = [
6289
- ...new Set([
6290
- ...(settings?.headerSearchPaths ?? []),
6291
- ...headers.map((file) => path.posix.dirname(file)),
6292
- ]),
6293
- ].flatMap((dir) => ['-I', path.join(layout.root, dir)])
6639
+ // xcode searches only the target's search paths and header maps; a
6640
+ // -I per header directory would let an angle include land on a
6641
+ // project header xcode never exposes (damus: <stdint.h> on flatcc's
6642
+ // portable/include/std/stdint.h instead of the sdk).
6643
+ const search = [...new Set([...(settings?.headerSearchPaths ?? [])])].flatMap(
6644
+ (dir) => ['-I', path.join(layout.root, dir)],
6645
+ )
6294
6646
  const toolchainBin = nativeToolchain()
6295
6647
  const sdkHeaders = materializeObjcSdk(
6296
6648
  path.join(layout.root, '.build', 'peach-objc-sdk'),
@@ -6331,7 +6683,8 @@ export function writeSwiftProject(
6331
6683
  ?.resources ?? false,
6332
6684
  usesBundleMacro: entries.some(
6333
6685
  ([file, contents]) =>
6334
- /\.(?:c|cc|cpp|cxx|m|mm|h|hpp|hh|hxx)$/.test(file) &&
6686
+ (isSwiftNativeTranslationUnit(file) ||
6687
+ /\.(?:h|hpp|hh|hxx)$/.test(file)) &&
6335
6688
  /\bSWIFTPM_MODULE_BUNDLE\b/.test(contents),
6336
6689
  ),
6337
6690
  bundles: input.resourceBundles,
@@ -7069,6 +7422,7 @@ public func __peachObjcExportRoot() { _objcRegisterPeerClass(NSObject.self, nati
7069
7422
  path.join(layout.root, 'Package.swift'),
7070
7423
  emitSwiftPackageManifest({
7071
7424
  targets,
7425
+ packages,
7072
7426
  native,
7073
7427
  objcExports,
7074
7428
  nativeFlags,
@@ -7092,6 +7446,35 @@ public func __peachObjcExportRoot() { _objcRegisterPeerClass(NSObject.self, nati
7092
7446
  }) + moduleFiles,
7093
7447
  )
7094
7448
  }
7449
+ for (const [file, bytes] of Object.entries(input.packageFiles ?? {}))
7450
+ files.set(path.join(layout.root, file), Buffer.from(bytes, 'base64'))
7451
+ if (input.packageFiles) {
7452
+ files.set(
7453
+ path.join(layout.root, '.peach-target-toolset.json'),
7454
+ JSON.stringify({
7455
+ schemaVersion: '1.0',
7456
+ swiftCompiler: {
7457
+ extraCLIOptions: [
7458
+ '-I',
7459
+ distribution
7460
+ ? path.join(moduleRoot, 'modules')
7461
+ : path.join(layout.root, '.build', WASM_TRIPLE, 'release', 'Modules'),
7462
+ '-Xfrontend',
7463
+ '-enable-cross-import-overlays',
7464
+ ...swiftCrossImportFlags(moduleRoot, Boolean(distribution)),
7465
+ ...(distribution
7466
+ ? FOUNDATION_IMPLICIT_MODULES.flatMap((module) => [
7467
+ '-Xfrontend',
7468
+ '-import-module',
7469
+ '-Xfrontend',
7470
+ module,
7471
+ ])
7472
+ : []),
7473
+ ],
7474
+ },
7475
+ }),
7476
+ )
7477
+ }
7095
7478
  // resource accessors and the /res pack share the original target assignment.
7096
7479
  for (const target of resourceTargets) {
7097
7480
  if (!target.resources) continue
@@ -7561,6 +7944,9 @@ export function compileSwiftProjectUnit(
7561
7944
  ...swiftSdkOptions(),
7562
7945
  '--swift-sdk',
7563
7946
  sdk,
7947
+ ...(input.packageFiles
7948
+ ? ['--toolset', path.join(root, '.peach-target-toolset.json')]
7949
+ : []),
7564
7950
  '-c',
7565
7951
  'release',
7566
7952
  '-Xswiftc',
@@ -7599,6 +7985,17 @@ export function compileSwiftProjectUnit(
7599
7985
  }
7600
7986
  report('compiling and linking Swift modules')
7601
7987
  try {
7988
+ if (input.packageFiles && !swiftDistributionAt(moduleRoot)) {
7989
+ const frameworks = new Set(['SwiftUI'])
7990
+ for (const name of input.packageGuestImports ?? [])
7991
+ if (OPTIONAL_FRAMEWORKS.has(name)) frameworks.add(name)
7992
+ for (const framework of frameworks)
7993
+ await runCompiler(
7994
+ swift,
7995
+ [...buildArgs, '--target', framework],
7996
+ buildOptions,
7997
+ )
7998
+ }
7602
7999
  // clang consumes the real emitted headers after swift finishes.
7603
8000
  // swiftpm's transitive swift module maps are not C declarations:
7604
8001
  // importing them would shadow SDK modules such as ObjectiveC.