peachsim 0.1.2605 → 0.1.2607

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 (147) hide show
  1. package/cli/commands/package.ts +71 -39
  2. package/cli/commands/perf-native.ts +259 -6
  3. package/cli/commands/shell-url.ts +1 -0
  4. package/dist-lib/agent-daemon-client.cjs +1 -1
  5. package/dist-lib/agent-events.cjs +1 -1
  6. package/dist-lib/attached-projects.cjs +1 -1
  7. package/dist-lib/auth/shared-session.cjs +1 -1
  8. package/dist-lib/backend-origin.cjs +1 -1
  9. package/dist-lib/beta.cjs +1 -1
  10. package/dist-lib/beta.mjs +2 -2
  11. package/dist-lib/bridge-constants.cjs +1 -1
  12. package/dist-lib/bridge-contract-input.cjs +1 -1
  13. package/dist-lib/bridge-contract-input.mjs +5 -5
  14. package/dist-lib/bridge-contract.cjs +1 -1
  15. package/dist-lib/bridge-contract.mjs +3 -3
  16. package/dist-lib/bundle-channel.cjs +1520 -932
  17. package/dist-lib/capture-contract.cjs +1 -1
  18. package/dist-lib/capture-contract.mjs +3 -3
  19. package/dist-lib/cloud-contract.cjs +1 -1
  20. package/dist-lib/cloud-contract.mjs +3 -3
  21. package/dist-lib/cloud-test-args.cjs +1 -1
  22. package/dist-lib/cloud-test-args.mjs +2 -2
  23. package/dist-lib/cloud.cjs +1 -1
  24. package/dist-lib/cloud.mjs +7 -7
  25. package/dist-lib/config.cjs +1 -1
  26. package/dist-lib/config.mjs +5 -5
  27. package/dist-lib/detox/index.cjs +1 -1
  28. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  29. package/dist-lib/esm-chunks/{acorn-UNOYFUKI.mjs → acorn-KFWXYMX5.mjs} +3 -3
  30. package/dist-lib/esm-chunks/{chunk-WSRPZF7M.mjs → chunk-6JPUMAC2.mjs} +1 -1
  31. package/dist-lib/esm-chunks/{chunk-M4G5YUO7.mjs → chunk-6NDABMDX.mjs} +3 -3
  32. package/dist-lib/esm-chunks/{chunk-GT54N3GG.mjs → chunk-7SKDPTZN.mjs} +1 -1
  33. package/dist-lib/esm-chunks/{chunk-FXONOT2L.mjs → chunk-ACAXWH62.mjs} +1 -1
  34. package/dist-lib/esm-chunks/chunk-ARYRQJUB.mjs +326 -0
  35. package/dist-lib/esm-chunks/{chunk-WB2EBX5Q.mjs → chunk-BNAXRY5Q.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-AST6VA7D.mjs → chunk-CA64UUHF.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-B54SPDLA.mjs → chunk-DBW62F4N.mjs} +3 -2
  38. package/dist-lib/esm-chunks/{chunk-7K33ENH6.mjs → chunk-ESS2CG5G.mjs} +5 -5
  39. package/dist-lib/esm-chunks/{chunk-LFN7VAPB.mjs → chunk-IGSLOAPL.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-RJCM34J7.mjs → chunk-KIIALACX.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-YO756PYQ.mjs → chunk-LJZ373SO.mjs} +819 -681
  42. package/dist-lib/esm-chunks/{chunk-VRQPEROV.mjs → chunk-M4ORY3NH.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-3XUIDCBF.mjs → chunk-MBWWOGI5.mjs} +4 -4
  44. package/dist-lib/esm-chunks/{chunk-M3V4F5OV.mjs → chunk-O5BPZVLB.mjs} +5 -5
  45. package/dist-lib/esm-chunks/chunk-P5Q5QCTP.mjs +32 -0
  46. package/dist-lib/esm-chunks/{chunk-O55DZ2EL.mjs → chunk-QJUAWJDB.mjs} +1 -1
  47. package/dist-lib/esm-chunks/{chunk-HHS4A7GI.mjs → chunk-RIDXKGBZ.mjs} +1 -1
  48. package/dist-lib/esm-chunks/{chunk-LG76KUUO.mjs → chunk-TD2DBEKQ.mjs} +1 -1
  49. package/dist-lib/esm-chunks/{chunk-AYHTHFG4.mjs → chunk-UTSB5CDG.mjs} +1 -1
  50. package/dist-lib/esm-chunks/{chunk-UPUOCALX.mjs → chunk-WMWOBH7E.mjs} +1 -1
  51. package/dist-lib/esm-chunks/{chunk-6TE7WLSF.mjs → chunk-ZNGLVJYL.mjs} +1 -1
  52. package/dist-lib/esm-chunks/{metro-layout-parser-YRBZCLVD.mjs → metro-layout-parser-UY3B6VGU.mjs} +3 -3
  53. package/dist-lib/esm-chunks/{swift-package-prebuilt-S7KR6TKE.mjs → swift-package-prebuilt-HDHPWS44.mjs} +10 -10
  54. package/dist-lib/esm-chunks/{swift-sdk-app-module-3JNA7PCB.mjs → swift-sdk-app-module-U6G5RZV2.mjs} +14 -14
  55. package/dist-lib/esm-chunks/{swift-sdk-image-3P4IUP2A.mjs → swift-sdk-image-PVDA2MVM.mjs} +14 -14
  56. package/dist-lib/esm-chunks/{swift-sdk-image-producer-EA2RYBM4.mjs → swift-sdk-image-producer-YHPS3KNR.mjs} +4 -4
  57. package/dist-lib/expo-swift-bundle.cjs +1519 -931
  58. package/dist-lib/expo-swift-metadata.cjs +1 -1
  59. package/dist-lib/expo-swift-metadata.mjs +7 -7
  60. package/dist-lib/home-paths.cjs +1 -1
  61. package/dist-lib/host/bridge-host.cjs +1677 -947
  62. package/dist-lib/host/fetch-proxy-handler.cjs +44 -37
  63. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  64. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
  65. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  66. package/dist-lib/host/websocket-proxy.cjs +1 -1
  67. package/dist-lib/index.cjs +1 -1
  68. package/dist-lib/kotlin-host.cjs +1 -1
  69. package/dist-lib/menu.cjs +1 -1
  70. package/dist-lib/menu.mjs +3 -3
  71. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  72. package/dist-lib/metro-fingerprint-registry.mjs +3 -3
  73. package/dist-lib/metro-production-bundle.cjs +1 -1
  74. package/dist-lib/metro-production-bundle.mjs +4 -4
  75. package/dist-lib/native-app-identity-project.cjs +540 -247
  76. package/dist-lib/native-app-identity-project.mjs +218 -1828
  77. package/dist-lib/native-app-identity.cjs +1 -1
  78. package/dist-lib/native-app-identity.mjs +6 -6
  79. package/dist-lib/native-firebase-metadata.cjs +1 -1
  80. package/dist-lib/native-firebase-metadata.mjs +3 -3
  81. package/dist-lib/pdfium-raster.cjs +1 -1
  82. package/dist-lib/pdfium-raster.mjs +2 -2
  83. package/dist-lib/plist.cjs +327 -15
  84. package/dist-lib/plist.mjs +13 -5
  85. package/dist-lib/profiles.cjs +1 -1
  86. package/dist-lib/public-brand.cjs +1 -1
  87. package/dist-lib/public-origins-lib-esm.json +82 -129
  88. package/dist-lib/public-origins-lib.json +69 -140
  89. package/dist-lib/react-native-host-modules.cjs +1 -1
  90. package/dist-lib/react-native-host-modules.mjs +2 -2
  91. package/dist-lib/reap-browser.cjs +1 -1
  92. package/dist-lib/scripts/dev-server-scanner.cjs +211 -3
  93. package/dist-lib/sdk.cjs +1 -1
  94. package/dist-lib/sdk.mjs +8 -8
  95. package/dist-lib/skills.cjs +1693 -963
  96. package/dist-lib/swift-compile.cjs +812 -673
  97. package/dist-lib/swift-compile.mjs +10 -10
  98. package/dist-lib/swift-package.cjs +1 -1
  99. package/dist-lib/swift-package.mjs +3 -3
  100. package/dist-lib/swift-submit.cjs +1 -1
  101. package/dist-lib/swift-submit.mjs +6 -6
  102. package/dist-lib/swift-svg-raster.cjs +1 -1
  103. package/dist-lib/swift-svg-raster.mjs +2 -2
  104. package/dist-lib/swift-toolchain.cjs +3 -2
  105. package/dist-lib/swift.cjs +1 -1
  106. package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
  107. package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
  108. package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
  109. package/dist-lib/vendor/acorn.cjs +1 -1
  110. package/dist-lib/vendor/magic-string.cjs +1 -1
  111. package/dist-lib/vendor/stream-json.cjs +1 -1
  112. package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
  113. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
  114. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
  115. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
  116. package/dist-lib/vendor/sucrase.cjs +1 -1
  117. package/dist-lib/vendor/terser.cjs +1 -1
  118. package/dist-lib/vendor/valibot.cjs +1 -1
  119. package/dist-lib/vendor/ws.cjs +1 -1
  120. package/dist-lib/vendor/zod.cjs +1 -1
  121. package/dist-lib/worklet-executable.cjs +1 -1
  122. package/dist-lib/worklet-executable.mjs +3 -3
  123. package/dist-types/packages/peach-engine/src/ios/apps/canvas-map-data.d.ts +38 -2
  124. package/dist-types/packages/peach-globals/src/canvasAgentContract.d.ts +8 -0
  125. package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
  126. package/package.json +1 -6
  127. package/src/agent-prompt.ts +5 -1
  128. package/src/bazel-project.ts +1 -1
  129. package/src/expo-native-prebuilt.ts +1 -1
  130. package/src/expo-workspace-exclusion.ts +1 -1
  131. package/src/gitignore.ts +175 -0
  132. package/src/intent-definition/plist-reader.ts +22 -168
  133. package/src/one-native-controls-package.ts +143 -1
  134. package/src/oneNativeControlsContract.ts +1 -0
  135. package/src/plist-bytes.ts +144 -2
  136. package/src/plist.ts +359 -2
  137. package/src/swift-compile-budget.ts +28 -7
  138. package/src/swift-compile.ts +972 -809
  139. package/src/swift-guest-compile.ts +3 -0
  140. package/src/swift-toolchain.ts +4 -1
  141. package/src/xcode-project.ts +1 -1
  142. package/dist-lib/esm-chunks/chunk-OW4VRQKO.mjs +0 -10993
  143. package/dist-lib/esm-chunks/chunk-ZSHGFGW7.mjs +0 -65
  144. package/dist-lib/vendor/@xmldom/xmldom.cjs +0 -6481
  145. package/dist-lib/vendor/bplist-parser.cjs +0 -1589
  146. package/dist-lib/vendor/ignore.cjs +0 -455
  147. package/dist-lib/vendor/plist.cjs +0 -10978
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.2605 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.2607 | (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;
@@ -2627,24 +2627,37 @@ function swiftBuilderHopTimeoutMs(compileTimeoutMs) {
2627
2627
  async function withSwiftCompileBudget(compileTimeoutMs, signal, work) {
2628
2628
  const deadline = new AbortController();
2629
2629
  const combined = signal ? AbortSignal.any([signal, deadline.signal]) : deadline.signal;
2630
+ const stallMs = compileTimeoutMs ?? SWIFT_COMPILE_TIMEOUT_MS;
2631
+ let compiling = false;
2630
2632
  let timer = setTimeout(
2631
2633
  () => deadline.abort(new Error("Swift build lock wait timed out")),
2632
2634
  SWIFT_LOCK_WAIT_TIMEOUT_MS
2633
2635
  );
2636
+ const restart = () => {
2637
+ clearTimeout(timer);
2638
+ timer = setTimeout(
2639
+ () => deadline.abort(
2640
+ new Error(
2641
+ `Swift compilation made no progress for ${Math.round(stallMs / 1e3)}s`
2642
+ )
2643
+ ),
2644
+ stallMs
2645
+ );
2646
+ };
2634
2647
  try {
2635
2648
  combined.throwIfAborted();
2636
2649
  const result = await work({
2637
2650
  signal: combined,
2638
2651
  startCompile() {
2639
2652
  combined.throwIfAborted();
2640
- clearTimeout(timer);
2641
- timer = setTimeout(
2642
- () => deadline.abort(new Error("Swift compilation timed out")),
2643
- compileTimeoutMs ?? SWIFT_COMPILE_TIMEOUT_MS
2644
- );
2653
+ compiling = true;
2654
+ restart();
2655
+ },
2656
+ progress() {
2657
+ if (compiling && !deadline.signal.aborted) restart();
2645
2658
  }
2646
2659
  });
2647
- combined.throwIfAborted();
2660
+ signal?.throwIfAborted();
2648
2661
  return result;
2649
2662
  } finally {
2650
2663
  clearTimeout(timer);
@@ -2776,7 +2789,8 @@ function swiftCompilerRelease(release) {
2776
2789
  }
2777
2790
  function swiftToolchainBin(release) {
2778
2791
  if (process.platform === "darwin") {
2779
- const dirs = [import_node_os3.default.homedir(), "/"].map(
2792
+ const bases = [.../* @__PURE__ */ new Set([import_node_os3.default.homedir(), import_node_path5.default.dirname(peachHome()), "/"])];
2793
+ const dirs = bases.map(
2780
2794
  (base) => import_node_path5.default.join(base, `Library/Developer/Toolchains/${release}.xctoolchain/usr/bin`)
2781
2795
  );
2782
2796
  const found = dirs.find((dir) => import_node_fs7.default.existsSync(import_node_path5.default.join(dir, "swift")));
@@ -20304,6 +20318,7 @@ async function compileGuestLink(options) {
20304
20318
  );
20305
20319
  continue;
20306
20320
  }
20321
+ options.onStage("lowering the app image");
20307
20322
  const lowerPromise = link.lower();
20308
20323
  await new Promise((resolve) => setImmediate(resolve));
20309
20324
  let binding;
@@ -20334,6 +20349,7 @@ async function compileGuestLink(options) {
20334
20349
  return binding;
20335
20350
  }
20336
20351
  }
20352
+ options.onStage("lowering the app image");
20337
20353
  await lowerWasm(options.output, options.optimized, {
20338
20354
  optimize: options.optimize,
20339
20355
  skipPasses: ["duplicate-function-elimination"],
@@ -21892,8 +21908,18 @@ async function runCompiler(command, args, options, stream = false, quiet) {
21892
21908
  void stopping.catch(() => {
21893
21909
  });
21894
21910
  };
21911
+ const restartTimeout = () => {
21912
+ if (!options.timeout) return;
21913
+ clearTimeout(timeout);
21914
+ timeout = setTimeout(() => {
21915
+ failure = new Error(`Swift compiler was silent for ${options.timeout}ms`);
21916
+ stop();
21917
+ }, options.timeout);
21918
+ };
21895
21919
  for (const name3 of ["stdout", "stderr"]) {
21896
21920
  child[name3].on("data", (bytes) => {
21921
+ restartTimeout();
21922
+ options.onOutput?.();
21897
21923
  if (stream === true) process[name3].write(bytes);
21898
21924
  else if (stream) {
21899
21925
  const lines = (partial[name3] + bytes.toString()).split("\n");
@@ -21942,11 +21968,7 @@ async function runCompiler(command, args, options, stream = false, quiet) {
21942
21968
  resolve(Buffer.concat(chunks.stdout).toString());
21943
21969
  }
21944
21970
  });
21945
- if (options.timeout)
21946
- timeout = setTimeout(() => {
21947
- failure = new Error("Swift compiler timed out");
21948
- stop();
21949
- }, options.timeout);
21971
+ restartTimeout();
21950
21972
  if (signal?.aborted) stop();
21951
21973
  });
21952
21974
  } finally {
@@ -24638,7 +24660,6 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
24638
24660
  (left, right) => right.path.length - left.path.length
24639
24661
  );
24640
24662
  const targetsByDir = indexTargetsByDirectory(bySourcePath);
24641
- const targetByName = new Map(targets.map((target) => [target.name, target]));
24642
24663
  const nativeTargets = input.nativeTargets ?? [];
24643
24664
  const nativeTargetByName = new Map(nativeTargets.map((target) => [target.name, target]));
24644
24665
  const nativeTargetIndex = new Map(
@@ -24714,7 +24735,6 @@ ${swiftProjectFilesProblems(input.projectFiles).join("\n")}`
24714
24735
  checkedToolchain = swiftToolchain(pin.release, swiftModuleSdk(moduleRoot));
24715
24736
  return checkedToolchain;
24716
24737
  };
24717
- const deploymentTarget = (name3) => nativeTargetByName.get(name3)?.deploymentTarget ?? targetByName.get(name3)?.iosDeploymentTarget ?? null;
24718
24738
  const targetStagedFiles = /* @__PURE__ */ new Map();
24719
24739
  const stageTargetFile = (target, file, contents2, options) => {
24720
24740
  const relative = import_node_path47.default.relative(layout2.root, file).split(import_node_path47.default.sep).join(import_node_path47.default.posix.sep);
@@ -25789,7 +25809,7 @@ ${entry}`);
25789
25809
  };
25790
25810
  for (const target of targets) {
25791
25811
  if (!target.executable && !reachesNative(target.name)) continue;
25792
- const version2 = deploymentTarget(target.name);
25812
+ const version2 = nativeTargetByName.get(target.name)?.deploymentTarget ?? target.iosDeploymentTarget ?? null;
25793
25813
  const minimum = iosDeploymentMinimum(version2);
25794
25814
  if (minimum === void 0)
25795
25815
  throw new Error(
@@ -26901,24 +26921,18 @@ function readFrameworkProductsReceipt(scratch2, receiptKey) {
26901
26921
  } catch {
26902
26922
  return null;
26903
26923
  }
26904
- const archive = import_node_path47.default.join(scratch2, "lib");
26905
- const archiveStamp = import_node_path47.default.join(archive, ".receipt");
26906
- const archiveMatches = (0, import_node_fs45.existsSync)(archiveStamp) && (0, import_node_fs45.readFileSync)(archiveStamp, "utf8") === receiptKey;
26924
+ const archiveRoot = import_node_path47.default.join(scratch2, "products-lib", receiptKey);
26925
+ if (parsed.root !== archiveRoot) return null;
26907
26926
  if (!(0, import_node_fs45.existsSync)(parsed.modules)) return null;
26908
- for (const [object4] of parsed.archived) if (!(0, import_node_fs45.existsSync)(object4)) return null;
26927
+ for (const [object4, rel] of parsed.archived) {
26928
+ if (!(0, import_node_fs45.existsSync)(object4) || !(0, import_node_fs45.existsSync)(import_node_path47.default.join(archiveRoot, rel))) return null;
26929
+ }
26909
26930
  for (const file of parsed.providers) if (!(0, import_node_fs45.existsSync)(file)) return null;
26910
26931
  for (const file of parsed.moduleMaps) if (!(0, import_node_fs45.existsSync)(file)) return null;
26911
- if (!archiveMatches) {
26912
- (0, import_node_fs45.rmSync)(archive, { recursive: true, force: true });
26913
- (0, import_node_fs45.mkdirSync)(archive, { recursive: true });
26914
- for (const [object4, rel] of parsed.archived)
26915
- (0, import_node_fs45.symlinkSync)(object4, import_node_path47.default.join(scratch2, rel));
26916
- (0, import_node_fs45.writeFileSync)(archiveStamp, receiptKey);
26917
- }
26918
26932
  for (const file of parsed.objects) if (!(0, import_node_fs45.existsSync)(file)) return null;
26919
26933
  for (const file of parsed.lazyObjects) if (!(0, import_node_fs45.existsSync)(file)) return null;
26920
26934
  return {
26921
- root: scratch2,
26935
+ root: parsed.root,
26922
26936
  modules: parsed.modules,
26923
26937
  objects: parsed.objects,
26924
26938
  lazyObjects: parsed.lazyObjects,
@@ -26936,7 +26950,7 @@ async function buildFrameworkProducts(scratch2, args) {
26936
26950
  const selectorOptions = swiftObjCSelectorOptions(args.moduleRoot);
26937
26951
  const receiptKey = (0, import_node_crypto29.createHash)("sha256").update(
26938
26952
  JSON.stringify([
26939
- "framework-products/v1",
26953
+ "framework-products/v2",
26940
26954
  args.frameworkKey,
26941
26955
  unoptimized,
26942
26956
  args.sdk,
@@ -27094,28 +27108,40 @@ async function buildFrameworkProducts(scratch2, args) {
27094
27108
  }
27095
27109
  const providers = (0, import_node_fs45.readdirSync)(providerDir).filter((file) => file.endsWith(".o")).sort().map((file) => import_node_path47.default.join(providerDir, file));
27096
27110
  for (const provider of providers) linked.owners.set(provider, "DarwinRecords");
27097
- const archive = import_node_path47.default.join(scratch2, "lib");
27098
- (0, import_node_fs45.rmSync)(archive, { recursive: true, force: true });
27099
- (0, import_node_fs45.mkdirSync)(archive);
27111
+ const archiveBase = import_node_path47.default.join(scratch2, "products-lib");
27112
+ (0, import_node_fs45.mkdirSync)(archiveBase, { recursive: true });
27113
+ const archiveRoot = import_node_path47.default.join(archiveBase, receiptKey);
27114
+ const stagedArchiveRoot = `${archiveRoot}.tmp-${process.pid}-${(0, import_node_crypto29.randomUUID)()}`;
27115
+ const stagedArchive = import_node_path47.default.join(stagedArchiveRoot, "lib");
27116
+ (0, import_node_fs45.mkdirSync)(stagedArchive, { recursive: true });
27100
27117
  const archived = /* @__PURE__ */ new Map();
27101
- for (const object4 of objects) {
27102
- const target = linked.owners.get(object4);
27103
- const dir = import_node_path47.default.join(release, `${target}.build`);
27104
- if (!target || target === "Darwin" || !object4.startsWith(dir + import_node_path47.default.sep)) continue;
27105
- const name3 = `${target}-${import_node_path47.default.relative(dir, object4).replaceAll(import_node_path47.default.sep, "-").replace(/\.swift\.o$/, ".o")}`;
27106
- (0, import_node_fs45.symlinkSync)(object4, import_node_path47.default.join(archive, name3));
27107
- archived.set(object4, `lib/${name3}`);
27108
- }
27109
- const roots = swiftObjcRootObjects(`${scratch2}
27110
- ${args.frameworkKey}`, scratch2, [
27111
- ...archived.values()
27112
- ]);
27118
+ try {
27119
+ for (const object4 of objects) {
27120
+ const target = linked.owners.get(object4);
27121
+ const dir = import_node_path47.default.join(release, `${target}.build`);
27122
+ if (!target || target === "Darwin" || !object4.startsWith(dir + import_node_path47.default.sep)) continue;
27123
+ const name3 = `${target}-${import_node_path47.default.relative(dir, object4).replaceAll(import_node_path47.default.sep, "-").replace(/\.swift\.o$/, ".o")}`;
27124
+ (0, import_node_fs45.symlinkSync)(object4, import_node_path47.default.join(stagedArchive, name3));
27125
+ archived.set(object4, `lib/${name3}`);
27126
+ }
27127
+ (0, import_node_fs45.rmSync)(archiveRoot, { recursive: true, force: true });
27128
+ (0, import_node_fs45.renameSync)(stagedArchiveRoot, archiveRoot);
27129
+ } catch (error) {
27130
+ (0, import_node_fs45.rmSync)(stagedArchiveRoot, { recursive: true, force: true });
27131
+ throw error;
27132
+ }
27133
+ const roots = swiftObjcRootObjects(
27134
+ `${archiveRoot}
27135
+ ${args.frameworkKey}`,
27136
+ archiveRoot,
27137
+ [...archived.values()]
27138
+ );
27113
27139
  const linkedObjects = objects.map((object4) => {
27114
27140
  const name3 = archived.get(object4);
27115
- return name3 ? { path: import_node_path47.default.join(scratch2, name3), lazy: !roots.has(name3) } : { path: object4, lazy: false };
27141
+ return name3 ? { path: import_node_path47.default.join(archiveRoot, name3), lazy: !roots.has(name3) } : { path: object4, lazy: false };
27116
27142
  });
27117
27143
  const result = {
27118
- root: scratch2,
27144
+ root: archiveRoot,
27119
27145
  modules: import_node_path47.default.join(release, "Modules"),
27120
27146
  objects: linkedObjects.filter((object4) => !object4.lazy).map((object4) => object4.path),
27121
27147
  lazyObjects: linkedObjects.filter((object4) => object4.lazy).map((object4) => object4.path),
@@ -27125,7 +27151,6 @@ ${args.frameworkKey}`, scratch2, [
27125
27151
  moduleMaps: linked.moduleMaps,
27126
27152
  objcHeaders: linked.objcHeaders
27127
27153
  };
27128
- (0, import_node_fs45.writeFileSync)(import_node_path47.default.join(archive, ".receipt"), receiptKey);
27129
27154
  const receiptsDir = import_node_path47.default.join(scratch2, "products-ready");
27130
27155
  (0, import_node_fs45.mkdirSync)(receiptsDir, { recursive: true });
27131
27156
  const receiptFile = import_node_path47.default.join(receiptsDir, `${receiptKey}.json`);
@@ -27133,6 +27158,7 @@ ${args.frameworkKey}`, scratch2, [
27133
27158
  (0, import_node_fs45.writeFileSync)(
27134
27159
  partialReceipt,
27135
27160
  JSON.stringify({
27161
+ root: result.root,
27136
27162
  modules: result.modules,
27137
27163
  objects: result.objects,
27138
27164
  lazyObjects: result.lazyObjects,
@@ -27164,7 +27190,10 @@ function swiftFrameworkSlotRecord(slot, record) {
27164
27190
  function swiftFrameworkSlotKey(slot) {
27165
27191
  return swiftFrameworkSlotRecord(slot, SWIFT_FRAMEWORK_SLOT_KEY);
27166
27192
  }
27167
- async function withSwiftFrameworkSlot(frameworkKey, moduleRoot, signal, work, unoptimized = false) {
27193
+ function swiftFrameworkSlotRelease(slot) {
27194
+ return swiftFrameworkSlotRecord(slot, SWIFT_FRAMEWORK_SLOT_RELEASE);
27195
+ }
27196
+ async function withSwiftFrameworkSlot(frameworkKey, release, moduleRoot, signal, work, unoptimized = false) {
27168
27197
  const slotCount = unoptimized ? SWIFT_FRAMEWORK_UNOPTIMIZED_SLOTS : SWIFT_FRAMEWORK_SLOTS;
27169
27198
  const slotsDir = swiftFrameworksDir(unoptimized);
27170
27199
  const slots = Array.from({ length: slotCount }, (_, index) => {
@@ -27187,9 +27216,12 @@ async function withSwiftFrameworkSlot(frameworkKey, moduleRoot, signal, work, un
27187
27216
  (0, import_node_fs45.readFileSync)(import_node_path47.default.join(moduleRoot, file))
27188
27217
  ])
27189
27218
  );
27190
- const ranked = slots.map((slot) => {
27219
+ const ranked = slots.map((slot, index) => {
27220
+ const slotKey = swiftFrameworkSlotKey(slot);
27221
+ if (slotKey === null) return { slot, index, tier: 1, changes: Infinity };
27222
+ if (swiftFrameworkSlotRelease(slot) !== release)
27223
+ return { slot, index, tier: 2, changes: Infinity };
27191
27224
  let changes = 0;
27192
- if (swiftFrameworkSlotKey(slot) === null) return { slot, changes: Infinity };
27193
27225
  const source = import_node_path47.default.join(slot, "source", "packages", import_node_path47.default.basename(moduleRoot));
27194
27226
  for (const [file, contents2] of inputs) {
27195
27227
  try {
@@ -27201,18 +27233,22 @@ async function withSwiftFrameworkSlot(frameworkKey, moduleRoot, signal, work, un
27201
27233
  changes++;
27202
27234
  }
27203
27235
  }
27204
- return { slot, changes };
27205
- }).sort(
27206
- (left, right) => left.changes - right.changes || Number(own(right.slot)) - Number(own(left.slot)) || (built.get(right.slot) ?? 0) - (built.get(left.slot) ?? 0)
27207
- );
27208
- for (const { slot, changes } of ranked) {
27236
+ return { slot, index, tier: 0, changes };
27237
+ }).sort((left, right) => {
27238
+ if (left.tier !== right.tier) return left.tier - right.tier;
27239
+ if (left.tier === 0)
27240
+ return left.changes - right.changes || Number(own(right.slot)) - Number(own(left.slot)) || (built.get(right.slot) ?? 0) - (built.get(left.slot) ?? 0);
27241
+ if (left.tier === 1) return left.index - right.index;
27242
+ return (built.get(left.slot) ?? 0) - (built.get(right.slot) ?? 0);
27243
+ });
27244
+ for (const { slot, tier, changes } of ranked) {
27209
27245
  if (await hasLiveSwiftRootReaders(slot, signal)) continue;
27210
27246
  const result = await withSwiftRootLock(
27211
27247
  slot,
27212
27248
  async (lease) => {
27213
27249
  if (await hasLiveSwiftRootReaders(slot, signal)) return void 0;
27214
27250
  console.error(
27215
- `[swift-framework-cache] ${import_node_path47.default.basename(slot)} changedInputs=${changes} totalInputs=${inputs.size}`
27251
+ `[swift-framework-cache] ${import_node_path47.default.basename(slot)} release=${release} tier=${tier} changedInputs=${changes} totalInputs=${inputs.size}`
27216
27252
  );
27217
27253
  return { value: await run5(slot)(lease) };
27218
27254
  },
@@ -27224,6 +27260,43 @@ async function withSwiftFrameworkSlot(frameworkKey, moduleRoot, signal, work, un
27224
27260
  const nearest = ranked[0].slot;
27225
27261
  return withSwiftRootLock(nearest, run5(nearest), signal);
27226
27262
  }
27263
+ async function withSwiftBuildRootSlot(baseRoot, buildShape, signal, work) {
27264
+ const slots = Array.from({ length: SWIFT_BUILD_ROOT_SLOTS }, (_, index) => {
27265
+ const slot = index === 0 ? baseRoot : `${baseRoot}-s${index}`;
27266
+ (0, import_node_fs45.mkdirSync)(slot, { recursive: true });
27267
+ return slot;
27268
+ });
27269
+ const runInSlot = (slot, waitStart2) => (lease) => {
27270
+ const waitedMs = Date.now() - waitStart2;
27271
+ const now = /* @__PURE__ */ new Date();
27272
+ (0, import_node_fs45.utimesSync)(slot, now, now);
27273
+ return work(slot, lease, waitedMs);
27274
+ };
27275
+ const built = new Map(slots.map((slot) => [slot, (0, import_node_fs45.statSync)(slot).mtimeMs]));
27276
+ const ranked = slots.map((slot, index) => {
27277
+ const shape = swiftFrameworkSlotRecord(slot, SWIFT_BUILD_ROOT_SHAPE);
27278
+ const tier = shape === buildShape ? 0 : shape === null ? 1 : 2;
27279
+ return { slot, index, tier };
27280
+ }).sort((left, right) => {
27281
+ if (left.tier !== right.tier) return left.tier - right.tier;
27282
+ if (left.tier === 0)
27283
+ return (built.get(right.slot) ?? 0) - (built.get(left.slot) ?? 0);
27284
+ if (left.tier === 1) return left.index - right.index;
27285
+ return (built.get(left.slot) ?? 0) - (built.get(right.slot) ?? 0);
27286
+ });
27287
+ for (const { slot } of ranked) {
27288
+ const result = await withSwiftRootLock(
27289
+ slot,
27290
+ async (lease) => ({ value: await runInSlot(slot, Date.now())(lease) }),
27291
+ signal,
27292
+ false
27293
+ );
27294
+ if (result) return result.value;
27295
+ }
27296
+ const nearest = ranked[0].slot;
27297
+ const waitStart = Date.now();
27298
+ return withSwiftRootLock(nearest, runInSlot(nearest, waitStart), signal);
27299
+ }
27227
27300
  function mirrorTree2(source, target, skip) {
27228
27301
  (0, import_node_fs45.mkdirSync)(target, { recursive: true });
27229
27302
  const wanted = /* @__PURE__ */ new Set();
@@ -27273,8 +27346,10 @@ function stageFrameworkSource(moduleRoot, slot, frameworkKey, release) {
27273
27346
  const hadKey = swiftFrameworkSlotKey(slot);
27274
27347
  if (hadKey !== frameworkKey) {
27275
27348
  (0, import_node_fs45.rmSync)(import_node_path47.default.join(slot, SWIFT_FRAMEWORK_SLOT_KEY), { force: true });
27349
+ (0, import_node_fs45.rmSync)(import_node_path47.default.join(slot, SWIFT_FRAMEWORK_SLOT_RELEASE), { force: true });
27276
27350
  (0, import_node_fs45.rmSync)(import_node_path47.default.join(slot, "products-ready"), { recursive: true, force: true });
27277
- (0, import_node_fs45.rmSync)(import_node_path47.default.join(slot, "lib", ".receipt"), { force: true });
27351
+ (0, import_node_fs45.rmSync)(import_node_path47.default.join(slot, "products-lib"), { recursive: true, force: true });
27352
+ (0, import_node_fs45.rmSync)(import_node_path47.default.join(slot, "lib"), { recursive: true, force: true });
27278
27353
  const moduleRestructured = mirrorTree2(moduleRoot, stagedModule, ".build");
27279
27354
  const sdkRestructured = mirrorTree2(
27280
27355
  swiftSharedSdkRoot(moduleRoot, false),
@@ -27302,8 +27377,11 @@ function stageFrameworkSource(moduleRoot, slot, frameworkKey, release) {
27302
27377
  (0, import_node_fs45.rmSync)(modules, { recursive: true, force: true });
27303
27378
  (0, import_node_fs45.symlinkSync)(target, modules);
27304
27379
  }
27380
+ (0, import_node_fs45.writeFileSync)(import_node_path47.default.join(slot, SWIFT_FRAMEWORK_SLOT_RELEASE), release);
27305
27381
  (0, import_node_fs45.writeFileSync)(import_node_path47.default.join(slot, SWIFT_FRAMEWORK_SLOT_KEY), frameworkKey);
27306
27382
  (0, import_node_fs45.writeFileSync)(import_node_path47.default.join(slot, SWIFT_FRAMEWORK_SLOT_ORIGIN), moduleRoot);
27383
+ } else if (swiftFrameworkSlotRelease(slot) !== release) {
27384
+ (0, import_node_fs45.writeFileSync)(import_node_path47.default.join(slot, SWIFT_FRAMEWORK_SLOT_RELEASE), release);
27307
27385
  }
27308
27386
  return stagedModule;
27309
27387
  }
@@ -27531,660 +27609,717 @@ ${cap}` : "";
27531
27609
  (0, import_node_fs45.rmSync)(requestRoot, { recursive: true, force: true });
27532
27610
  }
27533
27611
  }
27612
+ const baseRoot = root;
27613
+ const canPoolBuildRoot = !options.intermediates && !options.project && !options.linkOnly && import_node_path47.default.basename(import_node_path47.default.dirname(baseRoot)) === "swift-builds";
27614
+ const buildShape = canPoolBuildRoot ? (0, import_node_crypto29.createHash)("sha256").update(
27615
+ JSON.stringify([
27616
+ frameworkKey,
27617
+ Boolean(sdkImage),
27618
+ compileTargets(input).map((target) => target.name).sort(),
27619
+ input.oneModule === true,
27620
+ input.optimize === true,
27621
+ input.unoptimized === true,
27622
+ Object.keys(input.files).sort()
27623
+ ])
27624
+ ).digest("hex").slice(0, 16) : "";
27534
27625
  return withSwiftCompileBudget(options.timeoutMs, options.signal, async (budget) => {
27535
- return withSwiftRootLock(
27536
- root,
27537
- async (lease) => {
27538
- if (!options.intermediates) {
27539
- const built = readCompiledArtifact(import_node_path47.default.join(sharedRoot, "artifact"), hash);
27540
- if (built) {
27541
- report("reusing verified disk artifact");
27542
- return retain(root, built);
27543
- }
27544
- }
27545
- const swift = import_node_path47.default.join(options.toolchainBin, "swift");
27546
- if (!(0, import_node_fs45.existsSync)(swift)) {
27547
- throw new Error(
27548
- `swift-compile: no swift.org toolchain at ${options.toolchainBin}; install ${options.release} and its matching wasm sdk`
27549
- );
27626
+ const stage = (message) => {
27627
+ budget.progress();
27628
+ report(message);
27629
+ };
27630
+ const runLocked = (work) => {
27631
+ if (canPoolBuildRoot) {
27632
+ (0, import_node_fs45.mkdirSync)(sharedRoot, { recursive: true });
27633
+ return withSwiftRootLock(
27634
+ sharedRoot,
27635
+ async () => {
27636
+ const built = readCompiledArtifact(
27637
+ import_node_path47.default.join(sharedRoot, "artifact"),
27638
+ hash
27639
+ );
27640
+ if (built) {
27641
+ stage("reusing verified disk artifact");
27642
+ return retain(baseRoot, built);
27643
+ }
27644
+ return withSwiftBuildRootSlot(baseRoot, buildShape, budget.signal, work);
27645
+ },
27646
+ budget.signal
27647
+ );
27648
+ }
27649
+ const waitStart = Date.now();
27650
+ return withSwiftRootLock(
27651
+ baseRoot,
27652
+ (lease) => work(baseRoot, lease, Date.now() - waitStart),
27653
+ budget.signal
27654
+ );
27655
+ };
27656
+ return runLocked(async (slotRoot, lease, waitedMs) => {
27657
+ const root2 = slotRoot;
27658
+ const layout3 = {
27659
+ root: root2,
27660
+ sources: import_node_path47.default.join(root2, "Sources", "App"),
27661
+ multi: compileTargets(input).length > 0
27662
+ };
27663
+ if (!options.intermediates) {
27664
+ const built = readCompiledArtifact(import_node_path47.default.join(sharedRoot, "artifact"), hash);
27665
+ if (built) {
27666
+ stage("reusing verified disk artifact");
27667
+ return retain(baseRoot, built);
27550
27668
  }
27551
- const unoptimized = input.unoptimized === true;
27552
- const withFrameworkLock = (work) => distribution ? work(null) : withSwiftFrameworkSlot(
27553
- frameworkKey,
27554
- moduleRoot,
27669
+ }
27670
+ if (waitedMs >= 1e3)
27671
+ report(`acquired build root ${import_node_path47.default.basename(root2)} after ${waitedMs}ms`);
27672
+ if (canPoolBuildRoot) {
27673
+ refreshSwiftCacheHold(root2);
27674
+ (0, import_node_fs45.writeFileSync)(import_node_path47.default.join(root2, SWIFT_BUILD_ROOT_SHAPE), buildShape);
27675
+ }
27676
+ const swift = import_node_path47.default.join(options.toolchainBin, "swift");
27677
+ if (!(0, import_node_fs45.existsSync)(swift)) {
27678
+ throw new Error(
27679
+ `swift-compile: no swift.org toolchain at ${options.toolchainBin}; install ${options.release} and its matching wasm sdk`
27680
+ );
27681
+ }
27682
+ const unoptimized = input.unoptimized === true;
27683
+ const withFrameworkLock = (work) => distribution ? work(null) : withSwiftFrameworkSlot(
27684
+ frameworkKey,
27685
+ options.release,
27686
+ moduleRoot,
27687
+ budget.signal,
27688
+ work,
27689
+ unoptimized
27690
+ );
27691
+ const baseBuildEnv = options.project?.env ? {
27692
+ ...options.project.env,
27693
+ // shipped host plugins resolve against the selected compiler's runtime.
27694
+ ...process.platform === "linux" ? {
27695
+ LD_LIBRARY_PATH: [
27696
+ import_node_path47.default.resolve(options.toolchainBin, "../lib/swift/linux"),
27697
+ import_node_path47.default.resolve(options.toolchainBin, "../lib/swift/host"),
27698
+ process.env.LD_LIBRARY_PATH
27699
+ ].filter(Boolean).join(":")
27700
+ } : {},
27701
+ PEACH_DEFER_WASM_LINK: "1"
27702
+ } : swiftCompilerBaseEnv(options.toolchainBin, process.env);
27703
+ const {
27704
+ frameworkRoot,
27705
+ compileFrameworkRoot,
27706
+ macroPlugins,
27707
+ sdk,
27708
+ icu,
27709
+ prebuilt,
27710
+ readHold
27711
+ } = await withFrameworkLock(async (slot, frameworkLease) => {
27712
+ budget.startCompile();
27713
+ if (slot && swiftFrameworkSlotKey(slot) !== frameworkKey)
27714
+ await waitForNoSwiftRootReaders(slot, budget.signal);
27715
+ const frameworkRoot2 = mirrorDistribution ? syncSwiftDistributionMirror(root2, moduleRoot, mirrorDistribution) : distribution ? moduleRoot : stageFrameworkSource(moduleRoot, slot, frameworkKey, options.release);
27716
+ if (!swiftModuleDigest(frameworkRoot2).equals(moduleDigest))
27717
+ throw new Error("Swift staged project source differs from the caller");
27718
+ stage("preparing compiler plugins");
27719
+ const macroPlugins2 = await ensureMacroPlugins(
27720
+ frameworkRoot2,
27721
+ options.toolchainBin,
27722
+ options.release,
27555
27723
  budget.signal,
27556
- work,
27557
- unoptimized
27724
+ frameworkLease
27558
27725
  );
27559
- const baseBuildEnv = options.project?.env ? {
27560
- ...options.project.env,
27561
- // shipped host plugins resolve against the selected compiler's runtime.
27562
- ...process.platform === "linux" ? {
27563
- LD_LIBRARY_PATH: [
27564
- import_node_path47.default.resolve(options.toolchainBin, "../lib/swift/linux"),
27565
- import_node_path47.default.resolve(options.toolchainBin, "../lib/swift/host"),
27566
- process.env.LD_LIBRARY_PATH
27567
- ].filter(Boolean).join(":")
27568
- } : {},
27569
- PEACH_DEFER_WASM_LINK: "1"
27570
- } : swiftCompilerBaseEnv(options.toolchainBin, process.env);
27571
- const {
27726
+ const compileFrameworkRoot2 = distribution ? swiftDistributionCompileView(frameworkRoot2, distribution) : frameworkRoot2;
27727
+ const sdk2 = swiftModuleSdk(frameworkRoot2).wasmSdkId;
27728
+ const icu2 = options.linkOnly ? null : swiftIcuAsset(options.toolchainBin, sdk2);
27729
+ let prebuilt2;
27730
+ if (!distribution) {
27731
+ stage("compiling framework products");
27732
+ prebuilt2 = await buildFrameworkProducts(slot, {
27733
+ moduleRoot: frameworkRoot2,
27734
+ frameworkKey,
27735
+ input,
27736
+ swift,
27737
+ sdk: sdk2,
27738
+ toolchainBin: options.toolchainBin,
27739
+ plugins: macroPlugins2,
27740
+ buildOptions: {
27741
+ env: baseBuildEnv,
27742
+ maxBuffer: 64 * 1024 * 1024,
27743
+ signal: budget.signal,
27744
+ onOutput: budget.progress,
27745
+ lease,
27746
+ frameworkLease
27747
+ }
27748
+ });
27749
+ }
27750
+ const readHold2 = slot ? acquireSwiftRootReadHold(slot) : void 0;
27751
+ return {
27752
+ frameworkRoot: frameworkRoot2,
27753
+ compileFrameworkRoot: compileFrameworkRoot2,
27754
+ macroPlugins: macroPlugins2,
27755
+ sdk: sdk2,
27756
+ icu: icu2,
27757
+ prebuilt: prebuilt2,
27758
+ readHold: readHold2
27759
+ };
27760
+ });
27761
+ const buildOptions = {
27762
+ env: baseBuildEnv,
27763
+ maxBuffer: 64 * 1024 * 1024,
27764
+ signal: budget.signal,
27765
+ onOutput: budget.progress,
27766
+ lease
27767
+ };
27768
+ try {
27769
+ if (options.project) removeProjectLinks(root2);
27770
+ const packageHostMacros = process.platform === "linux" ? input.packageHostMacros : void 0;
27771
+ if (retireStaleSwiftLink(
27772
+ root2,
27773
+ swiftLinkStamp({
27774
+ frameworkKey: `${options.release}\0${Boolean(distribution)}\0${swiftModuleSdk(frameworkRoot).wasmSdkId}`,
27775
+ packageHostMacros
27776
+ }),
27777
+ swiftLinkStamp({
27778
+ // a distribution's objects reach only the deferred link, and
27779
+ // the root's mirror keeps its compile inputs at fixed paths
27780
+ frameworkKey: distribution ? `${options.release}\0${distribution.wasmSdkChecksum}` : frameworkKey,
27781
+ prebuilt,
27782
+ packageHostMacros
27783
+ }),
27784
+ Boolean(options.linkOnly)
27785
+ ))
27786
+ stage("framework revision changed; rebuilding the app link");
27787
+ const nativeToolset = needsNativeToolset(input, prebuilt);
27788
+ const preparation = writeSwiftProject(
27789
+ layout3,
27790
+ input,
27572
27791
  frameworkRoot,
27573
- compileFrameworkRoot,
27574
- macroPlugins,
27575
- sdk,
27576
- icu,
27577
27792
  prebuilt,
27578
- readHold
27579
- } = await withFrameworkLock(async (slot, frameworkLease) => {
27580
- budget.startCompile();
27581
- if (slot && swiftFrameworkSlotKey(slot) !== frameworkKey)
27582
- await waitForNoSwiftRootReaders(slot, budget.signal);
27583
- const frameworkRoot2 = mirrorDistribution ? syncSwiftDistributionMirror(root, moduleRoot, mirrorDistribution) : distribution ? moduleRoot : stageFrameworkSource(moduleRoot, slot, frameworkKey, options.release);
27584
- if (!swiftModuleDigest(frameworkRoot2).equals(moduleDigest))
27585
- throw new Error("Swift staged project source differs from the caller");
27586
- report("preparing compiler plugins");
27587
- const macroPlugins2 = await ensureMacroPlugins(
27588
- frameworkRoot2,
27589
- options.toolchainBin,
27590
- options.release,
27591
- budget.signal,
27592
- frameworkLease
27793
+ !options.project,
27794
+ options.project ? false : options.objcPrebuiltStage ?? (options.intermediates ? false : void 0)
27795
+ );
27796
+ const productFile = import_node_path47.default.join(frameworkRoot, SWIFT_FRAMEWORK_PRODUCT_FILE);
27797
+ writeSwiftAutolinkLinker(
27798
+ root2,
27799
+ options.toolchainBin,
27800
+ (0, import_node_fs45.existsSync)(productFile) ? [
27801
+ v6.parse(
27802
+ swiftFrameworkProductSchema,
27803
+ JSON.parse((0, import_node_fs45.readFileSync)(productFile, "utf8"))
27804
+ ).product.name
27805
+ ] : []
27806
+ );
27807
+ const compiler = preparation.targetToolset ? { CC: import_node_path47.default.join(root2, CLANG_TARGET_MODULE_WRAPPER) } : {};
27808
+ if (packageHostMacros?.length) {
27809
+ const swiftc = import_node_path47.default.join(root2, SWIFT_HOST_COMPILER_WRAPPER);
27810
+ writeBuildFile(
27811
+ swiftc,
27812
+ [
27813
+ "#!/bin/sh",
27814
+ "target=",
27815
+ "module=",
27816
+ "compile=",
27817
+ "previous=",
27818
+ "for argument do",
27819
+ ' case "$previous" in -target) target=$argument ;; -module-name) module=$argument ;; esac',
27820
+ ' case "$argument" in -c|-emit-module|-scan-dependencies|-typecheck) compile=1 ;; esac',
27821
+ " previous=$argument",
27822
+ "done",
27823
+ 'case "$target/$compile" in',
27824
+ " *-*-linux*/1)",
27825
+ ' case ",$PEACH_SWIFT_HOST_MACROS," in',
27826
+ ' *",$module,"*) set -- "$@" -Xfrontend -import-module -Xfrontend Foundation ;;',
27827
+ " esac ;;",
27828
+ "esac",
27829
+ 'exec "$PEACH_SWIFTC" "$@"',
27830
+ ""
27831
+ ].join("\n")
27593
27832
  );
27594
- const compileFrameworkRoot2 = distribution ? swiftDistributionCompileView(frameworkRoot2, distribution) : frameworkRoot2;
27595
- const sdk2 = swiftModuleSdk(frameworkRoot2).wasmSdkId;
27596
- const icu2 = options.linkOnly ? null : swiftIcuAsset(options.toolchainBin, sdk2);
27597
- let prebuilt2;
27598
- if (!distribution) {
27599
- report("compiling framework products");
27600
- prebuilt2 = await buildFrameworkProducts(slot, {
27601
- moduleRoot: frameworkRoot2,
27602
- frameworkKey,
27603
- input,
27604
- swift,
27605
- sdk: sdk2,
27606
- toolchainBin: options.toolchainBin,
27607
- plugins: macroPlugins2,
27608
- buildOptions: {
27609
- env: baseBuildEnv,
27610
- maxBuffer: 64 * 1024 * 1024,
27611
- signal: budget.signal,
27612
- lease,
27613
- frameworkLease
27614
- }
27615
- });
27833
+ (0, import_node_fs45.chmodSync)(swiftc, 493);
27834
+ compiler.SWIFT_EXEC = swiftc;
27835
+ compiler.PEACH_SWIFT_HOST_MACROS = packageHostMacros.join(",");
27836
+ compiler.PEACH_SWIFTC = import_node_path47.default.join(options.toolchainBin, "swiftc");
27837
+ }
27838
+ const projectProcess = options.project ? prepareSwiftProjectProcess(root2, options.project) : void 0;
27839
+ const temporaryDirectory = projectProcess ? void 0 : import_node_path47.default.join(root2, ".build", "peach-compiler-tmp");
27840
+ const appOptions = projectProcess ? {
27841
+ ...buildOptions,
27842
+ uid: projectProcess.uid,
27843
+ gid: projectProcess.gid,
27844
+ confined: { ...projectProcess.env, ...compiler }
27845
+ } : {
27846
+ ...buildOptions,
27847
+ temporaryDirectory,
27848
+ env: {
27849
+ ...buildOptions.env,
27850
+ ...preparation.usesObjcPrebuilt && process.env.PEACH_HOME !== void 0 ? { PEACH_HOME: process.env.PEACH_HOME } : {},
27851
+ ...compiler
27616
27852
  }
27617
- const readHold2 = slot ? acquireSwiftRootReadHold(slot) : void 0;
27618
- return {
27619
- frameworkRoot: frameworkRoot2,
27620
- compileFrameworkRoot: compileFrameworkRoot2,
27621
- macroPlugins: macroPlugins2,
27622
- sdk: sdk2,
27623
- icu: icu2,
27624
- prebuilt: prebuilt2,
27625
- readHold: readHold2
27626
- };
27627
- });
27628
- const buildOptions = {
27629
- env: baseBuildEnv,
27630
- maxBuffer: 64 * 1024 * 1024,
27631
- signal: budget.signal,
27632
- lease
27633
27853
  };
27634
- try {
27635
- if (options.project) removeProjectLinks(root);
27636
- const packageHostMacros = process.platform === "linux" ? input.packageHostMacros : void 0;
27637
- if (retireStaleSwiftLink(
27638
- root,
27639
- swiftLinkStamp({
27640
- frameworkKey: `${options.release}\0${Boolean(distribution)}\0${swiftModuleSdk(frameworkRoot).wasmSdkId}`,
27641
- packageHostMacros
27642
- }),
27643
- swiftLinkStamp({
27644
- // a distribution's objects reach only the deferred link, and
27645
- // the root's mirror keeps its compile inputs at fixed paths
27646
- frameworkKey: distribution ? `${options.release}\0${distribution.wasmSdkChecksum}` : frameworkKey,
27647
- prebuilt,
27648
- packageHostMacros
27649
- }),
27650
- Boolean(options.linkOnly)
27651
- ))
27652
- report("framework revision changed; rebuilding the app link");
27653
- const nativeToolset = needsNativeToolset(input, prebuilt);
27654
- const preparation = writeSwiftProject(
27655
- layout2,
27656
- input,
27657
- frameworkRoot,
27658
- prebuilt,
27659
- !options.project,
27660
- options.project ? false : options.objcPrebuiltStage ?? (options.intermediates ? false : void 0)
27854
+ const unprepared = preparation.targetFailures.map(
27855
+ (failure) => `error: target ${failure}`
27856
+ );
27857
+ const forwarders = /* @__PURE__ */ new Map();
27858
+ for (const [file, text2] of Object.entries(input.files)) {
27859
+ const parents = /^#include "((?:\.\.\/)+)[^"\n]+"\n$/.exec(text2)?.[1];
27860
+ if (!parents) continue;
27861
+ const directory = import_node_path47.default.posix.dirname(file);
27862
+ forwarders.set(
27863
+ `${import_node_path47.default.join(root2, directory)}/${parents.slice(0, -1)}`,
27864
+ import_node_path47.default.posix.join("build", directory, parents).replace(/\/$/, "")
27661
27865
  );
27662
- const productFile = import_node_path47.default.join(frameworkRoot, SWIFT_FRAMEWORK_PRODUCT_FILE);
27663
- writeSwiftAutolinkLinker(
27664
- root,
27665
- options.toolchainBin,
27666
- (0, import_node_fs45.existsSync)(productFile) ? [
27667
- v6.parse(
27668
- swiftFrameworkProductSchema,
27669
- JSON.parse((0, import_node_fs45.readFileSync)(productFile, "utf8"))
27670
- ).product.name
27671
- ] : []
27866
+ }
27867
+ const jobs = swiftCompilerJobs();
27868
+ const incrementalPreview = sdkImage !== void 0 && !guestGraph && !options.project && !input.optimize && !input.unoptimized;
27869
+ const perFile = input.unoptimized || incrementalPreview;
27870
+ const buildArgs = [
27871
+ "build",
27872
+ ...projectProcess?.cacheOptions ?? swiftPackageCacheOptions(),
27873
+ "--build-system",
27874
+ "native",
27875
+ "-j",
27876
+ String(jobs),
27877
+ "--package-path",
27878
+ root2,
27879
+ ...swiftCompileSdkOptions(frameworkRoot, options.toolchainBin),
27880
+ ...swiftObjCSelectorOptions(frameworkRoot),
27881
+ "--swift-sdk",
27882
+ sdk,
27883
+ ...preparation.targetToolset ? ["--toolset", import_node_path47.default.join(root2, ".peach-target-toolset.json")] : [],
27884
+ "-c",
27885
+ "release",
27886
+ ...input.unoptimized ? ["-Xswiftc", "-Onone"] : [],
27887
+ ...perFile ? [
27888
+ "-Xswiftc",
27889
+ "-no-whole-module-optimization",
27890
+ "-Xswiftc",
27891
+ "-j",
27892
+ "-Xswiftc",
27893
+ String(jobs)
27894
+ ] : [],
27895
+ ...incrementalPreview ? ["-Xswiftc", "-incremental", "-Xswiftc", "-enable-batch-mode"] : [],
27896
+ // the mirror finds a changed sdk header's readers in their
27897
+ // dependency files, which omit system headers by default
27898
+ ...mirrorDistribution ? ["-Xswiftc", "-track-system-dependencies"] : [],
27899
+ // the link strips debug info, so none is generated (as for the framework).
27900
+ // keep -num-threads fixed across caller core caps so llbuild does not
27901
+ // rebuild every target when callers alternate --cores, and bound backend
27902
+ // fan-out under high -j.
27903
+ "-Xswiftc",
27904
+ "-gnone",
27905
+ ...incrementalPreview ? [] : [
27906
+ "-Xswiftc",
27907
+ "-num-threads",
27908
+ "-Xswiftc",
27909
+ String(perFile ? 1 : Math.min(8, import_node_os11.default.availableParallelism()))
27910
+ ],
27911
+ ...swiftReproducibleBuildFlags([
27912
+ [import_node_path47.default.dirname(options.toolchainBin), "toolchain"],
27913
+ [compileFrameworkRoot, "framework"],
27914
+ [root2, "build"],
27915
+ ...forwarders
27916
+ ]).flatMap((flag, index, flags) => {
27917
+ if (!nativeToolset || !flag.startsWith("-ffile-prefix-map="))
27918
+ return [flag];
27919
+ const toolchainDir = import_node_path47.default.dirname(options.toolchainBin);
27920
+ let mapped = flag;
27921
+ for (const [dir, target] of [
27922
+ [root2, "/peach/build"],
27923
+ [compileFrameworkRoot, "/peach/framework"],
27924
+ [(0, import_node_fs45.realpathSync)(compileFrameworkRoot), "/peach/framework"],
27925
+ [toolchainDir, "/peach/toolchain"],
27926
+ [(0, import_node_fs45.realpathSync)(toolchainDir), "/peach/toolchain"]
27927
+ ]) {
27928
+ mapped = mapped.replaceAll(dir, target);
27929
+ }
27930
+ const [, from, to] = /^-ffile-prefix-map=([^=]+)=(.+)$/.exec(mapped) ?? [];
27931
+ const tool = flags[index - 1];
27932
+ return mapped !== flag && from !== to ? [flag, tool, mapped] : [flag];
27933
+ }),
27934
+ ...macroPlugins.libraries.flatMap((plugin) => [
27935
+ "-Xswiftc",
27936
+ "-load-plugin-library",
27937
+ "-Xswiftc",
27938
+ plugin
27939
+ ]),
27940
+ ...macroPlugins.executables.flatMap((plugin) => [
27941
+ "-Xswiftc",
27942
+ "-load-plugin-executable",
27943
+ "-Xswiftc",
27944
+ `${plugin}#ExpoModulesMacros`
27945
+ ])
27946
+ ];
27947
+ const linked = builtArtifact(layout3);
27948
+ (0, import_node_fs45.rmSync)(import_node_path47.default.join(root2, ".peach-link.rsp"), { force: true });
27949
+ if (options.linkOnly || (0, import_node_fs45.existsSync)(linked) && (0, import_node_fs45.statSync)(linked).size <= 8)
27950
+ (0, import_node_fs45.rmSync)(linked, { force: true });
27951
+ stage("compiling and linking Swift modules");
27952
+ const frameworkInterfaces = /* @__PURE__ */ new Map();
27953
+ const sdkFrameworks = import_node_path47.default.join(
27954
+ swiftSdkPaths(frameworkRoot, options.toolchainBin).darwin,
27955
+ "System/Library/Frameworks"
27956
+ );
27957
+ const generatedInterface = (source) => withoutImportedSdkEnumForwards(
27958
+ clangInterfaceHeader((0, import_node_fs45.readFileSync)(source, "utf8"), frameworkRoot),
27959
+ sdkObjCDeclarationOwners(sdkFrameworks)
27960
+ );
27961
+ const nativeDeclarations = /* @__PURE__ */ new Map();
27962
+ const nativeHeaders = Object.entries(input.files).filter(([name3]) => name3.endsWith(".h") && !name3.endsWith("-Swift.h")).map(([, source]) => source);
27963
+ for (const [file, contents2] of Object.entries(input.files)) {
27964
+ if (!file.endsWith(".modulemap")) continue;
27965
+ const name3 = moduleMapName(contents2);
27966
+ const umbrella = /\bumbrella\s+header\s+"([^"]+)"/.exec(contents2)?.[1];
27967
+ if (!name3 || !umbrella) continue;
27968
+ const header = input.files[import_node_path47.default.posix.join(import_node_path47.default.posix.dirname(file), umbrella)];
27969
+ if (header === void 0) continue;
27970
+ const included = new Set(
27971
+ [
27972
+ ...header.matchAll(/^\s*#\s*(?:import|include)\s*[<"]([^">]+)[">]/gm)
27973
+ ].map((match) => import_node_path47.default.posix.basename(match[1]))
27672
27974
  );
27673
- const compiler = preparation.targetToolset ? { CC: import_node_path47.default.join(root, CLANG_TARGET_MODULE_WRAPPER) } : {};
27674
- if (packageHostMacros?.length) {
27675
- const swiftc = import_node_path47.default.join(root, SWIFT_HOST_COMPILER_WRAPPER);
27676
- writeBuildFile(
27677
- swiftc,
27678
- [
27679
- "#!/bin/sh",
27680
- "target=",
27681
- "module=",
27682
- "compile=",
27683
- "previous=",
27684
- "for argument do",
27685
- ' case "$previous" in -target) target=$argument ;; -module-name) module=$argument ;; esac',
27686
- ' case "$argument" in -c|-emit-module|-scan-dependencies|-typecheck) compile=1 ;; esac',
27687
- " previous=$argument",
27688
- "done",
27689
- 'case "$target/$compile" in',
27690
- " *-*-linux*/1)",
27691
- ' case ",$PEACH_SWIFT_HOST_MACROS," in',
27692
- ' *",$module,"*) set -- "$@" -Xfrontend -import-module -Xfrontend Foundation ;;',
27693
- " esac ;;",
27694
- "esac",
27695
- 'exec "$PEACH_SWIFTC" "$@"',
27696
- ""
27697
- ].join("\n")
27698
- );
27699
- (0, import_node_fs45.chmodSync)(swiftc, 493);
27700
- compiler.SWIFT_EXEC = swiftc;
27701
- compiler.PEACH_SWIFT_HOST_MACROS = packageHostMacros.join(",");
27702
- compiler.PEACH_SWIFTC = import_node_path47.default.join(options.toolchainBin, "swiftc");
27975
+ const declarations = nativeDeclarations.get(name3) ?? /* @__PURE__ */ new Set();
27976
+ for (const declaration of swiftInterfaceDeclarations(header))
27977
+ declarations.add(declaration);
27978
+ for (const [candidate, source] of Object.entries(input.files))
27979
+ if (included.has(import_node_path47.default.posix.basename(candidate)))
27980
+ for (const declaration of swiftInterfaceDeclarations(source))
27981
+ declarations.add(declaration);
27982
+ nativeDeclarations.set(name3, declarations);
27983
+ }
27984
+ const frameworkInterface = (name3) => {
27985
+ if (frameworkInterfaces.has(name3)) return frameworkInterfaces.get(name3);
27986
+ const source = distribution ? import_node_path47.default.join(frameworkRoot, "modules", `${name3}-Swift.h`) : prebuilt.objcHeaders.get(name3);
27987
+ if (!source || !(0, import_node_fs45.existsSync)(source)) {
27988
+ frameworkInterfaces.set(name3, null);
27989
+ return null;
27703
27990
  }
27704
- const projectProcess = options.project ? prepareSwiftProjectProcess(root, options.project) : void 0;
27705
- const temporaryDirectory = projectProcess ? void 0 : import_node_path47.default.join(root, ".build", "peach-compiler-tmp");
27706
- const appOptions = projectProcess ? {
27707
- ...buildOptions,
27708
- uid: projectProcess.uid,
27709
- gid: projectProcess.gid,
27710
- confined: { ...projectProcess.env, ...compiler }
27711
- } : {
27712
- ...buildOptions,
27713
- temporaryDirectory,
27714
- env: {
27715
- ...buildOptions.env,
27716
- ...preparation.usesObjcPrebuilt && process.env.PEACH_HOME !== void 0 ? { PEACH_HOME: process.env.PEACH_HOME } : {},
27717
- ...compiler
27718
- }
27719
- };
27720
- const unprepared = preparation.targetFailures.map(
27721
- (failure) => `error: target ${failure}`
27991
+ const headers = import_node_path47.default.join(sdkFrameworks, `${name3}.framework/Headers`);
27992
+ const declared = /* @__PURE__ */ new Set();
27993
+ if ((0, import_node_fs45.existsSync)(headers)) {
27994
+ for (const file of (0, import_node_fs45.readdirSync)(headers, {
27995
+ recursive: true,
27996
+ encoding: "utf8"
27997
+ }))
27998
+ if (file.endsWith(".h"))
27999
+ for (const name4 of swiftInterfaceDeclarations(
28000
+ (0, import_node_fs45.readFileSync)(import_node_path47.default.join(headers, file), "utf8")
28001
+ ))
28002
+ declared.add(name4);
28003
+ }
28004
+ for (const declaration of nativeDeclarations.get(name3) ?? [])
28005
+ declared.add(declaration);
28006
+ const own = withoutSwiftDeclarations(
28007
+ generatedInterface(source),
28008
+ declared,
28009
+ nativeDeclarations.has(name3) ? `@import ${name3};` : `#import <${name3}/${name3}.h>`
27722
28010
  );
27723
- const forwarders = /* @__PURE__ */ new Map();
27724
- for (const [file, text2] of Object.entries(input.files)) {
27725
- const parents = /^#include "((?:\.\.\/)+)[^"\n]+"\n$/.exec(text2)?.[1];
27726
- if (!parents) continue;
27727
- const directory = import_node_path47.default.posix.dirname(file);
27728
- forwarders.set(
27729
- `${import_node_path47.default.join(root, directory)}/${parents.slice(0, -1)}`,
27730
- import_node_path47.default.posix.join("build", directory, parents).replace(/\/$/, "")
27731
- );
28011
+ const owners = sdkObjCDeclarationOwners(sdkFrameworks);
28012
+ const foreign = /* @__PURE__ */ new Map();
28013
+ for (const declaration of [
28014
+ ...swiftInterfaceDeclarations(own),
28015
+ ...objcEnumerations(own),
28016
+ ...[...own.matchAll(/^\s*SWIFT_EXTERN\b[^(\n]*?\b(\w+)\s*\(/gm)].map(
28017
+ (match) => match[1]
28018
+ )
28019
+ ]) {
28020
+ const owner = owners.get(declaration);
28021
+ if (owner && owner !== name3) foreign.set(declaration, owner);
27732
28022
  }
27733
- const jobs = swiftCompilerJobs();
27734
- const incrementalPreview = sdkImage !== void 0 && !guestGraph && !options.project && !input.optimize && !input.unoptimized;
27735
- const perFile = input.unoptimized || incrementalPreview;
27736
- const buildArgs = [
27737
- "build",
27738
- ...projectProcess?.cacheOptions ?? swiftPackageCacheOptions(),
27739
- "--build-system",
27740
- "native",
27741
- "-j",
27742
- String(jobs),
27743
- "--package-path",
27744
- root,
27745
- ...swiftCompileSdkOptions(frameworkRoot, options.toolchainBin),
27746
- ...swiftObjCSelectorOptions(frameworkRoot),
27747
- "--swift-sdk",
27748
- sdk,
27749
- ...preparation.targetToolset ? ["--toolset", import_node_path47.default.join(root, ".peach-target-toolset.json")] : [],
27750
- "-c",
27751
- "release",
27752
- ...input.unoptimized ? ["-Xswiftc", "-Onone"] : [],
27753
- ...perFile ? [
27754
- "-Xswiftc",
27755
- "-no-whole-module-optimization",
27756
- "-Xswiftc",
27757
- "-j",
27758
- "-Xswiftc",
27759
- String(jobs)
27760
- ] : [],
27761
- ...incrementalPreview ? ["-Xswiftc", "-incremental", "-Xswiftc", "-enable-batch-mode"] : [],
27762
- // the mirror finds a changed sdk header's readers in their
27763
- // dependency files, which omit system headers by default
27764
- ...mirrorDistribution ? ["-Xswiftc", "-track-system-dependencies"] : [],
27765
- // the link strips debug info, so none is generated (as for the framework).
27766
- // keep -num-threads fixed across caller core caps so llbuild does not
27767
- // rebuild every target when callers alternate --cores, and bound backend
27768
- // fan-out under high -j.
27769
- "-Xswiftc",
27770
- "-gnone",
27771
- ...incrementalPreview ? [] : [
27772
- "-Xswiftc",
27773
- "-num-threads",
27774
- "-Xswiftc",
27775
- String(perFile ? 1 : Math.min(8, import_node_os11.default.availableParallelism()))
27776
- ],
27777
- ...swiftReproducibleBuildFlags([
27778
- [import_node_path47.default.dirname(options.toolchainBin), "toolchain"],
27779
- [compileFrameworkRoot, "framework"],
27780
- [root, "build"],
27781
- ...forwarders
27782
- ]).flatMap((flag, index, flags) => {
27783
- if (!nativeToolset || !flag.startsWith("-ffile-prefix-map="))
27784
- return [flag];
27785
- const toolchainDir = import_node_path47.default.dirname(options.toolchainBin);
27786
- let mapped = flag;
27787
- for (const [dir, target] of [
27788
- [root, "/peach/build"],
27789
- [compileFrameworkRoot, "/peach/framework"],
27790
- [(0, import_node_fs45.realpathSync)(compileFrameworkRoot), "/peach/framework"],
27791
- [toolchainDir, "/peach/toolchain"],
27792
- [(0, import_node_fs45.realpathSync)(toolchainDir), "/peach/toolchain"]
27793
- ]) {
27794
- mapped = mapped.replaceAll(dir, target);
27795
- }
27796
- const [, from, to] = /^-ffile-prefix-map=([^=]+)=(.+)$/.exec(mapped) ?? [];
27797
- const tool = flags[index - 1];
27798
- return mapped !== flag && from !== to ? [flag, tool, mapped] : [flag];
27799
- }),
27800
- ...macroPlugins.libraries.flatMap((plugin) => [
27801
- "-Xswiftc",
27802
- "-load-plugin-library",
27803
- "-Xswiftc",
27804
- plugin
27805
- ]),
27806
- ...macroPlugins.executables.flatMap((plugin) => [
27807
- "-Xswiftc",
27808
- "-load-plugin-executable",
27809
- "-Xswiftc",
27810
- `${plugin}#ExpoModulesMacros`
27811
- ])
27812
- ];
27813
- const linked = builtArtifact(layout2);
27814
- (0, import_node_fs45.rmSync)(import_node_path47.default.join(root, ".peach-link.rsp"), { force: true });
27815
- if (options.linkOnly || (0, import_node_fs45.existsSync)(linked) && (0, import_node_fs45.statSync)(linked).size <= 8)
27816
- (0, import_node_fs45.rmSync)(linked, { force: true });
27817
- report("compiling and linking Swift modules");
27818
- const frameworkInterfaces = /* @__PURE__ */ new Map();
27819
- const sdkFrameworks = import_node_path47.default.join(
27820
- swiftSdkPaths(frameworkRoot, options.toolchainBin).darwin,
27821
- "System/Library/Frameworks"
28023
+ const header = foreign.size ? withoutSwiftDeclarations(
28024
+ own,
28025
+ new Set(foreign.keys()),
28026
+ [...new Set(foreign.values())].map((owner) => `#import <${owner}/${owner}.h>`).join("\n")
28027
+ ) : own;
28028
+ const value = {
28029
+ file: import_node_path47.default.join(root2, ".build/peach-framework-objc", `${name3}-Swift.h`),
28030
+ header,
28031
+ module: (0, import_node_fs45.existsSync)(headers)
28032
+ };
28033
+ frameworkInterfaces.set(name3, value);
28034
+ writeBuildFile(
28035
+ value.file,
28036
+ ((0, import_node_fs45.existsSync)(import_node_path47.default.join(headers, `${name3}.h`)) ? `#import <${name3}/${name3}.h>
28037
+ ` : "") + swiftHeaderWithSuperclassImports(header, frameworkInterface)
27822
28038
  );
27823
- const generatedInterface = (source) => withoutImportedSdkEnumForwards(
27824
- clangInterfaceHeader((0, import_node_fs45.readFileSync)(source, "utf8"), frameworkRoot),
27825
- sdkObjCDeclarationOwners(sdkFrameworks)
28039
+ return value;
28040
+ };
28041
+ const headerPaths = (producer) => {
28042
+ const stem = import_node_path47.default.join(
28043
+ root2,
28044
+ ".build",
28045
+ "peach-cxx-headers",
28046
+ `${producer}-Swift`
27826
28047
  );
27827
- const nativeDeclarations = /* @__PURE__ */ new Map();
27828
- const nativeHeaders = Object.entries(input.files).filter(([name3]) => name3.endsWith(".h") && !name3.endsWith("-Swift.h")).map(([, source]) => source);
27829
- for (const [file, contents2] of Object.entries(input.files)) {
27830
- if (!file.endsWith(".modulemap")) continue;
27831
- const name3 = moduleMapName(contents2);
27832
- const umbrella = /\bumbrella\s+header\s+"([^"]+)"/.exec(contents2)?.[1];
27833
- if (!name3 || !umbrella) continue;
27834
- const header = input.files[import_node_path47.default.posix.join(import_node_path47.default.posix.dirname(file), umbrella)];
27835
- if (header === void 0) continue;
27836
- const included = new Set(
27837
- [
27838
- ...header.matchAll(/^\s*#\s*(?:import|include)\s*[<"]([^">]+)[">]/gm)
27839
- ].map((match) => import_node_path47.default.posix.basename(match[1]))
27840
- );
27841
- const declarations = nativeDeclarations.get(name3) ?? /* @__PURE__ */ new Set();
27842
- for (const declaration of swiftInterfaceDeclarations(header))
27843
- declarations.add(declaration);
27844
- for (const [candidate, source] of Object.entries(input.files))
27845
- if (included.has(import_node_path47.default.posix.basename(candidate)))
27846
- for (const declaration of swiftInterfaceDeclarations(source))
27847
- declarations.add(declaration);
27848
- nativeDeclarations.set(name3, declarations);
27849
- }
27850
- const frameworkInterface = (name3) => {
27851
- if (frameworkInterfaces.has(name3)) return frameworkInterfaces.get(name3);
27852
- const source = distribution ? import_node_path47.default.join(frameworkRoot, "modules", `${name3}-Swift.h`) : prebuilt.objcHeaders.get(name3);
27853
- if (!source || !(0, import_node_fs45.existsSync)(source)) {
27854
- frameworkInterfaces.set(name3, null);
27855
- return null;
27856
- }
27857
- const headers = import_node_path47.default.join(sdkFrameworks, `${name3}.framework/Headers`);
27858
- const declared = /* @__PURE__ */ new Set();
27859
- if ((0, import_node_fs45.existsSync)(headers)) {
27860
- for (const file of (0, import_node_fs45.readdirSync)(headers, {
27861
- recursive: true,
27862
- encoding: "utf8"
27863
- }))
27864
- if (file.endsWith(".h"))
27865
- for (const name4 of swiftInterfaceDeclarations(
27866
- (0, import_node_fs45.readFileSync)(import_node_path47.default.join(headers, file), "utf8")
27867
- ))
27868
- declared.add(name4);
27869
- }
27870
- for (const declaration of nativeDeclarations.get(name3) ?? [])
27871
- declared.add(declaration);
27872
- const own = withoutSwiftDeclarations(
27873
- generatedInterface(source),
27874
- declared,
27875
- nativeDeclarations.has(name3) ? `@import ${name3};` : `#import <${name3}/${name3}.h>`
27876
- );
27877
- const owners = sdkObjCDeclarationOwners(sdkFrameworks);
27878
- const foreign = /* @__PURE__ */ new Map();
27879
- for (const declaration of [
27880
- ...swiftInterfaceDeclarations(own),
27881
- ...objcEnumerations(own),
27882
- ...[...own.matchAll(/^\s*SWIFT_EXTERN\b[^(\n]*?\b(\w+)\s*\(/gm)].map(
27883
- (match) => match[1]
27884
- )
27885
- ]) {
27886
- const owner = owners.get(declaration);
27887
- if (owner && owner !== name3) foreign.set(declaration, owner);
28048
+ return { producer, original: `${stem}.original.h`, emitted: `${stem}.h` };
28049
+ };
28050
+ const publishHeader = ({
28051
+ producer,
28052
+ original,
28053
+ emitted
28054
+ }) => {
28055
+ const generated = generatedInterface(original);
28056
+ writeBuildFile(
28057
+ emitted,
28058
+ withoutSwiftDeclarations(
28059
+ swiftHeaderWithSuperclassImports(generated, frameworkInterface),
28060
+ /* @__PURE__ */ new Set([
28061
+ ...preparation.nativeHeaderDeclarations[producer] ?? [],
28062
+ ...nativelyDeclaredFunctions(generated, nativeHeaders)
28063
+ ]),
28064
+ `#import <${producer}/${producer}.h>`
28065
+ )
28066
+ );
28067
+ };
28068
+ const recipe = inputHash.copy().update(
28069
+ distribution ? swiftCompileSurfaceDigest(frameworkRoot) : moduleDigest
28070
+ ).update((0, import_node_fs45.readFileSync)(import_node_path47.default.join(root2, "Package.swift"))).update(JSON.stringify(buildArgs)).digest("hex");
28071
+ const runApp = async (compiler2) => {
28072
+ const optionsWithCompiler = compiler2 ? { ...appOptions, env: { ...appOptions.env, ...compiler2 } } : appOptions;
28073
+ const stages = [
28074
+ ...(preparation.nativePrerequisiteTargets ?? []).map((target) => ({
28075
+ target,
28076
+ producers: []
28077
+ })),
28078
+ ...preparation.headerBuilds,
28079
+ ...(preparation.nativeProductTargets ?? []).map((target) => ({
28080
+ target,
28081
+ producers: []
28082
+ }))
28083
+ ];
28084
+ const checkpoints = import_node_path47.default.join(root2, ".build", "peach-product-checkpoints");
28085
+ const buildDbExists = (0, import_node_fs45.existsSync)(import_node_path47.default.join(root2, ".build", "build.db"));
28086
+ const releaseDir = import_node_path47.default.dirname(linked);
28087
+ for (const { target, producers } of stages) {
28088
+ if (!options.project && producers.length === 0 && buildDbExists) {
28089
+ const expectedObjects = preparation.nativeStageObjects.get(target);
28090
+ if (expectedObjects && expectedObjects.length > 0 && expectedObjects.every(
28091
+ (relative) => (0, import_node_fs45.statSync)(import_node_path47.default.join(releaseDir, relative), {
28092
+ throwIfNoEntry: false
28093
+ })?.isFile()
28094
+ ))
28095
+ continue;
27888
28096
  }
27889
- const header = foreign.size ? withoutSwiftDeclarations(
27890
- own,
27891
- new Set(foreign.keys()),
27892
- [...new Set(foreign.values())].map((owner) => `#import <${owner}/${owner}.h>`).join("\n")
27893
- ) : own;
27894
- const value = {
27895
- file: import_node_path47.default.join(root, ".build/peach-framework-objc", `${name3}-Swift.h`),
27896
- header,
27897
- module: (0, import_node_fs45.existsSync)(headers)
27898
- };
27899
- frameworkInterfaces.set(name3, value);
27900
- writeBuildFile(
27901
- value.file,
27902
- ((0, import_node_fs45.existsSync)(import_node_path47.default.join(headers, `${name3}.h`)) ? `#import <${name3}/${name3}.h>
27903
- ` : "") + swiftHeaderWithSuperclassImports(header, frameworkInterface)
28097
+ const receipt = import_node_path47.default.join(
28098
+ checkpoints,
28099
+ (0, import_node_crypto29.createHash)("sha256").update(target).digest("hex")
27904
28100
  );
27905
- return value;
27906
- };
27907
- const headerPaths = (producer) => {
27908
- const stem = import_node_path47.default.join(
27909
- root,
27910
- ".build",
27911
- "peach-cxx-headers",
27912
- `${producer}-Swift`
27913
- );
27914
- return { producer, original: `${stem}.original.h`, emitted: `${stem}.h` };
27915
- };
27916
- const publishHeader = ({
27917
- producer,
27918
- original,
27919
- emitted
27920
- }) => {
27921
- const generated = generatedInterface(original);
27922
- writeBuildFile(
27923
- emitted,
27924
- withoutSwiftDeclarations(
27925
- swiftHeaderWithSuperclassImports(generated, frameworkInterface),
27926
- /* @__PURE__ */ new Set([
27927
- ...preparation.nativeHeaderDeclarations[producer] ?? [],
27928
- ...nativelyDeclaredFunctions(generated, nativeHeaders)
27929
- ]),
27930
- `#import <${producer}/${producer}.h>`
27931
- )
27932
- );
27933
- };
27934
- const recipe = inputHash.copy().update(
27935
- distribution ? swiftCompileSurfaceDigest(frameworkRoot) : moduleDigest
27936
- ).update((0, import_node_fs45.readFileSync)(import_node_path47.default.join(root, "Package.swift"))).update(JSON.stringify(buildArgs)).digest("hex");
27937
- const runApp = async (compiler2) => {
27938
- const optionsWithCompiler = compiler2 ? { ...appOptions, env: { ...appOptions.env, ...compiler2 } } : appOptions;
27939
- const stages = [
27940
- ...(preparation.nativePrerequisiteTargets ?? []).map((target) => ({
27941
- target,
27942
- producers: []
27943
- })),
27944
- ...preparation.headerBuilds,
27945
- ...(preparation.nativeProductTargets ?? []).map((target) => ({
27946
- target,
27947
- producers: []
27948
- }))
27949
- ];
27950
- const checkpoints = import_node_path47.default.join(root, ".build", "peach-product-checkpoints");
27951
- const buildDbExists = (0, import_node_fs45.existsSync)(import_node_path47.default.join(root, ".build", "build.db"));
27952
- const releaseDir = import_node_path47.default.dirname(linked);
27953
- for (const { target, producers } of stages) {
27954
- if (!options.project && producers.length === 0 && buildDbExists) {
27955
- const expectedObjects = preparation.nativeStageObjects.get(target);
27956
- if (expectedObjects && expectedObjects.length > 0 && expectedObjects.every(
27957
- (relative) => (0, import_node_fs45.statSync)(import_node_path47.default.join(releaseDir, relative), {
27958
- throwIfNoEntry: false
27959
- })?.isFile()
27960
- ))
27961
- continue;
27962
- }
27963
- const receipt = import_node_path47.default.join(
27964
- checkpoints,
27965
- (0, import_node_crypto29.createHash)("sha256").update(target).digest("hex")
27966
- );
27967
- const headers = producers.map(headerPaths);
27968
- for (const header of headers)
27969
- if ((0, import_node_fs45.existsSync)(header.original)) publishHeader(header);
27970
- const fingerprint = () => {
27971
- const digest = (0, import_node_crypto29.createHash)("sha256").update(recipe);
27972
- for (const { original, emitted } of headers) {
27973
- if (!(0, import_node_fs45.existsSync)(original) || !(0, import_node_fs45.existsSync)(emitted)) return;
27974
- digest.update(
27975
- (0, import_node_crypto29.createHash)("sha256").update((0, import_node_fs45.readFileSync)(emitted)).digest()
27976
- );
27977
- }
27978
- return digest.digest("hex");
27979
- };
27980
- if (!options.project && (0, import_node_fs45.existsSync)(receipt) && (0, import_node_fs45.readFileSync)(receipt, "utf8") === fingerprint())
27981
- continue;
27982
- if (!options.project) (0, import_node_fs45.rmSync)(receipt, { force: true });
27983
- for (const header of headers) {
27984
- if (!(0, import_node_fs45.existsSync)(header.original))
27985
- (0, import_node_fs45.rmSync)(
27986
- import_node_path47.default.join(
27987
- import_node_path47.default.dirname(linked),
27988
- "Modules",
27989
- `${swiftTargetModuleName(header.producer)}.swiftmodule`
27990
- ),
27991
- { force: true }
27992
- );
27993
- }
27994
- await runCompiler(
27995
- swift,
27996
- [...buildArgs, "--target", target],
27997
- optionsWithCompiler,
27998
- /^(?:\[swift-prebuilt\]|\[\d+\/\d+\] )/,
27999
- SWIFTPM_NOISE
28000
- );
28001
- if (!compiler2) for (const header of headers) publishHeader(header);
28002
- if (!options.project) {
28003
- const checkpoint = fingerprint();
28004
- if (checkpoint === void 0)
28005
- throw new Error(`missing Swift headers after building ${target}`);
28006
- (0, import_node_fs45.mkdirSync)(checkpoints, { recursive: true });
28007
- (0, import_node_fs45.writeFileSync)(`${receipt}.partial`, checkpoint);
28008
- (0, import_node_fs45.renameSync)(`${receipt}.partial`, receipt);
28101
+ const headers = producers.map(headerPaths);
28102
+ for (const header of headers)
28103
+ if ((0, import_node_fs45.existsSync)(header.original)) publishHeader(header);
28104
+ const fingerprint = () => {
28105
+ const digest = (0, import_node_crypto29.createHash)("sha256").update(recipe);
28106
+ for (const { original, emitted } of headers) {
28107
+ if (!(0, import_node_fs45.existsSync)(original) || !(0, import_node_fs45.existsSync)(emitted)) return;
28108
+ digest.update(
28109
+ (0, import_node_crypto29.createHash)("sha256").update((0, import_node_fs45.readFileSync)(emitted)).digest()
28110
+ );
28009
28111
  }
28112
+ return digest.digest("hex");
28113
+ };
28114
+ if (!options.project && (0, import_node_fs45.existsSync)(receipt) && (0, import_node_fs45.readFileSync)(receipt, "utf8") === fingerprint())
28115
+ continue;
28116
+ if (!options.project) (0, import_node_fs45.rmSync)(receipt, { force: true });
28117
+ for (const header of headers) {
28118
+ if (!(0, import_node_fs45.existsSync)(header.original))
28119
+ (0, import_node_fs45.rmSync)(
28120
+ import_node_path47.default.join(
28121
+ import_node_path47.default.dirname(linked),
28122
+ "Modules",
28123
+ `${swiftTargetModuleName(header.producer)}.swiftmodule`
28124
+ ),
28125
+ { force: true }
28126
+ );
28010
28127
  }
28011
28128
  await runCompiler(
28012
28129
  swift,
28013
- buildArgs,
28130
+ [...buildArgs, "--target", target],
28014
28131
  optionsWithCompiler,
28015
- SWIFTPM_PROGRESS,
28132
+ /^(?:\[swift-prebuilt\]|\[\d+\/\d+\] )/,
28016
28133
  SWIFTPM_NOISE
28017
28134
  );
28018
- };
28019
- const compileApp = () => preparation.headerCompiler ? withSwiftHeaderCompiler(
28020
- root,
28021
- options.toolchainBin,
28022
- recipe,
28023
- new Map(
28024
- preparation.headerBuilds[0].producers.map((producer) => {
28025
- const paths = headerPaths(producer);
28026
- return [
28027
- swiftTargetModuleName(producer),
28028
- {
28029
- header: paths.original,
28030
- publish: () => publishHeader(paths)
28031
- }
28032
- ];
28033
- })
28034
- ),
28035
- runApp
28036
- ) : runApp();
28037
- try {
28038
- if (temporaryDirectory) (0, import_node_fs45.mkdirSync)(temporaryDirectory, { recursive: true });
28039
- await compileApp();
28040
- } catch (error) {
28041
- const output2 = outputOf(error);
28042
- const moduleCache = import_node_path47.default.join(
28043
- root,
28044
- ".build",
28045
- WASM_TRIPLE,
28046
- "release",
28047
- "ModuleCache"
28048
- );
28049
- if (output2.includes("was compiled with module cache path") && (0, import_node_fs45.existsSync)(moduleCache)) {
28050
- (0, import_node_fs45.rmSync)(moduleCache, { recursive: true, force: true });
28051
- try {
28052
- await compileApp();
28053
- } catch (retryError) {
28054
- throw new Error(
28055
- [
28056
- ...unprepared,
28057
- projectDiagnostic(outputOf(retryError), layout2, input.files)
28058
- ].join("\n"),
28059
- { cause: retryError }
28060
- );
28061
- }
28062
- } else {
28135
+ if (!compiler2) for (const header of headers) publishHeader(header);
28136
+ if (!options.project) {
28137
+ const checkpoint = fingerprint();
28138
+ if (checkpoint === void 0)
28139
+ throw new Error(`missing Swift headers after building ${target}`);
28140
+ (0, import_node_fs45.mkdirSync)(checkpoints, { recursive: true });
28141
+ (0, import_node_fs45.writeFileSync)(`${receipt}.partial`, checkpoint);
28142
+ (0, import_node_fs45.renameSync)(`${receipt}.partial`, receipt);
28143
+ }
28144
+ }
28145
+ await runCompiler(
28146
+ swift,
28147
+ buildArgs,
28148
+ optionsWithCompiler,
28149
+ SWIFTPM_PROGRESS,
28150
+ SWIFTPM_NOISE
28151
+ );
28152
+ };
28153
+ const compileApp = () => preparation.headerCompiler ? withSwiftHeaderCompiler(
28154
+ root2,
28155
+ options.toolchainBin,
28156
+ recipe,
28157
+ new Map(
28158
+ preparation.headerBuilds[0].producers.map((producer) => {
28159
+ const paths = headerPaths(producer);
28160
+ return [
28161
+ swiftTargetModuleName(producer),
28162
+ {
28163
+ header: paths.original,
28164
+ publish: () => publishHeader(paths)
28165
+ }
28166
+ ];
28167
+ })
28168
+ ),
28169
+ runApp
28170
+ ) : runApp();
28171
+ try {
28172
+ if (temporaryDirectory) (0, import_node_fs45.mkdirSync)(temporaryDirectory, { recursive: true });
28173
+ await compileApp();
28174
+ } catch (error) {
28175
+ const output2 = outputOf(error);
28176
+ const moduleCache = import_node_path47.default.join(
28177
+ root2,
28178
+ ".build",
28179
+ WASM_TRIPLE,
28180
+ "release",
28181
+ "ModuleCache"
28182
+ );
28183
+ if (output2.includes("was compiled with module cache path") && (0, import_node_fs45.existsSync)(moduleCache)) {
28184
+ (0, import_node_fs45.rmSync)(moduleCache, { recursive: true, force: true });
28185
+ try {
28186
+ await compileApp();
28187
+ } catch (retryError) {
28063
28188
  throw new Error(
28064
- [...unprepared, projectDiagnostic(output2, layout2, input.files)].join(
28065
- "\n"
28066
- ),
28067
- { cause: error }
28189
+ [
28190
+ ...unprepared,
28191
+ projectDiagnostic(outputOf(retryError), layout3, input.files)
28192
+ ].join("\n"),
28193
+ { cause: retryError }
28068
28194
  );
28069
28195
  }
28070
- } finally {
28071
- if (temporaryDirectory)
28072
- (0, import_node_fs45.rmSync)(temporaryDirectory, { recursive: true, force: true });
28073
- if (options.project) endSwiftProjectProcesses(options.project);
28074
- }
28075
- if (unprepared.length) throw new Error(unprepared.join("\n"));
28076
- if (!(0, import_node_fs45.existsSync)(linked)) {
28077
- const binDir = import_node_path47.default.dirname(linked);
28078
- const found = (0, import_node_fs45.existsSync)(binDir) ? (0, import_node_fs45.readdirSync)(binDir).filter((name3) => name3.endsWith(".wasm")).sort() : [];
28196
+ } else {
28079
28197
  throw new Error(
28080
- `swift-compile: the build produced no ${import_node_path47.default.basename(linked)} (found: ${found.join(", ") || "none"})`
28198
+ [...unprepared, projectDiagnostic(output2, layout3, input.files)].join(
28199
+ "\n"
28200
+ ),
28201
+ { cause: error }
28081
28202
  );
28082
28203
  }
28083
- if (options.project) removeProjectLinks(root);
28084
- const resourceReferences = Object.values(input.resources ?? {}).map(
28085
- (value) => Buffer.from(value, "base64")
28204
+ } finally {
28205
+ if (temporaryDirectory)
28206
+ (0, import_node_fs45.rmSync)(temporaryDirectory, { recursive: true, force: true });
28207
+ if (options.project) endSwiftProjectProcesses(options.project);
28208
+ }
28209
+ if (unprepared.length) throw new Error(unprepared.join("\n"));
28210
+ if (!(0, import_node_fs45.existsSync)(linked)) {
28211
+ const binDir = import_node_path47.default.dirname(linked);
28212
+ const found = (0, import_node_fs45.existsSync)(binDir) ? (0, import_node_fs45.readdirSync)(binDir).filter((name3) => name3.endsWith(".wasm")).sort() : [];
28213
+ throw new Error(
28214
+ `swift-compile: the build produced no ${import_node_path47.default.basename(linked)} (found: ${found.join(", ") || "none"})`
28086
28215
  );
28087
- if (!guestGraph)
28088
- pruneSwiftWasmLink(
28089
- root,
28090
- options.toolchainBin,
28091
- prebuilt?.root ?? frameworkRoot,
28092
- input.staticClangTargets,
28093
- options.project,
28094
- void 0,
28095
- resourceReferences
28096
- );
28097
- if (options.linkOnly) {
28098
- if ((0, import_node_fs45.statSync)(linked).size <= 8)
28099
- throw new Error("swift-compile: deferred linker produced no executable");
28100
- report("project link verified");
28101
- return;
28102
- }
28103
- const output = options.project ? projectOutputFile(root, linked, options.project) : linked;
28104
- const optimized = `${output}.optimized`;
28105
- if (sdkImage && options.project) (0, import_node_fs45.rmSync)(optimized, { force: true });
28106
- let sdkAsset;
28107
- if (guestGraph) {
28108
- const binding = await compileGuestLink({
28109
- graph: guestGraph,
28110
- buildDirectory: root,
28111
- releaseDirectory: import_node_path47.default.dirname(linked),
28112
- moduleRoot: frameworkRoot,
28113
- toolchainBin: options.toolchainBin,
28114
- swiftCompiler: preparation.headerCompiler ? import_node_path47.default.join(root, SWIFT_HEADER_COMPILER_WRAPPER) : compiler.SWIFT_EXEC ?? import_node_path47.default.join(options.toolchainBin, "swiftc"),
28115
- sysroot: swiftSdkPaths(frameworkRoot, options.toolchainBin).sysroot,
28116
- sdk: swiftModuleSdk(frameworkRoot),
28117
- sdkImage,
28118
- compilerDigest: compilerSourceDigest,
28119
- project: options.project && {
28120
- ...options.project,
28121
- env: { ...options.project.env, ...projectProcess?.env }
28122
- },
28123
- staticClangTargets: input.staticClangTargets ?? [],
28124
- resourceReferences,
28125
- resourceBundles: input.resourceBundles ?? [],
28126
- generatedOwners: preparation.generatedOwners,
28127
- output,
28128
- optimized,
28129
- optimize: input.optimize === true,
28130
- jobs: swiftBuildJobs()
28131
- });
28132
- if (sdkImage && binding)
28133
- sdkAsset = { key: sdkImage.key, sha256: sdkImage.sha256, binding };
28134
- } else if (sdkImage) {
28135
- const { buildSwiftAppModule: buildSwiftAppModule2 } = await Promise.resolve().then(() => (init_swift_sdk_app_module(), swift_sdk_app_module_exports));
28136
- const binding = await buildSwiftAppModule2({
28137
- buildRoot: root,
28138
- toolchainBin: options.toolchainBin,
28139
- sdk: sdkImage,
28140
- output: optimized,
28141
- optimize: input.optimize === true,
28142
- project: options.project && {
28143
- ...options.project,
28144
- env: { ...options.project.env, ...projectProcess?.env },
28145
- sdkRoot: import_node_path47.default.dirname(
28146
- swiftSdkPaths(frameworkRoot, options.toolchainBin).sysroot
28147
- ),
28148
- linked: output
28149
- }
28150
- });
28151
- sdkAsset = { key: sdkImage.key, sha256: sdkImage.sha256, binding };
28152
- } else {
28153
- const bytes = (0, import_node_fs45.readFileSync)(output);
28154
- const ordered = orderObjCConstructors(bytes);
28155
- if (ordered !== bytes) (0, import_node_fs45.writeFileSync)(output, ordered);
28156
- await lowerWasm(output, optimized, { optimize: input.optimize === true });
28157
- }
28158
- if (!sdkImage)
28159
- await runCompiler(
28160
- import_node_path47.default.join(options.toolchainBin, "llvm-objcopy"),
28161
- ["--remove-section=.swift1_autolink_entries", optimized],
28162
- buildOptions
28163
- );
28164
- const artifact = {
28165
- hash,
28166
- bytes: (0, import_node_fs45.readFileSync)(optimized),
28167
- icu: await icu,
28168
- sdk: sdkAsset
28169
- };
28170
- if (artifact.bytes.length <= 8)
28216
+ }
28217
+ if (options.project) removeProjectLinks(root2);
28218
+ const resourceReferences = Object.values(input.resources ?? {}).map(
28219
+ (value) => Buffer.from(value, "base64")
28220
+ );
28221
+ if (!guestGraph)
28222
+ pruneSwiftWasmLink(
28223
+ root2,
28224
+ options.toolchainBin,
28225
+ prebuilt?.root ?? frameworkRoot,
28226
+ input.staticClangTargets,
28227
+ options.project,
28228
+ void 0,
28229
+ resourceReferences
28230
+ );
28231
+ if (options.linkOnly) {
28232
+ if ((0, import_node_fs45.statSync)(linked).size <= 8)
28171
28233
  throw new Error("swift-compile: deferred linker produced no executable");
28172
- if (!options.project) saveCompiledArtifact(root, artifact);
28173
- saveSharedArtifact(sharedRoot, artifact);
28174
- report("compiled artifact verified");
28175
- return retain(root, artifact);
28176
- } finally {
28177
- readHold?.release();
28234
+ stage("project link verified");
28235
+ return;
28178
28236
  }
28179
- },
28180
- budget.signal
28181
- );
28237
+ const output = options.project ? projectOutputFile(root2, linked, options.project) : linked;
28238
+ const optimized = `${output}.optimized`;
28239
+ if (sdkImage && options.project) (0, import_node_fs45.rmSync)(optimized, { force: true });
28240
+ let sdkAsset;
28241
+ stage("linking the app image");
28242
+ if (guestGraph) {
28243
+ const binding = await compileGuestLink({
28244
+ graph: guestGraph,
28245
+ buildDirectory: root2,
28246
+ releaseDirectory: import_node_path47.default.dirname(linked),
28247
+ moduleRoot: frameworkRoot,
28248
+ toolchainBin: options.toolchainBin,
28249
+ swiftCompiler: preparation.headerCompiler ? import_node_path47.default.join(root2, SWIFT_HEADER_COMPILER_WRAPPER) : compiler.SWIFT_EXEC ?? import_node_path47.default.join(options.toolchainBin, "swiftc"),
28250
+ sysroot: swiftSdkPaths(frameworkRoot, options.toolchainBin).sysroot,
28251
+ sdk: swiftModuleSdk(frameworkRoot),
28252
+ sdkImage,
28253
+ compilerDigest: compilerSourceDigest,
28254
+ project: options.project && {
28255
+ ...options.project,
28256
+ env: { ...options.project.env, ...projectProcess?.env }
28257
+ },
28258
+ staticClangTargets: input.staticClangTargets ?? [],
28259
+ resourceReferences,
28260
+ resourceBundles: input.resourceBundles ?? [],
28261
+ generatedOwners: preparation.generatedOwners,
28262
+ output,
28263
+ optimized,
28264
+ optimize: input.optimize === true,
28265
+ jobs: swiftBuildJobs(),
28266
+ onStage: stage
28267
+ });
28268
+ if (sdkImage && binding)
28269
+ sdkAsset = { key: sdkImage.key, sha256: sdkImage.sha256, binding };
28270
+ } else if (sdkImage) {
28271
+ const { buildSwiftAppModule: buildSwiftAppModule2 } = await Promise.resolve().then(() => (init_swift_sdk_app_module(), swift_sdk_app_module_exports));
28272
+ const binding = await buildSwiftAppModule2({
28273
+ buildRoot: root2,
28274
+ toolchainBin: options.toolchainBin,
28275
+ sdk: sdkImage,
28276
+ output: optimized,
28277
+ optimize: input.optimize === true,
28278
+ project: options.project && {
28279
+ ...options.project,
28280
+ env: { ...options.project.env, ...projectProcess?.env },
28281
+ sdkRoot: import_node_path47.default.dirname(
28282
+ swiftSdkPaths(frameworkRoot, options.toolchainBin).sysroot
28283
+ ),
28284
+ linked: output
28285
+ }
28286
+ });
28287
+ sdkAsset = { key: sdkImage.key, sha256: sdkImage.sha256, binding };
28288
+ } else {
28289
+ const bytes = (0, import_node_fs45.readFileSync)(output);
28290
+ const ordered = orderObjCConstructors(bytes);
28291
+ if (ordered !== bytes) (0, import_node_fs45.writeFileSync)(output, ordered);
28292
+ stage("lowering the app image");
28293
+ await lowerWasm(output, optimized, { optimize: input.optimize === true });
28294
+ }
28295
+ if (!sdkImage)
28296
+ await runCompiler(
28297
+ import_node_path47.default.join(options.toolchainBin, "llvm-objcopy"),
28298
+ ["--remove-section=.swift1_autolink_entries", optimized],
28299
+ buildOptions
28300
+ );
28301
+ const artifact = {
28302
+ hash,
28303
+ bytes: (0, import_node_fs45.readFileSync)(optimized),
28304
+ icu: await icu,
28305
+ sdk: sdkAsset
28306
+ };
28307
+ if (artifact.bytes.length <= 8)
28308
+ throw new Error("swift-compile: deferred linker produced no executable");
28309
+ if (!options.project) saveCompiledArtifact(root2, artifact);
28310
+ saveSharedArtifact(sharedRoot, artifact);
28311
+ stage("compiled artifact verified");
28312
+ return retain(baseRoot, artifact);
28313
+ } finally {
28314
+ readHold?.release();
28315
+ }
28316
+ });
28182
28317
  });
28183
28318
  },
28184
28319
  options.signal
28185
28320
  );
28186
28321
  }
28187
- var import_node_child_process28, import_node_crypto29, import_node_fs45, import_node_os11, import_node_path47, v6, WASM_TRIPLE, SWIFTPM_PROGRESS, SWIFTPM_NOISE, SWIFT_COMPILER_ENV_KEYS, distributionManifests, distributionCompileViews, REACH_STAGED_FRAMEWORKS, objcEnumerations, clangDeclarationEnumCache, objcEnumForward, sdkDeclarationOwners, swiftInterfaceDeclarations, linkedModuleDigests, compileSurfaces, SYSTEM_MODULE_LIBRARIES, SYSTEM_MODULE_IMPORT, OPTIONAL_FRAMEWORK_DEPENDENCIES, OPTIONAL_FRAMEWORKS, SWIFT_IMPORT, kleeneNot, kleeneAnd, kleeneOr, NON_IOS_MODULES, sdkPaths, availableModules, sdkOverlayFrameworks, DISTRIBUTION_CLANG_MODULES, CLANG_DISTRIBUTION_MODULES, ONE_PRODUCT, GAME_FAMILY, gameProducts, gameProduct, GAME_REACH, FOUNDATION_IMPLICIT_MODULES, FRAMEWORK_COMPANION_IMPORT, ONE_IMPLICIT_FLAGS, executableLinkFlags, darwinRecordsRegion, REACTOR_FLAG, MULTI_MANIFEST_VERSION, SWIFT_HEADER_PRODUCTS_TARGET, compilerSourceDigest, nativeCxxCompilerFlags, MODULE_MAP_RESPONSE_FILE_RUN, cFlagArray, cxxFlagArray, SWIFTPM_DEFAULT_IOS_DEPLOYMENT_TARGET, OS_IOS, ARCH_ARM64, NOT_ON_IOS, DELEGATE_CLASS, ARM64_MACRO, WASM_MACRO, ARCH_WASM32, C_WORDS, archEnvironments, codeMasks, codeMaskChars, CODE_MASK_CACHE_CHARS, FOUNDATION_NETWORKING_TYPES, FOUNDATION_OVERLAY_TYPES, FOUNDATION_OVERLAY_GLOBALS, CORE_FOUNDATION_OVERLAY_GLOBALS, CORE_FOUNDATION_GEOMETRY_TYPES, CORE_FOUNDATION_GRAPHICS_TYPES, CORE_FOUNDATION_HANDLE_IMPORTS, emptyMacroEnvironment, wasmMacroEnvironment, cPredefineTable, cPredefineCache, HIDDEN_UNITS, FIRST_WINS_PAIRS, LAST_WINS_PAIRS, VALUE_FLAGS, LIBXML_REFERENCE, LIBXML_SOURCE, ROOT_LOCKS, host, rootLocks, SHARED_ARTIFACT_BUDGET_BYTES, SHARED_ARTIFACT_GRACE_MS, RETIRED_PREFIX, retainedArtifacts, FRAMEWORK_LINK_TARGET, frameworkProductsReceiptSchema, SWIFT_LINK_STAMP, SWIFT_HOST_COMPILER_WRAPPER, SWIFT_FRAMEWORK_SLOTS, SWIFT_FRAMEWORK_UNOPTIMIZED_SLOTS, SWIFT_FRAMEWORK_SLOT_KEY, SWIFT_FRAMEWORK_SLOT_ORIGIN;
28322
+ var import_node_child_process28, import_node_crypto29, import_node_fs45, import_node_os11, import_node_path47, v6, WASM_TRIPLE, SWIFTPM_PROGRESS, SWIFTPM_NOISE, SWIFT_COMPILER_ENV_KEYS, distributionManifests, distributionCompileViews, REACH_STAGED_FRAMEWORKS, objcEnumerations, clangDeclarationEnumCache, objcEnumForward, sdkDeclarationOwners, swiftInterfaceDeclarations, linkedModuleDigests, compileSurfaces, SYSTEM_MODULE_LIBRARIES, SYSTEM_MODULE_IMPORT, OPTIONAL_FRAMEWORK_DEPENDENCIES, OPTIONAL_FRAMEWORKS, SWIFT_IMPORT, kleeneNot, kleeneAnd, kleeneOr, NON_IOS_MODULES, sdkPaths, availableModules, sdkOverlayFrameworks, DISTRIBUTION_CLANG_MODULES, CLANG_DISTRIBUTION_MODULES, ONE_PRODUCT, GAME_FAMILY, gameProducts, gameProduct, GAME_REACH, FOUNDATION_IMPLICIT_MODULES, FRAMEWORK_COMPANION_IMPORT, ONE_IMPLICIT_FLAGS, executableLinkFlags, darwinRecordsRegion, REACTOR_FLAG, MULTI_MANIFEST_VERSION, SWIFT_HEADER_PRODUCTS_TARGET, compilerSourceDigest, nativeCxxCompilerFlags, MODULE_MAP_RESPONSE_FILE_RUN, cFlagArray, cxxFlagArray, SWIFTPM_DEFAULT_IOS_DEPLOYMENT_TARGET, OS_IOS, ARCH_ARM64, NOT_ON_IOS, DELEGATE_CLASS, ARM64_MACRO, WASM_MACRO, ARCH_WASM32, C_WORDS, archEnvironments, codeMasks, codeMaskChars, CODE_MASK_CACHE_CHARS, FOUNDATION_NETWORKING_TYPES, FOUNDATION_OVERLAY_TYPES, FOUNDATION_OVERLAY_GLOBALS, CORE_FOUNDATION_OVERLAY_GLOBALS, CORE_FOUNDATION_GEOMETRY_TYPES, CORE_FOUNDATION_GRAPHICS_TYPES, CORE_FOUNDATION_HANDLE_IMPORTS, emptyMacroEnvironment, wasmMacroEnvironment, cPredefineTable, cPredefineCache, HIDDEN_UNITS, FIRST_WINS_PAIRS, LAST_WINS_PAIRS, VALUE_FLAGS, LIBXML_REFERENCE, LIBXML_SOURCE, ROOT_LOCKS, host, rootLocks, SHARED_ARTIFACT_BUDGET_BYTES, SHARED_ARTIFACT_GRACE_MS, RETIRED_PREFIX, retainedArtifacts, FRAMEWORK_LINK_TARGET, frameworkProductsReceiptSchema, SWIFT_LINK_STAMP, SWIFT_HOST_COMPILER_WRAPPER, SWIFT_FRAMEWORK_SLOTS, SWIFT_FRAMEWORK_UNOPTIMIZED_SLOTS, SWIFT_FRAMEWORK_SLOT_KEY, SWIFT_FRAMEWORK_SLOT_ORIGIN, SWIFT_FRAMEWORK_SLOT_RELEASE, SWIFT_BUILD_ROOT_SLOTS, SWIFT_BUILD_ROOT_SHAPE;
28188
28323
  var init_swift_compile = __esm({
28189
28324
  "src/swift-compile.ts"() {
28190
28325
  import_node_child_process28 = require("node:child_process");
@@ -28454,7 +28589,7 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
28454
28589
  REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
28455
28590
  MULTI_MANIFEST_VERSION = 76;
28456
28591
  SWIFT_HEADER_PRODUCTS_TARGET = "PeachHeaderProducts";
28457
- compilerSourceDigest = true ? "6fbcbab3535da2f464a19f4d3c1db8a7e4b393927e5158477332f4cc978cc22f" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
28592
+ compilerSourceDigest = true ? "203439fc20df8d328b0c245496fc6db90092265409adb61b593725e82ce837de" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
28458
28593
  nativeCxxCompilerFlags = ["-fno-cxx-modules"];
28459
28594
  MODULE_MAP_RESPONSE_FILE_RUN = 16;
28460
28595
  cFlagArray = (flags) => JSON.stringify(withoutGlogModuleMap(flags));
@@ -28878,6 +29013,7 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
28878
29013
  retainedArtifacts = /* @__PURE__ */ new Map();
28879
29014
  FRAMEWORK_LINK_TARGET = "PeachFrameworkLink";
28880
29015
  frameworkProductsReceiptSchema = v6.object({
29016
+ root: v6.string(),
28881
29017
  modules: v6.string(),
28882
29018
  objects: v6.array(v6.string()),
28883
29019
  lazyObjects: v6.array(v6.string()),
@@ -28894,6 +29030,9 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
28894
29030
  SWIFT_FRAMEWORK_UNOPTIMIZED_SLOTS = 4;
28895
29031
  SWIFT_FRAMEWORK_SLOT_KEY = ".peach-framework-key";
28896
29032
  SWIFT_FRAMEWORK_SLOT_ORIGIN = ".peach-framework-origin";
29033
+ SWIFT_FRAMEWORK_SLOT_RELEASE = ".peach-framework-release";
29034
+ SWIFT_BUILD_ROOT_SLOTS = 4;
29035
+ SWIFT_BUILD_ROOT_SHAPE = ".peach-build-shape";
28897
29036
  }
28898
29037
  });
28899
29038
  init_swift_compile();