peachsim 0.1.1716 → 0.1.1728

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 (234) hide show
  1. package/README.md +21 -3
  2. package/cli/app-bundle-resources.ts +2 -1
  3. package/cli/app-fonts.ts +4 -4
  4. package/cli/app-splash.ts +4 -4
  5. package/cli/app-stubs.ts +17 -0
  6. package/cli/command-registry.ts +1 -0
  7. package/cli/commands/control.ts +82 -822
  8. package/cli/commands/daemon.ts +8 -0
  9. package/cli/commands/detox.ts +3 -0
  10. package/cli/commands/doctor.ts +19 -2
  11. package/cli/commands/inspect/actions.ts +74 -14
  12. package/cli/commands/inspect/core.ts +5 -1
  13. package/cli/commands/inspect/settling.ts +5 -2
  14. package/cli/commands/inspect/wait-ready.ts +6 -0
  15. package/cli/commands/inspect.ts +48 -45
  16. package/cli/commands/kotlin.ts +12 -2
  17. package/cli/commands/package.ts +750 -0
  18. package/cli/commands/serve.ts +6 -0
  19. package/cli/commands/shell-url.ts +834 -0
  20. package/cli/commands/swift.ts +42 -102
  21. package/cli/commands/test.ts +20 -0
  22. package/cli/commands/upload.ts +1 -1
  23. package/cli/device-option.ts +1 -1
  24. package/cli/main.ts +13 -1
  25. package/cli/native-input.ts +199 -0
  26. package/cli/outbound-endpoints.ts +26 -1
  27. package/cli/packaged-app-launcher.ts +95 -0
  28. package/cli/scene-video.ts +13 -6
  29. package/detox/index.ts +187 -23
  30. package/dist-lib/agent-daemon-client.cjs +1 -1
  31. package/dist-lib/agent-events.cjs +1 -1
  32. package/dist-lib/attached-projects.cjs +1 -1
  33. package/dist-lib/auth/shared-session.cjs +1 -1
  34. package/dist-lib/backend-origin.cjs +1 -1
  35. package/dist-lib/beta.cjs +1 -1
  36. package/dist-lib/beta.mjs +1 -1
  37. package/dist-lib/bridge-constants.cjs +1 -1
  38. package/dist-lib/bridge-contract-input.cjs +1 -1
  39. package/dist-lib/bridge-contract-input.mjs +1 -1
  40. package/dist-lib/bridge-contract.cjs +1 -1
  41. package/dist-lib/bridge-contract.mjs +1 -1
  42. package/dist-lib/bundle-channel.cjs +38000 -31658
  43. package/dist-lib/capture-contract.cjs +1 -1
  44. package/dist-lib/capture-contract.mjs +1 -1
  45. package/dist-lib/cloud-contract.cjs +1 -1
  46. package/dist-lib/cloud-contract.mjs +1 -1
  47. package/dist-lib/cloud-test-args.cjs +1 -1
  48. package/dist-lib/cloud-test-args.mjs +1 -1
  49. package/dist-lib/cloud.cjs +1 -1
  50. package/dist-lib/cloud.mjs +1 -1
  51. package/dist-lib/config.cjs +1 -1
  52. package/dist-lib/config.mjs +1 -1
  53. package/dist-lib/detox/index.cjs +184 -60
  54. package/dist-lib/dev-bundle-resolution.cjs +14 -13
  55. package/dist-lib/expo-swift-bundle.cjs +18199 -11834
  56. package/dist-lib/expo-swift-metadata.cjs +4 -1
  57. package/dist-lib/expo-swift-metadata.mjs +3 -1
  58. package/dist-lib/home-paths.cjs +21 -2
  59. package/dist-lib/host/bridge-host.cjs +26509 -23850
  60. package/dist-lib/host/fetch-proxy-handler.cjs +221 -222
  61. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  62. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  63. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  64. package/dist-lib/host/websocket-proxy.cjs +1 -1
  65. package/dist-lib/index.cjs +876 -389
  66. package/dist-lib/jump-to-source-babel.cjs +1 -1
  67. package/dist-lib/jump-to-source-native.cjs +1 -1
  68. package/dist-lib/kotlin-host.cjs +127 -16
  69. package/dist-lib/menu.cjs +7 -1
  70. package/dist-lib/menu.mjs +7 -1
  71. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  72. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  73. package/dist-lib/metro-production-bundle.cjs +1 -1
  74. package/dist-lib/metro-production-bundle.mjs +1 -1
  75. package/dist-lib/metro.cjs +883 -404
  76. package/dist-lib/native-app-identity-project.cjs +694 -280
  77. package/dist-lib/native-app-identity-project.mjs +490 -83
  78. package/dist-lib/native-app-identity.cjs +13 -2
  79. package/dist-lib/native-app-identity.mjs +13 -2
  80. package/dist-lib/native-firebase-metadata.cjs +1 -1
  81. package/dist-lib/native-firebase-metadata.mjs +1 -1
  82. package/dist-lib/plist.cjs +1 -1
  83. package/dist-lib/plist.mjs +1 -1
  84. package/dist-lib/profiles.cjs +1 -1
  85. package/dist-lib/public-brand.cjs +1 -1
  86. package/dist-lib/public-origins-lib-esm.json +28 -23
  87. package/dist-lib/public-origins-lib.json +392 -224
  88. package/dist-lib/react-native-host-modules.cjs +32 -2
  89. package/dist-lib/react-native-host-modules.mjs +32 -2
  90. package/dist-lib/reap-browser.cjs +12 -4
  91. package/dist-lib/scripts/dev-server-scanner.cjs +15 -8
  92. package/dist-lib/sdk.cjs +17 -7
  93. package/dist-lib/sdk.mjs +16 -7
  94. package/dist-lib/skills.cjs +61838 -47851
  95. package/dist-lib/swift-compile.cjs +583 -360
  96. package/dist-lib/swift-compile.mjs +496 -275
  97. package/dist-lib/swift-package.cjs +1 -1
  98. package/dist-lib/swift-package.mjs +1 -1
  99. package/dist-lib/swift-submit.cjs +2 -2
  100. package/dist-lib/swift-submit.mjs +2 -2
  101. package/dist-lib/swift-toolchain.cjs +105 -17
  102. package/dist-lib/swift.cjs +1 -1
  103. package/dist-lib/vite-swift.cjs +4453 -2231
  104. package/dist-lib/vite.cjs +230 -228
  105. package/dist-lib/worklet-executable.cjs +1 -1
  106. package/dist-lib/worklet-executable.mjs +1 -1
  107. package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-cookies.d.ts +17 -8
  108. package/dist-types/packages/peach-engine/src/engine/canvaskit-renderer.d.ts +1 -0
  109. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +7 -5
  110. package/dist-types/packages/peach-engine/src/engine/memory-counts.d.ts +3 -1
  111. package/dist-types/packages/peach-engine/src/engine/node.d.ts +1 -11
  112. package/dist-types/packages/peach-engine/src/engine/types.d.ts +3 -0
  113. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +9 -0
  114. package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +3 -0
  115. package/dist-types/packages/peach-engine/src/render-worker/native-ui-commandContract.d.ts +1 -1
  116. package/dist-types/packages/peach-engine/src/render-worker/shell-protocol.d.ts +4 -0
  117. package/dist-types/packages/peach-engine/src/render-worker/tree-sync-port.d.ts +1 -1
  118. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +23 -1
  119. package/dist-types/packages/peach-engine/src/shell-events.d.ts +1 -0
  120. package/dist-types/packages/peach-globals/src/audioBridgeContract.d.ts +5 -0
  121. package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
  122. package/dist-types/packages/peach-globals/src/keyboardBridgeContract.d.ts +11 -0
  123. package/dist-types/packages/peach-globals/src/shellBridgeContract.d.ts +1 -0
  124. package/dist-types/packages/peach-globals/src/testBridgeContract.d.ts +9 -2
  125. package/package.json +1 -1
  126. package/runtime-companion.json +1 -1
  127. package/scripts/dev-server-scanner.ts +12 -25
  128. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASFoundation.h +52 -0
  129. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASWebAuthenticationSession.h +128 -0
  130. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASWebAuthenticationSessionCallback.h +35 -0
  131. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/AuthenticationServices.h +3 -0
  132. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Modules/module.modulemap +5 -0
  133. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFHTTPMessage.h +724 -0
  134. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetwork.h +4 -0
  135. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetworkDefs.h +27 -0
  136. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Modules/module.modulemap +5 -0
  137. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFURL.h +1301 -0
  138. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h +2 -0
  139. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationManager.h +21 -50
  140. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLRegion.h +6 -6
  141. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +75 -9
  142. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h +12 -0
  143. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIInterface.h +23 -0
  144. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h +7 -9
  145. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIOrientation.h +14 -0
  146. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIStringDrawing.h +12 -0
  147. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIView.h +14 -0
  148. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIViewAnimating.h +12 -0
  149. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIViewController.h +16 -0
  150. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIWindow.h +2 -0
  151. package/sdk/ios/usr/include/ConditionalMacros.h +619 -0
  152. package/sdk/ios/usr/include/module.modulemap +1 -0
  153. package/sdk/ios/usr/include/objc/objc-sync.h +59 -0
  154. package/sdk/ios/usr/include/os.modulemap +5 -0
  155. package/sdk/ios/usr/include/sys/cdefs.h +5 -0
  156. package/sdk/ios/usr/include/sys/ioccom.h +99 -0
  157. package/sdk/ios/usr/include/sys/syslog.h +236 -0
  158. package/sdk/ios/usr/include/syslog.h +24 -0
  159. package/sdk/ios/wasm/include/fcntl.h +4 -2
  160. package/sdk/ios/wasm/include/stdio.h +24 -0
  161. package/sdk/ios/wasm/include/stdlib.h +32 -7
  162. package/sdk/ios/wasm/include/sys/file.h +7 -0
  163. package/sdk/ios/wasm/include/sys/ioctl.h +6 -0
  164. package/sdk/ios/wasm/include/sys/syscall.h +9 -0
  165. package/sdk/ios/wasm/include/sys/time.h +10 -0
  166. package/sdk/ios/wasm/include/unistd.h +12 -3
  167. package/sdk/native-hashes.json +1 -0
  168. package/skills/contrast/SKILL.md +2 -1
  169. package/skills/peach-test/SKILL.md +7 -3
  170. package/src/admitted-mac-build.ts +3 -0
  171. package/src/android-app-identity.ts +18 -0
  172. package/src/android-root-module.ts +9 -9
  173. package/src/appPackageContract.ts +81 -0
  174. package/src/bridge-contract.ts +50 -0
  175. package/src/bundle-channel.mjs +21 -4
  176. package/src/dev-bundle-resolution.ts +7 -27
  177. package/src/dom-source-reference.ts +15 -0
  178. package/src/expo-discovery-cache.ts +127 -23
  179. package/src/expo-manifest-body.ts +33 -0
  180. package/src/expo-native-workspace.ts +38 -13
  181. package/src/expo-swift-host.ts +264 -62
  182. package/src/expoSwiftContract.ts +3 -0
  183. package/src/generated/swift-c-predefines.json +1 -1
  184. package/src/home-paths.ts +35 -1
  185. package/src/host/app-package-handler.ts +47 -0
  186. package/src/host/bridge-host.ts +3 -0
  187. package/src/host/staged-host-files.ts +18 -0
  188. package/src/index.ts +3 -0
  189. package/src/kotlin-host.ts +21 -18
  190. package/src/kotlin-instance-source.ts +126 -0
  191. package/src/menu.ts +7 -0
  192. package/src/native-app-identity-project.ts +7 -2
  193. package/src/native-app-identity.ts +11 -0
  194. package/src/native-firebase-config.ts +24 -1
  195. package/src/nitro-adapter.lock.json +268 -268
  196. package/src/nitro-bundle.ts +8 -0
  197. package/src/nitro-compile.ts +35 -9
  198. package/src/nitro-dependencies.ts +21 -19
  199. package/src/nitro-source.ts +4 -0
  200. package/src/nitroContract.ts +7 -0
  201. package/src/react-native-bridge-modules.ts +68 -42
  202. package/src/react-native-host-modules.ts +31 -1
  203. package/src/reactNativeConfigurationContract.ts +14 -0
  204. package/src/reap-browser.ts +15 -3
  205. package/src/sdk.ts +5 -0
  206. package/src/settingsContract.ts +27 -1
  207. package/src/sim-client.ts +4 -1
  208. package/src/storageSnapshotContract.ts +3 -0
  209. package/src/swift-compile.ts +221 -41
  210. package/src/swift-coverage/provenance.ts +1 -0
  211. package/src/swift-coverage/xcode-asset-symbols.ts +922 -0
  212. package/src/swift-coverage/xcode-assets.ts +89 -131
  213. package/src/swift-coverage/xcode.ts +1 -1
  214. package/src/swift-cxx-reachable.ts +2 -1
  215. package/src/swift-distribution.lock.json +14 -13
  216. package/src/swift-host.ts +95 -22
  217. package/src/swift-icu.ts +1 -1
  218. package/src/swift-link-roots.ts +118 -0
  219. package/src/swift-objc-compile.ts +144 -22
  220. package/src/swift-objc-import.ts +6 -0
  221. package/src/swift-objc-standin.ts +2 -14
  222. package/src/swift-package-manifest.ts +14 -6
  223. package/src/swift-packages.ts +75 -11
  224. package/src/swift-pdf-raster.ts +1 -0
  225. package/src/swift-root-lock.ts +17 -1
  226. package/src/swift-source-pods.ts +2 -10
  227. package/src/swift-standin-emit.ts +592 -57
  228. package/src/swift-standins.ts +430 -49
  229. package/src/swift-submit.ts +3 -1
  230. package/src/swift-toolchain.ts +140 -17
  231. package/src/turbo-codegen-intake.ts +91 -0
  232. package/src/vite-plugin-one.ts +13 -9
  233. package/src/vite-plugin.ts +28 -15
  234. package/src/xcode-project.ts +223 -22
