peachsim 0.1.2623 → 0.1.2625

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 (140) 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 +1023 -621
  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-E6V72TM2.mjs → acorn-SHZZDBSI.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-EIOVKQ2C.mjs → chunk-2LDG7OD4.mjs} +5 -5
  28. package/dist-lib/esm-chunks/{chunk-ISH6XB23.mjs → chunk-3XZGWT62.mjs} +1 -1
  29. package/dist-lib/esm-chunks/{chunk-Q7KCK4YO.mjs → chunk-6PZI7TYE.mjs} +1 -1
  30. package/dist-lib/esm-chunks/{chunk-RLWITQ5C.mjs → chunk-7Z7YJ4FU.mjs} +1 -1
  31. package/dist-lib/esm-chunks/{chunk-4GNQG2GT.mjs → chunk-A4R4YGFJ.mjs} +1 -1
  32. package/dist-lib/esm-chunks/{chunk-GP3KL2GC.mjs → chunk-A66VNSO6.mjs} +565 -290
  33. package/dist-lib/esm-chunks/{chunk-XOAOND7F.mjs → chunk-DVMKYLDN.mjs} +9 -8
  34. package/dist-lib/esm-chunks/{chunk-IGB7TRLS.mjs → chunk-F4YHL4UM.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-4BJIJ3GP.mjs → chunk-JRU2VXUU.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-EI7CZDMR.mjs → chunk-JVEJLPJC.mjs} +2 -2
  37. package/dist-lib/esm-chunks/{chunk-UCW7ITXE.mjs → chunk-KA4AQDVF.mjs} +1 -1
  38. package/dist-lib/esm-chunks/{chunk-RLWTJ6II.mjs → chunk-LJYNZ5HM.mjs} +1 -1
  39. package/dist-lib/esm-chunks/{chunk-RBXTTEI6.mjs → chunk-M2FEKSK3.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-KPG4FUTY.mjs → chunk-OCCZJOSA.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-CXNXKUNJ.mjs → chunk-P542MMIN.mjs} +1 -1
  42. package/dist-lib/esm-chunks/{chunk-NOM66H2G.mjs → chunk-Q5NI4L3Z.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-V2CHR3OI.mjs → chunk-R4FFTWPL.mjs} +1 -1
  44. package/dist-lib/esm-chunks/{chunk-W3X7RP3H.mjs → chunk-RJWEWNAJ.mjs} +3 -3
  45. package/dist-lib/esm-chunks/{chunk-B5OQSD4B.mjs → chunk-RXXCTHJG.mjs} +1 -1
  46. package/dist-lib/esm-chunks/{chunk-B4APPUTT.mjs → chunk-SRIRVPNX.mjs} +1 -1
  47. package/dist-lib/esm-chunks/{chunk-6MNE57DC.mjs → chunk-ULHG6CND.mjs} +22 -13
  48. package/dist-lib/esm-chunks/{chunk-PAEJF2JP.mjs → chunk-W4HQINQ6.mjs} +4 -4
  49. package/dist-lib/esm-chunks/{chunk-RVM3WWST.mjs → chunk-XQBHCWS4.mjs} +1 -1
  50. package/dist-lib/esm-chunks/{chunk-Q4ZATFEN.mjs → chunk-Z6AH6AQC.mjs} +1 -1
  51. package/dist-lib/esm-chunks/{metro-layout-parser-OHVROLNJ.mjs → metro-layout-parser-GJHR7FCR.mjs} +3 -3
  52. package/dist-lib/esm-chunks/{swift-package-prebuilt-DRAUK6KR.mjs → swift-package-prebuilt-UVRGKTD4.mjs} +12 -12
  53. package/dist-lib/esm-chunks/{swift-sdk-app-module-U2M7CMKA.mjs → swift-sdk-app-module-U3MUJ7QD.mjs} +107 -20
  54. package/dist-lib/esm-chunks/{swift-sdk-image-ZHWSHCNI.mjs → swift-sdk-image-U4W7QMAT.mjs} +16 -18
  55. package/dist-lib/esm-chunks/{swift-sdk-image-producer-EOJUCK7N.mjs → swift-sdk-image-producer-TFFZDNRK.mjs} +5 -5
  56. package/dist-lib/expo-swift-bundle.cjs +918 -516
  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 +1025 -623
  61. package/dist-lib/host/fetch-proxy-handler.cjs +10 -9
  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 +33 -17
  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 +87 -86
  87. package/dist-lib/public-origins-lib.json +69 -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 +1062 -660
  95. package/dist-lib/swift-compile.cjs +708 -336
  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-contract.ts +6 -1
  127. package/src/swift-distribution.lock.json +4 -2
  128. package/src/swift-guest-compile.ts +170 -160
  129. package/src/swift-guest-dyld-table.ts +22 -9
  130. package/src/swift-guest-link.ts +116 -42
  131. package/src/swift-guest-linked-spans.ts +63 -14
  132. package/src/swift-guest-projection-storage.ts +7 -6
  133. package/src/swift-guest-source-inputs.ts +35 -21
  134. package/src/swift-objc-compile.ts +1 -0
  135. package/src/swift-sdk-app-module.ts +118 -15
  136. package/src/swift-sdk-image-recipe.ts +20 -0
  137. package/src/swift-sdk-image-wasm.ts +119 -17
  138. package/src/swift-sdk-image.ts +6 -5
  139. package/src/swift-wasm-prune.ts +71 -41
  140. package/src/wasm-narrow-boundary.ts +31 -6
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.2623 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.2625 | (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;
@@ -6418,6 +6418,15 @@ function guestLinkedSpans(map, before, after, owners, sectionOwners = /* @__PURE
6418
6418
  const unchanged = before === after;
6419
6419
  const original = layout(before, !unchanged, !importsLayout);
6420
6420
  const optimized = unchanged ? original : layout(after, true, !importsLayout);
6421
+ if (extra?.optimizedDataSegments) {
6422
+ for (const segment of optimized.data) {
6423
+ extra.optimizedDataSegments.push({
6424
+ address: segment.address,
6425
+ offset: segment.bytes.byteOffset - after.byteOffset,
6426
+ length: segment.bytes.length
6427
+ });
6428
+ }
6429
+ }
6421
6430
  const collectSymbols = extra?.collectSymbols;
6422
6431
  const trackedObject = extra?.trackedObject;
6423
6432
  const trackedObjectOwner = extra?.trackedObjectOwner;
@@ -6586,12 +6595,39 @@ function guestLinkedSpans(map, before, after, owners, sectionOwners = /* @__PURE
6586
6595
  }
6587
6596
  return result;
6588
6597
  };
6598
+ const singleSegmentSlice = (module2, start, length) => {
6599
+ const segs = module2.dataByAddress;
6600
+ let low = 0;
6601
+ let high = segs.length;
6602
+ while (low < high) {
6603
+ const middle = low + high >> 1;
6604
+ if (segs[middle].maximumEnd <= start) low = middle + 1;
6605
+ else high = middle;
6606
+ }
6607
+ let found;
6608
+ const end = start + length;
6609
+ for (let index = low; index < segs.length; index++) {
6610
+ const segment = segs[index];
6611
+ if (segment.address >= end) break;
6612
+ if (segment.address + segment.bytes.length > start) {
6613
+ if (found) return void 0;
6614
+ found = segment;
6615
+ }
6616
+ }
6617
+ if (!found || found.address > start || found.address + found.bytes.length < end)
6618
+ return void 0;
6619
+ return found.bytes.subarray(start - found.address, end - found.address);
6620
+ };
6621
+ const sameDataAt = (start, length) => {
6622
+ const origSlice = singleSegmentSlice(original, start, length);
6623
+ const optSlice = origSlice ? singleSegmentSlice(optimized, start, length) : void 0;
6624
+ if (origSlice && optSlice) return Buffer.compare(origSlice, optSlice) === 0;
6625
+ return dataAt(original, start, length).equals(dataAt(optimized, start, length));
6626
+ };
6589
6627
  for (const span of spans) {
6590
6628
  if (span.address + span.length > original.memoryBytes || span.address + span.length > optimized.memoryBytes)
6591
6629
  throw new Error(`linked data lies outside guest memory at ${span.address}`);
6592
- if (!unchanged && !dataAt(original, span.address, span.length).equals(
6593
- dataAt(optimized, span.address, span.length)
6594
- ))
6630
+ if (!unchanged && !sameDataAt(span.address, span.length))
6595
6631
  throw new Error(`optimization changed linked data at ${span.address}`);
6596
6632
  }
6597
6633
  let previous;
@@ -6725,7 +6761,7 @@ function takeGuestStartupData(wasm, address, length) {
6725
6761
  const bytes = new Uint8Array(length);
6726
6762
  const emptied = /* @__PURE__ */ new Set();
6727
6763
  let covered = 0;
6728
- const result = Buffer.from(wasm);
6764
+ const patchedBody = Buffer.from(wasm.subarray(body[0], body[1]));
6729
6765
  for (const initializer of startupDataInitializers(wasm.subarray(...body))) {
6730
6766
  const end = initializer.address + initializer.length;
6731
6767
  if (end <= address || initializer.address >= address + length || !initializer.length)
@@ -6740,19 +6776,18 @@ function takeGuestStartupData(wasm, address, length) {
6740
6776
  covered += segment.length;
6741
6777
  emptied.add(initializer.segment);
6742
6778
  const [at, immediateEnd] = initializer.lengthImmediate;
6743
- result.fill(128, body[0] + at, body[0] + immediateEnd - 1);
6744
- result[body[0] + immediateEnd - 1] = 0;
6779
+ patchedBody.fill(128, at, immediateEnd - 1);
6780
+ patchedBody[immediateEnd - 1] = 0;
6745
6781
  }
6746
6782
  if (covered !== length)
6747
6783
  throw new Error("guest startup data does not initialize the whole range");
6748
- const parts = [result.subarray(0, data[0])];
6749
- const payload = [result.subarray(data[1], segments[0].header)];
6784
+ const payload = [wasm.subarray(data[1], segments[0].header)];
6750
6785
  for (const [index, segment] of segments.entries()) {
6751
6786
  if (!emptied.has(index)) {
6752
- payload.push(result.subarray(segment.header, segment.payload + segment.length));
6787
+ payload.push(wasm.subarray(segment.header, segment.payload + segment.length));
6753
6788
  continue;
6754
6789
  }
6755
- payload.push(result.subarray(segment.header, segment.sizeAt), Uint8Array.of(0));
6790
+ payload.push(wasm.subarray(segment.header, segment.sizeAt), Uint8Array.of(0));
6756
6791
  }
6757
6792
  const section2 = Buffer.concat(payload);
6758
6793
  const size = [];
@@ -6763,7 +6798,14 @@ function takeGuestStartupData(wasm, address, length) {
6763
6798
  }
6764
6799
  size.push(rest % 128 | 128);
6765
6800
  }
6766
- parts.push(Uint8Array.of(11, ...size), section2, result.subarray(data[2]));
6801
+ const parts = [
6802
+ wasm.subarray(0, body[0]),
6803
+ patchedBody,
6804
+ wasm.subarray(body[1], data[0]),
6805
+ Uint8Array.of(11, ...size),
6806
+ section2,
6807
+ wasm.subarray(data[2])
6808
+ ];
6767
6809
  return { wasm: Buffer.concat(parts), bytes };
6768
6810
  }
6769
6811
  var import_node_fs15, import_node_string_decoder, constant;
@@ -7072,6 +7114,32 @@ function readImports(bytes, imports) {
7072
7114
  }
7073
7115
  return { functionTypes, importedGlobals, memoryPages };
7074
7116
  }
