peachsim 0.1.2622 → 0.1.2624

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 (138) 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 +693 -306
  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-FYCW5KQE.mjs → acorn-DH6VFUJ3.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-UQ3ACQY7.mjs → chunk-265THLTP.mjs} +1 -1
  28. package/dist-lib/esm-chunks/{chunk-5SDBXLYL.mjs → chunk-2YHIYKY2.mjs} +4 -4
  29. package/dist-lib/esm-chunks/{chunk-SKVUSWJU.mjs → chunk-3XA5HYI5.mjs} +6 -6
  30. package/dist-lib/esm-chunks/{chunk-W7AGZLTK.mjs → chunk-A2WMBGJO.mjs} +3 -3
  31. package/dist-lib/esm-chunks/{chunk-HY7D6BBU.mjs → chunk-AV7G5PTE.mjs} +1 -1
  32. package/dist-lib/esm-chunks/{chunk-HMWCDFVQ.mjs → chunk-CM2NU5MS.mjs} +5 -5
  33. package/dist-lib/esm-chunks/{chunk-C2QXEBC5.mjs → chunk-EFQFJ7M6.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-7Z4ESZI7.mjs → chunk-HKPKCJI5.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-N3LFPMVM.mjs → chunk-IMI2NE4A.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-G7NMIYJW.mjs → chunk-JHMD4G4V.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-67RCWRPX.mjs → chunk-LCO2EXKF.mjs} +1 -1
  38. package/dist-lib/esm-chunks/{chunk-DOCJYFRP.mjs → chunk-LD7Z3NDO.mjs} +1 -1
  39. package/dist-lib/esm-chunks/{chunk-7DFBTAWA.mjs → chunk-LMWSFXYN.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-IEVIGGKG.mjs → chunk-LOQBWIPM.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-X62EBL6H.mjs → chunk-LT533AHJ.mjs} +1 -1
  42. package/dist-lib/esm-chunks/{chunk-P64OR3XD.mjs → chunk-N4ZJZUCO.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-UR2EIB2I.mjs → chunk-OLAYY7SG.mjs} +1 -1
  44. package/dist-lib/esm-chunks/{chunk-G4CIR7M6.mjs → chunk-QNXV766K.mjs} +565 -290
  45. package/dist-lib/esm-chunks/{chunk-3XZWIVAA.mjs → chunk-QZ5HTMWV.mjs} +1 -1
  46. package/dist-lib/esm-chunks/{chunk-V7CGV5XO.mjs → chunk-T7C6Z5UH.mjs} +1 -1
  47. package/dist-lib/esm-chunks/{chunk-Y2RPOAEE.mjs → chunk-UJORQHAE.mjs} +1 -1
  48. package/dist-lib/esm-chunks/{chunk-IRUQ2NMF.mjs → chunk-VH4BJS5V.mjs} +1 -1
  49. package/dist-lib/esm-chunks/{chunk-5UDR743S.mjs → chunk-XONCLAVA.mjs} +8 -7
  50. package/dist-lib/esm-chunks/{chunk-WRQCYESG.mjs → chunk-YOD53JTM.mjs} +2 -2
  51. package/dist-lib/esm-chunks/{metro-layout-parser-GR4EJUCZ.mjs → metro-layout-parser-MDVTDJ65.mjs} +3 -3
  52. package/dist-lib/esm-chunks/{swift-package-prebuilt-CW6VQ6A5.mjs → swift-package-prebuilt-ZN7I4FYC.mjs} +12 -12
  53. package/dist-lib/esm-chunks/{swift-sdk-app-module-NULACNZJ.mjs → swift-sdk-app-module-DUVE2OXH.mjs} +107 -20
  54. package/dist-lib/esm-chunks/{swift-sdk-image-ZFATI6XZ.mjs → swift-sdk-image-YSWQBCYV.mjs} +16 -16
  55. package/dist-lib/esm-chunks/{swift-sdk-image-producer-WKVRKIRF.mjs → swift-sdk-image-producer-MZ235WSK.mjs} +5 -5
  56. package/dist-lib/expo-swift-bundle.cjs +686 -299
  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 +691 -304
  61. package/dist-lib/host/fetch-proxy-handler.cjs +7 -7
  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 +30 -15
  75. package/dist-lib/native-app-identity-project.mjs +44 -29
  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 +85 -85
  87. package/dist-lib/public-origins-lib.json +64 -64
  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 +691 -304
  95. package/dist-lib/swift-compile.cjs +638 -280
  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/package.json +1 -1
  123. package/src/bazel-project.ts +34 -18
  124. package/src/binaryen.lock.json +3 -3
  125. package/src/swift-compile.ts +8 -0
  126. package/src/swift-distribution.lock.json +8 -3
  127. package/src/swift-guest-compile.ts +170 -160
  128. package/src/swift-guest-dyld-table.ts +22 -9
  129. package/src/swift-guest-link.ts +116 -42
  130. package/src/swift-guest-linked-spans.ts +63 -14
  131. package/src/swift-guest-projection-storage.ts +7 -6
  132. package/src/swift-guest-source-inputs.ts +35 -21
  133. package/src/swift-objc-compile.ts +1 -0
  134. package/src/swift-sdk-app-module.ts +118 -15
  135. package/src/swift-sdk-image-wasm.ts +119 -17
  136. package/src/swift-sdk-image.ts +4 -1
  137. package/src/swift-wasm-prune.ts +71 -41
  138. package/src/wasm-narrow-boundary.ts +31 -6
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.2622 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.2624 | (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;
@@ -17999,13 +17999,13 @@ var init_swift_standin_digest = __esm({
17999
17999
  ];
18000
18000
  RUNTIME_IMPORT = /(?:^|[;\n])[ \t]*(?:import|export)\s+(?!type(?:\s|\{))([\s\S]*?)\s+from\s*['"]([^'"]+)['"]|(?:^|[;\n])[ \t]*import\s+['"]([^'"]+)['"]|import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
18001
18001
  standinSourceDigest = (srcDir = __sootsim_import_meta_dirname) => sourceClosureDigest(srcDir, STANDIN_DIGEST_ENTRYPOINTS, STANDIN_DIGEST_EXCLUDED_FILES);
18002
- STANDIN_SOURCE_DIGEST = true ? "434280be603d7288671556bd3927e00632cd94beab9d58010000add5587f959b" : standinSourceDigest();
18002
+ STANDIN_SOURCE_DIGEST = true ? "7f9a1a548c5ea58c56b73bfc2a755a05031acbd1b10c1c79dc32b1d6c9bea9e4" : standinSourceDigest();
18003
18003
  }
18004
18004
  });
18005
18005
 
18006
18006
  // src/expo-native-compiler-digest.ts
18007
18007
  function expoNativeCompilerDigestValue() {
18008
- return true ? "7f7c6f1e119c24a766a57ad1eb82a023ad01a7784e663fe1d68436f2a912ccac" : expoNativeCompilerDigest(__sootsim_import_meta_dirname);
18008
+ return true ? "ee97927d0c41fd6dd7d1290da2bbe36d7c9ec0fe81e3d5a7aa101cd4d446e5ab" : expoNativeCompilerDigest(__sootsim_import_meta_dirname);
18009
18009
  }
18010
18010
  var import_node_crypto17;
