peachsim 0.1.2592 → 0.1.2593

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 (137) hide show
  1. package/dist-lib/agent-daemon-client.cjs +1 -1
  2. package/dist-lib/agent-events.cjs +1 -1
  3. package/dist-lib/attached-projects.cjs +1 -1
  4. package/dist-lib/auth/shared-session.cjs +1 -1
  5. package/dist-lib/backend-origin.cjs +1 -1
  6. package/dist-lib/beta.cjs +1 -1
  7. package/dist-lib/beta.mjs +2 -2
  8. package/dist-lib/bridge-constants.cjs +1 -1
  9. package/dist-lib/bridge-contract-input.cjs +1 -1
  10. package/dist-lib/bridge-contract-input.mjs +5 -5
  11. package/dist-lib/bridge-contract.cjs +1 -1
  12. package/dist-lib/bridge-contract.mjs +3 -3
  13. package/dist-lib/bundle-channel.cjs +1737 -1648
  14. package/dist-lib/capture-contract.cjs +1 -1
  15. package/dist-lib/capture-contract.mjs +3 -3
  16. package/dist-lib/cloud-contract.cjs +1 -1
  17. package/dist-lib/cloud-contract.mjs +3 -3
  18. package/dist-lib/cloud-test-args.cjs +1 -1
  19. package/dist-lib/cloud-test-args.mjs +2 -2
  20. package/dist-lib/cloud.cjs +1 -1
  21. package/dist-lib/cloud.mjs +7 -7
  22. package/dist-lib/config.cjs +1 -1
  23. package/dist-lib/config.mjs +5 -5
  24. package/dist-lib/detox/index.cjs +1 -1
  25. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  26. package/dist-lib/esm-chunks/{acorn-67PU73QE.mjs → acorn-DLENU3SM.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-L5T3HBPO.mjs → chunk-23D4W2EY.mjs} +240 -206
  28. package/dist-lib/esm-chunks/{chunk-D4LYKRRB.mjs → chunk-2MWUVSRW.mjs} +1 -1
  29. package/dist-lib/esm-chunks/{chunk-PITO2NI2.mjs → chunk-2UERF2EN.mjs} +2 -2
  30. package/dist-lib/esm-chunks/{chunk-XSQH4R5E.mjs → chunk-4YJJKKKF.mjs} +69 -48
  31. package/dist-lib/esm-chunks/{chunk-FYXXFYML.mjs → chunk-6O2M4J2Y.mjs} +1 -1
  32. package/dist-lib/esm-chunks/{chunk-CF3MTPMY.mjs → chunk-BMKI4WBL.mjs} +1 -1
  33. package/dist-lib/esm-chunks/{chunk-EITX573K.mjs → chunk-DLSPHUHQ.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-5FTHILIE.mjs → chunk-E6OGMX3T.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-TJZPNFVF.mjs → chunk-GFMQ5PNX.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-6DB5FR7S.mjs → chunk-IT4CC3HU.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-EWHA6X3Z.mjs → chunk-JPNUGMLE.mjs} +5 -5
  38. package/dist-lib/esm-chunks/{chunk-XZ3FX3HW.mjs → chunk-KWMJUJJS.mjs} +1 -1
  39. package/dist-lib/esm-chunks/{chunk-DFF5XZ5M.mjs → chunk-LK3KQ4X3.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-RV4ACE6R.mjs → chunk-LN7ZTBNS.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-EHRSWFTD.mjs → chunk-NIYJBFXV.mjs} +3 -3
  42. package/dist-lib/esm-chunks/{chunk-M4QLI2SY.mjs → chunk-OIHSBING.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-SW4PSSTF.mjs → chunk-P3A4MQHR.mjs} +1 -1
  44. package/dist-lib/esm-chunks/{chunk-GY6TE4B4.mjs → chunk-TXBZEHNH.mjs} +4 -4
  45. package/dist-lib/esm-chunks/{chunk-R3WTQB5J.mjs → chunk-UM4DCXPA.mjs} +1 -1
  46. package/dist-lib/esm-chunks/{chunk-GQ3EO2UV.mjs → chunk-UZPLSN2V.mjs} +1 -1
  47. package/dist-lib/esm-chunks/{chunk-QSFWBVUO.mjs → chunk-XFFPOSW2.mjs} +1 -1
  48. package/dist-lib/esm-chunks/{chunk-KDI5YYQ6.mjs → chunk-ZT5ZXQC2.mjs} +1 -1
  49. package/dist-lib/esm-chunks/{metro-layout-parser-EX65MARK.mjs → metro-layout-parser-DHGC2DVE.mjs} +3 -3
  50. package/dist-lib/esm-chunks/{swift-package-prebuilt-3BPDQVA7.mjs → swift-package-prebuilt-ROIDLGLU.mjs} +10 -10
  51. package/dist-lib/esm-chunks/{swift-sdk-app-module-CRX6E3TR.mjs → swift-sdk-app-module-5VU63S56.mjs} +30 -20
  52. package/dist-lib/esm-chunks/{swift-sdk-image-EJD5TPQH.mjs → swift-sdk-image-SNFZVUQ3.mjs} +14 -14
  53. package/dist-lib/esm-chunks/{swift-sdk-image-producer-QAZOSLTZ.mjs → swift-sdk-image-producer-5RQDIX53.mjs} +4 -4
  54. package/dist-lib/expo-swift-bundle.cjs +324 -235
  55. package/dist-lib/expo-swift-metadata.cjs +1 -1
  56. package/dist-lib/expo-swift-metadata.mjs +7 -7
  57. package/dist-lib/home-paths.cjs +1 -1
  58. package/dist-lib/host/bridge-host.cjs +421 -246
  59. package/dist-lib/host/fetch-proxy-handler.cjs +8 -7
  60. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  61. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
  62. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  63. package/dist-lib/host/websocket-proxy.cjs +1 -1
  64. package/dist-lib/index.cjs +1 -1
  65. package/dist-lib/kotlin-host.cjs +1 -1
  66. package/dist-lib/menu.cjs +1 -1
  67. package/dist-lib/menu.mjs +3 -3
  68. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  69. package/dist-lib/metro-fingerprint-registry.mjs +3 -3
  70. package/dist-lib/metro-production-bundle.cjs +1 -1
  71. package/dist-lib/metro-production-bundle.mjs +4 -4
  72. package/dist-lib/native-app-identity-project.cjs +5 -5
  73. package/dist-lib/native-app-identity-project.mjs +16 -16
  74. package/dist-lib/native-app-identity.cjs +1 -1
  75. package/dist-lib/native-app-identity.mjs +6 -6
  76. package/dist-lib/native-firebase-metadata.cjs +1 -1
  77. package/dist-lib/native-firebase-metadata.mjs +3 -3
  78. package/dist-lib/pdfium-raster.cjs +1 -1
  79. package/dist-lib/pdfium-raster.mjs +2 -2
  80. package/dist-lib/plist.cjs +1 -1
  81. package/dist-lib/plist.mjs +3 -3
  82. package/dist-lib/profiles.cjs +1 -1
  83. package/dist-lib/public-brand.cjs +1 -1
  84. package/dist-lib/public-origins-lib-esm.json +81 -81
  85. package/dist-lib/public-origins-lib.json +71 -71
  86. package/dist-lib/react-native-host-modules.cjs +1 -1
  87. package/dist-lib/react-native-host-modules.mjs +2 -2
  88. package/dist-lib/reap-browser.cjs +1 -1
  89. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  90. package/dist-lib/sdk.cjs +1 -1
  91. package/dist-lib/sdk.mjs +8 -8
  92. package/dist-lib/skills.cjs +421 -246
  93. package/dist-lib/swift-compile.cjs +286 -230
  94. package/dist-lib/swift-compile.mjs +10 -10
  95. package/dist-lib/swift-package.cjs +1 -1
  96. package/dist-lib/swift-package.mjs +3 -3
  97. package/dist-lib/swift-submit.cjs +1 -1
  98. package/dist-lib/swift-submit.mjs +6 -6
  99. package/dist-lib/swift-svg-raster.cjs +1 -1
  100. package/dist-lib/swift-svg-raster.mjs +2 -2
  101. package/dist-lib/swift-toolchain.cjs +1 -1
  102. package/dist-lib/swift.cjs +1 -1
  103. package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
  104. package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
  105. package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
  106. package/dist-lib/vendor/@xmldom/xmldom.cjs +1 -1
  107. package/dist-lib/vendor/acorn.cjs +1 -1
  108. package/dist-lib/vendor/bplist-parser.cjs +1 -1
  109. package/dist-lib/vendor/ignore.cjs +1 -1
  110. package/dist-lib/vendor/magic-string.cjs +1 -1
  111. package/dist-lib/vendor/plist.cjs +1 -1
  112. package/dist-lib/vendor/smol-toml.cjs +1 -1
  113. package/dist-lib/vendor/stream-json.cjs +1 -1
  114. package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
  115. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
  116. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
  117. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
  118. package/dist-lib/vendor/sucrase.cjs +1 -1
  119. package/dist-lib/vendor/terser.cjs +1 -1
  120. package/dist-lib/vendor/valibot.cjs +1 -1
  121. package/dist-lib/vendor/ws.cjs +1 -1
  122. package/dist-lib/vendor/zod.cjs +1 -1
  123. package/dist-lib/worklet-executable.cjs +1 -1
  124. package/dist-lib/worklet-executable.mjs +3 -3
  125. package/kotlin/sdk.tar.gz +0 -0
  126. package/package.json +1 -1
  127. package/src/binaryen.lock.json +3 -3
  128. package/src/one-native-controls-package.ts +95 -10
  129. package/src/one-sdk-preparation.ts +40 -2
  130. package/src/swift-guest-compile.ts +11 -2
  131. package/src/swift-guest-projection-storage.ts +45 -26
  132. package/src/swift-guest-runtime-plan.ts +1 -1
  133. package/src/swift-sdk-app-module.ts +15 -6
  134. package/src/swift-sdk-image-wasm.ts +5 -2
  135. package/src/swift-sdk-image.ts +69 -49
  136. package/src/swift-wasm-prune.ts +51 -34
  137. package/src/wasm-optimize.ts +146 -140
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.2592 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.2593 | (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;
@@ -26249,13 +26249,13 @@ var init_swift_standin_digest = __esm({
26249
26249
  STANDIN_DIGEST_ENTRYPOINTS = ["swift-standins.ts", "swift-objc-compile.ts"];
26250
26250
  SPECIFIER = /from\s*['"]([^'"]+)['"]|import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
26251
26251
  standinSourceDigest = (srcDir = __sootsim_import_meta_dirname) => sourceClosureDigest(srcDir, STANDIN_DIGEST_ENTRYPOINTS);
26252
- STANDIN_SOURCE_DIGEST = true ? "b7465e4180ef2be70330a5488deb331c0846752c0495581fcd000574c0aa480a" : standinSourceDigest();
26252
+ STANDIN_SOURCE_DIGEST = true ? "63adfed92cb0f03f7e74bd25588e866da41eaddd5ff8c13d50802edd65706617" : standinSourceDigest();
26253
26253
  }
26254
26254
  });
