peachsim 0.1.1728 → 0.1.1744
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/README.md +4 -0
- package/cli/app-catalog.ts +47 -23
- package/cli/app-fonts.ts +19 -1
- package/cli/command-registry.ts +3 -0
- package/cli/commands/control.ts +68 -16
- package/cli/commands/coverage-swift.ts +112 -4
- package/cli/commands/device.ts +3 -1
- package/cli/commands/doctor.ts +1 -4
- package/cli/commands/inspect/settling.ts +6 -1
- package/cli/commands/inspect/wait-ready.ts +22 -2
- package/cli/commands/package.ts +33 -21
- package/cli/commands/push.ts +56 -0
- package/cli/commands/serve.ts +9 -0
- package/cli/commands/shell-url.ts +41 -9
- package/cli/commands/swift.ts +1 -1
- package/cli/current-sim.ts +27 -0
- package/cli/drivers/linux-browser-libs.lock.json +323 -1
- package/cli/drivers/linux-browser-libs.ts +8 -6
- package/cli/drivers/playwright.ts +5 -1
- package/cli/internal-child.ts +11 -1
- package/cli/main.ts +6 -0
- package/cli/native-input.ts +1 -7
- package/cli/outbound-endpoints.ts +9 -1
- package/cli/packaged-app-launcher.ts +3 -1
- package/cli/scene-video.ts +28 -7
- package/cli/ws-bridge.ts +3 -1
- package/detox/index.ts +18 -5
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +5 -2
- package/dist-lib/auth/shared-session.cjs +5 -2
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/bundle-channel.cjs +9932 -4561
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/config.mjs +1 -1
- package/dist-lib/detox/index.cjs +30 -8
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/expo-swift-bundle.cjs +6886 -3303
- package/dist-lib/expo-swift-metadata.cjs +14 -2
- package/dist-lib/expo-swift-metadata.mjs +14 -2
- package/dist-lib/home-paths.cjs +7 -2
- package/dist-lib/host/bridge-host.cjs +8513 -3085
- package/dist-lib/host/fetch-proxy-handler.cjs +19 -7
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +6 -3
- package/dist-lib/index.cjs +175 -80
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +209 -32
- package/dist-lib/menu.cjs +7 -1
- package/dist-lib/menu.mjs +7 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +146 -76
- package/dist-lib/native-app-identity-project.cjs +76 -39
- package/dist-lib/native-app-identity-project.mjs +76 -39
- package/dist-lib/native-app-identity.cjs +10 -3
- package/dist-lib/native-app-identity.mjs +10 -3
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +5 -2
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +25 -23
- package/dist-lib/public-origins-lib.json +138 -80
- package/dist-lib/react-native-host-modules.cjs +5 -2
- package/dist-lib/react-native-host-modules.mjs +5 -2
- package/dist-lib/reap-browser.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +4 -1
- package/dist-lib/sdk.mjs +4 -1
- package/dist-lib/skills.cjs +41126 -36493
- package/dist-lib/swift-compile.cjs +2103 -444
- package/dist-lib/swift-compile.mjs +2025 -369
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +2 -2
- package/dist-lib/swift-submit.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +84 -24
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +6094 -2687
- package/dist-lib/vite.cjs +32 -10
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +1 -1
- package/dist-types/packages/peach-compat/src/stubs/screen-transition-math.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/cli-companion.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/engine/canvaskit-renderer.d.ts +2 -0
- package/dist-types/packages/peach-engine/src/engine/font-config.d.ts +7 -4
- package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +1 -3
- package/dist-types/packages/peach-engine/src/engine/liquid-glass.d.ts +0 -5
- package/dist-types/packages/peach-engine/src/engine/memory-counts.d.ts +8 -0
- package/dist-types/packages/peach-engine/src/engine/node.d.ts +10 -1
- package/dist-types/packages/peach-engine/src/engine/paint-boundary.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/engine/render-damage.d.ts +2 -2
- package/dist-types/packages/peach-engine/src/engine/scene-table.d.ts +25 -3
- package/dist-types/packages/peach-engine/src/engine/scroll-platform.d.ts +1 -15
- package/dist-types/packages/peach-engine/src/engine/scroll.d.ts +1 -3
- package/dist-types/packages/peach-engine/src/engine/text-first-baseline.d.ts +6 -0
- package/dist-types/packages/peach-engine/src/engine/text-paragraph.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/engine/types.d.ts +23 -0
- package/dist-types/packages/peach-engine/src/ios/chrome-metrics.d.ts +6 -0
- package/dist-types/packages/peach-engine/src/metro-identity-contract.d.ts +33 -0
- package/dist-types/packages/peach-engine/src/native-preview-bundle.d.ts +2 -0
- package/dist-types/packages/peach-engine/src/preview/bundle-layout.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/remote-stream/scene-recording.d.ts +2 -0
- package/dist-types/packages/peach-engine/src/render-worker/compositor-gpu.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +2 -0
- package/dist-types/packages/peach-engine/src/render-worker/metro-bundle-metadata.d.ts +28 -0
- package/dist-types/packages/peach-engine/src/render-worker/native-ui-protocol.d.ts +21 -1
- package/dist-types/packages/peach-engine/src/render-worker/prepared-boot-bundle.d.ts +7 -0
- package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +15 -2
- package/dist-types/packages/peach-engine/src/render-worker/scroll-mirror.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/render-worker/shell-protocol.d.ts +6 -0
- package/dist-types/packages/peach-engine/src/render-worker/test-bridge-protocol.d.ts +3 -3
- package/dist-types/packages/peach-engine/src/render-worker/webgpu-frame-transaction.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/render-worker/webgpu-readback-scheduler.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +14 -1
- package/dist-types/packages/peach-engine/src/rolldown-bundle-inventory.d.ts +8 -1
- package/dist-types/packages/peach-engine/src/rolldown-production-fingerprint.d.ts +1 -4
- package/dist-types/packages/peach-engine/src/rolldown-production-module.d.ts +12 -0
- package/dist-types/packages/peach-engine/src/rolldown-production-roles.d.ts +6 -0
- package/dist-types/packages/peach-engine/src/settings/devices.d.ts +6 -1
- package/dist-types/packages/peach-engine/src/settings/duo-fold-bus.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/shell-events.d.ts +4 -0
- package/dist-types/packages/peach-kit/src/capabilities.d.ts +8 -0
- package/kotlin/README.md +3 -0
- package/kotlin/sdk.tar.gz +0 -0
- package/package.json +2 -1
- package/runtime-companion.json +1 -1
- package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccount.h +55 -0
- package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccountCredential.h +35 -0
- package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccountStore.h +94 -0
- package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccountType.h +53 -0
- package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACError.h +37 -0
- package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/Accounts.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/AccountsDefines.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Accounts.framework/Modules/module.modulemap +5 -0
- package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetwork.h +1 -0
- package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetworkErrors.h +257 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFByteOrder.h +305 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h +2 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGAffineTransform.h +204 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGBitmapContext.h +260 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGColor.h +164 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGColorConversionInfo.h +101 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGColorSpace.h +510 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGContext.h +1132 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGConvertColorDataWithFormat.h +34 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGDataConsumer.h +83 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGDataProvider.h +197 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGEXRToneMappingGamma.h +36 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGError.h +38 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGFont.h +312 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGFunction.h +106 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGGradient.h +123 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGITUToneMapping.h +31 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGImage.h +409 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGLayer.h +78 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFArray.h +120 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFContentStream.h +55 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFContext.h +535 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFDictionary.h +133 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFDocument.h +252 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFMarkedContentItem.h +37 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFObject.h +67 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFOperatorTable.h +51 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFPage.h +101 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFScanner.h +123 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFStream.h +44 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFString.h +52 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPDFStructureElement.h +87 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPath.h +441 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGPattern.h +89 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGRenderingBufferProvider.h +49 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGShading.h +124 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CGToneMapping.h +85 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h +44 -252
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Modules/module.modulemap +1 -0
- package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/CFNetworkErrors.h +257 -0
- package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes +58 -9
- package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +992 -98
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/NSURLSession+Network.h +32 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/Network.h +51 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/advertise_descriptor.h +193 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/browse_descriptor.h +163 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/browse_result.h +207 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/browser.h +285 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/connection.h +714 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/connection_group.h +629 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/connection_report.h +932 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/content_context.h +229 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/endpoint.h +390 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/error.h +135 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/ethernet_channel.h +349 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/framer_options.h +1187 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/group_descriptor.h +184 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/interface.h +150 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/ip_options.h +351 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/listener.h +438 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/nw_object.h +200 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/parameters.h +1205 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/path.h +392 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/path_monitor.h +216 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/privacy_context.h +188 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/protocol_options.h +126 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/proxy_config.h +357 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/quic_options.h +889 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/resolver_config.h +94 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/tcp_options.h +459 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/tls_options.h +115 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/txt_record.h +432 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/udp_options.h +112 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Headers/ws_options.h +743 -0
- package/sdk/ios/System/Library/Frameworks/Network.framework/Modules/module.modulemap +9 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAAnimation.h +395 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CABase.h +132 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CADisplayLink.h +107 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAEmitterCell.h +153 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAEmitterLayer.h +151 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAFrameRateRange.h +40 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAGradientLayer.h +78 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CALayer.h +1078 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAMediaTiming.h +97 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAMediaTimingFunction.h +67 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAReplicatorLayer.h +65 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAScrollLayer.h +64 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAShapeLayer.h +135 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CATextLayer.h +99 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CATiledLayer.h +67 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CATransaction.h +124 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CATransform3D.h +138 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CATransformLayer.h +40 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CAValueFunction.h +78 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.h +19 -38
- package/sdk/ios/System/Library/Frameworks/Security.framework/Headers/SecureTransport.h +1757 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/NSAttributedString.h +19 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/NSParagraphStyle.h +28 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIAccessibilityConstants.h +114 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h +16 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIBarAppearance.h +47 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIDataDetectors.h +20 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIDatePicker.h +13 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIDevice.h +16 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIEvent.h +84 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIGestureRecognizer.h +119 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIGestureRecognizerSubclass.h +66 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIHoverGestureRecognizer.h +45 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h +161 -37
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIPickerView.h +76 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UITabBar.h +8 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UITabBarAppearance.h +78 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UITextInputTraits.h +29 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UITouch.h +104 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UITraitCollection.h +19 -0
- package/sdk/ios/usr/include/dns_sd.h +3616 -0
- package/sdk/ios/usr/include/dnssd.modulemap +4 -0
- package/sdk/ios/usr/include/module.modulemap +1 -0
- package/sdk/ios/usr/include/os/signpost.h +414 -0
- package/sdk/ios/usr/include/os.modulemap +5 -0
- package/sdk/ios/usr/include/sys/socketvar.h +191 -0
- package/sdk/ios/usr/include/sys/vsock.h +84 -0
- package/sdk/ios/wasm/include/errno.h +4 -20
- package/sdk/ios/wasm/include/pthread.h +3 -0
- package/sdk/ios/wasm/include/setjmp.h +57 -0
- package/sdk/ios/wasm/include/sys/resource.h +2 -2
- package/sdk/native-hashes.json +3 -3
- package/skills/contrast/SKILL.md +6 -5
- package/skills/peach-debug/SKILL.md +68 -265
- package/skills/peach-debug/references/accessibility.md +37 -73
- package/skills/peach-debug/references/commands.md +2 -2
- package/skills/peach-debug/references/events.md +74 -0
- package/skills/peach-perf/SKILL.md +64 -402
- package/skills/peach-perf/references/presentation.md +46 -0
- package/skills/peach-perf/references/profiling.md +93 -0
- package/skills/peach-perf/references/render-counters.md +57 -0
- package/skills/peach-setup/SKILL.md +66 -217
- package/skills/peach-setup/references/native-config.md +35 -0
- package/skills/peach-setup/references/reporting.md +28 -0
- package/skills/peach-test/SKILL.md +68 -285
- package/skills/peach-test/references/detox.md +69 -0
- package/skills/peach-test/references/maestro.md +95 -0
- package/skills/peach-visual/SKILL.md +53 -106
- package/src/android-autolinking.ts +1 -0
- package/src/android-bridge-packages.ts +279 -0
- package/src/appPackageContract.ts +14 -1
- package/src/assetCatalogContract.ts +8 -1
- package/src/bridge-contract.ts +6 -0
- package/src/bundle-channel.mjs +152 -60
- package/src/cli-runtime.ts +3 -0
- package/src/configured-bundle-producer.ts +10 -0
- package/src/device-catalog.ts +68 -4
- package/src/expo-discovery-cache.ts +10 -3
- package/src/expo-kotlin-host.ts +97 -26
- package/src/expo-native-workspace.ts +211 -52
- package/src/expo-swift-host.ts +149 -123
- package/src/expo-swift-ready.ts +5 -1
- package/src/expo-widget-assets.ts +76 -0
- package/src/expoKotlinContract.ts +12 -2
- package/src/expoSwiftContract.ts +21 -2
- package/src/generated/swift-c-predefines.json +1 -1
- package/src/home-paths.ts +6 -1
- package/src/host/bridge-host.ts +5 -0
- package/src/host/fetch-proxy-handler.ts +10 -0
- package/src/host/websocket-proxy.ts +7 -2
- package/src/kotlin-host.ts +204 -30
- package/src/kotlinSdkContract.ts +2 -1
- package/src/menu.ts +7 -0
- package/src/native-prebuilt.ts +154 -0
- package/src/nitro-adapter.lock.json +261 -261
- package/src/nitro-adapter.ts +118 -50
- package/src/nitro-bundle.ts +134 -96
- package/src/nitro-compile.ts +16 -6
- package/src/nitro-dependencies.ts +43 -28
- package/src/nitro-source.ts +142 -30
- package/src/nitro-superset.lock.json +103 -0
- package/src/nitro-superset.ts +137 -0
- package/src/nitroAdapterContract.ts +146 -98
- package/src/nitroContract.ts +68 -21
- package/src/react-bridge-importers.ts +1 -0
- package/src/react-native-bridge-modules.ts +2 -0
- package/src/react-native-host-modules.ts +4 -1
- package/src/settingsContract.ts +37 -1
- package/src/storageSnapshotContract.ts +29 -81
- package/src/swift-compile.ts +315 -117
- package/src/swift-compiler-digest.ts +2 -0
- package/src/swift-coverage/indexdump.ts +22 -6
- package/src/swift-coverage/indexing.ts +4 -4
- package/src/swift-coverage/sdk.ts +104 -20
- package/src/swift-coverage/types.ts +34 -0
- package/src/swift-coverage/xcode-packages.ts +61 -1
- package/src/swift-coverage/xcode.ts +19 -13
- package/src/swift-cxx-reachable.ts +1 -1
- package/src/swift-distribution.lock.json +18 -13
- package/src/swift-distribution.ts +57 -26
- package/src/swift-host.ts +51 -35
- package/src/swift-link-roots.ts +45 -18
- package/src/swift-objc-compile.ts +78 -2
- package/src/swift-objc-standin.ts +3 -0
- package/src/swift-shared-sdk.ts +85 -1
- package/src/swift-standin-emit.ts +6 -1
- package/src/swift-standins.ts +403 -19
- package/src/swift-submit.ts +17 -1
- package/src/swift-toolchain.ts +98 -23
- package/src/swift-wasm-prune.ts +1629 -0
- package/src/turbo-bundle.ts +82 -0
- package/src/turbo-compile.ts +120 -0
- package/src/turbo-runtime.lock.json +69 -0
- package/src/turbo-source.ts +754 -0
- package/src/vite-plugin-one.ts +15 -3
- package/src/vite-plugin.ts +82 -23
- package/src/wasm-optimize.ts +34 -0
- package/src/worker-system-chunks.ts +3 -3
- package/src/xcode-project.ts +52 -0
- package/src/xcode-target-members.ts +12 -1
|
@@ -0,0 +1,1629 @@
|
|
|
1
|
+
// link-time type and symbol reachability pruning for swift wasm builds.
|
|
2
|
+
//
|
|
3
|
+
// swift and foundation object files carry type metadata descriptors, protocol
|
|
4
|
+
// conformances, reflection field descriptors and objc class registration
|
|
5
|
+
// initializers that reference nominal types and witness tables across each
|
|
6
|
+
// compilation unit. wasm-ld --gc-sections treats those registration sections
|
|
7
|
+
// as unconditional roots (via swiftrt.o's __start_swift5_* / __stop_swift5_*
|
|
8
|
+
// references and WASM_SEG_FLAG_RETAIN / WASM_SYM_NO_STRIP flags), pulling in
|
|
9
|
+
// ~24 MB of unreachable framework and foundation code even when a package
|
|
10
|
+
// uses only a few types.
|
|
11
|
+
//
|
|
12
|
+
// this pass parses the wasm object graph before wasm-ld runs, traces reachable
|
|
13
|
+
// functions, data segments, partitioned .rodata/.data symbols and nominal
|
|
14
|
+
// types from the executable and host entrypoints, rewrites reached framework
|
|
15
|
+
// and sdk swift objects to drop relocations and initializers from dead types
|
|
16
|
+
// and functions, neutralizes swiftrt.o's reflection-only section bounds so
|
|
17
|
+
// --gc-sections collects unreferenced fieldmd/typeref/reflstr/assocty/capture
|
|
18
|
+
// segments, and invokes wasm-ld on the pruned response file.
|
|
19
|
+
|
|
20
|
+
import { execFileSync } from 'node:child_process'
|
|
21
|
+
import { createHash } from 'node:crypto'
|
|
22
|
+
import fs from 'node:fs'
|
|
23
|
+
import os from 'node:os'
|
|
24
|
+
import path from 'node:path'
|
|
25
|
+
|
|
26
|
+
function readULEB(b: Uint8Array, o: number): [number, number] {
|
|
27
|
+
let res = 0
|
|
28
|
+
let shift = 0
|
|
29
|
+
let p = o
|
|
30
|
+
while (true) {
|
|
31
|
+
const byte = b[p++]!
|
|
32
|
+
res |= (byte & 0x7f) << shift
|
|
33
|
+
if ((byte & 0x80) === 0) break
|
|
34
|
+
shift += 7
|
|
35
|
+
}
|
|
36
|
+
return [res, p]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function readSLEB(b: Uint8Array, o: number): [number, number] {
|
|
40
|
+
let res = 0
|
|
41
|
+
let shift = 0
|
|
42
|
+
let p = o
|
|
43
|
+
let byte = 0
|
|
44
|
+
do {
|
|
45
|
+
byte = b[p++]!
|
|
46
|
+
res |= (byte & 0x7f) << shift
|
|
47
|
+
shift += 7
|
|
48
|
+
} while (byte & 0x80)
|
|
49
|
+
if (shift < 32 && byte & 0x40) res |= ~0 << shift
|
|
50
|
+
return [res, p]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function encodeULEB(val: number): number[] {
|
|
54
|
+
const out: number[] = []
|
|
55
|
+
do {
|
|
56
|
+
let byte = val & 0x7f
|
|
57
|
+
val >>>= 7
|
|
58
|
+
if (val !== 0) byte |= 0x80
|
|
59
|
+
out.push(byte)
|
|
60
|
+
} while (val !== 0)
|
|
61
|
+
return out
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const HAS_ADDEND = new Set([3, 4, 5, 8, 9, 11, 13, 14, 15, 16, 21, 22, 23, 24, 25])
|
|
65
|
+
|
|
66
|
+
const ROOT_SEG_PREFIXES = [
|
|
67
|
+
'.init_array',
|
|
68
|
+
'__objc_init_func',
|
|
69
|
+
'__objc_classes',
|
|
70
|
+
'__objc_cats',
|
|
71
|
+
'__objc_class_aliases',
|
|
72
|
+
'objc_clsrolist',
|
|
73
|
+
'swift5_protocols',
|
|
74
|
+
'swift5_protocol_conformances',
|
|
75
|
+
'swift5_type_metadata',
|
|
76
|
+
'swift5_type_metadata_2',
|
|
77
|
+
'swift5_replace',
|
|
78
|
+
'swift5_replac2',
|
|
79
|
+
'swift5_accessible_functions',
|
|
80
|
+
'swift5_entry',
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
function isRootSegName(name: string): boolean {
|
|
84
|
+
for (const pref of ROOT_SEG_PREFIXES) {
|
|
85
|
+
if (name === pref || name.startsWith(`${pref}.`)) return true
|
|
86
|
+
}
|
|
87
|
+
return false
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const PARTITIONED_SEGS = new Set([
|
|
91
|
+
'.rodata',
|
|
92
|
+
'.data',
|
|
93
|
+
'.data.rel.ro',
|
|
94
|
+
'swift5_capture',
|
|
95
|
+
'swift5_fieldmd',
|
|
96
|
+
'swift5_assocty',
|
|
97
|
+
'swift5_typeref',
|
|
98
|
+
'swift5_builtin',
|
|
99
|
+
'swift5_mpenum',
|
|
100
|
+
])
|
|
101
|
+
|
|
102
|
+
const PRUNED_SDK_ARCHIVES = new Set([
|
|
103
|
+
'libFoundation',
|
|
104
|
+
'lib_FoundationCollections',
|
|
105
|
+
'libswift_StringProcessing',
|
|
106
|
+
'libswift_RegexParser',
|
|
107
|
+
'libswiftObservation',
|
|
108
|
+
'libswiftSynchronization',
|
|
109
|
+
'libswiftCxx',
|
|
110
|
+
'libswiftCxxStdlib',
|
|
111
|
+
'libswiftWASILibc',
|
|
112
|
+
'libswift_Builtin_float',
|
|
113
|
+
'libObjectiveC',
|
|
114
|
+
])
|
|
115
|
+
|
|
116
|
+
const OMIT_SDK_LIB_FLAGS = new Set([
|
|
117
|
+
...[...PRUNED_SDK_ARCHIVES].map((a) => `-l${a.slice(3)}`),
|
|
118
|
+
'-lswiftCore',
|
|
119
|
+
'-lswift_Concurrency',
|
|
120
|
+
])
|
|
121
|
+
|
|
122
|
+
const NEUTRALIZED_SWIFTRT_SECTIONS = new Set([
|
|
123
|
+
'swift5_tests',
|
|
124
|
+
'swift5_runtime_attributes',
|
|
125
|
+
'swift5_mpenum',
|
|
126
|
+
'swift5_capture',
|
|
127
|
+
'swift5_builtin',
|
|
128
|
+
'swift5_assocty',
|
|
129
|
+
'swift5_fieldmd',
|
|
130
|
+
'swift5_reflstr',
|
|
131
|
+
'swift5_typeref',
|
|
132
|
+
])
|
|
133
|
+
|
|
134
|
+
interface DataReloc {
|
|
135
|
+
rawBytes: Uint8Array
|
|
136
|
+
ro: number
|
|
137
|
+
rs: number
|
|
138
|
+
segIdx: number
|
|
139
|
+
offInSeg: number
|
|
140
|
+
ownerSymIdx: number
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
interface CodeReloc {
|
|
144
|
+
rawBytes: Uint8Array
|
|
145
|
+
ro: number
|
|
146
|
+
rs: number
|
|
147
|
+
funcIdx: number
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
interface ParsedObject {
|
|
151
|
+
file: string
|
|
152
|
+
isDist: boolean
|
|
153
|
+
numImportFuncs: number
|
|
154
|
+
numFuncs: number
|
|
155
|
+
numSegments: number
|
|
156
|
+
segNames: string[]
|
|
157
|
+
symKind: Uint8Array
|
|
158
|
+
symFlags: Uint32Array
|
|
159
|
+
symElemIdx: Int32Array
|
|
160
|
+
symOff: Int32Array
|
|
161
|
+
symSz: Int32Array
|
|
162
|
+
symParentIdx: Int32Array
|
|
163
|
+
symNames: string[]
|
|
164
|
+
funcRelocs: number[][]
|
|
165
|
+
segRelocs: number[][]
|
|
166
|
+
symDataRelocs: Map<number, number[]>
|
|
167
|
+
codeRelocList: CodeReloc[]
|
|
168
|
+
dataRelocList: DataReloc[]
|
|
169
|
+
initFuncSyms: number[]
|
|
170
|
+
objcRegisterFuncToTypePrefix: Map<number, string>
|
|
171
|
+
objcClassSymToTypePrefix: Map<string, string>
|
|
172
|
+
typePrefixesInObj: Set<string>
|
|
173
|
+
rootFuncs: number[]
|
|
174
|
+
rootSegs: number[]
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const parsedObjectCache = new Map<string, ParsedObject>()
|
|
178
|
+
|
|
179
|
+
function readArMembers(buf: Uint8Array): { name: string; bytes: Uint8Array }[] {
|
|
180
|
+
if (buf.length < 8) return []
|
|
181
|
+
const magic = Buffer.from(buf.subarray(0, 8)).toString('ascii')
|
|
182
|
+
if (magic !== '!<arch>\n') return []
|
|
183
|
+
const out: { name: string; bytes: Uint8Array }[] = []
|
|
184
|
+
let gnuNames: Uint8Array | null = null
|
|
185
|
+
let pos = 8
|
|
186
|
+
while (pos + 60 <= buf.length) {
|
|
187
|
+
const rawName = Buffer.from(buf.subarray(pos, pos + 16)).toString('ascii')
|
|
188
|
+
const sizeStr = Buffer.from(buf.subarray(pos + 48, pos + 58))
|
|
189
|
+
.toString('ascii')
|
|
190
|
+
.trim()
|
|
191
|
+
const size = Number.parseInt(sizeStr, 10)
|
|
192
|
+
pos += 60
|
|
193
|
+
if (Number.isNaN(size) || pos + size > buf.length) break
|
|
194
|
+
let bodyStart = pos
|
|
195
|
+
const bodyEnd = pos + size
|
|
196
|
+
let name = rawName.trim()
|
|
197
|
+
if (rawName.startsWith('#1/')) {
|
|
198
|
+
const nLen = Number.parseInt(rawName.slice(3).trim(), 10)
|
|
199
|
+
name = Buffer.from(buf.subarray(bodyStart, bodyStart + nLen))
|
|
200
|
+
.toString('utf8')
|
|
201
|
+
.replace(/\0+$/, '')
|
|
202
|
+
bodyStart += nLen
|
|
203
|
+
} else if (rawName.startsWith('//')) {
|
|
204
|
+
gnuNames = buf.subarray(bodyStart, bodyEnd)
|
|
205
|
+
pos = bodyEnd + (size & 1)
|
|
206
|
+
continue
|
|
207
|
+
} else if (rawName.startsWith('/') && gnuNames) {
|
|
208
|
+
const offStr = rawName.slice(1).trim()
|
|
209
|
+
if (offStr.length > 0 && /^\d+$/.test(offStr)) {
|
|
210
|
+
const off = Number.parseInt(offStr, 10)
|
|
211
|
+
let end = off
|
|
212
|
+
while (
|
|
213
|
+
end < gnuNames.length &&
|
|
214
|
+
gnuNames[end] !== 0x0a &&
|
|
215
|
+
gnuNames[end] !== 0x2f
|
|
216
|
+
) {
|
|
217
|
+
end++
|
|
218
|
+
}
|
|
219
|
+
name = Buffer.from(gnuNames.subarray(off, end)).toString('utf8')
|
|
220
|
+
} else {
|
|
221
|
+
pos = bodyEnd + (size & 1)
|
|
222
|
+
continue
|
|
223
|
+
}
|
|
224
|
+
} else if (name.endsWith('/')) {
|
|
225
|
+
name = name.slice(0, -1)
|
|
226
|
+
}
|
|
227
|
+
const bytes = buf.subarray(bodyStart, bodyEnd)
|
|
228
|
+
if (
|
|
229
|
+
bytes.length >= 8 &&
|
|
230
|
+
bytes[0] === 0x00 &&
|
|
231
|
+
bytes[1] === 0x61 &&
|
|
232
|
+
bytes[2] === 0x73 &&
|
|
233
|
+
bytes[3] === 0x6d
|
|
234
|
+
) {
|
|
235
|
+
out.push({ name, bytes })
|
|
236
|
+
}
|
|
237
|
+
pos = bodyEnd + (size & 1)
|
|
238
|
+
}
|
|
239
|
+
return out
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function patchSwiftrtObject(src: Uint8Array): Uint8Array {
|
|
243
|
+
const buf = new Uint8Array(src)
|
|
244
|
+
const neutralizedSyms = new Set<number>()
|
|
245
|
+
let fallbackSymIdx = 2
|
|
246
|
+
let pos = 8
|
|
247
|
+
while (pos < buf.length) {
|
|
248
|
+
const id = buf[pos++]!
|
|
249
|
+
const [sz, p] = readULEB(buf, pos)
|
|
250
|
+
const end = p + sz
|
|
251
|
+
if (id === 0) {
|
|
252
|
+
const [nLen, np] = readULEB(buf, p)
|
|
253
|
+
const name = Buffer.from(buf.subarray(np, np + nLen)).toString('utf8')
|
|
254
|
+
const cp = np + nLen
|
|
255
|
+
if (name === 'linking') {
|
|
256
|
+
let [, lp] = readULEB(buf, cp)
|
|
257
|
+
while (lp < end) {
|
|
258
|
+
const subId = buf[lp++]!
|
|
259
|
+
const [subLen, sp] = readULEB(buf, lp)
|
|
260
|
+
const subEnd = sp + subLen
|
|
261
|
+
if (subId === 8) {
|
|
262
|
+
let [cnt, cur] = readULEB(buf, sp)
|
|
263
|
+
for (let i = 0; i < cnt; i++) {
|
|
264
|
+
const kind = buf[cur++]!
|
|
265
|
+
const [fl, c2] = readULEB(buf, cur)
|
|
266
|
+
cur = c2
|
|
267
|
+
const isUndef = (fl & 0x10) !== 0
|
|
268
|
+
const isExplicitName = (fl & 0x40) !== 0
|
|
269
|
+
if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
|
|
270
|
+
const [, c3] = readULEB(buf, cur)
|
|
271
|
+
cur = c3
|
|
272
|
+
if (!isUndef || isExplicitName) {
|
|
273
|
+
const [sLen, c4] = readULEB(buf, cur)
|
|
274
|
+
cur = c4 + sLen
|
|
275
|
+
}
|
|
276
|
+
} else if (kind === 1) {
|
|
277
|
+
const [sLen, c3] = readULEB(buf, cur)
|
|
278
|
+
const sName = Buffer.from(buf.subarray(c3, c3 + sLen)).toString('utf8')
|
|
279
|
+
if (sName === '_ZN12_GLOBAL__N_18sectionsE') fallbackSymIdx = i
|
|
280
|
+
for (const prefix of ['__start_', '__stop_']) {
|
|
281
|
+
if (
|
|
282
|
+
sName.startsWith(prefix) &&
|
|
283
|
+
NEUTRALIZED_SWIFTRT_SECTIONS.has(sName.slice(prefix.length))
|
|
284
|
+
) {
|
|
285
|
+
buf[c3] = 0x78
|
|
286
|
+
neutralizedSyms.add(i)
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
cur = c3 + sLen
|
|
290
|
+
if (!isUndef) {
|
|
291
|
+
const [, c4] = readULEB(buf, cur)
|
|
292
|
+
const [, c5] = readULEB(buf, c4)
|
|
293
|
+
const [, c6] = readULEB(buf, c5)
|
|
294
|
+
cur = c6
|
|
295
|
+
}
|
|
296
|
+
} else if (kind === 3) {
|
|
297
|
+
const [, c3] = readULEB(buf, cur)
|
|
298
|
+
cur = c3
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
lp = subEnd
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
pos = end
|
|
307
|
+
}
|
|
308
|
+
pos = 8
|
|
309
|
+
while (pos < buf.length) {
|
|
310
|
+
const id = buf[pos++]!
|
|
311
|
+
const [sz, p] = readULEB(buf, pos)
|
|
312
|
+
const end = p + sz
|
|
313
|
+
if (id === 0) {
|
|
314
|
+
const [nLen, np] = readULEB(buf, p)
|
|
315
|
+
const name = Buffer.from(buf.subarray(np, np + nLen)).toString('utf8')
|
|
316
|
+
const cp = np + nLen
|
|
317
|
+
if (name === 'reloc.CODE') {
|
|
318
|
+
const [, r1] = readULEB(buf, cp)
|
|
319
|
+
let [cnt, cur] = readULEB(buf, r1)
|
|
320
|
+
for (let i = 0; i < cnt; i++) {
|
|
321
|
+
const rType = buf[cur++]!
|
|
322
|
+
const [, c2] = readULEB(buf, cur)
|
|
323
|
+
const [rs, c3] = readULEB(buf, c2)
|
|
324
|
+
if (neutralizedSyms.has(rs) && c3 - c2 === 1) {
|
|
325
|
+
buf[c2] = fallbackSymIdx
|
|
326
|
+
}
|
|
327
|
+
cur = c3
|
|
328
|
+
if (HAS_ADDEND.has(rType)) {
|
|
329
|
+
const [, c4] = readSLEB(buf, cur)
|
|
330
|
+
cur = c4
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
pos = end
|
|
336
|
+
}
|
|
337
|
+
return buf
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function parseWasmObjectBytes(
|
|
341
|
+
file: string,
|
|
342
|
+
buf: Uint8Array,
|
|
343
|
+
isDist: boolean,
|
|
344
|
+
): ParsedObject {
|
|
345
|
+
let pos = 8
|
|
346
|
+
let numImportFuncs = 0
|
|
347
|
+
const importFuncNames: string[] = []
|
|
348
|
+
const importGlobalNames: string[] = []
|
|
349
|
+
const importTableNames: string[] = []
|
|
350
|
+
const importEventNames: string[] = []
|
|
351
|
+
let codeStart = 0
|
|
352
|
+
const fStarts: number[] = []
|
|
353
|
+
const fEnds: number[] = []
|
|
354
|
+
let dataStart = 0
|
|
355
|
+
const sStarts: number[] = []
|
|
356
|
+
const sEnds: number[] = []
|
|
357
|
+
const sPayloadStarts: number[] = []
|
|
358
|
+
const segNames: string[] = []
|
|
359
|
+
const segFlags: number[] = []
|
|
360
|
+
|
|
361
|
+
let symKind = new Uint8Array(0)
|
|
362
|
+
let symFlags = new Uint32Array(0)
|
|
363
|
+
let symElemIdx = new Int32Array(0)
|
|
364
|
+
let symOff = new Int32Array(0)
|
|
365
|
+
let symSz = new Int32Array(0)
|
|
366
|
+
const symNames: string[] = []
|
|
367
|
+
const initFuncs: number[] = []
|
|
368
|
+
|
|
369
|
+
const rawCodeRelocs: { rawBytes: Uint8Array; ro: number; rs: number }[] = []
|
|
370
|
+
const rawDataRelocs: { rawBytes: Uint8Array; ro: number; rs: number }[] = []
|
|
371
|
+
|
|
372
|
+
while (pos < buf.length) {
|
|
373
|
+
const id = buf[pos++]!
|
|
374
|
+
const [sz, p] = readULEB(buf, pos)
|
|
375
|
+
const end = p + sz
|
|
376
|
+
|
|
377
|
+
if (id === 2) {
|
|
378
|
+
let [cnt, cp] = readULEB(buf, p)
|
|
379
|
+
for (let i = 0; i < cnt; i++) {
|
|
380
|
+
const [mLen, m2] = readULEB(buf, cp)
|
|
381
|
+
cp = m2 + mLen
|
|
382
|
+
const [fLen, f2] = readULEB(buf, cp)
|
|
383
|
+
const fName = Buffer.from(buf.subarray(f2, f2 + fLen)).toString('utf8')
|
|
384
|
+
cp = f2 + fLen
|
|
385
|
+
const kind = buf[cp++]!
|
|
386
|
+
if (kind === 0) {
|
|
387
|
+
const [, c2] = readULEB(buf, cp)
|
|
388
|
+
cp = c2
|
|
389
|
+
importFuncNames.push(fName)
|
|
390
|
+
numImportFuncs++
|
|
391
|
+
} else if (kind === 1) {
|
|
392
|
+
cp++
|
|
393
|
+
const [fl, c2] = readULEB(buf, cp)
|
|
394
|
+
cp = c2
|
|
395
|
+
const [, c3] = readULEB(buf, cp)
|
|
396
|
+
cp = c3
|
|
397
|
+
if (fl & 1) {
|
|
398
|
+
const [, c4] = readULEB(buf, cp)
|
|
399
|
+
cp = c4
|
|
400
|
+
}
|
|
401
|
+
importTableNames.push(fName)
|
|
402
|
+
} else if (kind === 2) {
|
|
403
|
+
const [fl, c2] = readULEB(buf, cp)
|
|
404
|
+
cp = c2
|
|
405
|
+
const [, c3] = readULEB(buf, cp)
|
|
406
|
+
cp = c3
|
|
407
|
+
if (fl & 1) {
|
|
408
|
+
const [, c4] = readULEB(buf, cp)
|
|
409
|
+
cp = c4
|
|
410
|
+
}
|
|
411
|
+
} else if (kind === 3) {
|
|
412
|
+
cp += 2
|
|
413
|
+
importGlobalNames.push(fName)
|
|
414
|
+
} else if (kind === 4) {
|
|
415
|
+
cp++
|
|
416
|
+
const [, c2] = readULEB(buf, cp)
|
|
417
|
+
cp = c2
|
|
418
|
+
importEventNames.push(fName)
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
} else if (id === 10) {
|
|
422
|
+
codeStart = p
|
|
423
|
+
let [cnt, cp] = readULEB(buf, p)
|
|
424
|
+
for (let i = 0; i < cnt; i++) {
|
|
425
|
+
const st = cp - codeStart
|
|
426
|
+
const [bLen, b2] = readULEB(buf, cp)
|
|
427
|
+
cp = b2 + bLen
|
|
428
|
+
fStarts.push(st)
|
|
429
|
+
fEnds.push(cp - codeStart)
|
|
430
|
+
}
|
|
431
|
+
} else if (id === 11) {
|
|
432
|
+
dataStart = p
|
|
433
|
+
let [cnt, cp] = readULEB(buf, p)
|
|
434
|
+
for (let i = 0; i < cnt; i++) {
|
|
435
|
+
const st = cp - dataStart
|
|
436
|
+
const [mode, m2] = readULEB(buf, cp)
|
|
437
|
+
cp = m2
|
|
438
|
+
if (mode === 2) {
|
|
439
|
+
const [, m3] = readULEB(buf, cp)
|
|
440
|
+
cp = m3
|
|
441
|
+
}
|
|
442
|
+
if (mode === 0 || mode === 2) {
|
|
443
|
+
const op = buf[cp++]!
|
|
444
|
+
if (op === 0x41 || op === 0x42) {
|
|
445
|
+
const [, m4] = readSLEB(buf, cp)
|
|
446
|
+
cp = m4
|
|
447
|
+
} else if (op === 0x23) {
|
|
448
|
+
const [, m4] = readULEB(buf, cp)
|
|
449
|
+
cp = m4
|
|
450
|
+
}
|
|
451
|
+
cp++
|
|
452
|
+
}
|
|
453
|
+
const [dLen, d2] = readULEB(buf, cp)
|
|
454
|
+
sPayloadStarts.push(d2 - dataStart)
|
|
455
|
+
cp = d2 + dLen
|
|
456
|
+
sStarts.push(st)
|
|
457
|
+
sEnds.push(cp - dataStart)
|
|
458
|
+
}
|
|
459
|
+
} else if (id === 0) {
|
|
460
|
+
const [nLen, np] = readULEB(buf, p)
|
|
461
|
+
const name = Buffer.from(buf.subarray(np, np + nLen)).toString('utf8')
|
|
462
|
+
const cp = np + nLen
|
|
463
|
+
if (name === 'linking') {
|
|
464
|
+
let [, lp] = readULEB(buf, cp)
|
|
465
|
+
while (lp < end) {
|
|
466
|
+
const subId = buf[lp++]!
|
|
467
|
+
const [subLen, sp] = readULEB(buf, lp)
|
|
468
|
+
const subEnd = sp + subLen
|
|
469
|
+
if (subId === 5) {
|
|
470
|
+
const [cnt, p2] = readULEB(buf, sp)
|
|
471
|
+
let cur = p2
|
|
472
|
+
for (let i = 0; i < cnt; i++) {
|
|
473
|
+
const [sLen, s2] = readULEB(buf, cur)
|
|
474
|
+
segNames.push(Buffer.from(buf.subarray(s2, s2 + sLen)).toString('utf8'))
|
|
475
|
+
cur = s2 + sLen
|
|
476
|
+
const [, s3] = readULEB(buf, cur)
|
|
477
|
+
const [fl, s4] = readULEB(buf, s3)
|
|
478
|
+
segFlags.push(fl)
|
|
479
|
+
cur = s4
|
|
480
|
+
}
|
|
481
|
+
} else if (subId === 6) {
|
|
482
|
+
const [cnt, p2] = readULEB(buf, sp)
|
|
483
|
+
let cur = p2
|
|
484
|
+
for (let i = 0; i < cnt; i++) {
|
|
485
|
+
const [, s2] = readULEB(buf, cur)
|
|
486
|
+
const [symIdx, s3] = readULEB(buf, s2)
|
|
487
|
+
initFuncs.push(symIdx)
|
|
488
|
+
cur = s3
|
|
489
|
+
}
|
|
490
|
+
} else if (subId === 8) {
|
|
491
|
+
const [cnt, p2] = readULEB(buf, sp)
|
|
492
|
+
symKind = new Uint8Array(cnt)
|
|
493
|
+
symFlags = new Uint32Array(cnt)
|
|
494
|
+
symElemIdx = new Int32Array(cnt).fill(-1)
|
|
495
|
+
symOff = new Int32Array(cnt).fill(0)
|
|
496
|
+
symSz = new Int32Array(cnt).fill(0)
|
|
497
|
+
let cur = p2
|
|
498
|
+
for (let i = 0; i < cnt; i++) {
|
|
499
|
+
const kind = buf[cur++]!
|
|
500
|
+
const [fl, c2] = readULEB(buf, cur)
|
|
501
|
+
cur = c2
|
|
502
|
+
symKind[i] = kind
|
|
503
|
+
symFlags[i] = fl
|
|
504
|
+
const isUndef = (fl & 0x10) !== 0
|
|
505
|
+
const isExplicitName = (fl & 0x40) !== 0
|
|
506
|
+
if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
|
|
507
|
+
const [el, c3] = readULEB(buf, cur)
|
|
508
|
+
cur = c3
|
|
509
|
+
if (!isUndef && kind === 0) symElemIdx[i] = el
|
|
510
|
+
let sName = ''
|
|
511
|
+
if (!isUndef || isExplicitName) {
|
|
512
|
+
const [sLen, c4] = readULEB(buf, cur)
|
|
513
|
+
sName = Buffer.from(buf.subarray(c4, c4 + sLen)).toString('utf8')
|
|
514
|
+
cur = c4 + sLen
|
|
515
|
+
} else if (kind === 0) {
|
|
516
|
+
sName = importFuncNames[el] ?? ''
|
|
517
|
+
} else if (kind === 2) {
|
|
518
|
+
sName = importGlobalNames[el] ?? ''
|
|
519
|
+
} else if (kind === 4) {
|
|
520
|
+
sName = importEventNames[el] ?? ''
|
|
521
|
+
} else if (kind === 5) {
|
|
522
|
+
sName = importTableNames[el] ?? ''
|
|
523
|
+
}
|
|
524
|
+
symNames.push(sName)
|
|
525
|
+
} else if (kind === 1) {
|
|
526
|
+
const [sLen, c3] = readULEB(buf, cur)
|
|
527
|
+
const sName = Buffer.from(buf.subarray(c3, c3 + sLen)).toString('utf8')
|
|
528
|
+
cur = c3 + sLen
|
|
529
|
+
if (!isUndef) {
|
|
530
|
+
const [segIdx, c4] = readULEB(buf, cur)
|
|
531
|
+
const [sOff, c5] = readULEB(buf, c4)
|
|
532
|
+
const [sSz, c6] = readULEB(buf, c5)
|
|
533
|
+
cur = c6
|
|
534
|
+
symElemIdx[i] = segIdx
|
|
535
|
+
symOff[i] = sOff
|
|
536
|
+
symSz[i] = sSz
|
|
537
|
+
}
|
|
538
|
+
symNames.push(sName)
|
|
539
|
+
} else if (kind === 3) {
|
|
540
|
+
const [, c3] = readULEB(buf, cur)
|
|
541
|
+
cur = c3
|
|
542
|
+
symNames.push('')
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
lp = subEnd
|
|
547
|
+
}
|
|
548
|
+
} else if (name === 'reloc.CODE' || name === 'reloc.DATA') {
|
|
549
|
+
const [, r1] = readULEB(buf, cp)
|
|
550
|
+
const [cnt, r2] = readULEB(buf, r1)
|
|
551
|
+
let cur = r2
|
|
552
|
+
const target = name === 'reloc.CODE' ? rawCodeRelocs : rawDataRelocs
|
|
553
|
+
for (let i = 0; i < cnt; i++) {
|
|
554
|
+
const rStart = cur
|
|
555
|
+
const rType = buf[cur++]!
|
|
556
|
+
const [ro, c2] = readULEB(buf, cur)
|
|
557
|
+
const [rs, c3] = readULEB(buf, c2)
|
|
558
|
+
cur = c3
|
|
559
|
+
if (HAS_ADDEND.has(rType)) {
|
|
560
|
+
const [, c4] = readSLEB(buf, cur)
|
|
561
|
+
cur = c4
|
|
562
|
+
}
|
|
563
|
+
target.push({ rawBytes: new Uint8Array(buf.subarray(rStart, cur)), ro, rs })
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
pos = end
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
const symParentIdx = new Int32Array(symKind.length).fill(-1)
|
|
571
|
+
const segTopSyms = new Map<number, { symIdx: number; off: number; end: number }[]>()
|
|
572
|
+
if (isDist) {
|
|
573
|
+
const bySeg = new Map<number, number[]>()
|
|
574
|
+
for (let i = 0; i < symKind.length; i++) {
|
|
575
|
+
if (symKind[i] === 1 && symElemIdx[i]! >= 0) {
|
|
576
|
+
const segIdx = symElemIdx[i]!
|
|
577
|
+
if (PARTITIONED_SEGS.has(segNames[segIdx]!)) {
|
|
578
|
+
let list = bySeg.get(segIdx)
|
|
579
|
+
if (!list) {
|
|
580
|
+
list = []
|
|
581
|
+
bySeg.set(segIdx, list)
|
|
582
|
+
}
|
|
583
|
+
list.push(i)
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
for (const [segIdx, syms] of bySeg) {
|
|
588
|
+
const segByteLen = (sEnds[segIdx] ?? 0) - (sPayloadStarts[segIdx] ?? 0)
|
|
589
|
+
const sorted = [...syms].sort(
|
|
590
|
+
(a, b) => symOff[a]! - symOff[b]! || symSz[b]! - symSz[a]!,
|
|
591
|
+
)
|
|
592
|
+
const dedupTop: { symIdx: number; off: number; end: number }[] = []
|
|
593
|
+
for (let k = 0; k < sorted.length; k++) {
|
|
594
|
+
const i = sorted[k]!
|
|
595
|
+
const off = symOff[i]!
|
|
596
|
+
const sz = symSz[i]!
|
|
597
|
+
const lastTop = dedupTop[dedupTop.length - 1]
|
|
598
|
+
if (lastTop && off < lastTop.end) {
|
|
599
|
+
symParentIdx[i] = lastTop.symIdx
|
|
600
|
+
continue
|
|
601
|
+
}
|
|
602
|
+
let nextOff = segByteLen
|
|
603
|
+
for (let m = k + 1; m < sorted.length; m++) {
|
|
604
|
+
if (symOff[sorted[m]!]! > off) {
|
|
605
|
+
nextOff = symOff[sorted[m]!]!
|
|
606
|
+
break
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
const end = sz > 0 ? off + sz : nextOff
|
|
610
|
+
symParentIdx[i] = i
|
|
611
|
+
dedupTop.push({ symIdx: i, off, end })
|
|
612
|
+
}
|
|
613
|
+
segTopSyms.set(segIdx, dedupTop)
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
const funcRelocs: number[][] = Array.from({ length: fEnds.length }, () => [])
|
|
618
|
+
const codeRelocList: CodeReloc[] = []
|
|
619
|
+
for (const r of rawCodeRelocs) {
|
|
620
|
+
let lo = 0
|
|
621
|
+
let hi = fEnds.length - 1
|
|
622
|
+
while (lo < hi) {
|
|
623
|
+
const mid = (lo + hi) >> 1
|
|
624
|
+
if (fEnds[mid]! <= r.ro) lo = mid + 1
|
|
625
|
+
else hi = mid
|
|
626
|
+
}
|
|
627
|
+
if (fEnds.length > 0) {
|
|
628
|
+
funcRelocs[lo]!.push(r.rs)
|
|
629
|
+
codeRelocList.push({ ...r, funcIdx: lo })
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
const segRelocs: number[][] = Array.from({ length: segNames.length }, () => [])
|
|
634
|
+
const symDataRelocs = new Map<number, number[]>()
|
|
635
|
+
const dataRelocList: DataReloc[] = []
|
|
636
|
+
|
|
637
|
+
for (const r of rawDataRelocs) {
|
|
638
|
+
let lo = 0
|
|
639
|
+
let hi = sEnds.length - 1
|
|
640
|
+
while (lo < hi) {
|
|
641
|
+
const mid = (lo + hi) >> 1
|
|
642
|
+
if (sEnds[mid]! <= r.ro) lo = mid + 1
|
|
643
|
+
else hi = mid
|
|
644
|
+
}
|
|
645
|
+
if (sEnds.length > 0 && lo < segRelocs.length) {
|
|
646
|
+
const offInSeg = r.ro - (sPayloadStarts[lo] ?? 0)
|
|
647
|
+
let ownerSymIdx = -1
|
|
648
|
+
const topList = segTopSyms.get(lo)
|
|
649
|
+
if (topList) {
|
|
650
|
+
const owner = topList.find((t) => offInSeg >= t.off && offInSeg < t.end)
|
|
651
|
+
if (owner) ownerSymIdx = owner.symIdx
|
|
652
|
+
}
|
|
653
|
+
if (ownerSymIdx !== -1) {
|
|
654
|
+
let list = symDataRelocs.get(ownerSymIdx)
|
|
655
|
+
if (!list) {
|
|
656
|
+
list = []
|
|
657
|
+
symDataRelocs.set(ownerSymIdx, list)
|
|
658
|
+
}
|
|
659
|
+
list.push(r.rs)
|
|
660
|
+
} else {
|
|
661
|
+
segRelocs[lo]!.push(r.rs)
|
|
662
|
+
}
|
|
663
|
+
dataRelocList.push({ ...r, segIdx: lo, offInSeg, ownerSymIdx })
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
const typePrefixesInObj = new Set<string>()
|
|
668
|
+
if (isDist) {
|
|
669
|
+
for (let i = 0; i < symKind.length; i++) {
|
|
670
|
+
if (
|
|
671
|
+
(symFlags[i]! & 0x10) === 0 &&
|
|
672
|
+
symNames[i]!.startsWith('$s') &&
|
|
673
|
+
symNames[i]!.endsWith('Mn')
|
|
674
|
+
) {
|
|
675
|
+
typePrefixesInObj.add(symNames[i]!.slice(0, -2))
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
const objcRegisterFuncToTypePrefix = new Map<number, string>()
|
|
681
|
+
const objcClassSymToTypePrefix = new Map<string, string>()
|
|
682
|
+
if (isDist) {
|
|
683
|
+
for (const symIdx of initFuncs) {
|
|
684
|
+
if (symKind[symIdx] === 0 && symElemIdx[symIdx]! >= numImportFuncs) {
|
|
685
|
+
const lf = symElemIdx[symIdx]! - numImportFuncs
|
|
686
|
+
const fName = symNames[symIdx]!
|
|
687
|
+
if (fName.startsWith('.L.swift.objc.register')) {
|
|
688
|
+
const relSyms = funcRelocs[lf]!.map((si) => symNames[si]!)
|
|
689
|
+
const mnSym = relSyms.find((s) => s.startsWith('$s') && s.endsWith('Mn'))
|
|
690
|
+
const objcSym = relSyms.find((s) => s.startsWith('._OBJC_CLASS_'))
|
|
691
|
+
if (mnSym) {
|
|
692
|
+
const pref = mnSym.slice(0, -2)
|
|
693
|
+
objcRegisterFuncToTypePrefix.set(lf, pref)
|
|
694
|
+
if (objcSym) objcClassSymToTypePrefix.set(objcSym, pref)
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
const rootFuncs: number[] = []
|
|
702
|
+
const rootSegs: number[] = []
|
|
703
|
+
for (const symIdx of initFuncs) {
|
|
704
|
+
if (symKind[symIdx] === 0 && symElemIdx[symIdx]! >= numImportFuncs) {
|
|
705
|
+
const lf = symElemIdx[symIdx]! - numImportFuncs
|
|
706
|
+
if (!objcRegisterFuncToTypePrefix.has(lf)) {
|
|
707
|
+
rootFuncs.push(lf)
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
for (let i = 0; i < symKind.length; i++) {
|
|
712
|
+
const isRootSym = isDist
|
|
713
|
+
? (symFlags[i]! & 0x20) !== 0
|
|
714
|
+
: (symFlags[i]! & 0x80) !== 0 || (symFlags[i]! & 0x20) !== 0
|
|
715
|
+
if (isRootSym && (symFlags[i]! & 0x10) === 0) {
|
|
716
|
+
if (symKind[i] === 0 && symElemIdx[i]! >= numImportFuncs) {
|
|
717
|
+
rootFuncs.push(symElemIdx[i]! - numImportFuncs)
|
|
718
|
+
} else if (symKind[i] === 1 && symElemIdx[i]! >= 0) {
|
|
719
|
+
rootSegs.push(symElemIdx[i]!)
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
for (let i = 0; i < segNames.length; i++) {
|
|
724
|
+
const sName = segNames[i]!
|
|
725
|
+
if (
|
|
726
|
+
isDist &&
|
|
727
|
+
(sName === 'swift5_type_metadata' ||
|
|
728
|
+
sName === 'swift5_protocol_conformances' ||
|
|
729
|
+
sName === '__objc_classes' ||
|
|
730
|
+
sName.startsWith('.init_array'))
|
|
731
|
+
) {
|
|
732
|
+
continue
|
|
733
|
+
}
|
|
734
|
+
if (isRootSegName(sName) || (!isDist && ((segFlags[i] ?? 0) & 0x4) !== 0)) {
|
|
735
|
+
rootSegs.push(i)
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
return {
|
|
740
|
+
file,
|
|
741
|
+
isDist,
|
|
742
|
+
numImportFuncs,
|
|
743
|
+
numFuncs: fEnds.length,
|
|
744
|
+
numSegments: segNames.length,
|
|
745
|
+
segNames,
|
|
746
|
+
symKind,
|
|
747
|
+
symFlags,
|
|
748
|
+
symElemIdx,
|
|
749
|
+
symOff,
|
|
750
|
+
symSz,
|
|
751
|
+
symParentIdx,
|
|
752
|
+
symNames,
|
|
753
|
+
funcRelocs,
|
|
754
|
+
segRelocs,
|
|
755
|
+
symDataRelocs,
|
|
756
|
+
codeRelocList,
|
|
757
|
+
dataRelocList,
|
|
758
|
+
initFuncSyms: initFuncs,
|
|
759
|
+
objcRegisterFuncToTypePrefix,
|
|
760
|
+
objcClassSymToTypePrefix,
|
|
761
|
+
typePrefixesInObj,
|
|
762
|
+
rootFuncs,
|
|
763
|
+
rootSegs,
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
function parseWasmObjectCached(
|
|
768
|
+
file: string,
|
|
769
|
+
isDist: boolean,
|
|
770
|
+
useCache: boolean,
|
|
771
|
+
): ParsedObject {
|
|
772
|
+
const key = `${isDist ? '1' : '0'}:${file}`
|
|
773
|
+
if (useCache) {
|
|
774
|
+
const hit = parsedObjectCache.get(key)
|
|
775
|
+
if (hit) return hit
|
|
776
|
+
}
|
|
777
|
+
const parsed = parseWasmObjectBytes(file, new Uint8Array(fs.readFileSync(file)), isDist)
|
|
778
|
+
if (useCache) parsedObjectCache.set(key, parsed)
|
|
779
|
+
return parsed
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
function peachHome(): string {
|
|
783
|
+
const override = process.env.PEACH_HOME
|
|
784
|
+
return override ? path.resolve(override) : path.join(os.homedir(), '.peach')
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
function ensureUnpackedSdkObjects(sdkWasiDir: string): string {
|
|
788
|
+
const sdkKey = createHash('sha256').update(sdkWasiDir).digest('hex').slice(0, 16)
|
|
789
|
+
const outDir = path.join(peachHome(), 'cache', 'swift-builds', `sdk-objs-${sdkKey}`)
|
|
790
|
+
const stamp = path.join(outDir, '.complete')
|
|
791
|
+
if (fs.existsSync(stamp)) return outDir
|
|
792
|
+
|
|
793
|
+
const tmpDir = `${outDir}.${process.pid}.${Date.now()}.tmp`
|
|
794
|
+
fs.mkdirSync(tmpDir, { recursive: true })
|
|
795
|
+
const archives = fs
|
|
796
|
+
.readdirSync(sdkWasiDir)
|
|
797
|
+
.filter((f) => f.endsWith('.a'))
|
|
798
|
+
.sort()
|
|
799
|
+
for (const archive of archives) {
|
|
800
|
+
const aBase = archive.replace(/\.a$/, '')
|
|
801
|
+
const members = readArMembers(
|
|
802
|
+
new Uint8Array(fs.readFileSync(path.join(sdkWasiDir, archive))),
|
|
803
|
+
)
|
|
804
|
+
const seen = new Map<string, number>()
|
|
805
|
+
for (const m of members) {
|
|
806
|
+
const count = (seen.get(m.name) ?? 0) + 1
|
|
807
|
+
seen.set(m.name, count)
|
|
808
|
+
const suffix = count > 1 ? `_${count}` : ''
|
|
809
|
+
const safeName = m.name.replaceAll('/', '__')
|
|
810
|
+
const outName = `${aBase}__${safeName}${suffix}`
|
|
811
|
+
fs.writeFileSync(path.join(tmpDir, outName), m.bytes)
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
fs.writeFileSync(path.join(tmpDir, '.complete'), '1\n')
|
|
815
|
+
fs.mkdirSync(path.dirname(outDir), { recursive: true })
|
|
816
|
+
if (fs.existsSync(stamp)) {
|
|
817
|
+
fs.rmSync(tmpDir, { recursive: true, force: true })
|
|
818
|
+
return outDir
|
|
819
|
+
}
|
|
820
|
+
fs.rmSync(outDir, { recursive: true, force: true })
|
|
821
|
+
fs.renameSync(tmpDir, outDir)
|
|
822
|
+
return outDir
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
function isPrunableSdkFile(file: string): boolean {
|
|
826
|
+
const base = path.basename(file)
|
|
827
|
+
const aBase = base.split('__')[0]!
|
|
828
|
+
if (PRUNED_SDK_ARCHIVES.has(aBase)) return true
|
|
829
|
+
if (
|
|
830
|
+
base === 'libswiftCore__Swift.o' ||
|
|
831
|
+
base === 'libswift_Concurrency___Concurrency.o'
|
|
832
|
+
) {
|
|
833
|
+
return true
|
|
834
|
+
}
|
|
835
|
+
return false
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
function getModulePrefix(file: string): string {
|
|
839
|
+
const base = path.basename(file)
|
|
840
|
+
const dbl = base.indexOf('__')
|
|
841
|
+
if (dbl > 0) return base.slice(0, dbl)
|
|
842
|
+
const dash = base.indexOf('-')
|
|
843
|
+
return dash > 0 ? base.slice(0, dash) : base
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
export function pruneSwiftWasmLink(
|
|
847
|
+
directory: string,
|
|
848
|
+
toolchainBin: string,
|
|
849
|
+
moduleRoot: string,
|
|
850
|
+
): void {
|
|
851
|
+
const rspPath = path.join(directory, '.peach-link.rsp')
|
|
852
|
+
if (!fs.existsSync(rspPath)) return
|
|
853
|
+
const origRsp = fs.readFileSync(rspPath, 'utf8')
|
|
854
|
+
const tokens = Array.from(origRsp.matchAll(/"([^"]+)"|(\S+)/g), (m) => m[1] ?? m[2]!)
|
|
855
|
+
if (!tokens.includes('--start-lib')) return
|
|
856
|
+
|
|
857
|
+
const sdkFlag = tokens.find(
|
|
858
|
+
(t) => t.startsWith('-L') && t.endsWith('/swift_static/wasi'),
|
|
859
|
+
)
|
|
860
|
+
if (!sdkFlag) return
|
|
861
|
+
const sdkWasiDir = sdkFlag.slice(2)
|
|
862
|
+
const sdkObjsDir = ensureUnpackedSdkObjects(sdkWasiDir)
|
|
863
|
+
const distDir = path.join(moduleRoot, 'lib')
|
|
864
|
+
|
|
865
|
+
const prunedObjsDir = path.join(directory, '.peach-pruned-objs')
|
|
866
|
+
fs.rmSync(prunedObjsDir, { recursive: true, force: true })
|
|
867
|
+
fs.mkdirSync(prunedObjsDir, { recursive: true })
|
|
868
|
+
|
|
869
|
+
// collect distribution and unpacked sdk object files
|
|
870
|
+
const distFiles: string[] = []
|
|
871
|
+
const eagerFiles: string[] = []
|
|
872
|
+
const extraArchiveObjs: ParsedObject[] = []
|
|
873
|
+
let inStartLib = false
|
|
874
|
+
let swiftrtOrigPath = ''
|
|
875
|
+
|
|
876
|
+
for (const t of tokens) {
|
|
877
|
+
if (t === '--start-lib') {
|
|
878
|
+
inStartLib = true
|
|
879
|
+
continue
|
|
880
|
+
}
|
|
881
|
+
if (t === '--end-lib') {
|
|
882
|
+
inStartLib = false
|
|
883
|
+
continue
|
|
884
|
+
}
|
|
885
|
+
if (t.endsWith('.o')) {
|
|
886
|
+
if (t.startsWith(distDir)) {
|
|
887
|
+
if (path.basename(t) !== 'Foundation-NSStringFormatting.o') {
|
|
888
|
+
distFiles.push(t)
|
|
889
|
+
}
|
|
890
|
+
if (!inStartLib) eagerFiles.push(t)
|
|
891
|
+
} else if (!inStartLib) {
|
|
892
|
+
if (t.endsWith('/swiftrt.o')) {
|
|
893
|
+
swiftrtOrigPath = t
|
|
894
|
+
} else {
|
|
895
|
+
eagerFiles.push(t)
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
} else if (
|
|
899
|
+
!inStartLib &&
|
|
900
|
+
t.endsWith('.a') &&
|
|
901
|
+
!t.endsWith('libclang_rt.builtins-wasm32.a') &&
|
|
902
|
+
fs.existsSync(t)
|
|
903
|
+
) {
|
|
904
|
+
const members = readArMembers(new Uint8Array(fs.readFileSync(t)))
|
|
905
|
+
for (const m of members) {
|
|
906
|
+
extraArchiveObjs.push(parseWasmObjectBytes(`${t}(${m.name})`, m.bytes, false))
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
let patchedSwiftrtPath = ''
|
|
912
|
+
if (swiftrtOrigPath && fs.existsSync(swiftrtOrigPath)) {
|
|
913
|
+
patchedSwiftrtPath = path.join(prunedObjsDir, 'swiftrt-patched.o')
|
|
914
|
+
fs.writeFileSync(
|
|
915
|
+
patchedSwiftrtPath,
|
|
916
|
+
patchSwiftrtObject(new Uint8Array(fs.readFileSync(swiftrtOrigPath))),
|
|
917
|
+
)
|
|
918
|
+
eagerFiles.push(patchedSwiftrtPath)
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
const allSdkObjFiles = fs
|
|
922
|
+
.readdirSync(sdkObjsDir)
|
|
923
|
+
.filter((f) => f.endsWith('.o') || f.endsWith('.obj'))
|
|
924
|
+
.sort()
|
|
925
|
+
const sdkFiles = allSdkObjFiles.map((f) => path.join(sdkObjsDir, f))
|
|
926
|
+
|
|
927
|
+
const distObjs = new Map<string, ParsedObject>()
|
|
928
|
+
const lazyProviders = new Map<string, ParsedObject[]>()
|
|
929
|
+
|
|
930
|
+
const registerLazyProvider = (obj: ParsedObject) => {
|
|
931
|
+
for (let i = 0; i < obj.symNames.length; i++) {
|
|
932
|
+
const fl = obj.symFlags[i]!
|
|
933
|
+
const isUndef = (fl & 0x10) !== 0
|
|
934
|
+
const isLocal = (fl & 0x03) === 0x02
|
|
935
|
+
if (!isUndef && !isLocal) {
|
|
936
|
+
const name = obj.symNames[i]!
|
|
937
|
+
if (name) {
|
|
938
|
+
let list = lazyProviders.get(name)
|
|
939
|
+
if (!list) {
|
|
940
|
+
list = []
|
|
941
|
+
lazyProviders.set(name, list)
|
|
942
|
+
}
|
|
943
|
+
list.push(obj)
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
for (const f of [...distFiles, ...sdkFiles]) {
|
|
950
|
+
const isSdk = f.startsWith(sdkObjsDir)
|
|
951
|
+
const isPrunableSwift = !isSdk || isPrunableSdkFile(f)
|
|
952
|
+
const obj = parseWasmObjectCached(f, isPrunableSwift, true)
|
|
953
|
+
distObjs.set(f, obj)
|
|
954
|
+
registerLazyProvider(obj)
|
|
955
|
+
}
|
|
956
|
+
for (const obj of extraArchiveObjs) {
|
|
957
|
+
registerLazyProvider(obj)
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
const extractedObjs = new Set<ParsedObject>()
|
|
961
|
+
const definedGlobalSyms = new Map<string, { obj: ParsedObject; symIdx: number }>()
|
|
962
|
+
const extractedSymbolDefs = new Map<string, { obj: ParsedObject; symIdx: number }[]>()
|
|
963
|
+
const liveGlobalNames = new Set<string>()
|
|
964
|
+
const liveFuncs = new Map<ParsedObject, Uint8Array>()
|
|
965
|
+
const liveSegs = new Map<ParsedObject, Uint8Array>()
|
|
966
|
+
const liveDataSyms = new Map<ParsedObject, Set<number>>()
|
|
967
|
+
const liveTypes = new Map<ParsedObject, Set<string>>()
|
|
968
|
+
|
|
969
|
+
type WorkItem =
|
|
970
|
+
| { kind: 'func'; obj: ParsedObject; idx: number }
|
|
971
|
+
| { kind: 'seg'; obj: ParsedObject; idx: number }
|
|
972
|
+
| { kind: 'datasym'; obj: ParsedObject; symIdx: number }
|
|
973
|
+
|
|
974
|
+
const workQueue: WorkItem[] = []
|
|
975
|
+
const pendingUndef = new Set<string>()
|
|
976
|
+
|
|
977
|
+
const markFuncLive = (obj: ParsedObject, localFuncIdx: number) => {
|
|
978
|
+
const arr = liveFuncs.get(obj)!
|
|
979
|
+
if (arr[localFuncIdx]) return
|
|
980
|
+
arr[localFuncIdx] = 1
|
|
981
|
+
workQueue.push({ kind: 'func', obj, idx: localFuncIdx })
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
const markSegLive = (obj: ParsedObject, segIdx: number) => {
|
|
985
|
+
const arr = liveSegs.get(obj)!
|
|
986
|
+
if (arr[segIdx]) return
|
|
987
|
+
arr[segIdx] = 1
|
|
988
|
+
workQueue.push({ kind: 'seg', obj, idx: segIdx })
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
const markDataSymLive = (obj: ParsedObject, symIdx: number) => {
|
|
992
|
+
const set = liveDataSyms.get(obj)!
|
|
993
|
+
if (set.has(symIdx)) return
|
|
994
|
+
set.add(symIdx)
|
|
995
|
+
workQueue.push({ kind: 'datasym', obj, symIdx })
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
const markTypeLive = (obj: ParsedObject, pref: string) => {
|
|
999
|
+
const set = liveTypes.get(obj)!
|
|
1000
|
+
if (set.has(pref)) return
|
|
1001
|
+
set.add(pref)
|
|
1002
|
+
|
|
1003
|
+
const mnName = `${pref}Mn`
|
|
1004
|
+
for (let i = 0; i < obj.symNames.length; i++) {
|
|
1005
|
+
if (obj.symNames[i] === mnName && (obj.symFlags[i]! & 0x10) === 0) {
|
|
1006
|
+
activateSymbolInObj(obj, i)
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
for (const [lf, p] of obj.objcRegisterFuncToTypePrefix) {
|
|
1010
|
+
if (p === pref) {
|
|
1011
|
+
markFuncLive(obj, lf)
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
for (let sIdx = 0; sIdx < obj.segNames.length; sIdx++) {
|
|
1015
|
+
if (obj.segNames[sIdx] === 'swift5_protocol_conformances') {
|
|
1016
|
+
for (const r of obj.dataRelocList) {
|
|
1017
|
+
if (r.segIdx === sIdx) {
|
|
1018
|
+
const mcName = obj.symNames[r.rs]!
|
|
1019
|
+
if (mcName.startsWith(pref)) {
|
|
1020
|
+
activateSymbolInObj(obj, r.rs)
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
const checkTypeTrigger = (obj: ParsedObject, rawSymName: string) => {
|
|
1029
|
+
if (!obj.isDist || !rawSymName) return
|
|
1030
|
+
const sName = rawSymName.startsWith('.Lgot.') ? rawSymName.slice(6) : rawSymName
|
|
1031
|
+
const objcPref = obj.objcClassSymToTypePrefix.get(sName)
|
|
1032
|
+
if (objcPref) {
|
|
1033
|
+
markTypeLive(obj, objcPref)
|
|
1034
|
+
return
|
|
1035
|
+
}
|
|
1036
|
+
if (!sName.startsWith('$s') || sName.endsWith('Tm')) return
|
|
1037
|
+
for (const suffix of ['Ma', 'Mf', 'N', 'Mn', 'ML']) {
|
|
1038
|
+
if (sName.endsWith(suffix)) {
|
|
1039
|
+
const cand = sName.slice(0, -suffix.length)
|
|
1040
|
+
if (obj.typePrefixesInObj.has(cand)) {
|
|
1041
|
+
markTypeLive(obj, cand)
|
|
1042
|
+
return
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
if (
|
|
1047
|
+
obj.file.endsWith('libswiftCore__Swift.o') ||
|
|
1048
|
+
obj.file.endsWith('libswift_Concurrency___Concurrency.o')
|
|
1049
|
+
) {
|
|
1050
|
+
for (const pref of obj.typePrefixesInObj) {
|
|
1051
|
+
if (sName.startsWith(pref)) {
|
|
1052
|
+
markTypeLive(obj, pref)
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
const activateGlobalName = (name: string) => {
|
|
1059
|
+
if (!name) return
|
|
1060
|
+
if (!liveGlobalNames.has(name)) liveGlobalNames.add(name)
|
|
1061
|
+
const defs = extractedSymbolDefs.get(name)
|
|
1062
|
+
if (defs) {
|
|
1063
|
+
for (const d of defs) {
|
|
1064
|
+
activateSymbolInObj(d.obj, d.symIdx)
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
function activateSymbolInObj(obj: ParsedObject, symIdx: number) {
|
|
1070
|
+
const kind = obj.symKind[symIdx]!
|
|
1071
|
+
const el = obj.symElemIdx[symIdx]!
|
|
1072
|
+
const sName = obj.symNames[symIdx]!
|
|
1073
|
+
const fl = obj.symFlags[symIdx]!
|
|
1074
|
+
const isUndef = (fl & 0x10) !== 0
|
|
1075
|
+
const isLocal = (fl & 0x03) === 0x02
|
|
1076
|
+
checkTypeTrigger(obj, sName)
|
|
1077
|
+
|
|
1078
|
+
if (!isUndef && !isLocal && sName && !liveGlobalNames.has(sName)) {
|
|
1079
|
+
activateGlobalName(sName)
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
if (kind === 0 && el >= obj.numImportFuncs) {
|
|
1083
|
+
markFuncLive(obj, el - obj.numImportFuncs)
|
|
1084
|
+
} else if (kind === 1 && el >= 0) {
|
|
1085
|
+
const pIdx = obj.symParentIdx[symIdx]!
|
|
1086
|
+
if (pIdx !== -1) {
|
|
1087
|
+
markDataSymLive(obj, pIdx)
|
|
1088
|
+
const parentName = obj.symNames[pIdx]!
|
|
1089
|
+
checkTypeTrigger(obj, parentName)
|
|
1090
|
+
}
|
|
1091
|
+
markSegLive(obj, el)
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
const extractObject = (obj: ParsedObject) => {
|
|
1096
|
+
if (extractedObjs.has(obj)) return
|
|
1097
|
+
extractedObjs.add(obj)
|
|
1098
|
+
liveFuncs.set(obj, new Uint8Array(obj.numFuncs))
|
|
1099
|
+
liveSegs.set(obj, new Uint8Array(obj.numSegments))
|
|
1100
|
+
liveDataSyms.set(obj, new Set<number>())
|
|
1101
|
+
liveTypes.set(obj, new Set<string>())
|
|
1102
|
+
|
|
1103
|
+
for (let i = 0; i < obj.symNames.length; i++) {
|
|
1104
|
+
const fl = obj.symFlags[i]!
|
|
1105
|
+
const isUndef = (fl & 0x10) !== 0
|
|
1106
|
+
const isLocal = (fl & 0x03) === 0x02
|
|
1107
|
+
const isWeak = (fl & 0x03) === 0x01
|
|
1108
|
+
if (!isUndef && !isLocal) {
|
|
1109
|
+
const name = obj.symNames[i]!
|
|
1110
|
+
if (name) {
|
|
1111
|
+
if (!definedGlobalSyms.has(name) || !isWeak) {
|
|
1112
|
+
definedGlobalSyms.set(name, { obj, symIdx: i })
|
|
1113
|
+
}
|
|
1114
|
+
let dList = extractedSymbolDefs.get(name)
|
|
1115
|
+
if (!dList) {
|
|
1116
|
+
dList = []
|
|
1117
|
+
extractedSymbolDefs.set(name, dList)
|
|
1118
|
+
}
|
|
1119
|
+
dList.push({ obj, symIdx: i })
|
|
1120
|
+
if (pendingUndef.has(name) || liveGlobalNames.has(name)) {
|
|
1121
|
+
pendingUndef.delete(name)
|
|
1122
|
+
activateSymbolInObj(obj, i)
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
for (const fIdx of obj.rootFuncs) markFuncLive(obj, fIdx)
|
|
1129
|
+
for (const sIdx of obj.rootSegs) markSegLive(obj, sIdx)
|
|
1130
|
+
|
|
1131
|
+
if (obj.file.endsWith('libswiftCore__Swift.o')) {
|
|
1132
|
+
for (const pref of obj.typePrefixesInObj) {
|
|
1133
|
+
if (!pref.startsWith('$ss')) {
|
|
1134
|
+
markTypeLive(obj, pref)
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
if (obj.isDist) {
|
|
1140
|
+
for (let sIdx = 0; sIdx < obj.segNames.length; sIdx++) {
|
|
1141
|
+
if (obj.segNames[sIdx] === 'swift5_protocol_conformances') {
|
|
1142
|
+
for (const r of obj.dataRelocList) {
|
|
1143
|
+
if (r.segIdx === sIdx) {
|
|
1144
|
+
const mcName = obj.symNames[r.rs]!
|
|
1145
|
+
let matchesLocalType = false
|
|
1146
|
+
for (const pref of obj.typePrefixesInObj) {
|
|
1147
|
+
if (mcName.startsWith(pref)) {
|
|
1148
|
+
matchesLocalType = true
|
|
1149
|
+
break
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
if (!matchesLocalType) {
|
|
1153
|
+
activateSymbolInObj(obj, r.rs)
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
for (const f of eagerFiles) {
|
|
1163
|
+
const isDist = f.startsWith(distDir)
|
|
1164
|
+
const obj = distObjs.get(f) ?? parseWasmObjectCached(f, isDist, false)
|
|
1165
|
+
extractObject(obj)
|
|
1166
|
+
if (isDist) {
|
|
1167
|
+
const base = path.basename(f)
|
|
1168
|
+
if (
|
|
1169
|
+
base.startsWith('PeachFoundation-') ||
|
|
1170
|
+
base.startsWith('PeachObjC-') ||
|
|
1171
|
+
base.startsWith('PeachICU-') ||
|
|
1172
|
+
base.startsWith('Darwin-')
|
|
1173
|
+
) {
|
|
1174
|
+
for (let i = 0; i < obj.symNames.length; i++) {
|
|
1175
|
+
const sName = obj.symNames[i]!
|
|
1176
|
+
if (
|
|
1177
|
+
(obj.symFlags[i]! & 0x10) === 0 &&
|
|
1178
|
+
sName &&
|
|
1179
|
+
!sName.startsWith('$s') &&
|
|
1180
|
+
!sName.startsWith('.')
|
|
1181
|
+
) {
|
|
1182
|
+
activateSymbolInObj(obj, i)
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
for (const symName of ['_initialize', '__main_argc_argv', 'main']) {
|
|
1190
|
+
const def = definedGlobalSyms.get(symName)
|
|
1191
|
+
if (def) activateSymbolInObj(def.obj, def.symIdx)
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
while (workQueue.length > 0) {
|
|
1195
|
+
const item = workQueue.pop()!
|
|
1196
|
+
const obj = item.obj
|
|
1197
|
+
let relocs: number[]
|
|
1198
|
+
if (item.kind === 'func') {
|
|
1199
|
+
relocs = obj.funcRelocs[item.idx]!
|
|
1200
|
+
} else if (item.kind === 'seg') {
|
|
1201
|
+
relocs = obj.segRelocs[item.idx]!
|
|
1202
|
+
} else {
|
|
1203
|
+
relocs = obj.symDataRelocs.get(item.symIdx) ?? []
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
for (const symIdx of relocs) {
|
|
1207
|
+
const fl = obj.symFlags[symIdx]!
|
|
1208
|
+
const isUndef = (fl & 0x10) !== 0
|
|
1209
|
+
const isLocal = (fl & 0x03) === 0x02
|
|
1210
|
+
const isWeak = (fl & 0x03) === 0x01
|
|
1211
|
+
|
|
1212
|
+
if (!isUndef) {
|
|
1213
|
+
activateSymbolInObj(obj, symIdx)
|
|
1214
|
+
if (!isLocal) {
|
|
1215
|
+
const name = obj.symNames[symIdx]!
|
|
1216
|
+
activateGlobalName(name)
|
|
1217
|
+
}
|
|
1218
|
+
} else {
|
|
1219
|
+
const name = obj.symNames[symIdx]!
|
|
1220
|
+
if (!name) continue
|
|
1221
|
+
let def = definedGlobalSyms.get(name)
|
|
1222
|
+
if (!def) {
|
|
1223
|
+
const cands = lazyProviders.get(name)
|
|
1224
|
+
if (cands && cands.length > 0) {
|
|
1225
|
+
const reqMod = getModulePrefix(obj.file)
|
|
1226
|
+
let chosen = cands.find((c) => extractedObjs.has(c))
|
|
1227
|
+
if (!chosen) {
|
|
1228
|
+
const sameMod = cands.filter((c) => getModulePrefix(c.file) === reqMod)
|
|
1229
|
+
const sdkPool = cands.filter((c) => c.file.startsWith(sdkObjsDir))
|
|
1230
|
+
const pool =
|
|
1231
|
+
sameMod.length > 0 ? sameMod : sdkPool.length > 0 ? sdkPool : cands
|
|
1232
|
+
chosen = pool.reduce((a, b) =>
|
|
1233
|
+
a.rootSegs.length + a.rootFuncs.length <=
|
|
1234
|
+
b.rootSegs.length + b.rootFuncs.length
|
|
1235
|
+
? a
|
|
1236
|
+
: b,
|
|
1237
|
+
)
|
|
1238
|
+
}
|
|
1239
|
+
extractObject(chosen)
|
|
1240
|
+
def = definedGlobalSyms.get(name)
|
|
1241
|
+
} else if (!isWeak) {
|
|
1242
|
+
pendingUndef.add(name)
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
if (def) {
|
|
1246
|
+
activateGlobalName(name)
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
const isSpecialSegRelocLive = (
|
|
1253
|
+
obj: ParsedObject,
|
|
1254
|
+
segName: string,
|
|
1255
|
+
r: DataReloc,
|
|
1256
|
+
): boolean => {
|
|
1257
|
+
const sLive = liveSegs.get(obj)!
|
|
1258
|
+
const dLive = liveDataSyms.get(obj)!
|
|
1259
|
+
const tLive = liveTypes.get(obj)!
|
|
1260
|
+
const targetName = obj.symNames[r.rs] ?? ''
|
|
1261
|
+
if (segName === 'swift5_type_metadata') {
|
|
1262
|
+
const raw = targetName.startsWith('.Lgot.') ? targetName.slice(6) : targetName
|
|
1263
|
+
if (raw.endsWith('Mn')) {
|
|
1264
|
+
const pref = raw.slice(0, -2)
|
|
1265
|
+
if (obj.typePrefixesInObj.has(pref)) return tLive.has(pref)
|
|
1266
|
+
}
|
|
1267
|
+
return true
|
|
1268
|
+
}
|
|
1269
|
+
if (segName === 'swift5_protocol_conformances' || segName === '__objc_classes') {
|
|
1270
|
+
const pIdx = obj.symParentIdx[r.rs]!
|
|
1271
|
+
if (pIdx !== -1) return dLive.has(pIdx)
|
|
1272
|
+
const segIdx = obj.symElemIdx[r.rs]!
|
|
1273
|
+
return segIdx >= 0 ? sLive[segIdx] === 1 : true
|
|
1274
|
+
}
|
|
1275
|
+
return true
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
const writePrunedObject = (obj: ParsedObject, outFile: string) => {
|
|
1279
|
+
const buf = new Uint8Array(fs.readFileSync(obj.file))
|
|
1280
|
+
const fLive = liveFuncs.get(obj)!
|
|
1281
|
+
const sLive = liveSegs.get(obj)!
|
|
1282
|
+
const dLive = liveDataSyms.get(obj)!
|
|
1283
|
+
|
|
1284
|
+
const keptCodeRelocs = obj.codeRelocList.filter((r) => fLive[r.funcIdx] === 1)
|
|
1285
|
+
const firstLiveInSpecialSeg = new Map<
|
|
1286
|
+
number,
|
|
1287
|
+
{ rType: number; afterRo: Uint8Array }
|
|
1288
|
+
>()
|
|
1289
|
+
const deadSpecialSegs = new Set<number>()
|
|
1290
|
+
|
|
1291
|
+
for (let sIdx = 0; sIdx < obj.segNames.length; sIdx++) {
|
|
1292
|
+
const sName = obj.segNames[sIdx]!
|
|
1293
|
+
if (
|
|
1294
|
+
sName === 'swift5_type_metadata' ||
|
|
1295
|
+
sName === 'swift5_protocol_conformances' ||
|
|
1296
|
+
sName === '__objc_classes'
|
|
1297
|
+
) {
|
|
1298
|
+
const segRels = obj.dataRelocList.filter((r) => r.segIdx === sIdx)
|
|
1299
|
+
const liveRels = segRels.filter((r) => isSpecialSegRelocLive(obj, sName, r))
|
|
1300
|
+
if (liveRels.length === 0) {
|
|
1301
|
+
deadSpecialSegs.add(sIdx)
|
|
1302
|
+
} else {
|
|
1303
|
+
const first = liveRels[0]!
|
|
1304
|
+
const rType = first.rawBytes[0]!
|
|
1305
|
+
const [, afterRoOff] = readULEB(first.rawBytes, 1)
|
|
1306
|
+
firstLiveInSpecialSeg.set(sIdx, {
|
|
1307
|
+
rType,
|
|
1308
|
+
afterRo: first.rawBytes.subarray(afterRoOff),
|
|
1309
|
+
})
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
const keptDataRelocBytes: Uint8Array[] = []
|
|
1315
|
+
const zeroDataRelocOffsets: number[] = []
|
|
1316
|
+
const usedSyms = new Set<number>()
|
|
1317
|
+
for (const r of keptCodeRelocs) usedSyms.add(r.rs)
|
|
1318
|
+
|
|
1319
|
+
for (const r of obj.dataRelocList) {
|
|
1320
|
+
const sName = obj.segNames[r.segIdx]!
|
|
1321
|
+
if (
|
|
1322
|
+
sName === 'swift5_type_metadata' ||
|
|
1323
|
+
sName === 'swift5_protocol_conformances' ||
|
|
1324
|
+
sName === '__objc_classes'
|
|
1325
|
+
) {
|
|
1326
|
+
if (deadSpecialSegs.has(r.segIdx)) continue
|
|
1327
|
+
if (isSpecialSegRelocLive(obj, sName, r)) {
|
|
1328
|
+
keptDataRelocBytes.push(r.rawBytes)
|
|
1329
|
+
usedSyms.add(r.rs)
|
|
1330
|
+
} else if (sName === '__objc_classes') {
|
|
1331
|
+
zeroDataRelocOffsets.push(r.ro)
|
|
1332
|
+
} else {
|
|
1333
|
+
const repl = firstLiveInSpecialSeg.get(r.segIdx)!
|
|
1334
|
+
const roBytes = encodeULEB(r.ro)
|
|
1335
|
+
const out = new Uint8Array(1 + roBytes.length + repl.afterRo.length)
|
|
1336
|
+
out[0] = repl.rType
|
|
1337
|
+
out.set(roBytes, 1)
|
|
1338
|
+
out.set(repl.afterRo, 1 + roBytes.length)
|
|
1339
|
+
keptDataRelocBytes.push(out)
|
|
1340
|
+
}
|
|
1341
|
+
} else if (r.ownerSymIdx !== -1) {
|
|
1342
|
+
if (dLive.has(r.ownerSymIdx)) {
|
|
1343
|
+
keptDataRelocBytes.push(r.rawBytes)
|
|
1344
|
+
usedSyms.add(r.rs)
|
|
1345
|
+
}
|
|
1346
|
+
} else if (sLive[r.segIdx] === 1) {
|
|
1347
|
+
keptDataRelocBytes.push(r.rawBytes)
|
|
1348
|
+
usedSyms.add(r.rs)
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
const keptInitSyms = obj.initFuncSyms.filter((symIdx) => {
|
|
1353
|
+
if (obj.symKind[symIdx] === 0 && obj.symElemIdx[symIdx]! >= obj.numImportFuncs) {
|
|
1354
|
+
return fLive[obj.symElemIdx[symIdx]! - obj.numImportFuncs] === 1
|
|
1355
|
+
}
|
|
1356
|
+
return true
|
|
1357
|
+
})
|
|
1358
|
+
for (const symIdx of keptInitSyms) usedSyms.add(symIdx)
|
|
1359
|
+
|
|
1360
|
+
const outChunks: Uint8Array[] = [buf.subarray(0, 8)]
|
|
1361
|
+
let pos = 8
|
|
1362
|
+
while (pos < buf.length) {
|
|
1363
|
+
const secStart = pos
|
|
1364
|
+
const id = buf[pos++]!
|
|
1365
|
+
const [sz, p] = readULEB(buf, pos)
|
|
1366
|
+
const end = p + sz
|
|
1367
|
+
|
|
1368
|
+
if (id === 0) {
|
|
1369
|
+
const [nLen, np] = readULEB(buf, p)
|
|
1370
|
+
const name = Buffer.from(buf.subarray(np, np + nLen)).toString('utf8')
|
|
1371
|
+
const cp = np + nLen
|
|
1372
|
+
|
|
1373
|
+
if (name === 'linking') {
|
|
1374
|
+
const [, lpStart] = readULEB(buf, cp)
|
|
1375
|
+
const subChunks: Uint8Array[] = [buf.subarray(p, lpStart)]
|
|
1376
|
+
let lp = lpStart
|
|
1377
|
+
while (lp < end) {
|
|
1378
|
+
const subStart = lp
|
|
1379
|
+
const subId = buf[lp++]!
|
|
1380
|
+
const [subLen, sp] = readULEB(buf, lp)
|
|
1381
|
+
const subEnd = sp + subLen
|
|
1382
|
+
|
|
1383
|
+
if (subId === 5) {
|
|
1384
|
+
const subCopy = new Uint8Array(buf.subarray(subStart, subEnd))
|
|
1385
|
+
let [cnt, cur] = readULEB(buf, sp)
|
|
1386
|
+
for (let i = 0; i < cnt; i++) {
|
|
1387
|
+
const [sLen, s2] = readULEB(buf, cur)
|
|
1388
|
+
const segName = obj.segNames[i]!
|
|
1389
|
+
const isSpecial =
|
|
1390
|
+
segName === 'swift5_type_metadata' ||
|
|
1391
|
+
segName === 'swift5_protocol_conformances' ||
|
|
1392
|
+
segName === '__objc_classes'
|
|
1393
|
+
if (deadSpecialSegs.has(i)) {
|
|
1394
|
+
let repl = ''
|
|
1395
|
+
if (segName === 'swift5_type_metadata') repl = '.dead_swift5_type_md'
|
|
1396
|
+
else if (segName === 'swift5_protocol_conformances')
|
|
1397
|
+
repl = '.dead_swift5_protocol_confor'
|
|
1398
|
+
else if (segName === '__objc_classes') repl = '.dead_objc_cls'
|
|
1399
|
+
if (repl.length === sLen) {
|
|
1400
|
+
subCopy.set(Buffer.from(repl, 'utf8'), s2 - subStart)
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
cur = s2 + sLen
|
|
1404
|
+
const [, s3] = readULEB(buf, cur)
|
|
1405
|
+
const [segFl, s4] = readULEB(buf, s3)
|
|
1406
|
+
const sFlLen = s4 - s3
|
|
1407
|
+
const keepRetain = isSpecial
|
|
1408
|
+
? !deadSpecialSegs.has(i)
|
|
1409
|
+
: isRootSegName(segName) &&
|
|
1410
|
+
!segName.startsWith('.init_array') &&
|
|
1411
|
+
sLive[i] === 1
|
|
1412
|
+
const newSegFl = keepRetain ? segFl | 0x04 : segFl & ~0x04
|
|
1413
|
+
if (sFlLen === 1) {
|
|
1414
|
+
subCopy[s3 - subStart] = newSegFl
|
|
1415
|
+
} else if (sFlLen === 2) {
|
|
1416
|
+
subCopy[s3 - subStart] = (newSegFl & 0x7f) | 0x80
|
|
1417
|
+
subCopy[s3 - subStart + 1] = newSegFl >> 7
|
|
1418
|
+
}
|
|
1419
|
+
cur = s4
|
|
1420
|
+
}
|
|
1421
|
+
subChunks.push(subCopy)
|
|
1422
|
+
} else if (subId === 6) {
|
|
1423
|
+
let [cnt, cur] = readULEB(buf, sp)
|
|
1424
|
+
const entrySlices: Uint8Array[] = []
|
|
1425
|
+
for (let i = 0; i < cnt; i++) {
|
|
1426
|
+
const eStart = cur
|
|
1427
|
+
const [, s2] = readULEB(buf, cur)
|
|
1428
|
+
const [symIdx, s3] = readULEB(buf, s2)
|
|
1429
|
+
cur = s3
|
|
1430
|
+
if (
|
|
1431
|
+
obj.symKind[symIdx] === 0 &&
|
|
1432
|
+
obj.symElemIdx[symIdx]! >= obj.numImportFuncs
|
|
1433
|
+
) {
|
|
1434
|
+
if (fLive[obj.symElemIdx[symIdx]! - obj.numImportFuncs] === 1) {
|
|
1435
|
+
entrySlices.push(buf.subarray(eStart, cur))
|
|
1436
|
+
}
|
|
1437
|
+
} else {
|
|
1438
|
+
entrySlices.push(buf.subarray(eStart, cur))
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
if (entrySlices.length > 0) {
|
|
1442
|
+
const cntBytes = Uint8Array.from(encodeULEB(entrySlices.length))
|
|
1443
|
+
const bodyLen =
|
|
1444
|
+
cntBytes.length + entrySlices.reduce((a, b) => a + b.length, 0)
|
|
1445
|
+
const lenBytes = Uint8Array.from(encodeULEB(bodyLen))
|
|
1446
|
+
subChunks.push(Uint8Array.of(6), lenBytes, cntBytes, ...entrySlices)
|
|
1447
|
+
}
|
|
1448
|
+
} else if (subId === 8) {
|
|
1449
|
+
const subCopy = new Uint8Array(buf.subarray(subStart, subEnd))
|
|
1450
|
+
let [cnt, cur] = readULEB(buf, sp)
|
|
1451
|
+
for (let i = 0; i < cnt; i++) {
|
|
1452
|
+
const kind = buf[cur++]!
|
|
1453
|
+
const flOffset = cur - subStart
|
|
1454
|
+
const [fl, c2] = readULEB(buf, cur)
|
|
1455
|
+
cur = c2
|
|
1456
|
+
const isUndef = (fl & 0x10) !== 0
|
|
1457
|
+
const isExplicitName = (fl & 0x40) !== 0
|
|
1458
|
+
const flLen = c2 - (flOffset + subStart)
|
|
1459
|
+
let newFl = fl & 0x7f
|
|
1460
|
+
if (isUndef && (kind === 0 || kind === 1) && !usedSyms.has(i)) {
|
|
1461
|
+
newFl = ((fl & ~0x03) | 0x01) & 0x7f
|
|
1462
|
+
} else if (
|
|
1463
|
+
!isUndef &&
|
|
1464
|
+
kind === 0 &&
|
|
1465
|
+
obj.symElemIdx[i]! >= obj.numImportFuncs &&
|
|
1466
|
+
fLive[obj.symElemIdx[i]! - obj.numImportFuncs] === 0
|
|
1467
|
+
) {
|
|
1468
|
+
newFl = (fl & 0x40) | 0x02
|
|
1469
|
+
}
|
|
1470
|
+
if (flLen === 1) {
|
|
1471
|
+
subCopy[flOffset] = newFl
|
|
1472
|
+
} else if (flLen === 2) {
|
|
1473
|
+
subCopy[flOffset] = newFl | 0x80
|
|
1474
|
+
subCopy[flOffset + 1] = 0x00
|
|
1475
|
+
}
|
|
1476
|
+
if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
|
|
1477
|
+
const [, c3] = readULEB(buf, cur)
|
|
1478
|
+
cur = c3
|
|
1479
|
+
if (!isUndef || isExplicitName) {
|
|
1480
|
+
const [sLen, c4] = readULEB(buf, cur)
|
|
1481
|
+
cur = c4 + sLen
|
|
1482
|
+
}
|
|
1483
|
+
} else if (kind === 1) {
|
|
1484
|
+
const [sLen, c3] = readULEB(buf, cur)
|
|
1485
|
+
cur = c3 + sLen
|
|
1486
|
+
if (!isUndef) {
|
|
1487
|
+
const [, c4] = readULEB(buf, cur)
|
|
1488
|
+
const [, c5] = readULEB(buf, c4)
|
|
1489
|
+
const [, c6] = readULEB(buf, c5)
|
|
1490
|
+
cur = c6
|
|
1491
|
+
}
|
|
1492
|
+
} else if (kind === 3) {
|
|
1493
|
+
const [, c3] = readULEB(buf, cur)
|
|
1494
|
+
cur = c3
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
subChunks.push(subCopy)
|
|
1498
|
+
} else {
|
|
1499
|
+
subChunks.push(buf.subarray(subStart, subEnd))
|
|
1500
|
+
}
|
|
1501
|
+
lp = subEnd
|
|
1502
|
+
}
|
|
1503
|
+
const totalSubLen = subChunks.reduce((a, b) => a + b.length, 0)
|
|
1504
|
+
outChunks.push(
|
|
1505
|
+
Uint8Array.of(0),
|
|
1506
|
+
Uint8Array.from(encodeULEB(totalSubLen)),
|
|
1507
|
+
...subChunks,
|
|
1508
|
+
)
|
|
1509
|
+
} else if (name === 'reloc.CODE') {
|
|
1510
|
+
const [, r1] = readULEB(buf, cp)
|
|
1511
|
+
const headerSlice = buf.subarray(p, r1)
|
|
1512
|
+
const cntBytes = Uint8Array.from(encodeULEB(keptCodeRelocs.length))
|
|
1513
|
+
const relSlices = keptCodeRelocs.map((r) => r.rawBytes)
|
|
1514
|
+
const totalLen =
|
|
1515
|
+
headerSlice.length +
|
|
1516
|
+
cntBytes.length +
|
|
1517
|
+
relSlices.reduce((a, b) => a + b.length, 0)
|
|
1518
|
+
outChunks.push(
|
|
1519
|
+
Uint8Array.of(0),
|
|
1520
|
+
Uint8Array.from(encodeULEB(totalLen)),
|
|
1521
|
+
headerSlice,
|
|
1522
|
+
cntBytes,
|
|
1523
|
+
...relSlices,
|
|
1524
|
+
)
|
|
1525
|
+
} else if (name === 'reloc.DATA') {
|
|
1526
|
+
const [, r1] = readULEB(buf, cp)
|
|
1527
|
+
const headerSlice = buf.subarray(p, r1)
|
|
1528
|
+
const cntBytes = Uint8Array.from(encodeULEB(keptDataRelocBytes.length))
|
|
1529
|
+
const totalLen =
|
|
1530
|
+
headerSlice.length +
|
|
1531
|
+
cntBytes.length +
|
|
1532
|
+
keptDataRelocBytes.reduce((a, b) => a + b.length, 0)
|
|
1533
|
+
outChunks.push(
|
|
1534
|
+
Uint8Array.of(0),
|
|
1535
|
+
Uint8Array.from(encodeULEB(totalLen)),
|
|
1536
|
+
headerSlice,
|
|
1537
|
+
cntBytes,
|
|
1538
|
+
...keptDataRelocBytes,
|
|
1539
|
+
)
|
|
1540
|
+
} else if (name === '.swift1_autolink_entries') {
|
|
1541
|
+
// drop autolink custom section from linked wasm
|
|
1542
|
+
} else {
|
|
1543
|
+
outChunks.push(buf.subarray(secStart, end))
|
|
1544
|
+
}
|
|
1545
|
+
} else {
|
|
1546
|
+
if (id === 11 && zeroDataRelocOffsets.length > 0) {
|
|
1547
|
+
for (const ro of zeroDataRelocOffsets) {
|
|
1548
|
+
buf.fill(0, p + ro, p + ro + 4)
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
outChunks.push(buf.subarray(secStart, end))
|
|
1552
|
+
}
|
|
1553
|
+
pos = end
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
fs.writeFileSync(outFile, Buffer.concat(outChunks))
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
const prunableCandidates = [
|
|
1560
|
+
...distFiles,
|
|
1561
|
+
...sdkFiles.filter((f) => isPrunableSdkFile(f)),
|
|
1562
|
+
]
|
|
1563
|
+
const reachedPrunableObjs = prunableCandidates
|
|
1564
|
+
.map((f) => distObjs.get(f)!)
|
|
1565
|
+
.filter((o) => extractedObjs.has(o))
|
|
1566
|
+
|
|
1567
|
+
const prunedMap = new Map<string, string>()
|
|
1568
|
+
for (const o of reachedPrunableObjs) {
|
|
1569
|
+
const outPath = path.join(prunedObjsDir, path.basename(o.file))
|
|
1570
|
+
writePrunedObject(o, outPath)
|
|
1571
|
+
prunedMap.set(o.file, outPath)
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
const extraCoreConcurrencyObjs = allSdkObjFiles
|
|
1575
|
+
.filter(
|
|
1576
|
+
(f) =>
|
|
1577
|
+
(f.startsWith('libswiftCore__') && f !== 'libswiftCore__Swift.o') ||
|
|
1578
|
+
(f.startsWith('libswift_Concurrency__') &&
|
|
1579
|
+
f !== 'libswift_Concurrency___Concurrency.o'),
|
|
1580
|
+
)
|
|
1581
|
+
.map((f) => path.join(sdkObjsDir, f))
|
|
1582
|
+
|
|
1583
|
+
const outTokens: string[] = []
|
|
1584
|
+
const emittedPruned = new Set<string>()
|
|
1585
|
+
inStartLib = false
|
|
1586
|
+
for (const t of tokens) {
|
|
1587
|
+
if (t === '--start-lib') {
|
|
1588
|
+
inStartLib = true
|
|
1589
|
+
outTokens.push('--start-lib')
|
|
1590
|
+
for (const rf of prunableCandidates) {
|
|
1591
|
+
if (emittedPruned.has(rf)) continue
|
|
1592
|
+
if (prunedMap.has(rf)) {
|
|
1593
|
+
outTokens.push(prunedMap.get(rf)!)
|
|
1594
|
+
emittedPruned.add(rf)
|
|
1595
|
+
} else if (rf.startsWith(distDir)) {
|
|
1596
|
+
const m = getModulePrefix(rf)
|
|
1597
|
+
if (m === 'PeachICU' || m === 'Darwin') {
|
|
1598
|
+
outTokens.push(rf)
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
outTokens.push(...extraCoreConcurrencyObjs)
|
|
1603
|
+
continue
|
|
1604
|
+
}
|
|
1605
|
+
if (t === '--end-lib') {
|
|
1606
|
+
inStartLib = false
|
|
1607
|
+
outTokens.push('--end-lib')
|
|
1608
|
+
continue
|
|
1609
|
+
}
|
|
1610
|
+
if (inStartLib) continue
|
|
1611
|
+
if (t === swiftrtOrigPath && patchedSwiftrtPath) {
|
|
1612
|
+
outTokens.push(patchedSwiftrtPath)
|
|
1613
|
+
} else if (prunedMap.has(t)) {
|
|
1614
|
+
outTokens.push(prunedMap.get(t)!)
|
|
1615
|
+
emittedPruned.add(t)
|
|
1616
|
+
} else if (OMIT_SDK_LIB_FLAGS.has(t)) {
|
|
1617
|
+
continue
|
|
1618
|
+
} else {
|
|
1619
|
+
outTokens.push(t)
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
const prunedRspPath = path.join(directory, '.peach-link.pruned.rsp')
|
|
1624
|
+
fs.writeFileSync(prunedRspPath, outTokens.map((t) => JSON.stringify(t)).join(' '))
|
|
1625
|
+
execFileSync(path.join(toolchainBin, 'wasm-ld'), [`@${prunedRspPath}`], {
|
|
1626
|
+
stdio: 'pipe',
|
|
1627
|
+
})
|
|
1628
|
+
fs.rmSync(rspPath, { force: true })
|
|
1629
|
+
}
|