18011
18011
  var init_expo_native_compiler_digest = __esm({
@@ -23241,6 +23241,15 @@ function guestLinkedSpans(map2, before, after, owners, sectionOwners = /* @__PUR
23241
23241
  const unchanged = before === after;
23242
23242
  const original = layout(before, !unchanged, !importsLayout);
23243
23243
  const optimized = unchanged ? original : layout(after, true, !importsLayout);
23244
+ if (extra?.optimizedDataSegments) {
23245
+ for (const segment2 of optimized.data) {
23246
+ extra.optimizedDataSegments.push({
23247
+ address: segment2.address,
23248
+ offset: segment2.bytes.byteOffset - after.byteOffset,
23249
+ length: segment2.bytes.length
23250
+ });
23251
+ }
23252
+ }
23244
23253
  const collectSymbols = extra?.collectSymbols;
23245
23254
  const trackedObject = extra?.trackedObject;
23246
23255
  const trackedObjectOwner = extra?.trackedObjectOwner;
@@ -23409,12 +23418,39 @@ function guestLinkedSpans(map2, before, after, owners, sectionOwners = /* @__PUR
23409
23418
  }
23410
23419
  return result;
23411
23420
  };
23421
+ const singleSegmentSlice = (module2, start, length) => {
23422
+ const segs = module2.dataByAddress;
23423
+ let low = 0;
23424
+ let high = segs.length;
23425
+ while (low < high) {
23426
+ const middle = low + high >> 1;
23427
+ if (segs[middle].maximumEnd <= start) low = middle + 1;
23428
+ else high = middle;
23429
+ }
23430
+ let found;
23431
+ const end = start + length;
23432
+ for (let index = low; index < segs.length; index++) {
23433
+ const segment2 = segs[index];
23434
+ if (segment2.address >= end) break;
23435
+ if (segment2.address + segment2.bytes.length > start) {
23436
+ if (found) return void 0;
23437
+ found = segment2;
23438
+ }
23439
+ }
23440
+ if (!found || found.address > start || found.address + found.bytes.length < end)
23441
+ return void 0;
23442
+ return found.bytes.subarray(start - found.address, end - found.address);
23443
+ };
23444
+ const sameDataAt = (start, length) => {
23445
+ const origSlice = singleSegmentSlice(original, start, length);
23446
+ const optSlice = origSlice ? singleSegmentSlice(optimized, start, length) : void 0;
23447
+ if (origSlice && optSlice) return Buffer.compare(origSlice, optSlice) === 0;
23448
+ return dataAt(original, start, length).equals(dataAt(optimized, start, length));
23449
+ };
23412
23450
  for (const span of spans) {
23413
23451
  if (span.address + span.length > original.memoryBytes || span.address + span.length > optimized.memoryBytes)
23414
23452
  throw new Error(`linked data lies outside guest memory at ${span.address}`);
23415
- if (!unchanged && !dataAt(original, span.address, span.length).equals(
23416
- dataAt(optimized, span.address, span.length)
23417
- ))
23453
+ if (!unchanged && !sameDataAt(span.address, span.length))
23418
23454
  throw new Error(`optimization changed linked data at ${span.address}`);
23419
23455
  }
23420
23456
  let previous;
@@ -23548,7 +23584,7 @@ function takeGuestStartupData(wasm, address, length) {
23548
23584
  const bytes = new Uint8Array(length);
23549
23585
  const emptied = /* @__PURE__ */ new Set();
23550
23586
  let covered = 0;
23551
- const result = Buffer.from(wasm);
23587
+ const patchedBody = Buffer.from(wasm.subarray(body[0], body[1]));
23552
23588
  for (const initializer of startupDataInitializers(wasm.subarray(...body))) {
23553
23589
  const end = initializer.address + initializer.length;
23554
23590
  if (end <= address || initializer.address >= address + length || !initializer.length)
@@ -23563,19 +23599,18 @@ function takeGuestStartupData(wasm, address, length) {
23563
23599
  covered += segment2.length;
23564
23600
  emptied.add(initializer.segment);
23565
23601
  const [at, immediateEnd] = initializer.lengthImmediate;
23566
- result.fill(128, body[0] + at, body[0] + immediateEnd - 1);
23567
- result[body[0] + immediateEnd - 1] = 0;
23602
+ patchedBody.fill(128, at, immediateEnd - 1);
23603
+ patchedBody[immediateEnd - 1] = 0;
23568
23604
  }
23569
23605
  if (covered !== length)
23570
23606
  throw new Error("guest startup data does not initialize the whole range");
23571
- const parts = [result.subarray(0, data[0])];
23572
- const payload = [result.subarray(data[1], segments[0].header)];
23607
+ const payload = [wasm.subarray(data[1], segments[0].header)];
23573
23608
  for (const [index, segment2] of segments.entries()) {
23574
23609
  if (!emptied.has(index)) {
23575
- payload.push(result.subarray(segment2.header, segment2.payload + segment2.length));
23610
+ payload.push(wasm.subarray(segment2.header, segment2.payload + segment2.length));
23576
23611
  continue;
23577
23612
  }
23578
- payload.push(result.subarray(segment2.header, segment2.sizeAt), Uint8Array.of(0));
23613
+ payload.push(wasm.subarray(segment2.header, segment2.sizeAt), Uint8Array.of(0));
23579
23614
  }
23580
23615
  const section2 = Buffer.concat(payload);
23581
23616
  const size2 = [];
@@ -23586,7 +23621,14 @@ function takeGuestStartupData(wasm, address, length) {
23586
23621
  }
23587
23622
  size2.push(rest % 128 | 128);
23588
23623
  }
23589
- parts.push(Uint8Array.of(11, ...size2), section2, result.subarray(data[2]));
23624
+ const parts = [
23625
+ wasm.subarray(0, body[0]),
23626
+ patchedBody,
23627
+ wasm.subarray(body[1], data[0]),
23628
+ Uint8Array.of(11, ...size2),
23629
+ section2,
23630
+ wasm.subarray(data[2])
23631
+ ];
23590
23632
  return { wasm: Buffer.concat(parts), bytes };
23591
23633
  }
23592
23634
  var import_node_fs43, import_node_string_decoder, constant;
@@ -23895,6 +23937,32 @@ function readImports(bytes, imports2) {
23895
23937
  }
23896
23938
  return { functionTypes, importedGlobals, memoryPages };
23897
23939
  }
23940
+ function countImportedFunctions(bytes, imports2) {
23941
+ let count = 0;
23942
+ if (!imports2) return count;
23943
+ const r = wasmReader(bytes, imports2.start);
23944
+ for (let n = r.u(); n > 0; n--) {
23945
+ r.skip(r.u());
23946
+ r.skip(r.u());
23947
+ const kind = r.byte();
23948
+ if (kind === 0) {
23949
+ r.u();
23950
+ count++;
23951
+ } else if (kind === 1) {
23952
+ r.byte();
23953
+ skipLimits(r);
23954
+ } else if (kind === 2) {
23955
+ skipLimits(r);
23956
+ } else if (kind === 3) {
23957
+ r.byte();
23958
+ r.byte();
23959
+ } else if (kind === 4) {
23960
+ r.byte();
23961
+ r.u();
23962
+ } else throw new Error(`unknown wasm import kind ${kind}`);
23963
+ }
23964
+ return count;
23965
+ }
23898
23966
  function* readFunctionNames(bytes, names) {
23899
23967
  for (const r = wasmReader(bytes, names.start); r.at < names.end; ) {
23900
23968
  const id = r.byte();
@@ -24262,28 +24330,73 @@ function codeOnlySdkImage(bytes, constructorMask) {
24262
24330
  return Buffer.concat(out);
24263
24331
  }
24264
24332
  function constructorKeys(map2, bytes) {
24265
- const m = readModule(bytes);
24266
24333
  const first = map2.code[0];
24267
- if (!first || !m.bodies.length) throw new Error("link has no code");
24268
- const prefixes = m.bodies.map(({ prefix }) => prefix);
24269
- const delta = prefixes[0] - first.offset;
24270
- const byOffset = new Map(map2.code.map((chunk) => [chunk.offset + delta, chunk]));
24334
+ if (!first) throw new Error("link has no code");
24335
+ const sections = wasmSections(bytes);
24336
+ const code = sections.find((s) => s.id === 10);
24337
+ if (!code) throw new Error("link has no code");
24271
24338
  const ctors = map2.code.find((chunk) => chunk.section === "__wasm_call_ctors");
24272
24339
  if (!ctors) throw new Error("link has no constructors");
24273
- const index = prefixes.indexOf(ctors.offset + delta);
24274
- if (index < 0) throw new Error("constructor function not found by map offset");
24275
- const body = m.bodies[index];
24276
- const r = wasmReader(bytes, body.start);
24340
+ const importedFuncs = countImportedFunctions(
24341
+ bytes,
24342
+ sections.find((s) => s.id === 2)
24343
+ );
24344
+ const codeReader = wasmReader(bytes, code.start);
24345
+ const bodyCount = codeReader.u();
24346
+ if (!bodyCount) throw new Error("link has no code");
24347
+ const prefixes = new Uint32Array(bodyCount);
24348
+ let delta = 0;
24349
+ let ctorPrefix = -1;
24350
+ let ctorStart = -1;
24351
+ let ctorEnd = -1;
24352
+ for (let i = 0; i < bodyCount; i++) {
24353
+ const prefix = codeReader.at;
24354
+ const size2 = codeReader.u();
24355
+ prefixes[i] = prefix;
24356
+ if (i === 0) {
24357
+ delta = prefix - first.offset;
24358
+ ctorPrefix = ctors.offset + delta;
24359
+ }
24360
+ if (prefix === ctorPrefix) {
24361
+ ctorStart = codeReader.at;
24362
+ ctorEnd = ctorStart + size2;
24363
+ }
24364
+ codeReader.skip(size2);
24365
+ }
24366
+ if (ctorStart < 0) throw new Error("constructor function not found by map offset");
24367
+ let sorted2 = true;
24368
+ for (let i = 1; i < map2.code.length; i++) {
24369
+ if (map2.code[i].offset < map2.code[i - 1].offset) {
24370
+ sorted2 = false;
24371
+ break;
24372
+ }
24373
+ }
24374
+ const byOffset = sorted2 ? void 0 : new Map(map2.code.map((chunk) => [chunk.offset + delta, chunk]));
24375
+ const findChunk = (targetPrefix) => {
24376
+ if (byOffset) return byOffset.get(targetPrefix);
24377
+ const targetOffset = targetPrefix - delta;
24378
+ let lo = 0;
24379
+ let hi = map2.code.length - 1;
24380
+ while (lo <= hi) {
24381
+ const mid = lo + hi >> 1;
24382
+ const offset = map2.code[mid].offset;
24383
+ if (offset < targetOffset) lo = mid + 1;
24384
+ else if (offset > targetOffset) hi = mid - 1;
24385
+ else return map2.code[mid];
24386
+ }
24387
+ return void 0;
24388
+ };
24389
+ const r = wasmReader(bytes, ctorStart);
24277
24390
  for (let n = r.u(); n > 0; n--) {
24278
24391
  r.u();
24279
24392
  r.byte();
24280
24393
  }
24281
24394
  const keys = [];
24282
- while (r.at < body.end) {
24395
+ while (r.at < ctorEnd) {
24283
24396
  const op = r.byte();
24284
24397
  if (op === 16) {
24285
- const callee = r.u() - m.importedFuncs;
24286
- const chunk = byOffset.get(prefixes[callee]);
24398
+ const callee = r.u() - importedFuncs;
24399
+ const chunk = callee >= 0 && callee < bodyCount ? findChunk(prefixes[callee]) : void 0;
24287
24400
  if (!chunk) throw new Error("constructor without a map chunk");
24288
24401
  keys.push(chunkKey(chunk, ""));
24289
24402
  } else if (op !== 26 && op !== 11) throw new Error(`constructor op ${op}`);
@@ -24366,7 +24479,10 @@ function relocationEdges(bytes, segmentAddress) {
24366
24479
  r.skip(r.u());
24367
24480
  }
24368
24481
  }
24369
- const importedFunctions = readModule(bytes).importedFuncs;
24482
+ const importedFunctions = countImportedFunctions(
24483
+ bytes,
24484
+ sections.find((s) => s.id === 2)
24485
+ );
24370
24486
  const data = [];
24371
24487
  const dataFunctions = [];
24372
24488
  const bodyCount = bodyStarts.length;
@@ -24480,9 +24596,30 @@ function strongDefinitions(bytes) {
24480
24596
  ).map((s) => s.name);
24481
24597
  }
24482
24598
  function unslottedFunctions(bytes) {
24483
- const m = readModule(bytes);
24484
- const slotted = new Set([...m.slots.keys()].filter((index) => index >= m.importedFuncs));
24485
- return m.bodies.length - slotted.size;
24599
+ const sections = wasmSections(bytes);
24600
+ const importedFuncs = countImportedFunctions(
24601
+ bytes,
24602
+ sections.find((s) => s.id === 2)
24603
+ );
24604
+ const code = sections.find((s) => s.id === 10);
24605
+ const definedFuncs = code ? wasmReader(bytes, code.start).u() : 0;
24606
+ const slotted = /* @__PURE__ */ new Set();
24607
+ const elements = sections.find((s) => s.id === 9);
24608
+ if (elements) {
24609
+ const r = wasmReader(bytes, elements.start);
24610
+ for (let n = r.u(); n > 0; n--) {
24611
+ const flags = r.u();
24612
+ if (flags !== 0 && flags !== 2) throw new Error(`sdk image element flags ${flags}`);
24613
+ if (flags === 2) r.u();
24614
+ constant2(r);
24615
+ if (flags === 2) r.byte();
24616
+ for (let i = 0, count = r.u(); i < count; i++) {
24617
+ const index = r.u();
24618
+ if (index >= importedFuncs) slotted.add(index);
24619
+ }
24620
+ }
24621
+ }
24622
+ return definedFuncs - slotted.size;
24486
24623
  }
24487
24624
  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;
24488
24625
  var init_swift_sdk_image_wasm = __esm({
@@ -24866,6 +25003,11 @@ var init_swiftRuntimeProductContract = __esm({
24866
25003
  });
24867
25004
 
24868
25005
  // src/swift-wasm-prune.ts
25006
+ function sha256Hex(bytes) {
25007
+ if (typeof Bun !== "undefined")
25008
+ return new Bun.CryptoHasher("sha256").update(bytes).digest("hex");
25009
+ return (0, import_node_crypto24.createHash)("sha256").update(bytes).digest("hex");
25010
+ }
24869
25011
  function readULEB2(b, o) {
24870
25012
  let res = 0;
24871
25013
  let shift = 0;
@@ -25618,6 +25760,42 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
25618
25760
  }
25619
25761
  }
25620
25762
  }
25763
+ const segObjCClasses = /* @__PURE__ */ new Map();
25764
+ for (let segIdx = 0; segIdx < sEnds.length; segIdx++) {
25765
+ const rangeStart = dataStart + sPayloadStarts[segIdx];
25766
+ const rangeEnd = dataStart + sEnds[segIdx];
25767
+ const sliceLen = rangeEnd - rangeStart;
25768
+ if (sliceLen < 4) continue;
25769
+ const slice = Buffer.from(rawBuf.buffer, rawBuf.byteOffset + rangeStart, sliceLen);
25770
+ let segPos = 0;
25771
+ let classes;
25772
+ while (segPos < sliceLen - 3) {
25773
+ const at = slice.indexOf("So", segPos);
25774
+ if (at < 0 || at >= sliceLen - 2) break;
25775
+ let digitEnd = at + 2;
25776
+ let length = 0;
25777
+ while (digitEnd < sliceLen) {
25778
+ const ch = slice[digitEnd];
25779
+ if (ch < 48 || ch > 57) break;
25780
+ length = length * 10 + (ch - 48);
25781
+ digitEnd++;
25782
+ }
25783
+ if (digitEnd === at + 2) {
25784
+ segPos = at + 2;
25785
+ continue;
25786
+ }
25787
+ segPos = digitEnd;
25788
+ const nameEnd = digitEnd + length;
25789
+ if (nameEnd >= sliceLen || slice[nameEnd] !== 67) continue;
25790
+ const symbol2 = `._OBJC_CLASS_${slice.toString("latin1", digitEnd, nameEnd)}`;
25791
+ if (!classes) {
25792
+ classes = [symbol2];
25793
+ segObjCClasses.set(segIdx, classes);
25794
+ } else if (!classes.includes(symbol2)) {
25795
+ classes.push(symbol2);
25796
+ }
25797
+ }
25798
+ }
25621
25799
  return {
25622
25800
  file,
25623
25801
  isDist,
@@ -25647,10 +25825,7 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
25647
25825
  objcCategoryTargets,
25648
25826
  rootFuncs,
25649
25827
  rootSegs,
25650
- segPayloadRanges: sEnds.map((end, i) => [
25651
- dataStart + sPayloadStarts[i],
25652
- dataStart + end
25653
- ])
25828
+ segObjCClasses
25654
25829
  };
25655
25830
  }
25656
25831
  function parseWasmObjectFile(file, isDist) {
@@ -26018,16 +26193,26 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
26018
26193
  transformations.set(file, {
26019
26194
  output,
26020
26195
  inputSha256,
26021
- outputSha256: (0, import_node_crypto24.createHash)("sha256").update(result).digest("hex"),
26196
+ outputSha256: sha256Hex(result),
26022
26197
  kind
26023
26198
  });
26024
26199
  };
26025
26200
  const distFiles = [];
26026
26201
  const distBaseNames = /* @__PURE__ */ new Set();
26027
26202
  const eagerFiles = [];
26203
+ const parsedBuildObjects = /* @__PURE__ */ new Map();
26028
26204
  const lazyBuildObjects = /* @__PURE__ */ new Map();
26029
26205
  const extraArchiveObjs = [];
26030
26206
  const objectBytes = /* @__PURE__ */ new Map();
26207
+ const archiveMembers = /* @__PURE__ */ new Map();
26208
+ const readArchiveMembers = (archive) => {
26209
+ let members2 = archiveMembers.get(archive);
26210
+ if (!members2) {
26211
+ members2 = readArMembers(new Uint8Array(import_node_fs44.default.readFileSync(archive)));
26212
+ archiveMembers.set(archive, members2);
26213
+ }
26214
+ return members2;
26215
+ };
26031
26216
  let inStartLib = false;
26032
26217
  let swiftrtOrigPath = "";
26033
26218
  for (const t of tokens2) {
@@ -26064,8 +26249,10 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
26064
26249
  break;
26065
26250
  }
26066
26251
  }
26067
- if (definesObjCClassOrCategory) eagerFiles.push(t);
26068
- else lazyBuildObjects.set(t, obj);
26252
+ if (definesObjCClassOrCategory) {
26253
+ parsedBuildObjects.set(t, obj);
26254
+ eagerFiles.push(t);
26255
+ } else lazyBuildObjects.set(t, obj);
26069
26256
  } else {
26070
26257
  eagerFiles.push(t);
26071
26258
  }
@@ -26073,7 +26260,7 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
26073
26260
  lazyBuildObjects.set(t, parseWasmObjectFile(t, false));
26074
26261
  }
