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,10 +1,10 @@
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
  import {
3
3
  acquireSwiftRootReadHold,
4
4
  hasLiveSwiftRootReaders,
5
5
  waitForNoSwiftRootReaders,
6
6
  withSwiftRootLock
7
- } from "./chunk-EI7CZDMR.mjs";
7
+ } from "./chunk-JVEJLPJC.mjs";
8
8
  import {
9
9
  CORE_FOUNDATION_OVERLAY_GLOBALS,
10
10
  NATIVE_GRAPH_SDK_VERSION,
@@ -55,7 +55,7 @@ import {
55
55
  withoutImportedSdkEnumForwards,
56
56
  withoutSwiftDeclarations,
57
57
  writeBuildFile
58
- } from "./chunk-XOAOND7F.mjs";
58
+ } from "./chunk-DVMKYLDN.mjs";
59
59
  import {
60
60
  SWIFT_AUTOLINK_LINKER,
61
61
  SWIFT_CACHE_HOLD_MARKER,
@@ -73,7 +73,7 @@ import {
73
73
  wasmThreadLinkFlags,
74
74
  windowAdmission,
75
75
  writeSwiftAutolinkLinker
76
- } from "./chunk-4GNQG2GT.mjs";
76
+ } from "./chunk-A4R4YGFJ.mjs";
77
77
  import {
78
78
  SWIFT_BINARY_TREES_DIR,
79
79
  SWIFT_NATIVE_INPUT_ROOT,
@@ -88,7 +88,7 @@ import {
88
88
  isSwiftResourcePath,
89
89
  isSwiftSourceLinkGraph,
90
90
  swiftProjectFilesProblems
91
- } from "./chunk-NOM66H2G.mjs";
91
+ } from "./chunk-Q5NI4L3Z.mjs";
92
92
  import {
93
93
  OBJC_RESOURCE_ACCESSOR_BODY,
94
94
  OBJC_RESOURCE_ACCESSOR_HEADER,
@@ -111,19 +111,19 @@ import {
111
111
  swiftPackagePartition,
112
112
  swiftTargetModuleName,
113
113
  withoutGlogModuleMap
114
- } from "./chunk-KPG4FUTY.mjs";
114
+ } from "./chunk-OCCZJOSA.mjs";
115
115
  import {
116
116
  rnxPublicBrand
117
- } from "./chunk-RLWITQ5C.mjs";
117
+ } from "./chunk-7Z7YJ4FU.mjs";
118
118
  import {
119
119
  isRecord
120
- } from "./chunk-UCW7ITXE.mjs";
120
+ } from "./chunk-KA4AQDVF.mjs";
121
121
  import {
122
122
  __publicField
123
- } from "./chunk-CXNXKUNJ.mjs";
123
+ } from "./chunk-P542MMIN.mjs";
124
124
 
125
125
  // src/swift-compile.ts
126
- import { spawn } from "node:child_process";
126
+ import { spawn as spawn2 } from "node:child_process";
127
127
  import { createHash as createHash15, randomUUID as randomUUID4 } from "node:crypto";
128
128
  import {
129
129
  chmodSync as chmodSync3,
@@ -4305,6 +4305,15 @@ function guestLinkedSpans(map, before, after, owners, sectionOwners = /* @__PURE
4305
4305
  const unchanged = before === after;
4306
4306
  const original = layout(before, !unchanged, !importsLayout);
4307
4307
  const optimized = unchanged ? original : layout(after, true, !importsLayout);
4308
+ if (extra?.optimizedDataSegments) {
4309
+ for (const segment of optimized.data) {
4310
+ extra.optimizedDataSegments.push({
4311
+ address: segment.address,
4312
+ offset: segment.bytes.byteOffset - after.byteOffset,
4313
+ length: segment.bytes.length
4314
+ });
4315
+ }
4316
+ }
4308
4317
  const collectSymbols = extra?.collectSymbols;
4309
4318
  const trackedObject = extra?.trackedObject;
4310
4319
  const trackedObjectOwner = extra?.trackedObjectOwner;
@@ -4473,12 +4482,39 @@ function guestLinkedSpans(map, before, after, owners, sectionOwners = /* @__PURE
4473
4482
  }
4474
4483
  return result;
4475
4484
  };
4485
+ const singleSegmentSlice = (module, start, length) => {
4486
+ const segs = module.dataByAddress;
4487
+ let low = 0;
4488
+ let high = segs.length;
4489
+ while (low < high) {
4490
+ const middle = low + high >> 1;
4491
+ if (segs[middle].maximumEnd <= start) low = middle + 1;
4492
+ else high = middle;
4493
+ }
4494
+ let found;
4495
+ const end = start + length;
4496
+ for (let index = low; index < segs.length; index++) {
4497
+ const segment = segs[index];
4498
+ if (segment.address >= end) break;
4499
+ if (segment.address + segment.bytes.length > start) {
4500
+ if (found) return void 0;
4501
+ found = segment;
4502
+ }
4503
+ }
4504
+ if (!found || found.address > start || found.address + found.bytes.length < end)
4505
+ return void 0;
4506
+ return found.bytes.subarray(start - found.address, end - found.address);
4507
+ };
4508
+ const sameDataAt = (start, length) => {
4509
+ const origSlice = singleSegmentSlice(original, start, length);
4510
+ const optSlice = origSlice ? singleSegmentSlice(optimized, start, length) : void 0;
4511
+ if (origSlice && optSlice) return Buffer.compare(origSlice, optSlice) === 0;
4512
+ return dataAt(original, start, length).equals(dataAt(optimized, start, length));
4513
+ };
4476
4514
  for (const span of spans) {
4477
4515
  if (span.address + span.length > original.memoryBytes || span.address + span.length > optimized.memoryBytes)
4478
4516
  throw new Error(`linked data lies outside guest memory at ${span.address}`);
4479
- if (!unchanged && !dataAt(original, span.address, span.length).equals(
4480
- dataAt(optimized, span.address, span.length)
4481
- ))
4517
+ if (!unchanged && !sameDataAt(span.address, span.length))
4482
4518
  throw new Error(`optimization changed linked data at ${span.address}`);
4483
4519
  }
4484
4520
  let previous;
@@ -4612,7 +4648,7 @@ function takeGuestStartupData(wasm, address, length) {
4612
4648
  const bytes = new Uint8Array(length);
4613
4649
  const emptied = /* @__PURE__ */ new Set();
4614
4650
  let covered = 0;
4615
- const result = Buffer.from(wasm);
4651
+ const patchedBody = Buffer.from(wasm.subarray(body[0], body[1]));
4616
4652
  for (const initializer of startupDataInitializers(wasm.subarray(...body))) {
4617
4653
  const end = initializer.address + initializer.length;
4618
4654
  if (end <= address || initializer.address >= address + length || !initializer.length)
@@ -4627,19 +4663,18 @@ function takeGuestStartupData(wasm, address, length) {
4627
4663
  covered += segment.length;
4628
4664
  emptied.add(initializer.segment);
4629
4665
  const [at, immediateEnd] = initializer.lengthImmediate;
4630
- result.fill(128, body[0] + at, body[0] + immediateEnd - 1);
4631
- result[body[0] + immediateEnd - 1] = 0;
4666
+ patchedBody.fill(128, at, immediateEnd - 1);
4667
+ patchedBody[immediateEnd - 1] = 0;
4632
4668
  }
4633
4669
  if (covered !== length)
4634
4670
  throw new Error("guest startup data does not initialize the whole range");
4635
- const parts = [result.subarray(0, data[0])];
4636
- const payload = [result.subarray(data[1], segments[0].header)];
4671
+ const payload = [wasm.subarray(data[1], segments[0].header)];
4637
4672
  for (const [index, segment] of segments.entries()) {
4638
4673
  if (!emptied.has(index)) {
4639
- payload.push(result.subarray(segment.header, segment.payload + segment.length));
4674
+ payload.push(wasm.subarray(segment.header, segment.payload + segment.length));
4640
4675
  continue;
4641
4676
  }
4642
- payload.push(result.subarray(segment.header, segment.sizeAt), Uint8Array.of(0));
4677
+ payload.push(wasm.subarray(segment.header, segment.sizeAt), Uint8Array.of(0));
4643
4678
  }
4644
4679
  const section2 = Buffer.concat(payload);
4645
4680
  const size = [];
@@ -4650,7 +4685,14 @@ function takeGuestStartupData(wasm, address, length) {
4650
4685
  }
4651
4686
  size.push(rest % 128 | 128);
4652
4687
  }
4653
- parts.push(Uint8Array.of(11, ...size), section2, result.subarray(data[2]));
4688
+ const parts = [
4689
+ wasm.subarray(0, body[0]),
4690
+ patchedBody,
4691
+ wasm.subarray(body[1], data[0]),
4692
+ Uint8Array.of(11, ...size),
4693
+ section2,
4694
+ wasm.subarray(data[2])
4695
+ ];
4654
4696
  return { wasm: Buffer.concat(parts), bytes };
4655
4697
  }
4656
4698
 
@@ -4963,6 +5005,32 @@ function readImports(bytes, imports) {
4963
5005
  }
4964
5006
  return { functionTypes, importedGlobals, memoryPages };
4965
5007
  }
