peachsim 0.1.2606 → 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 (133) 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 +815 -674
  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-UL7Z3WUQ.mjs → acorn-KFWXYMX5.mjs} +3 -3
  30. package/dist-lib/esm-chunks/{chunk-EXB4QSQI.mjs → chunk-6JPUMAC2.mjs} +1 -1
  31. package/dist-lib/esm-chunks/{chunk-CPMK3DA6.mjs → chunk-6NDABMDX.mjs} +3 -3
  32. package/dist-lib/esm-chunks/{chunk-5JMW5G3U.mjs → chunk-7SKDPTZN.mjs} +1 -1
  33. package/dist-lib/esm-chunks/{chunk-MBCSJQRY.mjs → chunk-ACAXWH62.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-25LYRBSX.mjs → chunk-ARYRQJUB.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-KWLQDES2.mjs → chunk-BNAXRY5Q.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-VTZJPPTE.mjs → chunk-CA64UUHF.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-OB5XSLW6.mjs → chunk-DBW62F4N.mjs} +3 -2
  38. package/dist-lib/esm-chunks/{chunk-RTPUFY2K.mjs → chunk-ESS2CG5G.mjs} +5 -5
  39. package/dist-lib/esm-chunks/{chunk-O6NRI4T2.mjs → chunk-IGSLOAPL.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-5ANQR24T.mjs → chunk-KIIALACX.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-66ESCMV3.mjs → chunk-LJZ373SO.mjs} +818 -678
  42. package/dist-lib/esm-chunks/{chunk-TVICD24H.mjs → chunk-M4ORY3NH.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-34CIYRB7.mjs → chunk-MBWWOGI5.mjs} +4 -4
  44. package/dist-lib/esm-chunks/{chunk-QFASF6EH.mjs → chunk-O5BPZVLB.mjs} +5 -5
  45. package/dist-lib/esm-chunks/{chunk-L7FPUZZO.mjs → chunk-P5Q5QCTP.mjs} +1 -1
  46. package/dist-lib/esm-chunks/{chunk-B7AXR7WA.mjs → chunk-QJUAWJDB.mjs} +1 -1
  47. package/dist-lib/esm-chunks/{chunk-O6ZNRBLB.mjs → chunk-RIDXKGBZ.mjs} +1 -1
  48. package/dist-lib/esm-chunks/{chunk-WJKACRMG.mjs → chunk-TD2DBEKQ.mjs} +1 -1
  49. package/dist-lib/esm-chunks/{chunk-E2TASYAA.mjs → chunk-UTSB5CDG.mjs} +1 -1
  50. package/dist-lib/esm-chunks/{chunk-PLOV7VQQ.mjs → chunk-WMWOBH7E.mjs} +1 -1
  51. package/dist-lib/esm-chunks/{chunk-XUWYWP35.mjs → chunk-ZNGLVJYL.mjs} +1 -1
  52. package/dist-lib/esm-chunks/{metro-layout-parser-OMUFYOJI.mjs → metro-layout-parser-UY3B6VGU.mjs} +3 -3
  53. package/dist-lib/esm-chunks/{swift-package-prebuilt-X7EZCX34.mjs → swift-package-prebuilt-HDHPWS44.mjs} +10 -10
  54. package/dist-lib/esm-chunks/{swift-sdk-app-module-E3IF2XPD.mjs → swift-sdk-app-module-U6G5RZV2.mjs} +14 -14
  55. package/dist-lib/esm-chunks/{swift-sdk-image-57YYLNU6.mjs → swift-sdk-image-PVDA2MVM.mjs} +14 -14
  56. package/dist-lib/esm-chunks/{swift-sdk-image-producer-DZOZTTDZ.mjs → swift-sdk-image-producer-YHPS3KNR.mjs} +4 -4
  57. package/dist-lib/expo-swift-bundle.cjs +814 -673
  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 +959 -676
  62. package/dist-lib/host/fetch-proxy-handler.cjs +6 -5
  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 +6 -4
  76. package/dist-lib/native-app-identity-project.mjs +17 -17
  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 +1 -1
  84. package/dist-lib/plist.mjs +3 -3
  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 +81 -81
  88. package/dist-lib/public-origins-lib.json +64 -64
  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 +1 -1
  93. package/dist-lib/sdk.cjs +1 -1
  94. package/dist-lib/sdk.mjs +8 -8
  95. package/dist-lib/skills.cjs +959 -676
  96. package/dist-lib/swift-compile.cjs +811 -670
  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 -1
  127. package/src/agent-prompt.ts +5 -1
  128. package/src/one-native-controls-package.ts +143 -1
  129. package/src/oneNativeControlsContract.ts +1 -0
  130. package/src/swift-compile-budget.ts +28 -7
  131. package/src/swift-compile.ts +968 -803
  132. package/src/swift-guest-compile.ts +3 -0
  133. package/src/swift-toolchain.ts +4 -1
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.2606 | (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 {
@@ -26899,24 +26921,18 @@ function readFrameworkProductsReceipt(scratch2, receiptKey) {
26899
26921
  } catch {
26900
26922
  return null;
26901
26923
  }
26902
- const archive = import_node_path47.default.join(scratch2, "lib");
26903
- const archiveStamp = import_node_path47.default.join(archive, ".receipt");
26904
- 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;
26905
26926
  if (!(0, import_node_fs45.existsSync)(parsed.modules)) return null;
26906
- 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
+ }
26907
26930
  for (const file of parsed.providers) if (!(0, import_node_fs45.existsSync)(file)) return null;
26908
26931
  for (const file of parsed.moduleMaps) if (!(0, import_node_fs45.existsSync)(file)) return null;
26909
- if (!archiveMatches) {
26910
- (0, import_node_fs45.rmSync)(archive, { recursive: true, force: true });
26911
- (0, import_node_fs45.mkdirSync)(archive, { recursive: true });
26912
- for (const [object4, rel] of parsed.archived)
26913
- (0, import_node_fs45.symlinkSync)(object4, import_node_path47.default.join(scratch2, rel));
26914
- (0, import_node_fs45.writeFileSync)(archiveStamp, receiptKey);
26915
- }
26916
26932
  for (const file of parsed.objects) if (!(0, import_node_fs45.existsSync)(file)) return null;
26917
26933
  for (const file of parsed.lazyObjects) if (!(0, import_node_fs45.existsSync)(file)) return null;
26918
26934
  return {
26919
- root: scratch2,
26935
+ root: parsed.root,
26920
26936
  modules: parsed.modules,
26921
26937
  objects: parsed.objects,
26922
26938
  lazyObjects: parsed.lazyObjects,
@@ -26934,7 +26950,7 @@ async function buildFrameworkProducts(scratch2, args) {
26934
26950
  const selectorOptions = swiftObjCSelectorOptions(args.moduleRoot);
26935
26951
  const receiptKey = (0, import_node_crypto29.createHash)("sha256").update(
26936
26952
  JSON.stringify([
26937
- "framework-products/v1",
26953
+ "framework-products/v2",
26938
26954
  args.frameworkKey,
26939
26955
  unoptimized,
26940
26956
  args.sdk,
@@ -27092,28 +27108,40 @@ async function buildFrameworkProducts(scratch2, args) {
27092
27108
  }
27093
27109
  const providers = (0, import_node_fs45.readdirSync)(providerDir).filter((file) => file.endsWith(".o")).sort().map((file) => import_node_path47.default.join(providerDir, file));
27094
27110
  for (const provider of providers) linked.owners.set(provider, "DarwinRecords");
27095
- const archive = import_node_path47.default.join(scratch2, "lib");
27096
- (0, import_node_fs45.rmSync)(archive, { recursive: true, force: true });
27097
- (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 });
27098
27117
  const archived = /* @__PURE__ */ new Map();
27099
- for (const object4 of objects) {
27100
- const target = linked.owners.get(object4);
27101
- const dir = import_node_path47.default.join(release, `${target}.build`);
27102
- if (!target || target === "Darwin" || !object4.startsWith(dir + import_node_path47.default.sep)) continue;
27103
- const name3 = `${target}-${import_node_path47.default.relative(dir, object4).replaceAll(import_node_path47.default.sep, "-").replace(/\.swift\.o$/, ".o")}`;
27104
- (0, import_node_fs45.symlinkSync)(object4, import_node_path47.default.join(archive, name3));
27105
- archived.set(object4, `lib/${name3}`);
27106
- }
27107
- const roots = swiftObjcRootObjects(`${scratch2}
27108
- ${args.frameworkKey}`, scratch2, [
27109
- ...archived.values()
27110
- ]);
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
+ );
27111
27139
  const linkedObjects = objects.map((object4) => {
27112
27140
  const name3 = archived.get(object4);
27113
- 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 };
27114
27142
  });
27115
27143
  const result = {
27116
- root: scratch2,
27144
+ root: archiveRoot,
27117
27145
  modules: import_node_path47.default.join(release, "Modules"),
27118
27146
  objects: linkedObjects.filter((object4) => !object4.lazy).map((object4) => object4.path),
27119
27147
  lazyObjects: linkedObjects.filter((object4) => object4.lazy).map((object4) => object4.path),
@@ -27123,7 +27151,6 @@ ${args.frameworkKey}`, scratch2, [
27123
27151
  moduleMaps: linked.moduleMaps,
27124
27152
  objcHeaders: linked.objcHeaders
27125
27153
  };
27126
- (0, import_node_fs45.writeFileSync)(import_node_path47.default.join(archive, ".receipt"), receiptKey);
27127
27154
  const receiptsDir = import_node_path47.default.join(scratch2, "products-ready");
27128
27155
  (0, import_node_fs45.mkdirSync)(receiptsDir, { recursive: true });
27129
27156
  const receiptFile = import_node_path47.default.join(receiptsDir, `${receiptKey}.json`);
@@ -27131,6 +27158,7 @@ ${args.frameworkKey}`, scratch2, [
27131
27158
  (0, import_node_fs45.writeFileSync)(
27132
27159
  partialReceipt,
27133
27160
  JSON.stringify({
27161
+ root: result.root,
27134
27162
  modules: result.modules,
27135
27163
  objects: result.objects,
27136
27164
  lazyObjects: result.lazyObjects,
@@ -27162,7 +27190,10 @@ function swiftFrameworkSlotRecord(slot, record) {
27162
27190
  function swiftFrameworkSlotKey(slot) {
27163
27191
  return swiftFrameworkSlotRecord(slot, SWIFT_FRAMEWORK_SLOT_KEY);
27164
27192
  }
27165
- 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) {
27166
27197
  const slotCount = unoptimized ? SWIFT_FRAMEWORK_UNOPTIMIZED_SLOTS : SWIFT_FRAMEWORK_SLOTS;
27167
27198
  const slotsDir = swiftFrameworksDir(unoptimized);
27168
27199
  const slots = Array.from({ length: slotCount }, (_, index) => {
@@ -27185,9 +27216,12 @@ async function withSwiftFrameworkSlot(frameworkKey, moduleRoot, signal, work, un
27185
27216
  (0, import_node_fs45.readFileSync)(import_node_path47.default.join(moduleRoot, file))
27186
27217
  ])
27187
27218
  );
27188
- 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 };
27189
27224
  let changes = 0;
27190
- if (swiftFrameworkSlotKey(slot) === null) return { slot, changes: Infinity };
27191
27225
  const source = import_node_path47.default.join(slot, "source", "packages", import_node_path47.default.basename(moduleRoot));
27192
27226
  for (const [file, contents2] of inputs) {
27193
27227
  try {
@@ -27199,18 +27233,22 @@ async function withSwiftFrameworkSlot(frameworkKey, moduleRoot, signal, work, un
27199
27233
  changes++;
27200
27234
  }
27201
27235
  }
27202
- return { slot, changes };
27203
- }).sort(
27204
- (left, right) => left.changes - right.changes || Number(own(right.slot)) - Number(own(left.slot)) || (built.get(right.slot) ?? 0) - (built.get(left.slot) ?? 0)
27205
- );
27206
- 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) {
27207
27245
  if (await hasLiveSwiftRootReaders(slot, signal)) continue;
27208
27246
  const result = await withSwiftRootLock(
27209
27247
  slot,
27210
27248
  async (lease) => {
27211
27249
  if (await hasLiveSwiftRootReaders(slot, signal)) return void 0;
27212
27250
  console.error(
27213
- `[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}`
27214
27252
  );
27215
27253
  return { value: await run5(slot)(lease) };
27216
27254
  },
@@ -27222,6 +27260,43 @@ async function withSwiftFrameworkSlot(frameworkKey, moduleRoot, signal, work, un
27222
27260
  const nearest = ranked[0].slot;
27223
27261
  return withSwiftRootLock(nearest, run5(nearest), signal);
27224
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
+ }
27225
27300
  function mirrorTree2(source, target, skip) {
27226
27301
  (0, import_node_fs45.mkdirSync)(target, { recursive: true });
27227
27302
  const wanted = /* @__PURE__ */ new Set();
@@ -27271,8 +27346,10 @@ function stageFrameworkSource(moduleRoot, slot, frameworkKey, release) {
27271
27346
  const hadKey = swiftFrameworkSlotKey(slot);
27272
27347
  if (hadKey !== frameworkKey) {
27273
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 });
27274
27350
  (0, import_node_fs45.rmSync)(import_node_path47.default.join(slot, "products-ready"), { recursive: true, force: true });
27275
- (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 });
27276
27353
  const moduleRestructured = mirrorTree2(moduleRoot, stagedModule, ".build");
27277
27354
  const sdkRestructured = mirrorTree2(
27278
27355
  swiftSharedSdkRoot(moduleRoot, false),
@@ -27300,8 +27377,11 @@ function stageFrameworkSource(moduleRoot, slot, frameworkKey, release) {
27300
27377
  (0, import_node_fs45.rmSync)(modules, { recursive: true, force: true });
27301
27378
  (0, import_node_fs45.symlinkSync)(target, modules);
27302
27379
  }
27380
+ (0, import_node_fs45.writeFileSync)(import_node_path47.default.join(slot, SWIFT_FRAMEWORK_SLOT_RELEASE), release);
27303
27381
  (0, import_node_fs45.writeFileSync)(import_node_path47.default.join(slot, SWIFT_FRAMEWORK_SLOT_KEY), frameworkKey);
27304
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);
27305
27385
  }
27306
27386
  return stagedModule;
27307
27387
  }
@@ -27529,660 +27609,717 @@ ${cap}` : "";
27529
27609
  (0, import_node_fs45.rmSync)(requestRoot, { recursive: true, force: true });
27530
27610
  }
27531
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) : "";
27532
27625
  return withSwiftCompileBudget(options.timeoutMs, options.signal, async (budget) => {
27533
- return withSwiftRootLock(
27534
- root,
27535
- async (lease) => {
27536
- if (!options.intermediates) {
27537
- const built = readCompiledArtifact(import_node_path47.default.join(sharedRoot, "artifact"), hash);
27538
- if (built) {
27539
- report("reusing verified disk artifact");
27540
- return retain(root, built);
27541
- }
27542
- }
27543
- const swift = import_node_path47.default.join(options.toolchainBin, "swift");
27544
- if (!(0, import_node_fs45.existsSync)(swift)) {
27545
- throw new Error(
27546
- `swift-compile: no swift.org toolchain at ${options.toolchainBin}; install ${options.release} and its matching wasm sdk`
27547
- );
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);
27548
27668
  }
27549
- const unoptimized = input.unoptimized === true;
27550
- const withFrameworkLock = (work) => distribution ? work(null) : withSwiftFrameworkSlot(
27551
- frameworkKey,
27552
- 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,
27553
27723
  budget.signal,
27554
- work,
27555
- unoptimized
27724
+ frameworkLease
27556
27725
  );
27557
- const baseBuildEnv = options.project?.env ? {
27558
- ...options.project.env,
27559
- // shipped host plugins resolve against the selected compiler's runtime.
27560
- ...process.platform === "linux" ? {
27561
- LD_LIBRARY_PATH: [
27562
- import_node_path47.default.resolve(options.toolchainBin, "../lib/swift/linux"),
27563
- import_node_path47.default.resolve(options.toolchainBin, "../lib/swift/host"),
27564
- process.env.LD_LIBRARY_PATH
27565
- ].filter(Boolean).join(":")
27566
- } : {},
27567
- PEACH_DEFER_WASM_LINK: "1"
27568
- } : swiftCompilerBaseEnv(options.toolchainBin, process.env);
27569
- 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,
27570
27791
  frameworkRoot,
27571
- compileFrameworkRoot,
27572
- macroPlugins,
27573
- sdk,
27574
- icu,
27575
27792
  prebuilt,
27576
- readHold
27577
- } = await withFrameworkLock(async (slot, frameworkLease) => {
27578
- budget.startCompile();
27579
- if (slot && swiftFrameworkSlotKey(slot) !== frameworkKey)
27580
- await waitForNoSwiftRootReaders(slot, budget.signal);
27581
- const frameworkRoot2 = mirrorDistribution ? syncSwiftDistributionMirror(root, moduleRoot, mirrorDistribution) : distribution ? moduleRoot : stageFrameworkSource(moduleRoot, slot, frameworkKey, options.release);
27582
- if (!swiftModuleDigest(frameworkRoot2).equals(moduleDigest))
27583
- throw new Error("Swift staged project source differs from the caller");
27584
- report("preparing compiler plugins");
27585
- const macroPlugins2 = await ensureMacroPlugins(
27586
- frameworkRoot2,
27587
- options.toolchainBin,
27588
- options.release,
27589
- budget.signal,
27590
- 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")
27591
27832
  );
27592
- const compileFrameworkRoot2 = distribution ? swiftDistributionCompileView(frameworkRoot2, distribution) : frameworkRoot2;
27593
- const sdk2 = swiftModuleSdk(frameworkRoot2).wasmSdkId;
27594
- const icu2 = options.linkOnly ? null : swiftIcuAsset(options.toolchainBin, sdk2);
27595
- let prebuilt2;
27596
- if (!distribution) {
27597
- report("compiling framework products");
27598
- prebuilt2 = await buildFrameworkProducts(slot, {
27599
- moduleRoot: frameworkRoot2,
27600
- frameworkKey,
27601
- input,
27602
- swift,
27603
- sdk: sdk2,
27604
- toolchainBin: options.toolchainBin,
27605
- plugins: macroPlugins2,
27606
- buildOptions: {
27607
- env: baseBuildEnv,
27608
- maxBuffer: 64 * 1024 * 1024,
27609
- signal: budget.signal,
27610
- lease,
27611
- frameworkLease
27612
- }
27613
- });
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
27614
27852
  }
27615
- const readHold2 = slot ? acquireSwiftRootReadHold(slot) : void 0;
27616
- return {
27617
- frameworkRoot: frameworkRoot2,
27618
- compileFrameworkRoot: compileFrameworkRoot2,
27619
- macroPlugins: macroPlugins2,
27620
- sdk: sdk2,
27621
- icu: icu2,
27622
- prebuilt: prebuilt2,
27623
- readHold: readHold2
27624
- };
27625
- });
27626
- const buildOptions = {
27627
- env: baseBuildEnv,
27628
- maxBuffer: 64 * 1024 * 1024,
27629
- signal: budget.signal,
27630
- lease
27631
27853
  };
27632
- try {
27633
- if (options.project) removeProjectLinks(root);
27634
- const packageHostMacros = process.platform === "linux" ? input.packageHostMacros : void 0;
27635
- if (retireStaleSwiftLink(
27636
- root,
27637
- swiftLinkStamp({
27638
- frameworkKey: `${options.release}\0${Boolean(distribution)}\0${swiftModuleSdk(frameworkRoot).wasmSdkId}`,
27639
- packageHostMacros
27640
- }),
27641
- swiftLinkStamp({
27642
- // a distribution's objects reach only the deferred link, and
27643
- // the root's mirror keeps its compile inputs at fixed paths
27644
- frameworkKey: distribution ? `${options.release}\0${distribution.wasmSdkChecksum}` : frameworkKey,
27645
- prebuilt,
27646
- packageHostMacros
27647
- }),
27648
- Boolean(options.linkOnly)
27649
- ))
27650
- report("framework revision changed; rebuilding the app link");
27651
- const nativeToolset = needsNativeToolset(input, prebuilt);
27652
- const preparation = writeSwiftProject(
27653
- layout2,
27654
- input,
27655
- frameworkRoot,
27656
- prebuilt,
27657
- !options.project,
27658
- 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(/\/$/, "")
27659
27865
  );
27660
- const productFile = import_node_path47.default.join(frameworkRoot, SWIFT_FRAMEWORK_PRODUCT_FILE);
27661
- writeSwiftAutolinkLinker(
27662
- root,
27663
- options.toolchainBin,
27664
- (0, import_node_fs45.existsSync)(productFile) ? [
27665
- v6.parse(
27666
- swiftFrameworkProductSchema,
27667
- JSON.parse((0, import_node_fs45.readFileSync)(productFile, "utf8"))
27668
- ).product.name
27669
- ] : []
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]))
27670
27974
  );
27671
- const compiler = preparation.targetToolset ? { CC: import_node_path47.default.join(root, CLANG_TARGET_MODULE_WRAPPER) } : {};
27672
- if (packageHostMacros?.length) {
27673
- const swiftc = import_node_path47.default.join(root, SWIFT_HOST_COMPILER_WRAPPER);
27674
- writeBuildFile(
27675
- swiftc,
27676
- [
27677
- "#!/bin/sh",
27678
- "target=",
27679
- "module=",
27680
- "compile=",
27681
- "previous=",
27682
- "for argument do",
27683
- ' case "$previous" in -target) target=$argument ;; -module-name) module=$argument ;; esac',
27684
- ' case "$argument" in -c|-emit-module|-scan-dependencies|-typecheck) compile=1 ;; esac',
27685
- " previous=$argument",
27686
- "done",
27687
- 'case "$target/$compile" in',
27688
- " *-*-linux*/1)",
27689
- ' case ",$PEACH_SWIFT_HOST_MACROS," in',
27690
- ' *",$module,"*) set -- "$@" -Xfrontend -import-module -Xfrontend Foundation ;;',
27691
- " esac ;;",
27692
- "esac",
27693
- 'exec "$PEACH_SWIFTC" "$@"',
27694
- ""
27695
- ].join("\n")
27696
- );
27697
- (0, import_node_fs45.chmodSync)(swiftc, 493);
27698
- compiler.SWIFT_EXEC = swiftc;
27699
- compiler.PEACH_SWIFT_HOST_MACROS = packageHostMacros.join(",");
27700
- 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;
27701
27990
  }
27702
- const projectProcess = options.project ? prepareSwiftProjectProcess(root, options.project) : void 0;
27703
- const temporaryDirectory = projectProcess ? void 0 : import_node_path47.default.join(root, ".build", "peach-compiler-tmp");
27704
- const appOptions = projectProcess ? {
27705
- ...buildOptions,
27706
- uid: projectProcess.uid,
27707
- gid: projectProcess.gid,
27708
- confined: { ...projectProcess.env, ...compiler }
27709
- } : {
27710
- ...buildOptions,
27711
- temporaryDirectory,
27712
- env: {
27713
- ...buildOptions.env,
27714
- ...preparation.usesObjcPrebuilt && process.env.PEACH_HOME !== void 0 ? { PEACH_HOME: process.env.PEACH_HOME } : {},
27715
- ...compiler
27716
- }
27717
- };
27718
- const unprepared = preparation.targetFailures.map(
27719
- (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>`
27720
28010
  );
27721
- const forwarders = /* @__PURE__ */ new Map();
27722
- for (const [file, text2] of Object.entries(input.files)) {
27723
- const parents = /^#include "((?:\.\.\/)+)[^"\n]+"\n$/.exec(text2)?.[1];
27724
- if (!parents) continue;
27725
- const directory = import_node_path47.default.posix.dirname(file);
27726
- forwarders.set(
27727
- `${import_node_path47.default.join(root, directory)}/${parents.slice(0, -1)}`,
27728
- import_node_path47.default.posix.join("build", directory, parents).replace(/\/$/, "")
27729
- );
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);
27730
28022
  }
27731
- const jobs = swiftCompilerJobs();
27732
- const incrementalPreview = sdkImage !== void 0 && !guestGraph && !options.project && !input.optimize && !input.unoptimized;
27733
- const perFile = input.unoptimized || incrementalPreview;
27734
- const buildArgs = [
27735
- "build",
27736
- ...projectProcess?.cacheOptions ?? swiftPackageCacheOptions(),
27737
- "--build-system",
27738
- "native",
27739
- "-j",
27740
- String(jobs),
27741
- "--package-path",
27742
- root,
27743
- ...swiftCompileSdkOptions(frameworkRoot, options.toolchainBin),
27744
- ...swiftObjCSelectorOptions(frameworkRoot),
27745
- "--swift-sdk",
27746
- sdk,
27747
- ...preparation.targetToolset ? ["--toolset", import_node_path47.default.join(root, ".peach-target-toolset.json")] : [],
27748
- "-c",
27749
- "release",
27750
- ...input.unoptimized ? ["-Xswiftc", "-Onone"] : [],
27751
- ...perFile ? [
27752
- "-Xswiftc",
27753
- "-no-whole-module-optimization",
27754
- "-Xswiftc",
27755
- "-j",
27756
- "-Xswiftc",
27757
- String(jobs)
27758
- ] : [],
27759
- ...incrementalPreview ? ["-Xswiftc", "-incremental", "-Xswiftc", "-enable-batch-mode"] : [],
27760
- // the mirror finds a changed sdk header's readers in their
27761
- // dependency files, which omit system headers by default
27762
- ...mirrorDistribution ? ["-Xswiftc", "-track-system-dependencies"] : [],
27763
- // the link strips debug info, so none is generated (as for the framework).
27764
- // keep -num-threads fixed across caller core caps so llbuild does not
27765
- // rebuild every target when callers alternate --cores, and bound backend
27766
- // fan-out under high -j.
27767
- "-Xswiftc",
27768
- "-gnone",
27769
- ...incrementalPreview ? [] : [
27770
- "-Xswiftc",
27771
- "-num-threads",
27772
- "-Xswiftc",
27773
- String(perFile ? 1 : Math.min(8, import_node_os11.default.availableParallelism()))
27774
- ],
27775
- ...swiftReproducibleBuildFlags([
27776
- [import_node_path47.default.dirname(options.toolchainBin), "toolchain"],
27777
- [compileFrameworkRoot, "framework"],
27778
- [root, "build"],
27779
- ...forwarders
27780
- ]).flatMap((flag, index, flags) => {
27781
- if (!nativeToolset || !flag.startsWith("-ffile-prefix-map="))
27782
- return [flag];
27783
- const toolchainDir = import_node_path47.default.dirname(options.toolchainBin);
27784
- let mapped = flag;
27785
- for (const [dir, target] of [
27786
- [root, "/peach/build"],
27787
- [compileFrameworkRoot, "/peach/framework"],
27788
- [(0, import_node_fs45.realpathSync)(compileFrameworkRoot), "/peach/framework"],
27789
- [toolchainDir, "/peach/toolchain"],
27790
- [(0, import_node_fs45.realpathSync)(toolchainDir), "/peach/toolchain"]
27791
- ]) {
27792
- mapped = mapped.replaceAll(dir, target);
27793
- }
27794
- const [, from, to] = /^-ffile-prefix-map=([^=]+)=(.+)$/.exec(mapped) ?? [];
27795
- const tool = flags[index - 1];
27796
- return mapped !== flag && from !== to ? [flag, tool, mapped] : [flag];
27797
- }),
27798
- ...macroPlugins.libraries.flatMap((plugin) => [
27799
- "-Xswiftc",
27800
- "-load-plugin-library",
27801
- "-Xswiftc",
27802
- plugin
27803
- ]),
27804
- ...macroPlugins.executables.flatMap((plugin) => [
27805
- "-Xswiftc",
27806
- "-load-plugin-executable",
27807
- "-Xswiftc",
27808
- `${plugin}#ExpoModulesMacros`
27809
- ])
27810
- ];
27811
- const linked = builtArtifact(layout2);
27812
- (0, import_node_fs45.rmSync)(import_node_path47.default.join(root, ".peach-link.rsp"), { force: true });
27813
- if (options.linkOnly || (0, import_node_fs45.existsSync)(linked) && (0, import_node_fs45.statSync)(linked).size <= 8)
27814
- (0, import_node_fs45.rmSync)(linked, { force: true });
27815
- report("compiling and linking Swift modules");
27816
- const frameworkInterfaces = /* @__PURE__ */ new Map();
27817
- const sdkFrameworks = import_node_path47.default.join(
27818
- swiftSdkPaths(frameworkRoot, options.toolchainBin).darwin,
27819
- "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)
27820
28038
  );
27821
- const generatedInterface = (source) => withoutImportedSdkEnumForwards(
27822
- clangInterfaceHeader((0, import_node_fs45.readFileSync)(source, "utf8"), frameworkRoot),
27823
- 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`
27824
28047
  );
27825
- const nativeDeclarations = /* @__PURE__ */ new Map();
27826
- const nativeHeaders = Object.entries(input.files).filter(([name3]) => name3.endsWith(".h") && !name3.endsWith("-Swift.h")).map(([, source]) => source);
27827
- for (const [file, contents2] of Object.entries(input.files)) {
27828
- if (!file.endsWith(".modulemap")) continue;
27829
- const name3 = moduleMapName(contents2);
27830
- const umbrella = /\bumbrella\s+header\s+"([^"]+)"/.exec(contents2)?.[1];
27831
- if (!name3 || !umbrella) continue;
27832
- const header = input.files[import_node_path47.default.posix.join(import_node_path47.default.posix.dirname(file), umbrella)];
27833
- if (header === void 0) continue;
27834
- const included = new Set(
27835
- [
27836
- ...header.matchAll(/^\s*#\s*(?:import|include)\s*[<"]([^">]+)[">]/gm)
27837
- ].map((match) => import_node_path47.default.posix.basename(match[1]))
27838
- );
27839
- const declarations = nativeDeclarations.get(name3) ?? /* @__PURE__ */ new Set();
27840
- for (const declaration of swiftInterfaceDeclarations(header))
27841
- declarations.add(declaration);
27842
- for (const [candidate, source] of Object.entries(input.files))
27843
- if (included.has(import_node_path47.default.posix.basename(candidate)))
27844
- for (const declaration of swiftInterfaceDeclarations(source))
27845
- declarations.add(declaration);
27846
- nativeDeclarations.set(name3, declarations);
27847
- }
27848
- const frameworkInterface = (name3) => {
27849
- if (frameworkInterfaces.has(name3)) return frameworkInterfaces.get(name3);
27850
- const source = distribution ? import_node_path47.default.join(frameworkRoot, "modules", `${name3}-Swift.h`) : prebuilt.objcHeaders.get(name3);
27851
- if (!source || !(0, import_node_fs45.existsSync)(source)) {
27852
- frameworkInterfaces.set(name3, null);
27853
- return null;
27854
- }
27855
- const headers = import_node_path47.default.join(sdkFrameworks, `${name3}.framework/Headers`);
27856
- const declared = /* @__PURE__ */ new Set();
27857
- if ((0, import_node_fs45.existsSync)(headers)) {
27858
- for (const file of (0, import_node_fs45.readdirSync)(headers, {
27859
- recursive: true,
27860
- encoding: "utf8"
27861
- }))
27862
- if (file.endsWith(".h"))
27863
- for (const name4 of swiftInterfaceDeclarations(
27864
- (0, import_node_fs45.readFileSync)(import_node_path47.default.join(headers, file), "utf8")
27865
- ))
27866
- declared.add(name4);
27867
- }
27868
- for (const declaration of nativeDeclarations.get(name3) ?? [])
27869
- declared.add(declaration);
27870
- const own = withoutSwiftDeclarations(
27871
- generatedInterface(source),
27872
- declared,
27873
- nativeDeclarations.has(name3) ? `@import ${name3};` : `#import <${name3}/${name3}.h>`
27874
- );
27875
- const owners = sdkObjCDeclarationOwners(sdkFrameworks);
27876
- const foreign = /* @__PURE__ */ new Map();
27877
- for (const declaration of [
27878
- ...swiftInterfaceDeclarations(own),
27879
- ...objcEnumerations(own),
27880
- ...[...own.matchAll(/^\s*SWIFT_EXTERN\b[^(\n]*?\b(\w+)\s*\(/gm)].map(
27881
- (match) => match[1]
27882
- )
27883
- ]) {
27884
- const owner = owners.get(declaration);
27885
- 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;
27886
28096
  }
27887
- const header = foreign.size ? withoutSwiftDeclarations(
27888
- own,
27889
- new Set(foreign.keys()),
27890
- [...new Set(foreign.values())].map((owner) => `#import <${owner}/${owner}.h>`).join("\n")
27891
- ) : own;
27892
- const value = {
27893
- file: import_node_path47.default.join(root, ".build/peach-framework-objc", `${name3}-Swift.h`),
27894
- header,
27895
- module: (0, import_node_fs45.existsSync)(headers)
27896
- };
27897
- frameworkInterfaces.set(name3, value);
27898
- writeBuildFile(
27899
- value.file,
27900
- ((0, import_node_fs45.existsSync)(import_node_path47.default.join(headers, `${name3}.h`)) ? `#import <${name3}/${name3}.h>
27901
- ` : "") + swiftHeaderWithSuperclassImports(header, frameworkInterface)
28097
+ const receipt = import_node_path47.default.join(
28098
+ checkpoints,
28099
+ (0, import_node_crypto29.createHash)("sha256").update(target).digest("hex")
27902
28100
  );
27903
- return value;
27904
- };
27905
- const headerPaths = (producer) => {
27906
- const stem = import_node_path47.default.join(
27907
- root,
27908
- ".build",
27909
- "peach-cxx-headers",
27910
- `${producer}-Swift`
27911
- );
27912
- return { producer, original: `${stem}.original.h`, emitted: `${stem}.h` };
27913
- };
27914
- const publishHeader = ({
27915
- producer,
27916
- original,
27917
- emitted
27918
- }) => {
27919
- const generated = generatedInterface(original);
27920
- writeBuildFile(
27921
- emitted,
27922
- withoutSwiftDeclarations(
27923
- swiftHeaderWithSuperclassImports(generated, frameworkInterface),
27924
- /* @__PURE__ */ new Set([
27925
- ...preparation.nativeHeaderDeclarations[producer] ?? [],
27926
- ...nativelyDeclaredFunctions(generated, nativeHeaders)
27927
- ]),
27928
- `#import <${producer}/${producer}.h>`
27929
- )
27930
- );
27931
- };
27932
- const recipe = inputHash.copy().update(
27933
- distribution ? swiftCompileSurfaceDigest(frameworkRoot) : moduleDigest
27934
- ).update((0, import_node_fs45.readFileSync)(import_node_path47.default.join(root, "Package.swift"))).update(JSON.stringify(buildArgs)).digest("hex");
27935
- const runApp = async (compiler2) => {
27936
- const optionsWithCompiler = compiler2 ? { ...appOptions, env: { ...appOptions.env, ...compiler2 } } : appOptions;
27937
- const stages = [
27938
- ...(preparation.nativePrerequisiteTargets ?? []).map((target) => ({
27939
- target,
27940
- producers: []
27941
- })),
27942
- ...preparation.headerBuilds,
27943
- ...(preparation.nativeProductTargets ?? []).map((target) => ({
27944
- target,
27945
- producers: []
27946
- }))
27947
- ];
27948
- const checkpoints = import_node_path47.default.join(root, ".build", "peach-product-checkpoints");
27949
- const buildDbExists = (0, import_node_fs45.existsSync)(import_node_path47.default.join(root, ".build", "build.db"));
27950
- const releaseDir = import_node_path47.default.dirname(linked);
27951
- for (const { target, producers } of stages) {
27952
- if (!options.project && producers.length === 0 && buildDbExists) {
27953
- const expectedObjects = preparation.nativeStageObjects.get(target);
27954
- if (expectedObjects && expectedObjects.length > 0 && expectedObjects.every(
27955
- (relative) => (0, import_node_fs45.statSync)(import_node_path47.default.join(releaseDir, relative), {
27956
- throwIfNoEntry: false
27957
- })?.isFile()
27958
- ))
27959
- continue;
27960
- }
27961
- const receipt = import_node_path47.default.join(
27962
- checkpoints,
27963
- (0, import_node_crypto29.createHash)("sha256").update(target).digest("hex")
27964
- );
27965
- const headers = producers.map(headerPaths);
27966
- for (const header of headers)
27967
- if ((0, import_node_fs45.existsSync)(header.original)) publishHeader(header);
27968
- const fingerprint = () => {
27969
- const digest = (0, import_node_crypto29.createHash)("sha256").update(recipe);
27970
- for (const { original, emitted } of headers) {
27971
- if (!(0, import_node_fs45.existsSync)(original) || !(0, import_node_fs45.existsSync)(emitted)) return;
27972
- digest.update(
27973
- (0, import_node_crypto29.createHash)("sha256").update((0, import_node_fs45.readFileSync)(emitted)).digest()
27974
- );
27975
- }
27976
- return digest.digest("hex");
27977
- };
27978
- if (!options.project && (0, import_node_fs45.existsSync)(receipt) && (0, import_node_fs45.readFileSync)(receipt, "utf8") === fingerprint())
27979
- continue;
27980
- if (!options.project) (0, import_node_fs45.rmSync)(receipt, { force: true });
27981
- for (const header of headers) {
27982
- if (!(0, import_node_fs45.existsSync)(header.original))
27983
- (0, import_node_fs45.rmSync)(
27984
- import_node_path47.default.join(
27985
- import_node_path47.default.dirname(linked),
27986
- "Modules",
27987
- `${swiftTargetModuleName(header.producer)}.swiftmodule`
27988
- ),
27989
- { force: true }
27990
- );
27991
- }
27992
- await runCompiler(
27993
- swift,
27994
- [...buildArgs, "--target", target],
27995
- optionsWithCompiler,
27996
- /^(?:\[swift-prebuilt\]|\[\d+\/\d+\] )/,
27997
- SWIFTPM_NOISE
27998
- );
27999
- if (!compiler2) for (const header of headers) publishHeader(header);
28000
- if (!options.project) {
28001
- const checkpoint = fingerprint();
28002
- if (checkpoint === void 0)
28003
- throw new Error(`missing Swift headers after building ${target}`);
28004
- (0, import_node_fs45.mkdirSync)(checkpoints, { recursive: true });
28005
- (0, import_node_fs45.writeFileSync)(`${receipt}.partial`, checkpoint);
28006
- (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
+ );
28007
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
+ );
28008
28127
  }
28009
28128
  await runCompiler(
28010
28129
  swift,
28011
- buildArgs,
28130
+ [...buildArgs, "--target", target],
28012
28131
  optionsWithCompiler,
28013
- SWIFTPM_PROGRESS,
28132
+ /^(?:\[swift-prebuilt\]|\[\d+\/\d+\] )/,
28014
28133
  SWIFTPM_NOISE
28015
28134
  );
28016
- };
28017
- const compileApp = () => preparation.headerCompiler ? withSwiftHeaderCompiler(
28018
- root,
28019
- options.toolchainBin,
28020
- recipe,
28021
- new Map(
28022
- preparation.headerBuilds[0].producers.map((producer) => {
28023
- const paths = headerPaths(producer);
28024
- return [
28025
- swiftTargetModuleName(producer),
28026
- {
28027
- header: paths.original,
28028
- publish: () => publishHeader(paths)
28029
- }
28030
- ];
28031
- })
28032
- ),
28033
- runApp
28034
- ) : runApp();
28035
- try {
28036
- if (temporaryDirectory) (0, import_node_fs45.mkdirSync)(temporaryDirectory, { recursive: true });
28037
- await compileApp();
28038
- } catch (error) {
28039
- const output2 = outputOf(error);
28040
- const moduleCache = import_node_path47.default.join(
28041
- root,
28042
- ".build",
28043
- WASM_TRIPLE,
28044
- "release",
28045
- "ModuleCache"
28046
- );
28047
- if (output2.includes("was compiled with module cache path") && (0, import_node_fs45.existsSync)(moduleCache)) {
28048
- (0, import_node_fs45.rmSync)(moduleCache, { recursive: true, force: true });
28049
- try {
28050
- await compileApp();
28051
- } catch (retryError) {
28052
- throw new Error(
28053
- [
28054
- ...unprepared,
28055
- projectDiagnostic(outputOf(retryError), layout2, input.files)
28056
- ].join("\n"),
28057
- { cause: retryError }
28058
- );
28059
- }
28060
- } 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) {
28061
28188
  throw new Error(
28062
- [...unprepared, projectDiagnostic(output2, layout2, input.files)].join(
28063
- "\n"
28064
- ),
28065
- { cause: error }
28189
+ [
28190
+ ...unprepared,
28191
+ projectDiagnostic(outputOf(retryError), layout3, input.files)
28192
+ ].join("\n"),
28193
+ { cause: retryError }
28066
28194
  );
28067
28195
  }
28068
- } finally {
28069
- if (temporaryDirectory)
28070
- (0, import_node_fs45.rmSync)(temporaryDirectory, { recursive: true, force: true });
28071
- if (options.project) endSwiftProjectProcesses(options.project);
28072
- }
28073
- if (unprepared.length) throw new Error(unprepared.join("\n"));
28074
- if (!(0, import_node_fs45.existsSync)(linked)) {
28075
- const binDir = import_node_path47.default.dirname(linked);
28076
- const found = (0, import_node_fs45.existsSync)(binDir) ? (0, import_node_fs45.readdirSync)(binDir).filter((name3) => name3.endsWith(".wasm")).sort() : [];
28196
+ } else {
28077
28197
  throw new Error(
28078
- `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 }
28079
28202
  );
28080
28203
  }
28081
- if (options.project) removeProjectLinks(root);
28082
- const resourceReferences = Object.values(input.resources ?? {}).map(
28083
- (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"})`
28084
28215
  );
28085
- if (!guestGraph)
28086
- pruneSwiftWasmLink(
28087
- root,
28088
- options.toolchainBin,
28089
- prebuilt?.root ?? frameworkRoot,
28090
- input.staticClangTargets,
28091
- options.project,
28092
- void 0,
28093
- resourceReferences
28094
- );
28095
- if (options.linkOnly) {
28096
- if ((0, import_node_fs45.statSync)(linked).size <= 8)
28097
- throw new Error("swift-compile: deferred linker produced no executable");
28098
- report("project link verified");
28099
- return;
28100
- }
28101
- const output = options.project ? projectOutputFile(root, linked, options.project) : linked;
28102
- const optimized = `${output}.optimized`;
28103
- if (sdkImage && options.project) (0, import_node_fs45.rmSync)(optimized, { force: true });
28104
- let sdkAsset;
28105
- if (guestGraph) {
28106
- const binding = await compileGuestLink({
28107
- graph: guestGraph,
28108
- buildDirectory: root,
28109
- releaseDirectory: import_node_path47.default.dirname(linked),
28110
- moduleRoot: frameworkRoot,
28111
- toolchainBin: options.toolchainBin,
28112
- swiftCompiler: preparation.headerCompiler ? import_node_path47.default.join(root, SWIFT_HEADER_COMPILER_WRAPPER) : compiler.SWIFT_EXEC ?? import_node_path47.default.join(options.toolchainBin, "swiftc"),
28113
- sysroot: swiftSdkPaths(frameworkRoot, options.toolchainBin).sysroot,
28114
- sdk: swiftModuleSdk(frameworkRoot),
28115
- sdkImage,
28116
- compilerDigest: compilerSourceDigest,
28117
- project: options.project && {
28118
- ...options.project,
28119
- env: { ...options.project.env, ...projectProcess?.env }
28120
- },
28121
- staticClangTargets: input.staticClangTargets ?? [],
28122
- resourceReferences,
28123
- resourceBundles: input.resourceBundles ?? [],
28124
- generatedOwners: preparation.generatedOwners,
28125
- output,
28126
- optimized,
28127
- optimize: input.optimize === true,
28128
- jobs: swiftBuildJobs()
28129
- });
28130
- if (sdkImage && binding)
28131
- sdkAsset = { key: sdkImage.key, sha256: sdkImage.sha256, binding };
28132
- } else if (sdkImage) {
28133
- const { buildSwiftAppModule: buildSwiftAppModule2 } = await Promise.resolve().then(() => (init_swift_sdk_app_module(), swift_sdk_app_module_exports));
28134
- const binding = await buildSwiftAppModule2({
28135
- buildRoot: root,
28136
- toolchainBin: options.toolchainBin,
28137
- sdk: sdkImage,
28138
- output: optimized,
28139
- optimize: input.optimize === true,
28140
- project: options.project && {
28141
- ...options.project,
28142
- env: { ...options.project.env, ...projectProcess?.env },
28143
- sdkRoot: import_node_path47.default.dirname(
28144
- swiftSdkPaths(frameworkRoot, options.toolchainBin).sysroot
28145
- ),
28146
- linked: output
28147
- }
28148
- });
28149
- sdkAsset = { key: sdkImage.key, sha256: sdkImage.sha256, binding };
28150
- } else {
28151
- const bytes = (0, import_node_fs45.readFileSync)(output);
28152
- const ordered = orderObjCConstructors(bytes);
28153
- if (ordered !== bytes) (0, import_node_fs45.writeFileSync)(output, ordered);
28154
- await lowerWasm(output, optimized, { optimize: input.optimize === true });
28155
- }
28156
- if (!sdkImage)
28157
- await runCompiler(
28158
- import_node_path47.default.join(options.toolchainBin, "llvm-objcopy"),
28159
- ["--remove-section=.swift1_autolink_entries", optimized],
28160
- buildOptions
28161
- );
28162
- const artifact = {
28163
- hash,
28164
- bytes: (0, import_node_fs45.readFileSync)(optimized),
28165
- icu: await icu,
28166
- sdk: sdkAsset
28167
- };
28168
- 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)
28169
28233
  throw new Error("swift-compile: deferred linker produced no executable");
28170
- if (!options.project) saveCompiledArtifact(root, artifact);
28171
- saveSharedArtifact(sharedRoot, artifact);
28172
- report("compiled artifact verified");
28173
- return retain(root, artifact);
28174
- } finally {
28175
- readHold?.release();
28234
+ stage("project link verified");
28235
+ return;
28176
28236
  }
28177
- },
28178
- budget.signal
28179
- );
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
+ });
28180
28317
  });
