peachsim 0.1.779 → 0.1.781
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/detox.ts +13 -9
- package/cli/commands/test.ts +1 -1
- package/detox/jest-preset.cjs +1 -1
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/agent-identity.cjs +1 -1
- package/dist-lib/agent-sessions.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/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cli-constants.cjs +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/detox/index.cjs +1 -1
- package/dist-lib/detox/jest-preset.cjs +1 -1
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +591 -257
- package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +1 -1
- 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 +1 -1
- 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/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/render-mode.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 +1 -1
- package/dist-lib/skills.cjs +594 -260
- package/dist-lib/swift-compile.cjs +1 -1
- package/dist-lib/swift-compile.mjs +1 -1
- 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 +583 -257
- package/dist-lib/vite.cjs +1 -1
- package/package.json +1 -1
- package/skills/peach-test/SKILL.md +1 -1
- package/src/swift-host.ts +55 -28
- package/src/swift-standin-emit.ts +471 -242
- package/src/swift-standins.ts +285 -40
package/src/swift-standins.ts
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
// xcframework holds iOS machine code peach cannot run, but its iOS simulator
|
|
3
3
|
// slice describes its public surface: a swift module's .swiftinterface, or a
|
|
4
4
|
// c module's modulemap and headers. from those this builds, on the compiling
|
|
5
|
-
// host, a source target under the module's own name
|
|
6
|
-
// naming the sdk and the symbol, so the app compiles
|
|
7
|
-
// into the sdk fails loudly where it happens.
|
|
8
|
-
//
|
|
5
|
+
// host, a source target under the module's own name: every extern function
|
|
6
|
+
// gets a body that traps naming the sdk and the symbol, so the app compiles
|
|
7
|
+
// and links and a call into the sdk fails loudly where it happens. a static
|
|
8
|
+
// function keeps the vendor's own body, which stays callable. objective-c
|
|
9
|
+
// headers get no stand-in, and the binary target stays missing with its
|
|
10
|
+
// reason.
|
|
9
11
|
|
|
10
12
|
import { execFileSync, spawnSync } from 'node:child_process'
|
|
11
13
|
import { createHash } from 'node:crypto'
|
|
@@ -15,11 +17,16 @@ import path from 'node:path'
|
|
|
15
17
|
import {
|
|
16
18
|
swiftDistributionAt,
|
|
17
19
|
swiftMacroPlugins,
|
|
20
|
+
swiftModuleDigest,
|
|
18
21
|
swiftModuleSdk,
|
|
19
22
|
swiftPeachModules,
|
|
20
23
|
swiftSdkPaths,
|
|
21
24
|
} from './swift-compile'
|
|
22
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
STANDIN_EMIT_VERSION,
|
|
27
|
+
emitSwiftStandin,
|
|
28
|
+
type SymbolGraph,
|
|
29
|
+
} from './swift-standin-emit'
|
|
23
30
|
import type { SwiftPackageBinary } from './swift-packages'
|
|
24
31
|
|
|
25
32
|
const TRIPLE = 'wasm32-unknown-wasip1'
|
|
@@ -43,6 +50,8 @@ export interface SwiftStandins {
|
|
|
43
50
|
interface Toolchain {
|
|
44
51
|
moduleRoot: string
|
|
45
52
|
toolchainBin: string
|
|
53
|
+
/** the toolchain release, read once where the toolchain is resolved. */
|
|
54
|
+
release: string
|
|
46
55
|
}
|
|
47
56
|
|
|
48
57
|
function exec(file: string, args: string[], cwd?: string): string {
|
|
@@ -70,21 +79,42 @@ function failure(error: unknown): string {
|
|
|
70
79
|
const key = (...parts: string[]) =>
|
|
71
80
|
createHash('sha256').update(parts.join('\0')).digest('hex').slice(0, 32)
|
|
72
81
|
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
// content digests, stat-gated: a matching stat reuses the digest, any stat
|
|
83
|
+
// change rehashes, so keys track contents without hashing on every call.
|
|
84
|
+
const digests = new Map<string, { stamp: string; digest: string }>()
|
|
85
|
+
|
|
86
|
+
function treeDigest(root: string): string {
|
|
87
|
+
const names: string[] = []
|
|
88
|
+
const walk = (dir: string) => {
|
|
89
|
+
for (const entry of fs
|
|
90
|
+
.readdirSync(dir, { withFileTypes: true })
|
|
91
|
+
.sort((left, right) => (left.name < right.name ? -1 : 1))) {
|
|
92
|
+
const full = path.join(dir, entry.name)
|
|
93
|
+
if (entry.isDirectory()) walk(full)
|
|
94
|
+
else if (entry.isFile()) names.push(path.relative(root, full))
|
|
95
|
+
}
|
|
87
96
|
}
|
|
97
|
+
walk(root)
|
|
98
|
+
const stamp = names
|
|
99
|
+
.map((name) => {
|
|
100
|
+
const stat = fs.statSync(path.join(root, name))
|
|
101
|
+
return `${name}\0${stat.size}:${stat.mtimeMs}`
|
|
102
|
+
})
|
|
103
|
+
.join('\n')
|
|
104
|
+
const memo = digests.get(`tree\0${root}`)
|
|
105
|
+
if (memo?.stamp === stamp) return memo.digest
|
|
106
|
+
const hash = createHash('sha256')
|
|
107
|
+
for (const name of names) {
|
|
108
|
+
hash.update(`${name}\0`)
|
|
109
|
+
hash.update(fs.readFileSync(path.join(root, name)))
|
|
110
|
+
hash.update('\0')
|
|
111
|
+
}
|
|
112
|
+
const digest = hash.digest('hex')
|
|
113
|
+
digests.set(`tree\0${root}`, { stamp, digest })
|
|
114
|
+
return digest
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function locateXcframework(tree: string): string | null {
|
|
88
118
|
const find = (root: string, depth: number): string | null => {
|
|
89
119
|
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
90
120
|
if (!entry.isDirectory() || entry.name === '__MACOSX') continue
|
|
@@ -95,9 +125,63 @@ function xcframework(binary: SwiftPackageBinary): string {
|
|
|
95
125
|
}
|
|
96
126
|
return null
|
|
97
127
|
}
|
|
98
|
-
|
|
128
|
+
return find(tree, 2)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// the xcframework a binary target names, with a digest of the artifact's
|
|
132
|
+
// contents: a local directory digests as a tree, while an archive (local or
|
|
133
|
+
// remote) keeps its bytes and unpacks again when they change. the digest,
|
|
134
|
+
// not the path, keys the stand-in cache, so a replaced same-path zip
|
|
135
|
+
// rebuilds instead of reusing stale output.
|
|
136
|
+
function xcframework(binary: SwiftPackageBinary): { dir: string; digest: string } {
|
|
137
|
+
if (!binary.url && !binary.dir.endsWith('.zip'))
|
|
138
|
+
return { dir: binary.dir, digest: treeDigest(binary.dir) }
|
|
139
|
+
const dir = path.join(cacheDir, 'archives', key(binary.url ?? binary.dir))
|
|
140
|
+
const archive = path.join(dir, 'archive.zip')
|
|
141
|
+
const fingerprint = path.join(dir, '.fingerprint')
|
|
142
|
+
const stored: { stamp?: string; sha: string } | null = (() => {
|
|
143
|
+
try {
|
|
144
|
+
const parsed: unknown = JSON.parse(fs.readFileSync(fingerprint, 'utf8'))
|
|
145
|
+
return parsed && typeof parsed === 'object' && 'sha' in parsed
|
|
146
|
+
? (parsed as { stamp?: string; sha: string })
|
|
147
|
+
: null
|
|
148
|
+
} catch {
|
|
149
|
+
return null
|
|
150
|
+
}
|
|
151
|
+
})()
|
|
152
|
+
if (!binary.url) {
|
|
153
|
+
// a local archive: its bytes are the identity, the stat only skips
|
|
154
|
+
// hashing them again while they are unchanged.
|
|
155
|
+
const stat = fs.statSync(binary.dir)
|
|
156
|
+
const stamp = `${stat.size}:${stat.mtimeMs}`
|
|
157
|
+
if (stored?.stamp === stamp) {
|
|
158
|
+
const found = locateXcframework(path.join(dir, 'tree'))
|
|
159
|
+
if (found) return { dir: found, digest: stored.sha }
|
|
160
|
+
}
|
|
161
|
+
const sha = createHash('sha256').update(fs.readFileSync(binary.dir)).digest('hex')
|
|
162
|
+
if (sha !== stored?.sha || !locateXcframework(path.join(dir, 'tree'))) {
|
|
163
|
+
fs.rmSync(dir, { recursive: true, force: true })
|
|
164
|
+
fs.mkdirSync(path.join(dir, 'tree'), { recursive: true })
|
|
165
|
+
exec('unzip', ['-q', binary.dir, '-d', path.join(dir, 'tree')])
|
|
166
|
+
}
|
|
167
|
+
fs.writeFileSync(fingerprint, JSON.stringify({ stamp, sha }))
|
|
168
|
+
const found = locateXcframework(path.join(dir, 'tree'))
|
|
169
|
+
if (!found) throw new Error('its archive holds no .xcframework')
|
|
170
|
+
return { dir: found, digest: sha }
|
|
171
|
+
}
|
|
172
|
+
if (stored && fs.existsSync(archive)) {
|
|
173
|
+
const found = locateXcframework(path.join(dir, 'tree'))
|
|
174
|
+
if (found) return { dir: found, digest: stored.sha }
|
|
175
|
+
}
|
|
176
|
+
fs.rmSync(dir, { recursive: true, force: true })
|
|
177
|
+
fs.mkdirSync(path.join(dir, 'tree'), { recursive: true })
|
|
178
|
+
exec('curl', ['-fsSL', '--retry', '2', '-o', archive, binary.url])
|
|
179
|
+
const sha = createHash('sha256').update(fs.readFileSync(archive)).digest('hex')
|
|
180
|
+
exec('unzip', ['-q', archive, '-d', path.join(dir, 'tree')])
|
|
181
|
+
fs.writeFileSync(fingerprint, JSON.stringify({ sha }))
|
|
182
|
+
const found = locateXcframework(path.join(dir, 'tree'))
|
|
99
183
|
if (!found) throw new Error('its archive holds no .xcframework')
|
|
100
|
-
return found
|
|
184
|
+
return { dir: found, digest: sha }
|
|
101
185
|
}
|
|
102
186
|
|
|
103
187
|
const files = (dir: string, test: (name: string) => boolean): string[] =>
|
|
@@ -351,6 +435,8 @@ function functionDeclarations(
|
|
|
351
435
|
const declFile = file
|
|
352
436
|
walk(decl)
|
|
353
437
|
if (Reflect.get(decl, 'kind') !== 'FunctionDecl' || !headers.has(declFile)) continue
|
|
438
|
+
// a static function keeps the vendor's own body, which stays callable:
|
|
439
|
+
// only extern declarations need definitions, and those trap.
|
|
354
440
|
if (Reflect.get(decl, 'isImplicit') || Reflect.get(decl, 'storageClass') === 'static')
|
|
355
441
|
continue
|
|
356
442
|
const inner = Reflect.get(decl, 'inner')
|
|
@@ -375,6 +461,76 @@ function functionDeclarations(
|
|
|
375
461
|
return found
|
|
376
462
|
}
|
|
377
463
|
|
|
464
|
+
// the opener matching the closer at `close`, scanning left.
|
|
465
|
+
function matchOpen(text: string, close: number): number {
|
|
466
|
+
const open = text[close] === ')' ? '(' : '['
|
|
467
|
+
let depth = 0
|
|
468
|
+
for (let index = close; index >= 0; index--) {
|
|
469
|
+
if (text[index] === text[close]) depth++
|
|
470
|
+
else if (text[index] === open && --depth === 0) return index
|
|
471
|
+
}
|
|
472
|
+
return -1
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
const identChar = (char: string | undefined): boolean =>
|
|
476
|
+
char !== undefined && /[\w$]/.test(char)
|
|
477
|
+
|
|
478
|
+
// one definition per declarator of a grouped declaration statement, in the
|
|
479
|
+
// declarators' order: the first keeps the statement as written, each later
|
|
480
|
+
// one reuses the specifiers before the first declarator (`const char *a, *b`
|
|
481
|
+
// declares two `const char *`). a mismatch throws, so it becomes a reported
|
|
482
|
+
// gap instead of invalid c.
|
|
483
|
+
function splitDeclarators(statement: string, names: readonly string[]): string[] {
|
|
484
|
+
const chunks: string[] = []
|
|
485
|
+
let depth = 0
|
|
486
|
+
let quote: string | null = null
|
|
487
|
+
let start = 0
|
|
488
|
+
for (let index = 0; index < statement.length; index++) {
|
|
489
|
+
const char = statement[index]!
|
|
490
|
+
if (quote) {
|
|
491
|
+
if (char === '\\') index++
|
|
492
|
+
else if (char === quote) quote = null
|
|
493
|
+
} else if (char === '"' || char === "'") quote = char
|
|
494
|
+
else if (char === '(' || char === '[' || char === '{') depth++
|
|
495
|
+
else if (char === ')' || char === ']' || char === '}') depth--
|
|
496
|
+
else if (char === ',' && depth === 0) {
|
|
497
|
+
chunks.push(statement.slice(start, index))
|
|
498
|
+
start = index + 1
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
chunks.push(statement.slice(start))
|
|
502
|
+
if (chunks.length !== names.length)
|
|
503
|
+
throw new Error(
|
|
504
|
+
`${names[0]} has an unexpected grouped declaration in ${JSON.stringify(statement.trim().slice(0, 80))}`,
|
|
505
|
+
)
|
|
506
|
+
// the specifiers end where the first declarator starts: left of its name
|
|
507
|
+
// over pointers and whitespace, and over attribute groups, stopping at a
|
|
508
|
+
// paren that groups the declarator itself (`int (*fp)(void)`).
|
|
509
|
+
let end = chunks[0]!.indexOf(names[0]!)
|
|
510
|
+
if (end < 0) throw new Error(`${names[0]} names no declarator in its own declaration`)
|
|
511
|
+
for (;;) {
|
|
512
|
+
while (end > 0 && /[\s*]/.test(chunks[0]![end - 1]!)) end--
|
|
513
|
+
if (end > 0 && (chunks[0]![end - 1] === ')' || chunks[0]![end - 1] === ']')) {
|
|
514
|
+
end = matchOpen(chunks[0]!, end - 1)
|
|
515
|
+
if (end < 0) throw new Error(`${names[0]} has unbalanced groups in its declaration`)
|
|
516
|
+
// an attribute call's arguments: the attribute's name goes with them
|
|
517
|
+
while (end > 0 && identChar(chunks[0]![end - 1])) end--
|
|
518
|
+
continue
|
|
519
|
+
}
|
|
520
|
+
if (end > 1 && chunks[0]![end - 1] === '(' && identChar(chunks[0]![end - 2])) {
|
|
521
|
+
end--
|
|
522
|
+
while (end > 0 && identChar(chunks[0]![end - 1])) end--
|
|
523
|
+
continue
|
|
524
|
+
}
|
|
525
|
+
break
|
|
526
|
+
}
|
|
527
|
+
if (end > 0 && chunks[0]![end - 1] === '(') end--
|
|
528
|
+
const specifiers = chunks[0]!.slice(0, end)
|
|
529
|
+
return chunks.map((chunk, index) =>
|
|
530
|
+
index === 0 ? chunk : `${specifiers} ${chunk.trim()}`,
|
|
531
|
+
)
|
|
532
|
+
}
|
|
533
|
+
|
|
378
534
|
function cStandin(
|
|
379
535
|
surface: Extract<Surface, { kind: 'c' }>,
|
|
380
536
|
binary: SwiftPackageBinary,
|
|
@@ -422,23 +578,45 @@ function cStandin(
|
|
|
422
578
|
)
|
|
423
579
|
const byPath = new Map(headers.map((file) => [path.join(include, file), file]))
|
|
424
580
|
const declarations = functionDeclarations(ast, new Set(byPath.keys()))
|
|
581
|
+
// declarations sharing one statement start are one grouped declaration
|
|
582
|
+
// (`int first(void), second(void);`): clang reports one FunctionDecl per
|
|
583
|
+
// declarator, and emitting the whole statement per declarator repeats it
|
|
584
|
+
// and breaks the compile. each declarator gets its own definition under
|
|
585
|
+
// the statement's specifiers instead.
|
|
586
|
+
const groups = new Map<string, typeof declarations>()
|
|
587
|
+
for (const declaration of declarations) {
|
|
588
|
+
const group = groups.get(`${declaration.file}\0${declaration.begin}`) ?? []
|
|
589
|
+
group.push(declaration)
|
|
590
|
+
groups.set(`${declaration.file}\0${declaration.begin}`, group)
|
|
591
|
+
}
|
|
425
592
|
const seen = new Set<string>()
|
|
426
593
|
const definitions: string[] = []
|
|
427
|
-
for (const
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
const
|
|
431
|
-
const close = text.indexOf(';', end)
|
|
594
|
+
for (const group of groups.values()) {
|
|
595
|
+
const first = group[0]!
|
|
596
|
+
const text = texts.get(byPath.get(first.file)!)!
|
|
597
|
+
const close = text.indexOf(';', first.end)
|
|
432
598
|
if (close < 0)
|
|
433
|
-
throw new Error(`${name} has no declaration end in ${byPath.get(file)}`)
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
599
|
+
throw new Error(`${first.name} has no declaration end in ${byPath.get(first.file)}`)
|
|
600
|
+
const statement = text.slice(first.begin, close)
|
|
601
|
+
const declarators =
|
|
602
|
+
group.length === 1
|
|
603
|
+
? [statement]
|
|
604
|
+
: splitDeclarators(
|
|
605
|
+
statement,
|
|
606
|
+
group.map((declaration) => declaration.name),
|
|
607
|
+
)
|
|
608
|
+
group.forEach((declaration, index) => {
|
|
609
|
+
if (seen.has(declaration.name)) return
|
|
610
|
+
seen.add(declaration.name)
|
|
611
|
+
definitions.push(
|
|
612
|
+
`${declarators[index]!.trim()} {\n peach_standin_trap("${declaration.name}");\n}\n`,
|
|
613
|
+
)
|
|
614
|
+
})
|
|
437
615
|
}
|
|
438
616
|
const sdk = JSON.stringify(`${binary.target} (${binary.source})`)
|
|
439
617
|
const source = [
|
|
440
618
|
`// generated by peach from ${surface.module}'s headers: ${binary.target} ships`,
|
|
441
|
-
'// iOS machine code only, so every function traps naming itself.',
|
|
619
|
+
'// iOS machine code only, so every extern function traps naming itself.',
|
|
442
620
|
...roots.map((file) => `#include "${file}"`),
|
|
443
621
|
'#include <stdio.h>',
|
|
444
622
|
'#include <stdlib.h>',
|
|
@@ -450,6 +628,24 @@ function cStandin(
|
|
|
450
628
|
'',
|
|
451
629
|
...definitions,
|
|
452
630
|
].join('\n')
|
|
631
|
+
// the generated source compiles on its own: a failure is a gap for the
|
|
632
|
+
// module, never invalid c breaking the app's compile.
|
|
633
|
+
const out = path.join(work, `${surface.module}.c`)
|
|
634
|
+
fs.writeFileSync(out, source)
|
|
635
|
+
try {
|
|
636
|
+
exec(path.join(toolchain.toolchainBin, 'clang'), [
|
|
637
|
+
'-target',
|
|
638
|
+
TRIPLE,
|
|
639
|
+
'--sysroot',
|
|
640
|
+
sysroot,
|
|
641
|
+
'-fsyntax-only',
|
|
642
|
+
'-I',
|
|
643
|
+
include,
|
|
644
|
+
out,
|
|
645
|
+
])
|
|
646
|
+
} catch (error) {
|
|
647
|
+
throw new Error(`its generated source does not compile: ${failure(error)}`)
|
|
648
|
+
}
|
|
453
649
|
return {
|
|
454
650
|
module: surface.module,
|
|
455
651
|
target: binary.target,
|
|
@@ -465,23 +661,66 @@ function cStandin(
|
|
|
465
661
|
|
|
466
662
|
const built = new Map<string, SwiftStandin[] | string>()
|
|
467
663
|
|
|
664
|
+
/** what stand-ins are generated from besides the surfaces' files: the
|
|
665
|
+
* toolchain, peach's modules and distribution, the emitter, and each
|
|
666
|
+
* artifact's contents. the host's memo and the stand-in cache both key on
|
|
667
|
+
* it, so either notices a changed input. */
|
|
668
|
+
export function standinGenerationInputs(
|
|
669
|
+
binaries: readonly SwiftPackageBinary[],
|
|
670
|
+
toolchain: Toolchain,
|
|
671
|
+
): string {
|
|
672
|
+
const { moduleRoot, toolchainBin, release } = toolchain
|
|
673
|
+
const parts = [
|
|
674
|
+
'standin/v2',
|
|
675
|
+
toolchainBin,
|
|
676
|
+
release,
|
|
677
|
+
swiftModuleSdk(moduleRoot).wasmSdkId,
|
|
678
|
+
swiftModuleDigest(moduleRoot).toString('hex'),
|
|
679
|
+
`emit/${STANDIN_EMIT_VERSION}`,
|
|
680
|
+
]
|
|
681
|
+
for (const binary of binaries) {
|
|
682
|
+
try {
|
|
683
|
+
parts.push(
|
|
684
|
+
binary.target,
|
|
685
|
+
binary.source,
|
|
686
|
+
binary.url ?? '',
|
|
687
|
+
xcframework(binary).digest,
|
|
688
|
+
)
|
|
689
|
+
} catch {
|
|
690
|
+
// unreadable here fails again below, where it becomes a gap
|
|
691
|
+
parts.push(binary.target, binary.source, binary.url ?? '', 'unreadable')
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
return createHash('sha256').update(parts.join('\0')).digest('hex')
|
|
695
|
+
}
|
|
696
|
+
|
|
468
697
|
// one binary target's stand-ins, or why it has none, cached by what they are
|
|
469
|
-
// generated from
|
|
698
|
+
// generated from. surfaces peach already ships (by target name or by the
|
|
699
|
+
// module names the slice carries, which differ: _FirebaseCore vends
|
|
700
|
+
// FirebaseCore) are skipped: a local generated target under the module's
|
|
701
|
+
// name would override the shipped module.
|
|
470
702
|
function binaryStandins(
|
|
471
703
|
binary: SwiftPackageBinary,
|
|
472
704
|
toolchain: Toolchain,
|
|
705
|
+
provided: ReadonlySet<string>,
|
|
473
706
|
): SwiftStandin[] | string {
|
|
474
|
-
|
|
707
|
+
if (provided.has(binary.target)) return []
|
|
708
|
+
let all: Surface[]
|
|
709
|
+
let digest: string
|
|
475
710
|
try {
|
|
476
|
-
|
|
711
|
+
const artifact = xcframework(binary)
|
|
712
|
+
all = surfaces(artifact.dir)
|
|
713
|
+
digest = artifact.digest
|
|
477
714
|
} catch (error) {
|
|
478
715
|
return error instanceof Error ? error.message : String(error)
|
|
479
716
|
}
|
|
480
|
-
|
|
717
|
+
const found = all.filter((surface) => !provided.has(surface.module))
|
|
718
|
+
if (found.length === 0) {
|
|
719
|
+
if (all.length > 0) return []
|
|
481
720
|
return 'its iOS simulator slice has no Swift interface or C modulemap'
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
)
|
|
721
|
+
}
|
|
722
|
+
const hash = createHash('sha256').update(standinGenerationInputs([binary], toolchain))
|
|
723
|
+
hash.update(digest)
|
|
485
724
|
for (const surface of found) {
|
|
486
725
|
hash.update(`${surface.kind}\0${surface.module}\0`)
|
|
487
726
|
for (const file of surface.kind === 'swift'
|
|
@@ -530,15 +769,21 @@ function binaryStandins(
|
|
|
530
769
|
return result
|
|
531
770
|
}
|
|
532
771
|
|
|
533
|
-
/**
|
|
772
|
+
/**
|
|
773
|
+
* stand-ins for the binary targets the app reaches, built on this host.
|
|
774
|
+
* `provided` names what peach already ships, by target and module: those
|
|
775
|
+
* surfaces are skipped, with no gap, so no generated target overrides a
|
|
776
|
+
* shipped module.
|
|
777
|
+
*/
|
|
534
778
|
export function swiftStandins(
|
|
535
779
|
binaries: readonly SwiftPackageBinary[],
|
|
536
780
|
toolchain: Toolchain,
|
|
781
|
+
provided: ReadonlySet<string> = new Set(),
|
|
537
782
|
): SwiftStandins {
|
|
538
783
|
const standins: SwiftStandin[] = []
|
|
539
784
|
const gaps = new Map<string, string>()
|
|
540
785
|
for (const binary of binaries) {
|
|
541
|
-
const result = binaryStandins(binary, toolchain)
|
|
786
|
+
const result = binaryStandins(binary, toolchain, provided)
|
|
542
787
|
if (typeof result === 'string') gaps.set(binary.target, result)
|
|
543
788
|
else standins.push(...result)
|
|
544
789
|
}
|