peachsim 0.1.2778 → 0.1.2779

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 +294 -480
  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-RWBIRNWO.mjs → acorn-SCZ56W4Q.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-GSTHJQMW.mjs → chunk-6BNEOOBT.mjs} +114 -18
  28. package/dist-lib/esm-chunks/{chunk-KX7LV722.mjs → chunk-7VWBLM73.mjs} +1 -1
  29. package/dist-lib/esm-chunks/{chunk-IQSFMB4R.mjs → chunk-DX5V3733.mjs} +4 -4
  30. package/dist-lib/esm-chunks/{chunk-KBYVKTVK.mjs → chunk-E56EZ3QT.mjs} +3 -3
  31. package/dist-lib/esm-chunks/{chunk-EXU474NE.mjs → chunk-FNQXQNQK.mjs} +1 -1
  32. package/dist-lib/esm-chunks/{chunk-3WQANOYY.mjs → chunk-H2V3ZZTO.mjs} +1 -1
  33. package/dist-lib/esm-chunks/{chunk-5WASPTSS.mjs → chunk-H6JAFCAZ.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-VZ3NXXUC.mjs → chunk-HMFIO57I.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-6YHF4VYF.mjs → chunk-HWK2V6R4.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-LQVLXDRN.mjs → chunk-KAMO4C4X.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-5TIUTQ55.mjs → chunk-KFDP4372.mjs} +1 -1
  38. package/dist-lib/esm-chunks/{chunk-F3OPIKJC.mjs → chunk-KOULWLTF.mjs} +2 -2
  39. package/dist-lib/esm-chunks/{chunk-DLBUPWTI.mjs → chunk-LVEDBGWX.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-X25PQNNH.mjs → chunk-MJXJYVF5.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-QKTKE4OX.mjs → chunk-MK4VAM4G.mjs} +1 -1
  42. package/dist-lib/esm-chunks/{chunk-ZWOS2EDN.mjs → chunk-Q6XMYYNV.mjs} +118 -361
  43. package/dist-lib/esm-chunks/{chunk-K3ULPN2R.mjs → chunk-SFTGQN5D.mjs} +1 -1
  44. package/dist-lib/esm-chunks/{chunk-KLA74B7J.mjs → chunk-SM5MJSQP.mjs} +1 -1
  45. package/dist-lib/esm-chunks/{chunk-G7UJ4BAC.mjs → chunk-SNMGOZXQ.mjs} +1 -1
  46. package/dist-lib/esm-chunks/{chunk-MRIDS3GE.mjs → chunk-SZI5IZ76.mjs} +5 -5
  47. package/dist-lib/esm-chunks/{chunk-N2PEXZGL.mjs → chunk-T7DTXCV5.mjs} +1 -1
  48. package/dist-lib/esm-chunks/{chunk-ZDWMPXYI.mjs → chunk-UBM772FD.mjs} +1 -1
  49. package/dist-lib/esm-chunks/{chunk-QUVLFF6I.mjs → chunk-VJSHIZ7J.mjs} +1 -1
  50. package/dist-lib/esm-chunks/{chunk-3RPELUA2.mjs → chunk-Z42YJEC4.mjs} +6 -6
  51. package/dist-lib/esm-chunks/{metro-layout-parser-RRIZOLBE.mjs → metro-layout-parser-7S5M3EG6.mjs} +3 -3
  52. package/dist-lib/esm-chunks/{swift-package-prebuilt-EIZ7MCKR.mjs → swift-package-prebuilt-MJSFHIOP.mjs} +12 -12
  53. package/dist-lib/esm-chunks/{swift-sdk-app-module-S2LQ4OXD.mjs → swift-sdk-app-module-ZIN3LFLS.mjs} +47 -69
  54. package/dist-lib/esm-chunks/{swift-sdk-image-77FFUGXI.mjs → swift-sdk-image-MIWPBZEN.mjs} +16 -16
  55. package/dist-lib/esm-chunks/{swift-sdk-image-producer-XFSFUXQJ.mjs → swift-sdk-image-producer-OTH543HF.mjs} +5 -5
  56. package/dist-lib/expo-swift-bundle.cjs +294 -480
  57. package/dist-lib/expo-swift-metadata.cjs +1 -1
  58. package/dist-lib/expo-swift-metadata.mjs +7 -7
  59. package/dist-lib/home-paths.cjs +1 -1
  60. package/dist-lib/host/bridge-host.cjs +300 -486
  61. package/dist-lib/host/fetch-proxy-handler.cjs +22 -11
  62. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  63. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
  64. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  65. package/dist-lib/host/websocket-proxy.cjs +1 -1
  66. package/dist-lib/index.cjs +1 -1
  67. package/dist-lib/kotlin-host.cjs +1 -1
  68. package/dist-lib/menu.cjs +1 -1
  69. package/dist-lib/menu.mjs +3 -3
  70. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  71. package/dist-lib/metro-fingerprint-registry.mjs +3 -3
  72. package/dist-lib/metro-production-bundle.cjs +1 -1
  73. package/dist-lib/metro-production-bundle.mjs +4 -4
  74. package/dist-lib/native-app-identity-project.cjs +1 -1
  75. package/dist-lib/native-app-identity-project.mjs +15 -15
  76. package/dist-lib/native-app-identity.cjs +1 -1
  77. package/dist-lib/native-app-identity.mjs +6 -6
  78. package/dist-lib/native-firebase-metadata.cjs +1 -1
  79. package/dist-lib/native-firebase-metadata.mjs +3 -3
  80. package/dist-lib/pdfium-raster.cjs +1 -1
  81. package/dist-lib/pdfium-raster.mjs +2 -2
  82. package/dist-lib/plist.cjs +1 -1
  83. package/dist-lib/plist.mjs +3 -3
  84. package/dist-lib/profiles.cjs +1 -1
  85. package/dist-lib/public-brand.cjs +1 -1
  86. package/dist-lib/public-origins-lib-esm.json +86 -86
  87. package/dist-lib/public-origins-lib.json +70 -70
  88. package/dist-lib/react-native-host-modules.cjs +1 -1
  89. package/dist-lib/react-native-host-modules.mjs +2 -2
  90. package/dist-lib/reap-browser.cjs +1 -1
  91. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  92. package/dist-lib/sdk.cjs +1 -1
  93. package/dist-lib/sdk.mjs +8 -8
  94. package/dist-lib/skills.cjs +300 -486
  95. package/dist-lib/swift-compile.cjs +287 -465
  96. package/dist-lib/swift-compile.mjs +12 -12
  97. package/dist-lib/swift-package.cjs +1 -1
  98. package/dist-lib/swift-package.mjs +3 -3
  99. package/dist-lib/swift-submit.cjs +1 -1
  100. package/dist-lib/swift-submit.mjs +6 -6
  101. package/dist-lib/swift-svg-raster.cjs +1 -1
  102. package/dist-lib/swift-svg-raster.mjs +2 -2
  103. package/dist-lib/swift-toolchain.cjs +1 -1
  104. package/dist-lib/swift.cjs +1 -1
  105. package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
  106. package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
  107. package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
  108. package/dist-lib/vendor/acorn.cjs +1 -1
  109. package/dist-lib/vendor/magic-string.cjs +1 -1
  110. package/dist-lib/vendor/stream-json.cjs +1 -1
  111. package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
  112. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
  113. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
  114. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
  115. package/dist-lib/vendor/sucrase.cjs +1 -1
  116. package/dist-lib/vendor/terser.cjs +1 -1
  117. package/dist-lib/vendor/valibot.cjs +1 -1
  118. package/dist-lib/vendor/ws.cjs +1 -1
  119. package/dist-lib/vendor/zod.cjs +1 -1
  120. package/dist-lib/worklet-executable.cjs +1 -1
  121. package/dist-lib/worklet-executable.mjs +3 -3
  122. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +15 -2
  123. package/dist-types/packages/peach-engine/src/render-worker/worklet-wire.d.ts +10 -1
  124. package/package.json +1 -1
  125. package/src/swift-compiler-digest.ts +1 -0
  126. package/src/swift-guest-dyld-functions.ts +1 -11
  127. package/src/swift-guest-dyld-table.ts +2 -9
  128. package/src/swift-guest-image-ledger.ts +9 -35
  129. package/src/swift-guest-source-inputs.ts +5 -22
  130. package/src/swift-icu.ts +15 -28
  131. package/src/swift-link-roots.ts +4 -8
  132. package/src/swift-sdk-app-module.ts +5 -27
  133. package/src/swift-sdk-image-wasm.ts +12 -41
  134. package/src/swift-shared-sdk.ts +1 -13
  135. package/src/swift-wasm-archive.ts +6 -11
  136. package/src/swift-wasm-prune.ts +22 -100
  137. package/src/wasm-binary-sections.ts +61 -7
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.2778 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.2779 | (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;
@@ -36021,7 +36021,7 @@ var init_swift_objc_sdk_tree = __esm({
36021
36021
 
36022
36022
  // src/swift-compiler-digest.ts
36023
36023
  function swiftArchiveCompilerDigestValue() {
36024
- return true ? "faa13b0ae0340e03d058b765e659f5e07b69f8e94793bf99981b3da7ca3bf2bd" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname, "archive");
36024
+ return true ? "b4b2fc7face997792991900efb229414642f042031ba789c00a1d17e542756e3" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname, "archive");
36025
36025
  }
36026
36026
  var import_node_crypto11, import_node_fs27, import_node_path25, SWIFT_DIGEST_SOURCES, LINKED_IMAGE_SOURCES, SWIFT_ARCHIVE_DIGEST_SOURCES;
36027
36027
  var init_swift_compiler_digest = __esm({
@@ -36050,6 +36050,7 @@ var init_swift_compiler_digest = __esm({
36050
36050
  "swift-objc-prebuilt-catalog.ts",
36051
36051
  "swift-toolchain.ts",
36052
36052
  "swift-shared-sdk.ts",
36053
+ "wasm-binary-sections.ts",
36053
36054
  "swift-distribution-mirror.ts",
36054
36055
  "swift-design-time.ts",
36055
36056
  "binaryen.lock.json",
@@ -36167,13 +36168,13 @@ var init_swift_standin_digest = __esm({
36167
36168
  ];
36168
36169
  RUNTIME_IMPORT = /(?:^|[;\n])[ \t]*(?:import|export)\s+(?!type(?:\s|\{))([\s\S]*?)\s+from\s*['"]([^'"]+)['"]|(?:^|[;\n])[ \t]*import\s+['"]([^'"]+)['"]|import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
36169
36170
  standinSourceDigest = (srcDir = __sootsim_import_meta_dirname) => sourceClosureDigest(srcDir, STANDIN_DIGEST_ENTRYPOINTS, STANDIN_DIGEST_EXCLUDED_FILES);
36170
- STANDIN_SOURCE_DIGEST = true ? "b6aa8eda1952d06a101c0a46227f227fb983255bb2a5f825515d7b9bc6f8650d" : standinSourceDigest();
36171
+ STANDIN_SOURCE_DIGEST = true ? "6f991ca933bc6ae43f06c18cb2029ff3209de583afa4457105e7452437c20f01" : standinSourceDigest();
36171
36172
  }
36172
36173
  });
36173
36174
 
36174
36175
  // src/expo-native-compiler-digest.ts
36175
36176
  function expoNativeCompilerDigestValue() {
36176
- return true ? "d396bac9636107aeb95f7657c77fa10e270f50f4ac8935e007b088b2ef65dfc8" : expoNativeCompilerDigest(__sootsim_import_meta_dirname);
36177
+ return true ? "5217c97f9f40e75420d8af715a312e49984d9ec52582e3c5d6209439c3cb70f4" : expoNativeCompilerDigest(__sootsim_import_meta_dirname);
36177
36178
  }
36178
36179
  var import_node_crypto13;
36179
36180
  var init_expo_native_compiler_digest = __esm({
@@ -58441,6 +58442,111 @@ var init_swift_objc_runtime = __esm({
58441
58442
  }
58442
58443
  });
58443
58444
 
58445
+ // src/wasm-binary-sections.ts
58446
+ function encodeWasmNumber(value) {
58447
+ const bytes = [];
58448
+ for (let rest = value; ; ) {
58449
+ const byte = rest % 128;
58450
+ rest = Math.floor(rest / 128);
58451
+ if (rest === 0) return [...bytes, byte];
58452
+ bytes.push(byte | 128);
58453
+ }
58454
+ }
58455
+ function encodeWasmSigned(value) {
58456
+ const out = [];
58457
+ for (; ; ) {
58458
+ const byte = Number(value & 127n);
58459
+ value >>= 7n;
58460
+ if (value === 0n && !(byte & 64) || value === -1n && byte & 64) {
58461
+ out.push(byte);
58462
+ return out;
58463
+ }
58464
+ out.push(byte | 128);
58465
+ }
58466
+ }
58467
+ function encodeWasmName(name3) {
58468
+ const bytes = new TextEncoder().encode(name3);
58469
+ return [...encodeWasmNumber(bytes.length), ...bytes];
58470
+ }
58471
+ function readULEB(bytes, offset, end = bytes.length) {
58472
+ if (offset < end) {
58473
+ const first = bytes[offset];
58474
+ if (first < 128) return [first, offset + 1];
58475
+ }
58476
+ let value = 0;
58477
+ for (let shift = 0; ; shift += 7) {
58478
+ if (offset >= end || shift > 63) throw new Error("invalid wasm integer");
58479
+ const byte = bytes[offset++];
58480
+ value += (byte & 127) * 2 ** shift;
58481
+ if (!(byte & 128)) return [value, offset];
58482
+ }
58483
+ }
58484
+ function readSLEB(bytes, offset, end = bytes.length) {
58485
+ let value = 0n;
58486
+ let shift = 0n;
58487
+ let byte = 0;
58488
+ do {
58489
+ if (offset >= end || shift > 70n) throw new Error("invalid wasm integer");
58490
+ byte = bytes[offset++];
58491
+ value |= BigInt(byte & 127) << shift;
58492
+ shift += 7n;
58493
+ } while (byte & 128);
58494
+ if (byte & 64) value -= 1n << shift;
58495
+ return [value, offset];
58496
+ }
58497
+ function skipLEB(bytes, offset) {
58498
+ while ((bytes[offset++] & 128) !== 0) {
58499
+ }
58500
+ return offset;
58501
+ }
58502
+ function readWasmSection(bytes, start, end) {
58503
+ let at = start;
58504
+ const number4 = () => {
58505
+ const [value, next] = readULEB(bytes, at, end);
58506
+ at = next;
58507
+ return value;
58508
+ };
58509
+ return {
58510
+ number: number4,
58511
+ byte: () => {
58512
+ if (at >= end) throw new Error("truncated wasm section");
58513
+ return bytes[at++];
58514
+ },
58515
+ name: () => {
58516
+ const length = number4();
58517
+ at += length;
58518
+ if (at > end) throw new Error("truncated wasm name");
58519
+ return Buffer.from(bytes.buffer, bytes.byteOffset + at - length, length).toString();
58520
+ },
58521
+ skip: (length) => {
58522
+ at += length;
58523
+ if (at > end) throw new Error("truncated wasm section");
58524
+ },
58525
+ position: () => at,
58526
+ done: () => at === end
58527
+ };
58528
+ }
58529
+ function wasmSections(bytes) {
58530
+ if (Buffer.from(bytes.subarray(0, 8)).toString("hex") !== "0061736d01000000")
58531
+ throw new Error("not a wasm module");
58532
+ const found2 = [];
58533
+ for (let at = 8; at < bytes.length; ) {
58534
+ const header = readWasmSection(bytes, at, bytes.length);
58535
+ const id = header.byte();
58536
+ const size2 = header.number();
58537
+ const start = header.position();
58538
+ if (start + size2 > bytes.length) throw new Error("truncated wasm section");
58539
+ found2.push({ id, offset: at, start, end: start + size2 });
58540
+ at = start + size2;
58541
+ }
58542
+ return found2;
58543
+ }
58544
+ var init_wasm_binary_sections = __esm({
58545
+ "src/wasm-binary-sections.ts"() {
58546
+ "use strict";
58547
+ }
58548
+ });
58549
+
58444
58550
  // src/swift-shared-sdk.ts
58445
58551
  function swiftSharedSdkSourceRoot(moduleRoot, distribution) {
58446
58552
  return import_node_path53.default.resolve(moduleRoot, distribution ? "sdk/ios" : "../peachsim/sdk/ios");
@@ -58491,18 +58597,6 @@ function swiftSharedSdkFlags(moduleRoot, distribution) {
58491
58597
  import_node_path53.default.join(root, "usr/include")
58492
58598
  ];
58493
58599
  }
58494
- function readULEB(b, o) {
58495
- let res = 0;
58496
- let shift = 0;
58497
- let p = o;
58498
- while (true) {
58499
- const byte = b[p++];
58500
- res |= (byte & 127) << shift;
58501
- if ((byte & 128) === 0) break;
58502
- shift += 7;
58503
- }
58504
- return [res, p];
58505
- }
58506
58600
  function weakenFoundationSymbolsInWasmObj(buf) {
58507
58601
  let pos = 8;
58508
58602
  while (pos < buf.length) {
@@ -58867,6 +58961,7 @@ var init_swift_shared_sdk = __esm({
58867
58961
  import_node_path53 = __toESM(require("node:path"), 1);
58868
58962
  init_swift_toolchain();
58869
58963
  init_swiftTargetContract();
58964
+ init_wasm_binary_sections();
58870
58965
  SWIFT_DISTRIBUTION_MIRROR_RECORD = ".peach-mirror.json";
58871
58966
  distributionHeaderRoots = /* @__PURE__ */ new Map();
58872
58967
  WEAKEN_FOUNDATION_SYMS = /* @__PURE__ */ new Set([
@@ -60273,16 +60368,12 @@ var init_swift_link_roots = __esm({
60273
60368
  "use strict";
60274
60369
  import_node_fs58 = __toESM(require("node:fs"), 1);
60275
60370
  import_node_path57 = __toESM(require("node:path"), 1);
60371
+ init_wasm_binary_sections();
60276
60372
  OBJC_RUNTIME_LOOKUP_SECTION = "peach_objc_runtime_lookup";
60277
60373
  leb = (bytes, at) => {
60278
- let value = 0;
60279
- let scale = 1;
60280
- for (; ; ) {
60281
- const byte = bytes[at.offset++];
60282
- value += (byte & 127) * scale;
60283
- if (!(byte & 128)) return value;
60284
- scale *= 128;
60285
- }
60374
+ const [value, next] = readULEB(bytes, at.offset);
60375
+ at.offset = next;
60376
+ return value;
60286
60377
  };
60287
60378
  rootsByDistribution = /* @__PURE__ */ new Map();
60288
60379
  }
@@ -61111,68 +61202,6 @@ var init_swift_guest_linked_spans = __esm({
61111
61202
  }
61112
61203
  });
61113
61204
 
61114
- // src/wasm-binary-sections.ts
61115
- function encodeWasmNumber(value) {
61116
- const bytes = [];
61117
- for (let rest = value; ; ) {
61118
- const byte = rest % 128;
61119
- rest = Math.floor(rest / 128);
61120
- if (rest === 0) return [...bytes, byte];
61121
- bytes.push(byte | 128);
61122
- }
61123
- }
61124
- function encodeWasmName(name3) {
61125
- const bytes = new TextEncoder().encode(name3);
61126
- return [...encodeWasmNumber(bytes.length), ...bytes];
61127
- }
61128
- function readWasmSection(bytes, start, end) {
61129
- let at = start;
61130
- const number4 = () => {
61131
- let value = 0;
61132
- for (let shift = 0; ; shift += 7) {
61133
- if (at >= end || shift > 63) throw new Error("invalid wasm integer");
61134
- const byte = bytes[at++];
61135
- value += (byte & 127) * 2 ** shift;
61136
- if (!(byte & 128)) return value;
61137
- }
61138
- };
61139
- return {
61140
- number: number4,
61141
- byte: () => {
61142
- if (at >= end) throw new Error("truncated wasm section");
61143
- return bytes[at++];
61144
- },
61145
- name: () => {
61146
- const length = number4();
61147
- at += length;
61148
- if (at > end) throw new Error("truncated wasm name");
61149
- return Buffer.from(bytes.buffer, bytes.byteOffset + at - length, length).toString();
61150
- },
61151
- position: () => at,
61152
- done: () => at === end
61153
- };
61154
- }
61155
- function wasmSections(bytes) {
61156
- if (Buffer.from(bytes.subarray(0, 8)).toString("hex") !== "0061736d01000000")
61157
- throw new Error("not a wasm module");
61158
- const found2 = [];
61159
- for (let at = 8; at < bytes.length; ) {
61160
- const header = readWasmSection(bytes, at, bytes.length);
61161
- const id = header.byte();
61162
- const size2 = header.number();
61163
- const start = header.position();
61164
- if (start + size2 > bytes.length) throw new Error("truncated wasm section");
61165
- found2.push({ id, offset: at, start, end: start + size2 });
61166
- at = start + size2;
61167
- }
61168
- return found2;
61169
- }
61170
- var init_wasm_binary_sections = __esm({
61171
- "src/wasm-binary-sections.ts"() {
61172
- "use strict";
61173
- }
61174
- });
61175
-
61176
61205
  // src/wasm-imports.ts
61177
61206
  function readWasmImports(bytes, section2, visit3) {
61178
61207
  const input = readWasmSection(bytes, section2.start, section2.end);
@@ -61456,23 +61485,13 @@ function wasmReader(bytes, start) {
61456
61485
  const rawBuf = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
61457
61486
  let at = start;
61458
61487
  const u = () => {
61459
- let value = 0;
61460
- for (let shift = 0; ; shift += 7) {
61461
- const byte = bytes[at++];
61462
- value += (byte & 127) * 2 ** shift;
61463
- if (!(byte & 128)) return value;
61464
- }
61488
+ const [value, next] = readULEB(bytes, at);
61489
+ at = next;
61490
+ return value;
61465
61491
  };
61466
61492
  const s = () => {
61467
- let value = 0n;
61468
- let shift = 0n;
61469
- let byte = 0;
61470
- do {
61471
- byte = bytes[at++];
61472
- value |= BigInt(byte & 127) << shift;
61473
- shift += 7n;
61474
- } while (byte & 128);
61475
- if (byte & 64) value -= 1n << shift;
61493
+ const [value, next] = readSLEB(bytes, at);
61494
+ at = next;
61476
61495
  return value;
61477
61496
  };
61478
61497
  return {
@@ -61777,7 +61796,7 @@ function finishSdkImage(bytes, hostExports, libraries, guestMap) {
61777
61796
  else data[entry.name] = value;
61778
61797
  }
61779
61798
  if (entry.kind !== 0 && entry.kind !== 3 || host2.has(entry.name))
61780
- kept.push([...encodedName(entry.name), entry.kind, ...uleb(entry.index)]);
61799
+ kept.push([...encodeWasmName(entry.name), entry.kind, ...encodeWasmNumber(entry.index)]);
61781
61800
  }
61782
61801
  if (guestMap) {
61783
61802
  if (guestMap.code.length !== m.bodies.length)
@@ -61792,19 +61811,19 @@ function finishSdkImage(bytes, hostExports, libraries, guestMap) {
61792
61811
  const er = wasmReader(bytes, elements.start);
61793
61812
  const segments = er.u();
61794
61813
  const replaced = /* @__PURE__ */ new Map([
61795
- [4, [1, 112, 4, ...uleb(tableEnd + added.length)]],
61796
- [7, [...uleb(kept.length), ...kept.flat()]],
61814
+ [4, [1, 112, 4, ...encodeWasmNumber(tableEnd + added.length)]],
61815
+ [7, [...encodeWasmNumber(kept.length), ...kept.flat()]],
61797
61816
  [
61798
61817
  9,
61799
61818
  [
61800
- ...uleb(segments + 1),
61819
+ ...encodeWasmNumber(segments + 1),
61801
61820
  ...bytes.subarray(er.at, elements.end),
61802
61821
  0,
61803
61822
  66,
61804
- ...sleb(BigInt(tableEnd)),
61823
+ ...encodeWasmSigned(BigInt(tableEnd)),
61805
61824
  11,
61806
- ...uleb(added.length),
61807
- ...added.flatMap(uleb)
61825
+ ...encodeWasmNumber(added.length),
61826
+ ...added.flatMap(encodeWasmNumber)
61808
61827
  ]
61809
61828
  ]
61810
61829
  ]);
@@ -61910,33 +61929,33 @@ function codeOnlySdkImage(bytes, constructorMask) {
61910
61929
  if (drop) r.skip(1);
61911
61930
  gated.push(
61912
61931
  66,
61913
- ...sleb(BigInt(constructorMask + index++)),
61932
+ ...encodeWasmSigned(BigInt(constructorMask + index++)),
61914
61933
  45,
61915
61934
  0,
61916
61935
  0,
61917
61936
  4,
61918
61937
  64,
61919
61938
  16,
61920
- ...uleb(callee),
61939
+ ...encodeWasmNumber(callee),
61921
61940
  ...drop ? [26] : [],
61922
61941
  11
61923
61942
  );
61924
61943
  }
61925
61944
  if (index > SWIFT_SDK_CONSTRUCTOR_LIMIT)
61926
61945
  throw new Error(`${index} sdk constructors exceed the mask`);
61927
- gated.push(16, ...uleb(functionIndex("__peach_sdk_register")), 11);
61946
+ gated.push(16, ...encodeWasmNumber(functionIndex("__peach_sdk_register")), 11);
61928
61947
  bodies[constructors] = Uint8Array.from(gated);
61929
61948
  }
61930
- const codeParts = [Uint8Array.from(uleb(bodies.length))];
61931
- for (const body of bodies) codeParts.push(Uint8Array.from(uleb(body.length)), body);
61949
+ const codeParts = [Uint8Array.from(encodeWasmNumber(bodies.length))];
61950
+ for (const body of bodies) codeParts.push(Uint8Array.from(encodeWasmNumber(body.length)), body);
61932
61951
  const codeSize = codeParts.reduce((sum, part) => sum + part.length, 0);
61933
61952
  const tls = passiveSegments(bytes)[0];
61934
61953
  const out = [bytes.subarray(0, 8)];
61935
61954
  for (const s of m.sections) {
61936
61955
  if (s.id === 10) {
61937
- out.push(Uint8Array.from([10, ...uleb(codeSize)]));
61956
+ out.push(Uint8Array.from([10, ...encodeWasmNumber(codeSize)]));
61938
61957
  for (const part of codeParts) out.push(part);
61939
- } else if (s.id === 11) out.push(section(11, [1, 1, ...uleb(tls.length), ...tls]));
61958
+ } else if (s.id === 11) out.push(section(11, [1, 1, ...encodeWasmNumber(tls.length), ...tls]));
61940
61959
  else if (s.id === 12) out.push(section(12, [1]));
61941
61960
  else out.push(bytes.subarray(s.offset, s.end));
61942
61961
  }
@@ -62253,39 +62272,14 @@ function unslottedFunctions(bytes) {
62253
62272
  }
62254
62273
  return definedFuncs - slotted.size;
62255
62274
  }
62256
- var uleb, sleb, encodedName, section, PROCESS_EXPORTS, SWIFT_SDK_CONSTRUCTOR_LIMIT, FUNCTION_RELOCATIONS, MEMORY_RELOCATIONS, ADDEND_RELOCATIONS, FUNCTION_RELOC_MASK, MEMORY_RELOC_MASK, ADDEND_RELOC_MASK;
62275
+ var section, PROCESS_EXPORTS, SWIFT_SDK_CONSTRUCTOR_LIMIT, FUNCTION_RELOCATIONS, MEMORY_RELOCATIONS, ADDEND_RELOCATIONS, FUNCTION_RELOC_MASK, MEMORY_RELOC_MASK, ADDEND_RELOC_MASK;
62257
62276
  var init_swift_sdk_image_wasm = __esm({
62258
62277
  "src/swift-sdk-image-wasm.ts"() {
62259
62278
  "use strict";
62260
62279
  init_swift_sdk_image_map();
62261
62280
  init_swiftSdkLinkContract();
62262
- uleb = (value) => {
62263
- const out = [];
62264
- do {
62265
- let byte = value % 128;
62266
- value = Math.floor(value / 128);
62267
- if (value) byte |= 128;
62268
- out.push(byte);
62269
- } while (value);
62270
- return out;
62271
- };
62272
- sleb = (value) => {
62273
- const out = [];
62274
- for (; ; ) {
62275
- const byte = Number(value & 127n);
62276
- value >>= 7n;
62277
- if (value === 0n && !(byte & 64) || value === -1n && byte & 64) {
62278
- out.push(byte);
62279
- return out;
62280
- }
62281
- out.push(byte | 128);
62282
- }
62283
- };
62284
- encodedName = (name3) => {
62285
- const bytes = [...Buffer.from(name3)];
62286
- return [...uleb(bytes.length), ...bytes];
62287
- };
62288
- section = (id, payload) => Uint8Array.from([id, ...uleb(payload.length), ...payload]);
62281
+ init_wasm_binary_sections();
62282
+ section = (id, payload) => Uint8Array.from([id, ...encodeWasmNumber(payload.length), ...payload]);
62289
62283
  PROCESS_EXPORTS = [
62290
62284
  "_initialize",
62291
62285
  "__wasm_call_ctors",
@@ -62390,20 +62384,12 @@ function localizeDefinedWasmSymbols(bytes, names) {
62390
62384
  const output = new Uint8Array(bytes);
62391
62385
  let cur = 8;
62392
62386
  const readU = () => {
62393
- const b0 = bytes[cur++];
62394
- if (b0 < 128) return b0;
62395
- let res = b0 & 127;
62396
- let shift = 7;
62397
- while (true) {
62398
- const byte = bytes[cur++];
62399
- res |= (byte & 127) << shift;
62400
- if ((byte & 128) === 0) return res;
62401
- shift += 7;
62402
- }
62387
+ const [res, next] = readULEB(bytes, cur);
62388
+ cur = next;
62389
+ return res;
62403
62390
  };
62404
62391
  const skipU = () => {
62405
- while ((bytes[cur++] & 128) !== 0) {
62406
- }
62392
+ cur = skipLEB(bytes, cur);
62407
62393
  };
62408
62394
  const importFuncNames = [];
62409
62395
  const importGlobalNames = [];
@@ -62510,45 +62496,11 @@ function localizeDefinedWasmSymbols(bytes, names) {
62510
62496
  var init_swift_wasm_archive = __esm({
62511
62497
  "src/swift-wasm-archive.ts"() {
62512
62498
  "use strict";
62499
+ init_wasm_binary_sections();
62513
62500
  }
62514
62501
  });
62515
62502
 
62516
62503
  // src/swift-wasm-prune.ts
62517
- function readULEB2(b, o) {
62518
- let res = 0;
62519
- let shift = 0;
62520
- let p = o;
62521
- while (true) {
62522
- const byte = b[p++];
62523
- res |= (byte & 127) << shift;
62524
- if ((byte & 128) === 0) break;
62525
- shift += 7;
62526
- }
62527
- return [res, p];
62528
- }
62529
- function readSLEB(b, o) {
62530
- let res = 0;
62531
- let shift = 0;
62532
- let p = o;
62533
- let byte = 0;
62534
- do {
62535
- byte = b[p++];
62536
- res |= (byte & 127) << shift;
62537
- shift += 7;
62538
- } while (byte & 128);
62539
- if (shift < 32 && byte & 64) res |= ~0 << shift;
62540
- return [res, p];
62541
- }
62542
- function encodeULEB(val) {
62543
- const out = [];
62544
- do {
62545
- let byte = val & 127;
62546
- val >>>= 7;
62547
- if (val !== 0) byte |= 128;
62548
- out.push(byte);
62549
- } while (val !== 0);
62550
- return out;
62551
- }
62552
62504
  function isRootSegName(name3) {
62553
62505
  for (const pref of ROOT_SEG_PREFIXES) {
62554
62506
  if (name3 === pref || name3.startsWith(`${pref}.`)) return true;
@@ -62574,39 +62526,14 @@ function decodeRelocations(buf, sections) {
62574
62526
  for (let k = 0; k < sectionCount; k++, i++) {
62575
62527
  start[i] = length + cur - baseAt;
62576
62528
  const rType = buf[cur++];
62577
- let offset = buf[cur++];
62578
- if (offset >= 128) {
62579
- offset &= 127;
62580
- let shift = 7;
62581
- while (true) {
62582
- const byte = buf[cur++];
62583
- offset |= (byte & 127) << shift;
62584
- if (byte < 128) break;
62585
- shift += 7;
62586
- }
62587
- }
62588
- let symbol2 = buf[cur++];
62589
- if (symbol2 >= 128) {
62590
- symbol2 &= 127;
62591
- let shift = 7;
62592
- while (true) {
62593
- const byte = buf[cur++];
62594
- symbol2 |= (byte & 127) << shift;
62595
- if (byte < 128) break;
62596
- shift += 7;
62597
- }
62598
- }
62529
+ let offset;
62530
+ [offset, cur] = readULEB(buf, cur);
62531
+ let symbol2;
62532
+ [symbol2, cur] = readULEB(buf, cur);
62599
62533
  if (rType < 32 && (ADDEND_RELOC_MASK2 & 1 << rType) !== 0) {
62600
- let byte = buf[cur++];
62601
- let value = byte & 127;
62602
- let shift = 7;
62603
- while (byte >= 128) {
62604
- byte = buf[cur++];
62605
- value |= (byte & 127) << shift;
62606
- shift += 7;
62607
- }
62608
- if (shift < 32 && (byte & 64) !== 0) value |= ~0 << shift;
62609
- addend[i] = value;
62534
+ let value;
62535
+ [value, cur] = readSLEB(buf, cur);
62536
+ addend[i] = Number(BigInt.asIntN(32, value));
62610
62537
  }
62611
62538
  ro[i] = offset;
62612
62539
  rs[i] = symbol2;
@@ -62641,36 +62568,36 @@ function patchSwiftrtObject(src) {
62641
62568
  let pos = 8;
62642
62569
  while (pos < buf.length) {
62643
62570
  const id = buf[pos++];
62644
- const [sz, p] = readULEB2(buf, pos);
62571
+ const [sz, p] = readULEB(buf, pos);
62645
62572
  const end = p + sz;
62646
62573
  if (id === 0) {
62647
- const [nLen, np] = readULEB2(buf, p);
62574
+ const [nLen, np] = readULEB(buf, p);
62648
62575
  const name3 = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
62649
62576
  const cp = np + nLen;
62650
62577
  if (name3 === "linking") {
62651
- let [, lp] = readULEB2(buf, cp);
62578
+ let [, lp] = readULEB(buf, cp);
62652
62579
  while (lp < end) {
62653
62580
  const subId = buf[lp++];
62654
- const [subLen, sp] = readULEB2(buf, lp);
62581
+ const [subLen, sp] = readULEB(buf, lp);
62655
62582
  const subEnd = sp + subLen;
62656
62583
  if (subId === 8) {
62657
- let [cnt, cur] = readULEB2(buf, sp);
62584
+ let [cnt, cur] = readULEB(buf, sp);
62658
62585
  for (let i = 0; i < cnt; i++) {
62659
62586
  const kind = buf[cur++];
62660
62587
  const flPos = cur;
62661
- const [fl, c2] = readULEB2(buf, cur);
62588
+ const [fl, c2] = readULEB(buf, cur);
62662
62589
  cur = c2;
62663
62590
  const isUndef = (fl & 16) !== 0;
62664
62591
  const isExplicitName = (fl & 64) !== 0;
62665
62592
  if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
62666
- const [, c3] = readULEB2(buf, cur);
62593
+ const [, c3] = readULEB(buf, cur);
62667
62594
  cur = c3;
62668
62595
  if (!isUndef || isExplicitName) {
62669
- const [sLen, c4] = readULEB2(buf, cur);
62596
+ const [sLen, c4] = readULEB(buf, cur);
62670
62597
  cur = c4 + sLen;
62671
62598
  }
62672
62599
  } else if (kind === 1) {
62673
- const [sLen, c3] = readULEB2(buf, cur);
62600
+ const [sLen, c3] = readULEB(buf, cur);
62674
62601
  const sName = Buffer.from(buf.subarray(c3, c3 + sLen)).toString("utf8");
62675
62602
  if (sName === "_ZN12_GLOBAL__N_18sectionsE") fallbackSymIdx = i;
62676
62603
  for (const prefix of ["__start_", "__stop_"]) {
@@ -62682,13 +62609,13 @@ function patchSwiftrtObject(src) {
62682
62609
  }
62683
62610
  cur = c3 + sLen;
62684
62611
  if (!isUndef) {
62685
- const [, c4] = readULEB2(buf, cur);
62686
- const [, c5] = readULEB2(buf, c4);
62687
- const [, c6] = readULEB2(buf, c5);
62612
+ const [, c4] = readULEB(buf, cur);
62613
+ const [, c5] = readULEB(buf, c4);
62614
+ const [, c6] = readULEB(buf, c5);
62688
62615
  cur = c6;
62689
62616
  }
62690
62617
  } else if (kind === 3) {
62691
- const [, c3] = readULEB2(buf, cur);
62618
+ const [, c3] = readULEB(buf, cur);
62692
62619
  cur = c3;
62693
62620
  }
62694
62621
  }
@@ -62702,26 +62629,25 @@ function patchSwiftrtObject(src) {
62702
62629
  pos = 8;
62703
62630
  while (pos < buf.length) {
62704
62631
  const id = buf[pos++];
62705
- const [sz, p] = readULEB2(buf, pos);
62632
+ const [sz, p] = readULEB(buf, pos);
62706
62633
  const end = p + sz;
62707
62634
  if (id === 0) {
62708
- const [nLen, np] = readULEB2(buf, p);
62635
+ const [nLen, np] = readULEB(buf, p);
62709
62636
  const name3 = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
62710
62637
  const cp = np + nLen;
62711
62638
  if (name3 === "reloc.CODE") {
62712
- const [, r1] = readULEB2(buf, cp);
62713
- let [cnt, cur] = readULEB2(buf, r1);
62639
+ const [, r1] = readULEB(buf, cp);
62640
+ let [cnt, cur] = readULEB(buf, r1);
62714
62641
  for (let i = 0; i < cnt; i++) {
62715
62642
  const rType = buf[cur++];
62716
- const [, c2] = readULEB2(buf, cur);
62717
- const [rs, c3] = readULEB2(buf, c2);
62643
+ const [, c2] = readULEB(buf, cur);
62644
+ const [rs, c3] = readULEB(buf, c2);
62718
62645
  if (neutralizedSyms.has(rs) && c3 - c2 === 1) {
62719
62646
  buf[c2] = fallbackSymIdx;
62720
62647
  }
62721
62648
  cur = c3;
62722
62649
  if (ADDEND_RELOCATIONS.has(rType)) {
62723
- const [, c4] = readSLEB(buf, cur);
62724
- cur = c4;
62650
+ cur = skipLEB(buf, cur);
62725
62651
  }
62726
62652
  }
62727
62653
  }
@@ -62735,25 +62661,14 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
62735
62661
  let pos = 8;
62736
62662
  let cur = 8;
62737
62663
  const readU = () => {
62738
- const b0 = buf[cur++];
62739
- if (b0 < 128) return b0;
62740
- let res = b0 & 127;
62741
- let shift = 7;
62742
- while (true) {
62743
- const byte = buf[cur++];
62744
- res |= (byte & 127) << shift;
62745
- if (byte < 128) return res;
62746
- shift += 7;
62747
- }
62664
+ const [res, next] = readULEB(buf, cur);
62665
+ cur = next;
62666
+ return res;
62748
62667
  };
62749
62668
  const skipU = () => {
62750
- while (buf[cur++] >= 128) {
62751
- }
62752
- };
62753
- const skipS = () => {
62754
- while (buf[cur++] >= 128) {
62755
- }
62669
+ cur = skipLEB(buf, cur);
62756
62670
  };
62671
+ const skipS = skipU;
62757
62672
  let numImportFuncs = 0;
62758
62673
  let importsDlsym = false;
62759
62674
  const importFuncNames = [];
@@ -63351,16 +63266,9 @@ function guestWasmSymbols(bytes) {
63351
63266
  const rawBuf = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
63352
63267
  let cur = 8;
63353
63268
  const readU = () => {
63354
- const b0 = bytes[cur++];
63355
- if (b0 < 128) return b0;
63356
- let res = b0 & 127;
63357
- let shift = 7;
63358
- while (true) {
63359
- const byte = bytes[cur++];
63360
- res |= (byte & 127) << shift;
63361
- if ((byte & 128) === 0) return res;
63362
- shift += 7;
63363
- }
63269
+ const [res, next] = readULEB(bytes, cur);
63270
+ cur = next;
63271
+ return res;
63364
63272
  };
63365
63273
  let importsDlsym = false;
63366
63274
  const importFuncNames = [];
@@ -64501,7 +64409,7 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
64501
64409
  if (!deadSpecialSegs.has(sIdx)) continue;
64502
64410
  if (!isSpecialSegRelocLive(obj, obj.segNames[sIdx], data.rs[i])) continue;
64503
64411
  const first = relocationBytes(data, i);
64504
- const [, afterRoOff] = readULEB2(first, 1);
64412
+ const [, afterRoOff] = readULEB(first, 1);
64505
64413
  firstLiveInSpecialSeg.set(sIdx, {
64506
64414
  rType: first[0],
64507
64415
  afterRo: first.subarray(afterRoOff)
@@ -64531,7 +64439,7 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
64531
64439
  zeroDataReloc(i);
64532
64440
  } else {
64533
64441
  const repl = firstLiveInSpecialSeg.get(segIdx);
64534
- const roBytes = encodeULEB(data.ro[i]);
64442
+ const roBytes = encodeWasmNumber(data.ro[i]);
64535
64443
  const out = new Uint8Array(1 + roBytes.length + repl.afterRo.length);
64536
64444
  out[0] = repl.rType;
64537
64445
  out.set(roBytes, 1);
@@ -64570,34 +64478,34 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
64570
64478
  while (pos < buf.length) {
64571
64479
  const secStart = pos;
64572
64480
  const id = buf[pos++];
64573
- const [sz, p] = readULEB2(buf, pos);
64481
+ const [sz, p] = readULEB(buf, pos);
64574
64482
  const end = p + sz;
64575
64483
  if (id === 0) {
64576
- const [nLen, np] = readULEB2(buf, p);
64484
+ const [nLen, np] = readULEB(buf, p);
64577
64485
  const name3 = rawBuf.toString("utf8", np, np + nLen);
64578
64486
  const cp = np + nLen;
64579
64487
  if (name3 === "linking") {
64580
- const [, lpStart] = readULEB2(buf, cp);
64488
+ const [, lpStart] = readULEB(buf, cp);
64581
64489
  const subChunks = [buf.subarray(p, lpStart)];
64582
64490
  let lp = lpStart;
64583
64491
  while (lp < end) {
64584
64492
  const subStart = lp;
64585
64493
  const subId = buf[lp++];
64586
- const [subLen, sp] = readULEB2(buf, lp);
64494
+ const [subLen, sp] = readULEB(buf, lp);
64587
64495
  const subEnd = sp + subLen;
64588
64496
  if (subId === 5) {
64589
64497
  const subCopy = new Uint8Array(buf.subarray(subStart, subEnd));
64590
- let [cnt, cur] = readULEB2(buf, sp);
64498
+ let [cnt, cur] = readULEB(buf, sp);
64591
64499
  for (let i = 0; i < cnt; i++) {
64592
- const [sLen, s2] = readULEB2(buf, cur);
64500
+ const [sLen, s2] = readULEB(buf, cur);
64593
64501
  const segName = obj.segNames[i];
64594
64502
  const repl = RECORD_SEGS.get(segName);
64595
64503
  const isSpecial = repl !== void 0;
64596
64504
  if (deadSpecialSegs.has(i) && repl !== void 0)
64597
64505
  subCopy.set(Buffer.from(repl, "utf8"), s2 - subStart);
64598
64506
  cur = s2 + sLen;
64599
- const [, s3] = readULEB2(buf, cur);
64600
- const [segFl, s4] = readULEB2(buf, s3);
64507
+ const [, s3] = readULEB(buf, cur);
64508
+ const [segFl, s4] = readULEB(buf, s3);
64601
64509
  const sFlLen = s4 - s3;
64602
64510
  const keepRetain = isSpecial ? !deadSpecialSegs.has(i) : isRootSegName(segName) && !segName.startsWith(".init_array") && sLive[i] === 1;
64603
64511
  const newSegFl = keepRetain ? segFl | 4 : segFl & ~4;
@@ -64611,12 +64519,12 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
64611
64519
  }
64612
64520
  subChunks.push(subCopy);
64613
64521
  } else if (subId === 6) {
64614
- let [cnt, cur] = readULEB2(buf, sp);
64522
+ let [cnt, cur] = readULEB(buf, sp);
64615
64523
  const entrySlices = [];
64616
64524
  for (let i = 0; i < cnt; i++) {
64617
64525
  const eStart = cur;
64618
- const [, s2] = readULEB2(buf, cur);
64619
- const [symIdx, s3] = readULEB2(buf, s2);
64526
+ const [, s2] = readULEB(buf, cur);
64527
+ const [symIdx, s3] = readULEB(buf, s2);
64620
64528
  cur = s3;
64621
64529
  if (obj.symKind[symIdx] === 0 && obj.symElemIdx[symIdx] >= obj.numImportFuncs) {
64622
64530
  if (fLive[obj.symElemIdx[symIdx] - obj.numImportFuncs] === 1) {
@@ -64627,19 +64535,19 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
64627
64535
  }
64628
64536
  }
64629
64537
  if (entrySlices.length > 0) {
64630
- const cntBytes = Uint8Array.from(encodeULEB(entrySlices.length));
64538
+ const cntBytes = Uint8Array.from(encodeWasmNumber(entrySlices.length));
64631
64539
  const bodyLen = cntBytes.length + entrySlices.reduce((a, b) => a + b.length, 0);
64632
- const lenBytes = Uint8Array.from(encodeULEB(bodyLen));
64540
+ const lenBytes = Uint8Array.from(encodeWasmNumber(bodyLen));
64633
64541
  subChunks.push(Uint8Array.of(6), lenBytes, cntBytes);
64634
64542
  for (const entry of entrySlices) subChunks.push(entry);
64635
64543
  }
64636
64544
  } else if (subId === 8) {
64637
64545
  const subCopy = new Uint8Array(buf.subarray(subStart, subEnd));
64638
- let [cnt, cur] = readULEB2(buf, sp);
64546
+ let [cnt, cur] = readULEB(buf, sp);
64639
64547
  for (let i = 0; i < cnt; i++) {
64640
64548
  const kind = buf[cur++];
64641
64549
  const flOffset = cur - subStart;
64642
- const [fl, c2] = readULEB2(buf, cur);
64550
+ const [fl, c2] = readULEB(buf, cur);
64643
64551
  cur = c2;
64644
64552
  const isUndef = (fl & 16) !== 0;
64645
64553
  const isExplicitName = (fl & 64) !== 0;
@@ -64659,23 +64567,23 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
64659
64567
  subCopy[flOffset + 1] = 0;
64660
64568
  }
64661
64569
  if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
64662
- const [, c3] = readULEB2(buf, cur);
64570
+ const [, c3] = readULEB(buf, cur);
64663
64571
  cur = c3;
64664
64572
  if (!isUndef || isExplicitName) {
64665
- const [sLen, c4] = readULEB2(buf, cur);
64573
+ const [sLen, c4] = readULEB(buf, cur);
64666
64574
  cur = c4 + sLen;
64667
64575
  }
64668
64576
  } else if (kind === 1) {
64669
- const [sLen, c3] = readULEB2(buf, cur);
64577
+ const [sLen, c3] = readULEB(buf, cur);
64670
64578
  cur = c3 + sLen;
64671
64579
  if (!isUndef) {
64672
- const [, c4] = readULEB2(buf, cur);
64673
- const [, c5] = readULEB2(buf, c4);
64674
- const [, c6] = readULEB2(buf, c5);
64580
+ const [, c4] = readULEB(buf, cur);
64581
+ const [, c5] = readULEB(buf, c4);
64582
+ const [, c6] = readULEB(buf, c5);
64675
64583
  cur = c6;
64676
64584
  }
64677
64585
  } else if (kind === 3) {
64678
- const [, c3] = readULEB2(buf, cur);
64586
+ const [, c3] = readULEB(buf, cur);
64679
64587
  cur = c3;
64680
64588
  }
64681
64589
  }
@@ -64686,29 +64594,29 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
64686
64594
  lp = subEnd;
64687
64595
  }
64688
64596
  const totalSubLen = subChunks.reduce((a, b) => a + b.length, 0);
64689
- outChunks.push(Uint8Array.of(0), Uint8Array.from(encodeULEB(totalSubLen)));
64597
+ outChunks.push(Uint8Array.of(0), Uint8Array.from(encodeWasmNumber(totalSubLen)));
64690
64598
  for (const chunk of subChunks) outChunks.push(chunk);
64691
64599
  } else if (name3 === "reloc.CODE") {
64692
- const [, r1] = readULEB2(buf, cp);
64600
+ const [, r1] = readULEB(buf, cp);
64693
64601
  const headerSlice = buf.subarray(p, r1);
64694
- const cntBytes = Uint8Array.from(encodeULEB(keptCodeRelocs.length));
64602
+ const cntBytes = Uint8Array.from(encodeWasmNumber(keptCodeRelocs.length));
64695
64603
  const relSlices = keptCodeRelocs.map((i) => relocationBytes(code, i));
64696
64604
  const totalLen = headerSlice.length + cntBytes.length + relSlices.reduce((a, b) => a + b.length, 0);
64697
64605
  outChunks.push(
64698
64606
  Uint8Array.of(0),
64699
- Uint8Array.from(encodeULEB(totalLen)),
64607
+ Uint8Array.from(encodeWasmNumber(totalLen)),
64700
64608
  headerSlice,
64701
64609
  cntBytes
64702
64610
  );
64703
64611
  for (const relocation of relSlices) outChunks.push(relocation);
64704
64612
  } else if (name3 === "reloc.DATA") {
64705
- const [, r1] = readULEB2(buf, cp);
64613
+ const [, r1] = readULEB(buf, cp);
64706
64614
  const headerSlice = buf.subarray(p, r1);
64707
- const cntBytes = Uint8Array.from(encodeULEB(keptDataRelocBytes.length));
64615
+ const cntBytes = Uint8Array.from(encodeWasmNumber(keptDataRelocBytes.length));
64708
64616
  const totalLen = headerSlice.length + cntBytes.length + keptDataRelocBytes.reduce((a, b) => a + b.length, 0);
64709
64617
  outChunks.push(
64710
64618
  Uint8Array.of(0),
64711
- Uint8Array.from(encodeULEB(totalLen)),
64619
+ Uint8Array.from(encodeWasmNumber(totalLen)),
64712
64620
  headerSlice,
64713
64621
  cntBytes
64714
64622
  );
@@ -64718,15 +64626,15 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
64718
64626
  const nameBytes = buf.subarray(p, cp);
64719
64627
  outChunks.push(
64720
64628
  Uint8Array.of(0),
64721
- Uint8Array.from(encodeULEB(nameBytes.length)),
64629
+ Uint8Array.from(encodeWasmNumber(nameBytes.length)),
64722
64630
  nameBytes
64723
64631
  );
64724
64632
  } else if (name3.startsWith("reloc..debug_")) {
64725
- const [, r1] = readULEB2(buf, cp);
64633
+ const [, r1] = readULEB(buf, cp);
64726
64634
  const headerSlice = buf.subarray(p, r1);
64727
64635
  outChunks.push(
64728
64636
  Uint8Array.of(0),
64729
- Uint8Array.from(encodeULEB(headerSlice.length + 1)),
64637
+ Uint8Array.from(encodeWasmNumber(headerSlice.length + 1)),
64730
64638
  headerSlice,
64731
64639
  Uint8Array.of(0)
64732
64640
  );
@@ -64856,6 +64764,7 @@ var init_swift_wasm_prune = __esm({
64856
64764
  init_swift_toolchain();
64857
64765
  init_swift_wasm_archive();
64858
64766
  init_swiftRuntimeProductContract();
64767
+ init_wasm_binary_sections();
64859
64768
  WIDE_DATA_RELOCS = /* @__PURE__ */ new Set([16, 19, 22, 27]);
64860
64769
  ROOT_SEG_PREFIXES = [
64861
64770
  ".init_array",
@@ -65149,34 +65058,11 @@ var init_nativeWasmContract = __esm({
65149
65058
  });
65150
65059
 
65151
65060
  // src/swift-guest-image-ledger.ts
65152
- function readNumber(bytes, position) {
65153
- if (position < bytes.length) {
65154
- const first = bytes[position];
65155
- if (first < 128) return [first, position + 1];
65156
- }
65157
- let value = 0;
65158
- let shift = 0;
65159
- for (; ; ) {
65160
- if (position >= bytes.length || shift > 63) throw new Error("invalid wasm integer");
65161
- const byte = bytes[position++];
65162
- value += (byte & 127) * 2 ** shift;
65163
- if (!(byte & 128)) return [value, position];
65164
- shift += 7;
65165
- }
65166
- }
65167
65061
  function encodeNumber(value) {
65168
- if (value < 128) return Buffer.from([value]);
65169
- const bytes = [];
65170
- do {
65171
- let byte = value % 128;
65172
- value = Math.floor(value / 128);
65173
- if (value) byte |= 128;
65174
- bytes.push(byte);
65175
- } while (value);
65176
- return Buffer.from(bytes);
65062
+ return Buffer.from(encodeWasmNumber(value));
65177
65063
  }
65178
65064
  function readString(bytes, position) {
65179
- const [length, start] = readNumber(bytes, position);
65065
+ const [length, start] = readULEB(bytes, position);
65180
65066
  if (start + length > bytes.length) throw new Error("invalid wasm string");
65181
65067
  return [
65182
65068
  Buffer.from(bytes.buffer, bytes.byteOffset + start, length).toString("utf8"),
@@ -65502,13 +65388,13 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
65502
65388
  for (const subsection of subsections) {
65503
65389
  if (subsection.kind === 6 && objcLoader !== void 0) {
65504
65390
  const content = subsection.parts[0];
65505
- const [count, entriesStart] = readNumber(content, 0);
65391
+ const [count, entriesStart] = readULEB(content, 0);
65506
65392
  const initWriter = new ByteWriter(content.length + 16);
65507
65393
  initWriter.bytes(content, 0, entriesStart);
65508
65394
  let entryStart = entriesStart;
65509
65395
  for (let i = 0; i < count; i++) {
65510
- const [, symbolStart] = readNumber(content, entryStart);
65511
- const [symbol2, entryEnd] = readNumber(content, symbolStart);
65396
+ const [, symbolStart] = readULEB(content, entryStart);
65397
+ const [symbol2, entryEnd] = readULEB(content, symbolStart);
65512
65398
  if (symbol2 === objcLoader) {
65513
65399
  initWriter.uleb(1);
65514
65400
  initWriter.bytes(content, symbolStart, entryEnd);
@@ -65578,7 +65464,7 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
65578
65464
  if (position < bytes.length && bytes[position] < 128) {
65579
65465
  size2 = bytes[position++];
65580
65466
  } else {
65581
- const [val, next] = readNumber(bytes, position);
65467
+ const [val, next] = readULEB(bytes, position);
65582
65468
  size2 = val;
65583
65469
  position = next;
65584
65470
  }
@@ -66334,7 +66220,7 @@ function nameGuestImageAliases(wasm, symbols) {
66334
66220
  const parts2 = [wasm.subarray(0, 8)];
66335
66221
  let position = 8;
66336
66222
  while (position < wasm.length) {
66337
- const [size2, start] = readNumber(wasm, position + 1);
66223
+ const [size2, start] = readULEB(wasm, position + 1);
66338
66224
  const end = start + size2;
66339
66225
  const custom = wasm[position] === 0 ? readString(wasm, start) : void 0;
66340
66226
  if (custom?.[0] !== "name") {
@@ -66345,17 +66231,17 @@ function nameGuestImageAliases(wasm, symbols) {
66345
66231
  const subsections = [encodedString("name")];
66346
66232
  let at = custom[1];
66347
66233
  while (at < end) {
66348
- const [subSize, subStart] = readNumber(wasm, at + 1);
66234
+ const [subSize, subStart] = readULEB(wasm, at + 1);
66349
66235
  const subEnd = subStart + subSize;
66350
66236
  if (wasm[at] !== 1) {
66351
66237
  subsections.push(wasm.subarray(at, subEnd));
66352
66238
  at = subEnd;
66353
66239
  continue;
66354
66240
  }
66355
- let [count, cursor] = readNumber(wasm, subStart);
66241
+ let [count, cursor] = readULEB(wasm, subStart);
66356
66242
  const entries2 = [encodeNumber(count)];
66357
66243
  for (; count > 0; count--) {
66358
- const [index, next] = readNumber(wasm, cursor);
66244
+ const [index, next] = readULEB(wasm, cursor);
66359
66245
  const [name3, after] = readString(wasm, next);
66360
66246
  cursor = after;
66361
66247
  const symbol2 = symbols[Number(alias.exec(name3)?.[1] ?? -1)];
@@ -66379,6 +66265,7 @@ var init_swift_guest_image_ledger = __esm({
66379
66265
  init_nativeWasmContract();
66380
66266
  init_swift_sdk_image_wasm();
66381
66267
  init_swiftSdkLinkContract();
66268
+ init_wasm_binary_sections();
66382
66269
  ByteWriter = class {
66383
66270
  buf;
66384
66271
  pos = 0;
@@ -66399,16 +66286,13 @@ var init_swift_guest_image_ledger = __esm({
66399
66286
  this.buf[this.pos++] = value;
66400
66287
  }
66401
66288
  uleb(value) {
66402
- this.ensure(10);
66403
- let pos = this.pos;
66404
- const buf = this.buf;
66405
- do {
66406
- let byte = value % 128;
66407
- value = Math.floor(value / 128);
66408
- if (value) byte |= 128;
66409
- buf[pos++] = byte;
66410
- } while (value);
66411
- this.pos = pos;
66289
+ if (value < 128) {
66290
+ this.byte(value);
66291
+ return;
66292
+ }
66293
+ const encoded = encodeWasmNumber(value);
66294
+ this.ensure(encoded.length);
66295
+ for (let i = 0; i < encoded.length; i++) this.buf[this.pos++] = encoded[i];
66412
66296
  }
66413
66297
  bytes(source, start = 0, end = source.length) {
66414
66298
  const len = end - start;
@@ -66926,13 +66810,6 @@ function sha256Buffer(bytes) {
66926
66810
  return Buffer.from(new Bun.CryptoHasher("sha256").update(bytes).digest());
66927
66811
  return (0, import_node_crypto35.createHash)("sha256").update(bytes).digest();
66928
66812
  }
66929
- function uleb2(value) {
66930
- const bytes = [];
66931
- for (let rest = value; ; rest = Math.floor(rest / 128)) {
66932
- if (rest < 128) return [...bytes, rest];
66933
- bytes.push(rest % 128 | 128);
66934
- }
66935
- }
66936
66813
  function encodeGuestDyldTable(rows) {
66937
66814
  const encoded = rows.map((row) => ({ ...row, bytes: Buffer.from(row.name) })).sort((a, b) => Buffer.compare(a.bytes, b.bytes));
66938
66815
  const packs = [];
@@ -66945,7 +66822,7 @@ function encodeGuestDyldTable(rows) {
66945
66822
  value.writeBigUInt64LE(row.value);
66946
66823
  const bytes = Buffer.concat([
66947
66824
  row.bytes,
66948
- Buffer.from([0, ...uleb2(row.image), row.kind]),
66825
+ Buffer.from([0, ...encodeWasmNumber(row.image), row.kind]),
66949
66826
  value
66950
66827
  ]);
66951
66828
  if (!current2.length) firsts.push(row.bytes);
@@ -67037,6 +66914,7 @@ var init_swift_guest_dyld_table = __esm({
67037
66914
  init_sha256();
67038
66915
  init_swift_guest_image_ledger();
67039
66916
  init_swift_guest_linked_spans();
66917
+ init_wasm_binary_sections();
67040
66918
  init_wasm_narrow_boundary();
67041
66919
  PACK_BYTES = 64 * 1024;
67042
66920
  }
@@ -67131,8 +67009,8 @@ function primaryFunctionTable(bytes) {
67131
67009
  return { name: wasmReader(exported2, 0).name(), table64 };
67132
67010
  }
67133
67011
  function vectorSection(id, count, parts2) {
67134
- const body = Buffer.concat([Buffer.from(uleb3(count)), ...parts2]);
67135
- return Buffer.concat([Buffer.from([id, ...uleb3(body.length)]), body]);
67012
+ const body = Buffer.concat([Buffer.from(encodeWasmNumber(count)), ...parts2]);
67013
+ return Buffer.concat([Buffer.from([id, ...encodeWasmNumber(body.length)]), body]);
67136
67014
  }
67137
67015
  function rewriteSections(bytes, sections, changes) {
67138
67016
  const out = [bytes.subarray(0, 8)];
@@ -67188,9 +67066,9 @@ function appendLazyPlacement(bytes, functions, table) {
67188
67066
  vectorSection(2, count + 1, [
67189
67067
  found2 && header ? bytes.subarray(header.at, found2.end) : new Uint8Array(),
67190
67068
  Buffer.from([
67191
- ...uleb3(module2.length),
67069
+ ...encodeWasmNumber(module2.length),
67192
67070
  ...module2,
67193
- ...uleb3(name4.length),
67071
+ ...encodeWasmNumber(name4.length),
67194
67072
  ...name4,
67195
67073
  1,
67196
67074
  112,
@@ -67212,7 +67090,7 @@ function appendLazyPlacement(bytes, functions, table) {
67212
67090
  elements.splice(
67213
67091
  placementIndex,
67214
67092
  0,
67215
- Buffer.from([1, 0, ...uleb3(functions.length), ...functions.flatMap(uleb3)])
67093
+ Buffer.from([1, 0, ...encodeWasmNumber(functions.length), ...functions.flatMap(encodeWasmNumber)])
67216
67094
  );
67217
67095
  const place2 = imports2.functions + declared.length;
67218
67096
  const instructions = [
@@ -67226,7 +67104,7 @@ function appendLazyPlacement(bytes, functions, table) {
67226
67104
  1,
67227
67105
  252,
67228
67106
  12,
67229
- ...uleb3(placementIndex),
67107
+ ...encodeWasmNumber(placementIndex),
67230
67108
  0,
67231
67109
  11
67232
67110
  ];
@@ -67247,14 +67125,14 @@ function appendLazyPlacement(bytes, functions, table) {
67247
67125
  3,
67248
67126
  vectorSection(3, declared.length + 1, [
67249
67127
  ...declared,
67250
- Buffer.from(uleb3(types2.length))
67128
+ Buffer.from(encodeWasmNumber(types2.length))
67251
67129
  ])
67252
67130
  ],
67253
67131
  [
67254
67132
  7,
67255
67133
  vectorSection(7, exports2.length + 1, [
67256
67134
  ...exports2,
67257
- Buffer.from([...uleb3(name3.length), ...name3, 0, ...uleb3(place2)])
67135
+ Buffer.from([...encodeWasmNumber(name3.length), ...name3, 0, ...encodeWasmNumber(place2)])
67258
67136
  ])
67259
67137
  ],
67260
67138
  [9, vectorSection(9, elements.length, elements)],
@@ -67262,7 +67140,7 @@ function appendLazyPlacement(bytes, functions, table) {
67262
67140
  10,
67263
67141
  vectorSection(10, bodies.length + 1, [
67264
67142
  ...bodies,
67265
- Buffer.from([...uleb3(instructions.length), ...instructions])
67143
+ Buffer.from([...encodeWasmNumber(instructions.length), ...instructions])
67266
67144
  ])
67267
67145
  ]
67268
67146
  ])
@@ -67384,40 +67262,31 @@ function nameLazyFunctions(bytes, functions) {
67384
67262
  for (const index of functions) {
67385
67263
  if (names.has(index)) continue;
67386
67264
  const name3 = Buffer.from(String(index - imported));
67387
- names.set(index, Buffer.from([...uleb3(name3.length), ...name3]));
67265
+ names.set(index, Buffer.from([...encodeWasmNumber(name3.length), ...name3]));
67388
67266
  }
67389
67267
  const ordered = [...names].sort(([a], [b]) => a - b);
67390
67268
  const functionNames = Buffer.concat([
67391
- Buffer.from(uleb3(ordered.length)),
67392
- ...ordered.flatMap(([index, name3]) => [Buffer.from(uleb3(index)), name3])
67269
+ Buffer.from(encodeWasmNumber(ordered.length)),
67270
+ ...ordered.flatMap(([index, name3]) => [Buffer.from(encodeWasmNumber(index)), name3])
67393
67271
  ]);
67394
- const content = [...subsections, { id: 1, body: functionNames }].sort((a, b) => a.id - b.id).flatMap(({ id, body }) => [Buffer.from([id, ...uleb3(body.length)]), body]);
67272
+ const content = [...subsections, { id: 1, body: functionNames }].sort((a, b) => a.id - b.id).flatMap(({ id, body }) => [Buffer.from([id, ...encodeWasmNumber(body.length)]), body]);
67395
67273
  const label = Buffer.from("name");
67396
67274
  const payload = Buffer.concat([
67397
- Buffer.from([...uleb3(label.length), ...label]),
67275
+ Buffer.from([...encodeWasmNumber(label.length), ...label]),
67398
67276
  ...content
67399
67277
  ]);
67400
67278
  const out = [bytes.subarray(0, 8)];
67401
67279
  for (const s of sections) if (s !== custom) out.push(bytes.subarray(s.offset, s.end));
67402
- out.push(Buffer.from([0, ...uleb3(payload.length)]), payload);
67280
+ out.push(Buffer.from([0, ...encodeWasmNumber(payload.length)]), payload);
67403
67281
  return Buffer.concat(out);
67404
67282
  }
67405
- var uleb3, SECTION_ORDER, readExport, lastTableElement, exportName;
67283
+ var SECTION_ORDER, readExport, lastTableElement, exportName;
67406
67284
  var init_swift_guest_dyld_functions = __esm({
67407
67285
  "src/swift-guest-dyld-functions.ts"() {
67408
67286
  "use strict";
67409
67287
  init_nativeWasmContract();
67410
67288
  init_swift_sdk_image_wasm();
67411
- uleb3 = (value) => {
67412
- const out = [];
67413
- do {
67414
- let byte = value % 128;
67415
- value = Math.floor(value / 128);
67416
- if (value) byte |= 128;
67417
- out.push(byte);
67418
- } while (value);
67419
- return out;
67420
- };
67289
+ init_wasm_binary_sections();
67421
67290
  SECTION_ORDER = [1, 2, 3, 4, 5, 13, 6, 7, 8, 9, 12, 10, 11];
67422
67291
  readExport = (r) => {
67423
67292
  r.name();
@@ -70743,30 +70612,12 @@ function wasmAutolinkEntries(bytes, out) {
70743
70612
  const len = bytes.length;
70744
70613
  while (pos < len) {
70745
70614
  const id = bytes[pos++];
70746
- let sz = bytes[pos++];
70747
- if (sz >= 128) {
70748
- sz &= 127;
70749
- let shift = 7;
70750
- while (true) {
70751
- const b = bytes[pos++];
70752
- sz |= (b & 127) << shift;
70753
- if (b < 128) break;
70754
- shift += 7;
70755
- }
70756
- }
70615
+ let sz;
70616
+ [sz, pos] = readULEB(bytes, pos, len);
70757
70617
  const end = pos + sz;
70758
70618
  if (id === 0) {
70759
- let nLen = bytes[pos++];
70760
- if (nLen >= 128) {
70761
- nLen &= 127;
70762
- let shift = 7;
70763
- while (true) {
70764
- const b = bytes[pos++];
70765
- nLen |= (b & 127) << shift;
70766
- if (b < 128) break;
70767
- shift += 7;
70768
- }
70769
- }
70619
+ let nLen;
70620
+ [nLen, pos] = readULEB(bytes, pos, end);
70770
70621
  if (nLen === 24 && raw2.toString("ascii", pos, pos + 24) === ".swift1_autolink_entries") {
70771
70622
  const payload = raw2.toString("utf8", pos + 24, end);
70772
70623
  for (const entry of payload.split("\0")) {
@@ -71003,6 +70854,7 @@ var init_swift_guest_source_inputs = __esm({
71003
70854
  init_swift_guest_source_plan();
71004
70855
  init_swift_runtime_products();
71005
70856
  init_swift_wasm_prune();
70857
+ init_wasm_binary_sections();
71006
70858
  CLANG_TARGET_MODULE_WRAPPER = ".peach-clang";
71007
70859
  PARALLEL_REPLAY = `
71008
70860
  const { spawn } = require('node:child_process')
@@ -77054,8 +76906,8 @@ function finishSwiftAppModuleFile(file) {
77054
76906
  return;
77055
76907
  }
77056
76908
  const thunks = sdkImportThunks(prefix);
77057
- const nameBytes = Buffer.from(encodedName2(NATIVE_SDK_THUNK_SECTION));
77058
- const header = Buffer.from([0, ...uleb4(nameBytes.length + thunks.length)]);
76909
+ const nameBytes = Buffer.from(encodeWasmName(NATIVE_SDK_THUNK_SECTION));
76910
+ const header = Buffer.from([0, ...encodeWasmNumber(nameBytes.length + thunks.length)]);
77059
76911
  (0, import_node_fs76.appendFileSync)(file, Buffer.concat([header, nameBytes, thunks]));
77060
76912
  }
77061
76913
  function swiftAppModuleInputs(tokens3, buildRoot, sdkLibraries) {
@@ -77407,17 +77259,17 @@ function sdkImportThunks(bytes) {
77407
77259
  for (const { type } of imports2)
77408
77260
  if (!typeIndex.has(type)) typeIndex.set(type, typeIndex.size + 1);
77409
77261
  const loaderType = [96, 1, 127, 0];
77410
- const vector = (items2) => [...uleb4(items2.length), ...items2.flat()];
77411
- const sectionBytes = (id, body) => [id, ...uleb4(body.length), ...body];
77262
+ const vector = (items2) => [...encodeWasmNumber(items2.length), ...items2.flat()];
77263
+ const sectionBytes = (id, body) => [id, ...encodeWasmNumber(body.length), ...body];
77412
77264
  const slotGlobals = imports2.map(({ slot }) => [
77413
- ...encodedName2(NATIVE_SDK_IMPORT_MODULE),
77414
- ...encodedName2(String(slot)),
77265
+ ...encodeWasmName(NATIVE_SDK_IMPORT_MODULE),
77266
+ ...encodeWasmName(String(slot)),
77415
77267
  3,
77416
77268
  127,
77417
77269
  0
77418
77270
  ]);
77419
77271
  const bodies = imports2.map(({ type }, index) => {
77420
- const slotValue = [35, ...uleb4(index)];
77272
+ const slotValue = [35, ...encodeWasmNumber(index)];
77421
77273
  const code = [
77422
77274
  0,
77423
77275
  ...slotValue,
@@ -77430,14 +77282,14 @@ function sdkImportThunks(bytes) {
77430
77282
  16,
77431
77283
  0,
77432
77284
  11,
77433
- ...Array.from({ length: params[type] }, (_, i) => [32, ...uleb4(i)]).flat(),
77285
+ ...Array.from({ length: params[type] }, (_, i) => [32, ...encodeWasmNumber(i)]).flat(),
77434
77286
  ...slotValue,
77435
77287
  17,
77436
- ...uleb4(typeIndex.get(type)),
77288
+ ...encodeWasmNumber(typeIndex.get(type)),
77437
77289
  0,
77438
77290
  11
77439
77291
  ];
77440
- return [...uleb4(code.length), ...code];
77292
+ return [...encodeWasmNumber(code.length), ...code];
77441
77293
  });
77442
77294
  return Uint8Array.from([
77443
77295
  0,
@@ -77455,21 +77307,21 @@ function sdkImportThunks(bytes) {
77455
77307
  ...sectionBytes(
77456
77308
  2,
77457
77309
  vector([
77458
- [...encodedName2("env"), ...encodedName2("__indirect_function_table"), 1, ...table],
77310
+ [...encodeWasmName("env"), ...encodeWasmName("__indirect_function_table"), 1, ...table],
77459
77311
  [
77460
- ...encodedName2(NATIVE_LAZY_IMPORT_MODULE),
77461
- ...encodedName2(NATIVE_LAZY_SLOT_IMPORT),
77312
+ ...encodeWasmName(NATIVE_LAZY_IMPORT_MODULE),
77313
+ ...encodeWasmName(NATIVE_LAZY_SLOT_IMPORT),
77462
77314
  0,
77463
77315
  0
77464
77316
  ],
77465
77317
  ...slotGlobals
77466
77318
  ])
77467
77319
  ),
77468
- ...sectionBytes(3, vector(imports2.map(({ type }) => uleb4(typeIndex.get(type))))),
77320
+ ...sectionBytes(3, vector(imports2.map(({ type }) => encodeWasmNumber(typeIndex.get(type))))),
77469
77321
  ...sectionBytes(
77470
77322
  7,
77471
77323
  vector(
77472
- imports2.map(({ slot }, i) => [...encodedName2(String(slot)), 0, ...uleb4(i + 1)])
77324
+ imports2.map(({ slot }, i) => [...encodeWasmName(String(slot)), 0, ...encodeWasmNumber(i + 1)])
77473
77325
  )
77474
77326
  ),
77475
77327
  ...sectionBytes(10, vector(bodies))
@@ -77589,7 +77441,7 @@ function resolveSdkReferences(source, sdk2, forwarders) {
77589
77441
  syntheticGlobals.push(type);
77590
77442
  got.set(index, value);
77591
77443
  }
77592
- return [35, ...uleb4(index)];
77444
+ return [35, ...encodeWasmNumber(index)];
77593
77445
  };
77594
77446
  const tlsHelpers = new Map(
77595
77447
  symbols.filter((symbol2) => symbol2.kind === 0 && symbol2.name.startsWith(SDK_TLS_HELPER)).map((symbol2) => [symbol2.name.slice(SDK_TLS_HELPER.length), symbol2.index])
@@ -77641,7 +77493,7 @@ function resolveSdkReferences(source, sdk2, forwarders) {
77641
77493
  const code = [16];
77642
77494
  for (let i = 0, rest = helper; i < 5; i++, rest >>>= 7)
77643
77495
  code.push(i < 4 ? rest & 127 | 128 : rest & 127);
77644
- if (addend) code.push(66, ...sleb2(addend), 124);
77496
+ if (addend) code.push(66, ...encodeWasmSigned(addend), 124);
77645
77497
  patchCode(at2, 11, code);
77646
77498
  continue;
77647
77499
  }
@@ -77715,7 +77567,7 @@ function resolveSdkReferences(source, sdk2, forwarders) {
77715
77567
  syntheticGlobals.push(valueType);
77716
77568
  scratchGlobals.set(valueType, scratch2);
77717
77569
  }
77718
- const index = uleb4(scratch2);
77570
+ const index = encodeWasmNumber(scratch2);
77719
77571
  patchCode(at - 2, 12, [
77720
77572
  36,
77721
77573
  ...index,
@@ -77731,7 +77583,7 @@ function resolveSdkReferences(source, sdk2, forwarders) {
77731
77583
  }
77732
77584
  const encodedNameBuf = (name3) => {
77733
77585
  const raw2 = Buffer.from(name3, "utf8");
77734
- const len = uleb4(raw2.length);
77586
+ const len = encodeWasmNumber(raw2.length);
77735
77587
  const out = Buffer.allocUnsafe(len.length + raw2.length);
77736
77588
  for (let i = 0; i < len.length; i++) out[i] = len[i];
77737
77589
  raw2.copy(out, len.length);
@@ -77776,7 +77628,7 @@ function resolveSdkReferences(source, sdk2, forwarders) {
77776
77628
  }
77777
77629
  }
77778
77630
  const globalParts = [
77779
- Buffer.from(uleb4(globalCount - 1 + syntheticGlobals.length))
77631
+ Buffer.from(encodeWasmNumber(globalCount - 1 + syntheticGlobals.length))
77780
77632
  ];
77781
77633
  for (let index = 0; index < globalCount; index++) {
77782
77634
  const start = gr.at;
@@ -77821,18 +77673,18 @@ function resolveSdkReferences(source, sdk2, forwarders) {
77821
77673
  }
77822
77674
  }
77823
77675
  const exportParts = [
77824
- Buffer.from(uleb4(exportCount + 1 + got.size)),
77676
+ Buffer.from(encodeWasmNumber(exportCount + 1 + got.size)),
77825
77677
  bytes.subarray(originalExportsStart, exportSection.end)
77826
77678
  ];
77827
77679
  for (const [index, value] of got) {
77828
77680
  exportParts.push(
77829
77681
  encodedNameBuf(`${NATIVE_SDK_GLOBAL_PREFIX}${value}.${index}`),
77830
- Buffer.from([3, ...uleb4(index)])
77682
+ Buffer.from([3, ...encodeWasmNumber(index)])
77831
77683
  );
77832
77684
  }
77833
77685
  exportParts.push(encodedNameBuf("__indirect_function_table"), Buffer.from([1, 0]));
77834
77686
  const replaced = /* @__PURE__ */ new Map([
77835
- [2, Buffer.concat([Buffer.from(uleb4(importEntryCount)), ...importParts])],
77687
+ [2, Buffer.concat([Buffer.from(encodeWasmNumber(importEntryCount)), ...importParts])],
77836
77688
  [6, Buffer.concat(globalParts)],
77837
77689
  [7, Buffer.concat(exportParts)]
77838
77690
  ]);
@@ -77849,7 +77701,7 @@ function resolveSdkReferences(source, sdk2, forwarders) {
77849
77701
  if (s.id === 10 && rebuiltCode) {
77850
77702
  parts2.push(rebuiltCode);
77851
77703
  } else if (payload) {
77852
- parts2.push(Buffer.from([s.id, ...uleb4(payload.length)]), payload);
77704
+ parts2.push(Buffer.from([s.id, ...encodeWasmNumber(payload.length)]), payload);
77853
77705
  } else {
77854
77706
  parts2.push(bytes.subarray(s.offset, s.end));
77855
77707
  }
@@ -77865,7 +77717,7 @@ function expandSdkRelocations(bytes, section2, patches) {
77865
77717
  patches.sort((a, b) => a.at - b.at);
77866
77718
  const r = wasmReader(bytes, section2.start);
77867
77719
  const count = r.u();
77868
- const payload = [Uint8Array.from(uleb4(count))];
77720
+ const payload = [Uint8Array.from(encodeWasmNumber(count))];
77869
77721
  let next = 0;
77870
77722
  for (let i = 0; i < count; i++) {
77871
77723
  const start = r.at;
@@ -77885,7 +77737,7 @@ function expandSdkRelocations(bytes, section2, patches) {
77885
77737
  }
77886
77738
  parts2.push(bytes.subarray(at, end));
77887
77739
  payload.push(
77888
- Uint8Array.from(uleb4(parts2.reduce((size3, part) => size3 + part.length, 0))),
77740
+ Uint8Array.from(encodeWasmNumber(parts2.reduce((size3, part) => size3 + part.length, 0))),
77889
77741
  ...parts2
77890
77742
  );
77891
77743
  }
@@ -77894,7 +77746,7 @@ function expandSdkRelocations(bytes, section2, patches) {
77894
77746
  if (next !== patches.length || r.at !== section2.end)
77895
77747
  throw new Error("Swift SDK code relocations exceed the code section");
77896
77748
  return Buffer.concat([
77897
- Uint8Array.from([10, ...uleb4(payload.reduce((size2, part) => size2 + part.length, 0))]),
77749
+ Uint8Array.from([10, ...encodeWasmNumber(payload.reduce((size2, part) => size2 + part.length, 0))]),
77898
77750
  ...payload
77899
77751
  ]);
77900
77752
  }
@@ -78586,7 +78438,7 @@ function partitionParent(section2) {
78586
78438
  "__objc_class_refs"
78587
78439
  ].find((name3) => section2 === name3 || section2.startsWith(`${name3}.`));
78588
78440
  }
78589
- var import_node_child_process40, import_node_crypto46, import_node_fs76, import_node_path74, import_node_util11, import_node_zlib5, run6, RELOCATION_WIDTHS, GLOBAL_INDEX, TLS_SLEB64, SDK_TLS_HELPER, SDK_TLS_DELTA, OBJC_SECTION_BOUNDARY, uleb4, sleb2, encodedName2, SCANNED, RUN_GAP;
78441
+ var import_node_child_process40, import_node_crypto46, import_node_fs76, import_node_path74, import_node_util11, import_node_zlib5, run6, RELOCATION_WIDTHS, GLOBAL_INDEX, TLS_SLEB64, SDK_TLS_HELPER, SDK_TLS_DELTA, OBJC_SECTION_BOUNDARY, SCANNED, RUN_GAP;
78590
78442
  var init_swift_sdk_app_module = __esm({
78591
78443
  "src/swift-sdk-app-module.ts"() {
78592
78444
  "use strict";
@@ -78609,6 +78461,7 @@ var init_swift_sdk_app_module = __esm({
78609
78461
  init_swift_wasm_prune();
78610
78462
  init_swiftSdkLinkContract();
78611
78463
  init_swiftTargetContract();
78464
+ init_wasm_binary_sections();
78612
78465
  init_wasm_narrow_boundary();
78613
78466
  init_wasm_optimize();
78614
78467
  run6 = (0, import_node_util11.promisify)(import_node_child_process40.execFile);
@@ -78629,32 +78482,6 @@ var init_swift_sdk_app_module = __esm({
78629
78482
  SDK_TLS_HELPER = "__peach_sdk_tls.";
78630
78483
  SDK_TLS_DELTA = "__peach_sdk_tls_delta.";
78631
78484
  OBJC_SECTION_BOUNDARY = /^__(?:start|stop)_(__objc_(?:selectors|classes|class_refs|cats|protocols|protocol_refs|class_aliases|constant_string))$/;
78632
- uleb4 = (value) => {
78633
- const out = [];
78634
- do {
78635
- let byte = value % 128;
78636
- value = Math.floor(value / 128);
78637
- if (value) byte |= 128;
78638
- out.push(byte);
78639
- } while (value);
78640
- return out;
78641
- };
78642
- sleb2 = (value) => {
78643
- const out = [];
78644
- for (; ; ) {
78645
- const byte = Number(value & 127n);
78646
- value >>= 7n;
78647
- if (value === 0n && !(byte & 64) || value === -1n && byte & 64) {
78648
- out.push(byte);
78649
- return out;
78650
- }
78651
- out.push(byte | 128);
78652
- }
78653
- };
78654
- encodedName2 = (name3) => {
78655
- const bytes = [...Buffer.from(name3)];
78656
- return [...uleb4(bytes.length), ...bytes];
78657
- };
78658
78485
  SCANNED = /* @__PURE__ */ new Set([
78659
78486
  "swift5_protocols",
78660
78487
  "swift5_protocol_conformances",
@@ -79782,36 +79609,22 @@ function archiveMember(archive, name3) {
79782
79609
  throw new Error(`swift-icu: ${name3} is not in the sdk's icu archive`);
79783
79610
  }
79784
79611
  function icuSegment(object9) {
79785
- let at = 8;
79786
- const leb2 = () => {
79787
- let result = 0;
79788
- let shift = 0;
79789
- let byte;
79790
- do {
79791
- byte = object9[at++];
79792
- result += (byte & 127) * 2 ** shift;
79793
- shift += 7;
79794
- } while (byte & 128);
79795
- return result;
79796
- };
79797
79612
  const found2 = [];
79798
- while (at < object9.length) {
79799
- const id = object9[at++];
79800
- const size2 = leb2();
79801
- const end = at + size2;
79802
- if (id === 11) {
79803
- for (let count = leb2(); count > 0; count--) {
79804
- if (leb2() !== 0) throw new Error("swift-icu: unexpected data segment kind");
79805
- at++;
79806
- leb2();
79807
- at++;
79808
- const length = leb2();
79809
- const bytes = object9.subarray(at, at + length);
79810
- if (bytes[2] === 218 && bytes[3] === 39) found2.push(bytes);
79811
- at += length;
79812
- }
79613
+ for (const section2 of wasmSections(object9)) {
79614
+ if (section2.id !== 11) continue;
79615
+ const reader = readWasmSection(object9, section2.start, section2.end);
79616
+ for (let count = reader.number(); count > 0; count--) {
79617
+ if (reader.number() !== 0)
79618
+ throw new Error("swift-icu: unexpected data segment kind");
79619
+ reader.byte();
79620
+ reader.number();
79621
+ reader.byte();
79622
+ const length = reader.number();
79623
+ const start = reader.position();
79624
+ const bytes = object9.subarray(start, start + length);
79625
+ if (bytes[2] === 218 && bytes[3] === 39) found2.push(bytes);
79626
+ reader.skip(length);
79813
79627
  }
79814
- at = end;
79815
79628
  }
79816
79629
  if (found2.length !== 1)
79817
79630
  throw new Error(`swift-icu: expected one icu data segment, found ${found2.length}`);
@@ -79865,6 +79678,7 @@ var init_swift_icu = __esm({
79865
79678
  init_icuData();
79866
79679
  init_swift_toolchain();
79867
79680
  init_swiftTargetContract();
79681
+ init_wasm_binary_sections();
79868
79682
  run7 = (0, import_node_util12.promisify)(import_node_child_process42.execFile);
79869
79683
  deflate = (0, import_node_util12.promisify)(import_node_zlib6.gzip);
79870
79684
  compressBrotli = (0, import_node_util12.promisify)(import_node_zlib6.brotliCompress);
@@ -86521,7 +86335,7 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
86521
86335
  REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
86522
86336
  MULTI_MANIFEST_VERSION = 76;
86523
86337
  SWIFT_HEADER_PRODUCTS_TARGET = "PeachHeaderProducts";
86524
- compilerSourceDigest = true ? "3bdbb1d31ba7d202e612a91b60a3b588f9bc94a11990fb114585b3e2521857f5" : swiftCompilerSourceDigest2(__sootsim_import_meta_dirname);
86338
+ compilerSourceDigest = true ? "816651f27c8e6bad4746f2f90d840446903e3c4a2384095dcdf1c9ceb69ceba8" : swiftCompilerSourceDigest2(__sootsim_import_meta_dirname);
86525
86339
  nativeCxxCompilerFlags = ["-fno-cxx-modules"];
86526
86340
  MODULE_MAP_RESPONSE_FILE_RUN = 16;
86527
86341
  cFlagArray = (flags) => JSON.stringify(withoutGlogModuleMap(flags));
@@ -155241,7 +155055,7 @@ var init_nitro_superset = __esm({
155241
155055
  init_nitroContract();
155242
155056
  init_swift_standin_digest();
155243
155057
  NITRO_SUPERSET_ENTRY_NAME = "superset";
155244
- NITRO_COMPILER_DIGEST = true ? "9e51ce132e701d77aa700249b4788f66b041f8f00fbd0bac84d9a3c8ed3a7569" : nitroCompilerSourceDigest(__sootsim_import_meta_dirname, STANDIN_SOURCE_DIGEST2);
155058
+ NITRO_COMPILER_DIGEST = true ? "379ef4bc3caf96c52a4ffe7df50670f16d8db945bfbc90e1513bff35258d8b6f" : nitroCompilerSourceDigest(__sootsim_import_meta_dirname, STANDIN_SOURCE_DIGEST2);
155245
155059
  nitroSupersetLock = parseLock(nitro_superset_lock_default);
155246
155060
  nitroSupersetKey = (inputs2) => nativeEntryKey({ ...inputs2, compiler: NITRO_COMPILER_DIGEST });
155247
155061
  published3 = /* @__PURE__ */ new Map();