5008
+ function countImportedFunctions(bytes, imports) {
5009
+ let count = 0;
5010
+ if (!imports) return count;
5011
+ const r = wasmReader(bytes, imports.start);
5012
+ for (let n = r.u(); n > 0; n--) {
5013
+ r.skip(r.u());
5014
+ r.skip(r.u());
5015
+ const kind = r.byte();
5016
+ if (kind === 0) {
5017
+ r.u();
5018
+ count++;
5019
+ } else if (kind === 1) {
5020
+ r.byte();
5021
+ skipLimits(r);
5022
+ } else if (kind === 2) {
5023
+ skipLimits(r);
5024
+ } else if (kind === 3) {
5025
+ r.byte();
5026
+ r.byte();
5027
+ } else if (kind === 4) {
5028
+ r.byte();
5029
+ r.u();
5030
+ } else throw new Error(`unknown wasm import kind ${kind}`);
5031
+ }
5032
+ return count;
5033
+ }
4966
5034
  function* readFunctionNames(bytes, names) {
4967
5035
  for (const r = wasmReader(bytes, names.start); r.at < names.end; ) {
4968
5036
  const id = r.byte();
@@ -5348,28 +5416,73 @@ function codeOnlySdkImage(bytes, constructorMask) {
5348
5416
  }
5349
5417
  var SWIFT_SDK_CONSTRUCTOR_LIMIT = 16384;
5350
5418
  function constructorKeys(map, bytes) {
5351
- const m = readModule(bytes);
5352
5419
  const first = map.code[0];
5353
- if (!first || !m.bodies.length) throw new Error("link has no code");
5354
- const prefixes = m.bodies.map(({ prefix }) => prefix);
5355
- const delta = prefixes[0] - first.offset;
5356
- const byOffset = new Map(map.code.map((chunk) => [chunk.offset + delta, chunk]));
5420
+ if (!first) throw new Error("link has no code");
5421
+ const sections = wasmSections(bytes);
5422
+ const code = sections.find((s) => s.id === 10);
5423
+ if (!code) throw new Error("link has no code");
5357
5424
  const ctors = map.code.find((chunk) => chunk.section === "__wasm_call_ctors");
5358
5425
  if (!ctors) throw new Error("link has no constructors");
5359
- const index = prefixes.indexOf(ctors.offset + delta);
5360
- if (index < 0) throw new Error("constructor function not found by map offset");
5361
- const body = m.bodies[index];
5362
- const r = wasmReader(bytes, body.start);
5426
+ const importedFuncs = countImportedFunctions(
5427
+ bytes,
5428
+ sections.find((s) => s.id === 2)
5429
+ );
5430
+ const codeReader = wasmReader(bytes, code.start);
5431
+ const bodyCount = codeReader.u();
5432
+ if (!bodyCount) throw new Error("link has no code");
5433
+ const prefixes = new Uint32Array(bodyCount);
5434
+ let delta = 0;
5435
+ let ctorPrefix = -1;
5436
+ let ctorStart = -1;
5437
+ let ctorEnd = -1;
5438
+ for (let i = 0; i < bodyCount; i++) {
5439
+ const prefix = codeReader.at;
5440
+ const size = codeReader.u();
5441
+ prefixes[i] = prefix;
5442
+ if (i === 0) {
5443
+ delta = prefix - first.offset;
5444
+ ctorPrefix = ctors.offset + delta;
5445
+ }
5446
+ if (prefix === ctorPrefix) {
5447
+ ctorStart = codeReader.at;
5448
+ ctorEnd = ctorStart + size;
5449
+ }
5450
+ codeReader.skip(size);
5451
+ }
5452
+ if (ctorStart < 0) throw new Error("constructor function not found by map offset");
5453
+ let sorted = true;
5454
+ for (let i = 1; i < map.code.length; i++) {
5455
+ if (map.code[i].offset < map.code[i - 1].offset) {
5456
+ sorted = false;
5457
+ break;
5458
+ }
5459
+ }
5460
+ const byOffset = sorted ? void 0 : new Map(map.code.map((chunk) => [chunk.offset + delta, chunk]));
5461
+ const findChunk = (targetPrefix) => {
5462
+ if (byOffset) return byOffset.get(targetPrefix);
5463
+ const targetOffset = targetPrefix - delta;
5464
+ let lo = 0;
5465
+ let hi = map.code.length - 1;
5466
+ while (lo <= hi) {
5467
+ const mid = lo + hi >> 1;
5468
+ const offset = map.code[mid].offset;
5469
+ if (offset < targetOffset) lo = mid + 1;
5470
+ else if (offset > targetOffset) hi = mid - 1;
5471
+ else return map.code[mid];
5472
+ }
5473
+ return void 0;
5474
+ };
5475
+ const r = wasmReader(bytes, ctorStart);
5363
5476
  for (let n = r.u(); n > 0; n--) {
5364
5477
  r.u();
5365
5478
  r.byte();
5366
5479
  }
5367
5480
  const keys = [];
5368
- while (r.at < body.end) {
5481
+ while (r.at < ctorEnd) {
5369
5482
  const op = r.byte();
5370
5483
  if (op === 16) {
5371
- const callee = r.u() - m.importedFuncs;
5372
- const chunk = byOffset.get(prefixes[callee]);
5484
+ const callee = r.u() - importedFuncs;
5485
+ const chunk = callee >= 0 && callee < bodyCount ? findChunk(prefixes[callee]) : void 0;
5373
5486
  if (!chunk) throw new Error("constructor without a map chunk");
5374
5487
  keys.push(chunkKey(chunk, ""));
5375
5488
  } else if (op !== 26 && op !== 11) throw new Error(`constructor op ${op}`);
@@ -5477,7 +5590,10 @@ function relocationEdges(bytes, segmentAddress) {
5477
5590
  r.skip(r.u());
5478
5591
  }
5479
5592
  }
5480
- const importedFunctions = readModule(bytes).importedFuncs;
5593
+ const importedFunctions = countImportedFunctions(
5594
+ bytes,
5595
+ sections.find((s) => s.id === 2)
5596
+ );
5481
5597
  const data = [];
5482
5598
  const dataFunctions = [];
5483
5599
  const bodyCount = bodyStarts.length;
@@ -5591,9 +5707,30 @@ function strongDefinitions(bytes) {
5591
5707
  ).map((s) => s.name);
5592
5708
  }
5593
5709
  function unslottedFunctions(bytes) {
5594
- const m = readModule(bytes);
5595
- const slotted = new Set([...m.slots.keys()].filter((index) => index >= m.importedFuncs));
5596
- return m.bodies.length - slotted.size;
5710
+ const sections = wasmSections(bytes);
5711
+ const importedFuncs = countImportedFunctions(
5712
+ bytes,
5713
+ sections.find((s) => s.id === 2)
5714
+ );
5715
+ const code = sections.find((s) => s.id === 10);
5716
+ const definedFuncs = code ? wasmReader(bytes, code.start).u() : 0;
5717
+ const slotted = /* @__PURE__ */ new Set();
5718
+ const elements = sections.find((s) => s.id === 9);
5719
+ if (elements) {
5720
+ const r = wasmReader(bytes, elements.start);
5721
+ for (let n = r.u(); n > 0; n--) {
5722
+ const flags = r.u();
5723
+ if (flags !== 0 && flags !== 2) throw new Error(`sdk image element flags ${flags}`);
5724
+ if (flags === 2) r.u();
5725
+ constant2(r);
5726
+ if (flags === 2) r.byte();
5727
+ for (let i = 0, count = r.u(); i < count; i++) {
5728
+ const index = r.u();
5729
+ if (index >= importedFuncs) slotted.add(index);
5730
+ }
5731
+ }
5732
+ }
5733
+ return definedFuncs - slotted.size;
5597
5734
  }
5598
5735
 
5599
5736
  // src/swift-wasm-archive.ts
@@ -5764,6 +5901,11 @@ var swiftSdkProductsSchema = object({
5764
5901
  });
5765
5902
 
5766
5903
  // src/swift-wasm-prune.ts
5904
+ function sha256Hex(bytes) {
5905
+ if (typeof Bun !== "undefined")
5906
+ return new Bun.CryptoHasher("sha256").update(bytes).digest("hex");
5907
+ return createHash2("sha256").update(bytes).digest("hex");
5908
+ }
5767
5909
  function readULEB(b, o) {
5768
5910
  let res = 0;
5769
5911
  let shift = 0;
@@ -6586,6 +6728,42 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
6586
6728
  }
6587
6729
  }
6588
6730
  }
6731
+ const segObjCClasses = /* @__PURE__ */ new Map();
6732
+ for (let segIdx = 0; segIdx < sEnds.length; segIdx++) {
6733
+ const rangeStart = dataStart + sPayloadStarts[segIdx];
6734
+ const rangeEnd = dataStart + sEnds[segIdx];
6735
+ const sliceLen = rangeEnd - rangeStart;
6736
+ if (sliceLen < 4) continue;
6737
+ const slice = Buffer.from(rawBuf.buffer, rawBuf.byteOffset + rangeStart, sliceLen);
6738
+ let segPos = 0;
6739
+ let classes;
6740
+ while (segPos < sliceLen - 3) {
6741
+ const at = slice.indexOf("So", segPos);
6742
+ if (at < 0 || at >= sliceLen - 2) break;
6743
+ let digitEnd = at + 2;
6744
+ let length = 0;
6745
+ while (digitEnd < sliceLen) {
6746
+ const ch = slice[digitEnd];
6747
+ if (ch < 48 || ch > 57) break;
6748
+ length = length * 10 + (ch - 48);
6749
+ digitEnd++;
6750
+ }
6751
+ if (digitEnd === at + 2) {
6752
+ segPos = at + 2;
6753
+ continue;
6754
+ }
6755
+ segPos = digitEnd;
6756
+ const nameEnd = digitEnd + length;
6757
+ if (nameEnd >= sliceLen || slice[nameEnd] !== 67) continue;
6758
+ const symbol = `._OBJC_CLASS_${slice.toString("latin1", digitEnd, nameEnd)}`;
6759
+ if (!classes) {
6760
+ classes = [symbol];
6761
+ segObjCClasses.set(segIdx, classes);
6762
+ } else if (!classes.includes(symbol)) {
6763
+ classes.push(symbol);
6764
+ }
6765
+ }
6766
+ }
6589
6767
  return {
6590
6768
  file,
6591
6769
  isDist,
@@ -6615,10 +6793,7 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
6615
6793
  objcCategoryTargets,
6616
6794
  rootFuncs,
6617
6795
  rootSegs,
6618
- segPayloadRanges: sEnds.map((end, i) => [
6619
- dataStart + sPayloadStarts[i],
6620
- dataStart + end
6621
- ])
6796
+ segObjCClasses
6622
6797
  };
6623
6798
  }