26075
26262
  } else if (!inStartLib && t.endsWith(".a") && !t.endsWith("libclang_rt.builtins-wasm64.a") && import_node_fs44.default.existsSync(t)) {
26076
- const members2 = readArMembers(new Uint8Array(import_node_fs44.default.readFileSync(t)));
26263
+ const members2 = readArchiveMembers(t);
26077
26264
  for (const m of members2) {
26078
26265
  const object8 = parseWasmObjectBytes(`${t}(${m.name})`, m.bytes, false);
26079
26266
  extraArchiveObjs.push(object8);
@@ -26096,7 +26283,7 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
26096
26283
  );
26097
26284
  const archiveOverlapsDist = (archive) => {
26098
26285
  if (!import_node_fs44.default.existsSync(archive)) return false;
26099
- const members2 = readArMembers(new Uint8Array(import_node_fs44.default.readFileSync(archive)));
26286
+ const members2 = readArchiveMembers(archive);
26100
26287
  return members2.some((m) => distBaseNames.has(m.name));
26101
26288
  };
26102
26289
  for (const t of tokens2) {
@@ -26118,7 +26305,7 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
26118
26305
  import_node_path43.default.basename(archive)
26119
26306
  );
26120
26307
  const ordinals = /* @__PURE__ */ new Map();
26121
- for (const m of readArMembers(new Uint8Array(import_node_fs44.default.readFileSync(archive)))) {
26308
+ for (const m of readArchiveMembers(archive)) {
26122
26309
  const ordinal = (ordinals.get(m.name) ?? 0) + 1;
26123
26310
  ordinals.set(m.name, ordinal);
26124
26311
  if (distBaseNames.has(m.name) || writtenLeftovers.has(m.name)) continue;
@@ -26152,7 +26339,7 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
26152
26339
  recordTransformation(
26153
26340
  swiftrtOrigPath,
26154
26341
  patchedSwiftrtPath,
26155
- link ? (0, import_node_crypto24.createHash)("sha256").update(input).digest("hex") : "",
26342
+ link ? sha256Hex(input) : "",
26156
26343
  result,
26157
26344
  "swiftrt"
26158
26345
  );
@@ -26639,7 +26826,7 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
26639
26826
  }
26640
26827
  for (const f of eagerFiles) {
26641
26828
  const isDist = f.startsWith(distDir);
26642
- const obj = distObjs.get(f) ?? parseWasmObjectFile(f, isDist);
26829
+ const obj = distObjs.get(f) ?? parsedBuildObjects.get(f) ?? parseWasmObjectFile(f, isDist);
26643
26830
  extractObject(obj);
26644
26831
  if (isDist) {
26645
26832
  const base = import_node_path43.default.basename(f);
@@ -26689,32 +26876,9 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
26689
26876
  "$s10Foundation6BundleC22preferredLocalizations4fromSaySSGAF_tFZTf4nd_n"
26690
26877
  ]);
26691
26878
  const keepObjCClassesNamedInSegment = (obj, segIdx) => {
26692
- const range3 = obj.segPayloadRanges[segIdx];
26693
- if (!range3) return;
26694
- const [rangeStart, rangeEnd] = range3;
26695
- if (rangeEnd - rangeStart < 4) return;
26696
- let bytes = objectBytes.get(obj);
26697
- if (!bytes) objectBytes.set(obj, bytes = import_node_fs44.default.readFileSync(obj.file));
26698
- let pos = rangeStart;
26699
- while (pos < rangeEnd - 3) {
26700
- const at = bytes.indexOf("So", pos);
26701
- if (at < 0 || at >= rangeEnd - 2) break;
26702
- let digitEnd = at + 2;
26703
- let length = 0;
26704
- while (digitEnd < rangeEnd) {
26705
- const ch = bytes[digitEnd];
26706
- if (ch < 48 || ch > 57) break;
26707
- length = length * 10 + (ch - 48);
26708
- digitEnd++;
26709
- }
26710
- if (digitEnd === at + 2) {
26711
- pos = at + 2;
26712
- continue;
26713
- }
26714
- pos = digitEnd;
26715
- const nameEnd = digitEnd + length;
26716
- if (nameEnd >= rangeEnd || bytes[nameEnd] !== 67) continue;
26717
- const symbol2 = `._OBJC_CLASS_${bytes.toString("latin1", digitEnd, nameEnd)}`;
26879
+ const symbols = obj.segObjCClasses.get(segIdx);
26880
+ if (!symbols) return;
26881
+ for (const symbol2 of symbols) {
26718
26882
  for (const provider of lazyProviders.get(symbol2) ?? []) {
26719
26883
  eagerDynamicObjects.add(provider);
26720
26884
  extractObject(provider);
@@ -26810,7 +26974,7 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
26810
26974
  const cached2 = objectBytes.get(obj);
26811
26975
  const buf = cached2 ? new Uint8Array(cached2) : new Uint8Array(import_node_fs44.default.readFileSync(obj.file));
26812
26976
  const rawBuf = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
26813
- const inputSha256 = link ? (0, import_node_crypto24.createHash)("sha256").update(buf).digest("hex") : "";
26977
+ const inputSha256 = link ? sha256Hex(buf) : "";
26814
26978
  const fLive = liveFuncs.get(obj);
26815
26979
  const sLive = liveSegs.get(obj);
26816
26980
  const dLive = liveDataSyms.get(obj);
@@ -29064,13 +29228,34 @@ function dropWasmCustomSection(bytes, name3) {
29064
29228
  }
29065
29229
  return Buffer.concat(parts);
29066
29230
  }
29231
+ function writeWasmCustomSections(bytes, entries2) {
29232
+ if (entries2.length === 0) return Buffer.concat([bytes]);
29233
+ const replaced = new Set(entries2.map(([name3]) => name3));
29234
+ const parts = [];
29235
+ let sliceStart = 0;
29236
+ let sliceEnd = 8;
29237
+ for (const { id, start, end } of wasmSections2(bytes)) {
29238
+ if (id === 0 && replaced.has(readWasmSection(bytes, start, end).name())) {
29239
+ if (sliceEnd > sliceStart) parts.push(bytes.subarray(sliceStart, sliceEnd));
29240
+ sliceStart = end;
29241
+ sliceEnd = end;
29242
+ } else {
29243
+ sliceEnd = end;
29244
+ }
29245
+ }
29246
+ if (sliceEnd > sliceStart) parts.push(bytes.subarray(sliceStart, sliceEnd));
29247
+ for (const [name3, data] of entries2) {
29248
+ const nameBytes = Buffer.from(encodeWasmName(name3));
29249
+ parts.push(
29250
+ Buffer.from([0, ...encodeWasmNumber(nameBytes.length + data.length)]),
29251
+ nameBytes,
29252
+ data
29253
+ );
29254
+ }
29255
+ return Buffer.concat(parts);
29256
+ }
29067
29257
  function writeWasmCustomSection(bytes, name3, data) {
29068
- const section2 = Buffer.concat([Buffer.from(encodeWasmName(name3)), data]);
29069
- return Buffer.concat([
29070
- dropWasmCustomSection(bytes, name3),
29071
- Buffer.from([0, ...encodeWasmNumber(section2.length)]),
29072
- section2
29073
- ]);
29258
+ return writeWasmCustomSections(bytes, [[name3, data]]);
29074
29259
  }
29075
29260
  function readWasmMemory(bytes) {
29076
29261
  return readWasmMemoryAndTableImports(bytes, wasmSections2(bytes)).memory;
@@ -29342,6 +29527,16 @@ var init_wasm_narrow_boundary = __esm({
29342
29527
  });
29343
29528
 
29344
29529
  // src/swift-guest-dyld-table.ts
29530
+ function sha256Buffer(bytes) {
29531
+ if (typeof Bun !== "undefined")
29532
+ return Buffer.from(new Bun.CryptoHasher("sha256").update(bytes).digest());
29533
+ return (0, import_node_crypto27.createHash)("sha256").update(bytes).digest();
29534
+ }
29535
+ function sha256Hex2(bytes) {
29536
+ if (typeof Bun !== "undefined")
29537
+ return new Bun.CryptoHasher("sha256").update(bytes).digest("hex");
29538
+ return (0, import_node_crypto27.createHash)("sha256").update(bytes).digest("hex");
29539
+ }
29345
29540
  function uleb3(value) {
29346
29541
  const bytes = [];
29347
29542
  for (let rest = value; ; rest = Math.floor(rest / 128)) {
@@ -29376,7 +29571,7 @@ function encodeGuestDyldTable(rows) {
29376
29571
  }
29377
29572
  const file = Buffer.concat(packs);
29378
29573
  const header = Buffer.alloc(40 + packs.length * 8);
29379
- (0, import_node_crypto27.createHash)("sha256").update(file).digest().copy(header, 0);
29574
+ sha256Buffer(file).copy(header, 0);
29380
29575
  header.writeUInt32LE(file.length, 32);
29381
29576
  header.writeUInt32LE(packs.length, 36);
29382
29577
  let offset = 0;
@@ -29388,11 +29583,11 @@ function encodeGuestDyldTable(rows) {
29388
29583
  const names = firsts.flatMap((name3) => [name3, Buffer.of(0)]);
29389
29584
  return { index: Buffer.concat([header, ...names]), packs: file };
29390
29585
  }
29391
- function moveGuestDyldTable(map2, wasm, symbols, bindingValues = /* @__PURE__ */ new Map()) {
29586
+ function moveGuestDyldTable(map2, wasm, symbols, bindingValues = /* @__PURE__ */ new Map(), extraSections = []) {
29392
29587
  const range3 = guestDyldValueRange(map2);
29393
29588
  if (!range3) {
29394
29589
  if (symbols.length) throw new Error("link map has no dyld values");
29395
- return wasm;
29590
+ return extraSections.length ? writeWasmCustomSections(wasm, extraSections) : wasm;
29396
29591
  }
29397
29592
  if (range3.length !== symbols.length * 8)
29398
29593
  throw new Error("linked dyld values do not match the ledger rows");
@@ -29407,11 +29602,11 @@ function moveGuestDyldTable(map2, wasm, symbols, bindingValues = /* @__PURE__ */
29407
29602
  return binding === void 0 ? { name: name3, image, kind: 0, value: view.getBigUint64(index2 * 8, true) } : { name: name3, image, kind: 1, value: BigInt(binding) };
29408
29603
  });
29409
29604
  const { index, packs } = encodeGuestDyldTable(rows);
29410
- return writeWasmCustomSection(
29411
- writeWasmCustomSection(taken.wasm, NATIVE_DYLD_TABLE_SECTION, index),
29412
- NATIVE_DYLD_PACKS_SECTION,
29413
- packs
29414
- );
29605
+ return writeWasmCustomSections(taken.wasm, [
29606
+ [NATIVE_DYLD_TABLE_SECTION, index],
29607
+ [NATIVE_DYLD_PACKS_SECTION, packs],
29608
+ ...extraSections
29609
+ ]);
29415
29610
  }
29416
29611
  function guestDyldValueRange(map2) {
29417
29612
  const suffix = `:(${GUEST_DYLD_VALUES_SECTION})`;
@@ -29440,7 +29635,7 @@ function splitSwiftDyldTable(wasm) {
29440
29635
  const bytes = Buffer.from(packs);
29441
29636
  return {
29442
29637
  module: dropWasmCustomSection(wasm, NATIVE_DYLD_PACKS_SECTION),
29443
- table: { sha256: (0, import_node_crypto27.createHash)("sha256").update(bytes).digest("hex"), bytes }
29638
+ table: { sha256: sha256Hex2(bytes), bytes }
29444
29639
  };
29445
29640
  }
29446
29641
  var import_node_crypto27, import_node_zlib3, PACK_BYTES;
@@ -29976,6 +30171,7 @@ function finalizeGuestProjectionStorage(options2) {
29976
30171
  const owner = options2.owners.get(options2.projectionObject);
29977
30172
  if (owner === void 0) throw new Error("guest projection object has no image owner");
29978
30173
  const ranges = [];
30174
+ const data = [];
29979
30175
  const spans = guestLinkedSpans(
29980
30176
  options2.map,
29981
30177
  options2.linked,
@@ -29986,7 +30182,8 @@ function finalizeGuestProjectionStorage(options2) {
29986
30182
  {
29987
30183
  trackedObject: options2.projectionObject,
29988
30184
  trackedObjectOwner: owner,
29989
- trackedLinearSpans: ranges
30185
+ trackedLinearSpans: ranges,
30186
+ optimizedDataSegments: data
29990
30187
  }
29991
30188
  );
29992
30189
  const images = planGuestProjectionRegions(
@@ -29995,7 +30192,6 @@ function finalizeGuestProjectionStorage(options2) {
29995
30192
  options2.sdkSpans ? [...spans, ...options2.sdkSpans] : spans
29996
30193
  );
29997
30194
  const result = Buffer.from(options2.optimized);
29998
- const data = guestWasmDataSegments(options2.optimized, options2.sdkSpans === void 0);
29999
30195
  const locations = /* @__PURE__ */ new Map();
30000
30196
  const counts = /* @__PURE__ */ new Map();
30001
30197
  const uuids = /* @__PURE__ */ new Map();
@@ -30669,17 +30865,17 @@ var init_binaryen_lock = __esm({
30669
30865
  "linux-x64": {
30670
30866
  asset: "x86_64-linux",
30671
30867
  upstreamSha256: "195ddc94f9bc89f45abdabb0b9eea86023d727ba90eac8b35b80f2544fc30572",
30672
- sha256: "1024974f254c1c2edd738246ec6af5add16d3d36b5f58a94545febda3b33c869"
30868
+ sha256: "40062fb1ebbad7f04f361c1e3bb309dffb1d2318dd2e12235a0e7e820e18d6c9"
30673
30869
  },
30674
30870
  "linux-arm64": {
30675
30871
  asset: "aarch64-linux",
30676
30872
  upstreamSha256: "c58562417836c5d0493d89bdefc434933bdc097db641b483df86bcfa557a107f",
30677
- sha256: "7dedfc9f5cb32e75a28831f3b5aa053fd3e0bdd74f73dc4d1b1588947236daef"
30873
+ sha256: "d79b09d5b66f62f9e4bb691517b174b42bcdc0b7f40769d1993b7c565b0a54c7"
30678
30874
  },
30679
30875
  "darwin-arm64": {
30680
30876
  asset: "arm64-macos",
30681
30877
  upstreamSha256: "98aad827847af7ef990ed7098d885725c8e5b5aae75073403635617ae4e259aa",
30682
- sha256: "0b56e0a06b6a873877871537a120fd94e2121e67f4bce5f8b5252c47b615854a"
30878
+ sha256: "29342632a4fa52466c4feea846698fe5aa56ff46226a914d60b65b8735373d63"
30683
30879
  }
30684
30880
  }
30685
30881
  };
@@ -31173,6 +31369,7 @@ function outputPath(args) {
31173
31369
  }
31174
31370
  function withOutput(args, output, discovery) {
31175
31371
  const result = [];
31372
+ let stripsDebug = false;
31176
31373
  for (let i = 0; i < args.length; i++) {
31177
31374
  const arg = args[i];
31178
31375
  if (arg === "-o" || arg === "--output") {
@@ -31182,9 +31379,12 @@ function withOutput(args, output, discovery) {
31182
31379
  if (arg.startsWith("--output=")) continue;
31183
31380
  if (discovery && (arg.startsWith("--why-extract=") || arg.startsWith("--Map=")))
31184
31381
  continue;
31382
+ if (arg === "--strip-debug" || arg === "-S" || arg === "--strip-all" || arg === "-s")
31383
+ stripsDebug = true;
31185
31384
  result.push(arg);
31186
31385
  }
31187
31386
  if (discovery) result.push("--allow-multiple-definition");
31387
+ if (!stripsDebug) result.push("--strip-debug");
31188
31388
  result.push("-o", output);
31189
31389
  return result;
31190
31390
  }
@@ -31215,6 +31415,37 @@ async function linkGuestImages(options2) {
31215
31415
  }
31216
31416
  return import_node_fs49.default.readFileSync(trace, "utf8");
31217
31417
  };
31418
+ const runLinkAsync = async (name3, arguments_) => {
31419
+ const response = import_node_path47.default.join(directory2, `${name3}.rsp`);
31420
+ const trace = import_node_path47.default.join(directory2, `${name3}-inputs.txt`);
31421
+ import_node_fs49.default.writeFileSync(
31422
+ response,
31423
+ [...arguments_, "--trace"].map((argument2) => JSON.stringify(argument2)).join(" ")
31424
+ );
31425
+ const output = import_node_fs49.default.openSync(trace, "w");
31426
+ try {
31427
+ await new Promise((resolve3, reject) => {
31428
+ const child = (0, import_node_child_process25.spawn)(wasmLd, [`@${response}`], {
31429
+ stdio: ["ignore", output, "pipe"]
31430
+ });
31431
+ const stderr = [];
31432
+ child.stderr?.on("data", (chunk) => stderr.push(chunk));
31433
+ child.once("error", reject);
31434
+ child.once("close", (code, signal) => {
31435
+ if (code === 0) resolve3();
31436
+ else
31437
+ reject(
31438
+ new Error(
31439
+ `wasm-ld (${name3}) failed (${signal ?? code}): ${Buffer.concat(stderr).toString("utf8")}`
31440
+ )
31441
+ );
31442
+ });
31443
+ });
31444
+ } finally {
31445
+ import_node_fs49.default.closeSync(output);
31446
+ }
31447
+ return import_node_fs49.default.readFileSync(trace, "utf8");
31448
+ };
31218
31449
  const preselection = options2.projection && options2.preselectionDiscovery ? options2.preselectionDiscovery : void 0;
31219
31450
  let discoveryProjection;
31220
31451
  if (options2.projection) {
@@ -31444,6 +31675,7 @@ async function linkGuestImages(options2) {
31444
31675
  };
31445
31676
  const ledgerObjectPromise = compileLedgerAsync("ledger", ledger.llvmIR);
31446
31677
  const appLedgerObjectPromise = options2.onSplitInputs && ledger.appLLVMIR ? compileLedgerAsync("app-ledger", ledger.appLLVMIR) : void 0;
31678
+ let deferredFinalLink;
31447
31679
  try {
31448
31680
  const replacements = /* @__PURE__ */ new Map();
31449
31681
  const linkedOwners = /* @__PURE__ */ new Map();
@@ -31545,7 +31777,7 @@ async function linkGuestImages(options2) {
31545
31777
  });
31546
31778
  const finalOutput = import_node_path47.default.join(directory2, "final.wasm");
31547
31779
  const finalWhy = import_node_path47.default.join(directory2, "final-why-extract.txt");
31548
- const linkFinal = (projectionObject2, layoutMap) => runLink("final", [
31780
+ const finalLinkArgs = (projectionObject2, layoutMap) => [
31549
31781
  ...withOutput(finalArgs, finalOutput, false),
31550
31782
  ledgerObject,
31551
31783
  `@${lazyExports}`,
@@ -31553,10 +31785,38 @@ async function linkGuestImages(options2) {
31553
31785
  ...provider ? [`--undefined=${providerSymbol}`] : [],
31554
31786
  ...layoutMap ? [`--Map=${layoutMap}`] : [],
31555
31787
  `--why-extract=${finalWhy}`
31556
- ]);
31788
+ ];
31789
+ const linkFinal = (projectionObject2, layoutMap) => runLink("final", finalLinkArgs(projectionObject2, layoutMap));
31790
+ const finalizeFinalLink = (trace) => {
31791
+ const finalSelection = selectedGuestLinkInputs(
31792
+ remapGuestLinkPlan(plan, replacements),
31793
+ finalArgs,
31794
+ import_node_fs49.default.readFileSync(finalWhy, "utf8"),
31795
+ trace,
31796
+ finalArchives
31797
+ );
31798
+ const original = new Map(
31799
+ [...replacements].map(([before2, after2]) => [after2, before2])
31800
+ );
31801
+ const key2 = (item) => JSON.stringify([original.get(item.artifact) ?? item.artifact, item.member]);
31802
+ const before = new Set(selected.map(key2));
31803
+ const after = new Set(finalSelection.map(key2));
31804
+ const changed = [...before].filter((item) => !after.has(item));
31805
+ changed.push(...[...after].filter((item) => !before.has(item)));
31806
+ if (changed.length)
31807
+ throw new Error(
31808
+ `guest link selected different inputs after rewriting:
31809
+ ${changed.join("\n")}`
31810
+ );
31811
+ import_node_fs49.default.renameSync(finalOutput, outputPath(args));
31812
+ if (KEEP_WASM_NAMES)
31813
+ import_node_fs49.default.writeFileSync(
31814
+ outputPath(args),
31815
+ nameGuestImageAliases(import_node_fs49.default.readFileSync(outputPath(args)), plan.symbols)
31816
+ );
31817
+ };
31557
31818
  let projectionObject;
31558
31819
  let projectionStorage;
31559
- let finalTrace;
31560
31820
  if (options2.projection) {
31561
31821
  const projection = options2.projection;
31562
31822
  if (!plan.images.some((image) => image.id === projection.image))
@@ -31609,8 +31869,18 @@ async function linkGuestImages(options2) {
31609
31869
  [...projection.clangOptions, "-c", projectionSource, "-o", projectionObject],
31610
31870
  { stdio: "pipe" }
31611
31871
  );
31612
- finalTrace = linkFinal(projectionObject, callerMap ? void 0 : layoutMap);
31613
- if (sharedSdk) break;
31872
+ if (sharedSdk && options2.onFinalLink && options2.onSplitInputs && appLedgerObjectPromise) {
31873
+ deferredFinalLink = runLinkAsync(
31874
+ "final",
31875
+ finalLinkArgs(projectionObject, callerMap ? void 0 : layoutMap)
31876
+ ).then((trace) => finalizeFinalLink(trace));
31877
+ break;
31878
+ }
31879
+ const finalTrace = linkFinal(projectionObject, callerMap ? void 0 : layoutMap);
31880
+ if (sharedSdk) {
31881
+ finalizeFinalLink(finalTrace);
31882
+ break;
31883
+ }
31614
31884
  const wasm = import_node_fs49.default.readFileSync(finalOutput);
31615
31885
  const actual = guestProjectionRegionCounts(
31616
31886
  images.length,
@@ -31622,38 +31892,17 @@ async function linkGuestImages(options2) {
31622
31892
  sectionOwners
31623
31893
  )
31624
31894
  );
31625
- if (actual.every((count, index) => count <= capacities[index].regions)) break;
31895
+ if (actual.every((count, index) => count <= capacities[index].regions)) {
31896
+ finalizeFinalLink(finalTrace);
31897
+ break;
31898
+ }
31626
31899
  capacities = capacities.map((capacity, index) => ({
31627
31900
  ...capacity,
31628
31901
  regions: Math.max(actual[index], capacity.regions)
31629
31902
  }));
31630
31903
  }
31631
31904
  linkedOwners.set(projectionObject, projection.image);
31632
- } else finalTrace = linkFinal();
31633
- const finalSelection = selectedGuestLinkInputs(
31634
- remapGuestLinkPlan(plan, replacements),
31635
- finalArgs,
31636
- import_node_fs49.default.readFileSync(finalWhy, "utf8"),
31637
- finalTrace,
31638
- finalArchives
31639
- );
31640
- const original = new Map([...replacements].map(([before2, after2]) => [after2, before2]));
31641
- const key2 = (item) => JSON.stringify([original.get(item.artifact) ?? item.artifact, item.member]);
31642
- const before = new Set(selected.map(key2));
31643
- const after = new Set(finalSelection.map(key2));
31644
- const changed = [...before].filter((item) => !after.has(item));
31645
- changed.push(...[...after].filter((item) => !before.has(item)));
31646
- if (changed.length)
31647
- throw new Error(
31648
- `guest link selected different inputs after rewriting:
31649
- ${changed.join("\n")}`
31650
- );
31651
- import_node_fs49.default.renameSync(finalOutput, outputPath(args));
31652
- if (KEEP_WASM_NAMES)
31653
- import_node_fs49.default.writeFileSync(
31654
- outputPath(args),
31655
- nameGuestImageAliases(import_node_fs49.default.readFileSync(outputPath(args)), plan.symbols)
31656
- );
31905
+ } else finalizeFinalLink(linkFinal());
31657
31906
  if (projectionStorage && projectionObject)
31658
31907
  options2.projection.onReserved(projectionStorage, projectionObject);
31659
31908
  options2.onLinkedOwners?.(linkedOwners);
@@ -31689,11 +31938,13 @@ ${changed.join("\n")}`
31689
31938
  appDefinedSymbols
31690
31939
  });
31691
31940
  }
31941
+ if (deferredFinalLink) options2.onFinalLink?.(deferredFinalLink);
31692
31942
  return selected;
31693
31943
  } catch (error) {
31694
31944
  await Promise.allSettled([
31695
31945
  ledgerObjectPromise,
31696
- ...appLedgerObjectPromise ? [appLedgerObjectPromise] : []
31946
+ ...appLedgerObjectPromise ? [appLedgerObjectPromise] : [],
31947
+ ...deferredFinalLink ? [deferredFinalLink] : []
31697
31948
  ]);
31698
31949
  throw error;
31699
31950
  }
@@ -32325,6 +32576,7 @@ async function linkPrunedGuestImages(options2) {
32325
32576
  identities: aliasGuestLinkIdentities(identities, prepared.archives)
32326
32577
  };
32327
32578
  }
32579
+ let finalLinkDone;
32328
32580
  const selected = await linkCompleteGuestImages({
32329
32581
  plan,
32330
32582
  args: [...linkedArgs, `--Map=${options2.mapPath}`],
@@ -32338,6 +32590,9 @@ async function linkPrunedGuestImages(options2) {
32338
32590
  resolvePlan: options2.resolvePlan,
32339
32591
  sharedSdk: options2.sharedSdk,
32340
32592
  onSplitInputs: options2.onSplitInputs,
32593
+ onFinalLink: options2.deferFinalLink ? (done) => {
32594
+ finalLinkDone = done;
32595
+ } : void 0,
32341
32596
  onDyldRows: options2.onDyldRows,
32342
32597
  onLinkedOwners: (value) => {
32343
32598
  owners = value;
@@ -32351,7 +32606,8 @@ async function linkPrunedGuestImages(options2) {
32351
32606
  owners,
32352
32607
  generatedSectionOwners,
32353
32608
  sdk: sdk2,
32354
- mapPath: options2.mapPath
32609
+ mapPath: options2.mapPath,
32610
+ finalLinkDone
32355
32611
  };
32356
32612
  }
32357
32613
  var import_node_child_process25, import_node_fs49, import_node_path47, import_node_util6, execFileAsync, WASM_MAGIC, BITCODE_MAGIC;
@@ -32420,8 +32676,13 @@ function clangBinaryStamp(file) {
32420
32676
  const stat = (0, import_node_fs50.statSync)(file, { bigint: true });
32421
32677
  return [file, stat.size, stat.mtimeNs].join(":");
32422
32678
  }
32679
+ function sha256Hex3(bytes) {
32680
+ if (typeof Bun !== "undefined")
32681
+ return new Bun.CryptoHasher("sha256").update(bytes).digest("hex");
32682
+ return (0, import_node_crypto31.createHash)("sha256").update(bytes).digest("hex");
32683
+ }
32423
32684
  function clangWrapperStamp(file) {
32424
- return (0, import_node_crypto31.createHash)("sha256").update((0, import_node_fs50.readFileSync)(file)).digest("hex");
32685
+ return sha256Hex3((0, import_node_fs50.readFileSync)(file));
32425
32686
  }
32426
32687
  function clangArgsNeedCwd(args) {
32427
32688
  const pathFlags = /* @__PURE__ */ new Set([
@@ -32571,22 +32832,35 @@ function sourceGuestClangLinkOptions(options2) {
32571
32832
  "SOURCE_DATE_EPOCH"
32572
32833
  ].map((name3) => process.env[name3] ?? "");
32573
32834
  const replays = [];
32835
+ const realPathCache = /* @__PURE__ */ new Map();
32836
+ const cachedRealpath = (file) => {
32837
+ let resolved = realPathCache.get(file);
32838
+ if (resolved === void 0) {
32839
+ resolved = (0, import_node_fs50.realpathSync)(file);
32840
+ realPathCache.set(file, resolved);
32841
+ }
32842
+ return resolved;
32843
+ };
32844
+ const resolvedSwiftCompiler = cachedRealpath(options2.swiftCompiler);
32574
32845
  let clang;
32846
+ let clangWrapper;
32575
32847
  let clangStamp;
32576
32848
  let wrapperStamp;
32577
32849
  for (const file of wanted) {
32578
32850
  const command = commands.get(file);
32579
32851
  if (!command) throw new Error(`missing source object producer ${file}`);
32580
32852
  if (command.tool === "shell") {
32581
- if (!command.args.length || (0, import_node_fs50.realpathSync)(command.args[0]) !== (0, import_node_fs50.realpathSync)(options2.swiftCompiler))
32853
+ if (!command.args.length || cachedRealpath(command.args[0]) !== resolvedSwiftCompiler)
32582
32854
  throw new Error(`unsupported source object producer ${file}`);
32583
32855
  continue;
32584
32856
  }
32585
- const compiler = command.args[0] ? (0, import_node_fs50.realpathSync)(command.args[0]) : "";
32586
- clang ??= (0, import_node_fs50.realpathSync)(import_node_path48.default.join(options2.toolchainBin, "clang"));
32587
- if (command.tool !== "clang" || compiler !== clang && compiler !== (0, import_node_fs50.realpathSync)(import_node_path48.default.join(options2.buildDirectory, CLANG_TARGET_MODULE_WRAPPER)))
32857
+ const compiler = command.args[0] ? cachedRealpath(command.args[0]) : "";
32858
+ clang ??= cachedRealpath(import_node_path48.default.join(options2.toolchainBin, "clang"));
32859
+ if (command.tool !== "clang" || compiler !== clang && compiler !== (clangWrapper ??= cachedRealpath(
32860
+ import_node_path48.default.join(options2.buildDirectory, CLANG_TARGET_MODULE_WRAPPER)
32861
+ )))
32588
32862
  throw new Error(`unsupported source object producer ${file}`);
32589
- const key2 = (0, import_node_crypto31.createHash)("sha256").update(
32863
+ const key2 = sha256Hex3(
32590
32864
  JSON.stringify([
32591
32865
  "clang-link-options/v2",
32592
32866
  clangArgsNeedCwd(command.args) ? process.cwd() : null,
@@ -32596,11 +32870,8 @@ function sourceGuestClangLinkOptions(options2) {
32596
32870
  compiler === clang ? null : wrapperStamp ??= clangWrapperStamp(compiler),
32597
32871
  clangProducerStamp(file)
32598
32872
  ])
32599
- ).digest("hex");
32600
- const cacheFile = import_node_path48.default.join(
32601
- cacheDirectory,
32602
- (0, import_node_crypto31.createHash)("sha256").update(file).digest("hex") + ".json"
32603
32873
  );
32874
+ const cacheFile = import_node_path48.default.join(cacheDirectory, sha256Hex3(file) + ".json");
32604
32875
  const cached2 = readClangLinkOptions(cacheFile, key2);
32605
32876
  if (cached2) {
32606
32877
  validateClangLinkOptions(cached2);
@@ -38355,6 +38626,7 @@ async function linkSwiftSdkImage(moduleRoot, key2, directory2, work, scopedLooku
38355
38626
  ].map((name3) => `--export=${name3}`),
38356
38627
  `@${import_node_path58.default.join(work, "exports.rsp")}`,
38357
38628
  "--gc-sections",
38629
+ "--strip-debug",
38358
38630
  // strings stay with their objects, so an app loads only the ones its pieces reference
38359
38631
  "-O0"
38360
38632
  ];
@@ -38415,7 +38687,7 @@ async function linkSwiftSdkImage(moduleRoot, key2, directory2, work, scopedLooku
38415
38687
  (0, import_node_fs60.writeFileSync)(import_node_path58.default.join(work, INTERFACE_FILE), JSON.stringify(sdkInterface));
38416
38688
  (0, import_node_fs60.writeFileSync)(
38417
38689
  import_node_path58.default.join(work, IMAGE_DIGEST),
38418
- (0, import_node_crypto38.createHash)("sha256").update(image).digest("hex")
38690
+ typeof Bun !== "undefined" ? new Bun.CryptoHasher("sha256").update(image).digest("hex") : (0, import_node_crypto38.createHash)("sha256").update(image).digest("hex")
38419
38691
  );
38420
38692
  if (swiftSdkImageKey(
38421
38693
  moduleRoot,
@@ -38855,6 +39127,7 @@ __export(swift_sdk_app_module_exports, {
38855
39127
  readSwiftSdkUsage: () => readSwiftSdkUsage,
38856
39128
  selectSwiftSdkData: () => selectSwiftSdkData,
38857
39129
  swiftAppModuleInputs: () => swiftAppModuleInputs,
39130
+ swiftAppModuleThunkSection: () => swiftAppModuleThunkSection,
38858
39131
  swiftSdkProjectionSpans: () => swiftSdkProjectionSpans,
38859
39132
  writeSwiftSdkAppLink: () => writeSwiftSdkAppLink
38860
39133
  });
@@ -38906,9 +39179,12 @@ async function buildSwiftAppModule(options2) {
38906
39179
  linkage: link.linkage,
38907
39180
  usage
38908
39181
  });
38909
- (0, import_node_fs61.writeFileSync)(options2.output, finishSwiftAppModule((0, import_node_fs61.readFileSync)(options2.output)));
39182
+ finishSwiftAppModuleFile(options2.output);
38910
39183
  return binding;
38911
39184
  }
39185
+ function swiftAppModuleThunkSection(lowered) {
39186
+ return [NATIVE_SDK_THUNK_SECTION, sdkImportThunks(lowered)];
39187
+ }
38912
39188
  function finishSwiftAppModule(lowered) {
38913
39189
  return writeWasmCustomSection(
38914
39190
  lowered,
@@ -38916,6 +39192,73 @@ function finishSwiftAppModule(lowered) {
38916
39192
  sdkImportThunks(lowered)
38917
39193
  );
38918
39194
  }
39195
+ function finishSwiftAppModuleFile(file) {
39196
+ const fd = (0, import_node_fs61.openSync)(file, "r");
39197
+ let prefixEnd = 8;
39198
+ let hasExistingThunk = false;
39199
+ let prefix;
39200
+ try {
39201
+ const total = (0, import_node_fs61.fstatSync)(fd).size;
39202
+ const probe = Buffer.allocUnsafe(16);
39203
+ let offset = 8;
39204
+ while (offset < total) {
39205
+ const read = (0, import_node_fs61.readSync)(fd, probe, 0, Math.min(16, total - offset), offset);
39206
+ if (read < 2) break;
39207
+ const id = probe[0];
39208
+ let size2 = 0;
39209
+ let shift = 0;
39210
+ let at = 1;
39211
+ for (; ; ) {
39212
+ const byte = probe[at++];
39213
+ size2 += (byte & 127) * 2 ** shift;
39214
+ if (!(byte & 128)) break;
39215
+ shift += 7;
39216
+ }
39217
+ const start = offset + at;
39218
+ const next = start + size2;
39219
+ if (id === 1 || id === 2) prefixEnd = next;
39220
+ else if (id === 0) {
39221
+ const nameBuf = Buffer.allocUnsafe(Math.min(128, size2));
39222
+ const nRead = (0, import_node_fs61.readSync)(fd, nameBuf, 0, nameBuf.length, start);
39223
+ let nLen = 0;
39224
+ let nShift = 0;
39225
+ let nAt = 0;
39226
+ for (; ; ) {
39227
+ if (nAt >= nRead) break;
39228
+ const byte = nameBuf[nAt++];
39229
+ nLen += (byte & 127) * 2 ** nShift;
39230
+ if (!(byte & 128)) break;
39231
+ nShift += 7;
39232
+ }
39233
+ if (nAt + nLen <= nRead && nameBuf.toString("utf8", nAt, nAt + nLen) === NATIVE_SDK_THUNK_SECTION) {
39234
+ hasExistingThunk = true;
39235
+ break;
39236
+ }
39237
+ }
39238
+ offset = next;
39239
+ }
39240
+ if (!hasExistingThunk) {
39241
+ prefix = Buffer.allocUnsafe(prefixEnd);
39242
+ let filled = 0;
39243
+ while (filled < prefixEnd) {
39244
+ const n = (0, import_node_fs61.readSync)(fd, prefix, filled, prefixEnd - filled, filled);
39245
+ if (n <= 0) break;
39246
+ filled += n;
39247
+ }
39248
+ prefix = prefix.subarray(0, filled);
39249
+ }
39250
+ } finally {
39251
+ (0, import_node_fs61.closeSync)(fd);
39252
+ }
39253
+ if (hasExistingThunk || !prefix) {
39254
+ (0, import_node_fs61.writeFileSync)(file, finishSwiftAppModule((0, import_node_fs61.readFileSync)(file)));
39255
+ return;
39256
+ }
39257
+ const thunks = sdkImportThunks(prefix);
39258
+ const nameBytes = Buffer.from(encodedName2(NATIVE_SDK_THUNK_SECTION));
39259
+ const header = Buffer.from([0, ...uleb4(nameBytes.length + thunks.length)]);
39260
+ (0, import_node_fs61.appendFileSync)(file, Buffer.concat([header, nameBytes, thunks]));
39261
+ }
38919
39262
  function swiftAppModuleInputs(tokens2, buildRoot, sdkLibraries) {
38920
39263
  const owned = (token) => import_node_path59.default.resolve(token).startsWith(`${buildRoot}/`) && (!token.includes("/.peach-pruned-objs/") || token.endsWith("/swiftrt-patched.o"));
38921
39264
  const inputs2 = [];
@@ -39130,6 +39473,7 @@ async function linkSwiftAppModule(options2) {
39130
39473
  "--unresolved-symbols=ignore-all",
39131
39474
  "--import-undefined",
39132
39475
  "--emit-relocs",
39476
+ "--strip-debug",
39133
39477
  "--gc-sections",
39134
39478
  "--keep-section=target_features",
39135
39479
  "--error-limit=0",
@@ -39152,7 +39496,16 @@ async function linkSwiftAppModule(options2) {
39152
39496
  const skipPasses = options2.layoutMap ? ["duplicate-function-elimination"] : void 0;
39153
39497
  const sdkTableEnd = sdk2.sdkInterface.layout.tableEnd;
39154
39498
  const { loweringCache } = options2;
39155
- const loweringKey = loweringCache && (0, import_node_crypto39.createHash)("sha256").update(
39499
+ const loweringKey = loweringCache && (typeof Bun !== "undefined" ? new Bun.CryptoHasher("sha256").update(
39500
+ JSON.stringify([
39501
+ loweringCache.compilerDigest,
39502
+ optimize,
39503
+ skipPasses,
39504
+ sdkTableEnd,
39505
+ lazy,
39506
+ KEEP_WASM_NAMES
39507
+ ])
39508
+ ).update(bytes).digest("hex") : (0, import_node_crypto39.createHash)("sha256").update(
39156
39509
  JSON.stringify([
39157
39510
  loweringCache.compilerDigest,
39158
39511
  optimize,
@@ -39161,7 +39514,7 @@ async function linkSwiftAppModule(options2) {
39161
39514
  lazy,
39162
39515
  KEEP_WASM_NAMES
39163
39516
  ])
39164
- ).update(bytes).digest("hex");
39517
+ ).update(bytes).digest("hex"));
39165
39518
  return {
39166
39519
  linkage,
39167
39520
  async lower() {
@@ -39771,7 +40124,8 @@ function createSwiftSdkBinding(linkage, sdk2, usage, projection) {
39771
40124
  bindSwiftAppModule(linkage, sdk2),
39772
40125
  selectSwiftSdkData(sdk2, usage, linkage, projection)
39773
40126
  ]);
39774
- return { bytes, sha256: (0, import_node_crypto39.createHash)("sha256").update(bytes).digest("hex") };
40127
+ const sha2565 = typeof Bun !== "undefined" ? new Bun.CryptoHasher("sha256").update(bytes).digest("hex") : (0, import_node_crypto39.createHash)("sha256").update(bytes).digest("hex");
40128
+ return { bytes, sha256: sha2565 };
39775
40129
  }
39776
40130
  function readSwiftSdkUsage(mapFile, linkedFile, sdkObjects) {
39777
40131
  const map2 = readWasmLinkMap(mapFile, false);
@@ -40527,6 +40881,7 @@ async function compileGuestLink(options2) {
40527
40881
  onSplitInputs: sdk2 ? (value) => {
40528
40882
  splitInputs = value;
40529
40883
  } : void 0,
40884
+ deferFinalLink: Boolean(sdk2),
40530
40885
  onDyldRows: (rows) => {
40531
40886
  lazyFunctions = rows.lazyFunctions;
40532
40887
  dyldSymbols = rows.dyldSymbols;
@@ -40795,156 +41150,164 @@ async function compileGuestLink(options2) {
40795
41150
  });
40796
41151
  if (!reserved2 || !projectionObject) throw new Error("guest projection was not reserved");
40797
41152
  if (sdk2) {
40798
- if (!splitInputs) throw new Error("guest link did not select shared SDK inputs");
40799
- const {
40800
- createSwiftSdkBinding: createSwiftSdkBinding2,
40801
- finishSwiftAppModule: finishSwiftAppModule2,
40802
- linkSwiftAppModule: linkSwiftAppModule2,
40803
- readSwiftSdkUsage: readSwiftSdkUsage2,
40804
- swiftSdkProjectionSpans: swiftSdkProjectionSpans2
40805
- } = await Promise.resolve().then(() => (init_swift_sdk_app_module(), swift_sdk_app_module_exports));
40806
- const project = options2.project;
40807
- const work = project ? (0, import_node_fs62.mkdtempSync)(import_node_path60.default.join(directory2, "app-module-")) : import_node_path60.default.join(directory2, "app-module");
40808
- if (project) (0, import_node_fs62.chownSync)(work, project.uid, project.gid);
40809
- else (0, import_node_fs62.mkdirSync)(work, { recursive: true });
40810
- const layoutMap = import_node_path60.default.join(work, "app.map");
40811
- const owners = new Map(splitInputs.appObjects).set(projectionObject, 0);
40812
- const sdkObjectKeys = /* @__PURE__ */ new Map();
40813
- const sdkObjectImages = /* @__PURE__ */ new Map();
40814
- const sdkProductImages = new Map(prepared?.sdkProducts.images);
40815
- for (const [file, { image, product, identity: identity2 }] of splitInputs.sdkObjects) {
40816
- const key2 = sdkGuestObjectKey(identity2);
40817
- sdkObjectKeys.set(file, key2);
40818
- sdkObjectImages.set(key2, image);
40819
- const priorImage = sdkProductImages.get(product);
40820
- if (priorImage !== void 0 && priorImage !== image)
40821
- throw new Error(`SDK product ${product} has several guest images`);
40822
- sdkProductImages.set(product, image);
40823
- }
40824
- const usage = readSwiftSdkUsage2(result.mapPath, options2.output, sdkObjectKeys);
40825
- const linkedModule = import_node_path60.default.join(work, "app.wasm");
40826
- const sdkSpans = swiftSdkProjectionSpans2(
40827
- sdk2,
40828
- (object8, product) => sdkObjectImages.get(object8) ?? sdkProductImages.get(product)
40829
- );
40830
- let storage = reserved2;
40831
- if (sdkSpans.length > 0) {
40832
- const sdkCounts = guestProjectionRegionCounts(storage.images.length, sdkSpans);
40833
- storage = reserveGuestProjectionStorage(
40834
- storage.images,
40835
- storage.capacities.map((capacity, index) => ({
40836
- ...capacity,
40837
- regions: capacity.regions + sdkCounts[index] + 16
40838
- }))
40839
- );
40840
- const projectionSource = import_node_path60.default.join(work, "projection.c");
40841
- (0, import_node_fs62.writeFileSync)(projectionSource, storage.source);
40842
- (0, import_node_child_process36.execFileSync)(
40843
- import_node_path60.default.join(options2.toolchainBin, "clang"),
40844
- [...clangOptions, "-c", projectionSource, "-o", projectionObject],
40845
- { stdio: "pipe" }
40846
- );
40847
- }
40848
- let precomputedSymbols;
40849
- if (splitInputs.appReferencedSymbols && splitInputs.appDefinedSymbols) {
40850
- const referenced = new Set(splitInputs.appReferencedSymbols);
40851
- const defined = new Set(splitInputs.appDefinedSymbols);
40852
- const projSyms = guestWasmSymbols((0, import_node_fs62.readFileSync)(projectionObject));
40853
- for (const name3 of projSyms.undefined) referenced.add(name3);
40854
- for (const name3 of projSyms.defined) defined.add(name3);
40855
- precomputedSymbols = { referenced, defined };
40856
- }
40857
- for (; ; ) {
40858
- const link = await linkSwiftAppModule2({
40859
- objects: [...owners.keys()],
40860
- lazyFunctions: splitInputs.lazyFunctions,
40861
- toolchainBin: options2.toolchainBin,
40862
- sdk: sdk2,
40863
- work,
40864
- output: options2.optimized,
40865
- optimize: options2.optimize,
40866
- layoutMap,
40867
- project,
40868
- precomputedSymbols,
40869
- loweringCache: project ? void 0 : {
40870
- file: import_node_path60.default.join(
40871
- options2.buildDirectory,
40872
- ".build",
40873
- "peach-app-module-lowered.wasm"
40874
- ),
40875
- compilerDigest: options2.compilerDigest
40876
- }
40877
- });
40878
- const map3 = (0, import_node_fs62.readFileSync)(
40879
- project ? projectOutputFile(work, layoutMap, project) : layoutMap,
40880
- "utf8"
40881
- );
40882
- const values = guestDyldValueRange(map3);
40883
- const bindingRows = /* @__PURE__ */ new Map();
40884
- const data = [];
40885
- for (let at = 0; at < link.linkage.data.length; at += 3) {
40886
- const address = link.linkage.data[at];
40887
- const size2 = link.linkage.data[at + 1];
40888
- const value = link.linkage.data[at + 2];
40889
- if (values && address >= values.address && address < values.address + values.length) {
40890
- if (size2 !== 8 || (address - values.address) % 8)
40891
- throw new Error("sdk binding splits a dyld value");
40892
- bindingRows.set((address - values.address) / 8, value);
40893
- } else data.push(address, size2, value);
40894
- }
40895
- const linked = (0, import_node_fs62.readFileSync)(
40896
- project ? projectOutputFile(work, linkedModule, project) : linkedModule
41153
+ try {
41154
+ if (!splitInputs) throw new Error("guest link did not select shared SDK inputs");
41155
+ const {
41156
+ createSwiftSdkBinding: createSwiftSdkBinding2,
41157
+ linkSwiftAppModule: linkSwiftAppModule2,
41158
+ readSwiftSdkUsage: readSwiftSdkUsage2,
41159
+ swiftAppModuleThunkSection: swiftAppModuleThunkSection2,
41160
+ swiftSdkProjectionSpans: swiftSdkProjectionSpans2
41161
+ } = await Promise.resolve().then(() => (init_swift_sdk_app_module(), swift_sdk_app_module_exports));
41162
+ const project = options2.project;
41163
+ const work = project ? (0, import_node_fs62.mkdtempSync)(import_node_path60.default.join(directory2, "app-module-")) : import_node_path60.default.join(directory2, "app-module");
41164
+ if (project) (0, import_node_fs62.chownSync)(work, project.uid, project.gid);
41165
+ else (0, import_node_fs62.mkdirSync)(work, { recursive: true });
41166
+ const layoutMap = import_node_path60.default.join(work, "app.map");
41167
+ let appProjectionObject = projectionObject;
41168
+ const owners = new Map(splitInputs.appObjects).set(appProjectionObject, 0);
41169
+ const sdkObjectKeys = /* @__PURE__ */ new Map();
41170
+ const sdkObjectImages = /* @__PURE__ */ new Map();
41171
+ const sdkProductImages = new Map(prepared?.sdkProducts.images);
41172
+ for (const [file, { image, product, identity: identity2 }] of splitInputs.sdkObjects) {
41173
+ const key2 = sdkGuestObjectKey(identity2);
41174
+ sdkObjectKeys.set(file, key2);
41175
+ sdkObjectImages.set(key2, image);
41176
+ const priorImage = sdkProductImages.get(product);
41177
+ if (priorImage !== void 0 && priorImage !== image)
41178
+ throw new Error(`SDK product ${product} has several guest images`);
41179
+ sdkProductImages.set(product, image);
41180
+ }
41181
+ const linkedModule = import_node_path60.default.join(work, "app.wasm");
41182
+ const sdkSpans = swiftSdkProjectionSpans2(
41183
+ sdk2,
41184
+ (object8, product) => sdkObjectImages.get(object8) ?? sdkProductImages.get(product)
40897
41185
  );
40898
- const required = guestProjectionRegionCounts(storage.images.length, [
40899
- ...guestLinkedSpans(map3, linked, linked, owners, splitInputs.appSections, true),
40900
- ...sdkSpans
40901
- ]);
40902
- if (storage.capacities.some(({ regions }, index) => required[index] > regions)) {
40903
- storage = reserveGuestProjectionStorage(
40904
- storage.images,
40905
- storage.capacities.map((capacity, index) => {
40906
- const count = required[index];
40907
- return count > capacity.regions ? { ...capacity, regions: Math.max(count, capacity.regions * 2) } : capacity;
40908
- })
40909
- );
41186
+ const compileAppProjection = (source) => {
40910
41187
  const projectionSource = import_node_path60.default.join(work, "projection.c");
40911
- (0, import_node_fs62.writeFileSync)(projectionSource, storage.source);
41188
+ const nextObject = import_node_path60.default.join(work, "projection.o");
41189
+ (0, import_node_fs62.writeFileSync)(projectionSource, source);
40912
41190
  (0, import_node_child_process36.execFileSync)(
40913
41191
  import_node_path60.default.join(options2.toolchainBin, "clang"),
40914
- [...clangOptions, "-c", projectionSource, "-o", projectionObject],
41192
+ [...clangOptions, "-c", projectionSource, "-o", nextObject],
40915
41193
  { stdio: "pipe" }
40916
41194
  );
40917
- continue;
41195
+ if (nextObject !== appProjectionObject) {
41196
+ owners.delete(appProjectionObject);
41197
+ appProjectionObject = nextObject;
41198
+ owners.set(appProjectionObject, 0);
41199
+ }
41200
+ };
41201
+ let storage = reserved2;
41202
+ if (sdkSpans.length > 0) {
41203
+ const sdkCounts = guestProjectionRegionCounts(storage.images.length, sdkSpans);
41204
+ storage = reserveGuestProjectionStorage(
41205
+ storage.images,
41206
+ storage.capacities.map((capacity, index) => ({
41207
+ ...capacity,
41208
+ regions: capacity.regions + sdkCounts[index] + 16
41209
+ }))
41210
+ );
41211
+ compileAppProjection(storage.source);
40918
41212
  }
40919
- options2.onStage("lowering the app image");
40920
- const lowerPromise = link.lower();
40921
- await new Promise((resolve3) => setImmediate(resolve3));
40922
- let binding;
40923
- try {
40924
- binding = createSwiftSdkBinding2({ ...link.linkage, data }, sdk2, usage);
40925
- } catch (error) {
40926
- await lowerPromise.catch(() => {
41213
+ let precomputedSymbols;
41214
+ if (splitInputs.appReferencedSymbols && splitInputs.appDefinedSymbols) {
41215
+ const referenced = new Set(splitInputs.appReferencedSymbols);
41216
+ const defined = new Set(splitInputs.appDefinedSymbols);
41217
+ const projSyms = guestWasmSymbols((0, import_node_fs62.readFileSync)(appProjectionObject));
41218
+ for (const name3 of projSyms.undefined) referenced.add(name3);
41219
+ for (const name3 of projSyms.defined) defined.add(name3);
41220
+ precomputedSymbols = { referenced, defined };
41221
+ }
41222
+ for (; ; ) {
41223
+ const link = await linkSwiftAppModule2({
41224
+ objects: [...owners.keys()],
41225
+ lazyFunctions: splitInputs.lazyFunctions,
41226
+ toolchainBin: options2.toolchainBin,
41227
+ sdk: sdk2,
41228
+ work,
41229
+ output: options2.optimized,
41230
+ optimize: options2.optimize,
41231
+ layoutMap,
41232
+ project,
41233
+ precomputedSymbols,
41234
+ loweringCache: project ? void 0 : {
41235
+ file: import_node_path60.default.join(
41236
+ options2.buildDirectory,
41237
+ ".build",
41238
+ "peach-app-module-lowered.wasm"
41239
+ ),
41240
+ compilerDigest: options2.compilerDigest
41241
+ }
40927
41242
  });
40928
- throw error;
41243
+ const map3 = (0, import_node_fs62.readFileSync)(
41244
+ project ? projectOutputFile(work, layoutMap, project) : layoutMap,
41245
+ "utf8"
41246
+ );
41247
+ const values = guestDyldValueRange(map3);
41248
+ const bindingRows = /* @__PURE__ */ new Map();
41249
+ const data = [];
41250
+ for (let at = 0; at < link.linkage.data.length; at += 3) {
41251
+ const address = link.linkage.data[at];
41252
+ const size2 = link.linkage.data[at + 1];
41253
+ const value = link.linkage.data[at + 2];
41254
+ if (values && address >= values.address && address < values.address + values.length) {
41255
+ if (size2 !== 8 || (address - values.address) % 8)
41256
+ throw new Error("sdk binding splits a dyld value");
41257
+ bindingRows.set((address - values.address) / 8, value);
41258
+ } else data.push(address, size2, value);
41259
+ }
41260
+ const linked = (0, import_node_fs62.readFileSync)(
41261
+ project ? projectOutputFile(work, linkedModule, project) : linkedModule
41262
+ );
41263
+ const required = guestProjectionRegionCounts(storage.images.length, [
41264
+ ...guestLinkedSpans(map3, linked, linked, owners, splitInputs.appSections, true),
41265
+ ...sdkSpans
41266
+ ]);
41267
+ if (storage.capacities.some(({ regions }, index) => required[index] > regions)) {
41268
+ storage = reserveGuestProjectionStorage(
41269
+ storage.images,
41270
+ storage.capacities.map((capacity, index) => {
41271
+ const count = required[index];
41272
+ return count > capacity.regions ? { ...capacity, regions: Math.max(count, capacity.regions * 2) } : capacity;
41273
+ })
41274
+ );
41275
+ compileAppProjection(storage.source);
41276
+ continue;
41277
+ }
41278
+ options2.onStage("lowering the app image");
41279
+ const lowerPromise = link.lower();
41280
+ await new Promise((resolve3) => setImmediate(resolve3));
41281
+ let binding;
41282
+ try {
41283
+ if (result.finalLinkDone) await result.finalLinkDone;
41284
+ const usage = readSwiftSdkUsage2(result.mapPath, options2.output, sdkObjectKeys);
41285
+ binding = createSwiftSdkBinding2({ ...link.linkage, data }, sdk2, usage);
41286
+ } catch (error) {
41287
+ await Promise.allSettled([lowerPromise]);
41288
+ throw error;
41289
+ }
41290
+ await lowerPromise;
41291
+ const finalized = finalizeGuestProjectionStorage({
41292
+ map: map3,
41293
+ linked,
41294
+ optimized: (0, import_node_fs62.readFileSync)(options2.optimized),
41295
+ owners,
41296
+ sectionOwners: splitInputs.appSections,
41297
+ projectionObject: appProjectionObject,
41298
+ reserved: storage,
41299
+ sdkSpans
41300
+ });
41301
+ (0, import_node_fs62.writeFileSync)(
41302
+ options2.optimized,
41303
+ moveGuestDyldTable(map3, finalized.wasm, splitInputs.dyldSymbols, bindingRows, [
41304
+ swiftAppModuleThunkSection2(finalized.wasm)
41305
+ ])
41306
+ );
41307
+ return binding;
40929
41308
  }
40930
- await lowerPromise;
40931
- const finalized = finalizeGuestProjectionStorage({
40932
- map: map3,
40933
- linked,
40934
- optimized: (0, import_node_fs62.readFileSync)(options2.optimized),
40935
- owners,
40936
- sectionOwners: splitInputs.appSections,
40937
- projectionObject,
40938
- reserved: storage,
40939
- sdkSpans
40940
- });
40941
- (0, import_node_fs62.writeFileSync)(
40942
- options2.optimized,
40943
- finishSwiftAppModule2(
40944
- moveGuestDyldTable(map3, finalized.wasm, splitInputs.dyldSymbols, bindingRows)
40945
- )
40946
- );
40947
- return binding;
41309
+ } finally {
41310
+ if (result.finalLinkDone) await Promise.allSettled([result.finalLinkDone]);
40948
41311
  }
40949
41312
  }
40950
41313
  options2.onStage("lowering the app image");
@@ -46374,6 +46737,10 @@ async function buildFrameworkProducts(scratch2, args) {
46374
46737
  // every framework target when callers alternate --cores.
46375
46738
  "-Xswiftc",
46376
46739
  "-gnone",
46740
+ "-Xcc",
46741
+ "-g0",
46742
+ "-Xcxx",
46743
+ "-g0",
46377
46744
  "-Xswiftc",
46378
46745
  "-num-threads",
46379
46746
  "-Xswiftc",
@@ -47264,6 +47631,10 @@ ${cap}` : "";
47264
47631
  // fan-out under high -j.
47265
47632
  "-Xswiftc",
47266
47633
  "-gnone",
47634
+ "-Xcc",
47635
+ "-g0",
47636
+ "-Xcxx",
47637
+ "-g0",
47267
47638
  ...incrementalPreview ? [] : [
47268
47639
  "-Xswiftc",
47269
47640
  "-num-threads",
@@ -47914,7 +48285,7 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
47914
48285
  REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
47915
48286
  MULTI_MANIFEST_VERSION = 76;
47916
48287
  SWIFT_HEADER_PRODUCTS_TARGET = "PeachHeaderProducts";
47917
- compilerSourceDigest = true ? "67e8f8e0e47047534254dae36e13cda1c7694fb49b1d92c2d01a9e386dc59e59" : swiftCompilerSourceDigest2(__sootsim_import_meta_dirname);
48288
+ compilerSourceDigest = true ? "ab7e385f5b9ca10737de11d59802a2b57ee084a172b96aa971acb4c26a58a573" : swiftCompilerSourceDigest2(__sootsim_import_meta_dirname);
47918
48289
  nativeCxxCompilerFlags = ["-fno-cxx-modules"];
47919
48290
  MODULE_MAP_RESPONSE_FILE_RUN = 16;
47920
48291
  cFlagArray = (flags) => JSON.stringify(withoutGlogModuleMap(flags));
@@ -65875,6 +66246,11 @@ end
65875
66246
  });
65876
66247
 
65877
66248
  // src/bazel-project.ts
66249
+ function sha256Hex4(bytes) {
66250
+ if (typeof Bun !== "undefined")
66251
+ return new Bun.CryptoHasher("sha256").update(bytes).digest("hex");
66252
+ return (0, import_node_crypto48.createHash)("sha256").update(bytes).digest("hex");
66253
+ }
65878
66254
  function isBazelPackage(input) {
65879
66255
  return /^BUILD(?:\.bazel)?$/.test(import_node_path83.default.basename(input)) && import_node_fs82.default.statSync(input).isFile();
65880
66256
  }
@@ -66441,6 +66817,18 @@ ${published2.map(
66441
66817
  `bazel application has ${missing.length} unbuilt inputs: ${missing.slice(0, 5).map((file) => import_node_path83.default.relative(root, file)).join(", ")}`
66442
66818
  );
66443
66819
  const archives = /* @__PURE__ */ new Map();
66820
+ let outputOwner;
66821
+ const ownerOfOutput = (file) => {
66822
+ if (!outputOwner) {
66823
+ outputOwner = /* @__PURE__ */ new Map();
66824
+ for (const item of graph.rules.values())
66825
+ for (const output of item.outputs) {
66826
+ const outputPath2 = files2.path(output);
66827
+ if (!outputOwner.has(outputPath2)) outputOwner.set(outputPath2, item);
66828
+ }
66829
+ }
66830
+ return outputOwner.get(file);
66831
+ };
66444
66832
  for (const rule of order) {
66445
66833
  for (const dep of rule.attrs.get("deps")?.list ?? []) {
66446
66834
  const owner = ruleOf(dep, rule.label);
@@ -66458,9 +66846,7 @@ ${published2.map(
66458
66846
  for (const raw2 of rule.attrs.get("srcs")?.list ?? []) {
66459
66847
  const label2 = canonicalLabel(raw2, rule.label);
66460
66848
  for (const archive of files2.expand([raw2], rule.label).filter((file) => file.endsWith(".a"))) {
66461
- const owner = [...graph.rules.values()].find(
66462
- (item) => item.outputs.some((output) => files2.path(output) === archive)
66463
- );
66849
+ const owner = ownerOfOutput(archive);
66464
66850
  const key2 = owner?.label ?? label2;
66465
66851
  const entry = archives.get(key2) ?? {
66466
66852
  library: import_node_path83.default.basename(archive),
@@ -66486,6 +66872,13 @@ ${published2.map(
66486
66872
  )
66487
66873
  )
66488
66874
  );
66875
+ const matchesAppInclude = (name3) => {
66876
+ if (appIncludes.has(name3)) return true;
66877
+ for (let slash = name3.indexOf("/"); slash >= 0; slash = name3.indexOf("/", slash + 1)) {
66878
+ if (appIncludes.has(name3.slice(slash + 1))) return true;
66879
+ }
66880
+ return false;
66881
+ };
66489
66882
  let generatedBy;
66490
66883
  const generators = () => {
66491
66884
  if (!generatedBy) {
@@ -66566,9 +66959,7 @@ ${published2.map(
66566
66959
  [...linkers].filter((rule) => rule.attrs.get("module_name")?.value).flatMap((rule) => files2.expand(rule.attrs.get("hdrs")?.list ?? [], rule.label))
66567
66960
  );
66568
66961
  const entries2 = headers.filter(
66569
- (header) => imported.has(header.file) || [...appIncludes].some(
66570
- (include) => header.name === include || header.name.endsWith(`/${include}`)
66571
- )
66962
+ (header) => imported.has(header.file) || matchesAppInclude(header.name)
66572
66963
  );
66573
66964
  const bundle = import_node_path83.default.join(products, "archives", `${name3}.xcframework`);
66574
66965
  const slice = import_node_path83.default.join(bundle, "ios-arm64-simulator");
@@ -66614,14 +67005,9 @@ ${published2.map(
66614
67005
  ]
66615
67006
  )
66616
67007
  ]);
66617
- const digest2 = (0, import_node_crypto48.createHash)("sha256").update(
66618
- JSON.stringify(
66619
- [...contents2].map(([file, bytes]) => [
66620
- file,
66621
- (0, import_node_crypto48.createHash)("sha256").update(bytes).digest("hex")
66622
- ])
66623
- )
66624
- ).digest("hex");
67008
+ const digest2 = sha256Hex4(
67009
+ JSON.stringify([...contents2].map(([file, bytes]) => [file, sha256Hex4(bytes)]))
67010
+ );
66625
67011
  const stamp = import_node_path83.default.join(bundle, ".peach-digest");
66626
67012
  if (!import_node_fs82.default.existsSync(stamp) || import_node_fs82.default.readFileSync(stamp, "utf8") !== digest2) {
66627
67013
  import_node_fs82.default.rmSync(bundle, { recursive: true, force: true });
@@ -81111,7 +81497,7 @@ function compiledFrameworkImports(app, products) {
81111
81497
  }
81112
81498
  return imports2;
81113
81499
  }
81114
- function sha256Hex(bytes) {
81500
+ function sha256Hex5(bytes) {
81115
81501
  if (typeof Bun !== "undefined")
81116
81502
  return new Bun.CryptoHasher("sha256").update(bytes).digest("hex");
81117
81503
  return (0, import_node_crypto67.createHash)("sha256").update(bytes).digest("hex");
@@ -81129,7 +81515,7 @@ function verifyRetainedFile(work, file, hash, stamps) {
81129
81515
  if (typeof expectedStamp === "string" && regularFileStamp(resolved) === expectedStamp)
81130
81516
  return true;
81131
81517
  if (!import_node_fs108.default.existsSync(resolved)) return false;
81132
- return sha256Hex(readPackageFile(work, resolved, Infinity)) === hash;
81518
+ return sha256Hex5(readPackageFile(work, resolved, Infinity)) === hash;
81133
81519
  }
81134
81520
  function recordRetainedStamps(work, files2) {
81135
81521
  const stamps = {};
@@ -81146,7 +81532,7 @@ function cachedBinaryFileDigest(file) {
81146
81532
  const memory = binaryFileDigests.get(real);
81147
81533
  if (memory?.stamp === stamp) return memory.digest;
81148
81534
  const dir = import_node_path110.default.join(cacheDir(), "swift-binary-digests");
81149
- const record4 = import_node_path110.default.join(dir, `${sha256Hex(real)}.json`);
81535
+ const record4 = import_node_path110.default.join(dir, `${sha256Hex5(real)}.json`);
81150
81536
  if (import_node_fs108.default.existsSync(record4)) {
81151
81537
  const saved = JSON.parse(import_node_fs108.default.readFileSync(record4, "utf8"));
81152
81538
  if (isRecord(saved) && saved.stamp === stamp && typeof saved.digest === "string") {
@@ -81154,7 +81540,7 @@ function cachedBinaryFileDigest(file) {
81154
81540
  return saved.digest;
81155
81541
  }
81156
81542
  }
81157
- const digest2 = sha256Hex(import_node_fs108.default.readFileSync(real));
81543
+ const digest2 = sha256Hex5(import_node_fs108.default.readFileSync(real));
81158
81544
  binaryFileDigests.set(real, { stamp, digest: digest2 });
81159
81545
  import_node_fs108.default.mkdirSync(dir, { recursive: true });
81160
81546
  const partial = `${record4}.${process.pid}.${(0, import_node_crypto67.randomUUID)()}`;
@@ -81689,7 +82075,7 @@ function prepareXcodeSwiftProducts(app, binaries, moduleRoot) {
81689
82075
  const staged = withFrameworkCompanionImports(original);
81690
82076
  if (staged !== original) sources.set(file, Buffer.from(staged));
81691
82077
  }
81692
- const digest2 = sha256Hex;
82078
+ const digest2 = sha256Hex5;
81693
82079
  const providers = /* @__PURE__ */ new Map();
81694
82080
  for (const target of targets) {
81695
82081
  if (!supplied.has(target.moduleName)) continue;
@@ -82045,7 +82431,7 @@ async function prepareXcodeNativeInputs(app, binaries, moduleRoot, purpose) {
82045
82431
  products
82046
82432
  );
82047
82433
  const checkouts = remoteSwiftCheckouts(app.rootDir);
82048
- const digest2 = sha256Hex;
82434
+ const digest2 = sha256Hex5;
82049
82435
  const inputs2 = Object.fromEntries(
82050
82436
  [...sources].map(([file, bytes]) => [file, digest2(bytes)])
82051
82437
  );
@@ -82327,6 +82713,7 @@ async function prepareXcodeNativeInputs(app, binaries, moduleRoot, purpose) {
82327
82713
  ...flags,
82328
82714
  ...target.prefix ? ["-include", staged(target.prefix)] : [],
82329
82715
  "-Os",
82716
+ ...purpose === "objects" ? ["-g0"] : [],
82330
82717
  "-c",
82331
82718
  staged(file),
82332
82719
  "-o",