peachsim 0.1.2595 → 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.
Files changed (139) hide show
  1. package/dist-lib/agent-daemon-client.cjs +1 -1
  2. package/dist-lib/agent-events.cjs +1 -1
  3. package/dist-lib/attached-projects.cjs +1 -1
  4. package/dist-lib/auth/shared-session.cjs +1 -1
  5. package/dist-lib/backend-origin.cjs +1 -1
  6. package/dist-lib/beta.cjs +1 -1
  7. package/dist-lib/beta.mjs +2 -2
  8. package/dist-lib/bridge-constants.cjs +1 -1
  9. package/dist-lib/bridge-contract-input.cjs +1 -1
  10. package/dist-lib/bridge-contract-input.mjs +5 -5
  11. package/dist-lib/bridge-contract.cjs +1 -1
  12. package/dist-lib/bridge-contract.mjs +3 -3
  13. package/dist-lib/bundle-channel.cjs +982 -431
  14. package/dist-lib/capture-contract.cjs +1 -1
  15. package/dist-lib/capture-contract.mjs +3 -3
  16. package/dist-lib/cloud-contract.cjs +1 -1
  17. package/dist-lib/cloud-contract.mjs +3 -3
  18. package/dist-lib/cloud-test-args.cjs +1 -1
  19. package/dist-lib/cloud-test-args.mjs +2 -2
  20. package/dist-lib/cloud.cjs +1 -1
  21. package/dist-lib/cloud.mjs +7 -7
  22. package/dist-lib/config.cjs +1 -1
  23. package/dist-lib/config.mjs +5 -5
  24. package/dist-lib/detox/index.cjs +1 -1
  25. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  26. package/dist-lib/esm-chunks/{acorn-J5DSQG5R.mjs → acorn-55PXV665.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-D4XFTOV2.mjs → chunk-3DRJIOHV.mjs} +1 -1
  28. package/dist-lib/esm-chunks/{chunk-NZEHZIHZ.mjs → chunk-42RIRPTB.mjs} +1 -1
  29. package/dist-lib/esm-chunks/{chunk-CDGSSOLF.mjs → chunk-56YYEI6C.mjs} +16 -13
  30. package/dist-lib/esm-chunks/{chunk-MTGZYNXH.mjs → chunk-7ECUAVIA.mjs} +2 -2
  31. package/dist-lib/esm-chunks/{chunk-YYAPBU4L.mjs → chunk-7J65FNXI.mjs} +1 -1
  32. package/dist-lib/esm-chunks/{chunk-FHFNRCCX.mjs → chunk-AJHFCIEU.mjs} +4 -4
  33. package/dist-lib/esm-chunks/{chunk-G35VGABO.mjs → chunk-CKUEWEY4.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-NCMIX32U.mjs → chunk-DCL2ZEGA.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-3Z2POHJV.mjs → chunk-GECWNEHA.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-BCLZPP3O.mjs → chunk-GRGNTIO7.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-RYCGXYYL.mjs → chunk-GZD5CTG7.mjs} +1 -1
  38. package/dist-lib/esm-chunks/{chunk-5U76J6OF.mjs → chunk-HATXI62T.mjs} +1 -1
  39. package/dist-lib/esm-chunks/{chunk-GCOZNVG7.mjs → chunk-INA4S3MF.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-AEI4FOZK.mjs → chunk-IPN35TGX.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-U4X644Y4.mjs → chunk-LH524OUR.mjs} +3 -3
  42. package/dist-lib/esm-chunks/{chunk-ESKLJRT5.mjs → chunk-MMHNSEZY.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-POM7QBEW.mjs → chunk-NWLCTKBM.mjs} +1 -1
  44. package/dist-lib/esm-chunks/{chunk-ZSJEHQ3R.mjs → chunk-O5FDNHDG.mjs} +1 -1
  45. package/dist-lib/esm-chunks/{chunk-D6RI7LMX.mjs → chunk-ROFBHGEA.mjs} +1 -1
  46. package/dist-lib/esm-chunks/{chunk-LLO2FLAP.mjs → chunk-V6SI2XY7.mjs} +967 -491
  47. package/dist-lib/esm-chunks/{chunk-JVVPCJEO.mjs → chunk-VN7BXTMG.mjs} +5 -5
  48. package/dist-lib/esm-chunks/{chunk-VZY2J2YJ.mjs → chunk-Y4XMEBRN.mjs} +1 -1
  49. package/dist-lib/esm-chunks/{metro-layout-parser-ZHPHHXG3.mjs → metro-layout-parser-5FUYCP6P.mjs} +3 -3
  50. package/dist-lib/esm-chunks/{swift-package-prebuilt-UXU6DFC3.mjs → swift-package-prebuilt-W3VMDYHC.mjs} +10 -10
  51. package/dist-lib/esm-chunks/{swift-sdk-app-module-25XPGJ4P.mjs → swift-sdk-app-module-ZHGBY6T7.mjs} +126 -56
  52. package/dist-lib/esm-chunks/{swift-sdk-image-7JKGAHEW.mjs → swift-sdk-image-2PC4PKHZ.mjs} +14 -14
  53. package/dist-lib/esm-chunks/{swift-sdk-image-producer-KG5I2NUP.mjs → swift-sdk-image-producer-WDN6BXQL.mjs} +4 -4
  54. package/dist-lib/expo-swift-bundle.cjs +981 -430
  55. package/dist-lib/expo-swift-metadata.cjs +1 -1
  56. package/dist-lib/expo-swift-metadata.mjs +7 -7
  57. package/dist-lib/home-paths.cjs +1 -1
  58. package/dist-lib/host/bridge-host.cjs +1019 -434
  59. package/dist-lib/host/fetch-proxy-handler.cjs +36 -6
  60. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  61. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
  62. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  63. package/dist-lib/host/websocket-proxy.cjs +1 -1
  64. package/dist-lib/index.cjs +1 -1
  65. package/dist-lib/kotlin-host.cjs +1 -1
  66. package/dist-lib/menu.cjs +1 -1
  67. package/dist-lib/menu.mjs +3 -3
  68. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  69. package/dist-lib/metro-fingerprint-registry.mjs +3 -3
  70. package/dist-lib/metro-production-bundle.cjs +1 -1
  71. package/dist-lib/metro-production-bundle.mjs +4 -4
  72. package/dist-lib/native-app-identity-project.cjs +34 -4
  73. package/dist-lib/native-app-identity-project.mjs +16 -16
  74. package/dist-lib/native-app-identity.cjs +1 -1
  75. package/dist-lib/native-app-identity.mjs +6 -6
  76. package/dist-lib/native-firebase-metadata.cjs +1 -1
  77. package/dist-lib/native-firebase-metadata.mjs +3 -3
  78. package/dist-lib/pdfium-raster.cjs +1 -1
  79. package/dist-lib/pdfium-raster.mjs +2 -2
  80. package/dist-lib/plist.cjs +1 -1
  81. package/dist-lib/plist.mjs +3 -3
  82. package/dist-lib/profiles.cjs +1 -1
  83. package/dist-lib/public-brand.cjs +1 -1
  84. package/dist-lib/public-origins-lib-esm.json +81 -81
  85. package/dist-lib/public-origins-lib.json +69 -69
  86. package/dist-lib/react-native-host-modules.cjs +1 -1
  87. package/dist-lib/react-native-host-modules.mjs +2 -2
  88. package/dist-lib/reap-browser.cjs +1 -1
  89. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  90. package/dist-lib/sdk.cjs +1 -1
  91. package/dist-lib/sdk.mjs +8 -8
  92. package/dist-lib/skills.cjs +1020 -435
  93. package/dist-lib/swift-compile.cjs +979 -428
  94. package/dist-lib/swift-compile.mjs +10 -10
  95. package/dist-lib/swift-package.cjs +1 -1
  96. package/dist-lib/swift-package.mjs +3 -3
  97. package/dist-lib/swift-submit.cjs +1 -1
  98. package/dist-lib/swift-submit.mjs +6 -6
  99. package/dist-lib/swift-svg-raster.cjs +1 -1
  100. package/dist-lib/swift-svg-raster.mjs +2 -2
  101. package/dist-lib/swift-toolchain.cjs +1 -1
  102. package/dist-lib/swift.cjs +1 -1
  103. package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
  104. package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
  105. package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
  106. package/dist-lib/vendor/@xmldom/xmldom.cjs +1 -1
  107. package/dist-lib/vendor/acorn.cjs +1 -1
  108. package/dist-lib/vendor/bplist-parser.cjs +1 -1
  109. package/dist-lib/vendor/ignore.cjs +1 -1
  110. package/dist-lib/vendor/magic-string.cjs +1 -1
  111. package/dist-lib/vendor/plist.cjs +1 -1
  112. package/dist-lib/vendor/smol-toml.cjs +1 -1
  113. package/dist-lib/vendor/stream-json.cjs +1 -1
  114. package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
  115. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
  116. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
  117. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
  118. package/dist-lib/vendor/sucrase.cjs +1 -1
  119. package/dist-lib/vendor/terser.cjs +1 -1
  120. package/dist-lib/vendor/valibot.cjs +1 -1
  121. package/dist-lib/vendor/ws.cjs +1 -1
  122. package/dist-lib/vendor/zod.cjs +1 -1
  123. package/dist-lib/worklet-executable.cjs +1 -1
  124. package/dist-lib/worklet-executable.mjs +3 -3
  125. package/dist-types/packages/peach-engine/src/render-worker/nativeAnimMirrorContract.d.ts +0 -2
  126. package/package.json +1 -1
  127. package/src/one-native-controls-package.ts +32 -1
  128. package/src/swift-compile.ts +421 -175
  129. package/src/swift-guest-compile.ts +16 -0
  130. package/src/swift-guest-image-ledger.ts +65 -14
  131. package/src/swift-guest-link.ts +25 -3
  132. package/src/swift-guest-manifest.ts +27 -5
  133. package/src/swift-guest-source-inputs.ts +119 -14
  134. package/src/swift-sdk-app-module.ts +128 -55
  135. package/src/swift-sdk-image-wasm.ts +76 -39
  136. package/src/swift-sdk-image.ts +13 -9
  137. package/src/swift-wasm-prune.ts +282 -222
  138. package/src/wasm-optimize.ts +1 -1
  139. 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: { sdkLookupOnly?: boolean; sdkProduct?: string } = {},
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(name === 'dlsym' ? callerAlias : dlerrorAlias)
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(binding(name)!)
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
- { sdkProduct: object.sdkProduct },
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
 
