peachsim 0.1.2606 → 0.1.2607

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/cli/commands/package.ts +71 -39
  2. package/cli/commands/perf-native.ts +259 -6
  3. package/cli/commands/shell-url.ts +1 -0
  4. package/dist-lib/agent-daemon-client.cjs +1 -1
  5. package/dist-lib/agent-events.cjs +1 -1
  6. package/dist-lib/attached-projects.cjs +1 -1
  7. package/dist-lib/auth/shared-session.cjs +1 -1
  8. package/dist-lib/backend-origin.cjs +1 -1
  9. package/dist-lib/beta.cjs +1 -1
  10. package/dist-lib/beta.mjs +2 -2
  11. package/dist-lib/bridge-constants.cjs +1 -1
  12. package/dist-lib/bridge-contract-input.cjs +1 -1
  13. package/dist-lib/bridge-contract-input.mjs +5 -5
  14. package/dist-lib/bridge-contract.cjs +1 -1
  15. package/dist-lib/bridge-contract.mjs +3 -3
  16. package/dist-lib/bundle-channel.cjs +815 -674
  17. package/dist-lib/capture-contract.cjs +1 -1
  18. package/dist-lib/capture-contract.mjs +3 -3
  19. package/dist-lib/cloud-contract.cjs +1 -1
  20. package/dist-lib/cloud-contract.mjs +3 -3
  21. package/dist-lib/cloud-test-args.cjs +1 -1
  22. package/dist-lib/cloud-test-args.mjs +2 -2
  23. package/dist-lib/cloud.cjs +1 -1
  24. package/dist-lib/cloud.mjs +7 -7
  25. package/dist-lib/config.cjs +1 -1
  26. package/dist-lib/config.mjs +5 -5
  27. package/dist-lib/detox/index.cjs +1 -1
  28. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  29. package/dist-lib/esm-chunks/{acorn-UL7Z3WUQ.mjs → acorn-KFWXYMX5.mjs} +3 -3
  30. package/dist-lib/esm-chunks/{chunk-EXB4QSQI.mjs → chunk-6JPUMAC2.mjs} +1 -1
  31. package/dist-lib/esm-chunks/{chunk-CPMK3DA6.mjs → chunk-6NDABMDX.mjs} +3 -3
  32. package/dist-lib/esm-chunks/{chunk-5JMW5G3U.mjs → chunk-7SKDPTZN.mjs} +1 -1
  33. package/dist-lib/esm-chunks/{chunk-MBCSJQRY.mjs → chunk-ACAXWH62.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-25LYRBSX.mjs → chunk-ARYRQJUB.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-KWLQDES2.mjs → chunk-BNAXRY5Q.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-VTZJPPTE.mjs → chunk-CA64UUHF.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-OB5XSLW6.mjs → chunk-DBW62F4N.mjs} +3 -2
  38. package/dist-lib/esm-chunks/{chunk-RTPUFY2K.mjs → chunk-ESS2CG5G.mjs} +5 -5
  39. package/dist-lib/esm-chunks/{chunk-O6NRI4T2.mjs → chunk-IGSLOAPL.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-5ANQR24T.mjs → chunk-KIIALACX.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-66ESCMV3.mjs → chunk-LJZ373SO.mjs} +818 -678
  42. package/dist-lib/esm-chunks/{chunk-TVICD24H.mjs → chunk-M4ORY3NH.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-34CIYRB7.mjs → chunk-MBWWOGI5.mjs} +4 -4
  44. package/dist-lib/esm-chunks/{chunk-QFASF6EH.mjs → chunk-O5BPZVLB.mjs} +5 -5
  45. package/dist-lib/esm-chunks/{chunk-L7FPUZZO.mjs → chunk-P5Q5QCTP.mjs} +1 -1
  46. package/dist-lib/esm-chunks/{chunk-B7AXR7WA.mjs → chunk-QJUAWJDB.mjs} +1 -1
  47. package/dist-lib/esm-chunks/{chunk-O6ZNRBLB.mjs → chunk-RIDXKGBZ.mjs} +1 -1
  48. package/dist-lib/esm-chunks/{chunk-WJKACRMG.mjs → chunk-TD2DBEKQ.mjs} +1 -1
  49. package/dist-lib/esm-chunks/{chunk-E2TASYAA.mjs → chunk-UTSB5CDG.mjs} +1 -1
  50. package/dist-lib/esm-chunks/{chunk-PLOV7VQQ.mjs → chunk-WMWOBH7E.mjs} +1 -1
  51. package/dist-lib/esm-chunks/{chunk-XUWYWP35.mjs → chunk-ZNGLVJYL.mjs} +1 -1
  52. package/dist-lib/esm-chunks/{metro-layout-parser-OMUFYOJI.mjs → metro-layout-parser-UY3B6VGU.mjs} +3 -3
  53. package/dist-lib/esm-chunks/{swift-package-prebuilt-X7EZCX34.mjs → swift-package-prebuilt-HDHPWS44.mjs} +10 -10
  54. package/dist-lib/esm-chunks/{swift-sdk-app-module-E3IF2XPD.mjs → swift-sdk-app-module-U6G5RZV2.mjs} +14 -14
  55. package/dist-lib/esm-chunks/{swift-sdk-image-57YYLNU6.mjs → swift-sdk-image-PVDA2MVM.mjs} +14 -14
  56. package/dist-lib/esm-chunks/{swift-sdk-image-producer-DZOZTTDZ.mjs → swift-sdk-image-producer-YHPS3KNR.mjs} +4 -4
  57. package/dist-lib/expo-swift-bundle.cjs +814 -673
  58. package/dist-lib/expo-swift-metadata.cjs +1 -1
  59. package/dist-lib/expo-swift-metadata.mjs +7 -7
  60. package/dist-lib/home-paths.cjs +1 -1
  61. package/dist-lib/host/bridge-host.cjs +959 -676
  62. package/dist-lib/host/fetch-proxy-handler.cjs +6 -5
  63. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  64. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
  65. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  66. package/dist-lib/host/websocket-proxy.cjs +1 -1
  67. package/dist-lib/index.cjs +1 -1
  68. package/dist-lib/kotlin-host.cjs +1 -1
  69. package/dist-lib/menu.cjs +1 -1
  70. package/dist-lib/menu.mjs +3 -3
  71. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  72. package/dist-lib/metro-fingerprint-registry.mjs +3 -3
  73. package/dist-lib/metro-production-bundle.cjs +1 -1
  74. package/dist-lib/metro-production-bundle.mjs +4 -4
  75. package/dist-lib/native-app-identity-project.cjs +6 -4
  76. package/dist-lib/native-app-identity-project.mjs +17 -17
  77. package/dist-lib/native-app-identity.cjs +1 -1
  78. package/dist-lib/native-app-identity.mjs +6 -6
  79. package/dist-lib/native-firebase-metadata.cjs +1 -1
  80. package/dist-lib/native-firebase-metadata.mjs +3 -3
  81. package/dist-lib/pdfium-raster.cjs +1 -1
  82. package/dist-lib/pdfium-raster.mjs +2 -2
  83. package/dist-lib/plist.cjs +1 -1
  84. package/dist-lib/plist.mjs +3 -3
  85. package/dist-lib/profiles.cjs +1 -1
  86. package/dist-lib/public-brand.cjs +1 -1
  87. package/dist-lib/public-origins-lib-esm.json +81 -81
  88. package/dist-lib/public-origins-lib.json +64 -64
  89. package/dist-lib/react-native-host-modules.cjs +1 -1
  90. package/dist-lib/react-native-host-modules.mjs +2 -2
  91. package/dist-lib/reap-browser.cjs +1 -1
  92. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  93. package/dist-lib/sdk.cjs +1 -1
  94. package/dist-lib/sdk.mjs +8 -8
  95. package/dist-lib/skills.cjs +959 -676
  96. package/dist-lib/swift-compile.cjs +811 -670
  97. package/dist-lib/swift-compile.mjs +10 -10
  98. package/dist-lib/swift-package.cjs +1 -1
  99. package/dist-lib/swift-package.mjs +3 -3
  100. package/dist-lib/swift-submit.cjs +1 -1
  101. package/dist-lib/swift-submit.mjs +6 -6
  102. package/dist-lib/swift-svg-raster.cjs +1 -1
  103. package/dist-lib/swift-svg-raster.mjs +2 -2
  104. package/dist-lib/swift-toolchain.cjs +3 -2
  105. package/dist-lib/swift.cjs +1 -1
  106. package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
  107. package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
  108. package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
  109. package/dist-lib/vendor/acorn.cjs +1 -1
  110. package/dist-lib/vendor/magic-string.cjs +1 -1
  111. package/dist-lib/vendor/stream-json.cjs +1 -1
  112. package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
  113. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
  114. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
  115. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
  116. package/dist-lib/vendor/sucrase.cjs +1 -1
  117. package/dist-lib/vendor/terser.cjs +1 -1
  118. package/dist-lib/vendor/valibot.cjs +1 -1
  119. package/dist-lib/vendor/ws.cjs +1 -1
  120. package/dist-lib/vendor/zod.cjs +1 -1
  121. package/dist-lib/worklet-executable.cjs +1 -1
  122. package/dist-lib/worklet-executable.mjs +3 -3
  123. package/dist-types/packages/peach-engine/src/ios/apps/canvas-map-data.d.ts +38 -2
  124. package/dist-types/packages/peach-globals/src/canvasAgentContract.d.ts +8 -0
  125. package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
  126. package/package.json +1 -1
  127. package/src/agent-prompt.ts +5 -1
  128. package/src/one-native-controls-package.ts +143 -1
  129. package/src/oneNativeControlsContract.ts +1 -0
  130. package/src/swift-compile-budget.ts +28 -7
  131. package/src/swift-compile.ts +968 -803
  132. package/src/swift-guest-compile.ts +3 -0
  133. package/src/swift-toolchain.ts +4 -1
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.2606 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.2607 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
2
2
  let __sootsim_import_meta_url = '', __sootsim_import_meta_dirname = '', __sootsim_import_meta_filename = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; __sootsim_import_meta_dirname = __dirname; __sootsim_import_meta_filename = __filename; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -8900,7 +8900,8 @@ function swiftCompilerRelease(release) {
8900
8900
  }
