peachsim 0.1.1640 → 0.1.1644

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 (125) hide show
  1. package/README.md +5 -0
  2. package/cli/app-bundle-resources.ts +57 -0
  3. package/cli/app-stubs.ts +38 -13
  4. package/cli/cloud-session.ts +16 -0
  5. package/cli/commands/assert.ts +17 -4
  6. package/cli/commands/box.ts +33 -19
  7. package/cli/commands/control.ts +12 -0
  8. package/cli/commands/doctor.ts +24 -15
  9. package/cli/commands/inspect/actions.ts +3 -2
  10. package/cli/commands/inspect/core.ts +0 -8
  11. package/cli/commands/inspect.ts +0 -14
  12. package/cli/commands/platform.ts +2 -1
  13. package/cli/commands/record.ts +64 -28
  14. package/cli/commands/swift.ts +10 -2
  15. package/cli/commands/three-mode.ts +4 -38
  16. package/cli/commands/upload.ts +8 -8
  17. package/cli/drivers/playwright.ts +39 -0
  18. package/cli/flow-live-status.ts +0 -2
  19. package/cli/main.ts +1 -1
  20. package/cli/outbound-endpoints.ts +4 -2
  21. package/cli/ws-bridge.ts +0 -6
  22. package/detox/attempt-events.cjs +41 -5
  23. package/detox/index.ts +155 -109
  24. package/detox/jest-environment.cjs +5 -1
  25. package/detox/motion-change.cjs +7 -5
  26. package/detox/motion-change.d.cts +1 -0
  27. package/detox/motion-leg-starts.cjs +20 -0
  28. package/detox/motion-leg-starts.d.cts +8 -0
  29. package/dist-lib/agent-daemon-client.cjs +1 -1
  30. package/dist-lib/agent-events.cjs +1 -1
  31. package/dist-lib/attached-projects.cjs +1 -1
  32. package/dist-lib/auth/shared-session.cjs +1 -1
  33. package/dist-lib/backend-origin.cjs +12 -3
  34. package/dist-lib/beta.cjs +1 -1
  35. package/dist-lib/beta.mjs +1 -1
  36. package/dist-lib/bridge-constants.cjs +1 -1
  37. package/dist-lib/bridge-contract-input.cjs +1 -1
  38. package/dist-lib/bridge-contract-input.mjs +1 -1
  39. package/dist-lib/bridge-contract.cjs +1 -1
  40. package/dist-lib/bridge-contract.mjs +1 -1
  41. package/dist-lib/bundle-channel.cjs +2671 -1833
  42. package/dist-lib/capture-contract.cjs +1 -1
  43. package/dist-lib/capture-contract.mjs +1 -1
  44. package/dist-lib/cloud-contract.cjs +1 -1
  45. package/dist-lib/cloud-contract.mjs +1 -1
  46. package/dist-lib/cloud-test-args.cjs +1 -1
  47. package/dist-lib/cloud-test-args.mjs +1 -1
  48. package/dist-lib/cloud.cjs +1 -1
  49. package/dist-lib/cloud.mjs +1 -1
  50. package/dist-lib/config.cjs +1 -1
  51. package/dist-lib/config.mjs +1 -1
  52. package/dist-lib/detox/index.cjs +578 -130
  53. package/dist-lib/detox/jest-environment.cjs +5 -1
  54. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  55. package/dist-lib/expo-swift-bundle.cjs +2374 -1554
  56. package/dist-lib/expo-swift-metadata.cjs +1 -1
  57. package/dist-lib/expo-swift-metadata.mjs +1 -1
  58. package/dist-lib/home-paths.cjs +1 -1
  59. package/dist-lib/host/bridge-host.cjs +2968 -2141
  60. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  61. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  62. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  63. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  64. package/dist-lib/host/websocket-proxy.cjs +1 -1
  65. package/dist-lib/index.cjs +132 -57
  66. package/dist-lib/jump-to-source-babel.cjs +1 -1
  67. package/dist-lib/jump-to-source-native.cjs +1 -1
  68. package/dist-lib/kotlin-host.cjs +1 -1
  69. package/dist-lib/menu.cjs +14 -6
  70. package/dist-lib/menu.mjs +14 -6
  71. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  72. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  73. package/dist-lib/metro-production-bundle.cjs +1 -1
  74. package/dist-lib/metro-production-bundle.mjs +1 -1
  75. package/dist-lib/metro.cjs +120 -53
  76. package/dist-lib/native-app-identity-project.cjs +96 -44
  77. package/dist-lib/native-app-identity-project.mjs +95 -44
  78. package/dist-lib/native-app-identity.cjs +1 -1
  79. package/dist-lib/native-app-identity.mjs +1 -1
  80. package/dist-lib/native-firebase-metadata.cjs +1 -1
  81. package/dist-lib/native-firebase-metadata.mjs +1 -1
  82. package/dist-lib/plist.cjs +1 -1
  83. package/dist-lib/plist.mjs +1 -1
  84. package/dist-lib/profiles.cjs +1 -1
  85. package/dist-lib/public-brand.cjs +1 -1
  86. package/dist-lib/react-native-host-modules.cjs +1 -1
  87. package/dist-lib/react-native-host-modules.mjs +1 -1
  88. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  89. package/dist-lib/sdk.cjs +5 -3
  90. package/dist-lib/sdk.mjs +5 -3
  91. package/dist-lib/skills.cjs +3932 -2868
  92. package/dist-lib/swift-compile.cjs +587 -374
  93. package/dist-lib/swift-compile.mjs +595 -369
  94. package/dist-lib/swift-package.cjs +1 -1
  95. package/dist-lib/swift-package.mjs +1 -1
  96. package/dist-lib/swift-submit.cjs +8 -3
  97. package/dist-lib/swift-submit.mjs +8 -3
  98. package/dist-lib/swift-toolchain.cjs +1 -1
  99. package/dist-lib/swift.cjs +1 -1
  100. package/dist-lib/vite-swift.cjs +2263 -1467
  101. package/dist-lib/vite.cjs +1 -1
  102. package/dist-lib/worklet-executable.cjs +1 -1
  103. package/dist-lib/worklet-executable.mjs +1 -1
  104. package/package.json +1 -1
  105. package/src/appBundleResourcesContract.ts +51 -0
  106. package/src/backend-origin.ts +11 -1
  107. package/src/host/bridge-host.ts +17 -11
  108. package/src/host/staged-host-files.ts +28 -4
  109. package/src/launchMetadataContract.ts +1 -0
  110. package/src/menu.ts +12 -4
  111. package/src/native-app-identity-project.ts +47 -38
  112. package/src/react-native-bridge-modules.ts +89 -76
  113. package/src/runtime-delivery.ts +6 -7
  114. package/src/swift-compile.ts +150 -112
  115. package/src/swift-compiler-digest.ts +5 -3
  116. package/src/swift-distribution.lock.json +9 -8
  117. package/src/swift-host.ts +6 -4
  118. package/src/swift-objc-compile.ts +416 -194
  119. package/src/swift-objc-metadata.ts +204 -0
  120. package/src/swift-objc-sdk.ts +195 -2
  121. package/src/swift-package-manifest.ts +6 -3
  122. package/src/swift-root-lock.ts +302 -0
  123. package/src/swift-submit.ts +15 -2
  124. package/src/swiftContract.ts +12 -0
  125. package/src/xcode-project.ts +77 -7
@@ -1,23 +1,26 @@
1
- /*! peach v0.1.1640 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.1644 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
2
2
 
3
3
  // src/swift-compile.ts
4
- import { spawn as spawn2, execFileSync as execFileSync2 } from "node:child_process";
5
- import { createHash as createHash4 } from "node:crypto";
4
+ import {
5
+ spawn as spawn3,
6
+ execFileSync as execFileSync2
7
+ } from "node:child_process";
8
+ import { createHash as createHash5 } from "node:crypto";
6
9
  import {
7
10
  cpSync,
8
11
  existsSync as existsSync2,
9
- mkdirSync,
12
+ mkdirSync as mkdirSync2,
10
13
  mkdtempSync as mkdtempSync2,
11
- readFileSync as readFileSync4,
12
- readdirSync as readdirSync2,
14
+ readFileSync as readFileSync5,
15
+ readdirSync as readdirSync3,
13
16
  realpathSync,
14
17
  renameSync,
15
- rmSync as rmSync2,
18
+ rmSync as rmSync3,
16
19
  statSync,
17
- writeFileSync as writeFileSync2
20
+ writeFileSync as writeFileSync3
18
21
  } from "node:fs";
19
22
  import os2 from "node:os";
20
- import path5 from "node:path";
23
+ import path6 from "node:path";
21
24
 
22
25
  // src/admitted-mac-build.ts
23
26
  import { spawnSync } from "node:child_process";
@@ -61,9 +64,9 @@ function cacheDir() {
61
64
  }
62
65
  function swiftPackageCacheOptions() {
63
66
  const root = path.join(cacheDir(), "swiftpm");
64
- return ["cache", "config", "security"].flatMap((name) => [
65
- `--${name}-path`,
66
- path.join(root, name)
67
+ return ["cache", "config", "security"].flatMap((name2) => [
68
+ `--${name2}-path`,
69
+ path.join(root, name2)
67
70
  ]);
68
71
  }
69
72
  var DAEMON_LOCKFILE_MAX_BYTES = 16 * 1024;
@@ -733,9 +736,9 @@ var EXCERPT = /^(\s*)(\d+)( \| )(.*)$/;
733
736
  var MARKER = /^(\s*)( \| )(.*)$/;
734
737
  function designTimeDiagnostic(output, files) {
735
738
  const rewritten = /* @__PURE__ */ new Map();
736
- const linesOf = (path6) => {
739
+ const linesOf = (path7) => {
737
740
  const file = Object.keys(files).find(
738
- (name) => name.endsWith(".swift") && (path6 === name || path6.endsWith(`/${name}`))
741
+ (name2) => name2.endsWith(".swift") && (path7 === name2 || path7.endsWith(`/${name2}`))
739
742
  );
740
743
  if (file === void 0) return null;
741
744
  let lines = rewritten.get(file);
@@ -900,7 +903,7 @@ async function load(toolchainBin, sdk) {
900
903
  icuSegment(archiveMember(readFileSync3(path4.join(resources, ARCHIVE)), MEMBER))
901
904
  );
902
905
  }
903
- function archiveMember(archive, name) {
906
+ function archiveMember(archive, name2) {
904
907
  if (archive.toString("latin1", 0, 8) !== "!<arch>\n")
905
908
  throw new Error("swift-icu: not an ar archive");
906
909
  let names = "";
@@ -910,10 +913,10 @@ function archiveMember(archive, name) {
910
913
  const body = archive.subarray(at + 60, at + 60 + size);
911
914
  if (raw2 === "//") names = body.toString("latin1");
912
915
  const member = /^\/\d+$/.test(raw2) ? names.slice(Number(raw2.slice(1)), names.indexOf("/\n", Number(raw2.slice(1)))) : raw2.replace(/\/$/, "");
913
- if (member === name) return body;
916
+ if (member === name2) return body;
914
917
  at += 60 + size + size % 2;
915
918
  }
916
- throw new Error(`swift-icu: ${name} is not in the sdk's icu archive`);
919
+ throw new Error(`swift-icu: ${name2} is not in the sdk's icu archive`);
917
920
  }
918
921
  function icuSegment(object) {
919
922
  let at = 8;
@@ -1047,8 +1050,8 @@ function splitManifestArguments(source) {
1047
1050
  if (final) arguments_.push(final);
1048
1051
  return arguments_;
1049
1052
  }
1050
- function swiftTargetModuleName(name) {
1051
- return name.replace(/[^A-Za-z0-9_]/g, "_").replace(/^[0-9]/, "_");
1053
+ function swiftTargetModuleName(name2) {
1054
+ return name2.replace(/[^A-Za-z0-9_]/g, "_").replace(/^[0-9]/, "_");
1052
1055
  }
1053
1056
  function swiftManifestTargets(manifest, resourcePaths = []) {
1054
1057
  const implicitResources = swiftImplicitResourcePaths(resourcePaths);
@@ -1060,16 +1063,16 @@ function swiftManifestTargets(manifest, resourcePaths = []) {
1060
1063
  ]);
1061
1064
  const targetNames = new Set(
1062
1065
  declarations.flatMap(({ flat }) => {
1063
- const name = /\bname\s*:\s*"([^"]+)"/.exec(flat)?.[1];
1064
- return name ? [name] : [];
1066
+ const name2 = /\bname\s*:\s*"([^"]+)"/.exec(flat)?.[1];
1067
+ return name2 ? [name2] : [];
1065
1068
  })
1066
1069
  );
1067
1070
  for (const { kind, flat, call } of declarations) {
1068
1071
  const executable = kind === "executableTarget";
1069
- const name = /\bname\s*:\s*"([^"]+)"/.exec(flat)?.[1];
1070
- if (!name) continue;
1072
+ const name2 = /\bname\s*:\s*"([^"]+)"/.exec(flat)?.[1];
1073
+ if (!name2) continue;
1071
1074
  const rawPath = /\bpath\s*:\s*"([^"]*)"/.exec(flat)?.[1];