6624
6799
  function parseWasmObjectFile(file, isDist) {
@@ -7000,16 +7175,26 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
7000
7175
  transformations.set(file, {
7001
7176
  output,
7002
7177
  inputSha256,
7003
- outputSha256: createHash2("sha256").update(result).digest("hex"),
7178
+ outputSha256: sha256Hex(result),
7004
7179
  kind
7005
7180
  });
7006
7181
  };
7007
7182
  const distFiles = [];
7008
7183
  const distBaseNames = /* @__PURE__ */ new Set();
7009
7184
  const eagerFiles = [];
7185
+ const parsedBuildObjects = /* @__PURE__ */ new Map();
7010
7186
  const lazyBuildObjects = /* @__PURE__ */ new Map();
7011
7187
  const extraArchiveObjs = [];
7012
7188
  const objectBytes = /* @__PURE__ */ new Map();
7189
+ const archiveMembers = /* @__PURE__ */ new Map();
7190
+ const readArchiveMembers = (archive) => {
7191
+ let members = archiveMembers.get(archive);
7192
+ if (!members) {
7193
+ members = readArMembers(new Uint8Array(fs2.readFileSync(archive)));
7194
+ archiveMembers.set(archive, members);
7195
+ }
7196
+ return members;
7197
+ };
7013
7198
  let inStartLib = false;
7014
7199
  let swiftrtOrigPath = "";
7015
7200
  for (const t of tokens) {
@@ -7046,8 +7231,10 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
7046
7231
  break;
7047
7232
  }
7048
7233
  }
7049
- if (definesObjCClassOrCategory) eagerFiles.push(t);
7050
- else lazyBuildObjects.set(t, obj);
7234
+ if (definesObjCClassOrCategory) {
7235
+ parsedBuildObjects.set(t, obj);
7236
+ eagerFiles.push(t);
7237
+ } else lazyBuildObjects.set(t, obj);
7051
7238
  } else {
7052
7239
  eagerFiles.push(t);
7053
7240
  }
@@ -7055,7 +7242,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
7055
7242
  lazyBuildObjects.set(t, parseWasmObjectFile(t, false));
7056
7243
  }