8901
8901
  function swiftToolchainBin(release) {
8902
8902
  if (process.platform === "darwin") {
8903
- const dirs = [import_node_os6.default.homedir(), "/"].map(
8903
+ const bases = [.../* @__PURE__ */ new Set([import_node_os6.default.homedir(), import_node_path14.default.dirname(peachHome()), "/"])];
8904
+ const dirs = bases.map(
8904
8905
  (base) => import_node_path14.default.join(base, `Library/Developer/Toolchains/${release}.xctoolchain/usr/bin`)
8905
8906
  );
8906
8907
  const found = dirs.find((dir) => import_node_fs17.default.existsSync(import_node_path14.default.join(dir, "swift")));
@@ -17979,13 +17980,13 @@ var init_swift_standin_digest = __esm({
17979
17980
  STANDIN_DIGEST_ENTRYPOINTS = ["swift-standins.ts", "swift-objc-compile.ts"];
17980
17981
  SPECIFIER = /from\s*['"]([^'"]+)['"]|import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
17981
17982
  standinSourceDigest = (srcDir = __sootsim_import_meta_dirname) => sourceClosureDigest(srcDir, STANDIN_DIGEST_ENTRYPOINTS);
17982
- STANDIN_SOURCE_DIGEST = true ? "0fa01889b40249e7aa8b8e48fee286aef4d4994798bf35e354ae224d421cdd03" : standinSourceDigest();
17983
+ STANDIN_SOURCE_DIGEST = true ? "fde0b0b7ddf441a32e71680bc17ba12f69f2cbaed1a0a024505e7f4a5394772d" : standinSourceDigest();
17983
17984
  }
17984
17985
  });
17985
17986
 
17986
17987
  // src/expo-native-compiler-digest.ts
17987
17988
  function expoNativeCompilerDigestValue() {
17988
- return true ? "f6f1fdf256bd2bea43a47405f3cf628eb70398ab6fe8a8b27eee2dd2c6354b11" : expoNativeCompilerDigest(__sootsim_import_meta_dirname);
17989
+ return true ? "0eb8b57c26c74de660f5dc029f1ae0ffa0af503b67afa64e2c93b02b517a2e68" : expoNativeCompilerDigest(__sootsim_import_meta_dirname);
17989
17990
  }
17990
17991
  var import_node_crypto17;
17991
17992
  var init_expo_native_compiler_digest = __esm({
@@ -21141,24 +21142,37 @@ function swiftBuilderHopTimeoutMs(compileTimeoutMs) {
21141
21142
  async function withSwiftCompileBudget(compileTimeoutMs, signal, work) {
21142
21143
  const deadline = new AbortController();
21143
21144
  const combined = signal ? AbortSignal.any([signal, deadline.signal]) : deadline.signal;
21145
+ const stallMs = compileTimeoutMs ?? SWIFT_COMPILE_TIMEOUT_MS;
21146
+ let compiling = false;
21144
21147
  let timer = setTimeout(
21145
21148
  () => deadline.abort(new Error("Swift build lock wait timed out")),
21146
21149
  SWIFT_LOCK_WAIT_TIMEOUT_MS
21147
21150
  );
21151
+ const restart = () => {
21152
+ clearTimeout(timer);
21153
+ timer = setTimeout(
21154
+ () => deadline.abort(
21155
+ new Error(
21156
+ `Swift compilation made no progress for ${Math.round(stallMs / 1e3)}s`
21157
+ )
21158
+ ),
21159
+ stallMs
21160
+ );
21161
+ };
21148
21162
  try {
21149
21163
  combined.throwIfAborted();
21150
21164
  const result = await work({
21151
21165
  signal: combined,
21152
21166
  startCompile() {
21153
21167
  combined.throwIfAborted();
21154
- clearTimeout(timer);
21155
- timer = setTimeout(
21156
- () => deadline.abort(new Error("Swift compilation timed out")),
21157
- compileTimeoutMs ?? SWIFT_COMPILE_TIMEOUT_MS
21158
- );
21168
+ compiling = true;
21169
+ restart();
21170
+ },
21171
+ progress() {
21172
+ if (compiling && !deadline.signal.aborted) restart();
21159
21173
  }
21160
21174
  });
21161
- combined.throwIfAborted();
21175
+ signal?.throwIfAborted();
21162
21176
  return result;
21163
21177
  } finally {
21164
21178
  clearTimeout(timer);
@@ -38601,6 +38615,7 @@ async function compileGuestLink(options2) {
38601
38615
  );
38602
38616
  continue;
38603
38617
  }
38618
+ options2.onStage("lowering the app image");
38604
38619
  const lowerPromise = link.lower();
38605
38620
  await new Promise((resolve3) => setImmediate(resolve3));
38606
38621
  let binding;
@@ -38631,6 +38646,7 @@ async function compileGuestLink(options2) {
38631
38646
  return binding;
38632
38647
  }
38633
38648
  }
38649
+ options2.onStage("lowering the app image");
38634
38650
  await lowerWasm(options2.output, options2.optimized, {
38635
38651
  optimize: options2.optimize,
38636
38652
  skipPasses: ["duplicate-function-elimination"],
@@ -40066,8 +40082,18 @@ async function runCompiler(command, args, options2, stream = false, quiet) {
40066
40082
  void stopping.catch(() => {
40067
40083
  });
40068
40084
  };
40085
+ const restartTimeout = () => {
40086
+ if (!options2.timeout) return;
40087
+ clearTimeout(timeout);
40088
+ timeout = setTimeout(() => {
40089
+ failure2 = new Error(`Swift compiler was silent for ${options2.timeout}ms`);
40090
+ stop();
40091
+ }, options2.timeout);
40092
+ };
40069
40093
  for (const name3 of ["stdout", "stderr"]) {
40070
40094
  child[name3].on("data", (bytes) => {
40095
+ restartTimeout();
40096
+ options2.onOutput?.();
40071
40097
  if (stream === true) process[name3].write(bytes);
40072
40098
  else if (stream) {
40073
40099
  const lines = (partial[name3] + bytes.toString()).split("\n");
@@ -40116,11 +40142,7 @@ async function runCompiler(command, args, options2, stream = false, quiet) {
40116
40142
  resolve3(Buffer.concat(chunks.stdout).toString());
40117
40143
  }
40118
40144
  });
40119
- if (options2.timeout)
40120
- timeout = setTimeout(() => {
40121
- failure2 = new Error("Swift compiler timed out");
40122
- stop();
40123
- }, options2.timeout);
40145
+ restartTimeout();
40124
40146
  if (signal?.aborted) stop();
40125
40147
  });
40126
40148
  } finally {
@@ -44998,24 +45020,18 @@ function readFrameworkProductsReceipt(scratch2, receiptKey) {
44998
45020
  } catch {
44999
45021
  return null;
45000
45022
  }
45001
- const archive = import_node_path68.default.join(scratch2, "lib");
45002
- const archiveStamp = import_node_path68.default.join(archive, ".receipt");
45003
- const archiveMatches = (0, import_node_fs68.existsSync)(archiveStamp) && (0, import_node_fs68.readFileSync)(archiveStamp, "utf8") === receiptKey;
45023
+ const archiveRoot = import_node_path68.default.join(scratch2, "products-lib", receiptKey);
45024
+ if (parsed2.root !== archiveRoot) return null;
45004
45025
  if (!(0, import_node_fs68.existsSync)(parsed2.modules)) return null;
45005
- for (const [object8] of parsed2.archived) if (!(0, import_node_fs68.existsSync)(object8)) return null;
45026
+ for (const [object8, rel] of parsed2.archived) {
45027
+ if (!(0, import_node_fs68.existsSync)(object8) || !(0, import_node_fs68.existsSync)(import_node_path68.default.join(archiveRoot, rel))) return null;
45028
+ }
45006
45029
  for (const file of parsed2.providers) if (!(0, import_node_fs68.existsSync)(file)) return null;
45007
45030
  for (const file of parsed2.moduleMaps) if (!(0, import_node_fs68.existsSync)(file)) return null;
45008
- if (!archiveMatches) {
45009
- (0, import_node_fs68.rmSync)(archive, { recursive: true, force: true });
45010
- (0, import_node_fs68.mkdirSync)(archive, { recursive: true });
45011
- for (const [object8, rel] of parsed2.archived)
45012
- (0, import_node_fs68.symlinkSync)(object8, import_node_path68.default.join(scratch2, rel));
45013
- (0, import_node_fs68.writeFileSync)(archiveStamp, receiptKey);
45014
- }
45015
45031
  for (const file of parsed2.objects) if (!(0, import_node_fs68.existsSync)(file)) return null;
45016
45032
  for (const file of parsed2.lazyObjects) if (!(0, import_node_fs68.existsSync)(file)) return null;
45017
45033
  return {
45018
- root: scratch2,
45034
+ root: parsed2.root,
45019
45035
  modules: parsed2.modules,
45020
45036
  objects: parsed2.objects,
45021
45037
  lazyObjects: parsed2.lazyObjects,
@@ -45033,7 +45049,7 @@ async function buildFrameworkProducts(scratch2, args) {
45033
45049
  const selectorOptions = swiftObjCSelectorOptions(args.moduleRoot);
45034
45050
  const receiptKey = (0, import_node_crypto42.createHash)("sha256").update(
45035
45051
  JSON.stringify([
45036
- "framework-products/v1",
45052
+ "framework-products/v2",
45037
45053
  args.frameworkKey,
45038
45054
  unoptimized,
45039
45055
  args.sdk,
@@ -45191,28 +45207,40 @@ async function buildFrameworkProducts(scratch2, args) {
45191
45207
  }
45192
45208
  const providers = (0, import_node_fs68.readdirSync)(providerDir).filter((file) => file.endsWith(".o")).sort().map((file) => import_node_path68.default.join(providerDir, file));
45193
45209
  for (const provider of providers) linked.owners.set(provider, "DarwinRecords");
45194
- const archive = import_node_path68.default.join(scratch2, "lib");
45195
- (0, import_node_fs68.rmSync)(archive, { recursive: true, force: true });
45196
- (0, import_node_fs68.mkdirSync)(archive);
45210
+ const archiveBase = import_node_path68.default.join(scratch2, "products-lib");
45211
+ (0, import_node_fs68.mkdirSync)(archiveBase, { recursive: true });
45212
+ const archiveRoot = import_node_path68.default.join(archiveBase, receiptKey);
45213
+ const stagedArchiveRoot = `${archiveRoot}.tmp-${process.pid}-${(0, import_node_crypto42.randomUUID)()}`;
45214
+ const stagedArchive = import_node_path68.default.join(stagedArchiveRoot, "lib");
45215
+ (0, import_node_fs68.mkdirSync)(stagedArchive, { recursive: true });
45197
45216
  const archived = /* @__PURE__ */ new Map();
45198
- for (const object8 of objects) {
45199
- const target = linked.owners.get(object8);
45200
- const dir = import_node_path68.default.join(release, `${target}.build`);
45201
- if (!target || target === "Darwin" || !object8.startsWith(dir + import_node_path68.default.sep)) continue;
45202
- const name3 = `${target}-${import_node_path68.default.relative(dir, object8).replaceAll(import_node_path68.default.sep, "-").replace(/\.swift\.o$/, ".o")}`;
45203
- (0, import_node_fs68.symlinkSync)(object8, import_node_path68.default.join(archive, name3));
45204
- archived.set(object8, `lib/${name3}`);
45205
- }
45206
- const roots = swiftObjcRootObjects(`${scratch2}
45207
- ${args.frameworkKey}`, scratch2, [
45208
- ...archived.values()
45209
- ]);
45217
+ try {
45218
+ for (const object8 of objects) {
45219
+ const target = linked.owners.get(object8);
45220
+ const dir = import_node_path68.default.join(release, `${target}.build`);
45221
+ if (!target || target === "Darwin" || !object8.startsWith(dir + import_node_path68.default.sep)) continue;
45222
+ const name3 = `${target}-${import_node_path68.default.relative(dir, object8).replaceAll(import_node_path68.default.sep, "-").replace(/\.swift\.o$/, ".o")}`;
45223
+ (0, import_node_fs68.symlinkSync)(object8, import_node_path68.default.join(stagedArchive, name3));
45224
+ archived.set(object8, `lib/${name3}`);
45225
+ }
45226
+ (0, import_node_fs68.rmSync)(archiveRoot, { recursive: true, force: true });
45227
+ (0, import_node_fs68.renameSync)(stagedArchiveRoot, archiveRoot);
45228
+ } catch (error) {
45229
+ (0, import_node_fs68.rmSync)(stagedArchiveRoot, { recursive: true, force: true });
45230
+ throw error;
45231
+ }
45232
+ const roots = swiftObjcRootObjects(
45233
+ `${archiveRoot}
45234
+ ${args.frameworkKey}`,
45235
+ archiveRoot,
45236
+ [...archived.values()]
45237
+ );
45210
45238
  const linkedObjects = objects.map((object8) => {
45211
45239
  const name3 = archived.get(object8);
45212
- return name3 ? { path: import_node_path68.default.join(scratch2, name3), lazy: !roots.has(name3) } : { path: object8, lazy: false };
45240
+ return name3 ? { path: import_node_path68.default.join(archiveRoot, name3), lazy: !roots.has(name3) } : { path: object8, lazy: false };
45213
45241
  });
45214
45242
  const result = {
45215
- root: scratch2,
45243
+ root: archiveRoot,
45216
45244
  modules: import_node_path68.default.join(release, "Modules"),
45217
45245
  objects: linkedObjects.filter((object8) => !object8.lazy).map((object8) => object8.path),
45218
45246
  lazyObjects: linkedObjects.filter((object8) => object8.lazy).map((object8) => object8.path),
@@ -45222,7 +45250,6 @@ ${args.frameworkKey}`, scratch2, [
45222
45250
  moduleMaps: linked.moduleMaps,
45223
45251
  objcHeaders: linked.objcHeaders
45224
45252
  };
45225
- (0, import_node_fs68.writeFileSync)(import_node_path68.default.join(archive, ".receipt"), receiptKey);
45226
45253
  const receiptsDir = import_node_path68.default.join(scratch2, "products-ready");
45227
45254
  (0, import_node_fs68.mkdirSync)(receiptsDir, { recursive: true });
45228
45255
  const receiptFile2 = import_node_path68.default.join(receiptsDir, `${receiptKey}.json`);
@@ -45230,6 +45257,7 @@ ${args.frameworkKey}`, scratch2, [
45230
45257
  (0, import_node_fs68.writeFileSync)(
45231
45258
  partialReceipt,
45232
45259
  JSON.stringify({
45260
+ root: result.root,
45233
45261
  modules: result.modules,
45234
45262
  objects: result.objects,
45235
45263
  lazyObjects: result.lazyObjects,
@@ -45261,7 +45289,10 @@ function swiftFrameworkSlotRecord(slot, record4) {
45261
45289
  function swiftFrameworkSlotKey(slot) {
45262
45290
  return swiftFrameworkSlotRecord(slot, SWIFT_FRAMEWORK_SLOT_KEY);
45263
45291
  }
45264
- async function withSwiftFrameworkSlot(frameworkKey, moduleRoot, signal, work, unoptimized = false) {
45292
+ function swiftFrameworkSlotRelease(slot) {
45293
+ return swiftFrameworkSlotRecord(slot, SWIFT_FRAMEWORK_SLOT_RELEASE);
45294
+ }
45295
+ async function withSwiftFrameworkSlot(frameworkKey, release, moduleRoot, signal, work, unoptimized = false) {
45265
45296
  const slotCount = unoptimized ? SWIFT_FRAMEWORK_UNOPTIMIZED_SLOTS : SWIFT_FRAMEWORK_SLOTS;
45266
45297
  const slotsDir = swiftFrameworksDir(unoptimized);
45267
45298
  const slots = Array.from({ length: slotCount }, (_, index) => {
@@ -45284,9 +45315,12 @@ async function withSwiftFrameworkSlot(frameworkKey, moduleRoot, signal, work, un
45284
45315
  (0, import_node_fs68.readFileSync)(import_node_path68.default.join(moduleRoot, file))
45285
45316
  ])
45286
45317
  );
45287
- const ranked = slots.map((slot) => {
45318
+ const ranked = slots.map((slot, index) => {
45319
+ const slotKey = swiftFrameworkSlotKey(slot);
45320
+ if (slotKey === null) return { slot, index, tier: 1, changes: Infinity };
45321
+ if (swiftFrameworkSlotRelease(slot) !== release)
45322
+ return { slot, index, tier: 2, changes: Infinity };
45288
45323
  let changes = 0;
45289
- if (swiftFrameworkSlotKey(slot) === null) return { slot, changes: Infinity };
45290
45324
  const source = import_node_path68.default.join(slot, "source", "packages", import_node_path68.default.basename(moduleRoot));
45291
45325
  for (const [file, contents2] of inputs2) {
45292
45326
  try {
@@ -45298,18 +45332,22 @@ async function withSwiftFrameworkSlot(frameworkKey, moduleRoot, signal, work, un
45298
45332
  changes++;
45299
45333
  }
45300
45334
  }
45301
- return { slot, changes };
45302
- }).sort(
45303
- (left, right) => left.changes - right.changes || Number(own2(right.slot)) - Number(own2(left.slot)) || (built2.get(right.slot) ?? 0) - (built2.get(left.slot) ?? 0)
45304
- );
45305
- for (const { slot, changes } of ranked) {
45335
+ return { slot, index, tier: 0, changes };
45336
+ }).sort((left, right) => {
45337
+ if (left.tier !== right.tier) return left.tier - right.tier;
45338
+ if (left.tier === 0)
45339
+ return left.changes - right.changes || Number(own2(right.slot)) - Number(own2(left.slot)) || (built2.get(right.slot) ?? 0) - (built2.get(left.slot) ?? 0);
45340
+ if (left.tier === 1) return left.index - right.index;
45341
+ return (built2.get(left.slot) ?? 0) - (built2.get(right.slot) ?? 0);
45342
+ });
45343
+ for (const { slot, tier, changes } of ranked) {
45306
45344
  if (await hasLiveSwiftRootReaders(slot, signal)) continue;
45307
45345
  const result = await withSwiftRootLock(
45308
45346
  slot,
45309
45347
  async (lease) => {
45310
45348
  if (await hasLiveSwiftRootReaders(slot, signal)) return void 0;
45311
45349
  console.error(
45312
- `[swift-framework-cache] ${import_node_path68.default.basename(slot)} changedInputs=${changes} totalInputs=${inputs2.size}`
45350
+ `[swift-framework-cache] ${import_node_path68.default.basename(slot)} release=${release} tier=${tier} changedInputs=${changes} totalInputs=${inputs2.size}`
45313
45351
  );
45314
45352
  return { value: await run12(slot)(lease) };
45315
45353
  },
@@ -45321,6 +45359,43 @@ async function withSwiftFrameworkSlot(frameworkKey, moduleRoot, signal, work, un
45321
45359
  const nearest = ranked[0].slot;
45322
45360
  return withSwiftRootLock(nearest, run12(nearest), signal);
45323
45361
  }
45362
+ async function withSwiftBuildRootSlot(baseRoot, buildShape, signal, work) {
45363
+ const slots = Array.from({ length: SWIFT_BUILD_ROOT_SLOTS }, (_, index) => {
45364
+ const slot = index === 0 ? baseRoot : `${baseRoot}-s${index}`;
45365
+ (0, import_node_fs68.mkdirSync)(slot, { recursive: true });
45366
+ return slot;
45367
+ });
45368
+ const runInSlot = (slot, waitStart2) => (lease) => {
45369
+ const waitedMs = Date.now() - waitStart2;
45370
+ const now = /* @__PURE__ */ new Date();
45371
+ (0, import_node_fs68.utimesSync)(slot, now, now);
45372
+ return work(slot, lease, waitedMs);
45373
+ };
45374
+ const built2 = new Map(slots.map((slot) => [slot, (0, import_node_fs68.statSync)(slot).mtimeMs]));
45375
+ const ranked = slots.map((slot, index) => {
45376
+ const shape = swiftFrameworkSlotRecord(slot, SWIFT_BUILD_ROOT_SHAPE);
45377
+ const tier = shape === buildShape ? 0 : shape === null ? 1 : 2;
45378
+ return { slot, index, tier };
45379
+ }).sort((left, right) => {
45380
+ if (left.tier !== right.tier) return left.tier - right.tier;
45381
+ if (left.tier === 0)
45382
+ return (built2.get(right.slot) ?? 0) - (built2.get(left.slot) ?? 0);
45383
+ if (left.tier === 1) return left.index - right.index;
45384
+ return (built2.get(left.slot) ?? 0) - (built2.get(right.slot) ?? 0);
45385
+ });
45386
+ for (const { slot } of ranked) {
45387
+ const result = await withSwiftRootLock(
45388
+ slot,
45389
+ async (lease) => ({ value: await runInSlot(slot, Date.now())(lease) }),
45390
+ signal,
45391
+ false
45392
+ );
45393
+ if (result) return result.value;
45394
+ }
45395
+ const nearest = ranked[0].slot;
45396
+ const waitStart = Date.now();
45397
+ return withSwiftRootLock(nearest, runInSlot(nearest, waitStart), signal);
45398
+ }
45324
45399
  function mirrorTree2(source, target, skip) {
45325
45400
  (0, import_node_fs68.mkdirSync)(target, { recursive: true });
45326
45401
  const wanted = /* @__PURE__ */ new Set();
@@ -45370,8 +45445,10 @@ function stageFrameworkSource(moduleRoot, slot, frameworkKey, release) {
45370
45445
  const hadKey = swiftFrameworkSlotKey(slot);
45371
45446
  if (hadKey !== frameworkKey) {
45372
45447
  (0, import_node_fs68.rmSync)(import_node_path68.default.join(slot, SWIFT_FRAMEWORK_SLOT_KEY), { force: true });
45448
+ (0, import_node_fs68.rmSync)(import_node_path68.default.join(slot, SWIFT_FRAMEWORK_SLOT_RELEASE), { force: true });
45373
45449
  (0, import_node_fs68.rmSync)(import_node_path68.default.join(slot, "products-ready"), { recursive: true, force: true });
45374
- (0, import_node_fs68.rmSync)(import_node_path68.default.join(slot, "lib", ".receipt"), { force: true });
45450
+ (0, import_node_fs68.rmSync)(import_node_path68.default.join(slot, "products-lib"), { recursive: true, force: true });
45451
+ (0, import_node_fs68.rmSync)(import_node_path68.default.join(slot, "lib"), { recursive: true, force: true });
45375
45452
  const moduleRestructured = mirrorTree2(moduleRoot, stagedModule, ".build");
45376
45453
  const sdkRestructured = mirrorTree2(
45377
45454
  swiftSharedSdkRoot(moduleRoot, false),
@@ -45399,8 +45476,11 @@ function stageFrameworkSource(moduleRoot, slot, frameworkKey, release) {
45399
45476
  (0, import_node_fs68.rmSync)(modules, { recursive: true, force: true });
45400
45477
  (0, import_node_fs68.symlinkSync)(target, modules);
45401
45478
  }
45479
+ (0, import_node_fs68.writeFileSync)(import_node_path68.default.join(slot, SWIFT_FRAMEWORK_SLOT_RELEASE), release);
45402
45480
  (0, import_node_fs68.writeFileSync)(import_node_path68.default.join(slot, SWIFT_FRAMEWORK_SLOT_KEY), frameworkKey);
45403
45481
  (0, import_node_fs68.writeFileSync)(import_node_path68.default.join(slot, SWIFT_FRAMEWORK_SLOT_ORIGIN), moduleRoot);
45482
+ } else if (swiftFrameworkSlotRelease(slot) !== release) {
45483
+ (0, import_node_fs68.writeFileSync)(import_node_path68.default.join(slot, SWIFT_FRAMEWORK_SLOT_RELEASE), release);
45404
45484
  }
45405
45485
  return stagedModule;
45406
45486
  }
@@ -45628,660 +45708,717 @@ ${cap}` : "";
45628
45708
  (0, import_node_fs68.rmSync)(requestRoot, { recursive: true, force: true });
45629
45709
  }
45630
45710
  }
45711
+ const baseRoot = root;
45712
+ const canPoolBuildRoot = !options2.intermediates && !options2.project && !options2.linkOnly && import_node_path68.default.basename(import_node_path68.default.dirname(baseRoot)) === "swift-builds";
45713
+ const buildShape = canPoolBuildRoot ? (0, import_node_crypto42.createHash)("sha256").update(
45714
+ JSON.stringify([
45715
+ frameworkKey,
45716
+ Boolean(sdkImage),
45717
+ compileTargets(input).map((target) => target.name).sort(),
45718
+ input.oneModule === true,
45719
+ input.optimize === true,
45720
+ input.unoptimized === true,
45721
+ Object.keys(input.files).sort()
45722
+ ])
45723
+ ).digest("hex").slice(0, 16) : "";
45631
45724
  return withSwiftCompileBudget(options2.timeoutMs, options2.signal, async (budget) => {
45632
- return withSwiftRootLock(
45633
- root,
45634
- async (lease) => {
45635
- if (!options2.intermediates) {
45636
- const built2 = readCompiledArtifact(import_node_path68.default.join(sharedRoot, "artifact"), hash);
45637
- if (built2) {
45638
- report("reusing verified disk artifact");
45639
- return retain(root, built2);
45640
- }
45641
- }
45642
- const swift = import_node_path68.default.join(options2.toolchainBin, "swift");
45643
- if (!(0, import_node_fs68.existsSync)(swift)) {
45644
- throw new Error(
45645
- `swift-compile: no swift.org toolchain at ${options2.toolchainBin}; install ${options2.release} and its matching wasm sdk`
45646
- );
45725
+ const stage = (message) => {
45726
+ budget.progress();
45727
+ report(message);
45728
+ };
45729
+ const runLocked = (work) => {
45730
+ if (canPoolBuildRoot) {
45731
+ (0, import_node_fs68.mkdirSync)(sharedRoot, { recursive: true });
45732
+ return withSwiftRootLock(
45733
+ sharedRoot,
45734
+ async () => {
45735
+ const built2 = readCompiledArtifact(
45736
+ import_node_path68.default.join(sharedRoot, "artifact"),
45737
+ hash
45738
+ );
45739
+ if (built2) {
45740
+ stage("reusing verified disk artifact");
45741
+ return retain(baseRoot, built2);
45742
+ }
45743
+ return withSwiftBuildRootSlot(baseRoot, buildShape, budget.signal, work);
45744
+ },
45745
+ budget.signal
45746
+ );
45747
+ }
45748
+ const waitStart = Date.now();
45749
+ return withSwiftRootLock(
45750
+ baseRoot,
45751
+ (lease) => work(baseRoot, lease, Date.now() - waitStart),
45752
+ budget.signal
45753
+ );
45754
+ };
45755
+ return runLocked(async (slotRoot, lease, waitedMs) => {
45756
+ const root2 = slotRoot;
45757
+ const layout3 = {
45758
+ root: root2,
45759
+ sources: import_node_path68.default.join(root2, "Sources", "App"),
45760
+ multi: compileTargets(input).length > 0
45761
+ };
45762
+ if (!options2.intermediates) {
45763
+ const built2 = readCompiledArtifact(import_node_path68.default.join(sharedRoot, "artifact"), hash);
45764
+ if (built2) {
45765
+ stage("reusing verified disk artifact");
45766
+ return retain(baseRoot, built2);
45647
45767
  }
45648
- const unoptimized = input.unoptimized === true;
45649
- const withFrameworkLock = (work) => distribution ? work(null) : withSwiftFrameworkSlot(
45650
- frameworkKey,
45651
- moduleRoot,
45768
+ }
45769
+ if (waitedMs >= 1e3)
45770
+ report(`acquired build root ${import_node_path68.default.basename(root2)} after ${waitedMs}ms`);
45771
+ if (canPoolBuildRoot) {
45772
+ refreshSwiftCacheHold(root2);
45773
+ (0, import_node_fs68.writeFileSync)(import_node_path68.default.join(root2, SWIFT_BUILD_ROOT_SHAPE), buildShape);
45774
+ }
45775
+ const swift = import_node_path68.default.join(options2.toolchainBin, "swift");
45776
+ if (!(0, import_node_fs68.existsSync)(swift)) {
45777
+ throw new Error(
45778
+ `swift-compile: no swift.org toolchain at ${options2.toolchainBin}; install ${options2.release} and its matching wasm sdk`
45779
+ );
45780
+ }
45781
+ const unoptimized = input.unoptimized === true;
45782
+ const withFrameworkLock = (work) => distribution ? work(null) : withSwiftFrameworkSlot(
45783
+ frameworkKey,
45784
+ options2.release,
45785
+ moduleRoot,
45786
+ budget.signal,
45787
+ work,
45788
+ unoptimized
45789
+ );
45790
+ const baseBuildEnv = options2.project?.env ? {
45791
+ ...options2.project.env,
45792
+ // shipped host plugins resolve against the selected compiler's runtime.
45793
+ ...process.platform === "linux" ? {
45794
+ LD_LIBRARY_PATH: [
45795
+ import_node_path68.default.resolve(options2.toolchainBin, "../lib/swift/linux"),
45796
+ import_node_path68.default.resolve(options2.toolchainBin, "../lib/swift/host"),
45797
+ process.env.LD_LIBRARY_PATH
45798
+ ].filter(Boolean).join(":")
45799
+ } : {},
45800
+ PEACH_DEFER_WASM_LINK: "1"
45801
+ } : swiftCompilerBaseEnv(options2.toolchainBin, process.env);
45802
+ const {
45803
+ frameworkRoot,
45804
+ compileFrameworkRoot,
45805
+ macroPlugins,
45806
+ sdk: sdk2,
45807
+ icu,
45808
+ prebuilt,
45809
+ readHold
45810
+ } = await withFrameworkLock(async (slot, frameworkLease) => {
45811
+ budget.startCompile();
45812
+ if (slot && swiftFrameworkSlotKey(slot) !== frameworkKey)
45813
+ await waitForNoSwiftRootReaders(slot, budget.signal);
45814
+ const frameworkRoot2 = mirrorDistribution ? syncSwiftDistributionMirror(root2, moduleRoot, mirrorDistribution) : distribution ? moduleRoot : stageFrameworkSource(moduleRoot, slot, frameworkKey, options2.release);
45815
+ if (!swiftModuleDigest(frameworkRoot2).equals(moduleDigest))
45816
+ throw new Error("Swift staged project source differs from the caller");
45817
+ stage("preparing compiler plugins");
45818
+ const macroPlugins2 = await ensureMacroPlugins(
45819
+ frameworkRoot2,
45820
+ options2.toolchainBin,
45821
+ options2.release,
45652
45822
  budget.signal,
45653
- work,
45654
- unoptimized
45823
+ frameworkLease
45655
45824
  );
45656
- const baseBuildEnv = options2.project?.env ? {
45657
- ...options2.project.env,
45658
- // shipped host plugins resolve against the selected compiler's runtime.
45659
- ...process.platform === "linux" ? {
45660
- LD_LIBRARY_PATH: [
45661
- import_node_path68.default.resolve(options2.toolchainBin, "../lib/swift/linux"),
45662
- import_node_path68.default.resolve(options2.toolchainBin, "../lib/swift/host"),
45663
- process.env.LD_LIBRARY_PATH
45664
- ].filter(Boolean).join(":")
45665
- } : {},
45666
- PEACH_DEFER_WASM_LINK: "1"
45667
- } : swiftCompilerBaseEnv(options2.toolchainBin, process.env);
45668
- const {
45825
+ const compileFrameworkRoot2 = distribution ? swiftDistributionCompileView(frameworkRoot2, distribution) : frameworkRoot2;
45826
+ const sdk3 = swiftModuleSdk(frameworkRoot2).wasmSdkId;
45827
+ const icu2 = options2.linkOnly ? null : swiftIcuAsset(options2.toolchainBin, sdk3);
45828
+ let prebuilt2;
45829
+ if (!distribution) {
45830
+ stage("compiling framework products");
45831
+ prebuilt2 = await buildFrameworkProducts(slot, {
45832
+ moduleRoot: frameworkRoot2,
45833
+ frameworkKey,
45834
+ input,
45835
+ swift,
45836
+ sdk: sdk3,
45837
+ toolchainBin: options2.toolchainBin,
45838
+ plugins: macroPlugins2,
45839
+ buildOptions: {
45840
+ env: baseBuildEnv,
45841
+ maxBuffer: 64 * 1024 * 1024,
45842
+ signal: budget.signal,
45843
+ onOutput: budget.progress,
45844
+ lease,
45845
+ frameworkLease
45846
+ }
45847
+ });
45848
+ }
45849
+ const readHold2 = slot ? acquireSwiftRootReadHold(slot) : void 0;
45850
+ return {
45851
+ frameworkRoot: frameworkRoot2,
45852
+ compileFrameworkRoot: compileFrameworkRoot2,
45853
+ macroPlugins: macroPlugins2,
45854
+ sdk: sdk3,
45855
+ icu: icu2,
45856
+ prebuilt: prebuilt2,
45857
+ readHold: readHold2
45858
+ };
45859
+ });
45860
+ const buildOptions = {
45861
+ env: baseBuildEnv,
45862
+ maxBuffer: 64 * 1024 * 1024,
45863
+ signal: budget.signal,
45864
+ onOutput: budget.progress,
45865
+ lease
45866
+ };
45867
+ try {
45868
+ if (options2.project) removeProjectLinks(root2);
45869
+ const packageHostMacros = process.platform === "linux" ? input.packageHostMacros : void 0;
45870
+ if (retireStaleSwiftLink(
45871
+ root2,
45872
+ swiftLinkStamp({
45873
+ frameworkKey: `${options2.release}\0${Boolean(distribution)}\0${swiftModuleSdk(frameworkRoot).wasmSdkId}`,
45874
+ packageHostMacros
45875
+ }),
45876
+ swiftLinkStamp({
45877
+ // a distribution's objects reach only the deferred link, and
45878
+ // the root's mirror keeps its compile inputs at fixed paths
45879
+ frameworkKey: distribution ? `${options2.release}\0${distribution.wasmSdkChecksum}` : frameworkKey,
45880
+ prebuilt,
45881
+ packageHostMacros
45882
+ }),
45883
+ Boolean(options2.linkOnly)
45884
+ ))
45885
+ stage("framework revision changed; rebuilding the app link");
45886
+ const nativeToolset = needsNativeToolset(input, prebuilt);
45887
+ const preparation = writeSwiftProject(
45888
+ layout3,
45889
+ input,
45669
45890
  frameworkRoot,
45670
- compileFrameworkRoot,
45671
- macroPlugins,
45672
- sdk: sdk2,
45673
- icu,
45674
45891
  prebuilt,
45675
- readHold
45676
- } = await withFrameworkLock(async (slot, frameworkLease) => {
45677
- budget.startCompile();
45678
- if (slot && swiftFrameworkSlotKey(slot) !== frameworkKey)
45679
- await waitForNoSwiftRootReaders(slot, budget.signal);
45680
- const frameworkRoot2 = mirrorDistribution ? syncSwiftDistributionMirror(root, moduleRoot, mirrorDistribution) : distribution ? moduleRoot : stageFrameworkSource(moduleRoot, slot, frameworkKey, options2.release);
45681
- if (!swiftModuleDigest(frameworkRoot2).equals(moduleDigest))
45682
- throw new Error("Swift staged project source differs from the caller");
45683
- report("preparing compiler plugins");
45684
- const macroPlugins2 = await ensureMacroPlugins(
45685
- frameworkRoot2,
45686
- options2.toolchainBin,
45687
- options2.release,
45688
- budget.signal,
45689
- frameworkLease
45892
+ !options2.project,
45893
+ options2.project ? false : options2.objcPrebuiltStage ?? (options2.intermediates ? false : void 0)
45894
+ );
45895
+ const productFile = import_node_path68.default.join(frameworkRoot, SWIFT_FRAMEWORK_PRODUCT_FILE);
45896
+ writeSwiftAutolinkLinker(
45897
+ root2,
45898
+ options2.toolchainBin,
45899
+ (0, import_node_fs68.existsSync)(productFile) ? [
45900
+ v6.parse(
45901
+ swiftFrameworkProductSchema,
45902
+ JSON.parse((0, import_node_fs68.readFileSync)(productFile, "utf8"))
45903
+ ).product.name
45904
+ ] : []
45905
+ );
45906
+ const compiler = preparation.targetToolset ? { CC: import_node_path68.default.join(root2, CLANG_TARGET_MODULE_WRAPPER) } : {};
45907
+ if (packageHostMacros?.length) {
45908
+ const swiftc = import_node_path68.default.join(root2, SWIFT_HOST_COMPILER_WRAPPER);
45909
+ writeBuildFile(
45910
+ swiftc,
45911
+ [
45912
+ "#!/bin/sh",
45913
+ "target=",
45914
+ "module=",
45915
+ "compile=",
45916
+ "previous=",
45917
+ "for argument do",
45918
+ ' case "$previous" in -target) target=$argument ;; -module-name) module=$argument ;; esac',
45919
+ ' case "$argument" in -c|-emit-module|-scan-dependencies|-typecheck) compile=1 ;; esac',
45920
+ " previous=$argument",
45921
+ "done",
45922
+ 'case "$target/$compile" in',
45923
+ " *-*-linux*/1)",
45924
+ ' case ",$PEACH_SWIFT_HOST_MACROS," in',
45925
+ ' *",$module,"*) set -- "$@" -Xfrontend -import-module -Xfrontend Foundation ;;',
45926
+ " esac ;;",
45927
+ "esac",
45928
+ 'exec "$PEACH_SWIFTC" "$@"',
45929
+ ""
45930
+ ].join("\n")
45690
45931
  );
45691
- const compileFrameworkRoot2 = distribution ? swiftDistributionCompileView(frameworkRoot2, distribution) : frameworkRoot2;
45692
- const sdk3 = swiftModuleSdk(frameworkRoot2).wasmSdkId;
45693
- const icu2 = options2.linkOnly ? null : swiftIcuAsset(options2.toolchainBin, sdk3);
45694
- let prebuilt2;
45695
- if (!distribution) {
45696
- report("compiling framework products");
45697
- prebuilt2 = await buildFrameworkProducts(slot, {
45698
- moduleRoot: frameworkRoot2,
45699
- frameworkKey,
45700
- input,
45701
- swift,
45702
- sdk: sdk3,
45703
- toolchainBin: options2.toolchainBin,
45704
- plugins: macroPlugins2,
45705
- buildOptions: {
45706
- env: baseBuildEnv,
45707
- maxBuffer: 64 * 1024 * 1024,
45708
- signal: budget.signal,
45709
- lease,
45710
- frameworkLease
45711
- }
45712
- });
45932
+ (0, import_node_fs68.chmodSync)(swiftc, 493);
45933
+ compiler.SWIFT_EXEC = swiftc;
45934
+ compiler.PEACH_SWIFT_HOST_MACROS = packageHostMacros.join(",");
45935
+ compiler.PEACH_SWIFTC = import_node_path68.default.join(options2.toolchainBin, "swiftc");
45936
+ }
45937
+ const projectProcess = options2.project ? prepareSwiftProjectProcess(root2, options2.project) : void 0;
45938
+ const temporaryDirectory = projectProcess ? void 0 : import_node_path68.default.join(root2, ".build", "peach-compiler-tmp");
45939
+ const appOptions = projectProcess ? {
45940
+ ...buildOptions,
45941
+ uid: projectProcess.uid,
45942
+ gid: projectProcess.gid,
45943
+ confined: { ...projectProcess.env, ...compiler }
45944
+ } : {
45945
+ ...buildOptions,
45946
+ temporaryDirectory,
45947
+ env: {
45948
+ ...buildOptions.env,
45949
+ ...preparation.usesObjcPrebuilt && process.env.PEACH_HOME !== void 0 ? { PEACH_HOME: process.env.PEACH_HOME } : {},
45950
+ ...compiler
45713
45951
  }
45714
- const readHold2 = slot ? acquireSwiftRootReadHold(slot) : void 0;
45715
- return {
45716
- frameworkRoot: frameworkRoot2,
45717
- compileFrameworkRoot: compileFrameworkRoot2,
45718
- macroPlugins: macroPlugins2,
45719
- sdk: sdk3,
45720
- icu: icu2,
45721
- prebuilt: prebuilt2,
45722
- readHold: readHold2
45723
- };
45724
- });
45725
- const buildOptions = {
45726
- env: baseBuildEnv,
45727
- maxBuffer: 64 * 1024 * 1024,
45728
- signal: budget.signal,
45729
- lease
45730
45952
  };
45731
- try {
45732
- if (options2.project) removeProjectLinks(root);
45733
- const packageHostMacros = process.platform === "linux" ? input.packageHostMacros : void 0;
45734
- if (retireStaleSwiftLink(
45735
- root,
45736
- swiftLinkStamp({
45737
- frameworkKey: `${options2.release}\0${Boolean(distribution)}\0${swiftModuleSdk(frameworkRoot).wasmSdkId}`,
45738
- packageHostMacros
45739
- }),
45740
- swiftLinkStamp({
45741
- // a distribution's objects reach only the deferred link, and
45742
- // the root's mirror keeps its compile inputs at fixed paths
45743
- frameworkKey: distribution ? `${options2.release}\0${distribution.wasmSdkChecksum}` : frameworkKey,
45744
- prebuilt,
45745
- packageHostMacros
45746
- }),
45747
- Boolean(options2.linkOnly)
45748
- ))
45749
- report("framework revision changed; rebuilding the app link");
45750
- const nativeToolset = needsNativeToolset(input, prebuilt);
45751
- const preparation = writeSwiftProject(
45752
- layout2,
45753
- input,
45754
- frameworkRoot,
45755
- prebuilt,
45756
- !options2.project,
45757
- options2.project ? false : options2.objcPrebuiltStage ?? (options2.intermediates ? false : void 0)
45953
+ const unprepared = preparation.targetFailures.map(
45954
+ (failure2) => `error: target ${failure2}`
45955
+ );
45956
+ const forwarders = /* @__PURE__ */ new Map();
45957
+ for (const [file, text7] of Object.entries(input.files)) {
45958
+ const parents = /^#include "((?:\.\.\/)+)[^"\n]+"\n$/.exec(text7)?.[1];
45959
+ if (!parents) continue;
45960
+ const directory2 = import_node_path68.default.posix.dirname(file);
45961
+ forwarders.set(
45962
+ `${import_node_path68.default.join(root2, directory2)}/${parents.slice(0, -1)}`,
45963
+ import_node_path68.default.posix.join("build", directory2, parents).replace(/\/$/, "")
45758
45964
  );
45759
- const productFile = import_node_path68.default.join(frameworkRoot, SWIFT_FRAMEWORK_PRODUCT_FILE);
45760
- writeSwiftAutolinkLinker(
45761
- root,
45762
- options2.toolchainBin,
45763
- (0, import_node_fs68.existsSync)(productFile) ? [
45764
- v6.parse(
45765
- swiftFrameworkProductSchema,
45766
- JSON.parse((0, import_node_fs68.readFileSync)(productFile, "utf8"))
45767
- ).product.name
45768
- ] : []
45965
+ }
45966
+ const jobs = swiftCompilerJobs();
45967
+ const incrementalPreview = sdkImage !== void 0 && !guestGraph && !options2.project && !input.optimize && !input.unoptimized;
45968
+ const perFile = input.unoptimized || incrementalPreview;
45969
+ const buildArgs = [
45970
+ "build",
45971
+ ...projectProcess?.cacheOptions ?? swiftPackageCacheOptions(),
45972
+ "--build-system",
45973
+ "native",
45974
+ "-j",
45975
+ String(jobs),
45976
+ "--package-path",
45977
+ root2,
45978
+ ...swiftCompileSdkOptions(frameworkRoot, options2.toolchainBin),
45979
+ ...swiftObjCSelectorOptions(frameworkRoot),
45980
+ "--swift-sdk",
45981
+ sdk2,
45982
+ ...preparation.targetToolset ? ["--toolset", import_node_path68.default.join(root2, ".peach-target-toolset.json")] : [],
45983
+ "-c",
45984
+ "release",
45985
+ ...input.unoptimized ? ["-Xswiftc", "-Onone"] : [],
45986
+ ...perFile ? [
45987
+ "-Xswiftc",
45988
+ "-no-whole-module-optimization",
45989
+ "-Xswiftc",
45990
+ "-j",
45991
+ "-Xswiftc",
45992
+ String(jobs)
45993
+ ] : [],
45994
+ ...incrementalPreview ? ["-Xswiftc", "-incremental", "-Xswiftc", "-enable-batch-mode"] : [],
45995
+ // the mirror finds a changed sdk header's readers in their
45996
+ // dependency files, which omit system headers by default
45997
+ ...mirrorDistribution ? ["-Xswiftc", "-track-system-dependencies"] : [],
45998
+ // the link strips debug info, so none is generated (as for the framework).
45999
+ // keep -num-threads fixed across caller core caps so llbuild does not
46000
+ // rebuild every target when callers alternate --cores, and bound backend
46001
+ // fan-out under high -j.
46002
+ "-Xswiftc",
46003
+ "-gnone",
46004
+ ...incrementalPreview ? [] : [
46005
+ "-Xswiftc",
46006
+ "-num-threads",
46007
+ "-Xswiftc",
46008
+ String(perFile ? 1 : Math.min(8, import_node_os14.default.availableParallelism()))
46009
+ ],
46010
+ ...swiftReproducibleBuildFlags([
46011
+ [import_node_path68.default.dirname(options2.toolchainBin), "toolchain"],
46012
+ [compileFrameworkRoot, "framework"],
46013
+ [root2, "build"],
46014
+ ...forwarders
46015
+ ]).flatMap((flag, index, flags) => {
46016
+ if (!nativeToolset || !flag.startsWith("-ffile-prefix-map="))
46017
+ return [flag];
46018
+ const toolchainDir = import_node_path68.default.dirname(options2.toolchainBin);
46019
+ let mapped = flag;
46020
+ for (const [dir, target] of [
46021
+ [root2, "/peach/build"],
46022
+ [compileFrameworkRoot, "/peach/framework"],
46023
+ [(0, import_node_fs68.realpathSync)(compileFrameworkRoot), "/peach/framework"],
46024
+ [toolchainDir, "/peach/toolchain"],
46025
+ [(0, import_node_fs68.realpathSync)(toolchainDir), "/peach/toolchain"]
46026
+ ]) {
46027
+ mapped = mapped.replaceAll(dir, target);
46028
+ }
46029
+ const [, from, to] = /^-ffile-prefix-map=([^=]+)=(.+)$/.exec(mapped) ?? [];
46030
+ const tool = flags[index - 1];
46031
+ return mapped !== flag && from !== to ? [flag, tool, mapped] : [flag];
46032
+ }),
46033
+ ...macroPlugins.libraries.flatMap((plugin) => [
46034
+ "-Xswiftc",
46035
+ "-load-plugin-library",
46036
+ "-Xswiftc",
46037
+ plugin
46038
+ ]),
46039
+ ...macroPlugins.executables.flatMap((plugin) => [
46040
+ "-Xswiftc",
46041
+ "-load-plugin-executable",
46042
+ "-Xswiftc",
46043
+ `${plugin}#ExpoModulesMacros`
46044
+ ])
46045
+ ];
46046
+ const linked = builtArtifact(layout3);
46047
+ (0, import_node_fs68.rmSync)(import_node_path68.default.join(root2, ".peach-link.rsp"), { force: true });
46048
+ if (options2.linkOnly || (0, import_node_fs68.existsSync)(linked) && (0, import_node_fs68.statSync)(linked).size <= 8)
46049
+ (0, import_node_fs68.rmSync)(linked, { force: true });
46050
+ stage("compiling and linking Swift modules");
46051
+ const frameworkInterfaces = /* @__PURE__ */ new Map();
46052
+ const sdkFrameworks = import_node_path68.default.join(
46053
+ swiftSdkPaths(frameworkRoot, options2.toolchainBin).darwin,
46054
+ "System/Library/Frameworks"
46055
+ );
46056
+ const generatedInterface = (source) => withoutImportedSdkEnumForwards(
46057
+ clangInterfaceHeader((0, import_node_fs68.readFileSync)(source, "utf8"), frameworkRoot),
46058
+ sdkObjCDeclarationOwners(sdkFrameworks)
46059
+ );
46060
+ const nativeDeclarations = /* @__PURE__ */ new Map();
46061
+ const nativeHeaders = Object.entries(input.files).filter(([name3]) => name3.endsWith(".h") && !name3.endsWith("-Swift.h")).map(([, source]) => source);
46062
+ for (const [file, contents2] of Object.entries(input.files)) {
46063
+ if (!file.endsWith(".modulemap")) continue;
46064
+ const name3 = moduleMapName(contents2);
46065
+ const umbrella = /\bumbrella\s+header\s+"([^"]+)"/.exec(contents2)?.[1];
46066
+ if (!name3 || !umbrella) continue;
46067
+ const header = input.files[import_node_path68.default.posix.join(import_node_path68.default.posix.dirname(file), umbrella)];
46068
+ if (header === void 0) continue;
46069
+ const included = new Set(
46070
+ [
46071
+ ...header.matchAll(/^\s*#\s*(?:import|include)\s*[<"]([^">]+)[">]/gm)
46072
+ ].map((match) => import_node_path68.default.posix.basename(match[1]))
45769
46073
  );
45770
- const compiler = preparation.targetToolset ? { CC: import_node_path68.default.join(root, CLANG_TARGET_MODULE_WRAPPER) } : {};
45771
- if (packageHostMacros?.length) {
45772
- const swiftc = import_node_path68.default.join(root, SWIFT_HOST_COMPILER_WRAPPER);
45773
- writeBuildFile(
45774
- swiftc,
45775
- [
45776
- "#!/bin/sh",
45777
- "target=",
45778
- "module=",
45779
- "compile=",
45780
- "previous=",
45781
- "for argument do",
45782
- ' case "$previous" in -target) target=$argument ;; -module-name) module=$argument ;; esac',
45783
- ' case "$argument" in -c|-emit-module|-scan-dependencies|-typecheck) compile=1 ;; esac',
45784
- " previous=$argument",
45785
- "done",
45786
- 'case "$target/$compile" in',
45787
- " *-*-linux*/1)",
45788
- ' case ",$PEACH_SWIFT_HOST_MACROS," in',
45789
- ' *",$module,"*) set -- "$@" -Xfrontend -import-module -Xfrontend Foundation ;;',
45790
- " esac ;;",
45791
- "esac",
45792
- 'exec "$PEACH_SWIFTC" "$@"',
45793
- ""
45794
- ].join("\n")
45795
- );
45796
- (0, import_node_fs68.chmodSync)(swiftc, 493);
45797
- compiler.SWIFT_EXEC = swiftc;
45798
- compiler.PEACH_SWIFT_HOST_MACROS = packageHostMacros.join(",");
45799
- compiler.PEACH_SWIFTC = import_node_path68.default.join(options2.toolchainBin, "swiftc");
46074
+ const declarations = nativeDeclarations.get(name3) ?? /* @__PURE__ */ new Set();
46075
+ for (const declaration of swiftInterfaceDeclarations(header))
46076
+ declarations.add(declaration);
46077
+ for (const [candidate, source] of Object.entries(input.files))
46078
+ if (included.has(import_node_path68.default.posix.basename(candidate)))
46079
+ for (const declaration of swiftInterfaceDeclarations(source))
46080
+ declarations.add(declaration);
46081
+ nativeDeclarations.set(name3, declarations);
46082
+ }
46083
+ const frameworkInterface = (name3) => {
46084
+ if (frameworkInterfaces.has(name3)) return frameworkInterfaces.get(name3);
46085
+ const source = distribution ? import_node_path68.default.join(frameworkRoot, "modules", `${name3}-Swift.h`) : prebuilt.objcHeaders.get(name3);
46086
+ if (!source || !(0, import_node_fs68.existsSync)(source)) {
46087
+ frameworkInterfaces.set(name3, null);
46088
+ return null;
45800
46089
  }
45801
- const projectProcess = options2.project ? prepareSwiftProjectProcess(root, options2.project) : void 0;
45802
- const temporaryDirectory = projectProcess ? void 0 : import_node_path68.default.join(root, ".build", "peach-compiler-tmp");
45803
- const appOptions = projectProcess ? {
45804
- ...buildOptions,
45805
- uid: projectProcess.uid,
45806
- gid: projectProcess.gid,
45807
- confined: { ...projectProcess.env, ...compiler }
45808
- } : {
45809
- ...buildOptions,
45810
- temporaryDirectory,
45811
- env: {
45812
- ...buildOptions.env,
45813
- ...preparation.usesObjcPrebuilt && process.env.PEACH_HOME !== void 0 ? { PEACH_HOME: process.env.PEACH_HOME } : {},
45814
- ...compiler
45815
- }
45816
- };
45817
- const unprepared = preparation.targetFailures.map(
45818
- (failure2) => `error: target ${failure2}`
46090
+ const headers = import_node_path68.default.join(sdkFrameworks, `${name3}.framework/Headers`);
46091
+ const declared = /* @__PURE__ */ new Set();
46092
+ if ((0, import_node_fs68.existsSync)(headers)) {
46093
+ for (const file of (0, import_node_fs68.readdirSync)(headers, {
46094
+ recursive: true,
46095
+ encoding: "utf8"
46096
+ }))
46097
+ if (file.endsWith(".h"))
46098
+ for (const name4 of swiftInterfaceDeclarations(
46099
+ (0, import_node_fs68.readFileSync)(import_node_path68.default.join(headers, file), "utf8")
46100
+ ))
46101
+ declared.add(name4);
46102
+ }
46103
+ for (const declaration of nativeDeclarations.get(name3) ?? [])
46104
+ declared.add(declaration);
46105
+ const own2 = withoutSwiftDeclarations(
46106
+ generatedInterface(source),
46107
+ declared,
46108
+ nativeDeclarations.has(name3) ? `@import ${name3};` : `#import <${name3}/${name3}.h>`
45819
46109
  );
45820
- const forwarders = /* @__PURE__ */ new Map();
45821
- for (const [file, text7] of Object.entries(input.files)) {
45822
- const parents = /^#include "((?:\.\.\/)+)[^"\n]+"\n$/.exec(text7)?.[1];
45823
- if (!parents) continue;
45824
- const directory2 = import_node_path68.default.posix.dirname(file);
45825
- forwarders.set(
45826
- `${import_node_path68.default.join(root, directory2)}/${parents.slice(0, -1)}`,
45827
- import_node_path68.default.posix.join("build", directory2, parents).replace(/\/$/, "")
45828
- );
46110
+ const owners = sdkObjCDeclarationOwners(sdkFrameworks);
46111
+ const foreign = /* @__PURE__ */ new Map();
46112
+ for (const declaration of [
46113
+ ...swiftInterfaceDeclarations(own2),
46114
+ ...objcEnumerations(own2),
46115
+ ...[...own2.matchAll(/^\s*SWIFT_EXTERN\b[^(\n]*?\b(\w+)\s*\(/gm)].map(
46116
+ (match) => match[1]
46117
+ )
46118
+ ]) {
46119
+ const owner = owners.get(declaration);
46120
+ if (owner && owner !== name3) foreign.set(declaration, owner);
45829
46121
  }
45830
- const jobs = swiftCompilerJobs();
45831
- const incrementalPreview = sdkImage !== void 0 && !guestGraph && !options2.project && !input.optimize && !input.unoptimized;
45832
- const perFile = input.unoptimized || incrementalPreview;
45833
- const buildArgs = [
45834
- "build",
45835
- ...projectProcess?.cacheOptions ?? swiftPackageCacheOptions(),
45836
- "--build-system",
45837
- "native",
45838
- "-j",
45839
- String(jobs),
45840
- "--package-path",
45841
- root,
45842
- ...swiftCompileSdkOptions(frameworkRoot, options2.toolchainBin),
45843
- ...swiftObjCSelectorOptions(frameworkRoot),
45844
- "--swift-sdk",
45845
- sdk2,
45846
- ...preparation.targetToolset ? ["--toolset", import_node_path68.default.join(root, ".peach-target-toolset.json")] : [],
45847
- "-c",
45848
- "release",
45849
- ...input.unoptimized ? ["-Xswiftc", "-Onone"] : [],
45850
- ...perFile ? [
45851
- "-Xswiftc",
45852
- "-no-whole-module-optimization",
45853
- "-Xswiftc",
45854
- "-j",
45855
- "-Xswiftc",
45856
- String(jobs)
45857
- ] : [],
45858
- ...incrementalPreview ? ["-Xswiftc", "-incremental", "-Xswiftc", "-enable-batch-mode"] : [],
45859
- // the mirror finds a changed sdk header's readers in their
45860
- // dependency files, which omit system headers by default
45861
- ...mirrorDistribution ? ["-Xswiftc", "-track-system-dependencies"] : [],
45862
- // the link strips debug info, so none is generated (as for the framework).
45863
- // keep -num-threads fixed across caller core caps so llbuild does not
45864
- // rebuild every target when callers alternate --cores, and bound backend
45865
- // fan-out under high -j.
45866
- "-Xswiftc",
45867
- "-gnone",
45868
- ...incrementalPreview ? [] : [
45869
- "-Xswiftc",
45870
- "-num-threads",
45871
- "-Xswiftc",
45872
- String(perFile ? 1 : Math.min(8, import_node_os14.default.availableParallelism()))
45873
- ],
45874
- ...swiftReproducibleBuildFlags([
45875
- [import_node_path68.default.dirname(options2.toolchainBin), "toolchain"],
45876
- [compileFrameworkRoot, "framework"],
45877
- [root, "build"],
45878
- ...forwarders
45879
- ]).flatMap((flag, index, flags) => {
45880
- if (!nativeToolset || !flag.startsWith("-ffile-prefix-map="))
45881
- return [flag];
45882
- const toolchainDir = import_node_path68.default.dirname(options2.toolchainBin);
45883
- let mapped = flag;
45884
- for (const [dir, target] of [
45885
- [root, "/peach/build"],
45886
- [compileFrameworkRoot, "/peach/framework"],
45887
- [(0, import_node_fs68.realpathSync)(compileFrameworkRoot), "/peach/framework"],
45888
- [toolchainDir, "/peach/toolchain"],
45889
- [(0, import_node_fs68.realpathSync)(toolchainDir), "/peach/toolchain"]
45890
- ]) {
45891
- mapped = mapped.replaceAll(dir, target);
45892
- }
45893
- const [, from, to] = /^-ffile-prefix-map=([^=]+)=(.+)$/.exec(mapped) ?? [];
45894
- const tool = flags[index - 1];
45895
- return mapped !== flag && from !== to ? [flag, tool, mapped] : [flag];
45896
- }),
45897
- ...macroPlugins.libraries.flatMap((plugin) => [
45898
- "-Xswiftc",
45899
- "-load-plugin-library",
45900
- "-Xswiftc",
45901
- plugin
45902
- ]),
45903
- ...macroPlugins.executables.flatMap((plugin) => [
45904
- "-Xswiftc",
45905
- "-load-plugin-executable",
45906
- "-Xswiftc",
45907
- `${plugin}#ExpoModulesMacros`
45908
- ])
45909
- ];
45910
- const linked = builtArtifact(layout2);
45911
- (0, import_node_fs68.rmSync)(import_node_path68.default.join(root, ".peach-link.rsp"), { force: true });
45912
- if (options2.linkOnly || (0, import_node_fs68.existsSync)(linked) && (0, import_node_fs68.statSync)(linked).size <= 8)
45913
- (0, import_node_fs68.rmSync)(linked, { force: true });
45914
- report("compiling and linking Swift modules");
45915
- const frameworkInterfaces = /* @__PURE__ */ new Map();
45916
- const sdkFrameworks = import_node_path68.default.join(
45917
- swiftSdkPaths(frameworkRoot, options2.toolchainBin).darwin,
45918
- "System/Library/Frameworks"
46122
+ const header = foreign.size ? withoutSwiftDeclarations(
46123
+ own2,
46124
+ new Set(foreign.keys()),
46125
+ [...new Set(foreign.values())].map((owner) => `#import <${owner}/${owner}.h>`).join("\n")
46126
+ ) : own2;
46127
+ const value = {
46128
+ file: import_node_path68.default.join(root2, ".build/peach-framework-objc", `${name3}-Swift.h`),
46129
+ header,
46130
+ module: (0, import_node_fs68.existsSync)(headers)
46131
+ };
46132
+ frameworkInterfaces.set(name3, value);
46133
+ writeBuildFile(
46134
+ value.file,
46135
+ ((0, import_node_fs68.existsSync)(import_node_path68.default.join(headers, `${name3}.h`)) ? `#import <${name3}/${name3}.h>
46136
+ ` : "") + swiftHeaderWithSuperclassImports(header, frameworkInterface)
45919
46137
  );
45920
- const generatedInterface = (source) => withoutImportedSdkEnumForwards(
45921
- clangInterfaceHeader((0, import_node_fs68.readFileSync)(source, "utf8"), frameworkRoot),
45922
- sdkObjCDeclarationOwners(sdkFrameworks)
46138
+ return value;
46139
+ };
46140
+ const headerPaths = (producer) => {
46141
+ const stem2 = import_node_path68.default.join(
46142
+ root2,
46143
+ ".build",
46144
+ "peach-cxx-headers",
46145
+ `${producer}-Swift`
45923
46146
  );
45924
- const nativeDeclarations = /* @__PURE__ */ new Map();
45925
- const nativeHeaders = Object.entries(input.files).filter(([name3]) => name3.endsWith(".h") && !name3.endsWith("-Swift.h")).map(([, source]) => source);
45926
- for (const [file, contents2] of Object.entries(input.files)) {
45927
- if (!file.endsWith(".modulemap")) continue;
45928
- const name3 = moduleMapName(contents2);
45929
- const umbrella = /\bumbrella\s+header\s+"([^"]+)"/.exec(contents2)?.[1];
45930
- if (!name3 || !umbrella) continue;
45931
- const header = input.files[import_node_path68.default.posix.join(import_node_path68.default.posix.dirname(file), umbrella)];
45932
- if (header === void 0) continue;
45933
- const included = new Set(
45934
- [
45935
- ...header.matchAll(/^\s*#\s*(?:import|include)\s*[<"]([^">]+)[">]/gm)
45936
- ].map((match) => import_node_path68.default.posix.basename(match[1]))
45937
- );
45938
- const declarations = nativeDeclarations.get(name3) ?? /* @__PURE__ */ new Set();
45939
- for (const declaration of swiftInterfaceDeclarations(header))
45940
- declarations.add(declaration);
45941
- for (const [candidate, source] of Object.entries(input.files))
45942
- if (included.has(import_node_path68.default.posix.basename(candidate)))
45943
- for (const declaration of swiftInterfaceDeclarations(source))
45944
- declarations.add(declaration);
45945
- nativeDeclarations.set(name3, declarations);
45946
- }
45947
- const frameworkInterface = (name3) => {
45948
- if (frameworkInterfaces.has(name3)) return frameworkInterfaces.get(name3);
45949
- const source = distribution ? import_node_path68.default.join(frameworkRoot, "modules", `${name3}-Swift.h`) : prebuilt.objcHeaders.get(name3);
45950
- if (!source || !(0, import_node_fs68.existsSync)(source)) {
45951
- frameworkInterfaces.set(name3, null);
45952
- return null;
45953
- }
45954
- const headers = import_node_path68.default.join(sdkFrameworks, `${name3}.framework/Headers`);
45955
- const declared = /* @__PURE__ */ new Set();
45956
- if ((0, import_node_fs68.existsSync)(headers)) {
45957
- for (const file of (0, import_node_fs68.readdirSync)(headers, {
45958
- recursive: true,
45959
- encoding: "utf8"
45960
- }))
45961
- if (file.endsWith(".h"))
45962
- for (const name4 of swiftInterfaceDeclarations(
45963
- (0, import_node_fs68.readFileSync)(import_node_path68.default.join(headers, file), "utf8")
45964
- ))
45965
- declared.add(name4);
45966
- }
45967
- for (const declaration of nativeDeclarations.get(name3) ?? [])
45968
- declared.add(declaration);
45969
- const own2 = withoutSwiftDeclarations(
45970
- generatedInterface(source),
45971
- declared,
45972
- nativeDeclarations.has(name3) ? `@import ${name3};` : `#import <${name3}/${name3}.h>`
45973
- );
45974
- const owners = sdkObjCDeclarationOwners(sdkFrameworks);
45975
- const foreign = /* @__PURE__ */ new Map();
45976
- for (const declaration of [
45977
- ...swiftInterfaceDeclarations(own2),
45978
- ...objcEnumerations(own2),
45979
- ...[...own2.matchAll(/^\s*SWIFT_EXTERN\b[^(\n]*?\b(\w+)\s*\(/gm)].map(
45980
- (match) => match[1]
45981
- )
45982
- ]) {
45983
- const owner = owners.get(declaration);
45984
- if (owner && owner !== name3) foreign.set(declaration, owner);
46147
+ return { producer, original: `${stem2}.original.h`, emitted: `${stem2}.h` };
46148
+ };
46149
+ const publishHeader = ({
46150
+ producer,
46151
+ original,
46152
+ emitted
46153
+ }) => {
46154
+ const generated = generatedInterface(original);
46155
+ writeBuildFile(
46156
+ emitted,
46157
+ withoutSwiftDeclarations(
46158
+ swiftHeaderWithSuperclassImports(generated, frameworkInterface),
46159
+ /* @__PURE__ */ new Set([
46160
+ ...preparation.nativeHeaderDeclarations[producer] ?? [],
46161
+ ...nativelyDeclaredFunctions(generated, nativeHeaders)
46162
+ ]),
46163
+ `#import <${producer}/${producer}.h>`
46164
+ )
46165
+ );
46166
+ };
46167
+ const recipe2 = inputHash.copy().update(
46168
+ distribution ? swiftCompileSurfaceDigest(frameworkRoot) : moduleDigest
46169
+ ).update((0, import_node_fs68.readFileSync)(import_node_path68.default.join(root2, "Package.swift"))).update(JSON.stringify(buildArgs)).digest("hex");
46170
+ const runApp = async (compiler2) => {
46171
+ const optionsWithCompiler = compiler2 ? { ...appOptions, env: { ...appOptions.env, ...compiler2 } } : appOptions;
46172
+ const stages = [
46173
+ ...(preparation.nativePrerequisiteTargets ?? []).map((target) => ({
46174
+ target,
46175
+ producers: []
46176
+ })),
46177
+ ...preparation.headerBuilds,
46178
+ ...(preparation.nativeProductTargets ?? []).map((target) => ({
46179
+ target,
46180
+ producers: []
46181
+ }))
46182
+ ];
46183
+ const checkpoints = import_node_path68.default.join(root2, ".build", "peach-product-checkpoints");
46184
+ const buildDbExists = (0, import_node_fs68.existsSync)(import_node_path68.default.join(root2, ".build", "build.db"));
46185
+ const releaseDir = import_node_path68.default.dirname(linked);
46186
+ for (const { target, producers } of stages) {
46187
+ if (!options2.project && producers.length === 0 && buildDbExists) {
46188
+ const expectedObjects = preparation.nativeStageObjects.get(target);
46189
+ if (expectedObjects && expectedObjects.length > 0 && expectedObjects.every(
46190
+ (relative3) => (0, import_node_fs68.statSync)(import_node_path68.default.join(releaseDir, relative3), {
46191
+ throwIfNoEntry: false
46192
+ })?.isFile()
46193
+ ))
46194
+ continue;
45985
46195
  }
45986
- const header = foreign.size ? withoutSwiftDeclarations(
45987
- own2,
45988
- new Set(foreign.keys()),
45989
- [...new Set(foreign.values())].map((owner) => `#import <${owner}/${owner}.h>`).join("\n")
45990
- ) : own2;
45991
- const value = {
45992
- file: import_node_path68.default.join(root, ".build/peach-framework-objc", `${name3}-Swift.h`),
45993
- header,
45994
- module: (0, import_node_fs68.existsSync)(headers)
45995
- };
45996
- frameworkInterfaces.set(name3, value);
45997
- writeBuildFile(
45998
- value.file,
45999
- ((0, import_node_fs68.existsSync)(import_node_path68.default.join(headers, `${name3}.h`)) ? `#import <${name3}/${name3}.h>
46000
- ` : "") + swiftHeaderWithSuperclassImports(header, frameworkInterface)
46001
- );
46002
- return value;
46003
- };
46004
- const headerPaths = (producer) => {
46005
- const stem2 = import_node_path68.default.join(
46006
- root,
46007
- ".build",
46008
- "peach-cxx-headers",
46009
- `${producer}-Swift`
46010
- );
46011
- return { producer, original: `${stem2}.original.h`, emitted: `${stem2}.h` };
46012
- };
46013
- const publishHeader = ({
46014
- producer,
46015
- original,
46016
- emitted
46017
- }) => {
46018
- const generated = generatedInterface(original);
46019
- writeBuildFile(
46020
- emitted,
46021
- withoutSwiftDeclarations(
46022
- swiftHeaderWithSuperclassImports(generated, frameworkInterface),
46023
- /* @__PURE__ */ new Set([
46024
- ...preparation.nativeHeaderDeclarations[producer] ?? [],
46025
- ...nativelyDeclaredFunctions(generated, nativeHeaders)
46026
- ]),
46027
- `#import <${producer}/${producer}.h>`
46028
- )
46196
+ const receipt = import_node_path68.default.join(
46197
+ checkpoints,
46198
+ (0, import_node_crypto42.createHash)("sha256").update(target).digest("hex")
46029
46199
  );
46030
- };
46031
- const recipe2 = inputHash.copy().update(
46032
- distribution ? swiftCompileSurfaceDigest(frameworkRoot) : moduleDigest
46033
- ).update((0, import_node_fs68.readFileSync)(import_node_path68.default.join(root, "Package.swift"))).update(JSON.stringify(buildArgs)).digest("hex");
46034
- const runApp = async (compiler2) => {
46035
- const optionsWithCompiler = compiler2 ? { ...appOptions, env: { ...appOptions.env, ...compiler2 } } : appOptions;
46036
- const stages = [
46037
- ...(preparation.nativePrerequisiteTargets ?? []).map((target) => ({
46038
- target,
46039
- producers: []
46040
- })),
46041
- ...preparation.headerBuilds,
46042
- ...(preparation.nativeProductTargets ?? []).map((target) => ({
46043
- target,
46044
- producers: []
46045
- }))
46046
- ];
46047
- const checkpoints = import_node_path68.default.join(root, ".build", "peach-product-checkpoints");
46048
- const buildDbExists = (0, import_node_fs68.existsSync)(import_node_path68.default.join(root, ".build", "build.db"));
46049
- const releaseDir = import_node_path68.default.dirname(linked);
46050
- for (const { target, producers } of stages) {
46051
- if (!options2.project && producers.length === 0 && buildDbExists) {
46052
- const expectedObjects = preparation.nativeStageObjects.get(target);
46053
- if (expectedObjects && expectedObjects.length > 0 && expectedObjects.every(
46054
- (relative3) => (0, import_node_fs68.statSync)(import_node_path68.default.join(releaseDir, relative3), {
46055
- throwIfNoEntry: false
46056
- })?.isFile()
46057
- ))
46058
- continue;
46059
- }
46060
- const receipt = import_node_path68.default.join(
46061
- checkpoints,
46062
- (0, import_node_crypto42.createHash)("sha256").update(target).digest("hex")
46063
- );
46064
- const headers = producers.map(headerPaths);
46065
- for (const header of headers)
46066
- if ((0, import_node_fs68.existsSync)(header.original)) publishHeader(header);
46067
- const fingerprint = () => {
46068
- const digest2 = (0, import_node_crypto42.createHash)("sha256").update(recipe2);
46069
- for (const { original, emitted } of headers) {
46070
- if (!(0, import_node_fs68.existsSync)(original) || !(0, import_node_fs68.existsSync)(emitted)) return;
46071
- digest2.update(
46072
- (0, import_node_crypto42.createHash)("sha256").update((0, import_node_fs68.readFileSync)(emitted)).digest()
46073
- );
46074
- }
46075
- return digest2.digest("hex");
46076
- };
46077
- if (!options2.project && (0, import_node_fs68.existsSync)(receipt) && (0, import_node_fs68.readFileSync)(receipt, "utf8") === fingerprint())
46078
- continue;
46079
- if (!options2.project) (0, import_node_fs68.rmSync)(receipt, { force: true });
46080
- for (const header of headers) {
46081
- if (!(0, import_node_fs68.existsSync)(header.original))
46082
- (0, import_node_fs68.rmSync)(
46083
- import_node_path68.default.join(
46084
- import_node_path68.default.dirname(linked),
46085
- "Modules",
46086
- `${swiftTargetModuleName(header.producer)}.swiftmodule`
46087
- ),
46088
- { force: true }
46089
- );
46090
- }
46091
- await runCompiler(
46092
- swift,
46093
- [...buildArgs, "--target", target],
46094
- optionsWithCompiler,
46095
- /^(?:\[swift-prebuilt\]|\[\d+\/\d+\] )/,
46096
- SWIFTPM_NOISE
46097
- );
46098
- if (!compiler2) for (const header of headers) publishHeader(header);
46099
- if (!options2.project) {
46100
- const checkpoint = fingerprint();
46101
- if (checkpoint === void 0)
46102
- throw new Error(`missing Swift headers after building ${target}`);
46103
- (0, import_node_fs68.mkdirSync)(checkpoints, { recursive: true });
46104
- (0, import_node_fs68.writeFileSync)(`${receipt}.partial`, checkpoint);
46105
- (0, import_node_fs68.renameSync)(`${receipt}.partial`, receipt);
46200
+ const headers = producers.map(headerPaths);
46201
+ for (const header of headers)
46202
+ if ((0, import_node_fs68.existsSync)(header.original)) publishHeader(header);
46203
+ const fingerprint = () => {
46204
+ const digest2 = (0, import_node_crypto42.createHash)("sha256").update(recipe2);
46205
+ for (const { original, emitted } of headers) {
46206
+ if (!(0, import_node_fs68.existsSync)(original) || !(0, import_node_fs68.existsSync)(emitted)) return;
46207
+ digest2.update(
46208
+ (0, import_node_crypto42.createHash)("sha256").update((0, import_node_fs68.readFileSync)(emitted)).digest()
46209
+ );
46106
46210
  }
46211
+ return digest2.digest("hex");
46212
+ };
46213
+ if (!options2.project && (0, import_node_fs68.existsSync)(receipt) && (0, import_node_fs68.readFileSync)(receipt, "utf8") === fingerprint())
46214
+ continue;
46215
+ if (!options2.project) (0, import_node_fs68.rmSync)(receipt, { force: true });
46216
+ for (const header of headers) {
46217
+ if (!(0, import_node_fs68.existsSync)(header.original))
46218
+ (0, import_node_fs68.rmSync)(
46219
+ import_node_path68.default.join(
46220
+ import_node_path68.default.dirname(linked),
46221
+ "Modules",
46222
+ `${swiftTargetModuleName(header.producer)}.swiftmodule`
46223
+ ),
46224
+ { force: true }
46225
+ );
46107
46226
  }
46108
46227
  await runCompiler(
46109
46228
  swift,
46110
- buildArgs,
46229
+ [...buildArgs, "--target", target],
46111
46230
  optionsWithCompiler,
46112
- SWIFTPM_PROGRESS,
46231
+ /^(?:\[swift-prebuilt\]|\[\d+\/\d+\] )/,
46113
46232
  SWIFTPM_NOISE
46114
46233
  );
46115
- };
46116
- const compileApp = () => preparation.headerCompiler ? withSwiftHeaderCompiler(
46117
- root,
46118
- options2.toolchainBin,
46119
- recipe2,
46120
- new Map(
46121
- preparation.headerBuilds[0].producers.map((producer) => {
46122
- const paths = headerPaths(producer);
46123
- return [
46124
- swiftTargetModuleName(producer),
46125
- {
46126
- header: paths.original,
46127
- publish: () => publishHeader(paths)
46128
- }
46129
- ];
46130
- })
46131
- ),
46132
- runApp
46133
- ) : runApp();
46134
- try {
46135
- if (temporaryDirectory) (0, import_node_fs68.mkdirSync)(temporaryDirectory, { recursive: true });
46136
- await compileApp();
46137
- } catch (error) {
46138
- const output2 = outputOf(error);
46139
- const moduleCache = import_node_path68.default.join(
46140
- root,
46141
- ".build",
46142
- WASM_TRIPLE,
46143
- "release",
46144
- "ModuleCache"
46145
- );
46146
- if (output2.includes("was compiled with module cache path") && (0, import_node_fs68.existsSync)(moduleCache)) {
46147
- (0, import_node_fs68.rmSync)(moduleCache, { recursive: true, force: true });
46148
- try {
46149
- await compileApp();
46150
- } catch (retryError) {
46151
- throw new Error(
46152
- [
46153
- ...unprepared,
46154
- projectDiagnostic(outputOf(retryError), layout2, input.files)
46155
- ].join("\n"),
46156
- { cause: retryError }
46157
- );
46158
- }
46159
- } else {
46234
+ if (!compiler2) for (const header of headers) publishHeader(header);
46235
+ if (!options2.project) {
46236
+ const checkpoint = fingerprint();
46237
+ if (checkpoint === void 0)
46238
+ throw new Error(`missing Swift headers after building ${target}`);
46239
+ (0, import_node_fs68.mkdirSync)(checkpoints, { recursive: true });
46240
+ (0, import_node_fs68.writeFileSync)(`${receipt}.partial`, checkpoint);
46241
+ (0, import_node_fs68.renameSync)(`${receipt}.partial`, receipt);
46242
+ }
46243
+ }
46244
+ await runCompiler(
46245
+ swift,
46246
+ buildArgs,
46247
+ optionsWithCompiler,
46248
+ SWIFTPM_PROGRESS,
46249
+ SWIFTPM_NOISE
46250
+ );
46251
+ };
46252
+ const compileApp = () => preparation.headerCompiler ? withSwiftHeaderCompiler(
46253
+ root2,
46254
+ options2.toolchainBin,
46255
+ recipe2,
46256
+ new Map(
46257
+ preparation.headerBuilds[0].producers.map((producer) => {
46258
+ const paths = headerPaths(producer);
46259
+ return [
46260
+ swiftTargetModuleName(producer),
46261
+ {
46262
+ header: paths.original,
46263
+ publish: () => publishHeader(paths)
46264
+ }
46265
+ ];
46266
+ })
46267
+ ),
46268
+ runApp
46269
+ ) : runApp();
46270
+ try {
46271
+ if (temporaryDirectory) (0, import_node_fs68.mkdirSync)(temporaryDirectory, { recursive: true });
46272
+ await compileApp();
46273
+ } catch (error) {
46274
+ const output2 = outputOf(error);
46275
+ const moduleCache = import_node_path68.default.join(
46276
+ root2,
46277
+ ".build",
46278
+ WASM_TRIPLE,
46279
+ "release",
46280
+ "ModuleCache"
46281
+ );
46282
+ if (output2.includes("was compiled with module cache path") && (0, import_node_fs68.existsSync)(moduleCache)) {
46283
+ (0, import_node_fs68.rmSync)(moduleCache, { recursive: true, force: true });
46284
+ try {
46285
+ await compileApp();
46286
+ } catch (retryError) {
46160
46287
  throw new Error(
46161
- [...unprepared, projectDiagnostic(output2, layout2, input.files)].join(
46162
- "\n"
46163
- ),
46164
- { cause: error }
46288
+ [
46289
+ ...unprepared,
46290
+ projectDiagnostic(outputOf(retryError), layout3, input.files)
46291
+ ].join("\n"),
46292
+ { cause: retryError }
46165
46293
  );
46166
46294
  }
46167
- } finally {
46168
- if (temporaryDirectory)
46169
- (0, import_node_fs68.rmSync)(temporaryDirectory, { recursive: true, force: true });
46170
- if (options2.project) endSwiftProjectProcesses(options2.project);
46171
- }
46172
- if (unprepared.length) throw new Error(unprepared.join("\n"));
46173
- if (!(0, import_node_fs68.existsSync)(linked)) {
46174
- const binDir = import_node_path68.default.dirname(linked);
46175
- const found = (0, import_node_fs68.existsSync)(binDir) ? (0, import_node_fs68.readdirSync)(binDir).filter((name3) => name3.endsWith(".wasm")).sort() : [];
46295
+ } else {
46176
46296
  throw new Error(
46177
- `swift-compile: the build produced no ${import_node_path68.default.basename(linked)} (found: ${found.join(", ") || "none"})`
46297
+ [...unprepared, projectDiagnostic(output2, layout3, input.files)].join(
46298
+ "\n"
46299
+ ),
46300
+ { cause: error }
46178
46301
  );
46179
46302
  }
46180
- if (options2.project) removeProjectLinks(root);
46181
- const resourceReferences = Object.values(input.resources ?? {}).map(
46182
- (value) => Buffer.from(value, "base64")
46303
+ } finally {
46304
+ if (temporaryDirectory)
46305
+ (0, import_node_fs68.rmSync)(temporaryDirectory, { recursive: true, force: true });
46306
+ if (options2.project) endSwiftProjectProcesses(options2.project);
46307
+ }
46308
+ if (unprepared.length) throw new Error(unprepared.join("\n"));
46309
+ if (!(0, import_node_fs68.existsSync)(linked)) {
46310
+ const binDir = import_node_path68.default.dirname(linked);
46311
+ const found = (0, import_node_fs68.existsSync)(binDir) ? (0, import_node_fs68.readdirSync)(binDir).filter((name3) => name3.endsWith(".wasm")).sort() : [];
46312
+ throw new Error(
46313
+ `swift-compile: the build produced no ${import_node_path68.default.basename(linked)} (found: ${found.join(", ") || "none"})`
46183
46314
  );
46184
- if (!guestGraph)
46185
- pruneSwiftWasmLink(
46186
- root,
46187
- options2.toolchainBin,
46188
- prebuilt?.root ?? frameworkRoot,
46189
- input.staticClangTargets,
46190
- options2.project,
46191
- void 0,
46192
- resourceReferences
46193
- );
46194
- if (options2.linkOnly) {
46195
- if ((0, import_node_fs68.statSync)(linked).size <= 8)
46196
- throw new Error("swift-compile: deferred linker produced no executable");
46197
- report("project link verified");
46198
- return;
46199
- }
46200
- const output = options2.project ? projectOutputFile(root, linked, options2.project) : linked;
46201
- const optimized = `${output}.optimized`;
46202
- if (sdkImage && options2.project) (0, import_node_fs68.rmSync)(optimized, { force: true });
46203
- let sdkAsset;
46204
- if (guestGraph) {
46205
- const binding = await compileGuestLink({
46206
- graph: guestGraph,
46207
- buildDirectory: root,
46208
- releaseDirectory: import_node_path68.default.dirname(linked),
46209
- moduleRoot: frameworkRoot,
46210
- toolchainBin: options2.toolchainBin,
46211
- swiftCompiler: preparation.headerCompiler ? import_node_path68.default.join(root, SWIFT_HEADER_COMPILER_WRAPPER) : compiler.SWIFT_EXEC ?? import_node_path68.default.join(options2.toolchainBin, "swiftc"),
46212
- sysroot: swiftSdkPaths(frameworkRoot, options2.toolchainBin).sysroot,
46213
- sdk: swiftModuleSdk(frameworkRoot),
46214
- sdkImage,
46215
- compilerDigest: compilerSourceDigest,
46216
- project: options2.project && {
46217
- ...options2.project,
46218
- env: { ...options2.project.env, ...projectProcess?.env }
46219
- },
46220
- staticClangTargets: input.staticClangTargets ?? [],
46221
- resourceReferences,
46222
- resourceBundles: input.resourceBundles ?? [],
46223
- generatedOwners: preparation.generatedOwners,
46224
- output,
46225
- optimized,
46226
- optimize: input.optimize === true,
46227
- jobs: swiftBuildJobs()
46228
- });
46229
- if (sdkImage && binding)
46230
- sdkAsset = { key: sdkImage.key, sha256: sdkImage.sha256, binding };
46231
- } else if (sdkImage) {
46232
- const { buildSwiftAppModule: buildSwiftAppModule2 } = await Promise.resolve().then(() => (init_swift_sdk_app_module(), swift_sdk_app_module_exports));
46233
- const binding = await buildSwiftAppModule2({
46234
- buildRoot: root,
46235
- toolchainBin: options2.toolchainBin,
46236
- sdk: sdkImage,
46237
- output: optimized,
46238
- optimize: input.optimize === true,
46239
- project: options2.project && {
46240
- ...options2.project,
46241
- env: { ...options2.project.env, ...projectProcess?.env },
46242
- sdkRoot: import_node_path68.default.dirname(
46243
- swiftSdkPaths(frameworkRoot, options2.toolchainBin).sysroot
46244
- ),
46245
- linked: output
46246
- }
46247
- });
46248
- sdkAsset = { key: sdkImage.key, sha256: sdkImage.sha256, binding };
46249
- } else {
46250
- const bytes = (0, import_node_fs68.readFileSync)(output);
46251
- const ordered = orderObjCConstructors(bytes);
46252
- if (ordered !== bytes) (0, import_node_fs68.writeFileSync)(output, ordered);
46253
- await lowerWasm(output, optimized, { optimize: input.optimize === true });
46254
- }
46255
- if (!sdkImage)
46256
- await runCompiler(
46257
- import_node_path68.default.join(options2.toolchainBin, "llvm-objcopy"),
46258
- ["--remove-section=.swift1_autolink_entries", optimized],
46259
- buildOptions
46260
- );
46261
- const artifact = {
46262
- hash,
46263
- bytes: (0, import_node_fs68.readFileSync)(optimized),
46264
- icu: await icu,
46265
- sdk: sdkAsset
46266
- };
46267
- if (artifact.bytes.length <= 8)
46315
+ }
46316
+ if (options2.project) removeProjectLinks(root2);
46317
+ const resourceReferences = Object.values(input.resources ?? {}).map(
46318
+ (value) => Buffer.from(value, "base64")
46319
+ );
46320
+ if (!guestGraph)
46321
+ pruneSwiftWasmLink(
46322
+ root2,
46323
+ options2.toolchainBin,
46324
+ prebuilt?.root ?? frameworkRoot,
46325
+ input.staticClangTargets,
46326
+ options2.project,
46327
+ void 0,
46328
+ resourceReferences
46329
+ );
46330
+ if (options2.linkOnly) {
46331
+ if ((0, import_node_fs68.statSync)(linked).size <= 8)
46268
46332
  throw new Error("swift-compile: deferred linker produced no executable");
46269
- if (!options2.project) saveCompiledArtifact(root, artifact);
46270
- saveSharedArtifact(sharedRoot, artifact);
46271
- report("compiled artifact verified");
46272
- return retain(root, artifact);
46273
- } finally {
46274
- readHold?.release();
46333
+ stage("project link verified");
46334
+ return;
46275
46335
  }
46276
- },
46277
- budget.signal
46278
- );
46336
+ const output = options2.project ? projectOutputFile(root2, linked, options2.project) : linked;
46337
+ const optimized = `${output}.optimized`;
46338
+ if (sdkImage && options2.project) (0, import_node_fs68.rmSync)(optimized, { force: true });
46339
+ let sdkAsset;
46340
+ stage("linking the app image");
46341
+ if (guestGraph) {
46342
+ const binding = await compileGuestLink({
46343
+ graph: guestGraph,
46344
+ buildDirectory: root2,
46345
+ releaseDirectory: import_node_path68.default.dirname(linked),
46346
+ moduleRoot: frameworkRoot,
46347
+ toolchainBin: options2.toolchainBin,
46348
+ swiftCompiler: preparation.headerCompiler ? import_node_path68.default.join(root2, SWIFT_HEADER_COMPILER_WRAPPER) : compiler.SWIFT_EXEC ?? import_node_path68.default.join(options2.toolchainBin, "swiftc"),
46349
+ sysroot: swiftSdkPaths(frameworkRoot, options2.toolchainBin).sysroot,
46350
+ sdk: swiftModuleSdk(frameworkRoot),
46351
+ sdkImage,
46352
+ compilerDigest: compilerSourceDigest,
46353
+ project: options2.project && {
46354
+ ...options2.project,
46355
+ env: { ...options2.project.env, ...projectProcess?.env }
46356
+ },
46357
+ staticClangTargets: input.staticClangTargets ?? [],
46358
+ resourceReferences,
46359
+ resourceBundles: input.resourceBundles ?? [],
46360
+ generatedOwners: preparation.generatedOwners,
46361
+ output,
46362
+ optimized,
46363
+ optimize: input.optimize === true,
46364
+ jobs: swiftBuildJobs(),
46365
+ onStage: stage
46366
+ });
46367
+ if (sdkImage && binding)
46368
+ sdkAsset = { key: sdkImage.key, sha256: sdkImage.sha256, binding };
46369
+ } else if (sdkImage) {
46370
+ const { buildSwiftAppModule: buildSwiftAppModule2 } = await Promise.resolve().then(() => (init_swift_sdk_app_module(), swift_sdk_app_module_exports));
46371
+ const binding = await buildSwiftAppModule2({
46372
+ buildRoot: root2,
46373
+ toolchainBin: options2.toolchainBin,
46374
+ sdk: sdkImage,
46375
+ output: optimized,
46376
+ optimize: input.optimize === true,
46377
+ project: options2.project && {
46378
+ ...options2.project,
46379
+ env: { ...options2.project.env, ...projectProcess?.env },
46380
+ sdkRoot: import_node_path68.default.dirname(
46381
+ swiftSdkPaths(frameworkRoot, options2.toolchainBin).sysroot
46382
+ ),
46383
+ linked: output
46384
+ }
46385
+ });
46386
+ sdkAsset = { key: sdkImage.key, sha256: sdkImage.sha256, binding };
46387
+ } else {
46388
+ const bytes = (0, import_node_fs68.readFileSync)(output);
46389
+ const ordered = orderObjCConstructors(bytes);
46390
+ if (ordered !== bytes) (0, import_node_fs68.writeFileSync)(output, ordered);
46391
+ stage("lowering the app image");
46392
+ await lowerWasm(output, optimized, { optimize: input.optimize === true });
46393
+ }
46394
+ if (!sdkImage)
46395
+ await runCompiler(
46396
+ import_node_path68.default.join(options2.toolchainBin, "llvm-objcopy"),
46397
+ ["--remove-section=.swift1_autolink_entries", optimized],
46398
+ buildOptions
46399
+ );
46400
+ const artifact = {
46401
+ hash,
46402
+ bytes: (0, import_node_fs68.readFileSync)(optimized),
46403
+ icu: await icu,
46404
+ sdk: sdkAsset
46405
+ };
46406
+ if (artifact.bytes.length <= 8)
46407
+ throw new Error("swift-compile: deferred linker produced no executable");
46408
+ if (!options2.project) saveCompiledArtifact(root2, artifact);
46409
+ saveSharedArtifact(sharedRoot, artifact);
46410
+ stage("compiled artifact verified");
46411
+ return retain(baseRoot, artifact);
46412
+ } finally {
46413
+ readHold?.release();
46414
+ }
46415
+ });
46279
46416
  });
46280
46417
  },
46281
46418
  options2.signal
46282
46419
  );
46283
46420
  }
46284
- var import_node_child_process38, import_node_crypto42, import_node_fs68, import_node_os14, import_node_path68, v6, WASM_TRIPLE, SWIFTPM_PROGRESS, SWIFTPM_NOISE, SWIFT_COMPILER_ENV_KEYS, distributionManifests, distributionCompileViews, REACH_STAGED_FRAMEWORKS, objcEnumerations, clangDeclarationEnumCache, objcEnumForward, sdkDeclarationOwners, swiftInterfaceDeclarations, linkedModuleDigests, compileSurfaces, SYSTEM_MODULE_LIBRARIES, SYSTEM_MODULE_IMPORT, OPTIONAL_FRAMEWORK_DEPENDENCIES, OPTIONAL_FRAMEWORKS, SWIFT_IMPORT, kleeneNot, kleeneAnd, kleeneOr, NON_IOS_MODULES, sdkPaths, availableModules, sdkOverlayFrameworks, DISTRIBUTION_CLANG_MODULES, CLANG_DISTRIBUTION_MODULES, ONE_PRODUCT, GAME_FAMILY, gameProducts, gameProduct, GAME_REACH, FOUNDATION_IMPLICIT_MODULES, FRAMEWORK_COMPANION_IMPORT, ONE_IMPLICIT_FLAGS, executableLinkFlags, darwinRecordsRegion, REACTOR_FLAG, MULTI_MANIFEST_VERSION, SWIFT_HEADER_PRODUCTS_TARGET, compilerSourceDigest, nativeCxxCompilerFlags, MODULE_MAP_RESPONSE_FILE_RUN, cFlagArray, cxxFlagArray, SWIFTPM_DEFAULT_IOS_DEPLOYMENT_TARGET, OS_IOS, ARCH_ARM64, NOT_ON_IOS, DELEGATE_CLASS, ARM64_MACRO, WASM_MACRO, ARCH_WASM32, C_WORDS, archEnvironments, codeMasks, codeMaskChars, CODE_MASK_CACHE_CHARS, FOUNDATION_NETWORKING_TYPES, FOUNDATION_OVERLAY_TYPES, FOUNDATION_OVERLAY_GLOBALS, CORE_FOUNDATION_OVERLAY_GLOBALS, CORE_FOUNDATION_GEOMETRY_TYPES, CORE_FOUNDATION_GRAPHICS_TYPES, CORE_FOUNDATION_HANDLE_IMPORTS, emptyMacroEnvironment, wasmMacroEnvironment, cPredefineTable, cPredefineCache, HIDDEN_UNITS, FIRST_WINS_PAIRS, LAST_WINS_PAIRS, VALUE_FLAGS, LIBXML_REFERENCE, LIBXML_SOURCE, ROOT_LOCKS, host, rootLocks, SHARED_ARTIFACT_BUDGET_BYTES, SHARED_ARTIFACT_GRACE_MS, RETIRED_PREFIX, retainedArtifacts, FRAMEWORK_LINK_TARGET, frameworkProductsReceiptSchema, SWIFT_LINK_STAMP, SWIFT_HOST_COMPILER_WRAPPER, SWIFT_FRAMEWORK_SLOTS, SWIFT_FRAMEWORK_UNOPTIMIZED_SLOTS, SWIFT_FRAMEWORK_SLOT_KEY, SWIFT_FRAMEWORK_SLOT_ORIGIN;
46421
+ var import_node_child_process38, import_node_crypto42, import_node_fs68, import_node_os14, import_node_path68, v6, WASM_TRIPLE, SWIFTPM_PROGRESS, SWIFTPM_NOISE, SWIFT_COMPILER_ENV_KEYS, distributionManifests, distributionCompileViews, REACH_STAGED_FRAMEWORKS, objcEnumerations, clangDeclarationEnumCache, objcEnumForward, sdkDeclarationOwners, swiftInterfaceDeclarations, linkedModuleDigests, compileSurfaces, SYSTEM_MODULE_LIBRARIES, SYSTEM_MODULE_IMPORT, OPTIONAL_FRAMEWORK_DEPENDENCIES, OPTIONAL_FRAMEWORKS, SWIFT_IMPORT, kleeneNot, kleeneAnd, kleeneOr, NON_IOS_MODULES, sdkPaths, availableModules, sdkOverlayFrameworks, DISTRIBUTION_CLANG_MODULES, CLANG_DISTRIBUTION_MODULES, ONE_PRODUCT, GAME_FAMILY, gameProducts, gameProduct, GAME_REACH, FOUNDATION_IMPLICIT_MODULES, FRAMEWORK_COMPANION_IMPORT, ONE_IMPLICIT_FLAGS, executableLinkFlags, darwinRecordsRegion, REACTOR_FLAG, MULTI_MANIFEST_VERSION, SWIFT_HEADER_PRODUCTS_TARGET, compilerSourceDigest, nativeCxxCompilerFlags, MODULE_MAP_RESPONSE_FILE_RUN, cFlagArray, cxxFlagArray, SWIFTPM_DEFAULT_IOS_DEPLOYMENT_TARGET, OS_IOS, ARCH_ARM64, NOT_ON_IOS, DELEGATE_CLASS, ARM64_MACRO, WASM_MACRO, ARCH_WASM32, C_WORDS, archEnvironments, codeMasks, codeMaskChars, CODE_MASK_CACHE_CHARS, FOUNDATION_NETWORKING_TYPES, FOUNDATION_OVERLAY_TYPES, FOUNDATION_OVERLAY_GLOBALS, CORE_FOUNDATION_OVERLAY_GLOBALS, CORE_FOUNDATION_GEOMETRY_TYPES, CORE_FOUNDATION_GRAPHICS_TYPES, CORE_FOUNDATION_HANDLE_IMPORTS, emptyMacroEnvironment, wasmMacroEnvironment, cPredefineTable, cPredefineCache, HIDDEN_UNITS, FIRST_WINS_PAIRS, LAST_WINS_PAIRS, VALUE_FLAGS, LIBXML_REFERENCE, LIBXML_SOURCE, ROOT_LOCKS, host, rootLocks, SHARED_ARTIFACT_BUDGET_BYTES, SHARED_ARTIFACT_GRACE_MS, RETIRED_PREFIX, retainedArtifacts, FRAMEWORK_LINK_TARGET, frameworkProductsReceiptSchema, SWIFT_LINK_STAMP, SWIFT_HOST_COMPILER_WRAPPER, SWIFT_FRAMEWORK_SLOTS, SWIFT_FRAMEWORK_UNOPTIMIZED_SLOTS, SWIFT_FRAMEWORK_SLOT_KEY, SWIFT_FRAMEWORK_SLOT_ORIGIN, SWIFT_FRAMEWORK_SLOT_RELEASE, SWIFT_BUILD_ROOT_SLOTS, SWIFT_BUILD_ROOT_SHAPE;
46285
46422
  var init_swift_compile = __esm({
46286
46423
  "src/swift-compile.ts"() {
46287
46424
  "use strict";
@@ -46552,7 +46689,7 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
46552
46689
  REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
46553
46690
  MULTI_MANIFEST_VERSION = 76;
46554
46691
  SWIFT_HEADER_PRODUCTS_TARGET = "PeachHeaderProducts";
46555
- compilerSourceDigest = true ? "37c95b1d4be497f3f882c4c51f2be7e5bb09b4bcc4976a51d553b0a993c9c7ca" : swiftCompilerSourceDigest2(__sootsim_import_meta_dirname);
46692
+ compilerSourceDigest = true ? "203439fc20df8d328b0c245496fc6db90092265409adb61b593725e82ce837de" : swiftCompilerSourceDigest2(__sootsim_import_meta_dirname);
46556
46693
  nativeCxxCompilerFlags = ["-fno-cxx-modules"];
46557
46694
  MODULE_MAP_RESPONSE_FILE_RUN = 16;
46558
46695
  cFlagArray = (flags) => JSON.stringify(withoutGlogModuleMap(flags));
@@ -46976,6 +47113,7 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
46976
47113
  retainedArtifacts = /* @__PURE__ */ new Map();
46977
47114
  FRAMEWORK_LINK_TARGET = "PeachFrameworkLink";
46978
47115
  frameworkProductsReceiptSchema = v6.object({
47116
+ root: v6.string(),
46979
47117
  modules: v6.string(),
46980
47118
  objects: v6.array(v6.string()),
46981
47119
  lazyObjects: v6.array(v6.string()),
@@ -46992,6 +47130,9 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
46992
47130
  SWIFT_FRAMEWORK_UNOPTIMIZED_SLOTS = 4;
46993
47131
  SWIFT_FRAMEWORK_SLOT_KEY = ".peach-framework-key";
46994
47132
  SWIFT_FRAMEWORK_SLOT_ORIGIN = ".peach-framework-origin";
47133
+ SWIFT_FRAMEWORK_SLOT_RELEASE = ".peach-framework-release";
47134
+ SWIFT_BUILD_ROOT_SLOTS = 4;
47135
+ SWIFT_BUILD_ROOT_SHAPE = ".peach-build-shape";
46995
47136
  }
46996
47137
  });
46997
47138
 
@@ -66727,7 +66868,7 @@ var init_provenance = __esm({
66727
66868
  import_node_crypto48 = require("node:crypto");
66728
66869
  import_node_fs82 = require("node:fs");
66729
66870
  import_node_path83 = require("node:path");
66730
- 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_path83.join)(__sootsim_import_meta_dirname, ".."));
66871
+ 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_path83.join)(__sootsim_import_meta_dirname, ".."));
66731
66872
  }
66732
66873
  });
66733
66874