peachsim 0.1.2595 → 0.1.2597

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 (139) 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 +982 -431
  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-J5DSQG5R.mjs → acorn-55PXV665.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-D4XFTOV2.mjs → chunk-3DRJIOHV.mjs} +1 -1
  28. package/dist-lib/esm-chunks/{chunk-NZEHZIHZ.mjs → chunk-42RIRPTB.mjs} +1 -1
  29. package/dist-lib/esm-chunks/{chunk-CDGSSOLF.mjs → chunk-56YYEI6C.mjs} +16 -13
  30. package/dist-lib/esm-chunks/{chunk-MTGZYNXH.mjs → chunk-7ECUAVIA.mjs} +2 -2
  31. package/dist-lib/esm-chunks/{chunk-YYAPBU4L.mjs → chunk-7J65FNXI.mjs} +1 -1
  32. package/dist-lib/esm-chunks/{chunk-FHFNRCCX.mjs → chunk-AJHFCIEU.mjs} +4 -4
  33. package/dist-lib/esm-chunks/{chunk-G35VGABO.mjs → chunk-CKUEWEY4.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-NCMIX32U.mjs → chunk-DCL2ZEGA.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-3Z2POHJV.mjs → chunk-GECWNEHA.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-BCLZPP3O.mjs → chunk-GRGNTIO7.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-RYCGXYYL.mjs → chunk-GZD5CTG7.mjs} +1 -1
  38. package/dist-lib/esm-chunks/{chunk-5U76J6OF.mjs → chunk-HATXI62T.mjs} +1 -1
  39. package/dist-lib/esm-chunks/{chunk-GCOZNVG7.mjs → chunk-INA4S3MF.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-AEI4FOZK.mjs → chunk-IPN35TGX.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-U4X644Y4.mjs → chunk-LH524OUR.mjs} +3 -3
  42. package/dist-lib/esm-chunks/{chunk-ESKLJRT5.mjs → chunk-MMHNSEZY.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-POM7QBEW.mjs → chunk-NWLCTKBM.mjs} +1 -1
  44. package/dist-lib/esm-chunks/{chunk-ZSJEHQ3R.mjs → chunk-O5FDNHDG.mjs} +1 -1
  45. package/dist-lib/esm-chunks/{chunk-D6RI7LMX.mjs → chunk-ROFBHGEA.mjs} +1 -1
  46. package/dist-lib/esm-chunks/{chunk-LLO2FLAP.mjs → chunk-V6SI2XY7.mjs} +967 -491
  47. package/dist-lib/esm-chunks/{chunk-JVVPCJEO.mjs → chunk-VN7BXTMG.mjs} +5 -5
  48. package/dist-lib/esm-chunks/{chunk-VZY2J2YJ.mjs → chunk-Y4XMEBRN.mjs} +1 -1
  49. package/dist-lib/esm-chunks/{metro-layout-parser-ZHPHHXG3.mjs → metro-layout-parser-5FUYCP6P.mjs} +3 -3
  50. package/dist-lib/esm-chunks/{swift-package-prebuilt-UXU6DFC3.mjs → swift-package-prebuilt-W3VMDYHC.mjs} +10 -10
  51. package/dist-lib/esm-chunks/{swift-sdk-app-module-25XPGJ4P.mjs → swift-sdk-app-module-ZHGBY6T7.mjs} +126 -56
  52. package/dist-lib/esm-chunks/{swift-sdk-image-7JKGAHEW.mjs → swift-sdk-image-2PC4PKHZ.mjs} +14 -14
  53. package/dist-lib/esm-chunks/{swift-sdk-image-producer-KG5I2NUP.mjs → swift-sdk-image-producer-WDN6BXQL.mjs} +4 -4
  54. package/dist-lib/expo-swift-bundle.cjs +981 -430
  55. package/dist-lib/expo-swift-metadata.cjs +1 -1
  56. package/dist-lib/expo-swift-metadata.mjs +7 -7
  57. package/dist-lib/home-paths.cjs +1 -1
  58. package/dist-lib/host/bridge-host.cjs +1019 -434
  59. package/dist-lib/host/fetch-proxy-handler.cjs +36 -6
  60. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  61. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
  62. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  63. package/dist-lib/host/websocket-proxy.cjs +1 -1
  64. package/dist-lib/index.cjs +1 -1
  65. package/dist-lib/kotlin-host.cjs +1 -1
  66. package/dist-lib/menu.cjs +1 -1
  67. package/dist-lib/menu.mjs +3 -3
  68. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  69. package/dist-lib/metro-fingerprint-registry.mjs +3 -3
  70. package/dist-lib/metro-production-bundle.cjs +1 -1
  71. package/dist-lib/metro-production-bundle.mjs +4 -4
  72. package/dist-lib/native-app-identity-project.cjs +34 -4
  73. package/dist-lib/native-app-identity-project.mjs +16 -16
  74. package/dist-lib/native-app-identity.cjs +1 -1
  75. package/dist-lib/native-app-identity.mjs +6 -6
  76. package/dist-lib/native-firebase-metadata.cjs +1 -1
  77. package/dist-lib/native-firebase-metadata.mjs +3 -3
  78. package/dist-lib/pdfium-raster.cjs +1 -1
  79. package/dist-lib/pdfium-raster.mjs +2 -2
  80. package/dist-lib/plist.cjs +1 -1
  81. package/dist-lib/plist.mjs +3 -3
  82. package/dist-lib/profiles.cjs +1 -1
  83. package/dist-lib/public-brand.cjs +1 -1
  84. package/dist-lib/public-origins-lib-esm.json +81 -81
  85. package/dist-lib/public-origins-lib.json +69 -69
  86. package/dist-lib/react-native-host-modules.cjs +1 -1
  87. package/dist-lib/react-native-host-modules.mjs +2 -2
  88. package/dist-lib/reap-browser.cjs +1 -1
  89. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  90. package/dist-lib/sdk.cjs +1 -1
  91. package/dist-lib/sdk.mjs +8 -8
  92. package/dist-lib/skills.cjs +1020 -435
  93. package/dist-lib/swift-compile.cjs +979 -428
  94. package/dist-lib/swift-compile.mjs +10 -10
  95. package/dist-lib/swift-package.cjs +1 -1
  96. package/dist-lib/swift-package.mjs +3 -3
  97. package/dist-lib/swift-submit.cjs +1 -1
  98. package/dist-lib/swift-submit.mjs +6 -6
  99. package/dist-lib/swift-svg-raster.cjs +1 -1
  100. package/dist-lib/swift-svg-raster.mjs +2 -2
  101. package/dist-lib/swift-toolchain.cjs +1 -1
  102. package/dist-lib/swift.cjs +1 -1
  103. package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
  104. package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
  105. package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
  106. package/dist-lib/vendor/@xmldom/xmldom.cjs +1 -1
  107. package/dist-lib/vendor/acorn.cjs +1 -1
  108. package/dist-lib/vendor/bplist-parser.cjs +1 -1
  109. package/dist-lib/vendor/ignore.cjs +1 -1
  110. package/dist-lib/vendor/magic-string.cjs +1 -1
  111. package/dist-lib/vendor/plist.cjs +1 -1
  112. package/dist-lib/vendor/smol-toml.cjs +1 -1
  113. package/dist-lib/vendor/stream-json.cjs +1 -1
  114. package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
  115. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
  116. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
  117. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
  118. package/dist-lib/vendor/sucrase.cjs +1 -1
  119. package/dist-lib/vendor/terser.cjs +1 -1
  120. package/dist-lib/vendor/valibot.cjs +1 -1
  121. package/dist-lib/vendor/ws.cjs +1 -1
  122. package/dist-lib/vendor/zod.cjs +1 -1
  123. package/dist-lib/worklet-executable.cjs +1 -1
  124. package/dist-lib/worklet-executable.mjs +3 -3
  125. package/dist-types/packages/peach-engine/src/render-worker/nativeAnimMirrorContract.d.ts +0 -2
  126. package/package.json +1 -1
  127. package/src/one-native-controls-package.ts +32 -1
  128. package/src/swift-compile.ts +421 -175
  129. package/src/swift-guest-compile.ts +16 -0
  130. package/src/swift-guest-image-ledger.ts +65 -14
  131. package/src/swift-guest-link.ts +25 -3
  132. package/src/swift-guest-manifest.ts +27 -5
  133. package/src/swift-guest-source-inputs.ts +119 -14
  134. package/src/swift-sdk-app-module.ts +128 -55
  135. package/src/swift-sdk-image-wasm.ts +76 -39
  136. package/src/swift-sdk-image.ts +13 -9
  137. package/src/swift-wasm-prune.ts +282 -222
  138. package/src/wasm-optimize.ts +1 -1
  139. package/src/write-build-file.ts +9 -8
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.2595 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.2597 | (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;
@@ -3537,8 +3537,14 @@ var init_swift_objc_runtime = __esm({
3537
3537
 
3538
3538
  // src/write-build-file.ts
3539
3539
  function writeBuildFile(file, contents2) {
3540
- if ((0, import_node_fs8.existsSync)(file) && (typeof contents2 === "string" ? (0, import_node_fs8.readFileSync)(file, "utf8") === contents2 : (0, import_node_fs8.readFileSync)(file).equals(contents2)))
3541
- return;
3540
+ const stat = (0, import_node_fs8.statSync)(file, { throwIfNoEntry: false });
3541
+ if (stat?.isFile()) {
3542
+ if (typeof contents2 === "string") {
3543
+ if ((0, import_node_fs8.readFileSync)(file, "utf8") === contents2) return;
3544
+ } else if (stat.size === contents2.length && (0, import_node_fs8.readFileSync)(file).equals(contents2)) {
3545
+ return;
3546
+ }
3547
+ }
3542
3548
  (0, import_node_fs8.mkdirSync)(import_node_path7.default.dirname(file), { recursive: true });
3543
3549
  (0, import_node_fs8.writeFileSync)(file, contents2);
3544
3550
  }
@@ -7451,7 +7457,11 @@ function relocationEdges(bytes, segmentAddress) {
7451
7457
  const sections = wasmSections(bytes);
7452
7458
  const linking = sections.find((s) => s.name === "linking");
7453
7459
  if (!linking) throw new Error("relocation link has no linking section");
7454
- const symbols = [];
7460
+ let symKind = new Uint8Array(0);
7461
+ let symFlags = new Uint32Array(0);
7462
+ let symSegment = new Int32Array(0);
7463
+ let symOffset = new Int32Array(0);
7464
+ let symIndex = new Int32Array(0);
7455
7465
  const segmentNames = [];
7456
7466
  {
7457
7467
  const r = wasmReader(bytes, linking.start);
@@ -7459,27 +7469,31 @@ function relocationEdges(bytes, segmentAddress) {
7459
7469
  while (r.at < linking.end) {
7460
7470
  const type = r.byte();
7461
7471
  const end = r.u() + r.at;
7462
- if (type === 8)
7463
- for (let n = r.u(); n > 0; n--) {
7472
+ if (type === 8) {
7473
+ const count = r.u();
7474
+ symKind = new Uint8Array(count);
7475
+ symFlags = new Uint32Array(count);
7476
+ symSegment = new Int32Array(count).fill(-1);
7477
+ symOffset = new Int32Array(count);
7478
+ symIndex = new Int32Array(count).fill(-1);
7479
+ for (let i = 0; i < count; i++) {
7464
7480
  const kind = r.byte();
7465
7481
  const flags = r.u();
7466
- let segment = -1;
7467
- let offset = 0;
7468
- let index = -1;
7482
+ symKind[i] = kind;
7483
+ symFlags[i] = flags;
7469
7484
  if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
7470
- index = r.u();
7471
- if (!(flags & 16) || flags & 64) r.name();
7485
+ symIndex[i] = r.u();
7486
+ if (!(flags & 16) || flags & 64) r.skip(r.u());
7472
7487
  } else if (kind === 1) {
7473
- r.name();
7488
+ r.skip(r.u());
7474
7489
  if (!(flags & 16)) {
7475
- segment = r.u();
7476
- offset = r.u();
7490
+ symSegment[i] = r.u();
7491
+ symOffset[i] = r.u();
7477
7492
  r.u();
7478
7493
  }
7479
7494
  } else if (kind === 3) r.u();
7480
- symbols.push({ kind, flags, segment, offset, index });
7481
7495
  }
7482
- else if (type === 5)
7496
+ } else if (type === 5)
7483
7497
  for (let n = r.u(); n > 0; n--) {
7484
7498
  segmentNames.push(r.name());
7485
7499
  r.u();
@@ -7518,37 +7532,66 @@ function relocationEdges(bytes, segmentAddress) {
7518
7532
  const importedFunctions = readModule(bytes).importedFuncs;
7519
7533
  const data = [];
7520
7534
  const dataFunctions = [];
7521
- const code = bodyStarts.map(() => []);
7522
- const calls = bodyStarts.map(() => []);
7535
+ const bodyCount = bodyStarts.length;
7536
+ const code = Array.from({ length: bodyCount }, () => []);
7537
+ const calls = Array.from({ length: bodyCount }, () => []);
7523
7538
  for (const s of sections) {
7524
7539
  if (!s.name?.startsWith("reloc.")) continue;
7525
- const r = wasmReader(bytes, s.start);
7526
- const target = r.u();
7540
+ let cur = s.start;
7541
+ const readU = () => {
7542
+ const b0 = bytes[cur++];
7543
+ if (b0 < 128) return b0;
7544
+ let value = b0 & 127;
7545
+ let shift = 7;
7546
+ for (; ; ) {
7547
+ const byte = bytes[cur++];
7548
+ value += (byte & 127) * 2 ** shift;
7549
+ if (byte < 128) return value;
7550
+ shift += 7;
7551
+ }
7552
+ };
7553
+ const readS = () => {
7554
+ const b0 = bytes[cur++];
7555
+ if (b0 < 128) return b0 & 64 ? b0 - 128 : b0;
7556
+ let value = b0 & 127;
7557
+ let shift = 7;
7558
+ let byte = b0;
7559
+ while (byte >= 128) {
7560
+ byte = bytes[cur++];
7561
+ value += (byte & 127) * 2 ** shift;
7562
+ shift += 7;
7563
+ }
7564
+ if (byte & 64) value -= 2 ** shift;
7565
+ return value;
7566
+ };
7567
+ const target = readU();
7527
7568
  if (target !== dataIndex && target !== codeIndex) continue;
7528
7569
  let segment = 0;
7529
7570
  let body = 0;
7530
- for (let n = r.u(); n > 0; n--) {
7531
- const type = r.byte();
7532
- const offset = r.u();
7533
- const index = r.u();
7534
- const addend = ADDEND_RELOCATIONS.has(type) ? Number(r.s()) : 0;
7535
- const functionRelocation = FUNCTION_RELOCATIONS.has(type);
7536
- const memoryRelocation = MEMORY_RELOCATIONS.has(type);
7571
+ const isData = target === dataIndex;
7572
+ for (let n = readU(); n > 0; n--) {
7573
+ const type = bytes[cur++];
7574
+ const offset = readU();
7575
+ const index = readU();
7576
+ const bit = type < 32 ? 1 << type : 0;
7577
+ const addend = (ADDEND_RELOC_MASK & bit) !== 0 ? readS() : 0;
7578
+ const functionRelocation = (FUNCTION_RELOC_MASK & bit) !== 0;
7579
+ const memoryRelocation = (MEMORY_RELOC_MASK & bit) !== 0;
7537
7580
  if (!functionRelocation && !memoryRelocation) continue;
7538
- const symbol = symbols[index];
7539
- const functionReference = functionRelocation && symbol.kind === 0;
7540
- if (symbol.flags & 16) continue;
7541
- if (!functionReference && (!memoryRelocation || symbol.kind !== 1 || symbol.segment < 0))
7581
+ if (symFlags[index] & 16) continue;
7582
+ const kind = symKind[index];
7583
+ const functionReference = functionRelocation && kind === 0;
7584
+ if (!functionReference && (!memoryRelocation || kind !== 1 || symSegment[index] < 0))
7542
7585
  continue;
7543
- const to = functionReference ? symbol.index - importedFunctions : addresses[symbol.segment] + symbol.offset + addend;
7544
- if (functionReference && (to < 0 || to >= bodyStarts.length)) continue;
7545
- if (target === dataIndex) {
7586
+ const to = functionReference ? symIndex[index] - importedFunctions : addresses[symSegment[index]] + symOffset[index] + addend;
7587
+ if (functionReference && (to < 0 || to >= bodyCount)) continue;
7588
+ if (isData) {
7546
7589
  while (payloads[segment].end <= offset) segment++;
7547
7590
  const payload = payloads[segment];
7548
7591
  const edges = functionReference ? dataFunctions : data;
7549
7592
  edges.push(payload.address + offset - payload.start, to);
7550
7593
  } else {
7551
- while (body + 1 < bodyStarts.length && bodyStarts[body + 1] <= offset) body++;
7594
+ while (body + 1 < bodyCount && bodyStarts[body + 1] <= offset) body++;
7552
7595
  const edges = functionReference ? calls : code;
7553
7596
  edges[body].push(to);
7554
7597
  }
@@ -7604,7 +7647,7 @@ function unslottedFunctions(bytes) {
7604
7647
  const slotted = new Set([...m.slots.keys()].filter((index) => index >= m.importedFuncs));
7605
7648
  return m.bodies.length - slotted.size;
7606
7649
  }
7607
- var uleb, sleb, encodedName, section, PROCESS_EXPORTS, SWIFT_SDK_CONSTRUCTOR_LIMIT, FUNCTION_RELOCATIONS, MEMORY_RELOCATIONS, ADDEND_RELOCATIONS;
7650
+ 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;
7608
7651
  var init_swift_sdk_image_wasm = __esm({
7609
7652
  "src/swift-sdk-image-wasm.ts"() {
7610
7653
  "use strict";
@@ -7674,6 +7717,12 @@ var init_swift_sdk_image_wasm = __esm({
7674
7717
  25,
7675
7718
  27
7676
7719
  ]);
7720
+ FUNCTION_RELOC_MASK = 0;
7721
+ for (const type of FUNCTION_RELOCATIONS) FUNCTION_RELOC_MASK |= 1 << type;
7722
+ MEMORY_RELOC_MASK = 0;
7723
+ for (const type of MEMORY_RELOCATIONS) MEMORY_RELOC_MASK |= 1 << type;
7724
+ ADDEND_RELOC_MASK = 0;
7725
+ for (const type of ADDEND_RELOCATIONS) ADDEND_RELOC_MASK |= 1 << type;
7677
7726
  }
7678
7727
  });
7679
7728
 
@@ -7841,7 +7890,8 @@ function isRootSegName(name3) {
7841
7890
  return false;
7842
7891
  }
7843
7892
  function decodeRelocations(buf, sections) {
7844
- const count = sections.reduce((sum, section2) => sum + section2.count, 0);
7893
+ let count = 0;
7894
+ for (let s = 0; s < sections.length; s++) count += sections[s].count;
7845
7895
  const start = new Uint32Array(count);
7846
7896
  const end = new Uint32Array(count);
7847
7897
  const ro = new Int32Array(count);
@@ -7850,29 +7900,59 @@ function decodeRelocations(buf, sections) {
7850
7900
  const spans = [];
7851
7901
  let i = 0;
7852
7902
  let length = 0;
7853
- for (const section2 of sections) {
7854
- let cur = section2.at;
7855
- for (let k = 0; k < section2.count; k++, i++) {
7856
- start[i] = length + cur - section2.at;
7903
+ for (let s = 0; s < sections.length; s++) {
7904
+ const section2 = sections[s];
7905
+ const baseAt = section2.at;
7906
+ const sectionCount = section2.count;
7907
+ let cur = baseAt;
7908
+ for (let k = 0; k < sectionCount; k++, i++) {
7909
+ start[i] = length + cur - baseAt;
7857
7910
  const rType = buf[cur++];
7858
- const [offset, c2] = readULEB2(buf, cur);
7859
- const [symbol, c3] = readULEB2(buf, c2);
7860
- cur = c3;
7861
- if (ADDEND_RELOCATIONS.has(rType)) {
7862
- const [value, c4] = readSLEB(buf, cur);
7911
+ let offset = buf[cur++];
7912
+ if (offset >= 128) {
7913
+ offset &= 127;
7914
+ let shift = 7;
7915
+ while (true) {
7916
+ const byte = buf[cur++];
7917
+ offset |= (byte & 127) << shift;
7918
+ if (byte < 128) break;
7919
+ shift += 7;
7920
+ }
7921
+ }
7922
+ let symbol = buf[cur++];
7923
+ if (symbol >= 128) {
7924
+ symbol &= 127;
7925
+ let shift = 7;
7926
+ while (true) {
7927
+ const byte = buf[cur++];
7928
+ symbol |= (byte & 127) << shift;
7929
+ if (byte < 128) break;
7930
+ shift += 7;
7931
+ }
7932
+ }
7933
+ if (rType < 32 && (ADDEND_RELOC_MASK2 & 1 << rType) !== 0) {
7934
+ let byte = buf[cur++];
7935
+ let value = byte & 127;
7936
+ let shift = 7;
7937
+ while (byte >= 128) {
7938
+ byte = buf[cur++];
7939
+ value |= (byte & 127) << shift;
7940
+ shift += 7;
7941
+ }
7942
+ if (shift < 32 && (byte & 64) !== 0) value |= ~0 << shift;
7863
7943
  addend[i] = value;
7864
- cur = c4;
7865
7944
  }
7866
7945
  ro[i] = offset;
7867
7946
  rs[i] = symbol;
7868
- end[i] = length + cur - section2.at;
7947
+ end[i] = length + cur - baseAt;
7869
7948
  }
7870
- spans.push([section2.at, cur]);
7871
- length += cur - section2.at;
7949
+ spans.push([baseAt, cur]);
7950
+ length += cur - baseAt;
7872
7951
  }
7873
7952
  const bytes = new Uint8Array(length);
7874
7953
  let at = 0;
7875
- for (const [from, to] of spans) {
7954
+ for (let s = 0; s < spans.length; s++) {
7955
+ const [from, to] = spans[s];
7876
7956
  bytes.set(buf.subarray(from, to), at);
7877
7957
  at += to - from;
7878
7958
  }
@@ -8037,6 +8117,27 @@ function patchSwiftrtObject(src) {
8037
8117
  function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
8038
8118
  const rawBuf = Buffer.isBuffer(buf) ? buf : Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
8039
8119
  let pos = 8;
8120
+ let cur = 8;
8121
+ const readU = () => {
8122
+ const b0 = buf[cur++];
8123
+ if (b0 < 128) return b0;
8124
+ let res = b0 & 127;
8125
+ let shift = 7;
8126
+ while (true) {
8127
+ const byte = buf[cur++];
8128
+ res |= (byte & 127) << shift;
8129
+ if (byte < 128) return res;
8130
+ shift += 7;
8131
+ }
8132
+ };
8133
+ const skipU = () => {
8134
+ while (buf[cur++] >= 128) {
8135
+ }
8136
+ };
8137
+ const skipS = () => {
8138
+ while (buf[cur++] >= 128) {
8139
+ }
8140
+ };
8040
8141
  let numImportFuncs = 0;
8041
8142
  let importsDlsym = false;
8042
8143
  const importFuncNames = [];
@@ -8065,150 +8166,122 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
8065
8166
  const dataRelocSections = [];
8066
8167
  while (pos < buf.length) {
8067
8168
  const id = buf[pos++];
8068
- const [sz, p] = readULEB2(buf, pos);
8169
+ cur = pos;
8170
+ const sz = readU();
8171
+ const p = cur;
8069
8172
  const end = p + sz;
8070
8173
  if (id === 2) {
8071
- let [cnt, cp] = readULEB2(buf, p);
8174
+ const cnt = readU();
8072
8175
  for (let i = 0; i < cnt; i++) {
8073
- const [mLen, m2] = readULEB2(buf, cp);
8074
- const mName = rawBuf.toString("utf8", m2, m2 + mLen);
8075
- cp = m2 + mLen;
8076
- const [fLen, f2] = readULEB2(buf, cp);
8077
- const fName = rawBuf.toString("utf8", f2, f2 + fLen);
8078
- cp = f2 + fLen;
8079
- const kind = buf[cp++];
8176
+ const mLen = readU();
8177
+ const mName = rawBuf.toString("utf8", cur, cur + mLen);
8178
+ cur += mLen;
8179
+ const fLen = readU();
8180
+ const fName = rawBuf.toString("utf8", cur, cur + fLen);
8181
+ cur += fLen;
8182
+ const kind = buf[cur++];
8080
8183
  if (kind === 0) {
8081
- const [, c2] = readULEB2(buf, cp);
8082
- cp = c2;
8184
+ skipU();
8083
8185
  importFuncNames.push(fName);
8084
8186
  importFuncModules.push(mName);
8085
8187
  if (mName === "env" && fName === "dlsym") importsDlsym = true;
8086
8188
  numImportFuncs++;
8087
8189
  } else if (kind === 1) {
8088
- cp++;
8089
- const [fl, c2] = readULEB2(buf, cp);
8090
- cp = c2;
8091
- const [, c3] = readULEB2(buf, cp);
8092
- cp = c3;
8093
- if (fl & 1) {
8094
- const [, c4] = readULEB2(buf, cp);
8095
- cp = c4;
8096
- }
8190
+ cur++;
8191
+ const fl = readU();
8192
+ skipU();
8193
+ if (fl & 1) skipU();
8097
8194
  importTableNames.push(fName);
8098
8195
  } else if (kind === 2) {
8099
- const [fl, c2] = readULEB2(buf, cp);
8100
- cp = c2;
8101
- const [, c3] = readULEB2(buf, cp);
8102
- cp = c3;
8103
- if (fl & 1) {
8104
- const [, c4] = readULEB2(buf, cp);
8105
- cp = c4;
8106
- }
8196
+ const fl = readU();
8197
+ skipU();
8198
+ if (fl & 1) skipU();
8107
8199
  } else if (kind === 3) {
8108
- cp += 2;
8200
+ cur += 2;
8109
8201
  importGlobalNames.push(fName);
8110
8202
  } else if (kind === 4) {
8111
- cp++;
8112
- const [, c2] = readULEB2(buf, cp);
8113
- cp = c2;
8203
+ cur++;
8204
+ skipU();
8114
8205
  importEventNames.push(fName);
8115
8206
  }
8116
8207
  }
8117
8208
  } else if (id === 10) {
8118
8209
  codeStart = p;
8119
- let [cnt, cp] = readULEB2(buf, p);
8210
+ const cnt = readU();
8120
8211
  for (let i = 0; i < cnt; i++) {
8121
- const st = cp - codeStart;
8122
- const [bLen, b2] = readULEB2(buf, cp);
8123
- cp = b2 + bLen;
8212
+ const st = cur - codeStart;
8213
+ const bLen = readU();
8214
+ cur += bLen;
8124
8215
  fStarts.push(st);
8125
- fEnds.push(cp - codeStart);
8216
+ fEnds.push(cur - codeStart);
8126
8217
  }
8127
8218
  } else if (id === 11) {
8128
8219
  dataStart = p;
8129
- let [cnt, cp] = readULEB2(buf, p);
8220
+ const cnt = readU();
8130
8221
  for (let i = 0; i < cnt; i++) {
8131
- const st = cp - dataStart;
8132
- const [mode, m2] = readULEB2(buf, cp);
8133
- cp = m2;
8134
- if (mode === 2) {
8135
- const [, m3] = readULEB2(buf, cp);
8136
- cp = m3;
8137
- }
8222
+ const st = cur - dataStart;
8223
+ const mode = readU();
8224
+ if (mode === 2) skipU();
8138
8225
  if (mode === 0 || mode === 2) {
8139
- const op = buf[cp++];
8140
- if (op === 65 || op === 66) {
8141
- const [, m4] = readSLEB(buf, cp);
8142
- cp = m4;
8143
- } else if (op === 35) {
8144
- const [, m4] = readULEB2(buf, cp);
8145
- cp = m4;
8146
- }
8147
- cp++;
8226
+ const op = buf[cur++];
8227
+ if (op === 65 || op === 66) skipS();
8228
+ else if (op === 35) skipU();
8229
+ cur++;
8148
8230
  }
8149
- const [dLen, d2] = readULEB2(buf, cp);
8150
- sPayloadStarts.push(d2 - dataStart);
8151
- cp = d2 + dLen;
8231
+ const dLen = readU();
8232
+ sPayloadStarts.push(cur - dataStart);
8233
+ cur += dLen;
8152
8234
  sStarts.push(st);
8153
- sEnds.push(cp - dataStart);
8235
+ sEnds.push(cur - dataStart);
8154
8236
  }
8155
8237
  } else if (id === 0) {
8156
- const [nLen, np] = readULEB2(buf, p);
8157
- const name3 = rawBuf.toString("utf8", np, np + nLen);
8158
- const cp = np + nLen;
8238
+ const nLen = readU();
8239
+ const name3 = rawBuf.toString("utf8", cur, cur + nLen);
8240
+ cur += nLen;
8159
8241
  if (name3 === "linking") {
8160
- let [, lp] = readULEB2(buf, cp);
8161
- while (lp < end) {
8162
- const subId = buf[lp++];
8163
- const [subLen, sp] = readULEB2(buf, lp);
8164
- const subEnd = sp + subLen;
8242
+ skipU();
8243
+ while (cur < end) {
8244
+ const subId = buf[cur++];
8245
+ const subLen = readU();
8246
+ const subEnd = cur + subLen;
8165
8247
  if (subId === 5) {
8166
- const [cnt, p2] = readULEB2(buf, sp);
8167
- let cur = p2;
8248
+ const cnt = readU();
8168
8249
  for (let i = 0; i < cnt; i++) {
8169
- const [sLen, s2] = readULEB2(buf, cur);
8170
- segNames.push(rawBuf.toString("utf8", s2, s2 + sLen));
8171
- cur = s2 + sLen;
8172
- const [, s3] = readULEB2(buf, cur);
8173
- const [fl, s4] = readULEB2(buf, s3);
8174
- segFlags.push(fl);
8175
- cur = s4;
8250
+ const sLen = readU();
8251
+ segNames.push(rawBuf.toString("utf8", cur, cur + sLen));
8252
+ cur += sLen;
8253
+ skipU();
8254
+ segFlags.push(readU());
8176
8255
  }
8177
8256
  } else if (subId === 6) {
8178
- const [cnt, p2] = readULEB2(buf, sp);
8179
- let cur = p2;
8257
+ const cnt = readU();
8180
8258
  for (let i = 0; i < cnt; i++) {
8181
- const [, s2] = readULEB2(buf, cur);
8182
- const [symIdx, s3] = readULEB2(buf, s2);
8183
- initFuncs.push(symIdx);
8184
- cur = s3;
8259
+ skipU();
8260
+ initFuncs.push(readU());
8185
8261
  }
8186
8262
  } else if (subId === 8) {
8187
- const [cnt, p2] = readULEB2(buf, sp);
8263
+ const cnt = readU();
8188
8264
  symKind = new Uint8Array(cnt);
8189
8265
  symFlags = new Uint32Array(cnt);
8190
8266
  symElemIdx = new Int32Array(cnt).fill(-1);
8191
- symOff = new Int32Array(cnt).fill(0);
8192
- symSz = new Int32Array(cnt).fill(0);
8193
- let cur = p2;
8267
+ symOff = new Int32Array(cnt);
8268
+ symSz = new Int32Array(cnt);
8194
8269
  for (let i = 0; i < cnt; i++) {
8195
8270
  const kind = buf[cur++];
8196
8271
  if (symbolFlagOffsets) symbolFlagOffsets[i] = cur;
8197
- const [fl, c2] = readULEB2(buf, cur);
8198
- cur = c2;
8272
+ const fl = readU();
8199
8273
  symKind[i] = kind;
8200
8274
  symFlags[i] = fl;
8201
8275
  const isUndef = (fl & 16) !== 0;
8202
8276
  const isExplicitName = (fl & 64) !== 0;
8203
8277
  if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
8204
- const [el, c3] = readULEB2(buf, cur);
8205
- cur = c3;
8278
+ const el = readU();
8206
8279
  if (!isUndef && kind === 0) symElemIdx[i] = el;
8207
8280
  let sName = "";
8208
8281
  if (!isUndef || isExplicitName) {
8209
- const [sLen, c4] = readULEB2(buf, cur);
8210
- sName = rawBuf.toString("utf8", c4, c4 + sLen);
8211
- cur = c4 + sLen;
8282
+ const sLen = readU();
8283
+ sName = rawBuf.toString("utf8", cur, cur + sLen);
8284
+ cur += sLen;
8212
8285
  } else if (kind === 0) {
8213
8286
  sName = importFuncNames[el] ?? "";
8214
8287
  } else if (kind === 2) {
@@ -8222,33 +8295,28 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
8222
8295
  hostImportNames.add(sName);
8223
8296
  symNames.push(sName);
8224
8297
  } else if (kind === 1) {
8225
- const [sLen, c3] = readULEB2(buf, cur);
8226
- const sName = rawBuf.toString("utf8", c3, c3 + sLen);
8227
- cur = c3 + sLen;
8298
+ const sLen = readU();
8299
+ const sName = rawBuf.toString("utf8", cur, cur + sLen);
8300
+ cur += sLen;
8228
8301
  if (!isUndef) {
8229
- const [segIdx, c4] = readULEB2(buf, cur);
8230
- const [sOff, c5] = readULEB2(buf, c4);
8231
- const [sSz, c6] = readULEB2(buf, c5);
8232
- cur = c6;
8233
- symElemIdx[i] = segIdx;
8234
- symOff[i] = sOff;
8235
- symSz[i] = sSz;
8302
+ symElemIdx[i] = readU();
8303
+ symOff[i] = readU();
8304
+ symSz[i] = readU();
8236
8305
  }
8237
8306
  symNames.push(sName);
8238
8307
  } else if (kind === 3) {
8239
- const [, c3] = readULEB2(buf, cur);
8240
- cur = c3;
8308
+ skipU();
8241
8309
  symNames.push("");
8242
8310
  }
8243
8311
  }
8244
8312
  }
8245
- lp = subEnd;
8313
+ cur = subEnd;
8246
8314
  }
8247
8315
  } else if (name3 === "reloc.CODE" || name3 === "reloc.DATA") {
8248
- const [, r1] = readULEB2(buf, cp);
8249
- const [count, at] = readULEB2(buf, r1);
8316
+ skipU();
8317
+ const count = readU();
8250
8318
  (name3 === "reloc.DATA" ? dataRelocSections : codeRelocSections).push({
8251
- at,
8319
+ at: cur,
8252
8320
  count
8253
8321
  });
8254
8322
  }
@@ -8301,40 +8369,63 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
8301
8369
  segTopSyms.set(segIdx, dedupTop);
8302
8370
  }
8303
8371
  }
8304
- const funcRelocs = Array.from({ length: fEnds.length }, () => []);
8305
- const rawCode = decodeRelocations(buf, fEnds.length > 0 ? codeRelocSections : []);
8372
+ const funcCount = fEnds.length;
8373
+ const funcRelocs = Array.from({ length: funcCount }, () => []);
8374
+ const rawCode = decodeRelocations(buf, funcCount > 0 ? codeRelocSections : []);
8306
8375
  const codeRelocs = { ...rawCode, funcIdx: new Uint32Array(rawCode.count) };
8376
+ let fCursor = 0;
8377
+ let prevCodeRo = -1;
8307
8378
  for (let i = 0; i < codeRelocs.count; i++) {
8308
8379
  const ro = codeRelocs.ro[i];
8309
- let lo = 0;
8310
- let hi = fEnds.length - 1;
8311
- while (lo < hi) {
8312
- const mid = lo + hi >> 1;
8313
- if (fEnds[mid] <= ro) lo = mid + 1;
8314
- else hi = mid;
8380
+ let lo;
8381
+ if (ro >= prevCodeRo) {
8382
+ while (fCursor < funcCount - 1 && fEnds[fCursor] <= ro) fCursor++;
8383
+ lo = fCursor;
8384
+ } else {
8385
+ lo = 0;
8386
+ let hi = funcCount - 1;
8387
+ while (lo < hi) {
8388
+ const mid = lo + hi >> 1;
8389
+ if (fEnds[mid] <= ro) lo = mid + 1;
8390
+ else hi = mid;
8391
+ }
8392
+ fCursor = lo;
8315
8393
  }
8394
+ prevCodeRo = ro;
8316
8395
  if (codeRelocs.bytes[codeRelocs.start[i]] !== 6)
8317
8396
  funcRelocs[lo].push(codeRelocs.rs[i]);
8318
8397
  codeRelocs.funcIdx[i] = lo;
8319
8398
  }
8320
- const segRelocs = Array.from({ length: segNames.length }, () => []);
8399
+ const segCount = segNames.length;
8400
+ const segRelocs = Array.from({ length: segCount }, () => []);
8321
8401
  const symDataRelocs = /* @__PURE__ */ new Map();
8322
8402
  const rawData = decodeRelocations(buf, sEnds.length > 0 ? dataRelocSections : []);
8323
8403
  const dataSegIdx = new Uint32Array(rawData.count);
8324
8404
  const dataOffInSeg = new Int32Array(rawData.count);
8325
8405
  const dataOwnerSymIdx = new Int32Array(rawData.count);
8326
8406
  let kept = 0;
8407
+ let sCursor = 0;
8408
+ let prevDataRo = -1;
8409
+ const sEndLast = sEnds.length - 1;
8327
8410
  for (let i = 0; i < rawData.count; i++) {
8328
8411
  const ro = rawData.ro[i];
8329
8412
  const rs = rawData.rs[i];
8330
- let lo = 0;
8331
- let hi = sEnds.length - 1;
8332
- while (lo < hi) {
8333
- const mid = lo + hi >> 1;
8334
- if (sEnds[mid] <= ro) lo = mid + 1;
8335
- else hi = mid;
8413
+ let lo;
8414
+ if (ro >= prevDataRo) {
8415
+ while (sCursor < sEndLast && sEnds[sCursor] <= ro) sCursor++;
8416
+ lo = sCursor;
8417
+ } else {
8418
+ lo = 0;
8419
+ let hi = sEndLast;
8420
+ while (lo < hi) {
8421
+ const mid = lo + hi >> 1;
8422
+ if (sEnds[mid] <= ro) lo = mid + 1;
8423
+ else hi = mid;
8424
+ }
8425
+ sCursor = lo;
8336
8426
  }
8337
- if (lo >= segRelocs.length) continue;
8427
+ prevDataRo = ro;
8428
+ if (lo >= segCount) continue;
8338
8429
  const offInSeg = ro - (sPayloadStarts[lo] ?? 0);
8339
8430
  let ownerSymIdx = -1;
8340
8431
  const topList = segTopSyms.get(lo);
@@ -8481,74 +8572,78 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
8481
8572
  const conformanceProtocols = /* @__PURE__ */ new Map();
8482
8573
  const objcCategoryTargets = [];
8483
8574
  if (isDist) {
8484
- const relocAt = /* @__PURE__ */ new Map();
8485
- for (let i = 0; i < dataRelocs.count; i++) {
8486
- relocAt.set(`${dataRelocs.segIdx[i]}:${dataRelocs.offInSeg[i]}`, {
8487
- rs: dataRelocs.rs[i],
8488
- addend: dataRelocs.addend[i]
8489
- });
8490
- }
8491
8575
  const confSegs = /* @__PURE__ */ new Set();
8492
8576
  let hasCatsSeg = false;
8493
8577
  for (let i = 0; i < segNames.length; i++) {
8494
8578
  if (segNames[i] === "swift5_protocol_conformances") confSegs.add(i);
8495
8579
  else if (segNames[i] === "__objc_cats") hasCatsSeg = true;
8496
8580
  }
8497
- if (confSegs.size > 0) {
8498
- const segOffToMpSym = /* @__PURE__ */ new Map();
8499
- for (let i = 0; i < symKind.length; i++) {
8500
- if (symKind[i] === 1 && (symFlags[i] & 16) === 0 && symElemIdx[i] >= 0 && symNames[i].startsWith("$s") && symNames[i].endsWith("Mp")) {
8501
- segOffToMpSym.set(`${symElemIdx[i]}:${symOff[i]}`, symNames[i]);
8502
- }
8503
- }
8504
- const dv = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
8581
+ if (confSegs.size > 0 || hasCatsSeg) {
8582
+ const relocKey = (seg, off) => seg * 4294967296 + (off >>> 0);
8583
+ const relocAt = /* @__PURE__ */ new Map();
8505
8584
  for (let i = 0; i < dataRelocs.count; i++) {
8506
- if (!confSegs.has(dataRelocs.segIdx[i])) continue;
8507
- const mcIdx = dataRelocs.rs[i];
8508
- if (symKind[mcIdx] !== 1 || (symFlags[mcIdx] & 16) !== 0 || symElemIdx[mcIdx] < 0) {
8509
- continue;
8585
+ relocAt.set(relocKey(dataRelocs.segIdx[i], dataRelocs.offInSeg[i]), i);
8586
+ }
8587
+ if (confSegs.size > 0) {
8588
+ const segOffToMpSym = /* @__PURE__ */ new Map();
8589
+ for (let i = 0; i < symKind.length; i++) {
8590
+ if (symKind[i] === 1 && (symFlags[i] & 16) === 0 && symElemIdx[i] >= 0 && symNames[i].startsWith("$s") && symNames[i].endsWith("Mp")) {
8591
+ segOffToMpSym.set(relocKey(symElemIdx[i], symOff[i]), symNames[i]);
8592
+ }
8510
8593
  }
8511
- const mcSeg = symElemIdx[mcIdx];
8512
- const mcOff = symOff[mcIdx];
8513
- const pr = relocAt.get(`${mcSeg}:${mcOff}`);
8514
- let mp = "";
8515
- if (pr) {
8516
- const raw2 = symNames[pr.rs];
8517
- const stripped = raw2.startsWith(".Lgot.") ? raw2.slice(6) : raw2;
8518
- if (stripped.startsWith("$s") && stripped.endsWith("Mp")) {
8519
- mp = stripped;
8520
- } else if (symKind[pr.rs] === 3 || stripped === "") {
8521
- mp = segOffToMpSym.get(`${mcSeg}:${pr.addend}`) ?? "";
8594
+ const dv = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
8595
+ for (let i = 0; i < dataRelocs.count; i++) {
8596
+ if (!confSegs.has(dataRelocs.segIdx[i])) continue;
8597
+ const mcIdx = dataRelocs.rs[i];
8598
+ if (symKind[mcIdx] !== 1 || (symFlags[mcIdx] & 16) !== 0 || symElemIdx[mcIdx] < 0) {
8599
+ continue;
8522
8600
  }
8523
- } else {
8524
- const fileOff = dataStart + sPayloadStarts[mcSeg] + mcOff;
8525
- if (fileOff + 4 <= buf.length) {
8526
- const delta = dv.getInt32(fileOff, true);
8527
- mp = segOffToMpSym.get(`${mcSeg}:${mcOff + delta}`) ?? segOffToMpSym.get(`${mcSeg}:${mcOff + (delta & ~1)}`) ?? "";
8601
+ const mcSeg = symElemIdx[mcIdx];
8602
+ const mcOff = symOff[mcIdx];
8603
+ const prIdx = relocAt.get(relocKey(mcSeg, mcOff));
8604
+ let mp = "";
8605
+ if (prIdx !== void 0) {
8606
+ const prRs = dataRelocs.rs[prIdx];
8607
+ const raw2 = symNames[prRs];
8608
+ const stripped = raw2.startsWith(".Lgot.") ? raw2.slice(6) : raw2;
8609
+ if (stripped.startsWith("$s") && stripped.endsWith("Mp")) {
8610
+ mp = stripped;
8611
+ } else if (symKind[prRs] === 3 || stripped === "") {
8612
+ mp = segOffToMpSym.get(relocKey(mcSeg, dataRelocs.addend[prIdx])) ?? "";
8613
+ }
8614
+ } else {
8615
+ const fileOff = dataStart + sPayloadStarts[mcSeg] + mcOff;
8616
+ if (fileOff + 4 <= buf.length) {
8617
+ const delta = dv.getInt32(fileOff, true);
8618
+ mp = segOffToMpSym.get(relocKey(mcSeg, mcOff + delta)) ?? segOffToMpSym.get(relocKey(mcSeg, mcOff + (delta & ~1))) ?? "";
8619
+ }
8528
8620
  }
8621
+ if (mp) conformanceProtocols.set(mcIdx, mp);
8529
8622
  }
8530
- if (mp) conformanceProtocols.set(mcIdx, mp);
8531
8623
  }
8532
- }
8533
- if (hasCatsSeg) {
8534
- const seenClasses = /* @__PURE__ */ new Set();
8535
- for (let i = 0; i < symKind.length; i++) {
8536
- if (symKind[i] !== 1 || (symFlags[i] & 16) !== 0 || symElemIdx[i] < 0 || segNames[symElemIdx[i]] !== "__objc_cats" || !symNames[i].startsWith(".objc_category_")) {
8537
- continue;
8538
- }
8539
- const cSeg = symElemIdx[i];
8540
- const cOff = symOff[i];
8541
- const cr = relocAt.get(`${cSeg}:${cOff + 8}`);
8542
- if (cr && symKind[cr.rs] === 1 && (symFlags[cr.rs] & 16) === 0 && symElemIdx[cr.rs] >= 0) {
8543
- const tSeg = symElemIdx[cr.rs];
8544
- const strOff = dataStart + sPayloadStarts[tSeg] + symOff[cr.rs] + cr.addend;
8545
- let sEnd = strOff;
8546
- while (sEnd < buf.length && buf[sEnd] !== 0) sEnd++;
8547
- if (sEnd > strOff) {
8548
- const clsName = Buffer.from(buf.subarray(strOff, sEnd)).toString("utf8");
8549
- if (!seenClasses.has(clsName)) {
8550
- seenClasses.add(clsName);
8551
- objcCategoryTargets.push(clsName);
8624
+ if (hasCatsSeg) {
8625
+ const seenClasses = /* @__PURE__ */ new Set();
8626
+ for (let i = 0; i < symKind.length; i++) {
8627
+ if (symKind[i] !== 1 || (symFlags[i] & 16) !== 0 || symElemIdx[i] < 0 || segNames[symElemIdx[i]] !== "__objc_cats" || !symNames[i].startsWith(".objc_category_")) {
8628
+ continue;
8629
+ }
8630
+ const cSeg = symElemIdx[i];
8631
+ const cOff = symOff[i];
8632
+ const crIdx = relocAt.get(relocKey(cSeg, cOff + 8));
8633
+ if (crIdx !== void 0) {
8634
+ const crRs = dataRelocs.rs[crIdx];
8635
+ if (symKind[crRs] === 1 && (symFlags[crRs] & 16) === 0 && symElemIdx[crRs] >= 0) {
8636
+ const tSeg = symElemIdx[crRs];
8637
+ const strOff = dataStart + sPayloadStarts[tSeg] + symOff[crRs] + dataRelocs.addend[crIdx];
8638
+ let sEnd = strOff;
8639
+ while (sEnd < buf.length && buf[sEnd] !== 0) sEnd++;
8640
+ if (sEnd > strOff) {
8641
+ const clsName = rawBuf.toString("utf8", strOff, sEnd);
8642
+ if (!seenClasses.has(clsName)) {
8643
+ seenClasses.add(clsName);
8644
+ objcCategoryTargets.push(clsName);
8645
+ }
8646
+ }
8552
8647
  }
8553
8648
  }
8554
8649
  }
@@ -9744,7 +9839,9 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
9744
9839
  return true;
9745
9840
  };
9746
9841
  const writePrunedObject = (obj, outFile) => {
9747
- const buf = new Uint8Array(import_node_fs16.default.readFileSync(obj.file));
9842
+ const cached2 = objectBytes.get(obj);
9843
+ const buf = cached2 ? new Uint8Array(cached2) : new Uint8Array(import_node_fs16.default.readFileSync(obj.file));
9844
+ const rawBuf = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
9748
9845
  const inputSha256 = link ? (0, import_node_crypto8.createHash)("sha256").update(buf).digest("hex") : "";
9749
9846
  const fLive = liveFuncs.get(obj);
9750
9847
  const sLive = liveSegs.get(obj);
@@ -9836,7 +9933,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
9836
9933
  const end = p + sz;
9837
9934
  if (id === 0) {
9838
9935
  const [nLen, np] = readULEB2(buf, p);
9839
- const name3 = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
9936
+ const name3 = rawBuf.toString("utf8", np, np + nLen);
9840
9937
  const cp = np + nLen;
9841
9938
  if (name3 === "linking") {
9842
9939
  const [, lpStart] = readULEB2(buf, cp);
@@ -10098,7 +10195,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
10098
10195
  );
10099
10196
  import_node_fs16.default.rmSync(rspPath, { force: true });
10100
10197
  }
10101
- var import_node_child_process10, import_node_crypto8, import_node_fs16, import_node_path17, v3, WIDE_DATA_RELOCS, ROOT_SEG_PREFIXES, RECORD_SEGS, PARTITIONED_SEGS, PRUNED_SDK_ARCHIVES, OMIT_SDK_LIB_FLAGS, NEUTRALIZED_SWIFTRT_SECTIONS, relocationBytes, parsedObjectCache, PARSED_ROOTS, SWIFTUI_WRAPPER_HOST_PROTOCOLS, SWIFT_PRUNED_LINK_MAP, SWIFT_PRUNED_LINK_RESPONSE;
10198
+ var import_node_child_process10, import_node_crypto8, import_node_fs16, import_node_path17, v3, WIDE_DATA_RELOCS, ROOT_SEG_PREFIXES, RECORD_SEGS, PARTITIONED_SEGS, PRUNED_SDK_ARCHIVES, OMIT_SDK_LIB_FLAGS, NEUTRALIZED_SWIFTRT_SECTIONS, ADDEND_RELOC_MASK2, relocationBytes, parsedObjectCache, PARSED_ROOTS, SWIFTUI_WRAPPER_HOST_PROTOCOLS, SWIFT_PRUNED_LINK_MAP, SWIFT_PRUNED_LINK_RESPONSE;
10102
10199
  var init_swift_wasm_prune = __esm({
10103
10200
  "src/swift-wasm-prune.ts"() {
10104
10201
  "use strict";
@@ -10178,6 +10275,8 @@ var init_swift_wasm_prune = __esm({
10178
10275
  "swift5_reflstr",
10179
10276
  "swift5_typeref"
10180
10277
  ]);
10278
+ ADDEND_RELOC_MASK2 = 0;
10279
+ for (const type of ADDEND_RELOCATIONS) ADDEND_RELOC_MASK2 |= 1 << type;
10181
10280
  relocationBytes = (relocs, i) => relocs.bytes.subarray(relocs.start[i], relocs.end[i]);
10182
10281
  parsedObjectCache = /* @__PURE__ */ new Map();
10183
10282
  PARSED_ROOTS = 2;
@@ -10645,7 +10744,7 @@ function llvmType(value) {
10645
10744
  function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLookups, preserveCanonical, options = {}) {
10646
10745
  if (!isWasmMagic(bytes)) throw new Error("expected wasm object");
10647
10746
  const rawBuf = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
10648
- const { sdkLookupOnly, sdkProduct } = options;
10747
+ const { sdkLookupOnly, sdkProduct, collectRewrittenSymbols } = options;
10649
10748
  const comdatScope = sdkProduct === void 0 ? callerAlias : `${callerAlias}:${sdkProduct}`;
10650
10749
  const rewrite = binding !== void 0;
10651
10750
  const sections = rewrite ? [bytes.subarray(0, 8)] : void 0;
@@ -10654,6 +10753,9 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
10654
10753
  const definitions = [];
10655
10754
  const functionImports = /* @__PURE__ */ new Map();
10656
10755
  const functionImportNames = [];
10756
+ const tableImportNames = [];
10757
+ const globalImportNames = [];
10758
+ const eventImportNames = [];
10657
10759
  const functionSymbols = [];
10658
10760
  const addressTaken = /* @__PURE__ */ new Set();
10659
10761
  let usesDlsym = false;
@@ -10775,12 +10877,18 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
10775
10877
  if (isDlsym) usesDlsym = true;
10776
10878
  if (isDlerror) usesDlerror = true;
10777
10879
  if (importWriter && binding) {
10880
+ const rewrittenName = isDlsym ? callerAlias : isDlerror ? dlerrorAlias : module2 === "env" && name3 !== "dlsym" && name3 !== "dlerror" ? binding(name3) ?? name3 : name3;
10778
10881
  importWriter.string(module2);
10779
- importWriter.string(
10780
- isDlsym ? callerAlias : isDlerror ? dlerrorAlias : module2 === "env" && name3 !== "dlsym" && name3 !== "dlerror" ? binding(name3) ?? name3 : name3
10781
- );
10882
+ importWriter.string(rewrittenName);
10782
10883
  importWriter.byte(kind);
10783
10884
  importWriter.bytes(bytes, typeStart, offset);
10885
+ if (collectRewrittenSymbols) {
10886
+ if (kind === 0)
10887
+ functionImportNames[functionImportNames.length - 1] = rewrittenName;
10888
+ else if (kind === 1) tableImportNames.push(rewrittenName);
10889
+ else if (kind === 3) globalImportNames.push(rewrittenName);
10890
+ else if (kind === 4) eventImportNames.push(rewrittenName);
10891
+ }
10784
10892
  }
10785
10893
  }
10786
10894
  if (offset !== end) throw new Error("invalid wasm import section");
@@ -10863,13 +10971,17 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
10863
10971
  if (!rewrite && flags & 16 && symbolKind === 1 && alias)
10864
10972
  usedSymbols.add(name3);
10865
10973
  if (entryWriter && binding) {
10974
+ let rewrittenSym = name3;
10975
+ let addedCanonical;
10866
10976
  if ((name3 === "dlsym" && usesDlsym || name3 === "dlerror" && usesDlerror) && flags & 16 && flags & 64 && symbolKind === 0) {
10977
+ rewrittenSym = name3 === "dlsym" ? callerAlias : dlerrorAlias;
10867
10978
  entryWriter.bytes(bytes, begin, nameStart);
10868
- entryWriter.string(name3 === "dlsym" ? callerAlias : dlerrorAlias);
10979
+ entryWriter.string(rewrittenSym);
10869
10980
  entryWriter.bytes(bytes, nameEnd, offset);
10870
10981
  } else if (flags & 16 && name3 !== "dlsym" && name3 !== "dlerror" && binding(name3) !== void 0) {
10982
+ rewrittenSym = binding(name3);
10871
10983
  entryWriter.bytes(bytes, begin, nameStart);
10872
- entryWriter.string(binding(name3));
10984
+ entryWriter.string(rewrittenSym);
10873
10985
  entryWriter.bytes(bytes, nameEnd, offset);
10874
10986
  } else if (alias && !(flags & 16) && (flags & 3) !== 2) {
10875
10987
  if (symbolKind !== 0 && symbolKind !== 1)
@@ -10883,7 +10995,9 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
10883
10995
  extraWriter.string(alias);
10884
10996
  extraWriter.bytes(bytes, nameEnd, offset);
10885
10997
  added++;
10998
+ addedCanonical = alias;
10886
10999
  } else {
11000
+ rewrittenSym = alias;
10887
11001
  entryWriter.bytes(bytes, begin, nameStart);
10888
11002
  entryWriter.string(alias);
10889
11003
  entryWriter.bytes(bytes, nameEnd, offset);
@@ -10891,6 +11005,16 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
10891
11005
  } else {
10892
11006
  entryWriter.bytes(bytes, begin, offset);
10893
11007
  }
11008
+ if (collectRewrittenSymbols) {
11009
+ if (flags & 16) {
11010
+ const resolved = flags & 64 || symbolKind === 1 ? rewrittenSym : symbolKind === 0 ? functionImportNames[index] ?? "" : symbolKind === 2 ? globalImportNames[index] ?? "" : symbolKind === 4 ? eventImportNames[index] ?? "" : symbolKind === 5 ? tableImportNames[index] ?? "" : "";
11011
+ if (resolved) collectRewrittenSymbols.referenced.add(resolved);
11012
+ } else if ((flags & 3) !== 2) {
11013
+ if (rewrittenSym) collectRewrittenSymbols.defined.add(rewrittenSym);
11014
+ if (addedCanonical)
11015
+ collectRewrittenSymbols.defined.add(addedCanonical);
11016
+ }
11017
+ }
10894
11018
  } else if (alias && !(flags & 16) && (flags & 3) !== 2) {
10895
11019
  if (symbolKind !== 0 && symbolKind !== 1)
10896
11020
  throw new Error(`unsupported symbol ${name3}`);
@@ -11254,6 +11378,7 @@ function createGuestImageLedger(input) {
11254
11378
  sdkGlobalBindings.set(name3, first.alias);
11255
11379
  }
11256
11380
  }
11381
+ const appSymbols = input.registerAppTables ? { referenced: /* @__PURE__ */ new Set(), defined: /* @__PURE__ */ new Set() } : void 0;
11257
11382
  const objects = units.map(({ image, object: object4, aliases, functionImports }) => {
11258
11383
  const shared = sharedLookupByImage.get(image);
11259
11384
  const own = startup.get(object4.path);
@@ -11288,7 +11413,10 @@ function createGuestImageLedger(input) {
11288
11413
  binding,
11289
11414
  object4.instrumentDynamicLookups,
11290
11415
  preserveCanonical,
11291
- { sdkProduct: object4.sdkProduct }
11416
+ {
11417
+ sdkProduct: object4.sdkProduct,
11418
+ collectRewrittenSymbols: object4.sdkProduct === void 0 ? appSymbols : void 0
11419
+ }
11292
11420
  ).bytes
11293
11421
  };
11294
11422
  });
@@ -11409,7 +11537,9 @@ function createGuestImageLedger(input) {
11409
11537
  llvmIR: render(false, lazy),
11410
11538
  lazyFunctions: lazy,
11411
11539
  appLLVMIR: appLazy && render(true, appLazy),
11412
- appLazyFunctions: appLazy
11540
+ appLazyFunctions: appLazy,
11541
+ appReferencedSymbols: appSymbols?.referenced,
11542
+ appDefinedSymbols: appSymbols?.defined
11413
11543
  };
11414
11544
  }
11415
11545
  function guestLazyFunctionRuntime(count) {
@@ -12114,6 +12244,26 @@ function selectedGuestManifestInputs(plan, selection, identities, readSelected)
12114
12244
  }
12115
12245
  return images;
12116
12246
  }
12247
+ function framedLinkOptions(options) {
12248
+ const cached2 = framedLinkOptionsCache.get(options);
12249
+ if (cached2) return cached2;
12250
+ const parts = new Array(options.length * 2 + 2);
12251
+ const count = Buffer.from(String(options.length), "utf8");
12252
+ const countSize = Buffer.allocUnsafe(8);
12253
+ countSize.writeBigUInt64BE(BigInt(count.byteLength));
12254
+ parts[0] = countSize;
12255
+ parts[1] = count;
12256
+ for (let i = 0; i < options.length; i++) {
12257
+ const encoded = Buffer.from(options[i], "utf8");
12258
+ const size = Buffer.allocUnsafe(8);
12259
+ size.writeBigUInt64BE(BigInt(encoded.byteLength));
12260
+ parts[i * 2 + 2] = size;
12261
+ parts[i * 2 + 3] = encoded;
12262
+ }
12263
+ const framed = Buffer.concat(parts);
12264
+ framedLinkOptionsCache.set(options, framed);
12265
+ return framed;
12266
+ }
12117
12267
  function createGuestImageManifest(image) {
12118
12268
  const target = {
12119
12269
  triple: SWIFT_WASM_TRIPLE,
@@ -12123,10 +12273,10 @@ function createGuestImageManifest(image) {
12123
12273
  cpuSubtype: 0
12124
12274
  };
12125
12275
  const digest = (0, import_node_crypto12.createHash)("sha256");
12276
+ const sizeBuf = Buffer.allocUnsafe(8);
12126
12277
  const add = (bytes) => {
12127
- const size = Buffer.alloc(8);
12128
- size.writeBigUInt64BE(BigInt(bytes.byteLength));
12129
- digest.update(size);
12278
+ sizeBuf.writeBigUInt64BE(BigInt(bytes.byteLength));
12279
+ digest.update(sizeBuf);
12130
12280
  digest.update(bytes);
12131
12281
  };
12132
12282
  const text2 = (value) => add(Buffer.from(value, "utf8"));
@@ -12143,8 +12293,7 @@ function createGuestImageManifest(image) {
12143
12293
  `${version2.platform}:${version2.minimum.major}:${version2.minimum.minor}:${version2.minimum.patch}`
12144
12294
  );
12145
12295
  text2(`${version2.sdk.major}:${version2.sdk.minor}:${version2.sdk.patch}`);
12146
- text2(String(image.linkOptions.length));
12147
- for (const option of image.linkOptions) text2(option);
12296
+ digest.update(framedLinkOptions(image.linkOptions));
12148
12297
  text2(String(image.inputs.length));
12149
12298
  for (const input of image.inputs) {
12150
12299
  text2(input.identity);
@@ -12165,7 +12314,7 @@ function createGuestImageManifest(image) {
12165
12314
  regions: image.regions
12166
12315
  };
12167
12316
  }
12168
- var import_node_crypto12, import_node_fs18;
12317
+ var import_node_crypto12, import_node_fs18, framedLinkOptionsCache;
12169
12318
  var init_swift_guest_manifest = __esm({
12170
12319
  "src/swift-guest-manifest.ts"() {
12171
12320
  "use strict";
@@ -12174,6 +12323,7 @@ var init_swift_guest_manifest = __esm({
12174
12323
  init_swift_guest_link_plan();
12175
12324
  init_swift_wasm_prune();
12176
12325
  init_swiftTargetContract();
12326
+ framedLinkOptionsCache = /* @__PURE__ */ new WeakMap();
12177
12327
  }
12178
12328
  });
12179
12329
 
@@ -13809,7 +13959,7 @@ var init_wasm_optimize = __esm({
13809
13959
  ];
13810
13960
  BINARYEN_VERSION = binaryen_lock_default.version;
13811
13961
  runBinaryen = (0, import_node_util2.promisify)(import_node_child_process13.execFile);
13812
- WASM_LOWER_IDENTITY = `binaryen ${BINARYEN_VERSION} narrow ${LOWERING.join(" ")} ${FEATURES.join(",")} shared-stack-check-v2 native-image-v1 table-reserve-v2 ${NATIVE_TABLE_ABI} unoptimized-names`;
13962
+ WASM_LOWER_IDENTITY = `binaryen ${BINARYEN_VERSION} fused-pipeline-v1 narrow ${LOWERING.join(" ")} ${FEATURES.join(",")} shared-stack-check-v2 native-image-v1 table-reserve-v2 ${NATIVE_TABLE_ABI} unoptimized-names`;
13813
13963
  BINARYEN_RELEASES = new Map(Object.entries(binaryen_lock_default.platforms));
13814
13964
  }
13815
13965
  });
@@ -14254,6 +14404,7 @@ function linkGuestImages(options) {
14254
14404
  const ledgerObjects = new Map(ledger.objects.map((item) => [item.path, item]));
14255
14405
  const appObjects = /* @__PURE__ */ new Map();
14256
14406
  const sdkObjects = /* @__PURE__ */ new Map();
14407
+ const finalArchives = /* @__PURE__ */ new Map();
14257
14408
  for (const [index, artifact] of plan.artifacts.entries()) {
14258
14409
  const prefix = `${artifact.path}(`;
14259
14410
  if (artifact.kind === "object") {
@@ -14275,7 +14426,10 @@ function linkGuestImages(options) {
14275
14426
  }
14276
14427
  const members = archives.get(artifact.path);
14277
14428
  if (!members) continue;
14278
- const listed = (0, import_node_child_process14.execFileSync)(llvmAr, ["t", artifact.path], { encoding: "utf8" }).trimEnd().split("\n");
14429
+ const listing = (0, import_node_child_process14.execFileSync)(llvmAr, ["t", artifact.path], {
14430
+ encoding: "utf8"
14431
+ }).trimEnd();
14432
+ const listed = listing ? listing.split("\n") : [];
14279
14433
  if (listed.length !== members.length || new Set(listed).size !== listed.length || members.some(
14280
14434
  (member, i) => listed[i] !== member.name || import_node_path24.default.basename(member.name) !== member.name
14281
14435
  ))
@@ -14304,6 +14458,10 @@ function linkGuestImages(options) {
14304
14458
  const response = import_node_path24.default.join(memberDir, "members.rsp");
14305
14459
  import_node_fs24.default.writeFileSync(response, inputs.map((input) => JSON.stringify(input)).join(" "));
14306
14460
  (0, import_node_child_process14.execFileSync)(llvmAr, ["rcs", output, `@${response}`], { stdio: "pipe" });
14461
+ finalArchives.set(
14462
+ output,
14463
+ members.map((member) => ({ name: member.name, bytes: new Uint8Array(0) }))
14464
+ );
14307
14465
  replacements.set(artifact.path, output);
14308
14466
  }
14309
14467
  const compileLedger = (name3, source) => {
@@ -14435,7 +14593,8 @@ function linkGuestImages(options) {
14435
14593
  remapGuestLinkPlan(plan, replacements),
14436
14594
  finalArgs,
14437
14595
  import_node_fs24.default.readFileSync(finalWhy, "utf8"),
14438
- finalTrace
14596
+ finalTrace,
14597
+ finalArchives
14439
14598
  );
14440
14599
  const original = new Map([...replacements].map(([before2, after2]) => [after2, before2]));
14441
14600
  const key = (item) => JSON.stringify([original.get(item.artifact) ?? item.artifact, item.member]);
@@ -14468,12 +14627,25 @@ ${changed.join("\n")}`
14468
14627
  ])
14469
14628
  );
14470
14629
  appObjects.set(appLedgerObject, options.ledgerDataImage);
14630
+ let appReferencedSymbols;
14631
+ let appDefinedSymbols;
14632
+ if (ledger.appReferencedSymbols && ledger.appDefinedSymbols) {
14633
+ const referenced = new Set(ledger.appReferencedSymbols);
14634
+ const defined = new Set(ledger.appDefinedSymbols);
14635
+ const ledgerSyms = guestWasmSymbols(import_node_fs24.default.readFileSync(appLedgerObject));
14636
+ for (const name3 of ledgerSyms.undefined) referenced.add(name3);
14637
+ for (const name3 of ledgerSyms.defined) defined.add(name3);
14638
+ appReferencedSymbols = referenced;
14639
+ appDefinedSymbols = defined;
14640
+ }
14471
14641
  options.onSplitInputs({
14472
14642
  appObjects,
14473
14643
  appSections,
14474
14644
  sdkObjects,
14475
14645
  lazyFunctions: ledger.appLazyFunctions ?? [],
14476
- dyldSymbols: ledger.dyldSymbols
14646
+ dyldSymbols: ledger.dyldSymbols,
14647
+ appReferencedSymbols,
14648
+ appDefinedSymbols
14477
14649
  });
14478
14650
  }
14479
14651
  return selected;
@@ -15465,6 +15637,93 @@ function sourceGuestInputIdentities(graph, buildDirectory, objects) {
15465
15637
  }
15466
15638
  return identities;
15467
15639
  }
15640
+ function wasmAutolinkEntries(bytes, out) {
15641
+ if (bytes.length < 8) return false;
15642
+ if (bytes[0] === 33 && bytes[1] === 60 && bytes[2] === 97 && bytes[3] === 114 && bytes[4] === 99 && bytes[5] === 104 && bytes[6] === 62 && bytes[7] === 10) {
15643
+ for (const member of readArMembers(bytes)) {
15644
+ if (!wasmAutolinkEntries(member.bytes, out)) return false;
15645
+ }
15646
+ return true;
15647
+ }
15648
+ if (bytes[0] !== 0 || bytes[1] !== 97 || bytes[2] !== 115 || bytes[3] !== 109)
15649
+ return false;
15650
+ const raw2 = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
15651
+ let pos = 8;
15652
+ const len = bytes.length;
15653
+ while (pos < len) {
15654
+ const id = bytes[pos++];
15655
+ let sz = bytes[pos++];
15656
+ if (sz >= 128) {
15657
+ sz &= 127;
15658
+ let shift = 7;
15659
+ while (true) {
15660
+ const b = bytes[pos++];
15661
+ sz |= (b & 127) << shift;
15662
+ if (b < 128) break;
15663
+ shift += 7;
15664
+ }
15665
+ }
15666
+ const end = pos + sz;
15667
+ if (id === 0) {
15668
+ let nLen = bytes[pos++];
15669
+ if (nLen >= 128) {
15670
+ nLen &= 127;
15671
+ let shift = 7;
15672
+ while (true) {
15673
+ const b = bytes[pos++];
15674
+ nLen |= (b & 127) << shift;
15675
+ if (b < 128) break;
15676
+ shift += 7;
15677
+ }
15678
+ }
15679
+ if (nLen === 24 && raw2.toString("ascii", pos, pos + 24) === ".swift1_autolink_entries") {
15680
+ const payload = raw2.toString("utf8", pos + 24, end);
15681
+ for (const entry of payload.split("\0")) {
15682
+ const trimmed = entry.trim();
15683
+ if (trimmed.length > 0) out.push(trimmed);
15684
+ }
15685
+ }
15686
+ }
15687
+ pos = end;
15688
+ }
15689
+ return true;
15690
+ }
15691
+ function readAutolinkFlags(objects, toolchainBin, responsePath) {
15692
+ if (!objects.length) return [];
15693
+ const rawFlags = [];
15694
+ for (const file of objects) {
15695
+ if (!wasmAutolinkEntries((0, import_node_fs25.readFileSync)(file), rawFlags)) {
15696
+ (0, import_node_fs25.writeFileSync)(
15697
+ responsePath,
15698
+ objects.map((entry) => JSON.stringify(entry)).join("\n") + "\n"
15699
+ );
15700
+ return (0, import_node_child_process15.execFileSync)(
15701
+ import_node_path25.default.join(toolchainBin, "swift-autolink-extract"),
15702
+ [`@${responsePath}`, "-o", "-"],
15703
+ { encoding: "utf8" }
15704
+ ).split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
15705
+ }
15706
+ }
15707
+ const seen = /* @__PURE__ */ new Set();
15708
+ const flags = [];
15709
+ for (let i = 0; i < rawFlags.length; i++) {
15710
+ const flag = rawFlags[i];
15711
+ if ((flag === "-framework" || flag === "-weak_framework" || flag === "-l" || flag === "--library") && i + 1 < rawFlags.length) {
15712
+ const value = rawFlags[++i];
15713
+ const key = `${flag}\0${value}`;
15714
+ if (!seen.has(key)) {
15715
+ seen.add(key);
15716
+ flags.push(flag, value);
15717
+ }
15718
+ continue;
15719
+ }
15720
+ if (!seen.has(flag)) {
15721
+ seen.add(flag);
15722
+ flags.push(flag);
15723
+ }
15724
+ }
15725
+ return flags;
15726
+ }
15468
15727
  function sourceGuestRuntimeLinks(options) {
15469
15728
  const aliases = /* @__PURE__ */ new Map();
15470
15729
  const artifacts = /* @__PURE__ */ new Map();
@@ -15552,15 +15811,7 @@ function sourceGuestRuntimeLinks(options) {
15552
15811
  for (const image of options.images) {
15553
15812
  if (result.has(image.id)) throw new Error(`duplicate source image ${image.id}`);
15554
15813
  const response = import_node_path25.default.join(options.directory, `image-${image.id}-autolink.rsp`);
15555
- (0, import_node_fs25.writeFileSync)(
15556
- response,
15557
- image.objects.map((file) => JSON.stringify(file)).join("\n") + "\n"
15558
- );
15559
- const autolink = image.objects.length ? (0, import_node_child_process15.execFileSync)(
15560
- import_node_path25.default.join(options.toolchainBin, "swift-autolink-extract"),
15561
- [`@${response}`, "-o", "-"],
15562
- { encoding: "utf8" }
15563
- ).split("\n").map((line) => line.trim()).filter((line) => line.length > 0) : [];
15814
+ const autolink = readAutolinkFlags(image.objects, options.toolchainBin, response);
15564
15815
  const links = [];
15565
15816
  const requests = [];
15566
15817
  const optionGroups = [
@@ -15660,6 +15911,7 @@ var init_swift_guest_source_inputs = __esm({
15660
15911
  init_forked_script_contract();
15661
15912
  init_swift_guest_source_plan();
15662
15913
  init_swift_runtime_products();
15914
+ init_swift_wasm_prune();
15663
15915
  CLANG_TARGET_MODULE_WRAPPER = ".peach-clang";
15664
15916
  PARALLEL_REPLAY = `
15665
15917
  const { spawn } = require('node:child_process')
@@ -16839,24 +17091,26 @@ function setBoundedCache(cache, key, value) {
16839
17091
  return value;
16840
17092
  }
16841
17093
  function cached(directory, key) {
16842
- const sdkInterfacePath = import_node_path35.default.join(directory, INTERFACE_FILE);
16843
- const image = import_node_path35.default.join(directory, IMAGE_FILE);
16844
17094
  const address = import_node_path35.default.join(directory, IMAGE_DIGEST);
16845
- if (!(0, import_node_fs35.existsSync)(image) || !(0, import_node_fs35.existsSync)(address) || !(0, import_node_fs35.existsSync)(sdkInterfacePath) || !(0, import_node_fs35.existsSync)(import_node_path35.default.join(directory, MANIFEST_FILE)) || !(0, import_node_fs35.existsSync)(import_node_path35.default.join(directory, MANIFEST_DATA_FILE)))
17095
+ if (!(0, import_node_fs35.existsSync)(import_node_path35.default.join(directory, IMAGE_FILE)) || !(0, import_node_fs35.existsSync)(address) || !(0, import_node_fs35.existsSync)(import_node_path35.default.join(directory, INTERFACE_FILE)) || !(0, import_node_fs35.existsSync)(import_node_path35.default.join(directory, MANIFEST_FILE)) || !(0, import_node_fs35.existsSync)(import_node_path35.default.join(directory, MANIFEST_DATA_FILE)))
16846
17096
  return void 0;
16847
- const sha2562 = (0, import_node_fs35.readFileSync)(address, "utf8");
17097
+ return sdkImageAt(directory, key, (0, import_node_fs35.readFileSync)(address, "utf8"));
17098
+ }
17099
+ function sdkImageAt(directory, key, sha2562) {
16848
17100
  const cacheKey = `${directory}\0${sha2562}`;
16849
17101
  let loadedInterface;
16850
17102
  return {
16851
17103
  key,
16852
17104
  directory,
16853
- image,
17105
+ image: import_node_path35.default.join(directory, IMAGE_FILE),
16854
17106
  sha256: sha2562,
16855
17107
  get sdkInterface() {
16856
17108
  if (loadedInterface) return loadedInterface;
16857
17109
  const memo2 = cachedSdkInterfaces.get(cacheKey);
16858
17110
  if (memo2) return loadedInterface = memo2;
16859
- const parsed = JSON.parse((0, import_node_fs35.readFileSync)(sdkInterfacePath, "utf8"));
17111
+ const parsed = JSON.parse(
17112
+ (0, import_node_fs35.readFileSync)(import_node_path35.default.join(directory, INTERFACE_FILE), "utf8")
17113
+ );
16860
17114
  return loadedInterface = setBoundedCache(cachedSdkInterfaces, cacheKey, parsed);
16861
17115
  }
16862
17116
  };
@@ -16909,7 +17163,7 @@ async function buildSwiftSdkImage(moduleRoot, scopedLookups = false, frameworkIm
16909
17163
  throw new Error(`invalid published Swift SDK image ${key}`);
16910
17164
  (0, import_node_fs35.rmSync)(directory, { recursive: true, force: true });
16911
17165
  (0, import_node_fs35.renameSync)(stage, directory);
16912
- return { ...image, directory, image: import_node_path35.default.join(directory, IMAGE_FILE) };
17166
+ return sdkImageAt(directory, key, image.sha256);
16913
17167
  } finally {
16914
17168
  (0, import_node_fs35.rmSync)(stage, { recursive: true, force: true });
16915
17169
  }
@@ -17262,9 +17516,10 @@ function sdkHostExports(appRoot) {
17262
17516
  if (!(byte & 128)) return value;
17263
17517
  }
17264
17518
  };
17519
+ const raw2 = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
17265
17520
  for (let n = u(); n > 0; n--) {
17266
17521
  const length = u();
17267
- names.push(Buffer.from(bytes.subarray(at, at + length)).toString());
17522
+ names.push(raw2.toString("utf8", at, at + length));
17268
17523
  at += length + 1;
17269
17524
  u();
17270
17525
  }
@@ -17690,56 +17945,109 @@ function swiftAppModuleInputs(tokens, buildRoot, sdkLibraries) {
17690
17945
  }
17691
17946
  return inputs;
17692
17947
  }
17693
- async function compileSdkForwarders(inputs, sdk, toolchainBin, output, project, readInput) {
17948
+ function llvmQuoted(value) {
17949
+ const bytes = Buffer.from(value, "utf8");
17950
+ let out = '"';
17951
+ for (let i = 0; i < bytes.length; i++) {
17952
+ const b = bytes[i];
17953
+ if (b >= 32 && b <= 126 && b !== 34 && b !== 92) out += String.fromCharCode(b);
17954
+ else out += `\\${b.toString(16).toUpperCase().padStart(2, "0")}`;
17955
+ }
17956
+ return out + '"';
17957
+ }
17958
+ async function compileSdkForwarders(inputs, sdk, toolchainBin, output, project, readInput, precomputedSymbols) {
17694
17959
  const { signatures, tls } = sdk.sdkInterface;
17695
- const directories = inputs.filter((input) => input.startsWith("-L")).map((input) => input.slice(2));
17696
- const referenced = /* @__PURE__ */ new Set();
17697
- const defined = /* @__PURE__ */ new Set();
17698
- const scan2 = (bytes) => {
17699
- const symbols = guestWasmSymbols(bytes);
17700
- for (const name3 of symbols.undefined) referenced.add(name3);
17701
- for (const name3 of symbols.defined) defined.add(name3);
17960
+ let referenced;
17961
+ let defined;
17962
+ if (precomputedSymbols) {
17963
+ referenced = precomputedSymbols.referenced;
17964
+ defined = precomputedSymbols.defined;
17965
+ } else {
17966
+ const directories = inputs.filter((input) => input.startsWith("-L")).map((input) => input.slice(2));
17967
+ const refSet = /* @__PURE__ */ new Set();
17968
+ const defSet = /* @__PURE__ */ new Set();
17969
+ const scan2 = (bytes) => {
17970
+ const symbols = guestWasmSymbols(bytes);
17971
+ for (const name3 of symbols.undefined) refSet.add(name3);
17972
+ for (const name3 of symbols.defined) defSet.add(name3);
17973
+ };
17974
+ for (const input of inputs) {
17975
+ const file = input.startsWith("-l") ? directories.map((directory) => import_node_path36.default.join(directory, `lib${input.slice(2)}.a`)).find((candidate) => (0, import_node_fs36.existsSync)(candidate)) : input.startsWith("-") ? void 0 : input;
17976
+ if (!file) continue;
17977
+ const bytes = readInput(file);
17978
+ if (file.endsWith(".a"))
17979
+ for (const member of readArMembers(bytes)) scan2(member.bytes);
17980
+ else scan2(bytes);
17981
+ }
17982
+ referenced = refSet;
17983
+ defined = defSet;
17984
+ }
17985
+ const irType = {
17986
+ i: "i32",
17987
+ j: "i64",
17988
+ f: "float",
17989
+ d: "double"
17702
17990
  };
17703
- for (const input of inputs) {
17704
- const file = input.startsWith("-l") ? directories.map((directory) => import_node_path36.default.join(directory, `lib${input.slice(2)}.a`)).find((candidate) => (0, import_node_fs36.existsSync)(candidate)) : input.startsWith("-") ? void 0 : input;
17705
- if (!file) continue;
17706
- const bytes = readInput(file);
17707
- if (file.endsWith(".a")) for (const member of readArMembers(bytes)) scan2(member.bytes);
17708
- else scan2(bytes);
17709
- }
17710
- const c = { i: "int", j: "long long", f: "float", d: "double" };
17711
- const type = (kinds) => [...kinds].map((kind) => {
17712
- const name3 = c[kind];
17713
- if (!name3) throw new Error(`sdk signature kind ${kind}`);
17714
- return name3;
17715
- });
17716
- const literal2 = (name3) => JSON.stringify(name3);
17717
- const lines = [];
17718
- if (signatures.__objc_send_load_messages === ":")
17991
+ const type = (kinds) => {
17992
+ const out = new Array(kinds.length);
17993
+ for (let i = 0; i < kinds.length; i++) {
17994
+ const kind = kinds[i];
17995
+ const name3 = irType[kind];
17996
+ if (!name3) throw new Error(`sdk signature kind ${kind}`);
17997
+ out[i] = name3;
17998
+ }
17999
+ return out;
18000
+ };
18001
+ const lines = [`target triple = "${SWIFT_WASM_TRIPLE}"`];
18002
+ const attrs = [];
18003
+ const addImportAttr = (name3) => {
18004
+ const id = attrs.length;
18005
+ attrs.push(
18006
+ `attributes #${id} = { "wasm-import-module"="env" "wasm-import-name"=${llvmQuoted(name3)} }`
18007
+ );
18008
+ return id;
18009
+ };
18010
+ if (signatures.__objc_send_load_messages === ":") {
18011
+ const attr = addImportAttr("__objc_send_load_messages");
17719
18012
  lines.push(
17720
- '__attribute__((import_module("env"), import_name("__objc_send_load_messages"))) void sdk_send_load_messages(void);',
17721
- "__attribute__((constructor)) static void send_app_load_messages(void) { sdk_send_load_messages(); }"
18013
+ "@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @send_app_load_messages, ptr null }]",
18014
+ `declare void @sdk_send_load_messages() #${attr}`,
18015
+ "define internal void @send_app_load_messages() {",
18016
+ " tail call void @sdk_send_load_messages()",
18017
+ " ret void",
18018
+ "}"
17722
18019
  );
18020
+ }
17723
18021
  const forwarders = /* @__PURE__ */ new Set();
17724
18022
  let index = 0;
17725
18023
  for (const name3 of referenced) {
17726
18024
  const signature2 = signatures[name3];
17727
18025
  if (signature2 === void 0 || defined.has(name3)) continue;
17728
- const [params = "", results = ""] = signature2.split(":");
18026
+ const colon = signature2.indexOf(":");
18027
+ const params = colon < 0 ? signature2 : signature2.slice(0, colon);
18028
+ const results = colon < 0 ? "" : signature2.slice(colon + 1);
17729
18029
  if (results.length > 1) throw new Error(`sdk function ${name3} returns several values`);
17730
18030
  const result = results ? type(results)[0] : "void";
17731
- const declared = type(params).map((kind, at) => `${kind} a${at}`).join(", ") || "void";
17732
- const passed = type(params).map((_, at) => `a${at}`).join(", ");
18031
+ const paramTypes = type(params);
18032
+ const declParams = paramTypes.join(", ");
18033
+ const defParams = paramTypes.map((kind, at) => `${kind} %a${at}`).join(", ");
18034
+ const callArgs = paramTypes.map((kind, at) => `${kind} %a${at}`).join(", ");
18035
+ const attr = addImportAttr(name3);
18036
+ const quoted2 = llvmQuoted(name3);
17733
18037
  lines.push(
17734
- `__attribute__((import_module("env"), import_name(${literal2(name3)}))) ${result} i${index}(${declared});`,
17735
- `__attribute__((weak)) ${result} f${index}(${declared}) __asm__(${literal2(name3)});`,
17736
- `${result} f${index}(${declared}) { ${result === "void" ? "" : "return "}i${index}(${passed}); }`
18038
+ `declare ${result} @i${index}(${declParams}) #${attr}`,
18039
+ `define weak hidden ${result} @${quoted2}(${defParams}) {`,
18040
+ result === "void" ? ` tail call void @i${index}(${callArgs})
18041
+ ret void` : ` %r = tail call ${result} @i${index}(${callArgs})
18042
+ ret ${result} %r`,
18043
+ "}"
17737
18044
  );
17738
18045
  forwarders.add(name3);
17739
18046
  index++;
17740
18047
  }
17741
18048
  const errno = tls.errno;
17742
18049
  let declaredErrno = false;
18050
+ const usedHelpers = [];
17743
18051
  for (const name3 of referenced) {
17744
18052
  const offset = tls[name3];
17745
18053
  if (offset === void 0 || defined.has(name3)) continue;
@@ -17747,28 +18055,44 @@ async function compileSdkForwarders(inputs, sdk, toolchainBin, output, project,
17747
18055
  throw new Error("the sdk image has no errno to find its thread block by");
17748
18056
  if (!declaredErrno) {
17749
18057
  declaredErrno = true;
18058
+ const attr = addImportAttr("__errno_location");
17750
18059
  lines.push(
17751
- `__attribute__((import_module("env"), import_name("__errno_location"))) char *__peach_errno(void);`
18060
+ `declare ptr @__peach_errno() #${attr}`,
18061
+ "declare ptr @llvm.wasm.tls.base()"
17752
18062
  );
17753
18063
  }
18064
+ const helper = `@${llvmQuoted(SDK_TLS_HELPER + name3)}`;
18065
+ const delta = `@${llvmQuoted(SDK_TLS_DELTA + name3)}`;
18066
+ usedHelpers.push(`ptr ${helper}`);
17754
18067
  lines.push(
17755
- `__attribute__((weak)) _Thread_local char t${index} __asm__(${literal2(name3)});`,
17756
- `__attribute__((used)) long long h${index}(void) __asm__(${literal2(SDK_TLS_HELPER + name3)});`,
17757
- `extern char d${index} __asm__(${literal2(SDK_TLS_DELTA + name3)});`,
17758
- `long long h${index}(void) { return (long long)__peach_errno() + (long long)&d${index} - (long long)__builtin_wasm_tls_base(); }`
18068
+ `@${llvmQuoted(name3)} = weak hidden thread_local global i8 0, align 1`,
18069
+ `${delta} = external global i8, align 1`,
18070
+ `define hidden i64 ${helper}() {`,
18071
+ " %e = tail call ptr @__peach_errno()",
18072
+ " %ei = ptrtoint ptr %e to i64",
18073
+ ` %di = ptrtoint ptr ${delta} to i64`,
18074
+ " %s = add i64 %ei, %di",
18075
+ " %b = tail call ptr @llvm.wasm.tls.base()",
18076
+ " %bi = ptrtoint ptr %b to i64",
18077
+ " %r = sub i64 %s, %bi",
18078
+ " ret i64 %r",
18079
+ "}"
17759
18080
  );
17760
18081
  index++;
17761
18082
  }
17762
- const source = `${output.slice(0, -2)}.c`;
17763
- (0, import_node_fs36.writeFileSync)(source, lines.join("\n") + "\n");
18083
+ if (usedHelpers.length > 0) {
18084
+ lines.push(
18085
+ `@llvm.used = appending global [${usedHelpers.length} x ptr] [${usedHelpers.join(", ")}], section "llvm.metadata"`
18086
+ );
18087
+ }
18088
+ const source = `${output.slice(0, -2)}.ll`;
18089
+ (0, import_node_fs36.writeFileSync)(source, [...lines, ...attrs].join("\n") + "\n");
17764
18090
  await run3(
17765
18091
  import_node_path36.default.join(toolchainBin, "clang"),
17766
18092
  [
17767
18093
  `--target=${SWIFT_WASM_TRIPLE}`,
17768
- "-O2",
17769
18094
  "-matomics",
17770
18095
  "-mbulk-memory",
17771
- "-ffreestanding",
17772
18096
  "-c",
17773
18097
  source,
17774
18098
  "-o",
@@ -17787,7 +18111,8 @@ async function linkSwiftAppModule(options) {
17787
18111
  toolchainBin,
17788
18112
  forwarders,
17789
18113
  options.project,
17790
- options.readInput ?? import_node_fs36.readFileSync
18114
+ options.readInput ?? import_node_fs36.readFileSync,
18115
+ options.precomputedSymbols
17791
18116
  );
17792
18117
  const lazy = options.lazyFunctions ?? [];
17793
18118
  const lazyExports = import_node_path36.default.join(work, "lazy-exports.rsp");
@@ -19531,6 +19856,15 @@ async function compileGuestLink(options) {
19531
19856
  { stdio: "pipe" }
19532
19857
  );
19533
19858
  }
19859
+ let precomputedSymbols;
19860
+ if (splitInputs.appReferencedSymbols && splitInputs.appDefinedSymbols) {
19861
+ const referenced = new Set(splitInputs.appReferencedSymbols);
19862
+ const defined = new Set(splitInputs.appDefinedSymbols);
19863
+ const projSyms = guestWasmSymbols((0, import_node_fs37.readFileSync)(projectionObject));
19864
+ for (const name3 of projSyms.undefined) referenced.add(name3);
19865
+ for (const name3 of projSyms.defined) defined.add(name3);
19866
+ precomputedSymbols = { referenced, defined };
19867
+ }
19534
19868
  for (; ; ) {
19535
19869
  const link = await linkSwiftAppModule2({
19536
19870
  objects: [...owners.keys()],
@@ -19542,6 +19876,7 @@ async function compileGuestLink(options) {
19542
19876
  optimize: options.optimize,
19543
19877
  layoutMap,
19544
19878
  project,
19879
+ precomputedSymbols,
19545
19880
  loweringCache: project ? void 0 : {
19546
19881
  file: import_node_path37.default.join(
19547
19882
  options.buildDirectory,
@@ -19666,6 +20001,7 @@ var init_swift_guest_compile = __esm({
19666
20001
  init_swift_runtime_products();
19667
20002
  init_swift_sdk_guest_lookups();
19668
20003
  init_swift_toolchain();
20004
+ init_swift_wasm_prune();
19669
20005
  init_swiftTargetContract();
19670
20006
  init_wasm_optimize();
19671
20007
  }
@@ -21252,7 +21588,25 @@ function swiftBuildJobs() {
21252
21588
  return Math.min(cores, memoryJobs);
21253
21589
  }
21254
21590
  function swiftCompilerJobs() {
21255
- return Math.min(16, swiftBuildJobs(), Math.max(1, Math.floor(import_node_os11.default.totalmem() / 2 ** 31)));
21591
+ return Math.min(32, swiftBuildJobs(), Math.max(1, Math.floor(import_node_os11.default.totalmem() / 2 ** 31)));
21592
+ }
21593
+ function swiftCompilerBaseEnv(toolchainBin, sourceEnv, includePeachHome = false) {
21594
+ const env = {};
21595
+ for (const key of SWIFT_COMPILER_ENV_KEYS) {
21596
+ const value = sourceEnv[key];
21597
+ if (value !== void 0) env[key] = value;
21598
+ }
21599
+ if (includePeachHome && sourceEnv.PEACH_HOME !== void 0)
21600
+ env.PEACH_HOME = sourceEnv.PEACH_HOME;
21601
+ if (process.platform === "linux") {
21602
+ env.LD_LIBRARY_PATH = [
21603
+ import_node_path47.default.resolve(toolchainBin, "../lib/swift/linux"),
21604
+ import_node_path47.default.resolve(toolchainBin, "../lib/swift/host"),
21605
+ sourceEnv.LD_LIBRARY_PATH
21606
+ ].filter(Boolean).join(":");
21607
+ }
21608
+ env.PEACH_DEFER_WASM_LINK = "1";
21609
+ return env;
21256
21610
  }
21257
21611
  function assertSwiftBuildCores() {
21258
21612
  const admitted = windowAdmission()?.cores ?? Number(process.env.TM_EXEC_CPU_CORES);
@@ -22448,10 +22802,22 @@ function emitSwiftPackageManifest(args) {
22448
22802
  const available = distribution.objects.filter(
22449
22803
  (object4) => !isProvider(object4) && !replacedObjects.has(object4)
22450
22804
  );
22805
+ const targetNamesWithDash = targets.filter((target) => target.name.includes("-")).map((target) => `lib/${target.name}-`);
22806
+ const targetNameSet = new Set(targets.map((target) => target.name));
22807
+ const optionalSet = /* @__PURE__ */ new Set([...OPTIONAL_FRAMEWORKS, ...GAME_FAMILY, "PeachBox2D"]);
22808
+ const isTargetObject = (object4) => {
22809
+ const dash = object4.indexOf("-", 4);
22810
+ if (dash > 4 && targetNameSet.has(object4.slice(4, dash))) return true;
22811
+ return targetNamesWithDash.some((prefix) => object4.startsWith(prefix));
22812
+ };
22813
+ const isUnreachedOptional = (object4) => {
22814
+ const dash = object4.indexOf("-", 4);
22815
+ if (dash <= 4) return false;
22816
+ const name3 = object4.slice(4, dash);
22817
+ return optionalSet.has(name3) && !reachedFrameworks.has(name3);
22818
+ };
22451
22819
  const objects = available.filter(
22452
- (object4) => !targets.some((target) => object4.startsWith(`lib/${target.name}-`)) && [...OPTIONAL_FRAMEWORKS, ...GAME_FAMILY, "PeachBox2D"].every(
22453
- (name3) => !object4.startsWith(`lib/${name3}-`) || reachedFrameworks.has(name3)
22454
- )
22820
+ (object4) => !isTargetObject(object4) && !isUnreachedOptional(object4)
22455
22821
  );
22456
22822
  const quoted2 = (object4) => `"${import_node_path47.default.join(moduleRoot, object4).replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
22457
22823
  const categoryObjects = new Set(
@@ -22532,18 +22898,53 @@ function emitSwiftPackageManifest(args) {
22532
22898
  args.files.set(file, content);
22533
22899
  return JSON.stringify([`@${file}`]);
22534
22900
  };
22535
- const frameworkDirectories = (name3, seen = /* @__PURE__ */ new Set()) => (siblings.get(name3) ?? []).flatMap((dependency) => {
22536
- if (seen.has(dependency)) return [];
22537
- seen.add(dependency);
22538
- const owner = args.targets.find((other) => other.name === dependency);
22901
+ const targetByName = new Map(targets.map((target) => [target.name, target]));
22902
+ const ownFrameworkDir = /* @__PURE__ */ new Map();
22903
+ for (const target of targets) {
22539
22904
  const framework = /^(.*)\/[^/]+\.framework\/Modules$/.exec(
22540
- owner?.publicHeadersPath ?? ""
22905
+ target.publicHeadersPath ?? ""
22541
22906
  );
22542
- return [
22543
- ...owner && framework ? [import_node_path47.default.posix.join(args.root, owner.path, framework[1])] : [],
22544
- ...frameworkDirectories(dependency, seen)
22545
- ];
22546
- });
22907
+ if (framework)
22908
+ ownFrameworkDir.set(
22909
+ target.name,
22910
+ import_node_path47.default.posix.join(args.root, target.path, framework[1])
22911
+ );
22912
+ }
22913
+ const frameworkDirectoriesCache = /* @__PURE__ */ new Map();
22914
+ const frameworkDirectories = (name3) => {
22915
+ if (ownFrameworkDir.size === 0) return [];
22916
+ const cached2 = frameworkDirectoriesCache.get(name3);
22917
+ if (cached2) return cached2;
22918
+ const dirs = [];
22919
+ const seen = /* @__PURE__ */ new Set();
22920
+ const visit = (current) => {
22921
+ for (const dependency of siblings.get(current) ?? []) {
22922
+ if (seen.has(dependency)) continue;
22923
+ seen.add(dependency);
22924
+ const dir = ownFrameworkDir.get(dependency);
22925
+ if (dir) dirs.push(dir);
22926
+ visit(dependency);
22927
+ }
22928
+ };
22929
+ visit(name3);
22930
+ frameworkDirectoriesCache.set(name3, dirs);
22931
+ return dirs;
22932
+ };
22933
+ const targetSwiftXccFlags = /* @__PURE__ */ new Map();
22934
+ for (const target of targets) {
22935
+ const flags = target.swiftFlags;
22936
+ if (!flags || flags.length === 0) continue;
22937
+ const xcc = [];
22938
+ for (let index = 1; index < flags.length; index++) {
22939
+ if (flags[index - 1] === "-Xcc")
22940
+ xcc.push(flags[index].replaceAll(SWIFT_NATIVE_INPUT_ROOT, args.root));
22941
+ }
22942
+ if (xcc.length > 0) targetSwiftXccFlags.set(target.name, xcc);
22943
+ }
22944
+ const binaryImports = args.binaryModules ? `, "-I", ${JSON.stringify(args.binaryModules)}` : "";
22945
+ const sharedImports = binaryImports + (distributionModules ? `, "-Isystem", ${JSON.stringify(
22946
+ providedModulesPath(args.root, distributionModules, args.moduleExcludes)
22947
+ )}${distributionClangModuleOptions(args.root, distributionModules).map((flag) => `, ${JSON.stringify(flag)}`).join("")}` : prebuilt ? `, "-Isystem", ${JSON.stringify(providedModulesPath(args.root, prebuilt.modules, args.moduleExcludes))}${prebuilt.moduleMaps.map((map) => `, "-Xcc", ${JSON.stringify(`-fmodule-map-file=${map}`)}`).join("")}` : "");
22547
22948
  const frameworkSearchFlags = (target, tool) => frameworkDirectories(target?.name ?? "").map((directory) => ({
22548
22949
  tool,
22549
22950
  flags: ["-F", directory]
@@ -22592,10 +22993,7 @@ function emitSwiftPackageManifest(args) {
22592
22993
  const upstream = (target.swiftFlags ?? []).map(
22593
22994
  (flag) => `, ${JSON.stringify(flag.replaceAll(SWIFT_NATIVE_INPUT_ROOT, args.root))}`
22594
22995
  ).join("");
22595
- const binaryImports = args.binaryModules ? `, "-I", ${JSON.stringify(args.binaryModules)}` : "";
22596
- const imports = binaryImports + (distributionModules ? `, "-Isystem", ${JSON.stringify(
22597
- providedModulesPath(args.root, distributionModules, args.moduleExcludes)
22598
- )}${distributionClangModuleOptions(args.root, distributionModules).map((flag) => `, ${JSON.stringify(flag)}`).join("")}` : prebuilt ? `, "-Isystem", ${JSON.stringify(providedModulesPath(args.root, prebuilt.modules, args.moduleExcludes))}${prebuilt.moduleMaps.map((map) => `, "-Xcc", ${JSON.stringify(`-fmodule-map-file=${map}`)}`).join("")}` : "");
22996
+ const imports = sharedImports;
22599
22997
  const nativeFlags = [
22600
22998
  ...args.nativeFlags?.get(target.name) ?? [],
22601
22999
  ...args.nativeHeaderFlags ?? []
@@ -22619,12 +23017,7 @@ function emitSwiftPackageManifest(args) {
22619
23017
  return map ? ["-fmodule-map-file=" + map] : [];
22620
23018
  }),
22621
23019
  ...[...importContext].flatMap((name3) => args.native?.get(name3)?.importFlags ?? []),
22622
- ...[...importContext].flatMap((name3) => {
22623
- const flags = targets.find((target2) => target2.name === name3)?.swiftFlags ?? [];
22624
- return flags.flatMap(
22625
- (flag, index) => flags[index - 1] === "-Xcc" ? [flag.replaceAll(SWIFT_NATIVE_INPUT_ROOT, args.root)] : []
22626
- );
22627
- })
23020
+ ...[...importContext].flatMap((name3) => targetSwiftXccFlags.get(name3) ?? [])
22628
23021
  ];
22629
23022
  const nativeImportFlags = [
22630
23023
  ...frameworkDirectories(target.name).flatMap((directory) => ["-F", directory]),
@@ -22639,9 +23032,7 @@ function emitSwiftPackageManifest(args) {
22639
23032
  ...native?.swiftFlags ?? [],
22640
23033
  ...args.objcImplementationModules?.has(target.name) ? ["-enable-experimental-feature", "ObjCImplementation"] : []
22641
23034
  ].map((flag) => `, ${JSON.stringify(flag)}`).join("");
22642
- const header = args.headerDirectory && (args.nativeHeaderDeclarations?.[target.name] || [...args.native?.values() ?? []].some(
22643
- (value) => value.late?.producers.includes(target.name)
22644
- )) ? `, "-emit-objc-header-path", ${JSON.stringify(import_node_path47.default.join(args.headerDirectory, `${target.name}-Swift.original.h`))}` : "";
23035
+ const header = args.headerDirectory && (args.nativeHeaderDeclarations?.[target.name] || lateProducers.has(target.name)) ? `, "-emit-objc-header-path", ${JSON.stringify(import_node_path47.default.join(args.headerDirectory, `${target.name}-Swift.original.h`))}` : "";
22645
23036
  const clangMode = target.cxxInterop ? "" : ', "-Xcc", "-fno-cxx-modules"';
22646
23037
  const deployment = `, "-Xfrontend", "-peach-ios-deployment-target", "-Xfrontend", ${JSON.stringify(target.iosDeploymentTarget ?? SWIFTPM_DEFAULT_IOS_DEPLOYMENT_TARGET)}`;
22647
23038
  const swiftSettings = `swiftSettings: [.swiftLanguageMode(.v${target.languageMode}),${isolation}${interoperability}${defines}${features}${upcoming} .unsafeFlags(${swiftFlagArray(`["-Osize", "-Xfrontend", "-enable-cross-import-overlays"${overlayFlags}${oneModule ? ONE_IMPLICIT_FLAGS : ""}${imports}${nativeImportFlags}${objcFlags}${header}${clangMode}${deployment}${upstream}]`)})]`;
@@ -22674,9 +23065,7 @@ function emitSwiftPackageManifest(args) {
22674
23065
  (dependency) => clang && // textual native headers can include one another without imposing
22675
23066
  // an object build order. the executable already links every native
22676
23067
  // target; only generated Swift headers require producer ordering.
22677
- (args.native?.get(dependency)?.clang || [...args.native?.values() ?? []].some(
22678
- (value) => value.late?.producers.includes(dependency)
22679
- )) ? [] : OPTIONAL_FRAMEWORKS.has(dependency) && !targets.some((candidate) => candidate.name === dependency) ? linkedObjects ? [] : [`.product(name: "${dependency}", package: "sootsim-swift")`] : [`"${dependency}"`]
23068
+ (args.native?.get(dependency)?.clang || lateProducers.has(dependency)) ? [] : OPTIONAL_FRAMEWORKS.has(dependency) && !targetNames.has(dependency) ? linkedObjects ? [] : [`.product(name: "${dependency}", package: "sootsim-swift")`] : [`"${dependency}"`]
22680
23069
  ),
22681
23070
  // a swift importer still needs the producers its clang dependencies
22682
23071
  // reached upstream, whose edges the clang targets above dropped.
@@ -22763,7 +23152,7 @@ function emitSwiftPackageManifest(args) {
22763
23152
  ...args.nativeFlags?.get(name3) ?? [],
22764
23153
  ...args.nativeHeaderFlags ?? []
22765
23154
  ];
22766
- const owner = targets.find((target) => target.name === name3);
23155
+ const owner = targetByName.get(name3);
22767
23156
  const context = /* @__PURE__ */ new Set();
22768
23157
  const visit = (dependency) => {
22769
23158
  if (context.has(dependency)) return;
@@ -22839,10 +23228,16 @@ ${declaration.replace(/,$/, "")}
22839
23228
  ""
22840
23229
  ].join("\n");
22841
23230
  }
22842
- function syncSwiftTree(base, files) {
23231
+ function syncSwiftTree(base, files, alreadySynced) {
22843
23232
  (0, import_node_fs45.mkdirSync)(base, { recursive: true });
22844
- const kept = /* @__PURE__ */ new Set();
22845
- for (const file of files.keys()) if ((0, import_node_fs45.existsSync)(file)) kept.add((0, import_node_fs45.statSync)(file).ino);
23233
+ let kept;
23234
+ if (process.platform !== "linux") {
23235
+ kept = /* @__PURE__ */ new Set();
23236
+ for (const file of files.keys()) {
23237
+ const stat = (0, import_node_fs45.statSync)(file, { throwIfNoEntry: false });
23238
+ if (stat) kept.add(stat.ino);
23239
+ }
23240
+ }
22846
23241
  const walk = (dir) => {
22847
23242
  for (const entry of (0, import_node_fs45.readdirSync)(dir, { withFileTypes: true })) {
22848
23243
  const full = import_node_path47.default.join(dir, entry.name);
@@ -22851,12 +23246,13 @@ function syncSwiftTree(base, files) {
22851
23246
  entry.name === CLANG_DISTRIBUTION_MODULES || entry.name === SWIFT_DISTRIBUTION_MIRROR || entry.name === SWIFT_LINK_STAMP))
22852
23247
  continue;
22853
23248
  if (entry.isDirectory()) walk(full);
22854
- else if (!files.has(full) && !kept.has((0, import_node_fs45.lstatSync)(full).ino))
23249
+ else if (!files.has(full) && (!kept || !kept.has((0, import_node_fs45.lstatSync)(full).ino)))
22855
23250
  (0, import_node_fs45.rmSync)(full, { force: true });
22856
23251
  }
22857
23252
  };
22858
23253
  walk(base);
22859
23254
  for (const [full, contents2] of files) {
23255
+ if (alreadySynced?.get(full) === contents2) continue;
22860
23256
  writeBuildFile(full, contents2);
22861
23257
  }
22862
23258
  }
@@ -22964,25 +23360,59 @@ function swiftWasmCallGuards(source, unavailable) {
22964
23360
  out = out.slice(0, at) + replacement + out.slice(at + width);
22965
23361
  return out;
22966
23362
  }
23363
+ function matchesPathPrefixSet(file, set) {
23364
+ if (set.has(file)) return true;
23365
+ for (let slash = file.lastIndexOf("/"); slash !== -1; slash = file.lastIndexOf("/", slash - 1)) {
23366
+ if (set.has(file.slice(0, slash))) return true;
23367
+ }
23368
+ return false;
23369
+ }
23370
+ function indexTargetsByDirectory(targets) {
23371
+ const byDir = /* @__PURE__ */ new Map();
23372
+ for (const target of targets) {
23373
+ const key = target.path === "." ? "" : target.path.replace(/\/+$/, "");
23374
+ let list = byDir.get(key);
23375
+ if (!list) byDir.set(key, list = []);
23376
+ list.push(target);
23377
+ }
23378
+ return byDir;
23379
+ }
23380
+ function findTargetForFile(file, byDir, predicate) {
23381
+ for (let slash = file.lastIndexOf("/"); slash !== -1; slash = file.lastIndexOf("/", slash - 1)) {
23382
+ const candidates = byDir.get(file.slice(0, slash));
23383
+ if (!candidates) continue;
23384
+ const relative = file.slice(slash + 1);
23385
+ for (const target of candidates) if (predicate(target, relative)) return target;
23386
+ }
23387
+ const rootCandidates = byDir.get("");
23388
+ if (rootCandidates) {
23389
+ for (const target of rootCandidates) if (predicate(target, file)) return target;
23390
+ }
23391
+ return void 0;
23392
+ }
22967
23393
  function compiledSwiftSources(files, targets, overlayFrameworks, headers, nativeSourceGlue = false) {
22968
23394
  const ordered = [...targets].sort((a, b) => b.path.length - a.path.length);
22969
- const owners = new Map(
22970
- Object.entries(files).filter(([file]) => file.endsWith(".swift")).map(([file, source]) => {
22971
- const owner = ordered.find((target) => {
22972
- const prefix = target.path === "." ? "" : target.path + "/";
22973
- if (!file.startsWith(prefix)) return false;
22974
- const relative = file.slice(prefix.length);
22975
- return !target.exclude?.some(
22976
- (excluded) => relative === excluded || relative.startsWith(excluded + "/")
22977
- );
22978
- });
22979
- return [file, { source, owner }];
22980
- })
22981
- );
23395
+ const byDir = indexTargetsByDirectory(ordered);
23396
+ const excludeSets = /* @__PURE__ */ new Map();
23397
+ for (const target of ordered) {
23398
+ if (target.exclude?.length) excludeSets.set(target.name, new Set(target.exclude));
23399
+ }
23400
+ const owners = /* @__PURE__ */ new Map();
23401
+ for (const [file, source] of Object.entries(files)) {
23402
+ if (!file.endsWith(".swift")) continue;
23403
+ const owner = findTargetForFile(file, byDir, (target, relative) => {
23404
+ const excluded = excludeSets.get(target.name);
23405
+ return !excluded || !matchesPathPrefixSet(relative, excluded);
23406
+ });
23407
+ owners.set(file, { source, owner });
23408
+ }
22982
23409
  const swiftSources = /* @__PURE__ */ new Map();
22983
- for (const { source, owner } of owners.values())
22984
- if (owner)
22985
- swiftSources.set(owner.name, [...swiftSources.get(owner.name) ?? [], source]);
23410
+ for (const { source, owner } of owners.values()) {
23411
+ if (!owner) continue;
23412
+ let list = swiftSources.get(owner.name);
23413
+ if (!list) swiftSources.set(owner.name, list = []);
23414
+ list.push(source);
23415
+ }
22986
23416
  const { onWasm, withoutWasm } = swiftTargetArchitectures(targets, swiftSources, headers);
22987
23417
  return new Map(
22988
23418
  [...owners].map(([file, { source, owner }]) => {
@@ -23830,18 +24260,46 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
23830
24260
  const bySourcePath = [...targets].sort(
23831
24261
  (left, right) => right.path.length - left.path.length
23832
24262
  );
24263
+ const targetsByDir = indexTargetsByDirectory(bySourcePath);
24264
+ const targetByName = new Map(targets.map((target) => [target.name, target]));
24265
+ const nativeTargets = input.nativeTargets ?? [];
24266
+ const nativeTargetByName = new Map(nativeTargets.map((target) => [target.name, target]));
24267
+ const nativeTargetIndex = new Map(
24268
+ nativeTargets.map((target, index) => [target.name, index])
24269
+ );
24270
+ const resourceTargetByName = new Map(
24271
+ resourceTargets.map((target) => [target.name, target])
24272
+ );
24273
+ const targetSourceSets = /* @__PURE__ */ new Map();
24274
+ const targetExcludeFullSets = /* @__PURE__ */ new Map();
24275
+ const targetExcludeExactSets = /* @__PURE__ */ new Map();
24276
+ for (const target of targets) {
24277
+ const prefix = target.path === "." ? "" : `${target.path}/`;
24278
+ if (target.sources !== void 0) {
24279
+ targetSourceSets.set(
24280
+ target.name,
24281
+ new Set(target.sources.map((source) => import_node_path47.default.posix.join(prefix, source)))
24282
+ );
24283
+ }
24284
+ if (target.exclude?.length) {
24285
+ targetExcludeFullSets.set(
24286
+ target.name,
24287
+ new Set(target.exclude.map((excluded) => `${prefix}${excluded}`))
24288
+ );
24289
+ targetExcludeExactSets.set(
24290
+ target.name,
24291
+ new Set(target.exclude.map((name3) => import_node_path47.default.posix.join(target.path, name3)))
24292
+ );
24293
+ }
24294
+ }
23833
24295
  const swiftTargets = /* @__PURE__ */ new Set();
23834
24296
  for (const file of Object.keys(input.files)) {
23835
24297
  if (!file.endsWith(".swift")) continue;
23836
- const target = bySourcePath.find(
23837
- (candidate) => (candidate.path === "." || file.startsWith(`${candidate.path}/`)) && (candidate.sources === void 0 || candidate.sources.some((source) => {
23838
- const selected = import_node_path47.default.posix.join(candidate.path, source);
23839
- return file === selected || file.startsWith(`${selected}/`);
23840
- }))
23841
- );
23842
- const excluded = target?.exclude?.some(
23843
- (name3) => file === import_node_path47.default.posix.join(target.path, name3)
23844
- );
24298
+ const target = findTargetForFile(file, targetsByDir, (candidate) => {
24299
+ const selected = targetSourceSets.get(candidate.name);
24300
+ return !selected || matchesPathPrefixSet(file, selected);
24301
+ });
24302
+ const excluded = target && targetExcludeExactSets.get(target.name)?.has(file);
23845
24303
  if (target && !excluded) swiftTargets.add(target.name);
23846
24304
  }
23847
24305
  const importedModules = /* @__PURE__ */ new Set();
@@ -23879,7 +24337,7 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
23879
24337
  checkedToolchain = swiftToolchain(pin.release, swiftModuleSdk(moduleRoot));
23880
24338
  return checkedToolchain;
23881
24339
  };
23882
- const deploymentTarget = (name3) => input.nativeTargets?.find((value) => value.name === name3)?.deploymentTarget ?? targets.find((value) => value.name === name3)?.iosDeploymentTarget ?? null;
24340
+ const deploymentTarget = (name3) => nativeTargetByName.get(name3)?.deploymentTarget ?? targetByName.get(name3)?.iosDeploymentTarget ?? null;
23883
24341
  const targetStagedFiles = /* @__PURE__ */ new Map();
23884
24342
  const stageTargetFile = (target, file, contents2, options) => {
23885
24343
  const relative = import_node_path47.default.relative(layout2.root, file).split(import_node_path47.default.sep).join(import_node_path47.default.posix.sep);
@@ -23891,18 +24349,41 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
23891
24349
  targetStagedFiles.set(target, staged);
23892
24350
  files.set(file, contents2);
23893
24351
  };
24352
+ const entriesByPrefix = /* @__PURE__ */ new Map();
24353
+ for (const target of targets) {
24354
+ const prefix = target.path === "." ? "" : `${target.path}/`;
24355
+ if (!entriesByPrefix.has(prefix)) entriesByPrefix.set(prefix, []);
24356
+ }
24357
+ for (const entry of Object.entries(input.files)) {
24358
+ const [file] = entry;
24359
+ entriesByPrefix.get("")?.push(entry);
24360
+ for (let end = file.indexOf("/"); end !== -1; end = file.indexOf("/", end + 1)) {
24361
+ entriesByPrefix.get(file.slice(0, end + 1))?.push(entry);
24362
+ }
24363
+ }
24364
+ const targetEntriesCache = /* @__PURE__ */ new Map();
23894
24365
  const targetEntries = (target) => {
24366
+ const cached2 = targetEntriesCache.get(target.name);
24367
+ if (cached2) return cached2;
23895
24368
  const prefix = target.path === "." ? "" : `${target.path}/`;
23896
- return Object.entries(input.files).filter(
23897
- ([file]) => file.startsWith(prefix) && (target.sources === void 0 || !(file.endsWith(".swift") || isSwiftNativeTranslationUnit(file)) || target.sources.some((source) => {
23898
- const selected = import_node_path47.default.posix.join(prefix, source);
23899
- return file === selected || file.startsWith(`${selected}/`);
23900
- })) && !target.exclude?.some(
23901
- (excluded) => file === `${prefix}${excluded}` || file.startsWith(`${prefix}${excluded}/`)
23902
- ) && !targets.some(
23903
- (candidate) => candidate.name !== target.name && candidate.path !== "." && candidate.path.startsWith(prefix) && file.startsWith(`${candidate.path}/`)
23904
- )
23905
- );
24369
+ const selectedSources = targetSourceSets.get(target.name);
24370
+ const excludedPaths = targetExcludeFullSets.get(target.name);
24371
+ const nestedPrefixes = [];
24372
+ for (const candidate of targets) {
24373
+ if (candidate.name !== target.name && candidate.path !== "." && candidate.path.startsWith(prefix))
24374
+ nestedPrefixes.push(`${candidate.path}/`);
24375
+ }
24376
+ const matched = (entriesByPrefix.get(prefix) ?? []).filter(([file]) => {
24377
+ if (selectedSources !== void 0 && (file.endsWith(".swift") || isSwiftNativeTranslationUnit(file)) && !matchesPathPrefixSet(file, selectedSources))
24378
+ return false;
24379
+ if (excludedPaths !== void 0 && matchesPathPrefixSet(file, excludedPaths))
24380
+ return false;
24381
+ if (nestedPrefixes.length > 0 && nestedPrefixes.some((p) => file.startsWith(p)))
24382
+ return false;
24383
+ return true;
24384
+ });
24385
+ targetEntriesCache.set(target.name, matched);
24386
+ return matched;
23906
24387
  };
23907
24388
  const failTargetPreparation = (target, message) => {
23908
24389
  const prefix = target.path === "." ? "" : `${target.path}/`;
@@ -23947,19 +24428,21 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
23947
24428
  return value;
23948
24429
  };
23949
24430
  const podHeaders = /* @__PURE__ */ new Map();
23950
- for (const settings of input.nativeTargets ?? [])
24431
+ for (const settings of nativeTargets)
23951
24432
  for (const file of settings.headers) {
23952
24433
  const owner = /\/Headers\/(?:Public|Private)\/([\w+-]+)\/(?:\1\/)?[^/]+\.h$/.exec(
23953
24434
  file
23954
24435
  )?.[1];
23955
- if (owner)
23956
- podHeaders.set(import_node_path47.default.basename(file), [
23957
- ...podHeaders.get(import_node_path47.default.basename(file)) ?? [],
23958
- { owner, content: input.files[file] }
23959
- ]);
24436
+ if (owner) {
24437
+ const base = import_node_path47.default.basename(file);
24438
+ let list = podHeaders.get(base);
24439
+ if (!list) podHeaders.set(base, list = []);
24440
+ list.push({ owner, content: input.files[file] });
24441
+ }
23960
24442
  }
23961
24443
  const podHeaderOwner = (file, content) => /\/Headers\/(?:Public|Private)\/([\w+-]+)\//.exec(file)?.[1] ?? podHeaders.get(import_node_path47.default.basename(file))?.find((header) => header.content === content)?.owner;
23962
- for (const settings of input.nativeTargets ?? []) {
24444
+ const alreadySynced = /* @__PURE__ */ new Map();
24445
+ for (const settings of nativeTargets) {
23963
24446
  for (const file of settings.headers) {
23964
24447
  const destination = import_node_path47.default.join(layout2.root, file);
23965
24448
  if (files.has(destination)) continue;
@@ -23976,10 +24459,10 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
23976
24459
  `#import <${interfaceOwner}/${interfaceOwner}-Swift.h>`
23977
24460
  ) : rawContents;
23978
24461
  writeBuildFile(destination, contents2);
24462
+ alreadySynced.set(destination, contents2);
23979
24463
  files.set(destination, contents2);
23980
24464
  }
23981
24465
  }
23982
- const nativeTargets = input.nativeTargets ?? [];
23983
24466
  const fromInputRoot = (file) => file.startsWith(`${SWIFT_NATIVE_INPUT_ROOT}/`) ? import_node_path47.default.join(layout2.root, file.slice(SWIFT_NATIVE_INPUT_ROOT.length + 1)) : file;
23984
24467
  const inRoot = `${layout2.root}${import_node_path47.default.sep}`;
23985
24468
  const binaryTree = `${import_node_path47.default.sep}${SWIFT_BINARY_TREES_DIR}${import_node_path47.default.sep}`;
@@ -24044,12 +24527,10 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
24044
24527
  const prefix = target.path === "." ? "" : `${target.path}/`;
24045
24528
  const entries2 = targetEntries(target);
24046
24529
  const units = entries2.filter(([file]) => isSwiftNativeTranslationUnit(file));
24047
- if (units.length === 0 && !(entries2.some(([file]) => file.endsWith(".swift")) && input.nativeTargets?.some(
24048
- (settings2) => settings2.name === target.name && (settings2.publicHeaders.length > 0 || settings2.bridgingHeader !== null)
24049
- )))
24530
+ const settings = nativeTargetByName.get(target.name);
24531
+ if (units.length === 0 && !(entries2.some(([file]) => file.endsWith(".swift")) && settings !== void 0 && (settings.publicHeaders.length > 0 || settings.bridgingHeader !== null)))
24050
24532
  continue;
24051
24533
  const includes = `${prefix}include/`;
24052
- const settings = input.nativeTargets?.find((value) => value.name === target.name);
24053
24534
  const searchRoots = [
24054
24535
  ...settings?.userHeaderSearchPaths ?? [],
24055
24536
  ...settings?.headerSearchPaths ?? [],
@@ -24080,7 +24561,9 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
24080
24561
  ...searchRoots.map((root) => import_node_path47.default.posix.join(root, include))
24081
24562
  ].find((candidate) => input.files[candidate] !== void 0);
24082
24563
  if (local) {
24083
- reverse.set(local, [...reverse.get(local) ?? [], file]);
24564
+ let parents = reverse.get(local);
24565
+ if (!parents) reverse.set(local, parents = []);
24566
+ parents.push(file);
24084
24567
  if (xcodeTarget && !seenHeaders.has(local)) {
24085
24568
  seenHeaders.add(local);
24086
24569
  searchEntries.push([local, input.files[local]]);
@@ -24126,9 +24609,10 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
24126
24609
  const stageFlags = (flags2, sdkInclude2) => flags2.map(
24127
24610
  (flag) => flag.replaceAll(SWIFT_NATIVE_INPUT_ROOT, layout2.root).replaceAll(SWIFT_NATIVE_SDK_INCLUDE, sdkInclude2)
24128
24611
  );
24612
+ const settingsHeaderFlags = headerSearch.flags[nativeTargetIndex.get(settings.name)];
24129
24613
  const originalFlags = [
24130
24614
  ...settings.flags,
24131
- ...headerSearch.flags[nativeTargets.indexOf(settings)],
24615
+ ...settingsHeaderFlags,
24132
24616
  ...search,
24133
24617
  ...(settings?.frameworkSearchPaths ?? []).flatMap((dir) => [
24134
24618
  "-F",
@@ -24139,7 +24623,7 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
24139
24623
  ];
24140
24624
  const importOriginalFlags = settings.flattensPublicHeaders ? [
24141
24625
  ...settings.importerFlags,
24142
- ...headerSearch.flags[nativeTargets.indexOf(settings)],
24626
+ ...settingsHeaderFlags,
24143
24627
  ...search,
24144
24628
  ...settings.frameworkSearchPaths.flatMap((dir) => [
24145
24629
  "-F",
@@ -24164,7 +24648,7 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
24164
24648
  }
24165
24649
  return [
24166
24650
  ...kept,
24167
- ...headerSearch.flags[nativeTargets.indexOf(settings)],
24651
+ ...settingsHeaderFlags,
24168
24652
  ...search,
24169
24653
  ...(settings?.frameworkSearchPaths ?? []).flatMap((dir) => [
24170
24654
  "-F",
@@ -24193,7 +24677,7 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
24193
24677
  const bundleName = entries2.some(([file]) => file.endsWith(".swift")) ? void 0 : swiftObjCResourceBundleName({
24194
24678
  target: target.name,
24195
24679
  path: target.path,
24196
- resources: resourceTargets.find((candidate) => candidate.name === target.name)?.resources ?? false,
24680
+ resources: resourceTargetByName.get(target.name)?.resources ?? false,
24197
24681
  usesBundleMacro: entries2.some(
24198
24682
  ([file, contents2]) => (isSwiftNativeTranslationUnit(file) || /\.(?:h|hpp|hh|hxx)$/.test(file)) && /\bSWIFTPM_MODULE_BUNDLE\b/.test(contents2)
24199
24683
  ),
@@ -24346,10 +24830,7 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
24346
24830
  .../\.mm?$/.test(file) ? ["-fobjc-exceptions"] : [],
24347
24831
  ...stageFlags(
24348
24832
  [...objcCxx ? settings.cxxFlags : [], ...fileFlags],
24349
- import_node_path47.default.join(
24350
- swiftSdkPaths(moduleRoot, toolchainBin).sysroot,
24351
- "darwin/usr/include"
24352
- )
24833
+ sdkInclude
24353
24834
  )
24354
24835
  ];
24355
24836
  const moduleFlag = perFile.some((flag) => flag.startsWith("-fmodule-name=")) ? [] : [`-fmodule-name=${swiftTargetModuleName(target.name)}`];
@@ -24389,13 +24870,7 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
24389
24870
  ...flags,
24390
24871
  ...prefixHeader,
24391
24872
  ...accessorFlags,
24392
- ...stageFlags(
24393
- cxx ? settings.cxxFlags : [],
24394
- import_node_path47.default.join(
24395
- swiftSdkPaths(moduleRoot, toolchainBin).sysroot,
24396
- "darwin/usr/include"
24397
- )
24398
- ),
24873
+ ...stageFlags(cxx ? settings.cxxFlags : [], sdkInclude),
24399
24874
  ...perFile,
24400
24875
  ...moduleFlag
24401
24876
  ]
@@ -24650,7 +25125,9 @@ module ${moduleName}.Swift {
24650
25125
  }
24651
25126
  ` : swiftObjCModuleMap(
24652
25127
  moduleName,
24653
- (input.nativeTargets?.find((target) => target.name === name3)?.publicHeaders ?? []).map((header) => import_node_path47.default.join(layout2.root, header)),
25128
+ (nativeTargetByName.get(name3)?.publicHeaders ?? []).map(
25129
+ (header) => import_node_path47.default.join(layout2.root, header)
25130
+ ),
24654
25131
  submoduleImports2.get(moduleName),
24655
25132
  import_node_path47.default.join(headerDirectory, name3 + "-Swift.h")
24656
25133
  )
@@ -25200,6 +25677,7 @@ ${entry}`);
25200
25677
  files.set(destination, Buffer.from(bytes, "base64"));
25201
25678
  }
25202
25679
  const targetToolset = nativeToolset || native.size > 0;
25680
+ let usesObjcPrebuilt = false;
25203
25681
  if (targetToolset) {
25204
25682
  const nativeToolsetFlags = [
25205
25683
  ...headerAliasFlags,
@@ -25220,6 +25698,7 @@ ${entry}`);
25220
25698
  [...native.keys()],
25221
25699
  objcPrebuiltStage
25222
25700
  ) : [];
25701
+ usesObjcPrebuilt = prebuiltCompiler.length > 0;
25223
25702
  files.set(
25224
25703
  clangWrapper2,
25225
25704
  [
@@ -25528,17 +26007,39 @@ package.targets += [.target(name: ${JSON.stringify(name3)}, dependencies: ${JSON
25528
26007
  (name3) => !nativePrerequisiteSet.has(name3)
25529
26008
  );
25530
26009
  const nativeTargetUnitCount = /* @__PURE__ */ new Map();
26010
+ const nativeTargetSources = /* @__PURE__ */ new Map();
25531
26011
  for (const target of manifestTargets)
25532
- if (target.sources?.length)
26012
+ if (target.sources?.length) {
25533
26013
  nativeTargetUnitCount.set(target.name, target.sources.length);
26014
+ nativeTargetSources.set(target.name, target.sources);
26015
+ }
25534
26016
  for (const [name3, plan] of native) {
25535
- if (!plan.mixed && plan.sources.length > 0)
25536
- nativeTargetUnitCount.set(name3, plan.clang?.sources.length ?? plan.sources.length);
25537
- for (const group of plan.groups ?? [])
26017
+ if (!plan.mixed && plan.sources.length > 0) {
26018
+ const sources = plan.clang?.sources ?? plan.sources;
26019
+ nativeTargetUnitCount.set(name3, sources.length);
26020
+ nativeTargetSources.set(name3, sources);
26021
+ }
26022
+ for (const group of plan.groups ?? []) {
25538
26023
  nativeTargetUnitCount.set(group.name, group.sources.length);
25539
- if (plan.late && !plan.groups?.length)
26024
+ nativeTargetSources.set(group.name, group.sources);
26025
+ }
26026
+ if (plan.late && !plan.groups?.length) {
25540
26027
  nativeTargetUnitCount.set(plan.late.name, plan.sources.length);
26028
+ nativeTargetSources.set(plan.late.name, plan.lateSources);
26029
+ }
25541
26030
  }
26031
+ const nativeStageObjects = /* @__PURE__ */ new Map();
26032
+ const recordStageObjects = (stageTarget, members) => {
26033
+ const objects = [];
26034
+ for (const member of members) {
26035
+ const sources = nativeTargetSources.get(member);
26036
+ if (!sources || sources.length === 0) return stageTarget;
26037
+ for (const source of sources)
26038
+ objects.push(import_node_path47.default.join(`${member}.build`, `${source}.o`));
26039
+ }
26040
+ nativeStageObjects.set(stageTarget, objects);
26041
+ return stageTarget;
26042
+ };
25542
26043
  const MAX_NATIVE_STAGE_UNITS = 250;
25543
26044
  const chunkNativeStageTargets = (prefix, names) => {
25544
26045
  if (names.length === 0) return [];
@@ -25547,7 +26048,7 @@ package.targets += [.target(name: ${JSON.stringify(name3)}, dependencies: ${JSON
25547
26048
  0
25548
26049
  );
25549
26050
  if (names.length === 1 || total <= MAX_NATIVE_STAGE_UNITS)
25550
- return [buildProduct(prefix, names)];
26051
+ return [recordStageObjects(buildProduct(prefix, names), names)];
25551
26052
  const chunks = [];
25552
26053
  let current = [];
25553
26054
  let count = 0;
@@ -25562,7 +26063,9 @@ package.targets += [.target(name: ${JSON.stringify(name3)}, dependencies: ${JSON
25562
26063
  count += size;
25563
26064
  }
25564
26065
  if (current.length > 0) chunks.push(current);
25565
- return chunks.map((members, index) => buildProduct(`${prefix}${index + 1}`, members));
26066
+ return chunks.map(
26067
+ (members, index) => recordStageObjects(buildProduct(`${prefix}${index + 1}`, members), members)
26068
+ );
25566
26069
  };
25567
26070
  const nativePrerequisiteStageTargets = chunkNativeStageTargets(
25568
26071
  "PeachHeaderNativePrereqs",
@@ -25573,7 +26076,7 @@ package.targets += [.target(name: ${JSON.stringify(name3)}, dependencies: ${JSON
25573
26076
  remainingNativeBuildTargets
25574
26077
  );
25575
26078
  files.set(manifestPath, manifest);
25576
- syncSwiftTree(layout2.root, files);
26079
+ syncSwiftTree(layout2.root, files, alreadySynced);
25577
26080
  if (layout2.multi)
25578
26081
  for (const target of targets)
25579
26082
  (0, import_node_fs45.mkdirSync)(import_node_path47.default.join(layout2.root, target.path), { recursive: true });
@@ -25588,7 +26091,9 @@ package.targets += [.target(name: ${JSON.stringify(name3)}, dependencies: ${JSON
25588
26091
  targetFailures,
25589
26092
  generatedOwners,
25590
26093
  targetToolset,
25591
- headerCompiler
26094
+ headerCompiler,
26095
+ usesObjcPrebuilt,
26096
+ nativeStageObjects
25592
26097
  };
25593
26098
  }
25594
26099
  function streamText(value) {
@@ -26674,8 +27179,8 @@ ${cap}` : "";
26674
27179
  work,
26675
27180
  unoptimized
26676
27181
  );
26677
- const baseBuildEnv = {
26678
- ...options.project?.env ?? process.env,
27182
+ const baseBuildEnv = options.project?.env ? {
27183
+ ...options.project.env,
26679
27184
  // shipped host plugins resolve against the selected compiler's runtime.
26680
27185
  ...process.platform === "linux" ? {
26681
27186
  LD_LIBRARY_PATH: [
@@ -26685,7 +27190,7 @@ ${cap}` : "";
26685
27190
  ].filter(Boolean).join(":")
26686
27191
  } : {},
26687
27192
  PEACH_DEFER_WASM_LINK: "1"
26688
- };
27193
+ } : swiftCompilerBaseEnv(options.toolchainBin, process.env);
26689
27194
  const {
26690
27195
  frameworkRoot,
26691
27196
  compileFrameworkRoot,
@@ -26829,7 +27334,11 @@ ${cap}` : "";
26829
27334
  } : {
26830
27335
  ...buildOptions,
26831
27336
  temporaryDirectory,
26832
- env: { ...buildOptions.env, ...compiler }
27337
+ env: {
27338
+ ...buildOptions.env,
27339
+ ...preparation.usesObjcPrebuilt && process.env.PEACH_HOME !== void 0 ? { PEACH_HOME: process.env.PEACH_HOME } : {},
27340
+ ...compiler
27341
+ }
26833
27342
  };
26834
27343
  const unprepared = preparation.targetFailures.map(
26835
27344
  (failure) => `error: target ${failure}`
@@ -26876,10 +27385,18 @@ ${cap}` : "";
26876
27385
  // the mirror finds a changed sdk header's readers in their
26877
27386
  // dependency files, which omit system headers by default
26878
27387
  ...mirrorDistribution ? ["-Xswiftc", "-track-system-dependencies"] : [],
26879
- // the link strips debug info, so none is generated (as for the framework)
27388
+ // the link strips debug info, so none is generated (as for the framework).
27389
+ // keep -num-threads fixed across caller core caps so llbuild does not
27390
+ // rebuild every target when callers alternate --cores, and bound backend
27391
+ // fan-out under high -j.
26880
27392
  "-Xswiftc",
26881
27393
  "-gnone",
26882
- ...incrementalPreview ? [] : ["-Xswiftc", "-num-threads", "-Xswiftc", String(perFile ? 1 : jobs)],
27394
+ ...incrementalPreview ? [] : [
27395
+ "-Xswiftc",
27396
+ "-num-threads",
27397
+ "-Xswiftc",
27398
+ String(perFile ? 1 : Math.min(8, import_node_os11.default.availableParallelism()))
27399
+ ],
26883
27400
  ...swiftReproducibleBuildFlags([
26884
27401
  [import_node_path47.default.dirname(options.toolchainBin), "toolchain"],
26885
27402
  [compileFrameworkRoot, "framework"],
@@ -27054,7 +27571,18 @@ ${cap}` : "";
27054
27571
  }))
27055
27572
  ];
27056
27573
  const checkpoints = import_node_path47.default.join(root, ".build", "peach-product-checkpoints");
27574
+ const buildDbExists = (0, import_node_fs45.existsSync)(import_node_path47.default.join(root, ".build", "build.db"));
27575
+ const releaseDir = import_node_path47.default.dirname(linked);
27057
27576
  for (const { target, producers } of stages) {
27577
+ if (!options.project && producers.length === 0 && buildDbExists) {
27578
+ const expectedObjects = preparation.nativeStageObjects.get(target);
27579
+ if (expectedObjects && expectedObjects.length > 0 && expectedObjects.every(
27580
+ (relative) => (0, import_node_fs45.statSync)(import_node_path47.default.join(releaseDir, relative), {
27581
+ throwIfNoEntry: false
27582
+ })?.isFile()
27583
+ ))
27584
+ continue;
27585
+ }
27058
27586
  const receipt = import_node_path47.default.join(
27059
27587
  checkpoints,
27060
27588
  (0, import_node_crypto29.createHash)("sha256").update(target).digest("hex")
@@ -27279,7 +27807,7 @@ ${cap}` : "";
27279
27807
  options.signal
27280
27808
  );
27281
27809
  }
27282
- var import_node_child_process28, import_node_crypto29, import_node_fs45, import_node_os11, import_node_path47, v6, WASM_TRIPLE, SWIFTPM_PROGRESS, SWIFTPM_NOISE, distributionManifests, distributionCompileViews, REACH_STAGED_FRAMEWORKS, objcEnumerations, clangDeclarationEnumCache, objcEnumForward, sdkDeclarationOwners, swiftInterfaceDeclarations, linkedModuleDigests, compileSurfaces, SYSTEM_MODULE_LIBRARIES, SYSTEM_MODULE_IMPORT, OPTIONAL_FRAMEWORK_DEPENDENCIES, OPTIONAL_FRAMEWORKS, SWIFT_IMPORT, kleeneNot, kleeneAnd, kleeneOr, NON_IOS_MODULES, sdkPaths, availableModules, sdkOverlayFrameworks, DISTRIBUTION_CLANG_MODULES, CLANG_DISTRIBUTION_MODULES, ONE_PRODUCT, GAME_FAMILY, gameProducts, gameProduct, GAME_REACH, FOUNDATION_IMPLICIT_MODULES, FRAMEWORK_COMPANION_IMPORT, 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, codeMasks, codeMaskChars, CODE_MASK_CACHE_CHARS, FOUNDATION_NETWORKING_TYPES, FOUNDATION_OVERLAY_TYPES, FOUNDATION_OVERLAY_GLOBALS, CORE_FOUNDATION_OVERLAY_GLOBALS, CORE_FOUNDATION_GEOMETRY_TYPES, CORE_FOUNDATION_GRAPHICS_TYPES, CORE_FOUNDATION_HANDLE_IMPORTS, emptyMacroEnvironment, wasmMacroEnvironment, 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;
27810
+ var import_node_child_process28, import_node_crypto29, import_node_fs45, import_node_os11, import_node_path47, v6, WASM_TRIPLE, SWIFTPM_PROGRESS, SWIFTPM_NOISE, SWIFT_COMPILER_ENV_KEYS, distributionManifests, distributionCompileViews, REACH_STAGED_FRAMEWORKS, objcEnumerations, clangDeclarationEnumCache, objcEnumForward, sdkDeclarationOwners, swiftInterfaceDeclarations, linkedModuleDigests, compileSurfaces, SYSTEM_MODULE_LIBRARIES, SYSTEM_MODULE_IMPORT, OPTIONAL_FRAMEWORK_DEPENDENCIES, OPTIONAL_FRAMEWORKS, SWIFT_IMPORT, kleeneNot, kleeneAnd, kleeneOr, NON_IOS_MODULES, sdkPaths, availableModules, sdkOverlayFrameworks, DISTRIBUTION_CLANG_MODULES, CLANG_DISTRIBUTION_MODULES, ONE_PRODUCT, GAME_FAMILY, gameProducts, gameProduct, GAME_REACH, FOUNDATION_IMPLICIT_MODULES, FRAMEWORK_COMPANION_IMPORT, 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, codeMasks, codeMaskChars, CODE_MASK_CACHE_CHARS, FOUNDATION_NETWORKING_TYPES, FOUNDATION_OVERLAY_TYPES, FOUNDATION_OVERLAY_GLOBALS, CORE_FOUNDATION_OVERLAY_GLOBALS, CORE_FOUNDATION_GEOMETRY_TYPES, CORE_FOUNDATION_GRAPHICS_TYPES, CORE_FOUNDATION_HANDLE_IMPORTS, emptyMacroEnvironment, wasmMacroEnvironment, 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;
27283
27811
  var init_swift_compile = __esm({
27284
27812
  "src/swift-compile.ts"() {
27285
27813
  import_node_child_process28 = require("node:child_process");
@@ -27331,6 +27859,29 @@ var init_swift_compile = __esm({
27331
27859
  WASM_TRIPLE = SWIFT_WASM_TRIPLE;
27332
27860
  SWIFTPM_PROGRESS = /^\[\d+\/\d+\] /;
27333
27861
  SWIFTPM_NOISE = /^(?:\[\d+\/\d+\] |Building for production\.\.\.$|warning: '--build-system native' has been deprecated)/;
27862
+ SWIFT_COMPILER_ENV_KEYS = [
27863
+ "PATH",
27864
+ "HOME",
27865
+ "USER",
27866
+ "LOGNAME",
27867
+ "LANG",
27868
+ "LC_ALL",
27869
+ "LC_CTYPE",
27870
+ "TZ",
27871
+ "SDKROOT",
27872
+ "DEVELOPER_DIR",
27873
+ "DYLD_LIBRARY_PATH",
27874
+ "SYSTEMROOT",
27875
+ "COMSPEC",
27876
+ "SSL_CERT_FILE",
27877
+ "SSL_CERT_DIR",
27878
+ "HTTP_PROXY",
27879
+ "HTTPS_PROXY",
27880
+ "NO_PROXY",
27881
+ "http_proxy",
27882
+ "https_proxy",
27883
+ "no_proxy"
27884
+ ];
27334
27885
  distributionManifests = /* @__PURE__ */ new Map();
27335
27886
  distributionCompileViews = /* @__PURE__ */ new WeakMap();
27336
27887
  REACH_STAGED_FRAMEWORKS = /* @__PURE__ */ new Set(["React"]);
@@ -27526,7 +28077,7 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
27526
28077
  REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
27527
28078
  MULTI_MANIFEST_VERSION = 76;
27528
28079
  SWIFT_HEADER_PRODUCTS_TARGET = "PeachHeaderProducts";
27529
- compilerSourceDigest = true ? "834b5c28c27bc5807cbb3c4eed5c44f7de81d47db3e3a8819bea6e6635689b24" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
28080
+ compilerSourceDigest = true ? "4d55fa7cbb29586c08e4e51867226f96047bae2103c89f4fa59d9cf3ed3862fb" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
27530
28081
  nativeCxxCompilerFlags = ["-fno-cxx-modules"];
27531
28082
  MODULE_MAP_RESPONSE_FILE_RUN = 16;
27532
28083
  cFlagArray = (flags) => JSON.stringify(withoutGlogModuleMap(flags));