1072
- const targetPath = rawPath == null || rawPath === "" ? `Sources/${name}` : rawPath.replace(/^\.\//, "").replace(/\/+$/, "");
1075
+ const targetPath = rawPath == null || rawPath === "" ? `Sources/${name2}` : rawPath.replace(/^\.\//, "").replace(/\/+$/, "");
1073
1076
  const languageMode = Number(
1074
1077
  /\.swiftLanguageMode\(\s*\.v(\d+)\s*\)/.exec(call)?.[1] ?? "5"
1075
1078
  );
@@ -1109,12 +1112,12 @@ function swiftManifestTargets(manifest, resourcePaths = []) {
1109
1112
  dependencyNames.add(dependencyName);
1110
1113
  }
1111
1114
  }
1112
- const dependencies = [...dependencyNames].map((name2) => ({
1115
+ const dependencies = [...dependencyNames].map((name3) => ({
1113
1116
  kind: "target",
1114
- name: name2
1117
+ name: name3
1115
1118
  }));
1116
1119
  targets.push({
1117
- name,
1120
+ name: name2,
1118
1121
  path: targetPath,
1119
1122
  executable,
1120
1123
  ...kind === "systemLibrary" ? { systemLibrary: true } : {},
@@ -1141,6 +1144,207 @@ function swiftPackagePartition(manifest, resourcePaths = []) {
1141
1144
  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;
1142
1145
  }
1143
1146
 
1147
+ // src/swift-root-lock.ts
1148
+ import {
1149
+ spawn as spawn2,
1150
+ spawnSync as spawnSync3
1151
+ } from "node:child_process";
1152
+ import { createHash as createHash4, randomUUID as randomUUID2 } from "node:crypto";
1153
+ import {
1154
+ linkSync,
1155
+ mkdirSync,
1156
+ readdirSync as readdirSync2,
1157
+ readFileSync as readFileSync4,
1158
+ rmSync as rmSync2,
1159
+ writeFileSync as writeFileSync2
1160
+ } from "node:fs";
1161
+ import path5 from "node:path";
1162
+ var POLL_MS = 250;
1163
+ var START_TOLERANCE_MS = 2e3;
1164
+ function errorCode(error) {
1165
+ return error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : void 0;
1166
+ }
1167
+ function parseStart(text2) {
1168
+ const start = Date.parse(`${text2} UTC`);
1169
+ if (Number.isNaN(start)) throw new Error(`unreadable process start time "${text2}"`);
1170
+ return start;
1171
+ }
1172
+ function processTable() {
1173
+ const result = spawnSync3("ps", ["-A", "-o", "pid=,pgid=,stat=,lstart="], {
1174
+ encoding: "utf8",
1175
+ env: { ...process.env, LC_ALL: "C", TZ: "UTC" },
1176
+ stdio: ["ignore", "pipe", "pipe"],
1177
+ timeout: 1e4,
1178
+ killSignal: "SIGKILL"
1179
+ });
1180
+ if (result.error || result.status !== 0) {
1181
+ throw new Error(
1182
+ `swift root lock cannot read the process table: ${result.error?.message || result.stderr.trim() || `ps exited ${result.status}`}`
1183
+ );
1184
+ }
1185
+ return result.stdout.split("\n").filter((line) => line.trim()).map((line) => {
1186
+ const match = /^\s*(\d+)\s+(\d+)\s+(\S+)\s+(.+?)\s*$/.exec(line);
1187
+ if (!match)
1188
+ throw new Error(`swift root lock cannot parse a process table row: ${line}`);
1189
+ return {
1190
+ pid: Number(match[1]),
1191
+ pgid: Number(match[2]),
1192
+ zombie: match[3].startsWith("Z"),
1193
+ start: parseStart(match[4])
1194
+ };
1195
+ });
1196
+ }
1197
+ function sameProcess(row, identity) {
1198
+ return row.pid === identity.pid && Math.abs(row.start - identity.start) <= START_TOLERANCE_MS;
1199
+ }
1200
+ function ownIdentity(pid) {
1201
+ const row = processTable().find(
1202
+ (candidate) => candidate.pid === pid && !candidate.zombie
1203
+ );
1204
+ if (!row) throw new Error(`swift root lock cannot find process ${pid}`);
1205
+ return { pid, start: row.start };
1206
+ }
1207
+ function parseIdentity(text2) {
1208
+ const value = JSON.parse(text2);
1209
+ if (value && typeof value === "object" && "pid" in value && typeof value.pid === "number" && "start" in value && typeof value.start === "number")
1210
+ return { pid: value.pid, start: value.start };
1211
+ throw new Error(`swift root lock record is not a process identity: ${text2}`);
1212
+ }
1213
+ function pause(ms, signal) {
1214
+ return new Promise((resolve) => {
1215
+ const done = () => {
1216
+ clearTimeout(timer);
1217
+ signal?.removeEventListener("abort", done);
1218
+ resolve();
1219
+ };
1220
+ const timer = setTimeout(done, ms);
1221
+ signal?.addEventListener("abort", done, { once: true });
1222
+ });
1223
+ }
1224
+ var name = (number, suffix) => `${String(number).padStart(12, "0")}.${suffix}`;
1225
+ function generationNumbers(directory) {
1226
+ const numbers = /* @__PURE__ */ new Set();
1227
+ for (const entry of readdirSync2(directory)) {
1228
+ const match = /^(\d{12})\./.exec(entry);
1229
+ if (match) numbers.add(Number(match[1]));
1230
+ }
1231
+ return [...numbers].sort((a, b) => a - b);
1232
+ }
1233
+ function readGeneration(directory, number) {
1234
+ let owner;
1235
+ try {
1236
+ owner = readFileSync4(path5.join(directory, name(number, "owner")), "utf8");
1237
+ } catch (error) {
1238
+ if (errorCode(error) === "ENOENT") return null;
1239
+ throw error;
1240
+ }
1241
+ return {
1242
+ number,
1243
+ holder: parseIdentity(owner),
1244
+ released: readdirSync2(directory).includes(name(number, "released"))
1245
+ };
1246
+ }
1247
+ function readChildren(directory, number) {
1248
+ const prefix = name(number, "child.");
1249
+ return readdirSync2(directory).filter((entry) => entry.startsWith(prefix)).map((entry) => parseIdentity(readFileSync4(path5.join(directory, entry), "utf8")));
1250
+ }
1251
+ function groupAlive(table, leader) {
1252
+ const row = table.find((candidate) => candidate.pid === leader.pid);
1253
+ if (row && !sameProcess(row, leader)) return false;
1254
+ return table.some((candidate) => candidate.pgid === leader.pid && !candidate.zombie);
1255
+ }
1256
+ async function withSwiftRootLock(root, work, signal) {
1257
+ const directory = path5.join(
1258
+ rnxHomeDir(),
1259
+ "cache",
1260
+ "swift-root-locks",
1261
+ createHash4("sha256").update(root).digest("hex").slice(0, 32)
1262
+ );
1263
+ mkdirSync(directory, { recursive: true });
1264
+ const token = randomUUID2();
1265
+ const owner = JSON.stringify(ownIdentity(process.pid));
1266
+ const pending = path5.join(directory, `pending.${token}`);
1267
+ let held = 0;
1268
+ for (; ; ) {
1269
+ signal?.throwIfAborted();
1270
+ const newest = generationNumbers(directory).at(-1) ?? 0;
1271
+ const current = newest > 0 ? readGeneration(directory, newest) : null;
1272
+ if (newest > 0 && !current) continue;
1273
+ if (current && !current.released) {
1274
+ const table = processTable();
1275
+ if (table.some((row) => !row.zombie && sameProcess(row, current.holder))) {
1276
+ await pause(POLL_MS, signal);
1277
+ continue;
1278
+ }
1279
+ const children2 = readChildren(directory, newest);
1280
+ if (children2.some((child) => groupAlive(table, child))) {
1281
+ await pause(POLL_MS, signal);
1282
+ continue;
1283
+ }
1284
+ }
1285
+ writeFileSync2(pending, owner);
1286
+ try {
1287
+ linkSync(pending, path5.join(directory, name(newest + 1, "owner")));
1288
+ } catch (error) {
1289
+ if (errorCode(error) === "EEXIST") continue;
1290
+ throw error;
1291
+ } finally {
1292
+ rmSync2(pending, { force: true });
1293
+ }
1294
+ const numbers = generationNumbers(directory);
1295
+ if (numbers.at(-1) !== newest + 1) {
1296
+ rmSync2(path5.join(directory, name(newest + 1, "owner")), { force: true });
1297
+ continue;
1298
+ }
1299
+ held = newest + 1;
1300
+ for (const number of numbers)
1301
+ if (number < held) {
1302
+ for (const entry of readdirSync2(directory))
1303
+ if (entry.startsWith(name(number, "")))
1304
+ rmSync2(path5.join(directory, entry), { force: true });
1305
+ }
1306
+ break;
1307
+ }
1308
+ const children = [];
1309
+ const lease = {
1310
+ spawn(command, args, options) {
1311
+ const child = spawn2(
1312
+ "/bin/sh",
1313
+ ["-c", 'IFS= read -r go || exit 1; exec "$@" </dev/null', "sh", command, ...args],
1314
+ { ...options, detached: true, stdio: ["pipe", "pipe", "pipe"] }
1315
+ );
1316
+ child.stdin.on("error", () => {
1317
+ });
1318
+ children.push(child);
1319
+ try {
1320
+ if (child.pid === void 0) {
1321
+ child.once("error", () => {
1322
+ });
1323
+ throw new Error(`could not start ${command}`);
1324
+ }
1325
+ const childPending = `${pending}.child.${child.pid}`;
1326
+ try {
1327
+ writeFileSync2(childPending, JSON.stringify(ownIdentity(child.pid)));
1328
+ linkSync(childPending, path5.join(directory, name(held, `child.${child.pid}`)));
1329
+ } finally {
1330
+ rmSync2(childPending, { force: true });
1331
+ }
1332
+ } catch (error) {
1333
+ child.stdin.destroy();
1334
+ throw error;
1335
+ }
1336
+ child.stdin.end("go\n");
1337
+ return child;
1338
+ }
1339
+ };
1340
+ try {
1341
+ return await work(lease);
1342
+ } finally {
1343
+ await Promise.all(children.map((child) => terminateProcessGroup(child, "SIGKILL", 0)));
1344
+ writeFileSync2(path5.join(directory, name(held, "released")), "");
1345
+ }
1346
+ }
1347
+
1144
1348
  // src/swiftContract.ts
1145
1349
  function isSwiftResourcePath(value) {
1146
1350
  return typeof value === "string" && value.length <= 4096 && !value.startsWith("/") && !value.includes("\\") && !value.includes("\0") && value.split("/").every((part) => part !== "" && part !== "." && part !== "..");
@@ -1158,12 +1362,13 @@ function isSwiftResourceBundles(value) {
1158
1362
  async function runCompiler(command, args, options, stream = false, quiet) {
1159
1363
  const { signal } = options;
1160
1364
  signal?.throwIfAborted();
1161
- const child = spawn2(command, args, {
1365
+ const launch = {
1162
1366
  cwd: options.cwd,
1163
1367
  env: swiftEnvironment(options.env),
1164
1368
  detached: true,
1165
1369
  stdio: ["ignore", "pipe", "pipe"]
1166
- });
1370
+ };
1371
+ const child = options.lease ? options.lease.spawn(command, args, launch) : spawn3(command, args, launch);
1167
1372
  let stopping;
1168
1373
  try {
1169
1374
  await new Promise((resolve, reject) => {
@@ -1177,20 +1382,20 @@ async function runCompiler(command, args, options, stream = false, quiet) {
1177
1382
  void stopping.catch(() => {
1178
1383
  });
1179
1384
  };
1180
- for (const name of ["stdout", "stderr"]) {
1181
- child[name].on("data", (bytes) => {
1182
- if (stream === true) process[name].write(bytes);
1385
+ for (const name2 of ["stdout", "stderr"]) {
1386
+ child[name2].on("data", (bytes) => {
1387
+ if (stream === true) process[name2].write(bytes);
1183
1388
  else if (stream) {
1184
- const lines = (partial[name] + bytes.toString()).split("\n");
1185
- partial[name] = lines.pop();
1389
+ const lines = (partial[name2] + bytes.toString()).split("\n");
1390
+ partial[name2] = lines.pop();
1186
1391
  for (const line of lines)
1187
- if (stream.test(line)) process[name].write(`${line}
1392
+ if (stream.test(line)) process[name2].write(`${line}
1188
1393
  `);
1189
1394
  }
1190
- sizes[name] += bytes.length;
1191
- if (sizes[name] <= (options.maxBuffer ?? 1024 * 1024)) chunks[name].push(bytes);
1395
+ sizes[name2] += bytes.length;
1396
+ if (sizes[name2] <= (options.maxBuffer ?? 1024 * 1024)) chunks[name2].push(bytes);
1192
1397
  else {
1193
- failure = new Error(`Swift compiler ${name} exceeded its output limit`);
1398
+ failure = new Error(`Swift compiler ${name2} exceeded its output limit`);
1194
1399
  stop();
1195
1400
  }
1196
1401
  });
@@ -1218,9 +1423,9 @@ async function runCompiler(command, args, options, stream = false, quiet) {
1218
1423
  );
1219
1424
  else {
1220
1425
  if (quiet) {
1221
- for (const name of ["stdout", "stderr"])
1222
- for (const line of Buffer.concat(chunks[name]).toString().split("\n"))
1223
- if (line && !quiet.test(line)) process[name].write(`${line}
1426
+ for (const name2 of ["stdout", "stderr"])
1427
+ for (const line of Buffer.concat(chunks[name2]).toString().split("\n"))
1428
+ if (line && !quiet.test(line)) process[name2].write(`${line}
1224
1429
  `);
1225
1430
  }
1226
1431
  resolve();
@@ -1244,12 +1449,12 @@ var BUILD_JOBS = String(
1244
1449
  Math.min(4, Math.max(1, Math.floor(os2.availableParallelism() / 2)))
1245
1450
  );
1246
1451
  function swiftDistributionAt(root) {
1247
- const file = path5.join(root, SWIFT_DISTRIBUTION_MANIFEST);
1452
+ const file = path6.join(root, SWIFT_DISTRIBUTION_MANIFEST);
1248
1453
  if (!existsSync2(file)) return null;
1249
- return parseSwiftDistributionManifest(JSON.parse(readFileSync4(file, "utf8")));
1454
+ return parseSwiftDistributionManifest(JSON.parse(readFileSync5(file, "utf8")));
1250
1455
  }
1251
1456
  function swiftModuleSdk(root) {
1252
- const pin = swiftDistributionAt(root) ?? JSON.parse(readFileSync4(path5.join(root, "toolchain.json"), "utf8"));
1457
+ const pin = swiftDistributionAt(root) ?? JSON.parse(readFileSync5(path6.join(root, "toolchain.json"), "utf8"));
1253
1458
  if (!pin || typeof pin !== "object" || typeof Reflect.get(pin, "wasmSdkId") !== "string" || typeof Reflect.get(pin, "wasmSdkUrl") !== "string" || typeof Reflect.get(pin, "wasmSdkChecksum") !== "string")
1254
1459
  throw new Error(`${root} pins no wasm SDK id, url and checksum`);
1255
1460
  return {
@@ -1275,7 +1480,7 @@ function swiftModuleInputFiles(root) {
1275
1480
  "toolchain.json"
1276
1481
  ];
1277
1482
  const walk = (dir) => {
1278
- for (const entry of readdirSync2(path5.join(root, dir), {
1483
+ for (const entry of readdirSync3(path6.join(root, dir), {
1279
1484
  withFileTypes: true
1280
1485
  })) {
1281
1486
  const relative = `${dir}/${entry.name}`;
@@ -1293,38 +1498,38 @@ function swiftMacroPlugins(moduleRoot) {
1293
1498
  const distribution = swiftDistributionAt(moduleRoot);
1294
1499
  if (distribution)
1295
1500
  return {
1296
- libraries: distribution.plugins.map((plugin) => path5.join(moduleRoot, plugin)),
1501
+ libraries: distribution.plugins.map((plugin) => path6.join(moduleRoot, plugin)),
1297
1502
  stale: false
1298
1503
  };
1299
- const dir = path5.join(moduleRoot, ".build/host/RnxPreviewMacros");
1504
+ const dir = path6.join(moduleRoot, ".build/host/RnxPreviewMacros");
1300
1505
  const release = JSON.parse(
1301
- readFileSync4(path5.join(moduleRoot, "toolchain.json"), "utf8")
1506
+ readFileSync5(path6.join(moduleRoot, "toolchain.json"), "utf8")
1302
1507
  ).release;
1303
- const compilerStamp = path5.join(dir, "compiler-release");
1508
+ const compilerStamp = path6.join(dir, "compiler-release");
1304
1509
  const ext = process.platform === "darwin" ? "dylib" : "so";
1305
1510
  const plugins = [
1306
1511
  {
1307
- library: path5.join(dir, `libRnxPreviewMacros.${ext}`),
1308
- sources: [path5.join(moduleRoot, "Sources/RnxPreviewMacros/PreviewMacro.swift")]
1512
+ library: path6.join(dir, `libRnxPreviewMacros.${ext}`),
1513
+ sources: [path6.join(moduleRoot, "Sources/RnxPreviewMacros/PreviewMacro.swift")]
1309
1514
  },
1310
1515
  {
1311
- library: path5.join(dir, `libFoundationMacros.${ext}`),
1516
+ library: path6.join(dir, `libFoundationMacros.${ext}`),
1312
1517
  sources: [
1313
- path5.join(moduleRoot, "Sources/FoundationMacros/PredicateMacro.swift"),
1314
- path5.join(moduleRoot, "Sources/SwiftMacroSupport/PredicateExpression.swift")
1518
+ path6.join(moduleRoot, "Sources/FoundationMacros/PredicateMacro.swift"),
1519
+ path6.join(moduleRoot, "Sources/SwiftMacroSupport/PredicateExpression.swift")
1315
1520
  ]
1316
1521
  },
1317
1522
  {
1318
- library: path5.join(dir, `libTipKitMacros.${ext}`),
1523
+ library: path6.join(dir, `libTipKitMacros.${ext}`),
1319
1524
  sources: [
1320
- path5.join(moduleRoot, "Sources/TipKitMacros/TipKitMacros.swift"),
1321
- path5.join(moduleRoot, "Sources/SwiftMacroSupport/PredicateExpression.swift")
1525
+ path6.join(moduleRoot, "Sources/TipKitMacros/TipKitMacros.swift"),
1526
+ path6.join(moduleRoot, "Sources/SwiftMacroSupport/PredicateExpression.swift")
1322
1527
  ]
1323
1528
  }
1324
1529
  ];
1325
1530
  return {
1326
1531
  libraries: plugins.map(({ library }) => library),
1327
- stale: !existsSync2(compilerStamp) || readFileSync4(compilerStamp, "utf8").trim() !== release || plugins.some(
1532
+ stale: !existsSync2(compilerStamp) || readFileSync5(compilerStamp, "utf8").trim() !== release || plugins.some(
1328
1533
  ({ library, sources }) => !existsSync2(library) || sources.some((source) => statSync(source).mtimeMs > statSync(library).mtimeMs)
1329
1534
  )
1330
1535
  };
@@ -1335,14 +1540,14 @@ async function ensureMacroPlugins(moduleRoot, toolchainBin, release, signal) {
1335
1540
  await runCompiler(
1336
1541
  "sh",
1337
1542
  [
1338
- path5.join(moduleRoot, "scripts/build-preview-plugin.sh"),
1543
+ path6.join(moduleRoot, "scripts/build-preview-plugin.sh"),
1339
1544
  toolchainBin,
1340
1545
  libraries[0]
1341
1546
  ],
1342
1547
  { signal }
1343
1548
  );
1344
- writeFileSync2(
1345
- path5.join(path5.dirname(libraries[0]), "compiler-release"),
1549
+ writeFileSync3(
1550
+ path6.join(path6.dirname(libraries[0]), "compiler-release"),
1346
1551
  `${release}
1347
1552
  `
1348
1553
  );
@@ -1356,9 +1561,9 @@ function clearLinkedModuleDigests(root) {
1356
1561
  }
1357
1562
  function swiftModuleDigest(root) {
1358
1563
  const files = swiftModuleInputFiles(root);
1359
- const stampHash = createHash4("sha256");
1564
+ const stampHash = createHash5("sha256");
1360
1565
  for (const file of files) {
1361
- const stat = statSync(path5.join(root, file), { bigint: true });
1566
+ const stat = statSync(path6.join(root, file), { bigint: true });
1362
1567
  stampHash.update(file);
1363
1568
  stampHash.update(
1364
1569
  `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}
@@ -1368,11 +1573,11 @@ function swiftModuleDigest(root) {
1368
1573
  const stamp = stampHash.digest("hex");
1369
1574
  const cached = linkedModuleDigests.get(root);
1370
1575
  if (cached?.stamp === stamp) return cached.digest;
1371
- const hash = createHash4("sha256");
1576
+ const hash = createHash5("sha256");
1372
1577
  for (const file of files) {
1373
- hash.update(createHash4("sha256").update(file).digest());
1578
+ hash.update(createHash5("sha256").update(file).digest());
1374
1579
  hash.update(
1375
- createHash4("sha256").update(readFileSync4(path5.join(root, file))).digest()
1580
+ createHash5("sha256").update(readFileSync5(path6.join(root, file))).digest()
1376
1581
  );
1377
1582
  }
1378
1583
  const digest = hash.digest();
@@ -1380,7 +1585,7 @@ function swiftModuleDigest(root) {
1380
1585
  return digest;
1381
1586
  }
1382
1587
  function swiftProjectBuildKey(moduleRoot, release) {
1383
- return createHash4("sha256").update(`${release}\0${swiftModuleSdk(moduleRoot).wasmSdkId}`).update(swiftModuleDigest(moduleRoot)).digest("hex").slice(0, 32);
1588
+ return createHash5("sha256").update(`${release}\0${swiftModuleSdk(moduleRoot).wasmSdkId}`).update(swiftModuleDigest(moduleRoot)).digest("hex").slice(0, 32);
1384
1589
  }
1385
1590
  function compileTargets(input) {
1386
1591
  const manifest = input.files["Package.swift"];
@@ -1396,7 +1601,7 @@ function withNativeSourceGlue(input, glue) {
1396
1601
  ...input,
1397
1602
  files: {
1398
1603
  ...input.files,
1399
- [path5.posix.join(targetPath, "OneNativeSource.generated.swift")]: glue
1604
+ [path6.posix.join(targetPath, "OneNativeSource.generated.swift")]: glue
1400
1605
  },
1401
1606
  oneModule: true
1402
1607
  };
@@ -1465,11 +1670,11 @@ function swiftCondition(text2, available) {
1465
1670
  if (token === "false") return false;
1466
1671
  const call = /^(\w+)\s*\(\s*([^,()]*?)\s*(?:,[^()]*)?\)$/.exec(token ?? "");
1467
1672
  if (!call) return void 0;
1468
- const [, name, argument] = call;
1469
- if (name === "os") return argument === "iOS" || argument === "WASI";
1470
- if (name === "canImport") return available.has(argument);
1471
- if (name === "targetEnvironment") return false;
1472
- if (name === "arch") return argument === "wasm32";
1673
+ const [, name2, argument] = call;
1674
+ if (name2 === "os") return argument === "iOS" || argument === "WASI";
1675
+ if (name2 === "canImport") return available.has(argument);
1676
+ if (name2 === "targetEnvironment") return false;
1677
+ if (name2 === "arch") return argument === "wasm32";
1473
1678
  return void 0;
1474
1679
  };
1475
1680
  const both = () => {
@@ -1513,15 +1718,15 @@ function swiftImportNames(contents, available) {
1513
1718
  continue;
1514
1719
  }
1515
1720
  if (available && frames.some((frame) => frame.active !== true)) continue;
1516
- const name = SWIFT_IMPORT.exec(line)?.[1];
1517
- if (name) names.push(name);
1721
+ const name2 = SWIFT_IMPORT.exec(line)?.[1];
1722
+ if (name2) names.push(name2);
1518
1723
  }
1519
1724
  return names;
1520
1725
  }
1521
1726
  function swiftPeachModules(moduleRoot) {
1522
1727
  const distribution = swiftDistributionAt(moduleRoot);
1523
1728
  return distribution ? distribution.modules : [
1524
- ...readFileSync4(path5.join(moduleRoot, "Package.swift"), "utf8").matchAll(
1729
+ ...readFileSync5(path6.join(moduleRoot, "Package.swift"), "utf8").matchAll(
1525
1730
  /\.(?:target|systemLibrary)\(\s*name:\s*"([^"]+)"/g
1526
1731
  )
1527
1732
  ].map((match) => match[1]);
@@ -1533,7 +1738,7 @@ function swiftSdkPaths(moduleRoot, toolchainBin) {
1533
1738
  const cached = sdkPaths.get(key);
1534
1739
  if (cached) return cached;
1535
1740
  const configuration = execFileSync2(
1536
- path5.join(toolchainBin, "swift"),
1741
+ path6.join(toolchainBin, "swift"),
1537
1742
  [
1538
1743
  "sdk",
1539
1744
  "configure",
@@ -1544,9 +1749,9 @@ function swiftSdkPaths(moduleRoot, toolchainBin) {
1544
1749
  ],
1545
1750
  { encoding: "utf8", env: swiftEnvironment(), stdio: ["ignore", "pipe", "pipe"] }
1546
1751
  );
1547
- const field = (name) => {
1548
- const value = new RegExp(`^${name}:\\s*(.+)$`, "m").exec(configuration)?.[1]?.trim();
1549
- if (!value) throw new Error(`swift sdk ${sdk} reports no ${name}`);
1752
+ const field = (name2) => {
1753
+ const value = new RegExp(`^${name2}:\\s*(.+)$`, "m").exec(configuration)?.[1]?.trim();
1754
+ if (!value) throw new Error(`swift sdk ${sdk} reports no ${name2}`);
1550
1755
  return value;
1551
1756
  };
1552
1757
  const paths = {
@@ -1564,14 +1769,14 @@ function swiftAvailableModules(moduleRoot, toolchainBin) {
1564
1769
  if (cached) return cached;
1565
1770
  const modules = new Set(swiftPeachModules(moduleRoot));
1566
1771
  const { resources } = swiftSdkPaths(moduleRoot, toolchainBin);
1567
- for (const entry of readdirSync2(path5.join(resources, "wasi"))) {
1772
+ for (const entry of readdirSync3(path6.join(resources, "wasi"))) {
1568
1773
  if (entry.endsWith(".swiftmodule"))
1569
1774
  modules.add(entry.slice(0, -".swiftmodule".length));
1570
1775
  }
1571
- for (const entry of readdirSync2(resources)) {
1572
- const map = path5.join(resources, entry, "module.modulemap");
1776
+ for (const entry of readdirSync3(resources)) {
1777
+ const map = path6.join(resources, entry, "module.modulemap");
1573
1778
  if (!existsSync2(map)) continue;
1574
- for (const match of readFileSync4(map, "utf8").matchAll(/^module\s+([A-Za-z_]\w*)/gm))
1779
+ for (const match of readFileSync5(map, "utf8").matchAll(/^module\s+([A-Za-z_]\w*)/gm))
1575
1780
  modules.add(match[1]);
1576
1781
  }
1577
1782
  availableModules.set(key, modules);
@@ -1581,9 +1786,9 @@ function missingSwiftModules(files, available) {
1581
1786
  const missing = /* @__PURE__ */ new Map();
1582
1787
  for (const [file, contents] of Object.entries(files)) {
1583
1788
  if (!file.endsWith(".swift") || file === "Package.swift") continue;
1584
- for (const name of new Set(swiftImportNames(contents, available))) {
1585
- if (available.has(name)) continue;
1586
- missing.set(name, [...missing.get(name) ?? [], file]);
1789
+ for (const name2 of new Set(swiftImportNames(contents, available))) {
1790
+ if (available.has(name2)) continue;
1791
+ missing.set(name2, [...missing.get(name2) ?? [], file]);
1587
1792
  }
1588
1793
  }
1589
1794
  return new Map([...missing].sort(([left], [right]) => left.localeCompare(right)));
@@ -1604,8 +1809,8 @@ function swiftTargetDependencies(files, targets) {
1604
1809
  (candidate) => candidate.name !== target.name && candidate.path !== "." && candidate.path.startsWith(prefix) && file.startsWith(`${candidate.path}/`)
1605
1810
  ))
1606
1811
  continue;
1607
- for (const name of swiftImportNames(contents)) {
1608
- if (names.has(name) && name !== target.name) deps.add(name);
1812
+ for (const name2 of swiftImportNames(contents)) {
1813
+ if (names.has(name2) && name2 !== target.name) deps.add(name2);
1609
1814
  }
1610
1815
  }
1611
1816
  siblings.set(target.name, [...deps].sort());
@@ -1635,9 +1840,9 @@ var EXECUTABLE_LINK_FLAGS = ` "-Xclang-linker", "-O0",
1635
1840
  `;
1636
1841
  var REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
1637
1842
  var MULTI_MANIFEST_VERSION = 39;
1638
- var compilerSourceDigest = true ? "0c614fef8e4e656ac3500002f7d1f2746f20f462321142e2f69a93e94f2321c4" : swiftCompilerSourceDigest(import.meta.dirname);
1843
+ var compilerSourceDigest = true ? "c2ab17198fbe6328c75dc09bbe160fe6b0fd74d4b84a08e9f8dfcd2fcf4ca1f0" : swiftCompilerSourceDigest(import.meta.dirname);
1639
1844
  function swiftArtifactHash(input, release, moduleRoot) {
1640
- const hash = createHash4("sha256");
1845
+ const hash = createHash5("sha256");
1641
1846
  hash.update(`swift-compile
1642
1847
  ${release}
1643
1848
  `);
@@ -1645,32 +1850,32 @@ ${release}
1645
1850
  if (input.oneModule) hash.update("one-module\n");
1646
1851
  hash.update(swiftModuleDigest(moduleRoot));
1647
1852
  for (const file of Object.keys(input.files).sort()) {
1648
- hash.update(createHash4("sha256").update(file).digest());
1649
- hash.update(createHash4("sha256").update(input.files[file]).digest());
1853
+ hash.update(createHash5("sha256").update(file).digest());
1854
+ hash.update(createHash5("sha256").update(input.files[file]).digest());
1650
1855
  }
1651
1856
  for (const file of Object.keys(input.metalSources ?? {}).sort()) {
1652
1857
  hash.update("metal-source\n");
1653
- hash.update(createHash4("sha256").update(file).digest());
1858
+ hash.update(createHash5("sha256").update(file).digest());
1654
1859
  hash.update(
1655
- createHash4("sha256").update(input.metalSources?.[file] ?? "").digest()
1860
+ createHash5("sha256").update(input.metalSources?.[file] ?? "").digest()
1656
1861
  );
1657
1862
  }
1658
1863
  for (const base of Object.keys(input.resources ?? {}).sort()) {
1659
- hash.update(createHash4("sha256").update(base).digest());
1864
+ hash.update(createHash5("sha256").update(base).digest());
1660
1865
  hash.update(
1661
- createHash4("sha256").update(input.resources?.[base] ?? "").digest()
1866
+ createHash5("sha256").update(input.resources?.[base] ?? "").digest()
1662
1867
  );
1663
1868
  }
1664
- for (const name of Object.keys(input.images ?? {}).sort()) {
1665
- const image = input.images?.[name];
1869
+ for (const name2 of Object.keys(input.images ?? {}).sort()) {
1870
+ const image = input.images?.[name2];
1666
1871
  if (!image) continue;
1667
- hash.update(createHash4("sha256").update(name).digest());
1668
- hash.update(createHash4("sha256").update(image.file).digest());
1669
- hash.update(createHash4("sha256").update(image.data).digest());
1872
+ hash.update(createHash5("sha256").update(name2).digest());
1873
+ hash.update(createHash5("sha256").update(image.file).digest());
1874
+ hash.update(createHash5("sha256").update(image.data).digest());
1670
1875
  }
1671
1876
  for (const file of [...new Set(input.resourcePaths ?? [])].sort()) {
1672
1877
  hash.update("resource-path\n");
1673
- hash.update(createHash4("sha256").update(file).digest());
1878
+ hash.update(createHash5("sha256").update(file).digest());
1674
1879
  }
1675
1880
  hash.update(
1676
1881
  JSON.stringify(
@@ -1682,7 +1887,7 @@ ${release}
1682
1887
  ${target}
1683
1888
  `);
1684
1889
  hash.update(
1685
- createHash4("sha256").update(input.libraries?.[target] ?? "").digest()
1890
+ createHash5("sha256").update(input.libraries?.[target] ?? "").digest()
1686
1891
  );
1687
1892
  }
1688
1893
  const targets = compileTargets(input);
@@ -1703,17 +1908,17 @@ ${target}
1703
1908
  function emitSwiftPackageManifest(args) {
1704
1909
  const { targets, siblings, moduleRoot, oneModule, spriteKit, distribution } = args;
1705
1910
  const reachedFrameworks = /* @__PURE__ */ new Set();
1706
- const reach = (name) => {
1707
- if (reachedFrameworks.has(name)) return;
1708
- reachedFrameworks.add(name);
1709
- for (const dependency of OPTIONAL_FRAMEWORK_DEPENDENCIES[name] ?? [])
1911
+ const reach = (name2) => {
1912
+ if (reachedFrameworks.has(name2)) return;
1913
+ reachedFrameworks.add(name2);
1914
+ for (const dependency of OPTIONAL_FRAMEWORK_DEPENDENCIES[name2] ?? [])
1710
1915
  reach(dependency);
1711
1916
  };
1712
- for (const name of [...siblings.values()].flat())
1713
- if (OPTIONAL_FRAMEWORKS.has(name) && !targets.some((target) => target.name === name))
1714
- reach(name);
1917
+ for (const name2 of [...siblings.values()].flat())
1918
+ if (OPTIONAL_FRAMEWORKS.has(name2) && !targets.some((target) => target.name === name2))
1919
+ reach(name2);
1715
1920
  if (spriteKit) {
1716
- for (const name of ["SpriteKit", "PeachBox2D", "simd", "GLKit"]) reach(name);
1921
+ for (const name2 of ["SpriteKit", "PeachBox2D", "simd", "GLKit"]) reach(name2);
1717
1922
  }
1718
1923
  const distributionLink = args.distributionLink;
1719
1924
  if (distribution && !distributionLink)
@@ -1723,27 +1928,27 @@ function emitSwiftPackageManifest(args) {
1723
1928
  if (distribution && distributionLink) {
1724
1929
  const objects = distribution.objects.filter(
1725
1930
  (object) => [...OPTIONAL_FRAMEWORKS, "SpriteKit", "PeachBox2D"].every(
1726
- (name) => !object.startsWith(`lib/${name}-`) || reachedFrameworks.has(name)
1931
+ (name2) => !object.startsWith(`lib/${name2}-`) || reachedFrameworks.has(name2)
1727
1932
  )
1728
1933
  );
1729
1934
  distributionLink.files.set(
1730
1935
  distributionLink.path,
1731
1936
  objects.map(
1732
- (object) => `"${path5.join(moduleRoot, object).replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`
1937
+ (object) => `"${path6.join(moduleRoot, object).replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`
1733
1938
  ).join("\n") + "\n"
1734
1939
  );
1735
1940
  }
1736
- const overlayRoot = path5.join(
1941
+ const overlayRoot = path6.join(
1737
1942
  moduleRoot,
1738
1943
  distribution ? "modules" : "cross-import-overlays"
1739
1944
  );
1740
- const overlayFlags = readdirSync2(overlayRoot, { encoding: "utf8", recursive: true }).filter((file) => file.endsWith(".swiftoverlay")).sort((left, right) => left.localeCompare(right)).flatMap((file) => [
1945
+ const overlayFlags = readdirSync3(overlayRoot, { encoding: "utf8", recursive: true }).filter((file) => file.endsWith(".swiftoverlay")).sort((left, right) => left.localeCompare(right)).flatMap((file) => [
1741
1946
  "-Xfrontend",
1742
1947
  "-swift-module-cross-import",
1743
1948
  "-Xfrontend",
1744
- path5.basename(path5.dirname(file), ".swiftcrossimport"),
1949
+ path6.basename(path6.dirname(file), ".swiftcrossimport"),
1745
1950
  "-Xfrontend",
1746
- path5.join(overlayRoot, file)
1951
+ path6.join(overlayRoot, file)
1747
1952
  ]).map((flag) => `, ${JSON.stringify(flag)}`).join("");
1748
1953
  const executable = targets.find((target) => target.executable);
1749
1954
  if (!executable) throw new Error("swift-compile: no executable target to emit");
@@ -1752,15 +1957,15 @@ function emitSwiftPackageManifest(args) {
1752
1957
  return ` .systemLibrary(name: ${JSON.stringify(target.name)}, path: ${JSON.stringify(target.path)}),`;
1753
1958
  const isolation = target.mainActorIsolation ? " .defaultIsolation(MainActor.self)," : "";
1754
1959
  const interoperability = target.cxxInterop ? " .interoperabilityMode(.Cxx)," : "";
1755
- const defines = (target.defines ?? []).map((name) => ` .define(${JSON.stringify(name)}),`).join("");
1756
- const imports = distribution ? `, "-I", ${JSON.stringify(path5.join(moduleRoot, "modules"))}` : "";
1960
+ const defines = (target.defines ?? []).map((name2) => ` .define(${JSON.stringify(name2)}),`).join("");
1961
+ const imports = distribution ? `, "-I", ${JSON.stringify(path6.join(moduleRoot, "modules"))}` : "";
1757
1962
  const native = args.native?.get(target.name);
1758
- const nativeImports = (siblings.get(target.name) ?? []).filter((name) => args.native?.has(name)).map(
1759
- (name) => `, "-Xfrontend", "-import-module", "-Xfrontend", ${JSON.stringify(swiftTargetModuleName(name))}`
1963
+ const nativeImports = (siblings.get(target.name) ?? []).filter((name2) => args.native?.has(name2)).map(
1964
+ (name2) => `, "-Xfrontend", "-import-module", "-Xfrontend", ${JSON.stringify(swiftTargetModuleName(name2))}`
1760
1965
  ).join("");
1761
1966
  const header = args.headerDirectory && [...args.native?.values() ?? []].some(
1762
1967
  (value) => value.late?.producers.includes(target.name)
1763
- ) ? `, "-emit-objc-header-path", ${JSON.stringify(path5.join(args.headerDirectory, `${target.name}-Swift.h`))}` : "";
1968
+ ) ? `, "-emit-objc-header-path", ${JSON.stringify(path6.join(args.headerDirectory, `${target.name}-Swift.h`))}` : "";
1764
1969
  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}])]`;
1765
1970
  const deps = [
1766
1971
  ...target.executable ? [...args.native?.values() ?? []].flatMap(
@@ -1775,10 +1980,10 @@ function emitSwiftPackageManifest(args) {
1775
1980
  (dependency) => OPTIONAL_FRAMEWORKS.has(dependency) && !targets.some((candidate) => candidate.name === dependency) ? distribution ? [] : [`.product(name: "${dependency}", package: "sootsim-swift")`] : [`"${dependency}"`]
1776
1981
  )
1777
1982
  ].join(", ");
1778
- const library = distribution && distributionLink ? ["-Xlinker", `@${distributionLink.path}`, ...distribution.link].map((flag) => `, ${JSON.stringify(flag)}`).join("") : "";
1983
+ const library = distribution && distributionLink ? ["-Xclang-linker", `--config=${distributionLink.path}`, ...distribution.link].map((flag) => `, ${JSON.stringify(flag)}`).join("") : "";
1779
1984
  const kind = target.executable ? ".executableTarget" : ".target";
1780
1985
  const linkedLibraries = (target.linkedLibraries ?? []).map(
1781
- (name) => `.linkedLibrary(${JSON.stringify(name)})`
1986
+ (name2) => `.linkedLibrary(${JSON.stringify(name2)})`
1782
1987
  );
1783
1988
  const librarySettings = [
1784
1989
  ...linkedLibraries,
@@ -1817,9 +2022,9 @@ function emitSwiftPackageManifest(args) {
1817
2022
  " targets: [",
1818
2023
  ...targets.map(stanza),
1819
2024
  ...[...args.native?.entries() ?? []].flatMap(
1820
- ([name, native]) => native.late ? [
2025
+ ([name2, native]) => native.late ? [
1821
2026
  ` .target(name: ${JSON.stringify(native.late.name)},`,
1822
- ` dependencies: ${JSON.stringify([name, ...native.late.producers])},`,
2027
+ ` dependencies: ${JSON.stringify([name2, ...native.late.producers])},`,
1823
2028
  ` path: ${JSON.stringify(native.path)},`,
1824
2029
  ` sources: ${JSON.stringify(native.lateSources)},`,
1825
2030
  ` publicHeadersPath: "include",`,
@@ -1833,21 +2038,21 @@ function emitSwiftPackageManifest(args) {
1833
2038
  ].join("\n");
1834
2039
  }
1835
2040
  function syncSwiftTree(base, files) {
1836
- mkdirSync(base, { recursive: true });
2041
+ mkdirSync2(base, { recursive: true });
1837
2042
  const walk = (dir) => {
1838
- for (const entry of readdirSync2(dir, { withFileTypes: true })) {
1839
- const full = path5.join(dir, entry.name);
2043
+ for (const entry of readdirSync3(dir, { withFileTypes: true })) {
2044
+ const full = path6.join(dir, entry.name);
1840
2045
  if (dir === base && entry.name === ".build") continue;
1841
2046
  if (entry.isDirectory()) walk(full);
1842
- else if (!files.has(full)) rmSync2(full, { force: true });
2047
+ else if (!files.has(full)) rmSync3(full, { force: true });
1843
2048
  }
1844
2049
  };
1845
2050
  walk(base);
1846
2051
  for (const [full, contents] of files) {
1847
- if (existsSync2(full) && (typeof contents === "string" ? readFileSync4(full, "utf8") === contents : readFileSync4(full).equals(contents)))
2052
+ if (existsSync2(full) && (typeof contents === "string" ? readFileSync5(full, "utf8") === contents : readFileSync5(full).equals(contents)))
1848
2053
  continue;
1849
- mkdirSync(path5.dirname(full), { recursive: true });
1850
- writeFileSync2(full, contents);
2054
+ mkdirSync2(path6.dirname(full), { recursive: true });
2055
+ writeFileSync3(full, contents);
1851
2056
  }
1852
2057
  }
1853
2058
  var DIRECTIVE = /^[ \t]*#(?:if|elseif)\b/;
@@ -2072,7 +2277,7 @@ function extensionOverrideEdits(source, extraObjCExtensions) {
2072
2277
  if (top?.kind !== "extension") continue;
2073
2278
  const func = OVERRIDE_FUNC.exec(rest);
2074
2279
  if (func) {
2075
- const name = func[2];
2280
+ const name2 = func[2];
2076
2281
  const open = at + func[0].length - 1;
2077
2282
  let depth = 0;
2078
2283
  let close = open;
@@ -2085,12 +2290,12 @@ function extensionOverrideEdits(source, extraObjCExtensions) {
2085
2290
  const clause = source.slice(close + 1, body).trim();
2086
2291
  const args = forwardedArguments(source.slice(open + 1, close));
2087
2292
  if (args === null) continue;
2088
- const call = (clause.includes("->") ? "return " : "") + (/\b(?:throws|rethrows)\b/.test(clause) ? "try " : "") + (/\basync\b/.test(clause) ? "await " : "") + `__peach_ext_${name}(${args})`;
2089
- const signature = `func ${name}${func[3] ?? ""}${source.slice(open, close + 1)}${clause ? ` ${clause}` : ""}`;
2090
- const nameAt = at + rest.indexOf(name, rest.indexOf("func", "override".length + func[1].length) + 4);
2293
+ const call = (clause.includes("->") ? "return " : "") + (/\b(?:throws|rethrows)\b/.test(clause) ? "try " : "") + (/\basync\b/.test(clause) ? "await " : "") + `__peach_ext_${name2}(${args})`;
2294
+ const signature = `func ${name2}${func[3] ?? ""}${source.slice(open, close + 1)}${clause ? ` ${clause}` : ""}`;
2295
+ const nameAt = at + rest.indexOf(name2, rest.indexOf("func", "override".length + func[1].length) + 4);
2091
2296
  lifted.push({
2092
2297
  type: top.name,
2093
- member: name,
2298
+ member: name2,
2094
2299
  at,
2095
2300
  modifiers,
2096
2301
  access,
@@ -2108,16 +2313,16 @@ function extensionOverrideEdits(source, extraObjCExtensions) {
2108
2313
  if (property) {
2109
2314
  const open = at + property[0].length - 1;
2110
2315
  if (/\b(?:set|willSet|didSet)\b/.test(source.slice(open, closing(open)))) continue;
2111
- const name = property[2];
2112
- const nameAt = at + rest.indexOf(name, rest.indexOf("var"));
2316
+ const name2 = property[2];
2317
+ const nameAt = at + rest.indexOf(name2, rest.indexOf("var"));
2113
2318
  lifted.push({
2114
2319
  type: top.name,
2115
- member: name,
2320
+ member: name2,
2116
2321
  at,
2117
2322
  modifiers,
2118
2323
  access,
2119
- decl: `var ${name}: ${property[3].trim()}`,
2120
- forward: `{ __peach_ext_${name} };`,
2324
+ decl: `var ${name2}: ${property[3].trim()}`,
2325
+ forward: `{ __peach_ext_${name2} };`,
2121
2326
  nameAt,
2122
2327
  edits: [
2123
2328
  [at, "override".length, " ".repeat("override".length)],
@@ -2255,15 +2460,15 @@ function objcRootedClasses(sources) {
2255
2460
  ))
2256
2461
  bases.set(match[1], match[2]);
2257
2462
  const rooted = /* @__PURE__ */ new Set();
2258
- for (const name of bases.keys()) {
2259
- const seen = /* @__PURE__ */ new Set([name]);
2260
- let base = bases.get(name);
2463
+ for (const name2 of bases.keys()) {
2464
+ const seen = /* @__PURE__ */ new Set([name2]);
2465
+ let base = bases.get(name2);
2261
2466
  while (bases.has(base) && !seen.has(base)) {
2262
2467
  seen.add(base);
2263
2468
  base = bases.get(base);
2264
2469
  }
2265
2470
  if (!bases.has(base) && APPLE_CLASS.test(base) && !APPLE_PROTOCOL.test(base) && !(base in SDK_OBJC_OPTIONAL))
2266
- rooted.add(name);
2471
+ rooted.add(name2);
2267
2472
  }
2268
2473
  return rooted;
2269
2474
  }
@@ -2406,8 +2611,8 @@ function inheritedTypes(sources) {
2406
2611
  if (colon === -1) continue;
2407
2612
  const inherited = parents.get(owner[1]) ?? /* @__PURE__ */ new Set();
2408
2613
  for (const type of splitTopLevel(header.slice(colon + 1).split(/\bwhere\b/)[0])) {
2409
- const name = /^\s*(?:[A-Za-z_]\w*\.)*([A-Za-z_]\w*)/.exec(type)?.[1];
2410
- if (name && !type.includes("<")) inherited.add(name);
2614
+ const name2 = /^\s*(?:[A-Za-z_]\w*\.)*([A-Za-z_]\w*)/.exec(type)?.[1];
2615
+ if (name2 && !type.includes("<")) inherited.add(name2);
2411
2616
  }
2412
2617
  parents.set(owner[1], inherited);
2413
2618
  }
@@ -2486,20 +2691,20 @@ var DECLARATION_MODIFIERS = /* @__PURE__ */ new Set([
2486
2691
  "unowned"
2487
2692
  ]);
2488
2693
  function objcSelectorName(base, labels, isAsync, isThrowing) {
2489
- let name = base;
2694
+ let name2 = base;
2490
2695
  labels.forEach((label, index) => {
2491
- if (index > 0) name += `${label === "_" ? "" : label}:`;
2696
+ if (index > 0) name2 += `${label === "_" ? "" : label}:`;
2492
2697
  else {
2493
2698
  if (label !== "_") {
2494
2699
  const firstWord = label[0] + /^[^A-Z_]*/.exec(label.slice(1))[0];
2495
- name += `${OBJC_PREPOSITIONS.has(firstWord) ? "" : "With"}${label[0].toUpperCase()}${label.slice(1)}`;
2700
+ name2 += `${OBJC_PREPOSITIONS.has(firstWord) ? "" : "With"}${label[0].toUpperCase()}${label.slice(1)}`;
2496
2701
  }
2497
- name += ":";
2702
+ name2 += ":";
2498
2703
  }
2499
2704
  });
2500
- if (isAsync) name += labels.length ? "completionHandler:" : "WithCompletionHandler:";
2501
- else if (isThrowing) name += labels.length ? "error:" : "AndReturnError:";
2502
- return name;
2705
+ if (isAsync) name2 += labels.length ? "completionHandler:" : "WithCompletionHandler:";
2706
+ else if (isThrowing) name2 += labels.length ? "error:" : "AndReturnError:";
2707
+ return name2;
2503
2708
  }
2504
2709
  function declarationStart(code, at, floor) {
2505
2710
  let start = at;
@@ -2561,22 +2766,22 @@ function objcOptionalProtocols(source) {
2561
2766
  ...(attributes.match(/@available\s*\((?:[^()"]|"(?:[^"\\]|\\.)*")*\)/g) ?? []).map((attribute) => attribute.replace(/\s*\n\s*/g, " ")),
2562
2767
  access ?? ""
2563
2768
  ].filter((word) => word !== "").join(" ");
2564
- const name = member[2];
2769
+ const name2 = member[2];
2565
2770
  const after = at + member[0].length;
2566
2771
  if (member[1] === "var") {
2567
2772
  const typed = /^\s*:\s*([^{\n]+?)\s*\{[^}]*\}/.exec(code.slice(after));
2568
2773
  if (!typed) continue;
2569
- const selector2 = explicit ?? name;
2774
+ const selector2 = explicit ?? name2;
2570
2775
  const typeMember2 = /\bstatic\b/.test(code.slice(start, at));
2571
2776
  members.push({
2572
- name,
2777
+ name: name2,
2573
2778
  labels: null,
2574
2779
  selector: selector2,
2575
2780
  start,
2576
2781
  end: after + typed[0].length,
2577
2782
  result: objcTypeName(typed[1]),
2578
2783
  typeMember: typeMember2,
2579
- helper: `${head} ${typeMember2 ? "static " : ""}var ${name}: ${optionalResult(typed[1])} { _objcOptionalSend(self, Selector(${JSON.stringify(selector2)}), [], default: nil) }`
2784
+ helper: `${head} ${typeMember2 ? "static " : ""}var ${name2}: ${optionalResult(typed[1])} { _objcOptionalSend(self, Selector(${JSON.stringify(selector2)}), [], default: nil) }`
2580
2785
  });
2581
2786
  continue;
2582
2787
  }
@@ -2588,10 +2793,10 @@ function objcOptionalProtocols(source) {
2588
2793
  const parameters = code.slice(paren + 1, shut);
2589
2794
  const names = parameterNames(parameters);
2590
2795
  const labels = names.map((parameter) => parameter.label);
2591
- const selector = explicit ?? objcSelectorName(name, labels, tail[1] !== void 0, tail[2] !== void 0);
2796
+ const selector = explicit ?? objcSelectorName(name2, labels, tail[1] !== void 0, tail[2] !== void 0);
2592
2797
  const typeMember = /\bstatic\b/.test(code.slice(start, at));
2593
2798
  members.push({
2594
- name,
2799
+ name: name2,
2595
2800
  labels,
2596
2801
  typeMember,
2597
2802
  selector,
@@ -2600,12 +2805,12 @@ function objcOptionalProtocols(source) {
2600
2805
  types: parameterTypes(parameters),
2601
2806
  result: objcTypeName(tail[3]?.trim() ?? "Void"),
2602
2807
  helper: typeMember && (tail[1] !== void 0 || tail[2] !== void 0) ? null : tail[1] !== void 0 ? objcAsyncOptionalHelper(
2603
- `${head} func ${name}(${parameters.replace(/\s*\n\s*/g, " ")})`,
2808
+ `${head} func ${name2}(${parameters.replace(/\s*\n\s*/g, " ")})`,
2604
2809
  parameters,
2605
2810
  selector,
2606
2811
  tail[3]?.trim() ?? "Void",
2607
2812
  tail[2] !== void 0
2608
- ) : tail[2] !== void 0 ? null : `@discardableResult ${head} ${typeMember ? "static " : ""}func ${name}(${parameters.replace(/\s*\n\s*/g, " ")}) -> ${optionalResult(tail[3]?.trim() ?? "Void")} { ${escapingSend(parameters, `_objcOptionalSend(self, Selector(${JSON.stringify(selector)}), [${names.map((parameter) => parameter.name).join(", ")}], default: nil)`)} }`
2813
+ ) : tail[2] !== void 0 ? null : `@discardableResult ${head} ${typeMember ? "static " : ""}func ${name2}(${parameters.replace(/\s*\n\s*/g, " ")}) -> ${optionalResult(tail[3]?.trim() ?? "Void")} { ${escapingSend(parameters, `_objcOptionalSend(self, Selector(${JSON.stringify(selector)}), [${names.map((parameter) => parameter.name).join(", ")}], default: nil)`)} }`
2609
2814
  });
2610
2815
  }
2611
2816
  if (members.length) found.push({ name: declared[1], close, members });
@@ -2622,8 +2827,8 @@ function escapingSend(parameters, send, effects = "") {
2622
2827
  if (!named || !type?.startsWith("(")) return body;
2623
2828
  const shut = closingParen(type, 0);
2624
2829
  if (!/^\s*(?:async\b\s*)?(?:throws\b\s*)?->/.test(type.slice(shut + 1))) return body;
2625
- const name = named[2] ?? named[1];
2626
- return `${effects}withoutActuallyEscaping(${name}) { ${name} in ${body} }`;
2830
+ const name2 = named[2] ?? named[1];
2831
+ return `${effects}withoutActuallyEscaping(${name2}) { ${name2} in ${body} }`;
2627
2832
  }, send);
2628
2833
  }
2629
2834
  function objcAsyncOptionalHelper(declaration, parameters, selector, result, throwing) {
@@ -4073,10 +4278,10 @@ function objcTypeMethods(source, found) {
4073
4278
  function objcIndex(sources) {
4074
4279
  const requirements = /* @__PURE__ */ new Map();
4075
4280
  const callable = /* @__PURE__ */ new Map();
4076
- const callableAs = (name, member, labels) => {
4077
- const known = callable.get(name);
4281
+ const callableAs = (name2, member, labels) => {
4282
+ const known = callable.get(name2);
4078
4283
  if (known) known.labels.push(labels);
4079
- else callable.set(name, { member, labels: [labels] });
4284
+ else callable.set(name2, { member, labels: [labels] });
4080
4285
  };
4081
4286
  const typeMethods = /* @__PURE__ */ new Map();
4082
4287
  const sdkParents = /* @__PURE__ */ new Map();
@@ -4094,9 +4299,9 @@ function objcIndex(sources) {
4094
4299
  requirements.set(
4095
4300
  protocol,
4096
4301
  sdk.requirements.map(([signature, selector, typed, asyncSignature]) => {
4097
- const name = signature.slice(0, signature.indexOf("("));
4098
- const labels = signature.slice(name.length + 1, -1).split(":").slice(0, -1);
4099
- if (sdk.callers) callableAs(name, `_objcOptional_${name}`, labels);
4302
+ const name2 = signature.slice(0, signature.indexOf("("));
4303
+ const labels = signature.slice(name2.length + 1, -1).split(":").slice(0, -1);
4304
+ if (sdk.callers) callableAs(name2, `_objcOptional_${name2}`, labels);
4100
4305
  const arrow = typed?.lastIndexOf("->") ?? -1;
4101
4306
  const types = typed?.slice(0, arrow);
4102
4307
  const result = typed?.slice(arrow + 2);
@@ -4107,7 +4312,7 @@ function objcIndex(sources) {
4107
4312
  const values = handler ? splitTopLevel(handler[1]) : [];
4108
4313
  const asyncName = asyncSignature?.slice(0, asyncSignature.indexOf("("));
4109
4314
  return {
4110
- name,
4315
+ name: name2,
4111
4316
  labels,
4112
4317
  selector,
4113
4318
  ...parameters !== void 0 && { types: parameters },
@@ -4133,8 +4338,8 @@ function objcIndex(sources) {
4133
4338
  for (const protocol of objcOptionalProtocols(source)) {
4134
4339
  requirements.set(
4135
4340
  protocol.name,
4136
- protocol.members.map(({ name, labels, selector, types, result, typeMember }) => ({
4137
- name,
4341
+ protocol.members.map(({ name: name2, labels, selector, types, result, typeMember }) => ({
4342
+ name: name2,
4138
4343
  labels,
4139
4344
  selector,
4140
4345
  ...typeMember && { typeMember },
@@ -4164,18 +4369,18 @@ function objcIndex(sources) {
4164
4369
  const code = swiftCodeMask(source);
4165
4370
  const braces = [...code.matchAll(/[{}]/g)].map((match) => match.index);
4166
4371
  for (const protocol of code.matchAll(/\bprotocol\s+([A-Za-z_]\w*)[^{}]*\{/g)) {
4167
- const name = protocol[1];
4168
- protocols.add(name);
4372
+ const name2 = protocol[1];
4373
+ protocols.add(name2);
4169
4374
  const open = protocol.index + protocol[0].length - 1;
4170
4375
  if (/\binit\s*[?!]?\s*\(/.test(code.slice(open + 1, closingBrace(code, braces, open))))
4171
- initializers.add(name);
4376
+ initializers.add(name2);
4172
4377
  }
4173
4378
  }
4174
4379
  const rooted = conformingTypes(parents, /* @__PURE__ */ new Set(["NSObject"]));
4175
4380
  const initialized = conformingTypes(parents, initializers);
4176
4381
  const nsObjectTypes = /* @__PURE__ */ new Set([
4177
4382
  "NSObject",
4178
- ...[...protocols].filter((name) => rooted.has(name) && !initialized.has(name))
4383
+ ...[...protocols].filter((name2) => rooted.has(name2) && !initialized.has(name2))
4179
4384
  ]);
4180
4385
  return {
4181
4386
  requirements,
@@ -4202,8 +4407,8 @@ function objcAliases(sources) {
4202
4407
  }
4203
4408
  }
4204
4409
  const aliases = /* @__PURE__ */ new Map();
4205
- for (const [name, type] of declared) if (type !== null) aliases.set(name, type);
4206
- for (const [name, type] of aliases) aliases.set(name, resolveAliases(type, aliases));
4410
+ for (const [name2, type] of declared) if (type !== null) aliases.set(name2, type);
4411
+ for (const [name2, type] of aliases) aliases.set(name2, resolveAliases(type, aliases));
4207
4412
  return aliases;
4208
4413
  }
4209
4414
  function resolveAliases(type, aliases) {
@@ -4211,7 +4416,7 @@ function resolveAliases(type, aliases) {
4211
4416
  for (let pass = 0; pass < 8 && aliases.size; pass++) {
4212
4417
  const next = resolved.replace(
4213
4418
  /(?<![\w.])[A-Za-z_]\w*(?![\w.])/g,
4214
- (name) => aliases.get(name) ?? name
4419
+ (name2) => aliases.get(name2) ?? name2
4215
4420
  );
4216
4421
  if (next === resolved) break;
4217
4422
  resolved = next;
@@ -4317,17 +4522,17 @@ function lowerObjCOptionalRequirements(source, index) {
4317
4522
  `; extension ${protocol.name} { ${helpers.join("; ")} }`
4318
4523
  ]);
4319
4524
  }
4320
- for (const name of code.matchAll(
4525
+ for (const name2 of code.matchAll(
4321
4526
  /#selector\(\s*([A-Za-z_]\w*)\.([A-Za-z_]\w*)\(((?:\s*\w+\s*:)+)\s*\)\s*\)/g
4322
4527
  )) {
4323
- const signature = `${name[2]}(${name[3].replace(/\s+/g, "")})`;
4324
- const found = SDK_OBJC_OPTIONAL[name[1]]?.requirements.filter(
4528
+ const signature = `${name2[2]}(${name2[3].replace(/\s+/g, "")})`;
4529
+ const found = SDK_OBJC_OPTIONAL[name2[1]]?.requirements.filter(
4325
4530
  ([requirement]) => requirement === signature
4326
4531
  );
4327
4532
  if (found?.length === 1)
4328
4533
  edits.push([
4329
- name.index,
4330
- name[0].length,
4534
+ name2.index,
4535
+ name2[0].length,
4331
4536
  `NSSelectorFromString(${JSON.stringify(found[0][1])})`
4332
4537
  ]);
4333
4538
  }
@@ -4335,7 +4540,7 @@ function lowerObjCOptionalRequirements(source, index) {
4335
4540
  const receivesAsProtocol = (dot) => {
4336
4541
  const receiver = /([A-Za-z_]\w*)\s*[?!]?\s*$/.exec(code.slice(0, dot))?.[1];
4337
4542
  if (!receiver) return false;
4338
- const name = /^\.\s*([A-Za-z_]\w*)/.exec(code.slice(dot))?.[1];
4543
+ const name2 = /^\.\s*([A-Za-z_]\w*)/.exec(code.slice(dot))?.[1];
4339
4544
  let innermost;
4340
4545
  for (const declared of code.matchAll(
4341
4546
  new RegExp(
@@ -4348,7 +4553,7 @@ function lowerObjCOptionalRequirements(source, index) {
4348
4553
  if (dot > from && dot < to && (!innermost || from >= innermost.from))
4349
4554
  innermost = { from, type: declared[1] };
4350
4555
  }
4351
- return innermost?.type !== void 0 && !!index.requirements.get(resolveAliases(innermost.type, index.aliases))?.some((wanted) => wanted.name === name);
4556
+ return innermost?.type !== void 0 && !!index.requirements.get(resolveAliases(innermost.type, index.aliases))?.some((wanted) => wanted.name === name2);
4352
4557
  };
4353
4558
  for (const call of code.matchAll(/\.\s*([A-Za-z_]\w*)\s*\?(?=\s*[({])/g)) {
4354
4559
  const callable = index.callable.get(call[1]);
@@ -4365,8 +4570,8 @@ function lowerObjCOptionalRequirements(source, index) {
4365
4570
  continue;
4366
4571
  if (callable.member === call[1]) edits.push([mark, 1, " "]);
4367
4572
  else {
4368
- const name = call.index + call[0].indexOf(call[1]);
4369
- edits.push([name, mark + 1 - name, callable.member]);
4573
+ const name2 = call.index + call[0].indexOf(call[1]);
4574
+ edits.push([name2, mark + 1 - name2, callable.member]);
4370
4575
  }
4371
4576
  }
4372
4577
  for (const owner of code.matchAll(
@@ -4465,8 +4670,8 @@ function lowerObjCRuntimeCalls(source, index) {
4465
4670
  for (const declared of code.matchAll(
4466
4671
  /(?:\b(?:let|var)\s+|[(,]\s*(?:[A-Za-z_]\w*\s+)?)([A-Za-z_]\w*)\s*:\s*(?:(?:any\s+)?([A-Z]\w*(?:\.\w+)*)\s*([?!])?|[[(])|\b(?:let|var|for)\s+([A-Za-z_]\w*)\b(?!\s*:)|[{,]\s*([A-Za-z_]\w*)\s+in\b/g
4467
4672
  )) {
4468
- const name = declared[1] ?? declared[4] ?? declared[5];
4469
- const list = declarations.get(name) ?? [];
4673
+ const name2 = declared[1] ?? declared[4] ?? declared[5];
4674
+ const list = declarations.get(name2) ?? [];
4470
4675
  let type = declared[3] ? "" : declared[2] ?? "";
4471
4676
  if (!type && declared[4]) {
4472
4677
  const lookup = /^\s*=\s*NSClassFromString\s*\(/.exec(
@@ -4481,7 +4686,7 @@ function lowerObjCRuntimeCalls(source, index) {
4481
4686
  }
4482
4687
  const resolved = type.endsWith(".Type") ? `${resolveAliases(type.slice(0, -5), index.aliases)}.Type` : resolveAliases(type, index.aliases);
4483
4688
  list.push({ at: declared.index, type: resolved });
4484
- declarations.set(name, list);
4689
+ declarations.set(name2, list);
4485
4690
  }
4486
4691
  for (const pattern of code.matchAll(/\b(?:let|var|for)\s*(?=\(|\.\s*\w+\s*\()/g)) {
4487
4692
  const open = code.indexOf("(", pattern.index + pattern[0].length);
@@ -4494,9 +4699,9 @@ function lowerObjCRuntimeCalls(source, index) {
4494
4699
  }
4495
4700
  for (const list of declarations.values()) list.sort((a, b) => a.at - b.at);
4496
4701
  const braces = [...code.matchAll(/[{}]/g)].map((match) => match.index);
4497
- const receiverType = (name, at) => {
4702
+ const receiverType = (name2, at) => {
4498
4703
  let innermost;
4499
- for (const declared of declarations.get(name) ?? []) {
4704
+ for (const declared of declarations.get(name2) ?? []) {
4500
4705
  if (declared.at > at) break;
4501
4706
  const [from, to] = declarationScope(code, braces, declared.at);
4502
4707
  if (at > from && at < to && (!innermost || from >= innermost.from))
@@ -5335,7 +5540,7 @@ var CORE_FOUNDATION_HANDLE_IMPORTS = [
5335
5540
  "CFSet",
5336
5541
  "CFString",
5337
5542
  "CFURL"
5338
- ].map((name) => `import class CoreFoundation.${name}`).concat([
5543
+ ].map((name2) => `import class CoreFoundation.${name2}`).concat([
5339
5544
  "import typealias CoreFoundation.CFPropertyList",
5340
5545
  "import typealias CoreFoundation.CFTypeRef",
5341
5546
  "import CoreGraphics"
@@ -5529,11 +5734,11 @@ function swiftSourceClosure(files, roots) {
5529
5734
  continue;
5530
5735
  }
5531
5736
  if (depth !== 0 || !match[2]) continue;
5532
- const name = match[2].split(".").pop();
5737
+ const name2 = match[2].split(".").pop();
5533
5738
  const index = match[1] === "extension" ? extensions : owners;
5534
- const set = index.get(name) ?? /* @__PURE__ */ new Set();
5739
+ const set = index.get(name2) ?? /* @__PURE__ */ new Set();
5535
5740
  set.add(file);
5536
- index.set(name, set);
5741
+ index.set(name2, set);
5537
5742
  }
5538
5743
  sources.set(file, references);
5539
5744
  }
@@ -5541,10 +5746,10 @@ function swiftSourceClosure(files, roots) {
5541
5746
  const pending = [...roots];
5542
5747
  const seen = /* @__PURE__ */ new Set();
5543
5748
  while (pending.length) {
5544
- const name = pending.pop();
5545
- if (seen.has(name)) continue;
5546
- seen.add(name);
5547
- for (const file of [...owners.get(name) ?? [], ...extensions.get(name) ?? []]) {
5749
+ const name2 = pending.pop();
5750
+ if (seen.has(name2)) continue;
5751
+ seen.add(name2);
5752
+ for (const file of [...owners.get(name2) ?? [], ...extensions.get(name2) ?? []]) {
5548
5753
  if (included.has(file)) continue;
5549
5754
  included.add(file);
5550
5755
  for (const reference of sources.get(file)) pending.push(reference);
@@ -5560,7 +5765,7 @@ function swiftApplicationEntry(file, source) {
5560
5765
  else if (source[at] === "}") depth--;
5561
5766
  else if (depth === 0 && /^@(?:main|UIApplicationMain)\b/.test(source.slice(at)))
5562
5767
  return true;
5563
- else if (depth === 0 && path5.basename(file) === "main.swift" && /^UIApplicationMain\s*\(/.test(source.slice(at)))
5768
+ else if (depth === 0 && path6.basename(file) === "main.swift" && /^UIApplicationMain\s*\(/.test(source.slice(at)))
5564
5769
  return true;
5565
5770
  }
5566
5771
  return false;
@@ -5660,32 +5865,32 @@ function swiftCodeScan(source) {
5660
5865
  return { lineStarts: starts, tokens };
5661
5866
  }
5662
5867
  function prepareSwiftDependency(source, destination) {
5663
- rmSync2(destination, { recursive: true, force: true });
5868
+ rmSync3(destination, { recursive: true, force: true });
5664
5869
  const origins = {};
5665
5870
  const gather = (from) => {
5666
- for (const entry of readdirSync2(from, { withFileTypes: true })) {
5871
+ for (const entry of readdirSync3(from, { withFileTypes: true })) {
5667
5872
  if (entry.name === ".git" || entry.name === ".build" || entry.name === ".swiftpm")
5668
5873
  continue;
5669
- const file = path5.join(from, entry.name);
5874
+ const file = path6.join(from, entry.name);
5670
5875
  if (entry.isDirectory()) gather(file);
5671
5876
  else if (entry.isFile() && entry.name.endsWith(".swift"))
5672
- origins[path5.relative(source, file)] = readFileSync4(file, "utf8");
5877
+ origins[path6.relative(source, file)] = readFileSync5(file, "utf8");
5673
5878
  }
5674
5879
  };
5675
5880
  gather(source);
5676
- const manifest = path5.join(source, "Package.swift");
5677
- const targets = existsSync2(manifest) ? swiftManifestTargets(readFileSync4(manifest, "utf8")) : [];
5881
+ const manifest = path6.join(source, "Package.swift");
5882
+ const targets = existsSync2(manifest) ? swiftManifestTargets(readFileSync5(manifest, "utf8")) : [];
5678
5883
  const compiled = compiledSwiftSources(origins, targets);
5679
5884
  const copy = (from, to) => {
5680
- mkdirSync(to, { recursive: true });
5681
- for (const entry of readdirSync2(from, { withFileTypes: true })) {
5885
+ mkdirSync2(to, { recursive: true });
5886
+ for (const entry of readdirSync3(from, { withFileTypes: true })) {
5682
5887
  if (entry.name === ".git" || entry.name === ".build" || entry.name === ".swiftpm")
5683
5888
  continue;
5684
- const file = path5.join(from, entry.name);
5685
- const target = path5.join(to, entry.name);
5889
+ const file = path6.join(from, entry.name);
5890
+ const target = path6.join(to, entry.name);
5686
5891
  if (entry.isDirectory()) copy(file, target);
5687
5892
  else if (entry.isFile() && entry.name.endsWith(".swift"))
5688
- writeFileSync2(target, compiled.get(path5.relative(source, file)));
5893
+ writeFileSync3(target, compiled.get(path6.relative(source, file)));
5689
5894
  else cpSync(file, target, { verbatimSymlinks: true });
5690
5895
  }
5691
5896
  };
@@ -5702,7 +5907,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
5702
5907
  const targets = distribution && compileTargets(input).length === 0 ? [
5703
5908
  {
5704
5909
  name: "App",
5705
- path: path5.relative(layout.root, layout.sources),
5910
+ path: path6.relative(layout.root, layout.sources),
5706
5911
  executable: true,
5707
5912
  languageMode: 5,
5708
5913
  mainActorIsolation: false,
@@ -5711,7 +5916,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
5711
5916
  ] : compileTargets(input);
5712
5917
  const files = /* @__PURE__ */ new Map();
5713
5918
  const native = /* @__PURE__ */ new Map();
5714
- const headerDirectory = path5.join(layout.root, ".build", "peach-cxx-headers");
5919
+ const headerDirectory = path6.join(layout.root, ".build", "peach-cxx-headers");
5715
5920
  for (const target of targets) {
5716
5921
  const prefix = target.path === "." ? "" : `${target.path}/`;
5717
5922
  const entries = Object.entries(input.files).filter(
@@ -5734,7 +5939,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
5734
5939
  if (producer && targets.some((value) => value.name === producer))
5735
5940
  producers.add(producer);
5736
5941
  const local = [
5737
- path5.posix.join(path5.posix.dirname(file), include),
5942
+ path6.posix.join(path6.posix.dirname(file), include),
5738
5943
  `${includes}${include}`
5739
5944
  ].find((candidate) => input.files[candidate] !== void 0);
5740
5945
  if (local) {
@@ -5756,7 +5961,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
5756
5961
  const late = units.filter(([file]) => consumers.get(file).size > 0);
5757
5962
  native.set(target.name, {
5758
5963
  path: target.path,
5759
- includeDirectory: path5.join(layout.root, includes),
5964
+ includeDirectory: path6.join(layout.root, includes),
5760
5965
  lateSources: late.map(([file]) => file.slice(prefix.length)),
5761
5966
  ...late.length > 0 ? {
5762
5967
  late: {
@@ -5773,7 +5978,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
5773
5978
  ([file]) => file.startsWith(includes) && /\.(?:h|hpp|hh|hxx)$/.test(file) && consumers.get(file).size === 0
5774
5979
  );
5775
5980
  files.set(
5776
- path5.join(layout.root, includes, "module.modulemap"),
5981
+ path6.join(layout.root, includes, "module.modulemap"),
5777
5982
  [
5778
5983
  `module ${target.name} {`,
5779
5984
  ...roots.map(
@@ -5785,14 +5990,14 @@ function writeSwiftProject(layout, input, moduleRoot) {
5785
5990
  ].join("\n")
5786
5991
  );
5787
5992
  }
5788
- if (native.size > 0) mkdirSync(headerDirectory, { recursive: true });
5789
- const modulePlan = createHash4("sha256").update(
5993
+ if (native.size > 0) mkdirSync2(headerDirectory, { recursive: true });
5994
+ const modulePlan = createHash5("sha256").update(
5790
5995
  swiftModuleInputFiles(moduleRoot).join("\n")
5791
5996
  );
5792
5997
  if (!distribution) {
5793
- modulePlan.update(readFileSync4(path5.join(moduleRoot, "Package.swift")));
5998
+ modulePlan.update(readFileSync5(path6.join(moduleRoot, "Package.swift")));
5794
5999
  }
5795
- const resourcePlan = createHash4("sha256").update(
6000
+ const resourcePlan = createHash5("sha256").update(
5796
6001
  JSON.stringify(
5797
6002
  resourceTargets.filter((target) => target.resources).map((target) => [
5798
6003
  target.name,
@@ -5817,10 +6022,10 @@ function writeSwiftProject(layout, input, moduleRoot) {
5817
6022
  if (targets.length === 0) {
5818
6023
  for (const [file, contents] of Object.entries(input.files)) {
5819
6024
  if (file === "Package.swift") continue;
5820
- files.set(path5.join(layout.sources, file), compiled.get(file) ?? contents);
6025
+ files.set(path6.join(layout.sources, file), compiled.get(file) ?? contents);
5821
6026
  }
5822
- let manifest = readFileSync4(
5823
- path5.join(moduleRoot, "scripts/contrast-app-Package.swift"),
6027
+ let manifest = readFileSync5(
6028
+ path6.join(moduleRoot, "scripts/contrast-app-Package.swift"),
5824
6029
  "utf8"
5825
6030
  ).replaceAll("__SOOTSIM_SWIFT_PACKAGE__", moduleRoot);
5826
6031
  const reactor = ` ${REACTOR_FLAG}`;
@@ -5839,7 +6044,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
5839
6044
  [
5840
6045
  product,
5841
6046
  ...optionalProducts.map(
5842
- (name) => `.product(name: "${name}", package: "sootsim-swift"),`
6047
+ (name2) => `.product(name: "${name2}", package: "sootsim-swift"),`
5843
6048
  )
5844
6049
  ].join("\n ")
5845
6050
  );
@@ -5864,21 +6069,21 @@ function writeSwiftProject(layout, input, moduleRoot) {
5864
6069
  manifest = manifest.replace(anchor, `${anchor}
5865
6070
  ${SPRITEKIT_PRODUCT},`);
5866
6071
  }
5867
- files.set(path5.join(layout.root, "Package.swift"), manifest + moduleFiles);
6072
+ files.set(path6.join(layout.root, "Package.swift"), manifest + moduleFiles);
5868
6073
  } else {
5869
6074
  const base = layout.multi ? layout.root : layout.sources;
5870
6075
  const libraries = /* @__PURE__ */ new Map();
5871
6076
  for (const [target, data] of Object.entries(input.libraries ?? {})) {
5872
- const file = path5.join(layout.root, ".peach-libraries", `lib${target}.a`);
6077
+ const file = path6.join(layout.root, ".peach-libraries", `lib${target}.a`);
5873
6078
  files.set(file, Buffer.from(data, "base64"));
5874
6079
  libraries.set(target, file);
5875
6080
  }
5876
6081
  for (const [file, contents] of Object.entries(input.files)) {
5877
6082
  if (file === "Package.swift") continue;
5878
- files.set(path5.join(base, file), compiled.get(file) ?? contents);
6083
+ files.set(path6.join(base, file), compiled.get(file) ?? contents);
5879
6084
  }
5880
6085
  files.set(
5881
- path5.join(layout.root, "Package.swift"),
6086
+ path6.join(layout.root, "Package.swift"),
5882
6087
  emitSwiftPackageManifest({
5883
6088
  targets,
5884
6089
  native,
@@ -5895,7 +6100,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
5895
6100
  spriteKit: importsSpriteKit(input.files),
5896
6101
  distribution: distribution ?? void 0,
5897
6102
  distributionLink: {
5898
- path: path5.join(layout.root, ".peach-distribution-objects.rsp"),
6103
+ path: path6.join(layout.root, ".peach-distribution-objects.rsp"),
5899
6104
  files
5900
6105
  },
5901
6106
  libraries
@@ -5911,9 +6116,9 @@ function writeSwiftProject(layout, input, moduleRoot) {
5911
6116
  throw new Error(
5912
6117
  `swift resource target ${target.name} has no matching bundle assignment`
5913
6118
  );
5914
- const directory = layout.multi ? path5.join(layout.root, target.path) : layout.sources;
6119
+ const directory = layout.multi ? path6.join(layout.root, target.path) : layout.sources;
5915
6120
  files.set(
5916
- path5.join(directory, "ResourceBundleAccessor.generated.swift"),
6121
+ path6.join(directory, "ResourceBundleAccessor.generated.swift"),
5917
6122
  [
5918
6123
  "import Foundation",
5919
6124
  "",
@@ -5946,15 +6151,15 @@ function outputOf(error) {
5946
6151
  return error instanceof Error ? error.message : String(error);
5947
6152
  }
5948
6153
  function builtArtifact(layout) {
5949
- const binDir = path5.join(layout.root, ".build", WASM_TRIPLE, "release");
5950
- const manifest = readFileSync4(path5.join(layout.root, "Package.swift"), "utf8");
6154
+ const binDir = path6.join(layout.root, ".build", WASM_TRIPLE, "release");
6155
+ const manifest = readFileSync5(path6.join(layout.root, "Package.swift"), "utf8");
5951
6156
  const executable = swiftManifestTargets(manifest).find((target) => target.executable);
5952
6157
  if (executable === void 0) {
5953
6158
  throw new Error("swift-compile: the written manifest names no executable target");
5954
6159
  }
5955
- const file = path5.join(binDir, `${executable.name}.wasm`);
6160
+ const file = path6.join(binDir, `${executable.name}.wasm`);
5956
6161
  if (!existsSync2(file)) {
5957
- const found = existsSync2(binDir) ? readdirSync2(binDir).filter((name) => name.endsWith(".wasm")).sort() : [];
6162
+ const found = existsSync2(binDir) ? readdirSync3(binDir).filter((name2) => name2.endsWith(".wasm")).sort() : [];
5958
6163
  throw new Error(
5959
6164
  `swift-compile: the build produced no ${executable.name}.wasm (found: ${found.join(", ") || "none"})`
5960
6165
  );
@@ -5963,7 +6168,7 @@ function builtArtifact(layout) {
5963
6168
  }
5964
6169
  function projectDiagnostic(output, layout, files) {
5965
6170
  const base = layout.multi ? layout.root : layout.sources;
5966
- const prefix = `${base}${path5.sep}`;
6171
+ const prefix = `${base}${path6.sep}`;
5967
6172
  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();
5968
6173
  }
5969
6174
  var ROOT_LOCKS = Symbol.for("peachsim.swiftCompile.rootLocks");
@@ -5999,13 +6204,13 @@ function serialize(root, work, signal) {
5999
6204
  function readCompiledArtifact(directory, hash) {
6000
6205
  try {
6001
6206
  const receipt = JSON.parse(
6002
- readFileSync4(path5.join(directory, "artifact.json"), "utf8")
6207
+ readFileSync5(path6.join(directory, "artifact.json"), "utf8")
6003
6208
  );
6004
6209
  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")
6005
6210
  return null;
6006
- const bytes = readFileSync4(path5.join(directory, "app.wasm"));
6007
- const gzip2 = readFileSync4(path5.join(directory, "icu.gz"));
6008
- if (createHash4("sha256").update(bytes).digest("hex") !== receipt.wasm || createHash4("sha256").update(gzip2).digest("hex") !== receipt.icu || bytes.length < 8 || bytes.readUInt32LE(0) !== 1836278016 || bytes.readUInt32LE(4) !== 1)
6211
+ const bytes = readFileSync5(path6.join(directory, "app.wasm"));
6212
+ const gzip2 = readFileSync5(path6.join(directory, "icu.gz"));
6213
+ if (createHash5("sha256").update(bytes).digest("hex") !== receipt.wasm || createHash5("sha256").update(gzip2).digest("hex") !== receipt.icu || bytes.length < 8 || bytes.readUInt32LE(0) !== 1836278016 || bytes.readUInt32LE(4) !== 1)
6009
6214
  return null;
6010
6215
  return { hash, bytes, icu: { sha256: receipt.icu, gzip: gzip2 } };
6011
6216
  } catch (error) {
@@ -6015,25 +6220,25 @@ function readCompiledArtifact(directory, hash) {
6015
6220
  }
6016
6221
  }
6017
6222
  function saveCompiledArtifact(root, artifact) {
6018
- const directory = path5.join(root, "artifact");
6019
- mkdirSync(directory, { recursive: true });
6020
- const pending = mkdtempSync2(path5.join(root, ".artifact-"));
6223
+ const directory = path6.join(root, "artifact");
6224
+ mkdirSync2(directory, { recursive: true });
6225
+ const pending = mkdtempSync2(path6.join(root, ".artifact-"));
6021
6226
  try {
6022
- writeFileSync2(path5.join(pending, "app.wasm"), artifact.bytes);
6023
- writeFileSync2(path5.join(pending, "icu.gz"), artifact.icu.gzip);
6024
- writeFileSync2(
6025
- path5.join(pending, "artifact.json"),
6227
+ writeFileSync3(path6.join(pending, "app.wasm"), artifact.bytes);
6228
+ writeFileSync3(path6.join(pending, "icu.gz"), artifact.icu.gzip);
6229
+ writeFileSync3(
6230
+ path6.join(pending, "artifact.json"),
6026
6231
  JSON.stringify({
6027
6232
  hash: artifact.hash,
6028
- wasm: createHash4("sha256").update(artifact.bytes).digest("hex"),
6233
+ wasm: createHash5("sha256").update(artifact.bytes).digest("hex"),
6029
6234
  icu: artifact.icu.sha256
6030
6235
  })
6031
6236
  );
6032
6237
  for (const file of ["app.wasm", "icu.gz", "artifact.json"]) {
6033
- renameSync(path5.join(pending, file), path5.join(directory, file));
6238
+ renameSync(path6.join(pending, file), path6.join(directory, file));
6034
6239
  }
6035
6240
  } finally {
6036
- rmSync2(pending, { recursive: true, force: true });
6241
+ rmSync3(pending, { recursive: true, force: true });
6037
6242
  }
6038
6243
  }
6039
6244
  var retainedArtifacts = /* @__PURE__ */ new Map();
@@ -6049,17 +6254,20 @@ function retain(root, artifact) {
6049
6254
  }
6050
6255
  function compileSwiftProjectUnit(input, options) {
6051
6256
  options.signal?.throwIfAborted();
6052
- mkdirSync(options.buildRoot, { recursive: true });
6257
+ mkdirSync2(options.buildRoot, { recursive: true });
6053
6258
  const root = realpathSync(options.buildRoot);
6054
- const moduleRoot = path5.resolve(options.moduleRoot);
6259
+ const moduleRoot = path6.resolve(options.moduleRoot);
6055
6260
  const layout = {
6056
6261
  root,
6057
- sources: path5.join(root, "Sources", "App"),
6262
+ sources: path6.join(root, "Sources", "App"),
6058
6263
  multi: compileTargets(input).length > 0
6059
6264
  };
6060
6265
  const hash = swiftArtifactHash(input, options.release, moduleRoot);
6061
- const sharedRoot = path5.join(rnxHomeDir(), "cache", "swift-projects", hash);
6062
- const report = (message) => console.error(`[swift-project ${hash.slice(0, 16)}] ${message}`);
6266
+ const sharedRoot = path6.join(rnxHomeDir(), "cache", "swift-projects", hash);
6267
+ const report = (message) => {
6268
+ console.error(`[swift-project ${hash.slice(0, 16)}] ${message}`);
6269
+ options.onStage?.(message);
6270
+ };
6063
6271
  report("checking verified artifacts");
6064
6272
  return serialize(
6065
6273
  root,
@@ -6069,18 +6277,18 @@ function compileSwiftProjectUnit(input, options) {
6069
6277
  report("reusing memory artifact");
6070
6278
  return retain(root, retained);
6071
6279
  }
6072
- const cached = readCompiledArtifact(path5.join(sharedRoot, "artifact"), hash);
6073
- const previous = cached ?? readCompiledArtifact(path5.join(root, "artifact"), hash);
6280
+ const cached = readCompiledArtifact(path6.join(sharedRoot, "artifact"), hash);
6281
+ const previous = cached ?? readCompiledArtifact(path6.join(root, "artifact"), hash);
6074
6282
  if (previous) {
6075
6283
  if (!cached) saveCompiledArtifact(sharedRoot, previous);
6076
6284
  report("reusing verified disk artifact");
6077
6285
  return retain(root, previous);
6078
6286
  }
6079
- if (process.platform === "darwin" && process.env.TM_SESSION && !admittedMacBuilderSlot() && process.env.CI !== "true" && moduleRoot === path5.resolve(import.meta.dirname, "../../sootsim-swift") && !swiftDistributionAt(moduleRoot)) {
6080
- const requestRoot = mkdtempSync2(path5.join(root, ".builder-request-"));
6081
- const output = path5.join(requestRoot, "output");
6082
- const request = path5.join(requestRoot, "request.json");
6083
- writeFileSync2(
6287
+ if (process.platform === "darwin" && process.env.TM_SESSION && !admittedMacBuilderSlot() && process.env.CI !== "true" && moduleRoot === path6.resolve(import.meta.dirname, "../../sootsim-swift") && !swiftDistributionAt(moduleRoot)) {
6288
+ const requestRoot = mkdtempSync2(path6.join(root, ".builder-request-"));
6289
+ const output = path6.join(requestRoot, "output");
6290
+ const request = path6.join(requestRoot, "request.json");
6291
+ writeFileSync3(
6084
6292
  request,
6085
6293
  JSON.stringify({
6086
6294
  input,
@@ -6093,12 +6301,12 @@ function compileSwiftProjectUnit(input, options) {
6093
6301
  })
6094
6302
  );
6095
6303
  try {
6096
- const repo = path5.resolve(moduleRoot, "../..");
6304
+ const repo = path6.resolve(moduleRoot, "../..");
6097
6305
  report("requesting builder admission or cached result");
6098
6306
  await runCompiler(
6099
6307
  "bun",
6100
6308
  [
6101
- path5.join(repo, "scripts/build/swift-project.ts"),
6309
+ path6.join(repo, "scripts/build/swift-project.ts"),
6102
6310
  "--request",
6103
6311
  request,
6104
6312
  "--output",
@@ -6115,93 +6323,89 @@ function compileSwiftProjectUnit(input, options) {
6115
6323
  if (options.signal?.aborted) throw error;
6116
6324
  throw new Error(outputOf(error), { cause: error });
6117
6325
  });
6118
- const artifact2 = readCompiledArtifact(output, hash);
6119
- if (!artifact2) {
6326
+ const artifact = readCompiledArtifact(output, hash);
6327
+ if (!artifact) {
6120
6328
  throw new Error(
6121
6329
  "swift-compile: builder artifact source, digest or wasm header is invalid"
6122
6330
  );
6123
6331
  }
6124
- saveCompiledArtifact(root, artifact2);
6125
- saveCompiledArtifact(sharedRoot, artifact2);
6332
+ saveCompiledArtifact(root, artifact);
6333
+ saveCompiledArtifact(sharedRoot, artifact);
6126
6334
  report("builder artifact verified");
6127
- return retain(root, artifact2);
6335
+ return retain(root, artifact);
6128
6336
  } finally {
6129
- rmSync2(requestRoot, { recursive: true, force: true });
6337
+ rmSync3(requestRoot, { recursive: true, force: true });
6130
6338
  }
6131
6339
  }
6132
- writeSwiftProject(layout, input, moduleRoot);
6133
- const swift = path5.join(options.toolchainBin, "swift");
6134
- if (!existsSync2(swift)) {
6135
- throw new Error(
6136
- `swift-compile: no swift.org toolchain at ${options.toolchainBin}; install ${options.release} and its matching wasm sdk`
6137
- );
6138
- }
6139
- report("preparing compiler plugins");
6140
- const macroPlugins = await ensureMacroPlugins(
6141
- moduleRoot,
6142
- options.toolchainBin,
6143
- options.release,
6144
- options.signal
6145
- );
6146
- const sdk = swiftModuleSdk(moduleRoot).wasmSdkId;
6147
- const icu = swiftIcuAsset(options.toolchainBin, sdk);
6148
- const buildArgs = [
6149
- "build",
6150
- ...swiftPackageCacheOptions(),
6151
- "--build-system",
6152
- "native",
6153
- "-j",
6154
- BUILD_JOBS,
6155
- "--package-path",
6340
+ return withSwiftRootLock(
6156
6341
  root,
6157
- ...swiftSdkOptions(),
6158
- "--swift-sdk",
6159
- sdk,
6160
- "-c",
6161
- "release",
6162
- "-Xswiftc",
6163
- "-Osize",
6164
- "-Xswiftc",
6165
- "-num-threads",
6166
- "-Xswiftc",
6167
- BUILD_JOBS,
6168
- ...macroPlugins.flatMap((plugin) => [
6169
- "-Xswiftc",
6170
- "-load-plugin-library",
6171
- "-Xswiftc",
6172
- plugin
6173
- ])
6174
- ];
6175
- const buildOptions = {
6176
- env: {
6177
- ...process.env,
6178
- // shipped host plugins resolve against the selected compiler's runtime.
6179
- ...process.platform === "linux" ? {
6180
- LD_LIBRARY_PATH: [
6181
- path5.resolve(options.toolchainBin, "../lib/swift/linux"),
6182
- path5.resolve(options.toolchainBin, "../lib/swift/host"),
6183
- process.env.LD_LIBRARY_PATH
6184
- ].filter(Boolean).join(":")
6185
- } : {}
6186
- },
6187
- maxBuffer: 64 * 1024 * 1024,
6188
- timeout: options.timeoutMs,
6189
- signal: options.signal
6190
- };
6191
- report("compiling and linking Swift modules");
6192
- try {
6193
- await runCompiler(swift, buildArgs, buildOptions, SWIFTPM_PROGRESS, SWIFTPM_NOISE);
6194
- } catch (error) {
6195
- const output = outputOf(error);
6196
- const moduleCache = path5.join(
6197
- root,
6198
- ".build",
6199
- WASM_TRIPLE,
6200
- "release",
6201
- "ModuleCache"
6202
- );
6203
- if (output.includes("was compiled with module cache path") && existsSync2(moduleCache)) {
6204
- rmSync2(moduleCache, { recursive: true, force: true });
6342
+ async (lease) => {
6343
+ const built = readCompiledArtifact(path6.join(sharedRoot, "artifact"), hash);
6344
+ if (built) {
6345
+ report("reusing verified disk artifact");
6346
+ return retain(root, built);
6347
+ }
6348
+ writeSwiftProject(layout, input, moduleRoot);
6349
+ const swift = path6.join(options.toolchainBin, "swift");
6350
+ if (!existsSync2(swift)) {
6351
+ throw new Error(
6352
+ `swift-compile: no swift.org toolchain at ${options.toolchainBin}; install ${options.release} and its matching wasm sdk`
6353
+ );
6354
+ }
6355
+ report("preparing compiler plugins");
6356
+ const macroPlugins = await ensureMacroPlugins(
6357
+ moduleRoot,
6358
+ options.toolchainBin,
6359
+ options.release,
6360
+ options.signal
6361
+ );
6362
+ const sdk = swiftModuleSdk(moduleRoot).wasmSdkId;
6363
+ const icu = swiftIcuAsset(options.toolchainBin, sdk);
6364
+ const buildArgs = [
6365
+ "build",
6366
+ ...swiftPackageCacheOptions(),
6367
+ "--build-system",
6368
+ "native",
6369
+ "-j",
6370
+ BUILD_JOBS,
6371
+ "--package-path",
6372
+ root,
6373
+ ...swiftSdkOptions(),
6374
+ "--swift-sdk",
6375
+ sdk,
6376
+ "-c",
6377
+ "release",
6378
+ "-Xswiftc",
6379
+ "-Osize",
6380
+ "-Xswiftc",
6381
+ "-num-threads",
6382
+ "-Xswiftc",
6383
+ BUILD_JOBS,
6384
+ ...macroPlugins.flatMap((plugin) => [
6385
+ "-Xswiftc",
6386
+ "-load-plugin-library",
6387
+ "-Xswiftc",
6388
+ plugin
6389
+ ])
6390
+ ];
6391
+ const buildOptions = {
6392
+ env: {
6393
+ ...process.env,
6394
+ // shipped host plugins resolve against the selected compiler's runtime.
6395
+ ...process.platform === "linux" ? {
6396
+ LD_LIBRARY_PATH: [
6397
+ path6.resolve(options.toolchainBin, "../lib/swift/linux"),
6398
+ path6.resolve(options.toolchainBin, "../lib/swift/host"),
6399
+ process.env.LD_LIBRARY_PATH
6400
+ ].filter(Boolean).join(":")
6401
+ } : {}
6402
+ },
6403
+ maxBuffer: 64 * 1024 * 1024,
6404
+ timeout: options.timeoutMs,
6405
+ signal: options.signal,
6406
+ lease
6407
+ };
6408
+ report("compiling and linking Swift modules");
6205
6409
  try {
6206
6410
  await runCompiler(
6207
6411
  swift,
@@ -6210,29 +6414,51 @@ function compileSwiftProjectUnit(input, options) {
6210
6414
  SWIFTPM_PROGRESS,
6211
6415
  SWIFTPM_NOISE
6212
6416
  );
6213
- } catch (retryError) {
6214
- throw new Error(
6215
- projectDiagnostic(outputOf(retryError), layout, input.files),
6216
- {
6217
- cause: retryError
6218
- }
6417
+ } catch (error) {
6418
+ const output = outputOf(error);
6419
+ const moduleCache = path6.join(
6420
+ root,
6421
+ ".build",
6422
+ WASM_TRIPLE,
6423
+ "release",
6424
+ "ModuleCache"
6219
6425
  );
6426
+ if (output.includes("was compiled with module cache path") && existsSync2(moduleCache)) {
6427
+ rmSync3(moduleCache, { recursive: true, force: true });
6428
+ try {
6429
+ await runCompiler(
6430
+ swift,
6431
+ buildArgs,
6432
+ buildOptions,
6433
+ SWIFTPM_PROGRESS,
6434
+ SWIFTPM_NOISE
6435
+ );
6436
+ } catch (retryError) {
6437
+ throw new Error(
6438
+ projectDiagnostic(outputOf(retryError), layout, input.files),
6439
+ {
6440
+ cause: retryError
6441
+ }
6442
+ );
6443
+ }
6444
+ } else {
6445
+ throw new Error(projectDiagnostic(output, layout, input.files), {
6446
+ cause: error
6447
+ });
6448
+ }
6220
6449
  }
6221
- } else {
6222
- throw new Error(projectDiagnostic(output, layout, input.files), {
6223
- cause: error
6224
- });
6225
- }
6226
- }
6227
- const artifact = {
6228
- hash,
6229
- bytes: readFileSync4(builtArtifact(layout)),
6230
- icu: await icu
6231
- };
6232
- saveCompiledArtifact(root, artifact);
6233
- saveCompiledArtifact(sharedRoot, artifact);
6234
- report("compiled artifact verified");
6235
- return retain(root, artifact);
6450
+ const artifact = {
6451
+ hash,
6452
+ bytes: readFileSync5(builtArtifact(layout)),
6453
+ icu: await icu
6454
+ };
6455
+ saveCompiledArtifact(root, artifact);
6456
+ saveCompiledArtifact(sharedRoot, artifact);
6457
+ report("compiled artifact verified");
6458
+ return retain(root, artifact);
6459
+ },
6460
+ options.signal
6461
+ );
6236
6462
  },
6237
6463
  options.signal
6238
6464
  );