peachsim 0.1.2792 → 0.1.2794
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/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 +1162 -997
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +3 -3
- package/dist-lib/cloud-contract.cjs +1 -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 +1 -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 +1 -1
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/esm-chunks/{acorn-WRJUSJKZ.mjs → acorn-A7OMJDVK.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-KM6MA4GX.mjs → chunk-2TCGEMEV.mjs} +5 -5
- package/dist-lib/esm-chunks/{chunk-LKQFWHTY.mjs → chunk-35HEHEYA.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-T2AWHCFQ.mjs → chunk-5RQ3U7WK.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-HLTCPSRU.mjs → chunk-7QNWHCMJ.mjs} +1121 -1060
- package/dist-lib/esm-chunks/{chunk-MPN7ASMV.mjs → chunk-ANIC22U3.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-2RLCLA6D.mjs → chunk-AW4Z3K2U.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-UIMK6KUZ.mjs → chunk-B3E5ZI2D.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-GSH5UN7J.mjs → chunk-CIFEHSEA.mjs} +2 -2
- package/dist-lib/esm-chunks/{chunk-DTUV3X2Q.mjs → chunk-CIR4VZ22.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-JGMADAGT.mjs → chunk-DLEQ5NZ5.mjs} +4 -4
- package/dist-lib/esm-chunks/{chunk-KZF5BL3C.mjs → chunk-E6KA576K.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-ETD4V3AD.mjs → chunk-GDITZ3K2.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-6WTE57J5.mjs → chunk-GHGDWJY3.mjs} +6 -6
- package/dist-lib/esm-chunks/{chunk-47WU4TMV.mjs → chunk-K7RLWF5X.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-6M75JXV2.mjs → chunk-KVFRYFZI.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-YIQKUSLV.mjs → chunk-NKJ67PFZ.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-OLGTAPUD.mjs → chunk-O6HHWO4Y.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-WDTW47HC.mjs → chunk-OS6YJU3W.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-IVMQXMAB.mjs → chunk-PRYC6EMT.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-T66EPEFI.mjs → chunk-R6ES6QCH.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-GGEXRAIP.mjs → chunk-TJULYSLY.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-U66IKMQZ.mjs → chunk-V6BE34Q3.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-NHFLYRY6.mjs → chunk-Y6YMRYNX.mjs} +64 -21
- package/dist-lib/esm-chunks/{chunk-AWVOMHWY.mjs → chunk-ZTDPCBGG.mjs} +3 -3
- package/dist-lib/esm-chunks/{metro-layout-parser-DCAE4BLG.mjs → metro-layout-parser-WG2ITRQD.mjs} +3 -3
- package/dist-lib/esm-chunks/{swift-package-prebuilt-PP63JS2U.mjs → swift-package-prebuilt-DN7G5XKR.mjs} +16 -13
- package/dist-lib/esm-chunks/{swift-sdk-app-module-Q5PK6AH4.mjs → swift-sdk-app-module-3DB4F4Y2.mjs} +16 -16
- package/dist-lib/esm-chunks/{swift-sdk-image-NTCJSARK.mjs → swift-sdk-image-JTYM3OQY.mjs} +16 -16
- package/dist-lib/esm-chunks/{swift-sdk-image-producer-KIVLLITM.mjs → swift-sdk-image-producer-QQUODPXF.mjs} +5 -5
- package/dist-lib/expo-swift-bundle.cjs +1104 -939
- 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 +3747 -3456
- package/dist-lib/host/fetch-proxy-handler.cjs +121 -117
- 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 +1 -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 +3 -1
- package/dist-lib/native-app-identity-project.mjs +15 -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 +85 -85
- package/dist-lib/public-origins-lib.json +76 -76
- 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 +8 -8
- package/dist-lib/skills.cjs +2032 -1741
- package/dist-lib/swift-compile.cjs +1061 -967
- package/dist-lib/swift-compile.mjs +12 -12
- 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 +6 -6
- 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/acorn.cjs +1 -1
- package/dist-lib/vendor/magic-string.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/engine/image-fetch.d.ts +0 -4
- package/dist-types/packages/peach-engine/src/engine/scene-native-binding.d.ts +2 -2
- package/dist-types/packages/peach-engine/src/render-worker/native-hot-ops.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/render-worker/nativeReanimatedCSSContract.d.ts +7 -7
- package/dist-types/packages/peach-engine/src/render-worker/reanimated-css-contract.d.ts +1 -20
- package/dist-types/packages/peach-engine/src/render-worker/scene-packet-feed.d.ts +2 -0
- package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +5 -23
- package/dist-types/packages/peach-engine/src/render-worker/worklet-wire.d.ts +4 -49
- package/package.json +1 -1
- package/src/one-native-controls-package.ts +56 -54
- package/src/swift-compile.ts +1034 -967
- package/src/swift-compiler-digest.ts +79 -4
- package/src/swift-host.ts +246 -91
- package/src/swift-package-prebuilt.ts +6 -3
- package/src/swift-sdk-surface.ts +75 -20
- package/src/swift-startup-split.ts +134 -12
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto'
|
|
2
|
-
import {
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto'
|
|
2
|
+
import {
|
|
3
|
+
existsSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
readdirSync,
|
|
6
|
+
readFileSync,
|
|
7
|
+
renameSync,
|
|
8
|
+
statSync,
|
|
9
|
+
writeFileSync,
|
|
10
|
+
} from 'node:fs'
|
|
11
|
+
import os from 'node:os'
|
|
3
12
|
import path from 'node:path'
|
|
4
|
-
|
|
13
|
+
|
|
14
|
+
// node builtins only: sparse CI workflows check out this file without swift-toolchain.ts.
|
|
15
|
+
function compilerDigestCacheDir(): string {
|
|
16
|
+
const home = process.env.PEACH_HOME || path.join(os.homedir(), '.peach')
|
|
17
|
+
return path.join(home, 'cache', 'swift-compiler-digests')
|
|
18
|
+
}
|
|
5
19
|
|
|
6
20
|
// the lowering and manifest code in swift-compile.ts and its design-time lowering
|
|
7
21
|
// decide the emitted output, the root lock decides whose sources and
|
|
@@ -88,6 +102,61 @@ export function swiftCompilerSourceDigest(
|
|
|
88
102
|
): string {
|
|
89
103
|
const known = digests.get(srcDir)
|
|
90
104
|
if (known) return known[output]
|
|
105
|
+
const sdkRoot = path.join(srcDir, '..', 'sdk', 'ios')
|
|
106
|
+
const sdkEntries = readdirSync(sdkRoot, { recursive: true, withFileTypes: true })
|
|
107
|
+
.filter((entry) => entry.isFile())
|
|
108
|
+
.map((entry) => {
|
|
109
|
+
const full = path.join(entry.parentPath, entry.name)
|
|
110
|
+
const rel = path.relative(sdkRoot, full).split(path.sep).join('/')
|
|
111
|
+
return [rel, full] as const
|
|
112
|
+
})
|
|
113
|
+
.sort(([a], [b]) => (a < b ? -1 : 1))
|
|
114
|
+
const stampHash = createHash('sha256')
|
|
115
|
+
for (const file of SWIFT_DIGEST_SOURCES) {
|
|
116
|
+
const stat = statSync(path.join(srcDir, file), { bigint: true })
|
|
117
|
+
stampHash.update(file)
|
|
118
|
+
stampHash.update(
|
|
119
|
+
`${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}\n`,
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
for (const [rel, full] of sdkEntries) {
|
|
123
|
+
const stat = statSync(full, { bigint: true })
|
|
124
|
+
stampHash.update(rel)
|
|
125
|
+
stampHash.update(
|
|
126
|
+
`${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}\n`,
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
const stamp = stampHash.digest('hex')
|
|
130
|
+
const digestDir = compilerDigestCacheDir()
|
|
131
|
+
const record = path.join(
|
|
132
|
+
digestDir,
|
|
133
|
+
`${createHash('sha256').update(srcDir).digest('hex')}.json`,
|
|
134
|
+
)
|
|
135
|
+
if (existsSync(record)) {
|
|
136
|
+
try {
|
|
137
|
+
const saved: unknown = JSON.parse(readFileSync(record, 'utf8'))
|
|
138
|
+
if (
|
|
139
|
+
saved &&
|
|
140
|
+
typeof saved === 'object' &&
|
|
141
|
+
Reflect.get(saved, 'stamp') === stamp &&
|
|
142
|
+
typeof Reflect.get(saved, 'image') === 'string' &&
|
|
143
|
+
typeof Reflect.get(saved, 'archive') === 'string'
|
|
144
|
+
) {
|
|
145
|
+
const result = {
|
|
146
|
+
image: String(Reflect.get(saved, 'image')),
|
|
147
|
+
archive: String(Reflect.get(saved, 'archive')),
|
|
148
|
+
}
|
|
149
|
+
digests.set(srcDir, result)
|
|
150
|
+
return result[output]
|
|
151
|
+
}
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (
|
|
154
|
+
!(error instanceof SyntaxError) &&
|
|
155
|
+
!(error instanceof Error && 'code' in error && error.code === 'ENOENT')
|
|
156
|
+
)
|
|
157
|
+
throw error
|
|
158
|
+
}
|
|
159
|
+
}
|
|
91
160
|
const image = createHash('sha256')
|
|
92
161
|
const archive = createHash('sha256')
|
|
93
162
|
for (const file of SWIFT_DIGEST_SOURCES) {
|
|
@@ -95,12 +164,18 @@ export function swiftCompilerSourceDigest(
|
|
|
95
164
|
image.update(bytes)
|
|
96
165
|
if (!LINKED_IMAGE_SOURCES.has(file)) archive.update(bytes)
|
|
97
166
|
}
|
|
98
|
-
const sdk = JSON.stringify(
|
|
167
|
+
const sdk = JSON.stringify(
|
|
168
|
+
sdkEntries.map(([rel, full]) => [rel, readFileSync(full, 'utf8')] as const),
|
|
169
|
+
)
|
|
99
170
|
const result = {
|
|
100
171
|
image: image.update(sdk).digest('hex'),
|
|
101
172
|
archive: archive.update(sdk).digest('hex'),
|
|
102
173
|
}
|
|
103
174
|
digests.set(srcDir, result)
|
|
175
|
+
mkdirSync(digestDir, { recursive: true })
|
|
176
|
+
const partial = `${record}.${process.pid}.${randomUUID()}`
|
|
177
|
+
writeFileSync(partial, JSON.stringify({ stamp, ...result }))
|
|
178
|
+
renameSync(partial, record)
|
|
104
179
|
return result[output]
|
|
105
180
|
}
|
|
106
181
|
|
package/src/swift-host.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
2
2
|
import { execFile, execFileSync, spawn } from 'node:child_process'
|
|
3
|
-
import { createHash, type Hash } from 'node:crypto'
|
|
3
|
+
import { createHash, randomUUID, type Hash } from 'node:crypto'
|
|
4
4
|
// the node host for every Swift preview: package inputs, one compile and
|
|
5
5
|
// immutable artifact addresses. vite and the foreground CLI adapt this host.
|
|
6
6
|
import fs from 'node:fs'
|
|
@@ -105,6 +105,11 @@ import {
|
|
|
105
105
|
} from './swift-packages'
|
|
106
106
|
import { rasterizePdfFiles } from './swift-pdf-raster'
|
|
107
107
|
import { wasmSections } from './swift-sdk-image-wasm'
|
|
108
|
+
import {
|
|
109
|
+
swiftModuleRelease,
|
|
110
|
+
swiftModuleStamp,
|
|
111
|
+
withSwiftModuleDigestScope,
|
|
112
|
+
} from './swift-sdk-surface'
|
|
108
113
|
import { shippedBinaryDiffers } from './swift-shipped-binaries'
|
|
109
114
|
import {
|
|
110
115
|
packageInputPath,
|
|
@@ -201,7 +206,26 @@ const SKIP_ROOT_DIRS = new Set(['dist', 'types', 'build', 'ios', 'android'])
|
|
|
201
206
|
const NATIVE_DESCRIPTOR = '.one-native-source.json'
|
|
202
207
|
const NATIVE_GLUE = '.one-native-source.swift.txt'
|
|
203
208
|
|
|
204
|
-
|
|
209
|
+
const packageReadScopes = new AsyncLocalStorage<Map<string, Buffer>>()
|
|
210
|
+
|
|
211
|
+
function withPackageReadScope<T>(fn: () => T): T {
|
|
212
|
+
if (packageReadScopes.getStore()) return fn()
|
|
213
|
+
return packageReadScopes.run(new Map(), fn)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function readPackageFileScoped(
|
|
217
|
+
packagePath: string,
|
|
218
|
+
file: string,
|
|
219
|
+
maxBytes: number,
|
|
220
|
+
): Buffer {
|
|
221
|
+
const scope = packageReadScopes.getStore()
|
|
222
|
+
const key = `${packagePath}\0${file}`
|
|
223
|
+
const cached = scope?.get(key)
|
|
224
|
+
if (cached) return cached
|
|
225
|
+
const bytes = readPackageFile(packagePath, file, maxBytes)
|
|
226
|
+
scope?.set(key, bytes)
|
|
227
|
+
return bytes
|
|
228
|
+
}
|
|
205
229
|
// package by.
|
|
206
230
|
function swiftPackageId(packagePath: string): string {
|
|
207
231
|
return path
|
|
@@ -2858,13 +2882,7 @@ function moduleStamp(
|
|
|
2858
2882
|
fs.existsSync(path.join(root, 'toolchain.json')),
|
|
2859
2883
|
))
|
|
2860
2884
|
if (!moduleRoot) return ''
|
|
2861
|
-
|
|
2862
|
-
hash.update(moduleRoot)
|
|
2863
|
-
for (const relative of swiftModuleInputFiles(moduleRoot)) {
|
|
2864
|
-
hash.update(relative)
|
|
2865
|
-
hash.update(String(fs.statSync(path.join(moduleRoot, relative)).mtimeMs))
|
|
2866
|
-
}
|
|
2867
|
-
return hash.digest('hex')
|
|
2885
|
+
return `${moduleRoot}\0${swiftModuleStamp(moduleRoot)}`
|
|
2868
2886
|
}
|
|
2869
2887
|
|
|
2870
2888
|
// a compile input's digest outside its source files
|
|
@@ -3037,7 +3055,7 @@ function packageSources(
|
|
|
3037
3055
|
if (manifests.has(file) || xcode?.packageFiles.has(file)) continue
|
|
3038
3056
|
files[xcode ? xcodeInputKey(xcode, file, relative) : relative] = (
|
|
3039
3057
|
xcode?.nativeFiles.get(file) ??
|
|
3040
|
-
|
|
3058
|
+
readPackageFileScoped(packagePath, file, limits.sourceBytes)
|
|
3041
3059
|
).toString('utf8')
|
|
3042
3060
|
}
|
|
3043
3061
|
if (xcode) {
|
|
@@ -3461,56 +3479,60 @@ async function compile(
|
|
|
3461
3479
|
fs.existsSync(path.join(root, 'toolchain.json')),
|
|
3462
3480
|
) ??
|
|
3463
3481
|
(await swiftDistributionRoot(signal))
|
|
3464
|
-
const
|
|
3482
|
+
const release = swiftModuleRelease(moduleRoot)
|
|
3465
3483
|
const input = snapshotCompileInput(snapshot)
|
|
3466
3484
|
const compiled = {
|
|
3467
3485
|
files: input.files,
|
|
3468
3486
|
inputs: otherInputs(input),
|
|
3469
3487
|
module: moduleStamp(packagePath, moduleRootOverride, false),
|
|
3470
3488
|
}
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
name,
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
const
|
|
3491
|
-
|
|
3489
|
+
const verifyMissingModules = async (toolchainBin: string) => {
|
|
3490
|
+
// targets are imported by their module names
|
|
3491
|
+
const parsed = compileTargets(input)
|
|
3492
|
+
const targets = parsed.map((target) => swiftTargetModuleName(target.name))
|
|
3493
|
+
// the compiler synthesizes Builtin for a file whose own target enables the
|
|
3494
|
+
// feature, exactly when its import compiles. longest path first, so a
|
|
3495
|
+
// nested target's files read its own settings.
|
|
3496
|
+
const byPath = [...parsed].sort((left, right) => right.path.length - left.path.length)
|
|
3497
|
+
const clangModulesByTarget = new Map(
|
|
3498
|
+
(input.nativeTargets ?? []).map(({ name, headerSearchPaths }) => [
|
|
3499
|
+
name,
|
|
3500
|
+
headerSearchPaths.flatMap((directory) => {
|
|
3501
|
+
const map =
|
|
3502
|
+
input.files[path.posix.join(directory, 'module.modulemap')] ??
|
|
3503
|
+
input.files[path.posix.join(directory, 'module.map')]
|
|
3504
|
+
return map === undefined ? [] : moduleMapModules(map).map(({ name }) => name)
|
|
3505
|
+
}),
|
|
3506
|
+
]),
|
|
3507
|
+
)
|
|
3508
|
+
const providedByFile = (file: string): readonly string[] => {
|
|
3509
|
+
const owner = byPath.find((target) =>
|
|
3510
|
+
target.path === '.' ? true : file.startsWith(`${target.path}/`),
|
|
3511
|
+
)
|
|
3512
|
+
if (!owner) return []
|
|
3513
|
+
const clangModules = clangModulesByTarget.get(owner.name) ?? []
|
|
3514
|
+
return owner.experimentalFeatures?.includes('BuiltinModule')
|
|
3515
|
+
? [...clangModules, 'Builtin']
|
|
3516
|
+
: clangModules
|
|
3517
|
+
}
|
|
3518
|
+
const missing = missingSwiftModules(
|
|
3519
|
+
input.files,
|
|
3520
|
+
new Set([
|
|
3521
|
+
...swiftAvailableModules(moduleRoot, toolchainBin),
|
|
3522
|
+
// a project without a manifest compiles as the template's one App target
|
|
3523
|
+
...(targets.length > 0 ? targets : ['App']),
|
|
3524
|
+
// a system target's clang module name need not match its target name
|
|
3525
|
+
...swiftSystemLibrarySurface(input.files, parsed).modules,
|
|
3526
|
+
...Object.keys(input.binaryModules ?? {}),
|
|
3527
|
+
...snapshot.nativeModules,
|
|
3528
|
+
]),
|
|
3529
|
+
providedByFile,
|
|
3492
3530
|
)
|
|
3493
|
-
if (
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
: clangModules
|
|
3531
|
+
if (missing.size > 0)
|
|
3532
|
+
throw new SwiftMissingModulesError(
|
|
3533
|
+
await missingModulesMessage(packagePath, missing),
|
|
3534
|
+
)
|
|
3498
3535
|
}
|
|
3499
|
-
const missing = missingSwiftModules(
|
|
3500
|
-
input.files,
|
|
3501
|
-
new Set([
|
|
3502
|
-
...swiftAvailableModules(moduleRoot, toolchain.toolchainBin),
|
|
3503
|
-
// a project without a manifest compiles as the template's one App target
|
|
3504
|
-
...(targets.length > 0 ? targets : ['App']),
|
|
3505
|
-
// a system target's clang module name need not match its target name
|
|
3506
|
-
...swiftSystemLibrarySurface(input.files, parsed).modules,
|
|
3507
|
-
...Object.keys(input.binaryModules ?? {}),
|
|
3508
|
-
...snapshot.nativeModules,
|
|
3509
|
-
]),
|
|
3510
|
-
providedByFile,
|
|
3511
|
-
)
|
|
3512
|
-
if (missing.size > 0)
|
|
3513
|
-
throw new SwiftMissingModulesError(await missingModulesMessage(packagePath, missing))
|
|
3514
3536
|
const artifact = await compileSwiftProjectUnit(input, {
|
|
3515
3537
|
// the compile rewrites Sources/App in its root before swiftpm builds, and
|
|
3516
3538
|
// a root lock orders every process using it, so two vites on one root
|
|
@@ -3520,7 +3542,9 @@ async function compile(
|
|
|
3520
3542
|
// incremental build across restarts.
|
|
3521
3543
|
buildRoot: swiftBuildRoot(packagePath, moduleRoot),
|
|
3522
3544
|
moduleRoot,
|
|
3523
|
-
|
|
3545
|
+
release,
|
|
3546
|
+
resolveToolchain: () => swiftModuleToolchain(moduleRoot).toolchainBin,
|
|
3547
|
+
beforeCompile: verifyMissingModules,
|
|
3524
3548
|
signal,
|
|
3525
3549
|
}).catch((error: unknown) => {
|
|
3526
3550
|
const report = error instanceof Error ? swiftApiGapReport(error.message) : null
|
|
@@ -3843,8 +3867,10 @@ export function artifactFor(
|
|
|
3843
3867
|
moduleRoot?: string,
|
|
3844
3868
|
signal: AbortSignal | undefined = project.signal,
|
|
3845
3869
|
): Promise<SwiftArtifact> {
|
|
3846
|
-
return
|
|
3847
|
-
|
|
3870
|
+
return withSwiftModuleDigestScope(() =>
|
|
3871
|
+
withXcodeLayout(project.packagePath, () =>
|
|
3872
|
+
scopedArtifact(project, entry, moduleRoot, signal),
|
|
3873
|
+
),
|
|
3848
3874
|
)
|
|
3849
3875
|
}
|
|
3850
3876
|
|
|
@@ -3961,6 +3987,34 @@ export async function swiftPackageMetadata(
|
|
|
3961
3987
|
startupRuntimeUrl?: URL,
|
|
3962
3988
|
startupGuest?: SwiftStartupLaunch['guest'],
|
|
3963
3989
|
startupArguments: readonly string[] = [],
|
|
3990
|
+
): Promise<SwiftEntryModuleArgs> {
|
|
3991
|
+
return withPackageReadScope(() =>
|
|
3992
|
+
swiftPackageMetadataScoped(
|
|
3993
|
+
packagePath,
|
|
3994
|
+
packageName,
|
|
3995
|
+
moduleRoot,
|
|
3996
|
+
origin,
|
|
3997
|
+
hosted,
|
|
3998
|
+
signal,
|
|
3999
|
+
startupEnvironment,
|
|
4000
|
+
startupRuntimeUrl,
|
|
4001
|
+
startupGuest,
|
|
4002
|
+
startupArguments,
|
|
4003
|
+
),
|
|
4004
|
+
)
|
|
4005
|
+
}
|
|
4006
|
+
|
|
4007
|
+
async function swiftPackageMetadataScoped(
|
|
4008
|
+
packagePath: string,
|
|
4009
|
+
packageName: string,
|
|
4010
|
+
moduleRoot: string | undefined,
|
|
4011
|
+
origin: string,
|
|
4012
|
+
hosted?: SwiftHostedCompileOptions,
|
|
4013
|
+
signal?: AbortSignal,
|
|
4014
|
+
startupEnvironment: readonly string[] = [],
|
|
4015
|
+
startupRuntimeUrl?: URL,
|
|
4016
|
+
startupGuest?: SwiftStartupLaunch['guest'],
|
|
4017
|
+
startupArguments: readonly string[] = [],
|
|
3964
4018
|
): Promise<SwiftEntryModuleArgs> {
|
|
3965
4019
|
packagePath = fs.realpathSync(packagePath)
|
|
3966
4020
|
const project = projectFor(packagePath, hosted, signal)
|
|
@@ -4020,9 +4074,11 @@ export async function swiftPackageMetadata(
|
|
|
4020
4074
|
return cxx ? 'c++' : 'c'
|
|
4021
4075
|
}
|
|
4022
4076
|
const mains = candidates.filter((file) => {
|
|
4023
|
-
const contents =
|
|
4024
|
-
|
|
4025
|
-
|
|
4077
|
+
const contents = readPackageFileScoped(
|
|
4078
|
+
packagePath,
|
|
4079
|
+
file,
|
|
4080
|
+
limits.sourceBytes,
|
|
4081
|
+
).toString('utf8')
|
|
4026
4082
|
return file.endsWith('.swift')
|
|
4027
4083
|
? swiftApplicationEntry(file, contents)
|
|
4028
4084
|
: swiftCMainEntry(file, contents, {
|
|
@@ -4131,19 +4187,30 @@ export async function swiftPackageMetadata(
|
|
|
4131
4187
|
let startup = profiles.get(key)
|
|
4132
4188
|
if (!startup) {
|
|
4133
4189
|
startup = (async () => {
|
|
4134
|
-
const
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
const { splitSwiftApp } = await import('./swift-startup-split')
|
|
4138
|
-
const result = await splitSwiftApp(artifact.bytes, {
|
|
4139
|
-
runtimeRoot,
|
|
4190
|
+
const { readCachedSwiftAppStartupSplit, splitSwiftApp } =
|
|
4191
|
+
await import('./swift-startup-split')
|
|
4192
|
+
const cachedSplit = await readCachedSwiftAppStartupSplit({
|
|
4140
4193
|
artifactHash: artifact.hash,
|
|
4141
4194
|
environment: startupEnvironment,
|
|
4142
4195
|
arguments: startupArguments,
|
|
4143
4196
|
guest: startupGuest,
|
|
4144
|
-
metadata: (profileOrigin) => metadata(profileOrigin, artifact, sdkDigest),
|
|
4145
|
-
serveAsset: serveSwiftPackageAsset,
|
|
4146
4197
|
})
|
|
4198
|
+
const result =
|
|
4199
|
+
cachedSplit ??
|
|
4200
|
+
(await (async () => {
|
|
4201
|
+
const runtimeRoot = startupRuntimeUrl ?? (await ensureSwiftStartupRuntimeRoot())
|
|
4202
|
+
if (!runtimeRoot)
|
|
4203
|
+
throw new Error('cannot profile Swift startup without the engine runtime')
|
|
4204
|
+
return splitSwiftApp(artifact.bytes, {
|
|
4205
|
+
runtimeRoot,
|
|
4206
|
+
artifactHash: artifact.hash,
|
|
4207
|
+
environment: startupEnvironment,
|
|
4208
|
+
arguments: startupArguments,
|
|
4209
|
+
guest: startupGuest,
|
|
4210
|
+
metadata: (profileOrigin) => metadata(profileOrigin, artifact, sdkDigest),
|
|
4211
|
+
serveAsset: serveSwiftPackageAsset,
|
|
4212
|
+
})
|
|
4213
|
+
})())
|
|
4147
4214
|
const image: SwiftArtifact = {
|
|
4148
4215
|
...artifact,
|
|
4149
4216
|
hash: swiftArtifactContentDigest(result.primary),
|
|
@@ -4202,6 +4269,67 @@ export async function localPublishedSwiftSdkUrl(url: string, origin: string) {
|
|
|
4202
4269
|
return origin + (await mirror)
|
|
4203
4270
|
}
|
|
4204
4271
|
|
|
4272
|
+
function readCachedSplitBinding(cacheDir: string): {
|
|
4273
|
+
digest: string
|
|
4274
|
+
binding: Buffer
|
|
4275
|
+
later: { sha256: string; bytes: Buffer }[]
|
|
4276
|
+
} | null {
|
|
4277
|
+
const receiptFile = path.join(cacheDir, 'receipt.json')
|
|
4278
|
+
if (!fs.existsSync(receiptFile)) return null
|
|
4279
|
+
try {
|
|
4280
|
+
const receipt: unknown = JSON.parse(fs.readFileSync(receiptFile, 'utf8'))
|
|
4281
|
+
if (
|
|
4282
|
+
!receipt ||
|
|
4283
|
+
typeof receipt !== 'object' ||
|
|
4284
|
+
!('digest' in receipt) ||
|
|
4285
|
+
typeof receipt.digest !== 'string' ||
|
|
4286
|
+
!('later' in receipt) ||
|
|
4287
|
+
!Array.isArray(receipt.later) ||
|
|
4288
|
+
!receipt.later.every((item): item is string => typeof item === 'string')
|
|
4289
|
+
)
|
|
4290
|
+
return null
|
|
4291
|
+
const binding = fs.readFileSync(path.join(cacheDir, 'binding.bin'))
|
|
4292
|
+
if (createHash('sha256').update(binding).digest('hex') !== receipt.digest) return null
|
|
4293
|
+
const later = receipt.later.map((sha256, index) => {
|
|
4294
|
+
const bytes = fs.readFileSync(path.join(cacheDir, `later-${index}.bin`))
|
|
4295
|
+
if (createHash('sha256').update(bytes).digest('hex') !== sha256)
|
|
4296
|
+
throw new SyntaxError('digest mismatch')
|
|
4297
|
+
return { sha256, bytes }
|
|
4298
|
+
})
|
|
4299
|
+
return { digest: receipt.digest, binding, later }
|
|
4300
|
+
} catch {
|
|
4301
|
+
return null
|
|
4302
|
+
}
|
|
4303
|
+
}
|
|
4304
|
+
|
|
4305
|
+
function writeCachedSplitBinding(
|
|
4306
|
+
cacheDir: string,
|
|
4307
|
+
digest: string,
|
|
4308
|
+
binding: Buffer,
|
|
4309
|
+
later: readonly { sha256: string; bytes: Buffer }[],
|
|
4310
|
+
): void {
|
|
4311
|
+
const parent = path.dirname(cacheDir)
|
|
4312
|
+
fs.mkdirSync(parent, { recursive: true })
|
|
4313
|
+
const staging = `${cacheDir}.${process.pid}.${randomUUID()}.tmp`
|
|
4314
|
+
try {
|
|
4315
|
+
fs.mkdirSync(staging, { recursive: true })
|
|
4316
|
+
fs.writeFileSync(path.join(staging, 'binding.bin'), binding)
|
|
4317
|
+
for (let index = 0; index < later.length; index++)
|
|
4318
|
+
fs.writeFileSync(path.join(staging, `later-${index}.bin`), later[index]!.bytes)
|
|
4319
|
+
fs.writeFileSync(
|
|
4320
|
+
path.join(staging, 'receipt.json'),
|
|
4321
|
+
JSON.stringify({ digest, later: later.map(({ sha256 }) => sha256) }),
|
|
4322
|
+
)
|
|
4323
|
+
try {
|
|
4324
|
+
fs.renameSync(staging, cacheDir)
|
|
4325
|
+
} catch {
|
|
4326
|
+
if (!fs.existsSync(cacheDir)) throw new Error(`failed to store ${cacheDir}`)
|
|
4327
|
+
}
|
|
4328
|
+
} finally {
|
|
4329
|
+
fs.rmSync(staging, { recursive: true, force: true })
|
|
4330
|
+
}
|
|
4331
|
+
}
|
|
4332
|
+
|
|
4205
4333
|
async function splitSdkBinding(sdk: SwiftSdkModuleAsset, splitKey: string, plan: Buffer) {
|
|
4206
4334
|
const key = `${sdk.binding.sha256}:${splitKey}`
|
|
4207
4335
|
if (sdkSplitBindings.has(key)) return
|
|
@@ -4209,15 +4337,32 @@ async function splitSdkBinding(sdk: SwiftSdkModuleAsset, splitKey: string, plan:
|
|
|
4209
4337
|
import('./swift-sdk-later-data'),
|
|
4210
4338
|
import('./swift-sdk-image'),
|
|
4211
4339
|
])
|
|
4212
|
-
const
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4340
|
+
const sdkDirectory = path.dirname(swiftSdkImageFile(sdk.key))
|
|
4341
|
+
const planDigest = createHash('sha256').update(plan).digest('hex')
|
|
4342
|
+
const cacheDir = path.join(
|
|
4343
|
+
sdkDirectory,
|
|
4344
|
+
'split-bindings-v1',
|
|
4345
|
+
createHash('sha256')
|
|
4346
|
+
.update(`${sdk.binding.sha256}\0${planDigest}`)
|
|
4347
|
+
.digest('hex')
|
|
4348
|
+
.slice(0, 32),
|
|
4216
4349
|
)
|
|
4350
|
+
const cached = readCachedSplitBinding(cacheDir)
|
|
4351
|
+
if (cached) {
|
|
4352
|
+
sdkBindingFiles.set(cached.digest, cached.binding)
|
|
4353
|
+
for (const { sha256, bytes } of cached.later) sdkBindingFiles.set(sha256, bytes)
|
|
4354
|
+
sdkSplitBindings.set(key, cached.digest)
|
|
4355
|
+
return
|
|
4356
|
+
}
|
|
4357
|
+
const split = splitSwiftSdkLaterData(sdkDirectory, sdk.binding.bytes, plan)
|
|
4217
4358
|
const digest = createHash('sha256').update(split.binding).digest('hex')
|
|
4359
|
+
const later = split.later.map((bytes) => ({
|
|
4360
|
+
sha256: createHash('sha256').update(bytes).digest('hex'),
|
|
4361
|
+
bytes,
|
|
4362
|
+
}))
|
|
4363
|
+
writeCachedSplitBinding(cacheDir, digest, split.binding, later)
|
|
4218
4364
|
sdkBindingFiles.set(digest, split.binding)
|
|
4219
|
-
for (const
|
|
4220
|
-
sdkBindingFiles.set(createHash('sha256').update(later).digest('hex'), later)
|
|
4365
|
+
for (const { sha256, bytes } of later) sdkBindingFiles.set(sha256, bytes)
|
|
4221
4366
|
sdkSplitBindings.set(key, digest)
|
|
4222
4367
|
}
|
|
4223
4368
|
|
|
@@ -4348,27 +4493,37 @@ function swiftSdkStartup(
|
|
|
4348
4493
|
if (cached && (!requireCurrentProfile || cached.artifactHash === artifactHash))
|
|
4349
4494
|
return cached.startup
|
|
4350
4495
|
const startup = (async () => {
|
|
4351
|
-
const
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
import('./swift-startup-split'),
|
|
4356
|
-
import('./swift-sdk-image'),
|
|
4357
|
-
])
|
|
4496
|
+
const [
|
|
4497
|
+
{ readCachedSwiftSdkStartupSplit, splitSwiftSdkImage },
|
|
4498
|
+
{ swiftSdkImageFile },
|
|
4499
|
+
] = await Promise.all([import('./swift-startup-split'), import('./swift-sdk-image')])
|
|
4358
4500
|
const file = swiftSdkImageFile(key)
|
|
4359
|
-
const
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
...launch,
|
|
4364
|
-
runtimeRoot,
|
|
4501
|
+
const directory = path.dirname(file)
|
|
4502
|
+
const split =
|
|
4503
|
+
(await readCachedSwiftSdkStartupSplit(
|
|
4504
|
+
directory,
|
|
4365
4505
|
artifactHash,
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4506
|
+
app,
|
|
4507
|
+
requireCurrentProfile,
|
|
4508
|
+
)) ??
|
|
4509
|
+
(await (async () => {
|
|
4510
|
+
const runtimeRoot = runtimeRootOverride ?? (await ensureSwiftStartupRuntimeRoot())
|
|
4511
|
+
if (!runtimeRoot)
|
|
4512
|
+
throw new Error('cannot profile Swift startup without the engine runtime')
|
|
4513
|
+
return splitSwiftSdkImage(
|
|
4514
|
+
await fs.promises.readFile(file),
|
|
4515
|
+
directory,
|
|
4516
|
+
{
|
|
4517
|
+
...launch,
|
|
4518
|
+
runtimeRoot,
|
|
4519
|
+
artifactHash,
|
|
4520
|
+
metadata,
|
|
4521
|
+
serveAsset: serveSwiftPackageAsset,
|
|
4522
|
+
},
|
|
4523
|
+
app,
|
|
4524
|
+
requireCurrentProfile,
|
|
4525
|
+
)
|
|
4526
|
+
})())
|
|
4372
4527
|
const name = createHash('sha256').update(split.primary).digest('hex')
|
|
4373
4528
|
sdkPieces.set(name, split.primary)
|
|
4374
4529
|
for (const [digest, bytes] of split.parts) sdkPieces.set(digest, bytes)
|
|
@@ -19,7 +19,7 @@ const PACKAGE_RECIPE = '1'
|
|
|
19
19
|
export function swiftPackagePrebuiltEntries(
|
|
20
20
|
input: SwiftCompileInput,
|
|
21
21
|
moduleRoot: string,
|
|
22
|
-
toolchainBin: string,
|
|
22
|
+
toolchainBin: string | (() => string),
|
|
23
23
|
) {
|
|
24
24
|
const manifest = input.files['Package.swift']
|
|
25
25
|
if (!manifest || input.unoptimized || input.oneModule) return []
|
|
@@ -33,7 +33,10 @@ export function swiftPackagePrebuiltEntries(
|
|
|
33
33
|
const calls = manifestCalls(manifest, ['target'])
|
|
34
34
|
const platform = /platforms:\s*\[\.iOS\("([\d.]+)"\)\]/.exec(manifest)?.[1]
|
|
35
35
|
if (!platform) return []
|
|
36
|
-
const sdkModules = swiftAvailableModules(
|
|
36
|
+
const sdkModules = swiftAvailableModules(
|
|
37
|
+
moduleRoot,
|
|
38
|
+
typeof toolchainBin === 'function' ? toolchainBin() : toolchainBin,
|
|
39
|
+
)
|
|
37
40
|
return selected.flatMap(([name, modules]) => {
|
|
38
41
|
const prefix = `${SWIFT_REMOTE_PACKAGES_DIR}/${name}/`
|
|
39
42
|
const members = targets.filter(
|
|
@@ -133,7 +136,7 @@ export function swiftPackagePrebuiltEntries(
|
|
|
133
136
|
export function useSwiftPackagePrebuilts(
|
|
134
137
|
input: SwiftCompileInput,
|
|
135
138
|
moduleRoot: string,
|
|
136
|
-
toolchainBin: string,
|
|
139
|
+
toolchainBin: string | (() => string),
|
|
137
140
|
): SwiftCompileInput {
|
|
138
141
|
let resolved = input
|
|
139
142
|
for (const entry of swiftPackagePrebuiltEntries(input, moduleRoot, toolchainBin)) {
|