peachsim 0.1.2608 → 0.1.2610
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/cli/commands/perf-native.ts +120 -6
- package/cli/drivers/playwright-provisioning.ts +4 -1
- 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 +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +2 -2
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +5 -5
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +3 -3
- package/dist-lib/bundle-channel.cjs +60485 -60177
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +3 -3
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +3 -3
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +2 -2
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +7 -7
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/config.mjs +5 -5
- package/dist-lib/detox/index.cjs +1 -1
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/esm-chunks/{acorn-4QDEL7IO.mjs → acorn-L2SFCOHG.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-4C57RZXG.mjs → chunk-2LJTZ2KG.mjs} +17 -328
- package/dist-lib/esm-chunks/{chunk-X6CONUT6.mjs → chunk-42NDD4R7.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-F724FZHJ.mjs → chunk-73NIGS7D.mjs} +1490 -3950
- package/dist-lib/esm-chunks/{chunk-KNCWQQZG.mjs → chunk-CUBTZPSZ.mjs} +1 -1
- package/dist-lib/esm-chunks/chunk-EU5WMP5O.mjs +322 -0
- package/dist-lib/esm-chunks/{chunk-NXG27NGU.mjs → chunk-EYSNLE5V.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-IKFFQXJN.mjs → chunk-FP447MCW.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-JIW4PICV.mjs → chunk-HMTSU22Q.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-7KU5ROOE.mjs → chunk-KTAGV5U6.mjs} +14 -12
- package/dist-lib/esm-chunks/{chunk-3DUFAH5J.mjs → chunk-MJP4WOSX.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-H3QASOKR.mjs → chunk-MK4DOEDN.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-ZFI5OF6U.mjs → chunk-N3M5KT33.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-F2FHFORX.mjs → chunk-N7XU2WWO.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-UHYHEJ3N.mjs → chunk-RN73P2DY.mjs} +34 -28
- package/dist-lib/esm-chunks/{chunk-VICI67J5.mjs → chunk-VDLPNJ6P.mjs} +1 -1
- package/dist-lib/esm-chunks/chunk-W3LNUIUA.mjs +2655 -0
- package/dist-lib/esm-chunks/{chunk-R25MOOFS.mjs → chunk-WBQFHIGS.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-YBMBAXAZ.mjs → chunk-WZHEW7Z7.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-RTXAZMTP.mjs → chunk-X74N3K5N.mjs} +4 -4
- package/dist-lib/esm-chunks/{chunk-IJX7PBNG.mjs → chunk-XN74REO2.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-RZLGVWHK.mjs → chunk-YLUD2UET.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-BEWJL2LY.mjs → chunk-YVLXYLNV.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-W5EHCHDD.mjs → chunk-YYGSN3BN.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-GPPOU5DO.mjs → chunk-ZZB2LFYV.mjs} +1 -1
- package/dist-lib/esm-chunks/{metro-layout-parser-YWPJI3L6.mjs → metro-layout-parser-VDPXJ7LW.mjs} +3 -3
- package/dist-lib/esm-chunks/{swift-package-prebuilt-MWTLCMQD.mjs → swift-package-prebuilt-HRPDLN2P.mjs} +14 -11
- package/dist-lib/esm-chunks/{swift-sdk-app-module-PF5QMK5X.mjs → swift-sdk-app-module-5DOGMU3M.mjs} +16 -14
- package/dist-lib/esm-chunks/{swift-sdk-image-5IMAACRF.mjs → swift-sdk-image-W3UU4H4L.mjs} +16 -14
- package/dist-lib/esm-chunks/{swift-sdk-image-producer-JPIJI25U.mjs → swift-sdk-image-producer-OJWD6ZOH.mjs} +8 -6
- package/dist-lib/expo-swift-bundle.cjs +42524 -42216
- package/dist-lib/expo-swift-metadata.cjs +1 -1
- package/dist-lib/expo-swift-metadata.mjs +7 -7
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +43716 -43244
- package/dist-lib/host/fetch-proxy-handler.cjs +670 -645
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +3 -3
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +3 -3
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +4 -4
- package/dist-lib/native-app-identity-project.cjs +1499 -2889
- package/dist-lib/native-app-identity-project.mjs +317 -339
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +6 -6
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +3 -3
- package/dist-lib/pdfium-raster.cjs +1 -1
- package/dist-lib/pdfium-raster.mjs +2 -2
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +3 -3
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +166 -154
- package/dist-lib/public-origins-lib.json +141 -198
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +2 -2
- package/dist-lib/reap-browser.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +1 -1
- package/dist-lib/sdk.mjs +8 -8
- package/dist-lib/skills.cjs +38979 -38507
- package/dist-lib/swift-compile.cjs +12239 -12121
- package/dist-lib/swift-compile.mjs +36 -33
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +3 -3
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +6 -6
- package/dist-lib/swift-svg-raster.cjs +1 -1
- package/dist-lib/swift-svg-raster.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
- package/dist-lib/vendor/acorn.cjs +1 -1
- package/dist-lib/vendor/magic-string.cjs +1 -1
- package/dist-lib/vendor/stream-json.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
- package/dist-lib/vendor/sucrase.cjs +1 -1
- package/dist-lib/vendor/terser.cjs +1 -1
- package/dist-lib/vendor/valibot.cjs +1 -1
- package/dist-lib/vendor/ws.cjs +1 -1
- package/dist-lib/vendor/zod.cjs +1 -1
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +3 -3
- package/dist-types/packages/peach-engine/src/ios/apps/canvas-map-data.d.ts +13 -0
- package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +3 -0
- package/package.json +1 -1
- package/src/agent-prompt.ts +15 -2
- package/src/binaryen.lock.json +3 -3
- package/src/genrule-archives.ts +5 -2
- package/src/native-framework-compiler.ts +1 -1
- package/src/native-static-libraries.ts +2 -3
- package/src/native-swift-slices.ts +1 -1
- package/src/nitro-dependencies.ts +3 -7
- package/src/one-native-controls-package.ts +165 -11
- package/src/oneNativeControlsContract.ts +1 -0
- package/src/rive-runtime-dependencies.ts +1 -2
- package/src/swift-compile.ts +165 -1796
- package/src/swift-compiler-digest.ts +2 -0
- package/src/swift-distribution.ts +39 -15
- package/src/swift-objc-compile.ts +194 -32
- package/src/swift-package-manifest.ts +6 -29
- package/src/swift-packages.ts +6 -14
- package/src/swift-sdk-surface.ts +1811 -0
- package/src/swift-standin-digest.ts +28 -5
- package/src/swift-standins.ts +16 -19
- package/src/swift-wasm-archive.ts +200 -0
- package/src/swift-wasm-prune.ts +3 -93
- package/src/swift-wasm64-native-source.ts +4 -2
- package/src/swiftWasm64ConfigContract.ts +10 -0
- package/src/wasm-optimize.ts +18 -14
- package/src/xcode-project.ts +2 -4
|
@@ -0,0 +1,2655 @@
|
|
|
1
|
+
/*! peach v0.1.2610 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
|
|
2
|
+
import {
|
|
3
|
+
SWIFT_CACHE_HOLD_MARKER,
|
|
4
|
+
SWIFT_WASM_TRIPLE,
|
|
5
|
+
refreshSwiftCacheHold,
|
|
6
|
+
swiftCacheDir,
|
|
7
|
+
swiftCompiler,
|
|
8
|
+
swiftEnvironment,
|
|
9
|
+
swiftSdkOptions,
|
|
10
|
+
swiftSourceSdk,
|
|
11
|
+
swiftToolchain,
|
|
12
|
+
terminateProcessGroup,
|
|
13
|
+
wasmThreadFlags,
|
|
14
|
+
windowAdmission
|
|
15
|
+
} from "./chunk-2LJTZ2KG.mjs";
|
|
16
|
+
import {
|
|
17
|
+
isSwiftResourcePath
|
|
18
|
+
} from "./chunk-MK4DOEDN.mjs";
|
|
19
|
+
import {
|
|
20
|
+
swiftManifestDeclarations
|
|
21
|
+
} from "./chunk-CUBTZPSZ.mjs";
|
|
22
|
+
import {
|
|
23
|
+
isRecord
|
|
24
|
+
} from "./chunk-XN74REO2.mjs";
|
|
25
|
+
import {
|
|
26
|
+
__publicField
|
|
27
|
+
} from "./chunk-N3M5KT33.mjs";
|
|
28
|
+
|
|
29
|
+
// src/write-build-file.ts
|
|
30
|
+
import { mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
31
|
+
import path from "node:path";
|
|
32
|
+
function writeBuildFile(file, contents2) {
|
|
33
|
+
const stat = statSync(file, { throwIfNoEntry: false });
|
|
34
|
+
if (stat?.isFile()) {
|
|
35
|
+
if (typeof contents2 === "string") {
|
|
36
|
+
if (readFileSync(file, "utf8") === contents2) return;
|
|
37
|
+
} else if (stat.size === contents2.length && readFileSync(file).equals(contents2)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
42
|
+
writeFileSync(file, contents2);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/swift-objc-standin.ts
|
|
46
|
+
import { execFileSync, spawnSync as spawnSync2 } from "node:child_process";
|
|
47
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
48
|
+
import fs2 from "node:fs";
|
|
49
|
+
import path6 from "node:path";
|
|
50
|
+
|
|
51
|
+
// src/case-insensitive-header-overlay.ts
|
|
52
|
+
import { createHash } from "node:crypto";
|
|
53
|
+
import fs from "node:fs";
|
|
54
|
+
import path2 from "node:path";
|
|
55
|
+
var HEADER = /\.(h|hh|hpp|hxx|inc|inl|def|modulemap|apinotes|tcc)$/i;
|
|
56
|
+
var volumeCaseSensitivity = /* @__PURE__ */ new Map();
|
|
57
|
+
function needsCaseOverlay(directory) {
|
|
58
|
+
if (process.platform !== "darwin") return true;
|
|
59
|
+
const device = fs.statSync(directory).dev;
|
|
60
|
+
const known = volumeCaseSensitivity.get(device);
|
|
61
|
+
if (known !== void 0) return known;
|
|
62
|
+
let probed = false;
|
|
63
|
+
for (const name of fs.readdirSync(directory)) {
|
|
64
|
+
const alternate = name.replace(
|
|
65
|
+
/[a-zA-Z]/,
|
|
66
|
+
(letter) => letter === letter.toLowerCase() ? letter.toUpperCase() : letter.toLowerCase()
|
|
67
|
+
);
|
|
68
|
+
if (alternate === name) continue;
|
|
69
|
+
const original = fs.lstatSync(path2.join(directory, name), { throwIfNoEntry: false });
|
|
70
|
+
if (!original) continue;
|
|
71
|
+
const changed = fs.lstatSync(path2.join(directory, alternate), {
|
|
72
|
+
throwIfNoEntry: false
|
|
73
|
+
});
|
|
74
|
+
if (!changed || original.ino !== changed.ino || original.dev !== changed.dev) {
|
|
75
|
+
volumeCaseSensitivity.set(device, true);
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
probed = true;
|
|
79
|
+
}
|
|
80
|
+
if (probed) volumeCaseSensitivity.set(device, false);
|
|
81
|
+
return !probed;
|
|
82
|
+
}
|
|
83
|
+
function scan(directory, listed) {
|
|
84
|
+
const node = { files: /* @__PURE__ */ new Map(), directories: /* @__PURE__ */ new Map() };
|
|
85
|
+
const entries = fs.readdirSync(directory, { withFileTypes: true }).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
86
|
+
for (const entry of entries) {
|
|
87
|
+
const full = path2.join(directory, entry.name);
|
|
88
|
+
const stat = entry.isSymbolicLink() ? fs.statSync(full, { throwIfNoEntry: false }) : entry;
|
|
89
|
+
if (!stat) continue;
|
|
90
|
+
if (stat.isDirectory()) {
|
|
91
|
+
const child = scan(full, listed);
|
|
92
|
+
if (child.files.size > 0 || child.directories.size > 0)
|
|
93
|
+
node.directories.set(entry.name, child);
|
|
94
|
+
} else if (HEADER.test(entry.name) && (!listed || listed(full)))
|
|
95
|
+
node.files.set(entry.name, full);
|
|
96
|
+
}
|
|
97
|
+
return node;
|
|
98
|
+
}
|
|
99
|
+
function contents(node) {
|
|
100
|
+
return [
|
|
101
|
+
...[...node.directories].map(([name, child]) => ({
|
|
102
|
+
name,
|
|
103
|
+
type: "directory",
|
|
104
|
+
contents: contents(child)
|
|
105
|
+
})),
|
|
106
|
+
...[...node.files].map(([name, file]) => ({
|
|
107
|
+
name,
|
|
108
|
+
type: "file",
|
|
109
|
+
"external-contents": file
|
|
110
|
+
}))
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
var scans = /* @__PURE__ */ new Map();
|
|
114
|
+
var listedScans = /* @__PURE__ */ new WeakMap();
|
|
115
|
+
function caseInsensitiveHeaderOverlay(directory, roots, listed) {
|
|
116
|
+
let known = scans;
|
|
117
|
+
if (listed) {
|
|
118
|
+
known = listedScans.get(listed) ?? /* @__PURE__ */ new Map();
|
|
119
|
+
listedScans.set(listed, known);
|
|
120
|
+
}
|
|
121
|
+
const existing = [...new Set(roots)].filter(
|
|
122
|
+
(root) => fs.existsSync(root) && needsCaseOverlay(root)
|
|
123
|
+
);
|
|
124
|
+
if (existing.length === 0) return null;
|
|
125
|
+
const unique = existing.filter(
|
|
126
|
+
(root) => !existing.some((other) => other !== root && root.startsWith(`${other}/`))
|
|
127
|
+
).sort();
|
|
128
|
+
const roots_ = unique.map((root) => {
|
|
129
|
+
let node = known.get(root);
|
|
130
|
+
if (!node) known.set(root, node = scan(root, listed));
|
|
131
|
+
return { name: root, type: "directory", contents: contents(node) };
|
|
132
|
+
});
|
|
133
|
+
const text = JSON.stringify({ "case-sensitive": "false", roots: roots_, version: 0 });
|
|
134
|
+
const file = path2.join(
|
|
135
|
+
directory,
|
|
136
|
+
`case-insensitive-${createHash("sha256").update(text).digest("hex").slice(0, 16)}.yaml`
|
|
137
|
+
);
|
|
138
|
+
writeBuildFile(file, text);
|
|
139
|
+
return file;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/swift-objc-platform.ts
|
|
143
|
+
import { spawnSync } from "node:child_process";
|
|
144
|
+
import path3 from "node:path";
|
|
145
|
+
var platforms = /* @__PURE__ */ new Map();
|
|
146
|
+
function swiftObjCPlatformFlags(toolchainBin, minimum) {
|
|
147
|
+
const key = `${toolchainBin}:${minimum}`;
|
|
148
|
+
const cached = platforms.get(key);
|
|
149
|
+
if (cached) return cached;
|
|
150
|
+
const version = [
|
|
151
|
+
Math.floor(minimum / 1e4),
|
|
152
|
+
Math.floor(minimum % 1e4 / 100),
|
|
153
|
+
minimum % 100
|
|
154
|
+
].join(".");
|
|
155
|
+
const result = spawnSync(
|
|
156
|
+
path3.join(toolchainBin, "clang"),
|
|
157
|
+
[
|
|
158
|
+
"-target",
|
|
159
|
+
`arm64-apple-ios${version}-simulator`,
|
|
160
|
+
"-dM",
|
|
161
|
+
"-E",
|
|
162
|
+
"-x",
|
|
163
|
+
"objective-c",
|
|
164
|
+
"-"
|
|
165
|
+
],
|
|
166
|
+
{
|
|
167
|
+
input: "",
|
|
168
|
+
encoding: "utf8",
|
|
169
|
+
env: swiftEnvironment(),
|
|
170
|
+
timeout: 3e4,
|
|
171
|
+
maxBuffer: 1024 * 1024
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
if (result.error || result.status !== 0)
|
|
175
|
+
throw new Error(
|
|
176
|
+
`could not read iOS compiler platform predefines: ${result.error?.message ?? result.stderr}`
|
|
177
|
+
);
|
|
178
|
+
const flags = [
|
|
179
|
+
...result.stdout.matchAll(
|
|
180
|
+
/^#define (TARGET_OS_\w+|TARGET_IPHONE_SIMULATOR|__APPLE\w*__|__MACH__|__ENVIRONMENT_\w+|__nonnull|__nullable|__null_unspecified) (.*)$/gm
|
|
181
|
+
)
|
|
182
|
+
].map(([, name, value]) => `-D${name}=${value}`);
|
|
183
|
+
if (!flags.includes("-D__APPLE__=1") || !flags.includes("-D__MACH__=1"))
|
|
184
|
+
throw new Error("iOS compiler platform predefines lack Apple and Mach identity");
|
|
185
|
+
platforms.set(key, flags);
|
|
186
|
+
return flags;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// src/swift-objc-sdk.ts
|
|
190
|
+
import path5 from "node:path";
|
|
191
|
+
|
|
192
|
+
// src/swift-objc-sdk-tree.ts
|
|
193
|
+
import { readdirSync, readFileSync as readFileSync2 } from "node:fs";
|
|
194
|
+
import path4 from "node:path";
|
|
195
|
+
|
|
196
|
+
// src/swift-objc-sdk.ts
|
|
197
|
+
var IOS_SDK_TARGET = "arm64-apple-ios16.0-simulator";
|
|
198
|
+
|
|
199
|
+
// src/swift-objc-standin.ts
|
|
200
|
+
var NATIVE_GRAPH_SDK_VERSION = "27.1";
|
|
201
|
+
var WASI_EMULATION = [
|
|
202
|
+
"_WASI_EMULATED_SIGNAL",
|
|
203
|
+
"_WASI_EMULATED_MMAN",
|
|
204
|
+
"_WASI_EMULATED_PROCESS_CLOCKS"
|
|
205
|
+
];
|
|
206
|
+
var WASI_EMULATION_FLAGS = WASI_EMULATION.map((name) => `-D${name}`);
|
|
207
|
+
var NATIVE_GRAPH_INPUTS = {
|
|
208
|
+
sdk: NATIVE_GRAPH_SDK_VERSION,
|
|
209
|
+
settings: "e68503e5e534e9194af5efe8c636ca8b824e2d8237c5f38ec84aa4d155bc8418",
|
|
210
|
+
build: "ff785237ba22f1d8f347a5c4f4c68400a387c6d935ef3a443545a72faef57e70",
|
|
211
|
+
compiler: "Apple Swift version 6.4 (swiftlang-6.4.0.34.1 clang-2100.3.34.1)",
|
|
212
|
+
target: IOS_SDK_TARGET
|
|
213
|
+
};
|
|
214
|
+
var NATIVE_GRAPH_ID = createHash2("sha256").update(JSON.stringify(NATIVE_GRAPH_INPUTS)).digest("hex");
|
|
215
|
+
function objcSdkIntakeFlags(headers, toolchainBin, minimum) {
|
|
216
|
+
const caseOverlay = caseInsensitiveHeaderOverlay(
|
|
217
|
+
path6.join(swiftCacheDir(), "swift-header-case"),
|
|
218
|
+
[
|
|
219
|
+
path6.join(headers, "System/Library/Frameworks"),
|
|
220
|
+
path6.join(headers, "wasm/include"),
|
|
221
|
+
path6.join(headers, "wasm/intrinsics"),
|
|
222
|
+
path6.join(headers, "usr/include")
|
|
223
|
+
]
|
|
224
|
+
);
|
|
225
|
+
return [
|
|
226
|
+
...swiftObjCPlatformFlags(toolchainBin, minimum),
|
|
227
|
+
...caseOverlay ? ["-ivfsoverlay", caseOverlay] : [],
|
|
228
|
+
// AvailabilityInternal.h derives these through __is_target_os(ios), which
|
|
229
|
+
// is false for wasm64. the maximum is the sdk the headers come from, as
|
|
230
|
+
// xcode defines it, so `#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_26_0`
|
|
231
|
+
// sources see the members the sdk declares instead of a 17.0 default.
|
|
232
|
+
`-D__IPHONE_OS_VERSION_MIN_REQUIRED=${minimum}`,
|
|
233
|
+
`-D__IPHONE_OS_VERSION_MAX_ALLOWED=__IPHONE_${NATIVE_GRAPH_SDK_VERSION.replace(".", "_")}`,
|
|
234
|
+
// the installed libc's default feature set otherwise defines
|
|
235
|
+
// _XOPEN_SOURCE, which darwin's sys/cdefs.h turns into a strict posix
|
|
236
|
+
// level; iOS compiles at darwin's full level with neither defined.
|
|
237
|
+
"-D_BSD_SOURCE",
|
|
238
|
+
// the installed icu archive exports its swift_-prefixed names, which the
|
|
239
|
+
// unicode headers rename to only off darwin.
|
|
240
|
+
"-DU_DISABLE_RENAMING=0",
|
|
241
|
+
// clang enables blocks in every language for darwin targets, and the sdk
|
|
242
|
+
// headers declare block types unguarded.
|
|
243
|
+
"-fblocks",
|
|
244
|
+
...WASI_EMULATION_FLAGS,
|
|
245
|
+
"-iframework",
|
|
246
|
+
path6.join(headers, "System/Library/Frameworks"),
|
|
247
|
+
"-isystem",
|
|
248
|
+
path6.join(headers, "wasm/include"),
|
|
249
|
+
// compiler intrinsics an arm64 unit includes, ahead of clang's arm-only ones.
|
|
250
|
+
"-isystem",
|
|
251
|
+
path6.join(headers, "wasm/intrinsics"),
|
|
252
|
+
// libxml2 headers sit one level deeper, as in the iOS sdk: a unit
|
|
253
|
+
// includes <libxml/parser.h> through usr/include/libxml2, never the parent.
|
|
254
|
+
"-I",
|
|
255
|
+
path6.join(headers, "usr/include/libxml2"),
|
|
256
|
+
"-idirafter",
|
|
257
|
+
path6.join(headers, "usr/include")
|
|
258
|
+
];
|
|
259
|
+
}
|
|
260
|
+
function iosDeploymentMinimum(version) {
|
|
261
|
+
const parts = /^(\d{1,2})(?:\.(\d{1,2}))?(?:\.(\d{1,2}))?$/.exec(version ?? "");
|
|
262
|
+
if (!parts) return void 0;
|
|
263
|
+
return Number(parts[1]) * 1e4 + Number(parts[2] ?? 0) * 100 + Number(parts[3] ?? 0);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// src/swift-distribution-contract.ts
|
|
267
|
+
var SWIFT_DISTRIBUTION_MANIFEST = "distribution.json";
|
|
268
|
+
var SWIFT_DISTRIBUTION_OBJC_SELECTORS = "objc-selectors.json";
|
|
269
|
+
var SWIFT_DISTRIBUTION_HOSTS = [
|
|
270
|
+
"darwin-arm64",
|
|
271
|
+
"linux-x64",
|
|
272
|
+
"linux-arm64"
|
|
273
|
+
];
|
|
274
|
+
var isStrings = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
275
|
+
function parseSwiftDistributionManifest(value) {
|
|
276
|
+
if (!isRecord(value) || typeof value.id !== "string" || typeof value.release !== "string" || typeof value.wasmSdkId !== "string" || typeof value.wasmSdkUrl !== "string" || typeof value.wasmSdkChecksum !== "string" || !isStrings(value.modules) || !isStrings(value.objects) || !isStrings(value.link) || !isRecord(value.files) || !Object.values(value.files).every((sha) => typeof sha === "string") || typeof value.host !== "string" || !isStrings(value.plugins)) {
|
|
277
|
+
throw new Error(`invalid Swift distribution ${SWIFT_DISTRIBUTION_MANIFEST}`);
|
|
278
|
+
}
|
|
279
|
+
const host = SWIFT_DISTRIBUTION_HOSTS.find((candidate) => candidate === value.host);
|
|
280
|
+
if (!host) throw new Error(`Swift distribution names an unknown host ${value.host}`);
|
|
281
|
+
return {
|
|
282
|
+
id: value.id,
|
|
283
|
+
release: value.release,
|
|
284
|
+
wasmSdkId: value.wasmSdkId,
|
|
285
|
+
wasmSdkUrl: value.wasmSdkUrl,
|
|
286
|
+
wasmSdkChecksum: value.wasmSdkChecksum,
|
|
287
|
+
modules: value.modules,
|
|
288
|
+
objects: value.objects,
|
|
289
|
+
link: value.link,
|
|
290
|
+
files: Object.fromEntries(
|
|
291
|
+
Object.entries(value.files).map(([file, sha]) => [file, String(sha)])
|
|
292
|
+
),
|
|
293
|
+
host,
|
|
294
|
+
plugins: value.plugins
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function parseSwiftDistributionLock(value) {
|
|
298
|
+
if (!isRecord(value) || typeof value.id !== "string" || !/^[a-f0-9]{16}$/.test(value.id) || value.archive !== void 0 && value.archive !== "tar.gz" && value.archive !== "tar.zst" || typeof value.release !== "string" || typeof value.wasmSdkId !== "string" || typeof value.wasmSdkUrl !== "string" || typeof value.wasmSdkChecksum !== "string" || typeof value.source !== "string" || !isStrings(value.targets) || !isRecord(value.systemEnvironment) || !Object.values(value.systemEnvironment).every(isStrings) || !isRecord(value.hosts)) {
|
|
299
|
+
throw new Error("invalid Swift distribution lock");
|
|
300
|
+
}
|
|
301
|
+
const hosts = value.hosts;
|
|
302
|
+
const publication = (runtime) => {
|
|
303
|
+
if (runtime === void 0) return void 0;
|
|
304
|
+
if (!isRecord(runtime) || typeof runtime.source !== "string" || !/^[a-f0-9]{64}$/.test(runtime.source) || typeof runtime.url !== "string" || !/^https:\/\/[a-z0-9.-]+(?::\d+)?\/compile\/asset\/[a-f0-9]{64}$/.test(
|
|
305
|
+
runtime.url
|
|
306
|
+
) || runtime.dataPlan !== void 0 && (typeof runtime.dataPlan !== "string" || !/^[a-f0-9]{64}$/.test(runtime.dataPlan)))
|
|
307
|
+
throw new Error("invalid shared SDK runtime publication in Swift distribution lock");
|
|
308
|
+
return {
|
|
309
|
+
source: runtime.source,
|
|
310
|
+
url: runtime.url,
|
|
311
|
+
...runtime.dataPlan && { dataPlan: runtime.dataPlan }
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
const sdkRuntime = publication(value.sdkRuntime);
|
|
315
|
+
const sdkGuestRuntime = publication(value.sdkGuestRuntime);
|
|
316
|
+
const entry = (host) => {
|
|
317
|
+
const item = hosts[host];
|
|
318
|
+
if (!isRecord(item) || typeof item.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(item.sha256) || typeof item.size !== "number") {
|
|
319
|
+
throw new Error(`invalid Swift distribution lock entry for ${host}`);
|
|
320
|
+
}
|
|
321
|
+
return { sha256: item.sha256, size: item.size };
|
|
322
|
+
};
|
|
323
|
+
return {
|
|
324
|
+
id: value.id,
|
|
325
|
+
release: value.release,
|
|
326
|
+
archive: value.archive ?? "tar.gz",
|
|
327
|
+
wasmSdkId: value.wasmSdkId,
|
|
328
|
+
wasmSdkUrl: value.wasmSdkUrl,
|
|
329
|
+
wasmSdkChecksum: value.wasmSdkChecksum,
|
|
330
|
+
source: value.source,
|
|
331
|
+
targets: value.targets,
|
|
332
|
+
systemEnvironment: Object.fromEntries(
|
|
333
|
+
Object.entries(value.systemEnvironment).map(([key, values]) => {
|
|
334
|
+
if (!isStrings(values))
|
|
335
|
+
throw new Error(`invalid Swift system environment values for ${key}`);
|
|
336
|
+
return [key, values];
|
|
337
|
+
})
|
|
338
|
+
),
|
|
339
|
+
hosts: {
|
|
340
|
+
"darwin-arm64": entry("darwin-arm64"),
|
|
341
|
+
"linux-x64": entry("linux-x64"),
|
|
342
|
+
"linux-arm64": entry("linux-arm64")
|
|
343
|
+
},
|
|
344
|
+
...sdkRuntime ? { sdkRuntime } : {},
|
|
345
|
+
...sdkGuestRuntime ? { sdkGuestRuntime } : {}
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// src/swift-lexical.ts
|
|
350
|
+
var SWIFT_SCAN_KEYWORDS = {
|
|
351
|
+
c: "class",
|
|
352
|
+
e: "extension",
|
|
353
|
+
o: "override",
|
|
354
|
+
i: "import",
|
|
355
|
+
f: "func",
|
|
356
|
+
U: "UIApplicationMain",
|
|
357
|
+
F: "Foundation",
|
|
358
|
+
C: "CoreFoundation",
|
|
359
|
+
O: "ObjectiveC",
|
|
360
|
+
_: "_LocationEssentials"
|
|
361
|
+
};
|
|
362
|
+
function swiftCodeScan(source) {
|
|
363
|
+
const starts = /* @__PURE__ */ new Set();
|
|
364
|
+
const tokens = [];
|
|
365
|
+
const stack = [{ kind: "code", parens: 0 }];
|
|
366
|
+
const hashesAt = (at) => {
|
|
367
|
+
let end = at;
|
|
368
|
+
while (source[end] === "#") end++;
|
|
369
|
+
return end - at;
|
|
370
|
+
};
|
|
371
|
+
const closes = (at, hashes) => source.startsWith("#".repeat(hashes), at);
|
|
372
|
+
let i = 0;
|
|
373
|
+
while (i < source.length) {
|
|
374
|
+
const top = stack[stack.length - 1];
|
|
375
|
+
if ((i === 0 || source[i - 1] === "\n") && top.kind === "code" && stack.length === 1)
|
|
376
|
+
starts.add(i);
|
|
377
|
+
const char = source[i];
|
|
378
|
+
if (top.kind === "block") {
|
|
379
|
+
if (source.startsWith("/*", i)) {
|
|
380
|
+
top.depth++;
|
|
381
|
+
i += 2;
|
|
382
|
+
} else if (source.startsWith("*/", i)) {
|
|
383
|
+
if (--top.depth === 0) stack.pop();
|
|
384
|
+
i += 2;
|
|
385
|
+
} else i++;
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
if (top.kind === "string") {
|
|
389
|
+
if (char === "\\" && closes(i + 1, top.hashes)) {
|
|
390
|
+
const after = i + 1 + top.hashes;
|
|
391
|
+
if (source[after] === "(") {
|
|
392
|
+
stack.push({ kind: "code", parens: 0 });
|
|
393
|
+
i = after + 1;
|
|
394
|
+
} else i = after + 1;
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
const quote = top.multiline ? '"""' : '"';
|
|
398
|
+
if (source.startsWith(quote, i) && closes(i + quote.length, top.hashes)) {
|
|
399
|
+
stack.pop();
|
|
400
|
+
i += quote.length + top.hashes;
|
|
401
|
+
} else i++;
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
if (top.kind === "regex") {
|
|
405
|
+
if (char === "/" && closes(i + 1, top.hashes)) {
|
|
406
|
+
stack.pop();
|
|
407
|
+
i += 1 + top.hashes;
|
|
408
|
+
} else i++;
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
if (source.startsWith("//", i)) {
|
|
412
|
+
const end = source.indexOf("\n", i);
|
|
413
|
+
i = end === -1 ? source.length : end;
|
|
414
|
+
} else if (source.startsWith("/*", i)) {
|
|
415
|
+
stack.push({ kind: "block", depth: 1 });
|
|
416
|
+
i += 2;
|
|
417
|
+
} else if (char === '"' || char === "#") {
|
|
418
|
+
const hashes = hashesAt(i);
|
|
419
|
+
const at = i + hashes;
|
|
420
|
+
if (source.startsWith('"""', at)) {
|
|
421
|
+
stack.push({ kind: "string", hashes, multiline: true });
|
|
422
|
+
i = at + 3;
|
|
423
|
+
} else if (source[at] === '"') {
|
|
424
|
+
stack.push({ kind: "string", hashes, multiline: false });
|
|
425
|
+
i = at + 1;
|
|
426
|
+
} else if (hashes > 0 && source[at] === "/") {
|
|
427
|
+
stack.push({ kind: "regex", hashes });
|
|
428
|
+
i = at + 1;
|
|
429
|
+
} else {
|
|
430
|
+
if (hashes > 0) tokens.push(at - 1);
|
|
431
|
+
i = Math.max(at, i + 1);
|
|
432
|
+
}
|
|
433
|
+
} else if (char === "{" || char === "}") {
|
|
434
|
+
tokens.push(i);
|
|
435
|
+
i++;
|
|
436
|
+
} else if (char === "(") {
|
|
437
|
+
top.parens++;
|
|
438
|
+
i++;
|
|
439
|
+
} else if (char === ")") {
|
|
440
|
+
if (top.parens === 0 && stack.length > 1) stack.pop();
|
|
441
|
+
else top.parens--;
|
|
442
|
+
i++;
|
|
443
|
+
} else {
|
|
444
|
+
const keyword = SWIFT_SCAN_KEYWORDS[char];
|
|
445
|
+
if (keyword && source.startsWith(keyword, i) && !/[\w$]/.test(source[i - 1] ?? "") && !/[\w$]/.test(source[i + keyword.length] ?? "")) {
|
|
446
|
+
tokens.push(i);
|
|
447
|
+
i += keyword.length;
|
|
448
|
+
} else {
|
|
449
|
+
if (char === "@") tokens.push(i);
|
|
450
|
+
i++;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return { lineStarts: starts, tokens };
|
|
455
|
+
}
|
|
456
|
+
function mapSwiftConditionalLines(source, lineStarts, map) {
|
|
457
|
+
let offset = 0;
|
|
458
|
+
return source.split("\n").map((line) => {
|
|
459
|
+
const start = offset;
|
|
460
|
+
offset += line.length + 1;
|
|
461
|
+
return lineStarts.has(start) && /^[ \t]*#(?:if|elseif)\b/.test(line) ? map(line) : line;
|
|
462
|
+
}).join("\n");
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// src/swift-shared-sdk.ts
|
|
466
|
+
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
467
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
468
|
+
import fs3, { readdirSync as readdirSync2, readFileSync as readFileSync3 } from "node:fs";
|
|
469
|
+
import path7 from "node:path";
|
|
470
|
+
var SWIFT_DISTRIBUTION_MIRROR_RECORD = ".peach-mirror.json";
|
|
471
|
+
var distributionHeaderRoots = /* @__PURE__ */ new Map();
|
|
472
|
+
function swiftSharedSdkSourceRoot(moduleRoot, distribution) {
|
|
473
|
+
return path7.resolve(moduleRoot, distribution ? "sdk/ios" : "../peachsim/sdk/ios");
|
|
474
|
+
}
|
|
475
|
+
function swiftSharedSdkRoot(moduleRoot, distribution) {
|
|
476
|
+
const root = swiftSharedSdkSourceRoot(moduleRoot, distribution);
|
|
477
|
+
if (!distribution || fs3.existsSync(path7.join(moduleRoot, SWIFT_DISTRIBUTION_MIRROR_RECORD)))
|
|
478
|
+
return root;
|
|
479
|
+
let headers = distributionHeaderRoots.get(root);
|
|
480
|
+
if (!headers || !fs3.existsSync(headers)) {
|
|
481
|
+
const files = readdirSync2(root, { recursive: true, withFileTypes: true }).filter((entry) => entry.isFile()).map((entry) => path7.relative(root, path7.join(entry.parentPath, entry.name))).sort();
|
|
482
|
+
const hash = createHash3("sha256");
|
|
483
|
+
for (const file of files) {
|
|
484
|
+
const bytes = readFileSync3(path7.join(root, file));
|
|
485
|
+
hash.update(JSON.stringify([file, bytes.length])).update(bytes);
|
|
486
|
+
}
|
|
487
|
+
headers = path7.join(
|
|
488
|
+
swiftCacheDir(),
|
|
489
|
+
"swift-sdk-views",
|
|
490
|
+
`headers-${hash.digest("hex")}`
|
|
491
|
+
);
|
|
492
|
+
if (!fs3.existsSync(headers)) {
|
|
493
|
+
fs3.mkdirSync(path7.dirname(headers), { recursive: true });
|
|
494
|
+
const staging = fs3.mkdtempSync(`${headers}-`);
|
|
495
|
+
fs3.chmodSync(staging, 493);
|
|
496
|
+
fs3.cpSync(root, staging, { recursive: true, preserveTimestamps: true });
|
|
497
|
+
try {
|
|
498
|
+
fs3.renameSync(staging, headers);
|
|
499
|
+
} catch (error) {
|
|
500
|
+
fs3.rmSync(staging, { recursive: true, force: true });
|
|
501
|
+
if (!fs3.existsSync(headers)) throw error;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
distributionHeaderRoots.set(root, headers);
|
|
505
|
+
}
|
|
506
|
+
const now = /* @__PURE__ */ new Date();
|
|
507
|
+
fs3.utimesSync(headers, now, now);
|
|
508
|
+
refreshSwiftCacheHold(headers);
|
|
509
|
+
return headers;
|
|
510
|
+
}
|
|
511
|
+
function swiftSharedSdkFlags(moduleRoot, distribution) {
|
|
512
|
+
const root = swiftSharedSdkRoot(moduleRoot, distribution);
|
|
513
|
+
return [
|
|
514
|
+
...wasmThreadFlags,
|
|
515
|
+
"-isystem",
|
|
516
|
+
path7.join(root, "wasm/storage-include"),
|
|
517
|
+
"-idirafter",
|
|
518
|
+
path7.join(root, "usr/include")
|
|
519
|
+
];
|
|
520
|
+
}
|
|
521
|
+
function readULEB(b, o) {
|
|
522
|
+
let res = 0;
|
|
523
|
+
let shift = 0;
|
|
524
|
+
let p = o;
|
|
525
|
+
while (true) {
|
|
526
|
+
const byte = b[p++];
|
|
527
|
+
res |= (byte & 127) << shift;
|
|
528
|
+
if ((byte & 128) === 0) break;
|
|
529
|
+
shift += 7;
|
|
530
|
+
}
|
|
531
|
+
return [res, p];
|
|
532
|
+
}
|
|
533
|
+
var WEAKEN_FOUNDATION_SYMS = /* @__PURE__ */ new Set([
|
|
534
|
+
"$s10Foundation6BundleC22preferredLocalizations4from14forPreferencesSaySSGAG_AGSgtFZ",
|
|
535
|
+
"$s10Foundation6BundleC22preferredLocalizations4fromSaySSGAF_tFZ",
|
|
536
|
+
"$s10Foundation6BundleC22preferredLocalizationsSaySSGvg",
|
|
537
|
+
"$s10Foundation16NSSortDescriptorC3key9ascendingACSSSg_SbtcfC",
|
|
538
|
+
"$s10Foundation16NSSortDescriptorC3key9ascendingACSSSg_Sbtcfc",
|
|
539
|
+
"$s10Foundation16NSSortDescriptorC3keySSSgvg",
|
|
540
|
+
"$s10Foundation16NSSortDescriptorC7keyPath9ascendingACs03KeyE0Cyxq_G_SbtcSLR_r0_lufC",
|
|
541
|
+
"$s10Foundation16NSSortDescriptorC7keyPath9ascendingACs03KeyE0Cyxq_G_SbtcSLR_r0_lufc"
|
|
542
|
+
]);
|
|
543
|
+
function weakenFoundationSymbolsInWasmObj(buf) {
|
|
544
|
+
let pos = 8;
|
|
545
|
+
while (pos < buf.length) {
|
|
546
|
+
const id = buf[pos++];
|
|
547
|
+
const [sz, p] = readULEB(buf, pos);
|
|
548
|
+
const end = p + sz;
|
|
549
|
+
if (id === 0) {
|
|
550
|
+
const [nLen, np] = readULEB(buf, p);
|
|
551
|
+
const name = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
|
|
552
|
+
const cp = np + nLen;
|
|
553
|
+
if (name === "linking") {
|
|
554
|
+
let [, lp] = readULEB(buf, cp);
|
|
555
|
+
while (lp < end) {
|
|
556
|
+
const subId = buf[lp++];
|
|
557
|
+
const [subLen, sp] = readULEB(buf, lp);
|
|
558
|
+
const subEnd = sp + subLen;
|
|
559
|
+
if (subId === 8) {
|
|
560
|
+
let [cnt, cur] = readULEB(buf, sp);
|
|
561
|
+
for (let i = 0; i < cnt; i++) {
|
|
562
|
+
const kind = buf[cur++];
|
|
563
|
+
const flOffset = cur;
|
|
564
|
+
const [fl, c2] = readULEB(buf, cur);
|
|
565
|
+
cur = c2;
|
|
566
|
+
const isUndef = (fl & 16) !== 0;
|
|
567
|
+
const isExplicitName = (fl & 64) !== 0;
|
|
568
|
+
if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
|
|
569
|
+
const [, c3] = readULEB(buf, cur);
|
|
570
|
+
cur = c3;
|
|
571
|
+
if (!isUndef || isExplicitName) {
|
|
572
|
+
const [sLen, c4] = readULEB(buf, cur);
|
|
573
|
+
const sName = Buffer.from(buf.subarray(c4, c4 + sLen)).toString("utf8");
|
|
574
|
+
if (!isUndef && kind === 0 && WEAKEN_FOUNDATION_SYMS.has(sName)) {
|
|
575
|
+
buf[flOffset] = buf[flOffset] & ~3 | 1;
|
|
576
|
+
}
|
|
577
|
+
cur = c4 + sLen;
|
|
578
|
+
}
|
|
579
|
+
} else if (kind === 1) {
|
|
580
|
+
const [sLen, c3] = readULEB(buf, cur);
|
|
581
|
+
cur = c3 + sLen;
|
|
582
|
+
if (!isUndef) {
|
|
583
|
+
const [, c4] = readULEB(buf, cur);
|
|
584
|
+
const [, c5] = readULEB(buf, c4);
|
|
585
|
+
const [, c6] = readULEB(buf, c5);
|
|
586
|
+
cur = c6;
|
|
587
|
+
}
|
|
588
|
+
} else if (kind === 3) {
|
|
589
|
+
const [, c3] = readULEB(buf, cur);
|
|
590
|
+
cur = c3;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
lp = subEnd;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
pos = end;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
function weakenFoundationOverridesInArchive(arBuf) {
|
|
602
|
+
let gnuNames = null;
|
|
603
|
+
let pos = 8;
|
|
604
|
+
while (pos + 60 <= arBuf.length) {
|
|
605
|
+
const rawName = Buffer.from(arBuf.subarray(pos, pos + 16)).toString("ascii");
|
|
606
|
+
const size = Number.parseInt(
|
|
607
|
+
Buffer.from(arBuf.subarray(pos + 48, pos + 58)).toString("ascii").trim(),
|
|
608
|
+
10
|
|
609
|
+
);
|
|
610
|
+
pos += 60;
|
|
611
|
+
if (Number.isNaN(size) || pos + size > arBuf.length) break;
|
|
612
|
+
let bodyStart = pos;
|
|
613
|
+
const bodyEnd = pos + size;
|
|
614
|
+
let name = rawName.trim();
|
|
615
|
+
if (rawName.startsWith("#1/")) {
|
|
616
|
+
const nLen = Number.parseInt(rawName.slice(3).trim(), 10);
|
|
617
|
+
name = Buffer.from(arBuf.subarray(bodyStart, bodyStart + nLen)).toString("utf8").replace(/\0+$/, "");
|
|
618
|
+
bodyStart += nLen;
|
|
619
|
+
} else if (rawName.startsWith("//")) {
|
|
620
|
+
gnuNames = arBuf.subarray(bodyStart, bodyEnd);
|
|
621
|
+
pos = bodyEnd + (size & 1);
|
|
622
|
+
continue;
|
|
623
|
+
} else if (rawName.startsWith("/") && gnuNames) {
|
|
624
|
+
const offStr = rawName.slice(1).trim();
|
|
625
|
+
if (offStr.length > 0 && /^\d+$/.test(offStr)) {
|
|
626
|
+
const off = Number.parseInt(offStr, 10);
|
|
627
|
+
let end = off;
|
|
628
|
+
while (end < gnuNames.length && gnuNames[end] !== 10 && gnuNames[end] !== 47) {
|
|
629
|
+
end++;
|
|
630
|
+
}
|
|
631
|
+
name = Buffer.from(gnuNames.subarray(off, end)).toString("utf8");
|
|
632
|
+
} else {
|
|
633
|
+
pos = bodyEnd + (size & 1);
|
|
634
|
+
continue;
|
|
635
|
+
}
|
|
636
|
+
} else if (name.endsWith("/")) {
|
|
637
|
+
name = name.slice(0, -1);
|
|
638
|
+
}
|
|
639
|
+
if (name.endsWith("Bundle.o") || name.endsWith("NSSortDescriptor.o")) {
|
|
640
|
+
weakenFoundationSymbolsInWasmObj(arBuf.subarray(bodyStart, bodyEnd));
|
|
641
|
+
}
|
|
642
|
+
pos = bodyEnd + (size & 1);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
function mirrorTree(real, mirror, overrides) {
|
|
646
|
+
fs3.mkdirSync(mirror);
|
|
647
|
+
for (const entry of fs3.readdirSync(real, { withFileTypes: true })) {
|
|
648
|
+
const from = path7.join(real, entry.name);
|
|
649
|
+
const to = path7.join(mirror, entry.name);
|
|
650
|
+
const override = overrides.get(from);
|
|
651
|
+
if (override) fs3.symlinkSync(override, to);
|
|
652
|
+
else if (fs3.statSync(from).isDirectory()) mirrorTree(from, to, overrides);
|
|
653
|
+
else fs3.symlinkSync(from, to);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
function stageOverlaySlot(realRoot, stagingRoot, relPath) {
|
|
657
|
+
const segments = relPath.split(path7.sep);
|
|
658
|
+
let real = realRoot;
|
|
659
|
+
let mirror = stagingRoot;
|
|
660
|
+
for (let i = 0; i < segments.length; i++) {
|
|
661
|
+
const segment = segments[i];
|
|
662
|
+
for (const entry of readdirSync2(real)) {
|
|
663
|
+
if (entry === segment || i === 0 && entry === SWIFT_CACHE_HOLD_MARKER) continue;
|
|
664
|
+
if (mirror === stagingRoot && entry === "configuration") continue;
|
|
665
|
+
const dest = path7.join(mirror, entry);
|
|
666
|
+
if (!fs3.lstatSync(dest, { throwIfNoEntry: false })) {
|
|
667
|
+
fs3.symlinkSync(path7.join(real, entry), dest);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
real = path7.join(real, segment);
|
|
671
|
+
mirror = path7.join(mirror, segment);
|
|
672
|
+
if (i < segments.length - 1) {
|
|
673
|
+
if (fs3.lstatSync(mirror, { throwIfNoEntry: false })?.isSymbolicLink()) {
|
|
674
|
+
fs3.unlinkSync(mirror);
|
|
675
|
+
}
|
|
676
|
+
fs3.mkdirSync(mirror, { recursive: true });
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
if (fs3.lstatSync(mirror, { throwIfNoEntry: false })?.isSymbolicLink()) {
|
|
680
|
+
fs3.unlinkSync(mirror);
|
|
681
|
+
}
|
|
682
|
+
return mirror;
|
|
683
|
+
}
|
|
684
|
+
var sdkViews = /* @__PURE__ */ new Map();
|
|
685
|
+
function swiftSharedSdkViewOptions(moduleRoot, distribution, toolchainBin, sdk) {
|
|
686
|
+
const sdkRoot = swiftSharedSdkRoot(moduleRoot, distribution);
|
|
687
|
+
const frameworks = path7.join(sdkRoot, "System/Library/Frameworks");
|
|
688
|
+
const overlay = path7.join(sdkRoot, "wasm");
|
|
689
|
+
const overlayFiles = ["include", "storage-include"].flatMap(
|
|
690
|
+
(directory) => readdirSync2(path7.join(overlay, directory), {
|
|
691
|
+
recursive: true,
|
|
692
|
+
withFileTypes: true
|
|
693
|
+
})
|
|
694
|
+
).filter((entry) => entry.isFile()).map((entry) => path7.join(entry.parentPath, entry.name)).sort();
|
|
695
|
+
const hasDarwinTcp = overlayFiles.includes(path7.join(overlay, "include/netinet/tcp.h"));
|
|
696
|
+
const hasDarwinTermios = fs3.existsSync(path7.join(sdkRoot, "usr/include/termios.h"));
|
|
697
|
+
const stdint = path7.join(overlay, "include/stdint.h");
|
|
698
|
+
const key = JSON.stringify([
|
|
699
|
+
// bump the recipe when the transformation changes; bundling changes function text.
|
|
700
|
+
"v39",
|
|
701
|
+
[...WEAKEN_FOUNDATION_SYMS],
|
|
702
|
+
toolchainBin,
|
|
703
|
+
sdk,
|
|
704
|
+
frameworks,
|
|
705
|
+
overlayFiles,
|
|
706
|
+
swiftSdkOptions(),
|
|
707
|
+
...hasDarwinTcp ? ["darwin-tcp-module"] : [],
|
|
708
|
+
...hasDarwinTermios ? ["darwin-termios"] : [],
|
|
709
|
+
// the view copies this overlay, so its bytes name the view
|
|
710
|
+
overlayFiles.includes(stdint) ? fs3.readFileSync(stdint, "utf8") : null
|
|
711
|
+
]);
|
|
712
|
+
const cached = sdkViews.get(key);
|
|
713
|
+
if (cached && fs3.existsSync(cached.manifest)) return touchSdkView(cached.options);
|
|
714
|
+
const configuration = execFileSync2(
|
|
715
|
+
path7.join(toolchainBin, "swift"),
|
|
716
|
+
[
|
|
717
|
+
"sdk",
|
|
718
|
+
"configure",
|
|
719
|
+
...swiftSdkOptions(),
|
|
720
|
+
"--show-configuration",
|
|
721
|
+
sdk,
|
|
722
|
+
SWIFT_WASM_TRIPLE
|
|
723
|
+
],
|
|
724
|
+
{ encoding: "utf8", env: swiftEnvironment(), stdio: ["ignore", "pipe", "pipe"] }
|
|
725
|
+
);
|
|
726
|
+
const sysroot = /^sdkRootPath: (.+)$/m.exec(configuration)?.[1]?.trim();
|
|
727
|
+
if (!sysroot || !path7.isAbsolute(sysroot))
|
|
728
|
+
throw new Error(`swift sdk ${sdk} reports no absolute sdkRootPath`);
|
|
729
|
+
let bundle = sysroot;
|
|
730
|
+
while (!bundle.endsWith(".artifactbundle")) {
|
|
731
|
+
if (path7.dirname(bundle) === bundle)
|
|
732
|
+
throw new Error(`swift sdk ${sdk} is outside an artifact bundle`);
|
|
733
|
+
bundle = path7.dirname(bundle);
|
|
734
|
+
}
|
|
735
|
+
const foundationArchive = path7.join(
|
|
736
|
+
path7.dirname(sysroot),
|
|
737
|
+
"swift.xctoolchain/usr/lib/swift_static/wasi/libFoundation.a"
|
|
738
|
+
);
|
|
739
|
+
const foundationBytes = fs3.existsSync(foundationArchive) ? new Uint8Array(fs3.readFileSync(foundationArchive)) : void 0;
|
|
740
|
+
const view = path7.join(
|
|
741
|
+
swiftCacheDir(),
|
|
742
|
+
"swift-sdk-views",
|
|
743
|
+
createHash3("sha256").update(key).update(foundationBytes ?? "").digest("hex").slice(0, 16)
|
|
744
|
+
);
|
|
745
|
+
const manifest = path7.join(view, path7.basename(bundle), "info.json");
|
|
746
|
+
const intact = () => !fs3.lstatSync(path7.join(view, SWIFT_CACHE_HOLD_MARKER), {
|
|
747
|
+
throwIfNoEntry: false
|
|
748
|
+
})?.isSymbolicLink() && fs3.existsSync(manifest) && fs3.readdirSync(
|
|
749
|
+
path7.join(
|
|
750
|
+
view,
|
|
751
|
+
path7.relative(path7.dirname(bundle), sysroot),
|
|
752
|
+
"darwin/usr/include"
|
|
753
|
+
),
|
|
754
|
+
{ withFileTypes: true }
|
|
755
|
+
).every(
|
|
756
|
+
(entry) => !entry.isSymbolicLink() || fs3.existsSync(path7.join(entry.parentPath, entry.name))
|
|
757
|
+
);
|
|
758
|
+
if (!intact()) {
|
|
759
|
+
fs3.rmSync(view, { recursive: true, force: true });
|
|
760
|
+
fs3.mkdirSync(path7.dirname(view), { recursive: true });
|
|
761
|
+
const staging = fs3.mkdtempSync(`${view}-`);
|
|
762
|
+
fs3.chmodSync(staging, 493);
|
|
763
|
+
const realRoot = path7.dirname(bundle);
|
|
764
|
+
const overrides = new Map([
|
|
765
|
+
[path7.join(sysroot, "darwin/System/Library/Frameworks"), frameworks],
|
|
766
|
+
...[
|
|
767
|
+
"MacTypes.h",
|
|
768
|
+
"objc/NSObject.h",
|
|
769
|
+
"ObjectiveC.apinotes",
|
|
770
|
+
"net/if.h",
|
|
771
|
+
"netinet/tcp.h",
|
|
772
|
+
"paths.h",
|
|
773
|
+
"sys/paths.h",
|
|
774
|
+
"sys/filio.h",
|
|
775
|
+
"sys/sockio.h",
|
|
776
|
+
"termios.h",
|
|
777
|
+
"sys/termios.h",
|
|
778
|
+
"sys/ttycom.h",
|
|
779
|
+
"sys/ttydefaults.h",
|
|
780
|
+
"notify.h",
|
|
781
|
+
"notify.modulemap",
|
|
782
|
+
"module.modulemap",
|
|
783
|
+
"darwin.modulemap",
|
|
784
|
+
"MachO.modulemap",
|
|
785
|
+
"mach/clock_reply.h",
|
|
786
|
+
"mach-o/arm/reloc.h",
|
|
787
|
+
"mach-o/arm64/reloc.h",
|
|
788
|
+
"mach-o/dyld.h",
|
|
789
|
+
"mach-o/dyld_images.h",
|
|
790
|
+
"mach-o/fixup-chains.h",
|
|
791
|
+
"mach-o/ldsyms.h",
|
|
792
|
+
"mach-o/nlist.h",
|
|
793
|
+
"mach-o/ranlib.h",
|
|
794
|
+
"mach-o/reloc.h",
|
|
795
|
+
"mach-o/swap.h",
|
|
796
|
+
"mach-o/x86_64/reloc.h"
|
|
797
|
+
].filter((header) => fs3.existsSync(path7.join(sdkRoot, "usr/include", header))).map((header) => [
|
|
798
|
+
path7.join(sysroot, "darwin/usr/include", header),
|
|
799
|
+
path7.join(sdkRoot, "usr/include", header)
|
|
800
|
+
])
|
|
801
|
+
]);
|
|
802
|
+
for (const file of overlayFiles)
|
|
803
|
+
overrides.set(path7.join(sysroot, "darwin/wasm", path7.relative(overlay, file)), file);
|
|
804
|
+
mirrorTree(
|
|
805
|
+
sysroot,
|
|
806
|
+
stageOverlaySlot(realRoot, staging, path7.relative(realRoot, sysroot)),
|
|
807
|
+
overrides
|
|
808
|
+
);
|
|
809
|
+
for (const [file, shared] of overrides) {
|
|
810
|
+
const destination = path7.join(staging, path7.relative(realRoot, file));
|
|
811
|
+
if (fs3.lstatSync(destination, { throwIfNoEntry: false })) continue;
|
|
812
|
+
fs3.mkdirSync(path7.dirname(destination), { recursive: true });
|
|
813
|
+
fs3.symlinkSync(shared, destination);
|
|
814
|
+
}
|
|
815
|
+
const wasmInclude = path7.join(path7.relative(realRoot, sysroot), "darwin/wasm/include");
|
|
816
|
+
const moduleMap = path7.join(staging, wasmInclude, "module.modulemap");
|
|
817
|
+
const original = fs3.readFileSync(moduleMap, "utf8");
|
|
818
|
+
let updated = original;
|
|
819
|
+
if (hasDarwinTcp) {
|
|
820
|
+
updated = updated.replace(
|
|
821
|
+
'"../../../include/wasm64-wasip1/netinet/tcp.h"',
|
|
822
|
+
'"netinet/tcp.h"'
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
const wasiModule = updated.indexOf("\nmodule SwiftWASILibc [system] {");
|
|
826
|
+
if (wasiModule !== -1) {
|
|
827
|
+
let foundation = updated.slice(0, wasiModule);
|
|
828
|
+
let libc = updated.slice(wasiModule);
|
|
829
|
+
for (const [layer, name] of [
|
|
830
|
+
[1, "_arm_arch_h"],
|
|
831
|
+
[1, "_machine__endian_h"],
|
|
832
|
+
[1, "_sys__types__os_inline_h"],
|
|
833
|
+
[2, "_libkern__OSByteOrder_h"],
|
|
834
|
+
[2, "_libkern_OSByteOrder_h"],
|
|
835
|
+
[2, "_libkern_arm_OSByteOrder_h"],
|
|
836
|
+
[2, "_machine_endian_h"],
|
|
837
|
+
[2, "_sys__endian_h"]
|
|
838
|
+
]) {
|
|
839
|
+
const member = new RegExp(`^ module ${name} \\{\\n[^}]+^ \\}\\n`, "m");
|
|
840
|
+
const block = libc.match(member)?.[0];
|
|
841
|
+
if (!block) continue;
|
|
842
|
+
libc = libc.replace(member, "");
|
|
843
|
+
foundation = foundation.replace(
|
|
844
|
+
`module _DarwinFoundation${layer} [system] {
|
|
845
|
+
module Darwin {
|
|
846
|
+
`,
|
|
847
|
+
(declaration) => declaration + block
|
|
848
|
+
);
|
|
849
|
+
}
|
|
850
|
+
updated = foundation + libc;
|
|
851
|
+
}
|
|
852
|
+
if (overlayFiles.includes(stdint)) {
|
|
853
|
+
fs3.writeFileSync(
|
|
854
|
+
stageOverlaySlot(realRoot, staging, path7.join(wasmInclude, "stdint.h")),
|
|
855
|
+
fs3.readFileSync(stdint, "utf8").replace(/^#pragma once\n/, "")
|
|
856
|
+
);
|
|
857
|
+
}
|
|
858
|
+
if (fs3.existsSync(path7.join(staging, wasmInclude, "stdint.h")) && !/^\s*header "(?:\.\.\/include\/)?stdint\.h"$/m.test(updated)) {
|
|
859
|
+
updated = updated.replace(
|
|
860
|
+
"module _DarwinFoundation2 [system] {\n module Darwin {\n",
|
|
861
|
+
'$& module _stdint_h {\n header "stdint.h"\n export *\n }\n'
|
|
862
|
+
);
|
|
863
|
+
}
|
|
864
|
+
if (updated !== original) {
|
|
865
|
+
fs3.unlinkSync(moduleMap);
|
|
866
|
+
fs3.writeFileSync(moduleMap, updated);
|
|
867
|
+
}
|
|
868
|
+
if (foundationBytes) {
|
|
869
|
+
const foundationSlot = stageOverlaySlot(
|
|
870
|
+
realRoot,
|
|
871
|
+
staging,
|
|
872
|
+
path7.relative(realRoot, foundationArchive)
|
|
873
|
+
);
|
|
874
|
+
weakenFoundationOverridesInArchive(foundationBytes);
|
|
875
|
+
fs3.writeFileSync(foundationSlot, foundationBytes);
|
|
876
|
+
}
|
|
877
|
+
try {
|
|
878
|
+
fs3.renameSync(staging, view);
|
|
879
|
+
} catch (error) {
|
|
880
|
+
fs3.rmSync(staging, { recursive: true, force: true });
|
|
881
|
+
if (!intact()) throw error;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
const options = ["--swift-sdks-path", view];
|
|
885
|
+
sdkViews.set(key, { options, manifest });
|
|
886
|
+
return touchSdkView(options);
|
|
887
|
+
}
|
|
888
|
+
function touchSdkView(options) {
|
|
889
|
+
const now = /* @__PURE__ */ new Date();
|
|
890
|
+
fs3.utimesSync(options[1], now, now);
|
|
891
|
+
refreshSwiftCacheHold(options[1]);
|
|
892
|
+
return options;
|
|
893
|
+
}
|
|
894
|
+
function swiftSharedSdkInputFiles(moduleRoot) {
|
|
895
|
+
const root = swiftSharedSdkRoot(moduleRoot, false);
|
|
896
|
+
return readdirSync2(root, { recursive: true, withFileTypes: true }).filter((entry) => entry.isFile()).map((entry) => path7.relative(moduleRoot, path7.join(entry.parentPath, entry.name))).sort();
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
// src/swift-sdk-surface.ts
|
|
900
|
+
import { execFileSync as execFileSync3, spawnSync as spawnSync3 } from "node:child_process";
|
|
901
|
+
import { createHash as createHash4, randomUUID as randomUUID2 } from "node:crypto";
|
|
902
|
+
import {
|
|
903
|
+
chmodSync,
|
|
904
|
+
copyFileSync,
|
|
905
|
+
existsSync,
|
|
906
|
+
mkdirSync as mkdirSync2,
|
|
907
|
+
mkdtempSync,
|
|
908
|
+
readFileSync as readFileSync4,
|
|
909
|
+
readdirSync as readdirSync3,
|
|
910
|
+
realpathSync,
|
|
911
|
+
renameSync,
|
|
912
|
+
rmSync,
|
|
913
|
+
statSync as statSync2,
|
|
914
|
+
utimesSync,
|
|
915
|
+
writeFileSync as writeFileSync2
|
|
916
|
+
} from "node:fs";
|
|
917
|
+
import os from "node:os";
|
|
918
|
+
import path9 from "node:path";
|
|
919
|
+
|
|
920
|
+
// src/home-paths.ts
|
|
921
|
+
import { randomUUID } from "node:crypto";
|
|
922
|
+
import fs4 from "node:fs";
|
|
923
|
+
import { homedir } from "node:os";
|
|
924
|
+
import path8 from "node:path";
|
|
925
|
+
var PEACH_HOME_ENV = "PEACH_HOME";
|
|
926
|
+
var ACTIVE_RUNTIME_FILE = "active";
|
|
927
|
+
function ambientHomeDir() {
|
|
928
|
+
return path8.join(homedir(), ".peach");
|
|
929
|
+
}
|
|
930
|
+
function rnxHomeDir() {
|
|
931
|
+
const override = process.env[PEACH_HOME_ENV];
|
|
932
|
+
return override && override.length > 0 ? path8.resolve(override) : ambientHomeDir();
|
|
933
|
+
}
|
|
934
|
+
function runtimesDir() {
|
|
935
|
+
return path8.join(rnxHomeDir(), "runtimes");
|
|
936
|
+
}
|
|
937
|
+
function runtimeDir(version) {
|
|
938
|
+
return path8.join(runtimesDir(), version);
|
|
939
|
+
}
|
|
940
|
+
function activeRuntimeFile() {
|
|
941
|
+
return path8.join(runtimesDir(), ACTIVE_RUNTIME_FILE);
|
|
942
|
+
}
|
|
943
|
+
function cacheDir() {
|
|
944
|
+
return path8.join(rnxHomeDir(), "cache");
|
|
945
|
+
}
|
|
946
|
+
function readActiveRuntime() {
|
|
947
|
+
try {
|
|
948
|
+
const value = fs4.readFileSync(activeRuntimeFile(), "utf8").trim();
|
|
949
|
+
return value.length > 0 ? value : null;
|
|
950
|
+
} catch {
|
|
951
|
+
return null;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
var DAEMON_LOCKFILE_MAX_BYTES = 16 * 1024;
|
|
955
|
+
|
|
956
|
+
// src/swift-sdk-surface.ts
|
|
957
|
+
function swiftBuildJobs() {
|
|
958
|
+
const admittedCores = windowAdmission()?.cores ?? Number(process.env.TM_EXEC_CPU_CORES);
|
|
959
|
+
const parallelism = Math.max(1, os.availableParallelism());
|
|
960
|
+
if (!Number.isInteger(admittedCores) || admittedCores <= 0)
|
|
961
|
+
return Math.min(4, Math.max(1, Math.floor(parallelism / 2)));
|
|
962
|
+
const cores = Math.min(admittedCores, parallelism);
|
|
963
|
+
if (process.platform === "darwin") return cores;
|
|
964
|
+
const memory = process.env.TM_EXEC_ADMITTED === "1" && process.env.LINUX_BUILD_SCOPE ? Number(process.env.TM_EXEC_LINUX_MEMORY_MAX) : NaN;
|
|
965
|
+
const memoryJobs = Number.isSafeInteger(memory) && memory > 0 ? Math.max(1, Math.floor(memory / (2 * 1024 ** 3))) : 8;
|
|
966
|
+
return Math.min(cores, memoryJobs);
|
|
967
|
+
}
|
|
968
|
+
function swiftDistributionAt(root) {
|
|
969
|
+
const file = path9.join(root, SWIFT_DISTRIBUTION_MANIFEST);
|
|
970
|
+
const stat = statSync2(file, { bigint: true, throwIfNoEntry: false });
|
|
971
|
+
if (!stat) return null;
|
|
972
|
+
const identity = `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}`;
|
|
973
|
+
const cached = distributionManifests.get(file);
|
|
974
|
+
if (cached?.identity === identity) return cached.manifest;
|
|
975
|
+
const manifest = parseSwiftDistributionManifest(JSON.parse(readFileSync4(file, "utf8")));
|
|
976
|
+
distributionManifests.set(file, { identity, manifest });
|
|
977
|
+
return manifest;
|
|
978
|
+
}
|
|
979
|
+
var distributionManifests = /* @__PURE__ */ new Map();
|
|
980
|
+
var distributionCompileViews = /* @__PURE__ */ new WeakMap();
|
|
981
|
+
function swiftDistributionCompileView(moduleRoot, distribution) {
|
|
982
|
+
let view = distributionCompileViews.get(distribution);
|
|
983
|
+
if (!view || !existsSync(view)) {
|
|
984
|
+
const inputs = Object.entries(distribution.files).filter(
|
|
985
|
+
([file]) => file.startsWith("host/") || file === SWIFT_DISTRIBUTION_OBJC_SELECTORS
|
|
986
|
+
).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0);
|
|
987
|
+
const digest = createHash4("sha256").update(JSON.stringify(inputs)).digest("hex");
|
|
988
|
+
view = path9.join(swiftCacheDir(), "swift-sdk-views", `compile-${digest}`);
|
|
989
|
+
if (!existsSync(view)) {
|
|
990
|
+
mkdirSync2(path9.dirname(view), { recursive: true });
|
|
991
|
+
const staging = mkdtempSync(`${view}-`);
|
|
992
|
+
try {
|
|
993
|
+
chmodSync(staging, 493);
|
|
994
|
+
for (const [file] of inputs) {
|
|
995
|
+
if (!isSwiftResourcePath(file))
|
|
996
|
+
throw new Error(`invalid Swift distribution compile path ${file}`);
|
|
997
|
+
const destination = path9.join(staging, file);
|
|
998
|
+
mkdirSync2(path9.dirname(destination), { recursive: true });
|
|
999
|
+
copyFileSync(path9.join(moduleRoot, file), destination);
|
|
1000
|
+
}
|
|
1001
|
+
try {
|
|
1002
|
+
renameSync(staging, view);
|
|
1003
|
+
} catch (error) {
|
|
1004
|
+
if (!existsSync(view)) throw error;
|
|
1005
|
+
}
|
|
1006
|
+
} finally {
|
|
1007
|
+
rmSync(staging, { recursive: true, force: true });
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
distributionCompileViews.set(distribution, view);
|
|
1011
|
+
}
|
|
1012
|
+
const now = /* @__PURE__ */ new Date();
|
|
1013
|
+
utimesSync(view, now, now);
|
|
1014
|
+
refreshSwiftCacheHold(view);
|
|
1015
|
+
return view;
|
|
1016
|
+
}
|
|
1017
|
+
var REACH_STAGED_FRAMEWORKS = /* @__PURE__ */ new Set(["React"]);
|
|
1018
|
+
function swiftModuleInterface(moduleRoot, name) {
|
|
1019
|
+
if (REACH_STAGED_FRAMEWORKS.has(name)) return null;
|
|
1020
|
+
if (swiftDistributionAt(moduleRoot)) {
|
|
1021
|
+
const file = path9.join(moduleRoot, "modules", `${name}-Swift.h`);
|
|
1022
|
+
if (!existsSync(file)) return null;
|
|
1023
|
+
const header = clangInterfaceHeader(readFileSync4(file, "utf8"), moduleRoot);
|
|
1024
|
+
return { declared: swiftInterfaceDeclarations(header), header };
|
|
1025
|
+
}
|
|
1026
|
+
const sources = path9.join(moduleRoot, "Sources", name);
|
|
1027
|
+
const built = path9.join(moduleRoot, ".build/host", `${name}-Swift.h`);
|
|
1028
|
+
if (!existsSync(sources) || !existsSync(built)) return null;
|
|
1029
|
+
const declared = /* @__PURE__ */ new Set();
|
|
1030
|
+
for (const file of readdirSync3(sources, { recursive: true, encoding: "utf8" }))
|
|
1031
|
+
if (file.endsWith(".swift"))
|
|
1032
|
+
for (const [, objc, subclass] of readFileSync4(
|
|
1033
|
+
path9.join(sources, file),
|
|
1034
|
+
"utf8"
|
|
1035
|
+
).matchAll(
|
|
1036
|
+
/@objc\((\w+)\)\s+(?:\w+\s+)*?(?:protocol|class)\s|^(?:public|open)\s+(?:final\s+)?class\s+(\w+)\s*:\s*NSObject\b/gm
|
|
1037
|
+
))
|
|
1038
|
+
declared.add(objc ?? subclass);
|
|
1039
|
+
if (declared.size === 0) return null;
|
|
1040
|
+
return {
|
|
1041
|
+
declared,
|
|
1042
|
+
header: clangInterfaceHeader(readFileSync4(built, "utf8"), moduleRoot)
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
1045
|
+
function clangInterfaceHeader(header, moduleRoot) {
|
|
1046
|
+
const distribution = swiftDistributionAt(moduleRoot) !== null;
|
|
1047
|
+
const frameworks = path9.join(
|
|
1048
|
+
swiftSharedSdkSourceRoot(moduleRoot, distribution),
|
|
1049
|
+
"System/Library/Frameworks"
|
|
1050
|
+
);
|
|
1051
|
+
let references;
|
|
1052
|
+
const imported = new Set(
|
|
1053
|
+
[...header.matchAll(/^@import (\w+);$/gm)].map((match) => match[1])
|
|
1054
|
+
);
|
|
1055
|
+
return header.replace(/^@import (?:UIKitCore|UIKitText);$/gm, "@import UIKit;").replace(
|
|
1056
|
+
/^@import ((\w+?)(?:Enums|Constants));$/gm,
|
|
1057
|
+
(_, module, framework) => {
|
|
1058
|
+
const imports = [`@import ${framework};`];
|
|
1059
|
+
imported.add(framework);
|
|
1060
|
+
const directory = distribution ? path9.join(moduleRoot, "modules", module) : path9.join(moduleRoot, "Sources", module, "include");
|
|
1061
|
+
if (!existsSync(directory)) return imports[0];
|
|
1062
|
+
if (!references) {
|
|
1063
|
+
references = new Set(header.match(/\b[A-Z]\w*\b/g));
|
|
1064
|
+
for (const name of objcEnumerations(header)) references.delete(name);
|
|
1065
|
+
}
|
|
1066
|
+
const owners = sdkObjCDeclarationOwners(frameworks);
|
|
1067
|
+
for (const name of clangDeclarationEnums(directory)) {
|
|
1068
|
+
const owner = references.has(name) ? owners.get(name) : void 0;
|
|
1069
|
+
if (!owner || imported.has(owner)) continue;
|
|
1070
|
+
imported.add(owner);
|
|
1071
|
+
imports.push(`@import ${owner};`);
|
|
1072
|
+
}
|
|
1073
|
+
return imports.join("\n");
|
|
1074
|
+
}
|
|
1075
|
+
).replace(
|
|
1076
|
+
/^@import (?:CoreFoundation(?:_Private)?|FoundationNetworking|PeachFoundation);$/gm,
|
|
1077
|
+
"@import Foundation;"
|
|
1078
|
+
).replace(/\b_TtC10Foundation\d+(NS\w+)\b/g, "$1").replace(/\b__attribute__\(\(objc_subclassing_restricted\)\)\s*/g, "");
|
|
1079
|
+
}
|
|
1080
|
+
var objcEnumerations = (header) => [
|
|
1081
|
+
...header.matchAll(
|
|
1082
|
+
/^\s*typedef\s+(?:NS|CF|SWIFT)_\w*(?:ENUM|OPTIONS)\w*\s*\(\s*\w+\s*,\s*(\w+)\b/gm
|
|
1083
|
+
)
|
|
1084
|
+
].map((match) => match[1]);
|
|
1085
|
+
var clangDeclarationEnumCache = /* @__PURE__ */ new Map();
|
|
1086
|
+
function clangDeclarationEnums(directory) {
|
|
1087
|
+
const cached = clangDeclarationEnumCache.get(directory);
|
|
1088
|
+
if (cached) return cached;
|
|
1089
|
+
const enums = readdirSync3(directory).filter((file) => file.endsWith(".h")).flatMap((file) => objcEnumerations(readFileSync4(path9.join(directory, file), "utf8")));
|
|
1090
|
+
clangDeclarationEnumCache.set(directory, enums);
|
|
1091
|
+
return enums;
|
|
1092
|
+
}
|
|
1093
|
+
var objcEnumForward = /^[ \t]*SWIFT_ENUM_FWD_DECL\s*\(\s*\w+\s*,\s*(\w+)\b/;
|
|
1094
|
+
function withoutImportedSdkEnumForwards(header, owners) {
|
|
1095
|
+
const imports = new Set([...header.matchAll(/^@import (\w+);$/gm)].map((m) => m[1]));
|
|
1096
|
+
return header.split("\n").filter((line) => {
|
|
1097
|
+
const name = objcEnumForward.exec(line)?.[1];
|
|
1098
|
+
const owner = name && owners.get(name);
|
|
1099
|
+
return !owner || !imports.has(owner);
|
|
1100
|
+
}).join("\n");
|
|
1101
|
+
}
|
|
1102
|
+
function nativelyDeclaredFunctions(generated, headers) {
|
|
1103
|
+
const candidates = [
|
|
1104
|
+
...new Set(
|
|
1105
|
+
[...generated.matchAll(/^\s*SWIFT_EXTERN\b[^(\n]*?\b(\w+)\s*\(/gm)].map(
|
|
1106
|
+
(match) => match[1]
|
|
1107
|
+
)
|
|
1108
|
+
)
|
|
1109
|
+
];
|
|
1110
|
+
if (candidates.length === 0) return [];
|
|
1111
|
+
const declaration = new RegExp(`^[^\\n#/*]*?\\b(${candidates.join("|")})\\s*\\(`, "gm");
|
|
1112
|
+
const found = /* @__PURE__ */ new Set();
|
|
1113
|
+
for (const header of headers)
|
|
1114
|
+
for (const match of header.matchAll(declaration)) found.add(match[1]);
|
|
1115
|
+
return [...found];
|
|
1116
|
+
}
|
|
1117
|
+
var sdkDeclarationOwners = /* @__PURE__ */ new Map();
|
|
1118
|
+
function sdkObjCDeclarationOwners(frameworks) {
|
|
1119
|
+
const known = sdkDeclarationOwners.get(frameworks);
|
|
1120
|
+
if (known) return known;
|
|
1121
|
+
const owners = /* @__PURE__ */ new Map();
|
|
1122
|
+
for (const framework of readdirSync3(frameworks))
|
|
1123
|
+
if (framework.endsWith(".framework")) {
|
|
1124
|
+
const headers = path9.join(frameworks, framework, "Headers");
|
|
1125
|
+
if (existsSync(headers)) {
|
|
1126
|
+
for (const file of readdirSync3(headers, { recursive: true, encoding: "utf8" }))
|
|
1127
|
+
if (file.endsWith(".h")) {
|
|
1128
|
+
const header = readFileSync4(path9.join(headers, file), "utf8");
|
|
1129
|
+
for (const name of [
|
|
1130
|
+
...swiftInterfaceDeclarations(header),
|
|
1131
|
+
...objcEnumerations(header),
|
|
1132
|
+
...[
|
|
1133
|
+
...header.matchAll(/^[A-Z_]*_(?:EXTERN|EXPORT)\b[^;(\n]*?\b(\w+)\s*\(/gm)
|
|
1134
|
+
].map((match) => match[1])
|
|
1135
|
+
])
|
|
1136
|
+
owners.set(name, framework.slice(0, -".framework".length));
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
sdkDeclarationOwners.set(frameworks, owners);
|
|
1141
|
+
return owners;
|
|
1142
|
+
}
|
|
1143
|
+
function swiftHeaderWithSuperclassImports(header, interfaceFor) {
|
|
1144
|
+
const superclasses = new Set(
|
|
1145
|
+
[...header.matchAll(/@interface\s+\w+\s*:\s*(\w+)/g)].map((match) => match[1])
|
|
1146
|
+
);
|
|
1147
|
+
return header.replace(/^@import (\w+);$/gm, (statement, name) => {
|
|
1148
|
+
const dependency = interfaceFor(name);
|
|
1149
|
+
if (dependency && !dependency.module)
|
|
1150
|
+
return `#import ${JSON.stringify(dependency.file)}`;
|
|
1151
|
+
if (!dependency || ![...swiftInterfaceDeclarations(dependency.header)].some(
|
|
1152
|
+
(name2) => superclasses.has(name2)
|
|
1153
|
+
))
|
|
1154
|
+
return statement;
|
|
1155
|
+
return `${statement}
|
|
1156
|
+
#import ${JSON.stringify(dependency.file)}`;
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
var swiftInterfaceDeclarations = (header) => /* @__PURE__ */ new Set([
|
|
1160
|
+
...[
|
|
1161
|
+
...header.matchAll(
|
|
1162
|
+
/^[ \t]*(?:[A-Z_]\w*(?:\([^()\n]*\))?[ \t]+)*@protocol\s+(\w+)\b(?![^\n]*;\s*$)/gm
|
|
1163
|
+
)
|
|
1164
|
+
].map((m) => m[1]),
|
|
1165
|
+
...[
|
|
1166
|
+
...header.matchAll(
|
|
1167
|
+
/^[ \t]*(?:[A-Z_]\w*(?:\([^()\n]*\))?[ \t]+)*@interface\s+(\w+)\s*(?=[:<{]|$)/gm
|
|
1168
|
+
)
|
|
1169
|
+
].map((m) => m[1])
|
|
1170
|
+
]);
|
|
1171
|
+
function withoutSwiftDeclarations(text, declared, interfaceImport) {
|
|
1172
|
+
const out = [];
|
|
1173
|
+
let skipping;
|
|
1174
|
+
let imported = false;
|
|
1175
|
+
let regionStart = -1;
|
|
1176
|
+
for (const line of text.split("\n")) {
|
|
1177
|
+
if (skipping) {
|
|
1178
|
+
if (skipping === "objc" ? /^@end\b/.test(line) : /^\s*};/.test(line))
|
|
1179
|
+
skipping = void 0;
|
|
1180
|
+
continue;
|
|
1181
|
+
}
|
|
1182
|
+
if (regionStart < 0 && /^NS_ASSUME_NONNULL_BEGIN\b/.test(line))
|
|
1183
|
+
regionStart = out.length;
|
|
1184
|
+
const name = /^\s*(?:[A-Z_]\w*(?:\([^()\n]*\))?\s+)*@(?:protocol|interface)\s+(\w+)\s*(?=[:<{]|$)/.exec(
|
|
1185
|
+
line
|
|
1186
|
+
)?.[1];
|
|
1187
|
+
const external = /^\s*SWIFT_EXTERN\b[^(\n]*?\b(\w+)\s*\(.*\)[^;\n]*;\s*$/.exec(
|
|
1188
|
+
line
|
|
1189
|
+
)?.[1];
|
|
1190
|
+
if (external && declared.has(external)) continue;
|
|
1191
|
+
const enumeration = /^\s*typedef\s+(?:NS_ENUM|NS_OPTIONS|SWIFT_ENUM(?:_NAMED)?)\s*\(\s*\w+\s*,\s*(\w+)\b/.exec(
|
|
1192
|
+
line
|
|
1193
|
+
)?.[1];
|
|
1194
|
+
const enumForward = objcEnumForward.exec(line)?.[1];
|
|
1195
|
+
const declaration = name ?? enumeration ?? enumForward;
|
|
1196
|
+
if (declaration && declared.has(declaration)) {
|
|
1197
|
+
skipping = name ? "objc" : enumeration && !line.includes("};") ? "enum" : void 0;
|
|
1198
|
+
while (/^(?:SWIFT_[A-Z_]+|(?:NS|CF)_SWIFT_NAME)(?:\(.*\))?\s*$/.test(out.at(-1) ?? ""))
|
|
1199
|
+
out.pop();
|
|
1200
|
+
if (!imported)
|
|
1201
|
+
out.splice(regionStart < 0 ? out.length : regionStart, 0, interfaceImport);
|
|
1202
|
+
imported = true;
|
|
1203
|
+
continue;
|
|
1204
|
+
}
|
|
1205
|
+
out.push(line);
|
|
1206
|
+
}
|
|
1207
|
+
return out.join("\n");
|
|
1208
|
+
}
|
|
1209
|
+
function swiftModuleSdk(root) {
|
|
1210
|
+
const pin = swiftDistributionAt(root) ?? swiftSourceSdk(root);
|
|
1211
|
+
return {
|
|
1212
|
+
wasmSdkId: pin.wasmSdkId,
|
|
1213
|
+
wasmSdkUrl: pin.wasmSdkUrl,
|
|
1214
|
+
wasmSdkChecksum: pin.wasmSdkChecksum
|
|
1215
|
+
};
|
|
1216
|
+
}
|
|
1217
|
+
function swiftCompileSdkOptions(moduleRoot, toolchainBin) {
|
|
1218
|
+
return swiftSharedSdkViewOptions(
|
|
1219
|
+
moduleRoot,
|
|
1220
|
+
swiftDistributionAt(moduleRoot) !== null,
|
|
1221
|
+
toolchainBin,
|
|
1222
|
+
swiftModuleSdk(moduleRoot).wasmSdkId
|
|
1223
|
+
);
|
|
1224
|
+
}
|
|
1225
|
+
function swiftModuleInputFiles(root) {
|
|
1226
|
+
if (swiftDistributionAt(root)) return [SWIFT_DISTRIBUTION_MANIFEST];
|
|
1227
|
+
const files = [
|
|
1228
|
+
...swiftSharedSdkInputFiles(root),
|
|
1229
|
+
"../peachsim/src/swift-shared-sdk.ts",
|
|
1230
|
+
"../peachsim/src/swift-runtime-products.ts",
|
|
1231
|
+
"../peachsim/src/swiftRuntimeProductContract.ts",
|
|
1232
|
+
"../peachsim/src/swiftTargetContract.ts",
|
|
1233
|
+
"../peachsim/src/swift-darwin-records.ts",
|
|
1234
|
+
"../peachsim/src/swift-uniform-type-constants.ts",
|
|
1235
|
+
"../peach-engine/native/core/input/control_tracking.h",
|
|
1236
|
+
"../../scripts/generate/swift-sdk-module/darwin-mach.json",
|
|
1237
|
+
"../../scripts/generate/swift-sdk-module/darwin-socketvar.json",
|
|
1238
|
+
"../../scripts/ops/swift-distribution-publish.ts",
|
|
1239
|
+
"../../src/helpers/mapLimit.ts",
|
|
1240
|
+
"Package.swift",
|
|
1241
|
+
"scripts/contrast-app-Package.swift",
|
|
1242
|
+
"scripts/build-distribution.ts",
|
|
1243
|
+
"scripts/runtime-product.ts",
|
|
1244
|
+
"scripts/runtime-product-scopes.ts",
|
|
1245
|
+
"scripts/distribution-runtime-products.ts",
|
|
1246
|
+
"scripts/build-helpers.ts",
|
|
1247
|
+
"scripts/build-cache.ts",
|
|
1248
|
+
"scripts/build-cache-launcher.ts",
|
|
1249
|
+
"scripts/distribution-clang.ts",
|
|
1250
|
+
"runtime/UniformTypeIdentifiersConstants.m",
|
|
1251
|
+
"Sources/libxml2/include/module.modulemap",
|
|
1252
|
+
"Sources/libxml2/COPYING",
|
|
1253
|
+
"scripts/build-distribution-plugins.sh",
|
|
1254
|
+
"scripts/build-distribution-plugins-docker.sh",
|
|
1255
|
+
"scripts/build-preview-plugin.sh",
|
|
1256
|
+
"toolchain.json"
|
|
1257
|
+
];
|
|
1258
|
+
const walk = (dir) => {
|
|
1259
|
+
for (const entry of readdirSync3(path9.join(root, dir), {
|
|
1260
|
+
withFileTypes: true
|
|
1261
|
+
})) {
|
|
1262
|
+
const relative = `${dir}/${entry.name}`;
|
|
1263
|
+
if (entry.isDirectory()) walk(relative);
|
|
1264
|
+
else if (/\.(swift|swiftinterface|swiftoverlay|c|cpp|h|inc|m|mm|modulemap|apinotes|json)$/.test(
|
|
1265
|
+
entry.name
|
|
1266
|
+
))
|
|
1267
|
+
files.push(relative);
|
|
1268
|
+
}
|
|
1269
|
+
};
|
|
1270
|
+
walk("Sources");
|
|
1271
|
+
walk("cross-import-overlays");
|
|
1272
|
+
walk("ios-simulator-stdlib");
|
|
1273
|
+
return files.sort();
|
|
1274
|
+
}
|
|
1275
|
+
function swiftMacroPlugins(moduleRoot, dir = path9.join(moduleRoot, ".build/host/RnxPreviewMacros")) {
|
|
1276
|
+
const distribution = swiftDistributionAt(moduleRoot);
|
|
1277
|
+
if (distribution) {
|
|
1278
|
+
const view = swiftDistributionCompileView(moduleRoot, distribution);
|
|
1279
|
+
return {
|
|
1280
|
+
libraries: distribution.plugins.filter((plugin) => path9.basename(plugin) !== "ExpoModulesMacros").map((plugin) => path9.join(view, plugin)),
|
|
1281
|
+
executables: distribution.plugins.filter((plugin) => path9.basename(plugin) === "ExpoModulesMacros").map((plugin) => path9.join(view, plugin)),
|
|
1282
|
+
stale: false
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
const release = JSON.parse(
|
|
1286
|
+
readFileSync4(path9.join(moduleRoot, "toolchain.json"), "utf8")
|
|
1287
|
+
).release;
|
|
1288
|
+
const compilerStamp = path9.join(dir, "compiler-release");
|
|
1289
|
+
const pluginScript = path9.join(moduleRoot, "scripts/build-preview-plugin.sh");
|
|
1290
|
+
const expoPlugin = path9.join(dir, "ExpoModulesMacros");
|
|
1291
|
+
const ext = process.platform === "darwin" ? "dylib" : "so";
|
|
1292
|
+
const plugins = [
|
|
1293
|
+
{
|
|
1294
|
+
library: path9.join(dir, `libRnxPreviewMacros.${ext}`),
|
|
1295
|
+
sources: [path9.join(moduleRoot, "Sources/RnxPreviewMacros/PreviewMacro.swift")]
|
|
1296
|
+
},
|
|
1297
|
+
{
|
|
1298
|
+
library: path9.join(dir, `libFoundationMacros.${ext}`),
|
|
1299
|
+
sources: [
|
|
1300
|
+
path9.join(moduleRoot, "Sources/FoundationMacros/PredicateMacro.swift"),
|
|
1301
|
+
path9.join(moduleRoot, "Sources/SwiftMacroSupport/PredicateExpression.swift")
|
|
1302
|
+
]
|
|
1303
|
+
},
|
|
1304
|
+
{
|
|
1305
|
+
library: path9.join(dir, `libTipKitMacros.${ext}`),
|
|
1306
|
+
sources: [
|
|
1307
|
+
path9.join(moduleRoot, "Sources/TipKitMacros/TipKitMacros.swift"),
|
|
1308
|
+
path9.join(moduleRoot, "Sources/SwiftMacroSupport/PredicateExpression.swift")
|
|
1309
|
+
]
|
|
1310
|
+
}
|
|
1311
|
+
];
|
|
1312
|
+
return {
|
|
1313
|
+
libraries: plugins.map(({ library }) => library),
|
|
1314
|
+
executables: [expoPlugin],
|
|
1315
|
+
stale: !existsSync(compilerStamp) || !existsSync(expoPlugin) || statSync2(pluginScript).mtimeMs > statSync2(expoPlugin).mtimeMs || readFileSync4(compilerStamp, "utf8").trim() !== release || plugins.some(
|
|
1316
|
+
({ library, sources }) => !existsSync(library) || sources.some((source) => statSync2(source).mtimeMs > statSync2(library).mtimeMs)
|
|
1317
|
+
)
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
var linkedModuleDigests = /* @__PURE__ */ new Map();
|
|
1321
|
+
function clearLinkedModuleDigests(root) {
|
|
1322
|
+
if (root === void 0) linkedModuleDigests.clear();
|
|
1323
|
+
else linkedModuleDigests.delete(root);
|
|
1324
|
+
}
|
|
1325
|
+
function gitCleanModuleInputsKey(root, files) {
|
|
1326
|
+
if (swiftDistributionAt(root)) return null;
|
|
1327
|
+
const top = spawnSync3("git", ["-C", root, "rev-parse", "--show-toplevel"], {
|
|
1328
|
+
encoding: "utf8",
|
|
1329
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
1330
|
+
});
|
|
1331
|
+
if (top.status !== 0) return null;
|
|
1332
|
+
const repoTop = top.stdout.trim();
|
|
1333
|
+
if (!repoTop) return null;
|
|
1334
|
+
const realTop = realpathSync(repoTop);
|
|
1335
|
+
const realRoot = realpathSync(root);
|
|
1336
|
+
const collapsedDirs = [
|
|
1337
|
+
path9.join(realRoot, "Sources"),
|
|
1338
|
+
path9.join(realRoot, "cross-import-overlays"),
|
|
1339
|
+
path9.join(realRoot, "ios-simulator-stdlib"),
|
|
1340
|
+
realpathSync(path9.resolve(realRoot, "../peachsim/sdk/ios"))
|
|
1341
|
+
];
|
|
1342
|
+
const scoped = /* @__PURE__ */ new Set();
|
|
1343
|
+
for (const dir of collapsedDirs) {
|
|
1344
|
+
const rel = path9.relative(realTop, dir).split(path9.sep).join("/");
|
|
1345
|
+
if (!rel || rel.startsWith("../")) return null;
|
|
1346
|
+
scoped.add(rel);
|
|
1347
|
+
}
|
|
1348
|
+
for (const file of files) {
|
|
1349
|
+
const full = path9.resolve(realRoot, file);
|
|
1350
|
+
if (collapsedDirs.some((dir) => full.startsWith(dir + path9.sep))) continue;
|
|
1351
|
+
const rel = path9.relative(realTop, full).split(path9.sep).join("/");
|
|
1352
|
+
if (!rel || rel.startsWith("../")) return null;
|
|
1353
|
+
scoped.add(rel);
|
|
1354
|
+
}
|
|
1355
|
+
const paths = [...scoped].sort();
|
|
1356
|
+
const status = spawnSync3(
|
|
1357
|
+
"git",
|
|
1358
|
+
[
|
|
1359
|
+
"-C",
|
|
1360
|
+
realTop,
|
|
1361
|
+
"status",
|
|
1362
|
+
"--porcelain",
|
|
1363
|
+
"--untracked-files=all",
|
|
1364
|
+
"--ignored=matching",
|
|
1365
|
+
"--",
|
|
1366
|
+
...paths
|
|
1367
|
+
],
|
|
1368
|
+
{
|
|
1369
|
+
encoding: "utf8",
|
|
1370
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
1371
|
+
maxBuffer: 16 * 1024 * 1024
|
|
1372
|
+
}
|
|
1373
|
+
);
|
|
1374
|
+
if (status.status !== 0 || status.stdout.trim().length > 0) return null;
|
|
1375
|
+
const oids = spawnSync3(
|
|
1376
|
+
"git",
|
|
1377
|
+
["-C", realTop, "rev-parse", ...paths.map((entry) => `HEAD:${entry}`)],
|
|
1378
|
+
{ encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }
|
|
1379
|
+
);
|
|
1380
|
+
if (oids.status !== 0) return null;
|
|
1381
|
+
const keyHash = createHash4("sha256");
|
|
1382
|
+
keyHash.update("git-module-digest/v1\n");
|
|
1383
|
+
keyHash.update(oids.stdout);
|
|
1384
|
+
keyHash.update("\n");
|
|
1385
|
+
for (const file of files) keyHash.update(file).update("\n");
|
|
1386
|
+
return keyHash.digest("hex");
|
|
1387
|
+
}
|
|
1388
|
+
function swiftModuleDigest(root) {
|
|
1389
|
+
const files = swiftModuleInputFiles(root);
|
|
1390
|
+
const stampHash = createHash4("sha256");
|
|
1391
|
+
for (const file of files) {
|
|
1392
|
+
const stat = statSync2(path9.join(root, file), { bigint: true });
|
|
1393
|
+
stampHash.update(file);
|
|
1394
|
+
stampHash.update(
|
|
1395
|
+
`${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}
|
|
1396
|
+
`
|
|
1397
|
+
);
|
|
1398
|
+
}
|
|
1399
|
+
const stamp = stampHash.digest("hex");
|
|
1400
|
+
const cached = linkedModuleDigests.get(root);
|
|
1401
|
+
if (cached?.stamp === stamp) return cached.digest;
|
|
1402
|
+
const digestDir = path9.join(swiftCacheDir(), "swift-module-digests");
|
|
1403
|
+
const record = path9.join(
|
|
1404
|
+
digestDir,
|
|
1405
|
+
`${createHash4("sha256").update(root).digest("hex")}.json`
|
|
1406
|
+
);
|
|
1407
|
+
const writeRecord = (target, body) => {
|
|
1408
|
+
mkdirSync2(path9.dirname(target), { recursive: true });
|
|
1409
|
+
const partial = `${target}.${process.pid}.${randomUUID2()}`;
|
|
1410
|
+
writeFileSync2(partial, body);
|
|
1411
|
+
renameSync(partial, target);
|
|
1412
|
+
};
|
|
1413
|
+
if (existsSync(record)) {
|
|
1414
|
+
const saved = JSON.parse(readFileSync4(record, "utf8"));
|
|
1415
|
+
if (saved && typeof saved === "object" && Reflect.get(saved, "stamp") === stamp && typeof Reflect.get(saved, "digest") === "string") {
|
|
1416
|
+
const digest2 = Buffer.from(String(Reflect.get(saved, "digest")), "hex");
|
|
1417
|
+
linkedModuleDigests.set(root, { stamp, digest: digest2 });
|
|
1418
|
+
return digest2;
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
const gitKey = gitCleanModuleInputsKey(root, files);
|
|
1422
|
+
const gitRecord = gitKey ? path9.join(digestDir, `git-${gitKey}.json`) : null;
|
|
1423
|
+
if (gitRecord && existsSync(gitRecord)) {
|
|
1424
|
+
const saved = JSON.parse(readFileSync4(gitRecord, "utf8"));
|
|
1425
|
+
if (saved && typeof saved === "object" && typeof Reflect.get(saved, "digest") === "string") {
|
|
1426
|
+
const hex2 = String(Reflect.get(saved, "digest"));
|
|
1427
|
+
const digest2 = Buffer.from(hex2, "hex");
|
|
1428
|
+
linkedModuleDigests.set(root, { stamp, digest: digest2 });
|
|
1429
|
+
writeRecord(record, JSON.stringify({ stamp, digest: hex2 }));
|
|
1430
|
+
return digest2;
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
const hash = createHash4("sha256");
|
|
1434
|
+
for (const file of files) {
|
|
1435
|
+
hash.update(createHash4("sha256").update(file).digest());
|
|
1436
|
+
hash.update(
|
|
1437
|
+
createHash4("sha256").update(readFileSync4(path9.join(root, file))).digest()
|
|
1438
|
+
);
|
|
1439
|
+
}
|
|
1440
|
+
const digest = hash.digest();
|
|
1441
|
+
const hex = digest.toString("hex");
|
|
1442
|
+
linkedModuleDigests.set(root, { stamp, digest });
|
|
1443
|
+
writeRecord(record, JSON.stringify({ stamp, digest: hex }));
|
|
1444
|
+
if (gitRecord) writeRecord(gitRecord, JSON.stringify({ digest: hex }));
|
|
1445
|
+
return digest;
|
|
1446
|
+
}
|
|
1447
|
+
var compileSurfaces = /* @__PURE__ */ new WeakMap();
|
|
1448
|
+
function swiftCompileSurfaceDigest(root) {
|
|
1449
|
+
const distribution = swiftDistributionAt(root);
|
|
1450
|
+
if (!distribution) return swiftModuleDigest(root);
|
|
1451
|
+
let digest = compileSurfaces.get(distribution);
|
|
1452
|
+
if (!digest) {
|
|
1453
|
+
digest = createHash4("sha256").update(
|
|
1454
|
+
JSON.stringify([
|
|
1455
|
+
distribution.release,
|
|
1456
|
+
distribution.wasmSdkId,
|
|
1457
|
+
distribution.wasmSdkChecksum,
|
|
1458
|
+
distribution.modules,
|
|
1459
|
+
distribution.plugins,
|
|
1460
|
+
distribution.link,
|
|
1461
|
+
Object.entries(distribution.files).filter(([file]) => !file.startsWith("lib/")).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)
|
|
1462
|
+
])
|
|
1463
|
+
).digest();
|
|
1464
|
+
compileSurfaces.set(distribution, digest);
|
|
1465
|
+
}
|
|
1466
|
+
return digest;
|
|
1467
|
+
}
|
|
1468
|
+
var SWIFT_IMPORT = /^\s*(?:@\w+(?:\([^)]*\))?\s+|(?:public|package|internal|fileprivate|private)\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?([A-Za-z_][A-Za-z0-9_]*)/;
|
|
1469
|
+
var kleeneNot = (value) => value === void 0 ? void 0 : !value;
|
|
1470
|
+
var kleeneAnd = (left, right) => left === false || right === false ? false : left === true && right === true ? true : void 0;
|
|
1471
|
+
var kleeneOr = (left, right) => left === true || right === true ? true : left === false && right === false ? false : void 0;
|
|
1472
|
+
var NON_IOS_MODULES = /* @__PURE__ */ new Set(["FoundationNetworking", "WASILibc"]);
|
|
1473
|
+
function swiftCondition(text, available, defines) {
|
|
1474
|
+
const tokens = text.match(/\w+\s*\([^()]*\)|&&|\|\||!|\(|\)|\w+/g) ?? [];
|
|
1475
|
+
let index = 0;
|
|
1476
|
+
const atom = () => {
|
|
1477
|
+
const token = tokens[index++];
|
|
1478
|
+
if (token === "!") return kleeneNot(atom());
|
|
1479
|
+
if (token === "(") {
|
|
1480
|
+
const value = either();
|
|
1481
|
+
index++;
|
|
1482
|
+
return value;
|
|
1483
|
+
}
|
|
1484
|
+
if (token === "true") return true;
|
|
1485
|
+
if (token === "false") return false;
|
|
1486
|
+
if (defines && /^[A-Za-z_]\w*$/.test(token ?? "")) return defines.has(token);
|
|
1487
|
+
const call = /^(\w+)\s*\(\s*([^,()]*?)\s*(?:,[^()]*)?\)$/.exec(token ?? "");
|
|
1488
|
+
if (!call) return void 0;
|
|
1489
|
+
const [, name, argument] = call;
|
|
1490
|
+
if (name === "os") return argument === "iOS";
|
|
1491
|
+
if (name === "canImport")
|
|
1492
|
+
return !NON_IOS_MODULES.has(argument) && available?.has(argument);
|
|
1493
|
+
if (name === "targetEnvironment") return argument === "simulator";
|
|
1494
|
+
if (name === "arch") return argument === "wasm64" || argument === "arm64";
|
|
1495
|
+
return void 0;
|
|
1496
|
+
};
|
|
1497
|
+
const both = () => {
|
|
1498
|
+
let value = atom();
|
|
1499
|
+
while (tokens[index] === "&&") {
|
|
1500
|
+
index++;
|
|
1501
|
+
value = kleeneAnd(value, atom());
|
|
1502
|
+
}
|
|
1503
|
+
return value;
|
|
1504
|
+
};
|
|
1505
|
+
const either = () => {
|
|
1506
|
+
let value = both();
|
|
1507
|
+
while (tokens[index] === "||") {
|
|
1508
|
+
index++;
|
|
1509
|
+
value = kleeneOr(value, both());
|
|
1510
|
+
}
|
|
1511
|
+
return value;
|
|
1512
|
+
};
|
|
1513
|
+
return either();
|
|
1514
|
+
}
|
|
1515
|
+
function* swiftConditionalLines(contents2, available, defines) {
|
|
1516
|
+
const frames = [];
|
|
1517
|
+
for (const line of swiftCodeMask(contents2).split("\n")) {
|
|
1518
|
+
const directive = /^\s*#(if|elseif|else|endif)\b(.*)$/.exec(line);
|
|
1519
|
+
if (directive) {
|
|
1520
|
+
const [, kind, rest] = directive;
|
|
1521
|
+
const condition = (rest ?? "").replace(/\/\/.*$/, "").trim();
|
|
1522
|
+
if (kind === "if") {
|
|
1523
|
+
const active = swiftCondition(condition, available, defines);
|
|
1524
|
+
frames.push({ active, taken: active });
|
|
1525
|
+
} else if (kind === "endif") frames.pop();
|
|
1526
|
+
else if (frames.length > 0) {
|
|
1527
|
+
const frame = frames[frames.length - 1];
|
|
1528
|
+
const holds = kind === "else" ? true : swiftCondition(condition, available, defines);
|
|
1529
|
+
frame.active = frame.taken === true ? false : frame.taken === false ? holds : holds && void 0;
|
|
1530
|
+
frame.taken = frame.taken === true || holds === true ? true : frame.taken === false ? holds : void 0;
|
|
1531
|
+
}
|
|
1532
|
+
yield { line, active: false };
|
|
1533
|
+
continue;
|
|
1534
|
+
}
|
|
1535
|
+
yield {
|
|
1536
|
+
line,
|
|
1537
|
+
active: frames.some((frame) => frame.active === false) ? false : frames.every((frame) => frame.active === true) ? true : void 0
|
|
1538
|
+
};
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
var importNamesCache = /* @__PURE__ */ new Map();
|
|
1542
|
+
function swiftImportNames(contents2, available) {
|
|
1543
|
+
if (available === void 0) {
|
|
1544
|
+
const cached = importNamesCache.get(contents2);
|
|
1545
|
+
if (cached !== void 0) return cached;
|
|
1546
|
+
}
|
|
1547
|
+
const names = [];
|
|
1548
|
+
for (const { line, active } of swiftConditionalLines(contents2, available)) {
|
|
1549
|
+
if (available && active !== true) continue;
|
|
1550
|
+
const name = SWIFT_IMPORT.exec(line)?.[1];
|
|
1551
|
+
if (name) names.push(name);
|
|
1552
|
+
}
|
|
1553
|
+
if (available === void 0) importNamesCache.set(contents2, names);
|
|
1554
|
+
return names;
|
|
1555
|
+
}
|
|
1556
|
+
function swiftPeachModules(moduleRoot) {
|
|
1557
|
+
const distribution = swiftDistributionAt(moduleRoot);
|
|
1558
|
+
return distribution ? distribution.modules : swiftManifestDeclarations(
|
|
1559
|
+
readFileSync4(path9.join(moduleRoot, "Package.swift"), "utf8")
|
|
1560
|
+
).filter((target) => !target.executable && !target.path.startsWith("fixtures/")).map((target) => target.name);
|
|
1561
|
+
}
|
|
1562
|
+
var sdkPaths = /* @__PURE__ */ new Map();
|
|
1563
|
+
function swiftSdkPaths(moduleRoot, toolchainBin, options = swiftCompileSdkOptions(moduleRoot, toolchainBin)) {
|
|
1564
|
+
const sdk = swiftModuleSdk(moduleRoot).wasmSdkId;
|
|
1565
|
+
const key = JSON.stringify([toolchainBin, sdk, options]);
|
|
1566
|
+
const cached = sdkPaths.get(key);
|
|
1567
|
+
if (cached) return cached;
|
|
1568
|
+
const configuration = execFileSync3(
|
|
1569
|
+
path9.join(toolchainBin, "swift"),
|
|
1570
|
+
["sdk", "configure", ...options, "--show-configuration", sdk, SWIFT_WASM_TRIPLE],
|
|
1571
|
+
{ encoding: "utf8", env: swiftEnvironment(), stdio: ["ignore", "pipe", "pipe"] }
|
|
1572
|
+
);
|
|
1573
|
+
const field = (name) => {
|
|
1574
|
+
const value = new RegExp(`^${name}:\\s*(.+)$`, "m").exec(configuration)?.[1]?.trim();
|
|
1575
|
+
if (!value) throw new Error(`swift sdk ${sdk} reports no ${name}`);
|
|
1576
|
+
return value;
|
|
1577
|
+
};
|
|
1578
|
+
const sysroot = field("sdkRootPath");
|
|
1579
|
+
const cFlags = [];
|
|
1580
|
+
const frameworks = [];
|
|
1581
|
+
const configuredToolsets = field("toolsetPaths");
|
|
1582
|
+
if (configuredToolsets !== "not set") {
|
|
1583
|
+
const toolsets = JSON.parse(configuredToolsets);
|
|
1584
|
+
if (!Array.isArray(toolsets) || !toolsets.every((value) => typeof value === "string"))
|
|
1585
|
+
throw new Error(`swift sdk ${sdk} reports invalid toolset paths`);
|
|
1586
|
+
for (const toolset of toolsets) {
|
|
1587
|
+
const config = JSON.parse(readFileSync4(toolset, "utf8"));
|
|
1588
|
+
if (!config || typeof config !== "object" || !("swiftCompiler" in config)) continue;
|
|
1589
|
+
const compiler = config.swiftCompiler;
|
|
1590
|
+
if (!compiler || typeof compiler !== "object" || !("extraCLIOptions" in compiler))
|
|
1591
|
+
continue;
|
|
1592
|
+
const options2 = compiler.extraCLIOptions;
|
|
1593
|
+
if (!Array.isArray(options2) || !options2.every((value) => typeof value === "string"))
|
|
1594
|
+
throw new Error(
|
|
1595
|
+
`swift sdk ${sdk} has invalid swift compiler options in ${toolset}`
|
|
1596
|
+
);
|
|
1597
|
+
for (let index = 0; index < options2.length; index++) {
|
|
1598
|
+
if (options2[index] === "-Xcc" && typeof options2[index + 1] === "string") {
|
|
1599
|
+
const flag = options2[index + 1];
|
|
1600
|
+
if (flag !== "-fwasm-exceptions") cFlags.push(flag);
|
|
1601
|
+
if (flag === "-iframeworkwithsysroot" && options2[index + 2] === "-Xcc" && typeof options2[index + 3] === "string") {
|
|
1602
|
+
cFlags.push(options2[index + 3]);
|
|
1603
|
+
frameworks.push(path9.join(sysroot, options2[index + 3]));
|
|
1604
|
+
index += 3;
|
|
1605
|
+
continue;
|
|
1606
|
+
}
|
|
1607
|
+
index += 1;
|
|
1608
|
+
continue;
|
|
1609
|
+
}
|
|
1610
|
+
const option = options2[index];
|
|
1611
|
+
if (option.startsWith("-iframework") || option.startsWith("-F"))
|
|
1612
|
+
throw new Error(
|
|
1613
|
+
`swift sdk ${sdk} has an unsupported framework search option ${option}`
|
|
1614
|
+
);
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
const paths = {
|
|
1619
|
+
sysroot,
|
|
1620
|
+
darwin: path9.join(sysroot, "darwin"),
|
|
1621
|
+
resources: field("swiftResourcesPath"),
|
|
1622
|
+
frameworks,
|
|
1623
|
+
cFlags
|
|
1624
|
+
};
|
|
1625
|
+
sdkPaths.set(key, paths);
|
|
1626
|
+
return paths;
|
|
1627
|
+
}
|
|
1628
|
+
var FOUNDATION_IMPLICIT_MODULES = [
|
|
1629
|
+
"PeachObjC",
|
|
1630
|
+
"Dispatch",
|
|
1631
|
+
"FoundationNetworking",
|
|
1632
|
+
"PeachFoundationCombine",
|
|
1633
|
+
"Darwin"
|
|
1634
|
+
];
|
|
1635
|
+
var FRAMEWORK_COMPANION_IMPORT = /^[ \t]*((?:(?:@\w+(?:\([^)]*\))?|public|package|internal|fileprivate|private)[ \t]+)*)import[ \t]+(Foundation|UIKit|SwiftUI|Photos|CoreData|SystemConfiguration|Dispatch)[ \t]*;?[ \t]*$/;
|
|
1636
|
+
function withFrameworkCompanionImports(source) {
|
|
1637
|
+
const original = source.split("\n");
|
|
1638
|
+
const imports = [];
|
|
1639
|
+
let hasCompanions = false;
|
|
1640
|
+
for (const [index, line] of swiftCodeMask(source).split("\n").entries()) {
|
|
1641
|
+
const conditional = /#(?:(?:if|elseif)\b.*|(?:else|endif)\b)/.exec(line);
|
|
1642
|
+
if (conditional) {
|
|
1643
|
+
const start = conditional.index;
|
|
1644
|
+
imports.push(original[index].slice(start, start + conditional[0].length));
|
|
1645
|
+
continue;
|
|
1646
|
+
}
|
|
1647
|
+
const matched = FRAMEWORK_COMPANION_IMPORT.exec(line.trimEnd());
|
|
1648
|
+
if (!matched) continue;
|
|
1649
|
+
const [, attributes = "", framework] = matched;
|
|
1650
|
+
const modifiers = attributes.match(
|
|
1651
|
+
/@(?:preconcurrency|_exported|_implementationOnly)\b|\b(?:public|package|internal|fileprivate|private)\b/g
|
|
1652
|
+
) ?? [];
|
|
1653
|
+
const preconcurrency = modifiers.includes("@preconcurrency");
|
|
1654
|
+
const modules = framework === "SystemConfiguration" ? ["Dispatch", "Darwin"] : framework === "Dispatch" ? ["PeachFoundationCombine"] : preconcurrency ? ["CoreFoundation", "ObjectiveC", ...FOUNDATION_IMPLICIT_MODULES] : FOUNDATION_IMPLICIT_MODULES;
|
|
1655
|
+
const prefix = modifiers.length ? modifiers.join(" ") + " " : "";
|
|
1656
|
+
imports.push(...modules.map((module) => `${prefix}import ${module}`));
|
|
1657
|
+
if (framework === "Foundation" && modifiers.includes("public"))
|
|
1658
|
+
imports.push(
|
|
1659
|
+
"@_exported public import protocol Combine.ObservableObject",
|
|
1660
|
+
"@_exported public import struct Combine.Published"
|
|
1661
|
+
);
|
|
1662
|
+
if (framework === "CoreData")
|
|
1663
|
+
imports.push(
|
|
1664
|
+
`${prefix}import protocol Combine.ObservableObject`,
|
|
1665
|
+
`${prefix}import struct Combine.Published`
|
|
1666
|
+
);
|
|
1667
|
+
hasCompanions = true;
|
|
1668
|
+
}
|
|
1669
|
+
if (!hasCompanions) return source;
|
|
1670
|
+
return `${source}${source.endsWith("\n") ? "" : "\n"}#if canImport(PeachObjC)
|
|
1671
|
+
${imports.join("\n")}
|
|
1672
|
+
#endif
|
|
1673
|
+
`;
|
|
1674
|
+
}
|
|
1675
|
+
var codeMasks = /* @__PURE__ */ new Map();
|
|
1676
|
+
var codeMaskChars = 0;
|
|
1677
|
+
var CODE_MASK_CACHE_CHARS = 256 * 1024 * 1024;
|
|
1678
|
+
function swiftCodeMask(source) {
|
|
1679
|
+
const cached = codeMasks.get(source);
|
|
1680
|
+
if (cached !== void 0) return cached;
|
|
1681
|
+
const masked = maskSwiftCode(source);
|
|
1682
|
+
if (codeMaskChars + source.length > CODE_MASK_CACHE_CHARS) {
|
|
1683
|
+
codeMasks.clear();
|
|
1684
|
+
importNamesCache.clear();
|
|
1685
|
+
codeMaskChars = 0;
|
|
1686
|
+
}
|
|
1687
|
+
codeMasks.set(source, masked);
|
|
1688
|
+
codeMaskChars += source.length;
|
|
1689
|
+
return masked;
|
|
1690
|
+
}
|
|
1691
|
+
function maskSwiftCode(source) {
|
|
1692
|
+
const chars = source.split("");
|
|
1693
|
+
const blank = (from, to) => {
|
|
1694
|
+
for (let i = Math.max(0, from); i < Math.min(to, chars.length); i++)
|
|
1695
|
+
if (chars[i] !== "\n") chars[i] = " ";
|
|
1696
|
+
};
|
|
1697
|
+
const hashesAt = (at) => {
|
|
1698
|
+
let end = at;
|
|
1699
|
+
while (source[end] === "#") end++;
|
|
1700
|
+
return end - at;
|
|
1701
|
+
};
|
|
1702
|
+
const scanString = (quote, hashes) => {
|
|
1703
|
+
const multiline = source.startsWith('"""', quote);
|
|
1704
|
+
let i = quote + (multiline ? 3 : 1);
|
|
1705
|
+
const keep = [];
|
|
1706
|
+
const quoteEnd = (at) => {
|
|
1707
|
+
const mark = multiline ? '"""' : '"';
|
|
1708
|
+
return source.startsWith(mark, at) && source.startsWith("#".repeat(hashes), at + mark.length);
|
|
1709
|
+
};
|
|
1710
|
+
while (i < chars.length) {
|
|
1711
|
+
if (source[i] === "\\" && source.startsWith("#".repeat(hashes), i + 1)) {
|
|
1712
|
+
const escaped = i + 1 + hashes;
|
|
1713
|
+
if (source[escaped] === "(") {
|
|
1714
|
+
const codeStart = escaped + 1;
|
|
1715
|
+
const codeEnd = scanCode(codeStart, true);
|
|
1716
|
+
keep.push([codeStart, codeEnd]);
|
|
1717
|
+
i = codeEnd + 1;
|
|
1718
|
+
} else {
|
|
1719
|
+
i = escaped + 1;
|
|
1720
|
+
}
|
|
1721
|
+
continue;
|
|
1722
|
+
}
|
|
1723
|
+
if (quoteEnd(i)) {
|
|
1724
|
+
const close = i + (multiline ? 3 : 1) + hashes;
|
|
1725
|
+
let cursor = quote - hashes;
|
|
1726
|
+
const ranges = [...keep, [close, close]];
|
|
1727
|
+
for (const [from, to] of ranges)
|
|
1728
|
+
if (from > cursor) {
|
|
1729
|
+
blank(cursor, from);
|
|
1730
|
+
cursor = to;
|
|
1731
|
+
} else cursor = Math.max(cursor, to);
|
|
1732
|
+
return close;
|
|
1733
|
+
}
|
|
1734
|
+
i++;
|
|
1735
|
+
}
|
|
1736
|
+
blank(quote - hashes, chars.length);
|
|
1737
|
+
return chars.length;
|
|
1738
|
+
};
|
|
1739
|
+
const scanCode = (i, nested) => {
|
|
1740
|
+
let parens = 0;
|
|
1741
|
+
while (i < chars.length) {
|
|
1742
|
+
const char = source[i];
|
|
1743
|
+
if (char === "/" && source[i + 1] === "/") {
|
|
1744
|
+
const end = source.indexOf("\n", i);
|
|
1745
|
+
blank(i, end === -1 ? chars.length : end);
|
|
1746
|
+
i = end === -1 ? chars.length : end;
|
|
1747
|
+
continue;
|
|
1748
|
+
}
|
|
1749
|
+
if (char === "/" && source[i + 1] === "*") {
|
|
1750
|
+
let j = i + 2;
|
|
1751
|
+
let depth = 1;
|
|
1752
|
+
while (j < chars.length && depth > 0) {
|
|
1753
|
+
if (source.startsWith("/*", j)) {
|
|
1754
|
+
depth++;
|
|
1755
|
+
j += 2;
|
|
1756
|
+
} else if (source.startsWith("*/", j)) {
|
|
1757
|
+
depth--;
|
|
1758
|
+
j += 2;
|
|
1759
|
+
} else j++;
|
|
1760
|
+
}
|
|
1761
|
+
blank(i, j);
|
|
1762
|
+
i = j;
|
|
1763
|
+
continue;
|
|
1764
|
+
}
|
|
1765
|
+
if (char === "#") {
|
|
1766
|
+
const hashes = hashesAt(i);
|
|
1767
|
+
const at = i + hashes;
|
|
1768
|
+
if (source[at] === '"') {
|
|
1769
|
+
i = scanString(at, hashes);
|
|
1770
|
+
continue;
|
|
1771
|
+
}
|
|
1772
|
+
if (hashes > 0 && source[at] === "/") {
|
|
1773
|
+
const mark = "#".repeat(hashes);
|
|
1774
|
+
let j = at + 1;
|
|
1775
|
+
while (j < chars.length && !(source[j] === "/" && source.startsWith(mark, j + 1)))
|
|
1776
|
+
j++;
|
|
1777
|
+
blank(i, Math.min(chars.length, j + 1 + hashes));
|
|
1778
|
+
i = Math.min(chars.length, j + 1 + hashes);
|
|
1779
|
+
continue;
|
|
1780
|
+
}
|
|
1781
|
+
i++;
|
|
1782
|
+
continue;
|
|
1783
|
+
}
|
|
1784
|
+
if (char === '"') {
|
|
1785
|
+
i = scanString(i, 0);
|
|
1786
|
+
continue;
|
|
1787
|
+
}
|
|
1788
|
+
if (char === "(") parens++;
|
|
1789
|
+
else if (char === ")") {
|
|
1790
|
+
if (nested && parens === 0) return i;
|
|
1791
|
+
parens--;
|
|
1792
|
+
}
|
|
1793
|
+
i++;
|
|
1794
|
+
}
|
|
1795
|
+
return i;
|
|
1796
|
+
};
|
|
1797
|
+
scanCode(0, false);
|
|
1798
|
+
return chars.join("");
|
|
1799
|
+
}
|
|
1800
|
+
var FOUNDATION_NETWORKING_TYPES = /* @__PURE__ */ new Set([
|
|
1801
|
+
"NSURLConnection",
|
|
1802
|
+
"NSURLConnectionDataDelegate",
|
|
1803
|
+
"NSURLConnectionDelegate",
|
|
1804
|
+
"NSURLConnectionDownloadDelegate"
|
|
1805
|
+
]);
|
|
1806
|
+
var FOUNDATION_OVERLAY_TYPES = /* @__PURE__ */ new Set([
|
|
1807
|
+
"AsyncCharacterSequence",
|
|
1808
|
+
"AsyncLineSequence",
|
|
1809
|
+
"AsyncUnicodeScalarSequence",
|
|
1810
|
+
"BlockOperation",
|
|
1811
|
+
"DateComponentsFormatter",
|
|
1812
|
+
"ErrorUserInfoKey",
|
|
1813
|
+
"ListFormatter",
|
|
1814
|
+
"LocalizedStringResource",
|
|
1815
|
+
"MachError",
|
|
1816
|
+
"MeasurementFormatUnitUsage",
|
|
1817
|
+
"MessagePort",
|
|
1818
|
+
"NSAssertionHandler",
|
|
1819
|
+
"NSAttributedStringFormattingContextKey",
|
|
1820
|
+
"NSBundleResourceRequest",
|
|
1821
|
+
"NSConditionLock",
|
|
1822
|
+
"NSException",
|
|
1823
|
+
"NSExtensionItem",
|
|
1824
|
+
"NSFastEnumerationIterator",
|
|
1825
|
+
"NSFastEnumerationState",
|
|
1826
|
+
"NSFileAccessIntent",
|
|
1827
|
+
"NSFileManagerResumeSyncBehavior",
|
|
1828
|
+
"NSFileManagerSupportedSyncControls",
|
|
1829
|
+
"NSFileManagerUploadLocalVersionConflictPolicy",
|
|
1830
|
+
"NSFileProviderService",
|
|
1831
|
+
"NSFileProviderServiceName",
|
|
1832
|
+
"NSFileSecurity",
|
|
1833
|
+
"NSGrammaticalCase",
|
|
1834
|
+
"NSGrammaticalDefiniteness",
|
|
1835
|
+
"NSGrammaticalDetermination",
|
|
1836
|
+
"NSGrammaticalGender",
|
|
1837
|
+
"NSGrammaticalNumber",
|
|
1838
|
+
"NSGrammaticalPartOfSpeech",
|
|
1839
|
+
"NSGrammaticalPerson",
|
|
1840
|
+
"NSGrammaticalPronounType",
|
|
1841
|
+
"NSHashEnumerator",
|
|
1842
|
+
"NSHashTable",
|
|
1843
|
+
"NSHashTableCallBacks",
|
|
1844
|
+
"NSKeyValueOperator",
|
|
1845
|
+
"NSKeyValueSetMutationKind",
|
|
1846
|
+
"NSKeyValueSharedObservers",
|
|
1847
|
+
// clang Foundation owns the linguistic tagger types. A Swift twin is ambiguous with the header.
|
|
1848
|
+
"NSMachPort",
|
|
1849
|
+
"NSMapEnumerator",
|
|
1850
|
+
"NSMapTable",
|
|
1851
|
+
"NSMapTableKeyCallBacks",
|
|
1852
|
+
"NSMapTableValueCallBacks",
|
|
1853
|
+
"NSMetadataItem",
|
|
1854
|
+
"NSMetadataQuery",
|
|
1855
|
+
"NSMetadataQueryAttributeValueTuple",
|
|
1856
|
+
"NSMetadataQueryDelegate",
|
|
1857
|
+
"NSMetadataQueryResultGroup",
|
|
1858
|
+
"NSPointerArray",
|
|
1859
|
+
"NSPredicateValidating",
|
|
1860
|
+
"NSProxy",
|
|
1861
|
+
"NSPurgeableData",
|
|
1862
|
+
"NSSecureUnarchiveFromDataTransformer",
|
|
1863
|
+
"NSUbiquitousKeyValueStore",
|
|
1864
|
+
"NSXPCCoder",
|
|
1865
|
+
"NSXPCConnection",
|
|
1866
|
+
"NSXPCInterface",
|
|
1867
|
+
"NSXPCListener",
|
|
1868
|
+
"NSXPCListenerDelegate",
|
|
1869
|
+
"NSXPCListenerEndpoint",
|
|
1870
|
+
"OperationQueue",
|
|
1871
|
+
"PredicateCodableConfiguration",
|
|
1872
|
+
"PresentationIntent",
|
|
1873
|
+
"SocketPort",
|
|
1874
|
+
"StringEncodingDetectionOptionsKey",
|
|
1875
|
+
"TermOfAddress",
|
|
1876
|
+
"URLFileProtection",
|
|
1877
|
+
"URLResource",
|
|
1878
|
+
"URLUbiquitousItemDownloadingStatus",
|
|
1879
|
+
"URLUbiquitousSharedItemPermissions",
|
|
1880
|
+
"URLUbiquitousSharedItemRole",
|
|
1881
|
+
"ValueTransformer"
|
|
1882
|
+
]);
|
|
1883
|
+
var FOUNDATION_OVERLAY_GLOBALS = /* @__PURE__ */ new Set([
|
|
1884
|
+
"CFBridgingRetain",
|
|
1885
|
+
"NSAllHashTableObjects",
|
|
1886
|
+
"NSAllMapTableKeys",
|
|
1887
|
+
"NSAllMapTableValues",
|
|
1888
|
+
"NSAllocateMemoryPages",
|
|
1889
|
+
"NSAssertionHandlerKey",
|
|
1890
|
+
"NSBuddhistCalendar",
|
|
1891
|
+
"NSBundleResourceRequestLoadingPriorityUrgent",
|
|
1892
|
+
"NSChineseCalendar",
|
|
1893
|
+
"NSCompareHashTables",
|
|
1894
|
+
"NSCompareMapTables",
|
|
1895
|
+
"NSCopyMemoryPages",
|
|
1896
|
+
"NSCountHashTable",
|
|
1897
|
+
"NSCountMapTable",
|
|
1898
|
+
"NSCreateHashTable",
|
|
1899
|
+
"NSCreateMapTable",
|
|
1900
|
+
"NSDeallocateMemoryPages",
|
|
1901
|
+
"NSEndHashTableEnumeration",
|
|
1902
|
+
"NSEndMapTableEnumeration",
|
|
1903
|
+
"NSEnumerateHashTable",
|
|
1904
|
+
"NSEnumerateMapTable",
|
|
1905
|
+
"NSExtensionItemAttachmentsKey",
|
|
1906
|
+
"NSExtensionItemAttributedContentTextKey",
|
|
1907
|
+
"NSExtensionItemAttributedTitleKey",
|
|
1908
|
+
"NSExtensionItemsAndErrorsKey",
|
|
1909
|
+
"NSExtensionJavaScriptFinalizeArgumentKey",
|
|
1910
|
+
"NSExtensionJavaScriptPreprocessingResultsKey",
|
|
1911
|
+
"NSFreeHashTable",
|
|
1912
|
+
"NSFreeMapTable",
|
|
1913
|
+
"NSGetUncaughtExceptionHandler",
|
|
1914
|
+
"NSGregorianCalendar",
|
|
1915
|
+
"NSHashGet",
|
|
1916
|
+
"NSHashInsert",
|
|
1917
|
+
"NSHashInsertIfAbsent",
|
|
1918
|
+
"NSHashInsertKnownAbsent",
|
|
1919
|
+
"NSHashRemove",
|
|
1920
|
+
"NSHebrewCalendar",
|
|
1921
|
+
"NSISO8601Calendar",
|
|
1922
|
+
"NSIndianCalendar",
|
|
1923
|
+
"NSIslamicCalendar",
|
|
1924
|
+
"NSIslamicCivilCalendar",
|
|
1925
|
+
"NSItemProviderPreferredImageSizeKey",
|
|
1926
|
+
"NSJapaneseCalendar",
|
|
1927
|
+
"NSLoadedClasses",
|
|
1928
|
+
"NSLocalizedFailureErrorKey",
|
|
1929
|
+
"NSLogPageSize",
|
|
1930
|
+
"NSMACHOperatingSystem",
|
|
1931
|
+
"NSMapGet",
|
|
1932
|
+
"NSMapInsert",
|
|
1933
|
+
"NSMapInsertIfAbsent",
|
|
1934
|
+
"NSMapInsertKnownAbsent",
|
|
1935
|
+
"NSMapMember",
|
|
1936
|
+
"NSMapRemove",
|
|
1937
|
+
"NSMultipleUnderlyingErrorsKey",
|
|
1938
|
+
"NSNextHashEnumeratorItem",
|
|
1939
|
+
"NSNextMapEnumeratorPair",
|
|
1940
|
+
"NSNonOwnedPointerHashCallBacks",
|
|
1941
|
+
"NSNonOwnedPointerMapKeyCallBacks",
|
|
1942
|
+
"NSNonOwnedPointerMapValueCallBacks",
|
|
1943
|
+
"NSNonOwnedPointerOrNullMapKeyCallBacks",
|
|
1944
|
+
"NSNonRetainedObjectHashCallBacks",
|
|
1945
|
+
"NSNonRetainedObjectMapKeyCallBacks",
|
|
1946
|
+
"NSNonRetainedObjectMapValueCallBacks",
|
|
1947
|
+
"NSObjectHashCallBacks",
|
|
1948
|
+
"NSObjectMapKeyCallBacks",
|
|
1949
|
+
"NSObjectMapValueCallBacks",
|
|
1950
|
+
"NSOpenStepRootDirectory",
|
|
1951
|
+
"NSOwnedObjectIdentityHashCallBacks",
|
|
1952
|
+
"NSOwnedPointerHashCallBacks",
|
|
1953
|
+
"NSOwnedPointerMapKeyCallBacks",
|
|
1954
|
+
"NSOwnedPointerMapValueCallBacks",
|
|
1955
|
+
"NSPersianCalendar",
|
|
1956
|
+
"NSPointerToStructHashCallBacks",
|
|
1957
|
+
"NSPropertyListErrorMaximum",
|
|
1958
|
+
"NSPropertyListErrorMinimum",
|
|
1959
|
+
"NSRepublicOfChinaCalendar",
|
|
1960
|
+
"NSResetHashTable",
|
|
1961
|
+
"NSResetMapTable",
|
|
1962
|
+
"NSSolarisOperatingSystem",
|
|
1963
|
+
"NSStringFromHashTable",
|
|
1964
|
+
"NSStringFromMapTable",
|
|
1965
|
+
"NSSunOSOperatingSystem",
|
|
1966
|
+
"NSTextCheckingAllCustomTypes",
|
|
1967
|
+
"NSTextCheckingAllSystemTypes",
|
|
1968
|
+
"NSTextCheckingAllTypes",
|
|
1969
|
+
"NSURLAuthenticationMethodHTMLForm",
|
|
1970
|
+
"NSURLAuthenticationMethodNTLM",
|
|
1971
|
+
"NSURLAuthenticationMethodNegotiate",
|
|
1972
|
+
"NSURLCredentialStorageRemoveSynchronizableCredentials",
|
|
1973
|
+
"NSURLErrorFileOutsideSafeArea",
|
|
1974
|
+
"NSURLProtectionSpaceFTP",
|
|
1975
|
+
"NSURLProtectionSpaceFTPProxy",
|
|
1976
|
+
"NSURLProtectionSpaceHTTP",
|
|
1977
|
+
"NSURLProtectionSpaceHTTPProxy",
|
|
1978
|
+
"NSURLProtectionSpaceHTTPS",
|
|
1979
|
+
"NSURLProtectionSpaceHTTPSProxy",
|
|
1980
|
+
"NSURLProtectionSpaceSOCKSProxy",
|
|
1981
|
+
"NSURLSessionUploadTaskResumeData",
|
|
1982
|
+
"NSUbiquitousFileErrorMaximum",
|
|
1983
|
+
"NSUbiquitousFileErrorMinimum",
|
|
1984
|
+
"NSUbiquitousKeyValueStoreAccountChange",
|
|
1985
|
+
"NSUbiquitousKeyValueStoreChangeReasonKey",
|
|
1986
|
+
"NSUbiquitousKeyValueStoreChangedKeysKey",
|
|
1987
|
+
"NSUbiquitousKeyValueStoreInitialSyncChange",
|
|
1988
|
+
"NSUbiquitousKeyValueStoreQuotaViolationChange",
|
|
1989
|
+
"NSUbiquitousKeyValueStoreServerChange",
|
|
1990
|
+
"NSUndoCloseGroupingRunLoopOrdering",
|
|
1991
|
+
"NSUndoManagerGroupIsDiscardableKey",
|
|
1992
|
+
"NSUserActivityErrorMaximum",
|
|
1993
|
+
"NSUserActivityErrorMinimum",
|
|
1994
|
+
"NSValidationErrorMaximum",
|
|
1995
|
+
"NSValidationErrorMinimum",
|
|
1996
|
+
"NSWindows95OperatingSystem",
|
|
1997
|
+
"NSWindowsNTOperatingSystem",
|
|
1998
|
+
"NSWrapCalendarComponents",
|
|
1999
|
+
"NSXPCConnectionCodeSigningRequirementFailure",
|
|
2000
|
+
"NSXPCConnectionErrorMaximum",
|
|
2001
|
+
"NSXPCConnectionErrorMinimum",
|
|
2002
|
+
"kCFStringEncodingASCII"
|
|
2003
|
+
]);
|
|
2004
|
+
var CORE_FOUNDATION_OVERLAY_GLOBALS = /* @__PURE__ */ new Set([
|
|
2005
|
+
"kCFCoreFoundationVersionNumber10_0",
|
|
2006
|
+
"kCFCoreFoundationVersionNumber10_0_3",
|
|
2007
|
+
"kCFCoreFoundationVersionNumber10_1",
|
|
2008
|
+
"kCFCoreFoundationVersionNumber10_10",
|
|
2009
|
+
"kCFCoreFoundationVersionNumber10_10_1",
|
|
2010
|
+
"kCFCoreFoundationVersionNumber10_10_2",
|
|
2011
|
+
"kCFCoreFoundationVersionNumber10_10_3",
|
|
2012
|
+
"kCFCoreFoundationVersionNumber10_10_4",
|
|
2013
|
+
"kCFCoreFoundationVersionNumber10_10_5",
|
|
2014
|
+
"kCFCoreFoundationVersionNumber10_10_Max",
|
|
2015
|
+
"kCFCoreFoundationVersionNumber10_11",
|
|
2016
|
+
"kCFCoreFoundationVersionNumber10_11_1",
|
|
2017
|
+
"kCFCoreFoundationVersionNumber10_11_2",
|
|
2018
|
+
"kCFCoreFoundationVersionNumber10_11_3",
|
|
2019
|
+
"kCFCoreFoundationVersionNumber10_11_4",
|
|
2020
|
+
"kCFCoreFoundationVersionNumber10_11_Max",
|
|
2021
|
+
"kCFCoreFoundationVersionNumber10_1_1",
|
|
2022
|
+
"kCFCoreFoundationVersionNumber10_1_2",
|
|
2023
|
+
"kCFCoreFoundationVersionNumber10_1_3",
|
|
2024
|
+
"kCFCoreFoundationVersionNumber10_1_4",
|
|
2025
|
+
"kCFCoreFoundationVersionNumber10_2",
|
|
2026
|
+
"kCFCoreFoundationVersionNumber10_2_1",
|
|
2027
|
+
"kCFCoreFoundationVersionNumber10_2_2",
|
|
2028
|
+
"kCFCoreFoundationVersionNumber10_2_3",
|
|
2029
|
+
"kCFCoreFoundationVersionNumber10_2_4",
|
|
2030
|
+
"kCFCoreFoundationVersionNumber10_2_5",
|
|
2031
|
+
"kCFCoreFoundationVersionNumber10_2_6",
|
|
2032
|
+
"kCFCoreFoundationVersionNumber10_2_7",
|
|
2033
|
+
"kCFCoreFoundationVersionNumber10_2_8",
|
|
2034
|
+
"kCFCoreFoundationVersionNumber10_3",
|
|
2035
|
+
"kCFCoreFoundationVersionNumber10_3_1",
|
|
2036
|
+
"kCFCoreFoundationVersionNumber10_3_2",
|
|
2037
|
+
"kCFCoreFoundationVersionNumber10_3_3",
|
|
2038
|
+
"kCFCoreFoundationVersionNumber10_3_4",
|
|
2039
|
+
"kCFCoreFoundationVersionNumber10_3_5",
|
|
2040
|
+
"kCFCoreFoundationVersionNumber10_3_6",
|
|
2041
|
+
"kCFCoreFoundationVersionNumber10_3_7",
|
|
2042
|
+
"kCFCoreFoundationVersionNumber10_3_8",
|
|
2043
|
+
"kCFCoreFoundationVersionNumber10_3_9",
|
|
2044
|
+
"kCFCoreFoundationVersionNumber10_4",
|
|
2045
|
+
"kCFCoreFoundationVersionNumber10_4_1",
|
|
2046
|
+
"kCFCoreFoundationVersionNumber10_4_10",
|
|
2047
|
+
"kCFCoreFoundationVersionNumber10_4_11",
|
|
2048
|
+
"kCFCoreFoundationVersionNumber10_4_2",
|
|
2049
|
+
"kCFCoreFoundationVersionNumber10_4_3",
|
|
2050
|
+
"kCFCoreFoundationVersionNumber10_4_4_Intel",
|
|
2051
|
+
"kCFCoreFoundationVersionNumber10_4_4_PowerPC",
|
|
2052
|
+
"kCFCoreFoundationVersionNumber10_4_5_Intel",
|
|
2053
|
+
"kCFCoreFoundationVersionNumber10_4_5_PowerPC",
|
|
2054
|
+
"kCFCoreFoundationVersionNumber10_4_6_Intel",
|
|
2055
|
+
"kCFCoreFoundationVersionNumber10_4_6_PowerPC",
|
|
2056
|
+
"kCFCoreFoundationVersionNumber10_4_7",
|
|
2057
|
+
"kCFCoreFoundationVersionNumber10_4_8",
|
|
2058
|
+
"kCFCoreFoundationVersionNumber10_4_9",
|
|
2059
|
+
"kCFCoreFoundationVersionNumber10_5",
|
|
2060
|
+
"kCFCoreFoundationVersionNumber10_5_1",
|
|
2061
|
+
"kCFCoreFoundationVersionNumber10_5_2",
|
|
2062
|
+
"kCFCoreFoundationVersionNumber10_5_3",
|
|
2063
|
+
"kCFCoreFoundationVersionNumber10_5_4",
|
|
2064
|
+
"kCFCoreFoundationVersionNumber10_5_5",
|
|
2065
|
+
"kCFCoreFoundationVersionNumber10_5_6",
|
|
2066
|
+
"kCFCoreFoundationVersionNumber10_5_7",
|
|
2067
|
+
"kCFCoreFoundationVersionNumber10_5_8",
|
|
2068
|
+
"kCFCoreFoundationVersionNumber10_6",
|
|
2069
|
+
"kCFCoreFoundationVersionNumber10_6_1",
|
|
2070
|
+
"kCFCoreFoundationVersionNumber10_6_2",
|
|
2071
|
+
"kCFCoreFoundationVersionNumber10_6_3",
|
|
2072
|
+
"kCFCoreFoundationVersionNumber10_6_4",
|
|
2073
|
+
"kCFCoreFoundationVersionNumber10_6_5",
|
|
2074
|
+
"kCFCoreFoundationVersionNumber10_6_6",
|
|
2075
|
+
"kCFCoreFoundationVersionNumber10_6_7",
|
|
2076
|
+
"kCFCoreFoundationVersionNumber10_6_8",
|
|
2077
|
+
"kCFCoreFoundationVersionNumber10_7",
|
|
2078
|
+
"kCFCoreFoundationVersionNumber10_7_1",
|
|
2079
|
+
"kCFCoreFoundationVersionNumber10_7_2",
|
|
2080
|
+
"kCFCoreFoundationVersionNumber10_7_3",
|
|
2081
|
+
"kCFCoreFoundationVersionNumber10_7_4",
|
|
2082
|
+
"kCFCoreFoundationVersionNumber10_7_5",
|
|
2083
|
+
"kCFCoreFoundationVersionNumber10_8",
|
|
2084
|
+
"kCFCoreFoundationVersionNumber10_8_1",
|
|
2085
|
+
"kCFCoreFoundationVersionNumber10_8_2",
|
|
2086
|
+
"kCFCoreFoundationVersionNumber10_8_3",
|
|
2087
|
+
"kCFCoreFoundationVersionNumber10_8_4",
|
|
2088
|
+
"kCFCoreFoundationVersionNumber10_9",
|
|
2089
|
+
"kCFCoreFoundationVersionNumber10_9_1",
|
|
2090
|
+
"kCFCoreFoundationVersionNumber10_9_2",
|
|
2091
|
+
"kCFCoreFoundationVersionNumber_iOS_4_0",
|
|
2092
|
+
"kCFCoreFoundationVersionNumber_iOS_4_1",
|
|
2093
|
+
"kCFCoreFoundationVersionNumber_iOS_4_2",
|
|
2094
|
+
"kCFCoreFoundationVersionNumber_iOS_4_3",
|
|
2095
|
+
"kCFCoreFoundationVersionNumber_iOS_5_0",
|
|
2096
|
+
"kCFCoreFoundationVersionNumber_iOS_5_1",
|
|
2097
|
+
"kCFCoreFoundationVersionNumber_iOS_6_0",
|
|
2098
|
+
"kCFCoreFoundationVersionNumber_iOS_6_1",
|
|
2099
|
+
"kCFCoreFoundationVersionNumber_iOS_7_0",
|
|
2100
|
+
"kCFCoreFoundationVersionNumber_iOS_7_1",
|
|
2101
|
+
"kCFCoreFoundationVersionNumber_iOS_8_0",
|
|
2102
|
+
"kCFCoreFoundationVersionNumber_iOS_8_1",
|
|
2103
|
+
"kCFCoreFoundationVersionNumber_iOS_8_2",
|
|
2104
|
+
"kCFCoreFoundationVersionNumber_iOS_8_3",
|
|
2105
|
+
"kCFCoreFoundationVersionNumber_iOS_8_4",
|
|
2106
|
+
"kCFCoreFoundationVersionNumber_iOS_8_x_Max",
|
|
2107
|
+
"kCFCoreFoundationVersionNumber_iOS_9_0",
|
|
2108
|
+
"kCFCoreFoundationVersionNumber_iOS_9_1",
|
|
2109
|
+
"kCFCoreFoundationVersionNumber_iOS_9_2",
|
|
2110
|
+
"kCFCoreFoundationVersionNumber_iOS_9_3",
|
|
2111
|
+
"kCFCoreFoundationVersionNumber_iOS_9_4",
|
|
2112
|
+
"kCFCoreFoundationVersionNumber_iOS_9_x_Max",
|
|
2113
|
+
"kCFCoreFoundationVersionNumber_iPhoneOS_2_0",
|
|
2114
|
+
"kCFCoreFoundationVersionNumber_iPhoneOS_2_1",
|
|
2115
|
+
"kCFCoreFoundationVersionNumber_iPhoneOS_2_2",
|
|
2116
|
+
"kCFCoreFoundationVersionNumber_iPhoneOS_3_0",
|
|
2117
|
+
"kCFCoreFoundationVersionNumber_iPhoneOS_3_1",
|
|
2118
|
+
"kCFCoreFoundationVersionNumber_iPhoneOS_3_2"
|
|
2119
|
+
]);
|
|
2120
|
+
function foundationOwnerOf(name) {
|
|
2121
|
+
if (name === "NSKeyValueObservedChange" || name === "NSKeyValueObservation")
|
|
2122
|
+
return "PeachObjC";
|
|
2123
|
+
if (name === "DispatchData") return "Dispatch";
|
|
2124
|
+
if (FOUNDATION_NETWORKING_TYPES.has(name)) return "FoundationNetworking";
|
|
2125
|
+
if (FOUNDATION_OVERLAY_TYPES.has(name) || FOUNDATION_OVERLAY_GLOBALS.has(name) || CORE_FOUNDATION_OVERLAY_GLOBALS.has(name))
|
|
2126
|
+
return "PeachFoundation";
|
|
2127
|
+
return void 0;
|
|
2128
|
+
}
|
|
2129
|
+
var emptyMacroEnvironment = {
|
|
2130
|
+
defines: /* @__PURE__ */ new Map(),
|
|
2131
|
+
predefines: /* @__PURE__ */ new Map(),
|
|
2132
|
+
targetDefined: /* @__PURE__ */ new Set()
|
|
2133
|
+
};
|
|
2134
|
+
function cMacroDefined(name, env) {
|
|
2135
|
+
if (env.defines.has(name) || env.predefines.has(name)) return true;
|
|
2136
|
+
if (env.targetDefined.has(name)) return void 0;
|
|
2137
|
+
return false;
|
|
2138
|
+
}
|
|
2139
|
+
function cMacroIntOrTrue(value) {
|
|
2140
|
+
if (value === void 0) return true;
|
|
2141
|
+
if (/^0[xX][0-9a-fA-F]+[uUlL]*$/.test(value) || /^\d+[uUlL]*$/.test(value))
|
|
2142
|
+
return Number.parseInt(value) !== 0;
|
|
2143
|
+
return void 0;
|
|
2144
|
+
}
|
|
2145
|
+
function cMacroBareValue(name, env) {
|
|
2146
|
+
if (env.defines.has(name)) return cMacroIntOrTrue(env.defines.get(name));
|
|
2147
|
+
if (env.predefines.has(name)) return cMacroIntOrTrue(env.predefines.get(name));
|
|
2148
|
+
if (env.targetDefined.has(name)) return void 0;
|
|
2149
|
+
return false;
|
|
2150
|
+
}
|
|
2151
|
+
function cMacroNegated(name, env) {
|
|
2152
|
+
return kleeneNot(cMacroDefined(name, env));
|
|
2153
|
+
}
|
|
2154
|
+
function cConditionValue(expression, env) {
|
|
2155
|
+
let i = 0;
|
|
2156
|
+
const skipSpaces = () => {
|
|
2157
|
+
while (i < expression.length && /\s/.test(expression[i])) i++;
|
|
2158
|
+
};
|
|
2159
|
+
const parseOr = () => {
|
|
2160
|
+
let value2 = parseAnd();
|
|
2161
|
+
for (; ; ) {
|
|
2162
|
+
skipSpaces();
|
|
2163
|
+
if (!expression.startsWith("||", i)) return value2;
|
|
2164
|
+
i += 2;
|
|
2165
|
+
value2 = kleeneOr(value2, parseAnd());
|
|
2166
|
+
}
|
|
2167
|
+
};
|
|
2168
|
+
const parseAnd = () => {
|
|
2169
|
+
let value2 = parseUnary();
|
|
2170
|
+
for (; ; ) {
|
|
2171
|
+
skipSpaces();
|
|
2172
|
+
if (!expression.startsWith("&&", i)) return value2;
|
|
2173
|
+
i += 2;
|
|
2174
|
+
value2 = kleeneAnd(value2, parseUnary());
|
|
2175
|
+
}
|
|
2176
|
+
};
|
|
2177
|
+
const parseUnary = () => {
|
|
2178
|
+
skipSpaces();
|
|
2179
|
+
if (expression[i] === "!") {
|
|
2180
|
+
i++;
|
|
2181
|
+
return kleeneNot(parseUnary());
|
|
2182
|
+
}
|
|
2183
|
+
if (expression[i] === "(") {
|
|
2184
|
+
i++;
|
|
2185
|
+
const value2 = parseOr();
|
|
2186
|
+
skipSpaces();
|
|
2187
|
+
return expression[i] === ")" ? (i++, value2) : void 0;
|
|
2188
|
+
}
|
|
2189
|
+
const defined = /^defined\b/.exec(expression.slice(i));
|
|
2190
|
+
if (defined) {
|
|
2191
|
+
i += defined[0].length;
|
|
2192
|
+
skipSpaces();
|
|
2193
|
+
const parenthesized = expression[i] === "(";
|
|
2194
|
+
if (parenthesized) {
|
|
2195
|
+
i++;
|
|
2196
|
+
skipSpaces();
|
|
2197
|
+
}
|
|
2198
|
+
const name2 = /^\w+/.exec(expression.slice(i))?.[0];
|
|
2199
|
+
if (!name2) return void 0;
|
|
2200
|
+
i += name2.length;
|
|
2201
|
+
skipSpaces();
|
|
2202
|
+
if (parenthesized) {
|
|
2203
|
+
if (expression[i] !== ")") return void 0;
|
|
2204
|
+
i++;
|
|
2205
|
+
}
|
|
2206
|
+
return cMacroDefined(name2, env);
|
|
2207
|
+
}
|
|
2208
|
+
const literal = /^(0[xX][0-9a-fA-F]+|\d+)[uUlL]*/.exec(expression.slice(i));
|
|
2209
|
+
if (literal) {
|
|
2210
|
+
i += literal[0].length;
|
|
2211
|
+
return Number(literal[1]) !== 0;
|
|
2212
|
+
}
|
|
2213
|
+
const name = /^\w+/.exec(expression.slice(i))?.[0];
|
|
2214
|
+
if (!name) return void 0;
|
|
2215
|
+
i += name.length;
|
|
2216
|
+
return cMacroBareValue(name, env);
|
|
2217
|
+
};
|
|
2218
|
+
const value = parseOr();
|
|
2219
|
+
skipSpaces();
|
|
2220
|
+
return i === expression.length ? value : void 0;
|
|
2221
|
+
}
|
|
2222
|
+
function cActiveCode(code, env) {
|
|
2223
|
+
const kept = [];
|
|
2224
|
+
const stack = [];
|
|
2225
|
+
let active = true;
|
|
2226
|
+
for (const line of code.replace(/\\\r?\n/g, "").split("\n")) {
|
|
2227
|
+
const directive = /^\s*#\s*(if|ifdef|ifndef|elif|elifdef|elifndef|else|endif)\b(.*)$/.exec(line);
|
|
2228
|
+
if (!directive) {
|
|
2229
|
+
if (active) kept.push(line);
|
|
2230
|
+
continue;
|
|
2231
|
+
}
|
|
2232
|
+
const keyword = directive[1];
|
|
2233
|
+
const rest = directive[2].trim();
|
|
2234
|
+
if (keyword === "if" || keyword === "ifdef" || keyword === "ifndef") {
|
|
2235
|
+
const name = /^\w+$/.exec(rest)?.[0];
|
|
2236
|
+
const value = keyword === "if" ? cConditionValue(rest, env) : name === void 0 ? void 0 : keyword === "ifdef" ? cMacroDefined(name, env) : cMacroNegated(name, env);
|
|
2237
|
+
stack.push({ parent: active, taken: value === true });
|
|
2238
|
+
active = active && value !== false;
|
|
2239
|
+
} else if (keyword === "endif") {
|
|
2240
|
+
active = stack.pop()?.parent ?? true;
|
|
2241
|
+
} else if (stack.length === 0) {
|
|
2242
|
+
continue;
|
|
2243
|
+
} else {
|
|
2244
|
+
const frame = stack[stack.length - 1];
|
|
2245
|
+
if (keyword === "else") {
|
|
2246
|
+
active = frame.parent && !frame.taken;
|
|
2247
|
+
frame.taken = true;
|
|
2248
|
+
} else {
|
|
2249
|
+
const name = /^\w+$/.exec(rest)?.[0];
|
|
2250
|
+
const value = keyword === "elif" ? cConditionValue(rest, env) : name === void 0 ? void 0 : keyword === "elifdef" ? cMacroDefined(name, env) : cMacroNegated(name, env);
|
|
2251
|
+
const branch = !frame.taken && value !== false;
|
|
2252
|
+
if (branch && value === true) frame.taken = true;
|
|
2253
|
+
active = frame.parent && branch;
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
return kept.join("\n");
|
|
2258
|
+
}
|
|
2259
|
+
function stripCCode(source) {
|
|
2260
|
+
let code = "";
|
|
2261
|
+
let i = 0;
|
|
2262
|
+
while (i < source.length) {
|
|
2263
|
+
if (source.startsWith("//", i)) {
|
|
2264
|
+
const end = source.indexOf("\n", i);
|
|
2265
|
+
i = end === -1 ? source.length : end;
|
|
2266
|
+
} else if (source.startsWith("/*", i)) {
|
|
2267
|
+
const end = source.indexOf("*/", i + 2);
|
|
2268
|
+
i = end === -1 ? source.length : end + 2;
|
|
2269
|
+
} else if (source[i] === '"' || source[i] === "'") {
|
|
2270
|
+
const quote = source[i];
|
|
2271
|
+
i++;
|
|
2272
|
+
while (i < source.length && source[i] !== quote) i += source[i] === "\\" ? 2 : 1;
|
|
2273
|
+
i++;
|
|
2274
|
+
} else {
|
|
2275
|
+
code += source[i];
|
|
2276
|
+
i++;
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
return code;
|
|
2280
|
+
}
|
|
2281
|
+
var wasmMacroEnvironment = {
|
|
2282
|
+
...emptyMacroEnvironment,
|
|
2283
|
+
defines: /* @__PURE__ */ new Map([
|
|
2284
|
+
["__wasm__", "1"],
|
|
2285
|
+
["__wasm64__", "1"],
|
|
2286
|
+
["__wasi__", "1"]
|
|
2287
|
+
])
|
|
2288
|
+
};
|
|
2289
|
+
function swiftCTakesReturnAddress(source) {
|
|
2290
|
+
if (!source.includes("__builtin_return_address")) return false;
|
|
2291
|
+
return /\b__builtin_return_address\s*\(/.test(
|
|
2292
|
+
cActiveCode(stripCCode(source), wasmMacroEnvironment)
|
|
2293
|
+
);
|
|
2294
|
+
}
|
|
2295
|
+
function swiftCDefinedNames(sources) {
|
|
2296
|
+
const names = /* @__PURE__ */ new Set();
|
|
2297
|
+
for (const source of sources)
|
|
2298
|
+
for (const line of stripCCode(source).split("\n")) {
|
|
2299
|
+
const name = /^\s*#\s*define\s+([A-Za-z_]\w*)/.exec(line)?.[1];
|
|
2300
|
+
if (name) names.add(name);
|
|
2301
|
+
}
|
|
2302
|
+
return names;
|
|
2303
|
+
}
|
|
2304
|
+
function swiftModuleCompiler(root) {
|
|
2305
|
+
const pin = swiftDistributionAt(root) ?? JSON.parse(readFileSync4(path9.join(root, "toolchain.json"), "utf8"));
|
|
2306
|
+
return {
|
|
2307
|
+
release: pin.release,
|
|
2308
|
+
toolchainBin: swiftCompiler(pin.release)
|
|
2309
|
+
};
|
|
2310
|
+
}
|
|
2311
|
+
function swiftModuleToolchain(root) {
|
|
2312
|
+
const { release } = swiftModuleCompiler(root);
|
|
2313
|
+
return { release, toolchainBin: swiftToolchain(release, swiftModuleSdk(root)) };
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
// ../contrast-runtime-delivery/src/index.ts
|
|
2317
|
+
import { spawn } from "node:child_process";
|
|
2318
|
+
import crypto from "node:crypto";
|
|
2319
|
+
import fs6 from "node:fs";
|
|
2320
|
+
import os2 from "node:os";
|
|
2321
|
+
import path11 from "node:path";
|
|
2322
|
+
import { pipeline } from "node:stream/promises";
|
|
2323
|
+
import zlib from "node:zlib";
|
|
2324
|
+
|
|
2325
|
+
// ../contrast-runtime-delivery/src/product.ts
|
|
2326
|
+
import fs5 from "node:fs";
|
|
2327
|
+
import path10 from "node:path";
|
|
2328
|
+
|
|
2329
|
+
// ../contrast-runtime-delivery/src/index.ts
|
|
2330
|
+
async function installVerifiedTarball(tarball) {
|
|
2331
|
+
const { destDir, installedMarker, signal } = tarball;
|
|
2332
|
+
fs6.mkdirSync(path11.dirname(destDir), { recursive: true });
|
|
2333
|
+
const presentAtStart = fs6.existsSync(path11.join(destDir, installedMarker));
|
|
2334
|
+
const lock = `${destDir}.lock`;
|
|
2335
|
+
for (; ; ) {
|
|
2336
|
+
signal?.throwIfAborted();
|
|
2337
|
+
try {
|
|
2338
|
+
fs6.writeFileSync(lock, String(process.pid), { flag: "wx" });
|
|
2339
|
+
break;
|
|
2340
|
+
} catch (err) {
|
|
2341
|
+
if (!isErrnoCode(err, "EEXIST")) throw err;
|
|
2342
|
+
if (lockOwnerGone(lock)) fs6.rmSync(lock, { force: true });
|
|
2343
|
+
else await new Promise((resolve) => setTimeout(resolve, 250));
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
try {
|
|
2347
|
+
if (!presentAtStart && fs6.existsSync(path11.join(destDir, installedMarker))) {
|
|
2348
|
+
await tarball.verify?.(destDir);
|
|
2349
|
+
return;
|
|
2350
|
+
}
|
|
2351
|
+
await installVerifiedTarballLocked(tarball, presentAtStart);
|
|
2352
|
+
} finally {
|
|
2353
|
+
fs6.rmSync(lock, { force: true });
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
function lockOwnerGone(lock) {
|
|
2357
|
+
try {
|
|
2358
|
+
process.kill(Number(fs6.readFileSync(lock, "utf8")), 0);
|
|
2359
|
+
return false;
|
|
2360
|
+
} catch (err) {
|
|
2361
|
+
return !isErrnoCode(err, "EPERM", "ENOENT");
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
async function installVerifiedTarballLocked(tarball, presentAtStart) {
|
|
2365
|
+
const { url, digest, destDir, installedMarker, label, localPath, signal } = tarball;
|
|
2366
|
+
signal?.throwIfAborted();
|
|
2367
|
+
const downloadDir = fs6.mkdtempSync(path11.join(os2.tmpdir(), "runtime-delivery-download-"));
|
|
2368
|
+
const archivePath = localPath ?? path11.join(downloadDir, "archive");
|
|
2369
|
+
const tmpDir = fs6.mkdtempSync(
|
|
2370
|
+
path11.join(path11.dirname(destDir), `.installing-${path11.basename(destDir)}-`)
|
|
2371
|
+
);
|
|
2372
|
+
try {
|
|
2373
|
+
for (let attempt = 1; ; attempt++) {
|
|
2374
|
+
if (!localPath) await downloadToFile(url, archivePath, signal);
|
|
2375
|
+
const actual = await digestFile(
|
|
2376
|
+
archivePath,
|
|
2377
|
+
digest.algorithm,
|
|
2378
|
+
digest.encoding,
|
|
2379
|
+
signal
|
|
2380
|
+
);
|
|
2381
|
+
if (actual === digest.value) break;
|
|
2382
|
+
if (localPath || attempt >= 2) {
|
|
2383
|
+
throw new Error(
|
|
2384
|
+
`${digest.algorithm} mismatch for ${label}: expected ${digest.value}, actual ${actual}`
|
|
2385
|
+
);
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
const { pathname } = new URL(url);
|
|
2389
|
+
if (pathname.endsWith(".zip")) await extractZip(archivePath, tmpDir, signal);
|
|
2390
|
+
else
|
|
2391
|
+
await extractTarball(
|
|
2392
|
+
archivePath,
|
|
2393
|
+
pathname.endsWith(".tar.zst"),
|
|
2394
|
+
tmpDir,
|
|
2395
|
+
tarball.stripComponents ?? 0,
|
|
2396
|
+
signal
|
|
2397
|
+
);
|
|
2398
|
+
signal?.throwIfAborted();
|
|
2399
|
+
if (!fs6.existsSync(path11.join(tmpDir, installedMarker))) {
|
|
2400
|
+
throw new Error(`extracted tarball for ${label} is missing ${installedMarker}`);
|
|
2401
|
+
}
|
|
2402
|
+
await tarball.verify?.(tmpDir);
|
|
2403
|
+
signal?.throwIfAborted();
|
|
2404
|
+
try {
|
|
2405
|
+
fs6.renameSync(tmpDir, destDir);
|
|
2406
|
+
} catch (err) {
|
|
2407
|
+
if (!isErrnoCode(err, "ENOTEMPTY", "EEXIST")) throw err;
|
|
2408
|
+
if (!presentAtStart && fs6.existsSync(path11.join(destDir, installedMarker))) {
|
|
2409
|
+
await tarball.verify?.(destDir);
|
|
2410
|
+
return;
|
|
2411
|
+
}
|
|
2412
|
+
const aside = `${tmpDir}-replaced`;
|
|
2413
|
+
try {
|
|
2414
|
+
fs6.renameSync(destDir, aside);
|
|
2415
|
+
} catch (moveErr) {
|
|
2416
|
+
if (!isErrnoCode(moveErr, "ENOENT")) throw moveErr;
|
|
2417
|
+
}
|
|
2418
|
+
try {
|
|
2419
|
+
fs6.renameSync(tmpDir, destDir);
|
|
2420
|
+
} catch (landErr) {
|
|
2421
|
+
if (!isErrnoCode(landErr, "ENOTEMPTY", "EEXIST") || !fs6.existsSync(path11.join(destDir, installedMarker))) {
|
|
2422
|
+
throw landErr;
|
|
2423
|
+
}
|
|
2424
|
+
await tarball.verify?.(destDir);
|
|
2425
|
+
} finally {
|
|
2426
|
+
fs6.rmSync(aside, { recursive: true, force: true });
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
} finally {
|
|
2430
|
+
fs6.rmSync(tmpDir, { recursive: true, force: true });
|
|
2431
|
+
fs6.rmSync(downloadDir, { recursive: true, force: true });
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
function isErrnoCode(err, ...codes) {
|
|
2435
|
+
return err instanceof Error && "code" in err && codes.includes(String(err.code));
|
|
2436
|
+
}
|
|
2437
|
+
var DownloadHttpError = class extends Error {
|
|
2438
|
+
constructor(status, statusText, url) {
|
|
2439
|
+
super(`download failed: ${status} ${statusText} (${url})`);
|
|
2440
|
+
__publicField(this, "retryable");
|
|
2441
|
+
this.retryable = status < 400 || status >= 500 || status === 408 || status === 429;
|
|
2442
|
+
}
|
|
2443
|
+
};
|
|
2444
|
+
async function waitRetryDelay(ms, signal) {
|
|
2445
|
+
signal?.throwIfAborted();
|
|
2446
|
+
await new Promise((resolve, reject) => {
|
|
2447
|
+
const onAbort = () => {
|
|
2448
|
+
clearTimeout(timer);
|
|
2449
|
+
const reason = signal?.reason;
|
|
2450
|
+
reject(
|
|
2451
|
+
reason instanceof Error ? reason : new Error("Download canceled", { cause: reason })
|
|
2452
|
+
);
|
|
2453
|
+
};
|
|
2454
|
+
const timer = setTimeout(() => {
|
|
2455
|
+
signal?.removeEventListener("abort", onAbort);
|
|
2456
|
+
resolve();
|
|
2457
|
+
}, ms);
|
|
2458
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
2459
|
+
});
|
|
2460
|
+
}
|
|
2461
|
+
async function downloadToFile(url, destPath, signal) {
|
|
2462
|
+
fs6.mkdirSync(path11.dirname(destPath), { recursive: true });
|
|
2463
|
+
const tmp = `${destPath}.partial`;
|
|
2464
|
+
for (let attempt = 1; attempt <= 4; attempt++) {
|
|
2465
|
+
signal?.throwIfAborted();
|
|
2466
|
+
let reader;
|
|
2467
|
+
let handle;
|
|
2468
|
+
let completed = false;
|
|
2469
|
+
try {
|
|
2470
|
+
const res = await fetch(url, { signal });
|
|
2471
|
+
if (!res.ok || !res.body) {
|
|
2472
|
+
throw new DownloadHttpError(res.status, res.statusText, url);
|
|
2473
|
+
}
|
|
2474
|
+
reader = res.body.getReader();
|
|
2475
|
+
handle = await fs6.promises.open(tmp, "w");
|
|
2476
|
+
let written = 0;
|
|
2477
|
+
for (; ; ) {
|
|
2478
|
+
signal?.throwIfAborted();
|
|
2479
|
+
const { done, value } = await reader.read();
|
|
2480
|
+
if (done) break;
|
|
2481
|
+
let offset = 0;
|
|
2482
|
+
while (offset < value.byteLength) {
|
|
2483
|
+
const { bytesWritten } = await handle.write(
|
|
2484
|
+
value,
|
|
2485
|
+
offset,
|
|
2486
|
+
value.byteLength - offset
|
|
2487
|
+
);
|
|
2488
|
+
offset += bytesWritten;
|
|
2489
|
+
}
|
|
2490
|
+
written += value.byteLength;
|
|
2491
|
+
}
|
|
2492
|
+
await handle.close();
|
|
2493
|
+
handle = void 0;
|
|
2494
|
+
if (!res.headers.get("content-encoding")) {
|
|
2495
|
+
const header = res.headers.get("content-length");
|
|
2496
|
+
const expected = header ? Number(header) : Number.NaN;
|
|
2497
|
+
if (Number.isFinite(expected) && expected > 0 && written !== expected) {
|
|
2498
|
+
throw new Error(`incomplete download (${written}/${expected} bytes): ${url}`);
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
signal?.throwIfAborted();
|
|
2502
|
+
fs6.renameSync(tmp, destPath);
|
|
2503
|
+
completed = true;
|
|
2504
|
+
return;
|
|
2505
|
+
} catch (err) {
|
|
2506
|
+
if (handle) await handle.close().catch(() => {
|
|
2507
|
+
});
|
|
2508
|
+
if (reader && !completed) await reader.cancel().catch(() => {
|
|
2509
|
+
});
|
|
2510
|
+
try {
|
|
2511
|
+
fs6.unlinkSync(tmp);
|
|
2512
|
+
} catch {
|
|
2513
|
+
}
|
|
2514
|
+
const nonRetryable = err instanceof DownloadHttpError && !err.retryable;
|
|
2515
|
+
if (signal?.aborted || nonRetryable || attempt === 4) throw err;
|
|
2516
|
+
await waitRetryDelay(250 * attempt, signal);
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
async function digestFile(filePath, algorithm, encoding, signal) {
|
|
2521
|
+
const hash = crypto.createHash(algorithm);
|
|
2522
|
+
await pipeline(fs6.createReadStream(filePath), hash, { signal });
|
|
2523
|
+
return hash.digest(encoding);
|
|
2524
|
+
}
|
|
2525
|
+
function extractZip(zipPath, destDir, signal) {
|
|
2526
|
+
return runExtractor("ditto", ["-x", "-k", zipPath, destDir], signal);
|
|
2527
|
+
}
|
|
2528
|
+
async function extractTarball(tarPath, zstd, destDir, stripComponents, signal) {
|
|
2529
|
+
const args = [zstd ? "-xf" : "-xzf", "-"];
|
|
2530
|
+
if (stripComponents > 0) args.push(`--strip-components=${stripComponents}`);
|
|
2531
|
+
if (zstd) {
|
|
2532
|
+
const decoder = zlib.createZstdDecompress({
|
|
2533
|
+
params: { [zlib.constants.ZSTD_d_windowLogMax]: 30 }
|
|
2534
|
+
});
|
|
2535
|
+
await runExtractor("tar", ["--ignore-zeros", ...args], signal, {
|
|
2536
|
+
cwd: destDir,
|
|
2537
|
+
stdin: (stdin) => pipeline(fs6.createReadStream(tarPath), decoder, stdin, { signal })
|
|
2538
|
+
});
|
|
2539
|
+
return;
|
|
2540
|
+
}
|
|
2541
|
+
const archive = fs6.openSync(tarPath, "r");
|
|
2542
|
+
try {
|
|
2543
|
+
await runExtractor("tar", args, signal, { cwd: destDir, stdin: archive });
|
|
2544
|
+
} finally {
|
|
2545
|
+
fs6.closeSync(archive);
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
async function runExtractor(command, args, signal, input) {
|
|
2549
|
+
signal?.throwIfAborted();
|
|
2550
|
+
const stdin = input?.stdin;
|
|
2551
|
+
const stdio = [
|
|
2552
|
+
typeof stdin === "function" ? "pipe" : stdin ?? "ignore",
|
|
2553
|
+
"inherit",
|
|
2554
|
+
"inherit"
|
|
2555
|
+
];
|
|
2556
|
+
const child = spawn(command, args, {
|
|
2557
|
+
cwd: input?.cwd,
|
|
2558
|
+
stdio,
|
|
2559
|
+
detached: process.platform !== "win32"
|
|
2560
|
+
});
|
|
2561
|
+
const fed = typeof stdin === "function" && child.stdin ? stdin(child.stdin) : void 0;
|
|
2562
|
+
void fed?.catch(() => {
|
|
2563
|
+
});
|
|
2564
|
+
let stopping;
|
|
2565
|
+
const abort = () => {
|
|
2566
|
+
stopping ?? (stopping = terminateProcessGroup(child, "SIGKILL", 0));
|
|
2567
|
+
void stopping.catch(() => {
|
|
2568
|
+
});
|
|
2569
|
+
};
|
|
2570
|
+
try {
|
|
2571
|
+
await new Promise((resolve, reject) => {
|
|
2572
|
+
let failure;
|
|
2573
|
+
child.on("error", (error) => {
|
|
2574
|
+
failure = error;
|
|
2575
|
+
});
|
|
2576
|
+
child.on("close", (code) => {
|
|
2577
|
+
if (signal?.aborted) {
|
|
2578
|
+
const reason = signal.reason;
|
|
2579
|
+
reject(
|
|
2580
|
+
reason instanceof Error ? reason : new Error("Extraction canceled", { cause: reason })
|
|
2581
|
+
);
|
|
2582
|
+
} else if (failure) reject(failure);
|
|
2583
|
+
else if (code === 0) resolve();
|
|
2584
|
+
else reject(new Error(`${command} exited with code ${code}`));
|
|
2585
|
+
});
|
|
2586
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
2587
|
+
if (signal?.aborted) abort();
|
|
2588
|
+
});
|
|
2589
|
+
await fed;
|
|
2590
|
+
} finally {
|
|
2591
|
+
signal?.removeEventListener("abort", abort);
|
|
2592
|
+
await stopping;
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
|
|
2596
|
+
export {
|
|
2597
|
+
writeBuildFile,
|
|
2598
|
+
caseInsensitiveHeaderOverlay,
|
|
2599
|
+
swiftObjCPlatformFlags,
|
|
2600
|
+
NATIVE_GRAPH_SDK_VERSION,
|
|
2601
|
+
WASI_EMULATION_FLAGS,
|
|
2602
|
+
objcSdkIntakeFlags,
|
|
2603
|
+
iosDeploymentMinimum,
|
|
2604
|
+
rnxHomeDir,
|
|
2605
|
+
runtimeDir,
|
|
2606
|
+
cacheDir,
|
|
2607
|
+
readActiveRuntime,
|
|
2608
|
+
installVerifiedTarball,
|
|
2609
|
+
SWIFT_DISTRIBUTION_MANIFEST,
|
|
2610
|
+
SWIFT_DISTRIBUTION_OBJC_SELECTORS,
|
|
2611
|
+
parseSwiftDistributionLock,
|
|
2612
|
+
swiftCodeScan,
|
|
2613
|
+
mapSwiftConditionalLines,
|
|
2614
|
+
SWIFT_DISTRIBUTION_MIRROR_RECORD,
|
|
2615
|
+
swiftSharedSdkRoot,
|
|
2616
|
+
swiftSharedSdkFlags,
|
|
2617
|
+
weakenFoundationOverridesInArchive,
|
|
2618
|
+
swiftBuildJobs,
|
|
2619
|
+
swiftDistributionAt,
|
|
2620
|
+
swiftDistributionCompileView,
|
|
2621
|
+
REACH_STAGED_FRAMEWORKS,
|
|
2622
|
+
swiftModuleInterface,
|
|
2623
|
+
clangInterfaceHeader,
|
|
2624
|
+
objcEnumerations,
|
|
2625
|
+
withoutImportedSdkEnumForwards,
|
|
2626
|
+
nativelyDeclaredFunctions,
|
|
2627
|
+
sdkObjCDeclarationOwners,
|
|
2628
|
+
swiftHeaderWithSuperclassImports,
|
|
2629
|
+
swiftInterfaceDeclarations,
|
|
2630
|
+
withoutSwiftDeclarations,
|
|
2631
|
+
swiftModuleSdk,
|
|
2632
|
+
swiftCompileSdkOptions,
|
|
2633
|
+
swiftModuleInputFiles,
|
|
2634
|
+
swiftMacroPlugins,
|
|
2635
|
+
clearLinkedModuleDigests,
|
|
2636
|
+
swiftModuleDigest,
|
|
2637
|
+
swiftCompileSurfaceDigest,
|
|
2638
|
+
NON_IOS_MODULES,
|
|
2639
|
+
swiftConditionalLines,
|
|
2640
|
+
swiftImportNames,
|
|
2641
|
+
swiftPeachModules,
|
|
2642
|
+
swiftSdkPaths,
|
|
2643
|
+
FOUNDATION_IMPLICIT_MODULES,
|
|
2644
|
+
withFrameworkCompanionImports,
|
|
2645
|
+
swiftCodeMask,
|
|
2646
|
+
CORE_FOUNDATION_OVERLAY_GLOBALS,
|
|
2647
|
+
foundationOwnerOf,
|
|
2648
|
+
emptyMacroEnvironment,
|
|
2649
|
+
cActiveCode,
|
|
2650
|
+
stripCCode,
|
|
2651
|
+
wasmMacroEnvironment,
|
|
2652
|
+
swiftCTakesReturnAddress,
|
|
2653
|
+
swiftCDefinedNames,
|
|
2654
|
+
swiftModuleToolchain
|
|
2655
|
+
};
|