peachsim 0.1.2405 → 0.1.2408
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/agent-note.ts +231 -0
- package/cli/cli-update.ts +2 -2
- package/cli/cloud-dispatch.ts +1 -1
- package/cli/commands/agent.ts +29 -26
- package/cli/commands/stream.ts +11 -7
- package/cli/main.ts +16 -2
- package/cli/outbound-endpoints.ts +16 -1
- package/dist-lib/agent-daemon-client.cjs +23 -3
- 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 +201 -60
- 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 +1 -1
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/expo-swift-bundle.cjs +200 -59
- 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 +356 -100
- 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 +4 -4
- 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 +4 -4
- package/dist-lib/native-app-identity-project.cjs +3 -3
- package/dist-lib/native-app-identity-project.mjs +3 -3
- 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 +56 -55
- 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 +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 +367 -106
- package/dist-lib/swift-compile.cjs +195 -54
- package/dist-lib/swift-compile.mjs +195 -54
- 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 +198 -57
- package/dist-lib/vite.cjs +4 -4
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +1 -1
- package/install.sh +1 -1
- package/kotlin/sdk.tar.gz +0 -0
- package/package.json +1 -1
- package/skills/peach-setup/SKILL.md +8 -3
- package/src/agent-daemon-client.ts +35 -2
- package/src/agent-prompt.ts +68 -0
- package/src/canvas-agent-note-delivery.ts +83 -0
- package/src/host/agent-host.ts +128 -18
- package/src/swift-compile.ts +124 -66
- package/src/swift-host.ts +2 -1
- package/src/swift-objc-import.ts +99 -0
- package/src/xcode-header-search.ts +33 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CanvasAgentNote,
|
|
3
|
+
CanvasAgentNoteDelivery,
|
|
4
|
+
CanvasAgentNoteStatus,
|
|
5
|
+
} from './agent-prompt'
|
|
6
|
+
|
|
7
|
+
export function createCanvasAgentNoteDelivery(
|
|
8
|
+
send: CanvasAgentNoteDelivery['send'],
|
|
9
|
+
readStatus: (id: string, signal: AbortSignal) => Promise<CanvasAgentNoteStatus>,
|
|
10
|
+
): CanvasAgentNoteDelivery {
|
|
11
|
+
return {
|
|
12
|
+
send,
|
|
13
|
+
async waitUntilTaken(id, signal) {
|
|
14
|
+
while (true) {
|
|
15
|
+
signal.throwIfAborted()
|
|
16
|
+
const status = await readStatus(id, signal)
|
|
17
|
+
if (status === 'taken') return
|
|
18
|
+
if (status === 'missing') throw new Error('This note is no longer available.')
|
|
19
|
+
await new Promise<void>((resolve, reject) => {
|
|
20
|
+
const abort = () => {
|
|
21
|
+
clearTimeout(timer)
|
|
22
|
+
reject(signal.reason)
|
|
23
|
+
}
|
|
24
|
+
const timer = setTimeout(() => {
|
|
25
|
+
signal.removeEventListener('abort', abort)
|
|
26
|
+
resolve()
|
|
27
|
+
}, 2_000)
|
|
28
|
+
signal.addEventListener('abort', abort, { once: true })
|
|
29
|
+
if (signal.aborted) abort()
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function cloudCanvasAgentNoteUrl(
|
|
37
|
+
origin: string,
|
|
38
|
+
target: { kind: 'sim' | 'box'; externalId: string },
|
|
39
|
+
): URL {
|
|
40
|
+
const url = new URL(
|
|
41
|
+
`/api/account/rnx-cloud/agent-notes/${encodeURIComponent(target.externalId)}`,
|
|
42
|
+
origin,
|
|
43
|
+
)
|
|
44
|
+
url.searchParams.set('kind', target.kind)
|
|
45
|
+
return url
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function cloudCanvasAgentNoteDelivery(
|
|
49
|
+
origin: string,
|
|
50
|
+
target: { kind: 'sim' | 'box'; externalId: string },
|
|
51
|
+
fetchNote: (input: URL, init: RequestInit) => Promise<Response> = fetch,
|
|
52
|
+
): CanvasAgentNoteDelivery {
|
|
53
|
+
const endpoint = cloudCanvasAgentNoteUrl(origin, target)
|
|
54
|
+
const post = async (body: object, signal?: AbortSignal): Promise<unknown> => {
|
|
55
|
+
const response = await fetchNote(endpoint, {
|
|
56
|
+
method: 'POST',
|
|
57
|
+
credentials: 'include',
|
|
58
|
+
headers: { 'content-type': 'application/json' },
|
|
59
|
+
body: JSON.stringify(body),
|
|
60
|
+
signal,
|
|
61
|
+
})
|
|
62
|
+
if (!response.ok) throw new Error('Could not reach the simulator’s note inbox.')
|
|
63
|
+
return response.json()
|
|
64
|
+
}
|
|
65
|
+
return createCanvasAgentNoteDelivery(
|
|
66
|
+
async (note: CanvasAgentNote) => {
|
|
67
|
+
const result = await post({ action: 'send', note })
|
|
68
|
+
const id: unknown =
|
|
69
|
+
result && typeof result === 'object' && Reflect.get(result, 'id')
|
|
70
|
+
if (typeof id !== 'string')
|
|
71
|
+
throw new Error('The simulator did not accept the note.')
|
|
72
|
+
return { id }
|
|
73
|
+
},
|
|
74
|
+
async (id, signal) => {
|
|
75
|
+
const result = await post({ action: 'status', id }, signal)
|
|
76
|
+
const status: unknown =
|
|
77
|
+
result && typeof result === 'object' && Reflect.get(result, 'status')
|
|
78
|
+
if (status === 'pending' || status === 'taken' || status === 'missing')
|
|
79
|
+
return status
|
|
80
|
+
throw new Error('The simulator did not report the note’s status.')
|
|
81
|
+
},
|
|
82
|
+
)
|
|
83
|
+
}
|
package/src/host/agent-host.ts
CHANGED
|
@@ -17,6 +17,15 @@ import { randomUUID } from 'node:crypto'
|
|
|
17
17
|
import fs from 'node:fs'
|
|
18
18
|
import path from 'node:path'
|
|
19
19
|
import { scanDevServers } from '../../scripts/dev-server-scanner.ts'
|
|
20
|
+
import {
|
|
21
|
+
AGENT_NOTE_QUEUE_LIMIT,
|
|
22
|
+
AGENT_NOTE_TTL_MS,
|
|
23
|
+
createCanvasAgentInspectMessage,
|
|
24
|
+
readCanvasAgentId,
|
|
25
|
+
readCanvasAgentNote,
|
|
26
|
+
type AgentInspectMessage,
|
|
27
|
+
type AgentPromptEnvelope,
|
|
28
|
+
} from '../agent-prompt.ts'
|
|
20
29
|
import {
|
|
21
30
|
AgentSessionError,
|
|
22
31
|
endSession as endAgentSession,
|
|
@@ -42,7 +51,6 @@ import {
|
|
|
42
51
|
type AttachedProject,
|
|
43
52
|
} from '../attached-projects.ts'
|
|
44
53
|
import type { AgentEvent } from '../agent-events.ts'
|
|
45
|
-
import type { AgentInspectMessage, AgentPromptEnvelope } from '../agent-prompt.ts'
|
|
46
54
|
import type { DiscoveredServer } from '../serverDiscoveryContract'
|
|
47
55
|
import type { WebSocket } from 'ws'
|
|
48
56
|
|
|
@@ -68,6 +76,7 @@ export interface AgentHostOptions {
|
|
|
68
76
|
}
|
|
69
77
|
|
|
70
78
|
interface InspectListener {
|
|
79
|
+
recipientId?: string
|
|
71
80
|
socket: WebSocket
|
|
72
81
|
resolve: (message: AgentInspectMessage) => void
|
|
73
82
|
reject: (error: Error) => void
|
|
@@ -99,6 +108,7 @@ export class AgentHost {
|
|
|
99
108
|
private allSockets = new Set<WebSocket>()
|
|
100
109
|
private inspectQueues = new Map<string, AgentInspectMessage[]>()
|
|
101
110
|
private inspectListeners = new Map<string, InspectListener[]>()
|
|
111
|
+
private takenNotes = new Map<string, { simId: string; expiresAt: number }>()
|
|
102
112
|
// agent wrappers also emit prompt-received from the FIFO reader, but the
|
|
103
113
|
// shell/daemon already knows the user-facing display text when send-prompt
|
|
104
114
|
// is accepted. emit the friendly prompt immediately and suppress the raw
|
|
@@ -201,6 +211,7 @@ export class AgentHost {
|
|
|
201
211
|
}
|
|
202
212
|
this.inspectListeners.clear()
|
|
203
213
|
this.inspectQueues.clear()
|
|
214
|
+
this.takenNotes.clear()
|
|
204
215
|
this.allSockets.clear()
|
|
205
216
|
}
|
|
206
217
|
|
|
@@ -222,7 +233,58 @@ export class AgentHost {
|
|
|
222
233
|
case 'agent:start-session':
|
|
223
234
|
return this.doStartSession(msg.input ?? {})
|
|
224
235
|
case 'agent:listen-inspect':
|
|
225
|
-
return this.listenForInspect(
|
|
236
|
+
return this.listenForInspect(
|
|
237
|
+
ws,
|
|
238
|
+
this.requireSimId(msg, type),
|
|
239
|
+
readCanvasAgentId(msg.recipientId),
|
|
240
|
+
)
|
|
241
|
+
case 'agent:cancel-listen-inspect': {
|
|
242
|
+
const simId = this.requireSimId(msg, type)
|
|
243
|
+
const listeners = this.inspectListeners.get(simId) ?? []
|
|
244
|
+
const index = listeners.findIndex((listener) => listener.socket === ws)
|
|
245
|
+
if (index < 0) return false
|
|
246
|
+
const [listener] = listeners.splice(index, 1)
|
|
247
|
+
if (!listeners.length) this.inspectListeners.delete(simId)
|
|
248
|
+
listener?.reject(new AgentSessionError('CANCELED', 'inspect listener canceled'))
|
|
249
|
+
return true
|
|
250
|
+
}
|
|
251
|
+
case 'agent:take-inspect-message': {
|
|
252
|
+
const recipientId = readCanvasAgentId(msg.recipientId)
|
|
253
|
+
return recipientId
|
|
254
|
+
? this.takeInspectMessage(this.requireSimId(msg, type), recipientId, true)
|
|
255
|
+
: null
|
|
256
|
+
}
|
|
257
|
+
case 'agent:send-canvas-note': {
|
|
258
|
+
const simId = this.requireSimId(msg, type)
|
|
259
|
+
const note = readCanvasAgentNote(msg.note)
|
|
260
|
+
if (!note) throw new AgentSessionError('INVALID_NOTE', 'invalid canvas note')
|
|
261
|
+
if (
|
|
262
|
+
this.inspectQueue(simId).filter((message) => message.recipientId).length >=
|
|
263
|
+
AGENT_NOTE_QUEUE_LIMIT
|
|
264
|
+
) {
|
|
265
|
+
throw new AgentSessionError(
|
|
266
|
+
'INBOX_FULL',
|
|
267
|
+
'the simulator has too many pending notes',
|
|
268
|
+
)
|
|
269
|
+
}
|
|
270
|
+
const message = createCanvasAgentInspectMessage(simId, note)
|
|
271
|
+
this.enqueueInspectMessage(message)
|
|
272
|
+
return { id: message.id }
|
|
273
|
+
}
|
|
274
|
+
case 'agent:canvas-note-status': {
|
|
275
|
+
const simId = this.requireSimId(msg, type)
|
|
276
|
+
this.pruneTakenNotes()
|
|
277
|
+
const pending = this.inspectQueue(simId).some(
|
|
278
|
+
(message) => message.id === msg.messageId,
|
|
279
|
+
)
|
|
280
|
+
return {
|
|
281
|
+
status: pending
|
|
282
|
+
? 'pending'
|
|
283
|
+
: this.takenNotes.get(msg.messageId)?.simId === simId
|
|
284
|
+
? 'taken'
|
|
285
|
+
: 'missing',
|
|
286
|
+
}
|
|
287
|
+
}
|
|
226
288
|
case 'agent:get-inspect-listener-status': {
|
|
227
289
|
const simId = this.requireSimId(msg, type)
|
|
228
290
|
return { simId, listening: (this.inspectListeners.get(simId)?.length ?? 0) > 0 }
|
|
@@ -274,20 +336,58 @@ export class AgentHost {
|
|
|
274
336
|
private listenForInspect(
|
|
275
337
|
socket: WebSocket,
|
|
276
338
|
simId: string,
|
|
339
|
+
recipientId?: string,
|
|
277
340
|
): Promise<AgentInspectMessage> {
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
if (queued && queue) {
|
|
281
|
-
if (queue.length === 0) this.inspectQueues.delete(simId)
|
|
282
|
-
return Promise.resolve(queued)
|
|
283
|
-
}
|
|
341
|
+
const queued = this.takeInspectMessage(simId, recipientId, false)
|
|
342
|
+
if (queued) return Promise.resolve(queued)
|
|
284
343
|
return new Promise((resolve, reject) => {
|
|
285
344
|
const listeners = this.inspectListeners.get(simId) ?? []
|
|
286
|
-
listeners.push({ socket, resolve, reject })
|
|
345
|
+
listeners.push({ socket, recipientId, resolve, reject })
|
|
287
346
|
this.inspectListeners.set(simId, listeners)
|
|
288
347
|
})
|
|
289
348
|
}
|
|
290
349
|
|
|
350
|
+
private pruneTakenNotes() {
|
|
351
|
+
const now = Date.now()
|
|
352
|
+
for (const [id, receipt] of this.takenNotes) {
|
|
353
|
+
if (receipt.expiresAt <= now) this.takenNotes.delete(id)
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
private markInspectMessageTaken(message: AgentInspectMessage) {
|
|
358
|
+
if (!message.recipientId) return
|
|
359
|
+
this.pruneTakenNotes()
|
|
360
|
+
this.takenNotes.set(message.id, {
|
|
361
|
+
simId: message.simId,
|
|
362
|
+
expiresAt: Date.now() + AGENT_NOTE_TTL_MS,
|
|
363
|
+
})
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
private inspectQueue(simId: string): AgentInspectMessage[] {
|
|
367
|
+
const queue = this.inspectQueues.get(simId)
|
|
368
|
+
if (!queue) return []
|
|
369
|
+
const cutoff = Date.now() - AGENT_NOTE_TTL_MS
|
|
370
|
+
const pending = queue.filter(
|
|
371
|
+
(message) => !message.recipientId || Date.parse(message.createdAt) > cutoff,
|
|
372
|
+
)
|
|
373
|
+
if (pending.length) this.inspectQueues.set(simId, pending)
|
|
374
|
+
else this.inspectQueues.delete(simId)
|
|
375
|
+
return pending
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
private takeInspectMessage(simId: string, recipientId?: string, notesOnly = false) {
|
|
379
|
+
const queue = this.inspectQueue(simId)
|
|
380
|
+
const index = queue.findIndex((message) =>
|
|
381
|
+
message.recipientId ? message.recipientId === recipientId : !notesOnly,
|
|
382
|
+
)
|
|
383
|
+
if (index < 0) return null
|
|
384
|
+
const [message] = queue.splice(index, 1)
|
|
385
|
+
if (!queue.length) this.inspectQueues.delete(simId)
|
|
386
|
+
if (!message) return null
|
|
387
|
+
this.markInspectMessageTaken(message)
|
|
388
|
+
return message
|
|
389
|
+
}
|
|
390
|
+
|
|
291
391
|
private sendInspectMessage(
|
|
292
392
|
simId: string,
|
|
293
393
|
prompt: AgentPromptEnvelope,
|
|
@@ -301,17 +401,27 @@ export class AgentHost {
|
|
|
301
401
|
createdAt: new Date().toISOString(),
|
|
302
402
|
prompt,
|
|
303
403
|
}
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const
|
|
404
|
+
const queued = this.enqueueInspectMessage(message)
|
|
405
|
+
return { ok: true, queued, messageId: message.id }
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
private enqueueInspectMessage(message: AgentInspectMessage): boolean {
|
|
409
|
+
const { simId, recipientId } = message
|
|
410
|
+
const listeners = this.inspectListeners.get(simId) ?? []
|
|
411
|
+
const index = listeners.findIndex(
|
|
412
|
+
(listener) => !recipientId || listener.recipientId === recipientId,
|
|
413
|
+
)
|
|
414
|
+
if (index >= 0) {
|
|
415
|
+
const [listener] = listeners.splice(index, 1)
|
|
416
|
+
if (!listeners.length) this.inspectListeners.delete(simId)
|
|
417
|
+
this.markInspectMessageTaken(message)
|
|
418
|
+
listener?.resolve(message)
|
|
419
|
+
return false
|
|
420
|
+
}
|
|
421
|
+
const queue = this.inspectQueue(simId)
|
|
312
422
|
queue.push(message)
|
|
313
423
|
this.inspectQueues.set(simId, queue)
|
|
314
|
-
return
|
|
424
|
+
return true
|
|
315
425
|
}
|
|
316
426
|
|
|
317
427
|
private async doStartSession(input: {
|
package/src/swift-compile.ts
CHANGED
|
@@ -63,6 +63,8 @@ import {
|
|
|
63
63
|
import { swiftObjcRootObjects } from './swift-link-roots'
|
|
64
64
|
import {
|
|
65
65
|
SWIFT_OBJC_INTEROP_FLAGS,
|
|
66
|
+
compactSwiftClangDefines,
|
|
67
|
+
compactSwiftClangOverlays,
|
|
66
68
|
swiftClangImporterFlags,
|
|
67
69
|
swiftObjCModuleMap,
|
|
68
70
|
swiftSubmoduleImports,
|
|
@@ -145,7 +147,7 @@ import {
|
|
|
145
147
|
} from './swiftRuntimeProductContract'
|
|
146
148
|
import { KEEP_WASM_NAMES, lowerWasm, WASM_LOWER_IDENTITY } from './wasm-optimize'
|
|
147
149
|
import { writeBuildFile } from './write-build-file'
|
|
148
|
-
import { writeXcodeHeaderSearch } from './xcode-header-search'
|
|
150
|
+
import { coalescibleHeaderOverlays, writeXcodeHeaderSearch } from './xcode-header-search'
|
|
149
151
|
import type { SwiftImageUpload } from './swift-submit'
|
|
150
152
|
import type { SwiftResourceBundle } from './swiftContract'
|
|
151
153
|
|
|
@@ -1611,6 +1613,15 @@ export function swiftTargetDependencies(
|
|
|
1611
1613
|
),
|
|
1612
1614
|
)
|
|
1613
1615
|
const names = new Set([...frameworks, ...targets.map((target) => target.name)])
|
|
1616
|
+
const entriesByPrefix = new Map<string, [string, string][]>(
|
|
1617
|
+
targets.map(({ path }) => [path === '.' ? '' : `${path}/`, []]),
|
|
1618
|
+
)
|
|
1619
|
+
for (const entry of Object.entries(files)) {
|
|
1620
|
+
const [file] = entry
|
|
1621
|
+
entriesByPrefix.get('')?.push(entry)
|
|
1622
|
+
for (let end = file.indexOf('/'); end !== -1; end = file.indexOf('/', end + 1))
|
|
1623
|
+
entriesByPrefix.get(file.slice(0, end + 1))?.push(entry)
|
|
1624
|
+
}
|
|
1614
1625
|
const siblings = new Map<string, string[]>()
|
|
1615
1626
|
for (const target of targets) {
|
|
1616
1627
|
const prefix = target.path === '.' ? '' : `${target.path}/`
|
|
@@ -1637,8 +1648,18 @@ export function swiftTargetDependencies(
|
|
|
1637
1648
|
: [],
|
|
1638
1649
|
),
|
|
1639
1650
|
)
|
|
1640
|
-
|
|
1641
|
-
|
|
1651
|
+
const nested =
|
|
1652
|
+
target.sources === undefined
|
|
1653
|
+
? targets.flatMap((candidate) =>
|
|
1654
|
+
candidate.name !== target.name &&
|
|
1655
|
+
candidate.path !== '.' &&
|
|
1656
|
+
candidate.path.startsWith(prefix)
|
|
1657
|
+
? [`${candidate.path}/`]
|
|
1658
|
+
: [],
|
|
1659
|
+
)
|
|
1660
|
+
: []
|
|
1661
|
+
for (const [file, contents] of entriesByPrefix.get(prefix) ?? []) {
|
|
1662
|
+
if (file === 'Package.swift') continue
|
|
1642
1663
|
const relative = file.slice(prefix.length)
|
|
1643
1664
|
if (
|
|
1644
1665
|
target.sources !== undefined &&
|
|
@@ -1654,17 +1675,7 @@ export function swiftTargetDependencies(
|
|
|
1654
1675
|
)
|
|
1655
1676
|
)
|
|
1656
1677
|
continue
|
|
1657
|
-
if (
|
|
1658
|
-
target.sources === undefined &&
|
|
1659
|
-
targets.some(
|
|
1660
|
-
(candidate) =>
|
|
1661
|
-
candidate.name !== target.name &&
|
|
1662
|
-
candidate.path !== '.' &&
|
|
1663
|
-
candidate.path.startsWith(prefix) &&
|
|
1664
|
-
file.startsWith(`${candidate.path}/`),
|
|
1665
|
-
)
|
|
1666
|
-
)
|
|
1667
|
-
continue
|
|
1678
|
+
if (nested.some((path) => file.startsWith(path))) continue
|
|
1668
1679
|
const imports = file.endsWith('.swift')
|
|
1669
1680
|
? swiftImportNames(contents)
|
|
1670
1681
|
: SWIFT_NATIVE_SOURCE_EXTENSIONS.some((extension) => file.endsWith(extension))
|
|
@@ -1773,7 +1784,7 @@ const darwinRecordsRegion = (quoted: readonly string[]): string[] =>
|
|
|
1773
1784
|
const REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n'
|
|
1774
1785
|
|
|
1775
1786
|
/** bump with any change to the emitted multi-target manifest text. */
|
|
1776
|
-
export const MULTI_MANIFEST_VERSION =
|
|
1787
|
+
export const MULTI_MANIFEST_VERSION = 71
|
|
1777
1788
|
const SWIFT_HEADER_PRODUCTS_TARGET = 'PeachHeaderProducts'
|
|
1778
1789
|
|
|
1779
1790
|
// build-cli replaces this in every bundle; source runs read the files directly.
|
|
@@ -1978,6 +1989,7 @@ export function emitSwiftPackageManifest(args: {
|
|
|
1978
1989
|
/** the objective-c runtime and sdk flags every original native unit compiles with. */
|
|
1979
1990
|
nativeFlags?: Map<string, string[]>
|
|
1980
1991
|
nativeImportFlags?: Map<string, string[]>
|
|
1992
|
+
coalescibleOverlays?: ReadonlySet<string>
|
|
1981
1993
|
nativeHeaderFlags?: string[]
|
|
1982
1994
|
nativeSwiftHeaderMaps?: ReadonlyMap<string, string>
|
|
1983
1995
|
nativeHeaderDeclarations?: Readonly<Record<string, readonly string[]>>
|
|
@@ -2166,7 +2178,11 @@ export function emitSwiftPackageManifest(args: {
|
|
|
2166
2178
|
!mapsPackageModule(flag) &&
|
|
2167
2179
|
!(flag === '-Xcc' && mapsPackageModule(all[index + 1] ?? '')),
|
|
2168
2180
|
)
|
|
2169
|
-
const
|
|
2181
|
+
const macros = compactSwiftClangDefines(flags)
|
|
2182
|
+
const compact = args.coalescibleOverlays
|
|
2183
|
+
? compactSwiftClangOverlays(macros, args.coalescibleOverlays)
|
|
2184
|
+
: macros
|
|
2185
|
+
const content = compact.map((flag) => JSON.stringify(flag)).join('\n') + '\n'
|
|
2170
2186
|
const digest = createHash('sha256').update(content).digest('hex')
|
|
2171
2187
|
const file = path.join(args.root, '.peach-swift-arguments', `${digest}.rsp`)
|
|
2172
2188
|
args.files.set(file, content)
|
|
@@ -2332,7 +2348,7 @@ export function emitSwiftPackageManifest(args: {
|
|
|
2332
2348
|
[...(args.native?.values() ?? [])].some((value) =>
|
|
2333
2349
|
value.late?.producers.includes(target.name),
|
|
2334
2350
|
))
|
|
2335
|
-
? `, "-emit-objc-header-path", ${JSON.stringify(path.join(args.headerDirectory, `${target.name}-Swift
|
|
2351
|
+
? `, "-emit-objc-header-path", ${JSON.stringify(path.join(args.headerDirectory, `${target.name}-Swift.original.h`))}`
|
|
2336
2352
|
: ''
|
|
2337
2353
|
const clangMode = target.cxxInterop ? '' : ', "-Xcc", "-fno-cxx-modules"'
|
|
2338
2354
|
const deployment = `, "-Xfrontend", "-peach-ios-deployment-target", "-Xfrontend", ${JSON.stringify(target.iosDeploymentTarget ?? SWIFTPM_DEFAULT_IOS_DEPLOYMENT_TARGET)}`
|
|
@@ -5781,6 +5797,9 @@ export function writeSwiftProject(
|
|
|
5781
5797
|
}
|
|
5782
5798
|
|
|
5783
5799
|
const nativeFlags = native.size > 0 ? new Map<string, string[]>() : undefined
|
|
5800
|
+
const generatedOverlays = new Set(
|
|
5801
|
+
headerSearch.files.filter((file) => file.endsWith('.yaml')),
|
|
5802
|
+
)
|
|
5784
5803
|
if (nativeFlags) {
|
|
5785
5804
|
const toolchainBin = nativeToolchain()
|
|
5786
5805
|
const headers = path.join(swiftSdkPaths(moduleRoot, toolchainBin).sysroot, 'darwin')
|
|
@@ -5803,8 +5822,11 @@ export function writeSwiftProject(
|
|
|
5803
5822
|
': missing or unsupported declared iOS deployment target ' +
|
|
5804
5823
|
JSON.stringify(version),
|
|
5805
5824
|
)
|
|
5825
|
+
const sdkIntake = objcSdkIntakeFlags(headers, toolchainBin, minimum)
|
|
5826
|
+
const sdkOverlay = sdkIntake.indexOf('-ivfsoverlay')
|
|
5827
|
+
if (sdkOverlay >= 0) generatedOverlays.add(sdkIntake[sdkOverlay + 1]!)
|
|
5806
5828
|
const intake = [
|
|
5807
|
-
...
|
|
5829
|
+
...sdkIntake,
|
|
5808
5830
|
'-ivfsoverlay',
|
|
5809
5831
|
headerSearch.files[0]!,
|
|
5810
5832
|
'-I',
|
|
@@ -6028,6 +6050,9 @@ export function writeSwiftProject(
|
|
|
6028
6050
|
sourceSwiftTargets: swiftTargets,
|
|
6029
6051
|
nativeFlags,
|
|
6030
6052
|
nativeImportFlags,
|
|
6053
|
+
coalescibleOverlays: nativeFlags
|
|
6054
|
+
? coalescibleHeaderOverlays(generatedOverlays)
|
|
6055
|
+
: undefined,
|
|
6031
6056
|
nativeHeaderFlags,
|
|
6032
6057
|
nativeSwiftHeaderMaps,
|
|
6033
6058
|
nativeHeaderDeclarations,
|
|
@@ -7712,6 +7737,9 @@ function compileSwiftProjectOnce(
|
|
|
7712
7737
|
{ file: string; header: string; module: boolean } | null
|
|
7713
7738
|
>()
|
|
7714
7739
|
const nativeDeclarations = new Map<string, Set<string>>()
|
|
7740
|
+
const nativeHeaders = Object.entries(input.files)
|
|
7741
|
+
.filter(([name]) => name.endsWith('.h') && !name.endsWith('-Swift.h'))
|
|
7742
|
+
.map(([, source]) => source)
|
|
7715
7743
|
for (const [file, contents] of Object.entries(input.files)) {
|
|
7716
7744
|
if (!file.endsWith('.modulemap')) continue
|
|
7717
7745
|
const name = moduleMapName(contents)
|
|
@@ -7812,64 +7840,97 @@ function compileSwiftProjectOnce(
|
|
|
7812
7840
|
)
|
|
7813
7841
|
return value
|
|
7814
7842
|
}
|
|
7815
|
-
|
|
7843
|
+
const compileApp = async () => {
|
|
7816
7844
|
// clang consumes the real emitted headers after swift finishes.
|
|
7817
7845
|
// swiftpm's transitive swift module maps are not C declarations:
|
|
7818
7846
|
// importing them would shadow SDK modules such as ObjectiveC.
|
|
7819
|
-
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
[
|
|
7823
|
-
|
|
7824
|
-
|
|
7825
|
-
|
|
7847
|
+
const stages = [
|
|
7848
|
+
...preparation.headerBuilds,
|
|
7849
|
+
...(preparation.nativeProductTarget
|
|
7850
|
+
? [{ target: preparation.nativeProductTarget, producers: [] }]
|
|
7851
|
+
: []),
|
|
7852
|
+
]
|
|
7853
|
+
const checkpoints = path.join(root, '.build', 'peach-product-checkpoints')
|
|
7854
|
+
const recipe = createHash('sha256')
|
|
7855
|
+
.update(hash)
|
|
7856
|
+
.update(readFileSync(path.join(root, 'Package.swift')))
|
|
7857
|
+
.update(JSON.stringify(buildArgs))
|
|
7858
|
+
.digest('hex')
|
|
7859
|
+
for (const { target, producers } of stages) {
|
|
7860
|
+
const receipt = path.join(
|
|
7861
|
+
checkpoints,
|
|
7862
|
+
createHash('sha256').update(target).digest('hex'),
|
|
7826
7863
|
)
|
|
7827
|
-
|
|
7828
|
-
const
|
|
7864
|
+
const headers = producers.map((producer) => {
|
|
7865
|
+
const stem = path.join(
|
|
7829
7866
|
root,
|
|
7830
7867
|
'.build',
|
|
7831
7868
|
'peach-cxx-headers',
|
|
7832
|
-
`${producer}-Swift
|
|
7869
|
+
`${producer}-Swift`,
|
|
7833
7870
|
)
|
|
7834
|
-
|
|
7835
|
-
|
|
7836
|
-
:
|
|
7837
|
-
|
|
7838
|
-
|
|
7839
|
-
|
|
7840
|
-
|
|
7841
|
-
|
|
7842
|
-
|
|
7843
|
-
|
|
7844
|
-
|
|
7845
|
-
|
|
7846
|
-
...(preparation.nativeHeaderDeclarations[producer] ?? []),
|
|
7847
|
-
...nativelyDeclaredFunctions(
|
|
7848
|
-
generated,
|
|
7849
|
-
Object.entries(input.files)
|
|
7850
|
-
.filter(
|
|
7851
|
-
([name]) =>
|
|
7852
|
-
name.endsWith('.h') && !name.endsWith('-Swift.h'),
|
|
7853
|
-
)
|
|
7854
|
-
.map(([, source]) => source),
|
|
7855
|
-
),
|
|
7856
|
-
]),
|
|
7857
|
-
`#import <${producer}/${producer}.h>`,
|
|
7858
|
-
),
|
|
7871
|
+
return {
|
|
7872
|
+
producer,
|
|
7873
|
+
original: `${stem}.original.h`,
|
|
7874
|
+
emitted: `${stem}.h`,
|
|
7875
|
+
}
|
|
7876
|
+
})
|
|
7877
|
+
const fingerprint = (): string | undefined => {
|
|
7878
|
+
const digest = createHash('sha256').update(recipe)
|
|
7879
|
+
for (const { emitted } of headers) {
|
|
7880
|
+
if (!existsSync(emitted)) return
|
|
7881
|
+
digest.update(
|
|
7882
|
+
createHash('sha256').update(readFileSync(emitted)).digest(),
|
|
7859
7883
|
)
|
|
7860
7884
|
}
|
|
7885
|
+
return digest.digest('hex')
|
|
7861
7886
|
}
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
|
|
7865
|
-
|
|
7887
|
+
if (
|
|
7888
|
+
!options.project &&
|
|
7889
|
+
existsSync(receipt) &&
|
|
7890
|
+
readFileSync(receipt, 'utf8') === fingerprint()
|
|
7891
|
+
)
|
|
7892
|
+
continue
|
|
7893
|
+
if (!options.project) rmSync(receipt, { force: true })
|
|
7894
|
+
// swiftpm doesn't track custom objc header paths as outputs.
|
|
7895
|
+
for (const { producer, original } of headers)
|
|
7896
|
+
if (!existsSync(original))
|
|
7897
|
+
rmSync(
|
|
7898
|
+
path.join(
|
|
7899
|
+
root,
|
|
7900
|
+
'.build',
|
|
7901
|
+
WASM_TRIPLE,
|
|
7902
|
+
'release',
|
|
7903
|
+
'Modules',
|
|
7904
|
+
`${swiftTargetModuleName(producer)}.swiftmodule`,
|
|
7905
|
+
),
|
|
7906
|
+
{ force: true },
|
|
7907
|
+
)
|
|
7866
7908
|
await runCompiler(
|
|
7867
7909
|
swift,
|
|
7868
|
-
[...buildArgs, '--target',
|
|
7910
|
+
[...buildArgs, '--target', target],
|
|
7869
7911
|
appOptions,
|
|
7870
7912
|
SWIFTPM_PROGRESS,
|
|
7871
7913
|
SWIFTPM_NOISE,
|
|
7872
7914
|
)
|
|
7915
|
+
for (const { producer, original, emitted } of headers) {
|
|
7916
|
+
const generated = clangInterfaceHeader(readFileSync(original, 'utf8'))
|
|
7917
|
+
writeBuildFile(
|
|
7918
|
+
emitted,
|
|
7919
|
+
withoutSwiftDeclarations(
|
|
7920
|
+
swiftHeaderWithSuperclassImports(generated, frameworkInterface),
|
|
7921
|
+
new Set([
|
|
7922
|
+
...(preparation.nativeHeaderDeclarations[producer] ?? []),
|
|
7923
|
+
...nativelyDeclaredFunctions(generated, nativeHeaders),
|
|
7924
|
+
]),
|
|
7925
|
+
`#import <${producer}/${producer}.h>`,
|
|
7926
|
+
),
|
|
7927
|
+
)
|
|
7928
|
+
}
|
|
7929
|
+
if (!options.project) {
|
|
7930
|
+
mkdirSync(checkpoints, { recursive: true })
|
|
7931
|
+
writeFileSync(`${receipt}.partial`, fingerprint()!)
|
|
7932
|
+
renameSync(`${receipt}.partial`, receipt)
|
|
7933
|
+
}
|
|
7873
7934
|
}
|
|
7874
7935
|
// always let swiftpm check the full graph, including missing outputs.
|
|
7875
7936
|
await runCompiler(
|
|
@@ -7879,6 +7940,9 @@ function compileSwiftProjectOnce(
|
|
|
7879
7940
|
SWIFTPM_PROGRESS,
|
|
7880
7941
|
SWIFTPM_NOISE,
|
|
7881
7942
|
)
|
|
7943
|
+
}
|
|
7944
|
+
try {
|
|
7945
|
+
await compileApp()
|
|
7882
7946
|
} catch (error) {
|
|
7883
7947
|
const output = outputOf(error)
|
|
7884
7948
|
const moduleCache = path.join(
|
|
@@ -7894,13 +7958,7 @@ function compileSwiftProjectOnce(
|
|
|
7894
7958
|
) {
|
|
7895
7959
|
rmSync(moduleCache, { recursive: true, force: true })
|
|
7896
7960
|
try {
|
|
7897
|
-
await
|
|
7898
|
-
swift,
|
|
7899
|
-
buildArgs,
|
|
7900
|
-
appOptions,
|
|
7901
|
-
SWIFTPM_PROGRESS,
|
|
7902
|
-
SWIFTPM_NOISE,
|
|
7903
|
-
)
|
|
7961
|
+
await compileApp()
|
|
7904
7962
|
} catch (retryError) {
|
|
7905
7963
|
throw new Error(
|
|
7906
7964
|
[
|
package/src/swift-host.ts
CHANGED
|
@@ -678,7 +678,8 @@ async function swiftPackages(
|
|
|
678
678
|
// compiling, or a placeholder package's swift target: each stands in from
|
|
679
679
|
// its public surface.
|
|
680
680
|
const standinArtifact = (binary: SwiftPackageBinary) =>
|
|
681
|
-
binary.
|
|
681
|
+
!binary.rustCrate &&
|
|
682
|
+
(binary.publicHeaders === undefined || binary.unloweredSources !== undefined)
|
|
682
683
|
const artifacts = reached.filter(standinArtifact)
|
|
683
684
|
if (entry.moduleRoot && entry.provided && artifacts.length > 0) {
|
|
684
685
|
const { provided } = entry
|