26255
26255
 
26256
26256
  // src/expo-native-compiler-digest.ts
26257
26257
  function expoNativeCompilerDigestValue() {
26258
- return true ? "6dd152b897024269db5b53a1f9c613429fd3fd15506a4914a77c3b2638fe2018" : expoNativeCompilerDigest(__sootsim_import_meta_dirname);
26258
+ return true ? "f789d146b1dafe1d68a49954dc5d223e9c982fc7b6602945b530568758babb0a" : expoNativeCompilerDigest(__sootsim_import_meta_dirname);
26259
26259
  }
26260
26260
  var import_node_crypto17;
26261
26261
  var init_expo_native_compiler_digest = __esm({
@@ -26698,7 +26698,9 @@ async function selectOneSDK(appRoot) {
26698
26698
  const imports2 = /* @__PURE__ */ new Set();
26699
26699
  const skipped = /* @__PURE__ */ new Set(["node_modules", "ios", "android", "dist", "build", "types"]);
26700
26700
  async function scan3(directory2) {
26701
+ if (imports2.has("one")) return;
26701
26702
  for (const entry of import_node_fs36.default.readdirSync(directory2, { withFileTypes: true })) {
26703
+ if (imports2.has("one")) return;
26702
26704
  if (entry.name.startsWith(".") || skipped.has(entry.name)) continue;
26703
26705
  const file = import_node_path35.default.join(directory2, entry.name);
26704
26706
  if (entry.isDirectory()) await scan3(file);
@@ -26712,8 +26714,10 @@ async function selectOneSDK(appRoot) {
26712
26714
  });
26713
26715
  for (const match of code.matchAll(
26714
26716
  /(?:\bfrom\s*|\bimport\s*\(?\s*|\brequire\s*\(\s*)['"](one(?:\/ios\/[A-Za-z_][A-Za-z0-9_]*)?)(?:\/[^'"]*)?['"]/g
26715
- ))
26717
+ )) {
26716
26718
  imports2.add(match[1]);
26719
+ if (match[1] === "one") return;
26720
+ }
26717
26721
  }
26718
26722
  }
26719
26723
  }
@@ -26779,6 +26783,22 @@ async function prepareOneSDKSources(appRoot, output) {
26779
26783
  import_node_fs36.default.copyFileSync(import_node_path35.default.join(published2, name3), import_node_path35.default.join(directory2, name3));
26780
26784
  return;
26781
26785
  }
26786
+ const localCache = import_node_path35.default.join(swiftCacheDir(), "one-sdk-sources", entry.key);
26787
+ const localManifestPath = import_node_path35.default.join(localCache, "manifest.json");
26788
+ if (import_node_fs36.default.existsSync(localManifestPath)) {
26789
+ const manifest2 = readOneSDKSourceManifest(
26790
+ JSON.parse(import_node_fs36.default.readFileSync(localManifestPath, "utf8"))
26791
+ );
26792
+ if (manifest2.generation === generation && JSON.stringify(manifest2.frameworks) === JSON.stringify(selected.frameworks) && selected.frameworks.every(
26793
+ (name3) => manifest2.selection[name3] === selected.selection[name3]
26794
+ ) && manifest2.files.every((name3) => import_node_fs36.default.existsSync(import_node_path35.default.join(localCache, name3)))) {
26795
+ import_node_fs36.default.rmSync(directory2, { recursive: true, force: true });
26796
+ import_node_fs36.default.mkdirSync(directory2, { recursive: true });
26797
+ for (const name3 of [...manifest2.files, "manifest.json"])
26798
+ import_node_fs36.default.copyFileSync(import_node_path35.default.join(localCache, name3), import_node_path35.default.join(directory2, name3));
26799
+ return;
26800
+ }
26801
+ }
26782
26802
  const generated = await generateAppSdkInChild(
26783
26803
  import_node_path35.default.join(selected.one, "dist/sdk/app.mjs"),
26784
26804
  selected.frameworks,
@@ -26796,7 +26816,19 @@ async function prepareOneSDKSources(appRoot, output) {
26796
26816
  selection: selected.selection,
26797
26817
  files: [...generated.files.keys()]
26798
26818
  };
26799
- import_node_fs36.default.writeFileSync(import_node_path35.default.join(directory2, "manifest.json"), JSON.stringify(manifest));
26819
+ const manifestJson = JSON.stringify(manifest);
26820
+ import_node_fs36.default.writeFileSync(import_node_path35.default.join(directory2, "manifest.json"), manifestJson);
26821
+ import_node_fs36.default.mkdirSync(import_node_path35.default.dirname(localCache), { recursive: true });
26822
+ const staging = import_node_fs36.default.mkdtempSync(`${localCache}.tmp-`);
26823
+ try {
26824
+ for (const [name3, from] of generated.files)
26825
+ import_node_fs36.default.copyFileSync(from, import_node_path35.default.join(staging, name3));
26826
+ import_node_fs36.default.writeFileSync(import_node_path35.default.join(staging, "manifest.json"), manifestJson);
26827
+ import_node_fs36.default.renameSync(staging, localCache);
26828
+ } catch (error) {
26829
+ import_node_fs36.default.rmSync(staging, { recursive: true, force: true });
26830
+ if (!import_node_fs36.default.existsSync(localManifestPath)) throw error;
26831
+ }
26800
26832
  }
26801
26833
  var import_node_child_process18, import_node_crypto19, import_node_fs36, import_node_module7, import_node_os8, import_node_path35, import_node_url2, import_sucrase2, GENERATE_SCRIPT;
26802
26834
  var init_one_sdk_preparation = __esm({
@@ -26812,6 +26844,7 @@ var init_one_sdk_preparation = __esm({
26812
26844
  import_sucrase2 = require("peachsim/vendor/sucrase");
26813
26845
  init_native_prebuilt();
26814
26846
  init_oneSdkContract();
26847
+ init_swift_toolchain();
26815
26848
  GENERATE_SCRIPT = `
26816
26849
  import { writeFileSync } from 'node:fs'
26817
26850
  import { pathToFileURL } from 'node:url'
@@ -31843,6 +31876,7 @@ var init_swiftSdkLinkContract = __esm({
31843
31876
 
31844
31877
  // src/swift-sdk-image-wasm.ts
31845
31878
  function wasmReader(bytes, start) {
31879
+ const rawBuf = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
31846
31880
  let at = start;
31847
31881
  const u = () => {
31848
31882
  let value = 0;
@@ -31871,7 +31905,7 @@ function wasmReader(bytes, start) {
31871
31905
  name: () => {
31872
31906
  const length = u();
31873
31907
  at += length;
31874
- return Buffer.from(bytes.subarray(at - length, at)).toString();
31908
+ return rawBuf.toString("utf8", at - length, at);
31875
31909
  },
31876
31910
  skip: (length) => {
31877
31911
  at += length;
@@ -32225,7 +32259,7 @@ function codeOnlySdkImage(bytes, constructorMask) {
32225
32259
  const bodies = m.bodies.map(({ start, end }) => bytes.subarray(start, end));
32226
32260
  const initMemory = functionIndex("__wasm_init_memory") - m.importedFuncs;
32227
32261
  {
32228
- const body = Uint8Array.from(bodies[initMemory]);
32262
+ const body = new Uint8Array(bodies[initMemory]);
32229
32263
  const r = wasmReader(body, 0);
32230
32264
  if (r.u() !== 0) throw new Error("sdk memory initializer has locals");
32231
32265
  while (r.at < body.length) {
@@ -33261,7 +33295,18 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
33261
33295
  dataOwnerSymIdx[kept] = ownerSymIdx;
33262
33296
  kept++;
33263
33297
  }
33264
- const dataRelocs = {
33298
+ const dataRelocs = kept === rawData.count ? {
33299
+ count: kept,
33300
+ bytes: rawData.bytes,
33301
+ start: rawData.start,
33302
+ end: rawData.end,
33303
+ ro: rawData.ro,
33304
+ rs: rawData.rs,
33305
+ addend: rawData.addend,
33306
+ segIdx: dataSegIdx,
33307
+ offInSeg: dataOffInSeg,
33308
+ ownerSymIdx: dataOwnerSymIdx
33309
+ } : {
33265
33310
  count: kept,
33266
33311
  bytes: rawData.bytes,
33267
33312
  start: rawData.start.slice(0, kept),
@@ -33273,26 +33318,29 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
33273
33318
  offInSeg: dataOffInSeg.slice(0, kept),
33274
33319
  ownerSymIdx: dataOwnerSymIdx.slice(0, kept)
33275
33320
  };
33276
- const relocatedWords = /* @__PURE__ */ new Map();
33277
- for (let i = 0; i < dataRelocs.count; i++) {
33278
- const segIdx = dataRelocs.segIdx[i];
33279
- let words2 = relocatedWords.get(segIdx);
33280
- if (!words2) relocatedWords.set(segIdx, words2 = /* @__PURE__ */ new Set());
33281
- words2.add(dataRelocs.offInSeg[i]);
33282
- }
33283
- for (const [segIdx, tops] of segTopSyms) {
33284
- const starts = new Map(tops.map((top) => [top.off, top.symIdx]));
33285
- const relocated = relocatedWords.get(segIdx);
33286
- const payload = dataStart + sPayloadStarts[segIdx];
33287
- const view = new DataView(buf.buffer, buf.byteOffset + payload);
33288
- for (const top of tops) {
33289
- for (let at = top.off; at + 4 <= top.end; at += 4) {
33290
- if (relocated?.has(at)) continue;
33291
- const target = starts.get(at + (view.getInt32(at, true) & ~3));
33292
- if (target === void 0 || target === top.symIdx) continue;
33293
- let list2 = symDataRelocs.get(top.symIdx);
33294
- if (!list2) symDataRelocs.set(top.symIdx, list2 = []);
33295
- list2.push(target);
33321
+ if (segTopSyms.size > 0) {
33322
+ const relocatedWords = /* @__PURE__ */ new Map();
33323
+ for (let i = 0; i < dataRelocs.count; i++) {
33324
+ const segIdx = dataRelocs.segIdx[i];
33325
+ if (!segTopSyms.has(segIdx)) continue;
33326
+ let words2 = relocatedWords.get(segIdx);
33327
+ if (!words2) relocatedWords.set(segIdx, words2 = /* @__PURE__ */ new Set());
33328
+ words2.add(dataRelocs.offInSeg[i]);
33329
+ }
33330
+ for (const [segIdx, tops] of segTopSyms) {
33331
+ const starts = new Map(tops.map((top) => [top.off, top.symIdx]));
33332
+ const relocated = relocatedWords.get(segIdx);
33333
+ const payload = dataStart + sPayloadStarts[segIdx];
33334
+ const view = new DataView(buf.buffer, buf.byteOffset + payload);
33335
+ for (const top of tops) {
33336
+ for (let at = top.off; at + 4 <= top.end; at += 4) {
33337
+ if (relocated?.has(at)) continue;
33338
+ const target = starts.get(at + (view.getInt32(at, true) & ~3));
33339
+ if (target === void 0 || target === top.symIdx) continue;
33340
+ let list2 = symDataRelocs.get(top.symIdx);
33341
+ if (!list2) symDataRelocs.set(top.symIdx, list2 = []);
33342
+ list2.push(target);
33343
+ }
33296
33344
  }
33297
33345
  }
33298
33346
  }
@@ -33464,7 +33512,7 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
33464
33512
  };
33465
33513
  }
33466
33514
  function parseWasmObjectFile(file, isDist) {
33467
- return parseWasmObjectBytes(file, new Uint8Array(import_node_fs44.default.readFileSync(file)), isDist);
33515
+ return parseWasmObjectBytes(file, import_node_fs44.default.readFileSync(file), isDist);
33468
33516
  }
33469
33517
  function parseWasmObjectCached(file, isDist, entries2) {
33470
33518
  const key2 = `${isDist ? "1" : "0"}:${file}`;
@@ -33479,7 +33527,7 @@ function parseWasmObjectCached(file, isDist, entries2) {
33479
33527
  function localizeDefinedWasmSymbols(bytes, names) {
33480
33528
  const offsets = [];
33481
33529
  const object8 = parseWasmObjectBytes("", bytes, false, offsets);
33482
- const output = Uint8Array.from(bytes);
33530
+ const output = new Uint8Array(bytes);
33483
33531
  let changed = 0;
33484
33532
  for (let index = 0; index < object8.symNames.length; index++) {
33485
33533
  if (!names.has(object8.symNames[index])) continue;
@@ -36657,18 +36705,6 @@ function readWasmMemoryAndTableImports(bytes, layout2) {
36657
36705
  }
36658
36706
  return { memory, tableImports };
36659
36707
  }
36660
- function hasWasmExport(bytes, name3) {
36661
- const section2 = wasmSections2(bytes).find((value) => value.id === 7);
36662
- if (!section2) return false;
36663
- const input = readWasmSection(bytes, section2.start, section2.end);
36664
- for (let count = input.number(); count > 0; count--) {
36665
- const found = input.name();
36666
- input.byte();
36667
- input.number();
36668
- if (found === name3) return true;
36669
- }
36670
- return false;
36671
- }
36672
36708
  function withSections(bytes, layout2, replacements) {
36673
36709
  const parts = [bytes.subarray(0, 8)];
36674
36710
  let at = 8;
@@ -37402,23 +37438,40 @@ function reserveGuestProjectionStorage(images, capacities) {
37402
37438
  };
37403
37439
  }
37404
37440
  function mergeGuestProjectionSpans(imageCount, spans) {
37405
- const sorted2 = [...spans].sort(
37406
- (a, b) => a.space.localeCompare(b.space) || a.address - b.address || a.image - b.image
37407
- );
37408
- const merged = [];
37409
- for (const span of sorted2) {
37441
+ const tableSpans = [];
37442
+ const memorySpans = [];
37443
+ for (const span of spans) {
37410
37444
  if (!Number.isInteger(span.image) || span.image < 0 || span.image >= imageCount || !Number.isInteger(span.address) || !Number.isInteger(span.length) || span.address < 0 || span.length <= 0 || span.address + span.length > 4294967296)
37411
37445
  throw new Error("invalid linked guest span");
37412
- const previous = merged[merged.length - 1];
37413
- if (previous && previous.space === span.space && span.address < previous.address + previous.length && previous.image !== span.image)
37414
- throw new Error("linked guest span has ambiguous image ownership");
37415
- if (previous && previous.space === span.space && previous.image === span.image && span.address <= previous.address + previous.length) {
37416
- merged[merged.length - 1] = {
37417
- ...previous,
37418
- length: Math.max(previous.address + previous.length, span.address + span.length) - previous.address
37419
- };
37420
- } else merged.push(span);
37446
+ if (span.space === "function-table") tableSpans.push(span);
37447
+ else memorySpans.push(span);
37421
37448
  }
37449
+ const byAddress = (a, b) => a.address - b.address || a.image - b.image;
37450
+ tableSpans.sort(byAddress);
37451
+ memorySpans.sort(byAddress);
37452
+ const merged = [];
37453
+ const mergeGroup = (group) => {
37454
+ let previous = null;
37455
+ for (const span of group) {
37456
+ if (previous && span.address < previous.address + previous.length && previous.image !== span.image)
37457
+ throw new Error("linked guest span has ambiguous image ownership");
37458
+ if (previous && previous.image === span.image && span.address <= previous.address + previous.length) {
37459
+ const end = span.address + span.length;
37460
+ if (end > previous.address + previous.length)
37461
+ previous.length = end - previous.address;
37462
+ } else {
37463
+ previous = {
37464
+ image: span.image,
37465
+ space: span.space,
37466
+ address: span.address,
37467
+ length: span.length
37468
+ };
37469
+ merged.push(previous);
37470
+ }
37471
+ }
37472
+ };
37473
+ mergeGroup(tableSpans);
37474
+ mergeGroup(memorySpans);
37422
37475
  return merged;
37423
37476
  }
37424
37477
  function guestProjectionRegionCounts(imageCount, spans) {
@@ -37614,7 +37667,7 @@ function sdkArtifactBytes(root, artifact) {
37614
37667
  const source = (0, import_node_fs47.readFileSync)(import_node_path45.default.join(sourceDirectory, "libFoundation.a"));
37615
37668
  if (hash(source) !== artifact.sha256)
37616
37669
  throw new Error(`SDK product artifact changed ${file}`);
37617
- const transformed = Uint8Array.from(source);
37670
+ const transformed = new Uint8Array(source);
37618
37671
  weakenFoundationOverridesInArchive(transformed);
37619
37672
  if (!linked.equals(transformed))
37620
37673
  throw new Error(`SDK view transformation changed ${file}`);
@@ -38154,17 +38207,17 @@ var init_binaryen_lock = __esm({
38154
38207
  "linux-x64": {
38155
38208
  asset: "x86_64-linux",
38156
38209
  upstreamSha256: "195ddc94f9bc89f45abdabb0b9eea86023d727ba90eac8b35b80f2544fc30572",
38157
- sha256: "feda0b3a5a24c902ec25e8d674f33c5771a0704e611a2e8e4800ab3c3fc591ca"
38210
+ sha256: "1024974f254c1c2edd738246ec6af5add16d3d36b5f58a94545febda3b33c869"
38158
38211
  },
38159
38212
  "linux-arm64": {
38160
38213
  asset: "aarch64-linux",
38161
38214
  upstreamSha256: "c58562417836c5d0493d89bdefc434933bdc097db641b483df86bcfa557a107f",
38162
- sha256: "0c67b9f36e9337afddf13b5150ab0e30bddf4f58633b02c4604f0cc87c2b89a2"
38215
+ sha256: "7dedfc9f5cb32e75a28831f3b5aa053fd3e0bdd74f73dc4d1b1588947236daef"
38163
38216
  },
38164
38217
  "darwin-arm64": {
38165
38218
  asset: "arm64-macos",
38166
38219
  upstreamSha256: "98aad827847af7ef990ed7098d885725c8e5b5aae75073403635617ae4e259aa",
38167
- sha256: "36373d0901b376c2868f09e0c2c303b1b7117b696e31dd661afa9711f31ea4a0"
38220
+ sha256: "0b56e0a06b6a873877871537a120fd94e2121e67f4bce5f8b5252c47b615854a"
38168
38221
  }
38169
38222
  }
38170
38223
  };
@@ -38193,6 +38246,45 @@ var init_wasm_features = __esm({
38193
38246
  });
38194
38247
 
38195
38248
  // src/wasm-optimize.ts
38249
+ function readWasmMemoryFromFile(file) {
38250
+ const fd = (0, import_node_fs48.openSync)(file, "r");
38251
+ try {
38252
+ const total = (0, import_node_fs48.fstatSync)(fd).size;
38253
+ const header = Buffer.allocUnsafe(8);
38254
+ if (total < 8 || (0, import_node_fs48.readSync)(fd, header, 0, 8, 0) < 8) return void 0;
38255
+ let offset = 8;
38256
+ const probe = Buffer.allocUnsafe(16);
38257
+ let prefixEnd = 8;
38258
+ while (offset < total) {
38259
+ const read = (0, import_node_fs48.readSync)(fd, probe, 0, Math.min(16, total - offset), offset);
38260
+ if (read < 2) break;
38261
+ const id = probe[0];
38262
+ let size2 = 0;
38263
+ let shift = 0;
38264
+ let at = 1;
38265
+ for (; ; ) {
38266
+ const byte = probe[at++];
38267
+ size2 += (byte & 127) * 2 ** shift;
38268
+ if (!(byte & 128)) break;
38269
+ shift += 7;
38270
+ }
38271
+ const next = offset + at + size2;
38272
+ if (id === 2 || id === 5) prefixEnd = next;
38273
+ if (id > 5) break;
38274
+ offset = next;
38275
+ }
38276
+ const prefix = Buffer.allocUnsafe(prefixEnd);
38277
+ let filled = 0;
38278
+ while (filled < prefixEnd) {
38279
+ const n = (0, import_node_fs48.readSync)(fd, prefix, filled, prefixEnd - filled, filled);
38280
+ if (n <= 0) break;
38281
+ filled += n;
38282
+ }
38283
+ return readWasmMemory(prefix.subarray(0, filled));
38284
+ } finally {
38285
+ (0, import_node_fs48.closeSync)(fd);
38286
+ }
38287
+ }
38196
38288
  async function runWasmOpt(file, output, optimize, skipPasses, binary2, sdkTableEnd, wideExports) {
38197
38289
  const admittedCores = windowAdmission()?.cores ?? Number(process.env.TM_EXEC_CPU_CORES);
38198
38290
  const requestedCores = Number(process.env.BINARYEN_CORES);
@@ -38209,25 +38301,75 @@ async function runWasmOpt(file, output, optimize, skipPasses, binary2, sdkTableE
38209
38301
  return;
38210
38302
  }
38211
38303
  const optimizeSize = optimize === true || optimize === "app-module";
38212
- const optimizeBeforeGuard = optimize === true;
38213
38304
  const relink = optimize === "relink";
38214
- const names = optimizeBeforeGuard && !KEEP_WASM_NAMES ? [] : ["-g"];
38215
- const outputNames = (optimizeSize || relink) && !KEEP_WASM_NAMES ? [] : names;
38216
- let input = (0, import_node_fs48.readFileSync)(file);
38217
- const memory = readWasmMemory(input);
38218
- const checked = `${output}.stack-checked`;
38305
+ const keepNames = !optimizeSize && !relink || KEEP_WASM_NAMES;
38306
+ const memory = readWasmMemoryFromFile(file);
38219
38307
  if (memory?.shared && memory.maximumPages !== 65536)
38220
38308
  throw new Error("threaded native memory must declare a 65536-page maximum");
38221
- if (memory?.shared && optimizeBeforeGuard) {
38222
- await runBinaryen(binary2, [...features, "-g", "--stack-check", file, "-o", checked], {
38223
- env: environment
38224
- });
38225
- input = (0, import_node_fs48.readFileSync)(checked);
38226
- if (!hasWasmExport(input, "__set_stack_limits"))
38227
- throw new Error(
38228
- "threaded native artifact must retain its __stack_pointer name for bounds checks"
38309
+ if (memory?.shared) {
38310
+ const wideExportsFile = wideExports.size ? `${output}.wide-exports` : void 0;
38311
+ const tableTool = (0, import_node_path46.join)((0, import_node_path46.dirname)(binary2), "wasm-table-guard");
38312
+ try {
38313
+ if (wideExportsFile)
38314
+ (0, import_node_fs48.writeFileSync)(wideExportsFile, [...wideExports].join("\n") + "\n");
38315
+ const pipelineArgs = [
38316
+ "--pipeline",
38317
+ "--in",
38318
+ file,
38319
+ "--out",
38320
+ output,
38321
+ "--narrow",
38322
+ ...wideExportsFile ? ["--wide-exports-file", wideExportsFile] : [],
38323
+ "--lower",
38324
+ "--shared",
38325
+ ...keepNames ? ["--debug"] : [],
38326
+ ...sdkTableEnd !== void 0 ? ["--slots-range", "1", String(sdkTableEnd), "--adapt"] : [],
38327
+ ...optimizeSize ? ["--optimize", "oz"] : relink ? ["--optimize", "relink"] : [],
38328
+ ...skipPasses.flatMap((pass) => ["--skip-pass", pass])
38329
+ ];
38330
+ const { stdout } = await runBinaryen(tableTool, pipelineArgs, { env: environment });
38331
+ const metadata = JSON.parse(stdout);
38332
+ if (typeof metadata !== "object" || metadata === null || !("tableMinimum" in metadata) || typeof metadata.tableMinimum !== "number" || !Number.isSafeInteger(metadata.tableMinimum) || metadata.tableMinimum < 0)
38333
+ throw new Error("native table tool returned an invalid table minimum");
38334
+ const sectionName = new TextEncoder().encode(NATIVE_IMAGE_SECTION);
38335
+ const layout2 = new TextEncoder().encode(
38336
+ JSON.stringify({
38337
+ initialPages: memory.initialPages,
38338
+ tableMinimum: metadata.tableMinimum
38339
+ })
38340
+ );
38341
+ const encode = (value) => {
38342
+ const bytes2 = [];
38343
+ do {
38344
+ const byte = value & 127;
38345
+ value >>>= 7;
38346
+ bytes2.push(byte | (value ? 128 : 0));
38347
+ } while (value);
38348
+ return bytes2;
38349
+ };
38350
+ const body = new Uint8Array([
38351
+ ...encode(sectionName.length),
38352
+ ...sectionName,
38353
+ ...layout2
38354
+ ]);
38355
+ const bytes = (0, import_node_fs48.readFileSync)(output);
38356
+ (0, import_node_fs48.writeFileSync)(
38357
+ output,
38358
+ Buffer.concat([
38359
+ sdkTableEnd === void 0 ? withWasmTableMinimum(
38360
+ bytes,
38361
+ metadata.tableMinimum + NATIVE_TABLE_RESERVE_SLOTS
38362
+ ) : bytes,
38363
+ Buffer.from([0, ...encode(body.length), ...body])
38364
+ ])
38229
38365
  );
38366
+ } finally {
38367
+ if (wideExportsFile) (0, import_node_fs48.rmSync)(wideExportsFile, { force: true });
38368
+ }
38369
+ return;
38230
38370
  }
38371
+ const outputNames = keepNames ? ["-g"] : [];
38372
+ const input = (0, import_node_fs48.readFileSync)(file);
38231
38373
  const narrowed = narrowWasmBoundary(input, wideExports);
38232
38374
  const merged = `${output}.narrowed`;
38233
38375
  if (narrowed) {
@@ -38239,7 +38381,7 @@ async function runWasmOpt(file, output, optimize, skipPasses, binary2, sdkTableE
38239
38381
  (0, import_node_path46.join)((0, import_node_path46.dirname)(binary2), "wasm-merge"),
38240
38382
  [
38241
38383
  ...features,
38242
- ...names,
38384
+ ...outputNames,
38243
38385
  guest,
38244
38386
  NARROW_MERGE_NAMES.guest,
38245
38387
  thunks,
@@ -38253,118 +38395,25 @@ async function runWasmOpt(file, output, optimize, skipPasses, binary2, sdkTableE
38253
38395
  (0, import_node_fs48.rmSync)(guest);
38254
38396
  (0, import_node_fs48.rmSync)(thunks);
38255
38397
  }
38256
- const lowered = memory?.shared ? `${output}.lowered` : output;
38257
- const compiled = narrowed ? merged : memory?.shared && optimizeBeforeGuard ? checked : file;
38398
+ const compiled = narrowed ? merged : file;
38258
38399
  const skip = skipPasses.flatMap((pass) => ["--skip-pass", pass]);
38259
38400
  try {
38260
- if (!memory?.shared || optimizeBeforeGuard)
38261
- await runBinaryen(
38262
- binary2,
38263
- [
38264
- ...LOWERING,
38265
- ...optimizeSize ? ["-Oz"] : relink ? RELINK_PASSES : [],
38266
- ...outputNames,
38267
- ...skip,
38268
- ...features,
38269
- compiled,
38270
- "-o",
38271
- lowered
38272
- ],
38273
- { env: environment, maxBuffer: Infinity }
38274
- );
38275
- if (memory?.shared) {
38276
- const guarded = `${output}.table.wasm`;
38277
- const sdkGuarded = `${output}.sdk-table.wasm`;
38278
- const sdkSlots = `${output}.sdk-table-slots`;
38279
- const tableTool = (0, import_node_path46.join)((0, import_node_path46.dirname)(binary2), "wasm-table-guard");
38280
- try {
38281
- const { stdout } = await runBinaryen(
38282
- tableTool,
38283
- [
38284
- optimizeBeforeGuard ? lowered : compiled,
38285
- guarded,
38286
- names.length ? "1" : "0",
38287
- ...optimizeBeforeGuard ? [] : ["lower"]
38288
- ],
38289
- { env: environment }
38290
- );
38291
- const metadata = JSON.parse(stdout);
38292
- if (typeof metadata !== "object" || metadata === null || !("tableMinimum" in metadata) || typeof metadata.tableMinimum !== "number" || !Number.isSafeInteger(metadata.tableMinimum) || metadata.tableMinimum < 0)
38293
- throw new Error("native table tool returned an invalid table minimum");
38294
- if (sdkTableEnd !== void 0) {
38295
- (0, import_node_fs48.writeFileSync)(
38296
- sdkSlots,
38297
- Array.from({ length: sdkTableEnd - 1 }, (_, index) => index + 1).join("\n")
38298
- );
38299
- await runBinaryen(
38300
- tableTool,
38301
- [guarded, sdkGuarded, names.length ? "1" : "0", "0", sdkSlots, "adapt"],
38302
- { env: environment }
38303
- );
38304
- (0, import_node_fs48.renameSync)(sdkGuarded, guarded);
38305
- }
38306
- if (optimize)
38307
- await runBinaryen(
38308
- binary2,
38309
- [
38310
- ...features,
38311
- // an adapted call tests its target's type with a typed function reference.
38312
- ...sdkTableEnd === void 0 ? [] : ["--enable-gc"],
38313
- ...optimizeSize ? ["-Oz"] : RELINK_PASSES,
38314
- ...outputNames,
38315
- ...skip,
38316
- guarded,
38317
- "-o",
38318
- output
38319
- ],
38320
- { env: environment }
38321
- );
38322
- const sectionName = new TextEncoder().encode(NATIVE_IMAGE_SECTION);
38323
- const layout2 = new TextEncoder().encode(
38324
- JSON.stringify({
38325
- initialPages: memory.initialPages,
38326
- tableMinimum: metadata.tableMinimum
38327
- })
38328
- );
38329
- const encode = (value) => {
38330
- const bytes2 = [];
38331
- do {
38332
- const byte = value & 127;
38333
- value >>>= 7;
38334
- bytes2.push(byte | (value ? 128 : 0));
38335
- } while (value);
38336
- return bytes2;
38337
- };
38338
- const body = new Uint8Array([
38339
- ...encode(sectionName.length),
38340
- ...sectionName,
38341
- ...layout2
38342
- ]);
38343
- const image = optimize ? output : guarded;
38344
- const bytes = (0, import_node_fs48.readFileSync)(image);
38345
- (0, import_node_fs48.writeFileSync)(
38346
- image,
38347
- Buffer.concat([
38348
- sdkTableEnd === void 0 ? withWasmTableMinimum(
38349
- bytes,
38350
- metadata.tableMinimum + NATIVE_TABLE_RESERVE_SLOTS
38351
- ) : bytes,
38352
- Buffer.from([0, ...encode(body.length), ...body])
38353
- ])
38354
- );
38355
- if (!optimize) (0, import_node_fs48.renameSync)(guarded, output);
38356
- } finally {
38357
- (0, import_node_fs48.rmSync)(guarded, { force: true });
38358
- (0, import_node_fs48.rmSync)(sdkGuarded, { force: true });
38359
- (0, import_node_fs48.rmSync)(sdkSlots, { force: true });
38360
- }
38361
- }
38401
+ await runBinaryen(
38402
+ binary2,
38403
+ [
38404
+ ...LOWERING,
38405
+ ...optimizeSize ? ["-Oz"] : relink ? RELINK_PASSES : [],
38406
+ ...outputNames,
38407
+ ...skip,
38408
+ ...features,
38409
+ compiled,
38410
+ "-o",
38411
+ output
38412
+ ],
38413
+ { env: environment, maxBuffer: Infinity }
38414
+ );
38362
38415
  } finally {
38363
38416
  if (narrowed) (0, import_node_fs48.rmSync)(merged, { force: true });
38364
- if (memory?.shared) {
38365
- (0, import_node_fs48.rmSync)(checked, { force: true });
38366
- (0, import_node_fs48.rmSync)(lowered, { force: true });
38367
- }
38368
38417
  }
38369
38418
  }
38370
38419
  async function installWasmOpt() {
@@ -43349,9 +43398,11 @@ async function linkSwiftSdkImage(moduleRoot, key2, directory2, work, scopedLooku
43349
43398
  objects.push({ path: object8, bytes, instrumentDynamicLookups: false });
43350
43399
  guestObjects.set(product, objects);
43351
43400
  };
43352
- const classifyFile = (file) => {
43401
+ const classifyFile = (file, collectAutolink = false) => {
43353
43402
  const bytes = (0, import_node_fs58.readFileSync)(file);
43354
43403
  if (!file.endsWith(".a")) {
43404
+ if (collectAutolink)
43405
+ for (const library of autolinkLibraries(bytes)) libraries.add(library);
43355
43406
  const scoped = lookups2?.rewrite(file, bytes) ?? bytes;
43356
43407
  return addObject(file, scoped, file);
43357
43408
  }
@@ -43359,6 +43410,8 @@ async function linkSwiftSdkImage(moduleRoot, key2, directory2, work, scopedLooku
43359
43410
  (0, import_node_fs58.mkdirSync)(import_node_path56.default.join(members2, archive));
43360
43411
  const ordinals = /* @__PURE__ */ new Map();
43361
43412
  readArMembers(bytes).forEach((member, index) => {
43413
+ if (collectAutolink)
43414
+ for (const library of autolinkLibraries(member.bytes)) libraries.add(library);
43362
43415
  const object8 = import_node_path56.default.join(members2, archive, `${index}-${import_node_path56.default.basename(member.name)}`);
43363
43416
  const ordinal = (ordinals.get(member.name) ?? 0) + 1;
43364
43417
  ordinals.set(member.name, ordinal);
@@ -43373,9 +43426,7 @@ async function linkSwiftSdkImage(moduleRoot, key2, directory2, work, scopedLooku
43373
43426
  });
43374
43427
  };
43375
43428
  for (const object8 of [...link.objects, ...link.providers]) {
43376
- classifyFile(object8);
43377
- for (const bytes of objectMembers(object8))
43378
- for (const library of autolinkLibraries(bytes)) libraries.add(library);
43429
+ classifyFile(object8, true);
43379
43430
  }
43380
43431
  for (const library of libraries) {
43381
43432
  if (unpacked.has(library.slice(2))) continue;
@@ -43388,6 +43439,7 @@ async function linkSwiftSdkImage(moduleRoot, key2, directory2, work, scopedLooku
43388
43439
  const hostExports = sdkHostExports(appRoot);
43389
43440
  const guestMap = /* @__PURE__ */ new Map();
43390
43441
  const guestMetadataNames = {};
43442
+ const compiles = [];
43391
43443
  if (lookups2) {
43392
43444
  const ledger = lookups2.link(guestObjects, [
43393
43445
  ...hostExports,
@@ -43423,33 +43475,38 @@ async function linkSwiftSdkImage(moduleRoot, key2, directory2, work, scopedLooku
43423
43475
  const scopeLedger = import_node_path56.default.join(work, "guest-ledger.ll");
43424
43476
  const scopeObject = import_node_path56.default.join(work, "guest-ledger.o");
43425
43477
  (0, import_node_fs58.writeFileSync)(scopeLedger, ledger.llvmIR);
43426
- await run4(import_node_path56.default.join(toolchain.toolchainBin, "clang"), [
43427
- `--target=${SWIFT_WASM_TRIPLE}`,
43428
- "-matomics",
43429
- "-mbulk-memory",
43430
- "-c",
43431
- scopeLedger,
43432
- "-o",
43433
- scopeObject
43434
- ]);
43478
+ compiles.push(
43479
+ run4(import_node_path56.default.join(toolchain.toolchainBin, "clang"), [
43480
+ `--target=${SWIFT_WASM_TRIPLE}`,
43481
+ "-matomics",
43482
+ "-mbulk-memory",
43483
+ "-c",
43484
+ scopeLedger,
43485
+ "-o",
43486
+ scopeObject
43487
+ ])
43488
+ );
43435
43489
  eager.push(scopeObject);
43436
43490
  }
43437
43491
  (0, import_node_fs58.writeFileSync)(
43438
43492
  import_node_path56.default.join(work, "image-tables.c"),
43439
43493
  IMAGE_TABLES + (guestLookups?.source ?? "")
43440
43494
  );
43441
- await run4(import_node_path56.default.join(toolchain.toolchainBin, "clang"), [
43442
- `--target=${SWIFT_WASM_TRIPLE}`,
43443
- "-O2",
43444
- "-matomics",
43445
- "-mbulk-memory",
43446
- "-ffreestanding",
43447
- ...lookups2 ? ["-DPEACH_SDK_GUEST_LINK"] : [],
43448
- "-c",
43449
- import_node_path56.default.join(work, "image-tables.c"),
43450
- "-o",
43451
- tables
43452
- ]);
43495
+ compiles.push(
43496
+ run4(import_node_path56.default.join(toolchain.toolchainBin, "clang"), [
43497
+ `--target=${SWIFT_WASM_TRIPLE}`,
43498
+ "-O2",
43499
+ "-matomics",
43500
+ "-mbulk-memory",
43501
+ "-ffreestanding",
43502
+ ...lookups2 ? ["-DPEACH_SDK_GUEST_LINK"] : [],
43503
+ "-c",
43504
+ import_node_path56.default.join(work, "image-tables.c"),
43505
+ "-o",
43506
+ tables
43507
+ ])
43508
+ );
43509
+ await Promise.all(compiles);
43453
43510
  const quote3 = (value) => JSON.stringify(value);
43454
43511
  (0, import_node_fs58.writeFileSync)(
43455
43512
  import_node_path56.default.join(work, "exports.rsp"),
@@ -43508,23 +43565,31 @@ async function linkSwiftSdkImage(moduleRoot, key2, directory2, work, scopedLooku
43508
43565
  if (mask === void 0) throw new Error("sdk image lacks its constructor mask");
43509
43566
  const code = import_node_path56.default.join(work, "code.wasm");
43510
43567
  (0, import_node_fs58.writeFileSync)(code, codeOnlySdkImage(finished, mask));
43511
- await lowerWasm(code, import_node_path56.default.join(work, IMAGE_FILE), {
43568
+ const lowerPromise = lowerWasm(code, import_node_path56.default.join(work, IMAGE_FILE), {
43512
43569
  optimize: true,
43513
43570
  skipPasses: lookups2 ? ["duplicate-function-elimination"] : void 0
43514
43571
  });
43572
+ await new Promise((resolve3) => setImmediate(resolve3));
43573
+ try {
43574
+ writeSdkManifest(
43575
+ work,
43576
+ linkMap,
43577
+ linkedBytes,
43578
+ finished,
43579
+ (0, import_node_fs58.readFileSync)(withRelocs),
43580
+ functionSlots,
43581
+ lookups2 && { inputs: guestMap, metadataNames: guestMetadataNames }
43582
+ );
43583
+ } catch (error) {
43584
+ await lowerPromise.catch(() => {
43585
+ });
43586
+ throw error;
43587
+ }
43588
+ await lowerPromise;
43515
43589
  const image = (0, import_node_fs58.readFileSync)(import_node_path56.default.join(work, IMAGE_FILE));
43516
43590
  sdkInterface.layout.tableEnd += unslottedFunctions(image);
43517
43591
  if (sdkInterface.layout.tableEnd > SWIFT_SDK_APP_TABLE_BASE)
43518
43592
  throw new Error("Swift SDK image exceeds its reserved function table range");
43519
- writeSdkManifest(
43520
- work,
43521
- linkMap,
43522
- linkedBytes,
43523
- finished,
43524
- (0, import_node_fs58.readFileSync)(withRelocs),
43525
- functionSlots,
43526
- lookups2 && { inputs: guestMap, metadataNames: guestMetadataNames }
43527
- );
43528
43593
  (0, import_node_fs58.writeFileSync)(import_node_path56.default.join(work, INTERFACE_FILE), JSON.stringify(sdkInterface));
43529
43594
  (0, import_node_fs58.writeFileSync)(
43530
43595
  import_node_path56.default.join(work, IMAGE_DIGEST),
@@ -43593,14 +43658,11 @@ function sdkLinkInputs(appRoot) {
43593
43658
  if (!crt) throw new Error("the sdk image link found no reactor startup object");
43594
43659
  return { flags, libraries, objects: [crt, ...objects], providers };
43595
43660
  }
43596
- function objectMembers(file) {
43597
- const bytes = (0, import_node_fs58.readFileSync)(file);
43598
- return file.endsWith(".a") ? readArMembers(bytes).map((member) => member.bytes) : [bytes];
43599
- }
43600
43661
  function autolinkLibraries(bytes) {
43601
43662
  const entries2 = wasmSections(bytes).find((s) => s.name === ".swift1_autolink_entries");
43602
43663
  if (!entries2) return [];
43603
- return Buffer.from(bytes.subarray(entries2.start, entries2.end)).toString().split("\0").filter((entry) => entry.startsWith("-l"));
43664
+ const raw2 = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
43665
+ return raw2.toString("utf8", entries2.start, entries2.end).split("\0").filter((entry) => entry.startsWith("-l"));
43604
43666
  }
43605
43667
  function sdkHostExports(appRoot) {
43606
43668
  const release = import_node_path56.default.join(appRoot, ".build", SWIFT_WASM_TRIPLE, "release");
@@ -43686,9 +43748,17 @@ function writeSdkManifest(work, map2, linked, finished, withRelocs, functionSlot
43686
43748
  return { starts, targets };
43687
43749
  };
43688
43750
  const byAddress = (edges2) => {
43689
- const pairs2 = [];
43690
- for (let i = 0; i < edges2.length; i += 2) pairs2.push([edges2[i], edges2[i + 1]]);
43691
- return pairs2.sort((a, b) => a[0] - b[0]).flat();
43751
+ const count = edges2.length >>> 1;
43752
+ const order = new Uint32Array(count);
43753
+ for (let i = 0; i < count; i++) order[i] = i;
43754
+ order.sort((a, b) => edges2[a * 2] - edges2[b * 2]);
43755
+ const sorted2 = new Uint32Array(edges2.length);
43756
+ for (let i = 0; i < count; i++) {
43757
+ const src = order[i] * 2;
43758
+ sorted2[i * 2] = edges2[src];
43759
+ sorted2[i * 2 + 1] = edges2[src + 1];
43760
+ }
43761
+ return sorted2;
43692
43762
  };
43693
43763
  const functionData = flatten2(edges.code);
43694
43764
  const functionCalls = flatten2(edges.calls);
@@ -43992,12 +44062,22 @@ async function buildSwiftAppModule(options2) {
43992
44062
  work,
43993
44063
  readInput
43994
44064
  });
43995
- await link.lower();
43996
- const usage = readSwiftSdkUsage(
43997
- project ? projectOutputFile(buildRoot, map2, project) : map2,
43998
- pruned
43999
- );
44000
- const binding = createSwiftSdkBinding(link.linkage, sdk2, usage);
44065
+ const lowerPromise = link.lower();
44066
+ await new Promise((resolve3) => setImmediate(resolve3));
44067
+ let usage;
44068
+ let binding;
44069
+ try {
44070
+ usage = readSwiftSdkUsage(
44071
+ project ? projectOutputFile(buildRoot, map2, project) : map2,
44072
+ pruned
44073
+ );
44074
+ binding = createSwiftSdkBinding(link.linkage, sdk2, usage);
44075
+ } catch (error) {
44076
+ await lowerPromise.catch(() => {
44077
+ });
44078
+ throw error;
44079
+ }
44080
+ await lowerPromise;
44001
44081
  if (!project)
44002
44082
  writeSwiftSdkAppLink(import_node_path57.default.join(work, "app-link.json.gz"), {
44003
44083
  linkage: link.linkage,
@@ -45907,7 +45987,6 @@ async function compileGuestLink(options2) {
45907
45987
  bindingRows.set((address - values.address) / 8, value);
45908
45988
  } else data.push(address, size2, value);
45909
45989
  }
45910
- const binding = createSwiftSdkBinding2({ ...link.linkage, data }, sdk2, usage);
45911
45990
  const linked = (0, import_node_fs60.readFileSync)(
45912
45991
  project ? projectOutputFile(work, linkedModule, project) : linkedModule
45913
45992
  );
@@ -45932,7 +46011,17 @@ async function compileGuestLink(options2) {
45932
46011
  );
45933
46012
  continue;
45934
46013
  }
45935
- await link.lower();
46014
+ const lowerPromise = link.lower();
46015
+ await new Promise((resolve3) => setImmediate(resolve3));
46016
+ let binding;
46017
+ try {
46018
+ binding = createSwiftSdkBinding2({ ...link.linkage, data }, sdk2, usage);
46019
+ } catch (error) {
46020
+ await lowerPromise.catch(() => {
46021
+ });
46022
+ throw error;
46023
+ }
46024
+ await lowerPromise;
45936
46025
  const finalized = finalizeGuestProjectionStorage({
45937
46026
  map: map3,
45938
46027
  linked,
@@ -53659,7 +53748,7 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
53659
53748
  REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
53660
53749
  MULTI_MANIFEST_VERSION = 76;
53661
53750
  SWIFT_HEADER_PRODUCTS_TARGET = "PeachHeaderProducts";
53662
- compilerSourceDigest = true ? "57c5faa7bb7758647030422e32db0f4a53fbab724723e220c14fea1e41d2391e" : swiftCompilerSourceDigest2(__sootsim_import_meta_dirname);
53751
+ compilerSourceDigest = true ? "834b5c28c27bc5807cbb3c4eed5c44f7de81d47db3e3a8819bea6e6635689b24" : swiftCompilerSourceDigest2(__sootsim_import_meta_dirname);
53663
53752
  nativeCxxCompilerFlags = ["-fno-cxx-modules"];
53664
53753
  MODULE_MAP_RESPONSE_FILE_RUN = 16;
53665
53754
  cFlagArray = (flags) => JSON.stringify(withoutGlogModuleMap(flags));