peachsim 0.1.780 → 0.1.782
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 +6 -2
- package/detox/expectations.ts +1 -1
- package/detox/gestures.ts +1 -1
- package/detox/index.ts +27 -3
- package/detox/navigation-lifecycle.ts +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 +3533 -133
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +6781 -2442
- 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 +4664 -1266
- 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 +1114 -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/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 +9017 -366
- 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 +2229 -583
- package/dist-lib/vite.cjs +38 -16
- package/package.json +1 -1
- package/skills/contrast/SKILL.md +2 -0
- package/src/one-widget-package.ts +202 -0
- package/src/oneWidgetContract.ts +16 -0
- package/src/swift-host.ts +56 -29
- package/src/swift-standin-emit.ts +471 -242
- package/src/swift-standins.ts +288 -40
- package/src/vite-plugin-one.ts +45 -17
- package/src/vite-plugin-swift.ts +2 -0
package/src/swift-standins.ts
CHANGED
|
@@ -2,24 +2,32 @@
|
|
|
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'
|
|
12
14
|
import fs from 'node:fs'
|
|
13
15
|
import os from 'node:os'
|
|
14
16
|
import path from 'node:path'
|
|
17
|
+
import { getCliVersion } from './cli-version'
|
|
15
18
|
import {
|
|
16
19
|
swiftDistributionAt,
|
|
17
20
|
swiftMacroPlugins,
|
|
21
|
+
swiftModuleDigest,
|
|
18
22
|
swiftModuleSdk,
|
|
19
23
|
swiftPeachModules,
|
|
20
24
|
swiftSdkPaths,
|
|
21
25
|
} from './swift-compile'
|
|
22
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
STANDIN_EMIT_VERSION,
|
|
28
|
+
emitSwiftStandin,
|
|
29
|
+
type SymbolGraph,
|
|
30
|
+
} from './swift-standin-emit'
|
|
23
31
|
import type { SwiftPackageBinary } from './swift-packages'
|
|
24
32
|
|
|
25
33
|
const TRIPLE = 'wasm32-unknown-wasip1'
|
|
@@ -43,6 +51,8 @@ export interface SwiftStandins {
|
|
|
43
51
|
interface Toolchain {
|
|
44
52
|
moduleRoot: string
|
|
45
53
|
toolchainBin: string
|
|
54
|
+
/** the toolchain release, read once where the toolchain is resolved. */
|
|
55
|
+
release: string
|
|
46
56
|
}
|
|
47
57
|
|
|
48
58
|
function exec(file: string, args: string[], cwd?: string): string {
|
|
@@ -70,21 +80,42 @@ function failure(error: unknown): string {
|
|
|
70
80
|
const key = (...parts: string[]) =>
|
|
71
81
|
createHash('sha256').update(parts.join('\0')).digest('hex').slice(0, 32)
|
|
72
82
|
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
// content digests, stat-gated: a matching stat reuses the digest, any stat
|
|
84
|
+
// change rehashes, so keys track contents without hashing on every call.
|
|
85
|
+
const digests = new Map<string, { stamp: string; digest: string }>()
|
|
86
|
+
|
|
87
|
+
function treeDigest(root: string): string {
|
|
88
|
+
const names: string[] = []
|
|
89
|
+
const walk = (dir: string) => {
|
|
90
|
+
for (const entry of fs
|
|
91
|
+
.readdirSync(dir, { withFileTypes: true })
|
|
92
|
+
.sort((left, right) => (left.name < right.name ? -1 : 1))) {
|
|
93
|
+
const full = path.join(dir, entry.name)
|
|
94
|
+
if (entry.isDirectory()) walk(full)
|
|
95
|
+
else if (entry.isFile()) names.push(path.relative(root, full))
|
|
96
|
+
}
|
|
87
97
|
}
|
|
98
|
+
walk(root)
|
|
99
|
+
const stamp = names
|
|
100
|
+
.map((name) => {
|
|
101
|
+
const stat = fs.statSync(path.join(root, name))
|
|
102
|
+
return `${name}\0${stat.size}:${stat.mtimeMs}`
|
|
103
|
+
})
|
|
104
|
+
.join('\n')
|
|
105
|
+
const memo = digests.get(`tree\0${root}`)
|
|
106
|
+
if (memo?.stamp === stamp) return memo.digest
|
|
107
|
+
const hash = createHash('sha256')
|
|
108
|
+
for (const name of names) {
|
|
109
|
+
hash.update(`${name}\0`)
|
|
110
|
+
hash.update(fs.readFileSync(path.join(root, name)))
|
|
111
|
+
hash.update('\0')
|
|
112
|
+
}
|
|
113
|
+
const digest = hash.digest('hex')
|
|
114
|
+
digests.set(`tree\0${root}`, { stamp, digest })
|
|
115
|
+
return digest
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function locateXcframework(tree: string): string | null {
|
|
88
119
|
const find = (root: string, depth: number): string | null => {
|
|
89
120
|
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
90
121
|
if (!entry.isDirectory() || entry.name === '__MACOSX') continue
|
|
@@ -95,9 +126,63 @@ function xcframework(binary: SwiftPackageBinary): string {
|
|
|
95
126
|
}
|
|
96
127
|
return null
|
|
97
128
|
}
|
|
98
|
-
|
|
129
|
+
return find(tree, 2)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// the xcframework a binary target names, with a digest of the artifact's
|
|
133
|
+
// contents: a local directory digests as a tree, while an archive (local or
|
|
134
|
+
// remote) keeps its bytes and unpacks again when they change. the digest,
|
|
135
|
+
// not the path, keys the stand-in cache, so a replaced same-path zip
|
|
136
|
+
// rebuilds instead of reusing stale output.
|
|
137
|
+
function xcframework(binary: SwiftPackageBinary): { dir: string; digest: string } {
|
|
138
|
+
if (!binary.url && !binary.dir.endsWith('.zip'))
|
|
139
|
+
return { dir: binary.dir, digest: treeDigest(binary.dir) }
|
|
140
|
+
const dir = path.join(cacheDir, 'archives', key(binary.url ?? binary.dir))
|
|
141
|
+
const archive = path.join(dir, 'archive.zip')
|
|
142
|
+
const fingerprint = path.join(dir, '.fingerprint')
|
|
143
|
+
const stored: { stamp?: string; sha: string } | null = (() => {
|
|
144
|
+
try {
|
|
145
|
+
const parsed: unknown = JSON.parse(fs.readFileSync(fingerprint, 'utf8'))
|
|
146
|
+
return parsed && typeof parsed === 'object' && 'sha' in parsed
|
|
147
|
+
? (parsed as { stamp?: string; sha: string })
|
|
148
|
+
: null
|
|
149
|
+
} catch {
|
|
150
|
+
return null
|
|
151
|
+
}
|
|
152
|
+
})()
|
|
153
|
+
if (!binary.url) {
|
|
154
|
+
// a local archive: its bytes are the identity, the stat only skips
|
|
155
|
+
// hashing them again while they are unchanged.
|
|
156
|
+
const stat = fs.statSync(binary.dir)
|
|
157
|
+
const stamp = `${stat.size}:${stat.mtimeMs}`
|
|
158
|
+
if (stored?.stamp === stamp) {
|
|
159
|
+
const found = locateXcframework(path.join(dir, 'tree'))
|
|
160
|
+
if (found) return { dir: found, digest: stored.sha }
|
|
161
|
+
}
|
|
162
|
+
const sha = createHash('sha256').update(fs.readFileSync(binary.dir)).digest('hex')
|
|
163
|
+
if (sha !== stored?.sha || !locateXcframework(path.join(dir, 'tree'))) {
|
|
164
|
+
fs.rmSync(dir, { recursive: true, force: true })
|
|
165
|
+
fs.mkdirSync(path.join(dir, 'tree'), { recursive: true })
|
|
166
|
+
exec('unzip', ['-q', binary.dir, '-d', path.join(dir, 'tree')])
|
|
167
|
+
}
|
|
168
|
+
fs.writeFileSync(fingerprint, JSON.stringify({ stamp, sha }))
|
|
169
|
+
const found = locateXcframework(path.join(dir, 'tree'))
|
|
170
|
+
if (!found) throw new Error('its archive holds no .xcframework')
|
|
171
|
+
return { dir: found, digest: sha }
|
|
172
|
+
}
|
|
173
|
+
if (stored && fs.existsSync(archive)) {
|
|
174
|
+
const found = locateXcframework(path.join(dir, 'tree'))
|
|
175
|
+
if (found) return { dir: found, digest: stored.sha }
|
|
176
|
+
}
|
|
177
|
+
fs.rmSync(dir, { recursive: true, force: true })
|
|
178
|
+
fs.mkdirSync(path.join(dir, 'tree'), { recursive: true })
|
|
179
|
+
exec('curl', ['-fsSL', '--retry', '2', '-o', archive, binary.url])
|
|
180
|
+
const sha = createHash('sha256').update(fs.readFileSync(archive)).digest('hex')
|
|
181
|
+
exec('unzip', ['-q', archive, '-d', path.join(dir, 'tree')])
|
|
182
|
+
fs.writeFileSync(fingerprint, JSON.stringify({ sha }))
|
|
183
|
+
const found = locateXcframework(path.join(dir, 'tree'))
|
|
99
184
|
if (!found) throw new Error('its archive holds no .xcframework')
|
|
100
|
-
return found
|
|
185
|
+
return { dir: found, digest: sha }
|
|
101
186
|
}
|
|
102
187
|
|
|
103
188
|
const files = (dir: string, test: (name: string) => boolean): string[] =>
|
|
@@ -351,6 +436,8 @@ function functionDeclarations(
|
|
|
351
436
|
const declFile = file
|
|
352
437
|
walk(decl)
|
|
353
438
|
if (Reflect.get(decl, 'kind') !== 'FunctionDecl' || !headers.has(declFile)) continue
|
|
439
|
+
// a static function keeps the vendor's own body, which stays callable:
|
|
440
|
+
// only extern declarations need definitions, and those trap.
|
|
354
441
|
if (Reflect.get(decl, 'isImplicit') || Reflect.get(decl, 'storageClass') === 'static')
|
|
355
442
|
continue
|
|
356
443
|
const inner = Reflect.get(decl, 'inner')
|
|
@@ -375,6 +462,76 @@ function functionDeclarations(
|
|
|
375
462
|
return found
|
|
376
463
|
}
|
|
377
464
|
|
|
465
|
+
// the opener matching the closer at `close`, scanning left.
|
|
466
|
+
function matchOpen(text: string, close: number): number {
|
|
467
|
+
const open = text[close] === ')' ? '(' : '['
|
|
468
|
+
let depth = 0
|
|
469
|
+
for (let index = close; index >= 0; index--) {
|
|
470
|
+
if (text[index] === text[close]) depth++
|
|
471
|
+
else if (text[index] === open && --depth === 0) return index
|
|
472
|
+
}
|
|
473
|
+
return -1
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
const identChar = (char: string | undefined): boolean =>
|
|
477
|
+
char !== undefined && /[\w$]/.test(char)
|
|
478
|
+
|
|
479
|
+
// one definition per declarator of a grouped declaration statement, in the
|
|
480
|
+
// declarators' order: the first keeps the statement as written, each later
|
|
481
|
+
// one reuses the specifiers before the first declarator (`const char *a, *b`
|
|
482
|
+
// declares two `const char *`). a mismatch throws, so it becomes a reported
|
|
483
|
+
// gap instead of invalid c.
|
|
484
|
+
function splitDeclarators(statement: string, names: readonly string[]): string[] {
|
|
485
|
+
const chunks: string[] = []
|
|
486
|
+
let depth = 0
|
|
487
|
+
let quote: string | null = null
|
|
488
|
+
let start = 0
|
|
489
|
+
for (let index = 0; index < statement.length; index++) {
|
|
490
|
+
const char = statement[index]!
|
|
491
|
+
if (quote) {
|
|
492
|
+
if (char === '\\') index++
|
|
493
|
+
else if (char === quote) quote = null
|
|
494
|
+
} else if (char === '"' || char === "'") quote = char
|
|
495
|
+
else if (char === '(' || char === '[' || char === '{') depth++
|
|
496
|
+
else if (char === ')' || char === ']' || char === '}') depth--
|
|
497
|
+
else if (char === ',' && depth === 0) {
|
|
498
|
+
chunks.push(statement.slice(start, index))
|
|
499
|
+
start = index + 1
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
chunks.push(statement.slice(start))
|
|
503
|
+
if (chunks.length !== names.length)
|
|
504
|
+
throw new Error(
|
|
505
|
+
`${names[0]} has an unexpected grouped declaration in ${JSON.stringify(statement.trim().slice(0, 80))}`,
|
|
506
|
+
)
|
|
507
|
+
// the specifiers end where the first declarator starts: left of its name
|
|
508
|
+
// over pointers and whitespace, and over attribute groups, stopping at a
|
|
509
|
+
// paren that groups the declarator itself (`int (*fp)(void)`).
|
|
510
|
+
let end = chunks[0]!.indexOf(names[0]!)
|
|
511
|
+
if (end < 0) throw new Error(`${names[0]} names no declarator in its own declaration`)
|
|
512
|
+
for (;;) {
|
|
513
|
+
while (end > 0 && /[\s*]/.test(chunks[0]![end - 1]!)) end--
|
|
514
|
+
if (end > 0 && (chunks[0]![end - 1] === ')' || chunks[0]![end - 1] === ']')) {
|
|
515
|
+
end = matchOpen(chunks[0]!, end - 1)
|
|
516
|
+
if (end < 0) throw new Error(`${names[0]} has unbalanced groups in its declaration`)
|
|
517
|
+
// an attribute call's arguments: the attribute's name goes with them
|
|
518
|
+
while (end > 0 && identChar(chunks[0]![end - 1])) end--
|
|
519
|
+
continue
|
|
520
|
+
}
|
|
521
|
+
if (end > 1 && chunks[0]![end - 1] === '(' && identChar(chunks[0]![end - 2])) {
|
|
522
|
+
end--
|
|
523
|
+
while (end > 0 && identChar(chunks[0]![end - 1])) end--
|
|
524
|
+
continue
|
|
525
|
+
}
|
|
526
|
+
break
|
|
527
|
+
}
|
|
528
|
+
if (end > 0 && chunks[0]![end - 1] === '(') end--
|
|
529
|
+
const specifiers = chunks[0]!.slice(0, end)
|
|
530
|
+
return chunks.map((chunk, index) =>
|
|
531
|
+
index === 0 ? chunk : `${specifiers} ${chunk.trim()}`,
|
|
532
|
+
)
|
|
533
|
+
}
|
|
534
|
+
|
|
378
535
|
function cStandin(
|
|
379
536
|
surface: Extract<Surface, { kind: 'c' }>,
|
|
380
537
|
binary: SwiftPackageBinary,
|
|
@@ -422,23 +579,45 @@ function cStandin(
|
|
|
422
579
|
)
|
|
423
580
|
const byPath = new Map(headers.map((file) => [path.join(include, file), file]))
|
|
424
581
|
const declarations = functionDeclarations(ast, new Set(byPath.keys()))
|
|
582
|
+
// declarations sharing one statement start are one grouped declaration
|
|
583
|
+
// (`int first(void), second(void);`): clang reports one FunctionDecl per
|
|
584
|
+
// declarator, and emitting the whole statement per declarator repeats it
|
|
585
|
+
// and breaks the compile. each declarator gets its own definition under
|
|
586
|
+
// the statement's specifiers instead.
|
|
587
|
+
const groups = new Map<string, typeof declarations>()
|
|
588
|
+
for (const declaration of declarations) {
|
|
589
|
+
const group = groups.get(`${declaration.file}\0${declaration.begin}`) ?? []
|
|
590
|
+
group.push(declaration)
|
|
591
|
+
groups.set(`${declaration.file}\0${declaration.begin}`, group)
|
|
592
|
+
}
|
|
425
593
|
const seen = new Set<string>()
|
|
426
594
|
const definitions: string[] = []
|
|
427
|
-
for (const
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
const
|
|
431
|
-
const close = text.indexOf(';', end)
|
|
595
|
+
for (const group of groups.values()) {
|
|
596
|
+
const first = group[0]!
|
|
597
|
+
const text = texts.get(byPath.get(first.file)!)!
|
|
598
|
+
const close = text.indexOf(';', first.end)
|
|
432
599
|
if (close < 0)
|
|
433
|
-
throw new Error(`${name} has no declaration end in ${byPath.get(file)}`)
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
600
|
+
throw new Error(`${first.name} has no declaration end in ${byPath.get(first.file)}`)
|
|
601
|
+
const statement = text.slice(first.begin, close)
|
|
602
|
+
const declarators =
|
|
603
|
+
group.length === 1
|
|
604
|
+
? [statement]
|
|
605
|
+
: splitDeclarators(
|
|
606
|
+
statement,
|
|
607
|
+
group.map((declaration) => declaration.name),
|
|
608
|
+
)
|
|
609
|
+
group.forEach((declaration, index) => {
|
|
610
|
+
if (seen.has(declaration.name)) return
|
|
611
|
+
seen.add(declaration.name)
|
|
612
|
+
definitions.push(
|
|
613
|
+
`${declarators[index]!.trim()} {\n peach_standin_trap("${declaration.name}");\n}\n`,
|
|
614
|
+
)
|
|
615
|
+
})
|
|
437
616
|
}
|
|
438
617
|
const sdk = JSON.stringify(`${binary.target} (${binary.source})`)
|
|
439
618
|
const source = [
|
|
440
619
|
`// generated by peach from ${surface.module}'s headers: ${binary.target} ships`,
|
|
441
|
-
'// iOS machine code only, so every function traps naming itself.',
|
|
620
|
+
'// iOS machine code only, so every extern function traps naming itself.',
|
|
442
621
|
...roots.map((file) => `#include "${file}"`),
|
|
443
622
|
'#include <stdio.h>',
|
|
444
623
|
'#include <stdlib.h>',
|
|
@@ -450,6 +629,24 @@ function cStandin(
|
|
|
450
629
|
'',
|
|
451
630
|
...definitions,
|
|
452
631
|
].join('\n')
|
|
632
|
+
// the generated source compiles on its own: a failure is a gap for the
|
|
633
|
+
// module, never invalid c breaking the app's compile.
|
|
634
|
+
const out = path.join(work, `${surface.module}.c`)
|
|
635
|
+
fs.writeFileSync(out, source)
|
|
636
|
+
try {
|
|
637
|
+
exec(path.join(toolchain.toolchainBin, 'clang'), [
|
|
638
|
+
'-target',
|
|
639
|
+
TRIPLE,
|
|
640
|
+
'--sysroot',
|
|
641
|
+
sysroot,
|
|
642
|
+
'-fsyntax-only',
|
|
643
|
+
'-I',
|
|
644
|
+
include,
|
|
645
|
+
out,
|
|
646
|
+
])
|
|
647
|
+
} catch (error) {
|
|
648
|
+
throw new Error(`its generated source does not compile: ${failure(error)}`)
|
|
649
|
+
}
|
|
453
650
|
return {
|
|
454
651
|
module: surface.module,
|
|
455
652
|
target: binary.target,
|
|
@@ -465,23 +662,68 @@ function cStandin(
|
|
|
465
662
|
|
|
466
663
|
const built = new Map<string, SwiftStandin[] | string>()
|
|
467
664
|
|
|
665
|
+
/** what stand-ins are generated from besides the surfaces' files: the
|
|
666
|
+
* toolchain, peach's modules and distribution, the emitter, and each
|
|
667
|
+
* artifact's contents. the host's memo and the stand-in cache both key on
|
|
668
|
+
* it, so either notices a changed input. */
|
|
669
|
+
export function standinGenerationInputs(
|
|
670
|
+
binaries: readonly SwiftPackageBinary[],
|
|
671
|
+
toolchain: Toolchain,
|
|
672
|
+
): string {
|
|
673
|
+
const { moduleRoot, toolchainBin, release } = toolchain
|
|
674
|
+
const parts = [
|
|
675
|
+
'standin/v2',
|
|
676
|
+
toolchainBin,
|
|
677
|
+
release,
|
|
678
|
+
swiftModuleSdk(moduleRoot).wasmSdkId,
|
|
679
|
+
swiftModuleDigest(moduleRoot).toString('hex'),
|
|
680
|
+
`emit/${STANDIN_EMIT_VERSION}`,
|
|
681
|
+
// a released cli can change the emitter without anyone bumping the constant
|
|
682
|
+
`cli/${getCliVersion()}`,
|
|
683
|
+
]
|
|
684
|
+
for (const binary of binaries) {
|
|
685
|
+
try {
|
|
686
|
+
parts.push(
|
|
687
|
+
binary.target,
|
|
688
|
+
binary.source,
|
|
689
|
+
binary.url ?? '',
|
|
690
|
+
xcframework(binary).digest,
|
|
691
|
+
)
|
|
692
|
+
} catch {
|
|
693
|
+
// unreadable here fails again below, where it becomes a gap
|
|
694
|
+
parts.push(binary.target, binary.source, binary.url ?? '', 'unreadable')
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
return createHash('sha256').update(parts.join('\0')).digest('hex')
|
|
698
|
+
}
|
|
699
|
+
|
|
468
700
|
// one binary target's stand-ins, or why it has none, cached by what they are
|
|
469
|
-
// generated from
|
|
701
|
+
// generated from. surfaces peach already ships (by target name or by the
|
|
702
|
+
// module names the slice carries, which differ: _FirebaseCore vends
|
|
703
|
+
// FirebaseCore) are skipped: a local generated target under the module's
|
|
704
|
+
// name would override the shipped module.
|
|
470
705
|
function binaryStandins(
|
|
471
706
|
binary: SwiftPackageBinary,
|
|
472
707
|
toolchain: Toolchain,
|
|
708
|
+
provided: ReadonlySet<string>,
|
|
473
709
|
): SwiftStandin[] | string {
|
|
474
|
-
|
|
710
|
+
if (provided.has(binary.target)) return []
|
|
711
|
+
let all: Surface[]
|
|
712
|
+
let digest: string
|
|
475
713
|
try {
|
|
476
|
-
|
|
714
|
+
const artifact = xcframework(binary)
|
|
715
|
+
all = surfaces(artifact.dir)
|
|
716
|
+
digest = artifact.digest
|
|
477
717
|
} catch (error) {
|
|
478
718
|
return error instanceof Error ? error.message : String(error)
|
|
479
719
|
}
|
|
480
|
-
|
|
720
|
+
const found = all.filter((surface) => !provided.has(surface.module))
|
|
721
|
+
if (found.length === 0) {
|
|
722
|
+
if (all.length > 0) return []
|
|
481
723
|
return 'its iOS simulator slice has no Swift interface or C modulemap'
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
)
|
|
724
|
+
}
|
|
725
|
+
const hash = createHash('sha256').update(standinGenerationInputs([binary], toolchain))
|
|
726
|
+
hash.update(digest)
|
|
485
727
|
for (const surface of found) {
|
|
486
728
|
hash.update(`${surface.kind}\0${surface.module}\0`)
|
|
487
729
|
for (const file of surface.kind === 'swift'
|
|
@@ -530,15 +772,21 @@ function binaryStandins(
|
|
|
530
772
|
return result
|
|
531
773
|
}
|
|
532
774
|
|
|
533
|
-
/**
|
|
775
|
+
/**
|
|
776
|
+
* stand-ins for the binary targets the app reaches, built on this host.
|
|
777
|
+
* `provided` names what peach already ships, by target and module: those
|
|
778
|
+
* surfaces are skipped, with no gap, so no generated target overrides a
|
|
779
|
+
* shipped module.
|
|
780
|
+
*/
|
|
534
781
|
export function swiftStandins(
|
|
535
782
|
binaries: readonly SwiftPackageBinary[],
|
|
536
783
|
toolchain: Toolchain,
|
|
784
|
+
provided: ReadonlySet<string> = new Set(),
|
|
537
785
|
): SwiftStandins {
|
|
538
786
|
const standins: SwiftStandin[] = []
|
|
539
787
|
const gaps = new Map<string, string>()
|
|
540
788
|
for (const binary of binaries) {
|
|
541
|
-
const result = binaryStandins(binary, toolchain)
|
|
789
|
+
const result = binaryStandins(binary, toolchain, provided)
|
|
542
790
|
if (typeof result === 'string') gaps.set(binary.target, result)
|
|
543
791
|
else standins.push(...result)
|
|
544
792
|
}
|
package/src/vite-plugin-one.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
SOOTSIM_RUNTIME_MISSING_MESSAGE,
|
|
29
29
|
} from './runtime-assets'
|
|
30
30
|
import { SWIFT_HMR_PATH, SWIFT_PACKAGE_PATH } from './swift-submit'
|
|
31
|
+
import type { OneWidgetPackage } from './oneWidgetContract'
|
|
31
32
|
import type { PeachPluginOptions } from './vite'
|
|
32
33
|
import type { Plugin } from 'vite'
|
|
33
34
|
|
|
@@ -88,6 +89,41 @@ export function rnxPlugin(options: PeachPluginOptions = {}): Plugin {
|
|
|
88
89
|
swiftPackages ??= swiftPackageDirectories(server.config.root)
|
|
89
90
|
return swiftPackages
|
|
90
91
|
}
|
|
92
|
+
let widgetPackage: OneWidgetPackage | null = null
|
|
93
|
+
const servedPackage = async (packageName: string) => {
|
|
94
|
+
const host = await loadSwiftHost()
|
|
95
|
+
const existing = packageMap().get(packageName)
|
|
96
|
+
if (packageName !== host.ONE_WIDGET_PACKAGE) return existing
|
|
97
|
+
widgetPackage = await host.oneWidgetPackage(server.config.root)
|
|
98
|
+
if (!widgetPackage) return existing
|
|
99
|
+
if (existing)
|
|
100
|
+
throw new Error(
|
|
101
|
+
`swift package ${packageName} conflicts with One's generated widget extension`,
|
|
102
|
+
)
|
|
103
|
+
server.watcher.add(widgetPackage.watched)
|
|
104
|
+
return widgetPackage.packagePath
|
|
105
|
+
}
|
|
106
|
+
const packageMetadata = async (
|
|
107
|
+
packageName: string,
|
|
108
|
+
moduleRoot: string | undefined,
|
|
109
|
+
) => {
|
|
110
|
+
const packagePath = await servedPackage(packageName)
|
|
111
|
+
if (!packagePath) throw new Error(`swift package ${packageName} was not found`)
|
|
112
|
+
const host = await loadSwiftHost()
|
|
113
|
+
const metadata = await host.swiftPackageMetadata(
|
|
114
|
+
packagePath,
|
|
115
|
+
packageName,
|
|
116
|
+
moduleRoot,
|
|
117
|
+
devOrigin(),
|
|
118
|
+
)
|
|
119
|
+
return {
|
|
120
|
+
...metadata,
|
|
121
|
+
hmrPath,
|
|
122
|
+
...(packageName === host.ONE_WIDGET_PACKAGE && widgetPackage
|
|
123
|
+
? { widget: widgetPackage.widget }
|
|
124
|
+
: {}),
|
|
125
|
+
}
|
|
126
|
+
}
|
|
91
127
|
const wsOptions = server.config.server.ws
|
|
92
128
|
const httpServer =
|
|
93
129
|
server.httpServer ??
|
|
@@ -162,32 +198,25 @@ export function rnxPlugin(options: PeachPluginOptions = {}): Plugin {
|
|
|
162
198
|
try {
|
|
163
199
|
packages = packageMap()
|
|
164
200
|
} catch (error) {
|
|
165
|
-
for (const packageName of activeSwiftPackages)
|
|
201
|
+
for (const packageName of activeSwiftPackages)
|
|
166
202
|
sendSwiftChange({
|
|
167
203
|
type: 'error',
|
|
168
204
|
packageName,
|
|
169
205
|
message: error instanceof Error ? error.message : String(error),
|
|
170
206
|
})
|
|
171
|
-
}
|
|
172
207
|
return
|
|
173
208
|
}
|
|
174
209
|
for (const packageName of activeSwiftPackages) {
|
|
175
210
|
const packagePath = packages.get(packageName)
|
|
176
|
-
|
|
211
|
+
const widgetChanged =
|
|
212
|
+
packageName === 'OneWidgets' && widgetPackage?.watched.includes(file)
|
|
177
213
|
if (
|
|
178
|
-
!
|
|
214
|
+
!widgetChanged &&
|
|
215
|
+
!(packagePath && file.startsWith(`${packagePath}${path.sep}`)) &&
|
|
179
216
|
!(moduleRoot && file.startsWith(`${moduleRoot}${path.sep}`))
|
|
180
217
|
)
|
|
181
218
|
continue
|
|
182
|
-
void
|
|
183
|
-
.then((host) =>
|
|
184
|
-
host.swiftPackageMetadata(
|
|
185
|
-
packagePath,
|
|
186
|
-
packageName,
|
|
187
|
-
moduleRoot,
|
|
188
|
-
devOrigin(),
|
|
189
|
-
),
|
|
190
|
-
)
|
|
219
|
+
void packageMetadata(packageName, moduleRoot)
|
|
191
220
|
.then((metadata) => {
|
|
192
221
|
sendSwiftChange({
|
|
193
222
|
type: 'package',
|
|
@@ -208,7 +237,7 @@ export function rnxPlugin(options: PeachPluginOptions = {}): Plugin {
|
|
|
208
237
|
const pathname = (req.url ?? '').split('?')[0]
|
|
209
238
|
if (!pathname.startsWith(SWIFT_ROUTE_PREFIX)) return next()
|
|
210
239
|
loadSwiftHost()
|
|
211
|
-
.then((host) => {
|
|
240
|
+
.then(async (host) => {
|
|
212
241
|
if (host.serveSwiftPackageAsset(pathname, res)) return
|
|
213
242
|
const prefix = SWIFT_PACKAGE_PATH
|
|
214
243
|
if (!pathname.startsWith(prefix)) return next()
|
|
@@ -220,7 +249,7 @@ export function rnxPlugin(options: PeachPluginOptions = {}): Plugin {
|
|
|
220
249
|
const packageName = pathname.slice(prefix.length)
|
|
221
250
|
let packagePath: string | undefined
|
|
222
251
|
try {
|
|
223
|
-
packagePath =
|
|
252
|
+
packagePath = await servedPackage(packageName)
|
|
224
253
|
} catch (error) {
|
|
225
254
|
res.statusCode = 500
|
|
226
255
|
res.end(error instanceof Error ? error.message : String(error))
|
|
@@ -234,8 +263,7 @@ export function rnxPlugin(options: PeachPluginOptions = {}): Plugin {
|
|
|
234
263
|
const moduleRoot = moduleRootFor()
|
|
235
264
|
activeSwiftPackages.add(packageName)
|
|
236
265
|
server.watcher.add(host.swiftPackageWatchFiles(packagePath, moduleRoot))
|
|
237
|
-
void
|
|
238
|
-
.swiftPackageMetadata(packagePath, packageName, moduleRoot, devOrigin())
|
|
266
|
+
void packageMetadata(packageName, moduleRoot)
|
|
239
267
|
.then((metadata) => {
|
|
240
268
|
res.setHeader('access-control-allow-origin', '*')
|
|
241
269
|
res.setHeader('content-type', 'application/json')
|
package/src/vite-plugin-swift.ts
CHANGED
|
@@ -34,6 +34,8 @@ export {
|
|
|
34
34
|
type SwiftResourceTable,
|
|
35
35
|
} from './swift-host'
|
|
36
36
|
|
|
37
|
+
export { oneWidgetPackage, ONE_WIDGET_PACKAGE } from './one-widget-package'
|
|
38
|
+
|
|
37
39
|
const ARTIFACT_PATH = '/__peach/swift/'
|
|
38
40
|
const VIRTUAL_PREFIX = '\0peach-swift:'
|
|
39
41
|
let devServer: ViteDevServer | undefined
|