peachsim 0.1.2596 → 0.1.2597
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 +969 -423
- 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-WGTQK4JN.mjs → acorn-55PXV665.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-IGMABYTC.mjs → chunk-3DRJIOHV.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-BNXCKF2B.mjs → chunk-42RIRPTB.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-WPX7HLFR.mjs → chunk-56YYEI6C.mjs} +7 -6
- package/dist-lib/esm-chunks/{chunk-FDMS7FWE.mjs → chunk-7ECUAVIA.mjs} +2 -2
- package/dist-lib/esm-chunks/{chunk-4PMXT2UO.mjs → chunk-7J65FNXI.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-SYCOZ2CT.mjs → chunk-AJHFCIEU.mjs} +4 -4
- package/dist-lib/esm-chunks/{chunk-4MMPS5YL.mjs → chunk-CKUEWEY4.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-QEGUUPRI.mjs → chunk-DCL2ZEGA.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-4UUWP6NP.mjs → chunk-GECWNEHA.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-5NZPSLS4.mjs → chunk-GRGNTIO7.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-ZVBBDMPW.mjs → chunk-GZD5CTG7.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-ISZE675P.mjs → chunk-HATXI62T.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-TILPABC4.mjs → chunk-INA4S3MF.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-3C2YVQZH.mjs → chunk-IPN35TGX.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-SPKD6UYK.mjs → chunk-LH524OUR.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-DY6PUVXF.mjs → chunk-MMHNSEZY.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-BAEOHCN5.mjs → chunk-NWLCTKBM.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-HZPXGVY4.mjs → chunk-O5FDNHDG.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-TNZG7SFG.mjs → chunk-ROFBHGEA.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-UCIOSXXU.mjs → chunk-V6SI2XY7.mjs} +963 -490
- package/dist-lib/esm-chunks/{chunk-C3C5OJG4.mjs → chunk-VN7BXTMG.mjs} +5 -5
- package/dist-lib/esm-chunks/{chunk-LZF4BVEY.mjs → chunk-Y4XMEBRN.mjs} +1 -1
- package/dist-lib/esm-chunks/{metro-layout-parser-QNM3HYV7.mjs → metro-layout-parser-5FUYCP6P.mjs} +3 -3
- package/dist-lib/esm-chunks/{swift-package-prebuilt-BXXQB7Q2.mjs → swift-package-prebuilt-W3VMDYHC.mjs} +10 -10
- package/dist-lib/esm-chunks/{swift-sdk-app-module-FKL3X2ZC.mjs → swift-sdk-app-module-ZHGBY6T7.mjs} +126 -56
- package/dist-lib/esm-chunks/{swift-sdk-image-CCVWDFHB.mjs → swift-sdk-image-2PC4PKHZ.mjs} +14 -14
- package/dist-lib/esm-chunks/{swift-sdk-image-producer-OTMZVBDN.mjs → swift-sdk-image-producer-WDN6BXQL.mjs} +4 -4
- package/dist-lib/expo-swift-bundle.cjs +968 -422
- 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 +969 -423
- package/dist-lib/host/fetch-proxy-handler.cjs +36 -6
- 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 +34 -4
- package/dist-lib/native-app-identity-project.mjs +16 -16
- 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 +81 -81
- package/dist-lib/public-origins-lib.json +69 -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 +8 -8
- package/dist-lib/skills.cjs +970 -424
- package/dist-lib/swift-compile.cjs +966 -420
- package/dist-lib/swift-compile.mjs +10 -10
- 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/@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/render-worker/nativeAnimMirrorContract.d.ts +0 -2
- package/package.json +1 -1
- package/src/swift-compile.ts +421 -175
- package/src/swift-guest-compile.ts +16 -0
- package/src/swift-guest-image-ledger.ts +65 -14
- package/src/swift-guest-link.ts +21 -0
- package/src/swift-guest-manifest.ts +27 -5
- package/src/swift-guest-source-inputs.ts +119 -14
- package/src/swift-sdk-app-module.ts +128 -55
- package/src/swift-sdk-image-wasm.ts +76 -39
- package/src/swift-sdk-image.ts +2 -1
- package/src/swift-wasm-prune.ts +282 -222
- package/src/wasm-optimize.ts +1 -1
- package/src/write-build-file.ts +9 -8
|
@@ -41,6 +41,7 @@ import { projectOutputFile, type SwiftProjectUser } from './swift-project-user'
|
|
|
41
41
|
import { frameworkRuntimeProductId } from './swift-runtime-products'
|
|
42
42
|
import { sdkGuestObjectKey } from './swift-sdk-guest-lookups'
|
|
43
43
|
import { refreshSwiftCacheHold } from './swift-toolchain'
|
|
44
|
+
import { guestWasmSymbols } from './swift-wasm-prune'
|
|
44
45
|
import { wasmThreadFlags } from './swiftTargetContract.ts'
|
|
45
46
|
import { lowerWasm, type WasmOptimization } from './wasm-optimize'
|
|
46
47
|
import type { SwiftSdkImage } from './swift-sdk-image'
|
|
@@ -596,6 +597,20 @@ export async function compileGuestLink(options: {
|
|
|
596
597
|
{ stdio: 'pipe' },
|
|
597
598
|
)
|
|
598
599
|
}
|
|
600
|
+
let precomputedSymbols:
|
|
601
|
+
| {
|
|
602
|
+
readonly referenced: ReadonlySet<string>
|
|
603
|
+
readonly defined: ReadonlySet<string>
|
|
604
|
+
}
|
|
605
|
+
| undefined
|
|
606
|
+
if (splitInputs.appReferencedSymbols && splitInputs.appDefinedSymbols) {
|
|
607
|
+
const referenced = new Set(splitInputs.appReferencedSymbols)
|
|
608
|
+
const defined = new Set(splitInputs.appDefinedSymbols)
|
|
609
|
+
const projSyms = guestWasmSymbols(readFileSync(projectionObject))
|
|
610
|
+
for (const name of projSyms.undefined) referenced.add(name)
|
|
611
|
+
for (const name of projSyms.defined) defined.add(name)
|
|
612
|
+
precomputedSymbols = { referenced, defined }
|
|
613
|
+
}
|
|
599
614
|
for (;;) {
|
|
600
615
|
const link = await linkSwiftAppModule({
|
|
601
616
|
objects: [...owners.keys()],
|
|
@@ -607,6 +622,7 @@ export async function compileGuestLink(options: {
|
|
|
607
622
|
optimize: options.optimize,
|
|
608
623
|
layoutMap,
|
|
609
624
|
project,
|
|
625
|
+
precomputedSymbols,
|
|
610
626
|
loweringCache: project
|
|
611
627
|
? undefined
|
|
612
628
|
: {
|
|
@@ -78,6 +78,8 @@ export interface GuestImageLedger {
|
|
|
78
78
|
readonly lazyFunctions: readonly string[]
|
|
79
79
|
readonly appLLVMIR?: string
|
|
80
80
|
readonly appLazyFunctions?: readonly string[]
|
|
81
|
+
readonly appReferencedSymbols?: ReadonlySet<string>
|
|
82
|
+
readonly appDefinedSymbols?: ReadonlySet<string>
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
class ByteWriter {
|
|
@@ -229,7 +231,11 @@ function rewriteObject(
|
|
|
229
231
|
binding: ((name: string) => string | undefined) | undefined,
|
|
230
232
|
instrumentDynamicLookups: boolean,
|
|
231
233
|
preserveCanonical: ReadonlySet<string>,
|
|
232
|
-
options: {
|
|
234
|
+
options: {
|
|
235
|
+
sdkLookupOnly?: boolean
|
|
236
|
+
sdkProduct?: string
|
|
237
|
+
collectRewrittenSymbols?: { referenced: Set<string>; defined: Set<string> }
|
|
238
|
+
} = {},
|
|
233
239
|
): {
|
|
234
240
|
readonly bytes: Uint8Array
|
|
235
241
|
readonly definitions: readonly ObjectDefinition[]
|
|
@@ -242,7 +248,7 @@ function rewriteObject(
|
|
|
242
248
|
const rawBuf = Buffer.isBuffer(bytes)
|
|
243
249
|
? bytes
|
|
244
250
|
: Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)
|
|
245
|
-
const { sdkLookupOnly, sdkProduct } = options
|
|
251
|
+
const { sdkLookupOnly, sdkProduct, collectRewrittenSymbols } = options
|
|
246
252
|
const comdatScope =
|
|
247
253
|
sdkProduct === undefined ? callerAlias : `${callerAlias}:${sdkProduct}`
|
|
248
254
|
const rewrite = binding !== undefined
|
|
@@ -252,6 +258,9 @@ function rewriteObject(
|
|
|
252
258
|
const definitions: ObjectDefinition[] = []
|
|
253
259
|
const functionImports = new Map<string, FunctionType>()
|
|
254
260
|
const functionImportNames: string[] = []
|
|
261
|
+
const tableImportNames: string[] = []
|
|
262
|
+
const globalImportNames: string[] = []
|
|
263
|
+
const eventImportNames: string[] = []
|
|
255
264
|
const functionSymbols: (string | undefined)[] = []
|
|
256
265
|
const addressTaken = new Set<string>()
|
|
257
266
|
let usesDlsym = false
|
|
@@ -378,18 +387,24 @@ function rewriteObject(
|
|
|
378
387
|
if (isDlsym) usesDlsym = true
|
|
379
388
|
if (isDlerror) usesDlerror = true
|
|
380
389
|
if (importWriter && binding) {
|
|
390
|
+
const rewrittenName = isDlsym
|
|
391
|
+
? callerAlias
|
|
392
|
+
: isDlerror
|
|
393
|
+
? dlerrorAlias
|
|
394
|
+
: module === 'env' && name !== 'dlsym' && name !== 'dlerror'
|
|
395
|
+
? (binding(name) ?? name)
|
|
396
|
+
: name
|
|
381
397
|
importWriter.string(module)
|
|
382
|
-
importWriter.string(
|
|
383
|
-
isDlsym
|
|
384
|
-
? callerAlias
|
|
385
|
-
: isDlerror
|
|
386
|
-
? dlerrorAlias
|
|
387
|
-
: module === 'env' && name !== 'dlsym' && name !== 'dlerror'
|
|
388
|
-
? (binding(name) ?? name)
|
|
389
|
-
: name,
|
|
390
|
-
)
|
|
398
|
+
importWriter.string(rewrittenName)
|
|
391
399
|
importWriter.byte(kind)
|
|
392
400
|
importWriter.bytes(bytes, typeStart, offset)
|
|
401
|
+
if (collectRewrittenSymbols) {
|
|
402
|
+
if (kind === 0)
|
|
403
|
+
functionImportNames[functionImportNames.length - 1] = rewrittenName
|
|
404
|
+
else if (kind === 1) tableImportNames.push(rewrittenName)
|
|
405
|
+
else if (kind === 3) globalImportNames.push(rewrittenName)
|
|
406
|
+
else if (kind === 4) eventImportNames.push(rewrittenName)
|
|
407
|
+
}
|
|
393
408
|
}
|
|
394
409
|
}
|
|
395
410
|
if (offset !== end) throw new Error('invalid wasm import section')
|
|
@@ -492,6 +507,8 @@ function rewriteObject(
|
|
|
492
507
|
if (!rewrite && flags & 16 && symbolKind === 1 && alias)
|
|
493
508
|
usedSymbols.add(name)
|
|
494
509
|
if (entryWriter && binding) {
|
|
510
|
+
let rewrittenSym = name
|
|
511
|
+
let addedCanonical: string | undefined
|
|
495
512
|
if (
|
|
496
513
|
((name === 'dlsym' && usesDlsym) ||
|
|
497
514
|
(name === 'dlerror' && usesDlerror)) &&
|
|
@@ -499,8 +516,9 @@ function rewriteObject(
|
|
|
499
516
|
flags & 64 &&
|
|
500
517
|
symbolKind === 0
|
|
501
518
|
) {
|
|
519
|
+
rewrittenSym = name === 'dlsym' ? callerAlias : dlerrorAlias
|
|
502
520
|
entryWriter.bytes(bytes, begin, nameStart)
|
|
503
|
-
entryWriter.string(
|
|
521
|
+
entryWriter.string(rewrittenSym)
|
|
504
522
|
entryWriter.bytes(bytes, nameEnd, offset)
|
|
505
523
|
} else if (
|
|
506
524
|
flags & 16 &&
|
|
@@ -508,8 +526,9 @@ function rewriteObject(
|
|
|
508
526
|
name !== 'dlerror' &&
|
|
509
527
|
binding(name) !== undefined
|
|
510
528
|
) {
|
|
529
|
+
rewrittenSym = binding(name)!
|
|
511
530
|
entryWriter.bytes(bytes, begin, nameStart)
|
|
512
|
-
entryWriter.string(
|
|
531
|
+
entryWriter.string(rewrittenSym)
|
|
513
532
|
entryWriter.bytes(bytes, nameEnd, offset)
|
|
514
533
|
} else if (alias && !(flags & 16) && (flags & 3) !== 2) {
|
|
515
534
|
if (symbolKind !== 0 && symbolKind !== 1)
|
|
@@ -524,7 +543,9 @@ function rewriteObject(
|
|
|
524
543
|
extraWriter.string(alias)
|
|
525
544
|
extraWriter.bytes(bytes, nameEnd, offset)
|
|
526
545
|
added++
|
|
546
|
+
addedCanonical = alias
|
|
527
547
|
} else {
|
|
548
|
+
rewrittenSym = alias
|
|
528
549
|
entryWriter.bytes(bytes, begin, nameStart)
|
|
529
550
|
entryWriter.string(alias)
|
|
530
551
|
entryWriter.bytes(bytes, nameEnd, offset)
|
|
@@ -532,6 +553,27 @@ function rewriteObject(
|
|
|
532
553
|
} else {
|
|
533
554
|
entryWriter.bytes(bytes, begin, offset)
|
|
534
555
|
}
|
|
556
|
+
if (collectRewrittenSymbols) {
|
|
557
|
+
if (flags & 16) {
|
|
558
|
+
const resolved =
|
|
559
|
+
flags & 64 || symbolKind === 1
|
|
560
|
+
? rewrittenSym
|
|
561
|
+
: symbolKind === 0
|
|
562
|
+
? (functionImportNames[index] ?? '')
|
|
563
|
+
: symbolKind === 2
|
|
564
|
+
? (globalImportNames[index] ?? '')
|
|
565
|
+
: symbolKind === 4
|
|
566
|
+
? (eventImportNames[index] ?? '')
|
|
567
|
+
: symbolKind === 5
|
|
568
|
+
? (tableImportNames[index] ?? '')
|
|
569
|
+
: ''
|
|
570
|
+
if (resolved) collectRewrittenSymbols.referenced.add(resolved)
|
|
571
|
+
} else if ((flags & 3) !== 2) {
|
|
572
|
+
if (rewrittenSym) collectRewrittenSymbols.defined.add(rewrittenSym)
|
|
573
|
+
if (addedCanonical)
|
|
574
|
+
collectRewrittenSymbols.defined.add(addedCanonical)
|
|
575
|
+
}
|
|
576
|
+
}
|
|
535
577
|
} else if (alias && !(flags & 16) && (flags & 3) !== 2) {
|
|
536
578
|
if (symbolKind !== 0 && symbolKind !== 1)
|
|
537
579
|
throw new Error(`unsupported symbol ${name}`)
|
|
@@ -947,6 +989,9 @@ export function createGuestImageLedger(input: GuestImageLedgerInput): GuestImage
|
|
|
947
989
|
sdkGlobalBindings.set(name, first.alias)
|
|
948
990
|
}
|
|
949
991
|
}
|
|
992
|
+
const appSymbols = input.registerAppTables
|
|
993
|
+
? { referenced: new Set<string>(), defined: new Set<string>() }
|
|
994
|
+
: undefined
|
|
950
995
|
const objects = units.map(({ image, object, aliases, functionImports }) => {
|
|
951
996
|
const shared = sharedLookupByImage.get(image)!
|
|
952
997
|
const own = startup.get(object.path)
|
|
@@ -992,7 +1037,11 @@ export function createGuestImageLedger(input: GuestImageLedgerInput): GuestImage
|
|
|
992
1037
|
binding,
|
|
993
1038
|
object.instrumentDynamicLookups,
|
|
994
1039
|
preserveCanonical,
|
|
995
|
-
{
|
|
1040
|
+
{
|
|
1041
|
+
sdkProduct: object.sdkProduct,
|
|
1042
|
+
collectRewrittenSymbols:
|
|
1043
|
+
object.sdkProduct === undefined ? appSymbols : undefined,
|
|
1044
|
+
},
|
|
996
1045
|
).bytes,
|
|
997
1046
|
}
|
|
998
1047
|
})
|
|
@@ -1150,6 +1199,8 @@ export function createGuestImageLedger(input: GuestImageLedgerInput): GuestImage
|
|
|
1150
1199
|
lazyFunctions: lazy,
|
|
1151
1200
|
appLLVMIR: appLazy && render(true, appLazy),
|
|
1152
1201
|
appLazyFunctions: appLazy,
|
|
1202
|
+
appReferencedSymbols: appSymbols?.referenced,
|
|
1203
|
+
appDefinedSymbols: appSymbols?.defined,
|
|
1153
1204
|
}
|
|
1154
1205
|
}
|
|
1155
1206
|
|
package/src/swift-guest-link.ts
CHANGED
|
@@ -103,6 +103,8 @@ export interface GuestSplitInputs {
|
|
|
103
103
|
readonly lazyFunctions: readonly string[]
|
|
104
104
|
/** each app dlsym row's name and image, in linked value order. */
|
|
105
105
|
readonly dyldSymbols: readonly { name: string; image: number }[]
|
|
106
|
+
readonly appReferencedSymbols?: ReadonlySet<string>
|
|
107
|
+
readonly appDefinedSymbols?: ReadonlySet<string>
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
/** The planner supplies source metadata, never post-link region shapes. */
|
|
@@ -640,6 +642,7 @@ export function linkGuestImages(
|
|
|
640
642
|
string,
|
|
641
643
|
{ image: number; product: string; identity: string }
|
|
642
644
|
>()
|
|
645
|
+
const finalArchives = new Map<string, ReturnType<typeof readArMembers>>()
|
|
643
646
|
for (const [index, artifact] of plan.artifacts.entries()) {
|
|
644
647
|
const prefix = `${artifact.path}(`
|
|
645
648
|
if (artifact.kind === 'object') {
|
|
@@ -698,6 +701,10 @@ export function linkGuestImages(
|
|
|
698
701
|
const response = path.join(memberDir, 'members.rsp')
|
|
699
702
|
fs.writeFileSync(response, inputs.map((input) => JSON.stringify(input)).join(' '))
|
|
700
703
|
execFileSync(llvmAr, ['rcs', output, `@${response}`], { stdio: 'pipe' })
|
|
704
|
+
finalArchives.set(
|
|
705
|
+
output,
|
|
706
|
+
members.map((member) => ({ name: member.name, bytes: new Uint8Array(0) })),
|
|
707
|
+
)
|
|
701
708
|
replacements.set(artifact.path, output)
|
|
702
709
|
}
|
|
703
710
|
const compileLedger = (name: string, source: string) => {
|
|
@@ -850,6 +857,7 @@ export function linkGuestImages(
|
|
|
850
857
|
finalArgs,
|
|
851
858
|
fs.readFileSync(finalWhy, 'utf8'),
|
|
852
859
|
finalTrace,
|
|
860
|
+
finalArchives,
|
|
853
861
|
)
|
|
854
862
|
const original = new Map([...replacements].map(([before, after]) => [after, before]))
|
|
855
863
|
const key = (item: GuestLinkSelection) =>
|
|
@@ -882,12 +890,25 @@ export function linkGuestImages(
|
|
|
882
890
|
]),
|
|
883
891
|
)
|
|
884
892
|
appObjects.set(appLedgerObject, options.ledgerDataImage)
|
|
893
|
+
let appReferencedSymbols: ReadonlySet<string> | undefined
|
|
894
|
+
let appDefinedSymbols: ReadonlySet<string> | undefined
|
|
895
|
+
if (ledger.appReferencedSymbols && ledger.appDefinedSymbols) {
|
|
896
|
+
const referenced = new Set(ledger.appReferencedSymbols)
|
|
897
|
+
const defined = new Set(ledger.appDefinedSymbols)
|
|
898
|
+
const ledgerSyms = guestWasmSymbols(fs.readFileSync(appLedgerObject))
|
|
899
|
+
for (const name of ledgerSyms.undefined) referenced.add(name)
|
|
900
|
+
for (const name of ledgerSyms.defined) defined.add(name)
|
|
901
|
+
appReferencedSymbols = referenced
|
|
902
|
+
appDefinedSymbols = defined
|
|
903
|
+
}
|
|
885
904
|
options.onSplitInputs({
|
|
886
905
|
appObjects,
|
|
887
906
|
appSections,
|
|
888
907
|
sdkObjects,
|
|
889
908
|
lazyFunctions: ledger.appLazyFunctions ?? [],
|
|
890
909
|
dyldSymbols: ledger.dyldSymbols,
|
|
910
|
+
appReferencedSymbols,
|
|
911
|
+
appDefinedSymbols,
|
|
891
912
|
})
|
|
892
913
|
}
|
|
893
914
|
return selected
|
|
@@ -98,6 +98,29 @@ export function selectedGuestManifestInputs(
|
|
|
98
98
|
return images
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
const framedLinkOptionsCache = new WeakMap<readonly string[], Buffer>()
|
|
102
|
+
|
|
103
|
+
function framedLinkOptions(options: readonly string[]): Buffer {
|
|
104
|
+
const cached = framedLinkOptionsCache.get(options)
|
|
105
|
+
if (cached) return cached
|
|
106
|
+
const parts: Buffer[] = new Array(options.length * 2 + 2)
|
|
107
|
+
const count = Buffer.from(String(options.length), 'utf8')
|
|
108
|
+
const countSize = Buffer.allocUnsafe(8)
|
|
109
|
+
countSize.writeBigUInt64BE(BigInt(count.byteLength))
|
|
110
|
+
parts[0] = countSize
|
|
111
|
+
parts[1] = count
|
|
112
|
+
for (let i = 0; i < options.length; i++) {
|
|
113
|
+
const encoded = Buffer.from(options[i]!, 'utf8')
|
|
114
|
+
const size = Buffer.allocUnsafe(8)
|
|
115
|
+
size.writeBigUInt64BE(BigInt(encoded.byteLength))
|
|
116
|
+
parts[i * 2 + 2] = size
|
|
117
|
+
parts[i * 2 + 3] = encoded
|
|
118
|
+
}
|
|
119
|
+
const framed = Buffer.concat(parts)
|
|
120
|
+
framedLinkOptionsCache.set(options, framed)
|
|
121
|
+
return framed
|
|
122
|
+
}
|
|
123
|
+
|
|
101
124
|
/** Build the manifest after selection and final address assignment. */
|
|
102
125
|
export function createGuestImageManifest(
|
|
103
126
|
image: GuestManifestImage,
|
|
@@ -110,12 +133,12 @@ export function createGuestImageManifest(
|
|
|
110
133
|
cpuSubtype: 0,
|
|
111
134
|
} satisfies SwiftGuestImageManifest['target']
|
|
112
135
|
const digest = createHash('sha256')
|
|
136
|
+
const sizeBuf = Buffer.allocUnsafe(8)
|
|
113
137
|
// length framing distinguishes different sequences without relying on a
|
|
114
138
|
// separator that an input name, compiler option, or object can contain.
|
|
115
139
|
const add = (bytes: Uint8Array) => {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
digest.update(size)
|
|
140
|
+
sizeBuf.writeBigUInt64BE(BigInt(bytes.byteLength))
|
|
141
|
+
digest.update(sizeBuf)
|
|
119
142
|
digest.update(bytes)
|
|
120
143
|
}
|
|
121
144
|
const text = (value: string) => add(Buffer.from(value, 'utf8'))
|
|
@@ -132,8 +155,7 @@ export function createGuestImageManifest(
|
|
|
132
155
|
`${version.platform}:${version.minimum.major}:${version.minimum.minor}:${version.minimum.patch}`,
|
|
133
156
|
)
|
|
134
157
|
text(`${version.sdk.major}:${version.sdk.minor}:${version.sdk.patch}`)
|
|
135
|
-
|
|
136
|
-
for (const option of image.linkOptions) text(option)
|
|
158
|
+
digest.update(framedLinkOptions(image.linkOptions))
|
|
137
159
|
text(String(image.inputs.length))
|
|
138
160
|
for (const input of image.inputs) {
|
|
139
161
|
text(input.identity)
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
type GuestSourceArtifact,
|
|
18
18
|
} from './swift-guest-source-plan'
|
|
19
19
|
import { frameworkRuntimeProductId } from './swift-runtime-products'
|
|
20
|
+
import { readArMembers } from './swift-wasm-prune'
|
|
20
21
|
import type { SwiftSourceLinkGraph } from './swiftContract'
|
|
21
22
|
import type {
|
|
22
23
|
GuestFrameworkProvider,
|
|
@@ -461,6 +462,123 @@ export function sourceGuestInputIdentities(
|
|
|
461
462
|
return identities
|
|
462
463
|
}
|
|
463
464
|
|
|
465
|
+
function wasmAutolinkEntries(bytes: Uint8Array, out: string[]): boolean {
|
|
466
|
+
if (bytes.length < 8) return false
|
|
467
|
+
if (
|
|
468
|
+
bytes[0] === 0x21 &&
|
|
469
|
+
bytes[1] === 0x3c &&
|
|
470
|
+
bytes[2] === 0x61 &&
|
|
471
|
+
bytes[3] === 0x72 &&
|
|
472
|
+
bytes[4] === 0x63 &&
|
|
473
|
+
bytes[5] === 0x68 &&
|
|
474
|
+
bytes[6] === 0x3e &&
|
|
475
|
+
bytes[7] === 0x0a
|
|
476
|
+
) {
|
|
477
|
+
for (const member of readArMembers(bytes)) {
|
|
478
|
+
if (!wasmAutolinkEntries(member.bytes, out)) return false
|
|
479
|
+
}
|
|
480
|
+
return true
|
|
481
|
+
}
|
|
482
|
+
if (bytes[0] !== 0x00 || bytes[1] !== 0x61 || bytes[2] !== 0x73 || bytes[3] !== 0x6d)
|
|
483
|
+
return false
|
|
484
|
+
const raw = Buffer.isBuffer(bytes)
|
|
485
|
+
? bytes
|
|
486
|
+
: Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)
|
|
487
|
+
let pos = 8
|
|
488
|
+
const len = bytes.length
|
|
489
|
+
while (pos < len) {
|
|
490
|
+
const id = bytes[pos++]!
|
|
491
|
+
let sz = bytes[pos++]!
|
|
492
|
+
if (sz >= 128) {
|
|
493
|
+
sz &= 0x7f
|
|
494
|
+
let shift = 7
|
|
495
|
+
while (true) {
|
|
496
|
+
const b = bytes[pos++]!
|
|
497
|
+
sz |= (b & 0x7f) << shift
|
|
498
|
+
if (b < 128) break
|
|
499
|
+
shift += 7
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
const end = pos + sz
|
|
503
|
+
if (id === 0) {
|
|
504
|
+
let nLen = bytes[pos++]!
|
|
505
|
+
if (nLen >= 128) {
|
|
506
|
+
nLen &= 0x7f
|
|
507
|
+
let shift = 7
|
|
508
|
+
while (true) {
|
|
509
|
+
const b = bytes[pos++]!
|
|
510
|
+
nLen |= (b & 0x7f) << shift
|
|
511
|
+
if (b < 128) break
|
|
512
|
+
shift += 7
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
if (
|
|
516
|
+
nLen === 24 &&
|
|
517
|
+
raw.toString('ascii', pos, pos + 24) === '.swift1_autolink_entries'
|
|
518
|
+
) {
|
|
519
|
+
const payload = raw.toString('utf8', pos + 24, end)
|
|
520
|
+
for (const entry of payload.split('\0')) {
|
|
521
|
+
const trimmed = entry.trim()
|
|
522
|
+
if (trimmed.length > 0) out.push(trimmed)
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
pos = end
|
|
527
|
+
}
|
|
528
|
+
return true
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
function readAutolinkFlags(
|
|
532
|
+
objects: readonly string[],
|
|
533
|
+
toolchainBin: string,
|
|
534
|
+
responsePath: string,
|
|
535
|
+
): string[] {
|
|
536
|
+
if (!objects.length) return []
|
|
537
|
+
const rawFlags: string[] = []
|
|
538
|
+
for (const file of objects) {
|
|
539
|
+
// non-wasm inputs (e.g. llvm bitcode) still defer to swift-autolink-extract.
|
|
540
|
+
if (!wasmAutolinkEntries(readFileSync(file), rawFlags)) {
|
|
541
|
+
writeFileSync(
|
|
542
|
+
responsePath,
|
|
543
|
+
objects.map((entry) => JSON.stringify(entry)).join('\n') + '\n',
|
|
544
|
+
)
|
|
545
|
+
return execFileSync(
|
|
546
|
+
path.join(toolchainBin, 'swift-autolink-extract'),
|
|
547
|
+
[`@${responsePath}`, '-o', '-'],
|
|
548
|
+
{ encoding: 'utf8' },
|
|
549
|
+
)
|
|
550
|
+
.split('\n')
|
|
551
|
+
.map((line) => line.trim())
|
|
552
|
+
.filter((line) => line.length > 0)
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
const seen = new Set<string>()
|
|
556
|
+
const flags: string[] = []
|
|
557
|
+
for (let i = 0; i < rawFlags.length; i++) {
|
|
558
|
+
const flag = rawFlags[i]!
|
|
559
|
+
if (
|
|
560
|
+
(flag === '-framework' ||
|
|
561
|
+
flag === '-weak_framework' ||
|
|
562
|
+
flag === '-l' ||
|
|
563
|
+
flag === '--library') &&
|
|
564
|
+
i + 1 < rawFlags.length
|
|
565
|
+
) {
|
|
566
|
+
const value = rawFlags[++i]!
|
|
567
|
+
const key = `${flag}\0${value}`
|
|
568
|
+
if (!seen.has(key)) {
|
|
569
|
+
seen.add(key)
|
|
570
|
+
flags.push(flag, value)
|
|
571
|
+
}
|
|
572
|
+
continue
|
|
573
|
+
}
|
|
574
|
+
if (!seen.has(flag)) {
|
|
575
|
+
seen.add(flag)
|
|
576
|
+
flags.push(flag)
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
return flags
|
|
580
|
+
}
|
|
581
|
+
|
|
464
582
|
/** resolve actual per-image autolinks through producer-declared aliases only. */
|
|
465
583
|
export function sourceGuestRuntimeLinks(options: {
|
|
466
584
|
toolchainBin: string
|
|
@@ -597,20 +715,7 @@ export function sourceGuestRuntimeLinks(options: {
|
|
|
597
715
|
for (const image of options.images) {
|
|
598
716
|
if (result.has(image.id)) throw new Error(`duplicate source image ${image.id}`)
|
|
599
717
|
const response = path.join(options.directory, `image-${image.id}-autolink.rsp`)
|
|
600
|
-
|
|
601
|
-
response,
|
|
602
|
-
image.objects.map((file) => JSON.stringify(file)).join('\n') + '\n',
|
|
603
|
-
)
|
|
604
|
-
const autolink = image.objects.length
|
|
605
|
-
? execFileSync(
|
|
606
|
-
path.join(options.toolchainBin, 'swift-autolink-extract'),
|
|
607
|
-
[`@${response}`, '-o', '-'],
|
|
608
|
-
{ encoding: 'utf8' },
|
|
609
|
-
)
|
|
610
|
-
.split('\n')
|
|
611
|
-
.map((line) => line.trim())
|
|
612
|
-
.filter((line) => line.length > 0)
|
|
613
|
-
: []
|
|
718
|
+
const autolink = readAutolinkFlags(image.objects, options.toolchainBin, response)
|
|
614
719
|
const links: string[] = []
|
|
615
720
|
const requests: GuestFrameworkRequest[] = []
|
|
616
721
|
const optionGroups = [
|