peachsim 0.1.1738 → 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 +67 -16
- 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 +22 -20
- package/cli/commands/push.ts +56 -0
- package/cli/commands/serve.ts +9 -0
- package/cli/commands/shell-url.ts +37 -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 +4 -0
- package/cli/ws-bridge.ts +3 -1
- package/detox/index.ts +9 -4
- 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 +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 +7372 -3675
- 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 +22 -8
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/expo-swift-bundle.cjs +6340 -3064
- package/dist-lib/expo-swift-metadata.cjs +14 -2
- package/dist-lib/expo-swift-metadata.mjs +14 -2
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +6524 -2720
- package/dist-lib/host/fetch-proxy-handler.cjs +8 -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 +97 -31
- 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 +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -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 +71 -29
- package/dist-lib/native-app-identity-project.cjs +53 -22
- package/dist-lib/native-app-identity-project.mjs +53 -22
- 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 +1 -1
- 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 +111 -79
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- 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 +40549 -37613
- package/dist-lib/swift-compile.cjs +2054 -388
- package/dist-lib/swift-compile.mjs +1976 -312
- 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 +68 -8
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +5867 -2646
- package/dist-lib/vite.cjs +18 -8
- 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/image-loader.d.ts +0 -3
- package/dist-types/packages/peach-engine/src/engine/node.d.ts +6 -0
- package/dist-types/packages/peach-engine/src/engine/paint-boundary.d.ts +1 -0
- 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 +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/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 +8 -0
- 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 +5 -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 +1 -0
- 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 +7 -0
- package/package.json +2 -1
- package/runtime-companion.json +1 -1
- 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 +0 -6
- package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +356 -61
- 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/sys/socketvar.h +191 -0
- package/sdk/ios/usr/include/sys/vsock.h +84 -0
- package/sdk/native-hashes.json +1 -1
- package/skills/contrast/SKILL.md +6 -5
- package/skills/peach-debug/SKILL.md +68 -264
- 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 -401
- 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 -216
- 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 -284
- 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 -105
- package/src/appPackageContract.ts +12 -1
- package/src/assetCatalogContract.ts +8 -1
- package/src/bridge-contract.ts +6 -0
- package/src/bundle-channel.mjs +133 -59
- package/src/cli-runtime.ts +8 -9
- package/src/configured-bundle-producer.ts +10 -0
- package/src/device-catalog.ts +68 -4
- package/src/expo-discovery-cache.ts +3 -0
- package/src/expo-native-workspace.ts +81 -17
- package/src/expo-swift-host.ts +57 -104
- package/src/expo-widget-assets.ts +76 -0
- package/src/expoSwiftContract.ts +13 -1
- package/src/host/websocket-proxy.ts +7 -2
- package/src/native-prebuilt.ts +3 -3
- package/src/nitro-adapter.lock.json +263 -263
- package/src/nitro-adapter.ts +69 -7
- package/src/nitro-bundle.ts +52 -24
- package/src/nitro-compile.ts +6 -1
- package/src/nitro-source.ts +82 -4
- package/src/nitro-superset.lock.json +103 -0
- package/src/nitro-superset.ts +137 -0
- package/src/nitroContract.ts +5 -1
- package/src/react-bridge-importers.ts +1 -0
- package/src/settingsContract.ts +26 -1
- package/src/swift-compile.ts +267 -68
- package/src/swift-compiler-digest.ts +2 -0
- package/src/swift-coverage/xcode-packages.ts +61 -1
- package/src/swift-coverage/xcode.ts +10 -12
- package/src/swift-cxx-reachable.ts +1 -1
- package/src/swift-distribution.lock.json +15 -13
- package/src/swift-distribution.ts +57 -26
- package/src/swift-host.ts +48 -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-standins.ts +233 -11
- package/src/swift-submit.ts +13 -1
- package/src/swift-toolchain.ts +82 -7
- package/src/swift-wasm-prune.ts +1629 -0
- package/src/turbo-bundle.ts +11 -10
- package/src/turbo-runtime.lock.json +16 -16
- package/src/vite-plugin-one.ts +12 -1
- 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
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/*! peach v0.1.
|
|
1
|
+
/*! peach v0.1.1744 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
|
|
2
2
|
|
|
3
3
|
// src/swift-compile.ts
|
|
4
4
|
import {
|
|
5
5
|
spawn as spawn3,
|
|
6
|
-
execFileSync as
|
|
6
|
+
execFileSync as execFileSync5
|
|
7
7
|
} from "node:child_process";
|
|
8
|
-
import { createHash as
|
|
8
|
+
import { createHash as createHash8, randomUUID as randomUUID3 } from "node:crypto";
|
|
9
9
|
import {
|
|
10
10
|
cpSync,
|
|
11
11
|
existsSync as existsSync2,
|
|
@@ -21,8 +21,8 @@ import {
|
|
|
21
21
|
utimesSync,
|
|
22
22
|
writeFileSync as writeFileSync3
|
|
23
23
|
} from "node:fs";
|
|
24
|
-
import
|
|
25
|
-
import
|
|
24
|
+
import os3 from "node:os";
|
|
25
|
+
import path14 from "node:path";
|
|
26
26
|
|
|
27
27
|
// src/admitted-mac-build.ts
|
|
28
28
|
import { spawnSync } from "node:child_process";
|
|
@@ -2825,9 +2825,9 @@ var EXCERPT = /^(\s*)(\d+)( \| )(.*)$/;
|
|
|
2825
2825
|
var MARKER = /^(\s*)( \| )(.*)$/;
|
|
2826
2826
|
function designTimeDiagnostic(output, files) {
|
|
2827
2827
|
const rewritten = /* @__PURE__ */ new Map();
|
|
2828
|
-
const linesOf = (
|
|
2828
|
+
const linesOf = (path15) => {
|
|
2829
2829
|
const file = Object.keys(files).find(
|
|
2830
|
-
(name2) => name2.endsWith(".swift") && (
|
|
2830
|
+
(name2) => name2.endsWith(".swift") && (path15 === name2 || path15.endsWith(`/${name2}`))
|
|
2831
2831
|
);
|
|
2832
2832
|
if (file === void 0) return null;
|
|
2833
2833
|
let lines = rewritten.get(file);
|
|
@@ -2964,6 +2964,23 @@ var compilerArchives = {
|
|
|
2964
2964
|
}
|
|
2965
2965
|
}
|
|
2966
2966
|
},
|
|
2967
|
+
"swift-6.4.0-RELEASE-custom-f7c03c3f59ec5d83": {
|
|
2968
|
+
identity: "f7c03c3f59ec5d83",
|
|
2969
|
+
hosts: {
|
|
2970
|
+
"darwin-arm64": {
|
|
2971
|
+
checksum: "8946a2d4716d3b0784cef7a85a35f66537bd319c4c5a48c63457d607260df5c5",
|
|
2972
|
+
manifest: "2a7754e6e365bf71ae6b6aefbbd810123795c73d43fb902a8a972d009d72790f"
|
|
2973
|
+
},
|
|
2974
|
+
"linux-x64": {
|
|
2975
|
+
checksum: "5ffa3b54d54583c1d6a38b708693072db4d088ba4bf5966b17014c068b2db641",
|
|
2976
|
+
manifest: "1b23ea52c5570de4697481a54bd0b0a0bcd6b54feccb7b0bb940d3643dec82cb"
|
|
2977
|
+
},
|
|
2978
|
+
"linux-arm64": {
|
|
2979
|
+
checksum: "29b0b97b7b0db4475dbe55f7011e57f493fed9f3482a6705becebd8b68c90bab",
|
|
2980
|
+
manifest: "3fdab1132715f5899de1bb1d7ddcd52cf540295ab86586c72f49502f37a403a1"
|
|
2981
|
+
}
|
|
2982
|
+
}
|
|
2983
|
+
},
|
|
2967
2984
|
[SWIFT_HOST_COMPILER_RELEASE]: {
|
|
2968
2985
|
identity: SWIFT_HOST_COMPILER_ID,
|
|
2969
2986
|
hosts: {
|
|
@@ -2982,6 +2999,22 @@ var compilerArchives = {
|
|
|
2982
2999
|
}
|
|
2983
3000
|
}
|
|
2984
3001
|
};
|
|
3002
|
+
var SWIFT_PRIVATE_DISTRIBUTION_ENV = "PEACH_SWIFT_PRIVATE_DISTRIBUTION";
|
|
3003
|
+
function privateSwiftDistributionRoot() {
|
|
3004
|
+
const root = process.env[SWIFT_PRIVATE_DISTRIBUTION_ENV]?.trim();
|
|
3005
|
+
return root ? path4.resolve(root) : null;
|
|
3006
|
+
}
|
|
3007
|
+
function privateSwiftRelease() {
|
|
3008
|
+
const root = privateSwiftDistributionRoot();
|
|
3009
|
+
if (!root) return null;
|
|
3010
|
+
const manifest = JSON.parse(
|
|
3011
|
+
fs2.readFileSync(path4.join(root, "distribution.json"), "utf8")
|
|
3012
|
+
);
|
|
3013
|
+
const release = manifest && typeof manifest === "object" && Reflect.get(manifest, "release");
|
|
3014
|
+
if (typeof release !== "string")
|
|
3015
|
+
throw new Error(`${root} holds no Swift distribution release`);
|
|
3016
|
+
return release;
|
|
3017
|
+
}
|
|
2985
3018
|
function swiftHostCompilerArchive(release, host2 = `${process.platform}-${process.arch}`) {
|
|
2986
3019
|
const compiler = compilerArchives[release];
|
|
2987
3020
|
if (!compiler) throw new Error(`unqualified host compiler ${release}`);
|
|
@@ -3029,6 +3062,14 @@ for arg in "$@"; do
|
|
|
3029
3062
|
rsp=\${arg#@}
|
|
3030
3063
|
awk 'BEGIN { RS = " "; ORS = " " } /^"-l/ { if (seen[$0]++) next } { print }' "$rsp" > "$rsp.dedup"
|
|
3031
3064
|
mv "$rsp.dedup" "$rsp"
|
|
3065
|
+
if [ "\${PEACH_DEFER_WASM_LINK:-}" = "1" ] && grep -q '"--start-lib"' "$rsp"; then
|
|
3066
|
+
cp "$rsp" ${JSON.stringify(path4.join(directory, ".peach-link.rsp"))}
|
|
3067
|
+
out=$(awk 'BEGIN { RS = " " } prev == "\\"'-o'\\"" { gsub(/^"|"[[:space:]]*$/, ""); print; exit } { prev = $0 }' "$rsp")
|
|
3068
|
+
if [ -n "$out" ]; then
|
|
3069
|
+
printf '\\000asm\\001\\000\\000\\000' > "$out"
|
|
3070
|
+
exit 0
|
|
3071
|
+
fi
|
|
3072
|
+
fi
|
|
3032
3073
|
;;
|
|
3033
3074
|
esac
|
|
3034
3075
|
done
|
|
@@ -3046,15 +3087,20 @@ function peachHome() {
|
|
|
3046
3087
|
return override ? path4.resolve(override) : path4.join(os.homedir(), ".peach");
|
|
3047
3088
|
}
|
|
3048
3089
|
var scratch;
|
|
3090
|
+
var linuxLibraryPath;
|
|
3049
3091
|
function swiftEnvironment(base = process.env) {
|
|
3050
|
-
if (!scratch) return base;
|
|
3051
3092
|
return {
|
|
3052
3093
|
...base,
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3094
|
+
...linuxLibraryPath ? {
|
|
3095
|
+
LD_LIBRARY_PATH: [linuxLibraryPath, base.LD_LIBRARY_PATH].filter(Boolean).join(":")
|
|
3096
|
+
} : {},
|
|
3097
|
+
...scratch ? {
|
|
3098
|
+
TMPDIR: scratch.directory,
|
|
3099
|
+
XDG_CONFIG_HOME: path4.join(scratch.home, ".config"),
|
|
3100
|
+
XDG_CACHE_HOME: path4.join(scratch.home, ".cache"),
|
|
3101
|
+
XDG_DATA_HOME: path4.join(scratch.home, ".local", "share"),
|
|
3102
|
+
...process.platform === "linux" ? { HOME: scratch.home } : {}
|
|
3103
|
+
} : {}
|
|
3058
3104
|
};
|
|
3059
3105
|
}
|
|
3060
3106
|
function swiftSourceSdk(root) {
|
|
@@ -3189,8 +3235,11 @@ function swiftFileChecksum(file) {
|
|
|
3189
3235
|
return hash.digest("hex");
|
|
3190
3236
|
}
|
|
3191
3237
|
function verifySwiftHostCompiler(release, root) {
|
|
3192
|
-
const pin = swiftHostCompilerArchive(release);
|
|
3193
3238
|
const file = path4.join(root, "compiler.json");
|
|
3239
|
+
const pin = release === privateSwiftRelease() ? {
|
|
3240
|
+
identity: release.replace(/^.*-custom-/, ""),
|
|
3241
|
+
manifest: swiftFileChecksum(file)
|
|
3242
|
+
} : swiftHostCompilerArchive(release);
|
|
3194
3243
|
if (swiftFileChecksum(file) !== pin.manifest)
|
|
3195
3244
|
throw new Error(`Swift compiler manifest mismatch at ${root}`);
|
|
3196
3245
|
const manifest = JSON.parse(fs2.readFileSync(file, "utf8"));
|
|
@@ -3241,6 +3290,8 @@ function swiftInstallSteps(release, wasmSdk) {
|
|
|
3241
3290
|
].join("\n");
|
|
3242
3291
|
}
|
|
3243
3292
|
function swiftCompilerInstall(release) {
|
|
3293
|
+
if (release === privateSwiftRelease())
|
|
3294
|
+
return { note: " (private: its builder installs it)", commands: [] };
|
|
3244
3295
|
if (release.includes("-custom-")) {
|
|
3245
3296
|
const archive = swiftHostCompilerArchive(release);
|
|
3246
3297
|
const directory = path4.resolve(swiftToolchainBin(release), "../..");
|
|
@@ -3391,12 +3442,7 @@ function icuSegment(object) {
|
|
|
3391
3442
|
// src/swift-link-roots.ts
|
|
3392
3443
|
import fs3 from "node:fs";
|
|
3393
3444
|
import path6 from "node:path";
|
|
3394
|
-
var OBJC_SEGMENTS = [
|
|
3395
|
-
"__objc_classes",
|
|
3396
|
-
"__objc_protocols",
|
|
3397
|
-
"__objc_cats",
|
|
3398
|
-
"__objc_class_aliases"
|
|
3399
|
-
];
|
|
3445
|
+
var OBJC_SEGMENTS = ["__objc_cats", "__objc_class_aliases"];
|
|
3400
3446
|
var leb = (bytes, at) => {
|
|
3401
3447
|
let value = 0;
|
|
3402
3448
|
let scale = 1;
|
|
@@ -3411,6 +3457,7 @@ function objcSegmentSizes(bytes) {
|
|
|
3411
3457
|
const at = { offset: 8 };
|
|
3412
3458
|
const names = [];
|
|
3413
3459
|
const sizes = [];
|
|
3460
|
+
let hasExportedSymbol = false;
|
|
3414
3461
|
while (at.offset < bytes.length) {
|
|
3415
3462
|
const id = bytes[at.offset++];
|
|
3416
3463
|
const size = leb(bytes, at);
|
|
@@ -3435,6 +3482,31 @@ function objcSegmentSizes(bytes) {
|
|
|
3435
3482
|
leb(bytes, at);
|
|
3436
3483
|
leb(bytes, at);
|
|
3437
3484
|
}
|
|
3485
|
+
} else if (kind === 8) {
|
|
3486
|
+
for (let count = leb(bytes, at); count > 0; count--) {
|
|
3487
|
+
const symKind = bytes[at.offset++];
|
|
3488
|
+
const flags = leb(bytes, at);
|
|
3489
|
+
const isUndef = (flags & 16) !== 0;
|
|
3490
|
+
const isExplicitName = (flags & 64) !== 0;
|
|
3491
|
+
if (!isUndef && (flags & 32) !== 0) hasExportedSymbol = true;
|
|
3492
|
+
if (symKind === 0 || symKind === 2 || symKind === 4 || symKind === 5) {
|
|
3493
|
+
leb(bytes, at);
|
|
3494
|
+
if (!isUndef || isExplicitName) {
|
|
3495
|
+
const sLen = leb(bytes, at);
|
|
3496
|
+
at.offset += sLen;
|
|
3497
|
+
}
|
|
3498
|
+
} else if (symKind === 1) {
|
|
3499
|
+
const sLen = leb(bytes, at);
|
|
3500
|
+
at.offset += sLen;
|
|
3501
|
+
if (!isUndef) {
|
|
3502
|
+
leb(bytes, at);
|
|
3503
|
+
leb(bytes, at);
|
|
3504
|
+
leb(bytes, at);
|
|
3505
|
+
}
|
|
3506
|
+
} else if (symKind === 3) {
|
|
3507
|
+
leb(bytes, at);
|
|
3508
|
+
}
|
|
3509
|
+
}
|
|
3438
3510
|
}
|
|
3439
3511
|
at.offset = next;
|
|
3440
3512
|
}
|
|
@@ -3460,6 +3532,7 @@ function objcSegmentSizes(bytes) {
|
|
|
3460
3532
|
if (OBJC_SEGMENTS.includes(name2))
|
|
3461
3533
|
result.set(name2, (result.get(name2) ?? 0) + (sizes[index] ?? 0));
|
|
3462
3534
|
});
|
|
3535
|
+
result.set("__wasm_exported", hasExportedSymbol ? 1 : 0);
|
|
3463
3536
|
return result;
|
|
3464
3537
|
}
|
|
3465
3538
|
var rootsByDistribution = /* @__PURE__ */ new Map();
|
|
@@ -3475,7 +3548,7 @@ function swiftObjcRootObjects(id, root, objects) {
|
|
|
3475
3548
|
empty.set(name2, Math.min(empty.get(name2) ?? size, size));
|
|
3476
3549
|
const roots = new Set(
|
|
3477
3550
|
measured.filter(
|
|
3478
|
-
([, sizes]) => [...sizes].some(([name2, size]) => size > (empty.get(name2) ?? 0))
|
|
3551
|
+
([object, sizes]) => object !== "lib/Foundation-NSStringFormatting.o" && object !== "lib/FoundationNetworking-Session.o" && [...sizes].some(([name2, size]) => size > (empty.get(name2) ?? 0))
|
|
3479
3552
|
).map(([object]) => object)
|
|
3480
3553
|
);
|
|
3481
3554
|
rootsByDistribution.set(id, roots);
|
|
@@ -4096,6 +4169,9 @@ function objcSdkIntakeFlags(headers, toolchainBin, minimum) {
|
|
|
4096
4169
|
// the installed icu archive exports its swift_-prefixed names, which the
|
|
4097
4170
|
// unicode headers rename to only off darwin.
|
|
4098
4171
|
"-DU_DISABLE_RENAMING=0",
|
|
4172
|
+
// clang enables blocks in every language for darwin targets, and the sdk
|
|
4173
|
+
// headers declare block types unguarded.
|
|
4174
|
+
"-fblocks",
|
|
4099
4175
|
...WASI_EMULATION_FLAGS,
|
|
4100
4176
|
"-iframework",
|
|
4101
4177
|
path9.join(headers, "System/Library/Frameworks"),
|
|
@@ -4315,16 +4391,1448 @@ async function withSwiftRootLock(root, work, signal, wait = true) {
|
|
|
4315
4391
|
}
|
|
4316
4392
|
|
|
4317
4393
|
// src/swift-shared-sdk.ts
|
|
4318
|
-
import {
|
|
4394
|
+
import { execFileSync as execFileSync3 } from "node:child_process";
|
|
4395
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
4396
|
+
import fs5, { readdirSync as readdirSync4, readFileSync as readFileSync6 } from "node:fs";
|
|
4319
4397
|
import path11 from "node:path";
|
|
4320
4398
|
function swiftSharedSdkRoot(moduleRoot, distribution) {
|
|
4321
4399
|
return path11.resolve(moduleRoot, distribution ? "sdk/ios" : "../peachsim/sdk/ios");
|
|
4322
4400
|
}
|
|
4401
|
+
var sdkViews = /* @__PURE__ */ new Map();
|
|
4402
|
+
function swiftSharedSdkViewOptions(moduleRoot, distribution, toolchainBin, sdk) {
|
|
4403
|
+
const frameworks = path11.join(
|
|
4404
|
+
swiftSharedSdkRoot(moduleRoot, distribution),
|
|
4405
|
+
"System/Library/Frameworks"
|
|
4406
|
+
);
|
|
4407
|
+
const key = JSON.stringify([toolchainBin, sdk, frameworks, swiftSdkOptions()]);
|
|
4408
|
+
const cached = sdkViews.get(key);
|
|
4409
|
+
if (cached) return cached;
|
|
4410
|
+
const configuration = execFileSync3(
|
|
4411
|
+
path11.join(toolchainBin, "swift"),
|
|
4412
|
+
[
|
|
4413
|
+
"sdk",
|
|
4414
|
+
"configure",
|
|
4415
|
+
...swiftSdkOptions(),
|
|
4416
|
+
"--show-configuration",
|
|
4417
|
+
sdk,
|
|
4418
|
+
"wasm32-unknown-wasip1"
|
|
4419
|
+
],
|
|
4420
|
+
{ encoding: "utf8", env: swiftEnvironment(), stdio: ["ignore", "pipe", "pipe"] }
|
|
4421
|
+
);
|
|
4422
|
+
const sysroot = /^sdkRootPath: (.+)$/m.exec(configuration)?.[1]?.trim();
|
|
4423
|
+
if (!sysroot || !path11.isAbsolute(sysroot))
|
|
4424
|
+
throw new Error(`swift sdk ${sdk} reports no absolute sdkRootPath`);
|
|
4425
|
+
let bundle = sysroot;
|
|
4426
|
+
while (!bundle.endsWith(".artifactbundle")) {
|
|
4427
|
+
if (path11.dirname(bundle) === bundle)
|
|
4428
|
+
throw new Error(`swift sdk ${sdk} is outside an artifact bundle`);
|
|
4429
|
+
bundle = path11.dirname(bundle);
|
|
4430
|
+
}
|
|
4431
|
+
const view = path11.join(
|
|
4432
|
+
swiftCacheDir(),
|
|
4433
|
+
"swift-sdk-views",
|
|
4434
|
+
createHash6("sha256").update(key).digest("hex").slice(0, 16)
|
|
4435
|
+
);
|
|
4436
|
+
if (!fs5.existsSync(view)) {
|
|
4437
|
+
fs5.mkdirSync(path11.dirname(view), { recursive: true });
|
|
4438
|
+
const staging = fs5.mkdtempSync(`${view}-`);
|
|
4439
|
+
const segments = [
|
|
4440
|
+
path11.basename(bundle),
|
|
4441
|
+
...path11.relative(bundle, path11.join(sysroot, "darwin/System/Library")).split(path11.sep),
|
|
4442
|
+
"Frameworks"
|
|
4443
|
+
];
|
|
4444
|
+
let real = path11.dirname(bundle);
|
|
4445
|
+
let mirror = staging;
|
|
4446
|
+
for (const segment of segments) {
|
|
4447
|
+
for (const entry of readdirSync4(real))
|
|
4448
|
+
if (entry !== segment)
|
|
4449
|
+
fs5.symlinkSync(path11.join(real, entry), path11.join(mirror, entry));
|
|
4450
|
+
real = path11.join(real, segment);
|
|
4451
|
+
mirror = path11.join(mirror, segment);
|
|
4452
|
+
if (segment !== "Frameworks") fs5.mkdirSync(mirror);
|
|
4453
|
+
}
|
|
4454
|
+
fs5.symlinkSync(frameworks, mirror);
|
|
4455
|
+
try {
|
|
4456
|
+
fs5.renameSync(staging, view);
|
|
4457
|
+
} catch (error) {
|
|
4458
|
+
fs5.rmSync(staging, { recursive: true, force: true });
|
|
4459
|
+
if (!fs5.existsSync(view)) throw error;
|
|
4460
|
+
}
|
|
4461
|
+
}
|
|
4462
|
+
const options = ["--swift-sdks-path", view];
|
|
4463
|
+
sdkViews.set(key, options);
|
|
4464
|
+
return options;
|
|
4465
|
+
}
|
|
4323
4466
|
function swiftSharedSdkInputFiles(moduleRoot) {
|
|
4324
4467
|
const root = swiftSharedSdkRoot(moduleRoot, false);
|
|
4325
4468
|
return readdirSync4(root, { recursive: true, withFileTypes: true }).filter((entry) => entry.isFile()).map((entry) => path11.relative(moduleRoot, path11.join(entry.parentPath, entry.name))).sort();
|
|
4326
4469
|
}
|
|
4327
4470
|
|
|
4471
|
+
// src/swift-wasm-prune.ts
|
|
4472
|
+
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
4473
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
4474
|
+
import fs6 from "node:fs";
|
|
4475
|
+
import os2 from "node:os";
|
|
4476
|
+
import path12 from "node:path";
|
|
4477
|
+
function readULEB(b, o) {
|
|
4478
|
+
let res = 0;
|
|
4479
|
+
let shift = 0;
|
|
4480
|
+
let p = o;
|
|
4481
|
+
while (true) {
|
|
4482
|
+
const byte = b[p++];
|
|
4483
|
+
res |= (byte & 127) << shift;
|
|
4484
|
+
if ((byte & 128) === 0) break;
|
|
4485
|
+
shift += 7;
|
|
4486
|
+
}
|
|
4487
|
+
return [res, p];
|
|
4488
|
+
}
|
|
4489
|
+
function readSLEB(b, o) {
|
|
4490
|
+
let res = 0;
|
|
4491
|
+
let shift = 0;
|
|
4492
|
+
let p = o;
|
|
4493
|
+
let byte = 0;
|
|
4494
|
+
do {
|
|
4495
|
+
byte = b[p++];
|
|
4496
|
+
res |= (byte & 127) << shift;
|
|
4497
|
+
shift += 7;
|
|
4498
|
+
} while (byte & 128);
|
|
4499
|
+
if (shift < 32 && byte & 64) res |= ~0 << shift;
|
|
4500
|
+
return [res, p];
|
|
4501
|
+
}
|
|
4502
|
+
function encodeULEB(val) {
|
|
4503
|
+
const out = [];
|
|
4504
|
+
do {
|
|
4505
|
+
let byte = val & 127;
|
|
4506
|
+
val >>>= 7;
|
|
4507
|
+
if (val !== 0) byte |= 128;
|
|
4508
|
+
out.push(byte);
|
|
4509
|
+
} while (val !== 0);
|
|
4510
|
+
return out;
|
|
4511
|
+
}
|
|
4512
|
+
var HAS_ADDEND = /* @__PURE__ */ new Set([3, 4, 5, 8, 9, 11, 13, 14, 15, 16, 21, 22, 23, 24, 25]);
|
|
4513
|
+
var ROOT_SEG_PREFIXES = [
|
|
4514
|
+
".init_array",
|
|
4515
|
+
"__objc_init_func",
|
|
4516
|
+
"__objc_classes",
|
|
4517
|
+
"__objc_cats",
|
|
4518
|
+
"__objc_class_aliases",
|
|
4519
|
+
"objc_clsrolist",
|
|
4520
|
+
"swift5_protocols",
|
|
4521
|
+
"swift5_protocol_conformances",
|
|
4522
|
+
"swift5_type_metadata",
|
|
4523
|
+
"swift5_type_metadata_2",
|
|
4524
|
+
"swift5_replace",
|
|
4525
|
+
"swift5_replac2",
|
|
4526
|
+
"swift5_accessible_functions",
|
|
4527
|
+
"swift5_entry"
|
|
4528
|
+
];
|
|
4529
|
+
function isRootSegName(name2) {
|
|
4530
|
+
for (const pref of ROOT_SEG_PREFIXES) {
|
|
4531
|
+
if (name2 === pref || name2.startsWith(`${pref}.`)) return true;
|
|
4532
|
+
}
|
|
4533
|
+
return false;
|
|
4534
|
+
}
|
|
4535
|
+
var PARTITIONED_SEGS = /* @__PURE__ */ new Set([
|
|
4536
|
+
".rodata",
|
|
4537
|
+
".data",
|
|
4538
|
+
".data.rel.ro",
|
|
4539
|
+
"swift5_capture",
|
|
4540
|
+
"swift5_fieldmd",
|
|
4541
|
+
"swift5_assocty",
|
|
4542
|
+
"swift5_typeref",
|
|
4543
|
+
"swift5_builtin",
|
|
4544
|
+
"swift5_mpenum"
|
|
4545
|
+
]);
|
|
4546
|
+
var PRUNED_SDK_ARCHIVES = /* @__PURE__ */ new Set([
|
|
4547
|
+
"libFoundation",
|
|
4548
|
+
"lib_FoundationCollections",
|
|
4549
|
+
"libswift_StringProcessing",
|
|
4550
|
+
"libswift_RegexParser",
|
|
4551
|
+
"libswiftObservation",
|
|
4552
|
+
"libswiftSynchronization",
|
|
4553
|
+
"libswiftCxx",
|
|
4554
|
+
"libswiftCxxStdlib",
|
|
4555
|
+
"libswiftWASILibc",
|
|
4556
|
+
"libswift_Builtin_float",
|
|
4557
|
+
"libObjectiveC"
|
|
4558
|
+
]);
|
|
4559
|
+
var OMIT_SDK_LIB_FLAGS = /* @__PURE__ */ new Set([
|
|
4560
|
+
...[...PRUNED_SDK_ARCHIVES].map((a) => `-l${a.slice(3)}`),
|
|
4561
|
+
"-lswiftCore",
|
|
4562
|
+
"-lswift_Concurrency"
|
|
4563
|
+
]);
|
|
4564
|
+
var NEUTRALIZED_SWIFTRT_SECTIONS = /* @__PURE__ */ new Set([
|
|
4565
|
+
"swift5_tests",
|
|
4566
|
+
"swift5_runtime_attributes",
|
|
4567
|
+
"swift5_mpenum",
|
|
4568
|
+
"swift5_capture",
|
|
4569
|
+
"swift5_builtin",
|
|
4570
|
+
"swift5_assocty",
|
|
4571
|
+
"swift5_fieldmd",
|
|
4572
|
+
"swift5_reflstr",
|
|
4573
|
+
"swift5_typeref"
|
|
4574
|
+
]);
|
|
4575
|
+
var parsedObjectCache = /* @__PURE__ */ new Map();
|
|
4576
|
+
function readArMembers(buf) {
|
|
4577
|
+
if (buf.length < 8) return [];
|
|
4578
|
+
const magic = Buffer.from(buf.subarray(0, 8)).toString("ascii");
|
|
4579
|
+
if (magic !== "!<arch>\n") return [];
|
|
4580
|
+
const out = [];
|
|
4581
|
+
let gnuNames = null;
|
|
4582
|
+
let pos = 8;
|
|
4583
|
+
while (pos + 60 <= buf.length) {
|
|
4584
|
+
const rawName = Buffer.from(buf.subarray(pos, pos + 16)).toString("ascii");
|
|
4585
|
+
const sizeStr = Buffer.from(buf.subarray(pos + 48, pos + 58)).toString("ascii").trim();
|
|
4586
|
+
const size = Number.parseInt(sizeStr, 10);
|
|
4587
|
+
pos += 60;
|
|
4588
|
+
if (Number.isNaN(size) || pos + size > buf.length) break;
|
|
4589
|
+
let bodyStart = pos;
|
|
4590
|
+
const bodyEnd = pos + size;
|
|
4591
|
+
let name2 = rawName.trim();
|
|
4592
|
+
if (rawName.startsWith("#1/")) {
|
|
4593
|
+
const nLen = Number.parseInt(rawName.slice(3).trim(), 10);
|
|
4594
|
+
name2 = Buffer.from(buf.subarray(bodyStart, bodyStart + nLen)).toString("utf8").replace(/\0+$/, "");
|
|
4595
|
+
bodyStart += nLen;
|
|
4596
|
+
} else if (rawName.startsWith("//")) {
|
|
4597
|
+
gnuNames = buf.subarray(bodyStart, bodyEnd);
|
|
4598
|
+
pos = bodyEnd + (size & 1);
|
|
4599
|
+
continue;
|
|
4600
|
+
} else if (rawName.startsWith("/") && gnuNames) {
|
|
4601
|
+
const offStr = rawName.slice(1).trim();
|
|
4602
|
+
if (offStr.length > 0 && /^\d+$/.test(offStr)) {
|
|
4603
|
+
const off = Number.parseInt(offStr, 10);
|
|
4604
|
+
let end = off;
|
|
4605
|
+
while (end < gnuNames.length && gnuNames[end] !== 10 && gnuNames[end] !== 47) {
|
|
4606
|
+
end++;
|
|
4607
|
+
}
|
|
4608
|
+
name2 = Buffer.from(gnuNames.subarray(off, end)).toString("utf8");
|
|
4609
|
+
} else {
|
|
4610
|
+
pos = bodyEnd + (size & 1);
|
|
4611
|
+
continue;
|
|
4612
|
+
}
|
|
4613
|
+
} else if (name2.endsWith("/")) {
|
|
4614
|
+
name2 = name2.slice(0, -1);
|
|
4615
|
+
}
|
|
4616
|
+
const bytes = buf.subarray(bodyStart, bodyEnd);
|
|
4617
|
+
if (bytes.length >= 8 && bytes[0] === 0 && bytes[1] === 97 && bytes[2] === 115 && bytes[3] === 109) {
|
|
4618
|
+
out.push({ name: name2, bytes });
|
|
4619
|
+
}
|
|
4620
|
+
pos = bodyEnd + (size & 1);
|
|
4621
|
+
}
|
|
4622
|
+
return out;
|
|
4623
|
+
}
|
|
4624
|
+
function patchSwiftrtObject(src) {
|
|
4625
|
+
const buf = new Uint8Array(src);
|
|
4626
|
+
const neutralizedSyms = /* @__PURE__ */ new Set();
|
|
4627
|
+
let fallbackSymIdx = 2;
|
|
4628
|
+
let pos = 8;
|
|
4629
|
+
while (pos < buf.length) {
|
|
4630
|
+
const id = buf[pos++];
|
|
4631
|
+
const [sz, p] = readULEB(buf, pos);
|
|
4632
|
+
const end = p + sz;
|
|
4633
|
+
if (id === 0) {
|
|
4634
|
+
const [nLen, np] = readULEB(buf, p);
|
|
4635
|
+
const name2 = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
|
|
4636
|
+
const cp = np + nLen;
|
|
4637
|
+
if (name2 === "linking") {
|
|
4638
|
+
let [, lp] = readULEB(buf, cp);
|
|
4639
|
+
while (lp < end) {
|
|
4640
|
+
const subId = buf[lp++];
|
|
4641
|
+
const [subLen, sp] = readULEB(buf, lp);
|
|
4642
|
+
const subEnd = sp + subLen;
|
|
4643
|
+
if (subId === 8) {
|
|
4644
|
+
let [cnt, cur] = readULEB(buf, sp);
|
|
4645
|
+
for (let i = 0; i < cnt; i++) {
|
|
4646
|
+
const kind = buf[cur++];
|
|
4647
|
+
const [fl, c2] = readULEB(buf, cur);
|
|
4648
|
+
cur = c2;
|
|
4649
|
+
const isUndef = (fl & 16) !== 0;
|
|
4650
|
+
const isExplicitName = (fl & 64) !== 0;
|
|
4651
|
+
if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
|
|
4652
|
+
const [, c3] = readULEB(buf, cur);
|
|
4653
|
+
cur = c3;
|
|
4654
|
+
if (!isUndef || isExplicitName) {
|
|
4655
|
+
const [sLen, c4] = readULEB(buf, cur);
|
|
4656
|
+
cur = c4 + sLen;
|
|
4657
|
+
}
|
|
4658
|
+
} else if (kind === 1) {
|
|
4659
|
+
const [sLen, c3] = readULEB(buf, cur);
|
|
4660
|
+
const sName = Buffer.from(buf.subarray(c3, c3 + sLen)).toString("utf8");
|
|
4661
|
+
if (sName === "_ZN12_GLOBAL__N_18sectionsE") fallbackSymIdx = i;
|
|
4662
|
+
for (const prefix of ["__start_", "__stop_"]) {
|
|
4663
|
+
if (sName.startsWith(prefix) && NEUTRALIZED_SWIFTRT_SECTIONS.has(sName.slice(prefix.length))) {
|
|
4664
|
+
buf[c3] = 120;
|
|
4665
|
+
neutralizedSyms.add(i);
|
|
4666
|
+
}
|
|
4667
|
+
}
|
|
4668
|
+
cur = c3 + sLen;
|
|
4669
|
+
if (!isUndef) {
|
|
4670
|
+
const [, c4] = readULEB(buf, cur);
|
|
4671
|
+
const [, c5] = readULEB(buf, c4);
|
|
4672
|
+
const [, c6] = readULEB(buf, c5);
|
|
4673
|
+
cur = c6;
|
|
4674
|
+
}
|
|
4675
|
+
} else if (kind === 3) {
|
|
4676
|
+
const [, c3] = readULEB(buf, cur);
|
|
4677
|
+
cur = c3;
|
|
4678
|
+
}
|
|
4679
|
+
}
|
|
4680
|
+
}
|
|
4681
|
+
lp = subEnd;
|
|
4682
|
+
}
|
|
4683
|
+
}
|
|
4684
|
+
}
|
|
4685
|
+
pos = end;
|
|
4686
|
+
}
|
|
4687
|
+
pos = 8;
|
|
4688
|
+
while (pos < buf.length) {
|
|
4689
|
+
const id = buf[pos++];
|
|
4690
|
+
const [sz, p] = readULEB(buf, pos);
|
|
4691
|
+
const end = p + sz;
|
|
4692
|
+
if (id === 0) {
|
|
4693
|
+
const [nLen, np] = readULEB(buf, p);
|
|
4694
|
+
const name2 = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
|
|
4695
|
+
const cp = np + nLen;
|
|
4696
|
+
if (name2 === "reloc.CODE") {
|
|
4697
|
+
const [, r1] = readULEB(buf, cp);
|
|
4698
|
+
let [cnt, cur] = readULEB(buf, r1);
|
|
4699
|
+
for (let i = 0; i < cnt; i++) {
|
|
4700
|
+
const rType = buf[cur++];
|
|
4701
|
+
const [, c2] = readULEB(buf, cur);
|
|
4702
|
+
const [rs, c3] = readULEB(buf, c2);
|
|
4703
|
+
if (neutralizedSyms.has(rs) && c3 - c2 === 1) {
|
|
4704
|
+
buf[c2] = fallbackSymIdx;
|
|
4705
|
+
}
|
|
4706
|
+
cur = c3;
|
|
4707
|
+
if (HAS_ADDEND.has(rType)) {
|
|
4708
|
+
const [, c4] = readSLEB(buf, cur);
|
|
4709
|
+
cur = c4;
|
|
4710
|
+
}
|
|
4711
|
+
}
|
|
4712
|
+
}
|
|
4713
|
+
}
|
|
4714
|
+
pos = end;
|
|
4715
|
+
}
|
|
4716
|
+
return buf;
|
|
4717
|
+
}
|
|
4718
|
+
function parseWasmObjectBytes(file, buf, isDist) {
|
|
4719
|
+
let pos = 8;
|
|
4720
|
+
let numImportFuncs = 0;
|
|
4721
|
+
const importFuncNames = [];
|
|
4722
|
+
const importGlobalNames = [];
|
|
4723
|
+
const importTableNames = [];
|
|
4724
|
+
const importEventNames = [];
|
|
4725
|
+
let codeStart = 0;
|
|
4726
|
+
const fStarts = [];
|
|
4727
|
+
const fEnds = [];
|
|
4728
|
+
let dataStart = 0;
|
|
4729
|
+
const sStarts = [];
|
|
4730
|
+
const sEnds = [];
|
|
4731
|
+
const sPayloadStarts = [];
|
|
4732
|
+
const segNames = [];
|
|
4733
|
+
const segFlags = [];
|
|
4734
|
+
let symKind = new Uint8Array(0);
|
|
4735
|
+
let symFlags = new Uint32Array(0);
|
|
4736
|
+
let symElemIdx = new Int32Array(0);
|
|
4737
|
+
let symOff = new Int32Array(0);
|
|
4738
|
+
let symSz = new Int32Array(0);
|
|
4739
|
+
const symNames = [];
|
|
4740
|
+
const initFuncs = [];
|
|
4741
|
+
const rawCodeRelocs = [];
|
|
4742
|
+
const rawDataRelocs = [];
|
|
4743
|
+
while (pos < buf.length) {
|
|
4744
|
+
const id = buf[pos++];
|
|
4745
|
+
const [sz, p] = readULEB(buf, pos);
|
|
4746
|
+
const end = p + sz;
|
|
4747
|
+
if (id === 2) {
|
|
4748
|
+
let [cnt, cp] = readULEB(buf, p);
|
|
4749
|
+
for (let i = 0; i < cnt; i++) {
|
|
4750
|
+
const [mLen, m2] = readULEB(buf, cp);
|
|
4751
|
+
cp = m2 + mLen;
|
|
4752
|
+
const [fLen, f2] = readULEB(buf, cp);
|
|
4753
|
+
const fName = Buffer.from(buf.subarray(f2, f2 + fLen)).toString("utf8");
|
|
4754
|
+
cp = f2 + fLen;
|
|
4755
|
+
const kind = buf[cp++];
|
|
4756
|
+
if (kind === 0) {
|
|
4757
|
+
const [, c2] = readULEB(buf, cp);
|
|
4758
|
+
cp = c2;
|
|
4759
|
+
importFuncNames.push(fName);
|
|
4760
|
+
numImportFuncs++;
|
|
4761
|
+
} else if (kind === 1) {
|
|
4762
|
+
cp++;
|
|
4763
|
+
const [fl, c2] = readULEB(buf, cp);
|
|
4764
|
+
cp = c2;
|
|
4765
|
+
const [, c3] = readULEB(buf, cp);
|
|
4766
|
+
cp = c3;
|
|
4767
|
+
if (fl & 1) {
|
|
4768
|
+
const [, c4] = readULEB(buf, cp);
|
|
4769
|
+
cp = c4;
|
|
4770
|
+
}
|
|
4771
|
+
importTableNames.push(fName);
|
|
4772
|
+
} else if (kind === 2) {
|
|
4773
|
+
const [fl, c2] = readULEB(buf, cp);
|
|
4774
|
+
cp = c2;
|
|
4775
|
+
const [, c3] = readULEB(buf, cp);
|
|
4776
|
+
cp = c3;
|
|
4777
|
+
if (fl & 1) {
|
|
4778
|
+
const [, c4] = readULEB(buf, cp);
|
|
4779
|
+
cp = c4;
|
|
4780
|
+
}
|
|
4781
|
+
} else if (kind === 3) {
|
|
4782
|
+
cp += 2;
|
|
4783
|
+
importGlobalNames.push(fName);
|
|
4784
|
+
} else if (kind === 4) {
|
|
4785
|
+
cp++;
|
|
4786
|
+
const [, c2] = readULEB(buf, cp);
|
|
4787
|
+
cp = c2;
|
|
4788
|
+
importEventNames.push(fName);
|
|
4789
|
+
}
|
|
4790
|
+
}
|
|
4791
|
+
} else if (id === 10) {
|
|
4792
|
+
codeStart = p;
|
|
4793
|
+
let [cnt, cp] = readULEB(buf, p);
|
|
4794
|
+
for (let i = 0; i < cnt; i++) {
|
|
4795
|
+
const st = cp - codeStart;
|
|
4796
|
+
const [bLen, b2] = readULEB(buf, cp);
|
|
4797
|
+
cp = b2 + bLen;
|
|
4798
|
+
fStarts.push(st);
|
|
4799
|
+
fEnds.push(cp - codeStart);
|
|
4800
|
+
}
|
|
4801
|
+
} else if (id === 11) {
|
|
4802
|
+
dataStart = p;
|
|
4803
|
+
let [cnt, cp] = readULEB(buf, p);
|
|
4804
|
+
for (let i = 0; i < cnt; i++) {
|
|
4805
|
+
const st = cp - dataStart;
|
|
4806
|
+
const [mode, m2] = readULEB(buf, cp);
|
|
4807
|
+
cp = m2;
|
|
4808
|
+
if (mode === 2) {
|
|
4809
|
+
const [, m3] = readULEB(buf, cp);
|
|
4810
|
+
cp = m3;
|
|
4811
|
+
}
|
|
4812
|
+
if (mode === 0 || mode === 2) {
|
|
4813
|
+
const op = buf[cp++];
|
|
4814
|
+
if (op === 65 || op === 66) {
|
|
4815
|
+
const [, m4] = readSLEB(buf, cp);
|
|
4816
|
+
cp = m4;
|
|
4817
|
+
} else if (op === 35) {
|
|
4818
|
+
const [, m4] = readULEB(buf, cp);
|
|
4819
|
+
cp = m4;
|
|
4820
|
+
}
|
|
4821
|
+
cp++;
|
|
4822
|
+
}
|
|
4823
|
+
const [dLen, d2] = readULEB(buf, cp);
|
|
4824
|
+
sPayloadStarts.push(d2 - dataStart);
|
|
4825
|
+
cp = d2 + dLen;
|
|
4826
|
+
sStarts.push(st);
|
|
4827
|
+
sEnds.push(cp - dataStart);
|
|
4828
|
+
}
|
|
4829
|
+
} else if (id === 0) {
|
|
4830
|
+
const [nLen, np] = readULEB(buf, p);
|
|
4831
|
+
const name2 = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
|
|
4832
|
+
const cp = np + nLen;
|
|
4833
|
+
if (name2 === "linking") {
|
|
4834
|
+
let [, lp] = readULEB(buf, cp);
|
|
4835
|
+
while (lp < end) {
|
|
4836
|
+
const subId = buf[lp++];
|
|
4837
|
+
const [subLen, sp] = readULEB(buf, lp);
|
|
4838
|
+
const subEnd = sp + subLen;
|
|
4839
|
+
if (subId === 5) {
|
|
4840
|
+
const [cnt, p2] = readULEB(buf, sp);
|
|
4841
|
+
let cur = p2;
|
|
4842
|
+
for (let i = 0; i < cnt; i++) {
|
|
4843
|
+
const [sLen, s2] = readULEB(buf, cur);
|
|
4844
|
+
segNames.push(Buffer.from(buf.subarray(s2, s2 + sLen)).toString("utf8"));
|
|
4845
|
+
cur = s2 + sLen;
|
|
4846
|
+
const [, s3] = readULEB(buf, cur);
|
|
4847
|
+
const [fl, s4] = readULEB(buf, s3);
|
|
4848
|
+
segFlags.push(fl);
|
|
4849
|
+
cur = s4;
|
|
4850
|
+
}
|
|
4851
|
+
} else if (subId === 6) {
|
|
4852
|
+
const [cnt, p2] = readULEB(buf, sp);
|
|
4853
|
+
let cur = p2;
|
|
4854
|
+
for (let i = 0; i < cnt; i++) {
|
|
4855
|
+
const [, s2] = readULEB(buf, cur);
|
|
4856
|
+
const [symIdx, s3] = readULEB(buf, s2);
|
|
4857
|
+
initFuncs.push(symIdx);
|
|
4858
|
+
cur = s3;
|
|
4859
|
+
}
|
|
4860
|
+
} else if (subId === 8) {
|
|
4861
|
+
const [cnt, p2] = readULEB(buf, sp);
|
|
4862
|
+
symKind = new Uint8Array(cnt);
|
|
4863
|
+
symFlags = new Uint32Array(cnt);
|
|
4864
|
+
symElemIdx = new Int32Array(cnt).fill(-1);
|
|
4865
|
+
symOff = new Int32Array(cnt).fill(0);
|
|
4866
|
+
symSz = new Int32Array(cnt).fill(0);
|
|
4867
|
+
let cur = p2;
|
|
4868
|
+
for (let i = 0; i < cnt; i++) {
|
|
4869
|
+
const kind = buf[cur++];
|
|
4870
|
+
const [fl, c2] = readULEB(buf, cur);
|
|
4871
|
+
cur = c2;
|
|
4872
|
+
symKind[i] = kind;
|
|
4873
|
+
symFlags[i] = fl;
|
|
4874
|
+
const isUndef = (fl & 16) !== 0;
|
|
4875
|
+
const isExplicitName = (fl & 64) !== 0;
|
|
4876
|
+
if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
|
|
4877
|
+
const [el, c3] = readULEB(buf, cur);
|
|
4878
|
+
cur = c3;
|
|
4879
|
+
if (!isUndef && kind === 0) symElemIdx[i] = el;
|
|
4880
|
+
let sName = "";
|
|
4881
|
+
if (!isUndef || isExplicitName) {
|
|
4882
|
+
const [sLen, c4] = readULEB(buf, cur);
|
|
4883
|
+
sName = Buffer.from(buf.subarray(c4, c4 + sLen)).toString("utf8");
|
|
4884
|
+
cur = c4 + sLen;
|
|
4885
|
+
} else if (kind === 0) {
|
|
4886
|
+
sName = importFuncNames[el] ?? "";
|
|
4887
|
+
} else if (kind === 2) {
|
|
4888
|
+
sName = importGlobalNames[el] ?? "";
|
|
4889
|
+
} else if (kind === 4) {
|
|
4890
|
+
sName = importEventNames[el] ?? "";
|
|
4891
|
+
} else if (kind === 5) {
|
|
4892
|
+
sName = importTableNames[el] ?? "";
|
|
4893
|
+
}
|
|
4894
|
+
symNames.push(sName);
|
|
4895
|
+
} else if (kind === 1) {
|
|
4896
|
+
const [sLen, c3] = readULEB(buf, cur);
|
|
4897
|
+
const sName = Buffer.from(buf.subarray(c3, c3 + sLen)).toString("utf8");
|
|
4898
|
+
cur = c3 + sLen;
|
|
4899
|
+
if (!isUndef) {
|
|
4900
|
+
const [segIdx, c4] = readULEB(buf, cur);
|
|
4901
|
+
const [sOff, c5] = readULEB(buf, c4);
|
|
4902
|
+
const [sSz, c6] = readULEB(buf, c5);
|
|
4903
|
+
cur = c6;
|
|
4904
|
+
symElemIdx[i] = segIdx;
|
|
4905
|
+
symOff[i] = sOff;
|
|
4906
|
+
symSz[i] = sSz;
|
|
4907
|
+
}
|
|
4908
|
+
symNames.push(sName);
|
|
4909
|
+
} else if (kind === 3) {
|
|
4910
|
+
const [, c3] = readULEB(buf, cur);
|
|
4911
|
+
cur = c3;
|
|
4912
|
+
symNames.push("");
|
|
4913
|
+
}
|
|
4914
|
+
}
|
|
4915
|
+
}
|
|
4916
|
+
lp = subEnd;
|
|
4917
|
+
}
|
|
4918
|
+
} else if (name2 === "reloc.CODE" || name2 === "reloc.DATA") {
|
|
4919
|
+
const [, r1] = readULEB(buf, cp);
|
|
4920
|
+
const [cnt, r2] = readULEB(buf, r1);
|
|
4921
|
+
let cur = r2;
|
|
4922
|
+
const target = name2 === "reloc.CODE" ? rawCodeRelocs : rawDataRelocs;
|
|
4923
|
+
for (let i = 0; i < cnt; i++) {
|
|
4924
|
+
const rStart = cur;
|
|
4925
|
+
const rType = buf[cur++];
|
|
4926
|
+
const [ro, c2] = readULEB(buf, cur);
|
|
4927
|
+
const [rs, c3] = readULEB(buf, c2);
|
|
4928
|
+
cur = c3;
|
|
4929
|
+
if (HAS_ADDEND.has(rType)) {
|
|
4930
|
+
const [, c4] = readSLEB(buf, cur);
|
|
4931
|
+
cur = c4;
|
|
4932
|
+
}
|
|
4933
|
+
target.push({ rawBytes: new Uint8Array(buf.subarray(rStart, cur)), ro, rs });
|
|
4934
|
+
}
|
|
4935
|
+
}
|
|
4936
|
+
}
|
|
4937
|
+
pos = end;
|
|
4938
|
+
}
|
|
4939
|
+
const symParentIdx = new Int32Array(symKind.length).fill(-1);
|
|
4940
|
+
const segTopSyms = /* @__PURE__ */ new Map();
|
|
4941
|
+
if (isDist) {
|
|
4942
|
+
const bySeg = /* @__PURE__ */ new Map();
|
|
4943
|
+
for (let i = 0; i < symKind.length; i++) {
|
|
4944
|
+
if (symKind[i] === 1 && symElemIdx[i] >= 0) {
|
|
4945
|
+
const segIdx = symElemIdx[i];
|
|
4946
|
+
if (PARTITIONED_SEGS.has(segNames[segIdx])) {
|
|
4947
|
+
let list = bySeg.get(segIdx);
|
|
4948
|
+
if (!list) {
|
|
4949
|
+
list = [];
|
|
4950
|
+
bySeg.set(segIdx, list);
|
|
4951
|
+
}
|
|
4952
|
+
list.push(i);
|
|
4953
|
+
}
|
|
4954
|
+
}
|
|
4955
|
+
}
|
|
4956
|
+
for (const [segIdx, syms] of bySeg) {
|
|
4957
|
+
const segByteLen = (sEnds[segIdx] ?? 0) - (sPayloadStarts[segIdx] ?? 0);
|
|
4958
|
+
const sorted = [...syms].sort(
|
|
4959
|
+
(a, b) => symOff[a] - symOff[b] || symSz[b] - symSz[a]
|
|
4960
|
+
);
|
|
4961
|
+
const dedupTop = [];
|
|
4962
|
+
for (let k = 0; k < sorted.length; k++) {
|
|
4963
|
+
const i = sorted[k];
|
|
4964
|
+
const off = symOff[i];
|
|
4965
|
+
const sz = symSz[i];
|
|
4966
|
+
const lastTop = dedupTop[dedupTop.length - 1];
|
|
4967
|
+
if (lastTop && off < lastTop.end) {
|
|
4968
|
+
symParentIdx[i] = lastTop.symIdx;
|
|
4969
|
+
continue;
|
|
4970
|
+
}
|
|
4971
|
+
let nextOff = segByteLen;
|
|
4972
|
+
for (let m = k + 1; m < sorted.length; m++) {
|
|
4973
|
+
if (symOff[sorted[m]] > off) {
|
|
4974
|
+
nextOff = symOff[sorted[m]];
|
|
4975
|
+
break;
|
|
4976
|
+
}
|
|
4977
|
+
}
|
|
4978
|
+
const end = sz > 0 ? off + sz : nextOff;
|
|
4979
|
+
symParentIdx[i] = i;
|
|
4980
|
+
dedupTop.push({ symIdx: i, off, end });
|
|
4981
|
+
}
|
|
4982
|
+
segTopSyms.set(segIdx, dedupTop);
|
|
4983
|
+
}
|
|
4984
|
+
}
|
|
4985
|
+
const funcRelocs = Array.from({ length: fEnds.length }, () => []);
|
|
4986
|
+
const codeRelocList = [];
|
|
4987
|
+
for (const r of rawCodeRelocs) {
|
|
4988
|
+
let lo = 0;
|
|
4989
|
+
let hi = fEnds.length - 1;
|
|
4990
|
+
while (lo < hi) {
|
|
4991
|
+
const mid = lo + hi >> 1;
|
|
4992
|
+
if (fEnds[mid] <= r.ro) lo = mid + 1;
|
|
4993
|
+
else hi = mid;
|
|
4994
|
+
}
|
|
4995
|
+
if (fEnds.length > 0) {
|
|
4996
|
+
funcRelocs[lo].push(r.rs);
|
|
4997
|
+
codeRelocList.push({ ...r, funcIdx: lo });
|
|
4998
|
+
}
|
|
4999
|
+
}
|
|
5000
|
+
const segRelocs = Array.from({ length: segNames.length }, () => []);
|
|
5001
|
+
const symDataRelocs = /* @__PURE__ */ new Map();
|
|
5002
|
+
const dataRelocList = [];
|
|
5003
|
+
for (const r of rawDataRelocs) {
|
|
5004
|
+
let lo = 0;
|
|
5005
|
+
let hi = sEnds.length - 1;
|
|
5006
|
+
while (lo < hi) {
|
|
5007
|
+
const mid = lo + hi >> 1;
|
|
5008
|
+
if (sEnds[mid] <= r.ro) lo = mid + 1;
|
|
5009
|
+
else hi = mid;
|
|
5010
|
+
}
|
|
5011
|
+
if (sEnds.length > 0 && lo < segRelocs.length) {
|
|
5012
|
+
const offInSeg = r.ro - (sPayloadStarts[lo] ?? 0);
|
|
5013
|
+
let ownerSymIdx = -1;
|
|
5014
|
+
const topList = segTopSyms.get(lo);
|
|
5015
|
+
if (topList) {
|
|
5016
|
+
const owner = topList.find((t) => offInSeg >= t.off && offInSeg < t.end);
|
|
5017
|
+
if (owner) ownerSymIdx = owner.symIdx;
|
|
5018
|
+
}
|
|
5019
|
+
if (ownerSymIdx !== -1) {
|
|
5020
|
+
let list = symDataRelocs.get(ownerSymIdx);
|
|
5021
|
+
if (!list) {
|
|
5022
|
+
list = [];
|
|
5023
|
+
symDataRelocs.set(ownerSymIdx, list);
|
|
5024
|
+
}
|
|
5025
|
+
list.push(r.rs);
|
|
5026
|
+
} else {
|
|
5027
|
+
segRelocs[lo].push(r.rs);
|
|
5028
|
+
}
|
|
5029
|
+
dataRelocList.push({ ...r, segIdx: lo, offInSeg, ownerSymIdx });
|
|
5030
|
+
}
|
|
5031
|
+
}
|
|
5032
|
+
const typePrefixesInObj = /* @__PURE__ */ new Set();
|
|
5033
|
+
if (isDist) {
|
|
5034
|
+
for (let i = 0; i < symKind.length; i++) {
|
|
5035
|
+
if ((symFlags[i] & 16) === 0 && symNames[i].startsWith("$s") && symNames[i].endsWith("Mn")) {
|
|
5036
|
+
typePrefixesInObj.add(symNames[i].slice(0, -2));
|
|
5037
|
+
}
|
|
5038
|
+
}
|
|
5039
|
+
}
|
|
5040
|
+
const objcRegisterFuncToTypePrefix = /* @__PURE__ */ new Map();
|
|
5041
|
+
const objcClassSymToTypePrefix = /* @__PURE__ */ new Map();
|
|
5042
|
+
if (isDist) {
|
|
5043
|
+
for (const symIdx of initFuncs) {
|
|
5044
|
+
if (symKind[symIdx] === 0 && symElemIdx[symIdx] >= numImportFuncs) {
|
|
5045
|
+
const lf = symElemIdx[symIdx] - numImportFuncs;
|
|
5046
|
+
const fName = symNames[symIdx];
|
|
5047
|
+
if (fName.startsWith(".L.swift.objc.register")) {
|
|
5048
|
+
const relSyms = funcRelocs[lf].map((si) => symNames[si]);
|
|
5049
|
+
const mnSym = relSyms.find((s) => s.startsWith("$s") && s.endsWith("Mn"));
|
|
5050
|
+
const objcSym = relSyms.find((s) => s.startsWith("._OBJC_CLASS_"));
|
|
5051
|
+
if (mnSym) {
|
|
5052
|
+
const pref = mnSym.slice(0, -2);
|
|
5053
|
+
objcRegisterFuncToTypePrefix.set(lf, pref);
|
|
5054
|
+
if (objcSym) objcClassSymToTypePrefix.set(objcSym, pref);
|
|
5055
|
+
}
|
|
5056
|
+
}
|
|
5057
|
+
}
|
|
5058
|
+
}
|
|
5059
|
+
}
|
|
5060
|
+
const rootFuncs = [];
|
|
5061
|
+
const rootSegs = [];
|
|
5062
|
+
for (const symIdx of initFuncs) {
|
|
5063
|
+
if (symKind[symIdx] === 0 && symElemIdx[symIdx] >= numImportFuncs) {
|
|
5064
|
+
const lf = symElemIdx[symIdx] - numImportFuncs;
|
|
5065
|
+
if (!objcRegisterFuncToTypePrefix.has(lf)) {
|
|
5066
|
+
rootFuncs.push(lf);
|
|
5067
|
+
}
|
|
5068
|
+
}
|
|
5069
|
+
}
|
|
5070
|
+
for (let i = 0; i < symKind.length; i++) {
|
|
5071
|
+
const isRootSym = isDist ? (symFlags[i] & 32) !== 0 : (symFlags[i] & 128) !== 0 || (symFlags[i] & 32) !== 0;
|
|
5072
|
+
if (isRootSym && (symFlags[i] & 16) === 0) {
|
|
5073
|
+
if (symKind[i] === 0 && symElemIdx[i] >= numImportFuncs) {
|
|
5074
|
+
rootFuncs.push(symElemIdx[i] - numImportFuncs);
|
|
5075
|
+
} else if (symKind[i] === 1 && symElemIdx[i] >= 0) {
|
|
5076
|
+
rootSegs.push(symElemIdx[i]);
|
|
5077
|
+
}
|
|
5078
|
+
}
|
|
5079
|
+
}
|
|
5080
|
+
for (let i = 0; i < segNames.length; i++) {
|
|
5081
|
+
const sName = segNames[i];
|
|
5082
|
+
if (isDist && (sName === "swift5_type_metadata" || sName === "swift5_protocol_conformances" || sName === "__objc_classes" || sName.startsWith(".init_array"))) {
|
|
5083
|
+
continue;
|
|
5084
|
+
}
|
|
5085
|
+
if (isRootSegName(sName) || !isDist && ((segFlags[i] ?? 0) & 4) !== 0) {
|
|
5086
|
+
rootSegs.push(i);
|
|
5087
|
+
}
|
|
5088
|
+
}
|
|
5089
|
+
return {
|
|
5090
|
+
file,
|
|
5091
|
+
isDist,
|
|
5092
|
+
numImportFuncs,
|
|
5093
|
+
numFuncs: fEnds.length,
|
|
5094
|
+
numSegments: segNames.length,
|
|
5095
|
+
segNames,
|
|
5096
|
+
symKind,
|
|
5097
|
+
symFlags,
|
|
5098
|
+
symElemIdx,
|
|
5099
|
+
symOff,
|
|
5100
|
+
symSz,
|
|
5101
|
+
symParentIdx,
|
|
5102
|
+
symNames,
|
|
5103
|
+
funcRelocs,
|
|
5104
|
+
segRelocs,
|
|
5105
|
+
symDataRelocs,
|
|
5106
|
+
codeRelocList,
|
|
5107
|
+
dataRelocList,
|
|
5108
|
+
initFuncSyms: initFuncs,
|
|
5109
|
+
objcRegisterFuncToTypePrefix,
|
|
5110
|
+
objcClassSymToTypePrefix,
|
|
5111
|
+
typePrefixesInObj,
|
|
5112
|
+
rootFuncs,
|
|
5113
|
+
rootSegs
|
|
5114
|
+
};
|
|
5115
|
+
}
|
|
5116
|
+
function parseWasmObjectCached(file, isDist, useCache) {
|
|
5117
|
+
const key = `${isDist ? "1" : "0"}:${file}`;
|
|
5118
|
+
if (useCache) {
|
|
5119
|
+
const hit = parsedObjectCache.get(key);
|
|
5120
|
+
if (hit) return hit;
|
|
5121
|
+
}
|
|
5122
|
+
const parsed = parseWasmObjectBytes(file, new Uint8Array(fs6.readFileSync(file)), isDist);
|
|
5123
|
+
if (useCache) parsedObjectCache.set(key, parsed);
|
|
5124
|
+
return parsed;
|
|
5125
|
+
}
|
|
5126
|
+
function peachHome2() {
|
|
5127
|
+
const override = process.env.PEACH_HOME;
|
|
5128
|
+
return override ? path12.resolve(override) : path12.join(os2.homedir(), ".peach");
|
|
5129
|
+
}
|
|
5130
|
+
function ensureUnpackedSdkObjects(sdkWasiDir) {
|
|
5131
|
+
const sdkKey = createHash7("sha256").update(sdkWasiDir).digest("hex").slice(0, 16);
|
|
5132
|
+
const outDir = path12.join(peachHome2(), "cache", "swift-builds", `sdk-objs-${sdkKey}`);
|
|
5133
|
+
const stamp = path12.join(outDir, ".complete");
|
|
5134
|
+
if (fs6.existsSync(stamp)) return outDir;
|
|
5135
|
+
const tmpDir = `${outDir}.${process.pid}.${Date.now()}.tmp`;
|
|
5136
|
+
fs6.mkdirSync(tmpDir, { recursive: true });
|
|
5137
|
+
const archives = fs6.readdirSync(sdkWasiDir).filter((f) => f.endsWith(".a")).sort();
|
|
5138
|
+
for (const archive of archives) {
|
|
5139
|
+
const aBase = archive.replace(/\.a$/, "");
|
|
5140
|
+
const members = readArMembers(
|
|
5141
|
+
new Uint8Array(fs6.readFileSync(path12.join(sdkWasiDir, archive)))
|
|
5142
|
+
);
|
|
5143
|
+
const seen = /* @__PURE__ */ new Map();
|
|
5144
|
+
for (const m of members) {
|
|
5145
|
+
const count = (seen.get(m.name) ?? 0) + 1;
|
|
5146
|
+
seen.set(m.name, count);
|
|
5147
|
+
const suffix = count > 1 ? `_${count}` : "";
|
|
5148
|
+
const safeName = m.name.replaceAll("/", "__");
|
|
5149
|
+
const outName = `${aBase}__${safeName}${suffix}`;
|
|
5150
|
+
fs6.writeFileSync(path12.join(tmpDir, outName), m.bytes);
|
|
5151
|
+
}
|
|
5152
|
+
}
|
|
5153
|
+
fs6.writeFileSync(path12.join(tmpDir, ".complete"), "1\n");
|
|
5154
|
+
fs6.mkdirSync(path12.dirname(outDir), { recursive: true });
|
|
5155
|
+
if (fs6.existsSync(stamp)) {
|
|
5156
|
+
fs6.rmSync(tmpDir, { recursive: true, force: true });
|
|
5157
|
+
return outDir;
|
|
5158
|
+
}
|
|
5159
|
+
fs6.rmSync(outDir, { recursive: true, force: true });
|
|
5160
|
+
fs6.renameSync(tmpDir, outDir);
|
|
5161
|
+
return outDir;
|
|
5162
|
+
}
|
|
5163
|
+
function isPrunableSdkFile(file) {
|
|
5164
|
+
const base = path12.basename(file);
|
|
5165
|
+
const aBase = base.split("__")[0];
|
|
5166
|
+
if (PRUNED_SDK_ARCHIVES.has(aBase)) return true;
|
|
5167
|
+
if (base === "libswiftCore__Swift.o" || base === "libswift_Concurrency___Concurrency.o") {
|
|
5168
|
+
return true;
|
|
5169
|
+
}
|
|
5170
|
+
return false;
|
|
5171
|
+
}
|
|
5172
|
+
function getModulePrefix(file) {
|
|
5173
|
+
const base = path12.basename(file);
|
|
5174
|
+
const dbl = base.indexOf("__");
|
|
5175
|
+
if (dbl > 0) return base.slice(0, dbl);
|
|
5176
|
+
const dash = base.indexOf("-");
|
|
5177
|
+
return dash > 0 ? base.slice(0, dash) : base;
|
|
5178
|
+
}
|
|
5179
|
+
function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot) {
|
|
5180
|
+
const rspPath = path12.join(directory, ".peach-link.rsp");
|
|
5181
|
+
if (!fs6.existsSync(rspPath)) return;
|
|
5182
|
+
const origRsp = fs6.readFileSync(rspPath, "utf8");
|
|
5183
|
+
const tokens = Array.from(origRsp.matchAll(/"([^"]+)"|(\S+)/g), (m) => m[1] ?? m[2]);
|
|
5184
|
+
if (!tokens.includes("--start-lib")) return;
|
|
5185
|
+
const sdkFlag = tokens.find(
|
|
5186
|
+
(t) => t.startsWith("-L") && t.endsWith("/swift_static/wasi")
|
|
5187
|
+
);
|
|
5188
|
+
if (!sdkFlag) return;
|
|
5189
|
+
const sdkWasiDir = sdkFlag.slice(2);
|
|
5190
|
+
const sdkObjsDir = ensureUnpackedSdkObjects(sdkWasiDir);
|
|
5191
|
+
const distDir = path12.join(moduleRoot, "lib");
|
|
5192
|
+
const prunedObjsDir = path12.join(directory, ".peach-pruned-objs");
|
|
5193
|
+
fs6.rmSync(prunedObjsDir, { recursive: true, force: true });
|
|
5194
|
+
fs6.mkdirSync(prunedObjsDir, { recursive: true });
|
|
5195
|
+
const distFiles = [];
|
|
5196
|
+
const eagerFiles = [];
|
|
5197
|
+
const extraArchiveObjs = [];
|
|
5198
|
+
let inStartLib = false;
|
|
5199
|
+
let swiftrtOrigPath = "";
|
|
5200
|
+
for (const t of tokens) {
|
|
5201
|
+
if (t === "--start-lib") {
|
|
5202
|
+
inStartLib = true;
|
|
5203
|
+
continue;
|
|
5204
|
+
}
|
|
5205
|
+
if (t === "--end-lib") {
|
|
5206
|
+
inStartLib = false;
|
|
5207
|
+
continue;
|
|
5208
|
+
}
|
|
5209
|
+
if (t.endsWith(".o")) {
|
|
5210
|
+
if (t.startsWith(distDir)) {
|
|
5211
|
+
if (path12.basename(t) !== "Foundation-NSStringFormatting.o") {
|
|
5212
|
+
distFiles.push(t);
|
|
5213
|
+
}
|
|
5214
|
+
if (!inStartLib) eagerFiles.push(t);
|
|
5215
|
+
} else if (!inStartLib) {
|
|
5216
|
+
if (t.endsWith("/swiftrt.o")) {
|
|
5217
|
+
swiftrtOrigPath = t;
|
|
5218
|
+
} else {
|
|
5219
|
+
eagerFiles.push(t);
|
|
5220
|
+
}
|
|
5221
|
+
}
|
|
5222
|
+
} else if (!inStartLib && t.endsWith(".a") && !t.endsWith("libclang_rt.builtins-wasm32.a") && fs6.existsSync(t)) {
|
|
5223
|
+
const members = readArMembers(new Uint8Array(fs6.readFileSync(t)));
|
|
5224
|
+
for (const m of members) {
|
|
5225
|
+
extraArchiveObjs.push(parseWasmObjectBytes(`${t}(${m.name})`, m.bytes, false));
|
|
5226
|
+
}
|
|
5227
|
+
}
|
|
5228
|
+
}
|
|
5229
|
+
let patchedSwiftrtPath = "";
|
|
5230
|
+
if (swiftrtOrigPath && fs6.existsSync(swiftrtOrigPath)) {
|
|
5231
|
+
patchedSwiftrtPath = path12.join(prunedObjsDir, "swiftrt-patched.o");
|
|
5232
|
+
fs6.writeFileSync(
|
|
5233
|
+
patchedSwiftrtPath,
|
|
5234
|
+
patchSwiftrtObject(new Uint8Array(fs6.readFileSync(swiftrtOrigPath)))
|
|
5235
|
+
);
|
|
5236
|
+
eagerFiles.push(patchedSwiftrtPath);
|
|
5237
|
+
}
|
|
5238
|
+
const allSdkObjFiles = fs6.readdirSync(sdkObjsDir).filter((f) => f.endsWith(".o") || f.endsWith(".obj")).sort();
|
|
5239
|
+
const sdkFiles = allSdkObjFiles.map((f) => path12.join(sdkObjsDir, f));
|
|
5240
|
+
const distObjs = /* @__PURE__ */ new Map();
|
|
5241
|
+
const lazyProviders = /* @__PURE__ */ new Map();
|
|
5242
|
+
const registerLazyProvider = (obj) => {
|
|
5243
|
+
for (let i = 0; i < obj.symNames.length; i++) {
|
|
5244
|
+
const fl = obj.symFlags[i];
|
|
5245
|
+
const isUndef = (fl & 16) !== 0;
|
|
5246
|
+
const isLocal = (fl & 3) === 2;
|
|
5247
|
+
if (!isUndef && !isLocal) {
|
|
5248
|
+
const name2 = obj.symNames[i];
|
|
5249
|
+
if (name2) {
|
|
5250
|
+
let list = lazyProviders.get(name2);
|
|
5251
|
+
if (!list) {
|
|
5252
|
+
list = [];
|
|
5253
|
+
lazyProviders.set(name2, list);
|
|
5254
|
+
}
|
|
5255
|
+
list.push(obj);
|
|
5256
|
+
}
|
|
5257
|
+
}
|
|
5258
|
+
}
|
|
5259
|
+
};
|
|
5260
|
+
for (const f of [...distFiles, ...sdkFiles]) {
|
|
5261
|
+
const isSdk = f.startsWith(sdkObjsDir);
|
|
5262
|
+
const isPrunableSwift = !isSdk || isPrunableSdkFile(f);
|
|
5263
|
+
const obj = parseWasmObjectCached(f, isPrunableSwift, true);
|
|
5264
|
+
distObjs.set(f, obj);
|
|
5265
|
+
registerLazyProvider(obj);
|
|
5266
|
+
}
|
|
5267
|
+
for (const obj of extraArchiveObjs) {
|
|
5268
|
+
registerLazyProvider(obj);
|
|
5269
|
+
}
|
|
5270
|
+
const extractedObjs = /* @__PURE__ */ new Set();
|
|
5271
|
+
const definedGlobalSyms = /* @__PURE__ */ new Map();
|
|
5272
|
+
const extractedSymbolDefs = /* @__PURE__ */ new Map();
|
|
5273
|
+
const liveGlobalNames = /* @__PURE__ */ new Set();
|
|
5274
|
+
const liveFuncs = /* @__PURE__ */ new Map();
|
|
5275
|
+
const liveSegs = /* @__PURE__ */ new Map();
|
|
5276
|
+
const liveDataSyms = /* @__PURE__ */ new Map();
|
|
5277
|
+
const liveTypes = /* @__PURE__ */ new Map();
|
|
5278
|
+
const workQueue = [];
|
|
5279
|
+
const pendingUndef = /* @__PURE__ */ new Set();
|
|
5280
|
+
const markFuncLive = (obj, localFuncIdx) => {
|
|
5281
|
+
const arr = liveFuncs.get(obj);
|
|
5282
|
+
if (arr[localFuncIdx]) return;
|
|
5283
|
+
arr[localFuncIdx] = 1;
|
|
5284
|
+
workQueue.push({ kind: "func", obj, idx: localFuncIdx });
|
|
5285
|
+
};
|
|
5286
|
+
const markSegLive = (obj, segIdx) => {
|
|
5287
|
+
const arr = liveSegs.get(obj);
|
|
5288
|
+
if (arr[segIdx]) return;
|
|
5289
|
+
arr[segIdx] = 1;
|
|
5290
|
+
workQueue.push({ kind: "seg", obj, idx: segIdx });
|
|
5291
|
+
};
|
|
5292
|
+
const markDataSymLive = (obj, symIdx) => {
|
|
5293
|
+
const set = liveDataSyms.get(obj);
|
|
5294
|
+
if (set.has(symIdx)) return;
|
|
5295
|
+
set.add(symIdx);
|
|
5296
|
+
workQueue.push({ kind: "datasym", obj, symIdx });
|
|
5297
|
+
};
|
|
5298
|
+
const markTypeLive = (obj, pref) => {
|
|
5299
|
+
const set = liveTypes.get(obj);
|
|
5300
|
+
if (set.has(pref)) return;
|
|
5301
|
+
set.add(pref);
|
|
5302
|
+
const mnName = `${pref}Mn`;
|
|
5303
|
+
for (let i = 0; i < obj.symNames.length; i++) {
|
|
5304
|
+
if (obj.symNames[i] === mnName && (obj.symFlags[i] & 16) === 0) {
|
|
5305
|
+
activateSymbolInObj(obj, i);
|
|
5306
|
+
}
|
|
5307
|
+
}
|
|
5308
|
+
for (const [lf, p] of obj.objcRegisterFuncToTypePrefix) {
|
|
5309
|
+
if (p === pref) {
|
|
5310
|
+
markFuncLive(obj, lf);
|
|
5311
|
+
}
|
|
5312
|
+
}
|
|
5313
|
+
for (let sIdx = 0; sIdx < obj.segNames.length; sIdx++) {
|
|
5314
|
+
if (obj.segNames[sIdx] === "swift5_protocol_conformances") {
|
|
5315
|
+
for (const r of obj.dataRelocList) {
|
|
5316
|
+
if (r.segIdx === sIdx) {
|
|
5317
|
+
const mcName = obj.symNames[r.rs];
|
|
5318
|
+
if (mcName.startsWith(pref)) {
|
|
5319
|
+
activateSymbolInObj(obj, r.rs);
|
|
5320
|
+
}
|
|
5321
|
+
}
|
|
5322
|
+
}
|
|
5323
|
+
}
|
|
5324
|
+
}
|
|
5325
|
+
};
|
|
5326
|
+
const checkTypeTrigger = (obj, rawSymName) => {
|
|
5327
|
+
if (!obj.isDist || !rawSymName) return;
|
|
5328
|
+
const sName = rawSymName.startsWith(".Lgot.") ? rawSymName.slice(6) : rawSymName;
|
|
5329
|
+
const objcPref = obj.objcClassSymToTypePrefix.get(sName);
|
|
5330
|
+
if (objcPref) {
|
|
5331
|
+
markTypeLive(obj, objcPref);
|
|
5332
|
+
return;
|
|
5333
|
+
}
|
|
5334
|
+
if (!sName.startsWith("$s") || sName.endsWith("Tm")) return;
|
|
5335
|
+
for (const suffix of ["Ma", "Mf", "N", "Mn", "ML"]) {
|
|
5336
|
+
if (sName.endsWith(suffix)) {
|
|
5337
|
+
const cand = sName.slice(0, -suffix.length);
|
|
5338
|
+
if (obj.typePrefixesInObj.has(cand)) {
|
|
5339
|
+
markTypeLive(obj, cand);
|
|
5340
|
+
return;
|
|
5341
|
+
}
|
|
5342
|
+
}
|
|
5343
|
+
}
|
|
5344
|
+
if (obj.file.endsWith("libswiftCore__Swift.o") || obj.file.endsWith("libswift_Concurrency___Concurrency.o")) {
|
|
5345
|
+
for (const pref of obj.typePrefixesInObj) {
|
|
5346
|
+
if (sName.startsWith(pref)) {
|
|
5347
|
+
markTypeLive(obj, pref);
|
|
5348
|
+
}
|
|
5349
|
+
}
|
|
5350
|
+
}
|
|
5351
|
+
};
|
|
5352
|
+
const activateGlobalName = (name2) => {
|
|
5353
|
+
if (!name2) return;
|
|
5354
|
+
if (!liveGlobalNames.has(name2)) liveGlobalNames.add(name2);
|
|
5355
|
+
const defs = extractedSymbolDefs.get(name2);
|
|
5356
|
+
if (defs) {
|
|
5357
|
+
for (const d of defs) {
|
|
5358
|
+
activateSymbolInObj(d.obj, d.symIdx);
|
|
5359
|
+
}
|
|
5360
|
+
}
|
|
5361
|
+
};
|
|
5362
|
+
function activateSymbolInObj(obj, symIdx) {
|
|
5363
|
+
const kind = obj.symKind[symIdx];
|
|
5364
|
+
const el = obj.symElemIdx[symIdx];
|
|
5365
|
+
const sName = obj.symNames[symIdx];
|
|
5366
|
+
const fl = obj.symFlags[symIdx];
|
|
5367
|
+
const isUndef = (fl & 16) !== 0;
|
|
5368
|
+
const isLocal = (fl & 3) === 2;
|
|
5369
|
+
checkTypeTrigger(obj, sName);
|
|
5370
|
+
if (!isUndef && !isLocal && sName && !liveGlobalNames.has(sName)) {
|
|
5371
|
+
activateGlobalName(sName);
|
|
5372
|
+
}
|
|
5373
|
+
if (kind === 0 && el >= obj.numImportFuncs) {
|
|
5374
|
+
markFuncLive(obj, el - obj.numImportFuncs);
|
|
5375
|
+
} else if (kind === 1 && el >= 0) {
|
|
5376
|
+
const pIdx = obj.symParentIdx[symIdx];
|
|
5377
|
+
if (pIdx !== -1) {
|
|
5378
|
+
markDataSymLive(obj, pIdx);
|
|
5379
|
+
const parentName = obj.symNames[pIdx];
|
|
5380
|
+
checkTypeTrigger(obj, parentName);
|
|
5381
|
+
}
|
|
5382
|
+
markSegLive(obj, el);
|
|
5383
|
+
}
|
|
5384
|
+
}
|
|
5385
|
+
const extractObject = (obj) => {
|
|
5386
|
+
if (extractedObjs.has(obj)) return;
|
|
5387
|
+
extractedObjs.add(obj);
|
|
5388
|
+
liveFuncs.set(obj, new Uint8Array(obj.numFuncs));
|
|
5389
|
+
liveSegs.set(obj, new Uint8Array(obj.numSegments));
|
|
5390
|
+
liveDataSyms.set(obj, /* @__PURE__ */ new Set());
|
|
5391
|
+
liveTypes.set(obj, /* @__PURE__ */ new Set());
|
|
5392
|
+
for (let i = 0; i < obj.symNames.length; i++) {
|
|
5393
|
+
const fl = obj.symFlags[i];
|
|
5394
|
+
const isUndef = (fl & 16) !== 0;
|
|
5395
|
+
const isLocal = (fl & 3) === 2;
|
|
5396
|
+
const isWeak = (fl & 3) === 1;
|
|
5397
|
+
if (!isUndef && !isLocal) {
|
|
5398
|
+
const name2 = obj.symNames[i];
|
|
5399
|
+
if (name2) {
|
|
5400
|
+
if (!definedGlobalSyms.has(name2) || !isWeak) {
|
|
5401
|
+
definedGlobalSyms.set(name2, { obj, symIdx: i });
|
|
5402
|
+
}
|
|
5403
|
+
let dList = extractedSymbolDefs.get(name2);
|
|
5404
|
+
if (!dList) {
|
|
5405
|
+
dList = [];
|
|
5406
|
+
extractedSymbolDefs.set(name2, dList);
|
|
5407
|
+
}
|
|
5408
|
+
dList.push({ obj, symIdx: i });
|
|
5409
|
+
if (pendingUndef.has(name2) || liveGlobalNames.has(name2)) {
|
|
5410
|
+
pendingUndef.delete(name2);
|
|
5411
|
+
activateSymbolInObj(obj, i);
|
|
5412
|
+
}
|
|
5413
|
+
}
|
|
5414
|
+
}
|
|
5415
|
+
}
|
|
5416
|
+
for (const fIdx of obj.rootFuncs) markFuncLive(obj, fIdx);
|
|
5417
|
+
for (const sIdx of obj.rootSegs) markSegLive(obj, sIdx);
|
|
5418
|
+
if (obj.file.endsWith("libswiftCore__Swift.o")) {
|
|
5419
|
+
for (const pref of obj.typePrefixesInObj) {
|
|
5420
|
+
if (!pref.startsWith("$ss")) {
|
|
5421
|
+
markTypeLive(obj, pref);
|
|
5422
|
+
}
|
|
5423
|
+
}
|
|
5424
|
+
}
|
|
5425
|
+
if (obj.isDist) {
|
|
5426
|
+
for (let sIdx = 0; sIdx < obj.segNames.length; sIdx++) {
|
|
5427
|
+
if (obj.segNames[sIdx] === "swift5_protocol_conformances") {
|
|
5428
|
+
for (const r of obj.dataRelocList) {
|
|
5429
|
+
if (r.segIdx === sIdx) {
|
|
5430
|
+
const mcName = obj.symNames[r.rs];
|
|
5431
|
+
let matchesLocalType = false;
|
|
5432
|
+
for (const pref of obj.typePrefixesInObj) {
|
|
5433
|
+
if (mcName.startsWith(pref)) {
|
|
5434
|
+
matchesLocalType = true;
|
|
5435
|
+
break;
|
|
5436
|
+
}
|
|
5437
|
+
}
|
|
5438
|
+
if (!matchesLocalType) {
|
|
5439
|
+
activateSymbolInObj(obj, r.rs);
|
|
5440
|
+
}
|
|
5441
|
+
}
|
|
5442
|
+
}
|
|
5443
|
+
}
|
|
5444
|
+
}
|
|
5445
|
+
}
|
|
5446
|
+
};
|
|
5447
|
+
for (const f of eagerFiles) {
|
|
5448
|
+
const isDist = f.startsWith(distDir);
|
|
5449
|
+
const obj = distObjs.get(f) ?? parseWasmObjectCached(f, isDist, false);
|
|
5450
|
+
extractObject(obj);
|
|
5451
|
+
if (isDist) {
|
|
5452
|
+
const base = path12.basename(f);
|
|
5453
|
+
if (base.startsWith("PeachFoundation-") || base.startsWith("PeachObjC-") || base.startsWith("PeachICU-") || base.startsWith("Darwin-")) {
|
|
5454
|
+
for (let i = 0; i < obj.symNames.length; i++) {
|
|
5455
|
+
const sName = obj.symNames[i];
|
|
5456
|
+
if ((obj.symFlags[i] & 16) === 0 && sName && !sName.startsWith("$s") && !sName.startsWith(".")) {
|
|
5457
|
+
activateSymbolInObj(obj, i);
|
|
5458
|
+
}
|
|
5459
|
+
}
|
|
5460
|
+
}
|
|
5461
|
+
}
|
|
5462
|
+
}
|
|
5463
|
+
for (const symName of ["_initialize", "__main_argc_argv", "main"]) {
|
|
5464
|
+
const def = definedGlobalSyms.get(symName);
|
|
5465
|
+
if (def) activateSymbolInObj(def.obj, def.symIdx);
|
|
5466
|
+
}
|
|
5467
|
+
while (workQueue.length > 0) {
|
|
5468
|
+
const item = workQueue.pop();
|
|
5469
|
+
const obj = item.obj;
|
|
5470
|
+
let relocs;
|
|
5471
|
+
if (item.kind === "func") {
|
|
5472
|
+
relocs = obj.funcRelocs[item.idx];
|
|
5473
|
+
} else if (item.kind === "seg") {
|
|
5474
|
+
relocs = obj.segRelocs[item.idx];
|
|
5475
|
+
} else {
|
|
5476
|
+
relocs = obj.symDataRelocs.get(item.symIdx) ?? [];
|
|
5477
|
+
}
|
|
5478
|
+
for (const symIdx of relocs) {
|
|
5479
|
+
const fl = obj.symFlags[symIdx];
|
|
5480
|
+
const isUndef = (fl & 16) !== 0;
|
|
5481
|
+
const isLocal = (fl & 3) === 2;
|
|
5482
|
+
const isWeak = (fl & 3) === 1;
|
|
5483
|
+
if (!isUndef) {
|
|
5484
|
+
activateSymbolInObj(obj, symIdx);
|
|
5485
|
+
if (!isLocal) {
|
|
5486
|
+
const name2 = obj.symNames[symIdx];
|
|
5487
|
+
activateGlobalName(name2);
|
|
5488
|
+
}
|
|
5489
|
+
} else {
|
|
5490
|
+
const name2 = obj.symNames[symIdx];
|
|
5491
|
+
if (!name2) continue;
|
|
5492
|
+
let def = definedGlobalSyms.get(name2);
|
|
5493
|
+
if (!def) {
|
|
5494
|
+
const cands = lazyProviders.get(name2);
|
|
5495
|
+
if (cands && cands.length > 0) {
|
|
5496
|
+
const reqMod = getModulePrefix(obj.file);
|
|
5497
|
+
let chosen = cands.find((c) => extractedObjs.has(c));
|
|
5498
|
+
if (!chosen) {
|
|
5499
|
+
const sameMod = cands.filter((c) => getModulePrefix(c.file) === reqMod);
|
|
5500
|
+
const sdkPool = cands.filter((c) => c.file.startsWith(sdkObjsDir));
|
|
5501
|
+
const pool = sameMod.length > 0 ? sameMod : sdkPool.length > 0 ? sdkPool : cands;
|
|
5502
|
+
chosen = pool.reduce(
|
|
5503
|
+
(a, b) => a.rootSegs.length + a.rootFuncs.length <= b.rootSegs.length + b.rootFuncs.length ? a : b
|
|
5504
|
+
);
|
|
5505
|
+
}
|
|
5506
|
+
extractObject(chosen);
|
|
5507
|
+
def = definedGlobalSyms.get(name2);
|
|
5508
|
+
} else if (!isWeak) {
|
|
5509
|
+
pendingUndef.add(name2);
|
|
5510
|
+
}
|
|
5511
|
+
}
|
|
5512
|
+
if (def) {
|
|
5513
|
+
activateGlobalName(name2);
|
|
5514
|
+
}
|
|
5515
|
+
}
|
|
5516
|
+
}
|
|
5517
|
+
}
|
|
5518
|
+
const isSpecialSegRelocLive = (obj, segName, r) => {
|
|
5519
|
+
const sLive = liveSegs.get(obj);
|
|
5520
|
+
const dLive = liveDataSyms.get(obj);
|
|
5521
|
+
const tLive = liveTypes.get(obj);
|
|
5522
|
+
const targetName = obj.symNames[r.rs] ?? "";
|
|
5523
|
+
if (segName === "swift5_type_metadata") {
|
|
5524
|
+
const raw2 = targetName.startsWith(".Lgot.") ? targetName.slice(6) : targetName;
|
|
5525
|
+
if (raw2.endsWith("Mn")) {
|
|
5526
|
+
const pref = raw2.slice(0, -2);
|
|
5527
|
+
if (obj.typePrefixesInObj.has(pref)) return tLive.has(pref);
|
|
5528
|
+
}
|
|
5529
|
+
return true;
|
|
5530
|
+
}
|
|
5531
|
+
if (segName === "swift5_protocol_conformances" || segName === "__objc_classes") {
|
|
5532
|
+
const pIdx = obj.symParentIdx[r.rs];
|
|
5533
|
+
if (pIdx !== -1) return dLive.has(pIdx);
|
|
5534
|
+
const segIdx = obj.symElemIdx[r.rs];
|
|
5535
|
+
return segIdx >= 0 ? sLive[segIdx] === 1 : true;
|
|
5536
|
+
}
|
|
5537
|
+
return true;
|
|
5538
|
+
};
|
|
5539
|
+
const writePrunedObject = (obj, outFile) => {
|
|
5540
|
+
const buf = new Uint8Array(fs6.readFileSync(obj.file));
|
|
5541
|
+
const fLive = liveFuncs.get(obj);
|
|
5542
|
+
const sLive = liveSegs.get(obj);
|
|
5543
|
+
const dLive = liveDataSyms.get(obj);
|
|
5544
|
+
const keptCodeRelocs = obj.codeRelocList.filter((r) => fLive[r.funcIdx] === 1);
|
|
5545
|
+
const firstLiveInSpecialSeg = /* @__PURE__ */ new Map();
|
|
5546
|
+
const deadSpecialSegs = /* @__PURE__ */ new Set();
|
|
5547
|
+
for (let sIdx = 0; sIdx < obj.segNames.length; sIdx++) {
|
|
5548
|
+
const sName = obj.segNames[sIdx];
|
|
5549
|
+
if (sName === "swift5_type_metadata" || sName === "swift5_protocol_conformances" || sName === "__objc_classes") {
|
|
5550
|
+
const segRels = obj.dataRelocList.filter((r) => r.segIdx === sIdx);
|
|
5551
|
+
const liveRels = segRels.filter((r) => isSpecialSegRelocLive(obj, sName, r));
|
|
5552
|
+
if (liveRels.length === 0) {
|
|
5553
|
+
deadSpecialSegs.add(sIdx);
|
|
5554
|
+
} else {
|
|
5555
|
+
const first = liveRels[0];
|
|
5556
|
+
const rType = first.rawBytes[0];
|
|
5557
|
+
const [, afterRoOff] = readULEB(first.rawBytes, 1);
|
|
5558
|
+
firstLiveInSpecialSeg.set(sIdx, {
|
|
5559
|
+
rType,
|
|
5560
|
+
afterRo: first.rawBytes.subarray(afterRoOff)
|
|
5561
|
+
});
|
|
5562
|
+
}
|
|
5563
|
+
}
|
|
5564
|
+
}
|
|
5565
|
+
const keptDataRelocBytes = [];
|
|
5566
|
+
const zeroDataRelocOffsets = [];
|
|
5567
|
+
const usedSyms = /* @__PURE__ */ new Set();
|
|
5568
|
+
for (const r of keptCodeRelocs) usedSyms.add(r.rs);
|
|
5569
|
+
for (const r of obj.dataRelocList) {
|
|
5570
|
+
const sName = obj.segNames[r.segIdx];
|
|
5571
|
+
if (sName === "swift5_type_metadata" || sName === "swift5_protocol_conformances" || sName === "__objc_classes") {
|
|
5572
|
+
if (deadSpecialSegs.has(r.segIdx)) continue;
|
|
5573
|
+
if (isSpecialSegRelocLive(obj, sName, r)) {
|
|
5574
|
+
keptDataRelocBytes.push(r.rawBytes);
|
|
5575
|
+
usedSyms.add(r.rs);
|
|
5576
|
+
} else if (sName === "__objc_classes") {
|
|
5577
|
+
zeroDataRelocOffsets.push(r.ro);
|
|
5578
|
+
} else {
|
|
5579
|
+
const repl = firstLiveInSpecialSeg.get(r.segIdx);
|
|
5580
|
+
const roBytes = encodeULEB(r.ro);
|
|
5581
|
+
const out = new Uint8Array(1 + roBytes.length + repl.afterRo.length);
|
|
5582
|
+
out[0] = repl.rType;
|
|
5583
|
+
out.set(roBytes, 1);
|
|
5584
|
+
out.set(repl.afterRo, 1 + roBytes.length);
|
|
5585
|
+
keptDataRelocBytes.push(out);
|
|
5586
|
+
}
|
|
5587
|
+
} else if (r.ownerSymIdx !== -1) {
|
|
5588
|
+
if (dLive.has(r.ownerSymIdx)) {
|
|
5589
|
+
keptDataRelocBytes.push(r.rawBytes);
|
|
5590
|
+
usedSyms.add(r.rs);
|
|
5591
|
+
}
|
|
5592
|
+
} else if (sLive[r.segIdx] === 1) {
|
|
5593
|
+
keptDataRelocBytes.push(r.rawBytes);
|
|
5594
|
+
usedSyms.add(r.rs);
|
|
5595
|
+
}
|
|
5596
|
+
}
|
|
5597
|
+
const keptInitSyms = obj.initFuncSyms.filter((symIdx) => {
|
|
5598
|
+
if (obj.symKind[symIdx] === 0 && obj.symElemIdx[symIdx] >= obj.numImportFuncs) {
|
|
5599
|
+
return fLive[obj.symElemIdx[symIdx] - obj.numImportFuncs] === 1;
|
|
5600
|
+
}
|
|
5601
|
+
return true;
|
|
5602
|
+
});
|
|
5603
|
+
for (const symIdx of keptInitSyms) usedSyms.add(symIdx);
|
|
5604
|
+
const outChunks = [buf.subarray(0, 8)];
|
|
5605
|
+
let pos = 8;
|
|
5606
|
+
while (pos < buf.length) {
|
|
5607
|
+
const secStart = pos;
|
|
5608
|
+
const id = buf[pos++];
|
|
5609
|
+
const [sz, p] = readULEB(buf, pos);
|
|
5610
|
+
const end = p + sz;
|
|
5611
|
+
if (id === 0) {
|
|
5612
|
+
const [nLen, np] = readULEB(buf, p);
|
|
5613
|
+
const name2 = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
|
|
5614
|
+
const cp = np + nLen;
|
|
5615
|
+
if (name2 === "linking") {
|
|
5616
|
+
const [, lpStart] = readULEB(buf, cp);
|
|
5617
|
+
const subChunks = [buf.subarray(p, lpStart)];
|
|
5618
|
+
let lp = lpStart;
|
|
5619
|
+
while (lp < end) {
|
|
5620
|
+
const subStart = lp;
|
|
5621
|
+
const subId = buf[lp++];
|
|
5622
|
+
const [subLen, sp] = readULEB(buf, lp);
|
|
5623
|
+
const subEnd = sp + subLen;
|
|
5624
|
+
if (subId === 5) {
|
|
5625
|
+
const subCopy = new Uint8Array(buf.subarray(subStart, subEnd));
|
|
5626
|
+
let [cnt, cur] = readULEB(buf, sp);
|
|
5627
|
+
for (let i = 0; i < cnt; i++) {
|
|
5628
|
+
const [sLen, s2] = readULEB(buf, cur);
|
|
5629
|
+
const segName = obj.segNames[i];
|
|
5630
|
+
const isSpecial = segName === "swift5_type_metadata" || segName === "swift5_protocol_conformances" || segName === "__objc_classes";
|
|
5631
|
+
if (deadSpecialSegs.has(i)) {
|
|
5632
|
+
let repl = "";
|
|
5633
|
+
if (segName === "swift5_type_metadata") repl = ".dead_swift5_type_md";
|
|
5634
|
+
else if (segName === "swift5_protocol_conformances")
|
|
5635
|
+
repl = ".dead_swift5_protocol_confor";
|
|
5636
|
+
else if (segName === "__objc_classes") repl = ".dead_objc_cls";
|
|
5637
|
+
if (repl.length === sLen) {
|
|
5638
|
+
subCopy.set(Buffer.from(repl, "utf8"), s2 - subStart);
|
|
5639
|
+
}
|
|
5640
|
+
}
|
|
5641
|
+
cur = s2 + sLen;
|
|
5642
|
+
const [, s3] = readULEB(buf, cur);
|
|
5643
|
+
const [segFl, s4] = readULEB(buf, s3);
|
|
5644
|
+
const sFlLen = s4 - s3;
|
|
5645
|
+
const keepRetain = isSpecial ? !deadSpecialSegs.has(i) : isRootSegName(segName) && !segName.startsWith(".init_array") && sLive[i] === 1;
|
|
5646
|
+
const newSegFl = keepRetain ? segFl | 4 : segFl & ~4;
|
|
5647
|
+
if (sFlLen === 1) {
|
|
5648
|
+
subCopy[s3 - subStart] = newSegFl;
|
|
5649
|
+
} else if (sFlLen === 2) {
|
|
5650
|
+
subCopy[s3 - subStart] = newSegFl & 127 | 128;
|
|
5651
|
+
subCopy[s3 - subStart + 1] = newSegFl >> 7;
|
|
5652
|
+
}
|
|
5653
|
+
cur = s4;
|
|
5654
|
+
}
|
|
5655
|
+
subChunks.push(subCopy);
|
|
5656
|
+
} else if (subId === 6) {
|
|
5657
|
+
let [cnt, cur] = readULEB(buf, sp);
|
|
5658
|
+
const entrySlices = [];
|
|
5659
|
+
for (let i = 0; i < cnt; i++) {
|
|
5660
|
+
const eStart = cur;
|
|
5661
|
+
const [, s2] = readULEB(buf, cur);
|
|
5662
|
+
const [symIdx, s3] = readULEB(buf, s2);
|
|
5663
|
+
cur = s3;
|
|
5664
|
+
if (obj.symKind[symIdx] === 0 && obj.symElemIdx[symIdx] >= obj.numImportFuncs) {
|
|
5665
|
+
if (fLive[obj.symElemIdx[symIdx] - obj.numImportFuncs] === 1) {
|
|
5666
|
+
entrySlices.push(buf.subarray(eStart, cur));
|
|
5667
|
+
}
|
|
5668
|
+
} else {
|
|
5669
|
+
entrySlices.push(buf.subarray(eStart, cur));
|
|
5670
|
+
}
|
|
5671
|
+
}
|
|
5672
|
+
if (entrySlices.length > 0) {
|
|
5673
|
+
const cntBytes = Uint8Array.from(encodeULEB(entrySlices.length));
|
|
5674
|
+
const bodyLen = cntBytes.length + entrySlices.reduce((a, b) => a + b.length, 0);
|
|
5675
|
+
const lenBytes = Uint8Array.from(encodeULEB(bodyLen));
|
|
5676
|
+
subChunks.push(Uint8Array.of(6), lenBytes, cntBytes, ...entrySlices);
|
|
5677
|
+
}
|
|
5678
|
+
} else if (subId === 8) {
|
|
5679
|
+
const subCopy = new Uint8Array(buf.subarray(subStart, subEnd));
|
|
5680
|
+
let [cnt, cur] = readULEB(buf, sp);
|
|
5681
|
+
for (let i = 0; i < cnt; i++) {
|
|
5682
|
+
const kind = buf[cur++];
|
|
5683
|
+
const flOffset = cur - subStart;
|
|
5684
|
+
const [fl, c2] = readULEB(buf, cur);
|
|
5685
|
+
cur = c2;
|
|
5686
|
+
const isUndef = (fl & 16) !== 0;
|
|
5687
|
+
const isExplicitName = (fl & 64) !== 0;
|
|
5688
|
+
const flLen = c2 - (flOffset + subStart);
|
|
5689
|
+
let newFl = fl & 127;
|
|
5690
|
+
if (isUndef && (kind === 0 || kind === 1) && !usedSyms.has(i)) {
|
|
5691
|
+
newFl = (fl & ~3 | 1) & 127;
|
|
5692
|
+
} else if (!isUndef && kind === 0 && obj.symElemIdx[i] >= obj.numImportFuncs && fLive[obj.symElemIdx[i] - obj.numImportFuncs] === 0) {
|
|
5693
|
+
newFl = fl & 64 | 2;
|
|
5694
|
+
}
|
|
5695
|
+
if (flLen === 1) {
|
|
5696
|
+
subCopy[flOffset] = newFl;
|
|
5697
|
+
} else if (flLen === 2) {
|
|
5698
|
+
subCopy[flOffset] = newFl | 128;
|
|
5699
|
+
subCopy[flOffset + 1] = 0;
|
|
5700
|
+
}
|
|
5701
|
+
if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
|
|
5702
|
+
const [, c3] = readULEB(buf, cur);
|
|
5703
|
+
cur = c3;
|
|
5704
|
+
if (!isUndef || isExplicitName) {
|
|
5705
|
+
const [sLen, c4] = readULEB(buf, cur);
|
|
5706
|
+
cur = c4 + sLen;
|
|
5707
|
+
}
|
|
5708
|
+
} else if (kind === 1) {
|
|
5709
|
+
const [sLen, c3] = readULEB(buf, cur);
|
|
5710
|
+
cur = c3 + sLen;
|
|
5711
|
+
if (!isUndef) {
|
|
5712
|
+
const [, c4] = readULEB(buf, cur);
|
|
5713
|
+
const [, c5] = readULEB(buf, c4);
|
|
5714
|
+
const [, c6] = readULEB(buf, c5);
|
|
5715
|
+
cur = c6;
|
|
5716
|
+
}
|
|
5717
|
+
} else if (kind === 3) {
|
|
5718
|
+
const [, c3] = readULEB(buf, cur);
|
|
5719
|
+
cur = c3;
|
|
5720
|
+
}
|
|
5721
|
+
}
|
|
5722
|
+
subChunks.push(subCopy);
|
|
5723
|
+
} else {
|
|
5724
|
+
subChunks.push(buf.subarray(subStart, subEnd));
|
|
5725
|
+
}
|
|
5726
|
+
lp = subEnd;
|
|
5727
|
+
}
|
|
5728
|
+
const totalSubLen = subChunks.reduce((a, b) => a + b.length, 0);
|
|
5729
|
+
outChunks.push(
|
|
5730
|
+
Uint8Array.of(0),
|
|
5731
|
+
Uint8Array.from(encodeULEB(totalSubLen)),
|
|
5732
|
+
...subChunks
|
|
5733
|
+
);
|
|
5734
|
+
} else if (name2 === "reloc.CODE") {
|
|
5735
|
+
const [, r1] = readULEB(buf, cp);
|
|
5736
|
+
const headerSlice = buf.subarray(p, r1);
|
|
5737
|
+
const cntBytes = Uint8Array.from(encodeULEB(keptCodeRelocs.length));
|
|
5738
|
+
const relSlices = keptCodeRelocs.map((r) => r.rawBytes);
|
|
5739
|
+
const totalLen = headerSlice.length + cntBytes.length + relSlices.reduce((a, b) => a + b.length, 0);
|
|
5740
|
+
outChunks.push(
|
|
5741
|
+
Uint8Array.of(0),
|
|
5742
|
+
Uint8Array.from(encodeULEB(totalLen)),
|
|
5743
|
+
headerSlice,
|
|
5744
|
+
cntBytes,
|
|
5745
|
+
...relSlices
|
|
5746
|
+
);
|
|
5747
|
+
} else if (name2 === "reloc.DATA") {
|
|
5748
|
+
const [, r1] = readULEB(buf, cp);
|
|
5749
|
+
const headerSlice = buf.subarray(p, r1);
|
|
5750
|
+
const cntBytes = Uint8Array.from(encodeULEB(keptDataRelocBytes.length));
|
|
5751
|
+
const totalLen = headerSlice.length + cntBytes.length + keptDataRelocBytes.reduce((a, b) => a + b.length, 0);
|
|
5752
|
+
outChunks.push(
|
|
5753
|
+
Uint8Array.of(0),
|
|
5754
|
+
Uint8Array.from(encodeULEB(totalLen)),
|
|
5755
|
+
headerSlice,
|
|
5756
|
+
cntBytes,
|
|
5757
|
+
...keptDataRelocBytes
|
|
5758
|
+
);
|
|
5759
|
+
} else if (name2 === ".swift1_autolink_entries") {
|
|
5760
|
+
} else {
|
|
5761
|
+
outChunks.push(buf.subarray(secStart, end));
|
|
5762
|
+
}
|
|
5763
|
+
} else {
|
|
5764
|
+
if (id === 11 && zeroDataRelocOffsets.length > 0) {
|
|
5765
|
+
for (const ro of zeroDataRelocOffsets) {
|
|
5766
|
+
buf.fill(0, p + ro, p + ro + 4);
|
|
5767
|
+
}
|
|
5768
|
+
}
|
|
5769
|
+
outChunks.push(buf.subarray(secStart, end));
|
|
5770
|
+
}
|
|
5771
|
+
pos = end;
|
|
5772
|
+
}
|
|
5773
|
+
fs6.writeFileSync(outFile, Buffer.concat(outChunks));
|
|
5774
|
+
};
|
|
5775
|
+
const prunableCandidates = [
|
|
5776
|
+
...distFiles,
|
|
5777
|
+
...sdkFiles.filter((f) => isPrunableSdkFile(f))
|
|
5778
|
+
];
|
|
5779
|
+
const reachedPrunableObjs = prunableCandidates.map((f) => distObjs.get(f)).filter((o) => extractedObjs.has(o));
|
|
5780
|
+
const prunedMap = /* @__PURE__ */ new Map();
|
|
5781
|
+
for (const o of reachedPrunableObjs) {
|
|
5782
|
+
const outPath = path12.join(prunedObjsDir, path12.basename(o.file));
|
|
5783
|
+
writePrunedObject(o, outPath);
|
|
5784
|
+
prunedMap.set(o.file, outPath);
|
|
5785
|
+
}
|
|
5786
|
+
const extraCoreConcurrencyObjs = allSdkObjFiles.filter(
|
|
5787
|
+
(f) => f.startsWith("libswiftCore__") && f !== "libswiftCore__Swift.o" || f.startsWith("libswift_Concurrency__") && f !== "libswift_Concurrency___Concurrency.o"
|
|
5788
|
+
).map((f) => path12.join(sdkObjsDir, f));
|
|
5789
|
+
const outTokens = [];
|
|
5790
|
+
const emittedPruned = /* @__PURE__ */ new Set();
|
|
5791
|
+
inStartLib = false;
|
|
5792
|
+
for (const t of tokens) {
|
|
5793
|
+
if (t === "--start-lib") {
|
|
5794
|
+
inStartLib = true;
|
|
5795
|
+
outTokens.push("--start-lib");
|
|
5796
|
+
for (const rf of prunableCandidates) {
|
|
5797
|
+
if (emittedPruned.has(rf)) continue;
|
|
5798
|
+
if (prunedMap.has(rf)) {
|
|
5799
|
+
outTokens.push(prunedMap.get(rf));
|
|
5800
|
+
emittedPruned.add(rf);
|
|
5801
|
+
} else if (rf.startsWith(distDir)) {
|
|
5802
|
+
const m = getModulePrefix(rf);
|
|
5803
|
+
if (m === "PeachICU" || m === "Darwin") {
|
|
5804
|
+
outTokens.push(rf);
|
|
5805
|
+
}
|
|
5806
|
+
}
|
|
5807
|
+
}
|
|
5808
|
+
outTokens.push(...extraCoreConcurrencyObjs);
|
|
5809
|
+
continue;
|
|
5810
|
+
}
|
|
5811
|
+
if (t === "--end-lib") {
|
|
5812
|
+
inStartLib = false;
|
|
5813
|
+
outTokens.push("--end-lib");
|
|
5814
|
+
continue;
|
|
5815
|
+
}
|
|
5816
|
+
if (inStartLib) continue;
|
|
5817
|
+
if (t === swiftrtOrigPath && patchedSwiftrtPath) {
|
|
5818
|
+
outTokens.push(patchedSwiftrtPath);
|
|
5819
|
+
} else if (prunedMap.has(t)) {
|
|
5820
|
+
outTokens.push(prunedMap.get(t));
|
|
5821
|
+
emittedPruned.add(t);
|
|
5822
|
+
} else if (OMIT_SDK_LIB_FLAGS.has(t)) {
|
|
5823
|
+
continue;
|
|
5824
|
+
} else {
|
|
5825
|
+
outTokens.push(t);
|
|
5826
|
+
}
|
|
5827
|
+
}
|
|
5828
|
+
const prunedRspPath = path12.join(directory, ".peach-link.pruned.rsp");
|
|
5829
|
+
fs6.writeFileSync(prunedRspPath, outTokens.map((t) => JSON.stringify(t)).join(" "));
|
|
5830
|
+
execFileSync4(path12.join(toolchainBin, "wasm-ld"), [`@${prunedRspPath}`], {
|
|
5831
|
+
stdio: "pipe"
|
|
5832
|
+
});
|
|
5833
|
+
fs6.rmSync(rspPath, { force: true });
|
|
5834
|
+
}
|
|
5835
|
+
|
|
4328
5836
|
// src/swiftContract.ts
|
|
4329
5837
|
var SWIFT_REMOTE_PACKAGES_DIR = "__packages__";
|
|
4330
5838
|
var SWIFT_LOCAL_PACKAGES_DIR = "__local_packages__";
|
|
@@ -4427,9 +5935,36 @@ function isSwiftResourceBundles(value) {
|
|
|
4427
5935
|
) && new Set(value.map((bundle) => bundle.target)).size === value.length && new Set(value.map((bundle) => bundle.path)).size === value.length;
|
|
4428
5936
|
}
|
|
4429
5937
|
|
|
5938
|
+
// src/wasm-optimize.ts
|
|
5939
|
+
import { BINARYEN_VERSION, wasmOpt } from "wasm-opt";
|
|
5940
|
+
var FEATURES = [
|
|
5941
|
+
"threads",
|
|
5942
|
+
"bulk-memory",
|
|
5943
|
+
"bulk-memory-opt",
|
|
5944
|
+
"call-indirect-overlong",
|
|
5945
|
+
"exception-handling",
|
|
5946
|
+
"multivalue",
|
|
5947
|
+
"mutable-globals",
|
|
5948
|
+
"nontrapping-float-to-int",
|
|
5949
|
+
"reference-types",
|
|
5950
|
+
"sign-ext"
|
|
5951
|
+
];
|
|
5952
|
+
var WASM_OPTIMIZE_IDENTITY = `wasm-opt ${BINARYEN_VERSION} -Oz ${FEATURES.join(",")}`;
|
|
5953
|
+
async function optimizeWasm(file, output) {
|
|
5954
|
+
const result = await wasmOpt([
|
|
5955
|
+
"-Oz",
|
|
5956
|
+
...FEATURES.map((feature) => `--enable-${feature}`),
|
|
5957
|
+
file,
|
|
5958
|
+
"-o",
|
|
5959
|
+
output
|
|
5960
|
+
]);
|
|
5961
|
+
if (result.status !== 0)
|
|
5962
|
+
throw new Error(`wasm-opt exited ${result.status}: ${result.stderr}`);
|
|
5963
|
+
}
|
|
5964
|
+
|
|
4430
5965
|
// src/xcode-header-search.ts
|
|
4431
|
-
import
|
|
4432
|
-
import
|
|
5966
|
+
import fs7 from "node:fs";
|
|
5967
|
+
import path13 from "node:path";
|
|
4433
5968
|
function headerMap(entries) {
|
|
4434
5969
|
const unique = /* @__PURE__ */ new Map();
|
|
4435
5970
|
for (const entry of entries)
|
|
@@ -4472,16 +6007,16 @@ function headerMap(entries) {
|
|
|
4472
6007
|
return Buffer.concat([table, ...strings]);
|
|
4473
6008
|
}
|
|
4474
6009
|
function writeXcodeHeaderSearch(directory, targets) {
|
|
4475
|
-
|
|
6010
|
+
fs7.mkdirSync(directory, { recursive: true });
|
|
4476
6011
|
const productDirectories = /* @__PURE__ */ new Map();
|
|
4477
6012
|
for (const target of targets)
|
|
4478
6013
|
for (const [product, file] of Object.entries(target.productHeaders)) {
|
|
4479
|
-
const listed = productDirectories.get(
|
|
4480
|
-
productDirectories.set(
|
|
4481
|
-
listed.push({ name:
|
|
6014
|
+
const listed = productDirectories.get(path13.dirname(product)) ?? [];
|
|
6015
|
+
productDirectories.set(path13.dirname(product), listed);
|
|
6016
|
+
listed.push({ name: path13.basename(product), file });
|
|
4482
6017
|
}
|
|
4483
|
-
const overlay =
|
|
4484
|
-
|
|
6018
|
+
const overlay = path13.join(directory, "all-product-headers.yaml");
|
|
6019
|
+
fs7.writeFileSync(
|
|
4485
6020
|
overlay,
|
|
4486
6021
|
JSON.stringify({
|
|
4487
6022
|
"case-sensitive": "false",
|
|
@@ -4500,8 +6035,8 @@ function writeXcodeHeaderSearch(directory, targets) {
|
|
|
4500
6035
|
const files = [overlay];
|
|
4501
6036
|
const flags = targets.map((target, index) => {
|
|
4502
6037
|
const maps = target.headerMaps.map((map, order) => {
|
|
4503
|
-
const file =
|
|
4504
|
-
|
|
6038
|
+
const file = path13.join(directory, `${index}-${order}.hmap`);
|
|
6039
|
+
fs7.writeFileSync(file, headerMap(map.entries));
|
|
4505
6040
|
files.push(file);
|
|
4506
6041
|
return { flag: map.flag, file };
|
|
4507
6042
|
});
|
|
@@ -4607,7 +6142,7 @@ var admittedCores = Number(process.env.TM_EXEC_CPU_CORES);
|
|
|
4607
6142
|
var BUILD_JOBS = String(
|
|
4608
6143
|
Math.min(
|
|
4609
6144
|
4,
|
|
4610
|
-
Math.max(1, Math.floor(
|
|
6145
|
+
Math.max(1, Math.floor(os3.availableParallelism() / 2)),
|
|
4611
6146
|
Number.isInteger(admittedCores) && admittedCores > 0 ? admittedCores : 4
|
|
4612
6147
|
)
|
|
4613
6148
|
);
|
|
@@ -4617,10 +6152,39 @@ function swiftBuilderHopTimeoutMs(compileTimeoutMs) {
|
|
|
4617
6152
|
return (compileTimeoutMs ?? SWIFT_BUILDER_DEFAULT_COMPILE_MS) + SWIFT_BUILDER_TRANSPORT_MARGIN_MS;
|
|
4618
6153
|
}
|
|
4619
6154
|
function swiftDistributionAt(root) {
|
|
4620
|
-
const file =
|
|
6155
|
+
const file = path14.join(root, SWIFT_DISTRIBUTION_MANIFEST);
|
|
4621
6156
|
if (!existsSync2(file)) return null;
|
|
4622
6157
|
return parseSwiftDistributionManifest(JSON.parse(readFileSync7(file, "utf8")));
|
|
4623
6158
|
}
|
|
6159
|
+
function swiftModuleInterface(moduleRoot, name2) {
|
|
6160
|
+
if (swiftDistributionAt(moduleRoot)) {
|
|
6161
|
+
const file = path14.join(moduleRoot, "modules", `${name2}-Swift.h`);
|
|
6162
|
+
if (!existsSync2(file)) return null;
|
|
6163
|
+
const header = clangInterfaceHeader(readFileSync7(file, "utf8"));
|
|
6164
|
+
return { declared: swiftInterfaceDeclarations(header), header };
|
|
6165
|
+
}
|
|
6166
|
+
const sources = path14.join(moduleRoot, "Sources", name2);
|
|
6167
|
+
if (!existsSync2(sources)) return null;
|
|
6168
|
+
const declared = /* @__PURE__ */ new Set();
|
|
6169
|
+
for (const file of readdirSync5(sources, { recursive: true, encoding: "utf8" }))
|
|
6170
|
+
if (file.endsWith(".swift"))
|
|
6171
|
+
for (const [, objc] of readFileSync7(path14.join(sources, file), "utf8").matchAll(
|
|
6172
|
+
/@objc\((\w+)\)\s+(?:\w+\s+)*?(?:protocol|class)\s/g
|
|
6173
|
+
))
|
|
6174
|
+
declared.add(objc);
|
|
6175
|
+
if (declared.size === 0) return null;
|
|
6176
|
+
const built = path14.join(moduleRoot, ".build/host", `${name2}-Swift.h`);
|
|
6177
|
+
return {
|
|
6178
|
+
declared,
|
|
6179
|
+
header: existsSync2(built) ? clangInterfaceHeader(readFileSync7(built, "utf8")) : `// ${name2}-Swift.h is generated when ${name2} builds
|
|
6180
|
+
`
|
|
6181
|
+
};
|
|
6182
|
+
}
|
|
6183
|
+
var clangInterfaceHeader = (header) => header.replace(/^@import UIKitCore;$/m, "@import UIKit;");
|
|
6184
|
+
var swiftInterfaceDeclarations = (header) => /* @__PURE__ */ new Set([
|
|
6185
|
+
...[...header.matchAll(/^@protocol\s+(\w+)\b(?![^\n]*;\s*$)/gm)].map((m) => m[1]),
|
|
6186
|
+
...[...header.matchAll(/^@interface\s+(\w+)\s*(?=[:<{]|$)/gm)].map((m) => m[1])
|
|
6187
|
+
]);
|
|
4624
6188
|
function swiftModuleSdk(root) {
|
|
4625
6189
|
const pin = swiftDistributionAt(root) ?? swiftSourceSdk(root);
|
|
4626
6190
|
return {
|
|
@@ -4629,12 +6193,21 @@ function swiftModuleSdk(root) {
|
|
|
4629
6193
|
wasmSdkChecksum: pin.wasmSdkChecksum
|
|
4630
6194
|
};
|
|
4631
6195
|
}
|
|
6196
|
+
function swiftCompileSdkOptions(moduleRoot, toolchainBin) {
|
|
6197
|
+
return swiftSharedSdkViewOptions(
|
|
6198
|
+
moduleRoot,
|
|
6199
|
+
swiftDistributionAt(moduleRoot) !== null,
|
|
6200
|
+
toolchainBin,
|
|
6201
|
+
swiftModuleSdk(moduleRoot).wasmSdkId
|
|
6202
|
+
);
|
|
6203
|
+
}
|
|
4632
6204
|
function swiftModuleInputFiles(root) {
|
|
4633
6205
|
if (swiftDistributionAt(root)) return [SWIFT_DISTRIBUTION_MANIFEST];
|
|
4634
6206
|
const files = [
|
|
4635
6207
|
...swiftSharedSdkInputFiles(root),
|
|
4636
6208
|
"../peachsim/src/swift-shared-sdk.ts",
|
|
4637
6209
|
"../../scripts/generate/swift-sdk-module/darwin-mach.json",
|
|
6210
|
+
"../../scripts/generate/swift-sdk-module/darwin-socketvar.json",
|
|
4638
6211
|
"../../scripts/ops/swift-distribution-publish.ts",
|
|
4639
6212
|
"Package.swift",
|
|
4640
6213
|
"scripts/contrast-app-Package.swift",
|
|
@@ -4650,7 +6223,7 @@ function swiftModuleInputFiles(root) {
|
|
|
4650
6223
|
"toolchain.json"
|
|
4651
6224
|
];
|
|
4652
6225
|
const walk = (dir) => {
|
|
4653
|
-
for (const entry of readdirSync5(
|
|
6226
|
+
for (const entry of readdirSync5(path14.join(root, dir), {
|
|
4654
6227
|
withFileTypes: true
|
|
4655
6228
|
})) {
|
|
4656
6229
|
const relative = `${dir}/${entry.name}`;
|
|
@@ -4668,35 +6241,35 @@ function swiftMacroPlugins(moduleRoot) {
|
|
|
4668
6241
|
const distribution = swiftDistributionAt(moduleRoot);
|
|
4669
6242
|
if (distribution)
|
|
4670
6243
|
return {
|
|
4671
|
-
libraries: distribution.plugins.filter((plugin) =>
|
|
4672
|
-
executables: distribution.plugins.filter((plugin) =>
|
|
6244
|
+
libraries: distribution.plugins.filter((plugin) => path14.basename(plugin) !== "ExpoModulesMacros").map((plugin) => path14.join(moduleRoot, plugin)),
|
|
6245
|
+
executables: distribution.plugins.filter((plugin) => path14.basename(plugin) === "ExpoModulesMacros").map((plugin) => path14.join(moduleRoot, plugin)),
|
|
4673
6246
|
stale: false
|
|
4674
6247
|
};
|
|
4675
|
-
const dir =
|
|
6248
|
+
const dir = path14.join(moduleRoot, ".build/host/RnxPreviewMacros");
|
|
4676
6249
|
const release = JSON.parse(
|
|
4677
|
-
readFileSync7(
|
|
6250
|
+
readFileSync7(path14.join(moduleRoot, "toolchain.json"), "utf8")
|
|
4678
6251
|
).release;
|
|
4679
|
-
const compilerStamp =
|
|
4680
|
-
const pluginScript =
|
|
4681
|
-
const expoPlugin =
|
|
6252
|
+
const compilerStamp = path14.join(dir, "compiler-release");
|
|
6253
|
+
const pluginScript = path14.join(moduleRoot, "scripts/build-preview-plugin.sh");
|
|
6254
|
+
const expoPlugin = path14.join(dir, "ExpoModulesMacros");
|
|
4682
6255
|
const ext = process.platform === "darwin" ? "dylib" : "so";
|
|
4683
6256
|
const plugins = [
|
|
4684
6257
|
{
|
|
4685
|
-
library:
|
|
4686
|
-
sources: [
|
|
6258
|
+
library: path14.join(dir, `libRnxPreviewMacros.${ext}`),
|
|
6259
|
+
sources: [path14.join(moduleRoot, "Sources/RnxPreviewMacros/PreviewMacro.swift")]
|
|
4687
6260
|
},
|
|
4688
6261
|
{
|
|
4689
|
-
library:
|
|
6262
|
+
library: path14.join(dir, `libFoundationMacros.${ext}`),
|
|
4690
6263
|
sources: [
|
|
4691
|
-
|
|
4692
|
-
|
|
6264
|
+
path14.join(moduleRoot, "Sources/FoundationMacros/PredicateMacro.swift"),
|
|
6265
|
+
path14.join(moduleRoot, "Sources/SwiftMacroSupport/PredicateExpression.swift")
|
|
4693
6266
|
]
|
|
4694
6267
|
},
|
|
4695
6268
|
{
|
|
4696
|
-
library:
|
|
6269
|
+
library: path14.join(dir, `libTipKitMacros.${ext}`),
|
|
4697
6270
|
sources: [
|
|
4698
|
-
|
|
4699
|
-
|
|
6271
|
+
path14.join(moduleRoot, "Sources/TipKitMacros/TipKitMacros.swift"),
|
|
6272
|
+
path14.join(moduleRoot, "Sources/SwiftMacroSupport/PredicateExpression.swift")
|
|
4700
6273
|
]
|
|
4701
6274
|
}
|
|
4702
6275
|
];
|
|
@@ -4714,14 +6287,14 @@ async function ensureMacroPlugins(moduleRoot, toolchainBin, release, signal) {
|
|
|
4714
6287
|
await runCompiler(
|
|
4715
6288
|
"sh",
|
|
4716
6289
|
[
|
|
4717
|
-
|
|
6290
|
+
path14.join(moduleRoot, "scripts/build-preview-plugin.sh"),
|
|
4718
6291
|
toolchainBin,
|
|
4719
6292
|
libraries[0]
|
|
4720
6293
|
],
|
|
4721
6294
|
{ signal }
|
|
4722
6295
|
);
|
|
4723
6296
|
writeFileSync3(
|
|
4724
|
-
|
|
6297
|
+
path14.join(path14.dirname(libraries[0]), "compiler-release"),
|
|
4725
6298
|
`${release}
|
|
4726
6299
|
`
|
|
4727
6300
|
);
|
|
@@ -4735,9 +6308,9 @@ function clearLinkedModuleDigests(root) {
|
|
|
4735
6308
|
}
|
|
4736
6309
|
function swiftModuleDigest(root) {
|
|
4737
6310
|
const files = swiftModuleInputFiles(root);
|
|
4738
|
-
const stampHash =
|
|
6311
|
+
const stampHash = createHash8("sha256");
|
|
4739
6312
|
for (const file of files) {
|
|
4740
|
-
const stat = statSync(
|
|
6313
|
+
const stat = statSync(path14.join(root, file), { bigint: true });
|
|
4741
6314
|
stampHash.update(file);
|
|
4742
6315
|
stampHash.update(
|
|
4743
6316
|
`${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}
|
|
@@ -4747,11 +6320,11 @@ function swiftModuleDigest(root) {
|
|
|
4747
6320
|
const stamp = stampHash.digest("hex");
|
|
4748
6321
|
const cached = linkedModuleDigests.get(root);
|
|
4749
6322
|
if (cached?.stamp === stamp) return cached.digest;
|
|
4750
|
-
const hash =
|
|
6323
|
+
const hash = createHash8("sha256");
|
|
4751
6324
|
for (const file of files) {
|
|
4752
|
-
hash.update(
|
|
6325
|
+
hash.update(createHash8("sha256").update(file).digest());
|
|
4753
6326
|
hash.update(
|
|
4754
|
-
|
|
6327
|
+
createHash8("sha256").update(readFileSync7(path14.join(root, file))).digest()
|
|
4755
6328
|
);
|
|
4756
6329
|
}
|
|
4757
6330
|
const digest = hash.digest();
|
|
@@ -4759,7 +6332,7 @@ function swiftModuleDigest(root) {
|
|
|
4759
6332
|
return digest;
|
|
4760
6333
|
}
|
|
4761
6334
|
function swiftProjectBuildKey(moduleRoot, release) {
|
|
4762
|
-
return
|
|
6335
|
+
return createHash8("sha256").update(`${release}\0${swiftModuleSdk(moduleRoot).wasmSdkId}`).update(swiftModuleDigest(moduleRoot)).digest("hex").slice(0, 32);
|
|
4763
6336
|
}
|
|
4764
6337
|
function compileTargets(input) {
|
|
4765
6338
|
const manifest = input.files["Package.swift"];
|
|
@@ -4775,7 +6348,7 @@ function withNativeSourceGlue(input, glue) {
|
|
|
4775
6348
|
...input,
|
|
4776
6349
|
files: {
|
|
4777
6350
|
...input.files,
|
|
4778
|
-
[
|
|
6351
|
+
[path14.posix.join(targetPath, "OneNativeSource.generated.swift")]: glue
|
|
4779
6352
|
},
|
|
4780
6353
|
oneModule: true
|
|
4781
6354
|
};
|
|
@@ -4915,21 +6488,22 @@ function swiftImportNames(contents, available) {
|
|
|
4915
6488
|
function swiftPeachModules(moduleRoot) {
|
|
4916
6489
|
const distribution = swiftDistributionAt(moduleRoot);
|
|
4917
6490
|
return distribution ? distribution.modules : swiftManifestDeclarations(
|
|
4918
|
-
readFileSync7(
|
|
6491
|
+
readFileSync7(path14.join(moduleRoot, "Package.swift"), "utf8")
|
|
4919
6492
|
).filter((target) => !target.executable && !target.path.startsWith("fixtures/")).map((target) => target.name);
|
|
4920
6493
|
}
|
|
4921
6494
|
var sdkPaths = /* @__PURE__ */ new Map();
|
|
4922
6495
|
function swiftSdkPaths(moduleRoot, toolchainBin) {
|
|
4923
6496
|
const sdk = swiftModuleSdk(moduleRoot).wasmSdkId;
|
|
4924
|
-
const
|
|
6497
|
+
const options = swiftCompileSdkOptions(moduleRoot, toolchainBin);
|
|
6498
|
+
const key = JSON.stringify([toolchainBin, sdk, options]);
|
|
4925
6499
|
const cached = sdkPaths.get(key);
|
|
4926
6500
|
if (cached) return cached;
|
|
4927
|
-
const configuration =
|
|
4928
|
-
|
|
6501
|
+
const configuration = execFileSync5(
|
|
6502
|
+
path14.join(toolchainBin, "swift"),
|
|
4929
6503
|
[
|
|
4930
6504
|
"sdk",
|
|
4931
6505
|
"configure",
|
|
4932
|
-
...
|
|
6506
|
+
...options,
|
|
4933
6507
|
"--show-configuration",
|
|
4934
6508
|
sdk,
|
|
4935
6509
|
"wasm32-unknown-wasip1"
|
|
@@ -4955,25 +6529,25 @@ function swiftSdkPaths(moduleRoot, toolchainBin) {
|
|
|
4955
6529
|
const compiler = config.swiftCompiler;
|
|
4956
6530
|
if (!compiler || typeof compiler !== "object" || !("extraCLIOptions" in compiler))
|
|
4957
6531
|
continue;
|
|
4958
|
-
const
|
|
4959
|
-
if (!Array.isArray(
|
|
6532
|
+
const options2 = compiler.extraCLIOptions;
|
|
6533
|
+
if (!Array.isArray(options2) || !options2.every((value) => typeof value === "string"))
|
|
4960
6534
|
throw new Error(
|
|
4961
6535
|
`swift sdk ${sdk} has invalid swift compiler options in ${toolset}`
|
|
4962
6536
|
);
|
|
4963
|
-
for (let index = 0; index <
|
|
4964
|
-
if (
|
|
4965
|
-
const flag =
|
|
6537
|
+
for (let index = 0; index < options2.length; index++) {
|
|
6538
|
+
if (options2[index] === "-Xcc" && typeof options2[index + 1] === "string") {
|
|
6539
|
+
const flag = options2[index + 1];
|
|
4966
6540
|
if (flag !== "-fwasm-exceptions") cFlags.push(flag);
|
|
4967
|
-
if (flag === "-iframeworkwithsysroot" &&
|
|
4968
|
-
cFlags.push(
|
|
4969
|
-
frameworks.push(
|
|
6541
|
+
if (flag === "-iframeworkwithsysroot" && options2[index + 2] === "-Xcc" && typeof options2[index + 3] === "string") {
|
|
6542
|
+
cFlags.push(options2[index + 3]);
|
|
6543
|
+
frameworks.push(path14.join(sysroot, options2[index + 3]));
|
|
4970
6544
|
index += 3;
|
|
4971
6545
|
continue;
|
|
4972
6546
|
}
|
|
4973
6547
|
index += 1;
|
|
4974
6548
|
continue;
|
|
4975
6549
|
}
|
|
4976
|
-
const option =
|
|
6550
|
+
const option = options2[index];
|
|
4977
6551
|
if (option.startsWith("-iframework") || option.startsWith("-F"))
|
|
4978
6552
|
throw new Error(
|
|
4979
6553
|
`swift sdk ${sdk} has an unsupported framework search option ${option}`
|
|
@@ -4983,7 +6557,7 @@ function swiftSdkPaths(moduleRoot, toolchainBin) {
|
|
|
4983
6557
|
}
|
|
4984
6558
|
const paths = {
|
|
4985
6559
|
sysroot,
|
|
4986
|
-
darwin:
|
|
6560
|
+
darwin: path14.join(sysroot, "darwin"),
|
|
4987
6561
|
resources: field("swiftResourcesPath"),
|
|
4988
6562
|
frameworks,
|
|
4989
6563
|
cFlags
|
|
@@ -4999,19 +6573,19 @@ function swiftAvailableModules(moduleRoot, toolchainBin) {
|
|
|
4999
6573
|
if (cached) return cached;
|
|
5000
6574
|
const modules = new Set(swiftPeachModules(moduleRoot));
|
|
5001
6575
|
const { resources, frameworks } = swiftSdkPaths(moduleRoot, toolchainBin);
|
|
5002
|
-
for (const entry of readdirSync5(
|
|
6576
|
+
for (const entry of readdirSync5(path14.join(resources, "wasi"))) {
|
|
5003
6577
|
if (entry.endsWith(".swiftmodule"))
|
|
5004
6578
|
modules.add(entry.slice(0, -".swiftmodule".length));
|
|
5005
6579
|
}
|
|
5006
6580
|
for (const entry of readdirSync5(resources)) {
|
|
5007
|
-
const map =
|
|
6581
|
+
const map = path14.join(resources, entry, "module.modulemap");
|
|
5008
6582
|
if (!existsSync2(map)) continue;
|
|
5009
6583
|
for (const match of readFileSync7(map, "utf8").matchAll(/^module\s+([A-Za-z_]\w*)/gm))
|
|
5010
6584
|
modules.add(match[1]);
|
|
5011
6585
|
}
|
|
5012
6586
|
for (const directory of frameworks) {
|
|
5013
6587
|
for (const entry of readdirSync5(directory)) {
|
|
5014
|
-
const map =
|
|
6588
|
+
const map = path14.join(directory, entry, "Modules/module.modulemap");
|
|
5015
6589
|
if (!existsSync2(map)) continue;
|
|
5016
6590
|
for (const match of readFileSync7(map, "utf8").matchAll(
|
|
5017
6591
|
/^framework\s+module\s+([A-Za-z_]\w*)/gm
|
|
@@ -5064,18 +6638,18 @@ function swiftSystemLibraryExclusions(files, targets, distributionModules) {
|
|
|
5064
6638
|
);
|
|
5065
6639
|
}
|
|
5066
6640
|
function distributionModulesPath(root, moduleRoot, excluded) {
|
|
5067
|
-
const modules =
|
|
6641
|
+
const modules = path14.join(moduleRoot, "modules");
|
|
5068
6642
|
if (!excluded || excluded.size === 0) return modules;
|
|
5069
|
-
const key =
|
|
5070
|
-
const directory =
|
|
5071
|
-
const complete =
|
|
6643
|
+
const key = createHash8("sha256").update([...excluded].sort().join("\0")).digest("hex").slice(0, 16);
|
|
6644
|
+
const directory = path14.join(root, `.peach-modules-${key}`);
|
|
6645
|
+
const complete = path14.join(directory, ".complete");
|
|
5072
6646
|
if (!existsSync2(complete)) {
|
|
5073
6647
|
mkdirSync2(directory, { recursive: true });
|
|
5074
6648
|
for (const entry of readdirSync5(directory))
|
|
5075
|
-
rmSync3(
|
|
6649
|
+
rmSync3(path14.join(directory, entry), { recursive: true, force: true });
|
|
5076
6650
|
for (const entry of readdirSync5(modules)) {
|
|
5077
6651
|
if (excluded.has(entry.replace(/\.swiftmodule$/, ""))) continue;
|
|
5078
|
-
symlinkSync(
|
|
6652
|
+
symlinkSync(path14.join(modules, entry), path14.join(directory, entry));
|
|
5079
6653
|
}
|
|
5080
6654
|
writeFileSync3(complete, "");
|
|
5081
6655
|
}
|
|
@@ -5122,7 +6696,7 @@ var FOUNDATION_IMPLICIT_FLAGS = FOUNDATION_IMPLICIT_MODULES.map(
|
|
|
5122
6696
|
).join("");
|
|
5123
6697
|
var ONE_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "One"';
|
|
5124
6698
|
var executableLinkFlags = (root) => ` "-Xclang-linker", "-O0",
|
|
5125
|
-
"-Xclang-linker", ${JSON.stringify(`-fuse-ld=${
|
|
6699
|
+
"-Xclang-linker", ${JSON.stringify(`-fuse-ld=${path14.join(root, SWIFT_AUTOLINK_LINKER)}`)},
|
|
5126
6700
|
"-Xlinker", "-z", "-Xlinker", "stack-size=8372224",
|
|
5127
6701
|
"-Xlinker", "--stack-first",
|
|
5128
6702
|
"-Xlinker", "--global-base=8372224",
|
|
@@ -5131,44 +6705,47 @@ var executableLinkFlags = (root) => ` "-Xclang-linker", "-O0",
|
|
|
5131
6705
|
"-Xlinker", "--growable-table",
|
|
5132
6706
|
`;
|
|
5133
6707
|
var REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
|
|
5134
|
-
var MULTI_MANIFEST_VERSION =
|
|
5135
|
-
var compilerSourceDigest = true ? "
|
|
6708
|
+
var MULTI_MANIFEST_VERSION = 51;
|
|
6709
|
+
var compilerSourceDigest = true ? "b895d808e6b9911d7c80744af3eb884b635b96b82b69c6903f1e66ebd7485d6c" : swiftCompilerSourceDigest(import.meta.dirname);
|
|
5136
6710
|
function swiftArtifactHash(input, release, moduleRoot) {
|
|
5137
|
-
const hash =
|
|
6711
|
+
const hash = createHash8("sha256");
|
|
5138
6712
|
hash.update(`swift-compile
|
|
5139
6713
|
${release}
|
|
5140
6714
|
`);
|
|
5141
6715
|
hash.update(compilerSourceDigest);
|
|
5142
6716
|
if (input.oneModule) hash.update("one-module\n");
|
|
5143
6717
|
hash.update(swiftModuleDigest(moduleRoot));
|
|
5144
|
-
if (input.lazyDistribution)
|
|
6718
|
+
if (input.lazyDistribution)
|
|
6719
|
+
hash.update(`lazy-distribution
|
|
6720
|
+
${WASM_OPTIMIZE_IDENTITY}
|
|
6721
|
+
`);
|
|
5145
6722
|
for (const file of Object.keys(input.files).sort()) {
|
|
5146
|
-
hash.update(
|
|
5147
|
-
hash.update(
|
|
6723
|
+
hash.update(createHash8("sha256").update(file).digest());
|
|
6724
|
+
hash.update(createHash8("sha256").update(input.files[file]).digest());
|
|
5148
6725
|
}
|
|
5149
6726
|
for (const file of Object.keys(input.metalSources ?? {}).sort()) {
|
|
5150
6727
|
hash.update("metal-source\n");
|
|
5151
|
-
hash.update(
|
|
6728
|
+
hash.update(createHash8("sha256").update(file).digest());
|
|
5152
6729
|
hash.update(
|
|
5153
|
-
|
|
6730
|
+
createHash8("sha256").update(input.metalSources?.[file] ?? "").digest()
|
|
5154
6731
|
);
|
|
5155
6732
|
}
|
|
5156
6733
|
for (const base of Object.keys(input.resources ?? {}).sort()) {
|
|
5157
|
-
hash.update(
|
|
6734
|
+
hash.update(createHash8("sha256").update(base).digest());
|
|
5158
6735
|
hash.update(
|
|
5159
|
-
|
|
6736
|
+
createHash8("sha256").update(input.resources?.[base] ?? "").digest()
|
|
5160
6737
|
);
|
|
5161
6738
|
}
|
|
5162
6739
|
for (const name2 of Object.keys(input.images ?? {}).sort()) {
|
|
5163
6740
|
const image = input.images?.[name2];
|
|
5164
6741
|
if (!image) continue;
|
|
5165
|
-
hash.update(
|
|
5166
|
-
hash.update(
|
|
5167
|
-
hash.update(
|
|
6742
|
+
hash.update(createHash8("sha256").update(name2).digest());
|
|
6743
|
+
hash.update(createHash8("sha256").update(image.file).digest());
|
|
6744
|
+
hash.update(createHash8("sha256").update(image.data).digest());
|
|
5168
6745
|
}
|
|
5169
6746
|
for (const file of [...new Set(input.resourcePaths ?? [])].sort()) {
|
|
5170
6747
|
hash.update("resource-path\n");
|
|
5171
|
-
hash.update(
|
|
6748
|
+
hash.update(createHash8("sha256").update(file).digest());
|
|
5172
6749
|
}
|
|
5173
6750
|
hash.update(
|
|
5174
6751
|
JSON.stringify(
|
|
@@ -5183,18 +6760,18 @@ ${input.defaultLocalization}
|
|
|
5183
6760
|
`);
|
|
5184
6761
|
for (const file of Object.keys(input.packageFiles ?? {}).sort()) {
|
|
5185
6762
|
hash.update(`package-file\0${file}\0`);
|
|
5186
|
-
hash.update(
|
|
6763
|
+
hash.update(createHash8("sha256").update(input.packageFiles[file]).digest());
|
|
5187
6764
|
}
|
|
5188
6765
|
for (const file of Object.keys(input.projectFiles ?? {}).sort()) {
|
|
5189
6766
|
hash.update(`project-file\0${file}\0`);
|
|
5190
|
-
hash.update(
|
|
6767
|
+
hash.update(createHash8("sha256").update(input.projectFiles[file]).digest());
|
|
5191
6768
|
}
|
|
5192
6769
|
for (const target of Object.keys(input.libraries ?? {}).sort()) {
|
|
5193
6770
|
hash.update(`library
|
|
5194
6771
|
${target}
|
|
5195
6772
|
`);
|
|
5196
6773
|
hash.update(
|
|
5197
|
-
|
|
6774
|
+
createHash8("sha256").update(input.libraries?.[target] ?? "").digest()
|
|
5198
6775
|
);
|
|
5199
6776
|
}
|
|
5200
6777
|
const targets = compileTargets(input);
|
|
@@ -5213,7 +6790,7 @@ ${target}
|
|
|
5213
6790
|
return hash.digest("hex");
|
|
5214
6791
|
}
|
|
5215
6792
|
function swiftCrossImportFlags(moduleRoot, distribution) {
|
|
5216
|
-
const overlayRoot =
|
|
6793
|
+
const overlayRoot = path14.join(
|
|
5217
6794
|
moduleRoot,
|
|
5218
6795
|
distribution ? "modules" : "cross-import-overlays"
|
|
5219
6796
|
);
|
|
@@ -5221,9 +6798,9 @@ function swiftCrossImportFlags(moduleRoot, distribution) {
|
|
|
5221
6798
|
"-Xfrontend",
|
|
5222
6799
|
"-swift-module-cross-import",
|
|
5223
6800
|
"-Xfrontend",
|
|
5224
|
-
|
|
6801
|
+
path14.basename(path14.dirname(file), ".swiftcrossimport"),
|
|
5225
6802
|
"-Xfrontend",
|
|
5226
|
-
|
|
6803
|
+
path14.join(overlayRoot, file)
|
|
5227
6804
|
]);
|
|
5228
6805
|
}
|
|
5229
6806
|
function withoutWasmOverlayIsystem(flags) {
|
|
@@ -5269,17 +6846,19 @@ function emitSwiftPackageManifest(args) {
|
|
|
5269
6846
|
(name2) => !object.startsWith(`lib/${name2}-`) || reachedFrameworks.has(name2)
|
|
5270
6847
|
)
|
|
5271
6848
|
);
|
|
5272
|
-
const quoted = (object) => `"${
|
|
6849
|
+
const quoted = (object) => `"${path14.join(moduleRoot, object).replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
|
|
5273
6850
|
const roots = args.lazyDistribution ? swiftObjcRootObjects(distribution.id, moduleRoot, distribution.objects) : null;
|
|
5274
6851
|
const list = (roots ? [
|
|
5275
6852
|
...objects.filter((object) => roots.has(object)).map(quoted),
|
|
5276
6853
|
"-Wl,--start-lib",
|
|
5277
|
-
...objects.filter(
|
|
6854
|
+
...objects.filter(
|
|
6855
|
+
(object) => !roots.has(object) && object !== "lib/Foundation-NSStringFormatting.o"
|
|
6856
|
+
).map(quoted),
|
|
5278
6857
|
"-Wl,--end-lib"
|
|
5279
6858
|
] : objects.map(quoted)).join("\n") + "\n";
|
|
5280
6859
|
distributionLinkPath = distributionLink.path.replace(
|
|
5281
6860
|
/\.rsp$/,
|
|
5282
|
-
`-${
|
|
6861
|
+
`-${createHash8("sha256").update(list).digest("hex").slice(0, 12)}.rsp`
|
|
5283
6862
|
);
|
|
5284
6863
|
distributionLink.files.set(distributionLinkPath, list);
|
|
5285
6864
|
}
|
|
@@ -5293,7 +6872,7 @@ function emitSwiftPackageManifest(args) {
|
|
|
5293
6872
|
const stanza = (target) => {
|
|
5294
6873
|
const native = args.native?.get(target.name);
|
|
5295
6874
|
if (target.systemLibrary || native?.clang?.sources.length === 0)
|
|
5296
|
-
return ` .systemLibrary(name: ${JSON.stringify(target.name)}, path: ${JSON.stringify(native?.clang ?
|
|
6875
|
+
return ` .systemLibrary(name: ${JSON.stringify(target.name)}, path: ${JSON.stringify(native?.clang ? path14.posix.dirname(native.clang.modulemap) : target.path)}),`;
|
|
5297
6876
|
const isolation = target.mainActorIsolation ? " .defaultIsolation(MainActor.self)," : "";
|
|
5298
6877
|
const interoperability = target.cxxInterop ? " .interoperabilityMode(.Cxx)," : "";
|
|
5299
6878
|
const defines = (target.defines ?? []).map((name2) => ` .define(${JSON.stringify(name2)}),`).join("");
|
|
@@ -5334,12 +6913,12 @@ function emitSwiftPackageManifest(args) {
|
|
|
5334
6913
|
].map((flag) => `, ${JSON.stringify(flag)}`).join("");
|
|
5335
6914
|
const header = args.headerDirectory && [...args.native?.values() ?? []].some(
|
|
5336
6915
|
(value) => value.late?.producers.includes(target.name)
|
|
5337
|
-
) ? `, "-emit-objc-header-path", ${JSON.stringify(
|
|
6916
|
+
) ? `, "-emit-objc-header-path", ${JSON.stringify(path14.join(args.headerDirectory, `${target.name}-Swift.h`))}` : "";
|
|
5338
6917
|
const swiftSettings = `swiftSettings: [.swiftLanguageMode(.v${target.languageMode}),${isolation}${interoperability}${defines}${features}${upcoming} .unsafeFlags(["-Osize", "-Xfrontend", "-enable-cross-import-overlays"${overlayFlags}${FOUNDATION_IMPLICIT_FLAGS}${oneModule ? ONE_IMPLICIT_FLAGS : ""}${imports}${nativeImports}${nativeImportFlags}${objcFlags}${header}${upstream}])]`;
|
|
5339
6918
|
const deps = [
|
|
5340
6919
|
.../* @__PURE__ */ new Set([
|
|
5341
6920
|
...(target.dependencies ?? []).flatMap(
|
|
5342
|
-
(dependency) => dependency.kind === "product" && !(linkedObjects && dependency.package ===
|
|
6921
|
+
(dependency) => dependency.kind === "product" && !(linkedObjects && dependency.package === path14.basename(moduleRoot).toLowerCase()) ? [
|
|
5343
6922
|
`.product(name: ${JSON.stringify(dependency.name)}, package: ${JSON.stringify(dependency.package)})`
|
|
5344
6923
|
] : []
|
|
5345
6924
|
),
|
|
@@ -5410,8 +6989,8 @@ function emitSwiftPackageManifest(args) {
|
|
|
5410
6989
|
` path: ${JSON.stringify(native?.clang ? "." : target.path)},`,
|
|
5411
6990
|
...exclusions.length ? [` exclude: ${JSON.stringify(exclusions)},`] : [],
|
|
5412
6991
|
...native?.clang ? [
|
|
5413
|
-
` sources: ${JSON.stringify(native.clang.sources.map((source) =>
|
|
5414
|
-
` publicHeadersPath: ${JSON.stringify(
|
|
6992
|
+
` sources: ${JSON.stringify(native.clang.sources.map((source) => path14.posix.join(native.path, source)))},`,
|
|
6993
|
+
` publicHeadersPath: ${JSON.stringify(path14.posix.dirname(native.clang.modulemap))},`
|
|
5415
6994
|
] : native?.flags ? [` sources: ${JSON.stringify(native.sources)},`] : [],
|
|
5416
6995
|
...!native?.clang && target.publicHeadersPath !== void 0 ? [` publicHeadersPath: ${JSON.stringify(target.publicHeadersPath)},`] : [],
|
|
5417
6996
|
// the native backend supplies dependency module maps without their
|
|
@@ -5455,8 +7034,8 @@ function emitSwiftPackageManifest(args) {
|
|
|
5455
7034
|
` .target(name: ${JSON.stringify(group.name)},`,
|
|
5456
7035
|
` dependencies: ${JSON.stringify(native.mixed ? [] : [name2])},`,
|
|
5457
7036
|
` path: ${JSON.stringify(native.clang || native.mixed ? "." : native.path)},`,
|
|
5458
|
-
` sources: ${JSON.stringify(native.clang || native.mixed ? group.sources.map((source) =>
|
|
5459
|
-
` publicHeadersPath: ${JSON.stringify(native.clang ?
|
|
7037
|
+
` sources: ${JSON.stringify(native.clang || native.mixed ? group.sources.map((source) => path14.posix.join(native.path, source)) : group.sources)},`,
|
|
7038
|
+
` publicHeadersPath: ${JSON.stringify(native.clang ? path14.posix.dirname(native.clang.modulemap) : native.implementationHeaders ?? "include")},`,
|
|
5460
7039
|
` cSettings: [${macroSettings(owner?.cDefines)} .unsafeFlags(${JSON.stringify([...nativeFlags, ...group.flags])})],`,
|
|
5461
7040
|
` cxxSettings: [${macroSettings(owner?.cxxDefines)} .unsafeFlags(${JSON.stringify(["-fno-cxx-modules", ...cxxFlagsFor(nativeFlags), "-I", native.includeDirectory, "-I", args.headerDirectory, ...group.cxxFlags])})]),`
|
|
5462
7041
|
]) : [];
|
|
@@ -5471,8 +7050,8 @@ function syncSwiftTree(base, files) {
|
|
|
5471
7050
|
mkdirSync2(base, { recursive: true });
|
|
5472
7051
|
const walk = (dir) => {
|
|
5473
7052
|
for (const entry of readdirSync5(dir, { withFileTypes: true })) {
|
|
5474
|
-
const full =
|
|
5475
|
-
if (dir === base && (entry.name === ".build" || entry.name.startsWith(".peach-modules-") || entry.name === SWIFT_LINK_STAMP
|
|
7053
|
+
const full = path14.join(dir, entry.name);
|
|
7054
|
+
if (dir === base && (entry.name === ".build" || entry.name.startsWith(".peach-modules-") || entry.name === SWIFT_LINK_STAMP))
|
|
5476
7055
|
continue;
|
|
5477
7056
|
if (entry.isDirectory()) walk(full);
|
|
5478
7057
|
else if (!files.has(full)) rmSync3(full, { force: true });
|
|
@@ -5482,7 +7061,7 @@ function syncSwiftTree(base, files) {
|
|
|
5482
7061
|
for (const [full, contents] of files) {
|
|
5483
7062
|
if (existsSync2(full) && (typeof contents === "string" ? readFileSync7(full, "utf8") === contents : readFileSync7(full).equals(contents)))
|
|
5484
7063
|
continue;
|
|
5485
|
-
mkdirSync2(
|
|
7064
|
+
mkdirSync2(path14.dirname(full), { recursive: true });
|
|
5486
7065
|
writeFileSync3(full, contents);
|
|
5487
7066
|
}
|
|
5488
7067
|
}
|
|
@@ -5768,9 +7347,7 @@ var FOUNDATION_OVERLAY_TYPES = /* @__PURE__ */ new Set([
|
|
|
5768
7347
|
"URLUbiquitousSharedItemPermissions",
|
|
5769
7348
|
"URLUbiquitousSharedItemRole",
|
|
5770
7349
|
"UndoManager",
|
|
5771
|
-
"ValueTransformer"
|
|
5772
|
-
"XMLParser",
|
|
5773
|
-
"XMLParserDelegate"
|
|
7350
|
+
"ValueTransformer"
|
|
5774
7351
|
]);
|
|
5775
7352
|
var FOUNDATION_OVERLAY_GLOBALS = /* @__PURE__ */ new Set([
|
|
5776
7353
|
"CFBridgingRetain",
|
|
@@ -6139,7 +7716,6 @@ var FOUNDATION_OVERLAY_GLOBALS = /* @__PURE__ */ new Set([
|
|
|
6139
7716
|
"NSUnicodeStringEncoding",
|
|
6140
7717
|
"NSUserActivityErrorMaximum",
|
|
6141
7718
|
"NSUserActivityErrorMinimum",
|
|
6142
|
-
"NSUserActivityTypeBrowsingWeb",
|
|
6143
7719
|
"NSValidationErrorMaximum",
|
|
6144
7720
|
"NSValidationErrorMinimum",
|
|
6145
7721
|
"NSWindows95OperatingSystem",
|
|
@@ -6481,7 +8057,7 @@ function swiftApplicationEntry(file, source) {
|
|
|
6481
8057
|
else if (source[at] === "}") depth--;
|
|
6482
8058
|
else if (depth === 0 && /^@(?:main|UIApplicationMain)\b/.test(source.slice(at)))
|
|
6483
8059
|
return true;
|
|
6484
|
-
else if (depth === 0 &&
|
|
8060
|
+
else if (depth === 0 && path14.basename(file) === "main.swift" && /^UIApplicationMain\s*\(/.test(source.slice(at)))
|
|
6485
8061
|
return true;
|
|
6486
8062
|
}
|
|
6487
8063
|
return false;
|
|
@@ -6842,14 +8418,14 @@ function prepareSwiftDependency(source, destination) {
|
|
|
6842
8418
|
for (const entry of readdirSync5(from, { withFileTypes: true })) {
|
|
6843
8419
|
if (entry.name === ".git" || entry.name === ".build" || entry.name === ".swiftpm")
|
|
6844
8420
|
continue;
|
|
6845
|
-
const file =
|
|
8421
|
+
const file = path14.join(from, entry.name);
|
|
6846
8422
|
if (entry.isDirectory()) gather(file);
|
|
6847
8423
|
else if (entry.isFile() && entry.name.endsWith(".swift"))
|
|
6848
|
-
origins[
|
|
8424
|
+
origins[path14.relative(source, file)] = readFileSync7(file, "utf8");
|
|
6849
8425
|
}
|
|
6850
8426
|
};
|
|
6851
8427
|
gather(source);
|
|
6852
|
-
const manifest =
|
|
8428
|
+
const manifest = path14.join(source, "Package.swift");
|
|
6853
8429
|
const targets = existsSync2(manifest) ? swiftManifestTargets(readFileSync7(manifest, "utf8")) : [];
|
|
6854
8430
|
const compiled = compiledSwiftSources(origins, targets);
|
|
6855
8431
|
const copy = (from, to) => {
|
|
@@ -6857,31 +8433,31 @@ function prepareSwiftDependency(source, destination) {
|
|
|
6857
8433
|
for (const entry of readdirSync5(from, { withFileTypes: true })) {
|
|
6858
8434
|
if (entry.name === ".git" || entry.name === ".build" || entry.name === ".swiftpm")
|
|
6859
8435
|
continue;
|
|
6860
|
-
const file =
|
|
6861
|
-
const target =
|
|
8436
|
+
const file = path14.join(from, entry.name);
|
|
8437
|
+
const target = path14.join(to, entry.name);
|
|
6862
8438
|
if (entry.isDirectory()) copy(file, target);
|
|
6863
8439
|
else if (entry.isFile() && entry.name.endsWith(".swift"))
|
|
6864
|
-
writeFileSync3(target, compiled.get(
|
|
8440
|
+
writeFileSync3(target, compiled.get(path14.relative(source, file)));
|
|
6865
8441
|
else cpSync(file, target, { verbatimSymlinks: true });
|
|
6866
8442
|
}
|
|
6867
8443
|
};
|
|
6868
8444
|
copy(source, destination);
|
|
6869
8445
|
}
|
|
6870
8446
|
var HIDDEN_UNITS = "PeachHiddenUnits";
|
|
6871
|
-
function clangImportModuleMapFlags(settings, layoutRoot, written) {
|
|
8447
|
+
function clangImportModuleMapFlags(settings, layoutRoot, written, generated) {
|
|
6872
8448
|
const searched = new Set(settings.headerSearchPaths);
|
|
6873
|
-
const directory =
|
|
8449
|
+
const directory = path14.join(layoutRoot, ".build", "peach-clang-modulemaps");
|
|
6874
8450
|
return (settings.moduleMaps ?? []).flatMap((map) => {
|
|
6875
|
-
const headers =
|
|
8451
|
+
const headers = path14.join(layoutRoot, map.headers);
|
|
6876
8452
|
if (!existsSync2(headers)) return [];
|
|
6877
|
-
const published =
|
|
8453
|
+
const published = path14.join(headers, "module.modulemap");
|
|
6878
8454
|
if (searched.has(map.headers) && existsSync2(published)) return [];
|
|
6879
8455
|
if (!searched.has(map.headers) && existsSync2(published))
|
|
6880
8456
|
return [`-fmodule-map-file=${published}`];
|
|
6881
8457
|
const cached = written.get(headers);
|
|
6882
8458
|
if (cached) return [cached];
|
|
6883
8459
|
mkdirSync2(directory, { recursive: true });
|
|
6884
|
-
const output =
|
|
8460
|
+
const output = path14.join(directory, `module-${written.size}.modulemap`);
|
|
6885
8461
|
writeFileSync3(
|
|
6886
8462
|
output,
|
|
6887
8463
|
swiftPackageClangModuleMap(swiftTargetModuleName(map.module), {
|
|
@@ -6889,6 +8465,7 @@ function clangImportModuleMapFlags(settings, layoutRoot, written) {
|
|
|
6889
8465
|
path: headers
|
|
6890
8466
|
})
|
|
6891
8467
|
);
|
|
8468
|
+
generated.push({ output, module: swiftTargetModuleName(map.module), published });
|
|
6892
8469
|
const flag = `-fmodule-map-file=${output}`;
|
|
6893
8470
|
written.set(headers, flag);
|
|
6894
8471
|
return [flag];
|
|
@@ -6917,14 +8494,19 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
6917
8494
|
const targets = distribution && compileTargets(input).length === 0 ? [
|
|
6918
8495
|
{
|
|
6919
8496
|
name: "App",
|
|
6920
|
-
path:
|
|
8497
|
+
path: path14.relative(layout.root, layout.sources),
|
|
6921
8498
|
executable: true,
|
|
6922
8499
|
languageMode: 5,
|
|
6923
8500
|
mainActorIsolation: false,
|
|
6924
8501
|
resources: false
|
|
6925
8502
|
}
|
|
6926
8503
|
] : compileTargets(input);
|
|
6927
|
-
const distributionExcludes = distribution ?
|
|
8504
|
+
const distributionExcludes = distribution ? /* @__PURE__ */ new Set([
|
|
8505
|
+
...swiftSystemLibraryExclusions(input.files, targets, distribution.modules),
|
|
8506
|
+
...distribution.modules.filter(
|
|
8507
|
+
(name2) => OPTIONAL_FRAMEWORKS.has(name2) && targets.some((target) => target.name === name2)
|
|
8508
|
+
)
|
|
8509
|
+
]) : void 0;
|
|
6928
8510
|
const files = /* @__PURE__ */ new Map();
|
|
6929
8511
|
const native = /* @__PURE__ */ new Map();
|
|
6930
8512
|
const targetFailures = [];
|
|
@@ -6956,18 +8538,18 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
6956
8538
|
clangImportedModules.add(name2);
|
|
6957
8539
|
}
|
|
6958
8540
|
}
|
|
6959
|
-
const headerDirectory =
|
|
8541
|
+
const headerDirectory = path14.join(layout.root, ".build", "peach-cxx-headers");
|
|
6960
8542
|
let checkedToolchain;
|
|
6961
8543
|
const nativeToolchain = () => {
|
|
6962
8544
|
if (checkedToolchain) return checkedToolchain;
|
|
6963
|
-
const pin = distribution ?? JSON.parse(readFileSync7(
|
|
8545
|
+
const pin = distribution ?? JSON.parse(readFileSync7(path14.join(moduleRoot, "toolchain.json"), "utf8"));
|
|
6964
8546
|
checkedToolchain = swiftToolchain(pin.release, swiftModuleSdk(moduleRoot));
|
|
6965
8547
|
return checkedToolchain;
|
|
6966
8548
|
};
|
|
6967
8549
|
const deploymentTarget = (name2) => input.nativeTargets?.find((value) => value.name === name2)?.deploymentTarget ?? targets.find((value) => value.name === name2)?.iosDeploymentTarget ?? null;
|
|
6968
8550
|
const targetStagedFiles = /* @__PURE__ */ new Map();
|
|
6969
8551
|
const stageTargetFile = (target, file, contents, options) => {
|
|
6970
|
-
const relative =
|
|
8552
|
+
const relative = path14.relative(layout.root, file).split(path14.sep).join(path14.posix.sep);
|
|
6971
8553
|
const prior = files.has(file) ? files.get(file) : Object.hasOwn(input.files, relative) ? input.files[relative] : void 0;
|
|
6972
8554
|
if (!options?.allowExisting && prior !== void 0)
|
|
6973
8555
|
throw new Error(`target ${target} already contains generated output ${relative}`);
|
|
@@ -6996,7 +8578,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
6996
8578
|
targetStagedFiles.delete(target.name);
|
|
6997
8579
|
if (entries.some(([file]) => isSwiftNativeTranslationUnit(file)) && (swift || input.nativeTargets?.some((value) => value.name === target.name))) {
|
|
6998
8580
|
if (!swift) {
|
|
6999
|
-
const unprepared =
|
|
8581
|
+
const unprepared = path14.join(
|
|
7000
8582
|
layout.root,
|
|
7001
8583
|
target.path,
|
|
7002
8584
|
"PeachUnprepared.generated.swift"
|
|
@@ -7011,7 +8593,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7011
8593
|
native.set(target.name, {
|
|
7012
8594
|
mixed: true,
|
|
7013
8595
|
path: target.path,
|
|
7014
|
-
includeDirectory:
|
|
8596
|
+
includeDirectory: path14.join(layout.root, target.path, "include"),
|
|
7015
8597
|
sources: [],
|
|
7016
8598
|
lateSources: [],
|
|
7017
8599
|
exclude: entries.filter(([file]) => !file.endsWith(".swift") && !file.endsWith(".metal")).map(([file]) => file.slice(prefix.length))
|
|
@@ -7020,30 +8602,33 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7020
8602
|
};
|
|
7021
8603
|
for (const settings of input.nativeTargets ?? []) {
|
|
7022
8604
|
for (const file of settings.headers) {
|
|
7023
|
-
const
|
|
8605
|
+
const interfaceModule = /(?:^|\/)(\w+)\.framework\/Headers\/\1-Swift\.h$/.exec(
|
|
8606
|
+
file
|
|
8607
|
+
)?.[1];
|
|
8608
|
+
const contents = interfaceModule && swiftModuleInterface(moduleRoot, interfaceModule)?.header || input.files[file];
|
|
7024
8609
|
if (contents === void 0)
|
|
7025
8610
|
throw new Error(`missing original Objective-C header ${file}`);
|
|
7026
|
-
const destination =
|
|
7027
|
-
mkdirSync2(
|
|
8611
|
+
const destination = path14.join(layout.root, file);
|
|
8612
|
+
mkdirSync2(path14.dirname(destination), { recursive: true });
|
|
7028
8613
|
writeFileSync3(destination, contents);
|
|
7029
8614
|
files.set(destination, contents);
|
|
7030
8615
|
}
|
|
7031
8616
|
if (!settings.flattensPublicHeaders) continue;
|
|
7032
8617
|
for (const header of settings.publicHeaders) {
|
|
7033
|
-
const destination =
|
|
8618
|
+
const destination = path14.join(headerDirectory, settings.name, path14.basename(header));
|
|
7034
8619
|
if (files.has(destination))
|
|
7035
8620
|
throw new Error(`duplicate product header ${destination}`);
|
|
7036
|
-
const contents = `#import ${JSON.stringify(
|
|
8621
|
+
const contents = `#import ${JSON.stringify(path14.join(layout.root, header))}
|
|
7037
8622
|
`;
|
|
7038
8623
|
files.set(destination, contents);
|
|
7039
|
-
mkdirSync2(
|
|
8624
|
+
mkdirSync2(path14.dirname(destination), { recursive: true });
|
|
7040
8625
|
writeFileSync3(destination, contents);
|
|
7041
8626
|
}
|
|
7042
8627
|
}
|
|
7043
8628
|
const nativeTargets = input.nativeTargets ?? [];
|
|
7044
|
-
const fromInputRoot = (file) => file.startsWith(`${SWIFT_NATIVE_INPUT_ROOT}/`) ?
|
|
8629
|
+
const fromInputRoot = (file) => file.startsWith(`${SWIFT_NATIVE_INPUT_ROOT}/`) ? path14.join(layout.root, file.slice(SWIFT_NATIVE_INPUT_ROOT.length + 1)) : file;
|
|
7045
8630
|
const headerSearch = writeXcodeHeaderSearch(
|
|
7046
|
-
|
|
8631
|
+
path14.join(layout.root, ".build", "peach-xcode-headers"),
|
|
7047
8632
|
nativeTargets.map((settings) => ({
|
|
7048
8633
|
headerMaps: settings.headerMaps.map((map) => ({
|
|
7049
8634
|
flag: map.flag,
|
|
@@ -7054,16 +8639,17 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7054
8639
|
})),
|
|
7055
8640
|
productHeaders: Object.fromEntries(
|
|
7056
8641
|
Object.entries(settings.productHeaders).map(([product, file]) => [
|
|
7057
|
-
|
|
7058
|
-
|
|
8642
|
+
path14.join(layout.root, product),
|
|
8643
|
+
path14.join(layout.root, file)
|
|
7059
8644
|
])
|
|
7060
8645
|
),
|
|
7061
8646
|
userHeaderSearchPaths: settings.userHeaderSearchPaths.map(
|
|
7062
|
-
(directory) =>
|
|
8647
|
+
(directory) => path14.join(layout.root, directory)
|
|
7063
8648
|
)
|
|
7064
8649
|
}))
|
|
7065
8650
|
);
|
|
7066
8651
|
const importModuleMaps = /* @__PURE__ */ new Map();
|
|
8652
|
+
const generatedModuleMaps = [];
|
|
7067
8653
|
for (const target of targets) {
|
|
7068
8654
|
const prefix = target.path === "." ? "" : `${target.path}/`;
|
|
7069
8655
|
const entries = targetEntries(target);
|
|
@@ -7083,7 +8669,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7083
8669
|
if (producer && targets.some((value) => value.name === producer))
|
|
7084
8670
|
producers2.add(producer);
|
|
7085
8671
|
const local = [
|
|
7086
|
-
|
|
8672
|
+
path14.posix.join(path14.posix.dirname(file), include2),
|
|
7087
8673
|
`${includes}${include2}`
|
|
7088
8674
|
].find((candidate) => input.files[candidate] !== void 0);
|
|
7089
8675
|
if (local) {
|
|
@@ -7117,12 +8703,12 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7117
8703
|
const headers = settings.headers;
|
|
7118
8704
|
const roots2 = settings.bridgingHeader ? [settings.bridgingHeader] : entries.some(([file]) => file.endsWith(".swift")) || importedModules.has(swiftTargetModuleName(target.name)) ? settings.publicHeaders : [];
|
|
7119
8705
|
for (const file of headers) {
|
|
7120
|
-
const destination =
|
|
7121
|
-
mkdirSync2(
|
|
8706
|
+
const destination = path14.join(layout.root, file);
|
|
8707
|
+
mkdirSync2(path14.dirname(destination), { recursive: true });
|
|
7122
8708
|
writeFileSync3(destination, input.files[file]);
|
|
7123
8709
|
}
|
|
7124
8710
|
const search = [.../* @__PURE__ */ new Set([...settings?.headerSearchPaths ?? []])].flatMap(
|
|
7125
|
-
(dir) => ["-I",
|
|
8711
|
+
(dir) => ["-I", path14.join(layout.root, dir)]
|
|
7126
8712
|
);
|
|
7127
8713
|
const toolchainBin = nativeToolchain();
|
|
7128
8714
|
const stageFlags = (flags2, sdkInclude2) => flags2.map(
|
|
@@ -7134,7 +8720,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7134
8720
|
...search,
|
|
7135
8721
|
...(settings?.frameworkSearchPaths ?? []).flatMap((dir) => [
|
|
7136
8722
|
"-F",
|
|
7137
|
-
|
|
8723
|
+
path14.join(layout.root, dir)
|
|
7138
8724
|
]),
|
|
7139
8725
|
"-I",
|
|
7140
8726
|
headerDirectory
|
|
@@ -7145,13 +8731,13 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7145
8731
|
const flag = settings.flags[index];
|
|
7146
8732
|
if (flag === "-I" || flag === "-iquote") {
|
|
7147
8733
|
const directory = settings.flags[index + 1];
|
|
7148
|
-
if (directory === void 0 || !
|
|
8734
|
+
if (directory === void 0 || !path14.isAbsolute(directory)) {
|
|
7149
8735
|
index++;
|
|
7150
8736
|
continue;
|
|
7151
8737
|
}
|
|
7152
8738
|
}
|
|
7153
8739
|
const joined = /^-(?:I|iquote)(.+)$/.exec(flag);
|
|
7154
|
-
if (joined && !
|
|
8740
|
+
if (joined && !path14.isAbsolute(joined[1])) continue;
|
|
7155
8741
|
kept.push(flag);
|
|
7156
8742
|
}
|
|
7157
8743
|
return [
|
|
@@ -7160,18 +8746,18 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7160
8746
|
...search,
|
|
7161
8747
|
...(settings?.frameworkSearchPaths ?? []).flatMap((dir) => [
|
|
7162
8748
|
"-F",
|
|
7163
|
-
|
|
8749
|
+
path14.join(layout.root, dir)
|
|
7164
8750
|
]),
|
|
7165
8751
|
"-I",
|
|
7166
8752
|
headerDirectory
|
|
7167
8753
|
];
|
|
7168
8754
|
})();
|
|
7169
|
-
const sdkInclude =
|
|
8755
|
+
const sdkInclude = path14.join(
|
|
7170
8756
|
swiftSdkPaths(moduleRoot, toolchainBin).sysroot,
|
|
7171
8757
|
"darwin/usr/include"
|
|
7172
8758
|
);
|
|
7173
8759
|
const flags = stageFlags(originalFlags, sdkInclude);
|
|
7174
|
-
const prefixHeader = settings?.prefixHeader ? ["-include",
|
|
8760
|
+
const prefixHeader = settings?.prefixHeader ? ["-include", path14.join(layout.root, settings.prefixHeader)] : [];
|
|
7175
8761
|
const bundleName = entries.some(([file]) => file.endsWith(".swift")) ? void 0 : swiftObjCResourceBundleName({
|
|
7176
8762
|
target: target.name,
|
|
7177
8763
|
path: target.path,
|
|
@@ -7182,7 +8768,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7182
8768
|
bundles: input.resourceBundles
|
|
7183
8769
|
});
|
|
7184
8770
|
const accessor = bundleName === void 0 ? void 0 : swiftObjCResourceAccessor(bundleName);
|
|
7185
|
-
const accessorHeader =
|
|
8771
|
+
const accessorHeader = path14.join(
|
|
7186
8772
|
layout.root,
|
|
7187
8773
|
target.path,
|
|
7188
8774
|
OBJC_RESOURCE_ACCESSOR_HEADER
|
|
@@ -7193,7 +8779,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7193
8779
|
const nativeUnits = accessor ? [...units, [accessorUnit, accessor.body]] : units;
|
|
7194
8780
|
const unitSource = (file) => {
|
|
7195
8781
|
const relative = file.slice(prefix.length);
|
|
7196
|
-
return relative.split("/").some((part) => part.startsWith(".")) ?
|
|
8782
|
+
return relative.split("/").some((part) => part.startsWith(".")) ? path14.posix.join(HIDDEN_UNITS, relative.replaceAll(/(^|\/)\./g, "$1%2E")) : relative;
|
|
7197
8783
|
};
|
|
7198
8784
|
const accessorFlags = accessor ? ["-include", accessorHeader] : [];
|
|
7199
8785
|
const nativeC = !entries.some(([file]) => file.endsWith(".swift"));
|
|
@@ -7223,20 +8809,20 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7223
8809
|
)
|
|
7224
8810
|
].sort();
|
|
7225
8811
|
const topHeaders = settings.publicHeaders.filter(
|
|
7226
|
-
(file) =>
|
|
8812
|
+
(file) => path14.posix.dirname(file) === headerDir
|
|
7227
8813
|
);
|
|
7228
8814
|
if (input.files[custom] !== void 0) {
|
|
7229
8815
|
swiftpmModuleMap = { path: custom, contents: input.files[custom] };
|
|
7230
8816
|
} else if (input.files[umbrella] !== void 0) {
|
|
7231
8817
|
if (siblingDirs.length > 0)
|
|
7232
8818
|
throw new Error(
|
|
7233
|
-
`target ${target.name} has invalid header layout: umbrella header found at '${
|
|
8819
|
+
`target ${target.name} has invalid header layout: umbrella header found at '${path14.join(layout.root, umbrella)}', but directories exist next to it: ${siblingDirs.map((name2) => path14.join(layout.root, headerDir, name2)).join(", ")}; consider removing them`
|
|
7234
8820
|
);
|
|
7235
8821
|
swiftpmModuleMap = {
|
|
7236
8822
|
path: custom,
|
|
7237
8823
|
contents: swiftPackageClangModuleMap(moduleName, {
|
|
7238
8824
|
kind: "header",
|
|
7239
|
-
path:
|
|
8825
|
+
path: path14.join(layout.root, umbrella)
|
|
7240
8826
|
})
|
|
7241
8827
|
};
|
|
7242
8828
|
} else if (input.files[nestedUmbrella] !== void 0 && siblingDirs.length === 1 && siblingDirs[0] === moduleName && topHeaders.length === 0) {
|
|
@@ -7244,7 +8830,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7244
8830
|
path: custom,
|
|
7245
8831
|
contents: swiftPackageClangModuleMap(moduleName, {
|
|
7246
8832
|
kind: "header",
|
|
7247
|
-
path:
|
|
8833
|
+
path: path14.join(layout.root, nestedUmbrella)
|
|
7248
8834
|
})
|
|
7249
8835
|
};
|
|
7250
8836
|
} else {
|
|
@@ -7252,12 +8838,12 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7252
8838
|
path: custom,
|
|
7253
8839
|
contents: swiftPackageClangModuleMap(moduleName, {
|
|
7254
8840
|
kind: "directory",
|
|
7255
|
-
path:
|
|
8841
|
+
path: path14.join(layout.root, headerDir)
|
|
7256
8842
|
})
|
|
7257
8843
|
};
|
|
7258
8844
|
}
|
|
7259
8845
|
}
|
|
7260
|
-
const modulemap = originalModuleMap?.[0] ?? swiftpmModuleMap?.path ?? packageModuleMap?.[0] ??
|
|
8846
|
+
const modulemap = originalModuleMap?.[0] ?? swiftpmModuleMap?.path ?? packageModuleMap?.[0] ?? path14.posix.join(
|
|
7261
8847
|
".build",
|
|
7262
8848
|
"peach-objc-originals",
|
|
7263
8849
|
target.name,
|
|
@@ -7265,48 +8851,53 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7265
8851
|
);
|
|
7266
8852
|
const moduleContents = originalModuleMap ? input.files[originalModuleMap[1]] : swiftpmModuleMap?.contents ?? packageModuleMap?.[1] ?? swiftObjCModuleMap(
|
|
7267
8853
|
swiftTargetModuleName(target.name),
|
|
7268
|
-
roots2.map((file) =>
|
|
8854
|
+
roots2.map((file) => path14.join(layout.root, file))
|
|
7269
8855
|
);
|
|
7270
8856
|
if (moduleContents === void 0)
|
|
7271
8857
|
throw new Error("missing original module map " + modulemap);
|
|
7272
|
-
stageTargetFile(target.name,
|
|
8858
|
+
stageTargetFile(target.name, path14.join(layout.root, modulemap), moduleContents, {
|
|
7273
8859
|
allowExisting: true
|
|
7274
8860
|
});
|
|
7275
8861
|
const importFlags = [
|
|
7276
8862
|
...swiftClangImporterFlags(stageFlags(importOriginalFlags, sdkInclude)),
|
|
7277
|
-
"-fmodule-map-file=" +
|
|
7278
|
-
...clangImportModuleMapFlags(
|
|
8863
|
+
"-fmodule-map-file=" + path14.join(layout.root, modulemap),
|
|
8864
|
+
...clangImportModuleMapFlags(
|
|
8865
|
+
settings,
|
|
8866
|
+
layout.root,
|
|
8867
|
+
importModuleMaps,
|
|
8868
|
+
generatedModuleMaps
|
|
8869
|
+
)
|
|
7279
8870
|
];
|
|
7280
8871
|
const groups = /* @__PURE__ */ new Map();
|
|
7281
8872
|
for (const [file, contents] of nativeUnits) {
|
|
7282
8873
|
const origin = settings?.sourceDirectories[file];
|
|
7283
8874
|
if (origin) {
|
|
7284
|
-
const original =
|
|
7285
|
-
mkdirSync2(
|
|
8875
|
+
const original = path14.join(layout.root, origin, path14.posix.basename(file));
|
|
8876
|
+
mkdirSync2(path14.dirname(original), { recursive: true });
|
|
7286
8877
|
stageTargetFile(target.name, original, contents, { allowExisting: true });
|
|
7287
8878
|
}
|
|
7288
8879
|
const source = unitSource(file);
|
|
7289
8880
|
if (source !== file.slice(prefix.length))
|
|
7290
8881
|
stageTargetFile(
|
|
7291
8882
|
target.name,
|
|
7292
|
-
|
|
8883
|
+
path14.join(layout.root, target.path, source),
|
|
7293
8884
|
contents,
|
|
7294
8885
|
{
|
|
7295
8886
|
allowExisting: true
|
|
7296
8887
|
}
|
|
7297
8888
|
);
|
|
7298
8889
|
const perFile = [
|
|
7299
|
-
...origin ? ["-iquote",
|
|
8890
|
+
...origin ? ["-iquote", path14.join(layout.root, origin)] : [],
|
|
7300
8891
|
...stageFlags(
|
|
7301
8892
|
settings?.fileFlags[file] ?? [],
|
|
7302
|
-
|
|
8893
|
+
path14.join(
|
|
7303
8894
|
swiftSdkPaths(moduleRoot, toolchainBin).sysroot,
|
|
7304
8895
|
"darwin/usr/include"
|
|
7305
8896
|
)
|
|
7306
8897
|
)
|
|
7307
8898
|
];
|
|
7308
8899
|
const cxx = /\.(?:cc|cpp|cxx|mm)$/.test(file);
|
|
7309
|
-
const identity =
|
|
8900
|
+
const identity = createHash8("sha256").update(JSON.stringify([cxx, perFile, (consumers.get(file)?.size ?? 0) > 0])).digest("hex").slice(0, 12);
|
|
7310
8901
|
const group = groups.get(identity) ?? {
|
|
7311
8902
|
name: `${target.name}${nativeC ? "Native" : "Swift"}Implementation_${identity}`,
|
|
7312
8903
|
sources: [],
|
|
@@ -7317,7 +8908,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7317
8908
|
...accessorFlags,
|
|
7318
8909
|
...stageFlags(
|
|
7319
8910
|
cxx ? settings.cxxFlags : [],
|
|
7320
|
-
|
|
8911
|
+
path14.join(
|
|
7321
8912
|
swiftSdkPaths(moduleRoot, toolchainBin).sysroot,
|
|
7322
8913
|
"darwin/usr/include"
|
|
7323
8914
|
)
|
|
@@ -7332,7 +8923,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7332
8923
|
stageTargetFile(target.name, accessorHeader, accessor.header);
|
|
7333
8924
|
stageTargetFile(
|
|
7334
8925
|
target.name,
|
|
7335
|
-
|
|
8926
|
+
path14.join(layout.root, accessorUnit),
|
|
7336
8927
|
accessor.body
|
|
7337
8928
|
);
|
|
7338
8929
|
}
|
|
@@ -7347,7 +8938,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7347
8938
|
].sort();
|
|
7348
8939
|
native.set(target.name, {
|
|
7349
8940
|
path: target.path,
|
|
7350
|
-
includeDirectory:
|
|
8941
|
+
includeDirectory: path14.dirname(path14.join(layout.root, modulemap)),
|
|
7351
8942
|
importFlags,
|
|
7352
8943
|
sources: nativeUnits.map(([file]) => unitSource(file)),
|
|
7353
8944
|
lateSources: implementations.flatMap((group) => group.sources),
|
|
@@ -7365,15 +8956,15 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7365
8956
|
});
|
|
7366
8957
|
continue;
|
|
7367
8958
|
}
|
|
7368
|
-
const implementationHeaders =
|
|
8959
|
+
const implementationHeaders = path14.posix.join(
|
|
7369
8960
|
".build",
|
|
7370
8961
|
"peach-objc-implementations",
|
|
7371
8962
|
target.name
|
|
7372
8963
|
);
|
|
7373
|
-
const include2 =
|
|
8964
|
+
const include2 = path14.join(layout.root, implementationHeaders);
|
|
7374
8965
|
stageTargetFile(
|
|
7375
8966
|
target.name,
|
|
7376
|
-
|
|
8967
|
+
path14.join(include2, "module.modulemap"),
|
|
7377
8968
|
`module ${target.name}ImplementationDeclarations { export * }
|
|
7378
8969
|
`
|
|
7379
8970
|
);
|
|
@@ -7384,7 +8975,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7384
8975
|
implementationHeaders,
|
|
7385
8976
|
importFlags,
|
|
7386
8977
|
swiftFlags: [
|
|
7387
|
-
...settings.bridgingHeader ? ["-import-objc-header",
|
|
8978
|
+
...settings.bridgingHeader ? ["-import-objc-header", path14.join(layout.root, settings.bridgingHeader)] : roots2.length ? ["-import-underlying-module"] : [],
|
|
7388
8979
|
...importFlags.flatMap((flag) => ["-Xcc", flag])
|
|
7389
8980
|
],
|
|
7390
8981
|
sources: nativeUnits.map(([file]) => unitSource(file)),
|
|
@@ -7414,7 +9005,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7414
9005
|
}
|
|
7415
9006
|
native.set(target.name, {
|
|
7416
9007
|
path: target.path,
|
|
7417
|
-
includeDirectory:
|
|
9008
|
+
includeDirectory: path14.join(layout.root, includes),
|
|
7418
9009
|
sources: units.map(([file]) => file.slice(prefix.length)),
|
|
7419
9010
|
lateSources: late.map(([file]) => file.slice(prefix.length)),
|
|
7420
9011
|
...late.length > 0 ? {
|
|
@@ -7432,7 +9023,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7432
9023
|
([file]) => file.startsWith(includes) && /\.(?:h|hpp|hh|hxx)$/.test(file) && consumers.get(file).size === 0
|
|
7433
9024
|
);
|
|
7434
9025
|
files.set(
|
|
7435
|
-
|
|
9026
|
+
path14.join(layout.root, includes, "module.modulemap"),
|
|
7436
9027
|
[
|
|
7437
9028
|
`module ${target.name} {`,
|
|
7438
9029
|
...roots.map(
|
|
@@ -7444,16 +9035,26 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7444
9035
|
].join("\n")
|
|
7445
9036
|
);
|
|
7446
9037
|
}
|
|
9038
|
+
for (const map of generatedModuleMaps)
|
|
9039
|
+
if (files.has(map.published) || Object.hasOwn(
|
|
9040
|
+
input.files,
|
|
9041
|
+
path14.relative(layout.root, map.published).split(path14.sep).join(path14.posix.sep)
|
|
9042
|
+
))
|
|
9043
|
+
writeFileSync3(
|
|
9044
|
+
map.output,
|
|
9045
|
+
`extern module ${map.module} ${JSON.stringify(map.published)}
|
|
9046
|
+
`
|
|
9047
|
+
);
|
|
7447
9048
|
if (native.size > 0) mkdirSync2(headerDirectory, { recursive: true });
|
|
7448
9049
|
const nativeHeaderFlags = [];
|
|
7449
9050
|
for (const name2 of new Set(
|
|
7450
9051
|
[...native.values()].flatMap((value) => value.late?.producers ?? [])
|
|
7451
9052
|
)) {
|
|
7452
9053
|
files.set(
|
|
7453
|
-
|
|
9054
|
+
path14.join(headerDirectory, name2, name2 + "-Swift.h"),
|
|
7454
9055
|
'#include "../' + name2 + '-Swift.h"\n'
|
|
7455
9056
|
);
|
|
7456
|
-
const modulemap =
|
|
9057
|
+
const modulemap = path14.join(
|
|
7457
9058
|
layout.root,
|
|
7458
9059
|
".build",
|
|
7459
9060
|
"peach-objc-swift-headers",
|
|
@@ -7463,19 +9064,19 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7463
9064
|
files.set(
|
|
7464
9065
|
modulemap,
|
|
7465
9066
|
swiftObjCModuleMap(swiftTargetModuleName(name2), [
|
|
7466
|
-
...(input.nativeTargets?.find((target) => target.name === name2)?.publicHeaders ?? []).map((header) =>
|
|
7467
|
-
|
|
9067
|
+
...(input.nativeTargets?.find((target) => target.name === name2)?.publicHeaders ?? []).map((header) => path14.join(layout.root, header)),
|
|
9068
|
+
path14.join(headerDirectory, name2 + "-Swift.h")
|
|
7468
9069
|
])
|
|
7469
9070
|
);
|
|
7470
9071
|
nativeHeaderFlags.push("-fmodule-map-file=" + modulemap);
|
|
7471
9072
|
}
|
|
7472
|
-
const modulePlan =
|
|
9073
|
+
const modulePlan = createHash8("sha256").update(
|
|
7473
9074
|
swiftModuleInputFiles(moduleRoot).join("\n")
|
|
7474
9075
|
);
|
|
7475
9076
|
if (!distribution) {
|
|
7476
|
-
modulePlan.update(readFileSync7(
|
|
9077
|
+
modulePlan.update(readFileSync7(path14.join(moduleRoot, "Package.swift")));
|
|
7477
9078
|
}
|
|
7478
|
-
const resourcePlan =
|
|
9079
|
+
const resourcePlan = createHash8("sha256").update(
|
|
7479
9080
|
JSON.stringify(
|
|
7480
9081
|
resourceTargets.filter((target) => target.resources).map((target) => [
|
|
7481
9082
|
target.name,
|
|
@@ -7520,7 +9121,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7520
9121
|
`;
|
|
7521
9122
|
} else if (mains.length === 0) {
|
|
7522
9123
|
const procedural = entries.filter(
|
|
7523
|
-
([file, source]) =>
|
|
9124
|
+
([file, source]) => path14.basename(file) === "main.swift" && swiftApplicationEntry(file, source)
|
|
7524
9125
|
);
|
|
7525
9126
|
const wrapped = procedural.length === 1 ? wrapUIApplicationMainEntry(procedural[0][1]) : null;
|
|
7526
9127
|
if (!wrapped)
|
|
@@ -7549,7 +9150,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7549
9150
|
exclude: []
|
|
7550
9151
|
});
|
|
7551
9152
|
files.set(
|
|
7552
|
-
|
|
9153
|
+
path14.join(layout.root, `PeachApplication/${name2}/Entry.swift`),
|
|
7553
9154
|
`import ${swiftTargetModuleName(target.name)}
|
|
7554
9155
|
@main struct __PeachApplicationEntry { @MainActor static func main() { __peachRunApplication() } }
|
|
7555
9156
|
`
|
|
@@ -7559,7 +9160,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7559
9160
|
const nativeFlags = native.size > 0 ? /* @__PURE__ */ new Map() : void 0;
|
|
7560
9161
|
if (nativeFlags) {
|
|
7561
9162
|
const toolchainBin = nativeToolchain();
|
|
7562
|
-
const headers =
|
|
9163
|
+
const headers = path14.join(swiftSdkPaths(moduleRoot, toolchainBin).sysroot, "darwin");
|
|
7563
9164
|
for (const target of targets) {
|
|
7564
9165
|
const version = deploymentTarget(target.name);
|
|
7565
9166
|
const minimum = iosDeploymentMinimum(version);
|
|
@@ -7590,10 +9191,10 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7590
9191
|
if (targets.length === 0 && !prebuilt) {
|
|
7591
9192
|
for (const [file, contents] of Object.entries(input.files)) {
|
|
7592
9193
|
if (file === "Package.swift") continue;
|
|
7593
|
-
files.set(
|
|
9194
|
+
files.set(path14.join(layout.sources, file), compiled.get(file) ?? contents);
|
|
7594
9195
|
}
|
|
7595
9196
|
let manifest = readFileSync7(
|
|
7596
|
-
|
|
9197
|
+
path14.join(moduleRoot, "scripts/contrast-app-Package.swift"),
|
|
7597
9198
|
"utf8"
|
|
7598
9199
|
).replaceAll("__SOOTSIM_SWIFT_PACKAGE__", moduleRoot);
|
|
7599
9200
|
const reactor = ` ${REACTOR_FLAG}`;
|
|
@@ -7637,25 +9238,25 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7637
9238
|
manifest = manifest.replace(anchor, `${anchor}
|
|
7638
9239
|
${SPRITEKIT_PRODUCT},`);
|
|
7639
9240
|
}
|
|
7640
|
-
files.set(
|
|
9241
|
+
files.set(path14.join(layout.root, "Package.swift"), manifest + moduleFiles);
|
|
7641
9242
|
} else {
|
|
7642
9243
|
const base = layout.multi ? layout.root : layout.sources;
|
|
7643
9244
|
const libraries = /* @__PURE__ */ new Map();
|
|
7644
9245
|
for (const [target, data] of Object.entries(input.libraries ?? {})) {
|
|
7645
9246
|
const bytes = Buffer.from(data, "base64");
|
|
7646
|
-
const digest =
|
|
7647
|
-
const file =
|
|
9247
|
+
const digest = createHash8("sha256").update(bytes).digest("hex");
|
|
9248
|
+
const file = path14.join(layout.root, ".peach-libraries", `lib${target}-${digest}.a`);
|
|
7648
9249
|
files.set(file, bytes);
|
|
7649
9250
|
libraries.set(target, file);
|
|
7650
9251
|
}
|
|
7651
9252
|
for (const [file, contents] of Object.entries(input.files)) {
|
|
7652
9253
|
if (file === "Package.swift") continue;
|
|
7653
|
-
files.set(
|
|
9254
|
+
files.set(path14.join(base, file), compiled.get(file) ?? contents);
|
|
7654
9255
|
}
|
|
7655
9256
|
const manifestTargets = targets.length > 0 ? targets : [
|
|
7656
9257
|
{
|
|
7657
9258
|
name: "App",
|
|
7658
|
-
path:
|
|
9259
|
+
path: path14.relative(layout.root, layout.sources).split(path14.sep).join("/"),
|
|
7659
9260
|
executable: true,
|
|
7660
9261
|
languageMode: 5,
|
|
7661
9262
|
mainActorIsolation: false,
|
|
@@ -7666,10 +9267,10 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7666
9267
|
([file, source]) => file.endsWith(".swift") && file !== input.entry && file !== "Package.swift" || /\.mm?$/.test(file) || source.includes("dispatch_")
|
|
7667
9268
|
) || [...importedModules].some(
|
|
7668
9269
|
(name2) => distribution.modules.includes(name2) && !targets.some((target) => target.name === name2) && !(clangImportedModules.has(name2) && !swiftImportedModules.has(name2) && existsSync2(
|
|
7669
|
-
|
|
9270
|
+
path14.join(swiftSharedSdkRoot(moduleRoot, true), "usr/include", name2)
|
|
7670
9271
|
))
|
|
7671
9272
|
);
|
|
7672
|
-
const frameworkLink = prebuilt ?
|
|
9273
|
+
const frameworkLink = prebuilt ? path14.join(layout.root, ".peach-framework-objects.rsp") : void 0;
|
|
7673
9274
|
if (prebuilt && frameworkLink) {
|
|
7674
9275
|
files.set(
|
|
7675
9276
|
frameworkLink,
|
|
@@ -7677,7 +9278,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7677
9278
|
);
|
|
7678
9279
|
}
|
|
7679
9280
|
files.set(
|
|
7680
|
-
|
|
9281
|
+
path14.join(layout.root, "Package.swift"),
|
|
7681
9282
|
emitSwiftPackageManifest({
|
|
7682
9283
|
root: layout.root,
|
|
7683
9284
|
targets: manifestTargets,
|
|
@@ -7711,7 +9312,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7711
9312
|
),
|
|
7712
9313
|
...reachesFrameworks ? {
|
|
7713
9314
|
distributionLink: {
|
|
7714
|
-
path:
|
|
9315
|
+
path: path14.join(layout.root, ".peach-distribution-objects.rsp"),
|
|
7715
9316
|
files
|
|
7716
9317
|
},
|
|
7717
9318
|
lazyDistribution: input.lazyDistribution
|
|
@@ -7730,21 +9331,21 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7730
9331
|
);
|
|
7731
9332
|
}
|
|
7732
9333
|
for (const [file, bytes] of Object.entries(input.packageFiles ?? {}))
|
|
7733
|
-
files.set(
|
|
9334
|
+
files.set(path14.join(layout.root, file), Buffer.from(bytes, "base64"));
|
|
7734
9335
|
for (const [file, bytes] of Object.entries(input.projectFiles ?? {})) {
|
|
7735
|
-
const destination =
|
|
9336
|
+
const destination = path14.join(layout.root, file);
|
|
7736
9337
|
if (files.has(destination)) continue;
|
|
7737
9338
|
files.set(destination, Buffer.from(bytes, "base64"));
|
|
7738
9339
|
}
|
|
7739
9340
|
if (input.packageFiles || prebuilt) {
|
|
7740
9341
|
files.set(
|
|
7741
|
-
|
|
9342
|
+
path14.join(layout.root, ".peach-target-toolset.json"),
|
|
7742
9343
|
JSON.stringify({
|
|
7743
9344
|
schemaVersion: "1.0",
|
|
7744
9345
|
swiftCompiler: {
|
|
7745
9346
|
extraCLIOptions: [
|
|
7746
9347
|
"-I",
|
|
7747
|
-
distribution ? distributionModulesPath(layout.root, moduleRoot, distributionExcludes) : prebuilt ? prebuilt.modules :
|
|
9348
|
+
distribution ? distributionModulesPath(layout.root, moduleRoot, distributionExcludes) : prebuilt ? prebuilt.modules : path14.join(layout.root, ".build", WASM_TRIPLE, "release", "Modules"),
|
|
7748
9349
|
...prebuilt?.moduleMaps.flatMap((map) => [
|
|
7749
9350
|
"-Xcc",
|
|
7750
9351
|
`-fmodule-map-file=${map}`
|
|
@@ -7773,9 +9374,9 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7773
9374
|
throw new Error(
|
|
7774
9375
|
`swift resource target ${target.name} has no matching bundle assignment`
|
|
7775
9376
|
);
|
|
7776
|
-
const directory = layout.multi ?
|
|
9377
|
+
const directory = layout.multi ? path14.join(layout.root, target.path) : layout.sources;
|
|
7777
9378
|
files.set(
|
|
7778
|
-
|
|
9379
|
+
path14.join(directory, "ResourceBundleAccessor.generated.swift"),
|
|
7779
9380
|
[
|
|
7780
9381
|
"import Foundation",
|
|
7781
9382
|
"",
|
|
@@ -7792,7 +9393,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7792
9393
|
}
|
|
7793
9394
|
for (const [file, source] of compiled)
|
|
7794
9395
|
if (!Object.hasOwn(input.files, file))
|
|
7795
|
-
files.set(
|
|
9396
|
+
files.set(path14.join(layout.multi ? layout.root : layout.sources, file), source);
|
|
7796
9397
|
syncSwiftTree(layout.root, files);
|
|
7797
9398
|
const producers = [
|
|
7798
9399
|
.../* @__PURE__ */ new Set([...[...native.values()].flatMap((value) => value.late?.producers ?? [])])
|
|
@@ -7827,24 +9428,17 @@ function outputOf(error) {
|
|
|
7827
9428
|
return error instanceof Error ? error.message : String(error);
|
|
7828
9429
|
}
|
|
7829
9430
|
function builtArtifact(layout) {
|
|
7830
|
-
const binDir =
|
|
7831
|
-
const manifest = readFileSync7(
|
|
9431
|
+
const binDir = path14.join(layout.root, ".build", WASM_TRIPLE, "release");
|
|
9432
|
+
const manifest = readFileSync7(path14.join(layout.root, "Package.swift"), "utf8");
|
|
7832
9433
|
const executable = swiftManifestTargets(manifest).find((target) => target.executable);
|
|
7833
9434
|
if (executable === void 0) {
|
|
7834
9435
|
throw new Error("swift-compile: the written manifest names no executable target");
|
|
7835
9436
|
}
|
|
7836
|
-
|
|
7837
|
-
if (!existsSync2(file)) {
|
|
7838
|
-
const found = existsSync2(binDir) ? readdirSync5(binDir).filter((name2) => name2.endsWith(".wasm")).sort() : [];
|
|
7839
|
-
throw new Error(
|
|
7840
|
-
`swift-compile: the build produced no ${executable.name}.wasm (found: ${found.join(", ") || "none"})`
|
|
7841
|
-
);
|
|
7842
|
-
}
|
|
7843
|
-
return file;
|
|
9437
|
+
return path14.join(binDir, `${executable.name}.wasm`);
|
|
7844
9438
|
}
|
|
7845
9439
|
function projectDiagnostic(output, layout, files) {
|
|
7846
9440
|
const base = layout.multi ? layout.root : layout.sources;
|
|
7847
|
-
const prefix = `${base}${
|
|
9441
|
+
const prefix = `${base}${path14.sep}`;
|
|
7848
9442
|
return designTimeDiagnostic(output, files).split("\n").filter((line) => !SWIFTPM_NOISE.test(line)).map((line) => line.startsWith(prefix) ? line.slice(prefix.length) : line).join("\n").trim();
|
|
7849
9443
|
}
|
|
7850
9444
|
var ROOT_LOCKS = Symbol.for("peachsim.swiftCompile.rootLocks");
|
|
@@ -7880,13 +9474,13 @@ function serialize(root, work, signal) {
|
|
|
7880
9474
|
function readCompiledArtifact(directory, hash) {
|
|
7881
9475
|
try {
|
|
7882
9476
|
const receipt = JSON.parse(
|
|
7883
|
-
readFileSync7(
|
|
9477
|
+
readFileSync7(path14.join(directory, "artifact.json"), "utf8")
|
|
7884
9478
|
);
|
|
7885
9479
|
if (!receipt || typeof receipt !== "object" || !("hash" in receipt) || receipt.hash !== hash || !("icu" in receipt) || typeof receipt.icu !== "string" || !("wasm" in receipt) || typeof receipt.wasm !== "string")
|
|
7886
9480
|
return null;
|
|
7887
|
-
const bytes = readFileSync7(
|
|
7888
|
-
const gzip2 = readFileSync7(
|
|
7889
|
-
if (
|
|
9481
|
+
const bytes = readFileSync7(path14.join(directory, "app.wasm"));
|
|
9482
|
+
const gzip2 = readFileSync7(path14.join(directory, "icu.gz"));
|
|
9483
|
+
if (createHash8("sha256").update(bytes).digest("hex") !== receipt.wasm || createHash8("sha256").update(gzip2).digest("hex") !== receipt.icu || bytes.length < 8 || bytes.readUInt32LE(0) !== 1836278016 || bytes.readUInt32LE(4) !== 1)
|
|
7890
9484
|
return null;
|
|
7891
9485
|
return { hash, bytes, icu: { sha256: receipt.icu, gzip: gzip2 } };
|
|
7892
9486
|
} catch (error) {
|
|
@@ -7896,22 +9490,22 @@ function readCompiledArtifact(directory, hash) {
|
|
|
7896
9490
|
}
|
|
7897
9491
|
}
|
|
7898
9492
|
function saveCompiledArtifact(root, artifact) {
|
|
7899
|
-
const directory =
|
|
9493
|
+
const directory = path14.join(root, "artifact");
|
|
7900
9494
|
mkdirSync2(directory, { recursive: true });
|
|
7901
|
-
const pending = mkdtempSync2(
|
|
9495
|
+
const pending = mkdtempSync2(path14.join(root, ".artifact-"));
|
|
7902
9496
|
try {
|
|
7903
|
-
writeFileSync3(
|
|
7904
|
-
writeFileSync3(
|
|
9497
|
+
writeFileSync3(path14.join(pending, "app.wasm"), artifact.bytes);
|
|
9498
|
+
writeFileSync3(path14.join(pending, "icu.gz"), artifact.icu.gzip);
|
|
7905
9499
|
writeFileSync3(
|
|
7906
|
-
|
|
9500
|
+
path14.join(pending, "artifact.json"),
|
|
7907
9501
|
JSON.stringify({
|
|
7908
9502
|
hash: artifact.hash,
|
|
7909
|
-
wasm:
|
|
9503
|
+
wasm: createHash8("sha256").update(artifact.bytes).digest("hex"),
|
|
7910
9504
|
icu: artifact.icu.sha256
|
|
7911
9505
|
})
|
|
7912
9506
|
);
|
|
7913
9507
|
for (const file of ["app.wasm", "icu.gz", "artifact.json"]) {
|
|
7914
|
-
renameSync(
|
|
9508
|
+
renameSync(path14.join(pending, file), path14.join(directory, file));
|
|
7915
9509
|
}
|
|
7916
9510
|
} finally {
|
|
7917
9511
|
rmSync3(pending, { recursive: true, force: true });
|
|
@@ -7933,16 +9527,16 @@ function renewSharedArtifact(sharedRoot) {
|
|
|
7933
9527
|
function pruneSharedArtifacts(parent, keep) {
|
|
7934
9528
|
const entries = [];
|
|
7935
9529
|
for (const name2 of readdirSync5(parent)) {
|
|
7936
|
-
const directory =
|
|
9530
|
+
const directory = path14.join(parent, name2);
|
|
7937
9531
|
if (name2.startsWith(RETIRED_PREFIX)) {
|
|
7938
9532
|
rmSync3(directory, { recursive: true, force: true });
|
|
7939
9533
|
continue;
|
|
7940
9534
|
}
|
|
7941
9535
|
try {
|
|
7942
9536
|
let bytes = 0;
|
|
7943
|
-
for (const file of readdirSync5(
|
|
9537
|
+
for (const file of readdirSync5(path14.join(directory, "artifact"))) {
|
|
7944
9538
|
try {
|
|
7945
|
-
bytes += statSync(
|
|
9539
|
+
bytes += statSync(path14.join(directory, "artifact", file)).size;
|
|
7946
9540
|
} catch (error) {
|
|
7947
9541
|
if (!vanished(error)) throw error;
|
|
7948
9542
|
}
|
|
@@ -7957,9 +9551,9 @@ function pruneSharedArtifacts(parent, keep) {
|
|
|
7957
9551
|
if (total <= SHARED_ARTIFACT_BUDGET_BYTES) break;
|
|
7958
9552
|
if (entry.directory === keep || Date.now() - entry.used < SHARED_ARTIFACT_GRACE_MS)
|
|
7959
9553
|
continue;
|
|
7960
|
-
const retired =
|
|
9554
|
+
const retired = path14.join(
|
|
7961
9555
|
parent,
|
|
7962
|
-
`${RETIRED_PREFIX}${process.pid}-${
|
|
9556
|
+
`${RETIRED_PREFIX}${process.pid}-${path14.basename(entry.directory)}`
|
|
7963
9557
|
);
|
|
7964
9558
|
try {
|
|
7965
9559
|
if (statSync(entry.directory).mtimeMs !== entry.used) continue;
|
|
@@ -7975,7 +9569,7 @@ function pruneSharedArtifacts(parent, keep) {
|
|
|
7975
9569
|
function saveSharedArtifact(sharedRoot, artifact) {
|
|
7976
9570
|
saveCompiledArtifact(sharedRoot, artifact);
|
|
7977
9571
|
renewSharedArtifact(sharedRoot);
|
|
7978
|
-
pruneSharedArtifacts(
|
|
9572
|
+
pruneSharedArtifacts(path14.dirname(sharedRoot), sharedRoot);
|
|
7979
9573
|
}
|
|
7980
9574
|
var retainedArtifacts = /* @__PURE__ */ new Map();
|
|
7981
9575
|
function retain(root, artifact) {
|
|
@@ -8003,7 +9597,7 @@ function frameworkLibraryTargets(manifest) {
|
|
|
8003
9597
|
}
|
|
8004
9598
|
function linkedFrameworkTargets(moduleRoot, input) {
|
|
8005
9599
|
const libraries = frameworkLibraryTargets(
|
|
8006
|
-
readFileSync7(
|
|
9600
|
+
readFileSync7(path14.join(moduleRoot, "Package.swift"), "utf8")
|
|
8007
9601
|
);
|
|
8008
9602
|
const targets = compileTargets(input);
|
|
8009
9603
|
const planning = targets.length > 0 ? targets : [{ name: "App", path: "." }];
|
|
@@ -8044,7 +9638,7 @@ function linkedFrameworkTargets(moduleRoot, input) {
|
|
|
8044
9638
|
return { products: linked, targets: linkedMembers };
|
|
8045
9639
|
}
|
|
8046
9640
|
function writeFrameworkLinkPackage(linkRoot, moduleRoot, products) {
|
|
8047
|
-
const identity =
|
|
9641
|
+
const identity = path14.basename(moduleRoot).toLowerCase();
|
|
8048
9642
|
const swiftString = (value) => `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
8049
9643
|
const dependencies = products.map(
|
|
8050
9644
|
(name2) => ` .product(name: ${swiftString(name2)}, package: ${swiftString(identity)}),`
|
|
@@ -8066,12 +9660,12 @@ ${dependencies}
|
|
|
8066
9660
|
]
|
|
8067
9661
|
)
|
|
8068
9662
|
`;
|
|
8069
|
-
const sourceDir =
|
|
9663
|
+
const sourceDir = path14.join(linkRoot, "Sources", FRAMEWORK_LINK_TARGET);
|
|
8070
9664
|
mkdirSync2(sourceDir, { recursive: true });
|
|
8071
|
-
const manifestPath =
|
|
9665
|
+
const manifestPath = path14.join(linkRoot, "Package.swift");
|
|
8072
9666
|
if (!existsSync2(manifestPath) || readFileSync7(manifestPath, "utf8") !== manifest)
|
|
8073
9667
|
writeFileSync3(manifestPath, manifest);
|
|
8074
|
-
const source =
|
|
9668
|
+
const source = path14.join(sourceDir, "Link.swift");
|
|
8075
9669
|
if (!existsSync2(source)) writeFileSync3(source, "");
|
|
8076
9670
|
}
|
|
8077
9671
|
function frameworkLinkClosure(scratch2, roots) {
|
|
@@ -8083,7 +9677,7 @@ function frameworkLinkClosure(scratch2, roots) {
|
|
|
8083
9677
|
const moduleMaps = /* @__PURE__ */ new Map();
|
|
8084
9678
|
let pending = null;
|
|
8085
9679
|
let compiling = null;
|
|
8086
|
-
for (const line of readFileSync7(
|
|
9680
|
+
for (const line of readFileSync7(path14.join(scratch2, "release.yaml"), "utf8").split(
|
|
8087
9681
|
"\n"
|
|
8088
9682
|
)) {
|
|
8089
9683
|
const phony = phonyHeader.exec(line);
|
|
@@ -8151,20 +9745,34 @@ function frameworkLinkClosure(scratch2, roots) {
|
|
|
8151
9745
|
files.sort();
|
|
8152
9746
|
return { objects: files, modules, moduleMaps: [...maps].sort() };
|
|
8153
9747
|
}
|
|
8154
|
-
function
|
|
9748
|
+
function removeCaseCollidingModuleArtifacts(modulesDir, keep) {
|
|
8155
9749
|
if (!existsSync2(modulesDir)) return;
|
|
9750
|
+
const folded = new Set([...keep].map((name2) => name2.toLowerCase()));
|
|
8156
9751
|
for (const name2 of readdirSync5(modulesDir)) {
|
|
8157
9752
|
const dot = name2.indexOf(".");
|
|
8158
9753
|
if (dot <= 0) continue;
|
|
8159
|
-
|
|
8160
|
-
|
|
9754
|
+
const module = name2.slice(0, dot);
|
|
9755
|
+
if (keep.has(module) || !folded.has(module.toLowerCase())) continue;
|
|
9756
|
+
rmSync3(path14.join(modulesDir, name2), { recursive: true, force: true });
|
|
8161
9757
|
}
|
|
8162
9758
|
}
|
|
8163
9759
|
async function compileFrameworkProducts(args) {
|
|
8164
|
-
const scratch2 = swiftFrameworkScratch(args.
|
|
9760
|
+
const scratch2 = swiftFrameworkScratch(args.frameworkKey);
|
|
8165
9761
|
mkdirSync2(scratch2, { recursive: true });
|
|
9762
|
+
const now = /* @__PURE__ */ new Date();
|
|
9763
|
+
utimesSync(scratch2, now, now);
|
|
9764
|
+
return withSwiftRootLock(
|
|
9765
|
+
scratch2,
|
|
9766
|
+
(lease) => buildFrameworkProducts(scratch2, {
|
|
9767
|
+
...args,
|
|
9768
|
+
buildOptions: { ...args.buildOptions, lease }
|
|
9769
|
+
}),
|
|
9770
|
+
args.buildOptions.signal
|
|
9771
|
+
);
|
|
9772
|
+
}
|
|
9773
|
+
async function buildFrameworkProducts(scratch2, args) {
|
|
8166
9774
|
const linkedTargets = linkedFrameworkTargets(args.moduleRoot, args.input);
|
|
8167
|
-
const linkRoot =
|
|
9775
|
+
const linkRoot = path14.join(scratch2, "link");
|
|
8168
9776
|
writeFrameworkLinkPackage(linkRoot, args.moduleRoot, linkedTargets.products);
|
|
8169
9777
|
await runCompiler(
|
|
8170
9778
|
args.swift,
|
|
@@ -8181,7 +9789,7 @@ async function compileFrameworkProducts(args) {
|
|
|
8181
9789
|
scratch2,
|
|
8182
9790
|
"--target",
|
|
8183
9791
|
FRAMEWORK_LINK_TARGET,
|
|
8184
|
-
...
|
|
9792
|
+
...swiftCompileSdkOptions(args.moduleRoot, args.toolchainBin),
|
|
8185
9793
|
"--swift-sdk",
|
|
8186
9794
|
args.sdk,
|
|
8187
9795
|
"-c",
|
|
@@ -8208,15 +9816,17 @@ async function compileFrameworkProducts(args) {
|
|
|
8208
9816
|
args.buildOptions,
|
|
8209
9817
|
SWIFTPM_PROGRESS,
|
|
8210
9818
|
SWIFTPM_NOISE
|
|
8211
|
-
)
|
|
8212
|
-
|
|
9819
|
+
).catch((error) => {
|
|
9820
|
+
throw new Error(outputOf(error), { cause: error });
|
|
9821
|
+
});
|
|
9822
|
+
const release = path14.join(scratch2, WASM_TRIPLE, "release");
|
|
8213
9823
|
const linked = frameworkLinkClosure(scratch2, linkedTargets.targets);
|
|
8214
9824
|
const objects = linked.objects;
|
|
8215
|
-
|
|
8216
|
-
const response =
|
|
9825
|
+
removeCaseCollidingModuleArtifacts(path14.join(release, "Modules"), linked.modules);
|
|
9826
|
+
const response = path14.join(scratch2, "autolink-objects.rsp");
|
|
8217
9827
|
writeFileSync3(response, objects.map((file) => JSON.stringify(file)).join("\n") + "\n");
|
|
8218
9828
|
const extracted = await runCompiler(
|
|
8219
|
-
|
|
9829
|
+
path14.join(args.toolchainBin, "swift-autolink-extract"),
|
|
8220
9830
|
[`@${response}`, "-o", "-"],
|
|
8221
9831
|
args.buildOptions
|
|
8222
9832
|
);
|
|
@@ -8224,25 +9834,54 @@ async function compileFrameworkProducts(args) {
|
|
|
8224
9834
|
const link = extracted.split("\n").map((line) => line.trim()).filter((flag, index, all) => flag.length > 0 && all.indexOf(flag) === index);
|
|
8225
9835
|
if (link.includes("-lFoundation"))
|
|
8226
9836
|
objects.push(
|
|
8227
|
-
|
|
9837
|
+
path14.join(
|
|
8228
9838
|
swiftSdkPaths(args.moduleRoot, args.toolchainBin).resources,
|
|
8229
9839
|
"wasi/NSStringFormatting.objc.o"
|
|
8230
9840
|
)
|
|
8231
9841
|
);
|
|
8232
9842
|
return {
|
|
8233
|
-
modules:
|
|
9843
|
+
modules: path14.join(release, "Modules"),
|
|
8234
9844
|
objects,
|
|
8235
9845
|
link,
|
|
8236
9846
|
moduleMaps: linked.moduleMaps
|
|
8237
9847
|
};
|
|
8238
9848
|
}
|
|
8239
9849
|
var SWIFT_LINK_STAMP = ".peach-link-stamp";
|
|
8240
|
-
var
|
|
8241
|
-
function
|
|
8242
|
-
return
|
|
9850
|
+
var SWIFT_FRAMEWORK_SCRATCHES_KEPT = 3;
|
|
9851
|
+
function swiftFrameworksDir() {
|
|
9852
|
+
return path14.join(swiftCacheDir(), "swift-frameworks");
|
|
9853
|
+
}
|
|
9854
|
+
function swiftFrameworkScratch(frameworkKey) {
|
|
9855
|
+
return path14.join(swiftFrameworksDir(), frameworkKey);
|
|
9856
|
+
}
|
|
9857
|
+
function stageFrameworkSource(moduleRoot, frameworkKey) {
|
|
9858
|
+
if (swiftDistributionAt(moduleRoot)) return moduleRoot;
|
|
9859
|
+
const staged = path14.join(swiftFrameworkScratch(frameworkKey), "source");
|
|
9860
|
+
const stagedModule = path14.join(staged, "packages", path14.basename(moduleRoot));
|
|
9861
|
+
if (existsSync2(path14.join(staged, ".complete"))) return stagedModule;
|
|
9862
|
+
const partial = `${staged}.${randomUUID3()}`;
|
|
9863
|
+
mkdirSync2(partial, { recursive: true });
|
|
9864
|
+
cpSync(moduleRoot, path14.join(partial, "packages", path14.basename(moduleRoot)), {
|
|
9865
|
+
recursive: true,
|
|
9866
|
+
preserveTimestamps: true,
|
|
9867
|
+
filter: (source) => path14.relative(moduleRoot, source) !== ".build"
|
|
9868
|
+
});
|
|
9869
|
+
cpSync(
|
|
9870
|
+
swiftSharedSdkRoot(moduleRoot, false),
|
|
9871
|
+
path14.join(partial, "packages/peachsim/sdk/ios"),
|
|
9872
|
+
{ recursive: true, preserveTimestamps: true }
|
|
9873
|
+
);
|
|
9874
|
+
symlinkSync(
|
|
9875
|
+
realpathSync(path14.join(moduleRoot, "../../node_modules")),
|
|
9876
|
+
path14.join(partial, "node_modules")
|
|
9877
|
+
);
|
|
9878
|
+
writeFileSync3(path14.join(partial, ".complete"), "");
|
|
9879
|
+
rmSync3(staged, { recursive: true, force: true });
|
|
9880
|
+
renameSync(partial, staged);
|
|
9881
|
+
return stagedModule;
|
|
8243
9882
|
}
|
|
8244
9883
|
function swiftLinkStamp(args) {
|
|
8245
|
-
const hash =
|
|
9884
|
+
const hash = createHash8("sha256");
|
|
8246
9885
|
hash.update(`swift-link/v1
|
|
8247
9886
|
${args.frameworkKey}
|
|
8248
9887
|
`);
|
|
@@ -8267,26 +9906,22 @@ ${args.prebuilt.modules}
|
|
|
8267
9906
|
`);
|
|
8268
9907
|
for (const entry of readdirSync5(args.prebuilt.modules).sort())
|
|
8269
9908
|
hash.update(`${entry}
|
|
8270
|
-
${statOf(
|
|
9909
|
+
${statOf(path14.join(args.prebuilt.modules, entry))}`);
|
|
8271
9910
|
return hash.digest("hex");
|
|
8272
9911
|
}
|
|
8273
|
-
function
|
|
8274
|
-
const
|
|
8275
|
-
|
|
8276
|
-
|
|
8277
|
-
|
|
8278
|
-
|
|
8279
|
-
|
|
8280
|
-
|
|
8281
|
-
|
|
8282
|
-
|
|
8283
|
-
const scratch2 = swiftFrameworkScratch(root);
|
|
8284
|
-
if (previous === key || !existsSync2(scratch2)) return false;
|
|
8285
|
-
rmSync3(scratch2, { recursive: true, force: true });
|
|
8286
|
-
return true;
|
|
9912
|
+
async function pruneFrameworkScratches(keep) {
|
|
9913
|
+
const dir = swiftFrameworksDir();
|
|
9914
|
+
const idle = readdirSync5(dir).filter((name2) => name2 !== keep).map((name2) => ({ name: name2, modified: statSync(path14.join(dir, name2)).mtimeMs })).sort((left, right) => right.modified - left.modified).slice(SWIFT_FRAMEWORK_SCRATCHES_KEPT - 1);
|
|
9915
|
+
for (const { name: name2 } of idle)
|
|
9916
|
+
await withSwiftRootLock(
|
|
9917
|
+
path14.join(dir, name2),
|
|
9918
|
+
async () => rmSync3(path14.join(dir, name2), { recursive: true, force: true }),
|
|
9919
|
+
void 0,
|
|
9920
|
+
false
|
|
9921
|
+
);
|
|
8287
9922
|
}
|
|
8288
9923
|
function retireStaleSwiftLink(root, stamp) {
|
|
8289
|
-
const receipt =
|
|
9924
|
+
const receipt = path14.join(root, SWIFT_LINK_STAMP);
|
|
8290
9925
|
let previous = null;
|
|
8291
9926
|
try {
|
|
8292
9927
|
previous = readFileSync7(receipt, "utf8").trim();
|
|
@@ -8295,7 +9930,7 @@ function retireStaleSwiftLink(root, stamp) {
|
|
|
8295
9930
|
}
|
|
8296
9931
|
writeFileSync3(receipt, `${stamp}
|
|
8297
9932
|
`);
|
|
8298
|
-
const retired =
|
|
9933
|
+
const retired = path14.join(root, ".build");
|
|
8299
9934
|
if (previous === stamp || !existsSync2(retired)) return false;
|
|
8300
9935
|
rmSync3(retired, { recursive: true, force: true });
|
|
8301
9936
|
return true;
|
|
@@ -8304,15 +9939,15 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8304
9939
|
options.signal?.throwIfAborted();
|
|
8305
9940
|
mkdirSync2(options.buildRoot, { recursive: true });
|
|
8306
9941
|
const root = realpathSync(options.buildRoot);
|
|
8307
|
-
const moduleRoot =
|
|
9942
|
+
const moduleRoot = path14.resolve(options.moduleRoot);
|
|
8308
9943
|
const layout = {
|
|
8309
9944
|
root,
|
|
8310
|
-
sources:
|
|
9945
|
+
sources: path14.join(root, "Sources", "App"),
|
|
8311
9946
|
multi: compileTargets(input).length > 0
|
|
8312
9947
|
};
|
|
8313
9948
|
const hash = swiftArtifactHash(input, options.release, moduleRoot);
|
|
8314
9949
|
const frameworkKey = swiftProjectBuildKey(moduleRoot, options.release);
|
|
8315
|
-
const sharedRoot =
|
|
9950
|
+
const sharedRoot = path14.join(swiftCacheDir(), "swift-projects", hash);
|
|
8316
9951
|
const report = (message) => {
|
|
8317
9952
|
console.error(`[swift-project ${hash.slice(0, 16)}] ${message}`);
|
|
8318
9953
|
options.onStage?.(message);
|
|
@@ -8326,8 +9961,8 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8326
9961
|
report("reusing memory artifact");
|
|
8327
9962
|
return retain(root, retained);
|
|
8328
9963
|
}
|
|
8329
|
-
const cached = readCompiledArtifact(
|
|
8330
|
-
const previous = cached ?? readCompiledArtifact(
|
|
9964
|
+
const cached = readCompiledArtifact(path14.join(sharedRoot, "artifact"), hash);
|
|
9965
|
+
const previous = cached ?? readCompiledArtifact(path14.join(root, "artifact"), hash);
|
|
8331
9966
|
if (previous) {
|
|
8332
9967
|
if (cached) renewSharedArtifact(sharedRoot);
|
|
8333
9968
|
else saveSharedArtifact(sharedRoot, previous);
|
|
@@ -8336,8 +9971,8 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8336
9971
|
}
|
|
8337
9972
|
if (process.platform === "darwin" && process.env.TM_SESSION && !admittedMacBuilderSlot() && process.env.CI !== "true" && moduleRoot === sourceSwiftCheckout() && !swiftDistributionAt(moduleRoot)) {
|
|
8338
9973
|
const requestRoot = mkdtempSync2(`${root}.builder-request-`);
|
|
8339
|
-
const output =
|
|
8340
|
-
const request =
|
|
9974
|
+
const output = path14.join(requestRoot, "output");
|
|
9975
|
+
const request = path14.join(requestRoot, "request.json");
|
|
8341
9976
|
writeFileSync3(
|
|
8342
9977
|
request,
|
|
8343
9978
|
JSON.stringify({
|
|
@@ -8351,12 +9986,12 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8351
9986
|
})
|
|
8352
9987
|
);
|
|
8353
9988
|
try {
|
|
8354
|
-
const repo =
|
|
9989
|
+
const repo = path14.resolve(moduleRoot, "../..");
|
|
8355
9990
|
report("requesting builder admission or cached result");
|
|
8356
9991
|
await runCompiler(
|
|
8357
9992
|
"bun",
|
|
8358
9993
|
[
|
|
8359
|
-
|
|
9994
|
+
path14.join(repo, "scripts/build/swift-project.ts"),
|
|
8360
9995
|
"--request",
|
|
8361
9996
|
request,
|
|
8362
9997
|
"--output",
|
|
@@ -8390,27 +10025,34 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8390
10025
|
return withSwiftRootLock(
|
|
8391
10026
|
root,
|
|
8392
10027
|
async (lease) => {
|
|
8393
|
-
const built = readCompiledArtifact(
|
|
10028
|
+
const built = readCompiledArtifact(path14.join(sharedRoot, "artifact"), hash);
|
|
8394
10029
|
if (built) {
|
|
8395
10030
|
report("reusing verified disk artifact");
|
|
8396
10031
|
return retain(root, built);
|
|
8397
10032
|
}
|
|
8398
|
-
const swift =
|
|
10033
|
+
const swift = path14.join(options.toolchainBin, "swift");
|
|
8399
10034
|
if (!existsSync2(swift)) {
|
|
8400
10035
|
throw new Error(
|
|
8401
10036
|
`swift-compile: no swift.org toolchain at ${options.toolchainBin}; install ${options.release} and its matching wasm sdk`
|
|
8402
10037
|
);
|
|
8403
10038
|
}
|
|
8404
|
-
|
|
8405
|
-
|
|
10039
|
+
const frameworkRoot = await withSwiftRootLock(
|
|
10040
|
+
swiftFrameworkScratch(frameworkKey),
|
|
10041
|
+
async () => stageFrameworkSource(moduleRoot, frameworkKey),
|
|
10042
|
+
options.signal
|
|
10043
|
+
);
|
|
8406
10044
|
report("preparing compiler plugins");
|
|
8407
|
-
const macroPlugins = await
|
|
8408
|
-
|
|
8409
|
-
|
|
8410
|
-
|
|
10045
|
+
const macroPlugins = await withSwiftRootLock(
|
|
10046
|
+
swiftFrameworkScratch(frameworkKey),
|
|
10047
|
+
async () => ensureMacroPlugins(
|
|
10048
|
+
frameworkRoot,
|
|
10049
|
+
options.toolchainBin,
|
|
10050
|
+
options.release,
|
|
10051
|
+
options.signal
|
|
10052
|
+
),
|
|
8411
10053
|
options.signal
|
|
8412
10054
|
);
|
|
8413
|
-
const sdk = swiftModuleSdk(
|
|
10055
|
+
const sdk = swiftModuleSdk(frameworkRoot).wasmSdkId;
|
|
8414
10056
|
const icu = swiftIcuAsset(options.toolchainBin, sdk);
|
|
8415
10057
|
const buildOptions = {
|
|
8416
10058
|
env: {
|
|
@@ -8418,11 +10060,12 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8418
10060
|
// shipped host plugins resolve against the selected compiler's runtime.
|
|
8419
10061
|
...process.platform === "linux" ? {
|
|
8420
10062
|
LD_LIBRARY_PATH: [
|
|
8421
|
-
|
|
8422
|
-
|
|
10063
|
+
path14.resolve(options.toolchainBin, "../lib/swift/linux"),
|
|
10064
|
+
path14.resolve(options.toolchainBin, "../lib/swift/host"),
|
|
8423
10065
|
process.env.LD_LIBRARY_PATH
|
|
8424
10066
|
].filter(Boolean).join(":")
|
|
8425
|
-
} : {}
|
|
10067
|
+
} : {},
|
|
10068
|
+
...input.lazyDistribution ? { PEACH_DEFER_WASM_LINK: "1" } : {}
|
|
8426
10069
|
},
|
|
8427
10070
|
maxBuffer: 64 * 1024 * 1024,
|
|
8428
10071
|
timeout: options.timeoutMs,
|
|
@@ -8433,8 +10076,8 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8433
10076
|
if (!swiftDistributionAt(moduleRoot)) {
|
|
8434
10077
|
report("compiling framework products");
|
|
8435
10078
|
prebuilt = await compileFrameworkProducts({
|
|
8436
|
-
moduleRoot,
|
|
8437
|
-
|
|
10079
|
+
moduleRoot: frameworkRoot,
|
|
10080
|
+
frameworkKey,
|
|
8438
10081
|
input,
|
|
8439
10082
|
swift,
|
|
8440
10083
|
sdk,
|
|
@@ -8442,6 +10085,7 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8442
10085
|
plugins: macroPlugins,
|
|
8443
10086
|
buildOptions
|
|
8444
10087
|
});
|
|
10088
|
+
await pruneFrameworkScratches(frameworkKey);
|
|
8445
10089
|
}
|
|
8446
10090
|
if (retireStaleSwiftLink(
|
|
8447
10091
|
root,
|
|
@@ -8451,7 +10095,7 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8451
10095
|
})
|
|
8452
10096
|
))
|
|
8453
10097
|
report("framework revision changed; rebuilding the app link");
|
|
8454
|
-
const preparation = writeSwiftProject(layout, input,
|
|
10098
|
+
const preparation = writeSwiftProject(layout, input, frameworkRoot, prebuilt);
|
|
8455
10099
|
writeSwiftAutolinkLinker(root, options.toolchainBin);
|
|
8456
10100
|
const unprepared = preparation.targetFailures.map(
|
|
8457
10101
|
(failure) => `error: target ${failure}`
|
|
@@ -8465,10 +10109,10 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8465
10109
|
BUILD_JOBS,
|
|
8466
10110
|
"--package-path",
|
|
8467
10111
|
root,
|
|
8468
|
-
...
|
|
10112
|
+
...swiftCompileSdkOptions(frameworkRoot, options.toolchainBin),
|
|
8469
10113
|
"--swift-sdk",
|
|
8470
10114
|
sdk,
|
|
8471
|
-
...input.packageFiles || prebuilt ? ["--toolset",
|
|
10115
|
+
...input.packageFiles || prebuilt ? ["--toolset", path14.join(root, ".peach-target-toolset.json")] : [],
|
|
8472
10116
|
"-c",
|
|
8473
10117
|
"release",
|
|
8474
10118
|
"-Xswiftc",
|
|
@@ -8490,6 +10134,12 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8490
10134
|
`${plugin}#ExpoModulesMacros`
|
|
8491
10135
|
])
|
|
8492
10136
|
];
|
|
10137
|
+
const linked = builtArtifact(layout);
|
|
10138
|
+
if (input.lazyDistribution) {
|
|
10139
|
+
rmSync3(path14.join(root, ".peach-link.rsp"), { force: true });
|
|
10140
|
+
if (existsSync2(linked) && statSync(linked).size <= 8)
|
|
10141
|
+
rmSync3(linked, { force: true });
|
|
10142
|
+
}
|
|
8493
10143
|
report("compiling and linking Swift modules");
|
|
8494
10144
|
try {
|
|
8495
10145
|
for (const producer of preparation.headerProducers) {
|
|
@@ -8510,7 +10160,7 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8510
10160
|
);
|
|
8511
10161
|
} catch (error) {
|
|
8512
10162
|
const output = outputOf(error);
|
|
8513
|
-
const moduleCache =
|
|
10163
|
+
const moduleCache = path14.join(
|
|
8514
10164
|
root,
|
|
8515
10165
|
".build",
|
|
8516
10166
|
WASM_TRIPLE,
|
|
@@ -8546,9 +10196,21 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8546
10196
|
}
|
|
8547
10197
|
}
|
|
8548
10198
|
if (unprepared.length) throw new Error(unprepared.join("\n"));
|
|
10199
|
+
if (!existsSync2(linked)) {
|
|
10200
|
+
const binDir = path14.dirname(linked);
|
|
10201
|
+
const found = existsSync2(binDir) ? readdirSync5(binDir).filter((name2) => name2.endsWith(".wasm")).sort() : [];
|
|
10202
|
+
throw new Error(
|
|
10203
|
+
`swift-compile: the build produced no ${path14.basename(linked)} (found: ${found.join(", ") || "none"})`
|
|
10204
|
+
);
|
|
10205
|
+
}
|
|
10206
|
+
const optimized = `${linked}.optimized`;
|
|
10207
|
+
if (input.lazyDistribution) {
|
|
10208
|
+
pruneSwiftWasmLink(root, options.toolchainBin, frameworkRoot);
|
|
10209
|
+
await optimizeWasm(linked, optimized);
|
|
10210
|
+
}
|
|
8549
10211
|
const artifact = {
|
|
8550
10212
|
hash,
|
|
8551
|
-
bytes: readFileSync7(
|
|
10213
|
+
bytes: readFileSync7(input.lazyDistribution ? optimized : linked),
|
|
8552
10214
|
icu: await icu
|
|
8553
10215
|
};
|
|
8554
10216
|
saveCompiledArtifact(root, artifact);
|
|
@@ -8584,12 +10246,14 @@ export {
|
|
|
8584
10246
|
swiftCMainEntry,
|
|
8585
10247
|
swiftCPredefines,
|
|
8586
10248
|
swiftCodeMask,
|
|
10249
|
+
swiftCompileSdkOptions,
|
|
8587
10250
|
swiftDistributionAt,
|
|
8588
10251
|
swiftIcuAsset,
|
|
8589
10252
|
swiftImportNames,
|
|
8590
10253
|
swiftMacroPlugins,
|
|
8591
10254
|
swiftModuleDigest,
|
|
8592
10255
|
swiftModuleInputFiles,
|
|
10256
|
+
swiftModuleInterface,
|
|
8593
10257
|
swiftModuleSdk,
|
|
8594
10258
|
swiftPeachModules,
|
|
8595
10259
|
swiftProjectBuildKey,
|