peachsim 0.1.1635 → 0.1.1641
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/cli/app-config.ts +14 -5
- package/cli/app-stubs.ts +96 -22
- package/cli/bridge-flow-runner.ts +2 -2
- package/cli/cloud-client.ts +60 -40
- package/cli/cloud-session.ts +16 -0
- package/cli/commands/assert.ts +17 -4
- package/cli/commands/box.ts +33 -19
- package/cli/commands/doctor.ts +37 -20
- package/cli/commands/flow.ts +1 -1
- package/cli/commands/inspect/actions.ts +3 -2
- package/cli/commands/inspect/core.ts +0 -8
- package/cli/commands/inspect/shared.ts +9 -4
- package/cli/commands/inspect.ts +65 -61
- package/cli/commands/platform.ts +2 -1
- package/cli/commands/preview.ts +1 -1
- package/cli/commands/record.ts +154 -68
- package/cli/commands/swift.ts +18 -4
- package/cli/commands/three-mode.ts +4 -38
- package/cli/commands/upload.ts +55 -49
- package/cli/drivers/playwright-sim-host.ts +65 -42
- package/cli/flow-live-status.ts +0 -2
- package/cli/main.ts +2 -2
- package/cli/outbound-endpoints.ts +7 -5
- package/cli/pause-aware-timeout.ts +4 -0
- package/cli/ws-bridge.ts +19 -16
- package/detox/attempt-events.cjs +99 -6
- package/detox/attempt-events.d.cts +7 -0
- package/detox/expectations.ts +7 -3
- package/detox/index.ts +259 -139
- package/detox/jest-environment.cjs +5 -1
- package/detox/motion-change.cjs +170 -21
- package/detox/motion-change.d.cts +32 -0
- package/detox/navigation-lifecycle.ts +35 -3
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +17 -7
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/bundle-channel.cjs +5014 -2268
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/config.mjs +1 -1
- package/dist-lib/detox/index.cjs +1036 -166
- package/dist-lib/detox/jest-environment.cjs +5 -1
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/expo-swift-bundle.cjs +4613 -1963
- package/dist-lib/expo-swift-metadata.cjs +9 -7
- package/dist-lib/expo-swift-metadata.mjs +9 -7
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +58072 -16400
- package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +2790 -143
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +2579 -95
- package/dist-lib/native-app-identity-project.cjs +243 -53
- package/dist-lib/native-app-identity-project.mjs +243 -53
- package/dist-lib/native-app-identity.cjs +29 -30
- package/dist-lib/native-app-identity.mjs +29 -30
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/react-native-host-modules.cjs +2 -2
- package/dist-lib/react-native-host-modules.mjs +2 -2
- package/dist-lib/scripts/dev-server-scanner.cjs +8 -6
- package/dist-lib/sdk.cjs +4 -3
- package/dist-lib/sdk.mjs +4 -3
- package/dist-lib/skills.cjs +66475 -23097
- package/dist-lib/swift-compile.cjs +452 -260
- package/dist-lib/swift-compile.mjs +451 -252
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +14 -7
- package/dist-lib/swift-submit.mjs +14 -7
- package/dist-lib/swift-toolchain.cjs +316 -41
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +8188 -5636
- package/dist-lib/vite.cjs +2857 -12
- package/dist-lib/worklet-executable.cjs +14 -2
- package/dist-lib/worklet-executable.mjs +14 -2
- package/package.json +1 -1
- package/src/backend-origin.ts +21 -6
- package/src/expo-swift-host.ts +5 -2
- package/src/expoKotlinContract.ts +4 -7
- package/src/expoSwiftContract.ts +4 -6
- package/src/host/staged-host-files.ts +9 -0
- package/src/native-app-identity-project.ts +1 -4
- package/src/native-app-identity.ts +1 -4
- package/src/nativeAppIconContract.ts +1 -4
- package/src/output-lock-stdio.ts +36 -0
- package/src/react-native-bridge-modules.ts +106 -78
- package/src/react-native-host-modules.ts +4 -1
- package/src/settings-bundle.ts +1 -4
- package/src/swift-compile.ts +224 -139
- package/src/swift-distribution.lock.json +23 -12
- package/src/swift-distribution.ts +103 -4
- package/src/swift-host.ts +95 -30
- package/src/swift-icu.ts +16 -10
- package/src/swift-objc-compile.ts +547 -0
- package/src/swift-objc-metadata.ts +204 -0
- package/src/swift-objc-sdk.ts +883 -19
- package/src/swift-objc-standin.ts +126 -14
- package/src/swift-package-manifest.ts +42 -1
- package/src/swift-packages.ts +35 -21
- package/src/swift-root-lock.ts +153 -0
- package/src/swift-standin-emit.ts +40 -7
- package/src/swift-standins.ts +404 -138
- package/src/swift-submit.ts +18 -7
- package/src/swift-toolchain.ts +378 -46
- package/src/swiftContract.ts +12 -0
- package/src/worker-system-chunks.ts +11 -12
- package/src/worklet-executable.ts +19 -1
- package/src/xcode-project.ts +280 -33
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
/*! peach v0.1.
|
|
1
|
+
/*! peach v0.1.1641 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
|
|
2
2
|
|
|
3
3
|
// src/swift-compile.ts
|
|
4
|
-
import { spawn as spawn2, execFileSync as
|
|
5
|
-
import { createHash as
|
|
4
|
+
import { spawn as spawn2, execFileSync as execFileSync3 } from "node:child_process";
|
|
5
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
6
6
|
import {
|
|
7
7
|
cpSync,
|
|
8
8
|
existsSync as existsSync2,
|
|
9
|
-
mkdirSync,
|
|
9
|
+
mkdirSync as mkdirSync2,
|
|
10
10
|
mkdtempSync as mkdtempSync2,
|
|
11
|
-
readFileSync as
|
|
11
|
+
readFileSync as readFileSync5,
|
|
12
12
|
readdirSync as readdirSync2,
|
|
13
13
|
realpathSync,
|
|
14
|
-
renameSync,
|
|
15
|
-
rmSync as
|
|
14
|
+
renameSync as renameSync2,
|
|
15
|
+
rmSync as rmSync3,
|
|
16
16
|
statSync,
|
|
17
|
-
writeFileSync as
|
|
17
|
+
writeFileSync as writeFileSync3
|
|
18
18
|
} from "node:fs";
|
|
19
19
|
import os2 from "node:os";
|
|
20
|
-
import
|
|
20
|
+
import path6 from "node:path";
|
|
21
21
|
|
|
22
22
|
// src/admitted-mac-build.ts
|
|
23
23
|
import { spawnSync } from "node:child_process";
|
|
@@ -733,9 +733,9 @@ var EXCERPT = /^(\s*)(\d+)( \| )(.*)$/;
|
|
|
733
733
|
var MARKER = /^(\s*)( \| )(.*)$/;
|
|
734
734
|
function designTimeDiagnostic(output, files) {
|
|
735
735
|
const rewritten = /* @__PURE__ */ new Map();
|
|
736
|
-
const linesOf = (
|
|
736
|
+
const linesOf = (path7) => {
|
|
737
737
|
const file = Object.keys(files).find(
|
|
738
|
-
(name) => name.endsWith(".swift") && (
|
|
738
|
+
(name) => name.endsWith(".swift") && (path7 === name || path7.endsWith(`/${name}`))
|
|
739
739
|
);
|
|
740
740
|
if (file === void 0) return null;
|
|
741
741
|
let lines = rewritten.get(file);
|
|
@@ -828,10 +828,17 @@ import { createHash as createHash2 } from "node:crypto";
|
|
|
828
828
|
import fs2 from "node:fs";
|
|
829
829
|
import os from "node:os";
|
|
830
830
|
import path3 from "node:path";
|
|
831
|
+
import { fileURLToPath } from "node:url";
|
|
831
832
|
function swiftSdkOptions() {
|
|
832
833
|
const directory = process.env.PEACH_SWIFT_SDKS_PATH;
|
|
833
834
|
return directory ? ["--swift-sdks-path", path3.resolve(directory)] : [];
|
|
834
835
|
}
|
|
836
|
+
var scratch;
|
|
837
|
+
var swiftHome;
|
|
838
|
+
function swiftEnvironment(base = process.env) {
|
|
839
|
+
if (!scratch) return base;
|
|
840
|
+
return swiftHome ? { ...base, TMPDIR: scratch, HOME: swiftHome } : { ...base, TMPDIR: scratch };
|
|
841
|
+
}
|
|
835
842
|
|
|
836
843
|
// src/swift-icu.ts
|
|
837
844
|
var run = promisify(execFile);
|
|
@@ -870,17 +877,23 @@ async function load(toolchainBin, sdk) {
|
|
|
870
877
|
const swift = path4.join(toolchainBin, "swift");
|
|
871
878
|
if (!existsSync(swift))
|
|
872
879
|
throw new Error(`swift-icu: no swift at ${swift} for the ${sdk} SDK's icu data`);
|
|
873
|
-
const { stdout: listed } = await run(swift, ["sdk", "list", ...swiftSdkOptions()]
|
|
880
|
+
const { stdout: listed } = await run(swift, ["sdk", "list", ...swiftSdkOptions()], {
|
|
881
|
+
env: swiftEnvironment()
|
|
882
|
+
});
|
|
874
883
|
if (!listed.split("\n").some((line) => line.trim() === sdk))
|
|
875
884
|
throw new Error(`swift-icu: ${sdk} is not installed for ${swift}`);
|
|
876
|
-
const { stdout } = await run(
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
885
|
+
const { stdout } = await run(
|
|
886
|
+
swift,
|
|
887
|
+
[
|
|
888
|
+
"sdk",
|
|
889
|
+
"configure",
|
|
890
|
+
...swiftSdkOptions(),
|
|
891
|
+
"--show-configuration",
|
|
892
|
+
sdk,
|
|
893
|
+
"wasm32-unknown-wasip1"
|
|
894
|
+
],
|
|
895
|
+
{ env: swiftEnvironment() }
|
|
896
|
+
);
|
|
884
897
|
const resources = /^swiftStaticResourcesPath: (.+)$/m.exec(stdout)?.[1]?.trim();
|
|
885
898
|
if (!resources) throw new Error(`swift-icu: ${sdk} names no static resources`);
|
|
886
899
|
return Buffer.from(
|
|
@@ -1128,6 +1141,124 @@ function swiftPackagePartition(manifest, resourcePaths = []) {
|
|
|
1128
1141
|
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;
|
|
1129
1142
|
}
|
|
1130
1143
|
|
|
1144
|
+
// src/swift-root-lock.ts
|
|
1145
|
+
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
1146
|
+
import { createHash as createHash4, randomUUID as randomUUID2 } from "node:crypto";
|
|
1147
|
+
import {
|
|
1148
|
+
linkSync,
|
|
1149
|
+
mkdirSync,
|
|
1150
|
+
readFileSync as readFileSync4,
|
|
1151
|
+
renameSync,
|
|
1152
|
+
rmSync as rmSync2,
|
|
1153
|
+
writeFileSync as writeFileSync2
|
|
1154
|
+
} from "node:fs";
|
|
1155
|
+
import path5 from "node:path";
|
|
1156
|
+
var POLL_MS = 250;
|
|
1157
|
+
function processStart(pid) {
|
|
1158
|
+
try {
|
|
1159
|
+
return execFileSync2("ps", ["-o", "lstart=", "-p", String(pid)], {
|
|
1160
|
+
encoding: "utf8",
|
|
1161
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
1162
|
+
}).trim() || null;
|
|
1163
|
+
} catch {
|
|
1164
|
+
return null;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
function parseHolder(text2) {
|
|
1168
|
+
try {
|
|
1169
|
+
const value = JSON.parse(text2);
|
|
1170
|
+
if (value && typeof value === "object" && "pid" in value && typeof value.pid === "number" && "start" in value && (typeof value.start === "string" || value.start === null))
|
|
1171
|
+
return { pid: value.pid, start: value.start };
|
|
1172
|
+
} catch {
|
|
1173
|
+
}
|
|
1174
|
+
return null;
|
|
1175
|
+
}
|
|
1176
|
+
function readLock(lock) {
|
|
1177
|
+
try {
|
|
1178
|
+
return readFileSync4(lock, "utf8");
|
|
1179
|
+
} catch (error) {
|
|
1180
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") return null;
|
|
1181
|
+
throw error;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
function holderAlive(text2) {
|
|
1185
|
+
const holder = parseHolder(text2);
|
|
1186
|
+
if (!holder) return false;
|
|
1187
|
+
const start = processStart(holder.pid);
|
|
1188
|
+
return start !== null && start === holder.start;
|
|
1189
|
+
}
|
|
1190
|
+
function pause(ms, signal) {
|
|
1191
|
+
return new Promise((resolve) => {
|
|
1192
|
+
const done = () => {
|
|
1193
|
+
clearTimeout(timer);
|
|
1194
|
+
signal?.removeEventListener("abort", done);
|
|
1195
|
+
resolve();
|
|
1196
|
+
};
|
|
1197
|
+
const timer = setTimeout(done, ms);
|
|
1198
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
1199
|
+
});
|
|
1200
|
+
}
|
|
1201
|
+
async function withSwiftRootLock(root, work, signal) {
|
|
1202
|
+
const directory = path5.join(rnxHomeDir(), "cache", "swift-root-locks");
|
|
1203
|
+
mkdirSync(directory, { recursive: true });
|
|
1204
|
+
const lock = path5.join(
|
|
1205
|
+
directory,
|
|
1206
|
+
`${createHash4("sha256").update(root).digest("hex").slice(0, 32)}.lock`
|
|
1207
|
+
);
|
|
1208
|
+
const token = randomUUID2();
|
|
1209
|
+
const owner = JSON.stringify({
|
|
1210
|
+
pid: process.pid,
|
|
1211
|
+
start: processStart(process.pid),
|
|
1212
|
+
token
|
|
1213
|
+
});
|
|
1214
|
+
const pending = `${lock}.${token}`;
|
|
1215
|
+
writeFileSync2(pending, owner);
|
|
1216
|
+
try {
|
|
1217
|
+
for (; ; ) {
|
|
1218
|
+
signal?.throwIfAborted();
|
|
1219
|
+
try {
|
|
1220
|
+
linkSync(pending, lock);
|
|
1221
|
+
break;
|
|
1222
|
+
} catch (error) {
|
|
1223
|
+
if (!(error instanceof Error && "code" in error && error.code === "EEXIST"))
|
|
1224
|
+
throw error;
|
|
1225
|
+
}
|
|
1226
|
+
const held = readLock(lock);
|
|
1227
|
+
if (held === null) continue;
|
|
1228
|
+
if (holderAlive(held)) {
|
|
1229
|
+
await pause(POLL_MS, signal);
|
|
1230
|
+
continue;
|
|
1231
|
+
}
|
|
1232
|
+
const dead = `${lock}.dead-${token}`;
|
|
1233
|
+
try {
|
|
1234
|
+
renameSync(lock, dead);
|
|
1235
|
+
} catch (error) {
|
|
1236
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") continue;
|
|
1237
|
+
throw error;
|
|
1238
|
+
}
|
|
1239
|
+
try {
|
|
1240
|
+
if (readLock(dead) !== held) {
|
|
1241
|
+
try {
|
|
1242
|
+
linkSync(dead, lock);
|
|
1243
|
+
} catch (error) {
|
|
1244
|
+
if (!(error instanceof Error && "code" in error && error.code === "EEXIST"))
|
|
1245
|
+
throw error;
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
} finally {
|
|
1249
|
+
rmSync2(dead, { force: true });
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
} finally {
|
|
1253
|
+
rmSync2(pending, { force: true });
|
|
1254
|
+
}
|
|
1255
|
+
try {
|
|
1256
|
+
return await work();
|
|
1257
|
+
} finally {
|
|
1258
|
+
if (readLock(lock) === owner) rmSync2(lock, { force: true });
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1131
1262
|
// src/swiftContract.ts
|
|
1132
1263
|
function isSwiftResourcePath(value) {
|
|
1133
1264
|
return typeof value === "string" && value.length <= 4096 && !value.startsWith("/") && !value.includes("\\") && !value.includes("\0") && value.split("/").every((part) => part !== "" && part !== "." && part !== "..");
|
|
@@ -1142,12 +1273,12 @@ function isSwiftResourceBundles(value) {
|
|
|
1142
1273
|
}
|
|
1143
1274
|
|
|
1144
1275
|
// src/swift-compile.ts
|
|
1145
|
-
async function runCompiler(command, args, options, stream = false) {
|
|
1276
|
+
async function runCompiler(command, args, options, stream = false, quiet) {
|
|
1146
1277
|
const { signal } = options;
|
|
1147
1278
|
signal?.throwIfAborted();
|
|
1148
1279
|
const child = spawn2(command, args, {
|
|
1149
1280
|
cwd: options.cwd,
|
|
1150
|
-
env: options.env,
|
|
1281
|
+
env: swiftEnvironment(options.env),
|
|
1151
1282
|
detached: true,
|
|
1152
1283
|
stdio: ["ignore", "pipe", "pipe"]
|
|
1153
1284
|
});
|
|
@@ -1158,6 +1289,7 @@ async function runCompiler(command, args, options, stream = false) {
|
|
|
1158
1289
|
let timeout;
|
|
1159
1290
|
const chunks = { stdout: [], stderr: [] };
|
|
1160
1291
|
const sizes = { stdout: 0, stderr: 0 };
|
|
1292
|
+
const partial = { stdout: "", stderr: "" };
|
|
1161
1293
|
const stop = () => {
|
|
1162
1294
|
stopping ?? (stopping = terminateProcessGroup(child));
|
|
1163
1295
|
void stopping.catch(() => {
|
|
@@ -1165,7 +1297,14 @@ async function runCompiler(command, args, options, stream = false) {
|
|
|
1165
1297
|
};
|
|
1166
1298
|
for (const name of ["stdout", "stderr"]) {
|
|
1167
1299
|
child[name].on("data", (bytes) => {
|
|
1168
|
-
if (stream) process[name].write(bytes);
|
|
1300
|
+
if (stream === true) process[name].write(bytes);
|
|
1301
|
+
else if (stream) {
|
|
1302
|
+
const lines = (partial[name] + bytes.toString()).split("\n");
|
|
1303
|
+
partial[name] = lines.pop();
|
|
1304
|
+
for (const line of lines)
|
|
1305
|
+
if (stream.test(line)) process[name].write(`${line}
|
|
1306
|
+
`);
|
|
1307
|
+
}
|
|
1169
1308
|
sizes[name] += bytes.length;
|
|
1170
1309
|
if (sizes[name] <= (options.maxBuffer ?? 1024 * 1024)) chunks[name].push(bytes);
|
|
1171
1310
|
else {
|
|
@@ -1195,7 +1334,15 @@ async function runCompiler(command, args, options, stream = false) {
|
|
|
1195
1334
|
}
|
|
1196
1335
|
)
|
|
1197
1336
|
);
|
|
1198
|
-
else
|
|
1337
|
+
else {
|
|
1338
|
+
if (quiet) {
|
|
1339
|
+
for (const name of ["stdout", "stderr"])
|
|
1340
|
+
for (const line of Buffer.concat(chunks[name]).toString().split("\n"))
|
|
1341
|
+
if (line && !quiet.test(line)) process[name].write(`${line}
|
|
1342
|
+
`);
|
|
1343
|
+
}
|
|
1344
|
+
resolve();
|
|
1345
|
+
}
|
|
1199
1346
|
});
|
|
1200
1347
|
if (options.timeout)
|
|
1201
1348
|
timeout = setTimeout(() => {
|
|
@@ -1209,16 +1356,18 @@ async function runCompiler(command, args, options, stream = false) {
|
|
|
1209
1356
|
}
|
|
1210
1357
|
}
|
|
1211
1358
|
var WASM_TRIPLE = "wasm32-unknown-wasip1";
|
|
1359
|
+
var SWIFTPM_PROGRESS = /^\[\d+\/\d+\] /;
|
|
1360
|
+
var SWIFTPM_NOISE = /^(?:\[\d+\/\d+\] |Building for production\.\.\.$|warning: '--build-system native' has been deprecated)/;
|
|
1212
1361
|
var BUILD_JOBS = String(
|
|
1213
1362
|
Math.min(4, Math.max(1, Math.floor(os2.availableParallelism() / 2)))
|
|
1214
1363
|
);
|
|
1215
1364
|
function swiftDistributionAt(root) {
|
|
1216
|
-
const file =
|
|
1365
|
+
const file = path6.join(root, SWIFT_DISTRIBUTION_MANIFEST);
|
|
1217
1366
|
if (!existsSync2(file)) return null;
|
|
1218
|
-
return parseSwiftDistributionManifest(JSON.parse(
|
|
1367
|
+
return parseSwiftDistributionManifest(JSON.parse(readFileSync5(file, "utf8")));
|
|
1219
1368
|
}
|
|
1220
1369
|
function swiftModuleSdk(root) {
|
|
1221
|
-
const pin = swiftDistributionAt(root) ?? JSON.parse(
|
|
1370
|
+
const pin = swiftDistributionAt(root) ?? JSON.parse(readFileSync5(path6.join(root, "toolchain.json"), "utf8"));
|
|
1222
1371
|
if (!pin || typeof pin !== "object" || typeof Reflect.get(pin, "wasmSdkId") !== "string" || typeof Reflect.get(pin, "wasmSdkUrl") !== "string" || typeof Reflect.get(pin, "wasmSdkChecksum") !== "string")
|
|
1223
1372
|
throw new Error(`${root} pins no wasm SDK id, url and checksum`);
|
|
1224
1373
|
return {
|
|
@@ -1234,13 +1383,17 @@ function swiftModuleInputFiles(root) {
|
|
|
1234
1383
|
"scripts/contrast-app-Package.swift",
|
|
1235
1384
|
"scripts/build-distribution.ts",
|
|
1236
1385
|
"scripts/distribution-clang.ts",
|
|
1386
|
+
"scripts/distribution-libxml2.ts",
|
|
1387
|
+
"scripts/distribution-libxml2.json",
|
|
1388
|
+
"Sources/libxml2/include/module.modulemap",
|
|
1389
|
+
"Sources/libxml2/COPYING",
|
|
1237
1390
|
"scripts/build-distribution-plugins.sh",
|
|
1238
1391
|
"scripts/build-distribution-plugins-docker.sh",
|
|
1239
1392
|
"scripts/build-preview-plugin.sh",
|
|
1240
1393
|
"toolchain.json"
|
|
1241
1394
|
];
|
|
1242
1395
|
const walk = (dir) => {
|
|
1243
|
-
for (const entry of readdirSync2(
|
|
1396
|
+
for (const entry of readdirSync2(path6.join(root, dir), {
|
|
1244
1397
|
withFileTypes: true
|
|
1245
1398
|
})) {
|
|
1246
1399
|
const relative = `${dir}/${entry.name}`;
|
|
@@ -1258,29 +1411,39 @@ function swiftMacroPlugins(moduleRoot) {
|
|
|
1258
1411
|
const distribution = swiftDistributionAt(moduleRoot);
|
|
1259
1412
|
if (distribution)
|
|
1260
1413
|
return {
|
|
1261
|
-
libraries: distribution.plugins.map((plugin) =>
|
|
1414
|
+
libraries: distribution.plugins.map((plugin) => path6.join(moduleRoot, plugin)),
|
|
1262
1415
|
stale: false
|
|
1263
1416
|
};
|
|
1264
|
-
const dir =
|
|
1417
|
+
const dir = path6.join(moduleRoot, ".build/host/RnxPreviewMacros");
|
|
1265
1418
|
const release = JSON.parse(
|
|
1266
|
-
|
|
1419
|
+
readFileSync5(path6.join(moduleRoot, "toolchain.json"), "utf8")
|
|
1267
1420
|
).release;
|
|
1268
|
-
const compilerStamp =
|
|
1421
|
+
const compilerStamp = path6.join(dir, "compiler-release");
|
|
1269
1422
|
const ext = process.platform === "darwin" ? "dylib" : "so";
|
|
1270
1423
|
const plugins = [
|
|
1271
1424
|
{
|
|
1272
|
-
library:
|
|
1273
|
-
|
|
1425
|
+
library: path6.join(dir, `libRnxPreviewMacros.${ext}`),
|
|
1426
|
+
sources: [path6.join(moduleRoot, "Sources/RnxPreviewMacros/PreviewMacro.swift")]
|
|
1274
1427
|
},
|
|
1275
1428
|
{
|
|
1276
|
-
library:
|
|
1277
|
-
|
|
1429
|
+
library: path6.join(dir, `libFoundationMacros.${ext}`),
|
|
1430
|
+
sources: [
|
|
1431
|
+
path6.join(moduleRoot, "Sources/FoundationMacros/PredicateMacro.swift"),
|
|
1432
|
+
path6.join(moduleRoot, "Sources/SwiftMacroSupport/PredicateExpression.swift")
|
|
1433
|
+
]
|
|
1434
|
+
},
|
|
1435
|
+
{
|
|
1436
|
+
library: path6.join(dir, `libTipKitMacros.${ext}`),
|
|
1437
|
+
sources: [
|
|
1438
|
+
path6.join(moduleRoot, "Sources/TipKitMacros/TipKitMacros.swift"),
|
|
1439
|
+
path6.join(moduleRoot, "Sources/SwiftMacroSupport/PredicateExpression.swift")
|
|
1440
|
+
]
|
|
1278
1441
|
}
|
|
1279
1442
|
];
|
|
1280
1443
|
return {
|
|
1281
1444
|
libraries: plugins.map(({ library }) => library),
|
|
1282
|
-
stale: !existsSync2(compilerStamp) ||
|
|
1283
|
-
({ library,
|
|
1445
|
+
stale: !existsSync2(compilerStamp) || readFileSync5(compilerStamp, "utf8").trim() !== release || plugins.some(
|
|
1446
|
+
({ library, sources }) => !existsSync2(library) || sources.some((source) => statSync(source).mtimeMs > statSync(library).mtimeMs)
|
|
1284
1447
|
)
|
|
1285
1448
|
};
|
|
1286
1449
|
}
|
|
@@ -1290,14 +1453,14 @@ async function ensureMacroPlugins(moduleRoot, toolchainBin, release, signal) {
|
|
|
1290
1453
|
await runCompiler(
|
|
1291
1454
|
"sh",
|
|
1292
1455
|
[
|
|
1293
|
-
|
|
1456
|
+
path6.join(moduleRoot, "scripts/build-preview-plugin.sh"),
|
|
1294
1457
|
toolchainBin,
|
|
1295
1458
|
libraries[0]
|
|
1296
1459
|
],
|
|
1297
1460
|
{ signal }
|
|
1298
1461
|
);
|
|
1299
|
-
|
|
1300
|
-
|
|
1462
|
+
writeFileSync3(
|
|
1463
|
+
path6.join(path6.dirname(libraries[0]), "compiler-release"),
|
|
1301
1464
|
`${release}
|
|
1302
1465
|
`
|
|
1303
1466
|
);
|
|
@@ -1311,9 +1474,9 @@ function clearLinkedModuleDigests(root) {
|
|
|
1311
1474
|
}
|
|
1312
1475
|
function swiftModuleDigest(root) {
|
|
1313
1476
|
const files = swiftModuleInputFiles(root);
|
|
1314
|
-
const stampHash =
|
|
1477
|
+
const stampHash = createHash5("sha256");
|
|
1315
1478
|
for (const file of files) {
|
|
1316
|
-
const stat = statSync(
|
|
1479
|
+
const stat = statSync(path6.join(root, file), { bigint: true });
|
|
1317
1480
|
stampHash.update(file);
|
|
1318
1481
|
stampHash.update(
|
|
1319
1482
|
`${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}
|
|
@@ -1323,17 +1486,20 @@ function swiftModuleDigest(root) {
|
|
|
1323
1486
|
const stamp = stampHash.digest("hex");
|
|
1324
1487
|
const cached = linkedModuleDigests.get(root);
|
|
1325
1488
|
if (cached?.stamp === stamp) return cached.digest;
|
|
1326
|
-
const hash =
|
|
1489
|
+
const hash = createHash5("sha256");
|
|
1327
1490
|
for (const file of files) {
|
|
1328
|
-
hash.update(
|
|
1491
|
+
hash.update(createHash5("sha256").update(file).digest());
|
|
1329
1492
|
hash.update(
|
|
1330
|
-
|
|
1493
|
+
createHash5("sha256").update(readFileSync5(path6.join(root, file))).digest()
|
|
1331
1494
|
);
|
|
1332
1495
|
}
|
|
1333
1496
|
const digest = hash.digest();
|
|
1334
1497
|
linkedModuleDigests.set(root, { stamp, digest });
|
|
1335
1498
|
return digest;
|
|
1336
1499
|
}
|
|
1500
|
+
function swiftProjectBuildKey(moduleRoot, release) {
|
|
1501
|
+
return createHash5("sha256").update(`${release}\0${swiftModuleSdk(moduleRoot).wasmSdkId}`).update(swiftModuleDigest(moduleRoot)).digest("hex").slice(0, 32);
|
|
1502
|
+
}
|
|
1337
1503
|
function compileTargets(input) {
|
|
1338
1504
|
const manifest = input.files["Package.swift"];
|
|
1339
1505
|
return manifest === void 0 ? [] : swiftPackagePartition(manifest, input.resourcePaths);
|
|
@@ -1348,7 +1514,7 @@ function withNativeSourceGlue(input, glue) {
|
|
|
1348
1514
|
...input,
|
|
1349
1515
|
files: {
|
|
1350
1516
|
...input.files,
|
|
1351
|
-
[
|
|
1517
|
+
[path6.posix.join(targetPath, "OneNativeSource.generated.swift")]: glue
|
|
1352
1518
|
},
|
|
1353
1519
|
oneModule: true
|
|
1354
1520
|
};
|
|
@@ -1361,11 +1527,13 @@ var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
|
|
|
1361
1527
|
Accelerate: [],
|
|
1362
1528
|
CryptoKit: [],
|
|
1363
1529
|
CommonCrypto: [],
|
|
1530
|
+
ImagePlayground: [],
|
|
1531
|
+
QuickLookThumbnailing: [],
|
|
1532
|
+
libxml2: [],
|
|
1364
1533
|
CoreText: [],
|
|
1365
1534
|
Compression: ["PeachCodec"],
|
|
1366
1535
|
zlib: ["PeachCodec"],
|
|
1367
1536
|
PeachCodec: [],
|
|
1368
|
-
Security: ["CryptoKit"],
|
|
1369
1537
|
TikTokBusinessSDK: [],
|
|
1370
1538
|
nSure: [],
|
|
1371
1539
|
Statsig: [],
|
|
@@ -1471,7 +1639,7 @@ function swiftImportNames(contents, available) {
|
|
|
1471
1639
|
function swiftPeachModules(moduleRoot) {
|
|
1472
1640
|
const distribution = swiftDistributionAt(moduleRoot);
|
|
1473
1641
|
return distribution ? distribution.modules : [
|
|
1474
|
-
...
|
|
1642
|
+
...readFileSync5(path6.join(moduleRoot, "Package.swift"), "utf8").matchAll(
|
|
1475
1643
|
/\.(?:target|systemLibrary)\(\s*name:\s*"([^"]+)"/g
|
|
1476
1644
|
)
|
|
1477
1645
|
].map((match) => match[1]);
|
|
@@ -1482,8 +1650,8 @@ function swiftSdkPaths(moduleRoot, toolchainBin) {
|
|
|
1482
1650
|
const key = JSON.stringify([toolchainBin, sdk, swiftSdkOptions()]);
|
|
1483
1651
|
const cached = sdkPaths.get(key);
|
|
1484
1652
|
if (cached) return cached;
|
|
1485
|
-
const configuration =
|
|
1486
|
-
|
|
1653
|
+
const configuration = execFileSync3(
|
|
1654
|
+
path6.join(toolchainBin, "swift"),
|
|
1487
1655
|
[
|
|
1488
1656
|
"sdk",
|
|
1489
1657
|
"configure",
|
|
@@ -1492,7 +1660,7 @@ function swiftSdkPaths(moduleRoot, toolchainBin) {
|
|
|
1492
1660
|
sdk,
|
|
1493
1661
|
"wasm32-unknown-wasip1"
|
|
1494
1662
|
],
|
|
1495
|
-
{ encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }
|
|
1663
|
+
{ encoding: "utf8", env: swiftEnvironment(), stdio: ["ignore", "pipe", "pipe"] }
|
|
1496
1664
|
);
|
|
1497
1665
|
const field = (name) => {
|
|
1498
1666
|
const value = new RegExp(`^${name}:\\s*(.+)$`, "m").exec(configuration)?.[1]?.trim();
|
|
@@ -1514,14 +1682,14 @@ function swiftAvailableModules(moduleRoot, toolchainBin) {
|
|
|
1514
1682
|
if (cached) return cached;
|
|
1515
1683
|
const modules = new Set(swiftPeachModules(moduleRoot));
|
|
1516
1684
|
const { resources } = swiftSdkPaths(moduleRoot, toolchainBin);
|
|
1517
|
-
for (const entry of readdirSync2(
|
|
1685
|
+
for (const entry of readdirSync2(path6.join(resources, "wasi"))) {
|
|
1518
1686
|
if (entry.endsWith(".swiftmodule"))
|
|
1519
1687
|
modules.add(entry.slice(0, -".swiftmodule".length));
|
|
1520
1688
|
}
|
|
1521
1689
|
for (const entry of readdirSync2(resources)) {
|
|
1522
|
-
const map =
|
|
1690
|
+
const map = path6.join(resources, entry, "module.modulemap");
|
|
1523
1691
|
if (!existsSync2(map)) continue;
|
|
1524
|
-
for (const match of
|
|
1692
|
+
for (const match of readFileSync5(map, "utf8").matchAll(/^module\s+([A-Za-z_]\w*)/gm))
|
|
1525
1693
|
modules.add(match[1]);
|
|
1526
1694
|
}
|
|
1527
1695
|
availableModules.set(key, modules);
|
|
@@ -1585,9 +1753,9 @@ var EXECUTABLE_LINK_FLAGS = ` "-Xclang-linker", "-O0",
|
|
|
1585
1753
|
`;
|
|
1586
1754
|
var REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
|
|
1587
1755
|
var MULTI_MANIFEST_VERSION = 39;
|
|
1588
|
-
var compilerSourceDigest = true ? "
|
|
1756
|
+
var compilerSourceDigest = true ? "ee2738333bb81c79211d5bee8a503c539cf65f25c95fb024c45b840450b5359e" : swiftCompilerSourceDigest(import.meta.dirname);
|
|
1589
1757
|
function swiftArtifactHash(input, release, moduleRoot) {
|
|
1590
|
-
const hash =
|
|
1758
|
+
const hash = createHash5("sha256");
|
|
1591
1759
|
hash.update(`swift-compile
|
|
1592
1760
|
${release}
|
|
1593
1761
|
`);
|
|
@@ -1595,32 +1763,32 @@ ${release}
|
|
|
1595
1763
|
if (input.oneModule) hash.update("one-module\n");
|
|
1596
1764
|
hash.update(swiftModuleDigest(moduleRoot));
|
|
1597
1765
|
for (const file of Object.keys(input.files).sort()) {
|
|
1598
|
-
hash.update(
|
|
1599
|
-
hash.update(
|
|
1766
|
+
hash.update(createHash5("sha256").update(file).digest());
|
|
1767
|
+
hash.update(createHash5("sha256").update(input.files[file]).digest());
|
|
1600
1768
|
}
|
|
1601
1769
|
for (const file of Object.keys(input.metalSources ?? {}).sort()) {
|
|
1602
1770
|
hash.update("metal-source\n");
|
|
1603
|
-
hash.update(
|
|
1771
|
+
hash.update(createHash5("sha256").update(file).digest());
|
|
1604
1772
|
hash.update(
|
|
1605
|
-
|
|
1773
|
+
createHash5("sha256").update(input.metalSources?.[file] ?? "").digest()
|
|
1606
1774
|
);
|
|
1607
1775
|
}
|
|
1608
1776
|
for (const base of Object.keys(input.resources ?? {}).sort()) {
|
|
1609
|
-
hash.update(
|
|
1777
|
+
hash.update(createHash5("sha256").update(base).digest());
|
|
1610
1778
|
hash.update(
|
|
1611
|
-
|
|
1779
|
+
createHash5("sha256").update(input.resources?.[base] ?? "").digest()
|
|
1612
1780
|
);
|
|
1613
1781
|
}
|
|
1614
1782
|
for (const name of Object.keys(input.images ?? {}).sort()) {
|
|
1615
1783
|
const image = input.images?.[name];
|
|
1616
1784
|
if (!image) continue;
|
|
1617
|
-
hash.update(
|
|
1618
|
-
hash.update(
|
|
1619
|
-
hash.update(
|
|
1785
|
+
hash.update(createHash5("sha256").update(name).digest());
|
|
1786
|
+
hash.update(createHash5("sha256").update(image.file).digest());
|
|
1787
|
+
hash.update(createHash5("sha256").update(image.data).digest());
|
|
1620
1788
|
}
|
|
1621
1789
|
for (const file of [...new Set(input.resourcePaths ?? [])].sort()) {
|
|
1622
1790
|
hash.update("resource-path\n");
|
|
1623
|
-
hash.update(
|
|
1791
|
+
hash.update(createHash5("sha256").update(file).digest());
|
|
1624
1792
|
}
|
|
1625
1793
|
hash.update(
|
|
1626
1794
|
JSON.stringify(
|
|
@@ -1632,7 +1800,7 @@ ${release}
|
|
|
1632
1800
|
${target}
|
|
1633
1801
|
`);
|
|
1634
1802
|
hash.update(
|
|
1635
|
-
|
|
1803
|
+
createHash5("sha256").update(input.libraries?.[target] ?? "").digest()
|
|
1636
1804
|
);
|
|
1637
1805
|
}
|
|
1638
1806
|
const targets = compileTargets(input);
|
|
@@ -1679,11 +1847,11 @@ function emitSwiftPackageManifest(args) {
|
|
|
1679
1847
|
distributionLink.files.set(
|
|
1680
1848
|
distributionLink.path,
|
|
1681
1849
|
objects.map(
|
|
1682
|
-
(object) => `"${
|
|
1850
|
+
(object) => `"${path6.join(moduleRoot, object).replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`
|
|
1683
1851
|
).join("\n") + "\n"
|
|
1684
1852
|
);
|
|
1685
1853
|
}
|
|
1686
|
-
const overlayRoot =
|
|
1854
|
+
const overlayRoot = path6.join(
|
|
1687
1855
|
moduleRoot,
|
|
1688
1856
|
distribution ? "modules" : "cross-import-overlays"
|
|
1689
1857
|
);
|
|
@@ -1691,9 +1859,9 @@ function emitSwiftPackageManifest(args) {
|
|
|
1691
1859
|
"-Xfrontend",
|
|
1692
1860
|
"-swift-module-cross-import",
|
|
1693
1861
|
"-Xfrontend",
|
|
1694
|
-
|
|
1862
|
+
path6.basename(path6.dirname(file), ".swiftcrossimport"),
|
|
1695
1863
|
"-Xfrontend",
|
|
1696
|
-
|
|
1864
|
+
path6.join(overlayRoot, file)
|
|
1697
1865
|
]).map((flag) => `, ${JSON.stringify(flag)}`).join("");
|
|
1698
1866
|
const executable = targets.find((target) => target.executable);
|
|
1699
1867
|
if (!executable) throw new Error("swift-compile: no executable target to emit");
|
|
@@ -1703,14 +1871,14 @@ function emitSwiftPackageManifest(args) {
|
|
|
1703
1871
|
const isolation = target.mainActorIsolation ? " .defaultIsolation(MainActor.self)," : "";
|
|
1704
1872
|
const interoperability = target.cxxInterop ? " .interoperabilityMode(.Cxx)," : "";
|
|
1705
1873
|
const defines = (target.defines ?? []).map((name) => ` .define(${JSON.stringify(name)}),`).join("");
|
|
1706
|
-
const imports = distribution ? `, "-I", ${JSON.stringify(
|
|
1874
|
+
const imports = distribution ? `, "-I", ${JSON.stringify(path6.join(moduleRoot, "modules"))}` : "";
|
|
1707
1875
|
const native = args.native?.get(target.name);
|
|
1708
1876
|
const nativeImports = (siblings.get(target.name) ?? []).filter((name) => args.native?.has(name)).map(
|
|
1709
1877
|
(name) => `, "-Xfrontend", "-import-module", "-Xfrontend", ${JSON.stringify(swiftTargetModuleName(name))}`
|
|
1710
1878
|
).join("");
|
|
1711
1879
|
const header = args.headerDirectory && [...args.native?.values() ?? []].some(
|
|
1712
1880
|
(value) => value.late?.producers.includes(target.name)
|
|
1713
|
-
) ? `, "-emit-objc-header-path", ${JSON.stringify(
|
|
1881
|
+
) ? `, "-emit-objc-header-path", ${JSON.stringify(path6.join(args.headerDirectory, `${target.name}-Swift.h`))}` : "";
|
|
1714
1882
|
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}])]`;
|
|
1715
1883
|
const deps = [
|
|
1716
1884
|
...target.executable ? [...args.native?.values() ?? []].flatMap(
|
|
@@ -1725,7 +1893,7 @@ function emitSwiftPackageManifest(args) {
|
|
|
1725
1893
|
(dependency) => OPTIONAL_FRAMEWORKS.has(dependency) && !targets.some((candidate) => candidate.name === dependency) ? distribution ? [] : [`.product(name: "${dependency}", package: "sootsim-swift")`] : [`"${dependency}"`]
|
|
1726
1894
|
)
|
|
1727
1895
|
].join(", ");
|
|
1728
|
-
const library = distribution && distributionLink ? ["-
|
|
1896
|
+
const library = distribution && distributionLink ? ["-Xclang-linker", `--config=${distributionLink.path}`, ...distribution.link].map((flag) => `, ${JSON.stringify(flag)}`).join("") : "";
|
|
1729
1897
|
const kind = target.executable ? ".executableTarget" : ".target";
|
|
1730
1898
|
const linkedLibraries = (target.linkedLibraries ?? []).map(
|
|
1731
1899
|
(name) => `.linkedLibrary(${JSON.stringify(name)})`
|
|
@@ -1783,21 +1951,21 @@ function emitSwiftPackageManifest(args) {
|
|
|
1783
1951
|
].join("\n");
|
|
1784
1952
|
}
|
|
1785
1953
|
function syncSwiftTree(base, files) {
|
|
1786
|
-
|
|
1954
|
+
mkdirSync2(base, { recursive: true });
|
|
1787
1955
|
const walk = (dir) => {
|
|
1788
1956
|
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
1789
|
-
const full =
|
|
1957
|
+
const full = path6.join(dir, entry.name);
|
|
1790
1958
|
if (dir === base && entry.name === ".build") continue;
|
|
1791
1959
|
if (entry.isDirectory()) walk(full);
|
|
1792
|
-
else if (!files.has(full))
|
|
1960
|
+
else if (!files.has(full)) rmSync3(full, { force: true });
|
|
1793
1961
|
}
|
|
1794
1962
|
};
|
|
1795
1963
|
walk(base);
|
|
1796
1964
|
for (const [full, contents] of files) {
|
|
1797
|
-
if (existsSync2(full) && (typeof contents === "string" ?
|
|
1965
|
+
if (existsSync2(full) && (typeof contents === "string" ? readFileSync5(full, "utf8") === contents : readFileSync5(full).equals(contents)))
|
|
1798
1966
|
continue;
|
|
1799
|
-
|
|
1800
|
-
|
|
1967
|
+
mkdirSync2(path6.dirname(full), { recursive: true });
|
|
1968
|
+
writeFileSync3(full, contents);
|
|
1801
1969
|
}
|
|
1802
1970
|
}
|
|
1803
1971
|
var DIRECTIVE = /^[ \t]*#(?:if|elseif)\b/;
|
|
@@ -2220,19 +2388,24 @@ function objcRootedClasses(sources) {
|
|
|
2220
2388
|
function hideObjCClassesFromCxx(source, rooted) {
|
|
2221
2389
|
if (rooted.size === 0) return source;
|
|
2222
2390
|
const code = swiftCodeMask(source);
|
|
2223
|
-
const
|
|
2391
|
+
const insertions = [];
|
|
2224
2392
|
let depth = 0;
|
|
2225
2393
|
for (const match of code.matchAll(
|
|
2226
2394
|
/[{}]|\bclass\s+(?!(?:func|var|let|subscript)\b)([A-Za-z_]\w*)/g
|
|
2227
2395
|
)) {
|
|
2228
2396
|
if (match[0] === "{") depth++;
|
|
2229
2397
|
else if (match[0] === "}") depth--;
|
|
2230
|
-
else if (depth === 0 && rooted.has(match[1]))
|
|
2231
|
-
|
|
2398
|
+
else if (depth === 0 && rooted.has(match[1])) {
|
|
2399
|
+
const start = declarationStart(code, match.index, 0);
|
|
2400
|
+
const main = /@main\b/.exec(code.slice(start, match.index));
|
|
2401
|
+
insertions.push(
|
|
2402
|
+
main ? { at: start + main.index + main[0].length, text: " @_expose(!Cxx)" } : { at: start, text: "@_expose(!Cxx) " }
|
|
2403
|
+
);
|
|
2404
|
+
}
|
|
2232
2405
|
}
|
|
2233
2406
|
let out = source;
|
|
2234
|
-
for (const at of
|
|
2235
|
-
out = `${out.slice(0, at)}
|
|
2407
|
+
for (const { at, text: text2 } of insertions.reverse())
|
|
2408
|
+
out = `${out.slice(0, at)}${text2}${out.slice(at)}`;
|
|
2236
2409
|
return out;
|
|
2237
2410
|
}
|
|
2238
2411
|
function lowerAnyObjectDoubleValue(source) {
|
|
@@ -5505,7 +5678,7 @@ function swiftApplicationEntry(file, source) {
|
|
|
5505
5678
|
else if (source[at] === "}") depth--;
|
|
5506
5679
|
else if (depth === 0 && /^@(?:main|UIApplicationMain)\b/.test(source.slice(at)))
|
|
5507
5680
|
return true;
|
|
5508
|
-
else if (depth === 0 &&
|
|
5681
|
+
else if (depth === 0 && path6.basename(file) === "main.swift" && /^UIApplicationMain\s*\(/.test(source.slice(at)))
|
|
5509
5682
|
return true;
|
|
5510
5683
|
}
|
|
5511
5684
|
return false;
|
|
@@ -5605,32 +5778,32 @@ function swiftCodeScan(source) {
|
|
|
5605
5778
|
return { lineStarts: starts, tokens };
|
|
5606
5779
|
}
|
|
5607
5780
|
function prepareSwiftDependency(source, destination) {
|
|
5608
|
-
|
|
5781
|
+
rmSync3(destination, { recursive: true, force: true });
|
|
5609
5782
|
const origins = {};
|
|
5610
5783
|
const gather = (from) => {
|
|
5611
5784
|
for (const entry of readdirSync2(from, { withFileTypes: true })) {
|
|
5612
5785
|
if (entry.name === ".git" || entry.name === ".build" || entry.name === ".swiftpm")
|
|
5613
5786
|
continue;
|
|
5614
|
-
const file =
|
|
5787
|
+
const file = path6.join(from, entry.name);
|
|
5615
5788
|
if (entry.isDirectory()) gather(file);
|
|
5616
5789
|
else if (entry.isFile() && entry.name.endsWith(".swift"))
|
|
5617
|
-
origins[
|
|
5790
|
+
origins[path6.relative(source, file)] = readFileSync5(file, "utf8");
|
|
5618
5791
|
}
|
|
5619
5792
|
};
|
|
5620
5793
|
gather(source);
|
|
5621
|
-
const manifest =
|
|
5622
|
-
const targets = existsSync2(manifest) ? swiftManifestTargets(
|
|
5794
|
+
const manifest = path6.join(source, "Package.swift");
|
|
5795
|
+
const targets = existsSync2(manifest) ? swiftManifestTargets(readFileSync5(manifest, "utf8")) : [];
|
|
5623
5796
|
const compiled = compiledSwiftSources(origins, targets);
|
|
5624
5797
|
const copy = (from, to) => {
|
|
5625
|
-
|
|
5798
|
+
mkdirSync2(to, { recursive: true });
|
|
5626
5799
|
for (const entry of readdirSync2(from, { withFileTypes: true })) {
|
|
5627
5800
|
if (entry.name === ".git" || entry.name === ".build" || entry.name === ".swiftpm")
|
|
5628
5801
|
continue;
|
|
5629
|
-
const file =
|
|
5630
|
-
const target =
|
|
5802
|
+
const file = path6.join(from, entry.name);
|
|
5803
|
+
const target = path6.join(to, entry.name);
|
|
5631
5804
|
if (entry.isDirectory()) copy(file, target);
|
|
5632
5805
|
else if (entry.isFile() && entry.name.endsWith(".swift"))
|
|
5633
|
-
|
|
5806
|
+
writeFileSync3(target, compiled.get(path6.relative(source, file)));
|
|
5634
5807
|
else cpSync(file, target, { verbatimSymlinks: true });
|
|
5635
5808
|
}
|
|
5636
5809
|
};
|
|
@@ -5647,7 +5820,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
|
|
|
5647
5820
|
const targets = distribution && compileTargets(input).length === 0 ? [
|
|
5648
5821
|
{
|
|
5649
5822
|
name: "App",
|
|
5650
|
-
path:
|
|
5823
|
+
path: path6.relative(layout.root, layout.sources),
|
|
5651
5824
|
executable: true,
|
|
5652
5825
|
languageMode: 5,
|
|
5653
5826
|
mainActorIsolation: false,
|
|
@@ -5656,7 +5829,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
|
|
|
5656
5829
|
] : compileTargets(input);
|
|
5657
5830
|
const files = /* @__PURE__ */ new Map();
|
|
5658
5831
|
const native = /* @__PURE__ */ new Map();
|
|
5659
|
-
const headerDirectory =
|
|
5832
|
+
const headerDirectory = path6.join(layout.root, ".build", "peach-cxx-headers");
|
|
5660
5833
|
for (const target of targets) {
|
|
5661
5834
|
const prefix = target.path === "." ? "" : `${target.path}/`;
|
|
5662
5835
|
const entries = Object.entries(input.files).filter(
|
|
@@ -5679,7 +5852,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
|
|
|
5679
5852
|
if (producer && targets.some((value) => value.name === producer))
|
|
5680
5853
|
producers.add(producer);
|
|
5681
5854
|
const local = [
|
|
5682
|
-
|
|
5855
|
+
path6.posix.join(path6.posix.dirname(file), include),
|
|
5683
5856
|
`${includes}${include}`
|
|
5684
5857
|
].find((candidate) => input.files[candidate] !== void 0);
|
|
5685
5858
|
if (local) {
|
|
@@ -5701,7 +5874,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
|
|
|
5701
5874
|
const late = units.filter(([file]) => consumers.get(file).size > 0);
|
|
5702
5875
|
native.set(target.name, {
|
|
5703
5876
|
path: target.path,
|
|
5704
|
-
includeDirectory:
|
|
5877
|
+
includeDirectory: path6.join(layout.root, includes),
|
|
5705
5878
|
lateSources: late.map(([file]) => file.slice(prefix.length)),
|
|
5706
5879
|
...late.length > 0 ? {
|
|
5707
5880
|
late: {
|
|
@@ -5718,7 +5891,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
|
|
|
5718
5891
|
([file]) => file.startsWith(includes) && /\.(?:h|hpp|hh|hxx)$/.test(file) && consumers.get(file).size === 0
|
|
5719
5892
|
);
|
|
5720
5893
|
files.set(
|
|
5721
|
-
|
|
5894
|
+
path6.join(layout.root, includes, "module.modulemap"),
|
|
5722
5895
|
[
|
|
5723
5896
|
`module ${target.name} {`,
|
|
5724
5897
|
...roots.map(
|
|
@@ -5730,14 +5903,14 @@ function writeSwiftProject(layout, input, moduleRoot) {
|
|
|
5730
5903
|
].join("\n")
|
|
5731
5904
|
);
|
|
5732
5905
|
}
|
|
5733
|
-
if (native.size > 0)
|
|
5734
|
-
const modulePlan =
|
|
5906
|
+
if (native.size > 0) mkdirSync2(headerDirectory, { recursive: true });
|
|
5907
|
+
const modulePlan = createHash5("sha256").update(
|
|
5735
5908
|
swiftModuleInputFiles(moduleRoot).join("\n")
|
|
5736
5909
|
);
|
|
5737
5910
|
if (!distribution) {
|
|
5738
|
-
modulePlan.update(
|
|
5911
|
+
modulePlan.update(readFileSync5(path6.join(moduleRoot, "Package.swift")));
|
|
5739
5912
|
}
|
|
5740
|
-
const resourcePlan =
|
|
5913
|
+
const resourcePlan = createHash5("sha256").update(
|
|
5741
5914
|
JSON.stringify(
|
|
5742
5915
|
resourceTargets.filter((target) => target.resources).map((target) => [
|
|
5743
5916
|
target.name,
|
|
@@ -5762,10 +5935,10 @@ function writeSwiftProject(layout, input, moduleRoot) {
|
|
|
5762
5935
|
if (targets.length === 0) {
|
|
5763
5936
|
for (const [file, contents] of Object.entries(input.files)) {
|
|
5764
5937
|
if (file === "Package.swift") continue;
|
|
5765
|
-
files.set(
|
|
5938
|
+
files.set(path6.join(layout.sources, file), compiled.get(file) ?? contents);
|
|
5766
5939
|
}
|
|
5767
|
-
let manifest =
|
|
5768
|
-
|
|
5940
|
+
let manifest = readFileSync5(
|
|
5941
|
+
path6.join(moduleRoot, "scripts/contrast-app-Package.swift"),
|
|
5769
5942
|
"utf8"
|
|
5770
5943
|
).replaceAll("__SOOTSIM_SWIFT_PACKAGE__", moduleRoot);
|
|
5771
5944
|
const reactor = ` ${REACTOR_FLAG}`;
|
|
@@ -5809,21 +5982,21 @@ function writeSwiftProject(layout, input, moduleRoot) {
|
|
|
5809
5982
|
manifest = manifest.replace(anchor, `${anchor}
|
|
5810
5983
|
${SPRITEKIT_PRODUCT},`);
|
|
5811
5984
|
}
|
|
5812
|
-
files.set(
|
|
5985
|
+
files.set(path6.join(layout.root, "Package.swift"), manifest + moduleFiles);
|
|
5813
5986
|
} else {
|
|
5814
5987
|
const base = layout.multi ? layout.root : layout.sources;
|
|
5815
5988
|
const libraries = /* @__PURE__ */ new Map();
|
|
5816
5989
|
for (const [target, data] of Object.entries(input.libraries ?? {})) {
|
|
5817
|
-
const file =
|
|
5990
|
+
const file = path6.join(layout.root, ".peach-libraries", `lib${target}.a`);
|
|
5818
5991
|
files.set(file, Buffer.from(data, "base64"));
|
|
5819
5992
|
libraries.set(target, file);
|
|
5820
5993
|
}
|
|
5821
5994
|
for (const [file, contents] of Object.entries(input.files)) {
|
|
5822
5995
|
if (file === "Package.swift") continue;
|
|
5823
|
-
files.set(
|
|
5996
|
+
files.set(path6.join(base, file), compiled.get(file) ?? contents);
|
|
5824
5997
|
}
|
|
5825
5998
|
files.set(
|
|
5826
|
-
|
|
5999
|
+
path6.join(layout.root, "Package.swift"),
|
|
5827
6000
|
emitSwiftPackageManifest({
|
|
5828
6001
|
targets,
|
|
5829
6002
|
native,
|
|
@@ -5840,7 +6013,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
|
|
|
5840
6013
|
spriteKit: importsSpriteKit(input.files),
|
|
5841
6014
|
distribution: distribution ?? void 0,
|
|
5842
6015
|
distributionLink: {
|
|
5843
|
-
path:
|
|
6016
|
+
path: path6.join(layout.root, ".peach-distribution-objects.rsp"),
|
|
5844
6017
|
files
|
|
5845
6018
|
},
|
|
5846
6019
|
libraries
|
|
@@ -5856,9 +6029,9 @@ function writeSwiftProject(layout, input, moduleRoot) {
|
|
|
5856
6029
|
throw new Error(
|
|
5857
6030
|
`swift resource target ${target.name} has no matching bundle assignment`
|
|
5858
6031
|
);
|
|
5859
|
-
const directory = layout.multi ?
|
|
6032
|
+
const directory = layout.multi ? path6.join(layout.root, target.path) : layout.sources;
|
|
5860
6033
|
files.set(
|
|
5861
|
-
|
|
6034
|
+
path6.join(directory, "ResourceBundleAccessor.generated.swift"),
|
|
5862
6035
|
[
|
|
5863
6036
|
"import Foundation",
|
|
5864
6037
|
"",
|
|
@@ -5891,13 +6064,13 @@ function outputOf(error) {
|
|
|
5891
6064
|
return error instanceof Error ? error.message : String(error);
|
|
5892
6065
|
}
|
|
5893
6066
|
function builtArtifact(layout) {
|
|
5894
|
-
const binDir =
|
|
5895
|
-
const manifest =
|
|
6067
|
+
const binDir = path6.join(layout.root, ".build", WASM_TRIPLE, "release");
|
|
6068
|
+
const manifest = readFileSync5(path6.join(layout.root, "Package.swift"), "utf8");
|
|
5896
6069
|
const executable = swiftManifestTargets(manifest).find((target) => target.executable);
|
|
5897
6070
|
if (executable === void 0) {
|
|
5898
6071
|
throw new Error("swift-compile: the written manifest names no executable target");
|
|
5899
6072
|
}
|
|
5900
|
-
const file =
|
|
6073
|
+
const file = path6.join(binDir, `${executable.name}.wasm`);
|
|
5901
6074
|
if (!existsSync2(file)) {
|
|
5902
6075
|
const found = existsSync2(binDir) ? readdirSync2(binDir).filter((name) => name.endsWith(".wasm")).sort() : [];
|
|
5903
6076
|
throw new Error(
|
|
@@ -5908,8 +6081,8 @@ function builtArtifact(layout) {
|
|
|
5908
6081
|
}
|
|
5909
6082
|
function projectDiagnostic(output, layout, files) {
|
|
5910
6083
|
const base = layout.multi ? layout.root : layout.sources;
|
|
5911
|
-
const prefix = `${base}${
|
|
5912
|
-
return designTimeDiagnostic(output, files).split("\n").map((line) => line.startsWith(prefix) ? line.slice(prefix.length) : line).join("\n").trim();
|
|
6084
|
+
const prefix = `${base}${path6.sep}`;
|
|
6085
|
+
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();
|
|
5913
6086
|
}
|
|
5914
6087
|
var ROOT_LOCKS = Symbol.for("peachsim.swiftCompile.rootLocks");
|
|
5915
6088
|
var host = globalThis;
|
|
@@ -5944,13 +6117,13 @@ function serialize(root, work, signal) {
|
|
|
5944
6117
|
function readCompiledArtifact(directory, hash) {
|
|
5945
6118
|
try {
|
|
5946
6119
|
const receipt = JSON.parse(
|
|
5947
|
-
|
|
6120
|
+
readFileSync5(path6.join(directory, "artifact.json"), "utf8")
|
|
5948
6121
|
);
|
|
5949
6122
|
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")
|
|
5950
6123
|
return null;
|
|
5951
|
-
const bytes =
|
|
5952
|
-
const gzip2 =
|
|
5953
|
-
if (
|
|
6124
|
+
const bytes = readFileSync5(path6.join(directory, "app.wasm"));
|
|
6125
|
+
const gzip2 = readFileSync5(path6.join(directory, "icu.gz"));
|
|
6126
|
+
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)
|
|
5954
6127
|
return null;
|
|
5955
6128
|
return { hash, bytes, icu: { sha256: receipt.icu, gzip: gzip2 } };
|
|
5956
6129
|
} catch (error) {
|
|
@@ -5960,25 +6133,25 @@ function readCompiledArtifact(directory, hash) {
|
|
|
5960
6133
|
}
|
|
5961
6134
|
}
|
|
5962
6135
|
function saveCompiledArtifact(root, artifact) {
|
|
5963
|
-
const directory =
|
|
5964
|
-
|
|
5965
|
-
const pending = mkdtempSync2(
|
|
6136
|
+
const directory = path6.join(root, "artifact");
|
|
6137
|
+
mkdirSync2(directory, { recursive: true });
|
|
6138
|
+
const pending = mkdtempSync2(path6.join(root, ".artifact-"));
|
|
5966
6139
|
try {
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
|
|
6140
|
+
writeFileSync3(path6.join(pending, "app.wasm"), artifact.bytes);
|
|
6141
|
+
writeFileSync3(path6.join(pending, "icu.gz"), artifact.icu.gzip);
|
|
6142
|
+
writeFileSync3(
|
|
6143
|
+
path6.join(pending, "artifact.json"),
|
|
5971
6144
|
JSON.stringify({
|
|
5972
6145
|
hash: artifact.hash,
|
|
5973
|
-
wasm:
|
|
6146
|
+
wasm: createHash5("sha256").update(artifact.bytes).digest("hex"),
|
|
5974
6147
|
icu: artifact.icu.sha256
|
|
5975
6148
|
})
|
|
5976
6149
|
);
|
|
5977
6150
|
for (const file of ["app.wasm", "icu.gz", "artifact.json"]) {
|
|
5978
|
-
|
|
6151
|
+
renameSync2(path6.join(pending, file), path6.join(directory, file));
|
|
5979
6152
|
}
|
|
5980
6153
|
} finally {
|
|
5981
|
-
|
|
6154
|
+
rmSync3(pending, { recursive: true, force: true });
|
|
5982
6155
|
}
|
|
5983
6156
|
}
|
|
5984
6157
|
var retainedArtifacts = /* @__PURE__ */ new Map();
|
|
@@ -5994,17 +6167,20 @@ function retain(root, artifact) {
|
|
|
5994
6167
|
}
|
|
5995
6168
|
function compileSwiftProjectUnit(input, options) {
|
|
5996
6169
|
options.signal?.throwIfAborted();
|
|
5997
|
-
|
|
6170
|
+
mkdirSync2(options.buildRoot, { recursive: true });
|
|
5998
6171
|
const root = realpathSync(options.buildRoot);
|
|
5999
|
-
const moduleRoot =
|
|
6172
|
+
const moduleRoot = path6.resolve(options.moduleRoot);
|
|
6000
6173
|
const layout = {
|
|
6001
6174
|
root,
|
|
6002
|
-
sources:
|
|
6175
|
+
sources: path6.join(root, "Sources", "App"),
|
|
6003
6176
|
multi: compileTargets(input).length > 0
|
|
6004
6177
|
};
|
|
6005
6178
|
const hash = swiftArtifactHash(input, options.release, moduleRoot);
|
|
6006
|
-
const sharedRoot =
|
|
6007
|
-
const report = (message) =>
|
|
6179
|
+
const sharedRoot = path6.join(rnxHomeDir(), "cache", "swift-projects", hash);
|
|
6180
|
+
const report = (message) => {
|
|
6181
|
+
console.error(`[swift-project ${hash.slice(0, 16)}] ${message}`);
|
|
6182
|
+
options.onStage?.(message);
|
|
6183
|
+
};
|
|
6008
6184
|
report("checking verified artifacts");
|
|
6009
6185
|
return serialize(
|
|
6010
6186
|
root,
|
|
@@ -6014,37 +6190,36 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
6014
6190
|
report("reusing memory artifact");
|
|
6015
6191
|
return retain(root, retained);
|
|
6016
6192
|
}
|
|
6017
|
-
const cached = readCompiledArtifact(
|
|
6018
|
-
const previous = cached ?? readCompiledArtifact(
|
|
6193
|
+
const cached = readCompiledArtifact(path6.join(sharedRoot, "artifact"), hash);
|
|
6194
|
+
const previous = cached ?? readCompiledArtifact(path6.join(root, "artifact"), hash);
|
|
6019
6195
|
if (previous) {
|
|
6020
6196
|
if (!cached) saveCompiledArtifact(sharedRoot, previous);
|
|
6021
6197
|
report("reusing verified disk artifact");
|
|
6022
6198
|
return retain(root, previous);
|
|
6023
6199
|
}
|
|
6024
|
-
if (process.platform === "darwin" && process.env.TM_SESSION && !admittedMacBuilderSlot() && process.env.CI !== "true" && moduleRoot ===
|
|
6025
|
-
const requestRoot = mkdtempSync2(
|
|
6026
|
-
const output =
|
|
6027
|
-
const request =
|
|
6028
|
-
|
|
6200
|
+
if (process.platform === "darwin" && process.env.TM_SESSION && !admittedMacBuilderSlot() && process.env.CI !== "true" && moduleRoot === path6.resolve(import.meta.dirname, "../../sootsim-swift") && !swiftDistributionAt(moduleRoot)) {
|
|
6201
|
+
const requestRoot = mkdtempSync2(path6.join(root, ".builder-request-"));
|
|
6202
|
+
const output = path6.join(requestRoot, "output");
|
|
6203
|
+
const request = path6.join(requestRoot, "request.json");
|
|
6204
|
+
writeFileSync3(
|
|
6029
6205
|
request,
|
|
6030
6206
|
JSON.stringify({
|
|
6031
6207
|
input,
|
|
6032
6208
|
hash,
|
|
6033
6209
|
release: options.release,
|
|
6034
6210
|
timeoutMs: options.timeoutMs,
|
|
6035
|
-
//
|
|
6036
|
-
//
|
|
6037
|
-
|
|
6038
|
-
buildKey: createHash4("sha256").update(`${options.release}\0${swiftModuleSdk(moduleRoot).wasmSdkId}`).digest("hex").slice(0, 32)
|
|
6211
|
+
// framework sources and compiler inputs own the shared object tree;
|
|
6212
|
+
// unrelated app edits reuse it without retaining stale private ABI.
|
|
6213
|
+
buildKey: swiftProjectBuildKey(moduleRoot, options.release)
|
|
6039
6214
|
})
|
|
6040
6215
|
);
|
|
6041
6216
|
try {
|
|
6042
|
-
const repo =
|
|
6217
|
+
const repo = path6.resolve(moduleRoot, "../..");
|
|
6043
6218
|
report("requesting builder admission or cached result");
|
|
6044
6219
|
await runCompiler(
|
|
6045
6220
|
"bun",
|
|
6046
6221
|
[
|
|
6047
|
-
|
|
6222
|
+
path6.join(repo, "scripts/build/swift-project.ts"),
|
|
6048
6223
|
"--request",
|
|
6049
6224
|
request,
|
|
6050
6225
|
"--output",
|
|
@@ -6061,118 +6236,141 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
6061
6236
|
if (options.signal?.aborted) throw error;
|
|
6062
6237
|
throw new Error(outputOf(error), { cause: error });
|
|
6063
6238
|
});
|
|
6064
|
-
const
|
|
6065
|
-
if (!
|
|
6239
|
+
const artifact = readCompiledArtifact(output, hash);
|
|
6240
|
+
if (!artifact) {
|
|
6066
6241
|
throw new Error(
|
|
6067
6242
|
"swift-compile: builder artifact source, digest or wasm header is invalid"
|
|
6068
6243
|
);
|
|
6069
6244
|
}
|
|
6070
|
-
saveCompiledArtifact(root,
|
|
6071
|
-
saveCompiledArtifact(sharedRoot,
|
|
6245
|
+
saveCompiledArtifact(root, artifact);
|
|
6246
|
+
saveCompiledArtifact(sharedRoot, artifact);
|
|
6072
6247
|
report("builder artifact verified");
|
|
6073
|
-
return retain(root,
|
|
6248
|
+
return retain(root, artifact);
|
|
6074
6249
|
} finally {
|
|
6075
|
-
|
|
6250
|
+
rmSync3(requestRoot, { recursive: true, force: true });
|
|
6076
6251
|
}
|
|
6077
6252
|
}
|
|
6078
|
-
|
|
6079
|
-
const swift = path5.join(options.toolchainBin, "swift");
|
|
6080
|
-
if (!existsSync2(swift)) {
|
|
6081
|
-
throw new Error(
|
|
6082
|
-
`swift-compile: no swift.org toolchain at ${options.toolchainBin}; install ${options.release} and its matching wasm sdk`
|
|
6083
|
-
);
|
|
6084
|
-
}
|
|
6085
|
-
report("preparing compiler plugins");
|
|
6086
|
-
const macroPlugins = await ensureMacroPlugins(
|
|
6087
|
-
moduleRoot,
|
|
6088
|
-
options.toolchainBin,
|
|
6089
|
-
options.release,
|
|
6090
|
-
options.signal
|
|
6091
|
-
);
|
|
6092
|
-
const sdk = swiftModuleSdk(moduleRoot).wasmSdkId;
|
|
6093
|
-
const icu = swiftIcuAsset(options.toolchainBin, sdk);
|
|
6094
|
-
const buildArgs = [
|
|
6095
|
-
"build",
|
|
6096
|
-
...swiftPackageCacheOptions(),
|
|
6097
|
-
"--build-system",
|
|
6098
|
-
"native",
|
|
6099
|
-
"-j",
|
|
6100
|
-
BUILD_JOBS,
|
|
6101
|
-
"--package-path",
|
|
6253
|
+
return withSwiftRootLock(
|
|
6102
6254
|
root,
|
|
6103
|
-
|
|
6104
|
-
|
|
6105
|
-
|
|
6106
|
-
|
|
6107
|
-
|
|
6108
|
-
|
|
6109
|
-
|
|
6110
|
-
|
|
6111
|
-
|
|
6112
|
-
"-Xswiftc",
|
|
6113
|
-
BUILD_JOBS,
|
|
6114
|
-
...macroPlugins.flatMap((plugin) => [
|
|
6115
|
-
"-Xswiftc",
|
|
6116
|
-
"-load-plugin-library",
|
|
6117
|
-
"-Xswiftc",
|
|
6118
|
-
plugin
|
|
6119
|
-
])
|
|
6120
|
-
];
|
|
6121
|
-
const buildOptions = {
|
|
6122
|
-
env: {
|
|
6123
|
-
...process.env,
|
|
6124
|
-
// shipped host plugins resolve against the selected compiler's runtime.
|
|
6125
|
-
...process.platform === "linux" ? {
|
|
6126
|
-
LD_LIBRARY_PATH: [
|
|
6127
|
-
path5.resolve(options.toolchainBin, "../lib/swift/linux"),
|
|
6128
|
-
path5.resolve(options.toolchainBin, "../lib/swift/host"),
|
|
6129
|
-
process.env.LD_LIBRARY_PATH
|
|
6130
|
-
].filter(Boolean).join(":")
|
|
6131
|
-
} : {}
|
|
6132
|
-
},
|
|
6133
|
-
maxBuffer: 64 * 1024 * 1024,
|
|
6134
|
-
timeout: options.timeoutMs,
|
|
6135
|
-
signal: options.signal
|
|
6136
|
-
};
|
|
6137
|
-
report("compiling and linking Swift modules");
|
|
6138
|
-
try {
|
|
6139
|
-
await runCompiler(swift, buildArgs, buildOptions, true);
|
|
6140
|
-
} catch (error) {
|
|
6141
|
-
const output = outputOf(error);
|
|
6142
|
-
const moduleCache = path5.join(
|
|
6143
|
-
root,
|
|
6144
|
-
".build",
|
|
6145
|
-
WASM_TRIPLE,
|
|
6146
|
-
"release",
|
|
6147
|
-
"ModuleCache"
|
|
6148
|
-
);
|
|
6149
|
-
if (output.includes("was compiled with module cache path") && existsSync2(moduleCache)) {
|
|
6150
|
-
rmSync2(moduleCache, { recursive: true, force: true });
|
|
6151
|
-
try {
|
|
6152
|
-
await runCompiler(swift, buildArgs, buildOptions, true);
|
|
6153
|
-
} catch (retryError) {
|
|
6255
|
+
async () => {
|
|
6256
|
+
const built = readCompiledArtifact(path6.join(sharedRoot, "artifact"), hash);
|
|
6257
|
+
if (built) {
|
|
6258
|
+
report("reusing verified disk artifact");
|
|
6259
|
+
return retain(root, built);
|
|
6260
|
+
}
|
|
6261
|
+
writeSwiftProject(layout, input, moduleRoot);
|
|
6262
|
+
const swift = path6.join(options.toolchainBin, "swift");
|
|
6263
|
+
if (!existsSync2(swift)) {
|
|
6154
6264
|
throw new Error(
|
|
6155
|
-
|
|
6156
|
-
{
|
|
6157
|
-
cause: retryError
|
|
6158
|
-
}
|
|
6265
|
+
`swift-compile: no swift.org toolchain at ${options.toolchainBin}; install ${options.release} and its matching wasm sdk`
|
|
6159
6266
|
);
|
|
6160
6267
|
}
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6268
|
+
report("preparing compiler plugins");
|
|
6269
|
+
const macroPlugins = await ensureMacroPlugins(
|
|
6270
|
+
moduleRoot,
|
|
6271
|
+
options.toolchainBin,
|
|
6272
|
+
options.release,
|
|
6273
|
+
options.signal
|
|
6274
|
+
);
|
|
6275
|
+
const sdk = swiftModuleSdk(moduleRoot).wasmSdkId;
|
|
6276
|
+
const icu = swiftIcuAsset(options.toolchainBin, sdk);
|
|
6277
|
+
const buildArgs = [
|
|
6278
|
+
"build",
|
|
6279
|
+
...swiftPackageCacheOptions(),
|
|
6280
|
+
"--build-system",
|
|
6281
|
+
"native",
|
|
6282
|
+
"-j",
|
|
6283
|
+
BUILD_JOBS,
|
|
6284
|
+
"--package-path",
|
|
6285
|
+
root,
|
|
6286
|
+
...swiftSdkOptions(),
|
|
6287
|
+
"--swift-sdk",
|
|
6288
|
+
sdk,
|
|
6289
|
+
"-c",
|
|
6290
|
+
"release",
|
|
6291
|
+
"-Xswiftc",
|
|
6292
|
+
"-Osize",
|
|
6293
|
+
"-Xswiftc",
|
|
6294
|
+
"-num-threads",
|
|
6295
|
+
"-Xswiftc",
|
|
6296
|
+
BUILD_JOBS,
|
|
6297
|
+
...macroPlugins.flatMap((plugin) => [
|
|
6298
|
+
"-Xswiftc",
|
|
6299
|
+
"-load-plugin-library",
|
|
6300
|
+
"-Xswiftc",
|
|
6301
|
+
plugin
|
|
6302
|
+
])
|
|
6303
|
+
];
|
|
6304
|
+
const buildOptions = {
|
|
6305
|
+
env: {
|
|
6306
|
+
...process.env,
|
|
6307
|
+
// shipped host plugins resolve against the selected compiler's runtime.
|
|
6308
|
+
...process.platform === "linux" ? {
|
|
6309
|
+
LD_LIBRARY_PATH: [
|
|
6310
|
+
path6.resolve(options.toolchainBin, "../lib/swift/linux"),
|
|
6311
|
+
path6.resolve(options.toolchainBin, "../lib/swift/host"),
|
|
6312
|
+
process.env.LD_LIBRARY_PATH
|
|
6313
|
+
].filter(Boolean).join(":")
|
|
6314
|
+
} : {}
|
|
6315
|
+
},
|
|
6316
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
6317
|
+
timeout: options.timeoutMs,
|
|
6318
|
+
signal: options.signal
|
|
6319
|
+
};
|
|
6320
|
+
report("compiling and linking Swift modules");
|
|
6321
|
+
try {
|
|
6322
|
+
await runCompiler(
|
|
6323
|
+
swift,
|
|
6324
|
+
buildArgs,
|
|
6325
|
+
buildOptions,
|
|
6326
|
+
SWIFTPM_PROGRESS,
|
|
6327
|
+
SWIFTPM_NOISE
|
|
6328
|
+
);
|
|
6329
|
+
} catch (error) {
|
|
6330
|
+
const output = outputOf(error);
|
|
6331
|
+
const moduleCache = path6.join(
|
|
6332
|
+
root,
|
|
6333
|
+
".build",
|
|
6334
|
+
WASM_TRIPLE,
|
|
6335
|
+
"release",
|
|
6336
|
+
"ModuleCache"
|
|
6337
|
+
);
|
|
6338
|
+
if (output.includes("was compiled with module cache path") && existsSync2(moduleCache)) {
|
|
6339
|
+
rmSync3(moduleCache, { recursive: true, force: true });
|
|
6340
|
+
try {
|
|
6341
|
+
await runCompiler(
|
|
6342
|
+
swift,
|
|
6343
|
+
buildArgs,
|
|
6344
|
+
buildOptions,
|
|
6345
|
+
SWIFTPM_PROGRESS,
|
|
6346
|
+
SWIFTPM_NOISE
|
|
6347
|
+
);
|
|
6348
|
+
} catch (retryError) {
|
|
6349
|
+
throw new Error(
|
|
6350
|
+
projectDiagnostic(outputOf(retryError), layout, input.files),
|
|
6351
|
+
{
|
|
6352
|
+
cause: retryError
|
|
6353
|
+
}
|
|
6354
|
+
);
|
|
6355
|
+
}
|
|
6356
|
+
} else {
|
|
6357
|
+
throw new Error(projectDiagnostic(output, layout, input.files), {
|
|
6358
|
+
cause: error
|
|
6359
|
+
});
|
|
6360
|
+
}
|
|
6361
|
+
}
|
|
6362
|
+
const artifact = {
|
|
6363
|
+
hash,
|
|
6364
|
+
bytes: readFileSync5(builtArtifact(layout)),
|
|
6365
|
+
icu: await icu
|
|
6366
|
+
};
|
|
6367
|
+
saveCompiledArtifact(root, artifact);
|
|
6368
|
+
saveCompiledArtifact(sharedRoot, artifact);
|
|
6369
|
+
report("compiled artifact verified");
|
|
6370
|
+
return retain(root, artifact);
|
|
6371
|
+
},
|
|
6372
|
+
options.signal
|
|
6373
|
+
);
|
|
6176
6374
|
},
|
|
6177
6375
|
options.signal
|
|
6178
6376
|
);
|
|
@@ -6203,6 +6401,7 @@ export {
|
|
|
6203
6401
|
swiftModuleInputFiles,
|
|
6204
6402
|
swiftModuleSdk,
|
|
6205
6403
|
swiftPeachModules,
|
|
6404
|
+
swiftProjectBuildKey,
|
|
6206
6405
|
swiftSdkPaths,
|
|
6207
6406
|
swiftSourceAsIOS,
|
|
6208
6407
|
swiftSourceClosure,
|