peachsim 0.1.1635 → 0.1.1641

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 (142) hide show
  1. package/README.md +10 -1
  2. package/cli/app-config.ts +14 -5
  3. package/cli/app-stubs.ts +96 -22
  4. package/cli/bridge-flow-runner.ts +2 -2
  5. package/cli/cloud-client.ts +60 -40
  6. package/cli/cloud-session.ts +16 -0
  7. package/cli/commands/assert.ts +17 -4
  8. package/cli/commands/box.ts +33 -19
  9. package/cli/commands/doctor.ts +37 -20
  10. package/cli/commands/flow.ts +1 -1
  11. package/cli/commands/inspect/actions.ts +3 -2
  12. package/cli/commands/inspect/core.ts +0 -8
  13. package/cli/commands/inspect/shared.ts +9 -4
  14. package/cli/commands/inspect.ts +65 -61
  15. package/cli/commands/platform.ts +2 -1
  16. package/cli/commands/preview.ts +1 -1
  17. package/cli/commands/record.ts +154 -68
  18. package/cli/commands/swift.ts +18 -4
  19. package/cli/commands/three-mode.ts +4 -38
  20. package/cli/commands/upload.ts +55 -49
  21. package/cli/drivers/playwright-sim-host.ts +65 -42
  22. package/cli/flow-live-status.ts +0 -2
  23. package/cli/main.ts +2 -2
  24. package/cli/outbound-endpoints.ts +7 -5
  25. package/cli/pause-aware-timeout.ts +4 -0
  26. package/cli/ws-bridge.ts +19 -16
  27. package/detox/attempt-events.cjs +99 -6
  28. package/detox/attempt-events.d.cts +7 -0
  29. package/detox/expectations.ts +7 -3
  30. package/detox/index.ts +259 -139
  31. package/detox/jest-environment.cjs +5 -1
  32. package/detox/motion-change.cjs +170 -21
  33. package/detox/motion-change.d.cts +32 -0
  34. package/detox/navigation-lifecycle.ts +35 -3
  35. package/dist-lib/agent-daemon-client.cjs +1 -1
  36. package/dist-lib/agent-events.cjs +1 -1
  37. package/dist-lib/attached-projects.cjs +1 -1
  38. package/dist-lib/auth/shared-session.cjs +1 -1
  39. package/dist-lib/backend-origin.cjs +17 -7
  40. package/dist-lib/beta.cjs +1 -1
  41. package/dist-lib/beta.mjs +1 -1
  42. package/dist-lib/bridge-constants.cjs +1 -1
  43. package/dist-lib/bridge-contract-input.cjs +1 -1
  44. package/dist-lib/bridge-contract-input.mjs +1 -1
  45. package/dist-lib/bridge-contract.cjs +1 -1
  46. package/dist-lib/bridge-contract.mjs +1 -1
  47. package/dist-lib/bundle-channel.cjs +5014 -2268
  48. package/dist-lib/capture-contract.cjs +1 -1
  49. package/dist-lib/capture-contract.mjs +1 -1
  50. package/dist-lib/cloud-contract.cjs +1 -1
  51. package/dist-lib/cloud-contract.mjs +1 -1
  52. package/dist-lib/cloud-test-args.cjs +1 -1
  53. package/dist-lib/cloud-test-args.mjs +1 -1
  54. package/dist-lib/cloud.cjs +1 -1
  55. package/dist-lib/cloud.mjs +1 -1
  56. package/dist-lib/config.cjs +1 -1
  57. package/dist-lib/config.mjs +1 -1
  58. package/dist-lib/detox/index.cjs +1036 -166
  59. package/dist-lib/detox/jest-environment.cjs +5 -1
  60. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  61. package/dist-lib/expo-swift-bundle.cjs +4613 -1963
  62. package/dist-lib/expo-swift-metadata.cjs +9 -7
  63. package/dist-lib/expo-swift-metadata.mjs +9 -7
  64. package/dist-lib/home-paths.cjs +1 -1
  65. package/dist-lib/host/bridge-host.cjs +58072 -16400
  66. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  67. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  68. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  69. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  70. package/dist-lib/host/websocket-proxy.cjs +1 -1
  71. package/dist-lib/index.cjs +2790 -143
  72. package/dist-lib/jump-to-source-babel.cjs +1 -1
  73. package/dist-lib/jump-to-source-native.cjs +1 -1
  74. package/dist-lib/kotlin-host.cjs +1 -1
  75. package/dist-lib/menu.cjs +1 -1
  76. package/dist-lib/menu.mjs +1 -1
  77. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  78. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  79. package/dist-lib/metro-production-bundle.cjs +1 -1
  80. package/dist-lib/metro-production-bundle.mjs +1 -1
  81. package/dist-lib/metro.cjs +2579 -95
  82. package/dist-lib/native-app-identity-project.cjs +243 -53
  83. package/dist-lib/native-app-identity-project.mjs +243 -53
  84. package/dist-lib/native-app-identity.cjs +29 -30
  85. package/dist-lib/native-app-identity.mjs +29 -30
  86. package/dist-lib/native-firebase-metadata.cjs +1 -1
  87. package/dist-lib/native-firebase-metadata.mjs +1 -1
  88. package/dist-lib/plist.cjs +1 -1
  89. package/dist-lib/plist.mjs +1 -1
  90. package/dist-lib/profiles.cjs +1 -1
  91. package/dist-lib/public-brand.cjs +1 -1
  92. package/dist-lib/react-native-host-modules.cjs +2 -2
  93. package/dist-lib/react-native-host-modules.mjs +2 -2
  94. package/dist-lib/scripts/dev-server-scanner.cjs +8 -6
  95. package/dist-lib/sdk.cjs +4 -3
  96. package/dist-lib/sdk.mjs +4 -3
  97. package/dist-lib/skills.cjs +66475 -23097
  98. package/dist-lib/swift-compile.cjs +452 -260
  99. package/dist-lib/swift-compile.mjs +451 -252
  100. package/dist-lib/swift-package.cjs +1 -1
  101. package/dist-lib/swift-package.mjs +1 -1
  102. package/dist-lib/swift-submit.cjs +14 -7
  103. package/dist-lib/swift-submit.mjs +14 -7
  104. package/dist-lib/swift-toolchain.cjs +316 -41
  105. package/dist-lib/swift.cjs +1 -1
  106. package/dist-lib/vite-swift.cjs +8188 -5636
  107. package/dist-lib/vite.cjs +2857 -12
  108. package/dist-lib/worklet-executable.cjs +14 -2
  109. package/dist-lib/worklet-executable.mjs +14 -2
  110. package/package.json +1 -1
  111. package/src/backend-origin.ts +21 -6
  112. package/src/expo-swift-host.ts +5 -2
  113. package/src/expoKotlinContract.ts +4 -7
  114. package/src/expoSwiftContract.ts +4 -6
  115. package/src/host/staged-host-files.ts +9 -0
  116. package/src/native-app-identity-project.ts +1 -4
  117. package/src/native-app-identity.ts +1 -4
  118. package/src/nativeAppIconContract.ts +1 -4
  119. package/src/output-lock-stdio.ts +36 -0
  120. package/src/react-native-bridge-modules.ts +106 -78
  121. package/src/react-native-host-modules.ts +4 -1
  122. package/src/settings-bundle.ts +1 -4
  123. package/src/swift-compile.ts +224 -139
  124. package/src/swift-distribution.lock.json +23 -12
  125. package/src/swift-distribution.ts +103 -4
  126. package/src/swift-host.ts +95 -30
  127. package/src/swift-icu.ts +16 -10
  128. package/src/swift-objc-compile.ts +547 -0
  129. package/src/swift-objc-metadata.ts +204 -0
  130. package/src/swift-objc-sdk.ts +883 -19
  131. package/src/swift-objc-standin.ts +126 -14
  132. package/src/swift-package-manifest.ts +42 -1
  133. package/src/swift-packages.ts +35 -21
  134. package/src/swift-root-lock.ts +153 -0
  135. package/src/swift-standin-emit.ts +40 -7
  136. package/src/swift-standins.ts +404 -138
  137. package/src/swift-submit.ts +18 -7
  138. package/src/swift-toolchain.ts +378 -46
  139. package/src/swiftContract.ts +12 -0
  140. package/src/worker-system-chunks.ts +11 -12
  141. package/src/worklet-executable.ts +19 -1
  142. package/src/xcode-project.ts +280 -33
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.1635 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.1641 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
2
2
  let __sootsim_import_meta_url = '', __sootsim_import_meta_dirname = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; __sootsim_import_meta_dirname = __dirname; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -57,6 +57,7 @@ __export(swift_compile_exports, {
57
57
  swiftModuleInputFiles: () => swiftModuleInputFiles,
58
58
  swiftModuleSdk: () => swiftModuleSdk,
59
59
  swiftPeachModules: () => swiftPeachModules,
60
+ swiftProjectBuildKey: () => swiftProjectBuildKey,
60
61
  swiftSdkPaths: () => swiftSdkPaths,
61
62
  swiftSourceAsIOS: () => swiftSourceAsIOS,
62
63
  swiftSourceClosure: () => swiftSourceClosure,
@@ -66,11 +67,11 @@ __export(swift_compile_exports, {
66
67
  writeSwiftProject: () => writeSwiftProject
67
68
  });
68
69
  module.exports = __toCommonJS(swift_compile_exports);
69
- var import_node_child_process4 = require("node:child_process");
70
- var import_node_crypto2 = require("node:crypto");
71
- var import_node_fs3 = require("node:fs");
70
+ var import_node_child_process5 = require("node:child_process");
71
+ var import_node_crypto3 = require("node:crypto");
72
+ var import_node_fs4 = require("node:fs");
72
73
  var import_node_os3 = __toESM(require("node:os"), 1);
73
- var import_node_path5 = __toESM(require("node:path"), 1);
74
+ var import_node_path6 = __toESM(require("node:path"), 1);
74
75
 
75
76
  // src/admitted-mac-build.ts
76
77
  var import_node_child_process = require("node:child_process");
@@ -772,9 +773,9 @@ var EXCERPT = /^(\s*)(\d+)( \| )(.*)$/;
772
773
  var MARKER = /^(\s*)( \| )(.*)$/;
773
774
  function designTimeDiagnostic(output, files) {
774
775
  const rewritten = /* @__PURE__ */ new Map();
775
- const linesOf = (path5) => {
776
+ const linesOf = (path6) => {
776
777
  const file = Object.keys(files).find(
777
- (name) => name.endsWith(".swift") && (path5 === name || path5.endsWith(`/${name}`))
778
+ (name) => name.endsWith(".swift") && (path6 === name || path6.endsWith(`/${name}`))
778
779
  );
779
780
  if (file === void 0) return null;
780
781
  let lines = rewritten.get(file);
@@ -867,6 +868,12 @@ function swiftSdkOptions() {
867
868
  const directory = process.env.PEACH_SWIFT_SDKS_PATH;
868
869
  return directory ? ["--swift-sdks-path", import_node_path3.default.resolve(directory)] : [];
869
870
  }
871
+ var scratch;
872
+ var swiftHome;
873
+ function swiftEnvironment(base = process.env) {
874
+ if (!scratch) return base;
875
+ return swiftHome ? { ...base, TMPDIR: scratch, HOME: swiftHome } : { ...base, TMPDIR: scratch };
876
+ }
870
877
 
871
878
  // src/swift-icu.ts
872
879
  var run = (0, import_node_util.promisify)(import_node_child_process3.execFile);
@@ -905,17 +912,23 @@ async function load(toolchainBin, sdk) {
905
912
  const swift = import_node_path4.default.join(toolchainBin, "swift");
906
913
  if (!(0, import_node_fs2.existsSync)(swift))
907
914
  throw new Error(`swift-icu: no swift at ${swift} for the ${sdk} SDK's icu data`);
908
- const { stdout: listed } = await run(swift, ["sdk", "list", ...swiftSdkOptions()]);
915
+ const { stdout: listed } = await run(swift, ["sdk", "list", ...swiftSdkOptions()], {
916
+ env: swiftEnvironment()
917
+ });
909
918
  if (!listed.split("\n").some((line) => line.trim() === sdk))
910
919
  throw new Error(`swift-icu: ${sdk} is not installed for ${swift}`);
911
- const { stdout } = await run(swift, [
912
- "sdk",
913
- "configure",
914
- ...swiftSdkOptions(),
915
- "--show-configuration",
916
- sdk,
917
- "wasm32-unknown-wasip1"
918
- ]);
920
+ const { stdout } = await run(
921
+ swift,
922
+ [
923
+ "sdk",
924
+ "configure",
925
+ ...swiftSdkOptions(),
926
+ "--show-configuration",
927
+ sdk,
928
+ "wasm32-unknown-wasip1"
929
+ ],
930
+ { env: swiftEnvironment() }
931
+ );
919
932
  const resources = /^swiftStaticResourcesPath: (.+)$/m.exec(stdout)?.[1]?.trim();
920
933
  if (!resources) throw new Error(`swift-icu: ${sdk} names no static resources`);
921
934
  return Buffer.from(
@@ -1163,6 +1176,117 @@ function swiftPackagePartition(manifest, resourcePaths = []) {
1163
1176
  return targets.length === 1 && targets[0].executable && targets[0].path === "." && targets[0].languageMode === 5 && !targets[0].mainActorIsolation && !targets[0].defines?.length && !targets[0].linkedLibraries?.length && !targets[0].cxxInterop && !swiftManifestCxxLanguageStandard(manifest) ? [] : targets;
1164
1177
  }
1165
1178
 
1179
+ // src/swift-root-lock.ts
1180
+ var import_node_child_process4 = require("node:child_process");
1181
+ var import_node_crypto2 = require("node:crypto");
1182
+ var import_node_fs3 = require("node:fs");
1183
+ var import_node_path5 = __toESM(require("node:path"), 1);
1184
+ var POLL_MS = 250;
1185
+ function processStart(pid) {
1186
+ try {
1187
+ return (0, import_node_child_process4.execFileSync)("ps", ["-o", "lstart=", "-p", String(pid)], {
1188
+ encoding: "utf8",
1189
+ stdio: ["ignore", "pipe", "ignore"]
1190
+ }).trim() || null;
1191
+ } catch {
1192
+ return null;
1193
+ }
1194
+ }
1195
+ function parseHolder(text2) {
1196
+ try {
1197
+ const value = JSON.parse(text2);
1198
+ if (value && typeof value === "object" && "pid" in value && typeof value.pid === "number" && "start" in value && (typeof value.start === "string" || value.start === null))
1199
+ return { pid: value.pid, start: value.start };
1200
+ } catch {
1201
+ }
1202
+ return null;
1203
+ }
1204
+ function readLock(lock) {
1205
+ try {
1206
+ return (0, import_node_fs3.readFileSync)(lock, "utf8");
1207
+ } catch (error) {
1208
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") return null;
1209
+ throw error;
1210
+ }
1211
+ }
1212
+ function holderAlive(text2) {
1213
+ const holder = parseHolder(text2);
1214
+ if (!holder) return false;
1215
+ const start = processStart(holder.pid);
1216
+ return start !== null && start === holder.start;
1217
+ }
1218
+ function pause(ms, signal) {
1219
+ return new Promise((resolve) => {
1220
+ const done = () => {
1221
+ clearTimeout(timer);
1222
+ signal?.removeEventListener("abort", done);
1223
+ resolve();
1224
+ };
1225
+ const timer = setTimeout(done, ms);
1226
+ signal?.addEventListener("abort", done, { once: true });
1227
+ });
1228
+ }
1229
+ async function withSwiftRootLock(root, work, signal) {
1230
+ const directory = import_node_path5.default.join(rnxHomeDir(), "cache", "swift-root-locks");
1231
+ (0, import_node_fs3.mkdirSync)(directory, { recursive: true });
1232
+ const lock = import_node_path5.default.join(
1233
+ directory,
1234
+ `${(0, import_node_crypto2.createHash)("sha256").update(root).digest("hex").slice(0, 32)}.lock`
1235
+ );
1236
+ const token = (0, import_node_crypto2.randomUUID)();
1237
+ const owner = JSON.stringify({
1238
+ pid: process.pid,
1239
+ start: processStart(process.pid),
1240
+ token
1241
+ });
1242
+ const pending = `${lock}.${token}`;
1243
+ (0, import_node_fs3.writeFileSync)(pending, owner);
1244
+ try {
1245
+ for (; ; ) {
1246
+ signal?.throwIfAborted();
1247
+ try {
1248
+ (0, import_node_fs3.linkSync)(pending, lock);
1249
+ break;
1250
+ } catch (error) {
1251
+ if (!(error instanceof Error && "code" in error && error.code === "EEXIST"))
1252
+ throw error;
1253
+ }
1254
+ const held = readLock(lock);
1255
+ if (held === null) continue;
1256
+ if (holderAlive(held)) {
1257
+ await pause(POLL_MS, signal);
1258
+ continue;
1259
+ }
1260
+ const dead = `${lock}.dead-${token}`;
1261
+ try {
1262
+ (0, import_node_fs3.renameSync)(lock, dead);
1263
+ } catch (error) {
1264
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") continue;
1265
+ throw error;
1266
+ }
1267
+ try {
1268
+ if (readLock(dead) !== held) {
1269
+ try {
1270
+ (0, import_node_fs3.linkSync)(dead, lock);
1271
+ } catch (error) {
1272
+ if (!(error instanceof Error && "code" in error && error.code === "EEXIST"))
1273
+ throw error;
1274
+ }
1275
+ }
1276
+ } finally {
1277
+ (0, import_node_fs3.rmSync)(dead, { force: true });
1278
+ }
1279
+ }
1280
+ } finally {
1281
+ (0, import_node_fs3.rmSync)(pending, { force: true });
1282
+ }
1283
+ try {
1284
+ return await work();
1285
+ } finally {
1286
+ if (readLock(lock) === owner) (0, import_node_fs3.rmSync)(lock, { force: true });
1287
+ }
1288
+ }
1289
+
1166
1290
  // src/swiftContract.ts
1167
1291
  function isSwiftResourcePath(value) {
1168
1292
  return typeof value === "string" && value.length <= 4096 && !value.startsWith("/") && !value.includes("\\") && !value.includes("\0") && value.split("/").every((part) => part !== "" && part !== "." && part !== "..");
@@ -1177,12 +1301,12 @@ function isSwiftResourceBundles(value) {
1177
1301
  }
1178
1302
 
1179
1303
  // src/swift-compile.ts
1180
- async function runCompiler(command, args, options, stream = false) {
1304
+ async function runCompiler(command, args, options, stream = false, quiet) {
1181
1305
  const { signal } = options;
1182
1306
  signal?.throwIfAborted();
1183
- const child = (0, import_node_child_process4.spawn)(command, args, {
1307
+ const child = (0, import_node_child_process5.spawn)(command, args, {
1184
1308
  cwd: options.cwd,
1185
- env: options.env,
1309
+ env: swiftEnvironment(options.env),
1186
1310
  detached: true,
1187
1311
  stdio: ["ignore", "pipe", "pipe"]
1188
1312
  });
@@ -1193,6 +1317,7 @@ async function runCompiler(command, args, options, stream = false) {
1193
1317
  let timeout;
1194
1318
  const chunks = { stdout: [], stderr: [] };
1195
1319
  const sizes = { stdout: 0, stderr: 0 };
1320
+ const partial = { stdout: "", stderr: "" };
1196
1321
  const stop = () => {
1197
1322
  stopping ??= terminateProcessGroup(child);
1198
1323
  void stopping.catch(() => {
@@ -1200,7 +1325,14 @@ async function runCompiler(command, args, options, stream = false) {
1200
1325
  };
1201
1326
  for (const name of ["stdout", "stderr"]) {
1202
1327
  child[name].on("data", (bytes) => {
1203
- if (stream) process[name].write(bytes);
1328
+ if (stream === true) process[name].write(bytes);
1329
+ else if (stream) {
1330
+ const lines = (partial[name] + bytes.toString()).split("\n");
1331
+ partial[name] = lines.pop();
1332
+ for (const line of lines)
1333
+ if (stream.test(line)) process[name].write(`${line}
1334
+ `);
1335
+ }
1204
1336
  sizes[name] += bytes.length;
1205
1337
  if (sizes[name] <= (options.maxBuffer ?? 1024 * 1024)) chunks[name].push(bytes);
1206
1338
  else {
@@ -1230,7 +1362,15 @@ async function runCompiler(command, args, options, stream = false) {
1230
1362
  }
1231
1363
  )
1232
1364
  );
1233
- else resolve();
1365
+ else {
1366
+ if (quiet) {
1367
+ for (const name of ["stdout", "stderr"])
1368
+ for (const line of Buffer.concat(chunks[name]).toString().split("\n"))
1369
+ if (line && !quiet.test(line)) process[name].write(`${line}
1370
+ `);
1371
+ }
1372
+ resolve();
1373
+ }
1234
1374
  });
1235
1375
  if (options.timeout)
1236
1376
  timeout = setTimeout(() => {
@@ -1244,16 +1384,18 @@ async function runCompiler(command, args, options, stream = false) {
1244
1384
  }
1245
1385
  }
1246
1386
  var WASM_TRIPLE = "wasm32-unknown-wasip1";
1387
+ var SWIFTPM_PROGRESS = /^\[\d+\/\d+\] /;
1388
+ var SWIFTPM_NOISE = /^(?:\[\d+\/\d+\] |Building for production\.\.\.$|warning: '--build-system native' has been deprecated)/;
1247
1389
  var BUILD_JOBS = String(
1248
1390
  Math.min(4, Math.max(1, Math.floor(import_node_os3.default.availableParallelism() / 2)))
1249
1391
  );
1250
1392
  function swiftDistributionAt(root) {
1251
- const file = import_node_path5.default.join(root, SWIFT_DISTRIBUTION_MANIFEST);
1252
- if (!(0, import_node_fs3.existsSync)(file)) return null;
1253
- return parseSwiftDistributionManifest(JSON.parse((0, import_node_fs3.readFileSync)(file, "utf8")));
1393
+ const file = import_node_path6.default.join(root, SWIFT_DISTRIBUTION_MANIFEST);
1394
+ if (!(0, import_node_fs4.existsSync)(file)) return null;
1395
+ return parseSwiftDistributionManifest(JSON.parse((0, import_node_fs4.readFileSync)(file, "utf8")));
1254
1396
  }
1255
1397
  function swiftModuleSdk(root) {
1256
- const pin = swiftDistributionAt(root) ?? JSON.parse((0, import_node_fs3.readFileSync)(import_node_path5.default.join(root, "toolchain.json"), "utf8"));
1398
+ const pin = swiftDistributionAt(root) ?? JSON.parse((0, import_node_fs4.readFileSync)(import_node_path6.default.join(root, "toolchain.json"), "utf8"));
1257
1399
  if (!pin || typeof pin !== "object" || typeof Reflect.get(pin, "wasmSdkId") !== "string" || typeof Reflect.get(pin, "wasmSdkUrl") !== "string" || typeof Reflect.get(pin, "wasmSdkChecksum") !== "string")
1258
1400
  throw new Error(`${root} pins no wasm SDK id, url and checksum`);
1259
1401
  return {
@@ -1269,13 +1411,17 @@ function swiftModuleInputFiles(root) {
1269
1411
  "scripts/contrast-app-Package.swift",
1270
1412
  "scripts/build-distribution.ts",
1271
1413
  "scripts/distribution-clang.ts",
1414
+ "scripts/distribution-libxml2.ts",
1415
+ "scripts/distribution-libxml2.json",
1416
+ "Sources/libxml2/include/module.modulemap",
1417
+ "Sources/libxml2/COPYING",
1272
1418
  "scripts/build-distribution-plugins.sh",
1273
1419
  "scripts/build-distribution-plugins-docker.sh",
1274
1420
  "scripts/build-preview-plugin.sh",
1275
1421
  "toolchain.json"
1276
1422
  ];
1277
1423
  const walk = (dir) => {
1278
- for (const entry of (0, import_node_fs3.readdirSync)(import_node_path5.default.join(root, dir), {
1424
+ for (const entry of (0, import_node_fs4.readdirSync)(import_node_path6.default.join(root, dir), {
1279
1425
  withFileTypes: true
1280
1426
  })) {
1281
1427
  const relative = `${dir}/${entry.name}`;
@@ -1293,29 +1439,39 @@ function swiftMacroPlugins(moduleRoot) {
1293
1439
  const distribution = swiftDistributionAt(moduleRoot);
1294
1440
  if (distribution)
1295
1441
  return {
1296
- libraries: distribution.plugins.map((plugin) => import_node_path5.default.join(moduleRoot, plugin)),
1442
+ libraries: distribution.plugins.map((plugin) => import_node_path6.default.join(moduleRoot, plugin)),
1297
1443
  stale: false
1298
1444
  };
1299
- const dir = import_node_path5.default.join(moduleRoot, ".build/host/RnxPreviewMacros");
1445
+ const dir = import_node_path6.default.join(moduleRoot, ".build/host/RnxPreviewMacros");
1300
1446
  const release = JSON.parse(
1301
- (0, import_node_fs3.readFileSync)(import_node_path5.default.join(moduleRoot, "toolchain.json"), "utf8")
1447
+ (0, import_node_fs4.readFileSync)(import_node_path6.default.join(moduleRoot, "toolchain.json"), "utf8")
1302
1448
  ).release;
1303
- const compilerStamp = import_node_path5.default.join(dir, "compiler-release");
1449
+ const compilerStamp = import_node_path6.default.join(dir, "compiler-release");
1304
1450
  const ext = process.platform === "darwin" ? "dylib" : "so";
1305
1451
  const plugins = [
1306
1452
  {
1307
- library: import_node_path5.default.join(dir, `libRnxPreviewMacros.${ext}`),
1308
- source: import_node_path5.default.join(moduleRoot, "Sources/RnxPreviewMacros/PreviewMacro.swift")
1453
+ library: import_node_path6.default.join(dir, `libRnxPreviewMacros.${ext}`),
1454
+ sources: [import_node_path6.default.join(moduleRoot, "Sources/RnxPreviewMacros/PreviewMacro.swift")]
1455
+ },
1456
+ {
1457
+ library: import_node_path6.default.join(dir, `libFoundationMacros.${ext}`),
1458
+ sources: [
1459
+ import_node_path6.default.join(moduleRoot, "Sources/FoundationMacros/PredicateMacro.swift"),
1460
+ import_node_path6.default.join(moduleRoot, "Sources/SwiftMacroSupport/PredicateExpression.swift")
1461
+ ]
1309
1462
  },
1310
1463
  {
1311
- library: import_node_path5.default.join(dir, `libFoundationMacros.${ext}`),
1312
- source: import_node_path5.default.join(moduleRoot, "Sources/FoundationMacros/PredicateMacro.swift")
1464
+ library: import_node_path6.default.join(dir, `libTipKitMacros.${ext}`),
1465
+ sources: [
1466
+ import_node_path6.default.join(moduleRoot, "Sources/TipKitMacros/TipKitMacros.swift"),
1467
+ import_node_path6.default.join(moduleRoot, "Sources/SwiftMacroSupport/PredicateExpression.swift")
1468
+ ]
1313
1469
  }
1314
1470
  ];
1315
1471
  return {
1316
1472
  libraries: plugins.map(({ library }) => library),
1317
- stale: !(0, import_node_fs3.existsSync)(compilerStamp) || (0, import_node_fs3.readFileSync)(compilerStamp, "utf8").trim() !== release || plugins.some(
1318
- ({ library, source }) => !(0, import_node_fs3.existsSync)(library) || (0, import_node_fs3.statSync)(source).mtimeMs > (0, import_node_fs3.statSync)(library).mtimeMs
1473
+ stale: !(0, import_node_fs4.existsSync)(compilerStamp) || (0, import_node_fs4.readFileSync)(compilerStamp, "utf8").trim() !== release || plugins.some(
1474
+ ({ library, sources }) => !(0, import_node_fs4.existsSync)(library) || sources.some((source) => (0, import_node_fs4.statSync)(source).mtimeMs > (0, import_node_fs4.statSync)(library).mtimeMs)
1319
1475
  )
1320
1476
  };
1321
1477
  }
@@ -1325,14 +1481,14 @@ async function ensureMacroPlugins(moduleRoot, toolchainBin, release, signal) {
1325
1481
  await runCompiler(
1326
1482
  "sh",
1327
1483
  [
1328
- import_node_path5.default.join(moduleRoot, "scripts/build-preview-plugin.sh"),
1484
+ import_node_path6.default.join(moduleRoot, "scripts/build-preview-plugin.sh"),
1329
1485
  toolchainBin,
1330
1486
  libraries[0]
1331
1487
  ],
1332
1488
  { signal }
1333
1489
  );
1334
- (0, import_node_fs3.writeFileSync)(
1335
- import_node_path5.default.join(import_node_path5.default.dirname(libraries[0]), "compiler-release"),
1490
+ (0, import_node_fs4.writeFileSync)(
1491
+ import_node_path6.default.join(import_node_path6.default.dirname(libraries[0]), "compiler-release"),
1336
1492
  `${release}
1337
1493
  `
1338
1494
  );
@@ -1346,9 +1502,9 @@ function clearLinkedModuleDigests(root) {
1346
1502
  }
1347
1503
  function swiftModuleDigest(root) {
1348
1504
  const files = swiftModuleInputFiles(root);
1349
- const stampHash = (0, import_node_crypto2.createHash)("sha256");
1505
+ const stampHash = (0, import_node_crypto3.createHash)("sha256");
1350
1506
  for (const file of files) {
1351
- const stat = (0, import_node_fs3.statSync)(import_node_path5.default.join(root, file), { bigint: true });
1507
+ const stat = (0, import_node_fs4.statSync)(import_node_path6.default.join(root, file), { bigint: true });
1352
1508
  stampHash.update(file);
1353
1509
  stampHash.update(
1354
1510
  `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}
@@ -1358,17 +1514,20 @@ function swiftModuleDigest(root) {
1358
1514
  const stamp = stampHash.digest("hex");
1359
1515
  const cached = linkedModuleDigests.get(root);
1360
1516
  if (cached?.stamp === stamp) return cached.digest;
1361
- const hash = (0, import_node_crypto2.createHash)("sha256");
1517
+ const hash = (0, import_node_crypto3.createHash)("sha256");
1362
1518
  for (const file of files) {
1363
- hash.update((0, import_node_crypto2.createHash)("sha256").update(file).digest());
1519
+ hash.update((0, import_node_crypto3.createHash)("sha256").update(file).digest());
1364
1520
  hash.update(
1365
- (0, import_node_crypto2.createHash)("sha256").update((0, import_node_fs3.readFileSync)(import_node_path5.default.join(root, file))).digest()
1521
+ (0, import_node_crypto3.createHash)("sha256").update((0, import_node_fs4.readFileSync)(import_node_path6.default.join(root, file))).digest()
1366
1522
  );
1367
1523
  }
1368
1524
  const digest = hash.digest();
1369
1525
  linkedModuleDigests.set(root, { stamp, digest });
1370
1526
  return digest;
1371
1527
  }
1528
+ function swiftProjectBuildKey(moduleRoot, release) {
1529
+ return (0, import_node_crypto3.createHash)("sha256").update(`${release}\0${swiftModuleSdk(moduleRoot).wasmSdkId}`).update(swiftModuleDigest(moduleRoot)).digest("hex").slice(0, 32);
1530
+ }
1372
1531
  function compileTargets(input) {
1373
1532
  const manifest = input.files["Package.swift"];
1374
1533
  return manifest === void 0 ? [] : swiftPackagePartition(manifest, input.resourcePaths);
@@ -1383,7 +1542,7 @@ function withNativeSourceGlue(input, glue) {
1383
1542
  ...input,
1384
1543
  files: {
1385
1544
  ...input.files,
1386
- [import_node_path5.default.posix.join(targetPath, "OneNativeSource.generated.swift")]: glue
1545
+ [import_node_path6.default.posix.join(targetPath, "OneNativeSource.generated.swift")]: glue
1387
1546
  },
1388
1547
  oneModule: true
1389
1548
  };
@@ -1396,11 +1555,13 @@ var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
1396
1555
  Accelerate: [],
1397
1556
  CryptoKit: [],
1398
1557
  CommonCrypto: [],
1558
+ ImagePlayground: [],
1559
+ QuickLookThumbnailing: [],
1560
+ libxml2: [],
1399
1561
  CoreText: [],
1400
1562
  Compression: ["PeachCodec"],
1401
1563
  zlib: ["PeachCodec"],
1402
1564
  PeachCodec: [],
1403
- Security: ["CryptoKit"],
1404
1565
  TikTokBusinessSDK: [],
1405
1566
  nSure: [],
1406
1567
  Statsig: [],
@@ -1506,7 +1667,7 @@ function swiftImportNames(contents, available) {
1506
1667
  function swiftPeachModules(moduleRoot) {
1507
1668
  const distribution = swiftDistributionAt(moduleRoot);
1508
1669
  return distribution ? distribution.modules : [
1509
- ...(0, import_node_fs3.readFileSync)(import_node_path5.default.join(moduleRoot, "Package.swift"), "utf8").matchAll(
1670
+ ...(0, import_node_fs4.readFileSync)(import_node_path6.default.join(moduleRoot, "Package.swift"), "utf8").matchAll(
1510
1671
  /\.(?:target|systemLibrary)\(\s*name:\s*"([^"]+)"/g
1511
1672
  )
1512
1673
  ].map((match) => match[1]);
@@ -1517,8 +1678,8 @@ function swiftSdkPaths(moduleRoot, toolchainBin) {
1517
1678
  const key = JSON.stringify([toolchainBin, sdk, swiftSdkOptions()]);
1518
1679
  const cached = sdkPaths.get(key);
1519
1680
  if (cached) return cached;
1520
- const configuration = (0, import_node_child_process4.execFileSync)(
1521
- import_node_path5.default.join(toolchainBin, "swift"),
1681
+ const configuration = (0, import_node_child_process5.execFileSync)(
1682
+ import_node_path6.default.join(toolchainBin, "swift"),
1522
1683
  [
1523
1684
  "sdk",
1524
1685
  "configure",
@@ -1527,7 +1688,7 @@ function swiftSdkPaths(moduleRoot, toolchainBin) {
1527
1688
  sdk,
1528
1689
  "wasm32-unknown-wasip1"
1529
1690
  ],
1530
- { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }
1691
+ { encoding: "utf8", env: swiftEnvironment(), stdio: ["ignore", "pipe", "pipe"] }
1531
1692
  );
1532
1693
  const field = (name) => {
1533
1694
  const value = new RegExp(`^${name}:\\s*(.+)$`, "m").exec(configuration)?.[1]?.trim();
@@ -1549,14 +1710,14 @@ function swiftAvailableModules(moduleRoot, toolchainBin) {
1549
1710
  if (cached) return cached;
1550
1711
  const modules = new Set(swiftPeachModules(moduleRoot));
1551
1712
  const { resources } = swiftSdkPaths(moduleRoot, toolchainBin);
1552
- for (const entry of (0, import_node_fs3.readdirSync)(import_node_path5.default.join(resources, "wasi"))) {
1713
+ for (const entry of (0, import_node_fs4.readdirSync)(import_node_path6.default.join(resources, "wasi"))) {
1553
1714
  if (entry.endsWith(".swiftmodule"))
1554
1715
  modules.add(entry.slice(0, -".swiftmodule".length));
1555
1716
  }
1556
- for (const entry of (0, import_node_fs3.readdirSync)(resources)) {
1557
- const map = import_node_path5.default.join(resources, entry, "module.modulemap");
1558
- if (!(0, import_node_fs3.existsSync)(map)) continue;
1559
- for (const match of (0, import_node_fs3.readFileSync)(map, "utf8").matchAll(/^module\s+([A-Za-z_]\w*)/gm))
1717
+ for (const entry of (0, import_node_fs4.readdirSync)(resources)) {
1718
+ const map = import_node_path6.default.join(resources, entry, "module.modulemap");
1719
+ if (!(0, import_node_fs4.existsSync)(map)) continue;
1720
+ for (const match of (0, import_node_fs4.readFileSync)(map, "utf8").matchAll(/^module\s+([A-Za-z_]\w*)/gm))
1560
1721
  modules.add(match[1]);
1561
1722
  }
1562
1723
  availableModules.set(key, modules);
@@ -1620,9 +1781,9 @@ var EXECUTABLE_LINK_FLAGS = ` "-Xclang-linker", "-O0",
1620
1781
  `;
1621
1782
  var REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
1622
1783
  var MULTI_MANIFEST_VERSION = 39;
1623
- var compilerSourceDigest = true ? "fe15160b7f10d0c1ea06e54dc06a1de4d770f6f968e547bd41bd11fc6f5dbd8f" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
1784
+ var compilerSourceDigest = true ? "ee2738333bb81c79211d5bee8a503c539cf65f25c95fb024c45b840450b5359e" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
1624
1785
  function swiftArtifactHash(input, release, moduleRoot) {
1625
- const hash = (0, import_node_crypto2.createHash)("sha256");
1786
+ const hash = (0, import_node_crypto3.createHash)("sha256");
1626
1787
  hash.update(`swift-compile
1627
1788
  ${release}
1628
1789
  `);
@@ -1630,32 +1791,32 @@ ${release}
1630
1791
  if (input.oneModule) hash.update("one-module\n");
1631
1792
  hash.update(swiftModuleDigest(moduleRoot));
1632
1793
  for (const file of Object.keys(input.files).sort()) {
1633
- hash.update((0, import_node_crypto2.createHash)("sha256").update(file).digest());
1634
- hash.update((0, import_node_crypto2.createHash)("sha256").update(input.files[file]).digest());
1794
+ hash.update((0, import_node_crypto3.createHash)("sha256").update(file).digest());
1795
+ hash.update((0, import_node_crypto3.createHash)("sha256").update(input.files[file]).digest());
1635
1796
  }
1636
1797
  for (const file of Object.keys(input.metalSources ?? {}).sort()) {
1637
1798
  hash.update("metal-source\n");
1638
- hash.update((0, import_node_crypto2.createHash)("sha256").update(file).digest());
1799
+ hash.update((0, import_node_crypto3.createHash)("sha256").update(file).digest());
1639
1800
  hash.update(
1640
- (0, import_node_crypto2.createHash)("sha256").update(input.metalSources?.[file] ?? "").digest()
1801
+ (0, import_node_crypto3.createHash)("sha256").update(input.metalSources?.[file] ?? "").digest()
1641
1802
  );
1642
1803
  }
1643
1804
  for (const base of Object.keys(input.resources ?? {}).sort()) {
1644
- hash.update((0, import_node_crypto2.createHash)("sha256").update(base).digest());
1805
+ hash.update((0, import_node_crypto3.createHash)("sha256").update(base).digest());
1645
1806
  hash.update(
1646
- (0, import_node_crypto2.createHash)("sha256").update(input.resources?.[base] ?? "").digest()
1807
+ (0, import_node_crypto3.createHash)("sha256").update(input.resources?.[base] ?? "").digest()
1647
1808
  );
1648
1809
  }
1649
1810
  for (const name of Object.keys(input.images ?? {}).sort()) {
1650
1811
  const image = input.images?.[name];
1651
1812
  if (!image) continue;
1652
- hash.update((0, import_node_crypto2.createHash)("sha256").update(name).digest());
1653
- hash.update((0, import_node_crypto2.createHash)("sha256").update(image.file).digest());
1654
- hash.update((0, import_node_crypto2.createHash)("sha256").update(image.data).digest());
1813
+ hash.update((0, import_node_crypto3.createHash)("sha256").update(name).digest());
1814
+ hash.update((0, import_node_crypto3.createHash)("sha256").update(image.file).digest());
1815
+ hash.update((0, import_node_crypto3.createHash)("sha256").update(image.data).digest());
1655
1816
  }
1656
1817
  for (const file of [...new Set(input.resourcePaths ?? [])].sort()) {
1657
1818
  hash.update("resource-path\n");
1658
- hash.update((0, import_node_crypto2.createHash)("sha256").update(file).digest());
1819
+ hash.update((0, import_node_crypto3.createHash)("sha256").update(file).digest());
1659
1820
  }
1660
1821
  hash.update(
1661
1822
  JSON.stringify(
@@ -1667,7 +1828,7 @@ ${release}
1667
1828
  ${target}
1668
1829
  `);
1669
1830
  hash.update(
1670
- (0, import_node_crypto2.createHash)("sha256").update(input.libraries?.[target] ?? "").digest()
1831
+ (0, import_node_crypto3.createHash)("sha256").update(input.libraries?.[target] ?? "").digest()
1671
1832
  );
1672
1833
  }
1673
1834
  const targets = compileTargets(input);
@@ -1714,21 +1875,21 @@ function emitSwiftPackageManifest(args) {
1714
1875
  distributionLink.files.set(
1715
1876
  distributionLink.path,
1716
1877
  objects.map(
1717
- (object) => `"${import_node_path5.default.join(moduleRoot, object).replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`
1878
+ (object) => `"${import_node_path6.default.join(moduleRoot, object).replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`
1718
1879
  ).join("\n") + "\n"
1719
1880
  );
1720
1881
  }
1721
- const overlayRoot = import_node_path5.default.join(
1882
+ const overlayRoot = import_node_path6.default.join(
1722
1883
  moduleRoot,
1723
1884
  distribution ? "modules" : "cross-import-overlays"
1724
1885
  );
1725
- const overlayFlags = (0, import_node_fs3.readdirSync)(overlayRoot, { encoding: "utf8", recursive: true }).filter((file) => file.endsWith(".swiftoverlay")).sort((left, right) => left.localeCompare(right)).flatMap((file) => [
1886
+ const overlayFlags = (0, import_node_fs4.readdirSync)(overlayRoot, { encoding: "utf8", recursive: true }).filter((file) => file.endsWith(".swiftoverlay")).sort((left, right) => left.localeCompare(right)).flatMap((file) => [
1726
1887
  "-Xfrontend",
1727
1888
  "-swift-module-cross-import",
1728
1889
  "-Xfrontend",
1729
- import_node_path5.default.basename(import_node_path5.default.dirname(file), ".swiftcrossimport"),
1890
+ import_node_path6.default.basename(import_node_path6.default.dirname(file), ".swiftcrossimport"),
1730
1891
  "-Xfrontend",
1731
- import_node_path5.default.join(overlayRoot, file)
1892
+ import_node_path6.default.join(overlayRoot, file)
1732
1893
  ]).map((flag) => `, ${JSON.stringify(flag)}`).join("");
1733
1894
  const executable = targets.find((target) => target.executable);
1734
1895
  if (!executable) throw new Error("swift-compile: no executable target to emit");
@@ -1738,14 +1899,14 @@ function emitSwiftPackageManifest(args) {
1738
1899
  const isolation = target.mainActorIsolation ? " .defaultIsolation(MainActor.self)," : "";
1739
1900
  const interoperability = target.cxxInterop ? " .interoperabilityMode(.Cxx)," : "";
1740
1901
  const defines = (target.defines ?? []).map((name) => ` .define(${JSON.stringify(name)}),`).join("");
1741
- const imports = distribution ? `, "-I", ${JSON.stringify(import_node_path5.default.join(moduleRoot, "modules"))}` : "";
1902
+ const imports = distribution ? `, "-I", ${JSON.stringify(import_node_path6.default.join(moduleRoot, "modules"))}` : "";
1742
1903
  const native = args.native?.get(target.name);
1743
1904
  const nativeImports = (siblings.get(target.name) ?? []).filter((name) => args.native?.has(name)).map(
1744
1905
  (name) => `, "-Xfrontend", "-import-module", "-Xfrontend", ${JSON.stringify(swiftTargetModuleName(name))}`
1745
1906
  ).join("");
1746
1907
  const header = args.headerDirectory && [...args.native?.values() ?? []].some(
1747
1908
  (value) => value.late?.producers.includes(target.name)
1748
- ) ? `, "-emit-objc-header-path", ${JSON.stringify(import_node_path5.default.join(args.headerDirectory, `${target.name}-Swift.h`))}` : "";
1909
+ ) ? `, "-emit-objc-header-path", ${JSON.stringify(import_node_path6.default.join(args.headerDirectory, `${target.name}-Swift.h`))}` : "";
1749
1910
  const swiftSettings = `swiftSettings: [.swiftLanguageMode(.v${target.languageMode}),${isolation}${interoperability}${defines} .unsafeFlags(["-Osize", "-Xfrontend", "-enable-cross-import-overlays"${overlayFlags}${FOUNDATION_IMPLICIT_FLAGS}${oneModule ? ONE_IMPLICIT_FLAGS : ""}${imports}${nativeImports}${header}])]`;
1750
1911
  const deps = [
1751
1912
  ...target.executable ? [...args.native?.values() ?? []].flatMap(
@@ -1760,7 +1921,7 @@ function emitSwiftPackageManifest(args) {
1760
1921
  (dependency) => OPTIONAL_FRAMEWORKS.has(dependency) && !targets.some((candidate) => candidate.name === dependency) ? distribution ? [] : [`.product(name: "${dependency}", package: "sootsim-swift")`] : [`"${dependency}"`]
1761
1922
  )
1762
1923
  ].join(", ");
1763
- const library = distribution && distributionLink ? ["-Xlinker", `@${distributionLink.path}`, ...distribution.link].map((flag) => `, ${JSON.stringify(flag)}`).join("") : "";
1924
+ const library = distribution && distributionLink ? ["-Xclang-linker", `--config=${distributionLink.path}`, ...distribution.link].map((flag) => `, ${JSON.stringify(flag)}`).join("") : "";
1764
1925
  const kind = target.executable ? ".executableTarget" : ".target";
1765
1926
  const linkedLibraries = (target.linkedLibraries ?? []).map(
1766
1927
  (name) => `.linkedLibrary(${JSON.stringify(name)})`
@@ -1818,21 +1979,21 @@ function emitSwiftPackageManifest(args) {
1818
1979
  ].join("\n");
1819
1980
  }
1820
1981
  function syncSwiftTree(base, files) {
1821
- (0, import_node_fs3.mkdirSync)(base, { recursive: true });
1982
+ (0, import_node_fs4.mkdirSync)(base, { recursive: true });
1822
1983
  const walk = (dir) => {
1823
- for (const entry of (0, import_node_fs3.readdirSync)(dir, { withFileTypes: true })) {
1824
- const full = import_node_path5.default.join(dir, entry.name);
1984
+ for (const entry of (0, import_node_fs4.readdirSync)(dir, { withFileTypes: true })) {
1985
+ const full = import_node_path6.default.join(dir, entry.name);
1825
1986
  if (dir === base && entry.name === ".build") continue;
1826
1987
  if (entry.isDirectory()) walk(full);
1827
- else if (!files.has(full)) (0, import_node_fs3.rmSync)(full, { force: true });
1988
+ else if (!files.has(full)) (0, import_node_fs4.rmSync)(full, { force: true });
1828
1989
  }
1829
1990
  };
1830
1991
  walk(base);
1831
1992
  for (const [full, contents] of files) {
1832
- if ((0, import_node_fs3.existsSync)(full) && (typeof contents === "string" ? (0, import_node_fs3.readFileSync)(full, "utf8") === contents : (0, import_node_fs3.readFileSync)(full).equals(contents)))
1993
+ if ((0, import_node_fs4.existsSync)(full) && (typeof contents === "string" ? (0, import_node_fs4.readFileSync)(full, "utf8") === contents : (0, import_node_fs4.readFileSync)(full).equals(contents)))
1833
1994
  continue;
1834
- (0, import_node_fs3.mkdirSync)(import_node_path5.default.dirname(full), { recursive: true });
1835
- (0, import_node_fs3.writeFileSync)(full, contents);
1995
+ (0, import_node_fs4.mkdirSync)(import_node_path6.default.dirname(full), { recursive: true });
1996
+ (0, import_node_fs4.writeFileSync)(full, contents);
1836
1997
  }
1837
1998
  }
1838
1999
  var DIRECTIVE = /^[ \t]*#(?:if|elseif)\b/;
@@ -2255,19 +2416,24 @@ function objcRootedClasses(sources) {
2255
2416
  function hideObjCClassesFromCxx(source, rooted) {
2256
2417
  if (rooted.size === 0) return source;
2257
2418
  const code = swiftCodeMask(source);
2258
- const starts = [];
2419
+ const insertions = [];
2259
2420
  let depth = 0;
2260
2421
  for (const match of code.matchAll(
2261
2422
  /[{}]|\bclass\s+(?!(?:func|var|let|subscript)\b)([A-Za-z_]\w*)/g
2262
2423
  )) {
2263
2424
  if (match[0] === "{") depth++;
2264
2425
  else if (match[0] === "}") depth--;
2265
- else if (depth === 0 && rooted.has(match[1]))
2266
- starts.push(declarationStart(code, match.index, 0));
2426
+ else if (depth === 0 && rooted.has(match[1])) {
2427
+ const start = declarationStart(code, match.index, 0);
2428
+ const main = /@main\b/.exec(code.slice(start, match.index));
2429
+ insertions.push(
2430
+ main ? { at: start + main.index + main[0].length, text: " @_expose(!Cxx)" } : { at: start, text: "@_expose(!Cxx) " }
2431
+ );
2432
+ }
2267
2433
  }
2268
2434
  let out = source;
2269
- for (const at of starts.reverse())
2270
- out = `${out.slice(0, at)}@_expose(!Cxx) ${out.slice(at)}`;
2435
+ for (const { at, text: text2 } of insertions.reverse())
2436
+ out = `${out.slice(0, at)}${text2}${out.slice(at)}`;
2271
2437
  return out;
2272
2438
  }
2273
2439
  function lowerAnyObjectDoubleValue(source) {
@@ -5540,7 +5706,7 @@ function swiftApplicationEntry(file, source) {
5540
5706
  else if (source[at] === "}") depth--;
5541
5707
  else if (depth === 0 && /^@(?:main|UIApplicationMain)\b/.test(source.slice(at)))
5542
5708
  return true;
5543
- else if (depth === 0 && import_node_path5.default.basename(file) === "main.swift" && /^UIApplicationMain\s*\(/.test(source.slice(at)))
5709
+ else if (depth === 0 && import_node_path6.default.basename(file) === "main.swift" && /^UIApplicationMain\s*\(/.test(source.slice(at)))
5544
5710
  return true;
5545
5711
  }
5546
5712
  return false;
@@ -5640,33 +5806,33 @@ function swiftCodeScan(source) {
5640
5806
  return { lineStarts: starts, tokens };
5641
5807
  }
5642
5808
  function prepareSwiftDependency(source, destination) {
5643
- (0, import_node_fs3.rmSync)(destination, { recursive: true, force: true });
5809
+ (0, import_node_fs4.rmSync)(destination, { recursive: true, force: true });
5644
5810
  const origins = {};
5645
5811
  const gather = (from) => {
5646
- for (const entry of (0, import_node_fs3.readdirSync)(from, { withFileTypes: true })) {
5812
+ for (const entry of (0, import_node_fs4.readdirSync)(from, { withFileTypes: true })) {
5647
5813
  if (entry.name === ".git" || entry.name === ".build" || entry.name === ".swiftpm")
5648
5814
  continue;
5649
- const file = import_node_path5.default.join(from, entry.name);
5815
+ const file = import_node_path6.default.join(from, entry.name);
5650
5816
  if (entry.isDirectory()) gather(file);
5651
5817
  else if (entry.isFile() && entry.name.endsWith(".swift"))
5652
- origins[import_node_path5.default.relative(source, file)] = (0, import_node_fs3.readFileSync)(file, "utf8");
5818
+ origins[import_node_path6.default.relative(source, file)] = (0, import_node_fs4.readFileSync)(file, "utf8");
5653
5819
  }
5654
5820
  };
5655
5821
  gather(source);
5656
- const manifest = import_node_path5.default.join(source, "Package.swift");
5657
- const targets = (0, import_node_fs3.existsSync)(manifest) ? swiftManifestTargets((0, import_node_fs3.readFileSync)(manifest, "utf8")) : [];
5822
+ const manifest = import_node_path6.default.join(source, "Package.swift");
5823
+ const targets = (0, import_node_fs4.existsSync)(manifest) ? swiftManifestTargets((0, import_node_fs4.readFileSync)(manifest, "utf8")) : [];
5658
5824
  const compiled = compiledSwiftSources(origins, targets);
5659
5825
  const copy = (from, to) => {
5660
- (0, import_node_fs3.mkdirSync)(to, { recursive: true });
5661
- for (const entry of (0, import_node_fs3.readdirSync)(from, { withFileTypes: true })) {
5826
+ (0, import_node_fs4.mkdirSync)(to, { recursive: true });
5827
+ for (const entry of (0, import_node_fs4.readdirSync)(from, { withFileTypes: true })) {
5662
5828
  if (entry.name === ".git" || entry.name === ".build" || entry.name === ".swiftpm")
5663
5829
  continue;
5664
- const file = import_node_path5.default.join(from, entry.name);
5665
- const target = import_node_path5.default.join(to, entry.name);
5830
+ const file = import_node_path6.default.join(from, entry.name);
5831
+ const target = import_node_path6.default.join(to, entry.name);
5666
5832
  if (entry.isDirectory()) copy(file, target);
5667
5833
  else if (entry.isFile() && entry.name.endsWith(".swift"))
5668
- (0, import_node_fs3.writeFileSync)(target, compiled.get(import_node_path5.default.relative(source, file)));
5669
- else (0, import_node_fs3.cpSync)(file, target, { verbatimSymlinks: true });
5834
+ (0, import_node_fs4.writeFileSync)(target, compiled.get(import_node_path6.default.relative(source, file)));
5835
+ else (0, import_node_fs4.cpSync)(file, target, { verbatimSymlinks: true });
5670
5836
  }
5671
5837
  };
5672
5838
  copy(source, destination);
@@ -5682,7 +5848,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
5682
5848
  const targets = distribution && compileTargets(input).length === 0 ? [
5683
5849
  {
5684
5850
  name: "App",
5685
- path: import_node_path5.default.relative(layout.root, layout.sources),
5851
+ path: import_node_path6.default.relative(layout.root, layout.sources),
5686
5852
  executable: true,
5687
5853
  languageMode: 5,
5688
5854
  mainActorIsolation: false,
@@ -5691,7 +5857,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
5691
5857
  ] : compileTargets(input);
5692
5858
  const files = /* @__PURE__ */ new Map();
5693
5859
  const native = /* @__PURE__ */ new Map();
5694
- const headerDirectory = import_node_path5.default.join(layout.root, ".build", "peach-cxx-headers");
5860
+ const headerDirectory = import_node_path6.default.join(layout.root, ".build", "peach-cxx-headers");
5695
5861
  for (const target of targets) {
5696
5862
  const prefix = target.path === "." ? "" : `${target.path}/`;
5697
5863
  const entries = Object.entries(input.files).filter(
@@ -5714,7 +5880,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
5714
5880
  if (producer && targets.some((value) => value.name === producer))
5715
5881
  producers.add(producer);
5716
5882
  const local = [
5717
- import_node_path5.default.posix.join(import_node_path5.default.posix.dirname(file), include),
5883
+ import_node_path6.default.posix.join(import_node_path6.default.posix.dirname(file), include),
5718
5884
  `${includes}${include}`
5719
5885
  ].find((candidate) => input.files[candidate] !== void 0);
5720
5886
  if (local) {
@@ -5736,7 +5902,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
5736
5902
  const late = units.filter(([file]) => consumers.get(file).size > 0);
5737
5903
  native.set(target.name, {
5738
5904
  path: target.path,
5739
- includeDirectory: import_node_path5.default.join(layout.root, includes),
5905
+ includeDirectory: import_node_path6.default.join(layout.root, includes),
5740
5906
  lateSources: late.map(([file]) => file.slice(prefix.length)),
5741
5907
  ...late.length > 0 ? {
5742
5908
  late: {
@@ -5753,7 +5919,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
5753
5919
  ([file]) => file.startsWith(includes) && /\.(?:h|hpp|hh|hxx)$/.test(file) && consumers.get(file).size === 0
5754
5920
  );
5755
5921
  files.set(
5756
- import_node_path5.default.join(layout.root, includes, "module.modulemap"),
5922
+ import_node_path6.default.join(layout.root, includes, "module.modulemap"),
5757
5923
  [
5758
5924
  `module ${target.name} {`,
5759
5925
  ...roots.map(
@@ -5765,14 +5931,14 @@ function writeSwiftProject(layout, input, moduleRoot) {
5765
5931
  ].join("\n")
5766
5932
  );
5767
5933
  }
5768
- if (native.size > 0) (0, import_node_fs3.mkdirSync)(headerDirectory, { recursive: true });
5769
- const modulePlan = (0, import_node_crypto2.createHash)("sha256").update(
5934
+ if (native.size > 0) (0, import_node_fs4.mkdirSync)(headerDirectory, { recursive: true });
5935
+ const modulePlan = (0, import_node_crypto3.createHash)("sha256").update(
5770
5936
  swiftModuleInputFiles(moduleRoot).join("\n")
5771
5937
  );
5772
5938
  if (!distribution) {
5773
- modulePlan.update((0, import_node_fs3.readFileSync)(import_node_path5.default.join(moduleRoot, "Package.swift")));
5939
+ modulePlan.update((0, import_node_fs4.readFileSync)(import_node_path6.default.join(moduleRoot, "Package.swift")));
5774
5940
  }
5775
- const resourcePlan = (0, import_node_crypto2.createHash)("sha256").update(
5941
+ const resourcePlan = (0, import_node_crypto3.createHash)("sha256").update(
5776
5942
  JSON.stringify(
5777
5943
  resourceTargets.filter((target) => target.resources).map((target) => [
5778
5944
  target.name,
@@ -5797,10 +5963,10 @@ function writeSwiftProject(layout, input, moduleRoot) {
5797
5963
  if (targets.length === 0) {
5798
5964
  for (const [file, contents] of Object.entries(input.files)) {
5799
5965
  if (file === "Package.swift") continue;
5800
- files.set(import_node_path5.default.join(layout.sources, file), compiled.get(file) ?? contents);
5966
+ files.set(import_node_path6.default.join(layout.sources, file), compiled.get(file) ?? contents);
5801
5967
  }
5802
- let manifest = (0, import_node_fs3.readFileSync)(
5803
- import_node_path5.default.join(moduleRoot, "scripts/contrast-app-Package.swift"),
5968
+ let manifest = (0, import_node_fs4.readFileSync)(
5969
+ import_node_path6.default.join(moduleRoot, "scripts/contrast-app-Package.swift"),
5804
5970
  "utf8"
5805
5971
  ).replaceAll("__SOOTSIM_SWIFT_PACKAGE__", moduleRoot);
5806
5972
  const reactor = ` ${REACTOR_FLAG}`;
@@ -5844,21 +6010,21 @@ function writeSwiftProject(layout, input, moduleRoot) {
5844
6010
  manifest = manifest.replace(anchor, `${anchor}
5845
6011
  ${SPRITEKIT_PRODUCT},`);
5846
6012
  }
5847
- files.set(import_node_path5.default.join(layout.root, "Package.swift"), manifest + moduleFiles);
6013
+ files.set(import_node_path6.default.join(layout.root, "Package.swift"), manifest + moduleFiles);
5848
6014
  } else {
5849
6015
  const base = layout.multi ? layout.root : layout.sources;
5850
6016
  const libraries = /* @__PURE__ */ new Map();
5851
6017
  for (const [target, data] of Object.entries(input.libraries ?? {})) {
5852
- const file = import_node_path5.default.join(layout.root, ".peach-libraries", `lib${target}.a`);
6018
+ const file = import_node_path6.default.join(layout.root, ".peach-libraries", `lib${target}.a`);
5853
6019
  files.set(file, Buffer.from(data, "base64"));
5854
6020
  libraries.set(target, file);
5855
6021
  }
5856
6022
  for (const [file, contents] of Object.entries(input.files)) {
5857
6023
  if (file === "Package.swift") continue;
5858
- files.set(import_node_path5.default.join(base, file), compiled.get(file) ?? contents);
6024
+ files.set(import_node_path6.default.join(base, file), compiled.get(file) ?? contents);
5859
6025
  }
5860
6026
  files.set(
5861
- import_node_path5.default.join(layout.root, "Package.swift"),
6027
+ import_node_path6.default.join(layout.root, "Package.swift"),
5862
6028
  emitSwiftPackageManifest({
5863
6029
  targets,
5864
6030
  native,
@@ -5875,7 +6041,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
5875
6041
  spriteKit: importsSpriteKit(input.files),
5876
6042
  distribution: distribution ?? void 0,
5877
6043
  distributionLink: {
5878
- path: import_node_path5.default.join(layout.root, ".peach-distribution-objects.rsp"),
6044
+ path: import_node_path6.default.join(layout.root, ".peach-distribution-objects.rsp"),
5879
6045
  files
5880
6046
  },
5881
6047
  libraries
@@ -5891,9 +6057,9 @@ function writeSwiftProject(layout, input, moduleRoot) {
5891
6057
  throw new Error(
5892
6058
  `swift resource target ${target.name} has no matching bundle assignment`
5893
6059
  );
5894
- const directory = layout.multi ? import_node_path5.default.join(layout.root, target.path) : layout.sources;
6060
+ const directory = layout.multi ? import_node_path6.default.join(layout.root, target.path) : layout.sources;
5895
6061
  files.set(
5896
- import_node_path5.default.join(directory, "ResourceBundleAccessor.generated.swift"),
6062
+ import_node_path6.default.join(directory, "ResourceBundleAccessor.generated.swift"),
5897
6063
  [
5898
6064
  "import Foundation",
5899
6065
  "",
@@ -5926,15 +6092,15 @@ function outputOf(error) {
5926
6092
  return error instanceof Error ? error.message : String(error);
5927
6093
  }
5928
6094
  function builtArtifact(layout) {
5929
- const binDir = import_node_path5.default.join(layout.root, ".build", WASM_TRIPLE, "release");
5930
- const manifest = (0, import_node_fs3.readFileSync)(import_node_path5.default.join(layout.root, "Package.swift"), "utf8");
6095
+ const binDir = import_node_path6.default.join(layout.root, ".build", WASM_TRIPLE, "release");
6096
+ const manifest = (0, import_node_fs4.readFileSync)(import_node_path6.default.join(layout.root, "Package.swift"), "utf8");
5931
6097
  const executable = swiftManifestTargets(manifest).find((target) => target.executable);
5932
6098
  if (executable === void 0) {
5933
6099
  throw new Error("swift-compile: the written manifest names no executable target");
5934
6100
  }
5935
- const file = import_node_path5.default.join(binDir, `${executable.name}.wasm`);
5936
- if (!(0, import_node_fs3.existsSync)(file)) {
5937
- const found = (0, import_node_fs3.existsSync)(binDir) ? (0, import_node_fs3.readdirSync)(binDir).filter((name) => name.endsWith(".wasm")).sort() : [];
6101
+ const file = import_node_path6.default.join(binDir, `${executable.name}.wasm`);
6102
+ if (!(0, import_node_fs4.existsSync)(file)) {
6103
+ const found = (0, import_node_fs4.existsSync)(binDir) ? (0, import_node_fs4.readdirSync)(binDir).filter((name) => name.endsWith(".wasm")).sort() : [];
5938
6104
  throw new Error(
5939
6105
  `swift-compile: the build produced no ${executable.name}.wasm (found: ${found.join(", ") || "none"})`
5940
6106
  );
@@ -5943,8 +6109,8 @@ function builtArtifact(layout) {
5943
6109
  }
5944
6110
  function projectDiagnostic(output, layout, files) {
5945
6111
  const base = layout.multi ? layout.root : layout.sources;
5946
- const prefix = `${base}${import_node_path5.default.sep}`;
5947
- return designTimeDiagnostic(output, files).split("\n").map((line) => line.startsWith(prefix) ? line.slice(prefix.length) : line).join("\n").trim();
6112
+ const prefix = `${base}${import_node_path6.default.sep}`;
6113
+ return designTimeDiagnostic(output, files).split("\n").filter((line) => !SWIFTPM_NOISE.test(line)).map((line) => line.startsWith(prefix) ? line.slice(prefix.length) : line).join("\n").trim();
5948
6114
  }
5949
6115
  var ROOT_LOCKS = Symbol.for("peachsim.swiftCompile.rootLocks");
5950
6116
  var host = globalThis;
@@ -5979,13 +6145,13 @@ function serialize(root, work, signal) {
5979
6145
  function readCompiledArtifact(directory, hash) {
5980
6146
  try {
5981
6147
  const receipt = JSON.parse(
5982
- (0, import_node_fs3.readFileSync)(import_node_path5.default.join(directory, "artifact.json"), "utf8")
6148
+ (0, import_node_fs4.readFileSync)(import_node_path6.default.join(directory, "artifact.json"), "utf8")
5983
6149
  );
5984
6150
  if (!receipt || typeof receipt !== "object" || !("hash" in receipt) || receipt.hash !== hash || !("icu" in receipt) || typeof receipt.icu !== "string" || !("wasm" in receipt) || typeof receipt.wasm !== "string")
5985
6151
  return null;
5986
- const bytes = (0, import_node_fs3.readFileSync)(import_node_path5.default.join(directory, "app.wasm"));
5987
- const gzip2 = (0, import_node_fs3.readFileSync)(import_node_path5.default.join(directory, "icu.gz"));
5988
- if ((0, import_node_crypto2.createHash)("sha256").update(bytes).digest("hex") !== receipt.wasm || (0, import_node_crypto2.createHash)("sha256").update(gzip2).digest("hex") !== receipt.icu || bytes.length < 8 || bytes.readUInt32LE(0) !== 1836278016 || bytes.readUInt32LE(4) !== 1)
6152
+ const bytes = (0, import_node_fs4.readFileSync)(import_node_path6.default.join(directory, "app.wasm"));
6153
+ const gzip2 = (0, import_node_fs4.readFileSync)(import_node_path6.default.join(directory, "icu.gz"));
6154
+ if ((0, import_node_crypto3.createHash)("sha256").update(bytes).digest("hex") !== receipt.wasm || (0, import_node_crypto3.createHash)("sha256").update(gzip2).digest("hex") !== receipt.icu || bytes.length < 8 || bytes.readUInt32LE(0) !== 1836278016 || bytes.readUInt32LE(4) !== 1)
5989
6155
  return null;
5990
6156
  return { hash, bytes, icu: { sha256: receipt.icu, gzip: gzip2 } };
5991
6157
  } catch (error) {
@@ -5995,25 +6161,25 @@ function readCompiledArtifact(directory, hash) {
5995
6161
  }
5996
6162
  }
5997
6163
  function saveCompiledArtifact(root, artifact) {
5998
- const directory = import_node_path5.default.join(root, "artifact");
5999
- (0, import_node_fs3.mkdirSync)(directory, { recursive: true });
6000
- const pending = (0, import_node_fs3.mkdtempSync)(import_node_path5.default.join(root, ".artifact-"));
6164
+ const directory = import_node_path6.default.join(root, "artifact");
6165
+ (0, import_node_fs4.mkdirSync)(directory, { recursive: true });
6166
+ const pending = (0, import_node_fs4.mkdtempSync)(import_node_path6.default.join(root, ".artifact-"));
6001
6167
  try {
6002
- (0, import_node_fs3.writeFileSync)(import_node_path5.default.join(pending, "app.wasm"), artifact.bytes);
6003
- (0, import_node_fs3.writeFileSync)(import_node_path5.default.join(pending, "icu.gz"), artifact.icu.gzip);
6004
- (0, import_node_fs3.writeFileSync)(
6005
- import_node_path5.default.join(pending, "artifact.json"),
6168
+ (0, import_node_fs4.writeFileSync)(import_node_path6.default.join(pending, "app.wasm"), artifact.bytes);
6169
+ (0, import_node_fs4.writeFileSync)(import_node_path6.default.join(pending, "icu.gz"), artifact.icu.gzip);
6170
+ (0, import_node_fs4.writeFileSync)(
6171
+ import_node_path6.default.join(pending, "artifact.json"),
6006
6172
  JSON.stringify({
6007
6173
  hash: artifact.hash,
6008
- wasm: (0, import_node_crypto2.createHash)("sha256").update(artifact.bytes).digest("hex"),
6174
+ wasm: (0, import_node_crypto3.createHash)("sha256").update(artifact.bytes).digest("hex"),
6009
6175
  icu: artifact.icu.sha256
6010
6176
  })
6011
6177
  );
6012
6178
  for (const file of ["app.wasm", "icu.gz", "artifact.json"]) {
6013
- (0, import_node_fs3.renameSync)(import_node_path5.default.join(pending, file), import_node_path5.default.join(directory, file));
6179
+ (0, import_node_fs4.renameSync)(import_node_path6.default.join(pending, file), import_node_path6.default.join(directory, file));
6014
6180
  }
6015
6181
  } finally {
6016
- (0, import_node_fs3.rmSync)(pending, { recursive: true, force: true });
6182
+ (0, import_node_fs4.rmSync)(pending, { recursive: true, force: true });
6017
6183
  }
6018
6184
  }
6019
6185
  var retainedArtifacts = /* @__PURE__ */ new Map();
@@ -6029,17 +6195,20 @@ function retain(root, artifact) {
6029
6195
  }
6030
6196
  function compileSwiftProjectUnit(input, options) {
6031
6197
  options.signal?.throwIfAborted();
6032
- (0, import_node_fs3.mkdirSync)(options.buildRoot, { recursive: true });
6033
- const root = (0, import_node_fs3.realpathSync)(options.buildRoot);
6034
- const moduleRoot = import_node_path5.default.resolve(options.moduleRoot);
6198
+ (0, import_node_fs4.mkdirSync)(options.buildRoot, { recursive: true });
6199
+ const root = (0, import_node_fs4.realpathSync)(options.buildRoot);
6200
+ const moduleRoot = import_node_path6.default.resolve(options.moduleRoot);
6035
6201
  const layout = {
6036
6202
  root,
6037
- sources: import_node_path5.default.join(root, "Sources", "App"),
6203
+ sources: import_node_path6.default.join(root, "Sources", "App"),
6038
6204
  multi: compileTargets(input).length > 0
6039
6205
  };
6040
6206
  const hash = swiftArtifactHash(input, options.release, moduleRoot);
6041
- const sharedRoot = import_node_path5.default.join(rnxHomeDir(), "cache", "swift-projects", hash);
6042
- const report = (message) => console.error(`[swift-project ${hash.slice(0, 16)}] ${message}`);
6207
+ const sharedRoot = import_node_path6.default.join(rnxHomeDir(), "cache", "swift-projects", hash);
6208
+ const report = (message) => {
6209
+ console.error(`[swift-project ${hash.slice(0, 16)}] ${message}`);
6210
+ options.onStage?.(message);
6211
+ };
6043
6212
  report("checking verified artifacts");
6044
6213
  return serialize(
6045
6214
  root,
@@ -6049,37 +6218,36 @@ function compileSwiftProjectUnit(input, options) {
6049
6218
  report("reusing memory artifact");
6050
6219
  return retain(root, retained);
6051
6220
  }
6052
- const cached = readCompiledArtifact(import_node_path5.default.join(sharedRoot, "artifact"), hash);
6053
- const previous = cached ?? readCompiledArtifact(import_node_path5.default.join(root, "artifact"), hash);
6221
+ const cached = readCompiledArtifact(import_node_path6.default.join(sharedRoot, "artifact"), hash);
6222
+ const previous = cached ?? readCompiledArtifact(import_node_path6.default.join(root, "artifact"), hash);
6054
6223
  if (previous) {
6055
6224
  if (!cached) saveCompiledArtifact(sharedRoot, previous);
6056
6225
  report("reusing verified disk artifact");
6057
6226
  return retain(root, previous);
6058
6227
  }
6059
- if (process.platform === "darwin" && process.env.TM_SESSION && !admittedMacBuilderSlot() && process.env.CI !== "true" && moduleRoot === import_node_path5.default.resolve(__sootsim_import_meta_dirname, "../../sootsim-swift") && !swiftDistributionAt(moduleRoot)) {
6060
- const requestRoot = (0, import_node_fs3.mkdtempSync)(import_node_path5.default.join(root, ".builder-request-"));
6061
- const output = import_node_path5.default.join(requestRoot, "output");
6062
- const request = import_node_path5.default.join(requestRoot, "request.json");
6063
- (0, import_node_fs3.writeFileSync)(
6228
+ if (process.platform === "darwin" && process.env.TM_SESSION && !admittedMacBuilderSlot() && process.env.CI !== "true" && moduleRoot === import_node_path6.default.resolve(__sootsim_import_meta_dirname, "../../sootsim-swift") && !swiftDistributionAt(moduleRoot)) {
6229
+ const requestRoot = (0, import_node_fs4.mkdtempSync)(import_node_path6.default.join(root, ".builder-request-"));
6230
+ const output = import_node_path6.default.join(requestRoot, "output");
6231
+ const request = import_node_path6.default.join(requestRoot, "request.json");
6232
+ (0, import_node_fs4.writeFileSync)(
6064
6233
  request,
6065
6234
  JSON.stringify({
6066
6235
  input,
6067
6236
  hash,
6068
6237
  release: options.release,
6069
6238
  timeoutMs: options.timeoutMs,
6070
- // the builder's swiftpm tree holds the sootsim-swift objects, which
6071
- // depend on the toolchain and sdk and not on the caller's checkout
6072
- // path, so every caller shares one warm tree per toolchain.
6073
- buildKey: (0, import_node_crypto2.createHash)("sha256").update(`${options.release}\0${swiftModuleSdk(moduleRoot).wasmSdkId}`).digest("hex").slice(0, 32)
6239
+ // framework sources and compiler inputs own the shared object tree;
6240
+ // unrelated app edits reuse it without retaining stale private ABI.
6241
+ buildKey: swiftProjectBuildKey(moduleRoot, options.release)
6074
6242
  })
6075
6243
  );
6076
6244
  try {
6077
- const repo = import_node_path5.default.resolve(moduleRoot, "../..");
6245
+ const repo = import_node_path6.default.resolve(moduleRoot, "../..");
6078
6246
  report("requesting builder admission or cached result");
6079
6247
  await runCompiler(
6080
6248
  "bun",
6081
6249
  [
6082
- import_node_path5.default.join(repo, "scripts/build/swift-project.ts"),
6250
+ import_node_path6.default.join(repo, "scripts/build/swift-project.ts"),
6083
6251
  "--request",
6084
6252
  request,
6085
6253
  "--output",
@@ -6096,118 +6264,141 @@ function compileSwiftProjectUnit(input, options) {
6096
6264
  if (options.signal?.aborted) throw error;
6097
6265
  throw new Error(outputOf(error), { cause: error });
6098
6266
  });
6099
- const artifact2 = readCompiledArtifact(output, hash);
6100
- if (!artifact2) {
6267
+ const artifact = readCompiledArtifact(output, hash);
6268
+ if (!artifact) {
6101
6269
  throw new Error(
6102
6270
  "swift-compile: builder artifact source, digest or wasm header is invalid"
6103
6271
  );
6104
6272
  }
6105
- saveCompiledArtifact(root, artifact2);
6106
- saveCompiledArtifact(sharedRoot, artifact2);
6273
+ saveCompiledArtifact(root, artifact);
6274
+ saveCompiledArtifact(sharedRoot, artifact);
6107
6275
  report("builder artifact verified");
6108
- return retain(root, artifact2);
6276
+ return retain(root, artifact);
6109
6277
  } finally {
6110
- (0, import_node_fs3.rmSync)(requestRoot, { recursive: true, force: true });
6278
+ (0, import_node_fs4.rmSync)(requestRoot, { recursive: true, force: true });
6111
6279
  }
6112
6280
  }
6113
- writeSwiftProject(layout, input, moduleRoot);
6114
- const swift = import_node_path5.default.join(options.toolchainBin, "swift");
6115
- if (!(0, import_node_fs3.existsSync)(swift)) {
6116
- throw new Error(
6117
- `swift-compile: no swift.org toolchain at ${options.toolchainBin}; install ${options.release} and its matching wasm sdk`
6118
- );
6119
- }
6120
- report("preparing compiler plugins");
6121
- const macroPlugins = await ensureMacroPlugins(
6122
- moduleRoot,
6123
- options.toolchainBin,
6124
- options.release,
6125
- options.signal
6126
- );
6127
- const sdk = swiftModuleSdk(moduleRoot).wasmSdkId;
6128
- const icu = swiftIcuAsset(options.toolchainBin, sdk);
6129
- const buildArgs = [
6130
- "build",
6131
- ...swiftPackageCacheOptions(),
6132
- "--build-system",
6133
- "native",
6134
- "-j",
6135
- BUILD_JOBS,
6136
- "--package-path",
6281
+ return withSwiftRootLock(
6137
6282
  root,
6138
- ...swiftSdkOptions(),
6139
- "--swift-sdk",
6140
- sdk,
6141
- "-c",
6142
- "release",
6143
- "-Xswiftc",
6144
- "-Osize",
6145
- "-Xswiftc",
6146
- "-num-threads",
6147
- "-Xswiftc",
6148
- BUILD_JOBS,
6149
- ...macroPlugins.flatMap((plugin) => [
6150
- "-Xswiftc",
6151
- "-load-plugin-library",
6152
- "-Xswiftc",
6153
- plugin
6154
- ])
6155
- ];
6156
- const buildOptions = {
6157
- env: {
6158
- ...process.env,
6159
- // shipped host plugins resolve against the selected compiler's runtime.
6160
- ...process.platform === "linux" ? {
6161
- LD_LIBRARY_PATH: [
6162
- import_node_path5.default.resolve(options.toolchainBin, "../lib/swift/linux"),
6163
- import_node_path5.default.resolve(options.toolchainBin, "../lib/swift/host"),
6164
- process.env.LD_LIBRARY_PATH
6165
- ].filter(Boolean).join(":")
6166
- } : {}
6167
- },
6168
- maxBuffer: 64 * 1024 * 1024,
6169
- timeout: options.timeoutMs,
6170
- signal: options.signal
6171
- };
6172
- report("compiling and linking Swift modules");
6173
- try {
6174
- await runCompiler(swift, buildArgs, buildOptions, true);
6175
- } catch (error) {
6176
- const output = outputOf(error);
6177
- const moduleCache = import_node_path5.default.join(
6178
- root,
6179
- ".build",
6180
- WASM_TRIPLE,
6181
- "release",
6182
- "ModuleCache"
6183
- );
6184
- if (output.includes("was compiled with module cache path") && (0, import_node_fs3.existsSync)(moduleCache)) {
6185
- (0, import_node_fs3.rmSync)(moduleCache, { recursive: true, force: true });
6186
- try {
6187
- await runCompiler(swift, buildArgs, buildOptions, true);
6188
- } catch (retryError) {
6283
+ async () => {
6284
+ const built = readCompiledArtifact(import_node_path6.default.join(sharedRoot, "artifact"), hash);
6285
+ if (built) {
6286
+ report("reusing verified disk artifact");
6287
+ return retain(root, built);
6288
+ }
6289
+ writeSwiftProject(layout, input, moduleRoot);
6290
+ const swift = import_node_path6.default.join(options.toolchainBin, "swift");
6291
+ if (!(0, import_node_fs4.existsSync)(swift)) {
6189
6292
  throw new Error(
6190
- projectDiagnostic(outputOf(retryError), layout, input.files),
6191
- {
6192
- cause: retryError
6193
- }
6293
+ `swift-compile: no swift.org toolchain at ${options.toolchainBin}; install ${options.release} and its matching wasm sdk`
6194
6294
  );
6195
6295
  }
6196
- } else {
6197
- throw new Error(projectDiagnostic(output, layout, input.files), {
6198
- cause: error
6199
- });
6200
- }
6201
- }
6202
- const artifact = {
6203
- hash,
6204
- bytes: (0, import_node_fs3.readFileSync)(builtArtifact(layout)),
6205
- icu: await icu
6206
- };
6207
- saveCompiledArtifact(root, artifact);
6208
- saveCompiledArtifact(sharedRoot, artifact);
6209
- report("compiled artifact verified");
6210
- return retain(root, artifact);
6296
+ report("preparing compiler plugins");
6297
+ const macroPlugins = await ensureMacroPlugins(
6298
+ moduleRoot,
6299
+ options.toolchainBin,
6300
+ options.release,
6301
+ options.signal
6302
+ );
6303
+ const sdk = swiftModuleSdk(moduleRoot).wasmSdkId;
6304
+ const icu = swiftIcuAsset(options.toolchainBin, sdk);
6305
+ const buildArgs = [
6306
+ "build",
6307
+ ...swiftPackageCacheOptions(),
6308
+ "--build-system",
6309
+ "native",
6310
+ "-j",
6311
+ BUILD_JOBS,
6312
+ "--package-path",
6313
+ root,
6314
+ ...swiftSdkOptions(),
6315
+ "--swift-sdk",
6316
+ sdk,
6317
+ "-c",
6318
+ "release",
6319
+ "-Xswiftc",
6320
+ "-Osize",
6321
+ "-Xswiftc",
6322
+ "-num-threads",
6323
+ "-Xswiftc",
6324
+ BUILD_JOBS,
6325
+ ...macroPlugins.flatMap((plugin) => [
6326
+ "-Xswiftc",
6327
+ "-load-plugin-library",
6328
+ "-Xswiftc",
6329
+ plugin
6330
+ ])
6331
+ ];
6332
+ const buildOptions = {
6333
+ env: {
6334
+ ...process.env,
6335
+ // shipped host plugins resolve against the selected compiler's runtime.
6336
+ ...process.platform === "linux" ? {
6337
+ LD_LIBRARY_PATH: [
6338
+ import_node_path6.default.resolve(options.toolchainBin, "../lib/swift/linux"),
6339
+ import_node_path6.default.resolve(options.toolchainBin, "../lib/swift/host"),
6340
+ process.env.LD_LIBRARY_PATH
6341
+ ].filter(Boolean).join(":")
6342
+ } : {}
6343
+ },
6344
+ maxBuffer: 64 * 1024 * 1024,
6345
+ timeout: options.timeoutMs,
6346
+ signal: options.signal
6347
+ };
6348
+ report("compiling and linking Swift modules");
6349
+ try {
6350
+ await runCompiler(
6351
+ swift,
6352
+ buildArgs,
6353
+ buildOptions,
6354
+ SWIFTPM_PROGRESS,
6355
+ SWIFTPM_NOISE
6356
+ );
6357
+ } catch (error) {
6358
+ const output = outputOf(error);
6359
+ const moduleCache = import_node_path6.default.join(
6360
+ root,
6361
+ ".build",
6362
+ WASM_TRIPLE,
6363
+ "release",
6364
+ "ModuleCache"
6365
+ );
6366
+ if (output.includes("was compiled with module cache path") && (0, import_node_fs4.existsSync)(moduleCache)) {
6367
+ (0, import_node_fs4.rmSync)(moduleCache, { recursive: true, force: true });
6368
+ try {
6369
+ await runCompiler(
6370
+ swift,
6371
+ buildArgs,
6372
+ buildOptions,
6373
+ SWIFTPM_PROGRESS,
6374
+ SWIFTPM_NOISE
6375
+ );
6376
+ } catch (retryError) {
6377
+ throw new Error(
6378
+ projectDiagnostic(outputOf(retryError), layout, input.files),
6379
+ {
6380
+ cause: retryError
6381
+ }
6382
+ );
6383
+ }
6384
+ } else {
6385
+ throw new Error(projectDiagnostic(output, layout, input.files), {
6386
+ cause: error
6387
+ });
6388
+ }
6389
+ }
6390
+ const artifact = {
6391
+ hash,
6392
+ bytes: (0, import_node_fs4.readFileSync)(builtArtifact(layout)),
6393
+ icu: await icu
6394
+ };
6395
+ saveCompiledArtifact(root, artifact);
6396
+ saveCompiledArtifact(sharedRoot, artifact);
6397
+ report("compiled artifact verified");
6398
+ return retain(root, artifact);
6399
+ },
6400
+ options.signal
6401
+ );
6211
6402
  },
6212
6403
  options.signal
6213
6404
  );
@@ -6239,6 +6430,7 @@ function compileSwiftProjectUnit(input, options) {
6239
6430
  swiftModuleInputFiles,
6240
6431
  swiftModuleSdk,
6241
6432
  swiftPeachModules,
6433
+ swiftProjectBuildKey,
6242
6434
  swiftSdkPaths,
6243
6435
  swiftSourceAsIOS,
6244
6436
  swiftSourceClosure,