7117
+ function countImportedFunctions(bytes, imports) {
7118
+ let count = 0;
7119
+ if (!imports) return count;
7120
+ const r = wasmReader(bytes, imports.start);
7121
+ for (let n = r.u(); n > 0; n--) {
7122
+ r.skip(r.u());
7123
+ r.skip(r.u());
7124
+ const kind = r.byte();
7125
+ if (kind === 0) {
7126
+ r.u();
7127
+ count++;
7128
+ } else if (kind === 1) {
7129
+ r.byte();
7130
+ skipLimits(r);
7131
+ } else if (kind === 2) {
7132
+ skipLimits(r);
7133
+ } else if (kind === 3) {
7134
+ r.byte();
7135
+ r.byte();
7136
+ } else if (kind === 4) {
7137
+ r.byte();
7138
+ r.u();
7139
+ } else throw new Error(`unknown wasm import kind ${kind}`);
7140
+ }
7141
+ return count;
7142
+ }
7075
7143
  function* readFunctionNames(bytes, names) {
7076
7144
  for (const r = wasmReader(bytes, names.start); r.at < names.end; ) {
7077
7145
  const id = r.byte();
@@ -7439,28 +7507,73 @@ function codeOnlySdkImage(bytes, constructorMask) {
7439
7507
  return Buffer.concat(out);
7440
7508
  }
7441
7509
  function constructorKeys(map, bytes) {
7442
- const m = readModule(bytes);
7443
7510
  const first = map.code[0];
7444
- if (!first || !m.bodies.length) throw new Error("link has no code");
7445
- const prefixes = m.bodies.map(({ prefix }) => prefix);
7446
- const delta = prefixes[0] - first.offset;
7447
- const byOffset = new Map(map.code.map((chunk) => [chunk.offset + delta, chunk]));
7511
+ if (!first) throw new Error("link has no code");
7512
+ const sections = wasmSections(bytes);
7513
+ const code = sections.find((s) => s.id === 10);
7514
+ if (!code) throw new Error("link has no code");
7448
7515
  const ctors = map.code.find((chunk) => chunk.section === "__wasm_call_ctors");
7449
7516
  if (!ctors) throw new Error("link has no constructors");
7450
- const index = prefixes.indexOf(ctors.offset + delta);
7451
- if (index < 0) throw new Error("constructor function not found by map offset");
7452
- const body = m.bodies[index];
7453
- const r = wasmReader(bytes, body.start);
7517
+ const importedFuncs = countImportedFunctions(
7518
+ bytes,
7519
+ sections.find((s) => s.id === 2)
7520
+ );
7521
+ const codeReader = wasmReader(bytes, code.start);
7522
+ const bodyCount = codeReader.u();
7523
+ if (!bodyCount) throw new Error("link has no code");
7524
+ const prefixes = new Uint32Array(bodyCount);
7525
+ let delta = 0;
7526
+ let ctorPrefix = -1;
7527
+ let ctorStart = -1;
7528
+ let ctorEnd = -1;
7529
+ for (let i = 0; i < bodyCount; i++) {
7530
+ const prefix = codeReader.at;
7531
+ const size = codeReader.u();
7532
+ prefixes[i] = prefix;
7533
+ if (i === 0) {
7534
+ delta = prefix - first.offset;
7535
+ ctorPrefix = ctors.offset + delta;
7536
+ }
7537
+ if (prefix === ctorPrefix) {
7538
+ ctorStart = codeReader.at;
7539
+ ctorEnd = ctorStart + size;
7540
+ }
7541
+ codeReader.skip(size);
7542
+ }
7543
+ if (ctorStart < 0) throw new Error("constructor function not found by map offset");
7544
+ let sorted = true;
7545
+ for (let i = 1; i < map.code.length; i++) {
7546
+ if (map.code[i].offset < map.code[i - 1].offset) {
7547
+ sorted = false;
7548
+ break;
7549
+ }
7550
+ }
7551
+ const byOffset = sorted ? void 0 : new Map(map.code.map((chunk) => [chunk.offset + delta, chunk]));
7552
+ const findChunk = (targetPrefix) => {
7553
+ if (byOffset) return byOffset.get(targetPrefix);
7554
+ const targetOffset = targetPrefix - delta;
7555
+ let lo = 0;
7556
+ let hi = map.code.length - 1;
7557
+ while (lo <= hi) {
7558
+ const mid = lo + hi >> 1;
7559
+ const offset = map.code[mid].offset;
7560
+ if (offset < targetOffset) lo = mid + 1;
7561
+ else if (offset > targetOffset) hi = mid - 1;
7562
+ else return map.code[mid];
7563
+ }
7564
+ return void 0;
7565
+ };
7566
+ const r = wasmReader(bytes, ctorStart);
7454
7567
  for (let n = r.u(); n > 0; n--) {
7455
7568
  r.u();
7456
7569
  r.byte();
7457
7570
  }
7458
7571
  const keys = [];
7459
- while (r.at < body.end) {
7572
+ while (r.at < ctorEnd) {
7460
7573
  const op = r.byte();
7461
7574
  if (op === 16) {
7462
- const callee = r.u() - m.importedFuncs;
7463
- const chunk = byOffset.get(prefixes[callee]);
7575
+ const callee = r.u() - importedFuncs;
7576
+ const chunk = callee >= 0 && callee < bodyCount ? findChunk(prefixes[callee]) : void 0;
7464
7577
  if (!chunk) throw new Error("constructor without a map chunk");
7465
7578
  keys.push(chunkKey(chunk, ""));
7466
7579
  } else if (op !== 26 && op !== 11) throw new Error(`constructor op ${op}`);
@@ -7543,7 +7656,10 @@ function relocationEdges(bytes, segmentAddress) {
7543
7656
  r.skip(r.u());
7544
7657
  }
7545
7658
  }
7546
- const importedFunctions = readModule(bytes).importedFuncs;
7659
+ const importedFunctions = countImportedFunctions(
7660
+ bytes,
7661
+ sections.find((s) => s.id === 2)
7662
+ );
7547
7663
  const data = [];
7548
7664
  const dataFunctions = [];
7549
7665
  const bodyCount = bodyStarts.length;
@@ -7657,9 +7773,30 @@ function strongDefinitions(bytes) {
7657
7773
  ).map((s) => s.name);
7658
7774
  }
7659
7775
  function unslottedFunctions(bytes) {
7660
- const m = readModule(bytes);
7661
- const slotted = new Set([...m.slots.keys()].filter((index) => index >= m.importedFuncs));
7662
- return m.bodies.length - slotted.size;
7776
+ const sections = wasmSections(bytes);
7777
+ const importedFuncs = countImportedFunctions(
7778
+ bytes,
7779
+ sections.find((s) => s.id === 2)
7780
+ );
7781
+ const code = sections.find((s) => s.id === 10);
7782
+ const definedFuncs = code ? wasmReader(bytes, code.start).u() : 0;
7783
+ const slotted = /* @__PURE__ */ new Set();
7784
+ const elements = sections.find((s) => s.id === 9);
7785
+ if (elements) {
7786
+ const r = wasmReader(bytes, elements.start);
7787
+ for (let n = r.u(); n > 0; n--) {
7788
+ const flags = r.u();
7789
+ if (flags !== 0 && flags !== 2) throw new Error(`sdk image element flags ${flags}`);
7790
+ if (flags === 2) r.u();
7791
+ constant2(r);
7792
+ if (flags === 2) r.byte();
7793
+ for (let i = 0, count = r.u(); i < count; i++) {
7794
+ const index = r.u();
7795
+ if (index >= importedFuncs) slotted.add(index);
7796
+ }
7797
+ }
7798
+ }
7799
+ return definedFuncs - slotted.size;
7663
7800
  }
7664
7801
  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;
7665
7802
  var init_swift_sdk_image_wasm = __esm({
@@ -7921,6 +8058,11 @@ var init_swiftRuntimeProductContract = __esm({
7921
8058
  });
7922
8059
 
7923
8060
  // src/swift-wasm-prune.ts
8061
+ function sha256Hex(bytes) {
8062
+ if (typeof Bun !== "undefined")
8063
+ return new Bun.CryptoHasher("sha256").update(bytes).digest("hex");
8064
+ return (0, import_node_crypto8.createHash)("sha256").update(bytes).digest("hex");
8065
+ }
7924
8066
  function readULEB2(b, o) {
7925
8067
  let res = 0;
7926
8068
  let shift = 0;
@@ -8673,6 +8815,42 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
8673
8815
  }
8674
8816
  }
8675
8817
  }
8818
+ const segObjCClasses = /* @__PURE__ */ new Map();
8819
+ for (let segIdx = 0; segIdx < sEnds.length; segIdx++) {
8820
+ const rangeStart = dataStart + sPayloadStarts[segIdx];
8821
+ const rangeEnd = dataStart + sEnds[segIdx];
8822
+ const sliceLen = rangeEnd - rangeStart;
8823
+ if (sliceLen < 4) continue;
8824
+ const slice = Buffer.from(rawBuf.buffer, rawBuf.byteOffset + rangeStart, sliceLen);
8825
+ let segPos = 0;
8826
+ let classes;
8827
+ while (segPos < sliceLen - 3) {
8828
+ const at = slice.indexOf("So", segPos);
8829
+ if (at < 0 || at >= sliceLen - 2) break;
8830
+ let digitEnd = at + 2;
8831
+ let length = 0;
8832
+ while (digitEnd < sliceLen) {
8833
+ const ch = slice[digitEnd];
8834
+ if (ch < 48 || ch > 57) break;
8835
+ length = length * 10 + (ch - 48);
8836
+ digitEnd++;
8837
+ }
8838
+ if (digitEnd === at + 2) {
8839
+ segPos = at + 2;
8840
+ continue;
8841
+ }
8842
+ segPos = digitEnd;
8843
+ const nameEnd = digitEnd + length;
8844
+ if (nameEnd >= sliceLen || slice[nameEnd] !== 67) continue;
8845
+ const symbol = `._OBJC_CLASS_${slice.toString("latin1", digitEnd, nameEnd)}`;
8846
+ if (!classes) {
8847
+ classes = [symbol];
8848
+ segObjCClasses.set(segIdx, classes);
8849
+ } else if (!classes.includes(symbol)) {
8850
+ classes.push(symbol);
8851
+ }
8852
+ }
8853
+ }
8676
8854
  return {
8677
8855
  file,
8678
8856
  isDist,
@@ -8702,10 +8880,7 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
8702
8880
  objcCategoryTargets,
8703
8881
  rootFuncs,
8704
8882
  rootSegs,
8705
- segPayloadRanges: sEnds.map((end, i) => [
8706
- dataStart + sPayloadStarts[i],
8707
- dataStart + end
8708
- ])
8883
+ segObjCClasses
8709
8884
  };
8710
8885
  }
8711
8886
  function parseWasmObjectFile(file, isDist) {
@@ -9073,16 +9248,26 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
9073
9248
  transformations.set(file, {
9074
9249
  output,
9075
9250
  inputSha256,
9076
- outputSha256: (0, import_node_crypto8.createHash)("sha256").update(result).digest("hex"),
9251
+ outputSha256: sha256Hex(result),
9077
9252
  kind
9078
9253
  });
9079
9254
  };
9080
9255
  const distFiles = [];
9081
9256
  const distBaseNames = /* @__PURE__ */ new Set();
9082
9257
  const eagerFiles = [];
9258
+ const parsedBuildObjects = /* @__PURE__ */ new Map();
9083
9259
  const lazyBuildObjects = /* @__PURE__ */ new Map();
9084
9260
  const extraArchiveObjs = [];
9085
9261
  const objectBytes = /* @__PURE__ */ new Map();
9262
+ const archiveMembers = /* @__PURE__ */ new Map();
9263
+ const readArchiveMembers = (archive) => {
9264
+ let members = archiveMembers.get(archive);
9265
+ if (!members) {
9266
+ members = readArMembers(new Uint8Array(import_node_fs16.default.readFileSync(archive)));
9267
+ archiveMembers.set(archive, members);
9268
+ }
9269
+ return members;
9270
+ };
9086
9271
  let inStartLib = false;
9087
9272
  let swiftrtOrigPath = "";
9088
9273
  for (const t of tokens) {
@@ -9119,8 +9304,10 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
9119
9304
  break;
9120
9305
  }
9121
9306
  }
9122
- if (definesObjCClassOrCategory) eagerFiles.push(t);
9123
- else lazyBuildObjects.set(t, obj);
9307
+ if (definesObjCClassOrCategory) {
9308
+ parsedBuildObjects.set(t, obj);
9309
+ eagerFiles.push(t);
9310
+ } else lazyBuildObjects.set(t, obj);
9124
9311
  } else {
9125
9312
  eagerFiles.push(t);
9126
9313
  }
@@ -9128,7 +9315,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
9128
9315
  lazyBuildObjects.set(t, parseWasmObjectFile(t, false));
9129
9316
  }