@@ -16,6 +16,7 @@ import {
16
16
  renameSync,
17
17
  rmSync,
18
18
  statSync,
19
+ symlinkSync,
19
20
  utimesSync,
20
21
  writeFileSync,
21
22
  } from 'node:fs'
@@ -23,7 +24,7 @@ import os from 'node:os'
23
24
  import path from 'node:path'
24
25
  import { admittedMacBuilderSlot } from './admitted-mac-build'
25
26
  import cPredefinesJson from './generated/swift-c-predefines.json' with { type: 'json' }
26
- import { rnxHomeDir, swiftPackageCacheOptions } from './home-paths'
27
+ import { swiftCacheDir, swiftPackageCacheOptions } from './home-paths'
27
28
  import { terminateProcessGroup } from './process-group'
28
29
  import { swiftCompilerSourceDigest } from './swift-compiler-digest'
29
30
  import { designTimeDiagnostic, designTimeSource } from './swift-design-time'
@@ -33,7 +34,12 @@ import {
33
34
  type SwiftDistributionManifest,
34
35
  } from './swift-distribution-contract'
35
36
  import { swiftIcuAsset, type SwiftIcuAsset } from './swift-icu'
36
- import { SWIFT_OBJC_INTEROP_FLAGS, swiftObjCModuleMap } from './swift-objc-import'
37
+ import { swiftObjcRootObjects } from './swift-link-roots'
38
+ import {
39
+ SWIFT_OBJC_INTEROP_FLAGS,
40
+ swiftClangImporterFlags,
41
+ swiftObjCModuleMap,
42
+ } from './swift-objc-import'
37
43
  import { swiftObjCRuntimeFlags } from './swift-objc-runtime'