@@ -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') {
@@ -661,9 +664,10 @@ export function linkGuestImages(
661
664
  }
662
665
  const members = archives.get(artifact.path)
663
666
  if (!members) continue
664
- const listed = execFileSync(llvmAr, ['t', artifact.path], { encoding: 'utf8' })
665
- .trimEnd()
666
- .split('\n')
667
+ const listing = execFileSync(llvmAr, ['t', artifact.path], {
668
+ encoding: 'utf8',
669
+ }).trimEnd()
670
+ const listed = listing ? listing.split('\n') : []
667
671
  if (
668
672
  listed.length !== members.length ||
669
673
  new Set(listed).size !== listed.length ||
@@ -697,6 +701,10 @@ export function linkGuestImages(
697
701
  const response = path.join(memberDir, 'members.rsp')
698
702
  fs.writeFileSync(response, inputs.map((input) => JSON.stringify(input)).join(' '))
699
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
+ )
700
708
  replacements.set(artifact.path, output)
701
709
  }
702
710
  const compileLedger = (name: string, source: string) => {
@@ -849,6 +857,7 @@ export function linkGuestImages(
849
857
  finalArgs,
850
858
  fs.readFileSync(finalWhy, 'utf8'),
851
859
  finalTrace,
860
+ finalArchives,
852
861
  )
853
862
  const original = new Map([...replacements].map(([before, after]) => [after, before]))
854
863
  const key = (item: GuestLinkSelection) =>
@@ -881,12 +890,25 @@ export function linkGuestImages(
881
890
  ]),
882
891
  )
883
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
+ }
884
904
  options.onSplitInputs({
885
905
  appObjects,
886
906
  appSections,
887
907
  sdkObjects,
888
908
  lazyFunctions: ledger.appLazyFunctions ?? [],
889
909
  dyldSymbols: ledger.dyldSymbols,
910
+ appReferencedSymbols,
911
+ appDefinedSymbols,
890
912
  })
891
913
  }
892
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
- const size = Buffer.alloc(8)
117
- size.writeBigUInt64BE(BigInt(bytes.byteLength))
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
- text(String(image.linkOptions.length))
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
- writeFileSync(
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 = [