9130
9317
  } else if (!inStartLib && t.endsWith(".a") && !t.endsWith("libclang_rt.builtins-wasm64.a") && import_node_fs16.default.existsSync(t)) {
9131
- const members = readArMembers(new Uint8Array(import_node_fs16.default.readFileSync(t)));
9318
+ const members = readArchiveMembers(t);
9132
9319
  for (const m of members) {
9133
9320
  const object4 = parseWasmObjectBytes(`${t}(${m.name})`, m.bytes, false);
9134
9321
  extraArchiveObjs.push(object4);
@@ -9151,7 +9338,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
9151
9338
  );
9152
9339
  const archiveOverlapsDist = (archive) => {
9153
9340
  if (!import_node_fs16.default.existsSync(archive)) return false;
9154
- const members = readArMembers(new Uint8Array(import_node_fs16.default.readFileSync(archive)));
9341
+ const members = readArchiveMembers(archive);
9155
9342
  return members.some((m) => distBaseNames.has(m.name));
9156
9343
  };
9157
9344
  for (const t of tokens) {
@@ -9173,7 +9360,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
9173
9360
  import_node_path17.default.basename(archive)
9174
9361
  );
9175
9362
  const ordinals = /* @__PURE__ */ new Map();
9176
- for (const m of readArMembers(new Uint8Array(import_node_fs16.default.readFileSync(archive)))) {
9363
+ for (const m of readArchiveMembers(archive)) {
9177
9364
  const ordinal = (ordinals.get(m.name) ?? 0) + 1;
9178
9365
  ordinals.set(m.name, ordinal);
9179
9366
  if (distBaseNames.has(m.name) || writtenLeftovers.has(m.name)) continue;
@@ -9207,7 +9394,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
9207
9394
  recordTransformation(
9208
9395
  swiftrtOrigPath,
9209
9396
  patchedSwiftrtPath,
9210
- link ? (0, import_node_crypto8.createHash)("sha256").update(input).digest("hex") : "",
9397
+ link ? sha256Hex(input) : "",
9211
9398
  result,
9212
9399
  "swiftrt"
9213
9400
  );
@@ -9694,7 +9881,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
9694
9881
  }
9695
9882
  for (const f of eagerFiles) {
9696
9883
  const isDist = f.startsWith(distDir);
9697
- const obj = distObjs.get(f) ?? parseWasmObjectFile(f, isDist);
9884
+ const obj = distObjs.get(f) ?? parsedBuildObjects.get(f) ?? parseWasmObjectFile(f, isDist);
9698
9885
  extractObject(obj);
9699
9886
  if (isDist) {
9700
9887
  const base = import_node_path17.default.basename(f);
@@ -9744,32 +9931,9 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
9744
9931
  "$s10Foundation6BundleC22preferredLocalizations4fromSaySSGAF_tFZTf4nd_n"
9745
9932
  ]);
9746
9933
  const keepObjCClassesNamedInSegment = (obj, segIdx) => {
9747
- const range = obj.segPayloadRanges[segIdx];
9748
- if (!range) return;
9749
- const [rangeStart, rangeEnd] = range;
9750
- if (rangeEnd - rangeStart < 4) return;
9751
- let bytes = objectBytes.get(obj);
9752
- if (!bytes) objectBytes.set(obj, bytes = import_node_fs16.default.readFileSync(obj.file));
9753
- let pos = rangeStart;
9754
- while (pos < rangeEnd - 3) {
9755
- const at = bytes.indexOf("So", pos);
9756
- if (at < 0 || at >= rangeEnd - 2) break;
9757
- let digitEnd = at + 2;
9758
- let length = 0;
9759
- while (digitEnd < rangeEnd) {
9760
- const ch = bytes[digitEnd];
9761
- if (ch < 48 || ch > 57) break;
9762
- length = length * 10 + (ch - 48);
9763
- digitEnd++;
9764
- }
9765
- if (digitEnd === at + 2) {
9766
- pos = at + 2;
9767
- continue;
9768
- }
9769
- pos = digitEnd;
9770
- const nameEnd = digitEnd + length;
9771
- if (nameEnd >= rangeEnd || bytes[nameEnd] !== 67) continue;
9772
- const symbol = `._OBJC_CLASS_${bytes.toString("latin1", digitEnd, nameEnd)}`;
9934
+ const symbols = obj.segObjCClasses.get(segIdx);
9935
+ if (!symbols) return;
9936
+ for (const symbol of symbols) {
9773
9937
  for (const provider of lazyProviders.get(symbol) ?? []) {
9774
9938
  eagerDynamicObjects.add(provider);
9775
9939
  extractObject(provider);
@@ -9865,7 +10029,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
9865
10029
  const cached2 = objectBytes.get(obj);
9866
10030
  const buf = cached2 ? new Uint8Array(cached2) : new Uint8Array(import_node_fs16.default.readFileSync(obj.file));
9867
10031
  const rawBuf = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
9868
- const inputSha256 = link ? (0, import_node_crypto8.createHash)("sha256").update(buf).digest("hex") : "";
10032
+ const inputSha256 = link ? sha256Hex(buf) : "";
9869
10033
  const fLive = liveFuncs.get(obj);
9870
10034
  const sLive = liveSegs.get(obj);
9871
10035
  const dLive = liveDataSyms.get(obj);
@@ -12063,21 +12227,34 @@ var init_wasm_binary_sections = __esm({
12063
12227
  });
12064
12228
 
12065
12229
  // src/wasm-narrow-boundary.ts
12066
- function dropWasmCustomSection(bytes, name3) {
12067
- const parts = [bytes.subarray(0, 8)];
12068
- for (const { id, offset, start, end } of wasmSections2(bytes)) {
12069
- if (id === 0 && readWasmSection(bytes, start, end).name() === name3) continue;
12070
- parts.push(bytes.subarray(offset, end));
12230
+ function writeWasmCustomSections(bytes, entries2) {
12231
+ if (entries2.length === 0) return Buffer.concat([bytes]);
12232
+ const replaced = new Set(entries2.map(([name3]) => name3));
12233
+ const parts = [];
12234
+ let sliceStart = 0;
12235
+ let sliceEnd = 8;
12236
+ for (const { id, start, end } of wasmSections2(bytes)) {
12237
+ if (id === 0 && replaced.has(readWasmSection(bytes, start, end).name())) {
12238
+ if (sliceEnd > sliceStart) parts.push(bytes.subarray(sliceStart, sliceEnd));
12239
+ sliceStart = end;
12240
+ sliceEnd = end;
12241
+ } else {
12242
+ sliceEnd = end;
12243
+ }
12244
+ }
12245
+ if (sliceEnd > sliceStart) parts.push(bytes.subarray(sliceStart, sliceEnd));
12246
+ for (const [name3, data] of entries2) {
12247
+ const nameBytes = Buffer.from(encodeWasmName(name3));
12248
+ parts.push(
12249
+ Buffer.from([0, ...encodeWasmNumber(nameBytes.length + data.length)]),
12250
+ nameBytes,
12251
+ data
12252
+ );
12071
12253
  }
12072
12254
  return Buffer.concat(parts);
12073
12255
  }
12074
12256
  function writeWasmCustomSection(bytes, name3, data) {
12075
- const section2 = Buffer.concat([Buffer.from(encodeWasmName(name3)), data]);
12076
- return Buffer.concat([
12077
- dropWasmCustomSection(bytes, name3),
12078
- Buffer.from([0, ...encodeWasmNumber(section2.length)]),
12079
- section2
12080
- ]);
12257
+ return writeWasmCustomSections(bytes, [[name3, data]]);
12081
12258
  }
12082
12259
  function readWasmMemory(bytes) {
12083
12260
  return readWasmMemoryAndTableImports(bytes, wasmSections2(bytes)).memory;
@@ -12349,6 +12526,11 @@ var init_wasm_narrow_boundary = __esm({
12349
12526
  });
12350
12527
 
12351
12528
  // src/swift-guest-dyld-table.ts
12529
+ function sha256Buffer(bytes) {
12530
+ if (typeof Bun !== "undefined")
12531
+ return Buffer.from(new Bun.CryptoHasher("sha256").update(bytes).digest());
12532
+ return (0, import_node_crypto11.createHash)("sha256").update(bytes).digest();
12533
+ }
12352
12534
  function uleb3(value) {
12353
12535
  const bytes = [];
12354
12536
  for (let rest = value; ; rest = Math.floor(rest / 128)) {
@@ -12383,7 +12565,7 @@ function encodeGuestDyldTable(rows) {
12383
12565
  }
12384
12566
  const file = Buffer.concat(packs);
12385
12567
  const header = Buffer.alloc(40 + packs.length * 8);
12386
- (0, import_node_crypto11.createHash)("sha256").update(file).digest().copy(header, 0);
12568
+ sha256Buffer(file).copy(header, 0);
12387
12569
  header.writeUInt32LE(file.length, 32);
12388
12570
  header.writeUInt32LE(packs.length, 36);
12389
12571
  let offset = 0;
@@ -12395,11 +12577,11 @@ function encodeGuestDyldTable(rows) {
12395
12577
  const names = firsts.flatMap((name3) => [name3, Buffer.of(0)]);
12396
12578
  return { index: Buffer.concat([header, ...names]), packs: file };
12397
12579
  }
12398
- function moveGuestDyldTable(map, wasm, symbols, bindingValues = /* @__PURE__ */ new Map()) {
12580
+ function moveGuestDyldTable(map, wasm, symbols, bindingValues = /* @__PURE__ */ new Map(), extraSections = []) {
12399
12581
  const range = guestDyldValueRange(map);
12400
12582
  if (!range) {
12401
12583
  if (symbols.length) throw new Error("link map has no dyld values");
12402
- return wasm;
12584
+ return extraSections.length ? writeWasmCustomSections(wasm, extraSections) : wasm;
12403
12585
  }
12404
12586
  if (range.length !== symbols.length * 8)
12405
12587
  throw new Error("linked dyld values do not match the ledger rows");
@@ -12414,11 +12596,11 @@ function moveGuestDyldTable(map, wasm, symbols, bindingValues = /* @__PURE__ */
12414
12596
  return binding === void 0 ? { name: name3, image, kind: 0, value: view.getBigUint64(index2 * 8, true) } : { name: name3, image, kind: 1, value: BigInt(binding) };
12415
12597
  });
12416
12598
  const { index, packs } = encodeGuestDyldTable(rows);
12417
- return writeWasmCustomSection(
12418
- writeWasmCustomSection(taken.wasm, NATIVE_DYLD_TABLE_SECTION, index),
12419
- NATIVE_DYLD_PACKS_SECTION,
12420
- packs
12421
- );
12599
+ return writeWasmCustomSections(taken.wasm, [
12600
+ [NATIVE_DYLD_TABLE_SECTION, index],
12601
+ [NATIVE_DYLD_PACKS_SECTION, packs],
12602
+ ...extraSections
12603
+ ]);
12422
12604
  }
12423
12605
  function guestDyldValueRange(map) {
12424
12606
  const suffix = `:(${GUEST_DYLD_VALUES_SECTION})`;
@@ -12968,6 +13150,7 @@ function finalizeGuestProjectionStorage(options) {
12968
13150
  const owner = options.owners.get(options.projectionObject);
12969
13151
  if (owner === void 0) throw new Error("guest projection object has no image owner");
12970
13152
  const ranges = [];
13153
+ const data = [];
12971
13154
  const spans = guestLinkedSpans(
12972
13155
  options.map,
12973
13156
  options.linked,
@@ -12978,7 +13161,8 @@ function finalizeGuestProjectionStorage(options) {
12978
13161
  {
12979
13162
  trackedObject: options.projectionObject,
12980
13163
  trackedObjectOwner: owner,
12981
- trackedLinearSpans: ranges
13164
+ trackedLinearSpans: ranges,
13165
+ optimizedDataSegments: data
12982
13166
  }
12983
13167
  );
12984
13168
  const images = planGuestProjectionRegions(
@@ -12987,7 +13171,6 @@ function finalizeGuestProjectionStorage(options) {
12987
13171
  options.sdkSpans ? [...spans, ...options.sdkSpans] : spans
12988
13172
  );
12989
13173
  const result = Buffer.from(options.optimized);
12990
- const data = guestWasmDataSegments(options.optimized, options.sdkSpans === void 0);
12991
13174
  const locations = /* @__PURE__ */ new Map();
12992
13175
  const counts = /* @__PURE__ */ new Map();
12993
13176
  const uuids = /* @__PURE__ */ new Map();
@@ -13970,17 +14153,17 @@ var init_binaryen_lock = __esm({
13970
14153
  "linux-x64": {
13971
14154
  asset: "x86_64-linux",
13972
14155
  upstreamSha256: "195ddc94f9bc89f45abdabb0b9eea86023d727ba90eac8b35b80f2544fc30572",
13973
- sha256: "1024974f254c1c2edd738246ec6af5add16d3d36b5f58a94545febda3b33c869"
14156
+ sha256: "40062fb1ebbad7f04f361c1e3bb309dffb1d2318dd2e12235a0e7e820e18d6c9"
13974
14157
  },
13975
14158
  "linux-arm64": {
13976
14159
  asset: "aarch64-linux",
13977
14160
  upstreamSha256: "c58562417836c5d0493d89bdefc434933bdc097db641b483df86bcfa557a107f",
13978
- sha256: "7dedfc9f5cb32e75a28831f3b5aa053fd3e0bdd74f73dc4d1b1588947236daef"
14161
+ sha256: "d79b09d5b66f62f9e4bb691517b174b42bcdc0b7f40769d1993b7c565b0a54c7"
13979
14162
  },
13980
14163
  "darwin-arm64": {
13981
14164
  asset: "arm64-macos",
13982
14165
  upstreamSha256: "98aad827847af7ef990ed7098d885725c8e5b5aae75073403635617ae4e259aa",
13983
- sha256: "0b56e0a06b6a873877871537a120fd94e2121e67f4bce5f8b5252c47b615854a"
14166
+ sha256: "29342632a4fa52466c4feea846698fe5aa56ff46226a914d60b65b8735373d63"
13984
14167
  }
13985
14168
  }
13986
14169
  };
@@ -14498,6 +14681,7 @@ function outputPath(args) {
14498
14681
  }
14499
14682
  function withOutput(args, output, discovery) {
14500
14683
  const result = [];
14684
+ let stripsDebug = false;
14501
14685
  for (let i = 0; i < args.length; i++) {
14502
14686
  const arg = args[i];
14503
14687
  if (arg === "-o" || arg === "--output") {
@@ -14507,9 +14691,12 @@ function withOutput(args, output, discovery) {
14507
14691
  if (arg.startsWith("--output=")) continue;
14508
14692
  if (discovery && (arg.startsWith("--why-extract=") || arg.startsWith("--Map=")))
14509
14693
  continue;
14694
+ if (arg === "--strip-debug" || arg === "-S" || arg === "--strip-all" || arg === "-s")
14695
+ stripsDebug = true;
14510
14696
  result.push(arg);
14511
14697
  }
14512
14698
  if (discovery) result.push("--allow-multiple-definition");
14699
+ if (!stripsDebug) result.push("--strip-debug");
14513
14700
  result.push("-o", output);
14514
14701
  return result;
14515
14702
  }
@@ -14540,6 +14727,37 @@ async function linkGuestImages(options) {
14540
14727
  }
14541
14728
  return import_node_fs24.default.readFileSync(trace, "utf8");
14542
14729
  };
14730
+ const runLinkAsync = async (name3, arguments_) => {
14731
+ const response = import_node_path24.default.join(directory, `${name3}.rsp`);
14732
+ const trace = import_node_path24.default.join(directory, `${name3}-inputs.txt`);
14733
+ import_node_fs24.default.writeFileSync(
14734
+ response,
14735
+ [...arguments_, "--trace"].map((argument2) => JSON.stringify(argument2)).join(" ")
14736
+ );
14737
+ const output = import_node_fs24.default.openSync(trace, "w");
14738
+ try {
14739
+ await new Promise((resolve, reject) => {
14740
+ const child = (0, import_node_child_process14.spawn)(wasmLd, [`@${response}`], {
14741
+ stdio: ["ignore", output, "pipe"]
14742
+ });
14743
+ const stderr = [];
14744
+ child.stderr?.on("data", (chunk) => stderr.push(chunk));
14745
+ child.once("error", reject);
14746
+ child.once("close", (code, signal) => {
14747
+ if (code === 0) resolve();
14748
+ else
14749
+ reject(
14750
+ new Error(
14751
+ `wasm-ld (${name3}) failed (${signal ?? code}): ${Buffer.concat(stderr).toString("utf8")}`
14752
+ )
14753
+ );
14754
+ });
14755
+ });
14756
+ } finally {
14757
+ import_node_fs24.default.closeSync(output);
14758
+ }
14759
+ return import_node_fs24.default.readFileSync(trace, "utf8");
14760
+ };
14543
14761
  const preselection = options.projection && options.preselectionDiscovery ? options.preselectionDiscovery : void 0;
14544
14762
  let discoveryProjection;
14545
14763
  if (options.projection) {
@@ -14769,6 +14987,7 @@ async function linkGuestImages(options) {
14769
14987
  };
14770
14988
  const ledgerObjectPromise = compileLedgerAsync("ledger", ledger.llvmIR);
14771
14989
  const appLedgerObjectPromise = options.onSplitInputs && ledger.appLLVMIR ? compileLedgerAsync("app-ledger", ledger.appLLVMIR) : void 0;
14990
+ let deferredFinalLink;
14772
14991
  try {
14773
14992
  const replacements = /* @__PURE__ */ new Map();
14774
14993
  const linkedOwners = /* @__PURE__ */ new Map();
@@ -14870,7 +15089,7 @@ async function linkGuestImages(options) {
14870
15089
  });
14871
15090
  const finalOutput = import_node_path24.default.join(directory, "final.wasm");
14872
15091
  const finalWhy = import_node_path24.default.join(directory, "final-why-extract.txt");
14873
- const linkFinal = (projectionObject2, layoutMap) => runLink("final", [
15092
+ const finalLinkArgs = (projectionObject2, layoutMap) => [
14874
15093
  ...withOutput(finalArgs, finalOutput, false),
14875
15094
  ledgerObject,
14876
15095
  `@${lazyExports}`,
@@ -14878,10 +15097,38 @@ async function linkGuestImages(options) {
14878
15097
  ...provider ? [`--undefined=${providerSymbol}`] : [],
14879
15098
  ...layoutMap ? [`--Map=${layoutMap}`] : [],
14880
15099
  `--why-extract=${finalWhy}`
14881
- ]);
15100
+ ];
15101
+ const linkFinal = (projectionObject2, layoutMap) => runLink("final", finalLinkArgs(projectionObject2, layoutMap));
15102
+ const finalizeFinalLink = (trace) => {
15103
+ const finalSelection = selectedGuestLinkInputs(
15104
+ remapGuestLinkPlan(plan, replacements),
15105
+ finalArgs,
15106
+ import_node_fs24.default.readFileSync(finalWhy, "utf8"),
15107
+ trace,
15108
+ finalArchives
15109
+ );
15110
+ const original = new Map(
15111
+ [...replacements].map(([before2, after2]) => [after2, before2])
15112
+ );
15113
+ const key = (item) => JSON.stringify([original.get(item.artifact) ?? item.artifact, item.member]);
15114
+ const before = new Set(selected.map(key));
15115
+ const after = new Set(finalSelection.map(key));
15116
+ const changed = [...before].filter((item) => !after.has(item));
15117
+ changed.push(...[...after].filter((item) => !before.has(item)));
15118
+ if (changed.length)
15119
+ throw new Error(
15120
+ `guest link selected different inputs after rewriting:
15121
+ ${changed.join("\n")}`
15122
+ );
15123
+ import_node_fs24.default.renameSync(finalOutput, outputPath(args));
15124
+ if (KEEP_WASM_NAMES)
15125
+ import_node_fs24.default.writeFileSync(
15126
+ outputPath(args),
15127
+ nameGuestImageAliases(import_node_fs24.default.readFileSync(outputPath(args)), plan.symbols)
15128
+ );
15129
+ };
14882
15130
  let projectionObject;
14883
15131
  let projectionStorage;
14884
- let finalTrace;
14885
15132
  if (options.projection) {
14886
15133
  const projection = options.projection;
14887
15134
  if (!plan.images.some((image) => image.id === projection.image))
@@ -14934,8 +15181,18 @@ async function linkGuestImages(options) {
14934
15181
  [...projection.clangOptions, "-c", projectionSource, "-o", projectionObject],
14935
15182
  { stdio: "pipe" }
14936
15183
  );
14937
- finalTrace = linkFinal(projectionObject, callerMap ? void 0 : layoutMap);
14938
- if (sharedSdk) break;
15184
+ if (sharedSdk && options.onFinalLink && options.onSplitInputs && appLedgerObjectPromise) {
15185
+ deferredFinalLink = runLinkAsync(
15186
+ "final",
15187
+ finalLinkArgs(projectionObject, callerMap ? void 0 : layoutMap)
15188
+ ).then((trace) => finalizeFinalLink(trace));
15189
+ break;
15190
+ }
15191
+ const finalTrace = linkFinal(projectionObject, callerMap ? void 0 : layoutMap);
15192
+ if (sharedSdk) {
15193
+ finalizeFinalLink(finalTrace);
15194
+ break;
15195
+ }
14939
15196
  const wasm = import_node_fs24.default.readFileSync(finalOutput);
14940
15197
  const actual = guestProjectionRegionCounts(
14941
15198
  images.length,
@@ -14947,38 +15204,17 @@ async function linkGuestImages(options) {
14947
15204
  sectionOwners
14948
15205
  )
14949
15206
  );
14950
- if (actual.every((count, index) => count <= capacities[index].regions)) break;
15207
+ if (actual.every((count, index) => count <= capacities[index].regions)) {
15208
+ finalizeFinalLink(finalTrace);
15209
+ break;
15210
+ }
14951
15211
  capacities = capacities.map((capacity, index) => ({
14952
15212
  ...capacity,
14953
15213
  regions: Math.max(actual[index], capacity.regions)
14954
15214
  }));
14955
15215
  }
14956
15216
  linkedOwners.set(projectionObject, projection.image);
14957
- } else finalTrace = linkFinal();
14958
- const finalSelection = selectedGuestLinkInputs(
14959
- remapGuestLinkPlan(plan, replacements),
14960
- finalArgs,
14961
- import_node_fs24.default.readFileSync(finalWhy, "utf8"),
14962
- finalTrace,
14963
- finalArchives
14964
- );
14965
- const original = new Map([...replacements].map(([before2, after2]) => [after2, before2]));
14966
- const key = (item) => JSON.stringify([original.get(item.artifact) ?? item.artifact, item.member]);
14967
- const before = new Set(selected.map(key));
14968
- const after = new Set(finalSelection.map(key));
14969
- const changed = [...before].filter((item) => !after.has(item));
14970
- changed.push(...[...after].filter((item) => !before.has(item)));
14971
- if (changed.length)
14972
- throw new Error(
14973
- `guest link selected different inputs after rewriting:
14974
- ${changed.join("\n")}`
14975
- );
14976
- import_node_fs24.default.renameSync(finalOutput, outputPath(args));
14977
- if (KEEP_WASM_NAMES)
14978
- import_node_fs24.default.writeFileSync(
14979
- outputPath(args),
14980
- nameGuestImageAliases(import_node_fs24.default.readFileSync(outputPath(args)), plan.symbols)
14981
- );
15217
+ } else finalizeFinalLink(linkFinal());
14982
15218
  if (projectionStorage && projectionObject)
14983
15219
  options.projection.onReserved(projectionStorage, projectionObject);
14984
15220
  options.onLinkedOwners?.(linkedOwners);
@@ -15014,11 +15250,13 @@ ${changed.join("\n")}`
15014
15250
  appDefinedSymbols
15015
15251
  });
15016
15252
  }
15253
+ if (deferredFinalLink) options.onFinalLink?.(deferredFinalLink);
15017
15254
  return selected;
15018
15255
  } catch (error) {
15019
15256
  await Promise.allSettled([
15020
15257
  ledgerObjectPromise,
15021
- ...appLedgerObjectPromise ? [appLedgerObjectPromise] : []
15258
+ ...appLedgerObjectPromise ? [appLedgerObjectPromise] : [],
15259
+ ...deferredFinalLink ? [deferredFinalLink] : []
15022
15260
  ]);
15023
15261
  throw error;
15024
15262
  }
@@ -15650,6 +15888,7 @@ async function linkPrunedGuestImages(options) {
15650
15888
  identities: aliasGuestLinkIdentities(identities, prepared.archives)
15651
15889
  };
15652
15890
  }
15891
+ let finalLinkDone;
15653
15892
  const selected = await linkCompleteGuestImages({
15654
15893
  plan,
15655
15894
  args: [...linkedArgs, `--Map=${options.mapPath}`],
@@ -15663,6 +15902,9 @@ async function linkPrunedGuestImages(options) {
15663
15902
  resolvePlan: options.resolvePlan,
15664
15903
  sharedSdk: options.sharedSdk,
15665
15904
  onSplitInputs: options.onSplitInputs,
15905
+ onFinalLink: options.deferFinalLink ? (done) => {
15906
+ finalLinkDone = done;
15907
+ } : void 0,
15666
15908
  onDyldRows: options.onDyldRows,
15667
15909
  onLinkedOwners: (value) => {
15668
15910
  owners = value;
@@ -15676,7 +15918,8 @@ async function linkPrunedGuestImages(options) {
15676
15918
  owners,
15677
15919
  generatedSectionOwners,
15678
15920
  sdk,
15679
- mapPath: options.mapPath
15921
+ mapPath: options.mapPath,
15922
+ finalLinkDone
15680
15923
  };
15681
15924
  }
15682
15925
  var import_node_child_process14, import_node_fs24, import_node_path24, import_node_util3, execFileAsync, WASM_MAGIC, BITCODE_MAGIC;
@@ -15754,8 +15997,13 @@ function clangBinaryStamp(file) {
15754
15997
  const stat = (0, import_node_fs25.statSync)(file, { bigint: true });
15755
15998
  return [file, stat.size, stat.mtimeNs].join(":");
15756
15999
  }
16000
+ function sha256Hex2(bytes) {
16001
+ if (typeof Bun !== "undefined")
16002
+ return new Bun.CryptoHasher("sha256").update(bytes).digest("hex");
16003
+ return (0, import_node_crypto17.createHash)("sha256").update(bytes).digest("hex");
16004
+ }
15757
16005
  function clangWrapperStamp(file) {
15758
- return (0, import_node_crypto17.createHash)("sha256").update((0, import_node_fs25.readFileSync)(file)).digest("hex");
16006
+ return sha256Hex2((0, import_node_fs25.readFileSync)(file));
15759
16007
  }
15760
16008
  function clangArgsNeedCwd(args) {
15761
16009
  const pathFlags = /* @__PURE__ */ new Set([
@@ -15905,22 +16153,35 @@ function sourceGuestClangLinkOptions(options) {
15905
16153
  "SOURCE_DATE_EPOCH"
15906
16154
  ].map((name3) => process.env[name3] ?? "");
15907
16155
  const replays = [];
16156
+ const realPathCache = /* @__PURE__ */ new Map();
16157
+ const cachedRealpath = (file) => {
16158
+ let resolved = realPathCache.get(file);
16159
+ if (resolved === void 0) {
16160
+ resolved = (0, import_node_fs25.realpathSync)(file);
16161
+ realPathCache.set(file, resolved);
16162
+ }
16163
+ return resolved;
16164
+ };
16165
+ const resolvedSwiftCompiler = cachedRealpath(options.swiftCompiler);
15908
16166
  let clang;
16167
+ let clangWrapper;
15909
16168
  let clangStamp;
15910
16169
  let wrapperStamp;
15911
16170
  for (const file of wanted) {
15912
16171
  const command = commands.get(file);
15913
16172
  if (!command) throw new Error(`missing source object producer ${file}`);
15914
16173
  if (command.tool === "shell") {
15915
- if (!command.args.length || (0, import_node_fs25.realpathSync)(command.args[0]) !== (0, import_node_fs25.realpathSync)(options.swiftCompiler))
16174
+ if (!command.args.length || cachedRealpath(command.args[0]) !== resolvedSwiftCompiler)
15916
16175
  throw new Error(`unsupported source object producer ${file}`);
15917
16176
  continue;
15918
16177
  }
15919
- const compiler = command.args[0] ? (0, import_node_fs25.realpathSync)(command.args[0]) : "";
15920
- clang ??= (0, import_node_fs25.realpathSync)(import_node_path25.default.join(options.toolchainBin, "clang"));
15921
- if (command.tool !== "clang" || compiler !== clang && compiler !== (0, import_node_fs25.realpathSync)(import_node_path25.default.join(options.buildDirectory, CLANG_TARGET_MODULE_WRAPPER)))
16178
+ const compiler = command.args[0] ? cachedRealpath(command.args[0]) : "";
16179
+ clang ??= cachedRealpath(import_node_path25.default.join(options.toolchainBin, "clang"));
16180
+ if (command.tool !== "clang" || compiler !== clang && compiler !== (clangWrapper ??= cachedRealpath(
16181
+ import_node_path25.default.join(options.buildDirectory, CLANG_TARGET_MODULE_WRAPPER)
16182
+ )))
15922
16183
  throw new Error(`unsupported source object producer ${file}`);
15923
- const key = (0, import_node_crypto17.createHash)("sha256").update(
16184
+ const key = sha256Hex2(
15924
16185
  JSON.stringify([
15925
16186
  "clang-link-options/v2",
15926
16187
  clangArgsNeedCwd(command.args) ? process.cwd() : null,
@@ -15930,11 +16191,8 @@ function sourceGuestClangLinkOptions(options) {
15930
16191
  compiler === clang ? null : wrapperStamp ??= clangWrapperStamp(compiler),
15931
16192
  clangProducerStamp(file)
15932
16193
  ])
15933
- ).digest("hex");
15934
- const cacheFile = import_node_path25.default.join(
15935
- cacheDirectory,
15936
- (0, import_node_crypto17.createHash)("sha256").update(file).digest("hex") + ".json"
15937
16194
  );
16195
+ const cacheFile = import_node_path25.default.join(cacheDirectory, sha256Hex2(file) + ".json");
15938
16196
  const cached2 = readClangLinkOptions(cacheFile, key);
15939
16197
  if (cached2) {
15940
16198
  validateClangLinkOptions(cached2);
@@ -18670,6 +18928,21 @@ var init_swift_root_lock = __esm({
18670
18928
  }
18671
18929
  });
18672
18930
 
18931
+ // src/swift-sdk-image-recipe.ts
18932
+ var import_node_crypto24, SWIFT_SDK_IMAGE_VERSION, swiftSdkImageScope, SWIFT_SDK_IMAGE_RECIPE;
18933
+ var init_swift_sdk_image_recipe = __esm({
18934
+ "src/swift-sdk-image-recipe.ts"() {
18935
+ "use strict";
18936
+ import_node_crypto24 = require("node:crypto");
18937
+ init_wasm_optimize();
18938
+ SWIFT_SDK_IMAGE_VERSION = 13;
18939
+ swiftSdkImageScope = (scopedLookups) => scopedLookups ? "guest image scopes 9\n" : "unscoped constructor order 1\n";
18940
+ SWIFT_SDK_IMAGE_RECIPE = (0, import_node_crypto24.createHash)("sha256").update(`swift-sdk-image
18941
+ ${SWIFT_SDK_IMAGE_VERSION}
18942
+ `).update(WASM_LOWER_IDENTITY).update(swiftSdkImageScope(false)).update(swiftSdkImageScope(true)).digest("hex").slice(0, 16);
18943
+ }
18944
+ });
18945
+
18673
18946
  // src/swift-sdk-image-producer.ts
18674
18947
  var swift_sdk_image_producer_exports = {};
18675
18948
  __export(swift_sdk_image_producer_exports, {
@@ -18710,7 +18983,7 @@ function applySwiftSdkProducerEnvironment(environment) {
18710
18983
  }
18711
18984
  }
18712
18985
  function writeSwiftSdkProducerResult(file, launchId, error) {
18713
- const temporary = `${file}.${(0, import_node_crypto24.randomUUID)()}`;
18986
+ const temporary = `${file}.${(0, import_node_crypto25.randomUUID)()}`;
18714
18987
  (0, import_node_fs36.writeFileSync)(temporary, JSON.stringify({ launchId, error: error ?? null }));
18715
18988
  (0, import_node_fs36.renameSync)(temporary, file);
18716
18989
  }
@@ -18822,7 +19095,7 @@ async function produceSwiftSdkImage(input) {
18822
19095
  }
18823
19096
  }
18824
19097
  const repo = import_node_path36.default.resolve(input.moduleRoot, "../..");
18825
- const launchId = (0, import_node_crypto24.randomUUID)();
19098
+ const launchId = (0, import_node_crypto25.randomUUID)();
18826
19099
  const directory2 = import_node_path36.default.join(root, launchId);
18827
19100
  const requestFile = import_node_path36.default.join(directory2, "request.json");
18828
19101
  const sessionFile2 = import_node_path36.default.join(directory2, "session");
@@ -18920,12 +19193,12 @@ async function produceSwiftSdkImage(input) {
18920
19193
  await (0, import_promises5.setTimeout)(2e3, void 0, { signal: input.signal });
18921
19194
  }
18922
19195
  }
18923
- var import_node_child_process23, import_node_crypto24, import_node_fs36, import_node_path36, import_promises5, import_node_util6, run, environmentNames, launcher;
19196
+ var import_node_child_process23, import_node_crypto25, import_node_fs36, import_node_path36, import_promises5, import_node_util6, run, environmentNames, launcher;
18924
19197
  var init_swift_sdk_image_producer = __esm({
18925
19198
  "src/swift-sdk-image-producer.ts"() {
18926
19199
  "use strict";
18927
19200
  import_node_child_process23 = require("node:child_process");
18928
- import_node_crypto24 = require("node:crypto");
19201
+ import_node_crypto25 = require("node:crypto");
18929
19202
  import_node_fs36 = require("node:fs");
18930
19203
  import_node_path36 = __toESM(require("node:path"), 1);
18931
19204
  import_promises5 = require("node:timers/promises");
@@ -18965,7 +19238,6 @@ __export(swift_sdk_image_exports, {
18965
19238
  SWIFT_SDK_APP_TABLE_BASE: () => SWIFT_SDK_APP_TABLE_BASE,
18966
19239
  SWIFT_SDK_IMAGE_BUNDLE: () => SWIFT_SDK_IMAGE_BUNDLE,
18967
19240
  SWIFT_SDK_IMAGE_FILES: () => SWIFT_SDK_IMAGE_FILES,
18968
- SWIFT_SDK_IMAGE_VERSION: () => SWIFT_SDK_IMAGE_VERSION,
18969
19241
  SWIFT_SDK_MEMORY_BASE: () => SWIFT_SDK_MEMORY_BASE,
18970
19242
  SWIFT_SDK_PIECE_FIELDS: () => SWIFT_SDK_PIECE_FIELDS,
18971
19243
  buildSwiftSdkImage: () => buildSwiftSdkImage,
@@ -19000,9 +19272,9 @@ function swiftSdkImageProducts(moduleRoot, frameworkImports) {
19000
19272
  function swiftSdkImageKey(moduleRoot, scopedLookups = false, products = []) {
19001
19273
  const distribution = swiftDistributionAt(moduleRoot);
19002
19274
  const inputs = distribution ? swiftSdkDistributionInputs(distribution) : swiftModuleDigest(moduleRoot);
19003
- return (0, import_node_crypto25.createHash)("sha256").update(`swift-sdk-image
19275
+ return (0, import_node_crypto26.createHash)("sha256").update(`swift-sdk-image
19004
19276
  ${SWIFT_SDK_IMAGE_VERSION}
19005
- `).update(WASM_LOWER_IDENTITY).update(KEEP_WASM_NAMES ? "\nnames\n" : "\n").update(scopedLookups ? "guest image scopes 9\n" : "unscoped constructor order 1\n").update(inputs).update(products.length === 0 ? "" : `
19277
+ `).update(WASM_LOWER_IDENTITY).update(KEEP_WASM_NAMES ? "\nnames\n" : "\n").update(swiftSdkImageScope(scopedLookups)).update(inputs).update(products.length === 0 ? "" : `
19006
19278
  products ${products.join(" ")}`).digest("hex").slice(0, 32);
19007
19279
  }
19008
19280
  function swiftSdkImageEntry(key, scopedLookups) {
@@ -19091,7 +19363,7 @@ async function buildSwiftSdkImage(moduleRoot, scopedLookups = false, frameworkIm
19091
19363
  stage
19092
19364
  ]);
19093
19365
  const image = cached(stage, key);
19094
- if (!image || (0, import_node_crypto25.createHash)("sha256").update((0, import_node_fs37.readFileSync)(image.image)).digest("hex") !== image.sha256)
19366
+ if (!image || (0, import_node_crypto26.createHash)("sha256").update((0, import_node_fs37.readFileSync)(image.image)).digest("hex") !== image.sha256)
19095
19367
  throw new Error(`invalid published Swift SDK image ${key}`);
19096
19368
  (0, import_node_fs37.rmSync)(directory, { recursive: true, force: true });
19097
19369
  (0, import_node_fs37.renameSync)(stage, directory);
@@ -19300,6 +19572,7 @@ async function linkSwiftSdkImage(moduleRoot, key, directory, work, scopedLookups
19300
19572
  ].map((name3) => `--export=${name3}`),
19301
19573
  `@${import_node_path37.default.join(work, "exports.rsp")}`,
19302
19574
  "--gc-sections",
19575
+ "--strip-debug",
19303
19576
  // strings stay with their objects, so an app loads only the ones its pieces reference
19304
19577
  "-O0"
19305
19578
  ];
@@ -19360,7 +19633,7 @@ async function linkSwiftSdkImage(moduleRoot, key, directory, work, scopedLookups
19360
19633
  (0, import_node_fs37.writeFileSync)(import_node_path37.default.join(work, INTERFACE_FILE), JSON.stringify(sdkInterface));
19361
19634
  (0, import_node_fs37.writeFileSync)(
19362
19635
  import_node_path37.default.join(work, IMAGE_DIGEST),
19363
- (0, import_node_crypto25.createHash)("sha256").update(image).digest("hex")
19636
+ typeof Bun !== "undefined" ? new Bun.CryptoHasher("sha256").update(image).digest("hex") : (0, import_node_crypto26.createHash)("sha256").update(image).digest("hex")
19364
19637
  );
19365
19638
  if (swiftSdkImageKey(
19366
19639
  moduleRoot,
@@ -19629,12 +19902,12 @@ function readSwiftSdkManifest(image) {
19629
19902
  }));
19630
19903
  return setBoundedCache(cachedSdkManifests, cacheKey, { manifest, block, segments });
19631
19904
  }
19632
- var import_node_child_process24, import_node_crypto25, import_node_fs37, import_node_path37, import_node_util7, run2, SWIFT_SDK_IMAGE_VERSION, SWIFT_SDK_APP_MEMORY_BASE, SWIFT_SDK_MEMORY_BASE, SWIFT_SDK_APP_TABLE_BASE, EMPTY_APP, IMAGE_TABLES, IMAGE_ENTRY, imageApp, IMAGE_FILE, IMAGE_DIGEST, swiftSdkImageFile, INTERFACE_FILE, MANIFEST_FILE, MANIFEST_DATA_FILE, SWIFT_SDK_IMAGE_FILES, SWIFT_SDK_IMAGE_BUNDLE, MAX_CACHED_SDK_IMAGES, cachedSdkInterfaces, cachedSdkManifestIndices, cachedSdkManifests, SWIFT_SDK_PIECE_FIELDS, MANIFEST_BLOCKS, isManifestBlock;
19905
+ var import_node_child_process24, import_node_crypto26, import_node_fs37, import_node_path37, import_node_util7, run2, SWIFT_SDK_APP_MEMORY_BASE, SWIFT_SDK_MEMORY_BASE, SWIFT_SDK_APP_TABLE_BASE, EMPTY_APP, IMAGE_TABLES, IMAGE_ENTRY, imageApp, IMAGE_FILE, IMAGE_DIGEST, swiftSdkImageFile, INTERFACE_FILE, MANIFEST_FILE, MANIFEST_DATA_FILE, SWIFT_SDK_IMAGE_FILES, SWIFT_SDK_IMAGE_BUNDLE, MAX_CACHED_SDK_IMAGES, cachedSdkInterfaces, cachedSdkManifestIndices, cachedSdkManifests, SWIFT_SDK_PIECE_FIELDS, MANIFEST_BLOCKS, isManifestBlock;
19633
19906
  var init_swift_sdk_image = __esm({
19634
19907
  "src/swift-sdk-image.ts"() {
19635
19908
  "use strict";
19636
19909
  import_node_child_process24 = require("node:child_process");
19637
- import_node_crypto25 = require("node:crypto");
19910
+ import_node_crypto26 = require("node:crypto");
19638
19911
  import_node_fs37 = require("node:fs");
19639
19912
  import_node_path37 = __toESM(require("node:path"), 1);
19640
19913
  import_node_util7 = require("node:util");
@@ -19646,13 +19919,13 @@ var init_swift_sdk_image = __esm({
19646
19919
  init_swift_root_lock();
19647
19920
  init_swift_sdk_guest_lookups();
19648
19921
  init_swift_sdk_image_map();
19922
+ init_swift_sdk_image_recipe();
19649
19923
  init_swift_sdk_image_wasm();
19650
19924
  init_swift_toolchain();
19651
19925
  init_swift_wasm_prune();
19652
19926
  init_swiftTargetContract();
19653
19927
  init_wasm_optimize();
19654
19928
  run2 = (0, import_node_util7.promisify)(import_node_child_process24.execFile);
19655
- SWIFT_SDK_IMAGE_VERSION = 13;
19656
19929
  SWIFT_SDK_APP_MEMORY_BASE = 8372224;
19657
19930
  SWIFT_SDK_MEMORY_BASE = 128 * 1024 * 1024;
19658
19931
  SWIFT_SDK_APP_TABLE_BASE = 524288;
@@ -19800,6 +20073,7 @@ __export(swift_sdk_app_module_exports, {
19800
20073
  readSwiftSdkUsage: () => readSwiftSdkUsage,
19801
20074
  selectSwiftSdkData: () => selectSwiftSdkData,
19802
20075
  swiftAppModuleInputs: () => swiftAppModuleInputs,
20076
+ swiftAppModuleThunkSection: () => swiftAppModuleThunkSection,
19803
20077
  swiftSdkProjectionSpans: () => swiftSdkProjectionSpans,
19804
20078
  writeSwiftSdkAppLink: () => writeSwiftSdkAppLink
19805
20079
  });
@@ -19851,9 +20125,12 @@ async function buildSwiftAppModule(options) {
19851
20125
  linkage: link.linkage,
19852
20126
  usage
19853
20127
  });
19854
- (0, import_node_fs38.writeFileSync)(options.output, finishSwiftAppModule((0, import_node_fs38.readFileSync)(options.output)));
20128
+ finishSwiftAppModuleFile(options.output);
19855
20129
  return binding;
19856
20130
  }
20131
+ function swiftAppModuleThunkSection(lowered) {
20132
+ return [NATIVE_SDK_THUNK_SECTION, sdkImportThunks(lowered)];
20133
+ }
19857
20134
  function finishSwiftAppModule(lowered) {
19858
20135
  return writeWasmCustomSection(
19859
20136
  lowered,
@@ -19861,6 +20138,73 @@ function finishSwiftAppModule(lowered) {
19861
20138
  sdkImportThunks(lowered)
19862
20139
  );
19863
20140
  }
20141
+ function finishSwiftAppModuleFile(file) {
20142
+ const fd = (0, import_node_fs38.openSync)(file, "r");
20143
+ let prefixEnd = 8;
20144
+ let hasExistingThunk = false;
20145
+ let prefix;
20146
+ try {
20147
+ const total = (0, import_node_fs38.fstatSync)(fd).size;
20148
+ const probe = Buffer.allocUnsafe(16);
20149
+ let offset = 8;
20150
+ while (offset < total) {
20151
+ const read = (0, import_node_fs38.readSync)(fd, probe, 0, Math.min(16, total - offset), offset);
20152
+ if (read < 2) break;
20153
+ const id = probe[0];
20154
+ let size = 0;
20155
+ let shift = 0;
20156
+ let at = 1;
20157
+ for (; ; ) {
20158
+ const byte = probe[at++];
20159
+ size += (byte & 127) * 2 ** shift;
20160
+ if (!(byte & 128)) break;
20161
+ shift += 7;
20162
+ }
20163
+ const start = offset + at;
20164
+ const next = start + size;
20165
+ if (id === 1 || id === 2) prefixEnd = next;
20166
+ else if (id === 0) {
20167
+ const nameBuf = Buffer.allocUnsafe(Math.min(128, size));
20168
+ const nRead = (0, import_node_fs38.readSync)(fd, nameBuf, 0, nameBuf.length, start);
20169
+ let nLen = 0;
20170
+ let nShift = 0;
20171
+ let nAt = 0;
20172
+ for (; ; ) {
20173
+ if (nAt >= nRead) break;
20174
+ const byte = nameBuf[nAt++];
20175
+ nLen += (byte & 127) * 2 ** nShift;
20176
+ if (!(byte & 128)) break;
20177
+ nShift += 7;
20178
+ }
20179
+ if (nAt + nLen <= nRead && nameBuf.toString("utf8", nAt, nAt + nLen) === NATIVE_SDK_THUNK_SECTION) {
20180
+ hasExistingThunk = true;
20181
+ break;
20182
+ }
20183
+ }
20184
+ offset = next;
20185
+ }
20186
+ if (!hasExistingThunk) {
20187
+ prefix = Buffer.allocUnsafe(prefixEnd);
20188
+ let filled = 0;
20189
+ while (filled < prefixEnd) {
20190
+ const n = (0, import_node_fs38.readSync)(fd, prefix, filled, prefixEnd - filled, filled);
20191
+ if (n <= 0) break;
20192
+ filled += n;
20193
+ }
20194
+ prefix = prefix.subarray(0, filled);
20195
+ }
20196
+ } finally {
20197
+ (0, import_node_fs38.closeSync)(fd);
20198
+ }
20199
+ if (hasExistingThunk || !prefix) {
20200
+ (0, import_node_fs38.writeFileSync)(file, finishSwiftAppModule((0, import_node_fs38.readFileSync)(file)));
20201
+ return;
20202
+ }
20203
+ const thunks = sdkImportThunks(prefix);
20204
+ const nameBytes = Buffer.from(encodedName2(NATIVE_SDK_THUNK_SECTION));
20205
+ const header = Buffer.from([0, ...uleb4(nameBytes.length + thunks.length)]);
20206
+ (0, import_node_fs38.appendFileSync)(file, Buffer.concat([header, nameBytes, thunks]));
20207
+ }
19864
20208
  function swiftAppModuleInputs(tokens, buildRoot, sdkLibraries) {
19865
20209
  const owned = (token) => import_node_path38.default.resolve(token).startsWith(`${buildRoot}/`) && (!token.includes("/.peach-pruned-objs/") || token.endsWith("/swiftrt-patched.o"));
19866
20210
  const inputs = [];
@@ -20075,6 +20419,7 @@ async function linkSwiftAppModule(options) {
20075
20419
  "--unresolved-symbols=ignore-all",
20076
20420
  "--import-undefined",
20077
20421
  "--emit-relocs",
20422
+ "--strip-debug",
20078
20423
  "--gc-sections",
20079
20424
  "--keep-section=target_features",
20080
20425
  "--error-limit=0",
@@ -20097,7 +20442,7 @@ async function linkSwiftAppModule(options) {
20097
20442
  const skipPasses = options.layoutMap ? ["duplicate-function-elimination"] : void 0;
20098
20443
  const sdkTableEnd = sdk.sdkInterface.layout.tableEnd;
20099
20444
  const { loweringCache } = options;
20100
- const loweringKey = loweringCache && (0, import_node_crypto26.createHash)("sha256").update(
20445
+ const loweringKey = loweringCache && (typeof Bun !== "undefined" ? new Bun.CryptoHasher("sha256").update(
20101
20446
  JSON.stringify([
20102
20447
  loweringCache.compilerDigest,
20103
20448
  optimize,
@@ -20106,7 +20451,16 @@ async function linkSwiftAppModule(options) {
20106
20451
  lazy,
20107
20452
  KEEP_WASM_NAMES
20108
20453
  ])
20109
- ).update(bytes).digest("hex");
20454
+ ).update(bytes).digest("hex") : (0, import_node_crypto27.createHash)("sha256").update(
20455
+ JSON.stringify([
20456
+ loweringCache.compilerDigest,
20457
+ optimize,
20458
+ skipPasses,
20459
+ sdkTableEnd,
20460
+ lazy,
20461
+ KEEP_WASM_NAMES
20462
+ ])
20463
+ ).update(bytes).digest("hex"));
20110
20464
  return {
20111
20465
  linkage,
20112
20466
  async lower() {
@@ -20716,7 +21070,8 @@ function createSwiftSdkBinding(linkage, sdk, usage, projection) {
20716
21070
  bindSwiftAppModule(linkage, sdk),
20717
21071
  selectSwiftSdkData(sdk, usage, linkage, projection)
20718
21072
  ]);
20719
- return { bytes, sha256: (0, import_node_crypto26.createHash)("sha256").update(bytes).digest("hex") };
21073
+ const sha2562 = typeof Bun !== "undefined" ? new Bun.CryptoHasher("sha256").update(bytes).digest("hex") : (0, import_node_crypto27.createHash)("sha256").update(bytes).digest("hex");
21074
+ return { bytes, sha256: sha2562 };
20720
21075
  }
20721
21076
  function readSwiftSdkUsage(mapFile, linkedFile, sdkObjects) {
20722
21077
  const map = readWasmLinkMap(mapFile, false);
@@ -21262,12 +21617,12 @@ function partitionParent(section2) {
21262
21617
  "__objc_class_refs"
21263
21618
  ].find((name3) => section2 === name3 || section2.startsWith(`${name3}.`));
21264
21619
  }
21265
- var import_node_child_process25, import_node_crypto26, import_node_fs38, import_node_path38, import_node_util8, import_node_zlib4, run3, RELOCATION_WIDTHS, GLOBAL_INDEX, TLS_SLEB64, SDK_TLS_HELPER, SDK_TLS_DELTA, OBJC_SECTION_BOUNDARY, uleb4, sleb2, encodedName2, SCANNED, RUN_GAP;
21620
+ var import_node_child_process25, import_node_crypto27, import_node_fs38, import_node_path38, import_node_util8, import_node_zlib4, run3, RELOCATION_WIDTHS, GLOBAL_INDEX, TLS_SLEB64, SDK_TLS_HELPER, SDK_TLS_DELTA, OBJC_SECTION_BOUNDARY, uleb4, sleb2, encodedName2, SCANNED, RUN_GAP;
21266
21621
  var init_swift_sdk_app_module = __esm({
21267
21622
  "src/swift-sdk-app-module.ts"() {
21268
21623
  "use strict";
21269
21624
  import_node_child_process25 = require("node:child_process");
21270
- import_node_crypto26 = require("node:crypto");
21625
+ import_node_crypto27 = require("node:crypto");
21271
21626
  import_node_fs38 = require("node:fs");
21272
21627
  import_node_path38 = __toESM(require("node:path"), 1);
21273
21628
  import_node_util8 = require("node:util");
@@ -21472,6 +21827,7 @@ async function compileGuestLink(options) {
21472
21827
  onSplitInputs: sdk ? (value) => {
21473
21828
  splitInputs = value;
21474
21829
  } : void 0,
21830
+ deferFinalLink: Boolean(sdk),
21475
21831
  onDyldRows: (rows) => {
21476
21832
  lazyFunctions = rows.lazyFunctions;
21477
21833
  dyldSymbols = rows.dyldSymbols;
@@ -21740,156 +22096,164 @@ async function compileGuestLink(options) {
21740
22096
  });
21741
22097
  if (!reserved || !projectionObject) throw new Error("guest projection was not reserved");
21742
22098
  if (sdk) {
21743
- if (!splitInputs) throw new Error("guest link did not select shared SDK inputs");
21744
- const {
21745
- createSwiftSdkBinding: createSwiftSdkBinding2,
21746
- finishSwiftAppModule: finishSwiftAppModule2,
21747
- linkSwiftAppModule: linkSwiftAppModule2,
21748
- readSwiftSdkUsage: readSwiftSdkUsage2,
21749
- swiftSdkProjectionSpans: swiftSdkProjectionSpans2
21750
- } = await Promise.resolve().then(() => (init_swift_sdk_app_module(), swift_sdk_app_module_exports));
21751
- const project = options.project;
21752
- const work = project ? (0, import_node_fs39.mkdtempSync)(import_node_path39.default.join(directory, "app-module-")) : import_node_path39.default.join(directory, "app-module");
21753
- if (project) (0, import_node_fs39.chownSync)(work, project.uid, project.gid);
21754
- else (0, import_node_fs39.mkdirSync)(work, { recursive: true });
21755
- const layoutMap = import_node_path39.default.join(work, "app.map");
21756
- const owners = new Map(splitInputs.appObjects).set(projectionObject, 0);
21757
- const sdkObjectKeys = /* @__PURE__ */ new Map();
21758
- const sdkObjectImages = /* @__PURE__ */ new Map();
21759
- const sdkProductImages = new Map(prepared?.sdkProducts.images);
21760
- for (const [file, { image, product, identity }] of splitInputs.sdkObjects) {
21761
- const key = sdkGuestObjectKey(identity);
21762
- sdkObjectKeys.set(file, key);
21763
- sdkObjectImages.set(key, image);
21764
- const priorImage = sdkProductImages.get(product);
21765
- if (priorImage !== void 0 && priorImage !== image)
21766
- throw new Error(`SDK product ${product} has several guest images`);
21767
- sdkProductImages.set(product, image);
21768
- }
21769
- const usage = readSwiftSdkUsage2(result.mapPath, options.output, sdkObjectKeys);
21770
- const linkedModule = import_node_path39.default.join(work, "app.wasm");
21771
- const sdkSpans = swiftSdkProjectionSpans2(
21772
- sdk,
21773
- (object4, product) => sdkObjectImages.get(object4) ?? sdkProductImages.get(product)
21774
- );
21775
- let storage = reserved;
21776
- if (sdkSpans.length > 0) {
21777
- const sdkCounts = guestProjectionRegionCounts(storage.images.length, sdkSpans);
21778
- storage = reserveGuestProjectionStorage(
21779
- storage.images,
21780
- storage.capacities.map((capacity, index) => ({
21781
- ...capacity,
21782
- regions: capacity.regions + sdkCounts[index] + 16
21783
- }))
21784
- );
21785
- const projectionSource = import_node_path39.default.join(work, "projection.c");
21786
- (0, import_node_fs39.writeFileSync)(projectionSource, storage.source);
21787
- (0, import_node_child_process26.execFileSync)(
21788
- import_node_path39.default.join(options.toolchainBin, "clang"),
21789
- [...clangOptions, "-c", projectionSource, "-o", projectionObject],
21790
- { stdio: "pipe" }
21791
- );
21792
- }
21793
- let precomputedSymbols;
21794
- if (splitInputs.appReferencedSymbols && splitInputs.appDefinedSymbols) {
21795
- const referenced = new Set(splitInputs.appReferencedSymbols);
21796
- const defined = new Set(splitInputs.appDefinedSymbols);
21797
- const projSyms = guestWasmSymbols((0, import_node_fs39.readFileSync)(projectionObject));
21798
- for (const name3 of projSyms.undefined) referenced.add(name3);
21799
- for (const name3 of projSyms.defined) defined.add(name3);
21800
- precomputedSymbols = { referenced, defined };
21801
- }
21802
- for (; ; ) {
21803
- const link = await linkSwiftAppModule2({
21804
- objects: [...owners.keys()],
21805
- lazyFunctions: splitInputs.lazyFunctions,
21806
- toolchainBin: options.toolchainBin,
22099
+ try {
22100
+ if (!splitInputs) throw new Error("guest link did not select shared SDK inputs");
22101
+ const {
22102
+ createSwiftSdkBinding: createSwiftSdkBinding2,
22103
+ linkSwiftAppModule: linkSwiftAppModule2,
22104
+ readSwiftSdkUsage: readSwiftSdkUsage2,
22105
+ swiftAppModuleThunkSection: swiftAppModuleThunkSection2,
22106
+ swiftSdkProjectionSpans: swiftSdkProjectionSpans2
22107
+ } = await Promise.resolve().then(() => (init_swift_sdk_app_module(), swift_sdk_app_module_exports));
22108
+ const project = options.project;
22109
+ const work = project ? (0, import_node_fs39.mkdtempSync)(import_node_path39.default.join(directory, "app-module-")) : import_node_path39.default.join(directory, "app-module");
22110
+ if (project) (0, import_node_fs39.chownSync)(work, project.uid, project.gid);
22111
+ else (0, import_node_fs39.mkdirSync)(work, { recursive: true });
22112
+ const layoutMap = import_node_path39.default.join(work, "app.map");
22113
+ let appProjectionObject = projectionObject;
22114
+ const owners = new Map(splitInputs.appObjects).set(appProjectionObject, 0);
22115
+ const sdkObjectKeys = /* @__PURE__ */ new Map();
22116
+ const sdkObjectImages = /* @__PURE__ */ new Map();
22117
+ const sdkProductImages = new Map(prepared?.sdkProducts.images);
22118
+ for (const [file, { image, product, identity }] of splitInputs.sdkObjects) {
22119
+ const key = sdkGuestObjectKey(identity);
22120
+ sdkObjectKeys.set(file, key);
22121
+ sdkObjectImages.set(key, image);
22122
+ const priorImage = sdkProductImages.get(product);
22123
+ if (priorImage !== void 0 && priorImage !== image)
22124
+ throw new Error(`SDK product ${product} has several guest images`);
22125
+ sdkProductImages.set(product, image);
22126
+ }
22127
+ const linkedModule = import_node_path39.default.join(work, "app.wasm");
22128
+ const sdkSpans = swiftSdkProjectionSpans2(
21807
22129
  sdk,
21808
- work,
21809
- output: options.optimized,
21810
- optimize: options.optimize,
21811
- layoutMap,
21812
- project,
21813
- precomputedSymbols,
21814
- loweringCache: project ? void 0 : {
21815
- file: import_node_path39.default.join(
21816
- options.buildDirectory,
21817
- ".build",
21818
- "peach-app-module-lowered.wasm"
21819
- ),
21820
- compilerDigest: options.compilerDigest
21821
- }
21822
- });
21823
- const map2 = (0, import_node_fs39.readFileSync)(
21824
- project ? projectOutputFile(work, layoutMap, project) : layoutMap,
21825
- "utf8"
22130
+ (object4, product) => sdkObjectImages.get(object4) ?? sdkProductImages.get(product)
21826
22131
  );
21827
- const values = guestDyldValueRange(map2);
21828
- const bindingRows = /* @__PURE__ */ new Map();
21829
- const data = [];
21830
- for (let at = 0; at < link.linkage.data.length; at += 3) {
21831
- const address = link.linkage.data[at];
21832
- const size = link.linkage.data[at + 1];
21833
- const value = link.linkage.data[at + 2];
21834
- if (values && address >= values.address && address < values.address + values.length) {
21835
- if (size !== 8 || (address - values.address) % 8)
21836
- throw new Error("sdk binding splits a dyld value");
21837
- bindingRows.set((address - values.address) / 8, value);
21838
- } else data.push(address, size, value);
21839
- }
21840
- const linked = (0, import_node_fs39.readFileSync)(
21841
- project ? projectOutputFile(work, linkedModule, project) : linkedModule
21842
- );
21843
- const required = guestProjectionRegionCounts(storage.images.length, [
21844
- ...guestLinkedSpans(map2, linked, linked, owners, splitInputs.appSections, true),
21845
- ...sdkSpans
21846
- ]);
21847
- if (storage.capacities.some(({ regions }, index) => required[index] > regions)) {
21848
- storage = reserveGuestProjectionStorage(
21849
- storage.images,
21850
- storage.capacities.map((capacity, index) => {
21851
- const count = required[index];
21852
- return count > capacity.regions ? { ...capacity, regions: Math.max(count, capacity.regions * 2) } : capacity;
21853
- })
21854
- );
22132
+ const compileAppProjection = (source) => {
21855
22133
  const projectionSource = import_node_path39.default.join(work, "projection.c");
21856
- (0, import_node_fs39.writeFileSync)(projectionSource, storage.source);
22134
+ const nextObject = import_node_path39.default.join(work, "projection.o");
22135
+ (0, import_node_fs39.writeFileSync)(projectionSource, source);
21857
22136
  (0, import_node_child_process26.execFileSync)(
21858
22137
  import_node_path39.default.join(options.toolchainBin, "clang"),
21859
- [...clangOptions, "-c", projectionSource, "-o", projectionObject],
22138
+ [...clangOptions, "-c", projectionSource, "-o", nextObject],
21860
22139
  { stdio: "pipe" }
21861
22140
  );
21862
- continue;
22141
+ if (nextObject !== appProjectionObject) {
22142
+ owners.delete(appProjectionObject);
22143
+ appProjectionObject = nextObject;
22144
+ owners.set(appProjectionObject, 0);
22145
+ }
22146
+ };
22147
+ let storage = reserved;
22148
+ if (sdkSpans.length > 0) {
22149
+ const sdkCounts = guestProjectionRegionCounts(storage.images.length, sdkSpans);
22150
+ storage = reserveGuestProjectionStorage(
22151
+ storage.images,
22152
+ storage.capacities.map((capacity, index) => ({
22153
+ ...capacity,
22154
+ regions: capacity.regions + sdkCounts[index] + 16
22155
+ }))
22156
+ );
22157
+ compileAppProjection(storage.source);
21863
22158
  }
21864
- options.onStage("lowering the app image");
21865
- const lowerPromise = link.lower();
21866
- await new Promise((resolve) => setImmediate(resolve));
21867
- let binding;
21868
- try {
21869
- binding = createSwiftSdkBinding2({ ...link.linkage, data }, sdk, usage);
21870
- } catch (error) {
21871
- await lowerPromise.catch(() => {
22159
+ let precomputedSymbols;
22160
+ if (splitInputs.appReferencedSymbols && splitInputs.appDefinedSymbols) {
22161
+ const referenced = new Set(splitInputs.appReferencedSymbols);
22162
+ const defined = new Set(splitInputs.appDefinedSymbols);
22163
+ const projSyms = guestWasmSymbols((0, import_node_fs39.readFileSync)(appProjectionObject));
22164
+ for (const name3 of projSyms.undefined) referenced.add(name3);
22165
+ for (const name3 of projSyms.defined) defined.add(name3);
22166
+ precomputedSymbols = { referenced, defined };
22167
+ }
22168
+ for (; ; ) {
22169
+ const link = await linkSwiftAppModule2({
22170
+ objects: [...owners.keys()],
22171
+ lazyFunctions: splitInputs.lazyFunctions,
22172
+ toolchainBin: options.toolchainBin,
22173
+ sdk,
22174
+ work,
22175
+ output: options.optimized,
22176
+ optimize: options.optimize,
22177
+ layoutMap,
22178
+ project,
22179
+ precomputedSymbols,
22180
+ loweringCache: project ? void 0 : {
22181
+ file: import_node_path39.default.join(
22182
+ options.buildDirectory,
22183
+ ".build",
22184
+ "peach-app-module-lowered.wasm"
22185
+ ),
22186
+ compilerDigest: options.compilerDigest
22187
+ }
21872
22188
  });
21873
- throw error;
22189
+ const map2 = (0, import_node_fs39.readFileSync)(
22190
+ project ? projectOutputFile(work, layoutMap, project) : layoutMap,
22191
+ "utf8"
22192
+ );
22193
+ const values = guestDyldValueRange(map2);
22194
+ const bindingRows = /* @__PURE__ */ new Map();
22195
+ const data = [];
22196
+ for (let at = 0; at < link.linkage.data.length; at += 3) {
22197
+ const address = link.linkage.data[at];
22198
+ const size = link.linkage.data[at + 1];
22199
+ const value = link.linkage.data[at + 2];
22200
+ if (values && address >= values.address && address < values.address + values.length) {
22201
+ if (size !== 8 || (address - values.address) % 8)
22202
+ throw new Error("sdk binding splits a dyld value");
22203
+ bindingRows.set((address - values.address) / 8, value);
22204
+ } else data.push(address, size, value);
22205
+ }
22206
+ const linked = (0, import_node_fs39.readFileSync)(
22207
+ project ? projectOutputFile(work, linkedModule, project) : linkedModule
22208
+ );
22209
+ const required = guestProjectionRegionCounts(storage.images.length, [
22210
+ ...guestLinkedSpans(map2, linked, linked, owners, splitInputs.appSections, true),
22211
+ ...sdkSpans
22212
+ ]);
22213
+ if (storage.capacities.some(({ regions }, index) => required[index] > regions)) {
22214
+ storage = reserveGuestProjectionStorage(
22215
+ storage.images,
22216
+ storage.capacities.map((capacity, index) => {
22217
+ const count = required[index];
22218
+ return count > capacity.regions ? { ...capacity, regions: Math.max(count, capacity.regions * 2) } : capacity;
22219
+ })
22220
+ );
22221
+ compileAppProjection(storage.source);
22222
+ continue;
22223
+ }
22224
+ options.onStage("lowering the app image");
22225
+ const lowerPromise = link.lower();
22226
+ await new Promise((resolve) => setImmediate(resolve));
22227
+ let binding;
22228
+ try {
22229
+ if (result.finalLinkDone) await result.finalLinkDone;
22230
+ const usage = readSwiftSdkUsage2(result.mapPath, options.output, sdkObjectKeys);
22231
+ binding = createSwiftSdkBinding2({ ...link.linkage, data }, sdk, usage);
22232
+ } catch (error) {
22233
+ await Promise.allSettled([lowerPromise]);
22234
+ throw error;
22235
+ }
22236
+ await lowerPromise;
22237
+ const finalized = finalizeGuestProjectionStorage({
22238
+ map: map2,
22239
+ linked,
22240
+ optimized: (0, import_node_fs39.readFileSync)(options.optimized),
22241
+ owners,
22242
+ sectionOwners: splitInputs.appSections,
22243
+ projectionObject: appProjectionObject,
22244
+ reserved: storage,
22245
+ sdkSpans
22246
+ });
22247
+ (0, import_node_fs39.writeFileSync)(
22248
+ options.optimized,
22249
+ moveGuestDyldTable(map2, finalized.wasm, splitInputs.dyldSymbols, bindingRows, [
22250
+ swiftAppModuleThunkSection2(finalized.wasm)
22251
+ ])
22252
+ );
22253
+ return binding;
21874
22254
  }
21875
- await lowerPromise;
21876
- const finalized = finalizeGuestProjectionStorage({
21877
- map: map2,
21878
- linked,
21879
- optimized: (0, import_node_fs39.readFileSync)(options.optimized),
21880
- owners,
21881
- sectionOwners: splitInputs.appSections,
21882
- projectionObject,
21883
- reserved: storage,
21884
- sdkSpans
21885
- });
21886
- (0, import_node_fs39.writeFileSync)(
21887
- options.optimized,
21888
- finishSwiftAppModule2(
21889
- moveGuestDyldTable(map2, finalized.wasm, splitInputs.dyldSymbols, bindingRows)
21890
- )
21891
- );
21892
- return binding;
22255
+ } finally {
22256
+ if (result.finalLinkDone) await Promise.allSettled([result.finalLinkDone]);
21893
22257
  }
21894
22258
  }
21895
22259
  options.onStage("lowering the app image");
@@ -21964,7 +22328,7 @@ function compilerCheckpoint(root, recipe, args, header) {
21964
22328
  }
21965
22329
  if (!objects.length) return;
21966
22330
  const outputs = [module2, header, map[""].dependencies, ...objects];
21967
- const digest = (0, import_node_crypto27.createHash)("sha256").update(recipe).update(JSON.stringify(args)).update(mapText);
22331
+ const digest = (0, import_node_crypto28.createHash)("sha256").update(recipe).update(JSON.stringify(args)).update(mapText);
21968
22332
  for (const flag of args) {
21969
22333
  if (!flag.startsWith("@")) continue;
21970
22334
  const response = flag.slice(1);
@@ -22058,11 +22422,11 @@ async function withSwiftHeaderCompiler(root, toolchainBin, recipe, producers, bu
22058
22422
  (0, import_node_fs40.rmSync)(directory, { recursive: true, force: true });
22059
22423
  }
22060
22424
  }
22061
- var import_node_crypto27, import_node_fs40, import_node_http, import_node_path40, SWIFT_HEADER_COMPILER_WRAPPER, argument, client;
22425
+ var import_node_crypto28, import_node_fs40, import_node_http, import_node_path40, SWIFT_HEADER_COMPILER_WRAPPER, argument, client;
22062
22426
  var init_swift_header_compiler = __esm({
22063
22427
  "src/swift-header-compiler.ts"() {
22064
22428
  "use strict";
22065
- import_node_crypto27 = require("node:crypto");
22429
+ import_node_crypto28 = require("node:crypto");
22066
22430
  import_node_fs40 = require("node:fs");
22067
22431
  import_node_http = require("node:http");
22068
22432
  import_node_path40 = __toESM(require("node:path"), 1);
@@ -22326,7 +22690,7 @@ var init_icuData = __esm({
22326
22690
 
22327
22691
  // src/swift-icu.ts
22328
22692
  async function cachedBrotli(bytes, quality, cacheKey) {
22329
- const key = cacheKey && /^[a-f0-9]{64}$/.test(cacheKey) ? cacheKey : (0, import_node_crypto28.createHash)("sha256").update(bytes).digest("hex");
22693
+ const key = cacheKey && /^[a-f0-9]{64}$/.test(cacheKey) ? cacheKey : (0, import_node_crypto29.createHash)("sha256").update(bytes).digest("hex");
22330
22694
  const cacheId = `${quality}:${key}`;
22331
22695
  const cached2 = brotliMemoryCache.get(cacheId);
22332
22696
  if (cached2) return cached2;
@@ -22344,7 +22708,7 @@ async function cachedBrotli(bytes, quality, cacheKey) {
22344
22708
  });
22345
22709
  try {
22346
22710
  await (0, import_promises6.mkdir)(dir, { recursive: true });
22347
- const tmp = `${file}.${(0, import_node_crypto28.randomUUID)()}.tmp`;
22711
+ const tmp = `${file}.${(0, import_node_crypto29.randomUUID)()}.tmp`;
22348
22712
  await (0, import_promises6.writeFile)(tmp, compressed);
22349
22713
  await (0, import_promises6.rename)(tmp, file);
22350
22714
  } catch {
@@ -22382,7 +22746,7 @@ function swiftIcuAsset(toolchainBin, sdk) {
22382
22746
  JSON.stringify([toolchainBin, sdk, swiftSdkOptions()]),
22383
22747
  async () => {
22384
22748
  const zipped = await deflate(await swiftIcuData(toolchainBin, sdk));
22385
- return { sha256: (0, import_node_crypto28.createHash)("sha256").update(zipped).digest("hex"), gzip: zipped };
22749
+ return { sha256: (0, import_node_crypto29.createHash)("sha256").update(zipped).digest("hex"), gzip: zipped };
22386
22750
  }
22387
22751
  );
22388
22752
  }
@@ -22484,7 +22848,7 @@ function swiftIcuPacked(icu) {
22484
22848
  )
22485
22849
  );
22486
22850
  await (0, import_promises6.mkdir)(import_node_path42.default.dirname(file), { recursive: true });
22487
- const tmp = `${file}.${(0, import_node_crypto28.randomUUID)()}.tmp`;
22851
+ const tmp = `${file}.${(0, import_node_crypto29.randomUUID)()}.tmp`;
22488
22852
  await (0, import_promises6.writeFile)(tmp, packed);
22489
22853
  await (0, import_promises6.rename)(tmp, file);
22490
22854
  return packed;
@@ -22497,12 +22861,12 @@ async function swiftIcuBundleAsset(icu) {
22497
22861
  contentType: "application/octet-stream"
22498
22862
  };
22499
22863
  }
22500
- var import_node_child_process27, import_node_crypto28, import_node_fs41, import_promises6, import_node_os11, import_node_path42, import_node_util9, import_node_zlib5, run4, deflate, compressBrotli, inflateGzip, ARCHIVE, MEMBER, raw, assets, brotliMemoryCache, packedFiles;
22864
+ var import_node_child_process27, import_node_crypto29, import_node_fs41, import_promises6, import_node_os11, import_node_path42, import_node_util9, import_node_zlib5, run4, deflate, compressBrotli, inflateGzip, ARCHIVE, MEMBER, raw, assets, brotliMemoryCache, packedFiles;
22501
22865
  var init_swift_icu = __esm({
22502
22866
  "src/swift-icu.ts"() {
22503
22867
  "use strict";
22504
22868
  import_node_child_process27 = require("node:child_process");
22505
- import_node_crypto28 = require("node:crypto");
22869
+ import_node_crypto29 = require("node:crypto");
22506
22870
  import_node_fs41 = require("node:fs");
22507
22871
  import_promises6 = require("node:fs/promises");
22508
22872
  import_node_os11 = __toESM(require("node:os"), 1);
@@ -22773,7 +23137,7 @@ function swiftObjCPrebuiltCompiler(clang, root, sysroot, distribution, targets,
22773
23137
  );
22774
23138
  if (!modules.length) return [];
22775
23139
  const { executable, prefixArgs } = rnxSelfInvocation();
22776
- const compiler = (0, import_node_crypto29.createHash)("sha256").update(import_node_fs43.default.readFileSync(clang)).digest("hex");
23140
+ const compiler = (0, import_node_crypto30.createHash)("sha256").update(import_node_fs43.default.readFileSync(clang)).digest("hex");
22777
23141
  return [
22778
23142
  'case "$module" in',
22779
23143
  ` ${modules.join("|")}) exec ${[
@@ -22791,12 +23155,12 @@ function swiftObjCPrebuiltCompiler(clang, root, sysroot, distribution, targets,
22791
23155
  "esac"
22792
23156
  ];
22793
23157
  }
22794
- var import_node_child_process29, import_node_crypto29, import_node_fs43, import_node_path44, quote;
23158
+ var import_node_child_process29, import_node_crypto30, import_node_fs43, import_node_path44, quote;
22795
23159
  var init_swift_objc_prebuilt = __esm({
22796
23160
  "src/swift-objc-prebuilt.ts"() {
22797
23161
  "use strict";
22798
23162
  import_node_child_process29 = require("node:child_process");
22799
- import_node_crypto29 = require("node:crypto");
23163
+ import_node_crypto30 = require("node:crypto");
22800
23164
  import_node_fs43 = __toESM(require("node:fs"), 1);
22801
23165
  import_node_path44 = __toESM(require("node:path"), 1);
22802
23166
  init_internal_child_contract();
@@ -23149,7 +23513,7 @@ function swiftPackagePrebuiltEntries(input, moduleRoot, toolchainBin) {
23149
23513
  ([file, source]) => !/\.(?:swift|c|h|inc|modulemap)$/.test(file) || file.endsWith(".swift") && swiftImportNames(source, available).some((name4) => !available.has(name4))
23150
23514
  ))
23151
23515
  return [];
23152
- const hash = (0, import_node_crypto30.createHash)("sha256");
23516
+ const hash = (0, import_node_crypto31.createHash)("sha256");
23153
23517
  for (const entry of files.sort(
23154
23518
  ([left], [right]) => left < right ? -1 : left > right ? 1 : 0
23155
23519
  ))
@@ -23216,11 +23580,11 @@ function useSwiftPackagePrebuilts(input, moduleRoot, toolchainBin) {
23216
23580
  }
23217
23581
  return resolved;
23218
23582
  }
23219
- var import_node_crypto30, import_node_fs46, import_node_path48, PACKAGE_RECIPE;
23583
+ var import_node_crypto31, import_node_fs46, import_node_path48, PACKAGE_RECIPE;
23220
23584
  var init_swift_package_prebuilt = __esm({
23221
23585
  "src/swift-package-prebuilt.ts"() {
23222
23586
  "use strict";
23223
- import_node_crypto30 = require("node:crypto");
23587
+ import_node_crypto31 = require("node:crypto");
23224
23588
  import_node_fs46 = __toESM(require("node:fs"), 1);
23225
23589
  import_node_path48 = __toESM(require("node:path"), 1);
23226
23590
  init_native_prebuilt();
@@ -23447,7 +23811,7 @@ function swiftObjCSelectorOptions(moduleRoot) {
23447
23811
  `;
23448
23812
  if (!(0, import_node_fs47.existsSync)(map) || (0, import_node_fs47.readFileSync)(map, "utf8") !== content) {
23449
23813
  (0, import_node_fs47.mkdirSync)(import_node_path49.default.dirname(map), { recursive: true });
23450
- const partial = `${map}.${(0, import_node_crypto31.randomUUID)()}`;
23814
+ const partial = `${map}.${(0, import_node_crypto32.randomUUID)()}`;
23451
23815
  (0, import_node_fs47.writeFileSync)(partial, content);
23452
23816
  (0, import_node_fs47.renameSync)(partial, map);
23453
23817
  }
@@ -23475,7 +23839,7 @@ async function ensureMacroPlugins(moduleRoot, toolchainBin, release, signal, lea
23475
23839
  return { libraries, executables };
23476
23840
  }
23477
23841
  function swiftProjectBuildKey(moduleRoot, release) {
23478
- return (0, import_node_crypto31.createHash)("sha256").update(`swift-framework/v2\0${release}\0${swiftModuleSdk(moduleRoot).wasmSdkId}`).update(swiftModuleDigest(moduleRoot)).digest("hex").slice(0, 32);
23842
+ return (0, import_node_crypto32.createHash)("sha256").update(`swift-framework/v2\0${release}\0${swiftModuleSdk(moduleRoot).wasmSdkId}`).update(swiftModuleDigest(moduleRoot)).digest("hex").slice(0, 32);
23479
23843
  }
23480
23844
  function sameStringList(left, right) {
23481
23845
  if (left === right) return true;
@@ -23723,7 +24087,7 @@ function distributionClangModuleOptions(root, modules) {
23723
24087
  function providedModulesPath(root, modules, excluded) {
23724
24088
  if (!excluded || excluded.size === 0) return modules;
23725
24089
  const entries2 = (0, import_node_fs47.readdirSync)(modules).filter((entry) => !excluded.has(entry.replace(/\..*$/, ""))).sort();
23726
- const key = (0, import_node_crypto31.createHash)("sha256").update(JSON.stringify([modules, entries2])).update([...excluded].sort().join("\0")).digest("hex").slice(0, 16);
24090
+ const key = (0, import_node_crypto32.createHash)("sha256").update(JSON.stringify([modules, entries2])).update([...excluded].sort().join("\0")).digest("hex").slice(0, 16);
23727
24091
  const directory = import_node_path49.default.join(root, `.peach-modules-${key}`);
23728
24092
  const complete = import_node_path49.default.join(directory, ".complete");
23729
24093
  if (!(0, import_node_fs47.existsSync)(complete)) {
@@ -23808,10 +24172,10 @@ function swiftArtifactHash(input, release, moduleRoot) {
23808
24172
  function sha256Digest(value) {
23809
24173
  if (typeof Bun !== "undefined")
23810
24174
  return new Bun.CryptoHasher("sha256").update(value).digest();
23811
- return (0, import_node_crypto31.createHash)("sha256").update(value).digest();
24175
+ return (0, import_node_crypto32.createHash)("sha256").update(value).digest();
23812
24176
  }
23813
24177
  function swiftCompileInputHash(input, release) {
23814
- const hash = (0, import_node_crypto31.createHash)("sha256");
24178
+ const hash = (0, import_node_crypto32.createHash)("sha256");
23815
24179
  hash.update(`swift-compile
23816
24180
  ${release}
23817
24181
  `);
@@ -24018,7 +24382,7 @@ function emitSwiftPackageManifest(args) {
24018
24382
  ].join("\n") + "\n";
24019
24383
  distributionLinkPath = distributionLink.path.replace(
24020
24384
  /\.rsp$/,
24021
- `-${(0, import_node_crypto31.createHash)("sha256").update(list).digest("hex").slice(0, 12)}.rsp`
24385
+ `-${(0, import_node_crypto32.createHash)("sha256").update(list).digest("hex").slice(0, 12)}.rsp`
24022
24386
  );
24023
24387
  distributionLink.files.set(distributionLinkPath, list);
24024
24388
  }
@@ -24039,7 +24403,7 @@ function emitSwiftPackageManifest(args) {
24039
24403
  const endRun = () => {
24040
24404
  if (run5.length >= MODULE_MAP_RESPONSE_FILE_RUN) {
24041
24405
  const lines = run5.map((flag) => JSON.stringify(flag)).join("\n") + "\n";
24042
- const digest2 = (0, import_node_crypto31.createHash)("sha256").update(lines).digest("hex");
24406
+ const digest2 = (0, import_node_crypto32.createHash)("sha256").update(lines).digest("hex");
24043
24407
  const file2 = import_node_path49.default.join(args.root, ".peach-clang-arguments", `${digest2}.rsp`);
24044
24408
  args.files.set(file2, lines);
24045
24409
  flags.push(`@${file2}`);
@@ -24063,7 +24427,7 @@ function emitSwiftPackageManifest(args) {
24063
24427
  }
24064
24428
  endRun();
24065
24429
  const content = JSON.stringify(flags);
24066
- const digest = (0, import_node_crypto31.createHash)("sha256").update(content).digest("hex");
24430
+ const digest = (0, import_node_crypto32.createHash)("sha256").update(content).digest("hex");
24067
24431
  const file = import_node_path49.default.join(args.root, ".peach-manifest-arguments", `${digest}.json`);
24068
24432
  args.files.set(file, content);
24069
24433
  return `peachCompilerArguments(${JSON.stringify(file)})`;
@@ -24075,7 +24439,7 @@ function emitSwiftPackageManifest(args) {
24075
24439
  const macros = compactSwiftClangDefines(swiftClangSearchArguments(flags));
24076
24440
  const compact = args.coalescibleOverlays ? compactSwiftClangOverlays(macros, args.coalescibleOverlays) : macros;
24077
24441
  const content = compact.map((flag) => JSON.stringify(flag)).join("\n") + "\n";
24078
- const digest = (0, import_node_crypto31.createHash)("sha256").update(content).digest("hex");
24442
+ const digest = (0, import_node_crypto32.createHash)("sha256").update(content).digest("hex");
24079
24443
  const file = import_node_path49.default.join(args.root, ".peach-swift-arguments", `${digest}.rsp`);
24080
24444
  args.files.set(file, content);
24081
24445
  return JSON.stringify([`@${file}`]);
@@ -25723,7 +26087,7 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
25723
26087
  )
25724
26088
  ];
25725
26089
  const moduleFlag = perFile.some((flag) => flag.startsWith("-fmodule-name=")) ? [] : [`-fmodule-name=${swiftTargetModuleName(target.name)}`];
25726
- const identity = (0, import_node_crypto31.createHash)("sha256").update(
26090
+ const identity = (0, import_node_crypto32.createHash)("sha256").update(
25727
26091
  JSON.stringify([
25728
26092
  cxx,
25729
26093
  quoteDirs,
@@ -26086,7 +26450,7 @@ module ${moduleName}.Swift {
26086
26450
  ])
26087
26451
  (0, import_node_fs47.rmSync)(cache, { recursive: true, force: true });
26088
26452
  files.set(frameworkSearchRecord, frameworkSearch);
26089
- const modulePlan = (0, import_node_crypto31.createHash)("sha256").update(
26453
+ const modulePlan = (0, import_node_crypto32.createHash)("sha256").update(
26090
26454
  swiftModuleInputFiles(moduleRoot).join("\n")
26091
26455
  );
26092
26456
  if (!distribution) {
@@ -26095,7 +26459,7 @@ module ${moduleName}.Swift {
26095
26459
  modulePlan.update(
26096
26460
  Object.keys(input.files).filter((file) => file.endsWith(".swift")).sort().join("\n")
26097
26461
  );
26098
- const resourcePlan = (0, import_node_crypto31.createHash)("sha256").update(
26462
+ const resourcePlan = (0, import_node_crypto32.createHash)("sha256").update(
26099
26463
  JSON.stringify(
26100
26464
  resourceTargets.filter((target) => target.resources).map((target) => [
26101
26465
  target.name,
@@ -26403,7 +26767,7 @@ ${entry}`);
26403
26767
  );
26404
26768
  for (const [target, data] of Object.entries(input.libraries ?? {})) {
26405
26769
  const bytes = Buffer.from(data, "base64");
26406
- const digest = (0, import_node_crypto31.createHash)("sha256").update(bytes).digest("hex");
26770
+ const digest = (0, import_node_crypto32.createHash)("sha256").update(bytes).digest("hex");
26407
26771
  if (input.binaryModules?.[target] && packageTargets.has(target)) {
26408
26772
  const objects = import_node_path49.default.join(
26409
26773
  layout2.root,
@@ -27055,7 +27419,7 @@ function readCompiledArtifact(directory, hash) {
27055
27419
  return null;
27056
27420
  const bytes = (0, import_node_fs47.readFileSync)(import_node_path49.default.join(directory, "app.wasm"));
27057
27421
  const gzip2 = (0, import_node_fs47.readFileSync)(import_node_path49.default.join(directory, "icu.gz"));
27058
- if ((0, import_node_crypto31.createHash)("sha256").update(bytes).digest("hex") !== receipt.wasm || (0, import_node_crypto31.createHash)("sha256").update(gzip2).digest("hex") !== receipt.icu || bytes.length <= 8 || bytes.readUInt32LE(0) !== 1836278016 || bytes.readUInt32LE(4) !== 1)
27422
+ if ((0, import_node_crypto32.createHash)("sha256").update(bytes).digest("hex") !== receipt.wasm || (0, import_node_crypto32.createHash)("sha256").update(gzip2).digest("hex") !== receipt.icu || bytes.length <= 8 || bytes.readUInt32LE(0) !== 1836278016 || bytes.readUInt32LE(4) !== 1)
27059
27423
  return null;
27060
27424
  let sdk;
27061
27425
  if ("sdk" in receipt) {
@@ -27063,7 +27427,7 @@ function readCompiledArtifact(directory, hash) {
27063
27427
  if (!isRecord(image) || typeof image.key !== "string" || typeof image.sha256 !== "string" || typeof image.binding !== "string")
27064
27428
  return null;
27065
27429
  const binding = (0, import_node_fs47.readFileSync)(import_node_path49.default.join(directory, "sdk-binding.bin"));
27066
- if ((0, import_node_crypto31.createHash)("sha256").update(binding).digest("hex") !== image.binding)
27430
+ if ((0, import_node_crypto32.createHash)("sha256").update(binding).digest("hex") !== image.binding)
27067
27431
  return null;
27068
27432
  sdk = {
27069
27433
  key: image.key,
@@ -27091,7 +27455,7 @@ function saveCompiledArtifact(root, artifact) {
27091
27455
  import_node_path49.default.join(pending, "artifact.json"),
27092
27456
  JSON.stringify({
27093
27457
  hash: artifact.hash,
27094
- wasm: (0, import_node_crypto31.createHash)("sha256").update(artifact.bytes).digest("hex"),
27458
+ wasm: (0, import_node_crypto32.createHash)("sha256").update(artifact.bytes).digest("hex"),
27095
27459
  icu: artifact.icu.sha256,
27096
27460
  sdk: artifact.sdk && {
27097
27461
  key: artifact.sdk.key,
@@ -27440,7 +27804,7 @@ async function buildFrameworkProducts(scratch2, args) {
27440
27804
  const unoptimized = args.input.unoptimized === true;
27441
27805
  const sdkOptions = swiftCompileSdkOptions(args.moduleRoot, args.toolchainBin);
27442
27806
  const selectorOptions = swiftObjCSelectorOptions(args.moduleRoot);
27443
- const receiptKey = (0, import_node_crypto31.createHash)("sha256").update(
27807
+ const receiptKey = (0, import_node_crypto32.createHash)("sha256").update(
27444
27808
  JSON.stringify([
27445
27809
  "framework-products/v2",
27446
27810
  args.frameworkKey,
@@ -27504,6 +27868,10 @@ async function buildFrameworkProducts(scratch2, args) {
27504
27868
  // every framework target when callers alternate --cores.
27505
27869
  "-Xswiftc",
27506
27870
  "-gnone",
27871
+ "-Xcc",
27872
+ "-g0",
27873
+ "-Xcxx",
27874
+ "-g0",
27507
27875
  "-Xswiftc",
27508
27876
  "-num-threads",
27509
27877
  "-Xswiftc",
@@ -27603,7 +27971,7 @@ async function buildFrameworkProducts(scratch2, args) {
27603
27971
  const archiveBase = import_node_path49.default.join(scratch2, "products-lib");
27604
27972
  (0, import_node_fs47.mkdirSync)(archiveBase, { recursive: true });
27605
27973
  const archiveRoot = import_node_path49.default.join(archiveBase, receiptKey);
27606
- const stagedArchiveRoot = `${archiveRoot}.tmp-${process.pid}-${(0, import_node_crypto31.randomUUID)()}`;
27974
+ const stagedArchiveRoot = `${archiveRoot}.tmp-${process.pid}-${(0, import_node_crypto32.randomUUID)()}`;
27607
27975
  const stagedArchive = import_node_path49.default.join(stagedArchiveRoot, "lib");
27608
27976
  (0, import_node_fs47.mkdirSync)(stagedArchive, { recursive: true });
27609
27977
  const archived = /* @__PURE__ */ new Map();
@@ -27646,7 +28014,7 @@ ${args.frameworkKey}`,
27646
28014
  const receiptsDir = import_node_path49.default.join(scratch2, "products-ready");
27647
28015
  (0, import_node_fs47.mkdirSync)(receiptsDir, { recursive: true });
27648
28016
  const receiptFile = import_node_path49.default.join(receiptsDir, `${receiptKey}.json`);
27649
- const partialReceipt = `${receiptFile}.${process.pid}.${(0, import_node_crypto31.randomUUID)()}`;
28017
+ const partialReceipt = `${receiptFile}.${process.pid}.${(0, import_node_crypto32.randomUUID)()}`;
27650
28018
  (0, import_node_fs47.writeFileSync)(
27651
28019
  partialReceipt,
27652
28020
  JSON.stringify({
@@ -27818,7 +28186,7 @@ function mirrorTree2(source, target, skip) {
27818
28186
  if (existing?.isFile() && existing.size === stat.size && (existing.mtimeMs === stat.mtimeMs || (0, import_node_fs47.readFileSync)(from).equals((0, import_node_fs47.readFileSync)(to))))
27819
28187
  continue;
27820
28188
  if (existing) (0, import_node_fs47.rmSync)(to, { recursive: true, force: true });
27821
- const partial = `${to}.${(0, import_node_crypto31.randomUUID)()}`;
28189
+ const partial = `${to}.${(0, import_node_crypto32.randomUUID)()}`;
27822
28190
  (0, import_node_fs47.copyFileSync)(from, partial);
27823
28191
  if (stat.mtimeMs > Date.now()) (0, import_node_fs47.utimesSync)(partial, stat.atime, stat.mtime);
27824
28192
  (0, import_node_fs47.renameSync)(partial, to);
@@ -27878,7 +28246,7 @@ function stageFrameworkSource(moduleRoot, slot, frameworkKey, release) {
27878
28246
  return stagedModule;
27879
28247
  }
27880
28248
  function swiftLinkStamp(args) {
27881
- const hash = (0, import_node_crypto31.createHash)("sha256");
28249
+ const hash = (0, import_node_crypto32.createHash)("sha256");
27882
28250
  hash.update(`swift-link/v1
27883
28251
  ${args.frameworkKey}
27884
28252
  `);
@@ -28006,7 +28374,7 @@ async function compileSwiftProjectOnce(sources, options) {
28006
28374
  const inputHash = swiftCompileInputHash(input, options.release);
28007
28375
  const moduleDigest = swiftModuleDigest(moduleRoot);
28008
28376
  const sourceHash = inputHash.copy().update(moduleDigest).digest("hex");
28009
- const hash = sdkImage ? (0, import_node_crypto31.createHash)("sha256").update(`${sourceHash}
28377
+ const hash = sdkImage ? (0, import_node_crypto32.createHash)("sha256").update(`${sourceHash}
28010
28378
  sdk module ${sdkImage.key}`).digest("hex") : sourceHash;
28011
28379
  const frameworkKey = swiftProjectBuildKey(moduleRoot, options.release);
28012
28380
  const sharedRoot = import_node_path49.default.join(swiftCacheDir(), "swift-projects", hash);
@@ -28103,7 +28471,7 @@ ${cap}` : "";
28103
28471
  }
28104
28472
  const baseRoot = root;
28105
28473
  const canPoolBuildRoot = !options.intermediates && !options.project && !options.linkOnly && import_node_path49.default.basename(import_node_path49.default.dirname(baseRoot)) === "swift-builds";
28106
- const buildShape = canPoolBuildRoot ? (0, import_node_crypto31.createHash)("sha256").update(
28474
+ const buildShape = canPoolBuildRoot ? (0, import_node_crypto32.createHash)("sha256").update(
28107
28475
  JSON.stringify([
28108
28476
  frameworkKey,
28109
28477
  Boolean(sdkImage),
@@ -28394,6 +28762,10 @@ ${cap}` : "";
28394
28762
  // fan-out under high -j.
28395
28763
  "-Xswiftc",
28396
28764
  "-gnone",
28765
+ "-Xcc",
28766
+ "-g0",
28767
+ "-Xcxx",
28768
+ "-g0",
28397
28769
  ...incrementalPreview ? [] : [
28398
28770
  "-Xswiftc",
28399
28771
  "-num-threads",
@@ -28588,17 +28960,17 @@ ${cap}` : "";
28588
28960
  }
28589
28961
  const receipt = import_node_path49.default.join(
28590
28962
  checkpoints,
28591
- (0, import_node_crypto31.createHash)("sha256").update(target).digest("hex")
28963
+ (0, import_node_crypto32.createHash)("sha256").update(target).digest("hex")
28592
28964
  );
28593
28965
  const headers = producers.map(headerPaths);
28594
28966
  for (const header of headers)
28595
28967
  if ((0, import_node_fs47.existsSync)(header.original)) publishHeader(header);
28596
28968
  const fingerprint = () => {
28597
- const digest = (0, import_node_crypto31.createHash)("sha256").update(recipe);
28969
+ const digest = (0, import_node_crypto32.createHash)("sha256").update(recipe);
28598
28970
  for (const { original, emitted } of headers) {
28599
28971
  if (!(0, import_node_fs47.existsSync)(original) || !(0, import_node_fs47.existsSync)(emitted)) return;
28600
28972
  digest.update(
28601
- (0, import_node_crypto31.createHash)("sha256").update((0, import_node_fs47.readFileSync)(emitted)).digest()
28973
+ (0, import_node_crypto32.createHash)("sha256").update((0, import_node_fs47.readFileSync)(emitted)).digest()
28602
28974
  );
28603
28975
  }
28604
28976
  return digest.digest("hex");
@@ -28811,11 +29183,11 @@ ${cap}` : "";
28811
29183
  options.signal
28812
29184
  );
28813
29185
  }
28814
- var import_node_child_process31, import_node_crypto31, import_node_fs47, import_node_os13, import_node_path49, v6, WASM_TRIPLE, SWIFTPM_PROGRESS, SWIFTPM_NOISE, SWIFT_COMPILER_ENV_KEYS, SYSTEM_MODULE_LIBRARIES, SYSTEM_MODULE_IMPORT, lastPartition, OPTIONAL_FRAMEWORK_DEPENDENCIES, OPTIONAL_FRAMEWORKS, availableModules, sdkOverlayFrameworks, DISTRIBUTION_CLANG_MODULES, CLANG_DISTRIBUTION_MODULES, ONE_PRODUCT, GAME_FAMILY, gameProducts, gameProduct, GAME_REACH, ONE_IMPLICIT_FLAGS, executableLinkFlags, darwinRecordsRegion, REACTOR_FLAG, MULTI_MANIFEST_VERSION, SWIFT_HEADER_PRODUCTS_TARGET, compilerSourceDigest, nativeCxxCompilerFlags, MODULE_MAP_RESPONSE_FILE_RUN, cFlagArray, cxxFlagArray, SWIFTPM_DEFAULT_IOS_DEPLOYMENT_TARGET, OS_IOS, ARCH_ARM64, NOT_ON_IOS, DELEGATE_CLASS, ARM64_MACRO, WASM_MACRO, ARCH_WASM32, C_WORDS, archEnvironments, CORE_FOUNDATION_GEOMETRY_TYPES, CORE_FOUNDATION_GRAPHICS_TYPES, CORE_FOUNDATION_HANDLE_IMPORTS, cPredefineTable, cPredefineCache, HIDDEN_UNITS, FIRST_WINS_PAIRS, LAST_WINS_PAIRS, VALUE_FLAGS, LIBXML_REFERENCE, LIBXML_SOURCE, ROOT_LOCKS, host, rootLocks, SHARED_ARTIFACT_BUDGET_BYTES, SHARED_ARTIFACT_GRACE_MS, RETIRED_PREFIX, retainedArtifacts, FRAMEWORK_LINK_TARGET, frameworkProductsReceiptSchema, SWIFT_LINK_STAMP, SWIFT_HOST_COMPILER_WRAPPER, SWIFT_FRAMEWORK_SLOTS, SWIFT_FRAMEWORK_UNOPTIMIZED_SLOTS, SWIFT_FRAMEWORK_SLOT_KEY, SWIFT_FRAMEWORK_SLOT_ORIGIN, SWIFT_FRAMEWORK_SLOT_RELEASE, SWIFT_BUILD_ROOT_SLOTS, SWIFT_BUILD_ROOT_SHAPE;
29186
+ var import_node_child_process31, import_node_crypto32, import_node_fs47, import_node_os13, import_node_path49, v6, WASM_TRIPLE, SWIFTPM_PROGRESS, SWIFTPM_NOISE, SWIFT_COMPILER_ENV_KEYS, SYSTEM_MODULE_LIBRARIES, SYSTEM_MODULE_IMPORT, lastPartition, OPTIONAL_FRAMEWORK_DEPENDENCIES, OPTIONAL_FRAMEWORKS, availableModules, sdkOverlayFrameworks, DISTRIBUTION_CLANG_MODULES, CLANG_DISTRIBUTION_MODULES, ONE_PRODUCT, GAME_FAMILY, gameProducts, gameProduct, GAME_REACH, ONE_IMPLICIT_FLAGS, executableLinkFlags, darwinRecordsRegion, REACTOR_FLAG, MULTI_MANIFEST_VERSION, SWIFT_HEADER_PRODUCTS_TARGET, compilerSourceDigest, nativeCxxCompilerFlags, MODULE_MAP_RESPONSE_FILE_RUN, cFlagArray, cxxFlagArray, SWIFTPM_DEFAULT_IOS_DEPLOYMENT_TARGET, OS_IOS, ARCH_ARM64, NOT_ON_IOS, DELEGATE_CLASS, ARM64_MACRO, WASM_MACRO, ARCH_WASM32, C_WORDS, archEnvironments, CORE_FOUNDATION_GEOMETRY_TYPES, CORE_FOUNDATION_GRAPHICS_TYPES, CORE_FOUNDATION_HANDLE_IMPORTS, cPredefineTable, cPredefineCache, HIDDEN_UNITS, FIRST_WINS_PAIRS, LAST_WINS_PAIRS, VALUE_FLAGS, LIBXML_REFERENCE, LIBXML_SOURCE, ROOT_LOCKS, host, rootLocks, SHARED_ARTIFACT_BUDGET_BYTES, SHARED_ARTIFACT_GRACE_MS, RETIRED_PREFIX, retainedArtifacts, FRAMEWORK_LINK_TARGET, frameworkProductsReceiptSchema, SWIFT_LINK_STAMP, SWIFT_HOST_COMPILER_WRAPPER, SWIFT_FRAMEWORK_SLOTS, SWIFT_FRAMEWORK_UNOPTIMIZED_SLOTS, SWIFT_FRAMEWORK_SLOT_KEY, SWIFT_FRAMEWORK_SLOT_ORIGIN, SWIFT_FRAMEWORK_SLOT_RELEASE, SWIFT_BUILD_ROOT_SLOTS, SWIFT_BUILD_ROOT_SHAPE;
28815
29187
  var init_swift_compile = __esm({
28816
29188
  "src/swift-compile.ts"() {
28817
29189
  import_node_child_process31 = require("node:child_process");
28818
- import_node_crypto31 = require("node:crypto");
29190
+ import_node_crypto32 = require("node:crypto");
28819
29191
  import_node_fs47 = require("node:fs");
28820
29192
  import_node_os13 = __toESM(require("node:os"), 1);
28821
29193
  import_node_path49 = __toESM(require("node:path"), 1);
@@ -29043,7 +29415,7 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
29043
29415
  REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
29044
29416
  MULTI_MANIFEST_VERSION = 76;
29045
29417
  SWIFT_HEADER_PRODUCTS_TARGET = "PeachHeaderProducts";
29046
- compilerSourceDigest = true ? "67e8f8e0e47047534254dae36e13cda1c7694fb49b1d92c2d01a9e386dc59e59" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
29418
+ compilerSourceDigest = true ? "169122685e250113f128b79efc78f9868f581da36ab083c174056ab99b87b629" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
29047
29419
  nativeCxxCompilerFlags = ["-fno-cxx-modules"];
29048
29420
  MODULE_MAP_RESPONSE_FILE_RUN = 16;
29049
29421
  cFlagArray = (flags) => JSON.stringify(withoutGlogModuleMap(flags));