peachsim 0.1.2590 → 0.1.2592
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 +4184 -3613
- 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 +2 -2
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/esm-chunks/{acorn-65FNEARV.mjs → acorn-67PU73QE.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-X2EKFONU.mjs → chunk-5FTHILIE.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-ADKUIQXX.mjs → chunk-6DB5FR7S.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-WPDY5IAD.mjs → chunk-CF3MTPMY.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-RGC2JNCL.mjs → chunk-D4LYKRRB.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-EFKDUMB5.mjs → chunk-DFF5XZ5M.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-2GUB5OLB.mjs → chunk-EHRSWFTD.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-NZY4GOG5.mjs → chunk-EITX573K.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-SLPXTLBK.mjs → chunk-EWHA6X3Z.mjs} +5 -5
- package/dist-lib/esm-chunks/{chunk-BZS5SIYK.mjs → chunk-FYXXFYML.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-JG4AANWA.mjs → chunk-GQ3EO2UV.mjs} +107 -6
- package/dist-lib/esm-chunks/{chunk-N2II5SRJ.mjs → chunk-GY6TE4B4.mjs} +4 -4
- package/dist-lib/esm-chunks/{chunk-HZTK7TP5.mjs → chunk-KDI5YYQ6.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-4VCRUQ36.mjs → chunk-L5T3HBPO.mjs} +973 -549
- package/dist-lib/esm-chunks/{chunk-SRFKOU76.mjs → chunk-M4QLI2SY.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-OZJ66CXY.mjs → chunk-PITO2NI2.mjs} +2 -2
- package/dist-lib/esm-chunks/{chunk-5GNGHM5B.mjs → chunk-QSFWBVUO.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-YPPH6F77.mjs → chunk-R3WTQB5J.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-XE3VHAU2.mjs → chunk-RV4ACE6R.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-GBD26EBV.mjs → chunk-SW4PSSTF.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-V5TTEXYO.mjs → chunk-TJZPNFVF.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-WYDRQRJL.mjs → chunk-XSQH4R5E.mjs} +48 -15
- package/dist-lib/esm-chunks/{chunk-462CWTWI.mjs → chunk-XZ3FX3HW.mjs} +1 -1
- package/dist-lib/esm-chunks/{metro-layout-parser-CRI3GMCM.mjs → metro-layout-parser-EX65MARK.mjs} +3 -3
- package/dist-lib/esm-chunks/{swift-package-prebuilt-5XDZ2HZZ.mjs → swift-package-prebuilt-3BPDQVA7.mjs} +10 -10
- package/dist-lib/esm-chunks/{swift-sdk-app-module-6H3G6AXD.mjs → swift-sdk-app-module-CRX6E3TR.mjs} +151 -67
- package/dist-lib/esm-chunks/{swift-sdk-image-WAC7GG2R.mjs → swift-sdk-image-EJD5TPQH.mjs} +14 -14
- package/dist-lib/esm-chunks/{swift-sdk-image-producer-B3L27QTG.mjs → swift-sdk-image-producer-QAZOSLTZ.mjs} +4 -4
- package/dist-lib/expo-swift-bundle.cjs +3555 -2987
- 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 +5981 -4986
- package/dist-lib/host/fetch-proxy-handler.cjs +310 -298
- 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 +238 -223
- package/dist-lib/native-app-identity-project.mjs +17 -17
- 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 +73 -71
- 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 +6603 -5608
- package/dist-lib/swift-compile.cjs +1363 -778
- 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 +12 -6
- 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/engine/native-node-queries.d.ts +1 -0
- package/kotlin/sdk.tar.gz +0 -0
- package/package.json +1 -1
- package/runtime-companion.json +1 -1
- package/src/native-bundles.ts +2 -0
- package/src/one-native-controls-package.ts +141 -31
- package/src/one-sdk/source.ts +2 -1
- package/src/oneSdkContract.ts +13 -2
- package/src/swift-compile.ts +301 -48
- package/src/swift-guest-compile.ts +41 -8
- package/src/swift-guest-link.ts +3 -0
- package/src/swift-guest-source-inputs.ts +158 -30
- package/src/swift-host.ts +88 -16
- package/src/swift-reproducible.ts +16 -2
- package/src/swift-root-lock.ts +77 -5
- package/src/swift-sdk-app-module.ts +146 -59
- package/src/swift-sdk-image.ts +53 -10
- package/src/swift-startup-split.ts +65 -27
- package/src/swift-toolchain.ts +16 -5
- package/src/wasm-lazy-split.ts +46 -40
|
@@ -242,15 +242,18 @@ async function compileSdkForwarders(
|
|
|
242
242
|
index++
|
|
243
243
|
}
|
|
244
244
|
const errno = tls.errno
|
|
245
|
+
let declaredErrno = false
|
|
245
246
|
for (const name of referenced) {
|
|
246
247
|
const offset = tls[name]
|
|
247
248
|
if (offset === undefined || defined.has(name)) continue
|
|
248
249
|
if (errno === undefined || signatures.__errno_location !== ':j')
|
|
249
250
|
throw new Error('the sdk image has no errno to find its thread block by')
|
|
250
|
-
if (!
|
|
251
|
+
if (!declaredErrno) {
|
|
252
|
+
declaredErrno = true
|
|
251
253
|
lines.push(
|
|
252
254
|
`__attribute__((import_module("env"), import_name("__errno_location"))) char *__peach_errno(void);`,
|
|
253
255
|
)
|
|
256
|
+
}
|
|
254
257
|
// the sdk's thread block starts errno's offset below errno
|
|
255
258
|
lines.push(
|
|
256
259
|
`__attribute__((weak)) _Thread_local char t${index} __asm__(${literal(name)});`,
|
|
@@ -717,6 +720,20 @@ function resolveSdkReferences(
|
|
|
717
720
|
.map((symbol) => [symbol.name.slice(SDK_TLS_HELPER.length), symbol.index]),
|
|
718
721
|
)
|
|
719
722
|
const segments = guestWasmDataSegments(bytes, false)
|
|
723
|
+
const segmentsByOffset = [...segments].sort((a, b) => a.offset - b.offset)
|
|
724
|
+
const segmentNameSet = new Set(segmentNames)
|
|
725
|
+
const findSegmentByOffset = (at: number, size: number) => {
|
|
726
|
+
let lo = 0
|
|
727
|
+
let hi = segmentsByOffset.length - 1
|
|
728
|
+
while (lo <= hi) {
|
|
729
|
+
const mid = (lo + hi) >> 1
|
|
730
|
+
const entry = segmentsByOffset[mid]!
|
|
731
|
+
if (at < entry.offset) hi = mid - 1
|
|
732
|
+
else if (at >= entry.offset + entry.length) lo = mid + 1
|
|
733
|
+
else return at + size <= entry.offset + entry.length ? entry : undefined
|
|
734
|
+
}
|
|
735
|
+
return undefined
|
|
736
|
+
}
|
|
720
737
|
const tdata = segmentNames.indexOf('.tdata')
|
|
721
738
|
const tlsTemplate = tdata < 0 ? undefined : passiveSegments(bytes)[tdata]
|
|
722
739
|
const tlsStart = tlsTemplate && tlsTemplate.byteOffset - bytes.byteOffset
|
|
@@ -789,7 +806,7 @@ function resolveSdkReferences(
|
|
|
789
806
|
const encoding = width.width
|
|
790
807
|
if (kind === 'address' && target.id === 11 && encoding === 'u64' && addend === 0n) {
|
|
791
808
|
const section = OBJC_SECTION_BOUNDARY.exec(name)?.[1]
|
|
792
|
-
if (section && !
|
|
809
|
+
if (section && !segmentNameSet.has(section)) {
|
|
793
810
|
// objc's app initializer uses a null range for an absent app section.
|
|
794
811
|
bytes.fill(0, at, at + 8)
|
|
795
812
|
continue
|
|
@@ -806,9 +823,7 @@ function resolveSdkReferences(
|
|
|
806
823
|
)
|
|
807
824
|
linkage.tls.push(at - tlsStart, size, value)
|
|
808
825
|
else {
|
|
809
|
-
const segment =
|
|
810
|
-
(entry) => at >= entry.offset && at + size <= entry.offset + entry.length,
|
|
811
|
-
)
|
|
826
|
+
const segment = findSegmentByOffset(at, size)
|
|
812
827
|
if (!segment)
|
|
813
828
|
throw new Error(`Swift SDK relocation has no load address for ${name}`)
|
|
814
829
|
linkage.data.push(segment.address + at - segment.offset, size, value)
|
|
@@ -855,18 +870,32 @@ function resolveSdkReferences(
|
|
|
855
870
|
}
|
|
856
871
|
}
|
|
857
872
|
}
|
|
858
|
-
const
|
|
873
|
+
const encodedNameBuf = (name: string): Buffer => {
|
|
874
|
+
const raw = Buffer.from(name, 'utf8')
|
|
875
|
+
const len = uleb(raw.length)
|
|
876
|
+
const out = Buffer.allocUnsafe(len.length + raw.length)
|
|
877
|
+
for (let i = 0; i < len.length; i++) out[i] = len[i]!
|
|
878
|
+
raw.copy(out, len.length)
|
|
879
|
+
return out
|
|
880
|
+
}
|
|
881
|
+
const importParts: Uint8Array[] = []
|
|
882
|
+
let importEntryCount = imports.length + 1
|
|
883
|
+
for (const entry of imports) {
|
|
859
884
|
const slot =
|
|
860
885
|
entry.kind === 0 && entry.module === 'env'
|
|
861
886
|
? functionSlots.get(entry.name)
|
|
862
887
|
: undefined
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
}
|
|
869
|
-
|
|
888
|
+
importParts.push(
|
|
889
|
+
encodedNameBuf(slot === undefined ? entry.module : NATIVE_SDK_IMPORT_MODULE),
|
|
890
|
+
encodedNameBuf(slot === undefined ? entry.name : String(slot)),
|
|
891
|
+
bytes.subarray(entry.start, entry.end),
|
|
892
|
+
)
|
|
893
|
+
}
|
|
894
|
+
importParts.push(
|
|
895
|
+
encodedNameBuf('env'),
|
|
896
|
+
encodedNameBuf('__stack_pointer'),
|
|
897
|
+
Buffer.from([3, 0x7e, 1]),
|
|
898
|
+
)
|
|
870
899
|
const tags = sections.find((section) => section.id === 13)
|
|
871
900
|
if (tags) {
|
|
872
901
|
const r = wasmReader(bytes, tags.start)
|
|
@@ -886,15 +915,18 @@ function resolveSdkReferences(
|
|
|
886
915
|
throw new Error(
|
|
887
916
|
`Swift app defines an exception tag the sdk does not own: ${name}`,
|
|
888
917
|
)
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
4,
|
|
893
|
-
|
|
894
|
-
|
|
918
|
+
importParts.push(
|
|
919
|
+
encodedNameBuf('env'),
|
|
920
|
+
encodedNameBuf(name),
|
|
921
|
+
Buffer.from([4]),
|
|
922
|
+
bytes.subarray(start, r.at),
|
|
923
|
+
)
|
|
924
|
+
importEntryCount++
|
|
895
925
|
}
|
|
896
926
|
}
|
|
897
|
-
const
|
|
927
|
+
const globalParts: Uint8Array[] = [
|
|
928
|
+
Buffer.from(uleb(globalCount - 1 + syntheticGlobals.length)),
|
|
929
|
+
]
|
|
898
930
|
for (let index = 0; index < globalCount; index++) {
|
|
899
931
|
const start = gr.at
|
|
900
932
|
const type = gr.byte()
|
|
@@ -907,8 +939,8 @@ function resolveSdkReferences(
|
|
|
907
939
|
// the first global is __stack_pointer, which becomes the sdk's import
|
|
908
940
|
if (index === 0) continue
|
|
909
941
|
const value = got.get(index)
|
|
910
|
-
if (value === undefined)
|
|
911
|
-
else
|
|
942
|
+
if (value === undefined) globalParts.push(bytes.subarray(start, gr.at))
|
|
943
|
+
else globalParts.push(Buffer.from([type, 1, type === 0x7e ? 0x42 : 0x41, 0, 0x0b]))
|
|
912
944
|
}
|
|
913
945
|
for (const type of syntheticGlobals) {
|
|
914
946
|
const zero =
|
|
@@ -917,7 +949,7 @@ function resolveSdkReferences(
|
|
|
917
949
|
: type === 0x7c
|
|
918
950
|
? [0x44, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
919
951
|
: [type === 0x7e ? 0x42 : 0x41, 0]
|
|
920
|
-
|
|
952
|
+
globalParts.push(Buffer.from([type, 1, ...zero, 0x0b]))
|
|
921
953
|
}
|
|
922
954
|
const exportSection = sections.find((s) => s.id === 7)
|
|
923
955
|
if (!exportSection) throw new Error('app link has no exports')
|
|
@@ -940,24 +972,21 @@ function resolveSdkReferences(
|
|
|
940
972
|
throw new Error('Swift app exceeds its reserved static memory range')
|
|
941
973
|
}
|
|
942
974
|
}
|
|
943
|
-
const
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
0,
|
|
959
|
-
],
|
|
960
|
-
],
|
|
975
|
+
const exportParts: Uint8Array[] = [
|
|
976
|
+
Buffer.from(uleb(exportCount + 1 + got.size)),
|
|
977
|
+
bytes.subarray(originalExportsStart, exportSection.end),
|
|
978
|
+
]
|
|
979
|
+
for (const [index, value] of got) {
|
|
980
|
+
exportParts.push(
|
|
981
|
+
encodedNameBuf(`${NATIVE_SDK_GLOBAL_PREFIX}${value}.${index}`),
|
|
982
|
+
Buffer.from([3, ...uleb(index)]),
|
|
983
|
+
)
|
|
984
|
+
}
|
|
985
|
+
exportParts.push(encodedNameBuf('__indirect_function_table'), Buffer.from([1, 0]))
|
|
986
|
+
const replaced = new Map<number, Buffer>([
|
|
987
|
+
[2, Buffer.concat([Buffer.from(uleb(importEntryCount)), ...importParts])],
|
|
988
|
+
[6, Buffer.concat(globalParts)],
|
|
989
|
+
[7, Buffer.concat(exportParts)],
|
|
961
990
|
])
|
|
962
991
|
const rebuiltCode = expanded.length
|
|
963
992
|
? expandSdkRelocations(
|
|
@@ -976,13 +1005,13 @@ function resolveSdkReferences(
|
|
|
976
1005
|
)
|
|
977
1006
|
continue
|
|
978
1007
|
const payload = replaced.get(s.id)
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
1008
|
+
if (s.id === 10 && rebuiltCode) {
|
|
1009
|
+
parts.push(rebuiltCode)
|
|
1010
|
+
} else if (payload) {
|
|
1011
|
+
parts.push(Buffer.from([s.id, ...uleb(payload.length)]), payload)
|
|
1012
|
+
} else {
|
|
1013
|
+
parts.push(bytes.subarray(s.offset, s.end))
|
|
1014
|
+
}
|
|
986
1015
|
}
|
|
987
1016
|
return { bytes: Buffer.concat(parts), linkage }
|
|
988
1017
|
}
|
|
@@ -1134,6 +1163,54 @@ export function readSwiftSdkUsage(
|
|
|
1134
1163
|
}
|
|
1135
1164
|
}
|
|
1136
1165
|
|
|
1166
|
+
/** SDK address and table spans owned by guest images, independent of app module layout. */
|
|
1167
|
+
export function swiftSdkProjectionSpans(
|
|
1168
|
+
sdk: SwiftSdkImage,
|
|
1169
|
+
imageFor: (object: string, product: string) => number | undefined,
|
|
1170
|
+
): GuestLinkedSpan[] {
|
|
1171
|
+
const { manifest, block } = readSwiftSdkManifest(sdk)
|
|
1172
|
+
const guestObjects = manifest.guestObjects
|
|
1173
|
+
if (!guestObjects) return []
|
|
1174
|
+
const { strings } = manifest
|
|
1175
|
+
const fields = block('pieces')
|
|
1176
|
+
const ordered: { object: string; address: number; size: number }[] = []
|
|
1177
|
+
for (let i = 0; i < fields.length; i += SWIFT_SDK_PIECE_FIELDS) {
|
|
1178
|
+
const size = fields[i + 1]!
|
|
1179
|
+
if (!size) continue
|
|
1180
|
+
ordered.push({
|
|
1181
|
+
address: fields[i]!,
|
|
1182
|
+
size,
|
|
1183
|
+
object: strings[fields[i + 3]!]!,
|
|
1184
|
+
})
|
|
1185
|
+
}
|
|
1186
|
+
ordered.sort((a, b) => a.address - b.address)
|
|
1187
|
+
const imageOf = (object: string) => {
|
|
1188
|
+
const product = guestObjects[object]?.product
|
|
1189
|
+
return product === undefined ? undefined : imageFor(object, product)
|
|
1190
|
+
}
|
|
1191
|
+
const spans: GuestLinkedSpan[] = []
|
|
1192
|
+
for (let index = 0; index < ordered.length; index++) {
|
|
1193
|
+
const { object, address, size } = ordered[index]!
|
|
1194
|
+
const image = imageOf(object)
|
|
1195
|
+
if (image === undefined) continue
|
|
1196
|
+
let next = index + 1
|
|
1197
|
+
while (next < ordered.length && ordered[next]!.address < address + size) next++
|
|
1198
|
+
const end = ordered[next]?.address ?? address + size
|
|
1199
|
+
spans.push({ image, space: 'linear-memory', address, length: end - address })
|
|
1200
|
+
}
|
|
1201
|
+
const functionKeys = block('functions')
|
|
1202
|
+
const slots = block('functionSlots')
|
|
1203
|
+
for (let index = 0; index < functionKeys.length; index++) {
|
|
1204
|
+
const slot = slots[index]!
|
|
1205
|
+
if (!slot) continue
|
|
1206
|
+
const key = strings[functionKeys[index]!]!
|
|
1207
|
+
const image = imageOf(key.slice(0, key.indexOf(':')))
|
|
1208
|
+
if (image !== undefined)
|
|
1209
|
+
spans.push({ image, space: 'function-table', address: slot, length: 1 })
|
|
1210
|
+
}
|
|
1211
|
+
return spans
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1137
1214
|
/**
|
|
1138
1215
|
* the sdk data an app uses, as runs the loader writes before the sdk instantiates: the data
|
|
1139
1216
|
* pieces its pruned link keeps, their transitive dependencies, the live swift record table and
|
|
@@ -1167,18 +1244,31 @@ export function selectSwiftSdkData(
|
|
|
1167
1244
|
})
|
|
1168
1245
|
}
|
|
1169
1246
|
const memory = new Map(segments.map((segment) => [segment.name, segment]))
|
|
1170
|
-
|
|
1247
|
+
let lastSegment = segments[0]
|
|
1248
|
+
const segmentAt = (address: number, size: number) => {
|
|
1249
|
+
if (
|
|
1250
|
+
lastSegment &&
|
|
1251
|
+
address >= lastSegment.address &&
|
|
1252
|
+
address + size <= lastSegment.address + lastSegment.data.length
|
|
1253
|
+
)
|
|
1254
|
+
return lastSegment
|
|
1171
1255
|
for (const segment of segments)
|
|
1172
1256
|
if (
|
|
1173
1257
|
address >= segment.address &&
|
|
1174
1258
|
address + size <= segment.address + segment.data.length
|
|
1175
|
-
)
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
)
|
|
1259
|
+
) {
|
|
1260
|
+
lastSegment = segment
|
|
1261
|
+
return segment
|
|
1262
|
+
}
|
|
1180
1263
|
return undefined
|
|
1181
1264
|
}
|
|
1265
|
+
const read = (address: number, size: number) => {
|
|
1266
|
+
const segment = segmentAt(address, size)
|
|
1267
|
+
return segment?.data.subarray(
|
|
1268
|
+
address - segment.address,
|
|
1269
|
+
address - segment.address + size,
|
|
1270
|
+
)
|
|
1271
|
+
}
|
|
1182
1272
|
const appSectionsByObject = new Map<string, Set<string>>()
|
|
1183
1273
|
const appSections = new Set<string>()
|
|
1184
1274
|
const appSymbols = new Set<string>()
|
|
@@ -1295,10 +1385,7 @@ export function selectSwiftSdkData(
|
|
|
1295
1385
|
const classAddress = Number(
|
|
1296
1386
|
new DataView(field.buffer, field.byteOffset, 8).getBigUint64(0, true),
|
|
1297
1387
|
)
|
|
1298
|
-
const segment =
|
|
1299
|
-
({ address, data }) =>
|
|
1300
|
-
classAddress >= address && classAddress < address + data.length,
|
|
1301
|
-
)
|
|
1388
|
+
const segment = segmentAt(classAddress, 1)
|
|
1302
1389
|
if (!segment) continue
|
|
1303
1390
|
const start = classAddress - segment.address
|
|
1304
1391
|
const end = segment.data.indexOf(0, start)
|
|
@@ -1546,7 +1633,7 @@ export function selectSwiftSdkData(
|
|
|
1546
1633
|
if (current)
|
|
1547
1634
|
runs.push({
|
|
1548
1635
|
address: current.address,
|
|
1549
|
-
bytes:
|
|
1636
|
+
bytes: Buffer.concat(current.parts),
|
|
1550
1637
|
})
|
|
1551
1638
|
}
|
|
1552
1639
|
for (const piece of loaded) {
|
package/src/swift-sdk-image.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
readFileSync,
|
|
8
8
|
renameSync,
|
|
9
9
|
rmSync,
|
|
10
|
+
statSync,
|
|
10
11
|
writeFileSync,
|
|
11
12
|
} from 'node:fs'
|
|
12
13
|
import path from 'node:path'
|
|
@@ -217,24 +218,56 @@ export function swiftSdkImageEntry(key: string, scopedLookups: boolean) {
|
|
|
217
218
|
}
|
|
218
219
|
}
|
|
219
220
|
|
|
221
|
+
// bounded in-memory caches avoid reparsing 70+ MB sdk json across repeated builds in one process.
|
|
222
|
+
const MAX_CACHED_SDK_IMAGES = 4
|
|
223
|
+
const cachedSdkInterfaces = new Map<string, SwiftSdkInterface>()
|
|
224
|
+
const cachedSdkManifestIndices = new Map<string, SwiftSdkManifest>()
|
|
225
|
+
const cachedSdkManifests = new Map<
|
|
226
|
+
string,
|
|
227
|
+
{
|
|
228
|
+
manifest: SwiftSdkManifest
|
|
229
|
+
block: (name: SwiftSdkManifestBlock) => Uint32Array
|
|
230
|
+
segments: Array<SwiftSdkManifest['segments'][number] & { data: Uint8Array }>
|
|
231
|
+
}
|
|
232
|
+
>()
|
|
233
|
+
|
|
234
|
+
function setBoundedCache<T>(cache: Map<string, T>, key: string, value: T): T {
|
|
235
|
+
cache.delete(key)
|
|
236
|
+
cache.set(key, value)
|
|
237
|
+
while (cache.size > MAX_CACHED_SDK_IMAGES) {
|
|
238
|
+
const oldest = cache.keys().next().value
|
|
239
|
+
if (oldest !== undefined) cache.delete(oldest)
|
|
240
|
+
}
|
|
241
|
+
return value
|
|
242
|
+
}
|
|
243
|
+
|
|
220
244
|
function cached(directory: string, key: string): SwiftSdkImage | undefined {
|
|
221
|
-
const
|
|
245
|
+
const sdkInterfacePath = path.join(directory, INTERFACE_FILE)
|
|
222
246
|
const image = path.join(directory, IMAGE_FILE)
|
|
223
247
|
const address = path.join(directory, IMAGE_DIGEST)
|
|
224
248
|
if (
|
|
225
249
|
!existsSync(image) ||
|
|
226
250
|
!existsSync(address) ||
|
|
227
|
-
!existsSync(
|
|
251
|
+
!existsSync(sdkInterfacePath) ||
|
|
228
252
|
!existsSync(path.join(directory, MANIFEST_FILE)) ||
|
|
229
253
|
!existsSync(path.join(directory, MANIFEST_DATA_FILE))
|
|
230
254
|
)
|
|
231
255
|
return undefined
|
|
256
|
+
const sha256 = readFileSync(address, 'utf8')
|
|
257
|
+
const cacheKey = `${directory}\0${sha256}`
|
|
258
|
+
let loadedInterface: SwiftSdkInterface | undefined
|
|
232
259
|
return {
|
|
233
260
|
key,
|
|
234
261
|
directory,
|
|
235
262
|
image,
|
|
236
|
-
sha256
|
|
237
|
-
sdkInterface:
|
|
263
|
+
sha256,
|
|
264
|
+
get sdkInterface(): SwiftSdkInterface {
|
|
265
|
+
if (loadedInterface) return loadedInterface
|
|
266
|
+
const memo = cachedSdkInterfaces.get(cacheKey)
|
|
267
|
+
if (memo) return (loadedInterface = memo)
|
|
268
|
+
const parsed: SwiftSdkInterface = JSON.parse(readFileSync(sdkInterfacePath, 'utf8'))
|
|
269
|
+
return (loadedInterface = setBoundedCache(cachedSdkInterfaces, cacheKey, parsed))
|
|
270
|
+
},
|
|
238
271
|
}
|
|
239
272
|
}
|
|
240
273
|
|
|
@@ -903,18 +936,28 @@ function writeSdkManifest(
|
|
|
903
936
|
export function readSwiftSdkManifestIndex(
|
|
904
937
|
image: Pick<SwiftSdkImage, 'directory'>,
|
|
905
938
|
): SwiftSdkManifest {
|
|
906
|
-
const
|
|
907
|
-
|
|
908
|
-
|
|
939
|
+
const manifestPath = path.join(image.directory, MANIFEST_FILE)
|
|
940
|
+
const stat = statSync(manifestPath, { bigint: true })
|
|
941
|
+
const cacheKey = `${manifestPath}\0${stat.size}:${stat.mtimeNs}`
|
|
942
|
+
const memo = cachedSdkManifestIndices.get(cacheKey)
|
|
943
|
+
if (memo) return memo
|
|
944
|
+
const manifest: SwiftSdkManifest = JSON.parse(readFileSync(manifestPath, 'utf8'))
|
|
909
945
|
if (manifest.version !== SWIFT_SDK_IMAGE_VERSION)
|
|
910
946
|
throw new Error(`sdk manifest version ${manifest.version}`)
|
|
911
|
-
return manifest
|
|
947
|
+
return setBoundedCache(cachedSdkManifestIndices, cacheKey, manifest)
|
|
912
948
|
}
|
|
913
949
|
|
|
914
950
|
/** the manifest of a built sdk image, its u32 blocks and the shipped segments' bytes. */
|
|
915
951
|
export function readSwiftSdkManifest(image: Pick<SwiftSdkImage, 'directory'>) {
|
|
952
|
+
const manifestPath = path.join(image.directory, MANIFEST_FILE)
|
|
953
|
+
const dataPath = path.join(image.directory, MANIFEST_DATA_FILE)
|
|
954
|
+
const mStat = statSync(manifestPath, { bigint: true })
|
|
955
|
+
const dStat = statSync(dataPath, { bigint: true })
|
|
956
|
+
const cacheKey = `${image.directory}\0${mStat.size}:${mStat.mtimeNs}\0${dStat.size}:${dStat.mtimeNs}`
|
|
957
|
+
const memo = cachedSdkManifests.get(cacheKey)
|
|
958
|
+
if (memo) return memo
|
|
916
959
|
const manifest = readSwiftSdkManifestIndex(image)
|
|
917
|
-
const data = readFileSync(
|
|
960
|
+
const data = readFileSync(dataPath)
|
|
918
961
|
const words = new Uint32Array(data.buffer, data.byteOffset, manifest.segmentBytes / 4)
|
|
919
962
|
const blocks = new Map<SwiftSdkManifestBlock, Uint32Array>()
|
|
920
963
|
let at = 0
|
|
@@ -928,7 +971,7 @@ export function readSwiftSdkManifest(image: Pick<SwiftSdkImage, 'directory'>) {
|
|
|
928
971
|
...segment,
|
|
929
972
|
data: data.subarray(segment.bytes, segment.bytes + segment.length),
|
|
930
973
|
}))
|
|
931
|
-
return { manifest, block, segments }
|
|
974
|
+
return setBoundedCache(cachedSdkManifests, cacheKey, { manifest, block, segments })
|
|
932
975
|
}
|
|
933
976
|
|
|
934
977
|
const MANIFEST_BLOCKS: readonly string[] = [
|
|
@@ -34,13 +34,13 @@ import { SWIFT_HMR_PATH, SWIFT_PACKAGE_PATH } from './swift-submit'
|
|
|
34
34
|
import { swiftCacheDir } from './swift-toolchain'
|
|
35
35
|
import {
|
|
36
36
|
instrumentNativeWasm,
|
|
37
|
-
mergeNativeWasmProfiles,
|
|
38
37
|
sealNativeWasmSplit,
|
|
39
38
|
splitNativeWasm,
|
|
40
39
|
} from './wasm-lazy-split'
|
|
41
40
|
import {
|
|
42
41
|
makeWasmFunctionNamesSingleLine,
|
|
43
42
|
readWasmCustomSection,
|
|
43
|
+
readWasmFunctionCount,
|
|
44
44
|
readWasmMemory,
|
|
45
45
|
} from './wasm-narrow-boundary'
|
|
46
46
|
import { installWasmOpt } from './wasm-optimize'
|
|
@@ -181,6 +181,27 @@ export async function splitSwiftApp(
|
|
|
181
181
|
)
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
// canonicalize binaryen wasm-split profiles (8-byte module hash + u32 slots) to a
|
|
185
|
+
// presence bitset (0 or 1 per function) and union them in memory without spawning
|
|
186
|
+
// wasm-split --merge-profiles. identical hot sets always share one cache hash even
|
|
187
|
+
// when execution timestamps differ.
|
|
188
|
+
function mergeProfileBitsets(files: readonly Buffer[]): Buffer {
|
|
189
|
+
const first = files[0]
|
|
190
|
+
if (!first || first.length < 8 || (first.length - 8) % 4 !== 0)
|
|
191
|
+
throw new Error('invalid native startup profile buffer')
|
|
192
|
+
const merged = Buffer.allocUnsafe(first.length)
|
|
193
|
+
first.copy(merged, 0, 0, 8)
|
|
194
|
+
merged.fill(0, 8)
|
|
195
|
+
const header = first.subarray(0, 8)
|
|
196
|
+
for (const file of files) {
|
|
197
|
+
if (file.length !== first.length || !file.subarray(0, 8).equals(header))
|
|
198
|
+
throw new Error('native startup profiles do not match the same sdk image')
|
|
199
|
+
for (let offset = 8; offset < file.length; offset += 4)
|
|
200
|
+
if (file.readUInt32LE(offset) !== 0) merged.writeUInt32LE(1, offset)
|
|
201
|
+
}
|
|
202
|
+
return merged
|
|
203
|
+
}
|
|
204
|
+
|
|
184
205
|
/**
|
|
185
206
|
* splits a shared sdk image by the merged startup of every app profiled on it: each app's
|
|
186
207
|
* profile stays beside the image, and a new app's profile widens the startup file.
|
|
@@ -195,34 +216,40 @@ export async function splitSwiftSdkImage(
|
|
|
195
216
|
const prefix = `${app}-`
|
|
196
217
|
const own = join(profiles, `${prefix}${launch.artifactHash}.profile`)
|
|
197
218
|
const names = () =>
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
219
|
+
existsSync(profiles)
|
|
220
|
+
? readdirSync(profiles)
|
|
221
|
+
.filter((name) => !name.startsWith('.') && name.endsWith('.profile'))
|
|
222
|
+
.sort()
|
|
223
|
+
: []
|
|
201
224
|
const union = () => {
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
225
|
+
const merged = mergeProfileBitsets(
|
|
226
|
+
names().map((name) => readFileSync(join(profiles, name))),
|
|
227
|
+
)
|
|
205
228
|
const cache = join(
|
|
206
229
|
directory,
|
|
207
|
-
`startup-v11-${platform}-${
|
|
230
|
+
`startup-v11-${platform}-${digest(merged).slice(0, 16)}`,
|
|
208
231
|
)
|
|
209
|
-
return {
|
|
232
|
+
return { merged, cache }
|
|
210
233
|
}
|
|
234
|
+
// an existing profile for this normalized app on the same sdk image already covers its
|
|
235
|
+
// startup paths; any newly called sdk function loads lazily on demand.
|
|
211
236
|
const current = () =>
|
|
212
|
-
withSwiftRootLock(profiles, async () =>
|
|
237
|
+
withSwiftRootLock(profiles, async () =>
|
|
238
|
+
names().some((name) => name.startsWith(prefix)) ? union() : undefined,
|
|
239
|
+
)
|
|
213
240
|
const available = await current()
|
|
214
241
|
if (available) {
|
|
215
242
|
const ready = readSwiftStartupImage(available.cache)
|
|
216
243
|
if (ready) return ready
|
|
217
244
|
}
|
|
218
245
|
return withStartupWork(bytes, async (work) => {
|
|
219
|
-
const {
|
|
246
|
+
const { merged, cache } =
|
|
220
247
|
available ??
|
|
221
|
-
(await withSwiftRootLock(
|
|
248
|
+
(await withSwiftRootLock(join(profiles, `${prefix}record`), async () => {
|
|
222
249
|
const alreadyRecorded = await current()
|
|
223
250
|
if (alreadyRecorded) return alreadyRecorded
|
|
224
251
|
const recorded = join(work.directory, 'app.profile')
|
|
225
|
-
await profileStartup(work, launch, 'sdkUrl', recorded)
|
|
252
|
+
await profileStartup(work, launch, 'sdkUrl', recorded, directory)
|
|
226
253
|
return withSwiftRootLock(profiles, async () => {
|
|
227
254
|
mkdirSync(profiles, { recursive: true })
|
|
228
255
|
const pending = join(profiles, `.${prefix}${launch.artifactHash}.profile`)
|
|
@@ -238,15 +265,10 @@ export async function splitSwiftSdkImage(
|
|
|
238
265
|
return withSwiftRootLock(cache, async () => {
|
|
239
266
|
const existing = readSwiftStartupImage(cache)
|
|
240
267
|
if (existing) return existing
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
writeFileSync(input, file)
|
|
244
|
-
return input
|
|
245
|
-
})
|
|
246
|
-
const merged = join(work.directory, 'merged.profile')
|
|
247
|
-
await mergeNativeWasmProfiles(work.binaryen, inputs, merged)
|
|
268
|
+
const mergedPath = join(work.directory, 'merged.profile')
|
|
269
|
+
writeFileSync(mergedPath, merged)
|
|
248
270
|
// an app outside the profiled set misses sdk code, so a miss loads a small part
|
|
249
|
-
return storeStartupSplit(work,
|
|
271
|
+
return storeStartupSplit(work, mergedPath, directory, cache, 1 << 18)
|
|
250
272
|
})
|
|
251
273
|
})
|
|
252
274
|
}
|
|
@@ -280,13 +302,29 @@ async function profileStartup(
|
|
|
280
302
|
launch: SwiftStartupLaunch,
|
|
281
303
|
role: 'url' | 'sdkUrl',
|
|
282
304
|
output: string,
|
|
305
|
+
sharedDirectory?: string,
|
|
283
306
|
) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
instrumented
|
|
288
|
-
|
|
289
|
-
|
|
307
|
+
let instrumented = join(work.directory, 'instrumented.wasm')
|
|
308
|
+
let functionCount: number
|
|
309
|
+
if (sharedDirectory) {
|
|
310
|
+
const cachedInstrumented = join(sharedDirectory, `instrumented-v1-${platform}.wasm`)
|
|
311
|
+
if (!existsSync(cachedInstrumented)) {
|
|
312
|
+
await withSwiftRootLock(cachedInstrumented, async () => {
|
|
313
|
+
if (existsSync(cachedInstrumented)) return
|
|
314
|
+
const pending = join(sharedDirectory, `.instrumented-${process.pid}.wasm`)
|
|
315
|
+
try {
|
|
316
|
+
await instrumentNativeWasm(work.original, pending, work.binaryen)
|
|
317
|
+
renameSync(pending, cachedInstrumented)
|
|
318
|
+
} finally {
|
|
319
|
+
rmSync(pending, { force: true })
|
|
320
|
+
}
|
|
321
|
+
})
|
|
322
|
+
}
|
|
323
|
+
instrumented = cachedInstrumented
|
|
324
|
+
functionCount = readWasmFunctionCount(work.bytes)
|
|
325
|
+
} else {
|
|
326
|
+
functionCount = await instrumentNativeWasm(work.original, instrumented, work.binaryen)
|
|
327
|
+
}
|
|
290
328
|
writeFileSync(
|
|
291
329
|
output,
|
|
292
330
|
await bootSwiftPreview(launch, { instrumented, functionCount, role }),
|
package/src/swift-toolchain.ts
CHANGED
|
@@ -490,7 +490,8 @@ export function swiftToolchainBin(release: string): string {
|
|
|
490
490
|
const dirs = [os.homedir(), '/'].map((base) =>
|
|
491
491
|
path.join(base, `Library/Developer/Toolchains/${release}.xctoolchain/usr/bin`),
|
|
492
492
|
)
|
|
493
|
-
|
|
493
|
+
const found = dirs.find((dir) => fs.existsSync(path.join(dir, 'swift')))
|
|
494
|
+
return found ? fs.realpathSync(found) : dirs[0]!
|
|
494
495
|
}
|
|
495
496
|
if (process.env.CONTRAST_SWIFT_TOOLCHAINS) {
|
|
496
497
|
return path.join(process.env.CONTRAST_SWIFT_TOOLCHAINS, release, 'usr/bin')
|
|
@@ -557,7 +558,11 @@ exec ${JSON.stringify(path.join(toolchainBin, 'wasm-ld'))} "$@"
|
|
|
557
558
|
// home-paths.ts's rnxHomeDir, repeated because this file imports node builtins only.
|
|
558
559
|
export function peachHome(): string {
|
|
559
560
|
const override = process.env.PEACH_HOME
|
|
560
|
-
|
|
561
|
+
if (override) return path.resolve(override)
|
|
562
|
+
const home = path.join(os.homedir(), '.peach')
|
|
563
|
+
// agent profiles symlink ~/.peach to the host user's ~/.peach; canonicalize so
|
|
564
|
+
// swift-sdk-views hashes and llbuild plans match across sessions on one host.
|
|
565
|
+
return fs.existsSync(home) ? fs.realpathSync(home) : home
|
|
561
566
|
}
|
|
562
567
|
|
|
563
568
|
/** where the pinned wasm SDK installs unless PEACH_SWIFT_SDKS_PATH names another. */
|
|
@@ -625,11 +630,17 @@ function buildersRootEnv(): string | null {
|
|
|
625
630
|
return root ? root : null
|
|
626
631
|
}
|
|
627
632
|
|
|
633
|
+
// mac agent sessions without an explicit private PEACH_HOME share the machine's
|
|
634
|
+
// resolved builders cache rather than cold-rebuilding SDK images on internal disk.
|
|
635
|
+
function resolvedBuildersRoot(): string | null {
|
|
636
|
+
return buildersRootEnv() ?? (process.env.PEACH_HOME ? null : agentSharedCacheRoot())
|
|
637
|
+
}
|
|
638
|
+
|
|
628
639
|
// machine-wide swift scratch and package caches, shared across lanes. keep
|
|
629
640
|
// their implementation with the compiler so daemon edits cannot cold-split
|
|
630
641
|
// the twin warm trees. the complete implementation remains a hashed input.
|
|
631
642
|
export function swiftCacheDir(): string {
|
|
632
|
-
const root =
|
|
643
|
+
const root = resolvedBuildersRoot()
|
|
633
644
|
return root ? path.join(root, 'peach-cache') : path.join(peachHome(), 'cache')
|
|
634
645
|
}
|
|
635
646
|
|
|
@@ -647,7 +658,7 @@ export function refreshSwiftCacheHold(directory: string): void {
|
|
|
647
658
|
const [kind, key] = relative.split(path.sep)
|
|
648
659
|
if (!key || kind === '..' || path.isAbsolute(relative)) return
|
|
649
660
|
const entry = path.join(cacheRoot, kind, key)
|
|
650
|
-
if (!
|
|
661
|
+
if (!resolvedBuildersRoot()) {
|
|
651
662
|
const now = new Date()
|
|
652
663
|
fs.utimesSync(entry, now, now)
|
|
653
664
|
return
|
|
@@ -665,7 +676,7 @@ export function refreshSwiftCacheHold(directory: string): void {
|
|
|
665
676
|
}
|
|
666
677
|
|
|
667
678
|
export function hasSwiftCacheHold(directory: string): boolean {
|
|
668
|
-
if (!
|
|
679
|
+
if (!resolvedBuildersRoot()) return false
|
|
669
680
|
const marker = fs.lstatSync(path.join(directory, SWIFT_CACHE_HOLD_MARKER), {
|
|
670
681
|
throwIfNoEntry: false,
|
|
671
682
|
})
|