peachsim 0.1.2248 → 0.1.2250
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/bridge-flow-runner.ts +30 -3
- package/cli/commands/flow.ts +4 -1
- package/cli/commands/inspect/settling.ts +35 -4
- package/cli/drivers/playwright.ts +2 -0
- 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 +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/bundle-channel.cjs +203 -53
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/config.mjs +1 -1
- package/dist-lib/detox/index.cjs +33 -9
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/expo-swift-bundle.cjs +177 -49
- package/dist-lib/expo-swift-metadata.cjs +1 -1
- package/dist-lib/expo-swift-metadata.mjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +210 -54
- package/dist-lib/host/fetch-proxy-handler.cjs +4 -4
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +45 -14
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +15 -8
- package/dist-lib/native-app-identity-project.cjs +2 -2
- package/dist-lib/native-app-identity-project.mjs +2 -2
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +1 -1
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/pdfium-raster.cjs +1 -1
- package/dist-lib/pdfium-raster.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +24 -24
- package/dist-lib/public-origins-lib.json +53 -53
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/reap-browser.cjs +2 -2
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +31 -7
- package/dist-lib/sdk.mjs +31 -7
- package/dist-lib/skills.cjs +289 -64
- package/dist-lib/swift-compile.cjs +165 -38
- package/dist-lib/swift-compile.mjs +165 -38
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +1 -1
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +174 -46
- package/dist-lib/vite.cjs +15 -8
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +1 -1
- package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +4 -0
- package/dist-types/packages/peach-engine/src/render-worker/image-pixel-contract.d.ts +0 -4
- package/dist-types/packages/peach-engine/src/render-worker/native-ui-protocol.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/render-worker/shell-tree-wire.d.ts +8 -0
- package/dist-types/packages/peach-engine/src/render-worker/webview-capture-protocol.d.ts +1 -0
- package/dist-types/packages/peach-globals/src/globalsContract.d.ts +5 -0
- package/kotlin/sdk.tar.gz +0 -0
- package/package.json +1 -1
- package/runtime-companion.json +1 -1
- package/sdk/ios/wasm/include/math.h +1 -1
- package/sdk/ios/wasm/include/pthread.h +1 -1
- package/src/assetCatalogContract.ts +6 -0
- package/src/nitro-compile.ts +23 -1
- package/src/process-group.ts +5 -2
- package/src/runtime-packs.ts +8 -0
- package/src/sfSymbolMetricsContract.ts +73 -37
- package/src/swift-compile.ts +119 -13
- package/src/swift-guest-image-ledger.ts +10 -5
- package/src/swift-guest-link.ts +20 -14
- package/src/swift-guest-source-inputs.ts +5 -1
- package/src/swift-installed-targets.ts +4 -1
- package/src/swift-standins.ts +11 -8
- package/src/swift-wasm-prune.ts +33 -1
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
// the asset data exchanged by project hosts and the private renderer.
|
|
2
|
+
export const SF_SYMBOL_METRICS_CATALOG_FILE = 'metrics-dict.bin.gz'
|
|
3
|
+
|
|
4
|
+
export function sfSymbolMetricsFilename(catalogVersion: string): string {
|
|
5
|
+
return `metrics-${catalogVersion}-rows.bin`
|
|
6
|
+
}
|
|
7
|
+
|
|
2
8
|
export interface SwiftImageSource {
|
|
3
9
|
uri: string
|
|
4
10
|
scale: number
|
package/src/nitro-compile.ts
CHANGED
|
@@ -348,6 +348,7 @@ export async function compileNitroModule(
|
|
|
348
348
|
options.packageRoots,
|
|
349
349
|
options.answers,
|
|
350
350
|
).flatMap(({ config }) => (config.swiftModule ? [config.swiftModule] : []))
|
|
351
|
+
let installedTargets: ReturnType<typeof swiftManifestTargets> = []
|
|
351
352
|
// a Swift provider's mixed-target boundary comes from the installed pods when
|
|
352
353
|
// they exist; without them its sources compile as the source collector laid them out
|
|
353
354
|
if (swiftModules.length > 0 && workspace) {
|
|
@@ -375,6 +376,7 @@ export async function compileNitroModule(
|
|
|
375
376
|
},
|
|
376
377
|
async (root) => {
|
|
377
378
|
const snapshot = await installedWorkspaceInput(root, 'main.swift')
|
|
379
|
+
installedTargets = swiftManifestTargets(snapshot.input.files['Package.swift']!)
|
|
378
380
|
// react's registration and turbomodule implementations belong to its
|
|
379
381
|
// runtime, while this executable owns the selected Nitro providers.
|
|
380
382
|
const swiftFiles = Object.keys(snapshot.input.files).filter((file) =>
|
|
@@ -382,7 +384,7 @@ export async function compileNitroModule(
|
|
|
382
384
|
)
|
|
383
385
|
const mixedTargets = new Set([
|
|
384
386
|
...collection.targets.map(({ name }) => name),
|
|
385
|
-
...
|
|
387
|
+
...installedTargets
|
|
386
388
|
.filter((target) =>
|
|
387
389
|
swiftFiles.some((file) => file.startsWith(`${target.path}/`)),
|
|
388
390
|
)
|
|
@@ -427,6 +429,26 @@ export async function compileNitroModule(
|
|
|
427
429
|
options.moduleRoot,
|
|
428
430
|
installedProviders ? [] : unresolvedFrameworkIncludes(collection.files),
|
|
429
431
|
)
|
|
432
|
+
if (dependencies) {
|
|
433
|
+
const podTargets = new Set(
|
|
434
|
+
swiftManifestTargets(dependencies.files['Package.swift']!).map(
|
|
435
|
+
({ name }) => name,
|
|
436
|
+
),
|
|
437
|
+
)
|
|
438
|
+
for (const target of collection.targets) {
|
|
439
|
+
const declared = installedTargets.find(({ name }) => name === target.name)
|
|
440
|
+
const owned = new Set((target.dependencies ?? []).map(({ name }) => name))
|
|
441
|
+
target.dependencies = [
|
|
442
|
+
...(target.dependencies ?? []),
|
|
443
|
+
...(declared?.dependencies ?? []).filter(
|
|
444
|
+
(dependency) =>
|
|
445
|
+
dependency.kind === 'target' &&
|
|
446
|
+
podTargets.has(dependency.name) &&
|
|
447
|
+
!owned.has(dependency.name),
|
|
448
|
+
),
|
|
449
|
+
]
|
|
450
|
+
}
|
|
451
|
+
}
|
|
430
452
|
}
|
|
431
453
|
// the compiled sources target the app's own declared iOS minimum
|
|
432
454
|
const iosDeploymentTarget = readIosAppTarget(
|
package/src/process-group.ts
CHANGED
|
@@ -15,10 +15,13 @@ import { readProcessTable } from './process-table.ts'
|
|
|
15
15
|
|
|
16
16
|
const GRACEFUL_TIMEOUT_MS = 3_000
|
|
17
17
|
const FORCED_EXIT_TIMEOUT_MS = 1_000
|
|
18
|
+
// a thrashing mac takes seconds to spawn each pgrep, so the frozen walk gets
|
|
19
|
+
// the process table's own budget rather than the graceful one.
|
|
20
|
+
const INSPECTION_TIMEOUT_MS = 10_000
|
|
18
21
|
const FREEZE_GUARD_NAME = 'process-freeze-guard'
|
|
19
22
|
|
|
20
23
|
// keep this self-contained: the detached browser host embeds its source.
|
|
21
|
-
export function listProcessChildren(parents: number[], timeoutMs =
|
|
24
|
+
export function listProcessChildren(parents: number[], timeoutMs = 10_000): number[] {
|
|
22
25
|
if (parents.some((pid) => !Number.isInteger(pid) || pid <= 1))
|
|
23
26
|
throw new Error('process inspection requires valid parent pids')
|
|
24
27
|
if (parents.length === 0) return []
|
|
@@ -257,7 +260,7 @@ export async function terminateProcessGroup(
|
|
|
257
260
|
try {
|
|
258
261
|
signalProcessGroup(child, 'SIGSTOP')
|
|
259
262
|
let parents = [child.pid]
|
|
260
|
-
const inspectionDeadline = Date.now() +
|
|
263
|
+
const inspectionDeadline = Date.now() + INSPECTION_TIMEOUT_MS
|
|
261
264
|
while (parents.length > 0) {
|
|
262
265
|
const remaining = inspectionDeadline - Date.now()
|
|
263
266
|
if (remaining <= 0) {
|
package/src/runtime-packs.ts
CHANGED
|
@@ -98,6 +98,14 @@ export async function ensureRuntimePackFor(
|
|
|
98
98
|
await installNamedPack(runtimeRoot, RUNTIME_MERGE_PACK_DIR)
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
/** install every pack of a runtime so a machine that cannot reach the CDN later
|
|
102
|
+
* serves the whole tree. rejects on the first pack that fails. */
|
|
103
|
+
export async function installAllRuntimePacks(runtimeRoot: string): Promise<void> {
|
|
104
|
+
for (const name of Object.keys(readPacks(runtimeRoot) ?? {}))
|
|
105
|
+
if (!(await installNamedPack(runtimeRoot, name)))
|
|
106
|
+
throw new Error(`runtime pack ${name} did not install under ${runtimeRoot}`)
|
|
107
|
+
}
|
|
108
|
+
|
|
101
109
|
function installNamedPack(runtimeRoot: string, name: string): Promise<boolean> {
|
|
102
110
|
if (name === RUNTIME_MERGE_PACK_DIR) {
|
|
103
111
|
const tenantDir = path.join(runtimeRoot, RUNTIME_MERGE_PACK_DIR)
|
|
@@ -106,9 +106,9 @@ function bracket(scale: SfSymbolScale, weight: SfSymbolWeight) {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
//
|
|
109
|
+
// little endian: name count, name bytes, unique row count (u32), padded utf-8
|
|
110
|
+
// names, variant constants (f32), name-to-row indices (u32), then unique rows
|
|
111
|
+
// in column order (f32). aliases retain their names and share identical rows.
|
|
112
112
|
export function encodeSfSymbolMetrics(
|
|
113
113
|
rows: ReadonlyMap<string, ReadonlyMap<string, SfSymbolMetricRow>>,
|
|
114
114
|
): Uint8Array {
|
|
@@ -116,22 +116,7 @@ export function encodeSfSymbolMetrics(
|
|
|
116
116
|
names.sort()
|
|
117
117
|
const nameBytes = new TextEncoder().encode(names.join('\n'))
|
|
118
118
|
const namesLength = Math.ceil(nameBytes.length / 4) * 4
|
|
119
|
-
const
|
|
120
|
-
const out = new Uint8Array(
|
|
121
|
-
header +
|
|
122
|
-
4 *
|
|
123
|
-
(VARIANT_COUNT * CONSTANTS.length +
|
|
124
|
-
KNOT_VARIANT_COUNT * COLUMNS.length * names.length),
|
|
125
|
-
)
|
|
126
|
-
const view = new DataView(out.buffer)
|
|
127
|
-
view.setUint32(0, names.length, true)
|
|
128
|
-
view.setUint32(4, nameBytes.length, true)
|
|
129
|
-
out.set(nameBytes, 8)
|
|
130
|
-
let offset = header
|
|
131
|
-
const put = (value: number) => {
|
|
132
|
-
view.setFloat32(offset, value, true)
|
|
133
|
-
offset += 4
|
|
134
|
-
}
|
|
119
|
+
const constants: number[] = []
|
|
135
120
|
for (const scale of SF_SYMBOL_SCALES)
|
|
136
121
|
for (const weight of SF_SYMBOL_WEIGHTS) {
|
|
137
122
|
const variant = rows.get(variantKey(scale, weight))
|
|
@@ -147,13 +132,51 @@ export function encodeSfSymbolMetrics(
|
|
|
147
132
|
`SF Symbol metrics: ${key} varies by name at ${scale}-${weight}`,
|
|
148
133
|
)
|
|
149
134
|
}
|
|
150
|
-
for (const key of CONSTANTS)
|
|
135
|
+
for (const key of CONSTANTS) constants.push(first[key])
|
|
151
136
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
137
|
+
const uniqueRows: Float32Array[] = []
|
|
138
|
+
const rowIds = new Map<string, number>()
|
|
139
|
+
const indices = new Uint32Array(names.length)
|
|
140
|
+
const columnCount = KNOT_VARIANT_COUNT * COLUMNS.length
|
|
141
|
+
for (const [index, name] of names.entries()) {
|
|
142
|
+
const values = new Float32Array(columnCount)
|
|
143
|
+
let column = 0
|
|
144
|
+
for (const scale of SF_SYMBOL_SCALES)
|
|
145
|
+
for (const knot of sfSymbolMetricKnots(scale)) {
|
|
146
|
+
const row = rows.get(variantKey(scale, knot))!.get(name)!
|
|
147
|
+
for (const key of COLUMNS) values[column++] = row[key]
|
|
148
|
+
}
|
|
149
|
+
const key = new Uint32Array(values.buffer).join(',')
|
|
150
|
+
let id = rowIds.get(key)
|
|
151
|
+
if (id === undefined) {
|
|
152
|
+
id = uniqueRows.length
|
|
153
|
+
rowIds.set(key, id)
|
|
154
|
+
uniqueRows.push(values)
|
|
155
|
+
}
|
|
156
|
+
indices[index] = id
|
|
157
|
+
}
|
|
158
|
+
const header = 12 + namesLength
|
|
159
|
+
const out = new Uint8Array(
|
|
160
|
+
header + 4 * (constants.length + indices.length + columnCount * uniqueRows.length),
|
|
161
|
+
)
|
|
162
|
+
const view = new DataView(out.buffer)
|
|
163
|
+
view.setUint32(0, names.length, true)
|
|
164
|
+
view.setUint32(4, nameBytes.length, true)
|
|
165
|
+
view.setUint32(8, uniqueRows.length, true)
|
|
166
|
+
out.set(nameBytes, 12)
|
|
167
|
+
let offset = header
|
|
168
|
+
for (const value of constants) {
|
|
169
|
+
view.setFloat32(offset, value, true)
|
|
170
|
+
offset += 4
|
|
171
|
+
}
|
|
172
|
+
for (const index of indices) {
|
|
173
|
+
view.setUint32(offset, index, true)
|
|
174
|
+
offset += 4
|
|
175
|
+
}
|
|
176
|
+
for (let column = 0; column < columnCount; column++)
|
|
177
|
+
for (const row of uniqueRows) {
|
|
178
|
+
view.setFloat32(offset, row[column]!, true)
|
|
179
|
+
offset += 4
|
|
157
180
|
}
|
|
158
181
|
return out
|
|
159
182
|
}
|
|
@@ -167,24 +190,37 @@ export class SfSymbolMetrics {
|
|
|
167
190
|
private readonly index = new Map<string, number>()
|
|
168
191
|
private readonly constants: Float32Array
|
|
169
192
|
private readonly columns: Float32Array
|
|
193
|
+
private readonly rowCount: number
|
|
170
194
|
|
|
171
195
|
constructor(bytes: Uint8Array) {
|
|
196
|
+
if (bytes.byteLength < 12) throw new Error('SF Symbol metrics: malformed header')
|
|
172
197
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)
|
|
173
198
|
const count = view.getUint32(0, true)
|
|
174
199
|
const nameLength = view.getUint32(4, true)
|
|
175
|
-
this.
|
|
176
|
-
|
|
177
|
-
throw new Error('SF Symbol metrics: name count mismatch')
|
|
178
|
-
this.names.forEach((name, i) => this.index.set(name, i))
|
|
179
|
-
const header = 8 + Math.ceil(nameLength / 4) * 4
|
|
180
|
-
const floats = bytes.byteLength - header
|
|
181
|
-
if (floats % 4 !== 0) throw new Error('SF Symbol metrics: malformed')
|
|
182
|
-
const all = new Float32Array(bytes.slice(header).buffer)
|
|
200
|
+
this.rowCount = view.getUint32(8, true)
|
|
201
|
+
const header = 12 + Math.ceil(nameLength / 4) * 4
|
|
183
202
|
const constantCount = VARIANT_COUNT * CONSTANTS.length
|
|
184
|
-
|
|
203
|
+
const expected =
|
|
204
|
+
header +
|
|
205
|
+
4 * (constantCount + count + KNOT_VARIANT_COUNT * COLUMNS.length * this.rowCount)
|
|
206
|
+
if (
|
|
207
|
+
!count ||
|
|
208
|
+
!this.rowCount ||
|
|
209
|
+
this.rowCount > count ||
|
|
210
|
+
bytes.byteLength !== expected
|
|
211
|
+
)
|
|
185
212
|
throw new Error('SF Symbol metrics: size mismatch')
|
|
186
|
-
this.
|
|
187
|
-
this.
|
|
213
|
+
this.names = new TextDecoder().decode(bytes.subarray(12, 12 + nameLength)).split('\n')
|
|
214
|
+
if (this.names.length !== count)
|
|
215
|
+
throw new Error('SF Symbol metrics: name count mismatch')
|
|
216
|
+
const indicesOffset = header + constantCount * 4
|
|
217
|
+
this.names.forEach((name, index) => {
|
|
218
|
+
const row = view.getUint32(indicesOffset + index * 4, true)
|
|
219
|
+
if (row >= this.rowCount) throw new Error('SF Symbol metrics: invalid row index')
|
|
220
|
+
this.index.set(name, row)
|
|
221
|
+
})
|
|
222
|
+
this.constants = new Float32Array(bytes.slice(header, indicesOffset).buffer)
|
|
223
|
+
this.columns = new Float32Array(bytes.slice(indicesOffset + count * 4).buffer)
|
|
188
224
|
}
|
|
189
225
|
|
|
190
226
|
has(name: string): boolean {
|
|
@@ -196,7 +232,7 @@ export class SfSymbolMetrics {
|
|
|
196
232
|
const at = this.index.get(name)
|
|
197
233
|
if (at === undefined) return undefined
|
|
198
234
|
const { lowKnot, highKnot, t } = bracket(scale, weight)
|
|
199
|
-
const count = this.
|
|
235
|
+
const count = this.rowCount
|
|
200
236
|
const read = (knot: SfSymbolWeight, column: number) =>
|
|
201
237
|
this.columns[(knotIndex(scale, knot) * COLUMNS.length + column) * count + at]!
|
|
202
238
|
const value = (column: number) => {
|
package/src/swift-compile.ts
CHANGED
|
@@ -437,6 +437,60 @@ const clangInterfaceHeader = (header: string): string =>
|
|
|
437
437
|
.replace(/\b_TtC10Foundation\d+(NS\w+)\b/g, '$1')
|
|
438
438
|
.replace(/\b__attribute__\(\(objc_subclassing_restricted\)\)\s*/g, '')
|
|
439
439
|
|
|
440
|
+
const objcEnumerations = (header: string): string[] =>
|
|
441
|
+
[
|
|
442
|
+
...header.matchAll(
|
|
443
|
+
/^\s*typedef\s+(?:NS|CF|SWIFT)_\w*(?:ENUM|OPTIONS)\w*\s*\(\s*\w+\s*,\s*(\w+)\b/gm,
|
|
444
|
+
),
|
|
445
|
+
].map((match) => match[1]!)
|
|
446
|
+
|
|
447
|
+
/** the @_cdecl functions a generated header declares that one of the native header texts also declares. */
|
|
448
|
+
function nativelyDeclaredFunctions(
|
|
449
|
+
generated: string,
|
|
450
|
+
headers: Iterable<string>,
|
|
451
|
+
): string[] {
|
|
452
|
+
const candidates = [
|
|
453
|
+
...new Set(
|
|
454
|
+
[...generated.matchAll(/^\s*SWIFT_EXTERN\b[^(\n]*?\b(\w+)\s*\(/gm)].map(
|
|
455
|
+
(match) => match[1]!,
|
|
456
|
+
),
|
|
457
|
+
),
|
|
458
|
+
]
|
|
459
|
+
if (candidates.length === 0) return []
|
|
460
|
+
const declaration = new RegExp(`^[^\\n#/*]*?\\b(${candidates.join('|')})\\s*\\(`, 'gm')
|
|
461
|
+
const found = new Set<string>()
|
|
462
|
+
for (const header of headers)
|
|
463
|
+
for (const match of header.matchAll(declaration)) found.add(match[1]!)
|
|
464
|
+
return [...found]
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const sdkDeclarationOwners = new Map<string, Map<string, string>>()
|
|
468
|
+
/** the framework whose headers define each Objective-C class, protocol and enumeration in an SDK's frameworks directory. */
|
|
469
|
+
function sdkObjCDeclarationOwners(frameworks: string): Map<string, string> {
|
|
470
|
+
const known = sdkDeclarationOwners.get(frameworks)
|
|
471
|
+
if (known) return known
|
|
472
|
+
const owners = new Map<string, string>()
|
|
473
|
+
for (const framework of readdirSync(frameworks))
|
|
474
|
+
if (framework.endsWith('.framework')) {
|
|
475
|
+
const headers = path.join(frameworks, framework, 'Headers')
|
|
476
|
+
if (existsSync(headers))
|
|
477
|
+
for (const file of readdirSync(headers, { recursive: true, encoding: 'utf8' }))
|
|
478
|
+
if (file.endsWith('.h')) {
|
|
479
|
+
const header = readFileSync(path.join(headers, file), 'utf8')
|
|
480
|
+
for (const name of [
|
|
481
|
+
...swiftInterfaceDeclarations(header),
|
|
482
|
+
...objcEnumerations(header),
|
|
483
|
+
...[
|
|
484
|
+
...header.matchAll(/^[A-Z_]*_(?:EXTERN|EXPORT)\b[^;(\n]*?\b(\w+)\s*\(/gm),
|
|
485
|
+
].map((match) => match[1]!),
|
|
486
|
+
])
|
|
487
|
+
owners.set(name, framework.slice(0, -'.framework'.length))
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
sdkDeclarationOwners.set(frameworks, owners)
|
|
491
|
+
return owners
|
|
492
|
+
}
|
|
493
|
+
|
|
440
494
|
export function swiftHeaderWithSuperclassImports(
|
|
441
495
|
header: string,
|
|
442
496
|
interfaceFor: (
|
|
@@ -502,6 +556,11 @@ export function withoutSwiftDeclarations(
|
|
|
502
556
|
/^\s*(?:[A-Z_]\w*(?:\([^()\n]*\))?\s+)*@(?:protocol|interface)\s+(\w+)\s*(?=[:<{]|$)/.exec(
|
|
503
557
|
line,
|
|
504
558
|
)?.[1]
|
|
559
|
+
// an @_cdecl function the native headers already declare keeps their prototype
|
|
560
|
+
const external = /^\s*SWIFT_EXTERN\b[^(\n]*?\b(\w+)\s*\(.*\)[^;\n]*;\s*$/.exec(
|
|
561
|
+
line,
|
|
562
|
+
)?.[1]
|
|
563
|
+
if (external && declared.has(external)) continue
|
|
505
564
|
const enumeration =
|
|
506
565
|
/^\s*typedef\s+(?:NS_ENUM|NS_OPTIONS|SWIFT_ENUM(?:_NAMED)?)\s*\(\s*\w+\s*,\s*(\w+)\b/.exec(
|
|
507
566
|
line,
|
|
@@ -5990,15 +6049,29 @@ export function writeSwiftProject(
|
|
|
5990
6049
|
[
|
|
5991
6050
|
'#!/bin/sh',
|
|
5992
6051
|
'name=',
|
|
6052
|
+
'explicit=',
|
|
5993
6053
|
'prev=',
|
|
5994
6054
|
'for arg in "$@"; do',
|
|
5995
|
-
'
|
|
6055
|
+
' case $arg in -fmodule-name=*) explicit=1 ;; esac',
|
|
6056
|
+
' if [ "$prev" = -o ]; then',
|
|
6057
|
+
' case $arg in */*) dir=${arg%/*} ;; *) dir= ;; esac',
|
|
6058
|
+
' while [ -n "$dir" ] && [ "$dir" != / ] && [ "$dir" != . ]; do',
|
|
6059
|
+
' base=${dir##*/}',
|
|
6060
|
+
' case $base in',
|
|
6061
|
+
' .build) break ;;',
|
|
6062
|
+
' *.build) name=${base%.build}; break ;;',
|
|
6063
|
+
' esac',
|
|
6064
|
+
' next=${dir%/*}',
|
|
6065
|
+
' [ "$next" = "$dir" ] && break',
|
|
6066
|
+
' dir=$next',
|
|
6067
|
+
' done',
|
|
6068
|
+
' fi',
|
|
5996
6069
|
' prev=$arg',
|
|
5997
6070
|
'done',
|
|
5998
|
-
'
|
|
5999
|
-
`
|
|
6000
|
-
|
|
6001
|
-
'
|
|
6071
|
+
'if [ -n "$name" ] && [ -z "$explicit" ]; then',
|
|
6072
|
+
` exec '${path.join(nativeToolchain(), 'clang')}' "-fmodule-name=$name" "$@"`,
|
|
6073
|
+
'fi',
|
|
6074
|
+
`exec '${path.join(nativeToolchain(), 'clang')}' "$@"`,
|
|
6002
6075
|
'',
|
|
6003
6076
|
].join('\n'),
|
|
6004
6077
|
)
|
|
@@ -6599,7 +6672,7 @@ export function frameworkLinkClosure(
|
|
|
6599
6672
|
const deps = new Set<string>()
|
|
6600
6673
|
for (const file of paths) {
|
|
6601
6674
|
const module = /\/Modules\/([^/]+)\.swiftmodule$/.exec(file)
|
|
6602
|
-
const object = /\/([^/]+)\.build
|
|
6675
|
+
const object = /\/release\/([^/]+)\.build\/.+\.o$/.exec(file)
|
|
6603
6676
|
if (module) deps.add(module[1]!)
|
|
6604
6677
|
else if (object && object[1] !== pending.name) deps.add(object[1]!)
|
|
6605
6678
|
}
|
|
@@ -7497,11 +7570,34 @@ function compileSwiftProjectOnce(
|
|
|
7497
7570
|
readFileSync(path.join(headers, file), 'utf8'),
|
|
7498
7571
|
))
|
|
7499
7572
|
declared.add(name)
|
|
7500
|
-
const
|
|
7573
|
+
const own = withoutSwiftDeclarations(
|
|
7501
7574
|
clangInterfaceHeader(readFileSync(source, 'utf8')),
|
|
7502
7575
|
declared,
|
|
7503
7576
|
`#import <${name}/${name}.h>`,
|
|
7504
7577
|
)
|
|
7578
|
+
// the swift module also implements classes another framework's headers
|
|
7579
|
+
// already define; clang takes those from the owning framework
|
|
7580
|
+
const owners = sdkObjCDeclarationOwners(path.dirname(path.dirname(headers)))
|
|
7581
|
+
const foreign = new Map<string, string>()
|
|
7582
|
+
for (const declaration of [
|
|
7583
|
+
...swiftInterfaceDeclarations(own),
|
|
7584
|
+
...objcEnumerations(own),
|
|
7585
|
+
...[...own.matchAll(/^\s*SWIFT_EXTERN\b[^(\n]*?\b(\w+)\s*\(/gm)].map(
|
|
7586
|
+
(match) => match[1]!,
|
|
7587
|
+
),
|
|
7588
|
+
]) {
|
|
7589
|
+
const owner = owners.get(declaration)
|
|
7590
|
+
if (owner && owner !== name) foreign.set(declaration, owner)
|
|
7591
|
+
}
|
|
7592
|
+
const header = foreign.size
|
|
7593
|
+
? withoutSwiftDeclarations(
|
|
7594
|
+
own,
|
|
7595
|
+
new Set(foreign.keys()),
|
|
7596
|
+
[...new Set(foreign.values())]
|
|
7597
|
+
.map((owner) => `#import <${owner}/${owner}.h>`)
|
|
7598
|
+
.join('\n'),
|
|
7599
|
+
)
|
|
7600
|
+
: own
|
|
7505
7601
|
const value = {
|
|
7506
7602
|
file: path.join(root, '.build/peach-framework-objc', `${name}-Swift.h`),
|
|
7507
7603
|
header,
|
|
@@ -7550,18 +7646,28 @@ function compileSwiftProjectOnce(
|
|
|
7550
7646
|
const original = preparation.nativeHeaderDeclarations[producer]
|
|
7551
7647
|
? emitted.replace(/-Swift\.h$/, '-Swift.original.h')
|
|
7552
7648
|
: emitted
|
|
7553
|
-
if (existsSync(original))
|
|
7649
|
+
if (existsSync(original)) {
|
|
7650
|
+
const generated = clangInterfaceHeader(readFileSync(original, 'utf8'))
|
|
7554
7651
|
writeBuildFile(
|
|
7555
7652
|
emitted,
|
|
7556
7653
|
withoutSwiftDeclarations(
|
|
7557
|
-
swiftHeaderWithSuperclassImports(
|
|
7558
|
-
|
|
7559
|
-
|
|
7560
|
-
|
|
7561
|
-
|
|
7654
|
+
swiftHeaderWithSuperclassImports(generated, frameworkInterface),
|
|
7655
|
+
new Set([
|
|
7656
|
+
...(preparation.nativeHeaderDeclarations[producer] ?? []),
|
|
7657
|
+
...nativelyDeclaredFunctions(
|
|
7658
|
+
generated,
|
|
7659
|
+
Object.entries(input.files)
|
|
7660
|
+
.filter(
|
|
7661
|
+
([name]) =>
|
|
7662
|
+
name.endsWith('.h') && !name.endsWith('-Swift.h'),
|
|
7663
|
+
)
|
|
7664
|
+
.map(([, source]) => source),
|
|
7665
|
+
),
|
|
7666
|
+
]),
|
|
7562
7667
|
`#import <${producer}/${producer}.h>`,
|
|
7563
7668
|
),
|
|
7564
7669
|
)
|
|
7670
|
+
}
|
|
7565
7671
|
}
|
|
7566
7672
|
}
|
|
7567
7673
|
// an interrupted swiftpm build rolls back completed object records.
|
|
@@ -486,9 +486,13 @@ export function createGuestImageLedger(input: GuestImageLedgerInput): GuestImage
|
|
|
486
486
|
}
|
|
487
487
|
}
|
|
488
488
|
}
|
|
489
|
+
const nameBytes = new Map<string, Buffer>()
|
|
490
|
+
for (const definition of definitions)
|
|
491
|
+
if (!nameBytes.has(definition.name))
|
|
492
|
+
nameBytes.set(definition.name, Buffer.from(definition.name))
|
|
489
493
|
definitions.sort(
|
|
490
494
|
(a, b) =>
|
|
491
|
-
Buffer.compare(
|
|
495
|
+
Buffer.compare(nameBytes.get(a.name)!, nameBytes.get(b.name)!) || a.image - b.image,
|
|
492
496
|
)
|
|
493
497
|
const preserveCanonical = new Set<string>()
|
|
494
498
|
const definitionsByName = Map.groupBy(definitions, (definition) => definition.name)
|
|
@@ -537,12 +541,12 @@ export function createGuestImageLedger(input: GuestImageLedgerInput): GuestImage
|
|
|
537
541
|
preserveCanonical.add(name)
|
|
538
542
|
for (const name of input.commandLineSymbols ?? []) preserveCanonical.add(name)
|
|
539
543
|
const bindingsByImage = new Map<number, Map<string, string>>()
|
|
544
|
+
const definitionsByImage = Map.groupBy(definitions, (definition) => definition.image)
|
|
540
545
|
for (const caller of input.callers) {
|
|
541
546
|
const bindings = new Map<string, string>()
|
|
542
547
|
const seen = new Map<string, GuestImageDefinition>()
|
|
543
548
|
for (const image of [caller.image, ...caller.next])
|
|
544
|
-
for (const definition of
|
|
545
|
-
if (definition.image !== image) continue
|
|
549
|
+
for (const definition of definitionsByImage.get(image) ?? []) {
|
|
546
550
|
const previous = seen.get(definition.name)
|
|
547
551
|
// the linker already accepted the image, so duplicate definitions inside
|
|
548
552
|
// it resolve as in a static link: the first binds and a strong one beats a weak one.
|
|
@@ -589,8 +593,9 @@ export function createGuestImageLedger(input: GuestImageLedgerInput): GuestImage
|
|
|
589
593
|
definitionsByAlias.set(definition.alias, definition)
|
|
590
594
|
}
|
|
591
595
|
const objects = units.map(({ image, object, aliases, functionImports }) => {
|
|
592
|
-
const
|
|
593
|
-
|
|
596
|
+
const shared = bindingsByImage.get(image)!
|
|
597
|
+
const own = startup.get(object.path)
|
|
598
|
+
const bindings = own ? new Map([...shared, ...own]) : shared
|
|
594
599
|
for (const [name, type] of functionImports) {
|
|
595
600
|
const alias = bindings.get(name)
|
|
596
601
|
const provider = alias === undefined ? undefined : definitionsByAlias.get(alias)
|
package/src/swift-guest-link.ts
CHANGED
|
@@ -359,6 +359,7 @@ export function linkGuestImages(
|
|
|
359
359
|
)
|
|
360
360
|
}
|
|
361
361
|
const archives = new Map<string, ReturnType<typeof readArMembers>>()
|
|
362
|
+
const memberBytes = new Map<string, Map<string, Uint8Array>>()
|
|
362
363
|
const prepare = (provider: boolean) => {
|
|
363
364
|
const trace = runLink('discovery', [
|
|
364
365
|
...withOutput(args, discovery, true),
|
|
@@ -403,20 +404,23 @@ export function linkGuestImages(
|
|
|
403
404
|
}
|
|
404
405
|
const objectsByImage = new Map<number, GuestImageObject[]>()
|
|
405
406
|
for (const image of plan.images) objectsByImage.set(image.id, [])
|
|
407
|
+
const artifacts = new Map(plan.artifacts.map((artifact) => [artifact.path, artifact]))
|
|
406
408
|
for (const item of selected) {
|
|
407
|
-
const artifact =
|
|
408
|
-
(candidate) => candidate.path === item.artifact,
|
|
409
|
-
)!
|
|
409
|
+
const artifact = artifacts.get(item.artifact)!
|
|
410
410
|
const image = selectedGuestInputImage(artifact, item.member)
|
|
411
411
|
let bytes: Uint8Array
|
|
412
412
|
if (item.member === null) bytes = fs.readFileSync(item.artifact)
|
|
413
413
|
else {
|
|
414
|
-
let
|
|
415
|
-
if (!
|
|
416
|
-
members = readArMembers(fs.readFileSync(item.artifact))
|
|
414
|
+
let byName = memberBytes.get(item.artifact)
|
|
415
|
+
if (!byName) {
|
|
416
|
+
const members = readArMembers(fs.readFileSync(item.artifact))
|
|
417
417
|
archives.set(item.artifact, members)
|
|
418
|
+
byName = new Map()
|
|
419
|
+
for (const member of members)
|
|
420
|
+
if (!byName.has(member.name)) byName.set(member.name, member.bytes)
|
|
421
|
+
memberBytes.set(item.artifact, byName)
|
|
418
422
|
}
|
|
419
|
-
bytes =
|
|
423
|
+
bytes = byName.get(item.member)!
|
|
420
424
|
}
|
|
421
425
|
const objects = objectsByImage.get(image)
|
|
422
426
|
if (!objects) throw new Error(`unknown image ${image}`)
|
|
@@ -453,10 +457,11 @@ export function linkGuestImages(
|
|
|
453
457
|
const { selected, ledger } = prepared
|
|
454
458
|
const replacements = new Map<string, string>()
|
|
455
459
|
const linkedOwners = new Map<string, number>()
|
|
460
|
+
const ledgerObjects = new Map(ledger.objects.map((item) => [item.path, item]))
|
|
456
461
|
for (const [index, artifact] of plan.artifacts.entries()) {
|
|
457
462
|
const prefix = `${artifact.path}(`
|
|
458
463
|
if (artifact.kind === 'object') {
|
|
459
|
-
const object =
|
|
464
|
+
const object = ledgerObjects.get(artifact.path)
|
|
460
465
|
if (!object) continue
|
|
461
466
|
const output = path.join(directory, `object-${index}.o`)
|
|
462
467
|
fs.writeFileSync(output, object.bytes)
|
|
@@ -483,9 +488,7 @@ export function linkGuestImages(
|
|
|
483
488
|
const output = path.join(directory, `archive-${index}.a`)
|
|
484
489
|
const inputs = members.map((member) => {
|
|
485
490
|
const memberOutput = path.join(memberDir, member.name)
|
|
486
|
-
const rewritten =
|
|
487
|
-
(item) => item.path === `${prefix}${member.name})`,
|
|
488
|
-
)
|
|
491
|
+
const rewritten = ledgerObjects.get(`${prefix}${member.name})`)
|
|
489
492
|
fs.writeFileSync(memberOutput, rewritten?.bytes ?? member.bytes)
|
|
490
493
|
if (rewritten) {
|
|
491
494
|
linkedOwners.set(
|
|
@@ -889,7 +892,7 @@ export function selectedGuestSymbolInputs(
|
|
|
889
892
|
readonly definitionObjects: ReadonlyMap<string, ReadonlySet<string>>
|
|
890
893
|
} {
|
|
891
894
|
const artifacts = new Map(plan.artifacts.map((artifact) => [artifact.path, artifact]))
|
|
892
|
-
const archives = new Map<string,
|
|
895
|
+
const archives = new Map<string, Map<string, { bytes: Uint8Array }[]>>()
|
|
893
896
|
const symbols = new Set<string>()
|
|
894
897
|
const hostImports = new Set<string>()
|
|
895
898
|
const tags = new Set<string>()
|
|
@@ -907,10 +910,13 @@ export function selectedGuestSymbolInputs(
|
|
|
907
910
|
else {
|
|
908
911
|
let members = archives.get(item.artifact)
|
|
909
912
|
if (!members) {
|
|
910
|
-
members =
|
|
913
|
+
members = Map.groupBy(
|
|
914
|
+
readArMembers(fs.readFileSync(item.artifact)),
|
|
915
|
+
(member) => member.name,
|
|
916
|
+
)
|
|
911
917
|
archives.set(item.artifact, members)
|
|
912
918
|
}
|
|
913
|
-
const matching = members.
|
|
919
|
+
const matching = members.get(item.member) ?? []
|
|
914
920
|
if (matching.length !== 1)
|
|
915
921
|
throw new Error(
|
|
916
922
|
`ambiguous selected symbol input ${item.artifact}(${item.member})`,
|
|
@@ -111,9 +111,13 @@ export function sourceGuestClangLinkOptions(options: {
|
|
|
111
111
|
throw new Error(`unsupported source object producer ${file}`)
|
|
112
112
|
const args = command.args.slice(1).filter((arg) => arg !== '-c')
|
|
113
113
|
// the replay keeps the object's <target>.build directory name
|
|
114
|
+
const targetBuild = path
|
|
115
|
+
.relative(options.buildDirectory, file)
|
|
116
|
+
.split(path.sep)
|
|
117
|
+
.findLast((part) => part !== '.build' && part.endsWith('.build'))
|
|
114
118
|
const outputDirectory = path.join(
|
|
115
119
|
options.directory,
|
|
116
|
-
path.basename(path.dirname(file)),
|
|
120
|
+
targetBuild ?? path.basename(path.dirname(file)),
|
|
117
121
|
)
|
|
118
122
|
mkdirSync(outputDirectory, { recursive: true })
|
|
119
123
|
const output = path.join(outputDirectory, `clang-link-${index}.ll`)
|
|
@@ -46,10 +46,11 @@ export function applyInstalledSwiftTargets(
|
|
|
46
46
|
].map((bundle) => [bundle.target, bundle]),
|
|
47
47
|
).values(),
|
|
48
48
|
]
|
|
49
|
-
|
|
49
|
+
const headerAliases = {
|
|
50
50
|
...collection.headerAliases,
|
|
51
51
|
...snapshot.input.headerAliases,
|
|
52
52
|
}
|
|
53
|
+
collection.headerAliases = headerAliases
|
|
53
54
|
const canonical = new Map<string, string>()
|
|
54
55
|
for (const [key, source] of Object.entries(snapshot.sourcePaths)) {
|
|
55
56
|
const real = fs.realpathSync(source)
|
|
@@ -133,6 +134,8 @@ export function applyInstalledSwiftTargets(
|
|
|
133
134
|
?.find((candidate) => candidate.content === content)
|
|
134
135
|
if (!match) continue
|
|
135
136
|
roots.add(match.root)
|
|
137
|
+
aliases[file] = copy
|
|
138
|
+
headerAliases[file] = copy
|
|
136
139
|
delete collection.files[file]
|
|
137
140
|
}
|
|
138
141
|
return roots
|
package/src/swift-standins.ts
CHANGED
|
@@ -137,12 +137,14 @@ function failure(error: unknown): string {
|
|
|
137
137
|
const output =
|
|
138
138
|
error && typeof error === 'object' && 'stderr' in error
|
|
139
139
|
? `${String(error.stderr)}\n${'stdout' in error ? String(error.stdout) : ''}`
|
|
140
|
-
:
|
|
140
|
+
: error instanceof Error
|
|
141
|
+
? error.message
|
|
142
|
+
: String(error)
|
|
141
143
|
const errors = output
|
|
142
144
|
.split('\n')
|
|
143
|
-
.filter((line) =>
|
|
144
|
-
.map((line) => line.replace(
|
|
145
|
-
return [...new Set(errors)].slice(0, 3).join('; ') || output.trim().slice(
|
|
145
|
+
.filter((line) => /^(\S.*?:\d+:\d+: )?error:/.test(line))
|
|
146
|
+
.map((line) => line.replace(/^(.*?:\d+:\d+: )?error:\s*/, '').trim())
|
|
147
|
+
return [...new Set(errors)].slice(0, 3).join('; ') || output.trim().slice(-600)
|
|
146
148
|
}
|
|
147
149
|
|
|
148
150
|
const key = (...parts: string[]) =>
|
|
@@ -867,6 +869,8 @@ function peachModuleDirs(
|
|
|
867
869
|
target,
|
|
868
870
|
'-Xswiftc',
|
|
869
871
|
'-Osize',
|
|
872
|
+
'-Xswiftc',
|
|
873
|
+
'-gnone',
|
|
870
874
|
...plugins.libraries.flatMap((library) => [
|
|
871
875
|
'-Xswiftc',
|
|
872
876
|
'-load-plugin-library',
|
|
@@ -3036,10 +3040,9 @@ async function binaryStandins(
|
|
|
3036
3040
|
: cStandin(surface, binary, toolchain, dir),
|
|
3037
3041
|
)
|
|
3038
3042
|
} catch (error) {
|
|
3039
|
-
throw new Error(
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
)
|
|
3043
|
+
throw new Error(`no stand-in for ${surface.module}: ${failure(error)}`, {
|
|
3044
|
+
cause: error,
|
|
3045
|
+
})
|
|
3043
3046
|
}
|
|
3044
3047
|
}
|
|
3045
3048
|
publish(result)
|