peachsim 0.1.2476 → 0.1.2478
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 +14 -0
- package/cli/command-agent.ts +2 -0
- package/cli/commands/control.ts +3 -2
- package/cli/commands/stream.ts +28 -8
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +2 -2
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +5 -5
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +3 -3
- package/dist-lib/bundle-channel.cjs +5382 -5067
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +3 -3
- package/dist-lib/cloud-contract.cjs +2 -1
- package/dist-lib/cloud-contract.mjs +3 -3
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +2 -2
- package/dist-lib/cloud.cjs +2 -1
- package/dist-lib/cloud.mjs +7 -7
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/config.mjs +5 -5
- package/dist-lib/detox/index.cjs +5 -2
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/esm-chunks/{acorn-XUDP7FUU.mjs → acorn-FQLOTPEI.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-5J6SH5PL.mjs → chunk-25VCIHSN.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-MS423IWH.mjs → chunk-355SS4SH.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-YA55AHKP.mjs → chunk-3IZX74HE.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-E254ZLN5.mjs → chunk-CIMYKM6N.mjs} +10 -8
- package/dist-lib/esm-chunks/{chunk-YKTS6JGV.mjs → chunk-FFCS7MFJ.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-YZGIW7I6.mjs → chunk-GGYYAJR7.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-T5HVFQ3M.mjs → chunk-GY7RVEFV.mjs} +4 -4
- package/dist-lib/esm-chunks/{chunk-XVVVMJ7H.mjs → chunk-ICJOTWER.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-FG6NDDVL.mjs → chunk-JUPWMWSX.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-VXDXNH7I.mjs → chunk-LCAQS5UW.mjs} +2 -2
- package/dist-lib/esm-chunks/{chunk-BIODQMYB.mjs → chunk-MLVSAVNL.mjs} +2 -1
- package/dist-lib/esm-chunks/{chunk-AUTNUR7W.mjs → chunk-MQM5KR5X.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-DFHVJLBP.mjs → chunk-OVBWXPD7.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-ACRNH6CJ.mjs → chunk-Q47VNBNR.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-7TOYW4KW.mjs → chunk-RSSHYN7S.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-DRUSXLT2.mjs → chunk-TUJL2AP2.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-XUNG5UYW.mjs → chunk-UETOLHI7.mjs} +2059 -3500
- package/dist-lib/esm-chunks/{chunk-G7ZQ4MZU.mjs → chunk-VAQFAFOC.mjs} +37 -7
- package/dist-lib/esm-chunks/{chunk-GR4GWWVO.mjs → chunk-VORKZFQK.mjs} +1 -1
- package/dist-lib/esm-chunks/chunk-XEZ4K3TZ.mjs +1475 -0
- package/dist-lib/esm-chunks/{chunk-VW34BZCP.mjs → chunk-XSSZZ2HY.mjs} +1 -1
- package/dist-lib/esm-chunks/{metro-layout-parser-GQPBXOFJ.mjs → metro-layout-parser-MRCK7YD5.mjs} +3 -3
- package/dist-lib/esm-chunks/{swift-package-prebuilt-IMNLLYSA.mjs → swift-package-prebuilt-LYR2P26A.mjs} +10 -9
- package/dist-lib/esm-chunks/{swift-sdk-app-module-LZE3N3OS.mjs → swift-sdk-app-module-CXY5TKBA.mjs} +15 -13
- package/dist-lib/esm-chunks/{swift-sdk-image-E2QZGC53.mjs → swift-sdk-image-6L3AMATS.mjs} +13 -12
- package/dist-lib/esm-chunks/swift-sdk-image-producer-C4TNZ4UM.mjs +294 -0
- package/dist-lib/expo-swift-bundle.cjs +4362 -4047
- package/dist-lib/expo-swift-metadata.cjs +1 -1
- package/dist-lib/expo-swift-metadata.mjs +7 -7
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +5284 -4966
- package/dist-lib/host/fetch-proxy-handler.cjs +5 -5
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +4 -1
- package/dist-lib/kotlin-host.cjs +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +3 -3
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +3 -3
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +4 -4
- package/dist-lib/native-app-identity-project.cjs +2 -2
- package/dist-lib/native-app-identity-project.mjs +17 -15
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +6 -6
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +3 -3
- package/dist-lib/pdfium-raster.cjs +1 -1
- package/dist-lib/pdfium-raster.mjs +2 -2
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +3 -3
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +92 -81
- package/dist-lib/public-origins-lib.json +74 -69
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +2 -2
- package/dist-lib/reap-browser.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +1 -1
- package/dist-lib/sdk.mjs +7 -7
- package/dist-lib/skills.cjs +5903 -5569
- package/dist-lib/swift-compile.cjs +1280 -965
- package/dist-lib/swift-compile.mjs +10 -9
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +3 -3
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +5 -5
- package/dist-lib/swift-svg-raster.cjs +1 -1
- package/dist-lib/swift-svg-raster.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
- package/dist-lib/vendor/@xmldom/xmldom.cjs +1 -1
- package/dist-lib/vendor/acorn.cjs +1 -1
- package/dist-lib/vendor/bplist-parser.cjs +1 -1
- package/dist-lib/vendor/ignore.cjs +1 -1
- package/dist-lib/vendor/magic-string.cjs +1 -1
- package/dist-lib/vendor/plist.cjs +1 -1
- package/dist-lib/vendor/smol-toml.cjs +1 -1
- package/dist-lib/vendor/stream-json.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
- package/dist-lib/vendor/sucrase.cjs +1 -1
- package/dist-lib/vendor/terser.cjs +1 -1
- package/dist-lib/vendor/valibot.cjs +1 -1
- package/dist-lib/vendor/ws.cjs +1 -1
- package/dist-lib/vendor/zod.cjs +1 -1
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +3 -3
- package/dist-types/packages/peach-engine/src/webview-automation-host.d.ts +4 -2
- package/dist-types/packages/peach-globals/src/compositorBridgeContract.d.ts +1 -0
- package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
- package/dist-types/packages/peach-globals/src/replayBridgeContract.d.ts +3 -2
- package/package.json +1 -1
- package/runtime-companion.json +1 -1
- package/src/bridge-contract.ts +1 -0
- package/src/cloud-contract.ts +1 -0
- package/src/host/bridge-host.ts +7 -1
- package/src/swift-compile.ts +1 -0
- package/src/swift-sdk-image-producer.ts +336 -0
- package/src/swift-sdk-image.ts +37 -1
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { execFile, execFileSync } from 'node:child_process'
|
|
2
|
+
import { randomUUID } from 'node:crypto'
|
|
3
|
+
import {
|
|
4
|
+
existsSync,
|
|
5
|
+
mkdirSync,
|
|
6
|
+
readFileSync,
|
|
7
|
+
renameSync,
|
|
8
|
+
rmSync,
|
|
9
|
+
writeFileSync,
|
|
10
|
+
} from 'node:fs'
|
|
11
|
+
import path from 'node:path'
|
|
12
|
+
import { setTimeout as sleep } from 'node:timers/promises'
|
|
13
|
+
import { promisify } from 'node:util'
|
|
14
|
+
import { windowAdmission } from './admitted-mac-build'
|
|
15
|
+
import { isRecord } from './is-record'
|
|
16
|
+
import { withSwiftRootLock } from './swift-root-lock'
|
|
17
|
+
import { swiftCacheDir } from './swift-toolchain'
|
|
18
|
+
|
|
19
|
+
const run = promisify(execFile)
|
|
20
|
+
const environmentNames = [
|
|
21
|
+
'CONTRAST_BUILDERS_ROOT',
|
|
22
|
+
'PEACH_HOME',
|
|
23
|
+
'PEACH_SWIFT_SDKS_PATH',
|
|
24
|
+
'CONTRAST_SWIFT_TOOLCHAINS',
|
|
25
|
+
'PEACH_SWIFT_PRIVATE_COMPILER_RELEASE',
|
|
26
|
+
'PEACH_SWIFT_NAMES',
|
|
27
|
+
] as const
|
|
28
|
+
|
|
29
|
+
interface Request {
|
|
30
|
+
key: string
|
|
31
|
+
launchId: string
|
|
32
|
+
created: number
|
|
33
|
+
scopedLookups: boolean
|
|
34
|
+
imports: string[]
|
|
35
|
+
cache: string
|
|
36
|
+
environment: Record<string, string>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function readRequest(file: string): Request {
|
|
40
|
+
const value: unknown = JSON.parse(readFileSync(file, 'utf8'))
|
|
41
|
+
if (
|
|
42
|
+
!isRecord(value) ||
|
|
43
|
+
typeof value.key !== 'string' ||
|
|
44
|
+
!/^[a-f0-9]{32}$/.test(value.key) ||
|
|
45
|
+
typeof value.launchId !== 'string' ||
|
|
46
|
+
typeof value.created !== 'number' ||
|
|
47
|
+
typeof value.scopedLookups !== 'boolean' ||
|
|
48
|
+
!Array.isArray(value.imports) ||
|
|
49
|
+
value.imports.some((name) => typeof name !== 'string') ||
|
|
50
|
+
typeof value.cache !== 'string' ||
|
|
51
|
+
!path.isAbsolute(value.cache) ||
|
|
52
|
+
!isRecord(value.environment) ||
|
|
53
|
+
Object.entries(value.environment).some(
|
|
54
|
+
([name, item]) =>
|
|
55
|
+
!environmentNames.some((allowed) => allowed === name) || typeof item !== 'string',
|
|
56
|
+
)
|
|
57
|
+
)
|
|
58
|
+
throw new Error(`invalid Swift SDK producer request: ${file}`)
|
|
59
|
+
const environment: Record<string, string> = {}
|
|
60
|
+
for (const name of environmentNames) {
|
|
61
|
+
const item = value.environment[name]
|
|
62
|
+
if (typeof item === 'string') environment[name] = item
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
key: value.key,
|
|
66
|
+
launchId: value.launchId,
|
|
67
|
+
created: value.created,
|
|
68
|
+
scopedLookups: value.scopedLookups,
|
|
69
|
+
imports: value.imports,
|
|
70
|
+
cache: value.cache,
|
|
71
|
+
environment,
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function swiftSdkProducerRequest(file: string): Request {
|
|
76
|
+
return readRequest(file)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function applySwiftSdkProducerEnvironment(environment: Record<string, string>) {
|
|
80
|
+
for (const name of environmentNames) {
|
|
81
|
+
const value = environment[name]
|
|
82
|
+
if (value === undefined) delete process.env[name]
|
|
83
|
+
else process.env[name] = value
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function writeSwiftSdkProducerResult(
|
|
88
|
+
file: string,
|
|
89
|
+
launchId: string,
|
|
90
|
+
error?: string,
|
|
91
|
+
) {
|
|
92
|
+
const temporary = `${file}.${randomUUID()}`
|
|
93
|
+
writeFileSync(temporary, JSON.stringify({ launchId, error: error ?? null }))
|
|
94
|
+
renameSync(temporary, file)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const launcher = `set -eu
|
|
98
|
+
tm detach "$TM_SESSION" >/dev/null
|
|
99
|
+
printf '%s\\n' "$TM_SESSION" > "$1.tmp"
|
|
100
|
+
mv "$1.tmp" "$1"
|
|
101
|
+
shift
|
|
102
|
+
export GIT_ALTERNATE_OBJECT_DIRECTORIES="$2/objects"
|
|
103
|
+
set +e
|
|
104
|
+
env -u TM_WINDOW -u TM_WAIT_DEADLINE_MS -u TM_EXEC_OUTER_DEADLINE_MS -u REMOTE_BUILD_DEADLINE -u TM_EXEC_ADMITTED -u LINUX_BUILD_SCOPE -u TM_EXEC_CPU_CORES -u TM_EXEC_LINUX_MEMORY_MAX -u CONTRAST_HEAVY_ADMITTED -u CONTRAST_HEAVY_CPU_CORES tm exec --local --kind build-linux --cores "$1" --timeout 90m --param wait=true --param "source-snapshot=$2" --param "delivery-dir=$4" --param "serial-key=swift-sdk-$5" -- bun scripts/ops/produce-swift-sdk-image.ts "$3" </dev/null
|
|
105
|
+
status=$?
|
|
106
|
+
if bun -e 'try { if (JSON.parse(require("node:fs").readFileSync(process.argv[1], "utf8")).released !== true) process.exit(1) } catch { process.exit(1) }' "$4/cleanup.json"; then rm -rf "$2"; fi
|
|
107
|
+
exit "$status"
|
|
108
|
+
`
|
|
109
|
+
|
|
110
|
+
function retainSnapshotObjects(repo: string, capture: string): void {
|
|
111
|
+
const target = path.join(capture, 'objects')
|
|
112
|
+
const original = readFileSync(path.join(target, 'info/alternates'), 'utf8').trim()
|
|
113
|
+
const inherited = path.join(original, 'info/alternates')
|
|
114
|
+
const retainedAlternates = existsSync(inherited)
|
|
115
|
+
? readFileSync(inherited, 'utf8')
|
|
116
|
+
.split('\n')
|
|
117
|
+
.filter(Boolean)
|
|
118
|
+
.map((entry) => path.resolve(original, entry))
|
|
119
|
+
: []
|
|
120
|
+
const env: NodeJS.ProcessEnv = {
|
|
121
|
+
...process.env,
|
|
122
|
+
GIT_OBJECT_DIRECTORY: target,
|
|
123
|
+
GIT_NO_LAZY_FETCH: '1',
|
|
124
|
+
}
|
|
125
|
+
delete env.GIT_ALTERNATE_OBJECT_DIRECTORIES
|
|
126
|
+
const roots = ['source-commit', 'staged-tree', 'worktree-tree'].map((file) =>
|
|
127
|
+
readFileSync(path.join(capture, file), 'utf8').trim(),
|
|
128
|
+
)
|
|
129
|
+
const inventoryArgs = [
|
|
130
|
+
'-C',
|
|
131
|
+
repo,
|
|
132
|
+
'rev-list',
|
|
133
|
+
'--objects',
|
|
134
|
+
'--no-object-names',
|
|
135
|
+
'--missing=print',
|
|
136
|
+
'--no-walk',
|
|
137
|
+
...roots,
|
|
138
|
+
]
|
|
139
|
+
const inventory = execFileSync('git', inventoryArgs, {
|
|
140
|
+
encoding: 'utf8',
|
|
141
|
+
env,
|
|
142
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
143
|
+
})
|
|
144
|
+
if (inventory.split('\n').some((line) => line.startsWith('?')))
|
|
145
|
+
throw new Error('Swift SDK producer snapshot is missing source objects')
|
|
146
|
+
const history = execFileSync(
|
|
147
|
+
'git',
|
|
148
|
+
['-C', repo, 'rev-list', '--first-parent', roots[0]!],
|
|
149
|
+
{
|
|
150
|
+
encoding: 'utf8',
|
|
151
|
+
env,
|
|
152
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
153
|
+
},
|
|
154
|
+
)
|
|
155
|
+
mkdirSync(path.join(target, 'pack'), { recursive: true })
|
|
156
|
+
execFileSync('git', ['-C', repo, 'pack-objects', path.join(target, 'pack/source')], {
|
|
157
|
+
input: `${inventory}${history}`,
|
|
158
|
+
env,
|
|
159
|
+
stdio: ['pipe', 'ignore', 'inherit'],
|
|
160
|
+
})
|
|
161
|
+
rmSync(path.join(target, 'info/alternates'), { force: true })
|
|
162
|
+
const retained = execFileSync('git', inventoryArgs, {
|
|
163
|
+
encoding: 'utf8',
|
|
164
|
+
env,
|
|
165
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
166
|
+
})
|
|
167
|
+
if (retained.split('\n').some((line) => line.startsWith('?')))
|
|
168
|
+
throw new Error('Swift SDK producer could not retain its source objects')
|
|
169
|
+
if (retainedAlternates.length)
|
|
170
|
+
writeFileSync(
|
|
171
|
+
path.join(target, 'info/alternates'),
|
|
172
|
+
`${retainedAlternates.join('\n')}\n`,
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function producerSession(file: string): { session: string; state: string } | null {
|
|
177
|
+
if (!existsSync(file)) return null
|
|
178
|
+
const session = readFileSync(file, 'utf8').trim()
|
|
179
|
+
if (!/^[a-z0-9-]+$/.test(session))
|
|
180
|
+
throw new Error(`invalid Swift SDK producer session: ${file}`)
|
|
181
|
+
const status: unknown = JSON.parse(
|
|
182
|
+
execFileSync('tm', ['show', 'record', session], { encoding: 'utf8' }),
|
|
183
|
+
)
|
|
184
|
+
if (!isRecord(status) || typeof status.state !== 'string')
|
|
185
|
+
throw new Error(`cannot inspect Swift SDK producer ${session}`)
|
|
186
|
+
return { session, state: status.state }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function producerSettled(directory: string): boolean {
|
|
190
|
+
if (producerSession(path.join(directory, 'session'))?.state !== 'exited') return false
|
|
191
|
+
const receipt = path.join(directory, 'delivery/cleanup.json')
|
|
192
|
+
if (!existsSync(receipt)) return false
|
|
193
|
+
const value: unknown = JSON.parse(readFileSync(receipt, 'utf8'))
|
|
194
|
+
return isRecord(value) && value.released === true
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Runs a source SDK image build in a daemon-owned Linux scope; callers only observe it. */
|
|
198
|
+
export async function produceSwiftSdkImage(input: {
|
|
199
|
+
moduleRoot: string
|
|
200
|
+
key: string
|
|
201
|
+
frameworkKey: string
|
|
202
|
+
scopedLookups: boolean
|
|
203
|
+
imports: readonly string[]
|
|
204
|
+
ready: () => boolean
|
|
205
|
+
signal?: AbortSignal
|
|
206
|
+
}): Promise<void> {
|
|
207
|
+
const root = path.join(swiftCacheDir(), 'swift-sdk-image-producers', input.key)
|
|
208
|
+
const current = path.join(root, 'current')
|
|
209
|
+
input.signal?.throwIfAborted()
|
|
210
|
+
const claim = await withSwiftRootLock(
|
|
211
|
+
`${root}.claim`,
|
|
212
|
+
async () => {
|
|
213
|
+
if (input.ready()) return null
|
|
214
|
+
if (existsSync(current)) {
|
|
215
|
+
const generation = readFileSync(current, 'utf8').trim()
|
|
216
|
+
if (!/^[a-f0-9-]{36}$/.test(generation))
|
|
217
|
+
throw new Error(`invalid Swift SDK producer generation: ${current}`)
|
|
218
|
+
const directory = path.join(root, generation)
|
|
219
|
+
const request = readRequest(path.join(directory, 'request.json'))
|
|
220
|
+
if (request.launchId !== generation)
|
|
221
|
+
throw new Error(`Swift SDK producer generation differs: ${directory}`)
|
|
222
|
+
const session = producerSession(path.join(directory, 'session'))
|
|
223
|
+
if (session) {
|
|
224
|
+
if (!producerSettled(directory)) return { directory, request }
|
|
225
|
+
rmSync(path.join(directory, 'snapshot'), {
|
|
226
|
+
recursive: true,
|
|
227
|
+
force: true,
|
|
228
|
+
})
|
|
229
|
+
} else if (Date.now() - request.created <= 60_000) {
|
|
230
|
+
return { directory, request }
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const repo = path.resolve(input.moduleRoot, '../..')
|
|
234
|
+
const launchId = randomUUID()
|
|
235
|
+
const directory = path.join(root, launchId)
|
|
236
|
+
const requestFile = path.join(directory, 'request.json')
|
|
237
|
+
const sessionFile = path.join(directory, 'session')
|
|
238
|
+
const capture = path.join(root, `.capture-${launchId}`)
|
|
239
|
+
mkdirSync(root, { recursive: true })
|
|
240
|
+
try {
|
|
241
|
+
execFileSync(
|
|
242
|
+
'bash',
|
|
243
|
+
[path.join(repo, 'scripts/lib/remote-source-snapshot.sh'), repo, capture],
|
|
244
|
+
{
|
|
245
|
+
stdio: 'inherit',
|
|
246
|
+
},
|
|
247
|
+
)
|
|
248
|
+
retainSnapshotObjects(repo, capture)
|
|
249
|
+
mkdirSync(directory)
|
|
250
|
+
renameSync(capture, path.join(directory, 'snapshot'))
|
|
251
|
+
const environment: Record<string, string> = {}
|
|
252
|
+
for (const name of environmentNames) {
|
|
253
|
+
const value = process.env[name]
|
|
254
|
+
if (value !== undefined) environment[name] = value
|
|
255
|
+
}
|
|
256
|
+
const record: Request = {
|
|
257
|
+
key: input.key,
|
|
258
|
+
launchId,
|
|
259
|
+
created: Date.now(),
|
|
260
|
+
scopedLookups: input.scopedLookups,
|
|
261
|
+
imports: [...input.imports],
|
|
262
|
+
cache: swiftCacheDir(),
|
|
263
|
+
environment,
|
|
264
|
+
}
|
|
265
|
+
writeFileSync(requestFile, JSON.stringify(record), { flag: 'wx' })
|
|
266
|
+
const next = `${current}.${launchId}`
|
|
267
|
+
writeFileSync(next, launchId, { flag: 'wx' })
|
|
268
|
+
renameSync(next, current)
|
|
269
|
+
const admitted = windowAdmission()?.cores ?? Number(process.env.TM_EXEC_CPU_CORES)
|
|
270
|
+
const cores =
|
|
271
|
+
Number.isSafeInteger(admitted) && admitted > 0 ? Math.max(4, admitted) : 4
|
|
272
|
+
const launched = await run(
|
|
273
|
+
'tm',
|
|
274
|
+
[
|
|
275
|
+
'run',
|
|
276
|
+
'--here',
|
|
277
|
+
'--in-place',
|
|
278
|
+
'--quiet',
|
|
279
|
+
'--no-finish-notice',
|
|
280
|
+
'--slug',
|
|
281
|
+
`swift-sdk-image-${record.launchId.slice(0, 8)}`,
|
|
282
|
+
'--',
|
|
283
|
+
'/bin/sh',
|
|
284
|
+
'-c',
|
|
285
|
+
launcher,
|
|
286
|
+
'swift-sdk-image',
|
|
287
|
+
sessionFile,
|
|
288
|
+
String(cores),
|
|
289
|
+
path.join(directory, 'snapshot'),
|
|
290
|
+
requestFile,
|
|
291
|
+
path.join(directory, 'delivery'),
|
|
292
|
+
input.frameworkKey,
|
|
293
|
+
],
|
|
294
|
+
{ cwd: repo },
|
|
295
|
+
)
|
|
296
|
+
if (!launched.stdout.trim())
|
|
297
|
+
throw new Error(`Swift SDK producer launch was not confirmed: ${directory}`)
|
|
298
|
+
return { directory, request: record }
|
|
299
|
+
} finally {
|
|
300
|
+
rmSync(capture, { recursive: true, force: true })
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
input.signal,
|
|
304
|
+
)
|
|
305
|
+
if (!claim) return
|
|
306
|
+
const { directory, request } = claim
|
|
307
|
+
const sessionFile = path.join(directory, 'session')
|
|
308
|
+
const resultFile = path.join(directory, 'result.json')
|
|
309
|
+
if (request.key !== input.key || request.cache !== swiftCacheDir())
|
|
310
|
+
throw new Error(`Swift SDK producer identity mismatch: ${directory}`)
|
|
311
|
+
for (;;) {
|
|
312
|
+
if (existsSync(resultFile)) {
|
|
313
|
+
const result: unknown = JSON.parse(readFileSync(resultFile, 'utf8'))
|
|
314
|
+
if (
|
|
315
|
+
!isRecord(result) ||
|
|
316
|
+
result.launchId !== request.launchId ||
|
|
317
|
+
!(result.error === null || typeof result.error === 'string')
|
|
318
|
+
)
|
|
319
|
+
throw new Error(`invalid Swift SDK producer result: ${resultFile}`)
|
|
320
|
+
if (result.error) throw new Error(`Swift SDK producer failed: ${result.error}`)
|
|
321
|
+
return
|
|
322
|
+
}
|
|
323
|
+
const status = producerSession(sessionFile)
|
|
324
|
+
if (status) {
|
|
325
|
+
if (status.state === 'exited') {
|
|
326
|
+
if (existsSync(resultFile)) continue
|
|
327
|
+
throw new Error(
|
|
328
|
+
`Swift SDK producer ${status.session} exited without a result; inspect its session before retrying`,
|
|
329
|
+
)
|
|
330
|
+
}
|
|
331
|
+
} else if (Date.now() - request.created > 60_000) {
|
|
332
|
+
throw new Error(`Swift SDK producer launch is unconfirmed: ${directory}`)
|
|
333
|
+
}
|
|
334
|
+
await sleep(2000, undefined, { signal: input.signal })
|
|
335
|
+
}
|
|
336
|
+
}
|
package/src/swift-sdk-image.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
linkedFrameworkTargets,
|
|
18
18
|
swiftDistributionAt,
|
|
19
19
|
swiftModuleDigest,
|
|
20
|
+
swiftProjectBuildKey,
|
|
20
21
|
swiftSdkPaths,
|
|
21
22
|
} from './swift-compile'
|
|
22
23
|
import { DARWIN_RECORDS_PREFIX } from './swift-darwin-records'
|
|
@@ -37,7 +38,7 @@ import {
|
|
|
37
38
|
wasmSections,
|
|
38
39
|
type SwiftSdkInterface,
|
|
39
40
|
} from './swift-sdk-image-wasm'
|
|
40
|
-
import { swiftCacheDir } from './swift-toolchain'
|
|
41
|
+
import { sourceSwiftCheckout, swiftCacheDir } from './swift-toolchain'
|
|
41
42
|
import {
|
|
42
43
|
guestWasmSymbols,
|
|
43
44
|
readArMembers,
|
|
@@ -241,10 +242,37 @@ export async function buildSwiftSdkImage(
|
|
|
241
242
|
moduleRoot: string,
|
|
242
243
|
scopedLookups = false,
|
|
243
244
|
frameworkImports: readonly string[] = [],
|
|
245
|
+
options?: { producer?: boolean; signal?: AbortSignal },
|
|
244
246
|
): Promise<SwiftSdkImage> {
|
|
245
247
|
const { imports, products } = swiftSdkImageProducts(moduleRoot, frameworkImports)
|
|
246
248
|
const key = swiftSdkImageKey(moduleRoot, scopedLookups, products)
|
|
247
249
|
const directory = path.join(swiftCacheDir(), 'swift-sdk-images', key)
|
|
250
|
+
const existing = cached(directory, key)
|
|
251
|
+
if (existing) return existing
|
|
252
|
+
if (
|
|
253
|
+
!options?.producer &&
|
|
254
|
+
!swiftDistributionAt(moduleRoot) &&
|
|
255
|
+
path.resolve(moduleRoot) === sourceSwiftCheckout() &&
|
|
256
|
+
process.platform === 'linux' &&
|
|
257
|
+
process.env.TM_SESSION
|
|
258
|
+
) {
|
|
259
|
+
const { produceSwiftSdkImage } = await import('./swift-sdk-image-producer')
|
|
260
|
+
await produceSwiftSdkImage({
|
|
261
|
+
moduleRoot,
|
|
262
|
+
key,
|
|
263
|
+
frameworkKey: swiftProjectBuildKey(
|
|
264
|
+
moduleRoot,
|
|
265
|
+
swiftModuleToolchain(moduleRoot).release,
|
|
266
|
+
),
|
|
267
|
+
scopedLookups,
|
|
268
|
+
imports,
|
|
269
|
+
ready: () => cached(directory, key) !== undefined,
|
|
270
|
+
signal: options?.signal,
|
|
271
|
+
})
|
|
272
|
+
const image = cached(directory, key)
|
|
273
|
+
if (!image) throw new Error(`Swift SDK producer completed without image ${key}`)
|
|
274
|
+
return image
|
|
275
|
+
}
|
|
248
276
|
return (
|
|
249
277
|
cached(directory, key) ??
|
|
250
278
|
withSwiftRootLock(directory, async () => {
|
|
@@ -561,6 +589,14 @@ async function linkSwiftSdkImage(
|
|
|
561
589
|
path.join(work, IMAGE_DIGEST),
|
|
562
590
|
createHash('sha256').update(image).digest('hex'),
|
|
563
591
|
)
|
|
592
|
+
if (
|
|
593
|
+
swiftSdkImageKey(
|
|
594
|
+
moduleRoot,
|
|
595
|
+
scopedLookups,
|
|
596
|
+
swiftSdkImageProducts(moduleRoot, imports).products,
|
|
597
|
+
) !== key
|
|
598
|
+
)
|
|
599
|
+
throw new Error('Swift SDK image inputs changed during compilation')
|
|
564
600
|
for (const name of readdirSync(work))
|
|
565
601
|
if (!SWIFT_SDK_IMAGE_FILES.includes(name))
|
|
566
602
|
rmSync(path.join(work, name), { recursive: true, force: true })
|