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;
@@ -8464,8 +8464,14 @@ var init_podspec_ruby_stdlib = __esm({
8464
8464
 
8465
8465
  // src/write-build-file.ts
8466
8466
  function writeBuildFile(file, contents2) {
8467
- if ((0, import_node_fs15.existsSync)(file) && (typeof contents2 === "string" ? (0, import_node_fs15.readFileSync)(file, "utf8") === contents2 : (0, import_node_fs15.readFileSync)(file).equals(contents2)))
8468
- return;
8467
+ const stat = (0, import_node_fs15.statSync)(file, { throwIfNoEntry: false });
8468
+ if (stat?.isFile()) {
8469
+ if (typeof contents2 === "string") {
8470
+ if ((0, import_node_fs15.readFileSync)(file, "utf8") === contents2) return;
8471
+ } else if (stat.size === contents2.length && (0, import_node_fs15.readFileSync)(file).equals(contents2)) {
8472
+ return;
8473
+ }
8474
+ }
8469
8475
  (0, import_node_fs15.mkdirSync)(import_node_path12.default.dirname(file), { recursive: true });
8470
8476
  (0, import_node_fs15.writeFileSync)(file, contents2);
8471
8477
  }
@@ -26249,13 +26255,13 @@ var init_swift_standin_digest = __esm({
26249
26255
  STANDIN_DIGEST_ENTRYPOINTS = ["swift-standins.ts", "swift-objc-compile.ts"];
26250
26256
  SPECIFIER = /from\s*['"]([^'"]+)['"]|import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
26251
26257
  standinSourceDigest = (srcDir = __sootsim_import_meta_dirname) => sourceClosureDigest(srcDir, STANDIN_DIGEST_ENTRYPOINTS);
26252
- STANDIN_SOURCE_DIGEST = true ? "63adfed92cb0f03f7e74bd25588e866da41eaddd5ff8c13d50802edd65706617" : standinSourceDigest();
26258
+ STANDIN_SOURCE_DIGEST = true ? "803880cad876e27e4e621723b8eae85b3c486a882db0f0f745babaf80c070680" : standinSourceDigest();
26253
26259
  }
26254
26260
  });
26255
26261
 
26256
26262
  // src/expo-native-compiler-digest.ts
26257
26263
  function expoNativeCompilerDigestValue() {
26258
- return true ? "8d9cc2b3945c4c67d77156d4c44a7d06d014ce6884cbc3351e77b81e4d4318aa" : expoNativeCompilerDigest(__sootsim_import_meta_dirname);
26264
+ return true ? "4e04e854647f1a1e167543007b405e6d43a936b2b02d7be227ac14a5bcb224f9" : expoNativeCompilerDigest(__sootsim_import_meta_dirname);
26259
26265
  }
26260
26266
  var import_node_crypto17;
26261
26267
  var init_expo_native_compiler_digest = __esm({
@@ -32372,7 +32378,11 @@ function relocationEdges(bytes, segmentAddress) {
32372
32378
  const sections = wasmSections(bytes);
32373
32379
  const linking = sections.find((s) => s.name === "linking");
32374
32380
  if (!linking) throw new Error("relocation link has no linking section");
32375
- const symbols = [];
32381
+ let symKind = new Uint8Array(0);
32382
+ let symFlags = new Uint32Array(0);
32383
+ let symSegment = new Int32Array(0);
32384
+ let symOffset = new Int32Array(0);
32385
+ let symIndex = new Int32Array(0);
32376
32386
  const segmentNames = [];
32377
32387
  {
32378
32388
  const r = wasmReader(bytes, linking.start);
@@ -32380,27 +32390,31 @@ function relocationEdges(bytes, segmentAddress) {
32380
32390
  while (r.at < linking.end) {
32381
32391
  const type = r.byte();
32382
32392
  const end = r.u() + r.at;
32383
- if (type === 8)
32384
- for (let n = r.u(); n > 0; n--) {
32393
+ if (type === 8) {
32394
+ const count = r.u();
32395
+ symKind = new Uint8Array(count);
32396
+ symFlags = new Uint32Array(count);
32397
+ symSegment = new Int32Array(count).fill(-1);
32398
+ symOffset = new Int32Array(count);
32399
+ symIndex = new Int32Array(count).fill(-1);
32400
+ for (let i = 0; i < count; i++) {
32385
32401
  const kind = r.byte();
32386
32402
  const flags = r.u();
32387
- let segment2 = -1;
32388
- let offset = 0;
32389
- let index = -1;
32403
+ symKind[i] = kind;
32404
+ symFlags[i] = flags;
32390
32405
  if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
32391
- index = r.u();
32392
- if (!(flags & 16) || flags & 64) r.name();
32406
+ symIndex[i] = r.u();
32407
+ if (!(flags & 16) || flags & 64) r.skip(r.u());
32393
32408
  } else if (kind === 1) {
32394
- r.name();
32409
+ r.skip(r.u());
32395
32410
  if (!(flags & 16)) {
32396
- segment2 = r.u();
32397
- offset = r.u();
32411
+ symSegment[i] = r.u();
32412
+ symOffset[i] = r.u();
32398
32413
  r.u();
32399
32414
  }
32400
32415
  } else if (kind === 3) r.u();
32401
- symbols.push({ kind, flags, segment: segment2, offset, index });
32402
32416
  }
32403
- else if (type === 5)
32417
+ } else if (type === 5)
32404
32418
  for (let n = r.u(); n > 0; n--) {
32405
32419
  segmentNames.push(r.name());
32406
32420
  r.u();
@@ -32439,37 +32453,66 @@ function relocationEdges(bytes, segmentAddress) {
32439
32453
  const importedFunctions = readModule(bytes).importedFuncs;
32440
32454
  const data = [];
32441
32455
  const dataFunctions = [];
32442
- const code = bodyStarts.map(() => []);
32443
- const calls = bodyStarts.map(() => []);
32456
+ const bodyCount = bodyStarts.length;
32457
+ const code = Array.from({ length: bodyCount }, () => []);
32458
+ const calls = Array.from({ length: bodyCount }, () => []);
32444
32459
  for (const s of sections) {
32445
32460
  if (!s.name?.startsWith("reloc.")) continue;
32446
- const r = wasmReader(bytes, s.start);
32447
- const target = r.u();
32461
+ let cur = s.start;
32462
+ const readU = () => {
32463
+ const b0 = bytes[cur++];
32464
+ if (b0 < 128) return b0;
32465
+ let value = b0 & 127;
32466
+ let shift = 7;
32467
+ for (; ; ) {
32468
+ const byte = bytes[cur++];
32469
+ value += (byte & 127) * 2 ** shift;
32470
+ if (byte < 128) return value;
32471
+ shift += 7;
32472
+ }
32473
+ };
32474
+ const readS = () => {
32475
+ const b0 = bytes[cur++];
32476
+ if (b0 < 128) return b0 & 64 ? b0 - 128 : b0;
32477
+ let value = b0 & 127;
32478
+ let shift = 7;
32479
+ let byte = b0;
32480
+ while (byte >= 128) {
32481
+ byte = bytes[cur++];
32482
+ value += (byte & 127) * 2 ** shift;
32483
+ shift += 7;
32484
+ }
32485
+ if (byte & 64) value -= 2 ** shift;
32486
+ return value;
32487
+ };
32488
+ const target = readU();
32448
32489
  if (target !== dataIndex && target !== codeIndex) continue;
32449
32490
  let segment2 = 0;
32450
32491
  let body = 0;
32451
- for (let n = r.u(); n > 0; n--) {
32452
- const type = r.byte();
32453
- const offset = r.u();
32454
- const index = r.u();
32455
- const addend = ADDEND_RELOCATIONS.has(type) ? Number(r.s()) : 0;
32456
- const functionRelocation = FUNCTION_RELOCATIONS.has(type);
32457
- const memoryRelocation = MEMORY_RELOCATIONS.has(type);
32492
+ const isData = target === dataIndex;
32493
+ for (let n = readU(); n > 0; n--) {
32494
+ const type = bytes[cur++];
32495
+ const offset = readU();
32496
+ const index = readU();
32497
+ const bit = type < 32 ? 1 << type : 0;
32498
+ const addend = (ADDEND_RELOC_MASK & bit) !== 0 ? readS() : 0;
32499
+ const functionRelocation = (FUNCTION_RELOC_MASK & bit) !== 0;
32500
+ const memoryRelocation = (MEMORY_RELOC_MASK & bit) !== 0;
32458
32501
  if (!functionRelocation && !memoryRelocation) continue;
32459
- const symbol2 = symbols[index];
32460
- const functionReference = functionRelocation && symbol2.kind === 0;
32461
- if (symbol2.flags & 16) continue;
32462
- if (!functionReference && (!memoryRelocation || symbol2.kind !== 1 || symbol2.segment < 0))
32502
+ if (symFlags[index] & 16) continue;
32503
+ const kind = symKind[index];
32504
+ const functionReference = functionRelocation && kind === 0;
32505
+ if (!functionReference && (!memoryRelocation || kind !== 1 || symSegment[index] < 0))
32463
32506
  continue;
32464
- const to = functionReference ? symbol2.index - importedFunctions : addresses[symbol2.segment] + symbol2.offset + addend;
32465
- if (functionReference && (to < 0 || to >= bodyStarts.length)) continue;
32466
- if (target === dataIndex) {
32507
+ const to = functionReference ? symIndex[index] - importedFunctions : addresses[symSegment[index]] + symOffset[index] + addend;
32508
+ if (functionReference && (to < 0 || to >= bodyCount)) continue;
32509
+ if (isData) {
32467
32510
  while (payloads[segment2].end <= offset) segment2++;
32468
32511
  const payload = payloads[segment2];
32469
32512
  const edges = functionReference ? dataFunctions : data;
32470
32513
  edges.push(payload.address + offset - payload.start, to);
32471
32514
  } else {
32472
- while (body + 1 < bodyStarts.length && bodyStarts[body + 1] <= offset) body++;
32515
+ while (body + 1 < bodyCount && bodyStarts[body + 1] <= offset) body++;
32473
32516
  const edges = functionReference ? calls : code;
32474
32517
  edges[body].push(to);
32475
32518
  }
@@ -32525,7 +32568,7 @@ function unslottedFunctions(bytes) {
32525
32568
  const slotted = new Set([...m.slots.keys()].filter((index) => index >= m.importedFuncs));
32526
32569
  return m.bodies.length - slotted.size;
32527
32570
  }
32528
- var uleb, sleb, encodedName, section, PROCESS_EXPORTS, SWIFT_SDK_CONSTRUCTOR_LIMIT, FUNCTION_RELOCATIONS, MEMORY_RELOCATIONS, ADDEND_RELOCATIONS;
32571
+ 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;
32529
32572
  var init_swift_sdk_image_wasm = __esm({
32530
32573
  "src/swift-sdk-image-wasm.ts"() {
32531
32574
  "use strict";
@@ -32595,6 +32638,12 @@ var init_swift_sdk_image_wasm = __esm({
32595
32638
  25,
32596
32639
  27
32597
32640
  ]);
32641
+ FUNCTION_RELOC_MASK = 0;
32642
+ for (const type of FUNCTION_RELOCATIONS) FUNCTION_RELOC_MASK |= 1 << type;
32643
+ MEMORY_RELOC_MASK = 0;
32644
+ for (const type of MEMORY_RELOCATIONS) MEMORY_RELOC_MASK |= 1 << type;
32645
+ ADDEND_RELOC_MASK = 0;
32646
+ for (const type of ADDEND_RELOCATIONS) ADDEND_RELOC_MASK |= 1 << type;
32598
32647
  }
32599
32648
  });
32600
32649
 
@@ -32762,7 +32811,8 @@ function isRootSegName(name3) {
32762
32811
  return false;
32763
32812
  }
32764
32813
  function decodeRelocations(buf, sections) {
32765
- const count = sections.reduce((sum, section2) => sum + section2.count, 0);
32814
+ let count = 0;
32815
+ for (let s = 0; s < sections.length; s++) count += sections[s].count;
32766
32816
  const start = new Uint32Array(count);
32767
32817
  const end = new Uint32Array(count);
32768
32818
  const ro = new Int32Array(count);
@@ -32771,29 +32821,59 @@ function decodeRelocations(buf, sections) {
32771
32821
  const spans = [];
32772
32822
  let i = 0;
32773
32823
  let length = 0;
32774
- for (const section2 of sections) {
32775
- let cur = section2.at;
32776
- for (let k = 0; k < section2.count; k++, i++) {
32777
- start[i] = length + cur - section2.at;
32824
+ for (let s = 0; s < sections.length; s++) {
32825
+ const section2 = sections[s];
32826
+ const baseAt = section2.at;
32827
+ const sectionCount = section2.count;
32828
+ let cur = baseAt;
32829
+ for (let k = 0; k < sectionCount; k++, i++) {
32830
+ start[i] = length + cur - baseAt;
32778
32831
  const rType = buf[cur++];
32779
- const [offset, c2] = readULEB2(buf, cur);
32780
- const [symbol2, c3] = readULEB2(buf, c2);
32781
- cur = c3;
32782
- if (ADDEND_RELOCATIONS.has(rType)) {
32783
- const [value, c4] = readSLEB(buf, cur);
32832
+ let offset = buf[cur++];
32833
+ if (offset >= 128) {
32834
+ offset &= 127;
32835
+ let shift = 7;
32836
+ while (true) {
32837
+ const byte = buf[cur++];
32838
+ offset |= (byte & 127) << shift;
32839
+ if (byte < 128) break;
32840
+ shift += 7;
32841
+ }
32842
+ }
32843
+ let symbol2 = buf[cur++];
32844
+ if (symbol2 >= 128) {
32845
+ symbol2 &= 127;
32846
+ let shift = 7;
32847
+ while (true) {
32848
+ const byte = buf[cur++];
32849
+ symbol2 |= (byte & 127) << shift;
32850
+ if (byte < 128) break;
32851
+ shift += 7;
32852
+ }
32853
+ }
32854
+ if (rType < 32 && (ADDEND_RELOC_MASK2 & 1 << rType) !== 0) {
32855
+ let byte = buf[cur++];
32856
+ let value = byte & 127;
32857
+ let shift = 7;
32858
+ while (byte >= 128) {
32859
+ byte = buf[cur++];
32860
+ value |= (byte & 127) << shift;
32861
+ shift += 7;
32862
+ }
32863
+ if (shift < 32 && (byte & 64) !== 0) value |= ~0 << shift;
32784
32864
  addend[i] = value;
32785
- cur = c4;
32786
32865
  }
32787
32866
  ro[i] = offset;
32788
32867
  rs[i] = symbol2;
32789
- end[i] = length + cur - section2.at;
32868
+ end[i] = length + cur - baseAt;
32790
32869
  }
32791
- spans.push([section2.at, cur]);
32792
- length += cur - section2.at;
32870
+ spans.push([baseAt, cur]);
32871
+ length += cur - baseAt;
32793
32872
  }
32794
32873
  const bytes = new Uint8Array(length);
32795
32874
  let at = 0;
32796
- for (const [from, to] of spans) {
32875
+ for (let s = 0; s < spans.length; s++) {
32876
+ const [from, to] = spans[s];
32797
32877
  bytes.set(buf.subarray(from, to), at);
32798
32878
  at += to - from;
32799
32879
  }
@@ -32958,6 +33038,27 @@ function patchSwiftrtObject(src) {
32958
33038
  function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
32959
33039
  const rawBuf = Buffer.isBuffer(buf) ? buf : Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
32960
33040
  let pos = 8;
33041
+ let cur = 8;
33042
+ const readU = () => {
33043
+ const b0 = buf[cur++];
33044
+ if (b0 < 128) return b0;
33045
+ let res = b0 & 127;
33046
+ let shift = 7;
33047
+ while (true) {
33048
+ const byte = buf[cur++];
33049
+ res |= (byte & 127) << shift;
33050
+ if (byte < 128) return res;
33051
+ shift += 7;
33052
+ }
33053
+ };
33054
+ const skipU = () => {
33055
+ while (buf[cur++] >= 128) {
33056
+ }
33057
+ };
33058
+ const skipS = () => {
33059
+ while (buf[cur++] >= 128) {
33060
+ }
33061
+ };
32961
33062
  let numImportFuncs = 0;
32962
33063
  let importsDlsym = false;
32963
33064
  const importFuncNames = [];
@@ -32986,150 +33087,122 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
32986
33087
  const dataRelocSections = [];
32987
33088
  while (pos < buf.length) {
32988
33089
  const id = buf[pos++];
32989
- const [sz, p] = readULEB2(buf, pos);
33090
+ cur = pos;
33091
+ const sz = readU();
33092
+ const p = cur;
32990
33093
  const end = p + sz;
32991
33094
  if (id === 2) {
32992
- let [cnt, cp] = readULEB2(buf, p);
33095
+ const cnt = readU();
32993
33096
  for (let i = 0; i < cnt; i++) {
32994
- const [mLen, m2] = readULEB2(buf, cp);
32995
- const mName = rawBuf.toString("utf8", m2, m2 + mLen);
32996
- cp = m2 + mLen;
32997
- const [fLen, f2] = readULEB2(buf, cp);
32998
- const fName = rawBuf.toString("utf8", f2, f2 + fLen);
32999
- cp = f2 + fLen;
33000
- const kind = buf[cp++];
33097
+ const mLen = readU();
33098
+ const mName = rawBuf.toString("utf8", cur, cur + mLen);
33099
+ cur += mLen;
33100
+ const fLen = readU();
33101
+ const fName = rawBuf.toString("utf8", cur, cur + fLen);
33102
+ cur += fLen;
33103
+ const kind = buf[cur++];
33001
33104
  if (kind === 0) {
33002
- const [, c2] = readULEB2(buf, cp);
33003
- cp = c2;
33105
+ skipU();
33004
33106
  importFuncNames.push(fName);
33005
33107
  importFuncModules.push(mName);
33006
33108
  if (mName === "env" && fName === "dlsym") importsDlsym = true;
33007
33109
  numImportFuncs++;
33008
33110
  } else if (kind === 1) {
33009
- cp++;
33010
- const [fl, c2] = readULEB2(buf, cp);
33011
- cp = c2;
33012
- const [, c3] = readULEB2(buf, cp);
33013
- cp = c3;
33014
- if (fl & 1) {
33015
- const [, c4] = readULEB2(buf, cp);
33016
- cp = c4;
33017
- }
33111
+ cur++;
33112
+ const fl = readU();
33113
+ skipU();
33114
+ if (fl & 1) skipU();
33018
33115
  importTableNames.push(fName);
33019
33116
  } else if (kind === 2) {
33020
- const [fl, c2] = readULEB2(buf, cp);
33021
- cp = c2;
33022
- const [, c3] = readULEB2(buf, cp);
33023
- cp = c3;
33024
- if (fl & 1) {
33025
- const [, c4] = readULEB2(buf, cp);
33026
- cp = c4;
33027
- }
33117
+ const fl = readU();
33118
+ skipU();
33119
+ if (fl & 1) skipU();
33028
33120
  } else if (kind === 3) {
33029
- cp += 2;
33121
+ cur += 2;
33030
33122
  importGlobalNames.push(fName);
33031
33123
  } else if (kind === 4) {
33032
- cp++;
33033
- const [, c2] = readULEB2(buf, cp);
33034
- cp = c2;
33124
+ cur++;
33125
+ skipU();
33035
33126
  importEventNames.push(fName);
33036
33127
  }
33037
33128
  }
33038
33129
  } else if (id === 10) {
33039
33130
  codeStart = p;
33040
- let [cnt, cp] = readULEB2(buf, p);
33131
+ const cnt = readU();
33041
33132
  for (let i = 0; i < cnt; i++) {
33042
- const st = cp - codeStart;
33043
- const [bLen, b2] = readULEB2(buf, cp);
33044
- cp = b2 + bLen;
33133
+ const st = cur - codeStart;
33134
+ const bLen = readU();
33135
+ cur += bLen;
33045
33136
  fStarts.push(st);
33046
- fEnds.push(cp - codeStart);
33137
+ fEnds.push(cur - codeStart);
33047
33138
  }
33048
33139
  } else if (id === 11) {
33049
33140
  dataStart = p;
33050
- let [cnt, cp] = readULEB2(buf, p);
33141
+ const cnt = readU();
33051
33142
  for (let i = 0; i < cnt; i++) {
33052
- const st = cp - dataStart;
33053
- const [mode, m2] = readULEB2(buf, cp);
33054
- cp = m2;
33055
- if (mode === 2) {
33056
- const [, m3] = readULEB2(buf, cp);
33057
- cp = m3;
33058
- }
33143
+ const st = cur - dataStart;
33144
+ const mode = readU();
33145
+ if (mode === 2) skipU();
33059
33146
  if (mode === 0 || mode === 2) {
33060
- const op = buf[cp++];
33061
- if (op === 65 || op === 66) {
33062
- const [, m4] = readSLEB(buf, cp);
33063
- cp = m4;
33064
- } else if (op === 35) {
33065
- const [, m4] = readULEB2(buf, cp);
33066
- cp = m4;
33067
- }
33068
- cp++;
33147
+ const op = buf[cur++];
33148
+ if (op === 65 || op === 66) skipS();
33149
+ else if (op === 35) skipU();
33150
+ cur++;
33069
33151
  }
33070
- const [dLen, d2] = readULEB2(buf, cp);
33071
- sPayloadStarts.push(d2 - dataStart);
33072
- cp = d2 + dLen;
33152
+ const dLen = readU();
33153
+ sPayloadStarts.push(cur - dataStart);
33154
+ cur += dLen;
33073
33155
  sStarts.push(st);
33074
- sEnds.push(cp - dataStart);
33156
+ sEnds.push(cur - dataStart);
33075
33157
  }
33076
33158
  } else if (id === 0) {
33077
- const [nLen, np] = readULEB2(buf, p);
33078
- const name3 = rawBuf.toString("utf8", np, np + nLen);
33079
- const cp = np + nLen;
33159
+ const nLen = readU();
33160
+ const name3 = rawBuf.toString("utf8", cur, cur + nLen);
33161
+ cur += nLen;
33080
33162
  if (name3 === "linking") {
33081
- let [, lp] = readULEB2(buf, cp);
33082
- while (lp < end) {
33083
- const subId = buf[lp++];
33084
- const [subLen, sp] = readULEB2(buf, lp);
33085
- const subEnd = sp + subLen;
33163
+ skipU();
33164
+ while (cur < end) {
33165
+ const subId = buf[cur++];
33166
+ const subLen = readU();
33167
+ const subEnd = cur + subLen;
33086
33168
  if (subId === 5) {
33087
- const [cnt, p2] = readULEB2(buf, sp);
33088
- let cur = p2;
33169
+ const cnt = readU();
33089
33170
  for (let i = 0; i < cnt; i++) {
33090
- const [sLen, s2] = readULEB2(buf, cur);
33091
- segNames.push(rawBuf.toString("utf8", s2, s2 + sLen));
33092
- cur = s2 + sLen;
33093
- const [, s3] = readULEB2(buf, cur);
33094
- const [fl, s4] = readULEB2(buf, s3);
33095
- segFlags.push(fl);
33096
- cur = s4;
33171
+ const sLen = readU();
33172
+ segNames.push(rawBuf.toString("utf8", cur, cur + sLen));
33173
+ cur += sLen;
33174
+ skipU();
33175
+ segFlags.push(readU());
33097
33176
  }
33098
33177
  } else if (subId === 6) {
33099
- const [cnt, p2] = readULEB2(buf, sp);
33100
- let cur = p2;
33178
+ const cnt = readU();
33101
33179
  for (let i = 0; i < cnt; i++) {
33102
- const [, s2] = readULEB2(buf, cur);
33103
- const [symIdx, s3] = readULEB2(buf, s2);
33104
- initFuncs.push(symIdx);
33105
- cur = s3;
33180
+ skipU();
33181
+ initFuncs.push(readU());
33106
33182
  }
33107
33183
  } else if (subId === 8) {
33108
- const [cnt, p2] = readULEB2(buf, sp);
33184
+ const cnt = readU();
33109
33185
  symKind = new Uint8Array(cnt);
33110
33186
  symFlags = new Uint32Array(cnt);
33111
33187
  symElemIdx = new Int32Array(cnt).fill(-1);
33112
- symOff = new Int32Array(cnt).fill(0);
33113
- symSz = new Int32Array(cnt).fill(0);
33114
- let cur = p2;
33188
+ symOff = new Int32Array(cnt);
33189
+ symSz = new Int32Array(cnt);
33115
33190
  for (let i = 0; i < cnt; i++) {
33116
33191
  const kind = buf[cur++];
33117
33192
  if (symbolFlagOffsets) symbolFlagOffsets[i] = cur;
33118
- const [fl, c2] = readULEB2(buf, cur);
33119
- cur = c2;
33193
+ const fl = readU();
33120
33194
  symKind[i] = kind;
33121
33195
  symFlags[i] = fl;
33122
33196
  const isUndef = (fl & 16) !== 0;
33123
33197
  const isExplicitName = (fl & 64) !== 0;
33124
33198
  if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
33125
- const [el, c3] = readULEB2(buf, cur);
33126
- cur = c3;
33199
+ const el = readU();
33127
33200
  if (!isUndef && kind === 0) symElemIdx[i] = el;
33128
33201
  let sName = "";
33129
33202
  if (!isUndef || isExplicitName) {
33130
- const [sLen, c4] = readULEB2(buf, cur);
33131
- sName = rawBuf.toString("utf8", c4, c4 + sLen);
33132
- cur = c4 + sLen;
33203
+ const sLen = readU();
33204
+ sName = rawBuf.toString("utf8", cur, cur + sLen);
33205
+ cur += sLen;
33133
33206
  } else if (kind === 0) {
33134
33207
  sName = importFuncNames[el] ?? "";
33135
33208
  } else if (kind === 2) {
@@ -33143,33 +33216,28 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
33143
33216
  hostImportNames.add(sName);
33144
33217
  symNames.push(sName);
33145
33218
  } else if (kind === 1) {
33146
- const [sLen, c3] = readULEB2(buf, cur);
33147
- const sName = rawBuf.toString("utf8", c3, c3 + sLen);
33148
- cur = c3 + sLen;
33219
+ const sLen = readU();
33220
+ const sName = rawBuf.toString("utf8", cur, cur + sLen);
33221
+ cur += sLen;
33149
33222
  if (!isUndef) {
33150
- const [segIdx, c4] = readULEB2(buf, cur);
33151
- const [sOff, c5] = readULEB2(buf, c4);
33152
- const [sSz, c6] = readULEB2(buf, c5);
33153
- cur = c6;
33154
- symElemIdx[i] = segIdx;
33155
- symOff[i] = sOff;
33156
- symSz[i] = sSz;
33223
+ symElemIdx[i] = readU();
33224
+ symOff[i] = readU();
33225
+ symSz[i] = readU();
33157
33226
  }
33158
33227
  symNames.push(sName);
33159
33228
  } else if (kind === 3) {
33160
- const [, c3] = readULEB2(buf, cur);
33161
- cur = c3;
33229
+ skipU();
33162
33230
  symNames.push("");
33163
33231
  }
33164
33232
  }
33165
33233
  }
33166
- lp = subEnd;
33234
+ cur = subEnd;
33167
33235
  }
33168
33236
  } else if (name3 === "reloc.CODE" || name3 === "reloc.DATA") {
33169
- const [, r1] = readULEB2(buf, cp);
33170
- const [count, at] = readULEB2(buf, r1);
33237
+ skipU();
33238
+ const count = readU();
33171
33239
  (name3 === "reloc.DATA" ? dataRelocSections : codeRelocSections).push({
33172
- at,
33240
+ at: cur,
33173
33241
  count
33174
33242
  });
33175
33243
  }
@@ -33222,40 +33290,63 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
33222
33290
  segTopSyms.set(segIdx, dedupTop);
33223
33291
  }
33224
33292
  }
33225
- const funcRelocs = Array.from({ length: fEnds.length }, () => []);
33226
- const rawCode = decodeRelocations(buf, fEnds.length > 0 ? codeRelocSections : []);
33293
+ const funcCount = fEnds.length;
33294
+ const funcRelocs = Array.from({ length: funcCount }, () => []);
33295
+ const rawCode = decodeRelocations(buf, funcCount > 0 ? codeRelocSections : []);
33227
33296
  const codeRelocs = { ...rawCode, funcIdx: new Uint32Array(rawCode.count) };
33297
+ let fCursor = 0;
33298
+ let prevCodeRo = -1;
33228
33299
  for (let i = 0; i < codeRelocs.count; i++) {
33229
33300
  const ro = codeRelocs.ro[i];
33230
- let lo = 0;
33231
- let hi = fEnds.length - 1;
33232
- while (lo < hi) {
33233
- const mid = lo + hi >> 1;
33234
- if (fEnds[mid] <= ro) lo = mid + 1;
33235
- else hi = mid;
33301
+ let lo;
33302
+ if (ro >= prevCodeRo) {
33303
+ while (fCursor < funcCount - 1 && fEnds[fCursor] <= ro) fCursor++;
33304
+ lo = fCursor;
33305
+ } else {
33306
+ lo = 0;
33307
+ let hi = funcCount - 1;
33308
+ while (lo < hi) {
33309
+ const mid = lo + hi >> 1;
33310
+ if (fEnds[mid] <= ro) lo = mid + 1;
33311
+ else hi = mid;
33312
+ }
33313
+ fCursor = lo;
33236
33314
  }
33315
+ prevCodeRo = ro;
33237
33316
  if (codeRelocs.bytes[codeRelocs.start[i]] !== 6)
33238
33317
  funcRelocs[lo].push(codeRelocs.rs[i]);
33239
33318
  codeRelocs.funcIdx[i] = lo;
33240
33319
  }
33241
- const segRelocs = Array.from({ length: segNames.length }, () => []);
33320
+ const segCount = segNames.length;
33321
+ const segRelocs = Array.from({ length: segCount }, () => []);
33242
33322
  const symDataRelocs = /* @__PURE__ */ new Map();
33243
33323
  const rawData = decodeRelocations(buf, sEnds.length > 0 ? dataRelocSections : []);
33244
33324
  const dataSegIdx = new Uint32Array(rawData.count);
33245
33325
  const dataOffInSeg = new Int32Array(rawData.count);
33246
33326
  const dataOwnerSymIdx = new Int32Array(rawData.count);
33247
33327
  let kept = 0;
33328
+ let sCursor = 0;
33329
+ let prevDataRo = -1;
33330
+ const sEndLast = sEnds.length - 1;
33248
33331
  for (let i = 0; i < rawData.count; i++) {
33249
33332
  const ro = rawData.ro[i];
33250
33333
  const rs = rawData.rs[i];
33251
- let lo = 0;
33252
- let hi = sEnds.length - 1;
33253
- while (lo < hi) {
33254
- const mid = lo + hi >> 1;
33255
- if (sEnds[mid] <= ro) lo = mid + 1;
33256
- else hi = mid;
33334
+ let lo;
33335
+ if (ro >= prevDataRo) {
33336
+ while (sCursor < sEndLast && sEnds[sCursor] <= ro) sCursor++;
33337
+ lo = sCursor;
33338
+ } else {
33339
+ lo = 0;
33340
+ let hi = sEndLast;
33341
+ while (lo < hi) {
33342
+ const mid = lo + hi >> 1;
33343
+ if (sEnds[mid] <= ro) lo = mid + 1;
33344
+ else hi = mid;
33345
+ }
33346
+ sCursor = lo;
33257
33347
  }
33258
- if (lo >= segRelocs.length) continue;
33348
+ prevDataRo = ro;
33349
+ if (lo >= segCount) continue;
33259
33350
  const offInSeg = ro - (sPayloadStarts[lo] ?? 0);
33260
33351
  let ownerSymIdx = -1;
33261
33352
  const topList = segTopSyms.get(lo);
@@ -33402,74 +33493,78 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
33402
33493
  const conformanceProtocols = /* @__PURE__ */ new Map();
33403
33494
  const objcCategoryTargets = [];
33404
33495
  if (isDist) {
33405
- const relocAt = /* @__PURE__ */ new Map();
33406
- for (let i = 0; i < dataRelocs.count; i++) {
33407
- relocAt.set(`${dataRelocs.segIdx[i]}:${dataRelocs.offInSeg[i]}`, {
33408
- rs: dataRelocs.rs[i],
33409
- addend: dataRelocs.addend[i]
33410
- });
33411
- }
33412
33496
  const confSegs = /* @__PURE__ */ new Set();
33413
33497
  let hasCatsSeg = false;
33414
33498
  for (let i = 0; i < segNames.length; i++) {
33415
33499
  if (segNames[i] === "swift5_protocol_conformances") confSegs.add(i);
33416
33500
  else if (segNames[i] === "__objc_cats") hasCatsSeg = true;
33417
33501
  }
33418
- if (confSegs.size > 0) {
33419
- const segOffToMpSym = /* @__PURE__ */ new Map();
33420
- for (let i = 0; i < symKind.length; i++) {
33421
- if (symKind[i] === 1 && (symFlags[i] & 16) === 0 && symElemIdx[i] >= 0 && symNames[i].startsWith("$s") && symNames[i].endsWith("Mp")) {
33422
- segOffToMpSym.set(`${symElemIdx[i]}:${symOff[i]}`, symNames[i]);
33423
- }
33424
- }
33425
- const dv = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
33502
+ if (confSegs.size > 0 || hasCatsSeg) {
33503
+ const relocKey = (seg, off) => seg * 4294967296 + (off >>> 0);
33504
+ const relocAt = /* @__PURE__ */ new Map();
33426
33505
  for (let i = 0; i < dataRelocs.count; i++) {
33427
- if (!confSegs.has(dataRelocs.segIdx[i])) continue;
33428
- const mcIdx = dataRelocs.rs[i];
33429
- if (symKind[mcIdx] !== 1 || (symFlags[mcIdx] & 16) !== 0 || symElemIdx[mcIdx] < 0) {
33430
- continue;
33506
+ relocAt.set(relocKey(dataRelocs.segIdx[i], dataRelocs.offInSeg[i]), i);
33507
+ }
33508
+ if (confSegs.size > 0) {
33509
+ const segOffToMpSym = /* @__PURE__ */ new Map();
33510
+ for (let i = 0; i < symKind.length; i++) {
33511
+ if (symKind[i] === 1 && (symFlags[i] & 16) === 0 && symElemIdx[i] >= 0 && symNames[i].startsWith("$s") && symNames[i].endsWith("Mp")) {
33512
+ segOffToMpSym.set(relocKey(symElemIdx[i], symOff[i]), symNames[i]);
33513
+ }
33431
33514
  }
33432
- const mcSeg = symElemIdx[mcIdx];
33433
- const mcOff = symOff[mcIdx];
33434
- const pr = relocAt.get(`${mcSeg}:${mcOff}`);
33435
- let mp = "";
33436
- if (pr) {
33437
- const raw2 = symNames[pr.rs];
33438
- const stripped2 = raw2.startsWith(".Lgot.") ? raw2.slice(6) : raw2;
33439
- if (stripped2.startsWith("$s") && stripped2.endsWith("Mp")) {
33440
- mp = stripped2;
33441
- } else if (symKind[pr.rs] === 3 || stripped2 === "") {
33442
- mp = segOffToMpSym.get(`${mcSeg}:${pr.addend}`) ?? "";
33515
+ const dv = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
33516
+ for (let i = 0; i < dataRelocs.count; i++) {
33517
+ if (!confSegs.has(dataRelocs.segIdx[i])) continue;
33518
+ const mcIdx = dataRelocs.rs[i];
33519
+ if (symKind[mcIdx] !== 1 || (symFlags[mcIdx] & 16) !== 0 || symElemIdx[mcIdx] < 0) {
33520
+ continue;
33443
33521
  }
33444
- } else {
33445
- const fileOff = dataStart + sPayloadStarts[mcSeg] + mcOff;
33446
- if (fileOff + 4 <= buf.length) {
33447
- const delta = dv.getInt32(fileOff, true);
33448
- mp = segOffToMpSym.get(`${mcSeg}:${mcOff + delta}`) ?? segOffToMpSym.get(`${mcSeg}:${mcOff + (delta & ~1)}`) ?? "";
33522
+ const mcSeg = symElemIdx[mcIdx];
33523
+ const mcOff = symOff[mcIdx];
33524
+ const prIdx = relocAt.get(relocKey(mcSeg, mcOff));
33525
+ let mp = "";
33526
+ if (prIdx !== void 0) {
33527
+ const prRs = dataRelocs.rs[prIdx];
33528
+ const raw2 = symNames[prRs];
33529
+ const stripped2 = raw2.startsWith(".Lgot.") ? raw2.slice(6) : raw2;
33530
+ if (stripped2.startsWith("$s") && stripped2.endsWith("Mp")) {
33531
+ mp = stripped2;
33532
+ } else if (symKind[prRs] === 3 || stripped2 === "") {
33533
+ mp = segOffToMpSym.get(relocKey(mcSeg, dataRelocs.addend[prIdx])) ?? "";
33534
+ }
33535
+ } else {
33536
+ const fileOff = dataStart + sPayloadStarts[mcSeg] + mcOff;
33537
+ if (fileOff + 4 <= buf.length) {
33538
+ const delta = dv.getInt32(fileOff, true);
33539
+ mp = segOffToMpSym.get(relocKey(mcSeg, mcOff + delta)) ?? segOffToMpSym.get(relocKey(mcSeg, mcOff + (delta & ~1))) ?? "";
33540
+ }
33449
33541
  }
33542
+ if (mp) conformanceProtocols.set(mcIdx, mp);
33450
33543
  }
33451
- if (mp) conformanceProtocols.set(mcIdx, mp);
33452
33544
  }
33453
- }
33454
- if (hasCatsSeg) {
33455
- const seenClasses = /* @__PURE__ */ new Set();
33456
- for (let i = 0; i < symKind.length; i++) {
33457
- if (symKind[i] !== 1 || (symFlags[i] & 16) !== 0 || symElemIdx[i] < 0 || segNames[symElemIdx[i]] !== "__objc_cats" || !symNames[i].startsWith(".objc_category_")) {
33458
- continue;
33459
- }
33460
- const cSeg = symElemIdx[i];
33461
- const cOff = symOff[i];
33462
- const cr = relocAt.get(`${cSeg}:${cOff + 8}`);
33463
- if (cr && symKind[cr.rs] === 1 && (symFlags[cr.rs] & 16) === 0 && symElemIdx[cr.rs] >= 0) {
33464
- const tSeg = symElemIdx[cr.rs];
33465
- const strOff = dataStart + sPayloadStarts[tSeg] + symOff[cr.rs] + cr.addend;
33466
- let sEnd = strOff;
33467
- while (sEnd < buf.length && buf[sEnd] !== 0) sEnd++;
33468
- if (sEnd > strOff) {
33469
- const clsName = Buffer.from(buf.subarray(strOff, sEnd)).toString("utf8");
33470
- if (!seenClasses.has(clsName)) {
33471
- seenClasses.add(clsName);
33472
- objcCategoryTargets.push(clsName);
33545
+ if (hasCatsSeg) {
33546
+ const seenClasses = /* @__PURE__ */ new Set();
33547
+ for (let i = 0; i < symKind.length; i++) {
33548
+ if (symKind[i] !== 1 || (symFlags[i] & 16) !== 0 || symElemIdx[i] < 0 || segNames[symElemIdx[i]] !== "__objc_cats" || !symNames[i].startsWith(".objc_category_")) {
33549
+ continue;
33550
+ }
33551
+ const cSeg = symElemIdx[i];
33552
+ const cOff = symOff[i];
33553
+ const crIdx = relocAt.get(relocKey(cSeg, cOff + 8));
33554
+ if (crIdx !== void 0) {
33555
+ const crRs = dataRelocs.rs[crIdx];
33556
+ if (symKind[crRs] === 1 && (symFlags[crRs] & 16) === 0 && symElemIdx[crRs] >= 0) {
33557
+ const tSeg = symElemIdx[crRs];
33558
+ const strOff = dataStart + sPayloadStarts[tSeg] + symOff[crRs] + dataRelocs.addend[crIdx];
33559
+ let sEnd = strOff;
33560
+ while (sEnd < buf.length && buf[sEnd] !== 0) sEnd++;
33561
+ if (sEnd > strOff) {
33562
+ const clsName = rawBuf.toString("utf8", strOff, sEnd);
33563
+ if (!seenClasses.has(clsName)) {
33564
+ seenClasses.add(clsName);
33565
+ objcCategoryTargets.push(clsName);
33566
+ }
33567
+ }
33473
33568
  }
33474
33569
  }
33475
33570
  }
@@ -34682,7 +34777,9 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
34682
34777
  return true;
34683
34778
  };
34684
34779
  const writePrunedObject = (obj, outFile) => {
34685
- const buf = new Uint8Array(import_node_fs44.default.readFileSync(obj.file));
34780
+ const cached2 = objectBytes.get(obj);
34781
+ const buf = cached2 ? new Uint8Array(cached2) : new Uint8Array(import_node_fs44.default.readFileSync(obj.file));
34782
+ const rawBuf = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
34686
34783
  const inputSha256 = link ? (0, import_node_crypto24.createHash)("sha256").update(buf).digest("hex") : "";
34687
34784
  const fLive = liveFuncs.get(obj);
34688
34785
  const sLive = liveSegs.get(obj);
@@ -34774,7 +34871,7 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
34774
34871
  const end = p + sz;
34775
34872
  if (id === 0) {
34776
34873
  const [nLen, np] = readULEB2(buf, p);
34777
- const name3 = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
34874
+ const name3 = rawBuf.toString("utf8", np, np + nLen);
34778
34875
  const cp = np + nLen;
34779
34876
  if (name3 === "linking") {
34780
34877
  const [, lpStart] = readULEB2(buf, cp);
@@ -35036,7 +35133,7 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
35036
35133
  );
35037
35134
  import_node_fs44.default.rmSync(rspPath, { force: true });
35038
35135
  }
35039
- var import_node_child_process22, import_node_crypto24, import_node_fs44, import_node_path43, 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;
35136
+ var import_node_child_process22, import_node_crypto24, import_node_fs44, import_node_path43, 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;
35040
35137
  var init_swift_wasm_prune = __esm({
35041
35138
  "src/swift-wasm-prune.ts"() {
35042
35139
  "use strict";
@@ -35116,6 +35213,8 @@ var init_swift_wasm_prune = __esm({
35116
35213
  "swift5_reflstr",
35117
35214
  "swift5_typeref"
35118
35215
  ]);
35216
+ ADDEND_RELOC_MASK2 = 0;
35217
+ for (const type of ADDEND_RELOCATIONS) ADDEND_RELOC_MASK2 |= 1 << type;
35119
35218
  relocationBytes = (relocs, i) => relocs.bytes.subarray(relocs.start[i], relocs.end[i]);
35120
35219
  parsedObjectCache = /* @__PURE__ */ new Map();
35121
35220
  PARSED_ROOTS = 2;
@@ -35623,7 +35722,7 @@ function llvmType(value) {
35623
35722
  function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLookups, preserveCanonical, options2 = {}) {
35624
35723
  if (!isWasmMagic(bytes)) throw new Error("expected wasm object");
35625
35724
  const rawBuf = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
35626
- const { sdkLookupOnly, sdkProduct } = options2;
35725
+ const { sdkLookupOnly, sdkProduct, collectRewrittenSymbols } = options2;
35627
35726
  const comdatScope = sdkProduct === void 0 ? callerAlias : `${callerAlias}:${sdkProduct}`;
35628
35727
  const rewrite = binding !== void 0;
35629
35728
  const sections = rewrite ? [bytes.subarray(0, 8)] : void 0;
@@ -35632,6 +35731,9 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
35632
35731
  const definitions = [];
35633
35732
  const functionImports = /* @__PURE__ */ new Map();
35634
35733
  const functionImportNames = [];
35734
+ const tableImportNames = [];
35735
+ const globalImportNames = [];
35736
+ const eventImportNames = [];
35635
35737
  const functionSymbols = [];
35636
35738
  const addressTaken = /* @__PURE__ */ new Set();
35637
35739
  let usesDlsym = false;
@@ -35753,12 +35855,18 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
35753
35855
  if (isDlsym) usesDlsym = true;
35754
35856
  if (isDlerror) usesDlerror = true;
35755
35857
  if (importWriter && binding) {
35858
+ const rewrittenName = isDlsym ? callerAlias : isDlerror ? dlerrorAlias : module2 === "env" && name3 !== "dlsym" && name3 !== "dlerror" ? binding(name3) ?? name3 : name3;
35756
35859
  importWriter.string(module2);
35757
- importWriter.string(
35758
- isDlsym ? callerAlias : isDlerror ? dlerrorAlias : module2 === "env" && name3 !== "dlsym" && name3 !== "dlerror" ? binding(name3) ?? name3 : name3
35759
- );
35860
+ importWriter.string(rewrittenName);
35760
35861
  importWriter.byte(kind);
35761
35862
  importWriter.bytes(bytes, typeStart, offset);
35863
+ if (collectRewrittenSymbols) {
35864
+ if (kind === 0)
35865
+ functionImportNames[functionImportNames.length - 1] = rewrittenName;
35866
+ else if (kind === 1) tableImportNames.push(rewrittenName);
35867
+ else if (kind === 3) globalImportNames.push(rewrittenName);
35868
+ else if (kind === 4) eventImportNames.push(rewrittenName);
35869
+ }
35762
35870
  }
35763
35871
  }
35764
35872
  if (offset !== end) throw new Error("invalid wasm import section");
@@ -35841,13 +35949,17 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
35841
35949
  if (!rewrite && flags & 16 && symbolKind === 1 && alias)
35842
35950
  usedSymbols.add(name3);
35843
35951
  if (entryWriter && binding) {
35952
+ let rewrittenSym = name3;
35953
+ let addedCanonical;
35844
35954
  if ((name3 === "dlsym" && usesDlsym || name3 === "dlerror" && usesDlerror) && flags & 16 && flags & 64 && symbolKind === 0) {
35955
+ rewrittenSym = name3 === "dlsym" ? callerAlias : dlerrorAlias;
35845
35956
  entryWriter.bytes(bytes, begin, nameStart);
35846
- entryWriter.string(name3 === "dlsym" ? callerAlias : dlerrorAlias);
35957
+ entryWriter.string(rewrittenSym);
35847
35958
  entryWriter.bytes(bytes, nameEnd, offset);
35848
35959
  } else if (flags & 16 && name3 !== "dlsym" && name3 !== "dlerror" && binding(name3) !== void 0) {
35960
+ rewrittenSym = binding(name3);
35849
35961
  entryWriter.bytes(bytes, begin, nameStart);
35850
- entryWriter.string(binding(name3));
35962
+ entryWriter.string(rewrittenSym);
35851
35963
  entryWriter.bytes(bytes, nameEnd, offset);
35852
35964
  } else if (alias && !(flags & 16) && (flags & 3) !== 2) {
35853
35965
  if (symbolKind !== 0 && symbolKind !== 1)
@@ -35861,7 +35973,9 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
35861
35973
  extraWriter.string(alias);
35862
35974
  extraWriter.bytes(bytes, nameEnd, offset);
35863
35975
  added++;
35976
+ addedCanonical = alias;
35864
35977
  } else {
35978
+ rewrittenSym = alias;
35865
35979
  entryWriter.bytes(bytes, begin, nameStart);
35866
35980
  entryWriter.string(alias);
35867
35981
  entryWriter.bytes(bytes, nameEnd, offset);
@@ -35869,6 +35983,16 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
35869
35983
  } else {
35870
35984
  entryWriter.bytes(bytes, begin, offset);
35871
35985
  }
35986
+ if (collectRewrittenSymbols) {
35987
+ if (flags & 16) {
35988
+ const resolved = flags & 64 || symbolKind === 1 ? rewrittenSym : symbolKind === 0 ? functionImportNames[index] ?? "" : symbolKind === 2 ? globalImportNames[index] ?? "" : symbolKind === 4 ? eventImportNames[index] ?? "" : symbolKind === 5 ? tableImportNames[index] ?? "" : "";
35989
+ if (resolved) collectRewrittenSymbols.referenced.add(resolved);
35990
+ } else if ((flags & 3) !== 2) {
35991
+ if (rewrittenSym) collectRewrittenSymbols.defined.add(rewrittenSym);
35992
+ if (addedCanonical)
35993
+ collectRewrittenSymbols.defined.add(addedCanonical);
35994
+ }
35995
+ }
35872
35996
  } else if (alias && !(flags & 16) && (flags & 3) !== 2) {
35873
35997
  if (symbolKind !== 0 && symbolKind !== 1)
35874
35998
  throw new Error(`unsupported symbol ${name3}`);
@@ -36232,6 +36356,7 @@ function createGuestImageLedger(input) {
36232
36356
  sdkGlobalBindings.set(name3, first.alias);
36233
36357
  }
36234
36358
  }
36359
+ const appSymbols = input.registerAppTables ? { referenced: /* @__PURE__ */ new Set(), defined: /* @__PURE__ */ new Set() } : void 0;
36235
36360
  const objects = units.map(({ image, object: object8, aliases, functionImports }) => {
36236
36361
  const shared = sharedLookupByImage.get(image);
36237
36362
  const own2 = startup.get(object8.path);
@@ -36266,7 +36391,10 @@ function createGuestImageLedger(input) {
36266
36391
  binding,
36267
36392
  object8.instrumentDynamicLookups,
36268
36393
  preserveCanonical,
36269
- { sdkProduct: object8.sdkProduct }
36394
+ {
36395
+ sdkProduct: object8.sdkProduct,
36396
+ collectRewrittenSymbols: object8.sdkProduct === void 0 ? appSymbols : void 0
36397
+ }
36270
36398
  ).bytes
36271
36399
  };
36272
36400
  });
@@ -36387,7 +36515,9 @@ function createGuestImageLedger(input) {
36387
36515
  llvmIR: render2(false, lazy),
36388
36516
  lazyFunctions: lazy,
36389
36517
  appLLVMIR: appLazy && render2(true, appLazy),
36390
- appLazyFunctions: appLazy
36518
+ appLazyFunctions: appLazy,
36519
+ appReferencedSymbols: appSymbols?.referenced,
36520
+ appDefinedSymbols: appSymbols?.defined
36391
36521
  };
36392
36522
  }
36393
36523
  function guestLazyFunctionRuntime(count) {
@@ -37115,6 +37245,26 @@ function selectedGuestManifestInputs(plan, selection, identities, readSelected)
37115
37245
  }
37116
37246
  return images;
37117
37247
  }
37248
+ function framedLinkOptions(options2) {
37249
+ const cached2 = framedLinkOptionsCache.get(options2);
37250
+ if (cached2) return cached2;
37251
+ const parts = new Array(options2.length * 2 + 2);
37252
+ const count = Buffer.from(String(options2.length), "utf8");
37253
+ const countSize = Buffer.allocUnsafe(8);
37254
+ countSize.writeBigUInt64BE(BigInt(count.byteLength));
37255
+ parts[0] = countSize;
37256
+ parts[1] = count;
37257
+ for (let i = 0; i < options2.length; i++) {
37258
+ const encoded = Buffer.from(options2[i], "utf8");
37259
+ const size2 = Buffer.allocUnsafe(8);
37260
+ size2.writeBigUInt64BE(BigInt(encoded.byteLength));
37261
+ parts[i * 2 + 2] = size2;
37262
+ parts[i * 2 + 3] = encoded;
37263
+ }
37264
+ const framed = Buffer.concat(parts);
37265
+ framedLinkOptionsCache.set(options2, framed);
37266
+ return framed;
37267
+ }
37118
37268
  function createGuestImageManifest(image) {
37119
37269
  const target = {
37120
37270
  triple: SWIFT_WASM_TRIPLE,
@@ -37124,10 +37274,10 @@ function createGuestImageManifest(image) {
37124
37274
  cpuSubtype: 0
37125
37275
  };
37126
37276
  const digest2 = (0, import_node_crypto28.createHash)("sha256");
37277
+ const sizeBuf = Buffer.allocUnsafe(8);
37127
37278
  const add = (bytes) => {
37128
- const size2 = Buffer.alloc(8);
37129
- size2.writeBigUInt64BE(BigInt(bytes.byteLength));
37130
- digest2.update(size2);
37279
+ sizeBuf.writeBigUInt64BE(BigInt(bytes.byteLength));
37280
+ digest2.update(sizeBuf);
37131
37281
  digest2.update(bytes);
37132
37282
  };
37133
37283
  const text7 = (value) => add(Buffer.from(value, "utf8"));
@@ -37144,8 +37294,7 @@ function createGuestImageManifest(image) {
37144
37294
  `${version2.platform}:${version2.minimum.major}:${version2.minimum.minor}:${version2.minimum.patch}`
37145
37295
  );
37146
37296
  text7(`${version2.sdk.major}:${version2.sdk.minor}:${version2.sdk.patch}`);
37147
- text7(String(image.linkOptions.length));
37148
- for (const option of image.linkOptions) text7(option);
37297
+ digest2.update(framedLinkOptions(image.linkOptions));
37149
37298
  text7(String(image.inputs.length));
37150
37299
  for (const input of image.inputs) {
37151
37300
  text7(input.identity);
@@ -37166,7 +37315,7 @@ function createGuestImageManifest(image) {
37166
37315
  regions: image.regions
37167
37316
  };
37168
37317
  }
37169
- var import_node_crypto28, import_node_fs46;
37318
+ var import_node_crypto28, import_node_fs46, framedLinkOptionsCache;
37170
37319
  var init_swift_guest_manifest = __esm({
37171
37320
  "src/swift-guest-manifest.ts"() {
37172
37321
  "use strict";
@@ -37175,6 +37324,7 @@ var init_swift_guest_manifest = __esm({
37175
37324
  init_swift_guest_link_plan();
37176
37325
  init_swift_wasm_prune();
37177
37326
  init_swiftTargetContract();
37327
+ framedLinkOptionsCache = /* @__PURE__ */ new WeakMap();
37178
37328
  }
37179
37329
  });
37180
37330
 
@@ -38477,7 +38627,7 @@ var init_wasm_optimize = __esm({
38477
38627
  ];
38478
38628
  BINARYEN_VERSION = binaryen_lock_default.version;
38479
38629
  runBinaryen = (0, import_node_util5.promisify)(import_node_child_process24.execFile);
38480
- 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`;
38630
+ 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`;
38481
38631
  BINARYEN_RELEASES = new Map(Object.entries(binaryen_lock_default.platforms));
38482
38632
  }
38483
38633
  });
@@ -38922,6 +39072,7 @@ function linkGuestImages(options2) {
38922
39072
  const ledgerObjects = new Map(ledger.objects.map((item) => [item.path, item]));
38923
39073
  const appObjects = /* @__PURE__ */ new Map();
38924
39074
  const sdkObjects = /* @__PURE__ */ new Map();
39075
+ const finalArchives = /* @__PURE__ */ new Map();
38925
39076
  for (const [index, artifact] of plan.artifacts.entries()) {
38926
39077
  const prefix = `${artifact.path}(`;
38927
39078
  if (artifact.kind === "object") {
@@ -38943,7 +39094,10 @@ function linkGuestImages(options2) {
38943
39094
  }
38944
39095
  const members2 = archives.get(artifact.path);
38945
39096
  if (!members2) continue;
38946
- const listed = (0, import_node_child_process25.execFileSync)(llvmAr, ["t", artifact.path], { encoding: "utf8" }).trimEnd().split("\n");
39097
+ const listing = (0, import_node_child_process25.execFileSync)(llvmAr, ["t", artifact.path], {
39098
+ encoding: "utf8"
39099
+ }).trimEnd();
39100
+ const listed = listing ? listing.split("\n") : [];
38947
39101
  if (listed.length !== members2.length || new Set(listed).size !== listed.length || members2.some(
38948
39102
  (member, i) => listed[i] !== member.name || import_node_path47.default.basename(member.name) !== member.name
38949
39103
  ))
@@ -38972,6 +39126,10 @@ function linkGuestImages(options2) {
38972
39126
  const response = import_node_path47.default.join(memberDir, "members.rsp");
38973
39127
  import_node_fs49.default.writeFileSync(response, inputs2.map((input) => JSON.stringify(input)).join(" "));
38974
39128
  (0, import_node_child_process25.execFileSync)(llvmAr, ["rcs", output, `@${response}`], { stdio: "pipe" });
39129
+ finalArchives.set(
39130
+ output,
39131
+ members2.map((member) => ({ name: member.name, bytes: new Uint8Array(0) }))
39132
+ );
38975
39133
  replacements.set(artifact.path, output);
38976
39134
  }
38977
39135
  const compileLedger = (name3, source) => {
@@ -39103,7 +39261,8 @@ function linkGuestImages(options2) {
39103
39261
  remapGuestLinkPlan(plan, replacements),
39104
39262
  finalArgs,
39105
39263
  import_node_fs49.default.readFileSync(finalWhy, "utf8"),
39106
- finalTrace
39264
+ finalTrace,
39265
+ finalArchives
39107
39266
  );
39108
39267
  const original = new Map([...replacements].map(([before2, after2]) => [after2, before2]));
39109
39268
  const key2 = (item) => JSON.stringify([original.get(item.artifact) ?? item.artifact, item.member]);
@@ -39136,12 +39295,25 @@ ${changed.join("\n")}`
39136
39295
  ])
39137
39296
  );
39138
39297
  appObjects.set(appLedgerObject, options2.ledgerDataImage);
39298
+ let appReferencedSymbols;
39299
+ let appDefinedSymbols;
39300
+ if (ledger.appReferencedSymbols && ledger.appDefinedSymbols) {
39301
+ const referenced = new Set(ledger.appReferencedSymbols);
39302
+ const defined = new Set(ledger.appDefinedSymbols);
39303
+ const ledgerSyms = guestWasmSymbols(import_node_fs49.default.readFileSync(appLedgerObject));
39304
+ for (const name3 of ledgerSyms.undefined) referenced.add(name3);
39305
+ for (const name3 of ledgerSyms.defined) defined.add(name3);
39306
+ appReferencedSymbols = referenced;
39307
+ appDefinedSymbols = defined;
39308
+ }
39139
39309
  options2.onSplitInputs({
39140
39310
  appObjects,
39141
39311
  appSections,
39142
39312
  sdkObjects,
39143
39313
  lazyFunctions: ledger.appLazyFunctions ?? [],
39144
- dyldSymbols: ledger.dyldSymbols
39314
+ dyldSymbols: ledger.dyldSymbols,
39315
+ appReferencedSymbols,
39316
+ appDefinedSymbols
39145
39317
  });
39146
39318
  }
39147
39319
  return selected;
@@ -40124,6 +40296,93 @@ function sourceGuestInputIdentities(graph, buildDirectory, objects) {
40124
40296
  }
40125
40297
  return identities;
40126
40298
  }
40299
+ function wasmAutolinkEntries(bytes, out) {
40300
+ if (bytes.length < 8) return false;
40301
+ 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) {
40302
+ for (const member of readArMembers(bytes)) {
40303
+ if (!wasmAutolinkEntries(member.bytes, out)) return false;
40304
+ }
40305
+ return true;
40306
+ }
40307
+ if (bytes[0] !== 0 || bytes[1] !== 97 || bytes[2] !== 115 || bytes[3] !== 109)
40308
+ return false;
40309
+ const raw2 = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
40310
+ let pos = 8;
40311
+ const len = bytes.length;
40312
+ while (pos < len) {
40313
+ const id = bytes[pos++];
40314
+ let sz = bytes[pos++];
40315
+ if (sz >= 128) {
40316
+ sz &= 127;
40317
+ let shift = 7;
40318
+ while (true) {
40319
+ const b = bytes[pos++];
40320
+ sz |= (b & 127) << shift;
40321
+ if (b < 128) break;
40322
+ shift += 7;
40323
+ }
40324
+ }
40325
+ const end = pos + sz;
40326
+ if (id === 0) {
40327
+ let nLen = bytes[pos++];
40328
+ if (nLen >= 128) {
40329
+ nLen &= 127;
40330
+ let shift = 7;
40331
+ while (true) {
40332
+ const b = bytes[pos++];
40333
+ nLen |= (b & 127) << shift;
40334
+ if (b < 128) break;
40335
+ shift += 7;
40336
+ }
40337
+ }
40338
+ if (nLen === 24 && raw2.toString("ascii", pos, pos + 24) === ".swift1_autolink_entries") {
40339
+ const payload = raw2.toString("utf8", pos + 24, end);
40340
+ for (const entry of payload.split("\0")) {
40341
+ const trimmed = entry.trim();
40342
+ if (trimmed.length > 0) out.push(trimmed);
40343
+ }
40344
+ }
40345
+ }
40346
+ pos = end;
40347
+ }
40348
+ return true;
40349
+ }
40350
+ function readAutolinkFlags(objects, toolchainBin, responsePath) {
40351
+ if (!objects.length) return [];
40352
+ const rawFlags = [];
40353
+ for (const file of objects) {
40354
+ if (!wasmAutolinkEntries((0, import_node_fs50.readFileSync)(file), rawFlags)) {
40355
+ (0, import_node_fs50.writeFileSync)(
40356
+ responsePath,
40357
+ objects.map((entry) => JSON.stringify(entry)).join("\n") + "\n"
40358
+ );
40359
+ return (0, import_node_child_process26.execFileSync)(
40360
+ import_node_path48.default.join(toolchainBin, "swift-autolink-extract"),
40361
+ [`@${responsePath}`, "-o", "-"],
40362
+ { encoding: "utf8" }
40363
+ ).split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
40364
+ }
40365
+ }
40366
+ const seen = /* @__PURE__ */ new Set();
40367
+ const flags = [];
40368
+ for (let i = 0; i < rawFlags.length; i++) {
40369
+ const flag = rawFlags[i];
40370
+ if ((flag === "-framework" || flag === "-weak_framework" || flag === "-l" || flag === "--library") && i + 1 < rawFlags.length) {
40371
+ const value = rawFlags[++i];
40372
+ const key2 = `${flag}\0${value}`;
40373
+ if (!seen.has(key2)) {
40374
+ seen.add(key2);
40375
+ flags.push(flag, value);
40376
+ }
40377
+ continue;
40378
+ }
40379
+ if (!seen.has(flag)) {
40380
+ seen.add(flag);
40381
+ flags.push(flag);
40382
+ }
40383
+ }
40384
+ return flags;
40385
+ }
40127
40386
  function sourceGuestRuntimeLinks(options2) {
40128
40387
  const aliases = /* @__PURE__ */ new Map();
40129
40388
  const artifacts = /* @__PURE__ */ new Map();
@@ -40211,15 +40470,7 @@ function sourceGuestRuntimeLinks(options2) {
40211
40470
  for (const image of options2.images) {
40212
40471
  if (result.has(image.id)) throw new Error(`duplicate source image ${image.id}`);
40213
40472
  const response = import_node_path48.default.join(options2.directory, `image-${image.id}-autolink.rsp`);
40214
- (0, import_node_fs50.writeFileSync)(
40215
- response,
40216
- image.objects.map((file) => JSON.stringify(file)).join("\n") + "\n"
40217
- );
40218
- const autolink = image.objects.length ? (0, import_node_child_process26.execFileSync)(
40219
- import_node_path48.default.join(options2.toolchainBin, "swift-autolink-extract"),
40220
- [`@${response}`, "-o", "-"],
40221
- { encoding: "utf8" }
40222
- ).split("\n").map((line) => line.trim()).filter((line) => line.length > 0) : [];
40473
+ const autolink = readAutolinkFlags(image.objects, options2.toolchainBin, response);
40223
40474
  const links = [];
40224
40475
  const requests = [];
40225
40476
  const optionGroups = [
@@ -40319,6 +40570,7 @@ var init_swift_guest_source_inputs = __esm({
40319
40570
  init_forked_script_contract();
40320
40571
  init_swift_guest_source_plan();
40321
40572
  init_swift_runtime_products();
40573
+ init_swift_wasm_prune();
40322
40574
  CLANG_TARGET_MODULE_WRAPPER = ".peach-clang";
40323
40575
  PARALLEL_REPLAY = `
40324
40576
  const { spawn } = require('node:child_process')
@@ -43258,24 +43510,26 @@ function setBoundedCache(cache, key2, value) {
43258
43510
  return value;
43259
43511
  }
43260
43512
  function cached(directory2, key2) {
43261
- const sdkInterfacePath = import_node_path56.default.join(directory2, INTERFACE_FILE);
43262
- const image = import_node_path56.default.join(directory2, IMAGE_FILE);
43263
43513
  const address = import_node_path56.default.join(directory2, IMAGE_DIGEST);
43264
- if (!(0, import_node_fs58.existsSync)(image) || !(0, import_node_fs58.existsSync)(address) || !(0, import_node_fs58.existsSync)(sdkInterfacePath) || !(0, import_node_fs58.existsSync)(import_node_path56.default.join(directory2, MANIFEST_FILE)) || !(0, import_node_fs58.existsSync)(import_node_path56.default.join(directory2, MANIFEST_DATA_FILE)))
43514
+ if (!(0, import_node_fs58.existsSync)(import_node_path56.default.join(directory2, IMAGE_FILE)) || !(0, import_node_fs58.existsSync)(address) || !(0, import_node_fs58.existsSync)(import_node_path56.default.join(directory2, INTERFACE_FILE)) || !(0, import_node_fs58.existsSync)(import_node_path56.default.join(directory2, MANIFEST_FILE)) || !(0, import_node_fs58.existsSync)(import_node_path56.default.join(directory2, MANIFEST_DATA_FILE)))
43265
43515
  return void 0;
43266
- const sha2565 = (0, import_node_fs58.readFileSync)(address, "utf8");
43516
+ return sdkImageAt(directory2, key2, (0, import_node_fs58.readFileSync)(address, "utf8"));
43517
+ }
43518
+ function sdkImageAt(directory2, key2, sha2565) {
43267
43519
  const cacheKey = `${directory2}\0${sha2565}`;
43268
43520
  let loadedInterface;
43269
43521
  return {
43270
43522
  key: key2,
43271
43523
  directory: directory2,
43272
- image,
43524
+ image: import_node_path56.default.join(directory2, IMAGE_FILE),
43273
43525
  sha256: sha2565,
43274
43526
  get sdkInterface() {
43275
43527
  if (loadedInterface) return loadedInterface;
43276
43528
  const memo2 = cachedSdkInterfaces.get(cacheKey);
43277
43529
  if (memo2) return loadedInterface = memo2;
43278
- const parsed2 = JSON.parse((0, import_node_fs58.readFileSync)(sdkInterfacePath, "utf8"));
43530
+ const parsed2 = JSON.parse(
43531
+ (0, import_node_fs58.readFileSync)(import_node_path56.default.join(directory2, INTERFACE_FILE), "utf8")
43532
+ );
43279
43533
  return loadedInterface = setBoundedCache(cachedSdkInterfaces, cacheKey, parsed2);
43280
43534
  }
43281
43535
  };
@@ -43328,7 +43582,7 @@ async function buildSwiftSdkImage(moduleRoot, scopedLookups = false, frameworkIm
43328
43582
  throw new Error(`invalid published Swift SDK image ${key2}`);
43329
43583
  (0, import_node_fs58.rmSync)(directory2, { recursive: true, force: true });
43330
43584
  (0, import_node_fs58.renameSync)(stage, directory2);
43331
- return { ...image, directory: directory2, image: import_node_path56.default.join(directory2, IMAGE_FILE) };
43585
+ return sdkImageAt(directory2, key2, image.sha256);
43332
43586
  } finally {
43333
43587
  (0, import_node_fs58.rmSync)(stage, { recursive: true, force: true });
43334
43588
  }
@@ -43681,9 +43935,10 @@ function sdkHostExports(appRoot) {
43681
43935
  if (!(byte & 128)) return value;
43682
43936
  }
43683
43937
  };
43938
+ const raw2 = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
43684
43939
  for (let n = u(); n > 0; n--) {
43685
43940
  const length = u();
43686
- names.push(Buffer.from(bytes.subarray(at, at + length)).toString());
43941
+ names.push(raw2.toString("utf8", at, at + length));
43687
43942
  at += length + 1;
43688
43943
  u();
43689
43944
  }
@@ -44109,56 +44364,109 @@ function swiftAppModuleInputs(tokens2, buildRoot, sdkLibraries) {
44109
44364
  }
44110
44365
  return inputs2;
44111
44366
  }
44112
- async function compileSdkForwarders(inputs2, sdk2, toolchainBin, output, project, readInput) {
44367
+ function llvmQuoted(value) {
44368
+ const bytes = Buffer.from(value, "utf8");
44369
+ let out = '"';
44370
+ for (let i = 0; i < bytes.length; i++) {
44371
+ const b = bytes[i];
44372
+ if (b >= 32 && b <= 126 && b !== 34 && b !== 92) out += String.fromCharCode(b);
44373
+ else out += `\\${b.toString(16).toUpperCase().padStart(2, "0")}`;
44374
+ }
44375
+ return out + '"';
44376
+ }
44377
+ async function compileSdkForwarders(inputs2, sdk2, toolchainBin, output, project, readInput, precomputedSymbols) {
44113
44378
  const { signatures, tls } = sdk2.sdkInterface;
44114
- const directories = inputs2.filter((input) => input.startsWith("-L")).map((input) => input.slice(2));
44115
- const referenced = /* @__PURE__ */ new Set();
44116
- const defined = /* @__PURE__ */ new Set();
44117
- const scan3 = (bytes) => {
44118
- const symbols = guestWasmSymbols(bytes);
44119
- for (const name3 of symbols.undefined) referenced.add(name3);
44120
- for (const name3 of symbols.defined) defined.add(name3);
44379
+ let referenced;
44380
+ let defined;
44381
+ if (precomputedSymbols) {
44382
+ referenced = precomputedSymbols.referenced;
44383
+ defined = precomputedSymbols.defined;
44384
+ } else {
44385
+ const directories = inputs2.filter((input) => input.startsWith("-L")).map((input) => input.slice(2));
44386
+ const refSet = /* @__PURE__ */ new Set();
44387
+ const defSet = /* @__PURE__ */ new Set();
44388
+ const scan3 = (bytes) => {
44389
+ const symbols = guestWasmSymbols(bytes);
44390
+ for (const name3 of symbols.undefined) refSet.add(name3);
44391
+ for (const name3 of symbols.defined) defSet.add(name3);
44392
+ };
44393
+ for (const input of inputs2) {
44394
+ const file = input.startsWith("-l") ? directories.map((directory2) => import_node_path57.default.join(directory2, `lib${input.slice(2)}.a`)).find((candidate) => (0, import_node_fs59.existsSync)(candidate)) : input.startsWith("-") ? void 0 : input;
44395
+ if (!file) continue;
44396
+ const bytes = readInput(file);
44397
+ if (file.endsWith(".a"))
44398
+ for (const member of readArMembers(bytes)) scan3(member.bytes);
44399
+ else scan3(bytes);
44400
+ }
44401
+ referenced = refSet;
44402
+ defined = defSet;
44403
+ }
44404
+ const irType = {
44405
+ i: "i32",
44406
+ j: "i64",
44407
+ f: "float",
44408
+ d: "double"
44409
+ };
44410
+ const type = (kinds) => {
44411
+ const out = new Array(kinds.length);
44412
+ for (let i = 0; i < kinds.length; i++) {
44413
+ const kind = kinds[i];
44414
+ const name3 = irType[kind];
44415
+ if (!name3) throw new Error(`sdk signature kind ${kind}`);
44416
+ out[i] = name3;
44417
+ }
44418
+ return out;
44121
44419
  };
44122
- for (const input of inputs2) {
44123
- const file = input.startsWith("-l") ? directories.map((directory2) => import_node_path57.default.join(directory2, `lib${input.slice(2)}.a`)).find((candidate) => (0, import_node_fs59.existsSync)(candidate)) : input.startsWith("-") ? void 0 : input;
44124
- if (!file) continue;
44125
- const bytes = readInput(file);
44126
- if (file.endsWith(".a")) for (const member of readArMembers(bytes)) scan3(member.bytes);
44127
- else scan3(bytes);
44128
- }
44129
- const c = { i: "int", j: "long long", f: "float", d: "double" };
44130
- const type = (kinds) => [...kinds].map((kind) => {
44131
- const name3 = c[kind];
44132
- if (!name3) throw new Error(`sdk signature kind ${kind}`);
44133
- return name3;
44134
- });
44135
- const literal2 = (name3) => JSON.stringify(name3);
44136
- const lines = [];
44137
- if (signatures.__objc_send_load_messages === ":")
44420
+ const lines = [`target triple = "${SWIFT_WASM_TRIPLE}"`];
44421
+ const attrs = [];
44422
+ const addImportAttr = (name3) => {
44423
+ const id = attrs.length;
44424
+ attrs.push(
44425
+ `attributes #${id} = { "wasm-import-module"="env" "wasm-import-name"=${llvmQuoted(name3)} }`
44426
+ );
44427
+ return id;
44428
+ };
44429
+ if (signatures.__objc_send_load_messages === ":") {
44430
+ const attr = addImportAttr("__objc_send_load_messages");
44138
44431
  lines.push(
44139
- '__attribute__((import_module("env"), import_name("__objc_send_load_messages"))) void sdk_send_load_messages(void);',
44140
- "__attribute__((constructor)) static void send_app_load_messages(void) { sdk_send_load_messages(); }"
44432
+ "@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @send_app_load_messages, ptr null }]",
44433
+ `declare void @sdk_send_load_messages() #${attr}`,
44434
+ "define internal void @send_app_load_messages() {",
44435
+ " tail call void @sdk_send_load_messages()",
44436
+ " ret void",
44437
+ "}"
44141
44438
  );
44439
+ }
44142
44440
  const forwarders = /* @__PURE__ */ new Set();
44143
44441
  let index = 0;
44144
44442
  for (const name3 of referenced) {
44145
44443
  const signature2 = signatures[name3];
44146
44444
  if (signature2 === void 0 || defined.has(name3)) continue;
44147
- const [params = "", results = ""] = signature2.split(":");
44445
+ const colon = signature2.indexOf(":");
44446
+ const params = colon < 0 ? signature2 : signature2.slice(0, colon);
44447
+ const results = colon < 0 ? "" : signature2.slice(colon + 1);
44148
44448
  if (results.length > 1) throw new Error(`sdk function ${name3} returns several values`);
44149
44449
  const result = results ? type(results)[0] : "void";
44150
- const declared = type(params).map((kind, at) => `${kind} a${at}`).join(", ") || "void";
44151
- const passed = type(params).map((_, at) => `a${at}`).join(", ");
44450
+ const paramTypes = type(params);
44451
+ const declParams = paramTypes.join(", ");
44452
+ const defParams = paramTypes.map((kind, at) => `${kind} %a${at}`).join(", ");
44453
+ const callArgs = paramTypes.map((kind, at) => `${kind} %a${at}`).join(", ");
44454
+ const attr = addImportAttr(name3);
44455
+ const quoted2 = llvmQuoted(name3);
44152
44456
  lines.push(
44153
- `__attribute__((import_module("env"), import_name(${literal2(name3)}))) ${result} i${index}(${declared});`,
44154
- `__attribute__((weak)) ${result} f${index}(${declared}) __asm__(${literal2(name3)});`,
44155
- `${result} f${index}(${declared}) { ${result === "void" ? "" : "return "}i${index}(${passed}); }`
44457
+ `declare ${result} @i${index}(${declParams}) #${attr}`,
44458
+ `define weak hidden ${result} @${quoted2}(${defParams}) {`,
44459
+ result === "void" ? ` tail call void @i${index}(${callArgs})
44460
+ ret void` : ` %r = tail call ${result} @i${index}(${callArgs})
44461
+ ret ${result} %r`,
44462
+ "}"
44156
44463
  );
44157
44464
  forwarders.add(name3);
44158
44465
  index++;
44159
44466
  }
44160
44467
  const errno = tls.errno;
44161
44468
  let declaredErrno = false;
44469
+ const usedHelpers = [];
44162
44470
  for (const name3 of referenced) {
44163
44471
  const offset = tls[name3];
44164
44472
  if (offset === void 0 || defined.has(name3)) continue;
@@ -44166,28 +44474,44 @@ async function compileSdkForwarders(inputs2, sdk2, toolchainBin, output, project
44166
44474
  throw new Error("the sdk image has no errno to find its thread block by");
44167
44475
  if (!declaredErrno) {
44168
44476
  declaredErrno = true;
44477
+ const attr = addImportAttr("__errno_location");
44169
44478
  lines.push(
44170
- `__attribute__((import_module("env"), import_name("__errno_location"))) char *__peach_errno(void);`
44479
+ `declare ptr @__peach_errno() #${attr}`,
44480
+ "declare ptr @llvm.wasm.tls.base()"
44171
44481
  );
44172
44482
  }
44483
+ const helper = `@${llvmQuoted(SDK_TLS_HELPER + name3)}`;
44484
+ const delta = `@${llvmQuoted(SDK_TLS_DELTA + name3)}`;
44485
+ usedHelpers.push(`ptr ${helper}`);
44173
44486
  lines.push(
44174
- `__attribute__((weak)) _Thread_local char t${index} __asm__(${literal2(name3)});`,
44175
- `__attribute__((used)) long long h${index}(void) __asm__(${literal2(SDK_TLS_HELPER + name3)});`,
44176
- `extern char d${index} __asm__(${literal2(SDK_TLS_DELTA + name3)});`,
44177
- `long long h${index}(void) { return (long long)__peach_errno() + (long long)&d${index} - (long long)__builtin_wasm_tls_base(); }`
44487
+ `@${llvmQuoted(name3)} = weak hidden thread_local global i8 0, align 1`,
44488
+ `${delta} = external global i8, align 1`,
44489
+ `define hidden i64 ${helper}() {`,
44490
+ " %e = tail call ptr @__peach_errno()",
44491
+ " %ei = ptrtoint ptr %e to i64",
44492
+ ` %di = ptrtoint ptr ${delta} to i64`,
44493
+ " %s = add i64 %ei, %di",
44494
+ " %b = tail call ptr @llvm.wasm.tls.base()",
44495
+ " %bi = ptrtoint ptr %b to i64",
44496
+ " %r = sub i64 %s, %bi",
44497
+ " ret i64 %r",
44498
+ "}"
44178
44499
  );
44179
44500
  index++;
44180
44501
  }
44181
- const source = `${output.slice(0, -2)}.c`;
44182
- (0, import_node_fs59.writeFileSync)(source, lines.join("\n") + "\n");
44502
+ if (usedHelpers.length > 0) {
44503
+ lines.push(
44504
+ `@llvm.used = appending global [${usedHelpers.length} x ptr] [${usedHelpers.join(", ")}], section "llvm.metadata"`
44505
+ );
44506
+ }
44507
+ const source = `${output.slice(0, -2)}.ll`;
44508
+ (0, import_node_fs59.writeFileSync)(source, [...lines, ...attrs].join("\n") + "\n");
44183
44509
  await run5(
44184
44510
  import_node_path57.default.join(toolchainBin, "clang"),
44185
44511
  [
44186
44512
  `--target=${SWIFT_WASM_TRIPLE}`,
44187
- "-O2",
44188
44513
  "-matomics",
44189
44514
  "-mbulk-memory",
44190
- "-ffreestanding",
44191
44515
  "-c",
44192
44516
  source,
44193
44517
  "-o",
@@ -44206,7 +44530,8 @@ async function linkSwiftAppModule(options2) {
44206
44530
  toolchainBin,
44207
44531
  forwarders,
44208
44532
  options2.project,
44209
- options2.readInput ?? import_node_fs59.readFileSync
44533
+ options2.readInput ?? import_node_fs59.readFileSync,
44534
+ options2.precomputedSymbols
44210
44535
  );
44211
44536
  const lazy = options2.lazyFunctions ?? [];
44212
44537
  const lazyExports = import_node_path57.default.join(work, "lazy-exports.rsp");
@@ -45950,6 +46275,15 @@ async function compileGuestLink(options2) {
45950
46275
  { stdio: "pipe" }
45951
46276
  );
45952
46277
  }
46278
+ let precomputedSymbols;
46279
+ if (splitInputs.appReferencedSymbols && splitInputs.appDefinedSymbols) {
46280
+ const referenced = new Set(splitInputs.appReferencedSymbols);
46281
+ const defined = new Set(splitInputs.appDefinedSymbols);
46282
+ const projSyms = guestWasmSymbols((0, import_node_fs60.readFileSync)(projectionObject));
46283
+ for (const name3 of projSyms.undefined) referenced.add(name3);
46284
+ for (const name3 of projSyms.defined) defined.add(name3);
46285
+ precomputedSymbols = { referenced, defined };
46286
+ }
45953
46287
  for (; ; ) {
45954
46288
  const link = await linkSwiftAppModule2({
45955
46289
  objects: [...owners.keys()],
@@ -45961,6 +46295,7 @@ async function compileGuestLink(options2) {
45961
46295
  optimize: options2.optimize,
45962
46296
  layoutMap,
45963
46297
  project,
46298
+ precomputedSymbols,
45964
46299
  loweringCache: project ? void 0 : {
45965
46300
  file: import_node_path58.default.join(
45966
46301
  options2.buildDirectory,
@@ -46085,6 +46420,7 @@ var init_swift_guest_compile = __esm({
46085
46420
  init_swift_runtime_products();
46086
46421
  init_swift_sdk_guest_lookups();
46087
46422
  init_swift_toolchain();
46423
+ init_swift_wasm_prune();
46088
46424
  init_swiftTargetContract();
46089
46425
  init_wasm_optimize();
46090
46426
  }
@@ -47548,7 +47884,25 @@ function swiftBuildJobs() {
47548
47884
  return Math.min(cores, memoryJobs);
47549
47885
  }
47550
47886
  function swiftCompilerJobs() {
47551
- return Math.min(16, swiftBuildJobs(), Math.max(1, Math.floor(import_node_os14.default.totalmem() / 2 ** 31)));
47887
+ return Math.min(32, swiftBuildJobs(), Math.max(1, Math.floor(import_node_os14.default.totalmem() / 2 ** 31)));
47888
+ }
47889
+ function swiftCompilerBaseEnv(toolchainBin, sourceEnv, includePeachHome = false) {
47890
+ const env = {};
47891
+ for (const key2 of SWIFT_COMPILER_ENV_KEYS) {
47892
+ const value = sourceEnv[key2];
47893
+ if (value !== void 0) env[key2] = value;
47894
+ }
47895
+ if (includePeachHome && sourceEnv.PEACH_HOME !== void 0)
47896
+ env.PEACH_HOME = sourceEnv.PEACH_HOME;
47897
+ if (process.platform === "linux") {
47898
+ env.LD_LIBRARY_PATH = [
47899
+ import_node_path68.default.resolve(toolchainBin, "../lib/swift/linux"),
47900
+ import_node_path68.default.resolve(toolchainBin, "../lib/swift/host"),
47901
+ sourceEnv.LD_LIBRARY_PATH
47902
+ ].filter(Boolean).join(":");
47903
+ }
47904
+ env.PEACH_DEFER_WASM_LINK = "1";
47905
+ return env;
47552
47906
  }
47553
47907
  function assertSwiftBuildCores() {
47554
47908
  const admitted = windowAdmission()?.cores ?? Number(process.env.TM_EXEC_CPU_CORES);
@@ -48737,10 +49091,22 @@ function emitSwiftPackageManifest(args) {
48737
49091
  const available2 = distribution.objects.filter(
48738
49092
  (object8) => !isProvider(object8) && !replacedObjects.has(object8)
48739
49093
  );
49094
+ const targetNamesWithDash = targets.filter((target) => target.name.includes("-")).map((target) => `lib/${target.name}-`);
49095
+ const targetNameSet = new Set(targets.map((target) => target.name));
49096
+ const optionalSet = /* @__PURE__ */ new Set([...OPTIONAL_FRAMEWORKS, ...GAME_FAMILY, "PeachBox2D"]);
49097
+ const isTargetObject = (object8) => {
49098
+ const dash = object8.indexOf("-", 4);
49099
+ if (dash > 4 && targetNameSet.has(object8.slice(4, dash))) return true;
49100
+ return targetNamesWithDash.some((prefix) => object8.startsWith(prefix));
49101
+ };
49102
+ const isUnreachedOptional = (object8) => {
49103
+ const dash = object8.indexOf("-", 4);
49104
+ if (dash <= 4) return false;
49105
+ const name3 = object8.slice(4, dash);
49106
+ return optionalSet.has(name3) && !reachedFrameworks.has(name3);
49107
+ };
48740
49108
  const objects = available2.filter(
48741
- (object8) => !targets.some((target) => object8.startsWith(`lib/${target.name}-`)) && [...OPTIONAL_FRAMEWORKS, ...GAME_FAMILY, "PeachBox2D"].every(
48742
- (name3) => !object8.startsWith(`lib/${name3}-`) || reachedFrameworks.has(name3)
48743
- )
49109
+ (object8) => !isTargetObject(object8) && !isUnreachedOptional(object8)
48744
49110
  );
48745
49111
  const quoted2 = (object8) => `"${import_node_path68.default.join(moduleRoot, object8).replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
48746
49112
  const categoryObjects = new Set(
@@ -48821,18 +49187,53 @@ function emitSwiftPackageManifest(args) {
48821
49187
  args.files.set(file, content);
48822
49188
  return JSON.stringify([`@${file}`]);
48823
49189
  };
48824
- const frameworkDirectories = (name3, seen = /* @__PURE__ */ new Set()) => (siblings.get(name3) ?? []).flatMap((dependency) => {
48825
- if (seen.has(dependency)) return [];
48826
- seen.add(dependency);
48827
- const owner = args.targets.find((other) => other.name === dependency);
49190
+ const targetByName = new Map(targets.map((target) => [target.name, target]));
49191
+ const ownFrameworkDir = /* @__PURE__ */ new Map();
49192
+ for (const target of targets) {
48828
49193
  const framework = /^(.*)\/[^/]+\.framework\/Modules$/.exec(
48829
- owner?.publicHeadersPath ?? ""
49194
+ target.publicHeadersPath ?? ""
48830
49195
  );
48831
- return [
48832
- ...owner && framework ? [import_node_path68.default.posix.join(args.root, owner.path, framework[1])] : [],
48833
- ...frameworkDirectories(dependency, seen)
48834
- ];
48835
- });
49196
+ if (framework)
49197
+ ownFrameworkDir.set(
49198
+ target.name,
49199
+ import_node_path68.default.posix.join(args.root, target.path, framework[1])
49200
+ );
49201
+ }
49202
+ const frameworkDirectoriesCache = /* @__PURE__ */ new Map();
49203
+ const frameworkDirectories = (name3) => {
49204
+ if (ownFrameworkDir.size === 0) return [];
49205
+ const cached2 = frameworkDirectoriesCache.get(name3);
49206
+ if (cached2) return cached2;
49207
+ const dirs = [];
49208
+ const seen = /* @__PURE__ */ new Set();
49209
+ const visit3 = (current2) => {
49210
+ for (const dependency of siblings.get(current2) ?? []) {
49211
+ if (seen.has(dependency)) continue;
49212
+ seen.add(dependency);
49213
+ const dir = ownFrameworkDir.get(dependency);
49214
+ if (dir) dirs.push(dir);
49215
+ visit3(dependency);
49216
+ }
49217
+ };
49218
+ visit3(name3);
49219
+ frameworkDirectoriesCache.set(name3, dirs);
49220
+ return dirs;
49221
+ };
49222
+ const targetSwiftXccFlags = /* @__PURE__ */ new Map();
49223
+ for (const target of targets) {
49224
+ const flags = target.swiftFlags;
49225
+ if (!flags || flags.length === 0) continue;
49226
+ const xcc = [];
49227
+ for (let index = 1; index < flags.length; index++) {
49228
+ if (flags[index - 1] === "-Xcc")
49229
+ xcc.push(flags[index].replaceAll(SWIFT_NATIVE_INPUT_ROOT, args.root));
49230
+ }
49231
+ if (xcc.length > 0) targetSwiftXccFlags.set(target.name, xcc);
49232
+ }
49233
+ const binaryImports = args.binaryModules ? `, "-I", ${JSON.stringify(args.binaryModules)}` : "";
49234
+ const sharedImports = binaryImports + (distributionModules ? `, "-Isystem", ${JSON.stringify(
49235
+ providedModulesPath(args.root, distributionModules, args.moduleExcludes)
49236
+ )}${distributionClangModuleOptions(args.root, distributionModules).map((flag) => `, ${JSON.stringify(flag)}`).join("")}` : prebuilt ? `, "-Isystem", ${JSON.stringify(providedModulesPath(args.root, prebuilt.modules, args.moduleExcludes))}${prebuilt.moduleMaps.map((map2) => `, "-Xcc", ${JSON.stringify(`-fmodule-map-file=${map2}`)}`).join("")}` : "");
48836
49237
  const frameworkSearchFlags = (target, tool) => frameworkDirectories(target?.name ?? "").map((directory2) => ({
48837
49238
  tool,
48838
49239
  flags: ["-F", directory2]
@@ -48881,10 +49282,7 @@ function emitSwiftPackageManifest(args) {
48881
49282
  const upstream = (target.swiftFlags ?? []).map(
48882
49283
  (flag) => `, ${JSON.stringify(flag.replaceAll(SWIFT_NATIVE_INPUT_ROOT, args.root))}`
48883
49284
  ).join("");
48884
- const binaryImports = args.binaryModules ? `, "-I", ${JSON.stringify(args.binaryModules)}` : "";
48885
- const imports2 = binaryImports + (distributionModules ? `, "-Isystem", ${JSON.stringify(
48886
- providedModulesPath(args.root, distributionModules, args.moduleExcludes)
48887
- )}${distributionClangModuleOptions(args.root, distributionModules).map((flag) => `, ${JSON.stringify(flag)}`).join("")}` : prebuilt ? `, "-Isystem", ${JSON.stringify(providedModulesPath(args.root, prebuilt.modules, args.moduleExcludes))}${prebuilt.moduleMaps.map((map2) => `, "-Xcc", ${JSON.stringify(`-fmodule-map-file=${map2}`)}`).join("")}` : "");
49285
+ const imports2 = sharedImports;
48888
49286
  const nativeFlags = [
48889
49287
  ...args.nativeFlags?.get(target.name) ?? [],
48890
49288
  ...args.nativeHeaderFlags ?? []
@@ -48908,12 +49306,7 @@ function emitSwiftPackageManifest(args) {
48908
49306
  return map2 ? ["-fmodule-map-file=" + map2] : [];
48909
49307
  }),
48910
49308
  ...[...importContext].flatMap((name3) => args.native?.get(name3)?.importFlags ?? []),
48911
- ...[...importContext].flatMap((name3) => {
48912
- const flags = targets.find((target2) => target2.name === name3)?.swiftFlags ?? [];
48913
- return flags.flatMap(
48914
- (flag, index) => flags[index - 1] === "-Xcc" ? [flag.replaceAll(SWIFT_NATIVE_INPUT_ROOT, args.root)] : []
48915
- );
48916
- })
49309
+ ...[...importContext].flatMap((name3) => targetSwiftXccFlags.get(name3) ?? [])
48917
49310
  ];
48918
49311
  const nativeImportFlags = [
48919
49312
  ...frameworkDirectories(target.name).flatMap((directory2) => ["-F", directory2]),
@@ -48928,9 +49321,7 @@ function emitSwiftPackageManifest(args) {
48928
49321
  ...native?.swiftFlags ?? [],
48929
49322
  ...args.objcImplementationModules?.has(target.name) ? ["-enable-experimental-feature", "ObjCImplementation"] : []
48930
49323
  ].map((flag) => `, ${JSON.stringify(flag)}`).join("");
48931
- const header = args.headerDirectory && (args.nativeHeaderDeclarations?.[target.name] || [...args.native?.values() ?? []].some(
48932
- (value) => value.late?.producers.includes(target.name)
48933
- )) ? `, "-emit-objc-header-path", ${JSON.stringify(import_node_path68.default.join(args.headerDirectory, `${target.name}-Swift.original.h`))}` : "";
49324
+ const header = args.headerDirectory && (args.nativeHeaderDeclarations?.[target.name] || lateProducers.has(target.name)) ? `, "-emit-objc-header-path", ${JSON.stringify(import_node_path68.default.join(args.headerDirectory, `${target.name}-Swift.original.h`))}` : "";
48934
49325
  const clangMode = target.cxxInterop ? "" : ', "-Xcc", "-fno-cxx-modules"';
48935
49326
  const deployment = `, "-Xfrontend", "-peach-ios-deployment-target", "-Xfrontend", ${JSON.stringify(target.iosDeploymentTarget ?? SWIFTPM_DEFAULT_IOS_DEPLOYMENT_TARGET)}`;
48936
49327
  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 : ""}${imports2}${nativeImportFlags}${objcFlags}${header}${clangMode}${deployment}${upstream}]`)})]`;
@@ -48963,9 +49354,7 @@ function emitSwiftPackageManifest(args) {
48963
49354
  (dependency) => clang && // textual native headers can include one another without imposing
48964
49355
  // an object build order. the executable already links every native
48965
49356
  // target; only generated Swift headers require producer ordering.
48966
- (args.native?.get(dependency)?.clang || [...args.native?.values() ?? []].some(
48967
- (value) => value.late?.producers.includes(dependency)
48968
- )) ? [] : OPTIONAL_FRAMEWORKS.has(dependency) && !targets.some((candidate) => candidate.name === dependency) ? linkedObjects ? [] : [`.product(name: "${dependency}", package: "sootsim-swift")`] : [`"${dependency}"`]
49357
+ (args.native?.get(dependency)?.clang || lateProducers.has(dependency)) ? [] : OPTIONAL_FRAMEWORKS.has(dependency) && !targetNames.has(dependency) ? linkedObjects ? [] : [`.product(name: "${dependency}", package: "sootsim-swift")`] : [`"${dependency}"`]
48969
49358
  ),
48970
49359
  // a swift importer still needs the producers its clang dependencies
48971
49360
  // reached upstream, whose edges the clang targets above dropped.
@@ -49052,7 +49441,7 @@ function emitSwiftPackageManifest(args) {
49052
49441
  ...args.nativeFlags?.get(name3) ?? [],
49053
49442
  ...args.nativeHeaderFlags ?? []
49054
49443
  ];
49055
- const owner = targets.find((target) => target.name === name3);
49444
+ const owner = targetByName.get(name3);
49056
49445
  const context = /* @__PURE__ */ new Set();
49057
49446
  const visit3 = (dependency) => {
49058
49447
  if (context.has(dependency)) return;
@@ -49128,10 +49517,16 @@ ${declaration.replace(/,$/, "")}
49128
49517
  ""
49129
49518
  ].join("\n");
49130
49519
  }
49131
- function syncSwiftTree(base, files2) {
49520
+ function syncSwiftTree(base, files2, alreadySynced) {
49132
49521
  (0, import_node_fs68.mkdirSync)(base, { recursive: true });
49133
- const kept = /* @__PURE__ */ new Set();
49134
- for (const file of files2.keys()) if ((0, import_node_fs68.existsSync)(file)) kept.add((0, import_node_fs68.statSync)(file).ino);
49522
+ let kept;
49523
+ if (process.platform !== "linux") {
49524
+ kept = /* @__PURE__ */ new Set();
49525
+ for (const file of files2.keys()) {
49526
+ const stat = (0, import_node_fs68.statSync)(file, { throwIfNoEntry: false });
49527
+ if (stat) kept.add(stat.ino);
49528
+ }
49529
+ }
49135
49530
  const walk4 = (dir) => {
49136
49531
  for (const entry of (0, import_node_fs68.readdirSync)(dir, { withFileTypes: true })) {
49137
49532
  const full = import_node_path68.default.join(dir, entry.name);
@@ -49140,12 +49535,13 @@ function syncSwiftTree(base, files2) {
49140
49535
  entry.name === CLANG_DISTRIBUTION_MODULES || entry.name === SWIFT_DISTRIBUTION_MIRROR || entry.name === SWIFT_LINK_STAMP))
49141
49536
  continue;
49142
49537
  if (entry.isDirectory()) walk4(full);
49143
- else if (!files2.has(full) && !kept.has((0, import_node_fs68.lstatSync)(full).ino))
49538
+ else if (!files2.has(full) && (!kept || !kept.has((0, import_node_fs68.lstatSync)(full).ino)))
49144
49539
  (0, import_node_fs68.rmSync)(full, { force: true });
49145
49540
  }
49146
49541
  };
49147
49542
  walk4(base);
49148
49543
  for (const [full, contents2] of files2) {
49544
+ if (alreadySynced?.get(full) === contents2) continue;
49149
49545
  writeBuildFile(full, contents2);
49150
49546
  }
49151
49547
  }
@@ -49253,25 +49649,59 @@ function swiftWasmCallGuards(source, unavailable2) {
49253
49649
  out = out.slice(0, at) + replacement + out.slice(at + width);
49254
49650
  return out;
49255
49651
  }
49652
+ function matchesPathPrefixSet(file, set2) {
49653
+ if (set2.has(file)) return true;
49654
+ for (let slash = file.lastIndexOf("/"); slash !== -1; slash = file.lastIndexOf("/", slash - 1)) {
49655
+ if (set2.has(file.slice(0, slash))) return true;
49656
+ }
49657
+ return false;
49658
+ }
49659
+ function indexTargetsByDirectory(targets) {
49660
+ const byDir = /* @__PURE__ */ new Map();
49661
+ for (const target of targets) {
49662
+ const key2 = target.path === "." ? "" : target.path.replace(/\/+$/, "");
49663
+ let list2 = byDir.get(key2);
49664
+ if (!list2) byDir.set(key2, list2 = []);
49665
+ list2.push(target);
49666
+ }
49667
+ return byDir;
49668
+ }
49669
+ function findTargetForFile(file, byDir, predicate) {
49670
+ for (let slash = file.lastIndexOf("/"); slash !== -1; slash = file.lastIndexOf("/", slash - 1)) {
49671
+ const candidates = byDir.get(file.slice(0, slash));
49672
+ if (!candidates) continue;
49673
+ const relative3 = file.slice(slash + 1);
49674
+ for (const target of candidates) if (predicate(target, relative3)) return target;
49675
+ }
49676
+ const rootCandidates = byDir.get("");
49677
+ if (rootCandidates) {
49678
+ for (const target of rootCandidates) if (predicate(target, file)) return target;
49679
+ }
49680
+ return void 0;
49681
+ }
49256
49682
  function compiledSwiftSources(files2, targets, overlayFrameworks, headers, nativeSourceGlue = false) {
49257
49683
  const ordered = [...targets].sort((a, b) => b.path.length - a.path.length);
49258
- const owners = new Map(
49259
- Object.entries(files2).filter(([file]) => file.endsWith(".swift")).map(([file, source]) => {
49260
- const owner = ordered.find((target) => {
49261
- const prefix = target.path === "." ? "" : target.path + "/";
49262
- if (!file.startsWith(prefix)) return false;
49263
- const relative3 = file.slice(prefix.length);
49264
- return !target.exclude?.some(
49265
- (excluded) => relative3 === excluded || relative3.startsWith(excluded + "/")
49266
- );
49267
- });
49268
- return [file, { source, owner }];
49269
- })
49270
- );
49684
+ const byDir = indexTargetsByDirectory(ordered);
49685
+ const excludeSets = /* @__PURE__ */ new Map();
49686
+ for (const target of ordered) {
49687
+ if (target.exclude?.length) excludeSets.set(target.name, new Set(target.exclude));
49688
+ }
49689
+ const owners = /* @__PURE__ */ new Map();
49690
+ for (const [file, source] of Object.entries(files2)) {
49691
+ if (!file.endsWith(".swift")) continue;
49692
+ const owner = findTargetForFile(file, byDir, (target, relative3) => {
49693
+ const excluded = excludeSets.get(target.name);
49694
+ return !excluded || !matchesPathPrefixSet(relative3, excluded);
49695
+ });
49696
+ owners.set(file, { source, owner });
49697
+ }
49271
49698
  const swiftSources = /* @__PURE__ */ new Map();
49272
- for (const { source, owner } of owners.values())
49273
- if (owner)
49274
- swiftSources.set(owner.name, [...swiftSources.get(owner.name) ?? [], source]);
49699
+ for (const { source, owner } of owners.values()) {
49700
+ if (!owner) continue;
49701
+ let list2 = swiftSources.get(owner.name);
49702
+ if (!list2) swiftSources.set(owner.name, list2 = []);
49703
+ list2.push(source);
49704
+ }
49275
49705
  const { onWasm, withoutWasm } = swiftTargetArchitectures(targets, swiftSources, headers);
49276
49706
  return new Map(
49277
49707
  [...owners].map(([file, { source, owner }]) => {
@@ -50051,18 +50481,46 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
50051
50481
  const bySourcePath = [...targets].sort(
50052
50482
  (left, right) => right.path.length - left.path.length
50053
50483
  );
50484
+ const targetsByDir = indexTargetsByDirectory(bySourcePath);
50485
+ const targetByName = new Map(targets.map((target) => [target.name, target]));
50486
+ const nativeTargets2 = input.nativeTargets ?? [];
50487
+ const nativeTargetByName = new Map(nativeTargets2.map((target) => [target.name, target]));
50488
+ const nativeTargetIndex = new Map(
50489
+ nativeTargets2.map((target, index) => [target.name, index])
50490
+ );
50491
+ const resourceTargetByName = new Map(
50492
+ resourceTargets.map((target) => [target.name, target])
50493
+ );
50494
+ const targetSourceSets = /* @__PURE__ */ new Map();
50495
+ const targetExcludeFullSets = /* @__PURE__ */ new Map();
50496
+ const targetExcludeExactSets = /* @__PURE__ */ new Map();
50497
+ for (const target of targets) {
50498
+ const prefix = target.path === "." ? "" : `${target.path}/`;
50499
+ if (target.sources !== void 0) {
50500
+ targetSourceSets.set(
50501
+ target.name,
50502
+ new Set(target.sources.map((source) => import_node_path68.default.posix.join(prefix, source)))
50503
+ );
50504
+ }
50505
+ if (target.exclude?.length) {
50506
+ targetExcludeFullSets.set(
50507
+ target.name,
50508
+ new Set(target.exclude.map((excluded) => `${prefix}${excluded}`))
50509
+ );
50510
+ targetExcludeExactSets.set(
50511
+ target.name,
50512
+ new Set(target.exclude.map((name3) => import_node_path68.default.posix.join(target.path, name3)))
50513
+ );
50514
+ }
50515
+ }
50054
50516
  const swiftTargets = /* @__PURE__ */ new Set();
50055
50517
  for (const file of Object.keys(input.files)) {
50056
50518
  if (!file.endsWith(".swift")) continue;
50057
- const target = bySourcePath.find(
50058
- (candidate) => (candidate.path === "." || file.startsWith(`${candidate.path}/`)) && (candidate.sources === void 0 || candidate.sources.some((source) => {
50059
- const selected = import_node_path68.default.posix.join(candidate.path, source);
50060
- return file === selected || file.startsWith(`${selected}/`);
50061
- }))
50062
- );
50063
- const excluded = target?.exclude?.some(
50064
- (name3) => file === import_node_path68.default.posix.join(target.path, name3)
50065
- );
50519
+ const target = findTargetForFile(file, targetsByDir, (candidate) => {
50520
+ const selected = targetSourceSets.get(candidate.name);
50521
+ return !selected || matchesPathPrefixSet(file, selected);
50522
+ });
50523
+ const excluded = target && targetExcludeExactSets.get(target.name)?.has(file);
50066
50524
  if (target && !excluded) swiftTargets.add(target.name);
50067
50525
  }
50068
50526
  const importedModules = /* @__PURE__ */ new Set();
@@ -50100,7 +50558,7 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
50100
50558
  checkedToolchain = swiftToolchain(pin2.release, swiftModuleSdk(moduleRoot));
50101
50559
  return checkedToolchain;
50102
50560
  };
50103
- const deploymentTarget = (name3) => input.nativeTargets?.find((value) => value.name === name3)?.deploymentTarget ?? targets.find((value) => value.name === name3)?.iosDeploymentTarget ?? null;
50561
+ const deploymentTarget = (name3) => nativeTargetByName.get(name3)?.deploymentTarget ?? targetByName.get(name3)?.iosDeploymentTarget ?? null;
50104
50562
  const targetStagedFiles = /* @__PURE__ */ new Map();
50105
50563
  const stageTargetFile = (target, file, contents2, options2) => {
50106
50564
  const relative3 = import_node_path68.default.relative(layout2.root, file).split(import_node_path68.default.sep).join(import_node_path68.default.posix.sep);
@@ -50112,18 +50570,41 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
50112
50570
  targetStagedFiles.set(target, staged);
50113
50571
  files2.set(file, contents2);
50114
50572
  };
50573
+ const entriesByPrefix = /* @__PURE__ */ new Map();
50574
+ for (const target of targets) {
50575
+ const prefix = target.path === "." ? "" : `${target.path}/`;
50576
+ if (!entriesByPrefix.has(prefix)) entriesByPrefix.set(prefix, []);
50577
+ }
50578
+ for (const entry of Object.entries(input.files)) {
50579
+ const [file] = entry;
50580
+ entriesByPrefix.get("")?.push(entry);
50581
+ for (let end = file.indexOf("/"); end !== -1; end = file.indexOf("/", end + 1)) {
50582
+ entriesByPrefix.get(file.slice(0, end + 1))?.push(entry);
50583
+ }
50584
+ }
50585
+ const targetEntriesCache = /* @__PURE__ */ new Map();
50115
50586
  const targetEntries = (target) => {
50587
+ const cached2 = targetEntriesCache.get(target.name);
50588
+ if (cached2) return cached2;
50116
50589
  const prefix = target.path === "." ? "" : `${target.path}/`;
50117
- return Object.entries(input.files).filter(
50118
- ([file]) => file.startsWith(prefix) && (target.sources === void 0 || !(file.endsWith(".swift") || isSwiftNativeTranslationUnit(file)) || target.sources.some((source) => {
50119
- const selected = import_node_path68.default.posix.join(prefix, source);
50120
- return file === selected || file.startsWith(`${selected}/`);
50121
- })) && !target.exclude?.some(
50122
- (excluded) => file === `${prefix}${excluded}` || file.startsWith(`${prefix}${excluded}/`)
50123
- ) && !targets.some(
50124
- (candidate) => candidate.name !== target.name && candidate.path !== "." && candidate.path.startsWith(prefix) && file.startsWith(`${candidate.path}/`)
50125
- )
50126
- );
50590
+ const selectedSources = targetSourceSets.get(target.name);
50591
+ const excludedPaths = targetExcludeFullSets.get(target.name);
50592
+ const nestedPrefixes = [];
50593
+ for (const candidate of targets) {
50594
+ if (candidate.name !== target.name && candidate.path !== "." && candidate.path.startsWith(prefix))
50595
+ nestedPrefixes.push(`${candidate.path}/`);
50596
+ }
50597
+ const matched = (entriesByPrefix.get(prefix) ?? []).filter(([file]) => {
50598
+ if (selectedSources !== void 0 && (file.endsWith(".swift") || isSwiftNativeTranslationUnit(file)) && !matchesPathPrefixSet(file, selectedSources))
50599
+ return false;
50600
+ if (excludedPaths !== void 0 && matchesPathPrefixSet(file, excludedPaths))
50601
+ return false;
50602
+ if (nestedPrefixes.length > 0 && nestedPrefixes.some((p) => file.startsWith(p)))
50603
+ return false;
50604
+ return true;
50605
+ });
50606
+ targetEntriesCache.set(target.name, matched);
50607
+ return matched;
50127
50608
  };
50128
50609
  const failTargetPreparation = (target, message) => {
50129
50610
  const prefix = target.path === "." ? "" : `${target.path}/`;
@@ -50168,19 +50649,21 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
50168
50649
  return value;
50169
50650
  };
50170
50651
  const podHeaders = /* @__PURE__ */ new Map();
50171
- for (const settings of input.nativeTargets ?? [])
50652
+ for (const settings of nativeTargets2)
50172
50653
  for (const file of settings.headers) {
50173
50654
  const owner = /\/Headers\/(?:Public|Private)\/([\w+-]+)\/(?:\1\/)?[^/]+\.h$/.exec(
50174
50655
  file
50175
50656
  )?.[1];
50176
- if (owner)
50177
- podHeaders.set(import_node_path68.default.basename(file), [
50178
- ...podHeaders.get(import_node_path68.default.basename(file)) ?? [],
50179
- { owner, content: input.files[file] }
50180
- ]);
50657
+ if (owner) {
50658
+ const base = import_node_path68.default.basename(file);
50659
+ let list2 = podHeaders.get(base);
50660
+ if (!list2) podHeaders.set(base, list2 = []);
50661
+ list2.push({ owner, content: input.files[file] });
50662
+ }
50181
50663
  }
50182
50664
  const podHeaderOwner = (file, content) => /\/Headers\/(?:Public|Private)\/([\w+-]+)\//.exec(file)?.[1] ?? podHeaders.get(import_node_path68.default.basename(file))?.find((header) => header.content === content)?.owner;
50183
- for (const settings of input.nativeTargets ?? []) {
50665
+ const alreadySynced = /* @__PURE__ */ new Map();
50666
+ for (const settings of nativeTargets2) {
50184
50667
  for (const file of settings.headers) {
50185
50668
  const destination = import_node_path68.default.join(layout2.root, file);
50186
50669
  if (files2.has(destination)) continue;
@@ -50197,10 +50680,10 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
50197
50680
  `#import <${interfaceOwner}/${interfaceOwner}-Swift.h>`
50198
50681
  ) : rawContents;
50199
50682
  writeBuildFile(destination, contents2);
50683
+ alreadySynced.set(destination, contents2);
50200
50684
  files2.set(destination, contents2);
50201
50685
  }
50202
50686
  }
50203
- const nativeTargets2 = input.nativeTargets ?? [];
50204
50687
  const fromInputRoot = (file) => file.startsWith(`${SWIFT_NATIVE_INPUT_ROOT}/`) ? import_node_path68.default.join(layout2.root, file.slice(SWIFT_NATIVE_INPUT_ROOT.length + 1)) : file;
50205
50688
  const inRoot = `${layout2.root}${import_node_path68.default.sep}`;
50206
50689
  const binaryTree = `${import_node_path68.default.sep}${SWIFT_BINARY_TREES_DIR}${import_node_path68.default.sep}`;
@@ -50265,12 +50748,10 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
50265
50748
  const prefix = target.path === "." ? "" : `${target.path}/`;
50266
50749
  const entries2 = targetEntries(target);
50267
50750
  const units = entries2.filter(([file]) => isSwiftNativeTranslationUnit(file));
50268
- if (units.length === 0 && !(entries2.some(([file]) => file.endsWith(".swift")) && input.nativeTargets?.some(
50269
- (settings2) => settings2.name === target.name && (settings2.publicHeaders.length > 0 || settings2.bridgingHeader !== null)
50270
- )))
50751
+ const settings = nativeTargetByName.get(target.name);
50752
+ if (units.length === 0 && !(entries2.some(([file]) => file.endsWith(".swift")) && settings !== void 0 && (settings.publicHeaders.length > 0 || settings.bridgingHeader !== null)))
50271
50753
  continue;
50272
50754
  const includes = `${prefix}include/`;
50273
- const settings = input.nativeTargets?.find((value) => value.name === target.name);
50274
50755
  const searchRoots = [
50275
50756
  ...settings?.userHeaderSearchPaths ?? [],
50276
50757
  ...settings?.headerSearchPaths ?? [],
@@ -50301,7 +50782,9 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
50301
50782
  ...searchRoots.map((root) => import_node_path68.default.posix.join(root, include))
50302
50783
  ].find((candidate) => input.files[candidate] !== void 0);
50303
50784
  if (local) {
50304
- reverse.set(local, [...reverse.get(local) ?? [], file]);
50785
+ let parents = reverse.get(local);
50786
+ if (!parents) reverse.set(local, parents = []);
50787
+ parents.push(file);
50305
50788
  if (xcodeTarget && !seenHeaders.has(local)) {
50306
50789
  seenHeaders.add(local);
50307
50790
  searchEntries.push([local, input.files[local]]);
@@ -50347,9 +50830,10 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
50347
50830
  const stageFlags = (flags2, sdkInclude2) => flags2.map(
50348
50831
  (flag) => flag.replaceAll(SWIFT_NATIVE_INPUT_ROOT, layout2.root).replaceAll(SWIFT_NATIVE_SDK_INCLUDE, sdkInclude2)
50349
50832
  );
50833
+ const settingsHeaderFlags = headerSearch.flags[nativeTargetIndex.get(settings.name)];
50350
50834
  const originalFlags = [
50351
50835
  ...settings.flags,
50352
- ...headerSearch.flags[nativeTargets2.indexOf(settings)],
50836
+ ...settingsHeaderFlags,
50353
50837
  ...search,
50354
50838
  ...(settings?.frameworkSearchPaths ?? []).flatMap((dir) => [
50355
50839
  "-F",
@@ -50360,7 +50844,7 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
50360
50844
  ];
50361
50845
  const importOriginalFlags = settings.flattensPublicHeaders ? [
50362
50846
  ...settings.importerFlags,
50363
- ...headerSearch.flags[nativeTargets2.indexOf(settings)],
50847
+ ...settingsHeaderFlags,
50364
50848
  ...search,
50365
50849
  ...settings.frameworkSearchPaths.flatMap((dir) => [
50366
50850
  "-F",
@@ -50385,7 +50869,7 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
50385
50869
  }
50386
50870
  return [
50387
50871
  ...kept,
50388
- ...headerSearch.flags[nativeTargets2.indexOf(settings)],
50872
+ ...settingsHeaderFlags,
50389
50873
  ...search,
50390
50874
  ...(settings?.frameworkSearchPaths ?? []).flatMap((dir) => [
50391
50875
  "-F",
@@ -50414,7 +50898,7 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
50414
50898
  const bundleName = entries2.some(([file]) => file.endsWith(".swift")) ? void 0 : swiftObjCResourceBundleName({
50415
50899
  target: target.name,
50416
50900
  path: target.path,
50417
- resources: resourceTargets.find((candidate) => candidate.name === target.name)?.resources ?? false,
50901
+ resources: resourceTargetByName.get(target.name)?.resources ?? false,
50418
50902
  usesBundleMacro: entries2.some(
50419
50903
  ([file, contents2]) => (isSwiftNativeTranslationUnit(file) || /\.(?:h|hpp|hh|hxx)$/.test(file)) && /\bSWIFTPM_MODULE_BUNDLE\b/.test(contents2)
50420
50904
  ),
@@ -50567,10 +51051,7 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
50567
51051
  .../\.mm?$/.test(file) ? ["-fobjc-exceptions"] : [],
50568
51052
  ...stageFlags(
50569
51053
  [...objcCxx ? settings.cxxFlags : [], ...fileFlags],
50570
- import_node_path68.default.join(
50571
- swiftSdkPaths(moduleRoot, toolchainBin).sysroot,
50572
- "darwin/usr/include"
50573
- )
51054
+ sdkInclude
50574
51055
  )
50575
51056
  ];
50576
51057
  const moduleFlag = perFile.some((flag) => flag.startsWith("-fmodule-name=")) ? [] : [`-fmodule-name=${swiftTargetModuleName(target.name)}`];
@@ -50610,13 +51091,7 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
50610
51091
  ...flags,
50611
51092
  ...prefixHeader,
50612
51093
  ...accessorFlags,
50613
- ...stageFlags(
50614
- cxx ? settings.cxxFlags : [],
50615
- import_node_path68.default.join(
50616
- swiftSdkPaths(moduleRoot, toolchainBin).sysroot,
50617
- "darwin/usr/include"
50618
- )
50619
- ),
51094
+ ...stageFlags(cxx ? settings.cxxFlags : [], sdkInclude),
50620
51095
  ...perFile,
50621
51096
  ...moduleFlag
50622
51097
  ]
@@ -50871,7 +51346,9 @@ module ${moduleName}.Swift {
50871
51346
  }
50872
51347
  ` : swiftObjCModuleMap(
50873
51348
  moduleName,
50874
- (input.nativeTargets?.find((target) => target.name === name3)?.publicHeaders ?? []).map((header) => import_node_path68.default.join(layout2.root, header)),
51349
+ (nativeTargetByName.get(name3)?.publicHeaders ?? []).map(
51350
+ (header) => import_node_path68.default.join(layout2.root, header)
51351
+ ),
50875
51352
  submoduleImports2.get(moduleName),
50876
51353
  import_node_path68.default.join(headerDirectory, name3 + "-Swift.h")
50877
51354
  )
@@ -51421,6 +51898,7 @@ ${entry}`);
51421
51898
  files2.set(destination, Buffer.from(bytes, "base64"));
51422
51899
  }
51423
51900
  const targetToolset = nativeToolset || native.size > 0;
51901
+ let usesObjcPrebuilt = false;
51424
51902
  if (targetToolset) {
51425
51903
  const nativeToolsetFlags = [
51426
51904
  ...headerAliasFlags,
@@ -51441,6 +51919,7 @@ ${entry}`);
51441
51919
  [...native.keys()],
51442
51920
  objcPrebuiltStage
51443
51921
  ) : [];
51922
+ usesObjcPrebuilt = prebuiltCompiler.length > 0;
51444
51923
  files2.set(
51445
51924
  clangWrapper2,
51446
51925
  [
@@ -51749,17 +52228,39 @@ package.targets += [.target(name: ${JSON.stringify(name3)}, dependencies: ${JSON
51749
52228
  (name3) => !nativePrerequisiteSet.has(name3)
51750
52229
  );
51751
52230
  const nativeTargetUnitCount = /* @__PURE__ */ new Map();
52231
+ const nativeTargetSources = /* @__PURE__ */ new Map();
51752
52232
  for (const target of manifestTargets)
51753
- if (target.sources?.length)
52233
+ if (target.sources?.length) {
51754
52234
  nativeTargetUnitCount.set(target.name, target.sources.length);
52235
+ nativeTargetSources.set(target.name, target.sources);
52236
+ }
51755
52237
  for (const [name3, plan] of native) {
51756
- if (!plan.mixed && plan.sources.length > 0)
51757
- nativeTargetUnitCount.set(name3, plan.clang?.sources.length ?? plan.sources.length);
51758
- for (const group of plan.groups ?? [])
52238
+ if (!plan.mixed && plan.sources.length > 0) {
52239
+ const sources = plan.clang?.sources ?? plan.sources;
52240
+ nativeTargetUnitCount.set(name3, sources.length);
52241
+ nativeTargetSources.set(name3, sources);
52242
+ }
52243
+ for (const group of plan.groups ?? []) {
51759
52244
  nativeTargetUnitCount.set(group.name, group.sources.length);
51760
- if (plan.late && !plan.groups?.length)
52245
+ nativeTargetSources.set(group.name, group.sources);
52246
+ }
52247
+ if (plan.late && !plan.groups?.length) {
51761
52248
  nativeTargetUnitCount.set(plan.late.name, plan.sources.length);
52249
+ nativeTargetSources.set(plan.late.name, plan.lateSources);
52250
+ }
51762
52251
  }
52252
+ const nativeStageObjects = /* @__PURE__ */ new Map();
52253
+ const recordStageObjects = (stageTarget, members2) => {
52254
+ const objects = [];
52255
+ for (const member of members2) {
52256
+ const sources = nativeTargetSources.get(member);
52257
+ if (!sources || sources.length === 0) return stageTarget;
52258
+ for (const source of sources)
52259
+ objects.push(import_node_path68.default.join(`${member}.build`, `${source}.o`));
52260
+ }
52261
+ nativeStageObjects.set(stageTarget, objects);
52262
+ return stageTarget;
52263
+ };
51763
52264
  const MAX_NATIVE_STAGE_UNITS = 250;
51764
52265
  const chunkNativeStageTargets = (prefix, names) => {
51765
52266
  if (names.length === 0) return [];
@@ -51768,7 +52269,7 @@ package.targets += [.target(name: ${JSON.stringify(name3)}, dependencies: ${JSON
51768
52269
  0
51769
52270
  );
51770
52271
  if (names.length === 1 || total <= MAX_NATIVE_STAGE_UNITS)
51771
- return [buildProduct(prefix, names)];
52272
+ return [recordStageObjects(buildProduct(prefix, names), names)];
51772
52273
  const chunks = [];
51773
52274
  let current2 = [];
51774
52275
  let count = 0;
@@ -51783,7 +52284,9 @@ package.targets += [.target(name: ${JSON.stringify(name3)}, dependencies: ${JSON
51783
52284
  count += size2;
51784
52285
  }
51785
52286
  if (current2.length > 0) chunks.push(current2);
51786
- return chunks.map((members2, index) => buildProduct(`${prefix}${index + 1}`, members2));
52287
+ return chunks.map(
52288
+ (members2, index) => recordStageObjects(buildProduct(`${prefix}${index + 1}`, members2), members2)
52289
+ );
51787
52290
  };
51788
52291
  const nativePrerequisiteStageTargets = chunkNativeStageTargets(
51789
52292
  "PeachHeaderNativePrereqs",
@@ -51794,7 +52297,7 @@ package.targets += [.target(name: ${JSON.stringify(name3)}, dependencies: ${JSON
51794
52297
  remainingNativeBuildTargets
51795
52298
  );
51796
52299
  files2.set(manifestPath, manifest);
51797
- syncSwiftTree(layout2.root, files2);
52300
+ syncSwiftTree(layout2.root, files2, alreadySynced);
51798
52301
  if (layout2.multi)
51799
52302
  for (const target of targets)
51800
52303
  (0, import_node_fs68.mkdirSync)(import_node_path68.default.join(layout2.root, target.path), { recursive: true });
@@ -51809,7 +52312,9 @@ package.targets += [.target(name: ${JSON.stringify(name3)}, dependencies: ${JSON
51809
52312
  targetFailures,
51810
52313
  generatedOwners,
51811
52314
  targetToolset,
51812
- headerCompiler
52315
+ headerCompiler,
52316
+ usesObjcPrebuilt,
52317
+ nativeStageObjects
51813
52318
  };
51814
52319
  }
51815
52320
  function streamText(value) {
@@ -52895,8 +53400,8 @@ ${cap}` : "";
52895
53400
  work,
52896
53401
  unoptimized
52897
53402
  );
52898
- const baseBuildEnv = {
52899
- ...options2.project?.env ?? process.env,
53403
+ const baseBuildEnv = options2.project?.env ? {
53404
+ ...options2.project.env,
52900
53405
  // shipped host plugins resolve against the selected compiler's runtime.
52901
53406
  ...process.platform === "linux" ? {
52902
53407
  LD_LIBRARY_PATH: [
@@ -52906,7 +53411,7 @@ ${cap}` : "";
52906
53411
  ].filter(Boolean).join(":")
52907
53412
  } : {},
52908
53413
  PEACH_DEFER_WASM_LINK: "1"
52909
- };
53414
+ } : swiftCompilerBaseEnv(options2.toolchainBin, process.env);
52910
53415
  const {
52911
53416
  frameworkRoot,
52912
53417
  compileFrameworkRoot,
@@ -53050,7 +53555,11 @@ ${cap}` : "";
53050
53555
  } : {
53051
53556
  ...buildOptions,
53052
53557
  temporaryDirectory,
53053
- env: { ...buildOptions.env, ...compiler }
53558
+ env: {
53559
+ ...buildOptions.env,
53560
+ ...preparation.usesObjcPrebuilt && process.env.PEACH_HOME !== void 0 ? { PEACH_HOME: process.env.PEACH_HOME } : {},
53561
+ ...compiler
53562
+ }
53054
53563
  };
53055
53564
  const unprepared = preparation.targetFailures.map(
53056
53565
  (failure2) => `error: target ${failure2}`
@@ -53097,10 +53606,18 @@ ${cap}` : "";
53097
53606
  // the mirror finds a changed sdk header's readers in their
53098
53607
  // dependency files, which omit system headers by default
53099
53608
  ...mirrorDistribution ? ["-Xswiftc", "-track-system-dependencies"] : [],
53100
- // the link strips debug info, so none is generated (as for the framework)
53609
+ // the link strips debug info, so none is generated (as for the framework).
53610
+ // keep -num-threads fixed across caller core caps so llbuild does not
53611
+ // rebuild every target when callers alternate --cores, and bound backend
53612
+ // fan-out under high -j.
53101
53613
  "-Xswiftc",
53102
53614
  "-gnone",
53103
- ...incrementalPreview ? [] : ["-Xswiftc", "-num-threads", "-Xswiftc", String(perFile ? 1 : jobs)],
53615
+ ...incrementalPreview ? [] : [
53616
+ "-Xswiftc",
53617
+ "-num-threads",
53618
+ "-Xswiftc",
53619
+ String(perFile ? 1 : Math.min(8, import_node_os14.default.availableParallelism()))
53620
+ ],
53104
53621
  ...swiftReproducibleBuildFlags([
53105
53622
  [import_node_path68.default.dirname(options2.toolchainBin), "toolchain"],
53106
53623
  [compileFrameworkRoot, "framework"],
@@ -53275,7 +53792,18 @@ ${cap}` : "";
53275
53792
  }))
53276
53793
  ];
53277
53794
  const checkpoints = import_node_path68.default.join(root, ".build", "peach-product-checkpoints");
53795
+ const buildDbExists = (0, import_node_fs68.existsSync)(import_node_path68.default.join(root, ".build", "build.db"));
53796
+ const releaseDir = import_node_path68.default.dirname(linked);
53278
53797
  for (const { target, producers } of stages) {
53798
+ if (!options2.project && producers.length === 0 && buildDbExists) {
53799
+ const expectedObjects = preparation.nativeStageObjects.get(target);
53800
+ if (expectedObjects && expectedObjects.length > 0 && expectedObjects.every(
53801
+ (relative3) => (0, import_node_fs68.statSync)(import_node_path68.default.join(releaseDir, relative3), {
53802
+ throwIfNoEntry: false
53803
+ })?.isFile()
53804
+ ))
53805
+ continue;
53806
+ }
53279
53807
  const receipt = import_node_path68.default.join(
53280
53808
  checkpoints,
53281
53809
  (0, import_node_crypto42.createHash)("sha256").update(target).digest("hex")
@@ -53500,7 +54028,7 @@ ${cap}` : "";
53500
54028
  options2.signal
53501
54029
  );
53502
54030
  }
53503
- var import_node_child_process38, import_node_crypto42, import_node_fs68, import_node_os14, import_node_path68, 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;
54031
+ var import_node_child_process38, import_node_crypto42, import_node_fs68, import_node_os14, import_node_path68, 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;
53504
54032
  var init_swift_compile = __esm({
53505
54033
  "src/swift-compile.ts"() {
53506
54034
  "use strict";
@@ -53553,6 +54081,29 @@ var init_swift_compile = __esm({
53553
54081
  WASM_TRIPLE = SWIFT_WASM_TRIPLE;
53554
54082
  SWIFTPM_PROGRESS = /^\[\d+\/\d+\] /;
53555
54083
  SWIFTPM_NOISE = /^(?:\[\d+\/\d+\] |Building for production\.\.\.$|warning: '--build-system native' has been deprecated)/;
54084
+ SWIFT_COMPILER_ENV_KEYS = [
54085
+ "PATH",
54086
+ "HOME",
54087
+ "USER",
54088
+ "LOGNAME",
54089
+ "LANG",
54090
+ "LC_ALL",
54091
+ "LC_CTYPE",
54092
+ "TZ",
54093
+ "SDKROOT",
54094
+ "DEVELOPER_DIR",
54095
+ "DYLD_LIBRARY_PATH",
54096
+ "SYSTEMROOT",
54097
+ "COMSPEC",
54098
+ "SSL_CERT_FILE",
54099
+ "SSL_CERT_DIR",
54100
+ "HTTP_PROXY",
54101
+ "HTTPS_PROXY",
54102
+ "NO_PROXY",
54103
+ "http_proxy",
54104
+ "https_proxy",
54105
+ "no_proxy"
54106
+ ];
53556
54107
  distributionManifests = /* @__PURE__ */ new Map();
53557
54108
  distributionCompileViews = /* @__PURE__ */ new WeakMap();
53558
54109
  REACH_STAGED_FRAMEWORKS = /* @__PURE__ */ new Set(["React"]);
@@ -53748,7 +54299,7 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
53748
54299
  REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
53749
54300
  MULTI_MANIFEST_VERSION = 76;
53750
54301
  SWIFT_HEADER_PRODUCTS_TARGET = "PeachHeaderProducts";
53751
- compilerSourceDigest = true ? "834b5c28c27bc5807cbb3c4eed5c44f7de81d47db3e3a8819bea6e6635689b24" : swiftCompilerSourceDigest2(__sootsim_import_meta_dirname);
54302
+ compilerSourceDigest = true ? "4d55fa7cbb29586c08e4e51867226f96047bae2103c89f4fa59d9cf3ed3862fb" : swiftCompilerSourceDigest2(__sootsim_import_meta_dirname);
53752
54303
  nativeCxxCompilerFlags = ["-fno-cxx-modules"];
53753
54304
  MODULE_MAP_RESPONSE_FILE_RUN = 16;
53754
54305
  cFlagArray = (flags) => JSON.stringify(withoutGlogModuleMap(flags));