7057
7244
  } else if (!inStartLib && t.endsWith(".a") && !t.endsWith("libclang_rt.builtins-wasm64.a") && fs2.existsSync(t)) {
7058
- const members = readArMembers(new Uint8Array(fs2.readFileSync(t)));
7245
+ const members = readArchiveMembers(t);
7059
7246
  for (const m of members) {
7060
7247
  const object2 = parseWasmObjectBytes(`${t}(${m.name})`, m.bytes, false);
7061
7248
  extraArchiveObjs.push(object2);
@@ -7078,7 +7265,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
7078
7265
  );
7079
7266
  const archiveOverlapsDist = (archive) => {
7080
7267
  if (!fs2.existsSync(archive)) return false;
7081
- const members = readArMembers(new Uint8Array(fs2.readFileSync(archive)));
7268
+ const members = readArchiveMembers(archive);
7082
7269
  return members.some((m) => distBaseNames.has(m.name));
7083
7270
  };
7084
7271
  for (const t of tokens) {
@@ -7100,7 +7287,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
7100
7287
  path7.basename(archive)
7101
7288
  );
7102
7289
  const ordinals = /* @__PURE__ */ new Map();
7103
- for (const m of readArMembers(new Uint8Array(fs2.readFileSync(archive)))) {
7290
+ for (const m of readArchiveMembers(archive)) {
7104
7291
  const ordinal = (ordinals.get(m.name) ?? 0) + 1;
7105
7292
  ordinals.set(m.name, ordinal);
7106
7293
  if (distBaseNames.has(m.name) || writtenLeftovers.has(m.name)) continue;
@@ -7134,7 +7321,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
7134
7321
  recordTransformation(
7135
7322
  swiftrtOrigPath,
7136
7323
  patchedSwiftrtPath,
7137
- link ? createHash2("sha256").update(input).digest("hex") : "",
7324
+ link ? sha256Hex(input) : "",
7138
7325
  result,
7139
7326
  "swiftrt"
7140
7327
  );
@@ -7621,7 +7808,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
7621
7808
  }
7622
7809
  for (const f of eagerFiles) {
7623
7810
  const isDist = f.startsWith(distDir);
7624
- const obj = distObjs.get(f) ?? parseWasmObjectFile(f, isDist);
7811
+ const obj = distObjs.get(f) ?? parsedBuildObjects.get(f) ?? parseWasmObjectFile(f, isDist);
7625
7812
  extractObject(obj);
7626
7813
  if (isDist) {
7627
7814
  const base = path7.basename(f);
@@ -7671,32 +7858,9 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
7671
7858
  "$s10Foundation6BundleC22preferredLocalizations4fromSaySSGAF_tFZTf4nd_n"
7672
7859
  ]);
7673
7860
  const keepObjCClassesNamedInSegment = (obj, segIdx) => {
7674
- const range = obj.segPayloadRanges[segIdx];
7675
- if (!range) return;
7676
- const [rangeStart, rangeEnd] = range;
7677
- if (rangeEnd - rangeStart < 4) return;
7678
- let bytes = objectBytes.get(obj);
7679
- if (!bytes) objectBytes.set(obj, bytes = fs2.readFileSync(obj.file));
7680
- let pos = rangeStart;
7681
- while (pos < rangeEnd - 3) {
7682
- const at = bytes.indexOf("So", pos);
7683
- if (at < 0 || at >= rangeEnd - 2) break;
7684
- let digitEnd = at + 2;
7685
- let length = 0;
7686
- while (digitEnd < rangeEnd) {
7687
- const ch = bytes[digitEnd];
7688
- if (ch < 48 || ch > 57) break;
7689
- length = length * 10 + (ch - 48);
7690
- digitEnd++;
7691
- }
7692
- if (digitEnd === at + 2) {
7693
- pos = at + 2;
7694
- continue;
7695
- }
7696
- pos = digitEnd;
7697
- const nameEnd = digitEnd + length;
7698
- if (nameEnd >= rangeEnd || bytes[nameEnd] !== 67) continue;
7699
- const symbol = `._OBJC_CLASS_${bytes.toString("latin1", digitEnd, nameEnd)}`;
7861
+ const symbols = obj.segObjCClasses.get(segIdx);
7862
+ if (!symbols) return;
7863
+ for (const symbol of symbols) {
7700
7864
  for (const provider of lazyProviders.get(symbol) ?? []) {
7701
7865
  eagerDynamicObjects.add(provider);
7702
7866
  extractObject(provider);
@@ -7792,7 +7956,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
7792
7956
  const cached = objectBytes.get(obj);
7793
7957
  const buf = cached ? new Uint8Array(cached) : new Uint8Array(fs2.readFileSync(obj.file));
7794
7958
  const rawBuf = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
7795
- const inputSha256 = link ? createHash2("sha256").update(buf).digest("hex") : "";
7959
+ const inputSha256 = link ? sha256Hex(buf) : "";
7796
7960
  const fLive = liveFuncs.get(obj);
7797
7961
  const sLive = liveSegs.get(obj);
7798
7962
  const dLive = liveDataSyms.get(obj);
@@ -9861,21 +10025,34 @@ var GUEST = "guest";
9861
10025
  var BOUNDARY = "boundary";
9862
10026
  var WIDE = "$wide.";
9863
10027
  var NARROW = "$narrow.";
9864
- function dropWasmCustomSection(bytes, name) {
9865
- const parts = [bytes.subarray(0, 8)];
9866
- for (const { id, offset, start, end } of wasmSections2(bytes)) {
9867
- if (id === 0 && readWasmSection(bytes, start, end).name() === name) continue;
9868
- parts.push(bytes.subarray(offset, end));
10028
+ function writeWasmCustomSections(bytes, entries2) {
10029
+ if (entries2.length === 0) return Buffer.concat([bytes]);
10030
+ const replaced = new Set(entries2.map(([name]) => name));
10031
+ const parts = [];
10032
+ let sliceStart = 0;
10033
+ let sliceEnd = 8;
10034
+ for (const { id, start, end } of wasmSections2(bytes)) {
10035
+ if (id === 0 && replaced.has(readWasmSection(bytes, start, end).name())) {
10036
+ if (sliceEnd > sliceStart) parts.push(bytes.subarray(sliceStart, sliceEnd));
10037
+ sliceStart = end;
10038
+ sliceEnd = end;
10039
+ } else {
10040
+ sliceEnd = end;
10041
+ }
10042
+ }
10043
+ if (sliceEnd > sliceStart) parts.push(bytes.subarray(sliceStart, sliceEnd));
10044
+ for (const [name, data] of entries2) {
10045
+ const nameBytes = Buffer.from(encodeWasmName(name));
10046
+ parts.push(
10047
+ Buffer.from([0, ...encodeWasmNumber(nameBytes.length + data.length)]),
10048
+ nameBytes,
10049
+ data
10050
+ );
9869
10051
  }
9870
10052
  return Buffer.concat(parts);
9871
10053
  }
9872
10054
  function writeWasmCustomSection(bytes, name, data) {
9873
- const section2 = Buffer.concat([Buffer.from(encodeWasmName(name)), data]);
9874
- return Buffer.concat([
9875
- dropWasmCustomSection(bytes, name),
9876
- Buffer.from([0, ...encodeWasmNumber(section2.length)]),
9877
- section2
9878
- ]);
10055
+ return writeWasmCustomSections(bytes, [[name, data]]);
9879
10056
  }
9880
10057
  function readWasmMemory(bytes) {
9881
10058
  return readWasmMemoryAndTableImports(bytes, wasmSections2(bytes)).memory;
@@ -10125,6 +10302,11 @@ function withWasmTableMinimum(bytes, minimum) {
10125
10302
  }
10126
10303
 
10127
10304
  // src/swift-guest-dyld-table.ts
10305
+ function sha256Buffer(bytes) {
10306
+ if (typeof Bun !== "undefined")
10307
+ return Buffer.from(new Bun.CryptoHasher("sha256").update(bytes).digest());
10308
+ return createHash5("sha256").update(bytes).digest();
10309
+ }
10128
10310
  var PACK_BYTES = 64 * 1024;
10129
10311
  function uleb3(value) {
10130
10312
  const bytes = [];
@@ -10160,7 +10342,7 @@ function encodeGuestDyldTable(rows) {
10160
10342
  }
10161
10343
  const file = Buffer.concat(packs);
10162
10344
  const header = Buffer.alloc(40 + packs.length * 8);
10163
- createHash5("sha256").update(file).digest().copy(header, 0);
10345
+ sha256Buffer(file).copy(header, 0);
10164
10346
  header.writeUInt32LE(file.length, 32);
10165
10347
  header.writeUInt32LE(packs.length, 36);
10166
10348
  let offset = 0;
@@ -10172,11 +10354,11 @@ function encodeGuestDyldTable(rows) {
10172
10354
  const names = firsts.flatMap((name) => [name, Buffer.of(0)]);
10173
10355
  return { index: Buffer.concat([header, ...names]), packs: file };
10174
10356
  }
10175
- function moveGuestDyldTable(map, wasm, symbols, bindingValues = /* @__PURE__ */ new Map()) {
10357
+ function moveGuestDyldTable(map, wasm, symbols, bindingValues = /* @__PURE__ */ new Map(), extraSections = []) {
10176
10358
  const range = guestDyldValueRange(map);
10177
10359
  if (!range) {
10178
10360
  if (symbols.length) throw new Error("link map has no dyld values");
10179
- return wasm;
10361
+ return extraSections.length ? writeWasmCustomSections(wasm, extraSections) : wasm;
10180
10362
  }
10181
10363
  if (range.length !== symbols.length * 8)
10182
10364
  throw new Error("linked dyld values do not match the ledger rows");
@@ -10191,11 +10373,11 @@ function moveGuestDyldTable(map, wasm, symbols, bindingValues = /* @__PURE__ */
10191
10373
  return binding === void 0 ? { name, image, kind: 0, value: view.getBigUint64(index2 * 8, true) } : { name, image, kind: 1, value: BigInt(binding) };
10192
10374
  });
10193
10375
  const { index, packs } = encodeGuestDyldTable(rows);
10194
- return writeWasmCustomSection(
10195
- writeWasmCustomSection(taken.wasm, NATIVE_DYLD_TABLE_SECTION, index),
10196
- NATIVE_DYLD_PACKS_SECTION,
10197
- packs
10198
- );
10376
+ return writeWasmCustomSections(taken.wasm, [
10377
+ [NATIVE_DYLD_TABLE_SECTION, index],
10378
+ [NATIVE_DYLD_PACKS_SECTION, packs],
10379
+ ...extraSections
10380
+ ]);
10199
10381
  }
10200
10382
  function guestDyldValueRange(map) {
10201
10383
  const suffix = `:(${GUEST_DYLD_VALUES_SECTION})`;
@@ -10214,7 +10396,7 @@ function guestDyldValueRange(map) {
10214
10396
  }
10215
10397
 
10216
10398
  // src/swift-guest-link.ts
10217
- import { execFile as execFile2, execFileSync as execFileSync5 } from "node:child_process";
10399
+ import { execFile as execFile2, execFileSync as execFileSync5, spawn } from "node:child_process";
10218
10400
  import fs3 from "node:fs";
10219
10401
  import path10 from "node:path";
10220
10402
  import { promisify as promisify2 } from "node:util";
@@ -10705,6 +10887,7 @@ function finalizeGuestProjectionStorage(options) {
10705
10887
  const owner = options.owners.get(options.projectionObject);
10706
10888
  if (owner === void 0) throw new Error("guest projection object has no image owner");
10707
10889
  const ranges = [];
10890
+ const data = [];
10708
10891
  const spans = guestLinkedSpans(
10709
10892
  options.map,
10710
10893
  options.linked,
@@ -10715,7 +10898,8 @@ function finalizeGuestProjectionStorage(options) {
10715
10898
  {
10716
10899
  trackedObject: options.projectionObject,
10717
10900
  trackedObjectOwner: owner,
10718
- trackedLinearSpans: ranges
10901
+ trackedLinearSpans: ranges,
10902
+ optimizedDataSegments: data
10719
10903
  }
10720
10904
  );
10721
10905
  const images = planGuestProjectionRegions(
@@ -10724,7 +10908,6 @@ function finalizeGuestProjectionStorage(options) {
10724
10908
  options.sdkSpans ? [...spans, ...options.sdkSpans] : spans
10725
10909
  );
10726
10910
  const result = Buffer.from(options.optimized);
10727
- const data = guestWasmDataSegments(options.optimized, options.sdkSpans === void 0);
10728
10911
  const locations = /* @__PURE__ */ new Map();
10729
10912
  const counts = /* @__PURE__ */ new Map();
10730
10913
  const uuids = /* @__PURE__ */ new Map();
@@ -11382,17 +11565,17 @@ var binaryen_lock_default = {
11382
11565
  "linux-x64": {
11383
11566
  asset: "x86_64-linux",
11384
11567
  upstreamSha256: "195ddc94f9bc89f45abdabb0b9eea86023d727ba90eac8b35b80f2544fc30572",
11385
- sha256: "1024974f254c1c2edd738246ec6af5add16d3d36b5f58a94545febda3b33c869"
11568
+ sha256: "40062fb1ebbad7f04f361c1e3bb309dffb1d2318dd2e12235a0e7e820e18d6c9"
11386
11569
  },
11387
11570
  "linux-arm64": {
11388
11571
  asset: "aarch64-linux",
11389
11572
  upstreamSha256: "c58562417836c5d0493d89bdefc434933bdc097db641b483df86bcfa557a107f",
11390
- sha256: "7dedfc9f5cb32e75a28831f3b5aa053fd3e0bdd74f73dc4d1b1588947236daef"
11573
+ sha256: "d79b09d5b66f62f9e4bb691517b174b42bcdc0b7f40769d1993b7c565b0a54c7"
11391
11574
  },
11392
11575
  "darwin-arm64": {
11393
11576
  asset: "arm64-macos",
11394
11577
  upstreamSha256: "98aad827847af7ef990ed7098d885725c8e5b5aae75073403635617ae4e259aa",
11395
- sha256: "0b56e0a06b6a873877871537a120fd94e2121e67f4bce5f8b5252c47b615854a"
11578
+ sha256: "29342632a4fa52466c4feea846698fe5aa56ff46226a914d60b65b8735373d63"
11396
11579
  }
11397
11580
  }
11398
11581
  };
@@ -11864,6 +12047,7 @@ function outputPath(args) {
11864
12047
  }
11865
12048
  function withOutput(args, output, discovery) {
11866
12049
  const result = [];
12050
+ let stripsDebug = false;
11867
12051
  for (let i = 0; i < args.length; i++) {
11868
12052
  const arg = args[i];
11869
12053
  if (arg === "-o" || arg === "--output") {
@@ -11873,9 +12057,12 @@ function withOutput(args, output, discovery) {
11873
12057
  if (arg.startsWith("--output=")) continue;
11874
12058
  if (discovery && (arg.startsWith("--why-extract=") || arg.startsWith("--Map=")))
11875
12059
  continue;
12060
+ if (arg === "--strip-debug" || arg === "-S" || arg === "--strip-all" || arg === "-s")
12061
+ stripsDebug = true;
11876
12062
  result.push(arg);
11877
12063
  }
11878
12064
  if (discovery) result.push("--allow-multiple-definition");
12065
+ if (!stripsDebug) result.push("--strip-debug");
11879
12066
  result.push("-o", output);
11880
12067
  return result;
11881
12068
  }
@@ -11906,6 +12093,37 @@ async function linkGuestImages(options) {
11906
12093
  }
11907
12094
  return fs3.readFileSync(trace, "utf8");
11908
12095
  };
12096
+ const runLinkAsync = async (name, arguments_) => {
12097
+ const response = path10.join(directory, `${name}.rsp`);
12098
+ const trace = path10.join(directory, `${name}-inputs.txt`);
12099
+ fs3.writeFileSync(
12100
+ response,
12101
+ [...arguments_, "--trace"].map((argument2) => JSON.stringify(argument2)).join(" ")
12102
+ );
12103
+ const output = fs3.openSync(trace, "w");
12104
+ try {
12105
+ await new Promise((resolve, reject) => {
12106
+ const child = spawn(wasmLd, [`@${response}`], {
12107
+ stdio: ["ignore", output, "pipe"]
12108
+ });
12109
+ const stderr = [];
12110
+ child.stderr?.on("data", (chunk) => stderr.push(chunk));
12111
+ child.once("error", reject);
12112
+ child.once("close", (code, signal) => {
12113
+ if (code === 0) resolve();
12114
+ else
12115
+ reject(
12116
+ new Error(
12117
+ `wasm-ld (${name}) failed (${signal ?? code}): ${Buffer.concat(stderr).toString("utf8")}`
12118
+ )
12119
+ );
12120
+ });
12121
+ });
12122
+ } finally {
12123
+ fs3.closeSync(output);
12124
+ }
12125
+ return fs3.readFileSync(trace, "utf8");
12126
+ };
11909
12127
  const preselection = options.projection && options.preselectionDiscovery ? options.preselectionDiscovery : void 0;
11910
12128
  let discoveryProjection;
11911
12129
  if (options.projection) {
@@ -12135,6 +12353,7 @@ async function linkGuestImages(options) {
12135
12353
  };
12136
12354
  const ledgerObjectPromise = compileLedgerAsync("ledger", ledger.llvmIR);
12137
12355
  const appLedgerObjectPromise = options.onSplitInputs && ledger.appLLVMIR ? compileLedgerAsync("app-ledger", ledger.appLLVMIR) : void 0;
12356
+ let deferredFinalLink;
12138
12357
  try {
12139
12358
  const replacements = /* @__PURE__ */ new Map();
12140
12359
  const linkedOwners = /* @__PURE__ */ new Map();
@@ -12236,7 +12455,7 @@ async function linkGuestImages(options) {
12236
12455
  });
12237
12456
  const finalOutput = path10.join(directory, "final.wasm");
12238
12457
  const finalWhy = path10.join(directory, "final-why-extract.txt");
12239
- const linkFinal = (projectionObject2, layoutMap) => runLink("final", [
12458
+ const finalLinkArgs = (projectionObject2, layoutMap) => [
12240
12459
  ...withOutput(finalArgs, finalOutput, false),
12241
12460
  ledgerObject,
12242
12461
  `@${lazyExports}`,
@@ -12244,10 +12463,38 @@ async function linkGuestImages(options) {
12244
12463
  ...provider ? [`--undefined=${providerSymbol}`] : [],
12245
12464
  ...layoutMap ? [`--Map=${layoutMap}`] : [],
12246
12465
  `--why-extract=${finalWhy}`
12247
- ]);
12466
+ ];
12467
+ const linkFinal = (projectionObject2, layoutMap) => runLink("final", finalLinkArgs(projectionObject2, layoutMap));
12468
+ const finalizeFinalLink = (trace) => {
12469
+ const finalSelection = selectedGuestLinkInputs(
12470
+ remapGuestLinkPlan(plan, replacements),
12471
+ finalArgs,
12472
+ fs3.readFileSync(finalWhy, "utf8"),
12473
+ trace,
12474
+ finalArchives
12475
+ );
12476
+ const original = new Map(
12477
+ [...replacements].map(([before2, after2]) => [after2, before2])
12478
+ );
12479
+ const key = (item) => JSON.stringify([original.get(item.artifact) ?? item.artifact, item.member]);
12480
+ const before = new Set(selected.map(key));
12481
+ const after = new Set(finalSelection.map(key));
12482
+ const changed = [...before].filter((item) => !after.has(item));
12483
+ changed.push(...[...after].filter((item) => !before.has(item)));
12484
+ if (changed.length)
12485
+ throw new Error(
12486
+ `guest link selected different inputs after rewriting:
12487
+ ${changed.join("\n")}`
12488
+ );
12489
+ fs3.renameSync(finalOutput, outputPath(args));
12490
+ if (KEEP_WASM_NAMES)
12491
+ fs3.writeFileSync(
12492
+ outputPath(args),
12493
+ nameGuestImageAliases(fs3.readFileSync(outputPath(args)), plan.symbols)
12494
+ );
12495
+ };
12248
12496
  let projectionObject;
12249
12497
  let projectionStorage;
12250
- let finalTrace;
12251
12498
  if (options.projection) {
12252
12499
  const projection = options.projection;
12253
12500
  if (!plan.images.some((image) => image.id === projection.image))
@@ -12300,8 +12547,18 @@ async function linkGuestImages(options) {
12300
12547
  [...projection.clangOptions, "-c", projectionSource, "-o", projectionObject],
12301
12548
  { stdio: "pipe" }
12302
12549
  );
12303
- finalTrace = linkFinal(projectionObject, callerMap ? void 0 : layoutMap);
12304
- if (sharedSdk) break;
12550
+ if (sharedSdk && options.onFinalLink && options.onSplitInputs && appLedgerObjectPromise) {
12551
+ deferredFinalLink = runLinkAsync(
12552
+ "final",
12553
+ finalLinkArgs(projectionObject, callerMap ? void 0 : layoutMap)
12554
+ ).then((trace) => finalizeFinalLink(trace));
12555
+ break;
12556
+ }
12557
+ const finalTrace = linkFinal(projectionObject, callerMap ? void 0 : layoutMap);
12558
+ if (sharedSdk) {
12559
+ finalizeFinalLink(finalTrace);
12560
+ break;
12561
+ }
12305
12562
  const wasm = fs3.readFileSync(finalOutput);
12306
12563
  const actual = guestProjectionRegionCounts(
12307
12564
  images.length,
@@ -12313,38 +12570,17 @@ async function linkGuestImages(options) {
12313
12570
  sectionOwners
12314
12571
  )
12315
12572
  );
12316
- if (actual.every((count, index) => count <= capacities[index].regions)) break;
12573
+ if (actual.every((count, index) => count <= capacities[index].regions)) {
12574
+ finalizeFinalLink(finalTrace);
12575
+ break;
12576
+ }
12317
12577
  capacities = capacities.map((capacity, index) => ({
12318
12578
  ...capacity,
12319
12579
  regions: Math.max(actual[index], capacity.regions)
12320
12580
  }));
12321
12581
  }
12322
12582
  linkedOwners.set(projectionObject, projection.image);
12323
- } else finalTrace = linkFinal();
12324
- const finalSelection = selectedGuestLinkInputs(
12325
- remapGuestLinkPlan(plan, replacements),
12326
- finalArgs,
12327
- fs3.readFileSync(finalWhy, "utf8"),
12328
- finalTrace,
12329
- finalArchives
12330
- );
12331
- const original = new Map([...replacements].map(([before2, after2]) => [after2, before2]));
12332
- const key = (item) => JSON.stringify([original.get(item.artifact) ?? item.artifact, item.member]);
12333
- const before = new Set(selected.map(key));
12334
- const after = new Set(finalSelection.map(key));
12335
- const changed = [...before].filter((item) => !after.has(item));
12336
- changed.push(...[...after].filter((item) => !before.has(item)));
12337
- if (changed.length)
12338
- throw new Error(
12339
- `guest link selected different inputs after rewriting:
12340
- ${changed.join("\n")}`
12341
- );
12342
- fs3.renameSync(finalOutput, outputPath(args));
12343
- if (KEEP_WASM_NAMES)
12344
- fs3.writeFileSync(
12345
- outputPath(args),
12346
- nameGuestImageAliases(fs3.readFileSync(outputPath(args)), plan.symbols)
12347
- );
12583
+ } else finalizeFinalLink(linkFinal());
12348
12584
  if (projectionStorage && projectionObject)
12349
12585
  options.projection.onReserved(projectionStorage, projectionObject);
12350
12586
  options.onLinkedOwners?.(linkedOwners);
@@ -12380,11 +12616,13 @@ ${changed.join("\n")}`
12380
12616
  appDefinedSymbols
12381
12617
  });
12382
12618
  }
12619
+ if (deferredFinalLink) options.onFinalLink?.(deferredFinalLink);
12383
12620
  return selected;
12384
12621
  } catch (error) {
12385
12622
  await Promise.allSettled([
12386
12623
  ledgerObjectPromise,
12387
- ...appLedgerObjectPromise ? [appLedgerObjectPromise] : []
12624
+ ...appLedgerObjectPromise ? [appLedgerObjectPromise] : [],
12625
+ ...deferredFinalLink ? [deferredFinalLink] : []
12388
12626
  ]);
12389
12627
  throw error;
12390
12628
  }
@@ -13016,6 +13254,7 @@ async function linkPrunedGuestImages(options) {
13016
13254
  identities: aliasGuestLinkIdentities(identities, prepared.archives)
13017
13255
  };
13018
13256
  }
13257
+ let finalLinkDone;
13019
13258
  const selected = await linkCompleteGuestImages({
13020
13259
  plan,
13021
13260
  args: [...linkedArgs, `--Map=${options.mapPath}`],
@@ -13029,6 +13268,9 @@ async function linkPrunedGuestImages(options) {
13029
13268
  resolvePlan: options.resolvePlan,
13030
13269
  sharedSdk: options.sharedSdk,
13031
13270
  onSplitInputs: options.onSplitInputs,
13271
+ onFinalLink: options.deferFinalLink ? (done) => {
13272
+ finalLinkDone = done;
13273
+ } : void 0,
13032
13274
  onDyldRows: options.onDyldRows,
13033
13275
  onLinkedOwners: (value) => {
13034
13276
  owners = value;
@@ -13042,7 +13284,8 @@ async function linkPrunedGuestImages(options) {
13042
13284
  owners,
13043
13285
  generatedSectionOwners,
13044
13286
  sdk,
13045
- mapPath: options.mapPath
13287
+ mapPath: options.mapPath,
13288
+ finalLinkDone
13046
13289
  };
13047
13290
  }
13048
13291
 
@@ -13146,8 +13389,13 @@ function clangBinaryStamp(file) {
13146
13389
  const stat = statSync(file, { bigint: true });
13147
13390
  return [file, stat.size, stat.mtimeNs].join(":");
13148
13391
  }
13392
+ function sha256Hex2(bytes) {
13393
+ if (typeof Bun !== "undefined")
13394
+ return new Bun.CryptoHasher("sha256").update(bytes).digest("hex");
13395
+ return createHash9("sha256").update(bytes).digest("hex");
13396
+ }
13149
13397
  function clangWrapperStamp(file) {
13150
- return createHash9("sha256").update(readFileSync8(file)).digest("hex");
13398
+ return sha256Hex2(readFileSync8(file));
13151
13399
  }
13152
13400
  function clangArgsNeedCwd(args) {
13153
13401
  const pathFlags = /* @__PURE__ */ new Set([
@@ -13297,22 +13545,35 @@ function sourceGuestClangLinkOptions(options) {
13297
13545
  "SOURCE_DATE_EPOCH"
13298
13546
  ].map((name) => process.env[name] ?? "");
13299
13547
  const replays = [];
13548
+ const realPathCache = /* @__PURE__ */ new Map();
13549
+ const cachedRealpath = (file) => {
13550
+ let resolved = realPathCache.get(file);
13551
+ if (resolved === void 0) {
13552
+ resolved = realpathSync2(file);
13553
+ realPathCache.set(file, resolved);
13554
+ }
13555
+ return resolved;
13556
+ };
13557
+ const resolvedSwiftCompiler = cachedRealpath(options.swiftCompiler);
13300
13558
  let clang;
13559
+ let clangWrapper;
13301
13560
  let clangStamp;
13302
13561
  let wrapperStamp;
13303
13562
  for (const file of wanted) {
13304
13563
  const command = commands.get(file);
13305
13564
  if (!command) throw new Error(`missing source object producer ${file}`);
13306
13565
  if (command.tool === "shell") {
13307
- if (!command.args.length || realpathSync2(command.args[0]) !== realpathSync2(options.swiftCompiler))
13566
+ if (!command.args.length || cachedRealpath(command.args[0]) !== resolvedSwiftCompiler)
13308
13567
  throw new Error(`unsupported source object producer ${file}`);
13309
13568
  continue;
13310
13569
  }
13311
- const compiler = command.args[0] ? realpathSync2(command.args[0]) : "";
13312
- clang ?? (clang = realpathSync2(path11.join(options.toolchainBin, "clang")));
13313
- if (command.tool !== "clang" || compiler !== clang && compiler !== realpathSync2(path11.join(options.buildDirectory, CLANG_TARGET_MODULE_WRAPPER)))
13570
+ const compiler = command.args[0] ? cachedRealpath(command.args[0]) : "";
13571
+ clang ?? (clang = cachedRealpath(path11.join(options.toolchainBin, "clang")));
13572
+ if (command.tool !== "clang" || compiler !== clang && compiler !== (clangWrapper ?? (clangWrapper = cachedRealpath(
13573
+ path11.join(options.buildDirectory, CLANG_TARGET_MODULE_WRAPPER)
13574
+ ))))
13314
13575
  throw new Error(`unsupported source object producer ${file}`);
13315
- const key = createHash9("sha256").update(
13576
+ const key = sha256Hex2(
13316
13577
  JSON.stringify([
13317
13578
  "clang-link-options/v2",
13318
13579
  clangArgsNeedCwd(command.args) ? process.cwd() : null,
@@ -13322,11 +13583,8 @@ function sourceGuestClangLinkOptions(options) {
13322
13583
  compiler === clang ? null : wrapperStamp ?? (wrapperStamp = clangWrapperStamp(compiler)),
13323
13584
  clangProducerStamp(file)
13324
13585
  ])
13325
- ).digest("hex");
13326
- const cacheFile = path11.join(
13327
- cacheDirectory,
13328
- createHash9("sha256").update(file).digest("hex") + ".json"
13329
13586
  );
13587
+ const cacheFile = path11.join(cacheDirectory, sha256Hex2(file) + ".json");
13330
13588
  const cached = readClangLinkOptions(cacheFile, key);
13331
13589
  if (cached) {
13332
13590
  validateClangLinkOptions(cached);
@@ -14032,7 +14290,7 @@ async function compileGuestLink(options) {
14032
14290
  };
14033
14291
  const sdk = options.sdkImage;
14034
14292
  const sdkCallers = sdk?.sdkInterface.guestCallers;
14035
- const sdkObjects = sdk ? (await import("./swift-sdk-image-ZHWSHCNI.mjs")).readSwiftSdkManifestIndex(sdk).guestObjects : void 0;
14293
+ const sdkObjects = sdk ? (await import("./swift-sdk-image-U4W7QMAT.mjs")).readSwiftSdkManifestIndex(sdk).guestObjects : void 0;
14036
14294
  if (sdk && (!sdkCallers || !sdkObjects))
14037
14295
  throw new Error("the SDK image has no guest link manifest");
14038
14296
  const result = await linkPrunedGuestImages({
@@ -14053,6 +14311,7 @@ async function compileGuestLink(options) {
14053
14311
  onSplitInputs: sdk ? (value) => {
14054
14312
  splitInputs = value;
14055
14313
  } : void 0,
14314
+ deferFinalLink: Boolean(sdk),
14056
14315
  onDyldRows: (rows) => {
14057
14316
  lazyFunctions = rows.lazyFunctions;
14058
14317
  dyldSymbols = rows.dyldSymbols;
@@ -14321,156 +14580,164 @@ async function compileGuestLink(options) {
14321
14580
  });
14322
14581
  if (!reserved || !projectionObject) throw new Error("guest projection was not reserved");
14323
14582
  if (sdk) {
14324
- if (!splitInputs) throw new Error("guest link did not select shared SDK inputs");
14325
- const {
14326
- createSwiftSdkBinding,
14327
- finishSwiftAppModule,
14328
- linkSwiftAppModule,
14329
- readSwiftSdkUsage,
14330
- swiftSdkProjectionSpans
14331
- } = await import("./swift-sdk-app-module-U2M7CMKA.mjs");
14332
- const project = options.project;
14333
- const work = project ? mkdtempSync2(path14.join(directory, "app-module-")) : path14.join(directory, "app-module");
14334
- if (project) chownSync(work, project.uid, project.gid);
14335
- else mkdirSync5(work, { recursive: true });
14336
- const layoutMap = path14.join(work, "app.map");
14337
- const owners = new Map(splitInputs.appObjects).set(projectionObject, 0);
14338
- const sdkObjectKeys = /* @__PURE__ */ new Map();
14339
- const sdkObjectImages = /* @__PURE__ */ new Map();
14340
- const sdkProductImages = new Map(prepared?.sdkProducts.images);
14341
- for (const [file, { image, product, identity }] of splitInputs.sdkObjects) {
14342
- const key = sdkGuestObjectKey(identity);
14343
- sdkObjectKeys.set(file, key);
14344
- sdkObjectImages.set(key, image);
14345
- const priorImage = sdkProductImages.get(product);
14346
- if (priorImage !== void 0 && priorImage !== image)
14347
- throw new Error(`SDK product ${product} has several guest images`);
14348
- sdkProductImages.set(product, image);
14349
- }
14350
- const usage = readSwiftSdkUsage(result.mapPath, options.output, sdkObjectKeys);
14351
- const linkedModule = path14.join(work, "app.wasm");
14352
- const sdkSpans = swiftSdkProjectionSpans(
14353
- sdk,
14354
- (object2, product) => sdkObjectImages.get(object2) ?? sdkProductImages.get(product)
14355
- );
14356
- let storage = reserved;
14357
- if (sdkSpans.length > 0) {
14358
- const sdkCounts = guestProjectionRegionCounts(storage.images.length, sdkSpans);
14359
- storage = reserveGuestProjectionStorage(
14360
- storage.images,
14361
- storage.capacities.map((capacity, index) => ({
14362
- ...capacity,
14363
- regions: capacity.regions + sdkCounts[index] + 16
14364
- }))
14365
- );
14366
- const projectionSource = path14.join(work, "projection.c");
14367
- writeFileSync5(projectionSource, storage.source);
14368
- execFileSync8(
14369
- path14.join(options.toolchainBin, "clang"),
14370
- [...clangOptions, "-c", projectionSource, "-o", projectionObject],
14371
- { stdio: "pipe" }
14372
- );
14373
- }
14374
- let precomputedSymbols;
14375
- if (splitInputs.appReferencedSymbols && splitInputs.appDefinedSymbols) {
14376
- const referenced = new Set(splitInputs.appReferencedSymbols);
14377
- const defined = new Set(splitInputs.appDefinedSymbols);
14378
- const projSyms = guestWasmSymbols(readFileSync10(projectionObject));
14379
- for (const name of projSyms.undefined) referenced.add(name);
14380
- for (const name of projSyms.defined) defined.add(name);
14381
- precomputedSymbols = { referenced, defined };
14382
- }
14383
- for (; ; ) {
14384
- const link = await linkSwiftAppModule({
14385
- objects: [...owners.keys()],
14386
- lazyFunctions: splitInputs.lazyFunctions,
14387
- toolchainBin: options.toolchainBin,
14388
- sdk,
14389
- work,
14390
- output: options.optimized,
14391
- optimize: options.optimize,
14392
- layoutMap,
14393
- project,
14394
- precomputedSymbols,
14395
- loweringCache: project ? void 0 : {
14396
- file: path14.join(
14397
- options.buildDirectory,
14398
- ".build",
14399
- "peach-app-module-lowered.wasm"
14400
- ),
14401
- compilerDigest: options.compilerDigest
14402
- }
14403
- });
14404
- const map2 = readFileSync10(
14405
- project ? projectOutputFile(work, layoutMap, project) : layoutMap,
14406
- "utf8"
14407
- );
14408
- const values = guestDyldValueRange(map2);
14409
- const bindingRows = /* @__PURE__ */ new Map();
14410
- const data = [];
14411
- for (let at = 0; at < link.linkage.data.length; at += 3) {
14412
- const address = link.linkage.data[at];
14413
- const size = link.linkage.data[at + 1];
14414
- const value = link.linkage.data[at + 2];
14415
- if (values && address >= values.address && address < values.address + values.length) {
14416
- if (size !== 8 || (address - values.address) % 8)
14417
- throw new Error("sdk binding splits a dyld value");
14418
- bindingRows.set((address - values.address) / 8, value);
14419
- } else data.push(address, size, value);
14583
+ try {
14584
+ if (!splitInputs) throw new Error("guest link did not select shared SDK inputs");
14585
+ const {
14586
+ createSwiftSdkBinding,
14587
+ linkSwiftAppModule,
14588
+ readSwiftSdkUsage,
14589
+ swiftAppModuleThunkSection,
14590
+ swiftSdkProjectionSpans
14591
+ } = await import("./swift-sdk-app-module-U3MUJ7QD.mjs");
14592
+ const project = options.project;
14593
+ const work = project ? mkdtempSync2(path14.join(directory, "app-module-")) : path14.join(directory, "app-module");
14594
+ if (project) chownSync(work, project.uid, project.gid);
14595
+ else mkdirSync5(work, { recursive: true });
14596
+ const layoutMap = path14.join(work, "app.map");
14597
+ let appProjectionObject = projectionObject;
14598
+ const owners = new Map(splitInputs.appObjects).set(appProjectionObject, 0);
14599
+ const sdkObjectKeys = /* @__PURE__ */ new Map();
14600
+ const sdkObjectImages = /* @__PURE__ */ new Map();
14601
+ const sdkProductImages = new Map(prepared?.sdkProducts.images);
14602
+ for (const [file, { image, product, identity }] of splitInputs.sdkObjects) {
14603
+ const key = sdkGuestObjectKey(identity);
14604
+ sdkObjectKeys.set(file, key);
14605
+ sdkObjectImages.set(key, image);
14606
+ const priorImage = sdkProductImages.get(product);
14607
+ if (priorImage !== void 0 && priorImage !== image)
14608
+ throw new Error(`SDK product ${product} has several guest images`);
14609
+ sdkProductImages.set(product, image);
14420
14610
  }
14421
- const linked = readFileSync10(
14422
- project ? projectOutputFile(work, linkedModule, project) : linkedModule
14611
+ const linkedModule = path14.join(work, "app.wasm");
14612
+ const sdkSpans = swiftSdkProjectionSpans(
14613
+ sdk,
14614
+ (object2, product) => sdkObjectImages.get(object2) ?? sdkProductImages.get(product)
14423
14615
  );
14424
- const required = guestProjectionRegionCounts(storage.images.length, [
14425
- ...guestLinkedSpans(map2, linked, linked, owners, splitInputs.appSections, true),
14426
- ...sdkSpans
14427
- ]);
14428
- if (storage.capacities.some(({ regions }, index) => required[index] > regions)) {
14429
- storage = reserveGuestProjectionStorage(
14430
- storage.images,
14431
- storage.capacities.map((capacity, index) => {
14432
- const count = required[index];
14433
- return count > capacity.regions ? { ...capacity, regions: Math.max(count, capacity.regions * 2) } : capacity;
14434
- })
14435
- );
14616
+ const compileAppProjection = (source) => {
14436
14617
  const projectionSource = path14.join(work, "projection.c");
14437
- writeFileSync5(projectionSource, storage.source);
14618
+ const nextObject = path14.join(work, "projection.o");
14619
+ writeFileSync5(projectionSource, source);
14438
14620
  execFileSync8(
14439
14621
  path14.join(options.toolchainBin, "clang"),
14440
- [...clangOptions, "-c", projectionSource, "-o", projectionObject],
14622
+ [...clangOptions, "-c", projectionSource, "-o", nextObject],
14441
14623
  { stdio: "pipe" }
14442
14624
  );
14443
- continue;
14625
+ if (nextObject !== appProjectionObject) {
14626
+ owners.delete(appProjectionObject);
14627
+ appProjectionObject = nextObject;
14628
+ owners.set(appProjectionObject, 0);
14629
+ }
14630
+ };
14631
+ let storage = reserved;
14632
+ if (sdkSpans.length > 0) {
14633
+ const sdkCounts = guestProjectionRegionCounts(storage.images.length, sdkSpans);
14634
+ storage = reserveGuestProjectionStorage(
14635
+ storage.images,
14636
+ storage.capacities.map((capacity, index) => ({
14637
+ ...capacity,
14638
+ regions: capacity.regions + sdkCounts[index] + 16
14639
+ }))
14640
+ );
14641
+ compileAppProjection(storage.source);
14444
14642
  }
14445
- options.onStage("lowering the app image");
14446
- const lowerPromise = link.lower();
14447
- await new Promise((resolve) => setImmediate(resolve));
14448
- let binding;
14449
- try {
14450
- binding = createSwiftSdkBinding({ ...link.linkage, data }, sdk, usage);
14451
- } catch (error) {
14452
- await lowerPromise.catch(() => {
14643
+ let precomputedSymbols;
14644
+ if (splitInputs.appReferencedSymbols && splitInputs.appDefinedSymbols) {
14645
+ const referenced = new Set(splitInputs.appReferencedSymbols);
14646
+ const defined = new Set(splitInputs.appDefinedSymbols);
14647
+ const projSyms = guestWasmSymbols(readFileSync10(appProjectionObject));
14648
+ for (const name of projSyms.undefined) referenced.add(name);
14649
+ for (const name of projSyms.defined) defined.add(name);
14650
+ precomputedSymbols = { referenced, defined };
14651
+ }
14652
+ for (; ; ) {
14653
+ const link = await linkSwiftAppModule({
14654
+ objects: [...owners.keys()],
14655
+ lazyFunctions: splitInputs.lazyFunctions,
14656
+ toolchainBin: options.toolchainBin,
14657
+ sdk,
14658
+ work,
14659
+ output: options.optimized,
14660
+ optimize: options.optimize,
14661
+ layoutMap,
14662
+ project,
14663
+ precomputedSymbols,
14664
+ loweringCache: project ? void 0 : {
14665
+ file: path14.join(
14666
+ options.buildDirectory,
14667
+ ".build",
14668
+ "peach-app-module-lowered.wasm"
14669
+ ),
14670
+ compilerDigest: options.compilerDigest
14671
+ }
14453
14672
  });
14454
- throw error;
14673
+ const map2 = readFileSync10(
14674
+ project ? projectOutputFile(work, layoutMap, project) : layoutMap,
14675
+ "utf8"
14676
+ );
14677
+ const values = guestDyldValueRange(map2);
14678
+ const bindingRows = /* @__PURE__ */ new Map();
14679
+ const data = [];
14680
+ for (let at = 0; at < link.linkage.data.length; at += 3) {
14681
+ const address = link.linkage.data[at];
14682
+ const size = link.linkage.data[at + 1];
14683
+ const value = link.linkage.data[at + 2];
14684
+ if (values && address >= values.address && address < values.address + values.length) {
14685
+ if (size !== 8 || (address - values.address) % 8)
14686
+ throw new Error("sdk binding splits a dyld value");
14687
+ bindingRows.set((address - values.address) / 8, value);
14688
+ } else data.push(address, size, value);
14689
+ }
14690
+ const linked = readFileSync10(
14691
+ project ? projectOutputFile(work, linkedModule, project) : linkedModule
14692
+ );
14693
+ const required = guestProjectionRegionCounts(storage.images.length, [
14694
+ ...guestLinkedSpans(map2, linked, linked, owners, splitInputs.appSections, true),
14695
+ ...sdkSpans
14696
+ ]);
14697
+ if (storage.capacities.some(({ regions }, index) => required[index] > regions)) {
14698
+ storage = reserveGuestProjectionStorage(
14699
+ storage.images,
14700
+ storage.capacities.map((capacity, index) => {
14701
+ const count = required[index];
14702
+ return count > capacity.regions ? { ...capacity, regions: Math.max(count, capacity.regions * 2) } : capacity;
14703
+ })
14704
+ );
14705
+ compileAppProjection(storage.source);
14706
+ continue;
14707
+ }
14708
+ options.onStage("lowering the app image");
14709
+ const lowerPromise = link.lower();
14710
+ await new Promise((resolve) => setImmediate(resolve));
14711
+ let binding;
14712
+ try {
14713
+ if (result.finalLinkDone) await result.finalLinkDone;
14714
+ const usage = readSwiftSdkUsage(result.mapPath, options.output, sdkObjectKeys);
14715
+ binding = createSwiftSdkBinding({ ...link.linkage, data }, sdk, usage);
14716
+ } catch (error) {
14717
+ await Promise.allSettled([lowerPromise]);
14718
+ throw error;
14719
+ }
14720
+ await lowerPromise;
14721
+ const finalized = finalizeGuestProjectionStorage({
14722
+ map: map2,
14723
+ linked,
14724
+ optimized: readFileSync10(options.optimized),
14725
+ owners,
14726
+ sectionOwners: splitInputs.appSections,
14727
+ projectionObject: appProjectionObject,
14728
+ reserved: storage,
14729
+ sdkSpans
14730
+ });
14731
+ writeFileSync5(
14732
+ options.optimized,
14733
+ moveGuestDyldTable(map2, finalized.wasm, splitInputs.dyldSymbols, bindingRows, [
14734
+ swiftAppModuleThunkSection(finalized.wasm)
14735
+ ])
14736
+ );
14737
+ return binding;
14455
14738
  }
14456
- await lowerPromise;
14457
- const finalized = finalizeGuestProjectionStorage({
14458
- map: map2,
14459
- linked,
14460
- optimized: readFileSync10(options.optimized),
14461
- owners,
14462
- sectionOwners: splitInputs.appSections,
14463
- projectionObject,
14464
- reserved: storage,
14465
- sdkSpans
14466
- });
14467
- writeFileSync5(
14468
- options.optimized,
14469
- finishSwiftAppModule(
14470
- moveGuestDyldTable(map2, finalized.wasm, splitInputs.dyldSymbols, bindingRows)
14471
- )
14472
- );
14473
- return binding;
14739
+ } finally {
14740
+ if (result.finalLinkDone) await Promise.allSettled([result.finalLinkDone]);
14474
14741
  }
14475
14742
  }
14476
14743
  options.onStage("lowering the app image");
@@ -15605,7 +15872,7 @@ async function runCompiler(command, args, options, stream = false, quiet) {
15605
15872
  detached: true,
15606
15873
  stdio: ["ignore", "pipe", "pipe"]
15607
15874
  };
15608
- const child = options.lease ? options.lease.spawn(command, args, launch, options.frameworkLease) : spawn(command, args, launch);
15875
+ const child = options.lease ? options.lease.spawn(command, args, launch, options.frameworkLease) : spawn2(command, args, launch);
15609
15876
  let stopping;
15610
15877
  try {
15611
15878
  return await new Promise((resolve, reject) => {
@@ -16275,7 +16542,7 @@ var darwinRecordsRegion = (quoted2) => quoted2.length ? ["-Wl,--start-lib", ...q
16275
16542
  var REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
16276
16543
  var MULTI_MANIFEST_VERSION = 76;
16277
16544
  var SWIFT_HEADER_PRODUCTS_TARGET = "PeachHeaderProducts";
16278
- var compilerSourceDigest = true ? "67e8f8e0e47047534254dae36e13cda1c7694fb49b1d92c2d01a9e386dc59e59" : swiftCompilerSourceDigest(import.meta.dirname);
16545
+ var compilerSourceDigest = true ? "169122685e250113f128b79efc78f9868f581da36ab083c174056ab99b87b629" : swiftCompilerSourceDigest(import.meta.dirname);
16279
16546
  function swiftArtifactHash(input, release, moduleRoot) {
16280
16547
  return swiftCompileInputHash(input, release).update(swiftModuleDigest(moduleRoot)).digest("hex");
16281
16548
  }
@@ -20077,6 +20344,10 @@ async function buildFrameworkProducts(scratch, args) {
20077
20344
  // every framework target when callers alternate --cores.
20078
20345
  "-Xswiftc",
20079
20346
  "-gnone",
20347
+ "-Xcc",
20348
+ "-g0",
20349
+ "-Xcxx",
20350
+ "-g0",
20080
20351
  "-Xswiftc",
20081
20352
  "-num-threads",
20082
20353
  "-Xswiftc",
@@ -20565,7 +20836,7 @@ async function compileSwiftProjectOnce(sources, options) {
20565
20836
  const distribution = swiftDistributionAt(moduleRoot);
20566
20837
  const mirrorDistribution = options.linkOnly || options.project ? null : distribution;
20567
20838
  if (distribution) refreshSwiftCacheHold(moduleRoot);
20568
- const input = distribution && !options.intermediates ? (await import("./swift-package-prebuilt-DRAUK6KR.mjs")).useSwiftPackagePrebuilts(
20839
+ const input = distribution && !options.intermediates ? (await import("./swift-package-prebuilt-UVRGKTD4.mjs")).useSwiftPackagePrebuilts(
20569
20840
  sources,
20570
20841
  moduleRoot,
20571
20842
  options.toolchainBin
@@ -20579,7 +20850,7 @@ async function compileSwiftProjectOnce(sources, options) {
20579
20850
  multi: compileTargets(input).length > 0
20580
20851
  };
20581
20852
  const sdkModule = options.sdkModule && !options.linkOnly;
20582
- const sdkImage = sdkModule ? await (await import("./swift-sdk-image-ZHWSHCNI.mjs")).buildSwiftSdkImage(
20853
+ const sdkImage = sdkModule ? await (await import("./swift-sdk-image-U4W7QMAT.mjs")).buildSwiftSdkImage(
20583
20854
  moduleRoot,
20584
20855
  !!guestGraph,
20585
20856
  distribution ? [] : linkedFrameworkTargets(moduleRoot, input).imports,
@@ -20976,6 +21247,10 @@ ${cap}` : "";
20976
21247
  // fan-out under high -j.
20977
21248
  "-Xswiftc",
20978
21249
  "-gnone",
21250
+ "-Xcc",
21251
+ "-g0",
21252
+ "-Xcxx",
21253
+ "-g0",
20979
21254
  ...incrementalPreview ? [] : [
20980
21255
  "-Xswiftc",
20981
21256
  "-num-threads",
@@ -21342,7 +21617,7 @@ ${cap}` : "";
21342
21617
  if (sdkImage && binding)
21343
21618
  sdkAsset = { key: sdkImage.key, sha256: sdkImage.sha256, binding };
21344
21619
  } else if (sdkImage) {
21345
- const { buildSwiftAppModule } = await import("./swift-sdk-app-module-U2M7CMKA.mjs");
21620
+ const { buildSwiftAppModule } = await import("./swift-sdk-app-module-U3MUJ7QD.mjs");
21346
21621
  const binding = await buildSwiftAppModule({
21347
21622
  buildRoot: root2,
21348
21623
  toolchainBin: options.toolchainBin,