38
44
  import { iosDeploymentMinimum, objcSdkIntakeFlags } from './swift-objc-standin'
39
45
  import {
@@ -215,6 +221,8 @@ export interface SwiftCompileInput {
215
221
  projectFiles?: Record<string, string>
216
222
  packageGuestImports?: string[]
217
223
  nativeTargets?: SwiftNativeTarget[]
224
+ /** the Xcode app project's development region, for the emitted manifest's default localization. */
225
+ defaultLocalization?: string
218
226
  metalSources?: Record<string, string>
219
227
  resources?: Record<string, string>
220
228
  /** project-relative resource paths retained before the bundle namespace flattens. */
@@ -234,6 +242,11 @@ export interface SwiftCompileInput {
234
242
  * replace the stand-in's traps.
235
243
  */
236
244
  libraries?: Record<string, string>
245
+ /**
246
+ * link the distribution as an archive: only the objects the program
247
+ * references by symbol, plus those that register ObjC classes at load.
248
+ */
249
+ lazyDistribution?: boolean
237
250
  }
238
251
 
239
252
  // the builder hop wraps the compiler's own timeout with admission, transfer and
@@ -305,6 +318,7 @@ export function swiftModuleInputFiles(root: string): string[] {
305
318
  ...swiftSharedSdkInputFiles(root),
306
319
  '../peachsim/src/swift-shared-sdk.ts',
307
320
  '../../scripts/generate/swift-sdk-module/darwin-mach.json',
321
+ '../../scripts/ops/swift-distribution-publish.ts',
308
322
  'Package.swift',
309
323
  'scripts/contrast-app-Package.swift',
310
324
  'scripts/build-distribution.ts',
@@ -893,6 +907,80 @@ export function missingSwiftModules(
893
907
  return new Map([...missing].sort(([left], [right]) => left.localeCompare(right)))
894
908
  }
895
909
 
910
+ /**
911
+ * the clang module names and plain C headers a package's `.systemLibrary`
912
+ * targets own. a system target's clang module name need not match its SwiftPM
913
+ * target name, and its headers need not be provided by the distribution.
914
+ */
915
+ export function swiftSystemLibrarySurface(
916
+ files: Record<string, string>,
917
+ targets: readonly Pick<SwiftPackageTarget, 'path' | 'systemLibrary'>[],
918
+ ): { modules: Set<string>; headers: Set<string> } {
919
+ const modules = new Set<string>()
920
+ const headers = new Set<string>()
921
+ for (const target of targets) {
922
+ if (!target.systemLibrary) continue
923
+ const prefix = target.path === '.' ? '' : `${target.path.replace(/\/+$/, '')}/`
924
+ for (const [file, contents] of Object.entries(files)) {
925
+ if (!file.startsWith(prefix) || !file.endsWith('.modulemap')) continue
926
+ for (const match of contents.matchAll(/^\s*module\s+([A-Za-z_]\w*)/gm))
927
+ modules.add(match[1]!)
928
+ for (const match of contents.matchAll(/^\s*(?:umbrella\s+)?header\s+"([^"]+)"/gm)) {
929
+ const header = files[`${prefix}${match[1]}`]
930
+ if (header === undefined) continue
931
+ for (const include of header.matchAll(/#\s*(?:include|import)\s*<([^>/]+)>/g))
932
+ headers.add(include[1]!.replace(/\.h$/, ''))
933
+ }
934
+ }
935
+ }
936
+ return { modules, headers }
937
+ }
938
+
939
+ /**
940
+ * distribution modules a local system library must win over. a distribution
941
+ * module or a header it owns would otherwise satisfy the system target's
942
+ * `#include`, replacing the target SDK's declarations with the distribution's.
943
+ */
944
+ export function swiftSystemLibraryExclusions(
945
+ files: Record<string, string>,
946
+ targets: readonly Pick<SwiftPackageTarget, 'path' | 'systemLibrary'>[],
947
+ distributionModules: readonly string[],
948
+ ): Set<string> {
949
+ const surface = swiftSystemLibrarySurface(files, targets)
950
+ return new Set(
951
+ distributionModules.filter(
952
+ (name) => surface.modules.has(name) || surface.headers.has(name),
953
+ ),
954
+ )
955
+ }
956
+
957
+ /** a distribution modules path without the modules a local system library owns. */
958
+ function distributionModulesPath(
959
+ root: string,
960
+ moduleRoot: string,
961
+ excluded: ReadonlySet<string> | undefined,
962
+ ): string {
963
+ const modules = path.join(moduleRoot, 'modules')
964
+ if (!excluded || excluded.size === 0) return modules
965
+ const key = createHash('sha256')
966
+ .update([...excluded].sort().join('\0'))
967
+ .digest('hex')
968
+ .slice(0, 16)
969
+ const directory = path.join(root, `.peach-modules-${key}`)
970
+ const complete = path.join(directory, '.complete')
971
+ if (!existsSync(complete)) {
972
+ mkdirSync(directory, { recursive: true })
973
+ for (const entry of readdirSync(directory))
974
+ rmSync(path.join(directory, entry), { recursive: true, force: true })
975
+ for (const entry of readdirSync(modules)) {
976
+ if (excluded.has(entry.replace(/\.swiftmodule$/, ''))) continue
977
+ symlinkSync(path.join(modules, entry), path.join(directory, entry))
978
+ }
979
+ writeFileSync(complete, '')
980
+ }
981
+ return directory
982
+ }
983
+
896
984
  export function swiftTargetDependencies(
897
985
  files: Record<string, string>,
898
986
  targets: Pick<SwiftPackageTarget, 'name' | 'path' | 'dependencies'>[],
@@ -978,11 +1066,13 @@ const executableLinkFlags = (root: string) => ` "-Xclang-linker", "-O0"
978
1066
  "-Xlinker", "--stack-first",
979
1067
  "-Xlinker", "--global-base=8372224",
980
1068
  "-Xlinker", "-lsetjmp",
1069
+ "-Xlinker", "--export-table",
1070
+ "-Xlinker", "--growable-table",
981
1071
  `
982
1072
  const REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n'
983
1073
 
984
1074
  /** bump with any change to the emitted multi-target manifest text. */
985
- export const MULTI_MANIFEST_VERSION = 46
1075
+ export const MULTI_MANIFEST_VERSION = 50
986
1076
 
987
1077
  // build-cli replaces this in every bundle; source runs read the files directly.
988
1078
  declare const __SWIFT_COMPILER_DIGEST__: string | undefined
@@ -1001,6 +1091,7 @@ export function swiftArtifactHash(
1001
1091
  hash.update(compilerSourceDigest)
1002
1092
  if (input.oneModule) hash.update('one-module\n')
1003
1093
  hash.update(swiftModuleDigest(moduleRoot))
1094
+ if (input.lazyDistribution) hash.update('lazy-distribution\n')
1004
1095
  for (const file of Object.keys(input.files).sort()) {
1005
1096
  hash.update(createHash('sha256').update(file).digest())
1006
1097
  hash.update(createHash('sha256').update(input.files[file]).digest())
@@ -1040,6 +1131,8 @@ export function swiftArtifactHash(
1040
1131
  )
1041
1132
  hash.update(JSON.stringify(input.nativeTargets ?? []))
1042
1133
  hash.update(JSON.stringify(input.packageGuestImports ?? []))
1134
+ if (input.defaultLocalization)
1135
+ hash.update(`default-localization\n${input.defaultLocalization}\n`)
1043
1136
  for (const file of Object.keys(input.packageFiles ?? {}).sort()) {
1044
1137
  hash.update(`package-file\0${file}\0`)
1045
1138
  hash.update(createHash('sha256').update(input.packageFiles![file]!).digest())
@@ -1161,8 +1254,16 @@ export function emitSwiftPackageManifest(args: {
1161
1254
  spriteKit?: boolean
1162
1255
  /** link the prebuilt distribution at moduleRoot instead of its sources. */
1163
1256
  distribution?: SwiftDistributionManifest
1164
- /** ordered distribution objects, read by the linker without expanding argv. */
1257
+ /** distribution modules a local system library must win over. */
1258
+ distributionExcludes?: ReadonlySet<string>
1259
+ /**
1260
+ * ordered distribution objects, read by the linker without expanding argv.
1261
+ * absent when no source reaches a distribution framework: the executable
1262
+ * then links only the stdlib and system archives its sources reference.
1263
+ */
1165
1264
  distributionLink?: { path: string; files: Map<string, string | Buffer> }
1265
+ /** link the distribution objects other than its ObjC registrants lazily. */
1266
+ lazyDistribution?: boolean
1166
1267
  /**
1167
1268
  * framework products already built in their own scratch. objects link whole,
1168
1269
  * and modules import from that scratch, so this package's targets never
@@ -1173,6 +1274,8 @@ export function emitSwiftPackageManifest(args: {
1173
1274
  libraries?: Map<string, string>
1174
1275
  /** the sdk toolset already searches libc++ before the darwin overlay. */
1175
1276
  deferDarwinOverlay?: boolean
1277
+ /** the development region SwiftPM needs as defaultLocalization beside localized resources. */
1278
+ defaultLocalization?: string
1176
1279
  }): string {
1177
1280
  const { targets, siblings, moduleRoot, oneModule, spriteKit, distribution } = args
1178
1281
  const prebuilt = args.prebuilt
@@ -1196,26 +1299,37 @@ export function emitSwiftPackageManifest(args: {
1196
1299
  }
1197
1300
  // the distribution builder names each object lib/<target>-<file>.o.
1198
1301
  // preserve link order while leaving unreached optional module objects out.
1302
+ // the list is named by its content: SwiftPM relinks when the linker
1303
+ // command changes, never when a file the command reads does.
1304
+ let distributionLinkPath: string | undefined
1199
1305
  const distributionLink = args.distributionLink
1200
- if (distribution && !distributionLink)
1201
- throw new Error(
1202
- 'swift-compile: distribution linking requires its object response file',
1203
- )
1204
1306
  if (distribution && distributionLink) {
1205
1307
  const objects = distribution.objects.filter((object) =>
1206
1308
  [...OPTIONAL_FRAMEWORKS, 'SpriteKit', 'PeachBox2D'].every(
1207
1309
  (name) => !object.startsWith(`lib/${name}-`) || reachedFrameworks.has(name),
1208
1310
  ),
1209
1311
  )
1210
- distributionLink.files.set(
1211
- distributionLink.path,
1212
- objects
1213
- .map(
1214
- (object) =>
1215
- `"${path.join(moduleRoot, object).replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"`,
1216
- )
1217
- .join('\n') + '\n',
1312
+ const quoted = (object: string) =>
1313
+ `"${path.join(moduleRoot, object).replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"`
1314
+ const roots = args.lazyDistribution
1315
+ ? swiftObjcRootObjects(distribution.id, moduleRoot, distribution.objects)
1316
+ : null
1317
+ // an archive region loads an object only when a loaded one references it
1318
+ const list =
1319
+ (roots
1320
+ ? [
1321
+ ...objects.filter((object) => roots.has(object)).map(quoted),
1322
+ '-Wl,--start-lib',
1323
+ ...objects.filter((object) => !roots.has(object)).map(quoted),
1324
+ '-Wl,--end-lib',
1325
+ ]
1326
+ : objects.map(quoted)
1327
+ ).join('\n') + '\n'
1328
+ distributionLinkPath = distributionLink.path.replace(
1329
+ /\.rsp$/,
1330
+ `-${createHash('sha256').update(list).digest('hex').slice(0, 12)}.rsp`,
1218
1331
  )
1332
+ distributionLink.files.set(distributionLinkPath, list)
1219
1333
  }
1220
1334
  const overlayFlags = swiftCrossImportFlags(moduleRoot, Boolean(distribution))
1221
1335
  .map((flag) => `, ${JSON.stringify(flag)}`)
@@ -1265,7 +1379,9 @@ export function emitSwiftPackageManifest(args: {
1265
1379
  // the file opaquely so swift neither expands it nor scans every framework
1266
1380
  // object for autolinks; distribution.link supplies those libraries.
1267
1381
  const imports = distribution
1268
- ? `, "-I", ${JSON.stringify(path.join(moduleRoot, 'modules'))}`
1382
+ ? `, "-I", ${JSON.stringify(
1383
+ distributionModulesPath(args.root, moduleRoot, args.distributionExcludes),
1384
+ )}`
1269
1385
  : prebuilt
1270
1386
  ? `, "-I", ${JSON.stringify(prebuilt.modules)}${prebuilt.moduleMaps
1271
1387
  .map((map) => `, "-Xcc", ${JSON.stringify(`-fmodule-map-file=${map}`)}`)
@@ -1378,16 +1494,20 @@ export function emitSwiftPackageManifest(args: {
1378
1494
  ),
1379
1495
  ]),
1380
1496
  ].join(', ')
1381
- const library =
1382
- distribution && distributionLink
1383
- ? ['-Xclang-linker', `--config=${distributionLink.path}`, ...distribution.link]
1497
+ const library = distribution
1498
+ ? [
1499
+ ...(distributionLinkPath
1500
+ ? ['-Xclang-linker', `--config=${distributionLinkPath}`]
1501
+ : []),
1502
+ ...distribution.link,
1503
+ ]
1504
+ .map((flag) => `, ${JSON.stringify(flag)}`)
1505
+ .join('')
1506
+ : prebuilt
1507
+ ? ['-Xclang-linker', `--config=${prebuilt.linkFile}`, ...prebuilt.link]
1384
1508
  .map((flag) => `, ${JSON.stringify(flag)}`)
1385
1509
  .join('')
1386
- : prebuilt
1387
- ? ['-Xclang-linker', `--config=${prebuilt.linkFile}`, ...prebuilt.link]
1388
- .map((flag) => `, ${JSON.stringify(flag)}`)
1389
- .join('')
1390
- : ''
1510
+ : ''
1391
1511
  const kind = target.executable ? '.executableTarget' : '.target'
1392
1512
  const linkedLibraries = (target.linkedLibraries ?? []).map(
1393
1513
  (name) => `.linkedLibrary(${JSON.stringify(name)})`,
@@ -1464,6 +1584,9 @@ export function emitSwiftPackageManifest(args: {
1464
1584
  '// generated by swift-compile from the project package partition.',
1465
1585
  'let package = Package(',
1466
1586
  ' name: "app",',
1587
+ ...(args.defaultLocalization
1588
+ ? [` defaultLocalization: ${JSON.stringify(args.defaultLocalization)},`]
1589
+ : []),
1467
1590
  ` products: [.executable(name: "${executable.name}", targets: ["${executable.name}"])],`,
1468
1591
  ` dependencies: [${[
1469
1592
  ...(linkedObjects ? [] : [`.package(path: ${JSON.stringify(moduleRoot)})`]),
@@ -1521,6 +1644,7 @@ export function syncSwiftTree(base: string, files: Map<string, string | Buffer>)
1521
1644
  if (
1522
1645
  dir === base &&
1523
1646
  (entry.name === '.build' ||
1647
+ entry.name.startsWith('.peach-modules-') ||
1524
1648
  entry.name === SWIFT_LINK_STAMP ||
1525
1649
  entry.name === SWIFT_FRAMEWORK_KEY)
1526
1650
  )
@@ -2705,6 +2829,18 @@ export function swiftApplicationEntry(file: string, source: string): boolean {
2705
2829
  return false
2706
2830
  }
2707
2831
 
2832
+ // a typed entry: @main on a struct, class or enum in a branch the wasm
2833
+ // compile reaches. inactive #if branches cannot introduce an entry.
2834
+ export function swiftTypedApplicationEntry(
2835
+ source: string,
2836
+ ): { index: number; name: string } | null {
2837
+ const code = [...swiftConditionalLines(swiftCodeMask(source))]
2838
+ .map(({ line, active }) => (active === false ? ' '.repeat(line.length) : line))
2839
+ .join('\n')
2840
+ const match = /@main\b[\s\S]*?\b(?:struct|class|enum)\s+([A-Za-z_]\w*)/.exec(code)
2841
+ return match ? { index: match.index, name: match[1]! } : null
2842
+ }
2843
+
2708
2844
  // a main.swift entry calls UIApplicationMain at file scope. a mixed target
2709
2845
  // becomes a library, which cannot run that statement as process entry, so the
2710
2846
  // call moves into the function the generated executable runs after linking.
@@ -3307,6 +3443,9 @@ export function writeSwiftProject(
3307
3443
  },
3308
3444
  ]
3309
3445
  : compileTargets(input)
3446
+ const distributionExcludes = distribution
3447
+ ? swiftSystemLibraryExclusions(input.files, targets, distribution.modules)
3448
+ : undefined
3310
3449
  const files = new Map<string, string | Buffer>()
3311
3450
  const native = new Map<string, SwiftNativeTargetPlan>()
3312
3451
  const targetFailures: string[] = []
@@ -3758,7 +3897,7 @@ export function writeSwiftProject(
3758
3897
  allowExisting: true,
3759
3898
  })
3760
3899
  const importFlags = [
3761
- ...stageFlags(importOriginalFlags, sdkInclude),
3900
+ ...swiftClangImporterFlags(stageFlags(importOriginalFlags, sdkInclude)),
3762
3901
  '-fmodule-map-file=' + path.join(layout.root, modulemap),
3763
3902
  ...clangImportModuleMapFlags(settings, layout.root, importModuleMaps),
3764
3903
  ]
@@ -4047,10 +4186,8 @@ export function writeSwiftProject(
4047
4186
  ),
4048
4187
  )
4049
4188
  const mains = entries.flatMap(([file, source]) => {
4050
- const match = /@main\b[\s\S]*?\b(?:struct|class|enum)\s+([A-Za-z_]\w*)/.exec(
4051
- swiftCodeMask(source),
4052
- )
4053
- return match ? [{ file, source, match }] : []
4189
+ const entry = swiftTypedApplicationEntry(source)
4190
+ return entry ? [{ file, source, ...entry }] : []
4054
4191
  })
4055
4192
  let entryFile: string
4056
4193
  let entrySource: string
@@ -4058,10 +4195,10 @@ export function writeSwiftProject(
4058
4195
  const main = mains[0]!
4059
4196
  entryFile = main.file
4060
4197
  entrySource =
4061
- main.source.slice(0, main.match.index) +
4198
+ main.source.slice(0, main.index) +
4062
4199
  ' ' +
4063
- main.source.slice(main.match.index + 5) +
4064
- `\n@MainActor public func __peachRunApplication() { ${main.match[1]}.main() }\n`
4200
+ main.source.slice(main.index + 5) +
4201
+ `\n@MainActor public func __peachRunApplication() { ${main.name}.main() }\n`
4065
4202
  } else if (mains.length === 0) {
4066
4203
  const procedural = entries.filter(
4067
4204
  ([file, source]) =>
@@ -4126,6 +4263,10 @@ export function writeSwiftProject(
4126
4263
  '-fobjc-exceptions',
4127
4264
  '-fexceptions',
4128
4265
  '-fwasm-exceptions',
4266
+ // the backend lowers direct setjmp-family calls; -lsetjmp is already
4267
+ // linked. no-op for units without setjmp calls (byte-identical).
4268
+ '-mllvm',
4269
+ '-wasm-enable-sjlj',
4129
4270
  '-fobjc-arc',
4130
4271
  ...intake,
4131
4272
  ])
@@ -4189,8 +4330,10 @@ export function writeSwiftProject(
4189
4330
  const base = layout.multi ? layout.root : layout.sources
4190
4331
  const libraries = new Map<string, string>()
4191
4332
  for (const [target, data] of Object.entries(input.libraries ?? {})) {
4192
- const file = path.join(layout.root, '.peach-libraries', `lib${target}.a`)
4193
- files.set(file, Buffer.from(data, 'base64'))
4333
+ const bytes = Buffer.from(data, 'base64')
4334
+ const digest = createHash('sha256').update(bytes).digest('hex')
4335
+ const file = path.join(layout.root, '.peach-libraries', `lib${target}-${digest}.a`)
4336
+ files.set(file, bytes)
4194
4337
  libraries.set(target, file)
4195
4338
  }
4196
4339
  for (const [file, contents] of Object.entries(input.files)) {
@@ -4212,6 +4355,25 @@ export function writeSwiftProject(
4212
4355
  resources: false,
4213
4356
  },
4214
4357
  ]
4358
+ // a package reaches the distribution's frameworks through any Swift source
4359
+ // but its entry (every target compiles with implicit framework imports),
4360
+ // through Objective-C, or by importing a distribution module. C that calls
4361
+ // libdispatch needs the run loop UIKit's host drives (rnx_tick). an entry
4362
+ // that only calls other C and C++ targets links none of the frameworks'
4363
+ // objects, so it carries no UIKit host and reserves no icu data.
4364
+ const reachesFrameworks =
4365
+ !distribution ||
4366
+ Object.entries(input.files).some(
4367
+ ([file, source]) =>
4368
+ (file.endsWith('.swift') && file !== input.entry && file !== 'Package.swift') ||
4369
+ /\.mm?$/.test(file) ||
4370
+ source.includes('dispatch_'),
4371
+ ) ||
4372
+ [...importedModules].some(
4373
+ (name) =>
4374
+ distribution.modules.includes(name) &&
4375
+ !targets.some((target) => target.name === name),
4376
+ )
4215
4377
  const frameworkLink = prebuilt
4216
4378
  ? path.join(layout.root, '.peach-framework-objects.rsp')
4217
4379
  : undefined
@@ -4258,15 +4420,21 @@ export function writeSwiftProject(
4258
4420
  oneModule: input.oneModule,
4259
4421
  spriteKit: importsSpriteKit(input.files),
4260
4422
  distribution: distribution ?? undefined,
4423
+ distributionExcludes,
4261
4424
  deferDarwinOverlay:
4262
4425
  native.size > 0 &&
4263
4426
  toolsetOrdersLibcxxBeforeDarwinOverlay(
4264
4427
  swiftSdkPaths(moduleRoot, nativeToolchain()).cFlags,
4265
4428
  ),
4266
- distributionLink: {
4267
- path: path.join(layout.root, '.peach-distribution-objects.rsp'),
4268
- files,
4269
- },
4429
+ ...(reachesFrameworks
4430
+ ? {
4431
+ distributionLink: {
4432
+ path: path.join(layout.root, '.peach-distribution-objects.rsp'),
4433
+ files,
4434
+ },
4435
+ lazyDistribution: input.lazyDistribution,
4436
+ }
4437
+ : {}),
4270
4438
  ...(prebuilt && frameworkLink
4271
4439
  ? {
4272
4440
  prebuilt: {
@@ -4278,6 +4446,9 @@ export function writeSwiftProject(
4278
4446
  }
4279
4447
  : {}),
4280
4448
  libraries,
4449
+ ...(input.defaultLocalization
4450
+ ? { defaultLocalization: input.defaultLocalization }
4451
+ : {}),
4281
4452
  }) + moduleFiles,
4282
4453
  )
4283
4454
  }
@@ -4297,7 +4468,7 @@ export function writeSwiftProject(
4297
4468
  extraCLIOptions: [
4298
4469
  '-I',
4299
4470
  distribution
4300
- ? path.join(moduleRoot, 'modules')
4471
+ ? distributionModulesPath(layout.root, moduleRoot, distributionExcludes)
4301
4472
  : prebuilt
4302
4473
  ? prebuilt.modules
4303
4474
  : path.join(layout.root, '.build', WASM_TRIPLE, 'release', 'Modules'),
@@ -4923,6 +5094,15 @@ async function compileFrameworkProducts(args: {
4923
5094
  .split('\n')
4924
5095
  .map((line) => line.trim())
4925
5096
  .filter((flag, index, all) => flag.length > 0 && all.indexOf(flag) === index)
5097
+ // category-only archive members have no symbol reference to pull them in.
5098
+ // source consumers need the same direct Foundation input as distributions.
5099
+ if (link.includes('-lFoundation'))
5100
+ objects.push(
5101
+ path.join(
5102
+ swiftSdkPaths(args.moduleRoot, args.toolchainBin).resources,
5103
+ 'wasi/NSStringFormatting.objc.o',
5104
+ ),
5105
+ )
4926
5106
  return {
4927
5107
  modules: path.join(release, 'Modules'),
4928
5108
  objects,
@@ -5021,7 +5201,7 @@ export function compileSwiftProjectUnit(
5021
5201
  }
5022
5202
  const hash = swiftArtifactHash(input, options.release, moduleRoot)
5023
5203
  const frameworkKey = swiftProjectBuildKey(moduleRoot, options.release)
5024
- const sharedRoot = path.join(rnxHomeDir(), 'cache', 'swift-projects', hash)
5204
+ const sharedRoot = path.join(swiftCacheDir(), 'swift-projects', hash)
5025
5205
  const report = (message: string) => {
5026
5206
  console.error(`[swift-project ${hash.slice(0, 16)}] ${message}`)
5027
5207
  options.onStage?.(message)
@@ -12,6 +12,7 @@ export const SWIFT_COVERAGE_DIGEST_SOURCES = [
12
12
  'swift-coverage/package.ts',
13
13
  'swift-coverage/xcode.ts',
14
14
  'swift-coverage/xcode-assets.ts',
15
+ 'swift-coverage/xcode-asset-symbols.ts',
15
16
  'swift-coverage/xcode-bridging.ts',
16
17
  'swift-coverage/xcode-packages.ts',
17
18
  'swift-coverage/xcode-strings.ts',