peachsim 0.1.2224 → 0.1.2228

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 (171) hide show
  1. package/cli/bridge-flow-runner.ts +56 -3
  2. package/cli/commands/control.ts +27 -1
  3. package/cli/commands/flow.ts +26 -0
  4. package/cli/commands/package.ts +9 -2
  5. package/cli/drivers/playwright.ts +1 -0
  6. package/cli/drivers/types.ts +3 -0
  7. package/cli/internal-child.ts +4 -2
  8. package/dist-lib/agent-daemon-client.cjs +1 -1
  9. package/dist-lib/agent-events.cjs +1 -1
  10. package/dist-lib/attached-projects.cjs +1 -1
  11. package/dist-lib/auth/shared-session.cjs +1 -1
  12. package/dist-lib/backend-origin.cjs +1 -1
  13. package/dist-lib/beta.cjs +1 -1
  14. package/dist-lib/beta.mjs +1 -1
  15. package/dist-lib/bridge-constants.cjs +1 -1
  16. package/dist-lib/bridge-contract-input.cjs +1 -1
  17. package/dist-lib/bridge-contract-input.mjs +1 -1
  18. package/dist-lib/bridge-contract.cjs +1 -1
  19. package/dist-lib/bridge-contract.mjs +1 -1
  20. package/dist-lib/bundle-channel.cjs +931 -455
  21. package/dist-lib/capture-contract.cjs +1 -1
  22. package/dist-lib/capture-contract.mjs +1 -1
  23. package/dist-lib/cloud-contract.cjs +1 -1
  24. package/dist-lib/cloud-contract.mjs +1 -1
  25. package/dist-lib/cloud-test-args.cjs +1 -1
  26. package/dist-lib/cloud-test-args.mjs +1 -1
  27. package/dist-lib/cloud.cjs +1 -1
  28. package/dist-lib/cloud.mjs +1 -1
  29. package/dist-lib/config.cjs +1 -1
  30. package/dist-lib/config.mjs +1 -1
  31. package/dist-lib/detox/index.cjs +2 -2
  32. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  33. package/dist-lib/expo-swift-bundle.cjs +867 -391
  34. package/dist-lib/expo-swift-metadata.cjs +1 -1
  35. package/dist-lib/expo-swift-metadata.mjs +1 -1
  36. package/dist-lib/home-paths.cjs +1 -1
  37. package/dist-lib/host/bridge-host.cjs +926 -450
  38. package/dist-lib/host/fetch-proxy-handler.cjs +55 -12
  39. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  40. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  41. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  42. package/dist-lib/host/websocket-proxy.cjs +1 -1
  43. package/dist-lib/index.cjs +60 -16
  44. package/dist-lib/jump-to-source-babel.cjs +1 -1
  45. package/dist-lib/jump-to-source-native.cjs +1 -1
  46. package/dist-lib/kotlin-host.cjs +1 -1
  47. package/dist-lib/menu.cjs +1 -1
  48. package/dist-lib/menu.mjs +1 -1
  49. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  50. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  51. package/dist-lib/metro-production-bundle.cjs +11 -4
  52. package/dist-lib/metro-production-bundle.mjs +10 -4
  53. package/dist-lib/metro.cjs +60 -16
  54. package/dist-lib/native-app-identity-project.cjs +53 -9
  55. package/dist-lib/native-app-identity-project.mjs +84 -37
  56. package/dist-lib/native-app-identity.cjs +1 -1
  57. package/dist-lib/native-app-identity.mjs +1 -1
  58. package/dist-lib/native-firebase-metadata.cjs +1 -1
  59. package/dist-lib/native-firebase-metadata.mjs +1 -1
  60. package/dist-lib/pdfium-raster.cjs +1 -1
  61. package/dist-lib/pdfium-raster.mjs +1 -1
  62. package/dist-lib/plist.cjs +1 -1
  63. package/dist-lib/plist.mjs +1 -1
  64. package/dist-lib/profiles.cjs +1 -1
  65. package/dist-lib/public-brand.cjs +1 -1
  66. package/dist-lib/public-origins-lib-esm.json +26 -24
  67. package/dist-lib/public-origins-lib.json +66 -54
  68. package/dist-lib/react-native-host-modules.cjs +1 -1
  69. package/dist-lib/react-native-host-modules.mjs +1 -1
  70. package/dist-lib/reap-browser.cjs +1 -1
  71. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  72. package/dist-lib/sdk.cjs +1 -1
  73. package/dist-lib/sdk.mjs +1 -1
  74. package/dist-lib/skills.cjs +1049 -512
  75. package/dist-lib/swift-compile.cjs +557 -121
  76. package/dist-lib/swift-compile.mjs +693 -258
  77. package/dist-lib/swift-package.cjs +1 -1
  78. package/dist-lib/swift-package.mjs +1 -1
  79. package/dist-lib/swift-submit.cjs +1 -1
  80. package/dist-lib/swift-submit.mjs +1 -1
  81. package/dist-lib/swift-toolchain.cjs +38 -2
  82. package/dist-lib/swift.cjs +1 -1
  83. package/dist-lib/vite-swift.cjs +1726 -1209
  84. package/dist-lib/vite.cjs +55 -12
  85. package/dist-lib/worklet-executable.cjs +1 -1
  86. package/dist-lib/worklet-executable.mjs +1 -1
  87. package/dist-types/packages/peach-engine/src/bundle-parse-receipt.d.ts +17 -0
  88. package/dist-types/packages/peach-engine/src/engine/canvaskit-api.d.ts +2 -1
  89. package/dist-types/packages/peach-engine/src/engine/font-config.d.ts +2 -2
  90. package/dist-types/packages/peach-engine/src/engine/native-layout.d.ts +1 -0
  91. package/dist-types/packages/peach-engine/src/engine/native-paragraph.d.ts +4 -0
  92. package/dist-types/packages/peach-engine/src/engine/node.d.ts +2 -0
  93. package/dist-types/packages/peach-engine/src/engine/scene-table.d.ts +1 -1
  94. package/dist-types/packages/peach-engine/src/engine/types.d.ts +7 -0
  95. package/dist-types/packages/peach-engine/src/engine/yoga-layout.d.ts +2 -0
  96. package/dist-types/packages/peach-engine/src/metro-fingerprint.d.ts +3 -2
  97. package/dist-types/packages/peach-engine/src/preview/preview-room-contract.d.ts +6 -0
  98. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +1 -0
  99. package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +15 -3
  100. package/dist-types/packages/peach-engine/src/rolldown-bundle-inventory.d.ts +0 -5
  101. package/dist-types/packages/peach-kit/src/capabilities.d.ts +2 -0
  102. package/dist-types/packages/peach-kit/src/internal.d.ts +1 -1
  103. package/dist-types/packages/peach-kit/src/ios-tint.d.ts +2 -0
  104. package/kotlin/sdk.tar.gz +0 -0
  105. package/package.json +1 -1
  106. package/runtime-companion.json +1 -1
  107. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFCGTypes.h +0 -6
  108. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/NSCharacterSet.h +1 -1
  109. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/NSURL.h +1 -1
  110. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIControl.h +0 -26
  111. package/sdk/ios/System/Library/Frameworks/UIKitTypes.framework/Headers/UIKitTypes.h +27 -0
  112. package/sdk/ios/usr/include/AvailabilityInternal.h +2 -2
  113. package/sdk/ios/usr/include/ObjectiveC.apinotes +380 -7
  114. package/sdk/ios/usr/include/peach/pthread.h +1 -7
  115. package/sdk/ios/wasm/include/TargetConditionals.h +2 -3
  116. package/sdk/ios/wasm/include/__struct_timeval.h +15 -0
  117. package/sdk/ios/wasm/include/__typedef_suseconds_t.h +9 -0
  118. package/sdk/ios/wasm/include/limits.h +1 -1
  119. package/sdk/ios/wasm/include/machine/_types.h +1 -1
  120. package/sdk/ios/wasm/include/machine/limits.h +1 -1
  121. package/sdk/ios/wasm/include/machine/param.h +2 -2
  122. package/sdk/ios/wasm/include/math.h +13 -0
  123. package/sdk/ios/wasm/include/pthread.h +1 -13
  124. package/sdk/ios/wasm/include/sys/resource.h +3 -0
  125. package/sdk/ios/wasm/include/sys/socket.h +0 -10
  126. package/sdk/ios/wasm/include/sys/stat.h +5 -2
  127. package/sdk/ios/wasm/include/sys/time.h +16 -3
  128. package/sdk/ios/wasm/include/sys/types.h +4 -1
  129. package/sdk/ios/wasm/include/time.h +2 -0
  130. package/sdk/ios/wasm/storage-include/TargetConditionals.h +2 -3
  131. package/sdk/native-hashes.json +14 -14
  132. package/src/metro-production-bundle.ts +15 -2
  133. package/src/native-slices.ts +3 -2
  134. package/src/native-static-libraries.ts +23 -23
  135. package/src/native-swift-slices.ts +2 -2
  136. package/src/nitro-adapter.lock.json +288 -288
  137. package/src/nitro-compiler-digest.ts +0 -1
  138. package/src/nitro-dependencies.ts +8 -9
  139. package/src/nitro-superset.lock.json +4 -4
  140. package/src/react-native-core-build.ts +2 -2
  141. package/src/swift-compile.ts +209 -47
  142. package/src/swift-compiler-digest.ts +2 -0
  143. package/src/swift-cxx-standin.ts +1 -1
  144. package/src/swift-darwin-records.ts +4 -4
  145. package/src/swift-distribution-contract.ts +2 -2
  146. package/src/swift-distribution.lock.json +13 -12
  147. package/src/swift-guest-compile.ts +6 -5
  148. package/src/swift-guest-image-ledger.ts +5 -5
  149. package/src/swift-guest-link.ts +1 -1
  150. package/src/swift-guest-linked-spans.ts +7 -4
  151. package/src/swift-guest-manifest.ts +2 -2
  152. package/src/swift-guest-source-inputs.ts +16 -5
  153. package/src/swift-host.ts +10 -5
  154. package/src/swift-icu.ts +1 -1
  155. package/src/swift-objc-compile.ts +9 -4
  156. package/src/swift-objc-standin.ts +1 -4
  157. package/src/swift-package-manifest.ts +5 -1
  158. package/src/swift-packages.ts +2 -2
  159. package/src/swift-shared-sdk.ts +1 -1
  160. package/src/swift-standin-emit.ts +3 -16
  161. package/src/swift-standins.ts +119 -87
  162. package/src/swift-toolchain.ts +37 -1
  163. package/src/swift-uniform-type-constants.ts +1 -1
  164. package/src/swift-wasm-prune.ts +17 -12
  165. package/src/swiftGuestImageContract.ts +4 -4
  166. package/src/swiftNativePinContract.ts +1 -1
  167. package/src/swiftRuntimeProductContract.ts +1 -1
  168. package/src/turbo-runtime.lock.json +28 -28
  169. package/src/wasm-narrow-boundary.ts +296 -0
  170. package/src/wasm-optimize.ts +59 -14
  171. package/src/xcode-project.ts +6 -4
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.2224 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.2228 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
2
2
  let __sootsim_import_meta_url = '', __sootsim_import_meta_dirname = '', __sootsim_import_meta_filename = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; __sootsim_import_meta_dirname = __dirname; __sootsim_import_meta_filename = __filename; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -64,6 +64,7 @@ __export(swift_compile_exports, {
64
64
  swiftCompileSdkOptions: () => swiftCompileSdkOptions,
65
65
  swiftCrossImportFlags: () => swiftCrossImportFlags,
66
66
  swiftDistributionAt: () => swiftDistributionAt,
67
+ swiftHeaderWithSuperclassImports: () => swiftHeaderWithSuperclassImports,
67
68
  swiftIcuAddress: () => swiftIcuAddress,
68
69
  swiftIcuAsset: () => swiftIcuAsset,
69
70
  swiftIcuBundleAsset: () => swiftIcuBundleAsset,
@@ -88,12 +89,13 @@ __export(swift_compile_exports, {
88
89
  swiftTypedApplicationEntry: () => swiftTypedApplicationEntry,
89
90
  syncSwiftTree: () => syncSwiftTree,
90
91
  withNativeSourceGlue: () => withNativeSourceGlue,
92
+ withPreconcurrencyFoundationModules: () => withPreconcurrencyFoundationModules,
91
93
  withoutSwiftDeclarations: () => withoutSwiftDeclarations,
92
94
  wrapUIApplicationMainEntry: () => wrapUIApplicationMainEntry,
93
95
  writeSwiftProject: () => writeSwiftProject
94
96
  });
95
97
  module.exports = __toCommonJS(swift_compile_exports);
96
- var import_node_child_process18 = require("node:child_process");
98
+ var import_node_child_process19 = require("node:child_process");
97
99
  var import_node_crypto13 = require("node:crypto");
98
100
  var import_node_fs25 = require("node:fs");
99
101
  var import_node_os11 = __toESM(require("node:os"), 1);
@@ -2677,6 +2679,42 @@ function swiftSdkOptions() {
2677
2679
  var SWIFT_HOST_COMPILER_RELEASE = "swift-6.4.0-RELEASE-custom-81b2c791c27276bf";
2678
2680
  var SWIFT_HOST_COMPILER_ID = "81b2c791c27276bf";
2679
2681
  var compilerArchives = {
2682
+ "swift-6.4.0-RELEASE-custom-fb42d2535739dfd2": {
2683
+ identity: "fb42d2535739dfd2",
2684
+ archive: "tar.zst",
2685
+ hosts: {
2686
+ "darwin-arm64": {
2687
+ checksum: "5e417d415ca74a435755e298a1d2d19ec47637fd03479de7a7d958eb382941f1",
2688
+ manifest: "eb5a0356aebabe89c7b2780f8809e13d6e2ad6f342fed87cf99f9a5834344363"
2689
+ },
2690
+ "linux-arm64": {
2691
+ checksum: "8ac7ad97f3d68bf485423001d1ce3cd92a8d4625313c47c8071867a9aeed3af9",
2692
+ manifest: "6126266dd65b43c43d719e4dc4d33c4ea6a3267f99f34e3638637439a995af2e"
2693
+ },
2694
+ "linux-x64": {
2695
+ checksum: "7d76463079619ba822123d250601bd35f6744ed5f8054a657ce472ce4dac76c8",
2696
+ manifest: "f1a6c0c61d15eddb2ecfa4c3a72a5154621881ac2f0c413162ff1d0f4343bd0e"
2697
+ }
2698
+ }
2699
+ },
2700
+ "swift-6.4.0-RELEASE-custom-44ecd25f163bb359": {
2701
+ identity: "44ecd25f163bb359",
2702
+ archive: "tar.zst",
2703
+ hosts: {
2704
+ "darwin-arm64": {
2705
+ checksum: "d06dda4435f99d8376179cc7a3804907aa7305513135ece6288fd8e6d4695ae6",
2706
+ manifest: "bc0d8b955f923f096dda2aa8bbb1d56176a73f3d4a4df4cc9a1f59d31417061a"
2707
+ },
2708
+ "linux-x64": {
2709
+ checksum: "f95b56440693c5de7995f10ea14c57fc7e659a161018a17f17a74b61a98e88a4",
2710
+ manifest: "c18a60b14d5c89a8b2e1dbb2b4b52342c5fb92c7f3069fdc55c985bce61683a7"
2711
+ },
2712
+ "linux-arm64": {
2713
+ checksum: "afb74ae60df2b5bd7792bfbcf29bcea03675a5c814b758dd6cb91a760c220cd2",
2714
+ manifest: "ac037f6b0fdc4a6ae582eebc22bcf811fa2becdc30d083057137fc857f3c456a"
2715
+ }
2716
+ }
2717
+ },
2680
2718
  "swift-6.4.0-RELEASE-custom-11345d60dca47496": {
2681
2719
  identity: "11345d60dca47496",
2682
2720
  archive: "tar.zst",
@@ -3084,7 +3122,7 @@ function validateSwiftSdkIdentity(sdk) {
3084
3122
  function swiftSdkBundle(swift, id, options) {
3085
3123
  const configuration = (0, import_node_child_process4.execFileSync)(
3086
3124
  swift,
3087
- ["sdk", "configure", ...options, "--show-configuration", id, "wasm32-unknown-wasip1"],
3125
+ ["sdk", "configure", ...options, "--show-configuration", id, "wasm64-unknown-wasip1"],
3088
3126
  { encoding: "utf8", env: swiftEnvironment(), stdio: ["ignore", "pipe", "pipe"] }
3089
3127
  );
3090
3128
  const sysroot = /^sdkRootPath: (.+)$/m.exec(configuration)?.[1]?.trim();
@@ -3888,14 +3926,11 @@ function objcSdkIntakeFlags(headers, toolchainBin, minimum) {
3888
3926
  return [
3889
3927
  ...swiftObjCPlatformFlags(toolchainBin, minimum),
3890
3928
  // AvailabilityInternal.h derives these through __is_target_os(ios), which
3891
- // is false for wasm32. the maximum is the sdk the headers come from, as
3929
+ // is false for wasm64. the maximum is the sdk the headers come from, as
3892
3930
  // xcode defines it, so `#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_26_0`
3893
3931
  // sources see the members the sdk declares instead of a 17.0 default.
3894
3932
  `-D__IPHONE_OS_VERSION_MIN_REQUIRED=${minimum}`,
3895
3933
  `-D__IPHONE_OS_VERSION_MAX_ALLOWED=__IPHONE_${NATIVE_GRAPH_SDK_VERSION.replace(".", "_")}`,
3896
- // apple's build setting for a 32-bit target to keep NSInteger and
3897
- // NSUInteger long, the nominal types they have on arm64.
3898
- "-DNS_BUILD_32_LIKE_64=1",
3899
3934
  // the installed libc's default feature set otherwise defines
3900
3935
  // _XOPEN_SOURCE, which darwin's sys/cdefs.h turns into a strict posix
3901
3936
  // level; iOS compiles at darwin's full level with neither defined.
@@ -4165,7 +4200,7 @@ function swiftSharedSdkViewOptions(moduleRoot, distribution, toolchainBin, sdk)
4165
4200
  ...swiftSdkOptions(),
4166
4201
  "--show-configuration",
4167
4202
  sdk,
4168
- "wasm32-unknown-wasip1"
4203
+ "wasm64-unknown-wasip1"
4169
4204
  ],
4170
4205
  { encoding: "utf8", env: swiftEnvironment(), stdio: ["ignore", "pipe", "pipe"] }
4171
4206
  );
@@ -4302,7 +4337,7 @@ function compileDarwinRecords(args) {
4302
4337
  (0, import_node_child_process7.execFileSync)(
4303
4338
  import_node_path9.default.join(args.bin, "clang"),
4304
4339
  [
4305
- "--target=wasm32-unknown-wasip1",
4340
+ "--target=wasm64-unknown-wasip1",
4306
4341
  `--sysroot=${args.sysroot}`,
4307
4342
  "-Oz",
4308
4343
  "-g0",
@@ -4313,7 +4348,7 @@ function compileDarwinRecords(args) {
4313
4348
  `-ffile-prefix-map=${records}${import_node_path9.default.sep}=DarwinRecords/`,
4314
4349
  // apple's headers select on the ios identity original units compile
4315
4350
  // with, and TargetConditionals.h refuses a compiler without it
4316
- ...file.endsWith(".m") ? objcSdkIntakeFlags(args.darwin, args.bin, args.minimum) : [
4351
+ ...file === "sysctl.c" || file.endsWith(".m") ? objcSdkIntakeFlags(args.darwin, args.bin, args.minimum) : [
4317
4352
  ...swiftObjCPlatformFlags(args.bin, args.minimum),
4318
4353
  ...WASI_EMULATION_FLAGS,
4319
4354
  // the sdk build compiles these with libobjc2's headers in
@@ -4780,7 +4815,7 @@ var foundationCategoryObjects = [
4780
4815
  ];
4781
4816
 
4782
4817
  // src/swift-guest-compile.ts
4783
- var import_node_child_process13 = require("node:child_process");
4818
+ var import_node_child_process14 = require("node:child_process");
4784
4819
  var import_node_fs17 = require("node:fs");
4785
4820
  var import_node_path19 = __toESM(require("node:path"), 1);
4786
4821
 
@@ -4839,7 +4874,7 @@ var swiftSdkProductSchema = v.pipe(
4839
4874
  v.object({
4840
4875
  id: v.string(),
4841
4876
  installName: v.string(),
4842
- target: v.literal("wasm32-unknown-wasip1"),
4877
+ target: v.literal("wasm64-unknown-wasip1"),
4843
4878
  linkNames: v.array(v.string()),
4844
4879
  // absent records declare no framework namespace, even when a library name matches.
4845
4880
  frameworkAliases: v.optional(
@@ -4948,7 +4983,8 @@ function encodeULEB(val) {
4948
4983
  } while (val !== 0);
4949
4984
  return out;
4950
4985
  }
4951
- var HAS_ADDEND = /* @__PURE__ */ new Set([3, 4, 5, 8, 9, 11, 13, 14, 15, 16, 21, 22, 23, 24, 25]);
4986
+ var HAS_ADDEND = /* @__PURE__ */ new Set([3, 4, 5, 8, 9, 11, 14, 15, 16, 17, 21, 22, 23, 25]);
4987
+ var WIDE_DATA_RELOCS = /* @__PURE__ */ new Set([16, 19, 22]);
4952
4988
  var ROOT_SEG_PREFIXES = [
4953
4989
  ".init_array",
4954
4990
  "__objc_init_func",
@@ -5844,7 +5880,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
5844
5880
  } else {
5845
5881
  lazyBuildObjects.set(t, parseWasmObjectCached(t, false, false));
5846
5882
  }
5847
- } else if (!inStartLib && t.endsWith(".a") && !t.endsWith("libclang_rt.builtins-wasm32.a") && import_node_fs9.default.existsSync(t)) {
5883
+ } else if (!inStartLib && t.endsWith(".a") && !t.endsWith("libclang_rt.builtins-wasm64.a") && import_node_fs9.default.existsSync(t)) {
5848
5884
  const members = readArMembers(new Uint8Array(import_node_fs9.default.readFileSync(t)));
5849
5885
  for (const m of members) {
5850
5886
  extraArchiveObjs.push(parseWasmObjectBytes(`${t}(${m.name})`, m.bytes, false));
@@ -6326,7 +6362,11 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
6326
6362
  }
6327
6363
  }
6328
6364
  const keptDataRelocBytes = [];
6329
- const zeroDataRelocOffsets = [];
6365
+ const zeroDataRelocs = [];
6366
+ const zeroDataReloc = (r) => zeroDataRelocs.push({
6367
+ ro: r.ro,
6368
+ width: WIDE_DATA_RELOCS.has(r.rawBytes[0]) ? 8 : 4
6369
+ });
6330
6370
  const usedSyms = /* @__PURE__ */ new Set();
6331
6371
  for (const r of keptCodeRelocs) if (r.rawBytes[0] !== 6) usedSyms.add(r.rs);
6332
6372
  for (const r of obj.dataRelocList) {
@@ -6337,7 +6377,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
6337
6377
  keptDataRelocBytes.push(r.rawBytes);
6338
6378
  usedSyms.add(r.rs);
6339
6379
  } else if (sName === "__objc_classes") {
6340
- zeroDataRelocOffsets.push(r.ro);
6380
+ zeroDataReloc(r);
6341
6381
  } else {
6342
6382
  const repl = firstLiveInSpecialSeg.get(r.segIdx);
6343
6383
  const roBytes = encodeULEB(r.ro);
@@ -6350,17 +6390,17 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
6350
6390
  } else if (r.ownerSymIdx !== -1) {
6351
6391
  if (dLive.has(r.ownerSymIdx)) {
6352
6392
  if (obj.isDist && dropsReflection(obj, obj.symNames[r.rs])) {
6353
- zeroDataRelocOffsets.push(r.ro);
6393
+ zeroDataReloc(r);
6354
6394
  } else {
6355
6395
  keptDataRelocBytes.push(r.rawBytes);
6356
6396
  usedSyms.add(r.rs);
6357
6397
  }
6358
6398
  } else if (sName === "__objc_class_refs") {
6359
- zeroDataRelocOffsets.push(r.ro);
6399
+ zeroDataReloc(r);
6360
6400
  }
6361
6401
  } else if (sLive[r.segIdx] === 1) {
6362
6402
  if (obj.isDist && obj.symNames[r.rs]?.startsWith("l__swift5_reflection_descriptor") && dropsReflection(obj, obj.symNames[r.rs])) {
6363
- zeroDataRelocOffsets.push(r.ro);
6403
+ zeroDataReloc(r);
6364
6404
  } else {
6365
6405
  keptDataRelocBytes.push(r.rawBytes);
6366
6406
  usedSyms.add(r.rs);
@@ -6543,11 +6583,8 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
6543
6583
  outChunks.push(buf.subarray(secStart, end));
6544
6584
  }
6545
6585
  } else {
6546
- if (id === 11 && zeroDataRelocOffsets.length > 0) {
6547
- for (const ro of zeroDataRelocOffsets) {
6548
- buf.fill(0, p + ro, p + ro + 4);
6549
- }
6550
- }
6586
+ if (id === 11)
6587
+ for (const { ro, width } of zeroDataRelocs) buf.fill(0, p + ro, p + ro + width);
6551
6588
  outChunks.push(buf.subarray(secStart, end));
6552
6589
  }
6553
6590
  pos = end;
@@ -6723,7 +6760,7 @@ function readNumber(bytes, position) {
6723
6760
  let value = 0;
6724
6761
  let shift = 0;
6725
6762
  for (; ; ) {
6726
- if (position >= bytes.length || shift > 28) throw new Error("invalid wasm integer");
6763
+ if (position >= bytes.length || shift > 63) throw new Error("invalid wasm integer");
6727
6764
  const byte = bytes[position++];
6728
6765
  value += (byte & 127) * 2 ** shift;
6729
6766
  if (!(byte & 128)) return [value, position];
@@ -6770,7 +6807,7 @@ var OBJC_INIT_RECORD = ".objc_init";
6770
6807
  function rewriteObject(bytes, names, callerAlias, bindings, instrumentDynamicLookups, preserveCanonical) {
6771
6808
  if (Buffer.from(bytes.subarray(0, 8)).toString("hex") !== "0061736d01000000")
6772
6809
  throw new Error("expected wasm object");
6773
- const sections = [Buffer.from(bytes.subarray(0, 8))];
6810
+ const sections2 = [Buffer.from(bytes.subarray(0, 8))];
6774
6811
  const types = [];
6775
6812
  const functionTypes = [];
6776
6813
  const definitions = [];
@@ -6827,12 +6864,12 @@ function rewriteObject(bytes, names, callerAlias, bindings, instrumentDynamicLoo
6827
6864
  if (referenceType !== 112 && referenceType !== 111)
6828
6865
  throw new Error("unsupported table type");
6829
6866
  const flags = number3();
6830
- if (flags & ~3) throw new Error("unsupported table limits");
6867
+ if (flags & ~7) throw new Error("unsupported table limits");
6831
6868
  number3();
6832
6869
  if (flags & 1) number3();
6833
6870
  } else if (kind === 2) {
6834
6871
  const flags = number3();
6835
- if (flags & ~3) throw new Error("unsupported memory limits");
6872
+ if (flags & ~7) throw new Error("unsupported memory limits");
6836
6873
  number3();
6837
6874
  if (flags & 1) number3();
6838
6875
  } else if (kind === 3) offset += 2;
@@ -6845,7 +6882,7 @@ function rewriteObject(bytes, names, callerAlias, bindings, instrumentDynamicLoo
6845
6882
  if (module2 === "env" && names.has(name2)) usedSymbols.add(name2);
6846
6883
  if (isDlsym || isDlerror) {
6847
6884
  const type = types[functionType];
6848
- const expected = isDlsym ? "127,127:127" : ":127";
6885
+ const expected = isDlsym ? "126,126:126" : ":126";
6849
6886
  if (!type || `${type.parameters.join(",")}:${type.results.join(",")}` !== expected)
6850
6887
  throw new Error(`unexpected ${name2} import type`);
6851
6888
  }
@@ -6987,10 +7024,10 @@ function rewriteObject(bytes, names, callerAlias, bindings, instrumentDynamicLoo
6987
7024
  section = Buffer.concat(parts);
6988
7025
  }
6989
7026
  }
6990
- sections.push(Buffer.from([id]), encodeNumber(section.length), section);
7027
+ sections2.push(Buffer.from([id]), encodeNumber(section.length), section);
6991
7028
  }
6992
7029
  return {
6993
- bytes: Buffer.concat(sections),
7030
+ bytes: Buffer.concat(sections2),
6994
7031
  definitions,
6995
7032
  usesDlsym,
6996
7033
  usedSymbols: [...usedSymbols]
@@ -7157,7 +7194,7 @@ function createGuestImageLedger(input) {
7157
7194
  return [...bytes].map((byte) => `\\${byte.toString(16).padStart(2, "0")}`).join("");
7158
7195
  }).join("");
7159
7196
  const ir = [
7160
- 'target triple = "wasm32-unknown-wasip1"',
7197
+ 'target triple = "wasm64-unknown-wasip1"',
7161
7198
  `@.names = private constant [${nameSize} x i8] c"${nameContents}"`
7162
7199
  ];
7163
7200
  for (const definition of exported.values()) {
@@ -7276,8 +7313,8 @@ function selectedGuestManifestInputs(plan, selection, identities) {
7276
7313
  }
7277
7314
  function createGuestImageManifest(image) {
7278
7315
  const target = {
7279
- triple: "wasm32-unknown-wasip1",
7280
- pointerWidth: 32,
7316
+ triple: "wasm64-unknown-wasip1",
7317
+ pointerWidth: 64,
7281
7318
  byteOrder: "little",
7282
7319
  cpuType: -1,
7283
7320
  cpuSubtype: 0
@@ -7337,6 +7374,7 @@ function number2(bytes, start) {
7337
7374
  shift += 7;
7338
7375
  }
7339
7376
  }
7377
+ var constant = (opcode) => opcode === 65 || opcode === 66;
7340
7378
  function signedAddress(bytes, start) {
7341
7379
  const [value, end] = number2(bytes, start);
7342
7380
  const bits = (end - start) * 7;
@@ -7346,16 +7384,16 @@ function signedAddress(bytes, start) {
7346
7384
  function layout(bytes) {
7347
7385
  if (Buffer.from(bytes.subarray(0, 8)).toString("hex") !== "0061736d01000000")
7348
7386
  throw new Error("expected linked wasm module");
7349
- const sections = /* @__PURE__ */ new Map();
7387
+ const sections2 = /* @__PURE__ */ new Map();
7350
7388
  let offset = 8;
7351
7389
  while (offset < bytes.length) {
7352
7390
  const id = bytes[offset++];
7353
7391
  const [size, start] = number2(bytes, offset);
7354
7392
  if (start + size > bytes.length) throw new Error("invalid wasm section");
7355
- if (id) sections.set(id, [start, start + size]);
7393
+ if (id) sections2.set(id, [start, start + size]);
7356
7394
  offset = start + size;
7357
7395
  }
7358
- const exports2 = sections.get(7);
7396
+ const exports2 = sections2.get(7);
7359
7397
  if (!exports2) throw new Error("guest wasm does not export memory and table");
7360
7398
  let exportPosition = exports2[0];
7361
7399
  const readExport = () => {
@@ -7376,7 +7414,7 @@ function layout(bytes) {
7376
7414
  throw new Error("guest wasm does not export memory and table");
7377
7415
  let imports = 0;
7378
7416
  let memoryPages;
7379
- const section = sections.get(2);
7417
+ const section = sections2.get(2);
7380
7418
  if (section) {
7381
7419
  let pos = section[0];
7382
7420
  const read = () => {
@@ -7391,7 +7429,7 @@ function layout(bytes) {
7391
7429
  };
7392
7430
  const limits = () => {
7393
7431
  const flags = read();
7394
- if (flags & ~3) throw new Error("unsupported wasm limits");
7432
+ if (flags & ~7) throw new Error("unsupported wasm limits");
7395
7433
  const minimum = read();
7396
7434
  if (flags & 1) read();
7397
7435
  return minimum;
@@ -7419,7 +7457,7 @@ function layout(bytes) {
7419
7457
  }
7420
7458
  if (pos !== section[1]) throw new Error("invalid wasm imports");
7421
7459
  }
7422
- const memory = sections.get(5);
7460
+ const memory = sections2.get(5);
7423
7461
  if (memory) {
7424
7462
  let pos = memory[0];
7425
7463
  const read = () => {
@@ -7430,14 +7468,14 @@ function layout(bytes) {
7430
7468
  if (read() !== 1 || memoryPages !== void 0)
7431
7469
  throw new Error("unsupported wasm memories");
7432
7470
  const flags = read();
7433
- if (flags & ~3) throw new Error("unsupported wasm memory limits");
7471
+ if (flags & ~7) throw new Error("unsupported wasm memory limits");
7434
7472
  memoryPages = read();
7435
7473
  if (flags & 1) read();
7436
7474
  if (pos !== memory[1]) throw new Error("invalid wasm memory section");
7437
7475
  }
7438
7476
  if (memoryPages === void 0) throw new Error("guest wasm has no memory");
7439
7477
  const functionsByCodeOffset = /* @__PURE__ */ new Map();
7440
- const code = sections.get(10);
7478
+ const code = sections2.get(10);
7441
7479
  if (code) {
7442
7480
  let pos = code[0];
7443
7481
  let count;
@@ -7453,7 +7491,7 @@ function layout(bytes) {
7453
7491
  if (pos !== code[1]) throw new Error("invalid wasm code section");
7454
7492
  }
7455
7493
  const functionsByTableSlot = /* @__PURE__ */ new Map();
7456
- const elements = sections.get(9);
7494
+ const elements = sections2.get(9);
7457
7495
  if (elements) {
7458
7496
  let pos = elements[0];
7459
7497
  const read = () => {
@@ -7467,7 +7505,7 @@ function layout(bytes) {
7467
7505
  if (flags !== 0 && flags !== 2)
7468
7506
  throw new Error(`unsupported wasm element segment ${flags}`);
7469
7507
  if (flags === 2 && read() !== 0) throw new Error("unsupported wasm table index");
7470
- if (bytes[pos++] !== 65) throw new Error("nonconstant wasm table offset");
7508
+ if (!constant(bytes[pos++])) throw new Error("nonconstant wasm table offset");
7471
7509
  let base;
7472
7510
  [base, pos] = signedAddress(bytes, pos);
7473
7511
  if (bytes[pos++] !== 11) throw new Error("invalid wasm table offset");
@@ -7484,7 +7522,7 @@ function layout(bytes) {
7484
7522
  if (pos !== elements[1]) throw new Error("invalid wasm element section");
7485
7523
  }
7486
7524
  const data = [];
7487
- const dataSection = sections.get(11);
7525
+ const dataSection = sections2.get(11);
7488
7526
  if (dataSection) {
7489
7527
  let pos = dataSection[0];
7490
7528
  const read = () => {
@@ -7498,7 +7536,7 @@ function layout(bytes) {
7498
7536
  if (flags !== 0 && flags !== 2)
7499
7537
  throw new Error(`unsupported wasm data segment ${flags}`);
7500
7538
  if (flags === 2 && read() !== 0) throw new Error("unsupported wasm memory index");
7501
- if (bytes[pos++] !== 65) throw new Error("nonconstant wasm data offset");
7539
+ if (!constant(bytes[pos++])) throw new Error("nonconstant wasm data offset");
7502
7540
  let address;
7503
7541
  [address, pos] = signedAddress(bytes, pos);
7504
7542
  if (bytes[pos++] !== 11) throw new Error("invalid wasm data offset");
@@ -7620,7 +7658,7 @@ function isSwiftGuestImageManifest(value) {
7620
7658
  const text2 = (value2) => typeof value2 === "string" && value2.length > 0 && value2.length <= 4096 && !value2.includes("\0");
7621
7659
  const name2 = (value2) => text2(value2) && new TextEncoder().encode(value2).length <= 16;
7622
7660
  const version2 = (value2) => isRecord(value2) && uint(value2.major, 65535) && uint(value2.minor, 255) && uint(value2.patch, 255);
7623
- if (!isRecord(value) || value.version !== 1 || !text2(value.id) || !text2(value.installName) || value.fileType !== "executable" && value.fileType !== "dylib" || !isRecord(value.target) || value.target.triple !== "wasm32-unknown-wasip1" || value.target.pointerWidth !== 32 || value.target.byteOrder !== "little" || value.target.cpuType !== -1 || value.target.cpuSubtype !== 0 || typeof value.inputsSha256 !== "string" || !/^[a-f0-9]{64}$/.test(value.inputsSha256) || value.uuid !== value.inputsSha256.slice(0, 32) || !isRecord(value.buildVersion) || !uint(value.buildVersion.platform, 4294967295) || !version2(value.buildVersion.minimum) || !version2(value.buildVersion.sdk) || !Array.isArray(value.regions))
7661
+ if (!isRecord(value) || value.version !== 1 || !text2(value.id) || !text2(value.installName) || value.fileType !== "executable" && value.fileType !== "dylib" || !isRecord(value.target) || value.target.triple !== "wasm64-unknown-wasip1" || value.target.pointerWidth !== 64 || value.target.byteOrder !== "little" || value.target.cpuType !== -1 || value.target.cpuSubtype !== 0 || typeof value.inputsSha256 !== "string" || !/^[a-f0-9]{64}$/.test(value.inputsSha256) || value.uuid !== value.inputsSha256.slice(0, 32) || !isRecord(value.buildVersion) || !uint(value.buildVersion.platform, 4294967295) || !version2(value.buildVersion.minimum) || !version2(value.buildVersion.sdk) || !Array.isArray(value.regions))
7624
7662
  return false;
7625
7663
  return value.regions.every((region) => {
7626
7664
  if (!isRecord(region) || !name2(region.name) || region.space !== "linear-memory" && region.space !== "function-table" || !uint(region.address, 4294967295) || !uint(region.length, 4294967295) || region.address + region.length > 4294967296 || !uint(region.initialProtection, 7) || !uint(region.maximumProtection, 7) || (region.initialProtection & region.maximumProtection) !== region.initialProtection || !Array.isArray(region.sections))
@@ -9052,7 +9090,7 @@ function linkGuestImages(options) {
9052
9090
  import_node_fs13.default.writeFileSync(irPath, ledger.llvmIR);
9053
9091
  (0, import_node_child_process10.execFileSync)(
9054
9092
  clang,
9055
- ["--target=wasm32-unknown-wasip1", "-c", irPath, "-o", ledgerObject],
9093
+ ["--target=wasm64-unknown-wasip1", "-c", irPath, "-o", ledgerObject],
9056
9094
  { stdio: "pipe" }
9057
9095
  );
9058
9096
  linkedOwners.set(ledgerObject, options.ledgerDataImage);
@@ -9725,6 +9763,7 @@ function clangIrLinkOptions(ir) {
9725
9763
  }
9726
9764
  return result;
9727
9765
  }
9766
+ var CLANG_TARGET_MODULE_WRAPPER = ".peach-clang";
9728
9767
  function sourceGuestClangLinkOptions(options) {
9729
9768
  const wanted = new Set(options.objects.map((file) => import_node_path15.default.resolve(file)));
9730
9769
  const commands = /* @__PURE__ */ new Map();
@@ -9767,10 +9806,16 @@ function sourceGuestClangLinkOptions(options) {
9767
9806
  throw new Error(`unsupported source object producer ${file}`);
9768
9807
  continue;
9769
9808
  }
9770
- if (command.tool !== "clang" || !command.args.length || (0, import_node_fs14.realpathSync)(command.args[0]) !== (0, import_node_fs14.realpathSync)(import_node_path15.default.join(options.toolchainBin, "clang")))
9809
+ const compiler = command.args[0] ? (0, import_node_fs14.realpathSync)(command.args[0]) : "";
9810
+ if (command.tool !== "clang" || compiler !== (0, import_node_fs14.realpathSync)(import_node_path15.default.join(options.toolchainBin, "clang")) && compiler !== (0, import_node_fs14.realpathSync)(import_node_path15.default.join(options.buildDirectory, CLANG_TARGET_MODULE_WRAPPER)))
9771
9811
  throw new Error(`unsupported source object producer ${file}`);
9772
9812
  const args = command.args.slice(1).filter((arg) => arg !== "-c");
9773
- const output = import_node_path15.default.join(options.directory, `clang-link-${index}.ll`);
9813
+ const outputDirectory = import_node_path15.default.join(
9814
+ options.directory,
9815
+ import_node_path15.default.basename(import_node_path15.default.dirname(file))
9816
+ );
9817
+ (0, import_node_fs14.mkdirSync)(outputDirectory, { recursive: true });
9818
+ const output = import_node_path15.default.join(outputDirectory, `clang-link-${index}.ll`);
9774
9819
  for (const flag of ["-o", "-MF"]) {
9775
9820
  const index2 = args.lastIndexOf(flag);
9776
9821
  if (index2 < 0 || index2 + 1 >= args.length)
@@ -10010,8 +10055,10 @@ function logicalGuestLinkOptions(args, identities, roots) {
10010
10055
  }
10011
10056
 
10012
10057
  // src/wasm-optimize.ts
10058
+ var import_node_child_process13 = require("node:child_process");
10013
10059
  var import_node_fs16 = require("node:fs");
10014
10060
  var import_node_path18 = require("node:path");
10061
+ var import_node_util = require("node:util");
10015
10062
 
10016
10063
  // ../contrast-runtime-delivery/src/index.ts
10017
10064
  var import_node_child_process12 = require("node:child_process");
@@ -10241,8 +10288,244 @@ function rnxHomeDir() {
10241
10288
  }
10242
10289
  var DAEMON_LOCKFILE_MAX_BYTES = 16 * 1024;
10243
10290
 
10291
+ // src/wasm-narrow-boundary.ts
10292
+ var I64 = 126;
10293
+ var VALUE_TYPES = /* @__PURE__ */ new Map([
10294
+ [127, "i32"],
10295
+ [I64, "i64"],
10296
+ [125, "f32"],
10297
+ [124, "f64"],
10298
+ [123, "v128"],
10299
+ [112, "funcref"],
10300
+ [111, "externref"]
10301
+ ]);
10302
+ var GUEST = "guest";
10303
+ var BOUNDARY = "boundary";
10304
+ var WIDE = "$wide.";
10305
+ var NARROW = "$narrow.";
10306
+ function encodeNumber2(value) {
10307
+ const bytes = [];
10308
+ for (let rest = value; ; ) {
10309
+ const byte = rest % 128;
10310
+ rest = Math.floor(rest / 128);
10311
+ if (rest === 0) return [...bytes, byte];
10312
+ bytes.push(byte | 128);
10313
+ }
10314
+ }
10315
+ function encodeName(name2) {
10316
+ const bytes = [...Buffer.from(name2)];
10317
+ return [...encodeNumber2(bytes.length), ...bytes];
10318
+ }
10319
+ function reader(bytes, start, end) {
10320
+ let at = start;
10321
+ const number3 = () => {
10322
+ let value = 0;
10323
+ for (let shift = 0; ; shift += 7) {
10324
+ if (at >= end || shift > 63) throw new Error("invalid wasm integer");
10325
+ const byte = bytes[at++];
10326
+ value += (byte & 127) * 2 ** shift;
10327
+ if (!(byte & 128)) return value;
10328
+ }
10329
+ };
10330
+ return {
10331
+ number: number3,
10332
+ byte: () => {
10333
+ if (at >= end) throw new Error("truncated wasm section");
10334
+ return bytes[at++];
10335
+ },
10336
+ name: () => {
10337
+ const length = number3();
10338
+ at += length;
10339
+ if (at > end) throw new Error("truncated wasm name");
10340
+ return Buffer.from(bytes.subarray(at - length, at)).toString();
10341
+ },
10342
+ position: () => at,
10343
+ done: () => at === end
10344
+ };
10345
+ }
10346
+ function sections(bytes) {
10347
+ if (Buffer.from(bytes.subarray(0, 8)).toString("hex") !== "0061736d01000000")
10348
+ throw new Error("not a wasm module");
10349
+ const found = [];
10350
+ for (let at = 8; at < bytes.length; ) {
10351
+ const header = reader(bytes, at, bytes.length);
10352
+ const id = header.byte();
10353
+ const size = header.number();
10354
+ const start = header.position();
10355
+ found.push({ id, start, end: start + size });
10356
+ at = start + size;
10357
+ }
10358
+ return found;
10359
+ }
10360
+ function withSections(bytes, layout2, replacements) {
10361
+ const parts = [bytes.subarray(0, 8)];
10362
+ let at = 8;
10363
+ for (const section of layout2) {
10364
+ const body = replacements.get(section.id);
10365
+ parts.push(
10366
+ body ? Uint8Array.from([section.id, ...encodeNumber2(body.length), ...body]) : bytes.subarray(at, section.end)
10367
+ );
10368
+ at = section.end;
10369
+ }
10370
+ return Buffer.concat(parts);
10371
+ }
10372
+ var quoted = (name2) => `"${[...Buffer.from(name2)].map((byte) => `\\${byte.toString(16).padStart(2, "0")}`).join("")}"`;
10373
+ var signature = (types, keyword, narrow) => types.length === 0 ? "" : ` (${keyword} ${types.map((type) => {
10374
+ const name2 = VALUE_TYPES.get(narrow && type === I64 ? 127 : type);
10375
+ if (!name2) throw new Error(`unsupported wasm boundary type ${type}`);
10376
+ return name2;
10377
+ }).join(" ")})`;
10378
+ var wide = (type) => type.parameters.includes(I64) || type.results.includes(I64);
10379
+ function narrowWasmBoundary(bytes) {
10380
+ const layout2 = sections(bytes);
10381
+ const section = (id) => {
10382
+ const found = layout2.find((entry) => entry.id === id);
10383
+ return found && reader(bytes, found.start, found.end);
10384
+ };
10385
+ const types = [];
10386
+ const typeSection = section(1);
10387
+ if (typeSection) {
10388
+ for (let count = typeSection.number(); count > 0; count--) {
10389
+ if (typeSection.byte() !== 96) throw new Error("unsupported wasm type");
10390
+ const values = () => Array.from({ length: typeSection.number() }, () => typeSection.byte());
10391
+ types.push({ parameters: values(), results: values() });
10392
+ }
10393
+ }
10394
+ const typeAt = (index) => {
10395
+ const type = types[index];
10396
+ if (!type) throw new Error("invalid wasm type index");
10397
+ return type;
10398
+ };
10399
+ const thunks = [];
10400
+ const functionTypes = [];
10401
+ const importBody = [];
10402
+ const importSection = section(2);
10403
+ if (importSection) {
10404
+ const count = importSection.number();
10405
+ importBody.push(...encodeNumber2(count));
10406
+ for (let index = 0; index < count; index++) {
10407
+ const module2 = importSection.name();
10408
+ const name2 = importSection.name();
10409
+ const start = importSection.position();
10410
+ const kind = importSection.byte();
10411
+ const limits = () => {
10412
+ const flags = importSection.number();
10413
+ importSection.number();
10414
+ if (flags & 1) importSection.number();
10415
+ };
10416
+ let type;
10417
+ if (kind === 0) {
10418
+ type = typeAt(importSection.number());
10419
+ functionTypes.push(type);
10420
+ } else if (kind === 1) {
10421
+ importSection.byte();
10422
+ limits();
10423
+ } else if (kind === 2) limits();
10424
+ else if (kind === 3) {
10425
+ importSection.byte();
10426
+ importSection.byte();
10427
+ } else if (kind === 4) {
10428
+ importSection.byte();
10429
+ importSection.number();
10430
+ } else throw new Error("unsupported wasm import");
10431
+ const scalar64 = (parameter) => module2 === "wasi_snapshot_preview1" && (!name2.startsWith("peach_") || name2 === "peach_fs_path_birthtime_set" && parameter === 2) || module2 === "peach" && name2 === "hw_memsize" && parameter === null || module2 === "peach_notify" && name2 === "set" && parameter === 1;
10432
+ const parameters = type?.parameters.map(
10433
+ (value, index2) => value === I64 && !scalar64(index2) ? 127 : value
10434
+ );
10435
+ const results = type?.results.map(
10436
+ (value) => value === I64 && !scalar64(null) ? 127 : value
10437
+ );
10438
+ if (type && parameters && results && (parameters.some((value, index2) => value !== type.parameters[index2]) || results.some((value, index2) => value !== type.results[index2]))) {
10439
+ if (type.results.length > 1)
10440
+ throw new Error(`import ${module2}.${name2} returns several values`);
10441
+ const id = thunks.length;
10442
+ const call = `(call $host${id}${type.parameters.map(
10443
+ (value, at) => value !== parameters[at] ? ` (i32.wrap_i64 (local.get ${at}))` : ` (local.get ${at})`
10444
+ ).join("")})`;
10445
+ thunks.push(
10446
+ `(import ${quoted(module2)} ${quoted(name2)} (func $host${id}${signature(parameters, "param", false)}${signature(results, "result", false)}))`,
10447
+ `(func (export "${NARROW}${id}")${signature(type.parameters, "param", false)}${signature(type.results, "result", false)} ${type.results[0] !== results[0] ? `(i64.extend_i32_u ${call})` : call})`
10448
+ );
10449
+ importBody.push(...encodeName(BOUNDARY), ...encodeName(`${NARROW}${id}`));
10450
+ } else importBody.push(...encodeName(module2), ...encodeName(name2));
10451
+ importBody.push(...bytes.subarray(start, importSection.position()));
10452
+ }
10453
+ if (!importSection.done()) throw new Error("invalid wasm imports");
10454
+ }
10455
+ const functionSection = section(3);
10456
+ if (functionSection)
10457
+ for (let count = functionSection.number(); count > 0; count--)
10458
+ functionTypes.push(typeAt(functionSection.number()));
10459
+ const exportBody = [];
10460
+ const exportSection = section(7);
10461
+ if (exportSection) {
10462
+ const count = exportSection.number();
10463
+ exportBody.push(...encodeNumber2(count));
10464
+ for (let index = 0; index < count; index++) {
10465
+ const name2 = exportSection.name();
10466
+ const kind = exportSection.byte();
10467
+ const target = exportSection.number();
10468
+ const type = kind === 0 ? functionTypes[target] : void 0;
10469
+ if (kind === 0 && !type) throw new Error("invalid wasm export");
10470
+ if (type && wide(type)) {
10471
+ if (type.results.length > 1)
10472
+ throw new Error(`export ${name2} returns several values`);
10473
+ const id = thunks.length;
10474
+ const call = `(call $guest${id}${type.parameters.map(
10475
+ (value, at) => value === I64 ? ` (i64.extend_i32_u (local.get ${at}))` : ` (local.get ${at})`
10476
+ ).join("")})`;
10477
+ thunks.push(
10478
+ `(import "${GUEST}" "${WIDE}${id}" (func $guest${id}${signature(type.parameters, "param", false)}${signature(type.results, "result", false)}))`,
10479
+ `(func (export ${quoted(name2)})${signature(type.parameters, "param", true)}${signature(type.results, "result", true)} ${type.results[0] === I64 ? `(i32.wrap_i64 ${call})` : call})`
10480
+ );
10481
+ exportBody.push(...encodeName(`${WIDE}${id}`));
10482
+ } else exportBody.push(...encodeName(name2));
10483
+ exportBody.push(kind, ...encodeNumber2(target));
10484
+ }
10485
+ if (!exportSection.done()) throw new Error("invalid wasm exports");
10486
+ }
10487
+ if (thunks.length === 0) return void 0;
10488
+ const imports = thunks.filter((line) => line.startsWith("(import"));
10489
+ const functions = thunks.filter((line) => !line.startsWith("(import"));
10490
+ return {
10491
+ module: withSections(
10492
+ bytes,
10493
+ layout2,
10494
+ /* @__PURE__ */ new Map([
10495
+ [2, importBody],
10496
+ [7, exportBody]
10497
+ ])
10498
+ ),
10499
+ thunks: `(module
10500
+ ${[...imports, ...functions].join("\n")}
10501
+ )
10502
+ `
10503
+ };
10504
+ }
10505
+ var NARROW_MERGE_NAMES = { guest: GUEST, boundary: BOUNDARY };
10506
+ function dropBoundaryExports(bytes) {
10507
+ const layout2 = sections(bytes);
10508
+ const found = layout2.find((entry) => entry.id === 7);
10509
+ if (!found) throw new Error("merged module has no exports");
10510
+ const exportSection = reader(bytes, found.start, found.end);
10511
+ const kept = [];
10512
+ for (let count = exportSection.number(); count > 0; count--) {
10513
+ const name2 = exportSection.name();
10514
+ const kind = exportSection.byte();
10515
+ const target = exportSection.number();
10516
+ if (!name2.startsWith(WIDE) && !name2.startsWith(NARROW))
10517
+ kept.push([...encodeName(name2), kind, ...encodeNumber2(target)]);
10518
+ }
10519
+ return withSections(
10520
+ bytes,
10521
+ layout2,
10522
+ /* @__PURE__ */ new Map([[7, [...encodeNumber2(kept.length), ...kept.flat()]]])
10523
+ );
10524
+ }
10525
+
10244
10526
  // src/wasm-optimize.ts
10245
10527
  var FEATURES = [
10528
+ "memory64",
10246
10529
  "threads",
10247
10530
  "bulk-memory",
10248
10531
  "bulk-memory-opt",
@@ -10255,7 +10538,8 @@ var FEATURES = [
10255
10538
  "sign-ext"
10256
10539
  ];
10257
10540
  var KEEP_WASM_NAMES = process.env.PEACH_SWIFT_NAMES === "1";
10258
- var WASM_OPTIMIZE_IDENTITY = `wasm-opt ${import_wasm_opt.BINARYEN_VERSION} -Oz ${FEATURES.join(",")}${KEEP_WASM_NAMES ? " -g" : ""}`;
10541
+ var LOWERING = ["--memory64-lowering", "--table64-lowering"];
10542
+ var WASM_LOWER_IDENTITY = `binaryen ${import_wasm_opt.BINARYEN_VERSION} narrow ${LOWERING.join(" ")} ${FEATURES.join(",")} unoptimized-names`;
10259
10543
  var PINNED_BINARYEN_VERSION = "132";
10260
10544
  var BINARYEN_RELEASES = /* @__PURE__ */ new Map([
10261
10545
  [
@@ -10280,7 +10564,7 @@ var BINARYEN_RELEASES = /* @__PURE__ */ new Map([
10280
10564
  }
10281
10565
  ]
10282
10566
  ]);
10283
- async function runWasmOpt(file, output, skipPasses, binary) {
10567
+ async function runWasmOpt(file, output, optimize, skipPasses, binary) {
10284
10568
  const admittedCores = windowAdmission()?.cores ?? Number(process.env.TM_EXEC_CPU_CORES);
10285
10569
  const requestedCores = Number(process.env.BINARYEN_CORES);
10286
10570
  const environment = { ...process.env, WASM_OPT_PATH: binary };
@@ -10288,18 +10572,43 @@ async function runWasmOpt(file, output, skipPasses, binary) {
10288
10572
  environment.BINARYEN_CORES = String(
10289
10573
  Number.isInteger(requestedCores) && requestedCores > 0 ? Math.min(admittedCores, requestedCores) : admittedCores
10290
10574
  );
10575
+ const features = FEATURES.map((feature) => `--enable-${feature}`);
10576
+ const names = optimize && !KEEP_WASM_NAMES ? [] : ["-g"];
10577
+ const narrowed = narrowWasmBoundary((0, import_node_fs16.readFileSync)(file));
10578
+ const merged = `${output}.narrowed`;
10579
+ if (narrowed) {
10580
+ const guest = `${output}.guest`;
10581
+ const thunks = `${output}.thunks.wat`;
10582
+ (0, import_node_fs16.writeFileSync)(guest, narrowed.module);
10583
+ (0, import_node_fs16.writeFileSync)(thunks, narrowed.thunks);
10584
+ await (0, import_node_util.promisify)(import_node_child_process13.execFile)((0, import_node_path18.join)((0, import_node_path18.dirname)(binary), "wasm-merge"), [
10585
+ ...features,
10586
+ ...names,
10587
+ guest,
10588
+ NARROW_MERGE_NAMES.guest,
10589
+ thunks,
10590
+ NARROW_MERGE_NAMES.boundary,
10591
+ "-o",
10592
+ merged
10593
+ ]);
10594
+ (0, import_node_fs16.writeFileSync)(merged, dropBoundaryExports((0, import_node_fs16.readFileSync)(merged)));
10595
+ (0, import_node_fs16.rmSync)(guest);
10596
+ (0, import_node_fs16.rmSync)(thunks);
10597
+ }
10291
10598
  const result = await (0, import_wasm_opt.wasmOpt)(
10292
10599
  [
10293
- "-Oz",
10294
- ...KEEP_WASM_NAMES ? ["-g"] : [],
10600
+ ...LOWERING,
10601
+ ...optimize ? ["-Oz"] : [],
10602
+ ...names,
10295
10603
  ...skipPasses.flatMap((pass) => ["--skip-pass", pass]),
10296
- ...FEATURES.map((feature) => `--enable-${feature}`),
10297
- file,
10604
+ ...features,
10605
+ narrowed ? merged : file,
10298
10606
  "-o",
10299
10607
  output
10300
10608
  ],
10301
10609
  { env: environment }
10302
10610
  );
10611
+ if (narrowed) (0, import_node_fs16.rmSync)(merged);
10303
10612
  if (result.status !== 0)
10304
10613
  throw new Error(`wasm-opt exited ${result.status}: ${result.stderr}`);
10305
10614
  }
@@ -10322,8 +10631,14 @@ async function installWasmOpt() {
10322
10631
  });
10323
10632
  return binary;
10324
10633
  }
10325
- async function optimizeWasm(file, output, skipPasses = []) {
10326
- await runWasmOpt(file, output, skipPasses, await installWasmOpt());
10634
+ async function lowerWasm(file, output, options) {
10635
+ await runWasmOpt(
10636
+ file,
10637
+ output,
10638
+ options.optimize,
10639
+ options.skipPasses ?? [],
10640
+ await installWasmOpt()
10641
+ );
10327
10642
  }
10328
10643
 
10329
10644
  // src/swift-guest-compile.ts
@@ -10357,7 +10672,7 @@ async function compileGuestLink(options) {
10357
10672
  };
10358
10673
  const buildVersion = imageBuildVersion(entry.buildVersion);
10359
10674
  const clangOptions = [
10360
- "--target=wasm32-unknown-wasip1",
10675
+ "--target=wasm64-unknown-wasip1",
10361
10676
  `--sysroot=${options.sysroot}`,
10362
10677
  `-I${import_node_path19.default.join(options.moduleRoot, "include")}`
10363
10678
  ];
@@ -10367,7 +10682,7 @@ async function compileGuestLink(options) {
10367
10682
  stubSource,
10368
10683
  '#include "guest-image-projection.h"\nconst struct peach_guest_image __peach_guest_images[] = {{0}};\nconst uint32_t __peach_guest_image_count = 0;\n'
10369
10684
  );
10370
- (0, import_node_child_process13.execFileSync)(
10685
+ (0, import_node_child_process14.execFileSync)(
10371
10686
  import_node_path19.default.join(options.toolchainBin, "clang"),
10372
10687
  [...clangOptions, "-c", stubSource, "-o", stub],
10373
10688
  { stdio: "pipe" }
@@ -10665,9 +10980,10 @@ async function compileGuestLink(options) {
10665
10980
  }
10666
10981
  });
10667
10982
  if (!reserved || !projectionObject) throw new Error("guest projection was not reserved");
10668
- await optimizeWasm(options.output, options.optimized, [
10669
- "duplicate-function-elimination"
10670
- ]);
10983
+ await lowerWasm(options.output, options.optimized, {
10984
+ optimize: true,
10985
+ skipPasses: ["duplicate-function-elimination"]
10986
+ });
10671
10987
  const map = (0, import_node_fs17.readFileSync)(result.mapPath, "utf8");
10672
10988
  if (!/ __peach_guest_images$/m.test(map)) return;
10673
10989
  const finalized = finalizeGuestProjectionStorage({
@@ -10683,13 +10999,13 @@ async function compileGuestLink(options) {
10683
10999
  }
10684
11000
 
10685
11001
  // src/swift-icu.ts
10686
- var import_node_child_process14 = require("node:child_process");
11002
+ var import_node_child_process15 = require("node:child_process");
10687
11003
  var import_node_crypto11 = require("node:crypto");
10688
11004
  var import_node_fs18 = require("node:fs");
10689
11005
  var import_promises4 = require("node:fs/promises");
10690
11006
  var import_node_os8 = __toESM(require("node:os"), 1);
10691
11007
  var import_node_path20 = __toESM(require("node:path"), 1);
10692
- var import_node_util = require("node:util");
11008
+ var import_node_util2 = require("node:util");
10693
11009
  var import_node_zlib2 = require("node:zlib");
10694
11010
 
10695
11011
  // ../sootsim-swift/src/icuData.ts
@@ -10747,10 +11063,10 @@ function swiftIcuPack(blob, deflate2) {
10747
11063
  }
10748
11064
 
10749
11065
  // src/swift-icu.ts
10750
- var run = (0, import_node_util.promisify)(import_node_child_process14.execFile);
10751
- var deflate = (0, import_node_util.promisify)(import_node_zlib2.gzip);
10752
- var compressBrotli = (0, import_node_util.promisify)(import_node_zlib2.brotliCompress);
10753
- var inflateGzip = (0, import_node_util.promisify)(import_node_zlib2.gunzip);
11066
+ var run = (0, import_node_util2.promisify)(import_node_child_process15.execFile);
11067
+ var deflate = (0, import_node_util2.promisify)(import_node_zlib2.gzip);
11068
+ var compressBrotli = (0, import_node_util2.promisify)(import_node_zlib2.brotliCompress);
11069
+ var inflateGzip = (0, import_node_util2.promisify)(import_node_zlib2.gunzip);
10754
11070
  var ARCHIVE = "wasi/lib_FoundationICU.a";
10755
11071
  var MEMBER = "icu_packaged_data.cpp.obj";
10756
11072
  var raw = /* @__PURE__ */ new Map();
@@ -10831,7 +11147,7 @@ async function load(toolchainBin, sdk) {
10831
11147
  ...swiftSdkOptions(),
10832
11148
  "--show-configuration",
10833
11149
  sdk,
10834
- "wasm32-unknown-wasip1"
11150
+ "wasm64-unknown-wasip1"
10835
11151
  ],
10836
11152
  { env: swiftEnvironment() }
10837
11153
  );
@@ -11079,7 +11395,7 @@ function swiftObjCModuleMap(module2, headers, submodules = /* @__PURE__ */ new S
11079
11395
  }
11080
11396
 
11081
11397
  // src/swift-project-user.ts
11082
- var import_node_child_process15 = require("node:child_process");
11398
+ var import_node_child_process16 = require("node:child_process");
11083
11399
  var import_node_fs20 = require("node:fs");
11084
11400
  var import_node_path22 = __toESM(require("node:path"), 1);
11085
11401
  function prepareSwiftProjectProcess(root, user) {
@@ -11090,7 +11406,7 @@ function prepareSwiftProjectProcess(root, user) {
11090
11406
  (0, import_node_fs20.mkdirSync)(tmp, { recursive: true });
11091
11407
  const caches = ["cache", "config", "security"].map((name2) => import_node_path22.default.join(swiftpm, name2));
11092
11408
  for (const directory of caches) (0, import_node_fs20.mkdirSync)(directory, { recursive: true });
11093
- (0, import_node_child_process15.execFileSync)("chown", ["-R", "-P", `${user.uid}:${user.gid}`, root, home]);
11409
+ (0, import_node_child_process16.execFileSync)("chown", ["-R", "-P", `${user.uid}:${user.gid}`, root, home]);
11094
11410
  (0, import_node_fs20.chmodSync)(root, 448);
11095
11411
  (0, import_node_fs20.chmodSync)(home, 448);
11096
11412
  return {
@@ -11113,7 +11429,7 @@ function prepareSwiftProjectProcess(root, user) {
11113
11429
  };
11114
11430
  }
11115
11431
  function endSwiftProjectProcesses(user) {
11116
- (0, import_node_child_process15.execFileSync)("sh", ["-c", "kill -s KILL -- -1 2>/dev/null || true"], {
11432
+ (0, import_node_child_process16.execFileSync)("sh", ["-c", "kill -s KILL -- -1 2>/dev/null || true"], {
11117
11433
  uid: user.uid,
11118
11434
  gid: user.gid
11119
11435
  });
@@ -11160,7 +11476,7 @@ function swiftReproducibleBuildFlags(roots) {
11160
11476
  }
11161
11477
 
11162
11478
  // src/swift-root-lock.ts
11163
- var import_node_child_process16 = require("node:child_process");
11479
+ var import_node_child_process17 = require("node:child_process");
11164
11480
  var import_node_crypto12 = require("node:crypto");
11165
11481
  var import_node_fs22 = require("node:fs");
11166
11482
  var import_node_os10 = require("node:os");
@@ -11326,7 +11642,7 @@ async function withSwiftRootLock(root, work, signal, wait = true) {
11326
11642
  }
11327
11643
  },
11328
11644
  spawn(command, args, options, companion) {
11329
- const child = (0, import_node_child_process16.spawn)(
11645
+ const child = (0, import_node_child_process17.spawn)(
11330
11646
  "/bin/sh",
11331
11647
  ["-c", 'IFS= read -r go || exit 1; exec "$@" </dev/null', "sh", command, ...args],
11332
11648
  { ...options, detached: true, stdio: ["pipe", "pipe", "pipe"] }
@@ -11358,15 +11674,15 @@ async function withSwiftRootLock(root, work, signal, wait = true) {
11358
11674
  }
11359
11675
 
11360
11676
  // src/swift-uniform-type-constants.ts
11361
- var import_node_child_process17 = require("node:child_process");
11677
+ var import_node_child_process18 = require("node:child_process");
11362
11678
  var import_node_path24 = __toESM(require("node:path"), 1);
11363
11679
  function compileUniformTypeConstants(args) {
11364
11680
  const source = import_node_path24.default.join(args.packageRoot, "runtime/UniformTypeIdentifiersConstants.m");
11365
11681
  const object3 = import_node_path24.default.join(args.out, "UniformTypeIdentifiers-NativeConstants.o");
11366
- (0, import_node_child_process17.execFileSync)(
11682
+ (0, import_node_child_process18.execFileSync)(
11367
11683
  import_node_path24.default.join(args.bin, "clang"),
11368
11684
  [
11369
- "--target=wasm32-unknown-wasip1",
11685
+ "--target=wasm64-unknown-wasip1",
11370
11686
  `--sysroot=${args.sysroot}`,
11371
11687
  "-Oz",
11372
11688
  "-g0",
@@ -11665,7 +11981,7 @@ async function runCompiler(command, args, options, stream = false, quiet) {
11665
11981
  detached: true,
11666
11982
  stdio: ["ignore", "pipe", "pipe"]
11667
11983
  };
11668
- const child = options.lease ? options.lease.spawn(command, args, launch, options.frameworkLease) : (0, import_node_child_process18.spawn)(command, args, launch);
11984
+ const child = options.lease ? options.lease.spawn(command, args, launch, options.frameworkLease) : (0, import_node_child_process19.spawn)(command, args, launch);
11669
11985
  let stopping;
11670
11986
  try {
11671
11987
  return await new Promise((resolve, reject) => {
@@ -11739,7 +12055,7 @@ async function runCompiler(command, args, options, stream = false, quiet) {
11739
12055
  await stopping;
11740
12056
  }
11741
12057
  }
11742
- var WASM_TRIPLE = "wasm32-unknown-wasip1";
12058
+ var WASM_TRIPLE = "wasm64-unknown-wasip1";
11743
12059
  var SWIFTPM_PROGRESS = /^\[\d+\/\d+\] /;
11744
12060
  var SWIFTPM_NOISE = /^(?:\[\d+\/\d+\] |Building for production\.\.\.$|warning: '--build-system native' has been deprecated)/;
11745
12061
  function swiftBuildJobs() {
@@ -11790,6 +12106,20 @@ var clangInterfaceHeader = (header) => header.replace(/^@import (?:UIKitCore|UIK
11790
12106
  /^@import (?:CoreFoundation|FoundationNetworking);$/gm,
11791
12107
  "@import Foundation;"
11792
12108
  ).replace(/\b_TtC10Foundation\d+(NS\w+)\b/g, "$1").replace(/\b__attribute__\(\(objc_subclassing_restricted\)\)\s*/g, "");
12109
+ function swiftHeaderWithSuperclassImports(header, interfaceFor) {
12110
+ const superclasses = new Set(
12111
+ [...header.matchAll(/@interface\s+\w+\s*:\s*(\w+)/g)].map((match) => match[1])
12112
+ );
12113
+ return header.replace(/^@import (\w+);$/gm, (statement, name2) => {
12114
+ const dependency = interfaceFor(name2);
12115
+ if (!dependency || ![...swiftInterfaceDeclarations(dependency.header)].some(
12116
+ (name3) => superclasses.has(name3)
12117
+ ))
12118
+ return statement;
12119
+ return `${statement}
12120
+ #import ${JSON.stringify(dependency.file)}`;
12121
+ });
12122
+ }
11793
12123
  var swiftInterfaceDeclarations = (header) => /* @__PURE__ */ new Set([
11794
12124
  ...[
11795
12125
  ...header.matchAll(
@@ -12147,7 +12477,7 @@ var OPTIONAL_FRAMEWORKS = new Set(Object.keys(OPTIONAL_FRAMEWORK_DEPENDENCIES));
12147
12477
  function swiftOptionalFramework(name2) {
12148
12478
  return OPTIONAL_FRAMEWORKS.has(name2);
12149
12479
  }
12150
- var SWIFT_IMPORT = /^\s*(?:@\w+(?:\([^)]*\))?\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?([A-Za-z_][A-Za-z0-9_]*)/;
12480
+ var SWIFT_IMPORT = /^\s*(?:@\w+(?:\([^)]*\))?\s+|(?:public|package|internal|fileprivate|private)\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?([A-Za-z_][A-Za-z0-9_]*)/;
12151
12481
  var kleeneNot = (value) => value === void 0 ? void 0 : !value;
12152
12482
  var kleeneAnd = (left, right) => left === false || right === false ? false : left === true && right === true ? true : void 0;
12153
12483
  var kleeneOr = (left, right) => left === true || right === true ? true : left === false && right === false ? false : void 0;
@@ -12167,10 +12497,11 @@ function swiftCondition(text2, available) {
12167
12497
  const call = /^(\w+)\s*\(\s*([^,()]*?)\s*(?:,[^()]*)?\)$/.exec(token ?? "");
12168
12498
  if (!call) return void 0;
12169
12499
  const [, name2, argument] = call;
12170
- if (name2 === "os") return argument === "iOS" || argument === "WASI";
12171
- if (name2 === "canImport") return available?.has(argument);
12500
+ if (name2 === "os") return argument === "iOS";
12501
+ if (name2 === "canImport")
12502
+ return argument !== "FoundationNetworking" && available?.has(argument);
12172
12503
  if (name2 === "targetEnvironment") return argument === "simulator";
12173
- if (name2 === "arch") return argument === "wasm32";
12504
+ if (name2 === "arch") return argument === "wasm64";
12174
12505
  return void 0;
12175
12506
  };
12176
12507
  const both = () => {
@@ -12239,7 +12570,7 @@ function swiftSdkPaths(moduleRoot, toolchainBin) {
12239
12570
  const key = JSON.stringify([toolchainBin, sdk, options]);
12240
12571
  const cached = sdkPaths.get(key);
12241
12572
  if (cached) return cached;
12242
- const configuration = (0, import_node_child_process18.execFileSync)(
12573
+ const configuration = (0, import_node_child_process19.execFileSync)(
12243
12574
  import_node_path27.default.join(toolchainBin, "swift"),
12244
12575
  [
12245
12576
  "sdk",
@@ -12247,7 +12578,7 @@ function swiftSdkPaths(moduleRoot, toolchainBin) {
12247
12578
  ...options,
12248
12579
  "--show-configuration",
12249
12580
  sdk,
12250
- "wasm32-unknown-wasip1"
12581
+ "wasm64-unknown-wasip1"
12251
12582
  ],
12252
12583
  { encoding: "utf8", env: swiftEnvironment(), stdio: ["ignore", "pipe", "pipe"] }
12253
12584
  );
@@ -12620,6 +12951,14 @@ var FOUNDATION_IMPLICIT_MODULES = [
12620
12951
  "PeachFoundationCombine",
12621
12952
  "Darwin"
12622
12953
  ];
12954
+ var PRECONCURRENCY_FOUNDATION_IMPORT = /^[ \t]*@preconcurrency[ \t]+(?:(?:public|package|internal|fileprivate|private)[ \t]+)?import[ \t]+(?:Foundation|UIKit|SwiftUI)[ \t]*(?:\/\/.*)?$/m;
12955
+ function withPreconcurrencyFoundationModules(source) {
12956
+ if (!PRECONCURRENCY_FOUNDATION_IMPORT.test(source)) return source;
12957
+ return `${source}${source.endsWith("\n") ? "" : "\n"}#if canImport(PeachObjC)
12958
+ ${["ObjectiveC", ...FOUNDATION_IMPLICIT_MODULES].map((module2) => `@preconcurrency import ${module2}
12959
+ `).join("")}#endif
12960
+ `;
12961
+ }
12623
12962
  var FOUNDATION_IMPLICIT_FLAGS = FOUNDATION_IMPLICIT_MODULES.map(
12624
12963
  (module2) => `, "-Xfrontend", "-import-module", "-Xfrontend", "${module2}"`
12625
12964
  ).join("");
@@ -12635,11 +12974,11 @@ var executableLinkFlags = (root) => ` "-Xclang-linker", "-O0",
12635
12974
  "-Xlinker", "--wrap=swift_udata_open",
12636
12975
  "-Xlinker", "--wrap=swift_udata_openChoice",
12637
12976
  `;
12638
- var darwinRecordsRegion = (quoted) => quoted.length ? ["-Wl,--start-lib", ...quoted, "-Wl,--end-lib"] : [];
12977
+ var darwinRecordsRegion = (quoted2) => quoted2.length ? ["-Wl,--start-lib", ...quoted2, "-Wl,--end-lib"] : [];
12639
12978
  var REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
12640
12979
  var MULTI_MANIFEST_VERSION = 68;
12641
12980
  var SWIFT_HEADER_PRODUCTS_TARGET = "PeachHeaderProducts";
12642
- var compilerSourceDigest = true ? "ae9e08389e6ab1901846342a7b347d7c10f8074172cf5d4d6505f7e955879ad4" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
12981
+ var compilerSourceDigest = true ? "280e858b01b1c1393d3765c8d6ff1b3ce4a1a93d7fb7e3dd2d4d3e5f1d5f1ac2" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
12643
12982
  function swiftArtifactHash(input, release, moduleRoot) {
12644
12983
  const hash = (0, import_node_crypto13.createHash)("sha256");
12645
12984
  hash.update(`swift-compile
@@ -12649,9 +12988,10 @@ ${release}
12649
12988
  if (input.oneModule) hash.update("one-module\n");
12650
12989
  if (KEEP_WASM_NAMES) hash.update("names\n");
12651
12990
  hash.update(swiftModuleDigest(moduleRoot));
12652
- if (input.optimize) hash.update(`optimize
12653
- ${WASM_OPTIMIZE_IDENTITY}
12991
+ hash.update(`lower
12992
+ ${WASM_LOWER_IDENTITY}
12654
12993
  `);
12994
+ if (input.optimize) hash.update("optimize\n");
12655
12995
  for (const file of Object.keys(input.files).sort()) {
12656
12996
  hash.update((0, import_node_crypto13.createHash)("sha256").update(file).digest());
12657
12997
  hash.update((0, import_node_crypto13.createHash)("sha256").update(input.files[file]).digest());
@@ -12761,6 +13101,7 @@ function toolsetOrdersLibcxxBeforeDarwinOverlay(options) {
12761
13101
  const overlay = options.indexOf("=/darwin/wasm/include");
12762
13102
  return libcxx >= 0 && overlay > libcxx;
12763
13103
  }
13104
+ var SWIFTPM_DEFAULT_IOS_DEPLOYMENT_TARGET = "12.0";
12764
13105
  function emitSwiftPackageManifest(args) {
12765
13106
  const {
12766
13107
  targets,
@@ -12826,7 +13167,7 @@ function emitSwiftPackageManifest(args) {
12826
13167
  (name2) => !object3.startsWith(`lib/${name2}-`) || reachedFrameworks.has(name2)
12827
13168
  )
12828
13169
  );
12829
- const quoted = (object3) => `"${import_node_path27.default.join(moduleRoot, object3).replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
13170
+ const quoted2 = (object3) => `"${import_node_path27.default.join(moduleRoot, object3).replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
12830
13171
  const categoryObjects = new Set(
12831
13172
  foundationCategoryObjects.map((name2) => `lib/Foundation-${name2}.o`)
12832
13173
  );
@@ -12835,11 +13176,11 @@ function emitSwiftPackageManifest(args) {
12835
13176
  objects.filter((object3) => roots.has(object3) || categoryObjects.has(object3))
12836
13177
  );
12837
13178
  const list = [
12838
- ...[...eager].map(quoted),
13179
+ ...[...eager].map(quoted2),
12839
13180
  "-Wl,--start-lib",
12840
- ...available.filter((object3) => !eager.has(object3)).map(quoted),
13181
+ ...available.filter((object3) => !eager.has(object3)).map(quoted2),
12841
13182
  "-Wl,--end-lib",
12842
- ...darwinRecordsRegion(distribution.objects.filter(isProvider).map(quoted))
13183
+ ...darwinRecordsRegion(distribution.objects.filter(isProvider).map(quoted2))
12843
13184
  ].join("\n") + "\n";
12844
13185
  distributionLinkPath = distributionLink.path.replace(
12845
13186
  /\.rsp$/,
@@ -12961,7 +13302,8 @@ function emitSwiftPackageManifest(args) {
12961
13302
  (value) => value.late?.producers.includes(target.name)
12962
13303
  )) ? `, "-emit-objc-header-path", ${JSON.stringify(import_node_path27.default.join(args.headerDirectory, `${target.name}-Swift${args.nativeHeaderDeclarations?.[target.name] ? ".original" : ""}.h`))}` : "";
12963
13304
  const clangMode = target.cxxInterop ? "" : ', "-Xcc", "-fno-cxx-modules"';
12964
- const swiftSettings = `swiftSettings: [.swiftLanguageMode(.v${target.languageMode}),${isolation}${interoperability}${defines}${features}${upcoming} .unsafeFlags(${swiftFlagArray(`["-Osize", "-Xfrontend", "-enable-cross-import-overlays"${overlayFlags}${FOUNDATION_IMPLICIT_FLAGS}${oneModule ? ONE_IMPLICIT_FLAGS : ""}${imports}${nativeImportFlags}${objcFlags}${header}${clangMode}${upstream}]`)})]`;
13305
+ const deployment = `, "-Xfrontend", "-peach-ios-deployment-target", "-Xfrontend", ${JSON.stringify(target.iosDeploymentTarget ?? SWIFTPM_DEFAULT_IOS_DEPLOYMENT_TARGET)}`;
13306
+ const swiftSettings = `swiftSettings: [.swiftLanguageMode(.v${target.languageMode}),${isolation}${interoperability}${defines}${features}${upcoming} .unsafeFlags(${swiftFlagArray(`["-Osize", "-Xfrontend", "-enable-cross-import-overlays"${overlayFlags}${FOUNDATION_IMPLICIT_FLAGS}${oneModule ? ONE_IMPLICIT_FLAGS : ""}${imports}${nativeImportFlags}${objcFlags}${header}${clangMode}${deployment}${upstream}]`)})]`;
12965
13307
  const deps = [
12966
13308
  .../* @__PURE__ */ new Set([
12967
13309
  ...(target.dependencies ?? []).flatMap(
@@ -13146,6 +13488,7 @@ function syncSwiftTree(base, files) {
13146
13488
  }
13147
13489
  var DIRECTIVE = /^[ \t]*#(?:if|elseif)\b/;
13148
13490
  var OS_IOS = /\b(?:os\(\s*iOS\s*\)|targetEnvironment\(\s*simulator\s*\))/g;
13491
+ var NOT_ON_IOS = /\b(?:os\(\s*WASI\s*\)|canImport\(\s*FoundationNetworking\s*\))/g;
13149
13492
  var DELEGATE_CLASS = /^class\s+[A-Za-z_]\w*\s*(?:<[^>{]*>)?\s*:[^{]*\b(?:UIApplicationDelegate|UISceneDelegate|UIWindowSceneDelegate)\b[^{]*\{/;
13150
13493
  function compiledSwiftSources(files, targets, overlayFrameworks) {
13151
13494
  const ordered = [...targets].sort((a, b) => b.path.length - a.path.length);
@@ -13160,14 +13503,14 @@ function compiledSwiftSources(files, targets, overlayFrameworks) {
13160
13503
  );
13161
13504
  });
13162
13505
  const manifest = /(?:^|\/)Package(?:@swift-[\d.]+)?\.swift$/.test(file);
13163
- return [
13164
- file,
13165
- manifest && (!owner || /^Package(?:@swift-[\d.]+)?\.swift$/.test(file)) ? source : swiftSourceAsIOS(
13166
- source,
13167
- overlayFrameworks,
13168
- owner?.defines?.includes(SWIFT_XCODE_BUILD_CONDITION) && !owner.defines.includes("SWIFT_PACKAGE") ? false : void 0
13169
- )
13170
- ];
13506
+ if (manifest && (!owner || /^Package(?:@swift-[\d.]+)?\.swift$/.test(file)))
13507
+ return [file, source];
13508
+ const ios = swiftSourceAsIOS(
13509
+ source,
13510
+ overlayFrameworks,
13511
+ owner?.defines?.includes(SWIFT_XCODE_BUILD_CONDITION) && !owner.defines.includes("SWIFT_PACKAGE") ? false : void 0
13512
+ );
13513
+ return [file, withPreconcurrencyFoundationModules(ios)];
13171
13514
  })
13172
13515
  );
13173
13516
  }
@@ -13818,16 +14161,22 @@ function foundationOwnerOf(name2) {
13818
14161
  return "PeachFoundation";
13819
14162
  return void 0;
13820
14163
  }
13821
- function swiftSourceAsIOS(source, overlayFrameworks, swiftPackage) {
13822
- const { lineStarts, tokens } = swiftCodeScan(source);
14164
+ function swiftPackageSourceAsIOS(source) {
14165
+ return swiftConditionsAsIOS(source, swiftCodeScan(source).lineStarts);
14166
+ }
14167
+ function swiftConditionsAsIOS(source, lineStarts, swiftPackage) {
13823
14168
  let offset = 0;
13824
- const conditioned = source.split("\n").map((line) => {
14169
+ return source.split("\n").map((line) => {
13825
14170
  const start = offset;
13826
14171
  offset += line.length + 1;
13827
14172
  if (!lineStarts.has(start) || !DIRECTIVE.test(line)) return line;
13828
- const platform = line.replace(OS_IOS, (match) => "true".padEnd(match.length));
14173
+ const platform = line.replace(OS_IOS, (match) => "true".padEnd(match.length)).replace(NOT_ON_IOS, (match) => "false".padEnd(match.length));
13829
14174
  return swiftPackage === false ? platform.replace(/\bSWIFT_PACKAGE\b/g, (match) => "false".padEnd(match.length)) : platform;
13830
14175
  }).join("\n");
14176
+ }
14177
+ function swiftSourceAsIOS(source, overlayFrameworks, swiftPackage) {
14178
+ const { lineStarts, tokens } = swiftCodeScan(source);
14179
+ const conditioned = swiftConditionsAsIOS(source, lineStarts, swiftPackage);
13831
14180
  let out = "";
13832
14181
  let copied = 0;
13833
14182
  const sceneLifecycleBodies = /* @__PURE__ */ new Set();
@@ -14284,7 +14633,7 @@ var wasmMacroEnvironment = {
14284
14633
  ...emptyMacroEnvironment,
14285
14634
  defines: /* @__PURE__ */ new Map([
14286
14635
  ["__wasm__", "1"],
14287
- ["__wasm32__", "1"],
14636
+ ["__wasm64__", "1"],
14288
14637
  ["__wasi__", "1"]
14289
14638
  ])
14290
14639
  };
@@ -15777,8 +16126,15 @@ module ${moduleName}.Swift {
15777
16126
  }) + moduleFiles
15778
16127
  );
15779
16128
  }
15780
- for (const [file, bytes] of Object.entries(input.packageFiles ?? {}))
15781
- files.set(import_node_path27.default.join(layout2.root, file), Buffer.from(bytes, "base64"));
16129
+ for (const [file, bytes] of Object.entries(input.packageFiles ?? {})) {
16130
+ const contents = Buffer.from(bytes, "base64");
16131
+ files.set(
16132
+ import_node_path27.default.join(layout2.root, file),
16133
+ file.endsWith(".swift") && !/(?:^|\/)Package(?:@swift-[\d.]+)?\.swift$/.test(file) ? withPreconcurrencyFoundationModules(
16134
+ swiftPackageSourceAsIOS(contents.toString("utf8"))
16135
+ ) : contents
16136
+ );
16137
+ }
15782
16138
  for (const [file, bytes] of Object.entries(input.projectFiles ?? {})) {
15783
16139
  const destination = import_node_path27.default.join(layout2.root, file);
15784
16140
  if (files.has(destination)) continue;
@@ -15795,14 +16151,36 @@ module ${moduleName}.Swift {
15795
16151
  )
15796
16152
  ] : []
15797
16153
  ];
16154
+ const clangWrapper2 = import_node_path27.default.join(layout2.root, CLANG_TARGET_MODULE_WRAPPER);
16155
+ files.set(
16156
+ clangWrapper2,
16157
+ [
16158
+ "#!/bin/sh",
16159
+ "name=",
16160
+ "prev=",
16161
+ 'for arg in "$@"; do',
16162
+ ' if [ "$prev" = -o ]; then name=${arg%/*}; name=${name##*/}; fi',
16163
+ " prev=$arg",
16164
+ "done",
16165
+ "case $name in",
16166
+ ` *.build) exec '${import_node_path27.default.join(nativeToolchain(), "clang")}' "-fmodule-name=\${name%.build}" "$@" ;;`,
16167
+ ` *) exec '${import_node_path27.default.join(nativeToolchain(), "clang")}' "$@" ;;`,
16168
+ "esac",
16169
+ ""
16170
+ ].join("\n")
16171
+ );
15798
16172
  files.set(
15799
16173
  import_node_path27.default.join(layout2.root, ".peach-target-toolset.json"),
15800
16174
  JSON.stringify({
15801
16175
  schemaVersion: "1.0",
15802
- ...nativeToolsetFlags.length > 0 ? {
15803
- cCompiler: { extraCLIOptions: nativeToolsetFlags },
15804
- cxxCompiler: { extraCLIOptions: nativeToolsetFlags }
15805
- } : {},
16176
+ cCompiler: {
16177
+ extraCLIOptions: [
16178
+ ...nativeToolsetFlags,
16179
+ "-fmodules",
16180
+ `-fmodules-cache-path=${import_node_path27.default.join(layout2.root, ".build", "ModuleCache")}`
16181
+ ]
16182
+ },
16183
+ ...nativeToolsetFlags.length > 0 ? { cxxCompiler: { extraCLIOptions: nativeToolsetFlags } } : {},
15806
16184
  swiftCompiler: {
15807
16185
  extraCLIOptions: [
15808
16186
  ...headerAliasFlags.flatMap((flag) => ["-Xcc", flag]),
@@ -15883,6 +16261,8 @@ module ${moduleName}.Swift {
15883
16261
  "// dependency targets emit their native compatibility headers.\n"
15884
16262
  );
15885
16263
  syncSwiftTree(layout2.root, files);
16264
+ const clangWrapper = import_node_path27.default.join(layout2.root, CLANG_TARGET_MODULE_WRAPPER);
16265
+ if (files.has(clangWrapper)) (0, import_node_fs25.chmodSync)(clangWrapper, 493);
15886
16266
  const dependencies = new Map(
15887
16267
  swiftManifestTargets(
15888
16268
  (0, import_node_fs25.readFileSync)(import_node_path27.default.join(layout2.root, "Package.swift"), "utf8")
@@ -16329,6 +16709,9 @@ async function buildFrameworkProducts(scratch2, args) {
16329
16709
  "release",
16330
16710
  "-Xswiftc",
16331
16711
  "-Osize",
16712
+ // the release link strips all debug info, so none is generated
16713
+ "-Xswiftc",
16714
+ "-gnone",
16332
16715
  "-Xswiftc",
16333
16716
  "-num-threads",
16334
16717
  "-Xswiftc",
@@ -16829,12 +17212,13 @@ function compileSwiftProjectOnce(input, options) {
16829
17212
  ] : []
16830
17213
  );
16831
17214
  const projectProcess = options.project ? prepareSwiftProjectProcess(root, options.project) : void 0;
17215
+ const compiler = preparation.targetToolset ? { CC: import_node_path27.default.join(root, CLANG_TARGET_MODULE_WRAPPER) } : {};
16832
17216
  const appOptions = projectProcess ? {
16833
17217
  ...buildOptions,
16834
17218
  uid: projectProcess.uid,
16835
17219
  gid: projectProcess.gid,
16836
- confined: projectProcess.env
16837
- } : buildOptions;
17220
+ confined: { ...projectProcess.env, ...compiler }
17221
+ } : { ...buildOptions, env: { ...buildOptions.env, ...compiler } };
16838
17222
  const unprepared = preparation.targetFailures.map(
16839
17223
  (failure) => `error: target ${failure}`
16840
17224
  );
@@ -16864,6 +17248,9 @@ function compileSwiftProjectOnce(input, options) {
16864
17248
  ...preparation.targetToolset ? ["--toolset", import_node_path27.default.join(root, ".peach-target-toolset.json")] : [],
16865
17249
  "-c",
16866
17250
  "release",
17251
+ // the link strips debug info, so none is generated (as for the framework)
17252
+ "-Xswiftc",
17253
+ "-gnone",
16867
17254
  "-Xswiftc",
16868
17255
  "-num-threads",
16869
17256
  "-Xswiftc",
@@ -16897,6 +17284,51 @@ function compileSwiftProjectOnce(input, options) {
16897
17284
  if ((0, import_node_fs25.existsSync)(linked) && (0, import_node_fs25.statSync)(linked).size <= 8)
16898
17285
  (0, import_node_fs25.rmSync)(linked, { force: true });
16899
17286
  report("compiling and linking Swift modules");
17287
+ const frameworkInterfaces = /* @__PURE__ */ new Map();
17288
+ const frameworkInterface = (name2) => {
17289
+ if (frameworkInterfaces.has(name2)) return frameworkInterfaces.get(name2);
17290
+ const source = distribution ? import_node_path27.default.join(frameworkRoot, "modules", `${name2}-Swift.h`) : import_node_path27.default.join(
17291
+ prebuilt.modules,
17292
+ "..",
17293
+ `${name2}.build/include/${name2}-Swift.h`
17294
+ );
17295
+ if (!(0, import_node_fs25.existsSync)(source)) {
17296
+ frameworkInterfaces.set(name2, null);
17297
+ return null;
17298
+ }
17299
+ const headers = import_node_path27.default.join(
17300
+ swiftSdkPaths(frameworkRoot, options.toolchainBin).darwin,
17301
+ `System/Library/Frameworks/${name2}.framework/Headers`
17302
+ );
17303
+ const declared = /* @__PURE__ */ new Set();
17304
+ if ((0, import_node_fs25.existsSync)(headers)) {
17305
+ for (const file of (0, import_node_fs25.readdirSync)(headers, {
17306
+ recursive: true,
17307
+ encoding: "utf8"
17308
+ }))
17309
+ if (file.endsWith(".h"))
17310
+ for (const name3 of swiftInterfaceDeclarations(
17311
+ (0, import_node_fs25.readFileSync)(import_node_path27.default.join(headers, file), "utf8")
17312
+ ))
17313
+ declared.add(name3);
17314
+ }
17315
+ const header = withoutSwiftDeclarations(
17316
+ clangInterfaceHeader((0, import_node_fs25.readFileSync)(source, "utf8")),
17317
+ declared,
17318
+ `#import <${name2}/${name2}.h>`
17319
+ );
17320
+ const value = {
17321
+ file: import_node_path27.default.join(root, ".build/peach-framework-objc", `${name2}-Swift.h`),
17322
+ header
17323
+ };
17324
+ frameworkInterfaces.set(name2, value);
17325
+ writeBuildFile(
17326
+ value.file,
17327
+ ((0, import_node_fs25.existsSync)(import_node_path27.default.join(headers, `${name2}.h`)) ? `#import <${name2}/${name2}.h>
17328
+ ` : "") + swiftHeaderWithSuperclassImports(header, frameworkInterface)
17329
+ );
17330
+ return value;
17331
+ };
16900
17332
  try {
16901
17333
  const headerBuilds = preparation.headerProductTarget ? [
16902
17334
  ...Object.keys(preparation.nativeHeaderDeclarations),
@@ -16924,7 +17356,10 @@ function compileSwiftProjectOnce(input, options) {
16924
17356
  writeBuildFile(
16925
17357
  emitted,
16926
17358
  withoutSwiftDeclarations(
16927
- clangInterfaceHeader((0, import_node_fs25.readFileSync)(original, "utf8")),
17359
+ swiftHeaderWithSuperclassImports(
17360
+ clangInterfaceHeader((0, import_node_fs25.readFileSync)(original, "utf8")),
17361
+ frameworkInterface
17362
+ ),
16928
17363
  new Set(preparation.nativeHeaderDeclarations[producer]),
16929
17364
  `#import <${producer}/${producer}.h>`
16930
17365
  )
@@ -17041,16 +17476,15 @@ function compileSwiftProjectOnce(input, options) {
17041
17476
  output,
17042
17477
  optimized
17043
17478
  });
17044
- else if (input.optimize) await optimizeWasm(output, optimized);
17045
- const executable = input.optimize ? optimized : output;
17479
+ else await lowerWasm(output, optimized, { optimize: input.optimize === true });
17046
17480
  await runCompiler(
17047
17481
  import_node_path27.default.join(options.toolchainBin, "llvm-objcopy"),
17048
- ["--remove-section=.swift1_autolink_entries", executable],
17482
+ ["--remove-section=.swift1_autolink_entries", optimized],
17049
17483
  buildOptions
17050
17484
  );
17051
17485
  const artifact = {
17052
17486
  hash,
17053
- bytes: (0, import_node_fs25.readFileSync)(executable),
17487
+ bytes: (0, import_node_fs25.readFileSync)(optimized),
17054
17488
  icu: await icu
17055
17489
  };
17056
17490
  if (artifact.bytes.length <= 8)
@@ -17101,6 +17535,7 @@ function compileSwiftProjectOnce(input, options) {
17101
17535
  swiftCompileSdkOptions,
17102
17536
  swiftCrossImportFlags,
17103
17537
  swiftDistributionAt,
17538
+ swiftHeaderWithSuperclassImports,
17104
17539
  swiftIcuAddress,
17105
17540
  swiftIcuAsset,
17106
17541
  swiftIcuBundleAsset,
@@ -17125,6 +17560,7 @@ function compileSwiftProjectOnce(input, options) {
17125
17560
  swiftTypedApplicationEntry,
17126
17561
  syncSwiftTree,
17127
17562
  withNativeSourceGlue,
17563
+ withPreconcurrencyFoundationModules,
17128
17564
  withoutSwiftDeclarations,
17129
17565
  wrapUIApplicationMainEntry,
17130
17566
  writeSwiftProject