28181
28318
  },
28182
28319
  options.signal
28183
28320
  );
28184
28321
  }
28185
- 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;
28186
28323
  var init_swift_compile = __esm({
28187
28324
  "src/swift-compile.ts"() {
28188
28325
  import_node_child_process28 = require("node:child_process");
@@ -28452,7 +28589,7 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
28452
28589
  REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
28453
28590
  MULTI_MANIFEST_VERSION = 76;
28454
28591
  SWIFT_HEADER_PRODUCTS_TARGET = "PeachHeaderProducts";
28455
- compilerSourceDigest = true ? "37c95b1d4be497f3f882c4c51f2be7e5bb09b4bcc4976a51d553b0a993c9c7ca" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
28592
+ compilerSourceDigest = true ? "203439fc20df8d328b0c245496fc6db90092265409adb61b593725e82ce837de" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
28456
28593
  nativeCxxCompilerFlags = ["-fno-cxx-modules"];
28457
28594
  MODULE_MAP_RESPONSE_FILE_RUN = 16;
28458
28595
  cFlagArray = (flags) => JSON.stringify(withoutGlogModuleMap(flags));
@@ -28876,6 +29013,7 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
28876
29013
  retainedArtifacts = /* @__PURE__ */ new Map();
28877
29014
  FRAMEWORK_LINK_TARGET = "PeachFrameworkLink";
28878
29015
  frameworkProductsReceiptSchema = v6.object({
29016
+ root: v6.string(),
28879
29017
  modules: v6.string(),
28880
29018
  objects: v6.array(v6.string()),
28881
29019
  lazyObjects: v6.array(v6.string()),
@@ -28892,6 +29030,9 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
28892
29030
  SWIFT_FRAMEWORK_UNOPTIMIZED_SLOTS = 4;
28893
29031
  SWIFT_FRAMEWORK_SLOT_KEY = ".peach-framework-key";
28894
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";
28895
29036
  }
28896
29037
  });
28897
29038
  init_swift_compile();