peachsim 0.1.2606 → 0.1.2608

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 (134) 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-4QDEL7IO.mjs} +3 -3
  30. package/dist-lib/esm-chunks/{chunk-5ANQR24T.mjs → chunk-3DUFAH5J.mjs} +1 -1
  31. package/dist-lib/esm-chunks/{chunk-OB5XSLW6.mjs → chunk-4C57RZXG.mjs} +3 -2
  32. package/dist-lib/esm-chunks/{chunk-QFASF6EH.mjs → chunk-7KU5ROOE.mjs} +5 -5
  33. package/dist-lib/esm-chunks/{chunk-EXB4QSQI.mjs → chunk-BEWJL2LY.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-O6NRI4T2.mjs → chunk-F2FHFORX.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-66ESCMV3.mjs → chunk-F724FZHJ.mjs} +818 -678
  36. package/dist-lib/esm-chunks/{chunk-VTZJPPTE.mjs → chunk-GPPOU5DO.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-WJKACRMG.mjs → chunk-H3QASOKR.mjs} +1 -1
  38. package/dist-lib/esm-chunks/{chunk-TVICD24H.mjs → chunk-IJX7PBNG.mjs} +1 -1
  39. package/dist-lib/esm-chunks/{chunk-25LYRBSX.mjs → chunk-IKFFQXJN.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-O6ZNRBLB.mjs → chunk-JIW4PICV.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-5JMW5G3U.mjs → chunk-KNCWQQZG.mjs} +1 -1
  42. package/dist-lib/esm-chunks/{chunk-MBCSJQRY.mjs → chunk-NXG27NGU.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-PLOV7VQQ.mjs → chunk-R25MOOFS.mjs} +1 -1
  44. package/dist-lib/esm-chunks/{chunk-34CIYRB7.mjs → chunk-RTXAZMTP.mjs} +4 -4
  45. package/dist-lib/esm-chunks/{chunk-B7AXR7WA.mjs → chunk-RZLGVWHK.mjs} +1 -1
  46. package/dist-lib/esm-chunks/{chunk-RTPUFY2K.mjs → chunk-UHYHEJ3N.mjs} +5 -5
  47. package/dist-lib/esm-chunks/{chunk-KWLQDES2.mjs → chunk-VICI67J5.mjs} +1 -1
  48. package/dist-lib/esm-chunks/{chunk-CPMK3DA6.mjs → chunk-W5EHCHDD.mjs} +3 -3
  49. package/dist-lib/esm-chunks/{chunk-E2TASYAA.mjs → chunk-X6CONUT6.mjs} +1 -1
  50. package/dist-lib/esm-chunks/{chunk-XUWYWP35.mjs → chunk-YBMBAXAZ.mjs} +1 -1
  51. package/dist-lib/esm-chunks/{chunk-L7FPUZZO.mjs → chunk-ZFI5OF6U.mjs} +1 -1
  52. package/dist-lib/esm-chunks/{metro-layout-parser-OMUFYOJI.mjs → metro-layout-parser-YWPJI3L6.mjs} +3 -3
  53. package/dist-lib/esm-chunks/{swift-package-prebuilt-X7EZCX34.mjs → swift-package-prebuilt-MWTLCMQD.mjs} +10 -10
  54. package/dist-lib/esm-chunks/{swift-sdk-app-module-E3IF2XPD.mjs → swift-sdk-app-module-PF5QMK5X.mjs} +14 -14
  55. package/dist-lib/esm-chunks/{swift-sdk-image-57YYLNU6.mjs → swift-sdk-image-5IMAACRF.mjs} +14 -14
  56. package/dist-lib/esm-chunks/{swift-sdk-image-producer-DZOZTTDZ.mjs → swift-sdk-image-producer-JPIJI25U.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/install.sh +3 -2
  127. package/package.json +1 -1
  128. package/src/agent-prompt.ts +5 -1
  129. package/src/one-native-controls-package.ts +143 -1
  130. package/src/oneNativeControlsContract.ts +1 -0
  131. package/src/swift-compile-budget.ts +28 -7
  132. package/src/swift-compile.ts +968 -803
  133. package/src/swift-guest-compile.ts +3 -0
  134. 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.2608 | (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;
@@ -6573,7 +6573,8 @@ function swiftCompilerRelease(release) {
6573
6573
  }
6574
6574
  function swiftToolchainBin(release) {
6575
6575
  if (process.platform === "darwin") {
6576
- const dirs = [import_node_os5.default.homedir(), "/"].map(
6576
+ const bases = [.../* @__PURE__ */ new Set([import_node_os5.default.homedir(), import_node_path12.default.dirname(peachHome()), "/"])];
6577
+ const dirs = bases.map(
6577
6578
  (base2) => import_node_path12.default.join(base2, `Library/Developer/Toolchains/${release}.xctoolchain/usr/bin`)
6578
6579
  );
6579
6580
  const found = dirs.find((dir) => import_node_fs14.default.existsSync(import_node_path12.default.join(dir, "swift")));
@@ -9996,24 +9997,37 @@ function swiftBuilderHopTimeoutMs(compileTimeoutMs) {
9996
9997
  async function withSwiftCompileBudget(compileTimeoutMs, signal, work) {
9997
9998
  const deadline = new AbortController();
9998
9999
  const combined = signal ? AbortSignal.any([signal, deadline.signal]) : deadline.signal;
10000
+ const stallMs = compileTimeoutMs ?? SWIFT_COMPILE_TIMEOUT_MS;
10001
+ let compiling = false;
9999
10002
  let timer = setTimeout(
10000
10003
  () => deadline.abort(new Error("Swift build lock wait timed out")),
10001
10004
  SWIFT_LOCK_WAIT_TIMEOUT_MS
10002
10005
  );
10006
+ const restart = () => {
10007
+ clearTimeout(timer);
10008
+ timer = setTimeout(
10009
+ () => deadline.abort(
10010
+ new Error(
10011
+ `Swift compilation made no progress for ${Math.round(stallMs / 1e3)}s`
10012
+ )
10013
+ ),
10014
+ stallMs
10015
+ );
10016
+ };
10003
10017
  try {
10004
10018
  combined.throwIfAborted();
10005
10019
  const result = await work({
10006
10020
  signal: combined,
10007
10021
  startCompile() {
10008
10022
  combined.throwIfAborted();
10009
- clearTimeout(timer);
10010
- timer = setTimeout(
10011
- () => deadline.abort(new Error("Swift compilation timed out")),
10012
- compileTimeoutMs ?? SWIFT_COMPILE_TIMEOUT_MS
10013
- );
10023
+ compiling = true;
10024
+ restart();
10025
+ },
10026
+ progress() {
10027
+ if (compiling && !deadline.signal.aborted) restart();
10014
10028
  }
10015
10029
  });
10016
- combined.throwIfAborted();
10030
+ signal?.throwIfAborted();
10017
10031
  return result;
10018
10032
  } finally {
10019
10033
  clearTimeout(timer);
@@ -31464,6 +31478,7 @@ async function compileGuestLink(options2) {
31464
31478
  );
31465
31479
  continue;
31466
31480
  }
31481
+ options2.onStage("lowering the app image");
31467
31482
  const lowerPromise = link.lower();
31468
31483
  await new Promise((resolve4) => setImmediate(resolve4));
31469
31484
  let binding;
@@ -31494,6 +31509,7 @@ async function compileGuestLink(options2) {
31494
31509
  return binding;
31495
31510
  }
31496
31511
  }
31512
+ options2.onStage("lowering the app image");
31497
31513
  await lowerWasm(options2.output, options2.optimized, {
31498
31514
  optimize: options2.optimize,
31499
31515
  skipPasses: ["duplicate-function-elimination"],
@@ -32947,8 +32963,18 @@ async function runCompiler(command, args, options2, stream = false, quiet) {
32947
32963
  void stopping.catch(() => {
32948
32964
  });
32949
32965
  };
32966
+ const restartTimeout = () => {
32967
+ if (!options2.timeout) return;
32968
+ clearTimeout(timeout);
32969
+ timeout = setTimeout(() => {
32970
+ failure2 = new Error(`Swift compiler was silent for ${options2.timeout}ms`);
32971
+ stop();
32972
+ }, options2.timeout);
32973
+ };
32950
32974
  for (const name3 of ["stdout", "stderr"]) {
32951
32975
  child[name3].on("data", (bytes) => {
32976
+ restartTimeout();
32977
+ options2.onOutput?.();
32952
32978
  if (stream === true) process[name3].write(bytes);
32953
32979
  else if (stream) {
32954
32980
  const lines = (partial[name3] + bytes.toString()).split("\n");
@@ -32997,11 +33023,7 @@ async function runCompiler(command, args, options2, stream = false, quiet) {
32997
33023
  resolve4(Buffer.concat(chunks.stdout).toString());
32998
33024
  }
32999
33025
  });
33000
- if (options2.timeout)
33001
- timeout = setTimeout(() => {
33002
- failure2 = new Error("Swift compiler timed out");
33003
- stop();
33004
- }, options2.timeout);
33026
+ restartTimeout();
33005
33027
  if (signal?.aborted) stop();
33006
33028
  });
33007
33029
  } finally {
@@ -37879,24 +37901,18 @@ function readFrameworkProductsReceipt(scratch2, receiptKey) {
37879
37901
  } catch {
37880
37902
  return null;
37881
37903
  }
37882
- const archive = import_node_path53.default.join(scratch2, "lib");
37883
- const archiveStamp = import_node_path53.default.join(archive, ".receipt");
37884
- const archiveMatches = (0, import_node_fs53.existsSync)(archiveStamp) && (0, import_node_fs53.readFileSync)(archiveStamp, "utf8") === receiptKey;
37904
+ const archiveRoot = import_node_path53.default.join(scratch2, "products-lib", receiptKey);
37905
+ if (parsed2.root !== archiveRoot) return null;
37885
37906
  if (!(0, import_node_fs53.existsSync)(parsed2.modules)) return null;
37886
- for (const [object8] of parsed2.archived) if (!(0, import_node_fs53.existsSync)(object8)) return null;
37907
+ for (const [object8, rel] of parsed2.archived) {
37908
+ if (!(0, import_node_fs53.existsSync)(object8) || !(0, import_node_fs53.existsSync)(import_node_path53.default.join(archiveRoot, rel))) return null;
37909
+ }
37887
37910
  for (const file of parsed2.providers) if (!(0, import_node_fs53.existsSync)(file)) return null;
37888
37911
  for (const file of parsed2.moduleMaps) if (!(0, import_node_fs53.existsSync)(file)) return null;
37889
- if (!archiveMatches) {
37890
- (0, import_node_fs53.rmSync)(archive, { recursive: true, force: true });
37891
- (0, import_node_fs53.mkdirSync)(archive, { recursive: true });
37892
- for (const [object8, rel] of parsed2.archived)
37893
- (0, import_node_fs53.symlinkSync)(object8, import_node_path53.default.join(scratch2, rel));
37894
- (0, import_node_fs53.writeFileSync)(archiveStamp, receiptKey);
37895
- }
37896
37912
  for (const file of parsed2.objects) if (!(0, import_node_fs53.existsSync)(file)) return null;
37897
37913
  for (const file of parsed2.lazyObjects) if (!(0, import_node_fs53.existsSync)(file)) return null;
37898
37914
  return {
37899
- root: scratch2,
37915
+ root: parsed2.root,
37900
37916
  modules: parsed2.modules,
37901
37917
  objects: parsed2.objects,
37902
37918
  lazyObjects: parsed2.lazyObjects,
@@ -37914,7 +37930,7 @@ async function buildFrameworkProducts(scratch2, args) {
37914
37930
  const selectorOptions = swiftObjCSelectorOptions(args.moduleRoot);
37915
37931
  const receiptKey = (0, import_node_crypto32.createHash)("sha256").update(
37916
37932
  JSON.stringify([
37917
- "framework-products/v1",
37933
+ "framework-products/v2",
37918
37934
  args.frameworkKey,
37919
37935
  unoptimized,
37920
37936
  args.sdk,
@@ -38072,28 +38088,40 @@ async function buildFrameworkProducts(scratch2, args) {
38072
38088
  }
38073
38089
  const providers = (0, import_node_fs53.readdirSync)(providerDir).filter((file) => file.endsWith(".o")).sort().map((file) => import_node_path53.default.join(providerDir, file));
38074
38090
  for (const provider of providers) linked.owners.set(provider, "DarwinRecords");
38075
- const archive = import_node_path53.default.join(scratch2, "lib");
38076
- (0, import_node_fs53.rmSync)(archive, { recursive: true, force: true });
38077
- (0, import_node_fs53.mkdirSync)(archive);
38091
+ const archiveBase = import_node_path53.default.join(scratch2, "products-lib");
38092
+ (0, import_node_fs53.mkdirSync)(archiveBase, { recursive: true });
38093
+ const archiveRoot = import_node_path53.default.join(archiveBase, receiptKey);
38094
+ const stagedArchiveRoot = `${archiveRoot}.tmp-${process.pid}-${(0, import_node_crypto32.randomUUID)()}`;
38095
+ const stagedArchive = import_node_path53.default.join(stagedArchiveRoot, "lib");
38096
+ (0, import_node_fs53.mkdirSync)(stagedArchive, { recursive: true });
38078
38097
  const archived = /* @__PURE__ */ new Map();
38079
- for (const object8 of objects) {
38080
- const target = linked.owners.get(object8);
38081
- const dir = import_node_path53.default.join(release, `${target}.build`);
38082
- if (!target || target === "Darwin" || !object8.startsWith(dir + import_node_path53.default.sep)) continue;
38083
- const name3 = `${target}-${import_node_path53.default.relative(dir, object8).replaceAll(import_node_path53.default.sep, "-").replace(/\.swift\.o$/, ".o")}`;
38084
- (0, import_node_fs53.symlinkSync)(object8, import_node_path53.default.join(archive, name3));
38085
- archived.set(object8, `lib/${name3}`);
38086
- }
38087
- const roots = swiftObjcRootObjects(`${scratch2}
38088
- ${args.frameworkKey}`, scratch2, [
38089
- ...archived.values()
38090
- ]);
38098
+ try {
38099
+ for (const object8 of objects) {
38100
+ const target = linked.owners.get(object8);
38101
+ const dir = import_node_path53.default.join(release, `${target}.build`);
38102
+ if (!target || target === "Darwin" || !object8.startsWith(dir + import_node_path53.default.sep)) continue;
38103
+ const name3 = `${target}-${import_node_path53.default.relative(dir, object8).replaceAll(import_node_path53.default.sep, "-").replace(/\.swift\.o$/, ".o")}`;
38104
+ (0, import_node_fs53.symlinkSync)(object8, import_node_path53.default.join(stagedArchive, name3));
38105
+ archived.set(object8, `lib/${name3}`);
38106
+ }
38107
+ (0, import_node_fs53.rmSync)(archiveRoot, { recursive: true, force: true });
38108
+ (0, import_node_fs53.renameSync)(stagedArchiveRoot, archiveRoot);
38109
+ } catch (error) {
38110
+ (0, import_node_fs53.rmSync)(stagedArchiveRoot, { recursive: true, force: true });
38111
+ throw error;
38112
+ }
38113
+ const roots = swiftObjcRootObjects(
38114
+ `${archiveRoot}
38115
+ ${args.frameworkKey}`,
38116
+ archiveRoot,
38117
+ [...archived.values()]
38118
+ );
38091
38119
  const linkedObjects = objects.map((object8) => {
38092
38120
  const name3 = archived.get(object8);
38093
- return name3 ? { path: import_node_path53.default.join(scratch2, name3), lazy: !roots.has(name3) } : { path: object8, lazy: false };
38121
+ return name3 ? { path: import_node_path53.default.join(archiveRoot, name3), lazy: !roots.has(name3) } : { path: object8, lazy: false };
38094
38122
  });
38095
38123
  const result = {
38096
- root: scratch2,
38124
+ root: archiveRoot,
38097
38125
  modules: import_node_path53.default.join(release, "Modules"),
38098
38126
  objects: linkedObjects.filter((object8) => !object8.lazy).map((object8) => object8.path),
38099
38127
  lazyObjects: linkedObjects.filter((object8) => object8.lazy).map((object8) => object8.path),
@@ -38103,7 +38131,6 @@ ${args.frameworkKey}`, scratch2, [
38103
38131
  moduleMaps: linked.moduleMaps,
38104
38132
  objcHeaders: linked.objcHeaders
38105
38133
  };
38106
- (0, import_node_fs53.writeFileSync)(import_node_path53.default.join(archive, ".receipt"), receiptKey);
38107
38134
  const receiptsDir = import_node_path53.default.join(scratch2, "products-ready");
38108
38135
  (0, import_node_fs53.mkdirSync)(receiptsDir, { recursive: true });
38109
38136
  const receiptFile2 = import_node_path53.default.join(receiptsDir, `${receiptKey}.json`);
@@ -38111,6 +38138,7 @@ ${args.frameworkKey}`, scratch2, [
38111
38138
  (0, import_node_fs53.writeFileSync)(
38112
38139
  partialReceipt,
38113
38140
  JSON.stringify({
38141
+ root: result.root,
38114
38142
  modules: result.modules,
38115
38143
  objects: result.objects,
38116
38144
  lazyObjects: result.lazyObjects,
@@ -38142,7 +38170,10 @@ function swiftFrameworkSlotRecord(slot, record5) {
38142
38170
  function swiftFrameworkSlotKey(slot) {
38143
38171
  return swiftFrameworkSlotRecord(slot, SWIFT_FRAMEWORK_SLOT_KEY);
38144
38172
  }
38145
- async function withSwiftFrameworkSlot(frameworkKey, moduleRoot, signal, work, unoptimized = false) {
38173
+ function swiftFrameworkSlotRelease(slot) {
38174
+ return swiftFrameworkSlotRecord(slot, SWIFT_FRAMEWORK_SLOT_RELEASE);
38175
+ }
38176
+ async function withSwiftFrameworkSlot(frameworkKey, release, moduleRoot, signal, work, unoptimized = false) {
38146
38177
  const slotCount = unoptimized ? SWIFT_FRAMEWORK_UNOPTIMIZED_SLOTS : SWIFT_FRAMEWORK_SLOTS;
38147
38178
  const slotsDir = swiftFrameworksDir(unoptimized);
38148
38179
  const slots = Array.from({ length: slotCount }, (_, index) => {
@@ -38165,9 +38196,12 @@ async function withSwiftFrameworkSlot(frameworkKey, moduleRoot, signal, work, un
38165
38196
  (0, import_node_fs53.readFileSync)(import_node_path53.default.join(moduleRoot, file))
38166
38197
  ])
38167
38198
  );
38168
- const ranked = slots.map((slot) => {
38199
+ const ranked = slots.map((slot, index) => {
38200
+ const slotKey = swiftFrameworkSlotKey(slot);
38201
+ if (slotKey === null) return { slot, index, tier: 1, changes: Infinity };
38202
+ if (swiftFrameworkSlotRelease(slot) !== release)
38203
+ return { slot, index, tier: 2, changes: Infinity };
38169
38204
  let changes = 0;
38170
- if (swiftFrameworkSlotKey(slot) === null) return { slot, changes: Infinity };
38171
38205
  const source = import_node_path53.default.join(slot, "source", "packages", import_node_path53.default.basename(moduleRoot));
38172
38206
  for (const [file, contents2] of inputs2) {
38173
38207
  try {
@@ -38179,18 +38213,22 @@ async function withSwiftFrameworkSlot(frameworkKey, moduleRoot, signal, work, un
38179
38213
  changes++;
38180
38214
  }
38181
38215
  }
38182
- return { slot, changes };
38183
- }).sort(
38184
- (left, right) => left.changes - right.changes || Number(own2(right.slot)) - Number(own2(left.slot)) || (built2.get(right.slot) ?? 0) - (built2.get(left.slot) ?? 0)
38185
- );
38186
- for (const { slot, changes } of ranked) {
38216
+ return { slot, index, tier: 0, changes };
38217
+ }).sort((left, right) => {
38218
+ if (left.tier !== right.tier) return left.tier - right.tier;
38219
+ if (left.tier === 0)
38220
+ return left.changes - right.changes || Number(own2(right.slot)) - Number(own2(left.slot)) || (built2.get(right.slot) ?? 0) - (built2.get(left.slot) ?? 0);
38221
+ if (left.tier === 1) return left.index - right.index;
38222
+ return (built2.get(left.slot) ?? 0) - (built2.get(right.slot) ?? 0);
38223
+ });
38224
+ for (const { slot, tier, changes } of ranked) {
38187
38225
  if (await hasLiveSwiftRootReaders(slot, signal)) continue;
38188
38226
  const result = await withSwiftRootLock(
38189
38227
  slot,
38190
38228
  async (lease) => {
38191
38229
  if (await hasLiveSwiftRootReaders(slot, signal)) return void 0;
38192
38230
  console.error(
38193
- `[swift-framework-cache] ${import_node_path53.default.basename(slot)} changedInputs=${changes} totalInputs=${inputs2.size}`
38231
+ `[swift-framework-cache] ${import_node_path53.default.basename(slot)} release=${release} tier=${tier} changedInputs=${changes} totalInputs=${inputs2.size}`
38194
38232
  );
38195
38233
  return { value: await run16(slot)(lease) };
38196
38234
  },
@@ -38202,6 +38240,43 @@ async function withSwiftFrameworkSlot(frameworkKey, moduleRoot, signal, work, un
38202
38240
  const nearest = ranked[0].slot;
38203
38241
  return withSwiftRootLock(nearest, run16(nearest), signal);
38204
38242
  }
38243
+ async function withSwiftBuildRootSlot(baseRoot, buildShape, signal, work) {
38244
+ const slots = Array.from({ length: SWIFT_BUILD_ROOT_SLOTS }, (_, index) => {
38245
+ const slot = index === 0 ? baseRoot : `${baseRoot}-s${index}`;
38246
+ (0, import_node_fs53.mkdirSync)(slot, { recursive: true });
38247
+ return slot;
38248
+ });
38249
+ const runInSlot = (slot, waitStart2) => (lease) => {
38250
+ const waitedMs = Date.now() - waitStart2;
38251
+ const now = /* @__PURE__ */ new Date();
38252
+ (0, import_node_fs53.utimesSync)(slot, now, now);
38253
+ return work(slot, lease, waitedMs);
38254
+ };
38255
+ const built2 = new Map(slots.map((slot) => [slot, (0, import_node_fs53.statSync)(slot).mtimeMs]));
38256
+ const ranked = slots.map((slot, index) => {
38257
+ const shape = swiftFrameworkSlotRecord(slot, SWIFT_BUILD_ROOT_SHAPE);
38258
+ const tier = shape === buildShape ? 0 : shape === null ? 1 : 2;
38259
+ return { slot, index, tier };
38260
+ }).sort((left, right) => {
38261
+ if (left.tier !== right.tier) return left.tier - right.tier;
38262
+ if (left.tier === 0)
38263
+ return (built2.get(right.slot) ?? 0) - (built2.get(left.slot) ?? 0);
38264
+ if (left.tier === 1) return left.index - right.index;
38265
+ return (built2.get(left.slot) ?? 0) - (built2.get(right.slot) ?? 0);
38266
+ });
38267
+ for (const { slot } of ranked) {
38268
+ const result = await withSwiftRootLock(
38269
+ slot,
38270
+ async (lease) => ({ value: await runInSlot(slot, Date.now())(lease) }),
38271
+ signal,
38272
+ false
38273
+ );
38274
+ if (result) return result.value;
38275
+ }
38276
+ const nearest = ranked[0].slot;
38277
+ const waitStart = Date.now();
38278
+ return withSwiftRootLock(nearest, runInSlot(nearest, waitStart), signal);
38279
+ }
38205
38280
  function mirrorTree2(source, target, skip) {
38206
38281
  (0, import_node_fs53.mkdirSync)(target, { recursive: true });
38207
38282
  const wanted = /* @__PURE__ */ new Set();
@@ -38251,8 +38326,10 @@ function stageFrameworkSource(moduleRoot, slot, frameworkKey, release) {
38251
38326
  const hadKey = swiftFrameworkSlotKey(slot);
38252
38327
  if (hadKey !== frameworkKey) {
38253
38328
  (0, import_node_fs53.rmSync)(import_node_path53.default.join(slot, SWIFT_FRAMEWORK_SLOT_KEY), { force: true });
38329
+ (0, import_node_fs53.rmSync)(import_node_path53.default.join(slot, SWIFT_FRAMEWORK_SLOT_RELEASE), { force: true });
38254
38330
  (0, import_node_fs53.rmSync)(import_node_path53.default.join(slot, "products-ready"), { recursive: true, force: true });
38255
- (0, import_node_fs53.rmSync)(import_node_path53.default.join(slot, "lib", ".receipt"), { force: true });
38331
+ (0, import_node_fs53.rmSync)(import_node_path53.default.join(slot, "products-lib"), { recursive: true, force: true });
38332
+ (0, import_node_fs53.rmSync)(import_node_path53.default.join(slot, "lib"), { recursive: true, force: true });
38256
38333
  const moduleRestructured = mirrorTree2(moduleRoot, stagedModule, ".build");
38257
38334
  const sdkRestructured = mirrorTree2(
38258
38335
  swiftSharedSdkRoot(moduleRoot, false),
@@ -38280,8 +38357,11 @@ function stageFrameworkSource(moduleRoot, slot, frameworkKey, release) {
38280
38357
  (0, import_node_fs53.rmSync)(modules, { recursive: true, force: true });
38281
38358
  (0, import_node_fs53.symlinkSync)(target, modules);
38282
38359
  }
38360
+ (0, import_node_fs53.writeFileSync)(import_node_path53.default.join(slot, SWIFT_FRAMEWORK_SLOT_RELEASE), release);
38283
38361
  (0, import_node_fs53.writeFileSync)(import_node_path53.default.join(slot, SWIFT_FRAMEWORK_SLOT_KEY), frameworkKey);
38284
38362
  (0, import_node_fs53.writeFileSync)(import_node_path53.default.join(slot, SWIFT_FRAMEWORK_SLOT_ORIGIN), moduleRoot);
38363
+ } else if (swiftFrameworkSlotRelease(slot) !== release) {
38364
+ (0, import_node_fs53.writeFileSync)(import_node_path53.default.join(slot, SWIFT_FRAMEWORK_SLOT_RELEASE), release);
38285
38365
  }
38286
38366
  return stagedModule;
38287
38367
  }
@@ -38509,660 +38589,717 @@ ${cap}` : "";
38509
38589
  (0, import_node_fs53.rmSync)(requestRoot, { recursive: true, force: true });
38510
38590
  }
38511
38591
  }
38592
+ const baseRoot = root;
38593
+ const canPoolBuildRoot = !options2.intermediates && !options2.project && !options2.linkOnly && import_node_path53.default.basename(import_node_path53.default.dirname(baseRoot)) === "swift-builds";
38594
+ const buildShape = canPoolBuildRoot ? (0, import_node_crypto32.createHash)("sha256").update(
38595
+ JSON.stringify([
38596
+ frameworkKey,
38597
+ Boolean(sdkImage),
38598
+ compileTargets(input).map((target) => target.name).sort(),
38599
+ input.oneModule === true,
38600
+ input.optimize === true,
38601
+ input.unoptimized === true,
38602
+ Object.keys(input.files).sort()
38603
+ ])
38604
+ ).digest("hex").slice(0, 16) : "";
38512
38605
  return withSwiftCompileBudget(options2.timeoutMs, options2.signal, async (budget) => {
38513
- return withSwiftRootLock(
38514
- root,
38515
- async (lease) => {
38516
- if (!options2.intermediates) {
38517
- const built2 = readCompiledArtifact(import_node_path53.default.join(sharedRoot, "artifact"), hash);
38518
- if (built2) {
38519
- report("reusing verified disk artifact");
38520
- return retain(root, built2);
38521
- }
38522
- }
38523
- const swift = import_node_path53.default.join(options2.toolchainBin, "swift");
38524
- if (!(0, import_node_fs53.existsSync)(swift)) {
38525
- throw new Error(
38526
- `swift-compile: no swift.org toolchain at ${options2.toolchainBin}; install ${options2.release} and its matching wasm sdk`
38527
- );
38606
+ const stage = (message) => {
38607
+ budget.progress();
38608
+ report(message);
38609
+ };
38610
+ const runLocked = (work) => {
38611
+ if (canPoolBuildRoot) {
38612
+ (0, import_node_fs53.mkdirSync)(sharedRoot, { recursive: true });
38613
+ return withSwiftRootLock(
38614
+ sharedRoot,
38615
+ async () => {
38616
+ const built2 = readCompiledArtifact(
38617
+ import_node_path53.default.join(sharedRoot, "artifact"),
38618
+ hash
38619
+ );
38620
+ if (built2) {
38621
+ stage("reusing verified disk artifact");
38622
+ return retain(baseRoot, built2);
38623
+ }
38624
+ return withSwiftBuildRootSlot(baseRoot, buildShape, budget.signal, work);
38625
+ },
38626
+ budget.signal
38627
+ );
38628
+ }
38629
+ const waitStart = Date.now();
38630
+ return withSwiftRootLock(
38631
+ baseRoot,
38632
+ (lease) => work(baseRoot, lease, Date.now() - waitStart),
38633
+ budget.signal
38634
+ );
38635
+ };
38636
+ return runLocked(async (slotRoot, lease, waitedMs) => {
38637
+ const root2 = slotRoot;
38638
+ const layout3 = {
38639
+ root: root2,
38640
+ sources: import_node_path53.default.join(root2, "Sources", "App"),
38641
+ multi: compileTargets(input).length > 0
38642
+ };
38643
+ if (!options2.intermediates) {
38644
+ const built2 = readCompiledArtifact(import_node_path53.default.join(sharedRoot, "artifact"), hash);
38645
+ if (built2) {
38646
+ stage("reusing verified disk artifact");
38647
+ return retain(baseRoot, built2);
38528
38648
  }
38529
- const unoptimized = input.unoptimized === true;
38530
- const withFrameworkLock = (work) => distribution ? work(null) : withSwiftFrameworkSlot(
38531
- frameworkKey,
38532
- moduleRoot,
38649
+ }
38650
+ if (waitedMs >= 1e3)
38651
+ report(`acquired build root ${import_node_path53.default.basename(root2)} after ${waitedMs}ms`);
38652
+ if (canPoolBuildRoot) {
38653
+ refreshSwiftCacheHold(root2);
38654
+ (0, import_node_fs53.writeFileSync)(import_node_path53.default.join(root2, SWIFT_BUILD_ROOT_SHAPE), buildShape);
38655
+ }
38656
+ const swift = import_node_path53.default.join(options2.toolchainBin, "swift");
38657
+ if (!(0, import_node_fs53.existsSync)(swift)) {
38658
+ throw new Error(
38659
+ `swift-compile: no swift.org toolchain at ${options2.toolchainBin}; install ${options2.release} and its matching wasm sdk`
38660
+ );
38661
+ }
38662
+ const unoptimized = input.unoptimized === true;
38663
+ const withFrameworkLock = (work) => distribution ? work(null) : withSwiftFrameworkSlot(
38664
+ frameworkKey,
38665
+ options2.release,
38666
+ moduleRoot,
38667
+ budget.signal,
38668
+ work,
38669
+ unoptimized
38670
+ );
38671
+ const baseBuildEnv = options2.project?.env ? {
38672
+ ...options2.project.env,
38673
+ // shipped host plugins resolve against the selected compiler's runtime.
38674
+ ...process.platform === "linux" ? {
38675
+ LD_LIBRARY_PATH: [
38676
+ import_node_path53.default.resolve(options2.toolchainBin, "../lib/swift/linux"),
38677
+ import_node_path53.default.resolve(options2.toolchainBin, "../lib/swift/host"),
38678
+ process.env.LD_LIBRARY_PATH
38679
+ ].filter(Boolean).join(":")
38680
+ } : {},
38681
+ PEACH_DEFER_WASM_LINK: "1"
38682
+ } : swiftCompilerBaseEnv(options2.toolchainBin, process.env);
38683
+ const {
38684
+ frameworkRoot,
38685
+ compileFrameworkRoot,
38686
+ macroPlugins,
38687
+ sdk: sdk2,
38688
+ icu,
38689
+ prebuilt,
38690
+ readHold
38691
+ } = await withFrameworkLock(async (slot, frameworkLease) => {
38692
+ budget.startCompile();
38693
+ if (slot && swiftFrameworkSlotKey(slot) !== frameworkKey)
38694
+ await waitForNoSwiftRootReaders(slot, budget.signal);
38695
+ const frameworkRoot2 = mirrorDistribution ? syncSwiftDistributionMirror(root2, moduleRoot, mirrorDistribution) : distribution ? moduleRoot : stageFrameworkSource(moduleRoot, slot, frameworkKey, options2.release);
38696
+ if (!swiftModuleDigest(frameworkRoot2).equals(moduleDigest))
38697
+ throw new Error("Swift staged project source differs from the caller");
38698
+ stage("preparing compiler plugins");
38699
+ const macroPlugins2 = await ensureMacroPlugins(
38700
+ frameworkRoot2,
38701
+ options2.toolchainBin,
38702
+ options2.release,
38533
38703
  budget.signal,
38534
- work,
38535
- unoptimized
38704
+ frameworkLease
38536
38705
  );
38537
- const baseBuildEnv = options2.project?.env ? {
38538
- ...options2.project.env,
38539
- // shipped host plugins resolve against the selected compiler's runtime.
38540
- ...process.platform === "linux" ? {
38541
- LD_LIBRARY_PATH: [
38542
- import_node_path53.default.resolve(options2.toolchainBin, "../lib/swift/linux"),
38543
- import_node_path53.default.resolve(options2.toolchainBin, "../lib/swift/host"),
38544
- process.env.LD_LIBRARY_PATH
38545
- ].filter(Boolean).join(":")
38546
- } : {},
38547
- PEACH_DEFER_WASM_LINK: "1"
38548
- } : swiftCompilerBaseEnv(options2.toolchainBin, process.env);
38549
- const {
38706
+ const compileFrameworkRoot2 = distribution ? swiftDistributionCompileView(frameworkRoot2, distribution) : frameworkRoot2;
38707
+ const sdk3 = swiftModuleSdk(frameworkRoot2).wasmSdkId;
38708
+ const icu2 = options2.linkOnly ? null : swiftIcuAsset(options2.toolchainBin, sdk3);
38709
+ let prebuilt2;
38710
+ if (!distribution) {
38711
+ stage("compiling framework products");
38712
+ prebuilt2 = await buildFrameworkProducts(slot, {
38713
+ moduleRoot: frameworkRoot2,
38714
+ frameworkKey,
38715
+ input,
38716
+ swift,
38717
+ sdk: sdk3,
38718
+ toolchainBin: options2.toolchainBin,
38719
+ plugins: macroPlugins2,
38720
+ buildOptions: {
38721
+ env: baseBuildEnv,
38722
+ maxBuffer: 64 * 1024 * 1024,
38723
+ signal: budget.signal,
38724
+ onOutput: budget.progress,
38725
+ lease,
38726
+ frameworkLease
38727
+ }
38728
+ });
38729
+ }
38730
+ const readHold2 = slot ? acquireSwiftRootReadHold(slot) : void 0;
38731
+ return {
38732
+ frameworkRoot: frameworkRoot2,
38733
+ compileFrameworkRoot: compileFrameworkRoot2,
38734
+ macroPlugins: macroPlugins2,
38735
+ sdk: sdk3,
38736
+ icu: icu2,
38737
+ prebuilt: prebuilt2,
38738
+ readHold: readHold2
38739
+ };
38740
+ });
38741
+ const buildOptions = {
38742
+ env: baseBuildEnv,
38743
+ maxBuffer: 64 * 1024 * 1024,
38744
+ signal: budget.signal,
38745
+ onOutput: budget.progress,
38746
+ lease
38747
+ };
38748
+ try {
38749
+ if (options2.project) removeProjectLinks(root2);
38750
+ const packageHostMacros = process.platform === "linux" ? input.packageHostMacros : void 0;
38751
+ if (retireStaleSwiftLink(
38752
+ root2,
38753
+ swiftLinkStamp({
38754
+ frameworkKey: `${options2.release}\0${Boolean(distribution)}\0${swiftModuleSdk(frameworkRoot).wasmSdkId}`,
38755
+ packageHostMacros
38756
+ }),
38757
+ swiftLinkStamp({
38758
+ // a distribution's objects reach only the deferred link, and
38759
+ // the root's mirror keeps its compile inputs at fixed paths
38760
+ frameworkKey: distribution ? `${options2.release}\0${distribution.wasmSdkChecksum}` : frameworkKey,
38761
+ prebuilt,
38762
+ packageHostMacros
38763
+ }),
38764
+ Boolean(options2.linkOnly)
38765
+ ))
38766
+ stage("framework revision changed; rebuilding the app link");
38767
+ const nativeToolset = needsNativeToolset(input, prebuilt);
38768
+ const preparation = writeSwiftProject(
38769
+ layout3,
38770
+ input,
38550
38771
  frameworkRoot,
38551
- compileFrameworkRoot,
38552
- macroPlugins,
38553
- sdk: sdk2,
38554
- icu,
38555
38772
  prebuilt,
38556
- readHold
38557
- } = await withFrameworkLock(async (slot, frameworkLease) => {
38558
- budget.startCompile();
38559
- if (slot && swiftFrameworkSlotKey(slot) !== frameworkKey)
38560
- await waitForNoSwiftRootReaders(slot, budget.signal);
38561
- const frameworkRoot2 = mirrorDistribution ? syncSwiftDistributionMirror(root, moduleRoot, mirrorDistribution) : distribution ? moduleRoot : stageFrameworkSource(moduleRoot, slot, frameworkKey, options2.release);
38562
- if (!swiftModuleDigest(frameworkRoot2).equals(moduleDigest))
38563
- throw new Error("Swift staged project source differs from the caller");
38564
- report("preparing compiler plugins");
38565
- const macroPlugins2 = await ensureMacroPlugins(
38566
- frameworkRoot2,
38567
- options2.toolchainBin,
38568
- options2.release,
38569
- budget.signal,
38570
- frameworkLease
38773
+ !options2.project,
38774
+ options2.project ? false : options2.objcPrebuiltStage ?? (options2.intermediates ? false : void 0)
38775
+ );
38776
+ const productFile = import_node_path53.default.join(frameworkRoot, SWIFT_FRAMEWORK_PRODUCT_FILE);
38777
+ writeSwiftAutolinkLinker(
38778
+ root2,
38779
+ options2.toolchainBin,
38780
+ (0, import_node_fs53.existsSync)(productFile) ? [
38781
+ v6.parse(
38782
+ swiftFrameworkProductSchema,
38783
+ JSON.parse((0, import_node_fs53.readFileSync)(productFile, "utf8"))
38784
+ ).product.name
38785
+ ] : []
38786
+ );
38787
+ const compiler = preparation.targetToolset ? { CC: import_node_path53.default.join(root2, CLANG_TARGET_MODULE_WRAPPER) } : {};
38788
+ if (packageHostMacros?.length) {
38789
+ const swiftc = import_node_path53.default.join(root2, SWIFT_HOST_COMPILER_WRAPPER);
38790
+ writeBuildFile(
38791
+ swiftc,
38792
+ [
38793
+ "#!/bin/sh",
38794
+ "target=",
38795
+ "module=",
38796
+ "compile=",
38797
+ "previous=",
38798
+ "for argument do",
38799
+ ' case "$previous" in -target) target=$argument ;; -module-name) module=$argument ;; esac',
38800
+ ' case "$argument" in -c|-emit-module|-scan-dependencies|-typecheck) compile=1 ;; esac',
38801
+ " previous=$argument",
38802
+ "done",
38803
+ 'case "$target/$compile" in',
38804
+ " *-*-linux*/1)",
38805
+ ' case ",$PEACH_SWIFT_HOST_MACROS," in',
38806
+ ' *",$module,"*) set -- "$@" -Xfrontend -import-module -Xfrontend Foundation ;;',
38807
+ " esac ;;",
38808
+ "esac",
38809
+ 'exec "$PEACH_SWIFTC" "$@"',
38810
+ ""
38811
+ ].join("\n")
38571
38812
  );
38572
- const compileFrameworkRoot2 = distribution ? swiftDistributionCompileView(frameworkRoot2, distribution) : frameworkRoot2;
38573
- const sdk3 = swiftModuleSdk(frameworkRoot2).wasmSdkId;
38574
- const icu2 = options2.linkOnly ? null : swiftIcuAsset(options2.toolchainBin, sdk3);
38575
- let prebuilt2;
38576
- if (!distribution) {
38577
- report("compiling framework products");
38578
- prebuilt2 = await buildFrameworkProducts(slot, {
38579
- moduleRoot: frameworkRoot2,
38580
- frameworkKey,
38581
- input,
38582
- swift,
38583
- sdk: sdk3,
38584
- toolchainBin: options2.toolchainBin,
38585
- plugins: macroPlugins2,
38586
- buildOptions: {
38587
- env: baseBuildEnv,
38588
- maxBuffer: 64 * 1024 * 1024,
38589
- signal: budget.signal,
38590
- lease,
38591
- frameworkLease
38592
- }
38593
- });
38813
+ (0, import_node_fs53.chmodSync)(swiftc, 493);
38814
+ compiler.SWIFT_EXEC = swiftc;
38815
+ compiler.PEACH_SWIFT_HOST_MACROS = packageHostMacros.join(",");
38816
+ compiler.PEACH_SWIFTC = import_node_path53.default.join(options2.toolchainBin, "swiftc");
38817
+ }
38818
+ const projectProcess = options2.project ? prepareSwiftProjectProcess(root2, options2.project) : void 0;
38819
+ const temporaryDirectory = projectProcess ? void 0 : import_node_path53.default.join(root2, ".build", "peach-compiler-tmp");
38820
+ const appOptions = projectProcess ? {
38821
+ ...buildOptions,
38822
+ uid: projectProcess.uid,
38823
+ gid: projectProcess.gid,
38824
+ confined: { ...projectProcess.env, ...compiler }
38825
+ } : {
38826
+ ...buildOptions,
38827
+ temporaryDirectory,
38828
+ env: {
38829
+ ...buildOptions.env,
38830
+ ...preparation.usesObjcPrebuilt && process.env.PEACH_HOME !== void 0 ? { PEACH_HOME: process.env.PEACH_HOME } : {},
38831
+ ...compiler
38594
38832
  }
38595
- const readHold2 = slot ? acquireSwiftRootReadHold(slot) : void 0;
38596
- return {
38597
- frameworkRoot: frameworkRoot2,
38598
- compileFrameworkRoot: compileFrameworkRoot2,
38599
- macroPlugins: macroPlugins2,
38600
- sdk: sdk3,
38601
- icu: icu2,
38602
- prebuilt: prebuilt2,
38603
- readHold: readHold2
38604
- };
38605
- });
38606
- const buildOptions = {
38607
- env: baseBuildEnv,
38608
- maxBuffer: 64 * 1024 * 1024,
38609
- signal: budget.signal,
38610
- lease
38611
38833
  };
38612
- try {
38613
- if (options2.project) removeProjectLinks(root);
38614
- const packageHostMacros = process.platform === "linux" ? input.packageHostMacros : void 0;
38615
- if (retireStaleSwiftLink(
38616
- root,
38617
- swiftLinkStamp({
38618
- frameworkKey: `${options2.release}\0${Boolean(distribution)}\0${swiftModuleSdk(frameworkRoot).wasmSdkId}`,
38619
- packageHostMacros
38620
- }),
38621
- swiftLinkStamp({
38622
- // a distribution's objects reach only the deferred link, and
38623
- // the root's mirror keeps its compile inputs at fixed paths
38624
- frameworkKey: distribution ? `${options2.release}\0${distribution.wasmSdkChecksum}` : frameworkKey,
38625
- prebuilt,
38626
- packageHostMacros
38627
- }),
38628
- Boolean(options2.linkOnly)
38629
- ))
38630
- report("framework revision changed; rebuilding the app link");
38631
- const nativeToolset = needsNativeToolset(input, prebuilt);
38632
- const preparation = writeSwiftProject(
38633
- layout2,
38634
- input,
38635
- frameworkRoot,
38636
- prebuilt,
38637
- !options2.project,
38638
- options2.project ? false : options2.objcPrebuiltStage ?? (options2.intermediates ? false : void 0)
38834
+ const unprepared = preparation.targetFailures.map(
38835
+ (failure2) => `error: target ${failure2}`
38836
+ );
38837
+ const forwarders = /* @__PURE__ */ new Map();
38838
+ for (const [file, text7] of Object.entries(input.files)) {
38839
+ const parents = /^#include "((?:\.\.\/)+)[^"\n]+"\n$/.exec(text7)?.[1];
38840
+ if (!parents) continue;
38841
+ const directory2 = import_node_path53.default.posix.dirname(file);
38842
+ forwarders.set(
38843
+ `${import_node_path53.default.join(root2, directory2)}/${parents.slice(0, -1)}`,
38844
+ import_node_path53.default.posix.join("build", directory2, parents).replace(/\/$/, "")
38639
38845
  );
38640
- const productFile = import_node_path53.default.join(frameworkRoot, SWIFT_FRAMEWORK_PRODUCT_FILE);
38641
- writeSwiftAutolinkLinker(
38642
- root,
38643
- options2.toolchainBin,
38644
- (0, import_node_fs53.existsSync)(productFile) ? [
38645
- v6.parse(
38646
- swiftFrameworkProductSchema,
38647
- JSON.parse((0, import_node_fs53.readFileSync)(productFile, "utf8"))
38648
- ).product.name
38649
- ] : []
38846
+ }
38847
+ const jobs = swiftCompilerJobs();
38848
+ const incrementalPreview = sdkImage !== void 0 && !guestGraph && !options2.project && !input.optimize && !input.unoptimized;
38849
+ const perFile = input.unoptimized || incrementalPreview;
38850
+ const buildArgs = [
38851
+ "build",
38852
+ ...projectProcess?.cacheOptions ?? swiftPackageCacheOptions(),
38853
+ "--build-system",
38854
+ "native",
38855
+ "-j",
38856
+ String(jobs),
38857
+ "--package-path",
38858
+ root2,
38859
+ ...swiftCompileSdkOptions(frameworkRoot, options2.toolchainBin),
38860
+ ...swiftObjCSelectorOptions(frameworkRoot),
38861
+ "--swift-sdk",
38862
+ sdk2,
38863
+ ...preparation.targetToolset ? ["--toolset", import_node_path53.default.join(root2, ".peach-target-toolset.json")] : [],
38864
+ "-c",
38865
+ "release",
38866
+ ...input.unoptimized ? ["-Xswiftc", "-Onone"] : [],
38867
+ ...perFile ? [
38868
+ "-Xswiftc",
38869
+ "-no-whole-module-optimization",
38870
+ "-Xswiftc",
38871
+ "-j",
38872
+ "-Xswiftc",
38873
+ String(jobs)
38874
+ ] : [],
38875
+ ...incrementalPreview ? ["-Xswiftc", "-incremental", "-Xswiftc", "-enable-batch-mode"] : [],
38876
+ // the mirror finds a changed sdk header's readers in their
38877
+ // dependency files, which omit system headers by default
38878
+ ...mirrorDistribution ? ["-Xswiftc", "-track-system-dependencies"] : [],
38879
+ // the link strips debug info, so none is generated (as for the framework).
38880
+ // keep -num-threads fixed across caller core caps so llbuild does not
38881
+ // rebuild every target when callers alternate --cores, and bound backend
38882
+ // fan-out under high -j.
38883
+ "-Xswiftc",
38884
+ "-gnone",
38885
+ ...incrementalPreview ? [] : [
38886
+ "-Xswiftc",
38887
+ "-num-threads",
38888
+ "-Xswiftc",
38889
+ String(perFile ? 1 : Math.min(8, import_node_os12.default.availableParallelism()))
38890
+ ],
38891
+ ...swiftReproducibleBuildFlags([
38892
+ [import_node_path53.default.dirname(options2.toolchainBin), "toolchain"],
38893
+ [compileFrameworkRoot, "framework"],
38894
+ [root2, "build"],
38895
+ ...forwarders
38896
+ ]).flatMap((flag, index, flags) => {
38897
+ if (!nativeToolset || !flag.startsWith("-ffile-prefix-map="))
38898
+ return [flag];
38899
+ const toolchainDir = import_node_path53.default.dirname(options2.toolchainBin);
38900
+ let mapped = flag;
38901
+ for (const [dir, target] of [
38902
+ [root2, "/peach/build"],
38903
+ [compileFrameworkRoot, "/peach/framework"],
38904
+ [(0, import_node_fs53.realpathSync)(compileFrameworkRoot), "/peach/framework"],
38905
+ [toolchainDir, "/peach/toolchain"],
38906
+ [(0, import_node_fs53.realpathSync)(toolchainDir), "/peach/toolchain"]
38907
+ ]) {
38908
+ mapped = mapped.replaceAll(dir, target);
38909
+ }
38910
+ const [, from, to] = /^-ffile-prefix-map=([^=]+)=(.+)$/.exec(mapped) ?? [];
38911
+ const tool = flags[index - 1];
38912
+ return mapped !== flag && from !== to ? [flag, tool, mapped] : [flag];
38913
+ }),
38914
+ ...macroPlugins.libraries.flatMap((plugin) => [
38915
+ "-Xswiftc",
38916
+ "-load-plugin-library",
38917
+ "-Xswiftc",
38918
+ plugin
38919
+ ]),
38920
+ ...macroPlugins.executables.flatMap((plugin) => [
38921
+ "-Xswiftc",
38922
+ "-load-plugin-executable",
38923
+ "-Xswiftc",
38924
+ `${plugin}#ExpoModulesMacros`
38925
+ ])
38926
+ ];
38927
+ const linked = builtArtifact(layout3);
38928
+ (0, import_node_fs53.rmSync)(import_node_path53.default.join(root2, ".peach-link.rsp"), { force: true });
38929
+ if (options2.linkOnly || (0, import_node_fs53.existsSync)(linked) && (0, import_node_fs53.statSync)(linked).size <= 8)
38930
+ (0, import_node_fs53.rmSync)(linked, { force: true });
38931
+ stage("compiling and linking Swift modules");
38932
+ const frameworkInterfaces = /* @__PURE__ */ new Map();
38933
+ const sdkFrameworks = import_node_path53.default.join(
38934
+ swiftSdkPaths(frameworkRoot, options2.toolchainBin).darwin,
38935
+ "System/Library/Frameworks"
38936
+ );
38937
+ const generatedInterface = (source) => withoutImportedSdkEnumForwards(
38938
+ clangInterfaceHeader((0, import_node_fs53.readFileSync)(source, "utf8"), frameworkRoot),
38939
+ sdkObjCDeclarationOwners(sdkFrameworks)
38940
+ );
38941
+ const nativeDeclarations = /* @__PURE__ */ new Map();
38942
+ const nativeHeaders = Object.entries(input.files).filter(([name3]) => name3.endsWith(".h") && !name3.endsWith("-Swift.h")).map(([, source]) => source);
38943
+ for (const [file, contents2] of Object.entries(input.files)) {
38944
+ if (!file.endsWith(".modulemap")) continue;
38945
+ const name3 = moduleMapName(contents2);
38946
+ const umbrella = /\bumbrella\s+header\s+"([^"]+)"/.exec(contents2)?.[1];
38947
+ if (!name3 || !umbrella) continue;
38948
+ const header = input.files[import_node_path53.default.posix.join(import_node_path53.default.posix.dirname(file), umbrella)];
38949
+ if (header === void 0) continue;
38950
+ const included = new Set(
38951
+ [
38952
+ ...header.matchAll(/^\s*#\s*(?:import|include)\s*[<"]([^">]+)[">]/gm)
38953
+ ].map((match) => import_node_path53.default.posix.basename(match[1]))
38650
38954
  );
38651
- const compiler = preparation.targetToolset ? { CC: import_node_path53.default.join(root, CLANG_TARGET_MODULE_WRAPPER) } : {};
38652
- if (packageHostMacros?.length) {
38653
- const swiftc = import_node_path53.default.join(root, SWIFT_HOST_COMPILER_WRAPPER);
38654
- writeBuildFile(
38655
- swiftc,
38656
- [
38657
- "#!/bin/sh",
38658
- "target=",
38659
- "module=",
38660
- "compile=",
38661
- "previous=",
38662
- "for argument do",
38663
- ' case "$previous" in -target) target=$argument ;; -module-name) module=$argument ;; esac',
38664
- ' case "$argument" in -c|-emit-module|-scan-dependencies|-typecheck) compile=1 ;; esac',
38665
- " previous=$argument",
38666
- "done",
38667
- 'case "$target/$compile" in',
38668
- " *-*-linux*/1)",
38669
- ' case ",$PEACH_SWIFT_HOST_MACROS," in',
38670
- ' *",$module,"*) set -- "$@" -Xfrontend -import-module -Xfrontend Foundation ;;',
38671
- " esac ;;",
38672
- "esac",
38673
- 'exec "$PEACH_SWIFTC" "$@"',
38674
- ""
38675
- ].join("\n")
38676
- );
38677
- (0, import_node_fs53.chmodSync)(swiftc, 493);
38678
- compiler.SWIFT_EXEC = swiftc;
38679
- compiler.PEACH_SWIFT_HOST_MACROS = packageHostMacros.join(",");
38680
- compiler.PEACH_SWIFTC = import_node_path53.default.join(options2.toolchainBin, "swiftc");
38955
+ const declarations = nativeDeclarations.get(name3) ?? /* @__PURE__ */ new Set();
38956
+ for (const declaration of swiftInterfaceDeclarations(header))
38957
+ declarations.add(declaration);
38958
+ for (const [candidate, source] of Object.entries(input.files))
38959
+ if (included.has(import_node_path53.default.posix.basename(candidate)))
38960
+ for (const declaration of swiftInterfaceDeclarations(source))
38961
+ declarations.add(declaration);
38962
+ nativeDeclarations.set(name3, declarations);
38963
+ }
38964
+ const frameworkInterface = (name3) => {
38965
+ if (frameworkInterfaces.has(name3)) return frameworkInterfaces.get(name3);
38966
+ const source = distribution ? import_node_path53.default.join(frameworkRoot, "modules", `${name3}-Swift.h`) : prebuilt.objcHeaders.get(name3);
38967
+ if (!source || !(0, import_node_fs53.existsSync)(source)) {
38968
+ frameworkInterfaces.set(name3, null);
38969
+ return null;
38681
38970
  }
38682
- const projectProcess = options2.project ? prepareSwiftProjectProcess(root, options2.project) : void 0;
38683
- const temporaryDirectory = projectProcess ? void 0 : import_node_path53.default.join(root, ".build", "peach-compiler-tmp");
38684
- const appOptions = projectProcess ? {
38685
- ...buildOptions,
38686
- uid: projectProcess.uid,
38687
- gid: projectProcess.gid,
38688
- confined: { ...projectProcess.env, ...compiler }
38689
- } : {
38690
- ...buildOptions,
38691
- temporaryDirectory,
38692
- env: {
38693
- ...buildOptions.env,
38694
- ...preparation.usesObjcPrebuilt && process.env.PEACH_HOME !== void 0 ? { PEACH_HOME: process.env.PEACH_HOME } : {},
38695
- ...compiler
38696
- }
38697
- };
38698
- const unprepared = preparation.targetFailures.map(
38699
- (failure2) => `error: target ${failure2}`
38971
+ const headers = import_node_path53.default.join(sdkFrameworks, `${name3}.framework/Headers`);
38972
+ const declared = /* @__PURE__ */ new Set();
38973
+ if ((0, import_node_fs53.existsSync)(headers)) {
38974
+ for (const file of (0, import_node_fs53.readdirSync)(headers, {
38975
+ recursive: true,
38976
+ encoding: "utf8"
38977
+ }))
38978
+ if (file.endsWith(".h"))
38979
+ for (const name4 of swiftInterfaceDeclarations(
38980
+ (0, import_node_fs53.readFileSync)(import_node_path53.default.join(headers, file), "utf8")
38981
+ ))
38982
+ declared.add(name4);
38983
+ }
38984
+ for (const declaration of nativeDeclarations.get(name3) ?? [])
38985
+ declared.add(declaration);
38986
+ const own2 = withoutSwiftDeclarations(
38987
+ generatedInterface(source),
38988
+ declared,
38989
+ nativeDeclarations.has(name3) ? `@import ${name3};` : `#import <${name3}/${name3}.h>`
38700
38990
  );
38701
- const forwarders = /* @__PURE__ */ new Map();
38702
- for (const [file, text7] of Object.entries(input.files)) {
38703
- const parents = /^#include "((?:\.\.\/)+)[^"\n]+"\n$/.exec(text7)?.[1];
38704
- if (!parents) continue;
38705
- const directory2 = import_node_path53.default.posix.dirname(file);
38706
- forwarders.set(
38707
- `${import_node_path53.default.join(root, directory2)}/${parents.slice(0, -1)}`,
38708
- import_node_path53.default.posix.join("build", directory2, parents).replace(/\/$/, "")
38709
- );
38991
+ const owners = sdkObjCDeclarationOwners(sdkFrameworks);
38992
+ const foreign = /* @__PURE__ */ new Map();
38993
+ for (const declaration of [
38994
+ ...swiftInterfaceDeclarations(own2),
38995
+ ...objcEnumerations(own2),
38996
+ ...[...own2.matchAll(/^\s*SWIFT_EXTERN\b[^(\n]*?\b(\w+)\s*\(/gm)].map(
38997
+ (match) => match[1]
38998
+ )
38999
+ ]) {
39000
+ const owner = owners.get(declaration);
39001
+ if (owner && owner !== name3) foreign.set(declaration, owner);
38710
39002
  }
38711
- const jobs = swiftCompilerJobs();
38712
- const incrementalPreview = sdkImage !== void 0 && !guestGraph && !options2.project && !input.optimize && !input.unoptimized;
38713
- const perFile = input.unoptimized || incrementalPreview;
38714
- const buildArgs = [
38715
- "build",
38716
- ...projectProcess?.cacheOptions ?? swiftPackageCacheOptions(),
38717
- "--build-system",
38718
- "native",
38719
- "-j",
38720
- String(jobs),
38721
- "--package-path",
38722
- root,
38723
- ...swiftCompileSdkOptions(frameworkRoot, options2.toolchainBin),
38724
- ...swiftObjCSelectorOptions(frameworkRoot),
38725
- "--swift-sdk",
38726
- sdk2,
38727
- ...preparation.targetToolset ? ["--toolset", import_node_path53.default.join(root, ".peach-target-toolset.json")] : [],
38728
- "-c",
38729
- "release",
38730
- ...input.unoptimized ? ["-Xswiftc", "-Onone"] : [],
38731
- ...perFile ? [
38732
- "-Xswiftc",
38733
- "-no-whole-module-optimization",
38734
- "-Xswiftc",
38735
- "-j",
38736
- "-Xswiftc",
38737
- String(jobs)
38738
- ] : [],
38739
- ...incrementalPreview ? ["-Xswiftc", "-incremental", "-Xswiftc", "-enable-batch-mode"] : [],
38740
- // the mirror finds a changed sdk header's readers in their
38741
- // dependency files, which omit system headers by default
38742
- ...mirrorDistribution ? ["-Xswiftc", "-track-system-dependencies"] : [],
38743
- // the link strips debug info, so none is generated (as for the framework).
38744
- // keep -num-threads fixed across caller core caps so llbuild does not
38745
- // rebuild every target when callers alternate --cores, and bound backend
38746
- // fan-out under high -j.
38747
- "-Xswiftc",
38748
- "-gnone",
38749
- ...incrementalPreview ? [] : [
38750
- "-Xswiftc",
38751
- "-num-threads",
38752
- "-Xswiftc",
38753
- String(perFile ? 1 : Math.min(8, import_node_os12.default.availableParallelism()))
38754
- ],
38755
- ...swiftReproducibleBuildFlags([
38756
- [import_node_path53.default.dirname(options2.toolchainBin), "toolchain"],
38757
- [compileFrameworkRoot, "framework"],
38758
- [root, "build"],
38759
- ...forwarders
38760
- ]).flatMap((flag, index, flags) => {
38761
- if (!nativeToolset || !flag.startsWith("-ffile-prefix-map="))
38762
- return [flag];
38763
- const toolchainDir = import_node_path53.default.dirname(options2.toolchainBin);
38764
- let mapped = flag;
38765
- for (const [dir, target] of [
38766
- [root, "/peach/build"],
38767
- [compileFrameworkRoot, "/peach/framework"],
38768
- [(0, import_node_fs53.realpathSync)(compileFrameworkRoot), "/peach/framework"],
38769
- [toolchainDir, "/peach/toolchain"],
38770
- [(0, import_node_fs53.realpathSync)(toolchainDir), "/peach/toolchain"]
38771
- ]) {
38772
- mapped = mapped.replaceAll(dir, target);
38773
- }
38774
- const [, from, to] = /^-ffile-prefix-map=([^=]+)=(.+)$/.exec(mapped) ?? [];
38775
- const tool = flags[index - 1];
38776
- return mapped !== flag && from !== to ? [flag, tool, mapped] : [flag];
38777
- }),
38778
- ...macroPlugins.libraries.flatMap((plugin) => [
38779
- "-Xswiftc",
38780
- "-load-plugin-library",
38781
- "-Xswiftc",
38782
- plugin
38783
- ]),
38784
- ...macroPlugins.executables.flatMap((plugin) => [
38785
- "-Xswiftc",
38786
- "-load-plugin-executable",
38787
- "-Xswiftc",
38788
- `${plugin}#ExpoModulesMacros`
38789
- ])
38790
- ];
38791
- const linked = builtArtifact(layout2);
38792
- (0, import_node_fs53.rmSync)(import_node_path53.default.join(root, ".peach-link.rsp"), { force: true });
38793
- if (options2.linkOnly || (0, import_node_fs53.existsSync)(linked) && (0, import_node_fs53.statSync)(linked).size <= 8)
38794
- (0, import_node_fs53.rmSync)(linked, { force: true });
38795
- report("compiling and linking Swift modules");
38796
- const frameworkInterfaces = /* @__PURE__ */ new Map();
38797
- const sdkFrameworks = import_node_path53.default.join(
38798
- swiftSdkPaths(frameworkRoot, options2.toolchainBin).darwin,
38799
- "System/Library/Frameworks"
39003
+ const header = foreign.size ? withoutSwiftDeclarations(
39004
+ own2,
39005
+ new Set(foreign.keys()),
39006
+ [...new Set(foreign.values())].map((owner) => `#import <${owner}/${owner}.h>`).join("\n")
39007
+ ) : own2;
39008
+ const value = {
39009
+ file: import_node_path53.default.join(root2, ".build/peach-framework-objc", `${name3}-Swift.h`),
39010
+ header,
39011
+ module: (0, import_node_fs53.existsSync)(headers)
39012
+ };
39013
+ frameworkInterfaces.set(name3, value);
39014
+ writeBuildFile(
39015
+ value.file,
39016
+ ((0, import_node_fs53.existsSync)(import_node_path53.default.join(headers, `${name3}.h`)) ? `#import <${name3}/${name3}.h>
39017
+ ` : "") + swiftHeaderWithSuperclassImports(header, frameworkInterface)
38800
39018
  );
38801
- const generatedInterface = (source) => withoutImportedSdkEnumForwards(
38802
- clangInterfaceHeader((0, import_node_fs53.readFileSync)(source, "utf8"), frameworkRoot),
38803
- sdkObjCDeclarationOwners(sdkFrameworks)
39019
+ return value;
39020
+ };
39021
+ const headerPaths = (producer) => {
39022
+ const stem2 = import_node_path53.default.join(
39023
+ root2,
39024
+ ".build",
39025
+ "peach-cxx-headers",
39026
+ `${producer}-Swift`
38804
39027
  );
38805
- const nativeDeclarations = /* @__PURE__ */ new Map();
38806
- const nativeHeaders = Object.entries(input.files).filter(([name3]) => name3.endsWith(".h") && !name3.endsWith("-Swift.h")).map(([, source]) => source);
38807
- for (const [file, contents2] of Object.entries(input.files)) {
38808
- if (!file.endsWith(".modulemap")) continue;
38809
- const name3 = moduleMapName(contents2);
38810
- const umbrella = /\bumbrella\s+header\s+"([^"]+)"/.exec(contents2)?.[1];
38811
- if (!name3 || !umbrella) continue;
38812
- const header = input.files[import_node_path53.default.posix.join(import_node_path53.default.posix.dirname(file), umbrella)];
38813
- if (header === void 0) continue;
38814
- const included = new Set(
38815
- [
38816
- ...header.matchAll(/^\s*#\s*(?:import|include)\s*[<"]([^">]+)[">]/gm)
38817
- ].map((match) => import_node_path53.default.posix.basename(match[1]))
38818
- );
38819
- const declarations = nativeDeclarations.get(name3) ?? /* @__PURE__ */ new Set();
38820
- for (const declaration of swiftInterfaceDeclarations(header))
38821
- declarations.add(declaration);
38822
- for (const [candidate, source] of Object.entries(input.files))
38823
- if (included.has(import_node_path53.default.posix.basename(candidate)))
38824
- for (const declaration of swiftInterfaceDeclarations(source))
38825
- declarations.add(declaration);
38826
- nativeDeclarations.set(name3, declarations);
38827
- }
38828
- const frameworkInterface = (name3) => {
38829
- if (frameworkInterfaces.has(name3)) return frameworkInterfaces.get(name3);
38830
- const source = distribution ? import_node_path53.default.join(frameworkRoot, "modules", `${name3}-Swift.h`) : prebuilt.objcHeaders.get(name3);
38831
- if (!source || !(0, import_node_fs53.existsSync)(source)) {
38832
- frameworkInterfaces.set(name3, null);
38833
- return null;
38834
- }
38835
- const headers = import_node_path53.default.join(sdkFrameworks, `${name3}.framework/Headers`);
38836
- const declared = /* @__PURE__ */ new Set();
38837
- if ((0, import_node_fs53.existsSync)(headers)) {
38838
- for (const file of (0, import_node_fs53.readdirSync)(headers, {
38839
- recursive: true,
38840
- encoding: "utf8"
38841
- }))
38842
- if (file.endsWith(".h"))
38843
- for (const name4 of swiftInterfaceDeclarations(
38844
- (0, import_node_fs53.readFileSync)(import_node_path53.default.join(headers, file), "utf8")
38845
- ))
38846
- declared.add(name4);
38847
- }
38848
- for (const declaration of nativeDeclarations.get(name3) ?? [])
38849
- declared.add(declaration);
38850
- const own2 = withoutSwiftDeclarations(
38851
- generatedInterface(source),
38852
- declared,
38853
- nativeDeclarations.has(name3) ? `@import ${name3};` : `#import <${name3}/${name3}.h>`
38854
- );
38855
- const owners = sdkObjCDeclarationOwners(sdkFrameworks);
38856
- const foreign = /* @__PURE__ */ new Map();
38857
- for (const declaration of [
38858
- ...swiftInterfaceDeclarations(own2),
38859
- ...objcEnumerations(own2),
38860
- ...[...own2.matchAll(/^\s*SWIFT_EXTERN\b[^(\n]*?\b(\w+)\s*\(/gm)].map(
38861
- (match) => match[1]
38862
- )
38863
- ]) {
38864
- const owner = owners.get(declaration);
38865
- if (owner && owner !== name3) foreign.set(declaration, owner);
39028
+ return { producer, original: `${stem2}.original.h`, emitted: `${stem2}.h` };
39029
+ };
39030
+ const publishHeader = ({
39031
+ producer,
39032
+ original,
39033
+ emitted
39034
+ }) => {
39035
+ const generated = generatedInterface(original);
39036
+ writeBuildFile(
39037
+ emitted,
39038
+ withoutSwiftDeclarations(
39039
+ swiftHeaderWithSuperclassImports(generated, frameworkInterface),
39040
+ /* @__PURE__ */ new Set([
39041
+ ...preparation.nativeHeaderDeclarations[producer] ?? [],
39042
+ ...nativelyDeclaredFunctions(generated, nativeHeaders)
39043
+ ]),
39044
+ `#import <${producer}/${producer}.h>`
39045
+ )
39046
+ );
39047
+ };
39048
+ const recipe2 = inputHash.copy().update(
39049
+ distribution ? swiftCompileSurfaceDigest(frameworkRoot) : moduleDigest
39050
+ ).update((0, import_node_fs53.readFileSync)(import_node_path53.default.join(root2, "Package.swift"))).update(JSON.stringify(buildArgs)).digest("hex");
39051
+ const runApp = async (compiler2) => {
39052
+ const optionsWithCompiler = compiler2 ? { ...appOptions, env: { ...appOptions.env, ...compiler2 } } : appOptions;
39053
+ const stages = [
39054
+ ...(preparation.nativePrerequisiteTargets ?? []).map((target) => ({
39055
+ target,
39056
+ producers: []
39057
+ })),
39058
+ ...preparation.headerBuilds,
39059
+ ...(preparation.nativeProductTargets ?? []).map((target) => ({
39060
+ target,
39061
+ producers: []
39062
+ }))
39063
+ ];
39064
+ const checkpoints = import_node_path53.default.join(root2, ".build", "peach-product-checkpoints");
39065
+ const buildDbExists = (0, import_node_fs53.existsSync)(import_node_path53.default.join(root2, ".build", "build.db"));
39066
+ const releaseDir = import_node_path53.default.dirname(linked);
39067
+ for (const { target, producers } of stages) {
39068
+ if (!options2.project && producers.length === 0 && buildDbExists) {
39069
+ const expectedObjects = preparation.nativeStageObjects.get(target);
39070
+ if (expectedObjects && expectedObjects.length > 0 && expectedObjects.every(
39071
+ (relative4) => (0, import_node_fs53.statSync)(import_node_path53.default.join(releaseDir, relative4), {
39072
+ throwIfNoEntry: false
39073
+ })?.isFile()
39074
+ ))
39075
+ continue;
38866
39076
  }
38867
- const header = foreign.size ? withoutSwiftDeclarations(
38868
- own2,
38869
- new Set(foreign.keys()),
38870
- [...new Set(foreign.values())].map((owner) => `#import <${owner}/${owner}.h>`).join("\n")
38871
- ) : own2;
38872
- const value = {
38873
- file: import_node_path53.default.join(root, ".build/peach-framework-objc", `${name3}-Swift.h`),
38874
- header,
38875
- module: (0, import_node_fs53.existsSync)(headers)
38876
- };
38877
- frameworkInterfaces.set(name3, value);
38878
- writeBuildFile(
38879
- value.file,
38880
- ((0, import_node_fs53.existsSync)(import_node_path53.default.join(headers, `${name3}.h`)) ? `#import <${name3}/${name3}.h>
38881
- ` : "") + swiftHeaderWithSuperclassImports(header, frameworkInterface)
39077
+ const receipt = import_node_path53.default.join(
39078
+ checkpoints,
39079
+ (0, import_node_crypto32.createHash)("sha256").update(target).digest("hex")
38882
39080
  );
38883
- return value;
38884
- };
38885
- const headerPaths = (producer) => {
38886
- const stem2 = import_node_path53.default.join(
38887
- root,
38888
- ".build",
38889
- "peach-cxx-headers",
38890
- `${producer}-Swift`
38891
- );
38892
- return { producer, original: `${stem2}.original.h`, emitted: `${stem2}.h` };
38893
- };
38894
- const publishHeader = ({
38895
- producer,
38896
- original,
38897
- emitted
38898
- }) => {
38899
- const generated = generatedInterface(original);
38900
- writeBuildFile(
38901
- emitted,
38902
- withoutSwiftDeclarations(
38903
- swiftHeaderWithSuperclassImports(generated, frameworkInterface),
38904
- /* @__PURE__ */ new Set([
38905
- ...preparation.nativeHeaderDeclarations[producer] ?? [],
38906
- ...nativelyDeclaredFunctions(generated, nativeHeaders)
38907
- ]),
38908
- `#import <${producer}/${producer}.h>`
38909
- )
38910
- );
38911
- };
38912
- const recipe2 = inputHash.copy().update(
38913
- distribution ? swiftCompileSurfaceDigest(frameworkRoot) : moduleDigest
38914
- ).update((0, import_node_fs53.readFileSync)(import_node_path53.default.join(root, "Package.swift"))).update(JSON.stringify(buildArgs)).digest("hex");
38915
- const runApp = async (compiler2) => {
38916
- const optionsWithCompiler = compiler2 ? { ...appOptions, env: { ...appOptions.env, ...compiler2 } } : appOptions;
38917
- const stages = [
38918
- ...(preparation.nativePrerequisiteTargets ?? []).map((target) => ({
38919
- target,
38920
- producers: []
38921
- })),
38922
- ...preparation.headerBuilds,
38923
- ...(preparation.nativeProductTargets ?? []).map((target) => ({
38924
- target,
38925
- producers: []
38926
- }))
38927
- ];
38928
- const checkpoints = import_node_path53.default.join(root, ".build", "peach-product-checkpoints");
38929
- const buildDbExists = (0, import_node_fs53.existsSync)(import_node_path53.default.join(root, ".build", "build.db"));
38930
- const releaseDir = import_node_path53.default.dirname(linked);
38931
- for (const { target, producers } of stages) {
38932
- if (!options2.project && producers.length === 0 && buildDbExists) {
38933
- const expectedObjects = preparation.nativeStageObjects.get(target);
38934
- if (expectedObjects && expectedObjects.length > 0 && expectedObjects.every(
38935
- (relative4) => (0, import_node_fs53.statSync)(import_node_path53.default.join(releaseDir, relative4), {
38936
- throwIfNoEntry: false
38937
- })?.isFile()
38938
- ))
38939
- continue;
38940
- }
38941
- const receipt = import_node_path53.default.join(
38942
- checkpoints,
38943
- (0, import_node_crypto32.createHash)("sha256").update(target).digest("hex")
38944
- );
38945
- const headers = producers.map(headerPaths);
38946
- for (const header of headers)
38947
- if ((0, import_node_fs53.existsSync)(header.original)) publishHeader(header);
38948
- const fingerprint = () => {
38949
- const digest3 = (0, import_node_crypto32.createHash)("sha256").update(recipe2);
38950
- for (const { original, emitted } of headers) {
38951
- if (!(0, import_node_fs53.existsSync)(original) || !(0, import_node_fs53.existsSync)(emitted)) return;
38952
- digest3.update(
38953
- (0, import_node_crypto32.createHash)("sha256").update((0, import_node_fs53.readFileSync)(emitted)).digest()
38954
- );
38955
- }
38956
- return digest3.digest("hex");
38957
- };
38958
- if (!options2.project && (0, import_node_fs53.existsSync)(receipt) && (0, import_node_fs53.readFileSync)(receipt, "utf8") === fingerprint())
38959
- continue;
38960
- if (!options2.project) (0, import_node_fs53.rmSync)(receipt, { force: true });
38961
- for (const header of headers) {
38962
- if (!(0, import_node_fs53.existsSync)(header.original))
38963
- (0, import_node_fs53.rmSync)(
38964
- import_node_path53.default.join(
38965
- import_node_path53.default.dirname(linked),
38966
- "Modules",
38967
- `${swiftTargetModuleName(header.producer)}.swiftmodule`
38968
- ),
38969
- { force: true }
38970
- );
38971
- }
38972
- await runCompiler(
38973
- swift,
38974
- [...buildArgs, "--target", target],
38975
- optionsWithCompiler,
38976
- /^(?:\[swift-prebuilt\]|\[\d+\/\d+\] )/,
38977
- SWIFTPM_NOISE
38978
- );
38979
- if (!compiler2) for (const header of headers) publishHeader(header);
38980
- if (!options2.project) {
38981
- const checkpoint = fingerprint();
38982
- if (checkpoint === void 0)
38983
- throw new Error(`missing Swift headers after building ${target}`);
38984
- (0, import_node_fs53.mkdirSync)(checkpoints, { recursive: true });
38985
- (0, import_node_fs53.writeFileSync)(`${receipt}.partial`, checkpoint);
38986
- (0, import_node_fs53.renameSync)(`${receipt}.partial`, receipt);
39081
+ const headers = producers.map(headerPaths);
39082
+ for (const header of headers)
39083
+ if ((0, import_node_fs53.existsSync)(header.original)) publishHeader(header);
39084
+ const fingerprint = () => {
39085
+ const digest3 = (0, import_node_crypto32.createHash)("sha256").update(recipe2);
39086
+ for (const { original, emitted } of headers) {
39087
+ if (!(0, import_node_fs53.existsSync)(original) || !(0, import_node_fs53.existsSync)(emitted)) return;
39088
+ digest3.update(
39089
+ (0, import_node_crypto32.createHash)("sha256").update((0, import_node_fs53.readFileSync)(emitted)).digest()
39090
+ );
38987
39091
  }
39092
+ return digest3.digest("hex");
39093
+ };
39094
+ if (!options2.project && (0, import_node_fs53.existsSync)(receipt) && (0, import_node_fs53.readFileSync)(receipt, "utf8") === fingerprint())
39095
+ continue;
39096
+ if (!options2.project) (0, import_node_fs53.rmSync)(receipt, { force: true });
39097
+ for (const header of headers) {
39098
+ if (!(0, import_node_fs53.existsSync)(header.original))
39099
+ (0, import_node_fs53.rmSync)(
39100
+ import_node_path53.default.join(
39101
+ import_node_path53.default.dirname(linked),
39102
+ "Modules",
39103
+ `${swiftTargetModuleName(header.producer)}.swiftmodule`
39104
+ ),
39105
+ { force: true }
39106
+ );
38988
39107
  }
38989
39108
  await runCompiler(
38990
39109
  swift,
38991
- buildArgs,
39110
+ [...buildArgs, "--target", target],
38992
39111
  optionsWithCompiler,
38993
- SWIFTPM_PROGRESS,
39112
+ /^(?:\[swift-prebuilt\]|\[\d+\/\d+\] )/,
38994
39113
  SWIFTPM_NOISE
38995
39114
  );
38996
- };
38997
- const compileApp = () => preparation.headerCompiler ? withSwiftHeaderCompiler(
38998
- root,
38999
- options2.toolchainBin,
39000
- recipe2,
39001
- new Map(
39002
- preparation.headerBuilds[0].producers.map((producer) => {
39003
- const paths = headerPaths(producer);
39004
- return [
39005
- swiftTargetModuleName(producer),
39006
- {
39007
- header: paths.original,
39008
- publish: () => publishHeader(paths)
39009
- }
39010
- ];
39011
- })
39012
- ),
39013
- runApp
39014
- ) : runApp();
39015
- try {
39016
- if (temporaryDirectory) (0, import_node_fs53.mkdirSync)(temporaryDirectory, { recursive: true });
39017
- await compileApp();
39018
- } catch (error) {
39019
- const output2 = outputOf(error);
39020
- const moduleCache = import_node_path53.default.join(
39021
- root,
39022
- ".build",
39023
- WASM_TRIPLE,
39024
- "release",
39025
- "ModuleCache"
39026
- );
39027
- if (output2.includes("was compiled with module cache path") && (0, import_node_fs53.existsSync)(moduleCache)) {
39028
- (0, import_node_fs53.rmSync)(moduleCache, { recursive: true, force: true });
39029
- try {
39030
- await compileApp();
39031
- } catch (retryError) {
39032
- throw new Error(
39033
- [
39034
- ...unprepared,
39035
- projectDiagnostic(outputOf(retryError), layout2, input.files)
39036
- ].join("\n"),
39037
- { cause: retryError }
39038
- );
39039
- }
39040
- } else {
39115
+ if (!compiler2) for (const header of headers) publishHeader(header);
39116
+ if (!options2.project) {
39117
+ const checkpoint = fingerprint();
39118
+ if (checkpoint === void 0)
39119
+ throw new Error(`missing Swift headers after building ${target}`);
39120
+ (0, import_node_fs53.mkdirSync)(checkpoints, { recursive: true });
39121
+ (0, import_node_fs53.writeFileSync)(`${receipt}.partial`, checkpoint);
39122
+ (0, import_node_fs53.renameSync)(`${receipt}.partial`, receipt);
39123
+ }
39124
+ }
39125
+ await runCompiler(
39126
+ swift,
39127
+ buildArgs,
39128
+ optionsWithCompiler,
39129
+ SWIFTPM_PROGRESS,
39130
+ SWIFTPM_NOISE
39131
+ );
39132
+ };
39133
+ const compileApp = () => preparation.headerCompiler ? withSwiftHeaderCompiler(
39134
+ root2,
39135
+ options2.toolchainBin,
39136
+ recipe2,
39137
+ new Map(
39138
+ preparation.headerBuilds[0].producers.map((producer) => {
39139
+ const paths = headerPaths(producer);
39140
+ return [
39141
+ swiftTargetModuleName(producer),
39142
+ {
39143
+ header: paths.original,
39144
+ publish: () => publishHeader(paths)
39145
+ }
39146
+ ];
39147
+ })
39148
+ ),
39149
+ runApp
39150
+ ) : runApp();
39151
+ try {
39152
+ if (temporaryDirectory) (0, import_node_fs53.mkdirSync)(temporaryDirectory, { recursive: true });
39153
+ await compileApp();
39154
+ } catch (error) {
39155
+ const output2 = outputOf(error);
39156
+ const moduleCache = import_node_path53.default.join(
39157
+ root2,
39158
+ ".build",
39159
+ WASM_TRIPLE,
39160
+ "release",
39161
+ "ModuleCache"
39162
+ );
39163
+ if (output2.includes("was compiled with module cache path") && (0, import_node_fs53.existsSync)(moduleCache)) {
39164
+ (0, import_node_fs53.rmSync)(moduleCache, { recursive: true, force: true });
39165
+ try {
39166
+ await compileApp();
39167
+ } catch (retryError) {
39041
39168
  throw new Error(
39042
- [...unprepared, projectDiagnostic(output2, layout2, input.files)].join(
39043
- "\n"
39044
- ),
39045
- { cause: error }
39169
+ [
39170
+ ...unprepared,
39171
+ projectDiagnostic(outputOf(retryError), layout3, input.files)
39172
+ ].join("\n"),
39173
+ { cause: retryError }
39046
39174
  );
39047
39175
  }
39048
- } finally {
39049
- if (temporaryDirectory)
39050
- (0, import_node_fs53.rmSync)(temporaryDirectory, { recursive: true, force: true });
39051
- if (options2.project) endSwiftProjectProcesses(options2.project);
39052
- }
39053
- if (unprepared.length) throw new Error(unprepared.join("\n"));
39054
- if (!(0, import_node_fs53.existsSync)(linked)) {
39055
- const binDir = import_node_path53.default.dirname(linked);
39056
- const found = (0, import_node_fs53.existsSync)(binDir) ? (0, import_node_fs53.readdirSync)(binDir).filter((name3) => name3.endsWith(".wasm")).sort() : [];
39176
+ } else {
39057
39177
  throw new Error(
39058
- `swift-compile: the build produced no ${import_node_path53.default.basename(linked)} (found: ${found.join(", ") || "none"})`
39178
+ [...unprepared, projectDiagnostic(output2, layout3, input.files)].join(
39179
+ "\n"
39180
+ ),
39181
+ { cause: error }
39059
39182
  );
39060
39183
  }
39061
- if (options2.project) removeProjectLinks(root);
39062
- const resourceReferences = Object.values(input.resources ?? {}).map(
39063
- (value) => Buffer.from(value, "base64")
39184
+ } finally {
39185
+ if (temporaryDirectory)
39186
+ (0, import_node_fs53.rmSync)(temporaryDirectory, { recursive: true, force: true });
39187
+ if (options2.project) endSwiftProjectProcesses(options2.project);
39188
+ }
39189
+ if (unprepared.length) throw new Error(unprepared.join("\n"));
39190
+ if (!(0, import_node_fs53.existsSync)(linked)) {
39191
+ const binDir = import_node_path53.default.dirname(linked);
39192
+ const found = (0, import_node_fs53.existsSync)(binDir) ? (0, import_node_fs53.readdirSync)(binDir).filter((name3) => name3.endsWith(".wasm")).sort() : [];
39193
+ throw new Error(
39194
+ `swift-compile: the build produced no ${import_node_path53.default.basename(linked)} (found: ${found.join(", ") || "none"})`
39064
39195
  );
39065
- if (!guestGraph)
39066
- pruneSwiftWasmLink(
39067
- root,
39068
- options2.toolchainBin,
39069
- prebuilt?.root ?? frameworkRoot,
39070
- input.staticClangTargets,
39071
- options2.project,
39072
- void 0,
39073
- resourceReferences
39074
- );
39075
- if (options2.linkOnly) {
39076
- if ((0, import_node_fs53.statSync)(linked).size <= 8)
39077
- throw new Error("swift-compile: deferred linker produced no executable");
39078
- report("project link verified");
39079
- return;
39080
- }
39081
- const output = options2.project ? projectOutputFile(root, linked, options2.project) : linked;
39082
- const optimized = `${output}.optimized`;
39083
- if (sdkImage && options2.project) (0, import_node_fs53.rmSync)(optimized, { force: true });
39084
- let sdkAsset;
39085
- if (guestGraph) {
39086
- const binding = await compileGuestLink({
39087
- graph: guestGraph,
39088
- buildDirectory: root,
39089
- releaseDirectory: import_node_path53.default.dirname(linked),
39090
- moduleRoot: frameworkRoot,
39091
- toolchainBin: options2.toolchainBin,
39092
- swiftCompiler: preparation.headerCompiler ? import_node_path53.default.join(root, SWIFT_HEADER_COMPILER_WRAPPER) : compiler.SWIFT_EXEC ?? import_node_path53.default.join(options2.toolchainBin, "swiftc"),
39093
- sysroot: swiftSdkPaths(frameworkRoot, options2.toolchainBin).sysroot,
39094
- sdk: swiftModuleSdk(frameworkRoot),
39095
- sdkImage,
39096
- compilerDigest: compilerSourceDigest,
39097
- project: options2.project && {
39098
- ...options2.project,
39099
- env: { ...options2.project.env, ...projectProcess?.env }
39100
- },
39101
- staticClangTargets: input.staticClangTargets ?? [],
39102
- resourceReferences,
39103
- resourceBundles: input.resourceBundles ?? [],
39104
- generatedOwners: preparation.generatedOwners,
39105
- output,
39106
- optimized,
39107
- optimize: input.optimize === true,
39108
- jobs: swiftBuildJobs()
39109
- });
39110
- if (sdkImage && binding)
39111
- sdkAsset = { key: sdkImage.key, sha256: sdkImage.sha256, binding };
39112
- } else if (sdkImage) {
39113
- const { buildSwiftAppModule: buildSwiftAppModule2 } = await Promise.resolve().then(() => (init_swift_sdk_app_module(), swift_sdk_app_module_exports));
39114
- const binding = await buildSwiftAppModule2({
39115
- buildRoot: root,
39116
- toolchainBin: options2.toolchainBin,
39117
- sdk: sdkImage,
39118
- output: optimized,
39119
- optimize: input.optimize === true,
39120
- project: options2.project && {
39121
- ...options2.project,
39122
- env: { ...options2.project.env, ...projectProcess?.env },
39123
- sdkRoot: import_node_path53.default.dirname(
39124
- swiftSdkPaths(frameworkRoot, options2.toolchainBin).sysroot
39125
- ),
39126
- linked: output
39127
- }
39128
- });
39129
- sdkAsset = { key: sdkImage.key, sha256: sdkImage.sha256, binding };
39130
- } else {
39131
- const bytes = (0, import_node_fs53.readFileSync)(output);
39132
- const ordered = orderObjCConstructors(bytes);
39133
- if (ordered !== bytes) (0, import_node_fs53.writeFileSync)(output, ordered);
39134
- await lowerWasm(output, optimized, { optimize: input.optimize === true });
39135
- }
39136
- if (!sdkImage)
39137
- await runCompiler(
39138
- import_node_path53.default.join(options2.toolchainBin, "llvm-objcopy"),
39139
- ["--remove-section=.swift1_autolink_entries", optimized],
39140
- buildOptions
39141
- );
39142
- const artifact = {
39143
- hash,
39144
- bytes: (0, import_node_fs53.readFileSync)(optimized),
39145
- icu: await icu,
39146
- sdk: sdkAsset
39147
- };
39148
- if (artifact.bytes.length <= 8)
39196
+ }
39197
+ if (options2.project) removeProjectLinks(root2);
39198
+ const resourceReferences = Object.values(input.resources ?? {}).map(
39199
+ (value) => Buffer.from(value, "base64")
39200
+ );
39201
+ if (!guestGraph)
39202
+ pruneSwiftWasmLink(
39203
+ root2,
39204
+ options2.toolchainBin,
39205
+ prebuilt?.root ?? frameworkRoot,
39206
+ input.staticClangTargets,
39207
+ options2.project,
39208
+ void 0,
39209
+ resourceReferences
39210
+ );
39211
+ if (options2.linkOnly) {
39212
+ if ((0, import_node_fs53.statSync)(linked).size <= 8)
39149
39213
  throw new Error("swift-compile: deferred linker produced no executable");
39150
- if (!options2.project) saveCompiledArtifact(root, artifact);
39151
- saveSharedArtifact(sharedRoot, artifact);
39152
- report("compiled artifact verified");
39153
- return retain(root, artifact);
39154
- } finally {
39155
- readHold?.release();
39214
+ stage("project link verified");
39215
+ return;
39156
39216
  }
39157
- },
39158
- budget.signal
39159
- );
39217
+ const output = options2.project ? projectOutputFile(root2, linked, options2.project) : linked;
39218
+ const optimized = `${output}.optimized`;
39219
+ if (sdkImage && options2.project) (0, import_node_fs53.rmSync)(optimized, { force: true });
39220
+ let sdkAsset;
39221
+ stage("linking the app image");
39222
+ if (guestGraph) {
39223
+ const binding = await compileGuestLink({
39224
+ graph: guestGraph,
39225
+ buildDirectory: root2,
39226
+ releaseDirectory: import_node_path53.default.dirname(linked),
39227
+ moduleRoot: frameworkRoot,
39228
+ toolchainBin: options2.toolchainBin,
39229
+ swiftCompiler: preparation.headerCompiler ? import_node_path53.default.join(root2, SWIFT_HEADER_COMPILER_WRAPPER) : compiler.SWIFT_EXEC ?? import_node_path53.default.join(options2.toolchainBin, "swiftc"),
39230
+ sysroot: swiftSdkPaths(frameworkRoot, options2.toolchainBin).sysroot,
39231
+ sdk: swiftModuleSdk(frameworkRoot),
39232
+ sdkImage,
39233
+ compilerDigest: compilerSourceDigest,
39234
+ project: options2.project && {
39235
+ ...options2.project,
39236
+ env: { ...options2.project.env, ...projectProcess?.env }
39237
+ },
39238
+ staticClangTargets: input.staticClangTargets ?? [],
39239
+ resourceReferences,
39240
+ resourceBundles: input.resourceBundles ?? [],
39241
+ generatedOwners: preparation.generatedOwners,
39242
+ output,
39243
+ optimized,
39244
+ optimize: input.optimize === true,
39245
+ jobs: swiftBuildJobs(),
39246
+ onStage: stage
39247
+ });
39248
+ if (sdkImage && binding)
39249
+ sdkAsset = { key: sdkImage.key, sha256: sdkImage.sha256, binding };
39250
+ } else if (sdkImage) {
39251
+ const { buildSwiftAppModule: buildSwiftAppModule2 } = await Promise.resolve().then(() => (init_swift_sdk_app_module(), swift_sdk_app_module_exports));
39252
+ const binding = await buildSwiftAppModule2({
39253
+ buildRoot: root2,
39254
+ toolchainBin: options2.toolchainBin,
39255
+ sdk: sdkImage,
39256
+ output: optimized,
39257
+ optimize: input.optimize === true,
39258
+ project: options2.project && {
39259
+ ...options2.project,
39260
+ env: { ...options2.project.env, ...projectProcess?.env },
39261
+ sdkRoot: import_node_path53.default.dirname(
39262
+ swiftSdkPaths(frameworkRoot, options2.toolchainBin).sysroot
39263
+ ),
39264
+ linked: output
39265
+ }
39266
+ });
39267
+ sdkAsset = { key: sdkImage.key, sha256: sdkImage.sha256, binding };
39268
+ } else {
39269
+ const bytes = (0, import_node_fs53.readFileSync)(output);
39270
+ const ordered = orderObjCConstructors(bytes);
39271
+ if (ordered !== bytes) (0, import_node_fs53.writeFileSync)(output, ordered);
39272
+ stage("lowering the app image");
39273
+ await lowerWasm(output, optimized, { optimize: input.optimize === true });
39274
+ }
39275
+ if (!sdkImage)
39276
+ await runCompiler(
39277
+ import_node_path53.default.join(options2.toolchainBin, "llvm-objcopy"),
39278
+ ["--remove-section=.swift1_autolink_entries", optimized],
39279
+ buildOptions
39280
+ );
39281
+ const artifact = {
39282
+ hash,
39283
+ bytes: (0, import_node_fs53.readFileSync)(optimized),
39284
+ icu: await icu,
39285
+ sdk: sdkAsset
39286
+ };
39287
+ if (artifact.bytes.length <= 8)
39288
+ throw new Error("swift-compile: deferred linker produced no executable");
39289
+ if (!options2.project) saveCompiledArtifact(root2, artifact);
39290
+ saveSharedArtifact(sharedRoot, artifact);
39291
+ stage("compiled artifact verified");
39292
+ return retain(baseRoot, artifact);
39293
+ } finally {
39294
+ readHold?.release();
39295
+ }
39296
+ });
39160
39297
  });
39161
39298
  },
39162
39299
  options2.signal
39163
39300
  );
39164
39301
  }
39165
- var import_node_child_process32, import_node_crypto32, import_node_fs53, import_node_os12, import_node_path53, 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;
39302
+ var import_node_child_process32, import_node_crypto32, import_node_fs53, import_node_os12, import_node_path53, 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;
39166
39303
  var init_swift_compile = __esm({
39167
39304
  "src/swift-compile.ts"() {
39168
39305
  "use strict";
@@ -39433,7 +39570,7 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
39433
39570
  REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
39434
39571
  MULTI_MANIFEST_VERSION = 76;
39435
39572
  SWIFT_HEADER_PRODUCTS_TARGET = "PeachHeaderProducts";
39436
- compilerSourceDigest = true ? "37c95b1d4be497f3f882c4c51f2be7e5bb09b4bcc4976a51d553b0a993c9c7ca" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
39573
+ compilerSourceDigest = true ? "203439fc20df8d328b0c245496fc6db90092265409adb61b593725e82ce837de" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
39437
39574
  nativeCxxCompilerFlags = ["-fno-cxx-modules"];
39438
39575
  MODULE_MAP_RESPONSE_FILE_RUN = 16;
39439
39576
  cFlagArray = (flags) => JSON.stringify(withoutGlogModuleMap(flags));
@@ -39857,6 +39994,7 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
39857
39994
  retainedArtifacts = /* @__PURE__ */ new Map();
39858
39995
  FRAMEWORK_LINK_TARGET = "PeachFrameworkLink";
39859
39996
  frameworkProductsReceiptSchema = v6.object({
39997
+ root: v6.string(),
39860
39998
  modules: v6.string(),
39861
39999
  objects: v6.array(v6.string()),
39862
40000
  lazyObjects: v6.array(v6.string()),
@@ -39873,6 +40011,9 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
39873
40011
  SWIFT_FRAMEWORK_UNOPTIMIZED_SLOTS = 4;
39874
40012
  SWIFT_FRAMEWORK_SLOT_KEY = ".peach-framework-key";
39875
40013
  SWIFT_FRAMEWORK_SLOT_ORIGIN = ".peach-framework-origin";
40014
+ SWIFT_FRAMEWORK_SLOT_RELEASE = ".peach-framework-release";
40015
+ SWIFT_BUILD_ROOT_SLOTS = 4;
40016
+ SWIFT_BUILD_ROOT_SHAPE = ".peach-build-shape";
39876
40017
  }
39877
40018
  });
39878
40019
 
@@ -66863,7 +67004,7 @@ var init_provenance = __esm({
66863
67004
  import_node_crypto42 = require("node:crypto");
66864
67005
  import_node_fs73 = require("node:fs");
66865
67006
  import_node_path73 = require("node:path");
66866
- swiftCoverageProvenance = true ? JSON.parse('{"swift-coverage/indexdump.ts":"0d82d8eeb96bf377f409ea7e33274c341a710c0e071f6b6e17571a23d8d92412","swift-coverage/indexing.ts":"633ccf19eec1f382a8847d0ee1dca42a2792a3c60aafd43622ed5152b09b8272","swift-coverage/types.ts":"bd8fae54ea6c53e110cd8a5d7b57c1d532dd0166e09fdaea63c4f270c3780dd1","swift-coverage/source.ts":"c151758a9f67631bc61473c375df0dc017da6902a34533b2cf4fc4fd7d19b6ee","swift-coverage/package.ts":"1f0068be7461fa7c5a7a891faf318f305cbed2e94c19667ba76627f7e5be260b","swift-coverage/xcode.ts":"d6a3228567a46c6d5280895383093889d9b868958a117881061bdd74729a225f","swift-coverage/xcode-assets.ts":"d98d6294b359528f7733b26db6f80f554782354faa235605f9562be4ad98b8a3","swift-coverage/xcode-asset-symbols.ts":"1b2a67733bc9d139b351466270205452a6172140bc25080d72619e2952c44671","swift-coverage/xcode-bridging.ts":"33184be8c5daf6646aa5a1276a4e15531f1be27b7c26f56550e0fbb1fc678a11","swift-coverage/xcode-packages.ts":"5c83f56357d880243ab485b260d23abd0094583ffa2287dac6e9e7eb18c3673d","swift-coverage/xcode-strings.ts":"facdbeb9de6bb12da4ab4954553edfaadd0e486f1181443138be70c3d8396236","swift-coverage/reader.ts":"da559b67ecd1161dea70c980b5f98f2c55af3550f0714479100fa5e9e813625c","swift-coverage/provenance.ts":"f5039c16e63c6129e22b71203f58982c68cef6e282a4f236b93da28edd39c108","swift-package-manifest.ts":"c64b677c93e48d61c71b371d887e9db8506c32ef968ed50d9468de1f67fe5d8d","swift-package.ts":"05c6cf101fbc944f6684a70db0a9c5aede846b2f0482a6b4a5a0abed737d4658","swift-source-file.ts":"8becce5e73b76a61d9d202c1ecfb39b1238e9bbf0e77841f1c51c98fa9ac7bd3","swift-toolchain.ts":"4f54e110f6f2f72da6d20ca6fc1a10c7dbd0cd462b7dd3959351e107c4aa7548","home-paths.ts":"d1606390f0e8e50f0ff72544eadb3d49dfabf08e004c1218f2998c36fb8995dd","xcode-header-search.ts":"c72b724fc497e4cf603c355f86eb3c07c929ad299758cffbc6ff88ed241654c6","xcode-project.ts":"fe50b74f53082e75bb32393ada42bbbcb0ff982024a026b4b673f2004dd404d8","xcode-target-members.ts":"96f6a9f5567a4fbd9806252229b35b9a451a112b20f70f8c20189ffd428815fd","xcode-json-project.ts":"df6d6db28e0c8cfdf1f480e1e32d35f12c9cf1936642d5dda923889fb18a8fd6","openstep-plist.ts":"da11f86885ef1e25979ad989f332195c113c4b7a43f108e8d36646973430b81b"}') : swiftCoverageSourceDigests((0, import_node_path73.join)(__sootsim_import_meta_dirname, ".."));
67007
+ swiftCoverageProvenance = true ? JSON.parse('{"swift-coverage/indexdump.ts":"0d82d8eeb96bf377f409ea7e33274c341a710c0e071f6b6e17571a23d8d92412","swift-coverage/indexing.ts":"633ccf19eec1f382a8847d0ee1dca42a2792a3c60aafd43622ed5152b09b8272","swift-coverage/types.ts":"bd8fae54ea6c53e110cd8a5d7b57c1d532dd0166e09fdaea63c4f270c3780dd1","swift-coverage/source.ts":"c151758a9f67631bc61473c375df0dc017da6902a34533b2cf4fc4fd7d19b6ee","swift-coverage/package.ts":"1f0068be7461fa7c5a7a891faf318f305cbed2e94c19667ba76627f7e5be260b","swift-coverage/xcode.ts":"d6a3228567a46c6d5280895383093889d9b868958a117881061bdd74729a225f","swift-coverage/xcode-assets.ts":"d98d6294b359528f7733b26db6f80f554782354faa235605f9562be4ad98b8a3","swift-coverage/xcode-asset-symbols.ts":"1b2a67733bc9d139b351466270205452a6172140bc25080d72619e2952c44671","swift-coverage/xcode-bridging.ts":"33184be8c5daf6646aa5a1276a4e15531f1be27b7c26f56550e0fbb1fc678a11","swift-coverage/xcode-packages.ts":"5c83f56357d880243ab485b260d23abd0094583ffa2287dac6e9e7eb18c3673d","swift-coverage/xcode-strings.ts":"facdbeb9de6bb12da4ab4954553edfaadd0e486f1181443138be70c3d8396236","swift-coverage/reader.ts":"da559b67ecd1161dea70c980b5f98f2c55af3550f0714479100fa5e9e813625c","swift-coverage/provenance.ts":"f5039c16e63c6129e22b71203f58982c68cef6e282a4f236b93da28edd39c108","swift-package-manifest.ts":"c64b677c93e48d61c71b371d887e9db8506c32ef968ed50d9468de1f67fe5d8d","swift-package.ts":"05c6cf101fbc944f6684a70db0a9c5aede846b2f0482a6b4a5a0abed737d4658","swift-source-file.ts":"8becce5e73b76a61d9d202c1ecfb39b1238e9bbf0e77841f1c51c98fa9ac7bd3","swift-toolchain.ts":"32bf10d6f3396dd1a20ff6d415499a5990ec2550c63306fd9ef071bdf4a58f1e","home-paths.ts":"d1606390f0e8e50f0ff72544eadb3d49dfabf08e004c1218f2998c36fb8995dd","xcode-header-search.ts":"c72b724fc497e4cf603c355f86eb3c07c929ad299758cffbc6ff88ed241654c6","xcode-project.ts":"fe50b74f53082e75bb32393ada42bbbcb0ff982024a026b4b673f2004dd404d8","xcode-target-members.ts":"96f6a9f5567a4fbd9806252229b35b9a451a112b20f70f8c20189ffd428815fd","xcode-json-project.ts":"df6d6db28e0c8cfdf1f480e1e32d35f12c9cf1936642d5dda923889fb18a8fd6","openstep-plist.ts":"da11f86885ef1e25979ad989f332195c113c4b7a43f108e8d36646973430b81b"}') : swiftCoverageSourceDigests((0, import_node_path73.join)(__sootsim_import_meta_dirname, ".."));
66867
67008
  }
66868
67009
  });
66869
67010
 
@@ -87326,7 +87467,7 @@ var init_swift_standin_digest = __esm({
87326
87467
  STANDIN_DIGEST_ENTRYPOINTS = ["swift-standins.ts", "swift-objc-compile.ts"];
87327
87468
  SPECIFIER = /from\s*['"]([^'"]+)['"]|import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
87328
87469
  standinSourceDigest = (srcDir = __sootsim_import_meta_dirname) => sourceClosureDigest(srcDir, STANDIN_DIGEST_ENTRYPOINTS);
87329
- STANDIN_SOURCE_DIGEST = true ? "0fa01889b40249e7aa8b8e48fee286aef4d4994798bf35e354ae224d421cdd03" : standinSourceDigest();
87470
+ STANDIN_SOURCE_DIGEST = true ? "fde0b0b7ddf441a32e71680bc17ba12f69f2cbaed1a0a024505e7f4a5394772d" : standinSourceDigest();
87330
87471
  }
87331
87472
  });
87332
87473
 
@@ -103788,7 +103929,7 @@ var init_nitro_superset = __esm({
103788
103929
  init_nitroContract();
103789
103930
  init_swift_standin_digest();
103790
103931
  NITRO_SUPERSET_ENTRY_NAME = "superset";
103791
- NITRO_COMPILER_DIGEST = true ? "6dd1320b8d444e55b9223745c327afa3e7fe0f51fbab1f79548b3eff6612ee4c" : nitroCompilerSourceDigest(__sootsim_import_meta_dirname, STANDIN_SOURCE_DIGEST2);
103932
+ NITRO_COMPILER_DIGEST = true ? "74b5613216c94c9a712253659e2803b31d4fe1a7f0ff32f2ad7d3fa7ef57f2ab" : nitroCompilerSourceDigest(__sootsim_import_meta_dirname, STANDIN_SOURCE_DIGEST2);
103792
103933
  nitroSupersetLock = parseLock(nitro_superset_lock_default);
103793
103934
  nitroSupersetKey = (inputs2) => nativeEntryKey({ ...inputs2, compiler: NITRO_COMPILER_DIGEST });
103794
103935
  published = /* @__PURE__ */ new Map();
@@ -104656,7 +104797,7 @@ var init_expo_eager_seam_contract = __esm({
104656
104797
 
104657
104798
  // src/expo-native-compiler-digest.ts
104658
104799
  function expoNativeCompilerDigestValue() {
104659
- return true ? "f6f1fdf256bd2bea43a47405f3cf628eb70398ab6fe8a8b27eee2dd2c6354b11" : expoNativeCompilerDigest(__sootsim_import_meta_dirname);
104800
+ return true ? "0eb8b57c26c74de660f5dc029f1ae0ffa0af503b67afa64e2c93b02b517a2e68" : expoNativeCompilerDigest(__sootsim_import_meta_dirname);
104660
104801
  }
104661
104802
  var import_node_crypto78;
104662
104803
  var init_expo_native_compiler_digest = __esm({