peachsim 0.1.2223 → 0.1.2225

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 (152) hide show
  1. package/cli/internal-child.ts +4 -2
  2. package/dist-lib/agent-daemon-client.cjs +1 -1
  3. package/dist-lib/agent-events.cjs +1 -1
  4. package/dist-lib/attached-projects.cjs +1 -1
  5. package/dist-lib/auth/shared-session.cjs +1 -1
  6. package/dist-lib/backend-origin.cjs +1 -1
  7. package/dist-lib/beta.cjs +1 -1
  8. package/dist-lib/beta.mjs +1 -1
  9. package/dist-lib/bridge-constants.cjs +1 -1
  10. package/dist-lib/bridge-contract-input.cjs +1 -1
  11. package/dist-lib/bridge-contract-input.mjs +1 -1
  12. package/dist-lib/bridge-contract.cjs +1 -1
  13. package/dist-lib/bridge-contract.mjs +1 -1
  14. package/dist-lib/bundle-channel.cjs +875 -468
  15. package/dist-lib/capture-contract.cjs +1 -1
  16. package/dist-lib/capture-contract.mjs +1 -1
  17. package/dist-lib/cloud-contract.cjs +1 -1
  18. package/dist-lib/cloud-contract.mjs +1 -1
  19. package/dist-lib/cloud-test-args.cjs +1 -1
  20. package/dist-lib/cloud-test-args.mjs +1 -1
  21. package/dist-lib/cloud.cjs +1 -1
  22. package/dist-lib/cloud.mjs +1 -1
  23. package/dist-lib/config.cjs +1 -1
  24. package/dist-lib/config.mjs +1 -1
  25. package/dist-lib/detox/index.cjs +2 -2
  26. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  27. package/dist-lib/expo-swift-bundle.cjs +811 -404
  28. package/dist-lib/expo-swift-metadata.cjs +1 -1
  29. package/dist-lib/expo-swift-metadata.mjs +1 -1
  30. package/dist-lib/home-paths.cjs +1 -1
  31. package/dist-lib/host/bridge-host.cjs +870 -463
  32. package/dist-lib/host/fetch-proxy-handler.cjs +55 -12
  33. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  34. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  35. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  36. package/dist-lib/host/websocket-proxy.cjs +1 -1
  37. package/dist-lib/index.cjs +60 -16
  38. package/dist-lib/jump-to-source-babel.cjs +1 -1
  39. package/dist-lib/jump-to-source-native.cjs +1 -1
  40. package/dist-lib/kotlin-host.cjs +1 -1
  41. package/dist-lib/menu.cjs +1 -1
  42. package/dist-lib/menu.mjs +1 -1
  43. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  44. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  45. package/dist-lib/metro-production-bundle.cjs +1 -1
  46. package/dist-lib/metro-production-bundle.mjs +1 -1
  47. package/dist-lib/metro.cjs +60 -16
  48. package/dist-lib/native-app-identity-project.cjs +53 -9
  49. package/dist-lib/native-app-identity-project.mjs +84 -37
  50. package/dist-lib/native-app-identity.cjs +1 -1
  51. package/dist-lib/native-app-identity.mjs +1 -1
  52. package/dist-lib/native-firebase-metadata.cjs +1 -1
  53. package/dist-lib/native-firebase-metadata.mjs +1 -1
  54. package/dist-lib/pdfium-raster.cjs +1 -1
  55. package/dist-lib/pdfium-raster.mjs +1 -1
  56. package/dist-lib/plist.cjs +1 -1
  57. package/dist-lib/plist.mjs +1 -1
  58. package/dist-lib/profiles.cjs +1 -1
  59. package/dist-lib/public-brand.cjs +1 -1
  60. package/dist-lib/public-origins-lib-esm.json +26 -24
  61. package/dist-lib/public-origins-lib.json +65 -54
  62. package/dist-lib/react-native-host-modules.cjs +1 -1
  63. package/dist-lib/react-native-host-modules.mjs +1 -1
  64. package/dist-lib/reap-browser.cjs +1 -1
  65. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  66. package/dist-lib/sdk.cjs +1 -1
  67. package/dist-lib/sdk.mjs +1 -1
  68. package/dist-lib/skills.cjs +919 -511
  69. package/dist-lib/swift-compile.cjs +491 -119
  70. package/dist-lib/swift-compile.mjs +629 -257
  71. package/dist-lib/swift-package.cjs +1 -1
  72. package/dist-lib/swift-package.mjs +1 -1
  73. package/dist-lib/swift-submit.cjs +1 -1
  74. package/dist-lib/swift-submit.mjs +1 -1
  75. package/dist-lib/swift-toolchain.cjs +38 -2
  76. package/dist-lib/swift.cjs +1 -1
  77. package/dist-lib/vite-swift.cjs +1665 -1217
  78. package/dist-lib/vite.cjs +55 -12
  79. package/dist-lib/worklet-executable.cjs +1 -1
  80. package/dist-lib/worklet-executable.mjs +1 -1
  81. package/dist-types/packages/peach-engine/src/engine/glass-material.d.ts +4 -0
  82. package/dist-types/packages/peach-engine/src/engine/liquid-glass.d.ts +3 -6
  83. package/dist-types/packages/peach-engine/src/engine/scene-table.d.ts +1 -1
  84. package/dist-types/packages/peach-engine/src/engine/types.d.ts +1 -0
  85. package/dist-types/packages/peach-engine/src/preview/preview-room-contract.d.ts +6 -0
  86. package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +12 -0
  87. package/kotlin/sdk.tar.gz +0 -0
  88. package/package.json +1 -1
  89. package/runtime-companion.json +1 -1
  90. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFCGTypes.h +0 -6
  91. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/NSCharacterSet.h +1 -1
  92. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/NSURL.h +1 -1
  93. package/sdk/ios/usr/include/AvailabilityInternal.h +2 -2
  94. package/sdk/ios/usr/include/peach/pthread.h +1 -7
  95. package/sdk/ios/wasm/include/TargetConditionals.h +2 -3
  96. package/sdk/ios/wasm/include/__struct_timeval.h +15 -0
  97. package/sdk/ios/wasm/include/__typedef_suseconds_t.h +9 -0
  98. package/sdk/ios/wasm/include/limits.h +1 -1
  99. package/sdk/ios/wasm/include/machine/_types.h +1 -1
  100. package/sdk/ios/wasm/include/machine/limits.h +1 -1
  101. package/sdk/ios/wasm/include/machine/param.h +2 -2
  102. package/sdk/ios/wasm/include/math.h +13 -0
  103. package/sdk/ios/wasm/include/pthread.h +1 -13
  104. package/sdk/ios/wasm/include/sys/resource.h +3 -0
  105. package/sdk/ios/wasm/include/sys/socket.h +0 -10
  106. package/sdk/ios/wasm/include/sys/stat.h +5 -2
  107. package/sdk/ios/wasm/include/sys/time.h +16 -3
  108. package/sdk/ios/wasm/include/sys/types.h +4 -1
  109. package/sdk/ios/wasm/include/time.h +2 -0
  110. package/sdk/ios/wasm/storage-include/TargetConditionals.h +2 -3
  111. package/sdk/native-hashes.json +14 -14
  112. package/src/conformance-comparison-contract.ts +9 -9
  113. package/src/native-slices.ts +3 -2
  114. package/src/native-static-libraries.ts +23 -23
  115. package/src/native-swift-slices.ts +2 -2
  116. package/src/nitro-adapter.lock.json +288 -288
  117. package/src/nitro-compiler-digest.ts +0 -1
  118. package/src/nitro-dependencies.ts +8 -9
  119. package/src/nitro-superset.lock.json +4 -4
  120. package/src/react-native-core-build.ts +2 -2
  121. package/src/swift-compile.ts +132 -45
  122. package/src/swift-compiler-digest.ts +2 -0
  123. package/src/swift-cxx-standin.ts +1 -1
  124. package/src/swift-darwin-records.ts +4 -4
  125. package/src/swift-distribution-contract.ts +2 -2
  126. package/src/swift-distribution.lock.json +13 -12
  127. package/src/swift-guest-compile.ts +6 -5
  128. package/src/swift-guest-image-ledger.ts +5 -5
  129. package/src/swift-guest-link.ts +1 -1
  130. package/src/swift-guest-linked-spans.ts +7 -4
  131. package/src/swift-guest-manifest.ts +2 -2
  132. package/src/swift-guest-source-inputs.ts +16 -5
  133. package/src/swift-host.ts +33 -31
  134. package/src/swift-icu.ts +1 -1
  135. package/src/swift-objc-compile.ts +9 -4
  136. package/src/swift-objc-standin.ts +1 -4
  137. package/src/swift-package-manifest.ts +5 -1
  138. package/src/swift-packages.ts +2 -2
  139. package/src/swift-shared-sdk.ts +1 -1
  140. package/src/swift-standin-emit.ts +2 -16
  141. package/src/swift-standins.ts +111 -87
  142. package/src/swift-toolchain.ts +37 -1
  143. package/src/swift-uniform-type-constants.ts +1 -1
  144. package/src/swift-wasm-prune.ts +17 -12
  145. package/src/swiftGuestImageContract.ts +4 -4
  146. package/src/swiftNativePinContract.ts +1 -1
  147. package/src/swiftRuntimeProductContract.ts +1 -1
  148. package/src/turbo-runtime.lock.json +28 -28
  149. package/src/vite-plugin.ts +6 -1
  150. package/src/wasm-narrow-boundary.ts +296 -0
  151. package/src/wasm-optimize.ts +59 -14
  152. package/src/xcode-project.ts +6 -4
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.2223 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.2225 | (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;
@@ -88,12 +88,13 @@ __export(swift_compile_exports, {
88
88
  swiftTypedApplicationEntry: () => swiftTypedApplicationEntry,
89
89
  syncSwiftTree: () => syncSwiftTree,
90
90
  withNativeSourceGlue: () => withNativeSourceGlue,
91
+ withPreconcurrencyFoundationModules: () => withPreconcurrencyFoundationModules,
91
92
  withoutSwiftDeclarations: () => withoutSwiftDeclarations,
92
93
  wrapUIApplicationMainEntry: () => wrapUIApplicationMainEntry,
93
94
  writeSwiftProject: () => writeSwiftProject
94
95
  });
95
96
  module.exports = __toCommonJS(swift_compile_exports);
96
- var import_node_child_process18 = require("node:child_process");
97
+ var import_node_child_process19 = require("node:child_process");
97
98
  var import_node_crypto13 = require("node:crypto");
98
99
  var import_node_fs25 = require("node:fs");
99
100
  var import_node_os11 = __toESM(require("node:os"), 1);
@@ -2677,6 +2678,42 @@ function swiftSdkOptions() {
2677
2678
  var SWIFT_HOST_COMPILER_RELEASE = "swift-6.4.0-RELEASE-custom-81b2c791c27276bf";
2678
2679
  var SWIFT_HOST_COMPILER_ID = "81b2c791c27276bf";
2679
2680
  var compilerArchives = {
2681
+ "swift-6.4.0-RELEASE-custom-fb42d2535739dfd2": {
2682
+ identity: "fb42d2535739dfd2",
2683
+ archive: "tar.zst",
2684
+ hosts: {
2685
+ "darwin-arm64": {
2686
+ checksum: "5e417d415ca74a435755e298a1d2d19ec47637fd03479de7a7d958eb382941f1",
2687
+ manifest: "eb5a0356aebabe89c7b2780f8809e13d6e2ad6f342fed87cf99f9a5834344363"
2688
+ },
2689
+ "linux-arm64": {
2690
+ checksum: "8ac7ad97f3d68bf485423001d1ce3cd92a8d4625313c47c8071867a9aeed3af9",
2691
+ manifest: "6126266dd65b43c43d719e4dc4d33c4ea6a3267f99f34e3638637439a995af2e"
2692
+ },
2693
+ "linux-x64": {
2694
+ checksum: "7d76463079619ba822123d250601bd35f6744ed5f8054a657ce472ce4dac76c8",
2695
+ manifest: "f1a6c0c61d15eddb2ecfa4c3a72a5154621881ac2f0c413162ff1d0f4343bd0e"
2696
+ }
2697
+ }
2698
+ },
2699
+ "swift-6.4.0-RELEASE-custom-44ecd25f163bb359": {
2700
+ identity: "44ecd25f163bb359",
2701
+ archive: "tar.zst",
2702
+ hosts: {
2703
+ "darwin-arm64": {
2704
+ checksum: "d06dda4435f99d8376179cc7a3804907aa7305513135ece6288fd8e6d4695ae6",
2705
+ manifest: "bc0d8b955f923f096dda2aa8bbb1d56176a73f3d4a4df4cc9a1f59d31417061a"
2706
+ },
2707
+ "linux-x64": {
2708
+ checksum: "f95b56440693c5de7995f10ea14c57fc7e659a161018a17f17a74b61a98e88a4",
2709
+ manifest: "c18a60b14d5c89a8b2e1dbb2b4b52342c5fb92c7f3069fdc55c985bce61683a7"
2710
+ },
2711
+ "linux-arm64": {
2712
+ checksum: "afb74ae60df2b5bd7792bfbcf29bcea03675a5c814b758dd6cb91a760c220cd2",
2713
+ manifest: "ac037f6b0fdc4a6ae582eebc22bcf811fa2becdc30d083057137fc857f3c456a"
2714
+ }
2715
+ }
2716
+ },
2680
2717
  "swift-6.4.0-RELEASE-custom-11345d60dca47496": {
2681
2718
  identity: "11345d60dca47496",
2682
2719
  archive: "tar.zst",
@@ -3084,7 +3121,7 @@ function validateSwiftSdkIdentity(sdk) {
3084
3121
  function swiftSdkBundle(swift, id, options) {
3085
3122
  const configuration = (0, import_node_child_process4.execFileSync)(
3086
3123
  swift,
3087
- ["sdk", "configure", ...options, "--show-configuration", id, "wasm32-unknown-wasip1"],
3124
+ ["sdk", "configure", ...options, "--show-configuration", id, "wasm64-unknown-wasip1"],
3088
3125
  { encoding: "utf8", env: swiftEnvironment(), stdio: ["ignore", "pipe", "pipe"] }
3089
3126
  );
3090
3127
  const sysroot = /^sdkRootPath: (.+)$/m.exec(configuration)?.[1]?.trim();
@@ -3888,14 +3925,11 @@ function objcSdkIntakeFlags(headers, toolchainBin, minimum) {
3888
3925
  return [
3889
3926
  ...swiftObjCPlatformFlags(toolchainBin, minimum),
3890
3927
  // 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
3928
+ // is false for wasm64. the maximum is the sdk the headers come from, as
3892
3929
  // xcode defines it, so `#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_26_0`
3893
3930
  // sources see the members the sdk declares instead of a 17.0 default.
3894
3931
  `-D__IPHONE_OS_VERSION_MIN_REQUIRED=${minimum}`,
3895
3932
  `-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
3933
  // the installed libc's default feature set otherwise defines
3900
3934
  // _XOPEN_SOURCE, which darwin's sys/cdefs.h turns into a strict posix
3901
3935
  // level; iOS compiles at darwin's full level with neither defined.
@@ -4165,7 +4199,7 @@ function swiftSharedSdkViewOptions(moduleRoot, distribution, toolchainBin, sdk)
4165
4199
  ...swiftSdkOptions(),
4166
4200
  "--show-configuration",
4167
4201
  sdk,
4168
- "wasm32-unknown-wasip1"
4202
+ "wasm64-unknown-wasip1"
4169
4203
  ],
4170
4204
  { encoding: "utf8", env: swiftEnvironment(), stdio: ["ignore", "pipe", "pipe"] }
4171
4205
  );
@@ -4302,7 +4336,7 @@ function compileDarwinRecords(args) {
4302
4336
  (0, import_node_child_process7.execFileSync)(
4303
4337
  import_node_path9.default.join(args.bin, "clang"),
4304
4338
  [
4305
- "--target=wasm32-unknown-wasip1",
4339
+ "--target=wasm64-unknown-wasip1",
4306
4340
  `--sysroot=${args.sysroot}`,
4307
4341
  "-Oz",
4308
4342
  "-g0",
@@ -4313,7 +4347,7 @@ function compileDarwinRecords(args) {
4313
4347
  `-ffile-prefix-map=${records}${import_node_path9.default.sep}=DarwinRecords/`,
4314
4348
  // apple's headers select on the ios identity original units compile
4315
4349
  // with, and TargetConditionals.h refuses a compiler without it
4316
- ...file.endsWith(".m") ? objcSdkIntakeFlags(args.darwin, args.bin, args.minimum) : [
4350
+ ...file === "sysctl.c" || file.endsWith(".m") ? objcSdkIntakeFlags(args.darwin, args.bin, args.minimum) : [
4317
4351
  ...swiftObjCPlatformFlags(args.bin, args.minimum),
4318
4352
  ...WASI_EMULATION_FLAGS,
4319
4353
  // the sdk build compiles these with libobjc2's headers in
@@ -4780,7 +4814,7 @@ var foundationCategoryObjects = [
4780
4814
  ];
4781
4815
 
4782
4816
  // src/swift-guest-compile.ts
4783
- var import_node_child_process13 = require("node:child_process");
4817
+ var import_node_child_process14 = require("node:child_process");
4784
4818
  var import_node_fs17 = require("node:fs");
4785
4819
  var import_node_path19 = __toESM(require("node:path"), 1);
4786
4820
 
@@ -4839,7 +4873,7 @@ var swiftSdkProductSchema = v.pipe(
4839
4873
  v.object({
4840
4874
  id: v.string(),
4841
4875
  installName: v.string(),
4842
- target: v.literal("wasm32-unknown-wasip1"),
4876
+ target: v.literal("wasm64-unknown-wasip1"),
4843
4877
  linkNames: v.array(v.string()),
4844
4878
  // absent records declare no framework namespace, even when a library name matches.
4845
4879
  frameworkAliases: v.optional(
@@ -4948,7 +4982,8 @@ function encodeULEB(val) {
4948
4982
  } while (val !== 0);
4949
4983
  return out;
4950
4984
  }
4951
- var HAS_ADDEND = /* @__PURE__ */ new Set([3, 4, 5, 8, 9, 11, 13, 14, 15, 16, 21, 22, 23, 24, 25]);
4985
+ var HAS_ADDEND = /* @__PURE__ */ new Set([3, 4, 5, 8, 9, 11, 14, 15, 16, 17, 21, 22, 23, 25]);
4986
+ var WIDE_DATA_RELOCS = /* @__PURE__ */ new Set([16, 19, 22]);
4952
4987
  var ROOT_SEG_PREFIXES = [
4953
4988
  ".init_array",
4954
4989
  "__objc_init_func",
@@ -5844,7 +5879,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
5844
5879
  } else {
5845
5880
  lazyBuildObjects.set(t, parseWasmObjectCached(t, false, false));
5846
5881
  }
5847
- } else if (!inStartLib && t.endsWith(".a") && !t.endsWith("libclang_rt.builtins-wasm32.a") && import_node_fs9.default.existsSync(t)) {
5882
+ } else if (!inStartLib && t.endsWith(".a") && !t.endsWith("libclang_rt.builtins-wasm64.a") && import_node_fs9.default.existsSync(t)) {
5848
5883
  const members = readArMembers(new Uint8Array(import_node_fs9.default.readFileSync(t)));
5849
5884
  for (const m of members) {
5850
5885
  extraArchiveObjs.push(parseWasmObjectBytes(`${t}(${m.name})`, m.bytes, false));
@@ -6326,7 +6361,11 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
6326
6361
  }
6327
6362
  }
6328
6363
  const keptDataRelocBytes = [];
6329
- const zeroDataRelocOffsets = [];
6364
+ const zeroDataRelocs = [];
6365
+ const zeroDataReloc = (r) => zeroDataRelocs.push({
6366
+ ro: r.ro,
6367
+ width: WIDE_DATA_RELOCS.has(r.rawBytes[0]) ? 8 : 4
6368
+ });
6330
6369
  const usedSyms = /* @__PURE__ */ new Set();
6331
6370
  for (const r of keptCodeRelocs) if (r.rawBytes[0] !== 6) usedSyms.add(r.rs);
6332
6371
  for (const r of obj.dataRelocList) {
@@ -6337,7 +6376,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
6337
6376
  keptDataRelocBytes.push(r.rawBytes);
6338
6377
  usedSyms.add(r.rs);
6339
6378
  } else if (sName === "__objc_classes") {
6340
- zeroDataRelocOffsets.push(r.ro);
6379
+ zeroDataReloc(r);
6341
6380
  } else {
6342
6381
  const repl = firstLiveInSpecialSeg.get(r.segIdx);
6343
6382
  const roBytes = encodeULEB(r.ro);
@@ -6350,17 +6389,17 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
6350
6389
  } else if (r.ownerSymIdx !== -1) {
6351
6390
  if (dLive.has(r.ownerSymIdx)) {
6352
6391
  if (obj.isDist && dropsReflection(obj, obj.symNames[r.rs])) {
6353
- zeroDataRelocOffsets.push(r.ro);
6392
+ zeroDataReloc(r);
6354
6393
  } else {
6355
6394
  keptDataRelocBytes.push(r.rawBytes);
6356
6395
  usedSyms.add(r.rs);
6357
6396
  }
6358
6397
  } else if (sName === "__objc_class_refs") {
6359
- zeroDataRelocOffsets.push(r.ro);
6398
+ zeroDataReloc(r);
6360
6399
  }
6361
6400
  } else if (sLive[r.segIdx] === 1) {
6362
6401
  if (obj.isDist && obj.symNames[r.rs]?.startsWith("l__swift5_reflection_descriptor") && dropsReflection(obj, obj.symNames[r.rs])) {
6363
- zeroDataRelocOffsets.push(r.ro);
6402
+ zeroDataReloc(r);
6364
6403
  } else {
6365
6404
  keptDataRelocBytes.push(r.rawBytes);
6366
6405
  usedSyms.add(r.rs);
@@ -6543,11 +6582,8 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
6543
6582
  outChunks.push(buf.subarray(secStart, end));
6544
6583
  }
6545
6584
  } 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
- }
6585
+ if (id === 11)
6586
+ for (const { ro, width } of zeroDataRelocs) buf.fill(0, p + ro, p + ro + width);
6551
6587
  outChunks.push(buf.subarray(secStart, end));
6552
6588
  }
6553
6589
  pos = end;
@@ -6723,7 +6759,7 @@ function readNumber(bytes, position) {
6723
6759
  let value = 0;
6724
6760
  let shift = 0;
6725
6761
  for (; ; ) {
6726
- if (position >= bytes.length || shift > 28) throw new Error("invalid wasm integer");
6762
+ if (position >= bytes.length || shift > 63) throw new Error("invalid wasm integer");
6727
6763
  const byte = bytes[position++];
6728
6764
  value += (byte & 127) * 2 ** shift;
6729
6765
  if (!(byte & 128)) return [value, position];
@@ -6770,7 +6806,7 @@ var OBJC_INIT_RECORD = ".objc_init";
6770
6806
  function rewriteObject(bytes, names, callerAlias, bindings, instrumentDynamicLookups, preserveCanonical) {
6771
6807
  if (Buffer.from(bytes.subarray(0, 8)).toString("hex") !== "0061736d01000000")
6772
6808
  throw new Error("expected wasm object");
6773
- const sections = [Buffer.from(bytes.subarray(0, 8))];
6809
+ const sections2 = [Buffer.from(bytes.subarray(0, 8))];
6774
6810
  const types = [];
6775
6811
  const functionTypes = [];
6776
6812
  const definitions = [];
@@ -6827,12 +6863,12 @@ function rewriteObject(bytes, names, callerAlias, bindings, instrumentDynamicLoo
6827
6863
  if (referenceType !== 112 && referenceType !== 111)
6828
6864
  throw new Error("unsupported table type");
6829
6865
  const flags = number3();
6830
- if (flags & ~3) throw new Error("unsupported table limits");
6866
+ if (flags & ~7) throw new Error("unsupported table limits");
6831
6867
  number3();
6832
6868
  if (flags & 1) number3();
6833
6869
  } else if (kind === 2) {
6834
6870
  const flags = number3();
6835
- if (flags & ~3) throw new Error("unsupported memory limits");
6871
+ if (flags & ~7) throw new Error("unsupported memory limits");
6836
6872
  number3();
6837
6873
  if (flags & 1) number3();
6838
6874
  } else if (kind === 3) offset += 2;
@@ -6845,7 +6881,7 @@ function rewriteObject(bytes, names, callerAlias, bindings, instrumentDynamicLoo
6845
6881
  if (module2 === "env" && names.has(name2)) usedSymbols.add(name2);
6846
6882
  if (isDlsym || isDlerror) {
6847
6883
  const type = types[functionType];
6848
- const expected = isDlsym ? "127,127:127" : ":127";
6884
+ const expected = isDlsym ? "126,126:126" : ":126";
6849
6885
  if (!type || `${type.parameters.join(",")}:${type.results.join(",")}` !== expected)
6850
6886
  throw new Error(`unexpected ${name2} import type`);
6851
6887
  }
@@ -6987,10 +7023,10 @@ function rewriteObject(bytes, names, callerAlias, bindings, instrumentDynamicLoo
6987
7023
  section = Buffer.concat(parts);
6988
7024
  }
6989
7025
  }
6990
- sections.push(Buffer.from([id]), encodeNumber(section.length), section);
7026
+ sections2.push(Buffer.from([id]), encodeNumber(section.length), section);
6991
7027
  }
6992
7028
  return {
6993
- bytes: Buffer.concat(sections),
7029
+ bytes: Buffer.concat(sections2),
6994
7030
  definitions,
6995
7031
  usesDlsym,
6996
7032
  usedSymbols: [...usedSymbols]
@@ -7157,7 +7193,7 @@ function createGuestImageLedger(input) {
7157
7193
  return [...bytes].map((byte) => `\\${byte.toString(16).padStart(2, "0")}`).join("");
7158
7194
  }).join("");
7159
7195
  const ir = [
7160
- 'target triple = "wasm32-unknown-wasip1"',
7196
+ 'target triple = "wasm64-unknown-wasip1"',
7161
7197
  `@.names = private constant [${nameSize} x i8] c"${nameContents}"`
7162
7198
  ];
7163
7199
  for (const definition of exported.values()) {
@@ -7276,8 +7312,8 @@ function selectedGuestManifestInputs(plan, selection, identities) {
7276
7312
  }
7277
7313
  function createGuestImageManifest(image) {
7278
7314
  const target = {
7279
- triple: "wasm32-unknown-wasip1",
7280
- pointerWidth: 32,
7315
+ triple: "wasm64-unknown-wasip1",
7316
+ pointerWidth: 64,
7281
7317
  byteOrder: "little",
7282
7318
  cpuType: -1,
7283
7319
  cpuSubtype: 0
@@ -7337,6 +7373,7 @@ function number2(bytes, start) {
7337
7373
  shift += 7;
7338
7374
  }
7339
7375
  }
7376
+ var constant = (opcode) => opcode === 65 || opcode === 66;
7340
7377
  function signedAddress(bytes, start) {
7341
7378
  const [value, end] = number2(bytes, start);
7342
7379
  const bits = (end - start) * 7;
@@ -7346,16 +7383,16 @@ function signedAddress(bytes, start) {
7346
7383
  function layout(bytes) {
7347
7384
  if (Buffer.from(bytes.subarray(0, 8)).toString("hex") !== "0061736d01000000")
7348
7385
  throw new Error("expected linked wasm module");
7349
- const sections = /* @__PURE__ */ new Map();
7386
+ const sections2 = /* @__PURE__ */ new Map();
7350
7387
  let offset = 8;
7351
7388
  while (offset < bytes.length) {
7352
7389
  const id = bytes[offset++];
7353
7390
  const [size, start] = number2(bytes, offset);
7354
7391
  if (start + size > bytes.length) throw new Error("invalid wasm section");
7355
- if (id) sections.set(id, [start, start + size]);
7392
+ if (id) sections2.set(id, [start, start + size]);
7356
7393
  offset = start + size;
7357
7394
  }
7358
- const exports2 = sections.get(7);
7395
+ const exports2 = sections2.get(7);
7359
7396
  if (!exports2) throw new Error("guest wasm does not export memory and table");
7360
7397
  let exportPosition = exports2[0];
7361
7398
  const readExport = () => {
@@ -7376,7 +7413,7 @@ function layout(bytes) {
7376
7413
  throw new Error("guest wasm does not export memory and table");
7377
7414
  let imports = 0;
7378
7415
  let memoryPages;
7379
- const section = sections.get(2);
7416
+ const section = sections2.get(2);
7380
7417
  if (section) {
7381
7418
  let pos = section[0];
7382
7419
  const read = () => {
@@ -7391,7 +7428,7 @@ function layout(bytes) {
7391
7428
  };
7392
7429
  const limits = () => {
7393
7430
  const flags = read();
7394
- if (flags & ~3) throw new Error("unsupported wasm limits");
7431
+ if (flags & ~7) throw new Error("unsupported wasm limits");
7395
7432
  const minimum = read();
7396
7433
  if (flags & 1) read();
7397
7434
  return minimum;
@@ -7419,7 +7456,7 @@ function layout(bytes) {
7419
7456
  }
7420
7457
  if (pos !== section[1]) throw new Error("invalid wasm imports");
7421
7458
  }
7422
- const memory = sections.get(5);
7459
+ const memory = sections2.get(5);
7423
7460
  if (memory) {
7424
7461
  let pos = memory[0];
7425
7462
  const read = () => {
@@ -7430,14 +7467,14 @@ function layout(bytes) {
7430
7467
  if (read() !== 1 || memoryPages !== void 0)
7431
7468
  throw new Error("unsupported wasm memories");
7432
7469
  const flags = read();
7433
- if (flags & ~3) throw new Error("unsupported wasm memory limits");
7470
+ if (flags & ~7) throw new Error("unsupported wasm memory limits");
7434
7471
  memoryPages = read();
7435
7472
  if (flags & 1) read();
7436
7473
  if (pos !== memory[1]) throw new Error("invalid wasm memory section");
7437
7474
  }
7438
7475
  if (memoryPages === void 0) throw new Error("guest wasm has no memory");
7439
7476
  const functionsByCodeOffset = /* @__PURE__ */ new Map();
7440
- const code = sections.get(10);
7477
+ const code = sections2.get(10);
7441
7478
  if (code) {
7442
7479
  let pos = code[0];
7443
7480
  let count;
@@ -7453,7 +7490,7 @@ function layout(bytes) {
7453
7490
  if (pos !== code[1]) throw new Error("invalid wasm code section");
7454
7491
  }
7455
7492
  const functionsByTableSlot = /* @__PURE__ */ new Map();
7456
- const elements = sections.get(9);
7493
+ const elements = sections2.get(9);
7457
7494
  if (elements) {
7458
7495
  let pos = elements[0];
7459
7496
  const read = () => {
@@ -7467,7 +7504,7 @@ function layout(bytes) {
7467
7504
  if (flags !== 0 && flags !== 2)
7468
7505
  throw new Error(`unsupported wasm element segment ${flags}`);
7469
7506
  if (flags === 2 && read() !== 0) throw new Error("unsupported wasm table index");
7470
- if (bytes[pos++] !== 65) throw new Error("nonconstant wasm table offset");
7507
+ if (!constant(bytes[pos++])) throw new Error("nonconstant wasm table offset");
7471
7508
  let base;
7472
7509
  [base, pos] = signedAddress(bytes, pos);
7473
7510
  if (bytes[pos++] !== 11) throw new Error("invalid wasm table offset");
@@ -7484,7 +7521,7 @@ function layout(bytes) {
7484
7521
  if (pos !== elements[1]) throw new Error("invalid wasm element section");
7485
7522
  }
7486
7523
  const data = [];
7487
- const dataSection = sections.get(11);
7524
+ const dataSection = sections2.get(11);
7488
7525
  if (dataSection) {
7489
7526
  let pos = dataSection[0];
7490
7527
  const read = () => {
@@ -7498,7 +7535,7 @@ function layout(bytes) {
7498
7535
  if (flags !== 0 && flags !== 2)
7499
7536
  throw new Error(`unsupported wasm data segment ${flags}`);
7500
7537
  if (flags === 2 && read() !== 0) throw new Error("unsupported wasm memory index");
7501
- if (bytes[pos++] !== 65) throw new Error("nonconstant wasm data offset");
7538
+ if (!constant(bytes[pos++])) throw new Error("nonconstant wasm data offset");
7502
7539
  let address;
7503
7540
  [address, pos] = signedAddress(bytes, pos);
7504
7541
  if (bytes[pos++] !== 11) throw new Error("invalid wasm data offset");
@@ -7620,7 +7657,7 @@ function isSwiftGuestImageManifest(value) {
7620
7657
  const text2 = (value2) => typeof value2 === "string" && value2.length > 0 && value2.length <= 4096 && !value2.includes("\0");
7621
7658
  const name2 = (value2) => text2(value2) && new TextEncoder().encode(value2).length <= 16;
7622
7659
  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))
7660
+ 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
7661
  return false;
7625
7662
  return value.regions.every((region) => {
7626
7663
  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 +9089,7 @@ function linkGuestImages(options) {
9052
9089
  import_node_fs13.default.writeFileSync(irPath, ledger.llvmIR);
9053
9090
  (0, import_node_child_process10.execFileSync)(
9054
9091
  clang,
9055
- ["--target=wasm32-unknown-wasip1", "-c", irPath, "-o", ledgerObject],
9092
+ ["--target=wasm64-unknown-wasip1", "-c", irPath, "-o", ledgerObject],
9056
9093
  { stdio: "pipe" }
9057
9094
  );
9058
9095
  linkedOwners.set(ledgerObject, options.ledgerDataImage);
@@ -9725,6 +9762,7 @@ function clangIrLinkOptions(ir) {
9725
9762
  }
9726
9763
  return result;
9727
9764
  }
9765
+ var CLANG_TARGET_MODULE_WRAPPER = ".peach-clang";
9728
9766
  function sourceGuestClangLinkOptions(options) {
9729
9767
  const wanted = new Set(options.objects.map((file) => import_node_path15.default.resolve(file)));
9730
9768
  const commands = /* @__PURE__ */ new Map();
@@ -9767,10 +9805,16 @@ function sourceGuestClangLinkOptions(options) {
9767
9805
  throw new Error(`unsupported source object producer ${file}`);
9768
9806
  continue;
9769
9807
  }
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")))
9808
+ const compiler = command.args[0] ? (0, import_node_fs14.realpathSync)(command.args[0]) : "";
9809
+ 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
9810
  throw new Error(`unsupported source object producer ${file}`);
9772
9811
  const args = command.args.slice(1).filter((arg) => arg !== "-c");
9773
- const output = import_node_path15.default.join(options.directory, `clang-link-${index}.ll`);
9812
+ const outputDirectory = import_node_path15.default.join(
9813
+ options.directory,
9814
+ import_node_path15.default.basename(import_node_path15.default.dirname(file))
9815
+ );
9816
+ (0, import_node_fs14.mkdirSync)(outputDirectory, { recursive: true });
9817
+ const output = import_node_path15.default.join(outputDirectory, `clang-link-${index}.ll`);
9774
9818
  for (const flag of ["-o", "-MF"]) {
9775
9819
  const index2 = args.lastIndexOf(flag);
9776
9820
  if (index2 < 0 || index2 + 1 >= args.length)
@@ -10010,8 +10054,10 @@ function logicalGuestLinkOptions(args, identities, roots) {
10010
10054
  }
10011
10055
 
10012
10056
  // src/wasm-optimize.ts
10057
+ var import_node_child_process13 = require("node:child_process");
10013
10058
  var import_node_fs16 = require("node:fs");
10014
10059
  var import_node_path18 = require("node:path");
10060
+ var import_node_util = require("node:util");
10015
10061
 
10016
10062
  // ../contrast-runtime-delivery/src/index.ts
10017
10063
  var import_node_child_process12 = require("node:child_process");
@@ -10241,8 +10287,244 @@ function rnxHomeDir() {
10241
10287
  }
10242
10288
  var DAEMON_LOCKFILE_MAX_BYTES = 16 * 1024;
10243
10289
 
10290
+ // src/wasm-narrow-boundary.ts
10291
+ var I64 = 126;
10292
+ var VALUE_TYPES = /* @__PURE__ */ new Map([
10293
+ [127, "i32"],
10294
+ [I64, "i64"],
10295
+ [125, "f32"],
10296
+ [124, "f64"],
10297
+ [123, "v128"],
10298
+ [112, "funcref"],
10299
+ [111, "externref"]
10300
+ ]);
10301
+ var GUEST = "guest";
10302
+ var BOUNDARY = "boundary";
10303
+ var WIDE = "$wide.";
10304
+ var NARROW = "$narrow.";
10305
+ function encodeNumber2(value) {
10306
+ const bytes = [];
10307
+ for (let rest = value; ; ) {
10308
+ const byte = rest % 128;
10309
+ rest = Math.floor(rest / 128);
10310
+ if (rest === 0) return [...bytes, byte];
10311
+ bytes.push(byte | 128);
10312
+ }
10313
+ }
10314
+ function encodeName(name2) {
10315
+ const bytes = [...Buffer.from(name2)];
10316
+ return [...encodeNumber2(bytes.length), ...bytes];
10317
+ }
10318
+ function reader(bytes, start, end) {
10319
+ let at = start;
10320
+ const number3 = () => {
10321
+ let value = 0;
10322
+ for (let shift = 0; ; shift += 7) {
10323
+ if (at >= end || shift > 63) throw new Error("invalid wasm integer");
10324
+ const byte = bytes[at++];
10325
+ value += (byte & 127) * 2 ** shift;
10326
+ if (!(byte & 128)) return value;
10327
+ }
10328
+ };
10329
+ return {
10330
+ number: number3,
10331
+ byte: () => {
10332
+ if (at >= end) throw new Error("truncated wasm section");
10333
+ return bytes[at++];
10334
+ },
10335
+ name: () => {
10336
+ const length = number3();
10337
+ at += length;
10338
+ if (at > end) throw new Error("truncated wasm name");
10339
+ return Buffer.from(bytes.subarray(at - length, at)).toString();
10340
+ },
10341
+ position: () => at,
10342
+ done: () => at === end
10343
+ };
10344
+ }
10345
+ function sections(bytes) {
10346
+ if (Buffer.from(bytes.subarray(0, 8)).toString("hex") !== "0061736d01000000")
10347
+ throw new Error("not a wasm module");
10348
+ const found = [];
10349
+ for (let at = 8; at < bytes.length; ) {
10350
+ const header = reader(bytes, at, bytes.length);
10351
+ const id = header.byte();
10352
+ const size = header.number();
10353
+ const start = header.position();
10354
+ found.push({ id, start, end: start + size });
10355
+ at = start + size;
10356
+ }
10357
+ return found;
10358
+ }
10359
+ function withSections(bytes, layout2, replacements) {
10360
+ const parts = [bytes.subarray(0, 8)];
10361
+ let at = 8;
10362
+ for (const section of layout2) {
10363
+ const body = replacements.get(section.id);
10364
+ parts.push(
10365
+ body ? Uint8Array.from([section.id, ...encodeNumber2(body.length), ...body]) : bytes.subarray(at, section.end)
10366
+ );
10367
+ at = section.end;
10368
+ }
10369
+ return Buffer.concat(parts);
10370
+ }
10371
+ var quoted = (name2) => `"${[...Buffer.from(name2)].map((byte) => `\\${byte.toString(16).padStart(2, "0")}`).join("")}"`;
10372
+ var signature = (types, keyword, narrow) => types.length === 0 ? "" : ` (${keyword} ${types.map((type) => {
10373
+ const name2 = VALUE_TYPES.get(narrow && type === I64 ? 127 : type);
10374
+ if (!name2) throw new Error(`unsupported wasm boundary type ${type}`);
10375
+ return name2;
10376
+ }).join(" ")})`;
10377
+ var wide = (type) => type.parameters.includes(I64) || type.results.includes(I64);
10378
+ function narrowWasmBoundary(bytes) {
10379
+ const layout2 = sections(bytes);
10380
+ const section = (id) => {
10381
+ const found = layout2.find((entry) => entry.id === id);
10382
+ return found && reader(bytes, found.start, found.end);
10383
+ };
10384
+ const types = [];
10385
+ const typeSection = section(1);
10386
+ if (typeSection) {
10387
+ for (let count = typeSection.number(); count > 0; count--) {
10388
+ if (typeSection.byte() !== 96) throw new Error("unsupported wasm type");
10389
+ const values = () => Array.from({ length: typeSection.number() }, () => typeSection.byte());
10390
+ types.push({ parameters: values(), results: values() });
10391
+ }
10392
+ }
10393
+ const typeAt = (index) => {
10394
+ const type = types[index];
10395
+ if (!type) throw new Error("invalid wasm type index");
10396
+ return type;
10397
+ };
10398
+ const thunks = [];
10399
+ const functionTypes = [];
10400
+ const importBody = [];
10401
+ const importSection = section(2);
10402
+ if (importSection) {
10403
+ const count = importSection.number();
10404
+ importBody.push(...encodeNumber2(count));
10405
+ for (let index = 0; index < count; index++) {
10406
+ const module2 = importSection.name();
10407
+ const name2 = importSection.name();
10408
+ const start = importSection.position();
10409
+ const kind = importSection.byte();
10410
+ const limits = () => {
10411
+ const flags = importSection.number();
10412
+ importSection.number();
10413
+ if (flags & 1) importSection.number();
10414
+ };
10415
+ let type;
10416
+ if (kind === 0) {
10417
+ type = typeAt(importSection.number());
10418
+ functionTypes.push(type);
10419
+ } else if (kind === 1) {
10420
+ importSection.byte();
10421
+ limits();
10422
+ } else if (kind === 2) limits();
10423
+ else if (kind === 3) {
10424
+ importSection.byte();
10425
+ importSection.byte();
10426
+ } else if (kind === 4) {
10427
+ importSection.byte();
10428
+ importSection.number();
10429
+ } else throw new Error("unsupported wasm import");
10430
+ 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;
10431
+ const parameters = type?.parameters.map(
10432
+ (value, index2) => value === I64 && !scalar64(index2) ? 127 : value
10433
+ );
10434
+ const results = type?.results.map(
10435
+ (value) => value === I64 && !scalar64(null) ? 127 : value
10436
+ );
10437
+ if (type && parameters && results && (parameters.some((value, index2) => value !== type.parameters[index2]) || results.some((value, index2) => value !== type.results[index2]))) {
10438
+ if (type.results.length > 1)
10439
+ throw new Error(`import ${module2}.${name2} returns several values`);
10440
+ const id = thunks.length;
10441
+ const call = `(call $host${id}${type.parameters.map(
10442
+ (value, at) => value !== parameters[at] ? ` (i32.wrap_i64 (local.get ${at}))` : ` (local.get ${at})`
10443
+ ).join("")})`;
10444
+ thunks.push(
10445
+ `(import ${quoted(module2)} ${quoted(name2)} (func $host${id}${signature(parameters, "param", false)}${signature(results, "result", false)}))`,
10446
+ `(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})`
10447
+ );
10448
+ importBody.push(...encodeName(BOUNDARY), ...encodeName(`${NARROW}${id}`));
10449
+ } else importBody.push(...encodeName(module2), ...encodeName(name2));
10450
+ importBody.push(...bytes.subarray(start, importSection.position()));
10451
+ }
10452
+ if (!importSection.done()) throw new Error("invalid wasm imports");
10453
+ }
10454
+ const functionSection = section(3);
10455
+ if (functionSection)
10456
+ for (let count = functionSection.number(); count > 0; count--)
10457
+ functionTypes.push(typeAt(functionSection.number()));
10458
+ const exportBody = [];
10459
+ const exportSection = section(7);
10460
+ if (exportSection) {
10461
+ const count = exportSection.number();
10462
+ exportBody.push(...encodeNumber2(count));
10463
+ for (let index = 0; index < count; index++) {
10464
+ const name2 = exportSection.name();
10465
+ const kind = exportSection.byte();
10466
+ const target = exportSection.number();
10467
+ const type = kind === 0 ? functionTypes[target] : void 0;
10468
+ if (kind === 0 && !type) throw new Error("invalid wasm export");
10469
+ if (type && wide(type)) {
10470
+ if (type.results.length > 1)
10471
+ throw new Error(`export ${name2} returns several values`);
10472
+ const id = thunks.length;
10473
+ const call = `(call $guest${id}${type.parameters.map(
10474
+ (value, at) => value === I64 ? ` (i64.extend_i32_u (local.get ${at}))` : ` (local.get ${at})`
10475
+ ).join("")})`;
10476
+ thunks.push(
10477
+ `(import "${GUEST}" "${WIDE}${id}" (func $guest${id}${signature(type.parameters, "param", false)}${signature(type.results, "result", false)}))`,
10478
+ `(func (export ${quoted(name2)})${signature(type.parameters, "param", true)}${signature(type.results, "result", true)} ${type.results[0] === I64 ? `(i32.wrap_i64 ${call})` : call})`
10479
+ );
10480
+ exportBody.push(...encodeName(`${WIDE}${id}`));
10481
+ } else exportBody.push(...encodeName(name2));
10482
+ exportBody.push(kind, ...encodeNumber2(target));
10483
+ }
10484
+ if (!exportSection.done()) throw new Error("invalid wasm exports");
10485
+ }
10486
+ if (thunks.length === 0) return void 0;
10487
+ const imports = thunks.filter((line) => line.startsWith("(import"));
10488
+ const functions = thunks.filter((line) => !line.startsWith("(import"));
10489
+ return {
10490
+ module: withSections(
10491
+ bytes,
10492
+ layout2,
10493
+ /* @__PURE__ */ new Map([
10494
+ [2, importBody],
10495
+ [7, exportBody]
10496
+ ])
10497
+ ),
10498
+ thunks: `(module
10499
+ ${[...imports, ...functions].join("\n")}
10500
+ )
10501
+ `
10502
+ };
10503
+ }
10504
+ var NARROW_MERGE_NAMES = { guest: GUEST, boundary: BOUNDARY };
10505
+ function dropBoundaryExports(bytes) {
10506
+ const layout2 = sections(bytes);
10507
+ const found = layout2.find((entry) => entry.id === 7);
10508
+ if (!found) throw new Error("merged module has no exports");
10509
+ const exportSection = reader(bytes, found.start, found.end);
10510
+ const kept = [];
10511
+ for (let count = exportSection.number(); count > 0; count--) {
10512
+ const name2 = exportSection.name();
10513
+ const kind = exportSection.byte();
10514
+ const target = exportSection.number();
10515
+ if (!name2.startsWith(WIDE) && !name2.startsWith(NARROW))
10516
+ kept.push([...encodeName(name2), kind, ...encodeNumber2(target)]);
10517
+ }
10518
+ return withSections(
10519
+ bytes,
10520
+ layout2,
10521
+ /* @__PURE__ */ new Map([[7, [...encodeNumber2(kept.length), ...kept.flat()]]])
10522
+ );
10523
+ }
10524
+
10244
10525
  // src/wasm-optimize.ts
10245
10526
  var FEATURES = [
10527
+ "memory64",
10246
10528
  "threads",
10247
10529
  "bulk-memory",
10248
10530
  "bulk-memory-opt",
@@ -10255,7 +10537,8 @@ var FEATURES = [
10255
10537
  "sign-ext"
10256
10538
  ];
10257
10539
  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" : ""}`;
10540
+ var LOWERING = ["--memory64-lowering", "--table64-lowering"];
10541
+ var WASM_LOWER_IDENTITY = `binaryen ${import_wasm_opt.BINARYEN_VERSION} narrow ${LOWERING.join(" ")} ${FEATURES.join(",")} unoptimized-names`;
10259
10542
  var PINNED_BINARYEN_VERSION = "132";
10260
10543
  var BINARYEN_RELEASES = /* @__PURE__ */ new Map([
10261
10544
  [
@@ -10280,7 +10563,7 @@ var BINARYEN_RELEASES = /* @__PURE__ */ new Map([
10280
10563
  }
10281
10564
  ]
10282
10565
  ]);
10283
- async function runWasmOpt(file, output, skipPasses, binary) {
10566
+ async function runWasmOpt(file, output, optimize, skipPasses, binary) {
10284
10567
  const admittedCores = windowAdmission()?.cores ?? Number(process.env.TM_EXEC_CPU_CORES);
10285
10568
  const requestedCores = Number(process.env.BINARYEN_CORES);
10286
10569
  const environment = { ...process.env, WASM_OPT_PATH: binary };
@@ -10288,18 +10571,43 @@ async function runWasmOpt(file, output, skipPasses, binary) {
10288
10571
  environment.BINARYEN_CORES = String(
10289
10572
  Number.isInteger(requestedCores) && requestedCores > 0 ? Math.min(admittedCores, requestedCores) : admittedCores
10290
10573
  );
10574
+ const features = FEATURES.map((feature) => `--enable-${feature}`);
10575
+ const names = optimize && !KEEP_WASM_NAMES ? [] : ["-g"];
10576
+ const narrowed = narrowWasmBoundary((0, import_node_fs16.readFileSync)(file));
10577
+ const merged = `${output}.narrowed`;
10578
+ if (narrowed) {
10579
+ const guest = `${output}.guest`;
10580
+ const thunks = `${output}.thunks.wat`;
10581
+ (0, import_node_fs16.writeFileSync)(guest, narrowed.module);
10582
+ (0, import_node_fs16.writeFileSync)(thunks, narrowed.thunks);
10583
+ await (0, import_node_util.promisify)(import_node_child_process13.execFile)((0, import_node_path18.join)((0, import_node_path18.dirname)(binary), "wasm-merge"), [
10584
+ ...features,
10585
+ ...names,
10586
+ guest,
10587
+ NARROW_MERGE_NAMES.guest,
10588
+ thunks,
10589
+ NARROW_MERGE_NAMES.boundary,
10590
+ "-o",
10591
+ merged
10592
+ ]);
10593
+ (0, import_node_fs16.writeFileSync)(merged, dropBoundaryExports((0, import_node_fs16.readFileSync)(merged)));
10594
+ (0, import_node_fs16.rmSync)(guest);
10595
+ (0, import_node_fs16.rmSync)(thunks);
10596
+ }
10291
10597
  const result = await (0, import_wasm_opt.wasmOpt)(
10292
10598
  [
10293
- "-Oz",
10294
- ...KEEP_WASM_NAMES ? ["-g"] : [],
10599
+ ...LOWERING,
10600
+ ...optimize ? ["-Oz"] : [],
10601
+ ...names,
10295
10602
  ...skipPasses.flatMap((pass) => ["--skip-pass", pass]),
10296
- ...FEATURES.map((feature) => `--enable-${feature}`),
10297
- file,
10603
+ ...features,
10604
+ narrowed ? merged : file,
10298
10605
  "-o",
10299
10606
  output
10300
10607
  ],
10301
10608
  { env: environment }
10302
10609
  );
10610
+ if (narrowed) (0, import_node_fs16.rmSync)(merged);
10303
10611
  if (result.status !== 0)
10304
10612
  throw new Error(`wasm-opt exited ${result.status}: ${result.stderr}`);
10305
10613
  }
@@ -10322,8 +10630,14 @@ async function installWasmOpt() {
10322
10630
  });
10323
10631
  return binary;
10324
10632
  }
10325
- async function optimizeWasm(file, output, skipPasses = []) {
10326
- await runWasmOpt(file, output, skipPasses, await installWasmOpt());
10633
+ async function lowerWasm(file, output, options) {
10634
+ await runWasmOpt(
10635
+ file,
10636
+ output,
10637
+ options.optimize,
10638
+ options.skipPasses ?? [],
10639
+ await installWasmOpt()
10640
+ );
10327
10641
  }
10328
10642
 
10329
10643
  // src/swift-guest-compile.ts
@@ -10357,7 +10671,7 @@ async function compileGuestLink(options) {
10357
10671
  };
10358
10672
  const buildVersion = imageBuildVersion(entry.buildVersion);
10359
10673
  const clangOptions = [
10360
- "--target=wasm32-unknown-wasip1",
10674
+ "--target=wasm64-unknown-wasip1",
10361
10675
  `--sysroot=${options.sysroot}`,
10362
10676
  `-I${import_node_path19.default.join(options.moduleRoot, "include")}`
10363
10677
  ];
@@ -10367,7 +10681,7 @@ async function compileGuestLink(options) {
10367
10681
  stubSource,
10368
10682
  '#include "guest-image-projection.h"\nconst struct peach_guest_image __peach_guest_images[] = {{0}};\nconst uint32_t __peach_guest_image_count = 0;\n'
10369
10683
  );
10370
- (0, import_node_child_process13.execFileSync)(
10684
+ (0, import_node_child_process14.execFileSync)(
10371
10685
  import_node_path19.default.join(options.toolchainBin, "clang"),
10372
10686
  [...clangOptions, "-c", stubSource, "-o", stub],
10373
10687
  { stdio: "pipe" }
@@ -10665,9 +10979,10 @@ async function compileGuestLink(options) {
10665
10979
  }
10666
10980
  });
10667
10981
  if (!reserved || !projectionObject) throw new Error("guest projection was not reserved");
10668
- await optimizeWasm(options.output, options.optimized, [
10669
- "duplicate-function-elimination"
10670
- ]);
10982
+ await lowerWasm(options.output, options.optimized, {
10983
+ optimize: true,
10984
+ skipPasses: ["duplicate-function-elimination"]
10985
+ });
10671
10986
  const map = (0, import_node_fs17.readFileSync)(result.mapPath, "utf8");
10672
10987
  if (!/ __peach_guest_images$/m.test(map)) return;
10673
10988
  const finalized = finalizeGuestProjectionStorage({
@@ -10683,13 +10998,13 @@ async function compileGuestLink(options) {
10683
10998
  }
10684
10999
 
10685
11000
  // src/swift-icu.ts
10686
- var import_node_child_process14 = require("node:child_process");
11001
+ var import_node_child_process15 = require("node:child_process");
10687
11002
  var import_node_crypto11 = require("node:crypto");
10688
11003
  var import_node_fs18 = require("node:fs");
10689
11004
  var import_promises4 = require("node:fs/promises");
10690
11005
  var import_node_os8 = __toESM(require("node:os"), 1);
10691
11006
  var import_node_path20 = __toESM(require("node:path"), 1);
10692
- var import_node_util = require("node:util");
11007
+ var import_node_util2 = require("node:util");
10693
11008
  var import_node_zlib2 = require("node:zlib");
10694
11009
 
10695
11010
  // ../sootsim-swift/src/icuData.ts
@@ -10747,10 +11062,10 @@ function swiftIcuPack(blob, deflate2) {
10747
11062
  }
10748
11063
 
10749
11064
  // 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);
11065
+ var run = (0, import_node_util2.promisify)(import_node_child_process15.execFile);
11066
+ var deflate = (0, import_node_util2.promisify)(import_node_zlib2.gzip);
11067
+ var compressBrotli = (0, import_node_util2.promisify)(import_node_zlib2.brotliCompress);
11068
+ var inflateGzip = (0, import_node_util2.promisify)(import_node_zlib2.gunzip);
10754
11069
  var ARCHIVE = "wasi/lib_FoundationICU.a";
10755
11070
  var MEMBER = "icu_packaged_data.cpp.obj";
10756
11071
  var raw = /* @__PURE__ */ new Map();
@@ -10831,7 +11146,7 @@ async function load(toolchainBin, sdk) {
10831
11146
  ...swiftSdkOptions(),
10832
11147
  "--show-configuration",
10833
11148
  sdk,
10834
- "wasm32-unknown-wasip1"
11149
+ "wasm64-unknown-wasip1"
10835
11150
  ],
10836
11151
  { env: swiftEnvironment() }
10837
11152
  );
@@ -11079,7 +11394,7 @@ function swiftObjCModuleMap(module2, headers, submodules = /* @__PURE__ */ new S
11079
11394
  }
11080
11395
 
11081
11396
  // src/swift-project-user.ts
11082
- var import_node_child_process15 = require("node:child_process");
11397
+ var import_node_child_process16 = require("node:child_process");
11083
11398
  var import_node_fs20 = require("node:fs");
11084
11399
  var import_node_path22 = __toESM(require("node:path"), 1);
11085
11400
  function prepareSwiftProjectProcess(root, user) {
@@ -11090,7 +11405,7 @@ function prepareSwiftProjectProcess(root, user) {
11090
11405
  (0, import_node_fs20.mkdirSync)(tmp, { recursive: true });
11091
11406
  const caches = ["cache", "config", "security"].map((name2) => import_node_path22.default.join(swiftpm, name2));
11092
11407
  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]);
11408
+ (0, import_node_child_process16.execFileSync)("chown", ["-R", "-P", `${user.uid}:${user.gid}`, root, home]);
11094
11409
  (0, import_node_fs20.chmodSync)(root, 448);
11095
11410
  (0, import_node_fs20.chmodSync)(home, 448);
11096
11411
  return {
@@ -11113,7 +11428,7 @@ function prepareSwiftProjectProcess(root, user) {
11113
11428
  };
11114
11429
  }
11115
11430
  function endSwiftProjectProcesses(user) {
11116
- (0, import_node_child_process15.execFileSync)("sh", ["-c", "kill -s KILL -- -1 2>/dev/null || true"], {
11431
+ (0, import_node_child_process16.execFileSync)("sh", ["-c", "kill -s KILL -- -1 2>/dev/null || true"], {
11117
11432
  uid: user.uid,
11118
11433
  gid: user.gid
11119
11434
  });
@@ -11160,7 +11475,7 @@ function swiftReproducibleBuildFlags(roots) {
11160
11475
  }
11161
11476
 
11162
11477
  // src/swift-root-lock.ts
11163
- var import_node_child_process16 = require("node:child_process");
11478
+ var import_node_child_process17 = require("node:child_process");
11164
11479
  var import_node_crypto12 = require("node:crypto");
11165
11480
  var import_node_fs22 = require("node:fs");
11166
11481
  var import_node_os10 = require("node:os");
@@ -11326,7 +11641,7 @@ async function withSwiftRootLock(root, work, signal, wait = true) {
11326
11641
  }
11327
11642
  },
11328
11643
  spawn(command, args, options, companion) {
11329
- const child = (0, import_node_child_process16.spawn)(
11644
+ const child = (0, import_node_child_process17.spawn)(
11330
11645
  "/bin/sh",
11331
11646
  ["-c", 'IFS= read -r go || exit 1; exec "$@" </dev/null', "sh", command, ...args],
11332
11647
  { ...options, detached: true, stdio: ["pipe", "pipe", "pipe"] }
@@ -11358,15 +11673,15 @@ async function withSwiftRootLock(root, work, signal, wait = true) {
11358
11673
  }
11359
11674
 
11360
11675
  // src/swift-uniform-type-constants.ts
11361
- var import_node_child_process17 = require("node:child_process");
11676
+ var import_node_child_process18 = require("node:child_process");
11362
11677
  var import_node_path24 = __toESM(require("node:path"), 1);
11363
11678
  function compileUniformTypeConstants(args) {
11364
11679
  const source = import_node_path24.default.join(args.packageRoot, "runtime/UniformTypeIdentifiersConstants.m");
11365
11680
  const object3 = import_node_path24.default.join(args.out, "UniformTypeIdentifiers-NativeConstants.o");
11366
- (0, import_node_child_process17.execFileSync)(
11681
+ (0, import_node_child_process18.execFileSync)(
11367
11682
  import_node_path24.default.join(args.bin, "clang"),
11368
11683
  [
11369
- "--target=wasm32-unknown-wasip1",
11684
+ "--target=wasm64-unknown-wasip1",
11370
11685
  `--sysroot=${args.sysroot}`,
11371
11686
  "-Oz",
11372
11687
  "-g0",
@@ -11665,7 +11980,7 @@ async function runCompiler(command, args, options, stream = false, quiet) {
11665
11980
  detached: true,
11666
11981
  stdio: ["ignore", "pipe", "pipe"]
11667
11982
  };
11668
- const child = options.lease ? options.lease.spawn(command, args, launch, options.frameworkLease) : (0, import_node_child_process18.spawn)(command, args, launch);
11983
+ const child = options.lease ? options.lease.spawn(command, args, launch, options.frameworkLease) : (0, import_node_child_process19.spawn)(command, args, launch);
11669
11984
  let stopping;
11670
11985
  try {
11671
11986
  return await new Promise((resolve, reject) => {
@@ -11739,7 +12054,7 @@ async function runCompiler(command, args, options, stream = false, quiet) {
11739
12054
  await stopping;
11740
12055
  }
11741
12056
  }
11742
- var WASM_TRIPLE = "wasm32-unknown-wasip1";
12057
+ var WASM_TRIPLE = "wasm64-unknown-wasip1";
11743
12058
  var SWIFTPM_PROGRESS = /^\[\d+\/\d+\] /;
11744
12059
  var SWIFTPM_NOISE = /^(?:\[\d+\/\d+\] |Building for production\.\.\.$|warning: '--build-system native' has been deprecated)/;
11745
12060
  function swiftBuildJobs() {
@@ -12167,10 +12482,11 @@ function swiftCondition(text2, available) {
12167
12482
  const call = /^(\w+)\s*\(\s*([^,()]*?)\s*(?:,[^()]*)?\)$/.exec(token ?? "");
12168
12483
  if (!call) return void 0;
12169
12484
  const [, name2, argument] = call;
12170
- if (name2 === "os") return argument === "iOS" || argument === "WASI";
12171
- if (name2 === "canImport") return available?.has(argument);
12485
+ if (name2 === "os") return argument === "iOS";
12486
+ if (name2 === "canImport")
12487
+ return argument !== "FoundationNetworking" && available?.has(argument);
12172
12488
  if (name2 === "targetEnvironment") return argument === "simulator";
12173
- if (name2 === "arch") return argument === "wasm32";
12489
+ if (name2 === "arch") return argument === "wasm64";
12174
12490
  return void 0;
12175
12491
  };
12176
12492
  const both = () => {
@@ -12239,7 +12555,7 @@ function swiftSdkPaths(moduleRoot, toolchainBin) {
12239
12555
  const key = JSON.stringify([toolchainBin, sdk, options]);
12240
12556
  const cached = sdkPaths.get(key);
12241
12557
  if (cached) return cached;
12242
- const configuration = (0, import_node_child_process18.execFileSync)(
12558
+ const configuration = (0, import_node_child_process19.execFileSync)(
12243
12559
  import_node_path27.default.join(toolchainBin, "swift"),
12244
12560
  [
12245
12561
  "sdk",
@@ -12247,7 +12563,7 @@ function swiftSdkPaths(moduleRoot, toolchainBin) {
12247
12563
  ...options,
12248
12564
  "--show-configuration",
12249
12565
  sdk,
12250
- "wasm32-unknown-wasip1"
12566
+ "wasm64-unknown-wasip1"
12251
12567
  ],
12252
12568
  { encoding: "utf8", env: swiftEnvironment(), stdio: ["ignore", "pipe", "pipe"] }
12253
12569
  );
@@ -12620,6 +12936,14 @@ var FOUNDATION_IMPLICIT_MODULES = [
12620
12936
  "PeachFoundationCombine",
12621
12937
  "Darwin"
12622
12938
  ];
12939
+ var PRECONCURRENCY_FOUNDATION_IMPORT = /^[ \t]*@preconcurrency[ \t]+(?:(?:public|package|internal|fileprivate|private)[ \t]+)?import[ \t]+(?:Foundation|UIKit|SwiftUI)[ \t]*(?:\/\/.*)?$/m;
12940
+ function withPreconcurrencyFoundationModules(source) {
12941
+ if (!PRECONCURRENCY_FOUNDATION_IMPORT.test(source)) return source;
12942
+ return `${source}${source.endsWith("\n") ? "" : "\n"}#if canImport(PeachObjC)
12943
+ ${["ObjectiveC", ...FOUNDATION_IMPLICIT_MODULES].map((module2) => `@preconcurrency import ${module2}
12944
+ `).join("")}#endif
12945
+ `;
12946
+ }
12623
12947
  var FOUNDATION_IMPLICIT_FLAGS = FOUNDATION_IMPLICIT_MODULES.map(
12624
12948
  (module2) => `, "-Xfrontend", "-import-module", "-Xfrontend", "${module2}"`
12625
12949
  ).join("");
@@ -12635,11 +12959,11 @@ var executableLinkFlags = (root) => ` "-Xclang-linker", "-O0",
12635
12959
  "-Xlinker", "--wrap=swift_udata_open",
12636
12960
  "-Xlinker", "--wrap=swift_udata_openChoice",
12637
12961
  `;
12638
- var darwinRecordsRegion = (quoted) => quoted.length ? ["-Wl,--start-lib", ...quoted, "-Wl,--end-lib"] : [];
12962
+ var darwinRecordsRegion = (quoted2) => quoted2.length ? ["-Wl,--start-lib", ...quoted2, "-Wl,--end-lib"] : [];
12639
12963
  var REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
12640
12964
  var MULTI_MANIFEST_VERSION = 68;
12641
12965
  var SWIFT_HEADER_PRODUCTS_TARGET = "PeachHeaderProducts";
12642
- var compilerSourceDigest = true ? "ae9e08389e6ab1901846342a7b347d7c10f8074172cf5d4d6505f7e955879ad4" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
12966
+ var compilerSourceDigest = true ? "645b0e6bc4e374f7c82da4d402e0ec9ddedfc49d6e5a74b73284852f1fbd4efc" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
12643
12967
  function swiftArtifactHash(input, release, moduleRoot) {
12644
12968
  const hash = (0, import_node_crypto13.createHash)("sha256");
12645
12969
  hash.update(`swift-compile
@@ -12649,9 +12973,10 @@ ${release}
12649
12973
  if (input.oneModule) hash.update("one-module\n");
12650
12974
  if (KEEP_WASM_NAMES) hash.update("names\n");
12651
12975
  hash.update(swiftModuleDigest(moduleRoot));
12652
- if (input.optimize) hash.update(`optimize
12653
- ${WASM_OPTIMIZE_IDENTITY}
12976
+ hash.update(`lower
12977
+ ${WASM_LOWER_IDENTITY}
12654
12978
  `);
12979
+ if (input.optimize) hash.update("optimize\n");
12655
12980
  for (const file of Object.keys(input.files).sort()) {
12656
12981
  hash.update((0, import_node_crypto13.createHash)("sha256").update(file).digest());
12657
12982
  hash.update((0, import_node_crypto13.createHash)("sha256").update(input.files[file]).digest());
@@ -12761,6 +13086,7 @@ function toolsetOrdersLibcxxBeforeDarwinOverlay(options) {
12761
13086
  const overlay = options.indexOf("=/darwin/wasm/include");
12762
13087
  return libcxx >= 0 && overlay > libcxx;
12763
13088
  }
13089
+ var SWIFTPM_DEFAULT_IOS_DEPLOYMENT_TARGET = "12.0";
12764
13090
  function emitSwiftPackageManifest(args) {
12765
13091
  const {
12766
13092
  targets,
@@ -12826,7 +13152,7 @@ function emitSwiftPackageManifest(args) {
12826
13152
  (name2) => !object3.startsWith(`lib/${name2}-`) || reachedFrameworks.has(name2)
12827
13153
  )
12828
13154
  );
12829
- const quoted = (object3) => `"${import_node_path27.default.join(moduleRoot, object3).replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
13155
+ const quoted2 = (object3) => `"${import_node_path27.default.join(moduleRoot, object3).replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
12830
13156
  const categoryObjects = new Set(
12831
13157
  foundationCategoryObjects.map((name2) => `lib/Foundation-${name2}.o`)
12832
13158
  );
@@ -12835,11 +13161,11 @@ function emitSwiftPackageManifest(args) {
12835
13161
  objects.filter((object3) => roots.has(object3) || categoryObjects.has(object3))
12836
13162
  );
12837
13163
  const list = [
12838
- ...[...eager].map(quoted),
13164
+ ...[...eager].map(quoted2),
12839
13165
  "-Wl,--start-lib",
12840
- ...available.filter((object3) => !eager.has(object3)).map(quoted),
13166
+ ...available.filter((object3) => !eager.has(object3)).map(quoted2),
12841
13167
  "-Wl,--end-lib",
12842
- ...darwinRecordsRegion(distribution.objects.filter(isProvider).map(quoted))
13168
+ ...darwinRecordsRegion(distribution.objects.filter(isProvider).map(quoted2))
12843
13169
  ].join("\n") + "\n";
12844
13170
  distributionLinkPath = distributionLink.path.replace(
12845
13171
  /\.rsp$/,
@@ -12961,7 +13287,8 @@ function emitSwiftPackageManifest(args) {
12961
13287
  (value) => value.late?.producers.includes(target.name)
12962
13288
  )) ? `, "-emit-objc-header-path", ${JSON.stringify(import_node_path27.default.join(args.headerDirectory, `${target.name}-Swift${args.nativeHeaderDeclarations?.[target.name] ? ".original" : ""}.h`))}` : "";
12963
13289
  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}]`)})]`;
13290
+ const deployment = `, "-Xfrontend", "-peach-ios-deployment-target", "-Xfrontend", ${JSON.stringify(target.iosDeploymentTarget ?? SWIFTPM_DEFAULT_IOS_DEPLOYMENT_TARGET)}`;
13291
+ 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
13292
  const deps = [
12966
13293
  .../* @__PURE__ */ new Set([
12967
13294
  ...(target.dependencies ?? []).flatMap(
@@ -13146,6 +13473,7 @@ function syncSwiftTree(base, files) {
13146
13473
  }
13147
13474
  var DIRECTIVE = /^[ \t]*#(?:if|elseif)\b/;
13148
13475
  var OS_IOS = /\b(?:os\(\s*iOS\s*\)|targetEnvironment\(\s*simulator\s*\))/g;
13476
+ var NOT_ON_IOS = /\b(?:os\(\s*WASI\s*\)|canImport\(\s*FoundationNetworking\s*\))/g;
13149
13477
  var DELEGATE_CLASS = /^class\s+[A-Za-z_]\w*\s*(?:<[^>{]*>)?\s*:[^{]*\b(?:UIApplicationDelegate|UISceneDelegate|UIWindowSceneDelegate)\b[^{]*\{/;
13150
13478
  function compiledSwiftSources(files, targets, overlayFrameworks) {
13151
13479
  const ordered = [...targets].sort((a, b) => b.path.length - a.path.length);
@@ -13160,14 +13488,14 @@ function compiledSwiftSources(files, targets, overlayFrameworks) {
13160
13488
  );
13161
13489
  });
13162
13490
  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
- ];
13491
+ if (manifest && (!owner || /^Package(?:@swift-[\d.]+)?\.swift$/.test(file)))
13492
+ return [file, source];
13493
+ const ios = swiftSourceAsIOS(
13494
+ source,
13495
+ overlayFrameworks,
13496
+ owner?.defines?.includes(SWIFT_XCODE_BUILD_CONDITION) && !owner.defines.includes("SWIFT_PACKAGE") ? false : void 0
13497
+ );
13498
+ return [file, withPreconcurrencyFoundationModules(ios)];
13171
13499
  })
13172
13500
  );
13173
13501
  }
@@ -13818,16 +14146,22 @@ function foundationOwnerOf(name2) {
13818
14146
  return "PeachFoundation";
13819
14147
  return void 0;
13820
14148
  }
13821
- function swiftSourceAsIOS(source, overlayFrameworks, swiftPackage) {
13822
- const { lineStarts, tokens } = swiftCodeScan(source);
14149
+ function swiftPackageSourceAsIOS(source) {
14150
+ return swiftConditionsAsIOS(source, swiftCodeScan(source).lineStarts);
14151
+ }
14152
+ function swiftConditionsAsIOS(source, lineStarts, swiftPackage) {
13823
14153
  let offset = 0;
13824
- const conditioned = source.split("\n").map((line) => {
14154
+ return source.split("\n").map((line) => {
13825
14155
  const start = offset;
13826
14156
  offset += line.length + 1;
13827
14157
  if (!lineStarts.has(start) || !DIRECTIVE.test(line)) return line;
13828
- const platform = line.replace(OS_IOS, (match) => "true".padEnd(match.length));
14158
+ const platform = line.replace(OS_IOS, (match) => "true".padEnd(match.length)).replace(NOT_ON_IOS, (match) => "false".padEnd(match.length));
13829
14159
  return swiftPackage === false ? platform.replace(/\bSWIFT_PACKAGE\b/g, (match) => "false".padEnd(match.length)) : platform;
13830
14160
  }).join("\n");
14161
+ }
14162
+ function swiftSourceAsIOS(source, overlayFrameworks, swiftPackage) {
14163
+ const { lineStarts, tokens } = swiftCodeScan(source);
14164
+ const conditioned = swiftConditionsAsIOS(source, lineStarts, swiftPackage);
13831
14165
  let out = "";
13832
14166
  let copied = 0;
13833
14167
  const sceneLifecycleBodies = /* @__PURE__ */ new Set();
@@ -14284,7 +14618,7 @@ var wasmMacroEnvironment = {
14284
14618
  ...emptyMacroEnvironment,
14285
14619
  defines: /* @__PURE__ */ new Map([
14286
14620
  ["__wasm__", "1"],
14287
- ["__wasm32__", "1"],
14621
+ ["__wasm64__", "1"],
14288
14622
  ["__wasi__", "1"]
14289
14623
  ])
14290
14624
  };
@@ -15777,8 +16111,15 @@ module ${moduleName}.Swift {
15777
16111
  }) + moduleFiles
15778
16112
  );
15779
16113
  }
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"));
16114
+ for (const [file, bytes] of Object.entries(input.packageFiles ?? {})) {
16115
+ const contents = Buffer.from(bytes, "base64");
16116
+ files.set(
16117
+ import_node_path27.default.join(layout2.root, file),
16118
+ file.endsWith(".swift") && !/(?:^|\/)Package(?:@swift-[\d.]+)?\.swift$/.test(file) ? withPreconcurrencyFoundationModules(
16119
+ swiftPackageSourceAsIOS(contents.toString("utf8"))
16120
+ ) : contents
16121
+ );
16122
+ }
15782
16123
  for (const [file, bytes] of Object.entries(input.projectFiles ?? {})) {
15783
16124
  const destination = import_node_path27.default.join(layout2.root, file);
15784
16125
  if (files.has(destination)) continue;
@@ -15795,14 +16136,36 @@ module ${moduleName}.Swift {
15795
16136
  )
15796
16137
  ] : []
15797
16138
  ];
16139
+ const clangWrapper2 = import_node_path27.default.join(layout2.root, CLANG_TARGET_MODULE_WRAPPER);
16140
+ files.set(
16141
+ clangWrapper2,
16142
+ [
16143
+ "#!/bin/sh",
16144
+ "name=",
16145
+ "prev=",
16146
+ 'for arg in "$@"; do',
16147
+ ' if [ "$prev" = -o ]; then name=${arg%/*}; name=${name##*/}; fi',
16148
+ " prev=$arg",
16149
+ "done",
16150
+ "case $name in",
16151
+ ` *.build) exec '${import_node_path27.default.join(nativeToolchain(), "clang")}' "-fmodule-name=\${name%.build}" "$@" ;;`,
16152
+ ` *) exec '${import_node_path27.default.join(nativeToolchain(), "clang")}' "$@" ;;`,
16153
+ "esac",
16154
+ ""
16155
+ ].join("\n")
16156
+ );
15798
16157
  files.set(
15799
16158
  import_node_path27.default.join(layout2.root, ".peach-target-toolset.json"),
15800
16159
  JSON.stringify({
15801
16160
  schemaVersion: "1.0",
15802
- ...nativeToolsetFlags.length > 0 ? {
15803
- cCompiler: { extraCLIOptions: nativeToolsetFlags },
15804
- cxxCompiler: { extraCLIOptions: nativeToolsetFlags }
15805
- } : {},
16161
+ cCompiler: {
16162
+ extraCLIOptions: [
16163
+ ...nativeToolsetFlags,
16164
+ "-fmodules",
16165
+ `-fmodules-cache-path=${import_node_path27.default.join(layout2.root, ".build", "ModuleCache")}`
16166
+ ]
16167
+ },
16168
+ ...nativeToolsetFlags.length > 0 ? { cxxCompiler: { extraCLIOptions: nativeToolsetFlags } } : {},
15806
16169
  swiftCompiler: {
15807
16170
  extraCLIOptions: [
15808
16171
  ...headerAliasFlags.flatMap((flag) => ["-Xcc", flag]),
@@ -15883,6 +16246,8 @@ module ${moduleName}.Swift {
15883
16246
  "// dependency targets emit their native compatibility headers.\n"
15884
16247
  );
15885
16248
  syncSwiftTree(layout2.root, files);
16249
+ const clangWrapper = import_node_path27.default.join(layout2.root, CLANG_TARGET_MODULE_WRAPPER);
16250
+ if (files.has(clangWrapper)) (0, import_node_fs25.chmodSync)(clangWrapper, 493);
15886
16251
  const dependencies = new Map(
15887
16252
  swiftManifestTargets(
15888
16253
  (0, import_node_fs25.readFileSync)(import_node_path27.default.join(layout2.root, "Package.swift"), "utf8")
@@ -16329,6 +16694,9 @@ async function buildFrameworkProducts(scratch2, args) {
16329
16694
  "release",
16330
16695
  "-Xswiftc",
16331
16696
  "-Osize",
16697
+ // the release link strips all debug info, so none is generated
16698
+ "-Xswiftc",
16699
+ "-gnone",
16332
16700
  "-Xswiftc",
16333
16701
  "-num-threads",
16334
16702
  "-Xswiftc",
@@ -16829,12 +17197,13 @@ function compileSwiftProjectOnce(input, options) {
16829
17197
  ] : []
16830
17198
  );
16831
17199
  const projectProcess = options.project ? prepareSwiftProjectProcess(root, options.project) : void 0;
17200
+ const compiler = preparation.targetToolset ? { CC: import_node_path27.default.join(root, CLANG_TARGET_MODULE_WRAPPER) } : {};
16832
17201
  const appOptions = projectProcess ? {
16833
17202
  ...buildOptions,
16834
17203
  uid: projectProcess.uid,
16835
17204
  gid: projectProcess.gid,
16836
- confined: projectProcess.env
16837
- } : buildOptions;
17205
+ confined: { ...projectProcess.env, ...compiler }
17206
+ } : { ...buildOptions, env: { ...buildOptions.env, ...compiler } };
16838
17207
  const unprepared = preparation.targetFailures.map(
16839
17208
  (failure) => `error: target ${failure}`
16840
17209
  );
@@ -16864,6 +17233,9 @@ function compileSwiftProjectOnce(input, options) {
16864
17233
  ...preparation.targetToolset ? ["--toolset", import_node_path27.default.join(root, ".peach-target-toolset.json")] : [],
16865
17234
  "-c",
16866
17235
  "release",
17236
+ // the link strips debug info, so none is generated (as for the framework)
17237
+ "-Xswiftc",
17238
+ "-gnone",
16867
17239
  "-Xswiftc",
16868
17240
  "-num-threads",
16869
17241
  "-Xswiftc",
@@ -17041,16 +17413,15 @@ function compileSwiftProjectOnce(input, options) {
17041
17413
  output,
17042
17414
  optimized
17043
17415
  });
17044
- else if (input.optimize) await optimizeWasm(output, optimized);
17045
- const executable = input.optimize ? optimized : output;
17416
+ else await lowerWasm(output, optimized, { optimize: input.optimize === true });
17046
17417
  await runCompiler(
17047
17418
  import_node_path27.default.join(options.toolchainBin, "llvm-objcopy"),
17048
- ["--remove-section=.swift1_autolink_entries", executable],
17419
+ ["--remove-section=.swift1_autolink_entries", optimized],
17049
17420
  buildOptions
17050
17421
  );
17051
17422
  const artifact = {
17052
17423
  hash,
17053
- bytes: (0, import_node_fs25.readFileSync)(executable),
17424
+ bytes: (0, import_node_fs25.readFileSync)(optimized),
17054
17425
  icu: await icu
17055
17426
  };
17056
17427
  if (artifact.bytes.length <= 8)
@@ -17125,6 +17496,7 @@ function compileSwiftProjectOnce(input, options) {
17125
17496
  swiftTypedApplicationEntry,
17126
17497
  syncSwiftTree,
17127
17498
  withNativeSourceGlue,
17499
+ withPreconcurrencyFoundationModules,
17128
17500
  withoutSwiftDeclarations,
17129
17501
  wrapUIApplicationMainEntry,
17130
17502
  writeSwiftProject