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,4 +1,4 @@
|
|
|
1
|
-
/*! peach v0.1.
|
|
1
|
+
/*! peach v0.1.1744 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
|
|
2
2
|
let __sootsim_import_meta_url = '', __sootsim_import_meta_dirname = '', __sootsim_import_meta_filename = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; __sootsim_import_meta_dirname = __dirname; __sootsim_import_meta_filename = __filename; } catch {}
|
|
3
3
|
"use strict";
|
|
4
4
|
var __create = Object.create;
|
|
@@ -53,12 +53,14 @@ __export(swift_compile_exports, {
|
|
|
53
53
|
swiftCMainEntry: () => swiftCMainEntry,
|
|
54
54
|
swiftCPredefines: () => swiftCPredefines,
|
|
55
55
|
swiftCodeMask: () => swiftCodeMask,
|
|
56
|
+
swiftCompileSdkOptions: () => swiftCompileSdkOptions,
|
|
56
57
|
swiftDistributionAt: () => swiftDistributionAt,
|
|
57
58
|
swiftIcuAsset: () => swiftIcuAsset,
|
|
58
59
|
swiftImportNames: () => swiftImportNames,
|
|
59
60
|
swiftMacroPlugins: () => swiftMacroPlugins,
|
|
60
61
|
swiftModuleDigest: () => swiftModuleDigest,
|
|
61
62
|
swiftModuleInputFiles: () => swiftModuleInputFiles,
|
|
63
|
+
swiftModuleInterface: () => swiftModuleInterface,
|
|
62
64
|
swiftModuleSdk: () => swiftModuleSdk,
|
|
63
65
|
swiftPeachModules: () => swiftPeachModules,
|
|
64
66
|
swiftProjectBuildKey: () => swiftProjectBuildKey,
|
|
@@ -75,11 +77,11 @@ __export(swift_compile_exports, {
|
|
|
75
77
|
writeSwiftProject: () => writeSwiftProject
|
|
76
78
|
});
|
|
77
79
|
module.exports = __toCommonJS(swift_compile_exports);
|
|
78
|
-
var
|
|
79
|
-
var
|
|
80
|
-
var
|
|
81
|
-
var
|
|
82
|
-
var
|
|
80
|
+
var import_node_child_process9 = require("node:child_process");
|
|
81
|
+
var import_node_crypto7 = require("node:crypto");
|
|
82
|
+
var import_node_fs10 = require("node:fs");
|
|
83
|
+
var import_node_os5 = __toESM(require("node:os"), 1);
|
|
84
|
+
var import_node_path14 = __toESM(require("node:path"), 1);
|
|
83
85
|
|
|
84
86
|
// src/admitted-mac-build.ts
|
|
85
87
|
var import_node_child_process = require("node:child_process");
|
|
@@ -2868,9 +2870,9 @@ var EXCERPT = /^(\s*)(\d+)( \| )(.*)$/;
|
|
|
2868
2870
|
var MARKER = /^(\s*)( \| )(.*)$/;
|
|
2869
2871
|
function designTimeDiagnostic(output, files) {
|
|
2870
2872
|
const rewritten = /* @__PURE__ */ new Map();
|
|
2871
|
-
const linesOf = (
|
|
2873
|
+
const linesOf = (path14) => {
|
|
2872
2874
|
const file = Object.keys(files).find(
|
|
2873
|
-
(name2) => name2.endsWith(".swift") && (
|
|
2875
|
+
(name2) => name2.endsWith(".swift") && (path14 === name2 || path14.endsWith(`/${name2}`))
|
|
2874
2876
|
);
|
|
2875
2877
|
if (file === void 0) return null;
|
|
2876
2878
|
let lines = rewritten.get(file);
|
|
@@ -3006,6 +3008,23 @@ var compilerArchives = {
|
|
|
3006
3008
|
}
|
|
3007
3009
|
}
|
|
3008
3010
|
},
|
|
3011
|
+
"swift-6.4.0-RELEASE-custom-f7c03c3f59ec5d83": {
|
|
3012
|
+
identity: "f7c03c3f59ec5d83",
|
|
3013
|
+
hosts: {
|
|
3014
|
+
"darwin-arm64": {
|
|
3015
|
+
checksum: "8946a2d4716d3b0784cef7a85a35f66537bd319c4c5a48c63457d607260df5c5",
|
|
3016
|
+
manifest: "2a7754e6e365bf71ae6b6aefbbd810123795c73d43fb902a8a972d009d72790f"
|
|
3017
|
+
},
|
|
3018
|
+
"linux-x64": {
|
|
3019
|
+
checksum: "5ffa3b54d54583c1d6a38b708693072db4d088ba4bf5966b17014c068b2db641",
|
|
3020
|
+
manifest: "1b23ea52c5570de4697481a54bd0b0a0bcd6b54feccb7b0bb940d3643dec82cb"
|
|
3021
|
+
},
|
|
3022
|
+
"linux-arm64": {
|
|
3023
|
+
checksum: "29b0b97b7b0db4475dbe55f7011e57f493fed9f3482a6705becebd8b68c90bab",
|
|
3024
|
+
manifest: "3fdab1132715f5899de1bb1d7ddcd52cf540295ab86586c72f49502f37a403a1"
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
},
|
|
3009
3028
|
[SWIFT_HOST_COMPILER_RELEASE]: {
|
|
3010
3029
|
identity: SWIFT_HOST_COMPILER_ID,
|
|
3011
3030
|
hosts: {
|
|
@@ -3024,6 +3043,22 @@ var compilerArchives = {
|
|
|
3024
3043
|
}
|
|
3025
3044
|
}
|
|
3026
3045
|
};
|
|
3046
|
+
var SWIFT_PRIVATE_DISTRIBUTION_ENV = "PEACH_SWIFT_PRIVATE_DISTRIBUTION";
|
|
3047
|
+
function privateSwiftDistributionRoot() {
|
|
3048
|
+
const root = process.env[SWIFT_PRIVATE_DISTRIBUTION_ENV]?.trim();
|
|
3049
|
+
return root ? import_node_path4.default.resolve(root) : null;
|
|
3050
|
+
}
|
|
3051
|
+
function privateSwiftRelease() {
|
|
3052
|
+
const root = privateSwiftDistributionRoot();
|
|
3053
|
+
if (!root) return null;
|
|
3054
|
+
const manifest = JSON.parse(
|
|
3055
|
+
import_node_fs3.default.readFileSync(import_node_path4.default.join(root, "distribution.json"), "utf8")
|
|
3056
|
+
);
|
|
3057
|
+
const release = manifest && typeof manifest === "object" && Reflect.get(manifest, "release");
|
|
3058
|
+
if (typeof release !== "string")
|
|
3059
|
+
throw new Error(`${root} holds no Swift distribution release`);
|
|
3060
|
+
return release;
|
|
3061
|
+
}
|
|
3027
3062
|
function swiftHostCompilerArchive(release, host2 = `${process.platform}-${process.arch}`) {
|
|
3028
3063
|
const compiler = compilerArchives[release];
|
|
3029
3064
|
if (!compiler) throw new Error(`unqualified host compiler ${release}`);
|
|
@@ -3071,6 +3106,14 @@ for arg in "$@"; do
|
|
|
3071
3106
|
rsp=\${arg#@}
|
|
3072
3107
|
awk 'BEGIN { RS = " "; ORS = " " } /^"-l/ { if (seen[$0]++) next } { print }' "$rsp" > "$rsp.dedup"
|
|
3073
3108
|
mv "$rsp.dedup" "$rsp"
|
|
3109
|
+
if [ "\${PEACH_DEFER_WASM_LINK:-}" = "1" ] && grep -q '"--start-lib"' "$rsp"; then
|
|
3110
|
+
cp "$rsp" ${JSON.stringify(import_node_path4.default.join(directory, ".peach-link.rsp"))}
|
|
3111
|
+
out=$(awk 'BEGIN { RS = " " } prev == "\\"'-o'\\"" { gsub(/^"|"[[:space:]]*$/, ""); print; exit } { prev = $0 }' "$rsp")
|
|
3112
|
+
if [ -n "$out" ]; then
|
|
3113
|
+
printf '\\000asm\\001\\000\\000\\000' > "$out"
|
|
3114
|
+
exit 0
|
|
3115
|
+
fi
|
|
3116
|
+
fi
|
|
3074
3117
|
;;
|
|
3075
3118
|
esac
|
|
3076
3119
|
done
|
|
@@ -3088,15 +3131,20 @@ function peachHome() {
|
|
|
3088
3131
|
return override ? import_node_path4.default.resolve(override) : import_node_path4.default.join(import_node_os3.default.homedir(), ".peach");
|
|
3089
3132
|
}
|
|
3090
3133
|
var scratch;
|
|
3134
|
+
var linuxLibraryPath;
|
|
3091
3135
|
function swiftEnvironment(base = process.env) {
|
|
3092
|
-
if (!scratch) return base;
|
|
3093
3136
|
return {
|
|
3094
3137
|
...base,
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3138
|
+
...linuxLibraryPath ? {
|
|
3139
|
+
LD_LIBRARY_PATH: [linuxLibraryPath, base.LD_LIBRARY_PATH].filter(Boolean).join(":")
|
|
3140
|
+
} : {},
|
|
3141
|
+
...scratch ? {
|
|
3142
|
+
TMPDIR: scratch.directory,
|
|
3143
|
+
XDG_CONFIG_HOME: import_node_path4.default.join(scratch.home, ".config"),
|
|
3144
|
+
XDG_CACHE_HOME: import_node_path4.default.join(scratch.home, ".cache"),
|
|
3145
|
+
XDG_DATA_HOME: import_node_path4.default.join(scratch.home, ".local", "share"),
|
|
3146
|
+
...process.platform === "linux" ? { HOME: scratch.home } : {}
|
|
3147
|
+
} : {}
|
|
3100
3148
|
};
|
|
3101
3149
|
}
|
|
3102
3150
|
function swiftSourceSdk(root) {
|
|
@@ -3231,8 +3279,11 @@ function swiftFileChecksum(file) {
|
|
|
3231
3279
|
return hash.digest("hex");
|
|
3232
3280
|
}
|
|
3233
3281
|
function verifySwiftHostCompiler(release, root) {
|
|
3234
|
-
const pin = swiftHostCompilerArchive(release);
|
|
3235
3282
|
const file = import_node_path4.default.join(root, "compiler.json");
|
|
3283
|
+
const pin = release === privateSwiftRelease() ? {
|
|
3284
|
+
identity: release.replace(/^.*-custom-/, ""),
|
|
3285
|
+
manifest: swiftFileChecksum(file)
|
|
3286
|
+
} : swiftHostCompilerArchive(release);
|
|
3236
3287
|
if (swiftFileChecksum(file) !== pin.manifest)
|
|
3237
3288
|
throw new Error(`Swift compiler manifest mismatch at ${root}`);
|
|
3238
3289
|
const manifest = JSON.parse(import_node_fs3.default.readFileSync(file, "utf8"));
|
|
@@ -3283,6 +3334,8 @@ function swiftInstallSteps(release, wasmSdk) {
|
|
|
3283
3334
|
].join("\n");
|
|
3284
3335
|
}
|
|
3285
3336
|
function swiftCompilerInstall(release) {
|
|
3337
|
+
if (release === privateSwiftRelease())
|
|
3338
|
+
return { note: " (private: its builder installs it)", commands: [] };
|
|
3286
3339
|
if (release.includes("-custom-")) {
|
|
3287
3340
|
const archive = swiftHostCompilerArchive(release);
|
|
3288
3341
|
const directory = import_node_path4.default.resolve(swiftToolchainBin(release), "../..");
|
|
@@ -3433,12 +3486,7 @@ function icuSegment(object) {
|
|
|
3433
3486
|
// src/swift-link-roots.ts
|
|
3434
3487
|
var import_node_fs5 = __toESM(require("node:fs"), 1);
|
|
3435
3488
|
var import_node_path6 = __toESM(require("node:path"), 1);
|
|
3436
|
-
var OBJC_SEGMENTS = [
|
|
3437
|
-
"__objc_classes",
|
|
3438
|
-
"__objc_protocols",
|
|
3439
|
-
"__objc_cats",
|
|
3440
|
-
"__objc_class_aliases"
|
|
3441
|
-
];
|
|
3489
|
+
var OBJC_SEGMENTS = ["__objc_cats", "__objc_class_aliases"];
|
|
3442
3490
|
var leb = (bytes, at) => {
|
|
3443
3491
|
let value = 0;
|
|
3444
3492
|
let scale = 1;
|
|
@@ -3453,6 +3501,7 @@ function objcSegmentSizes(bytes) {
|
|
|
3453
3501
|
const at = { offset: 8 };
|
|
3454
3502
|
const names = [];
|
|
3455
3503
|
const sizes = [];
|
|
3504
|
+
let hasExportedSymbol = false;
|
|
3456
3505
|
while (at.offset < bytes.length) {
|
|
3457
3506
|
const id = bytes[at.offset++];
|
|
3458
3507
|
const size = leb(bytes, at);
|
|
@@ -3477,6 +3526,31 @@ function objcSegmentSizes(bytes) {
|
|
|
3477
3526
|
leb(bytes, at);
|
|
3478
3527
|
leb(bytes, at);
|
|
3479
3528
|
}
|
|
3529
|
+
} else if (kind === 8) {
|
|
3530
|
+
for (let count = leb(bytes, at); count > 0; count--) {
|
|
3531
|
+
const symKind = bytes[at.offset++];
|
|
3532
|
+
const flags = leb(bytes, at);
|
|
3533
|
+
const isUndef = (flags & 16) !== 0;
|
|
3534
|
+
const isExplicitName = (flags & 64) !== 0;
|
|
3535
|
+
if (!isUndef && (flags & 32) !== 0) hasExportedSymbol = true;
|
|
3536
|
+
if (symKind === 0 || symKind === 2 || symKind === 4 || symKind === 5) {
|
|
3537
|
+
leb(bytes, at);
|
|
3538
|
+
if (!isUndef || isExplicitName) {
|
|
3539
|
+
const sLen = leb(bytes, at);
|
|
3540
|
+
at.offset += sLen;
|
|
3541
|
+
}
|
|
3542
|
+
} else if (symKind === 1) {
|
|
3543
|
+
const sLen = leb(bytes, at);
|
|
3544
|
+
at.offset += sLen;
|
|
3545
|
+
if (!isUndef) {
|
|
3546
|
+
leb(bytes, at);
|
|
3547
|
+
leb(bytes, at);
|
|
3548
|
+
leb(bytes, at);
|
|
3549
|
+
}
|
|
3550
|
+
} else if (symKind === 3) {
|
|
3551
|
+
leb(bytes, at);
|
|
3552
|
+
}
|
|
3553
|
+
}
|
|
3480
3554
|
}
|
|
3481
3555
|
at.offset = next;
|
|
3482
3556
|
}
|
|
@@ -3502,6 +3576,7 @@ function objcSegmentSizes(bytes) {
|
|
|
3502
3576
|
if (OBJC_SEGMENTS.includes(name2))
|
|
3503
3577
|
result.set(name2, (result.get(name2) ?? 0) + (sizes[index] ?? 0));
|
|
3504
3578
|
});
|
|
3579
|
+
result.set("__wasm_exported", hasExportedSymbol ? 1 : 0);
|
|
3505
3580
|
return result;
|
|
3506
3581
|
}
|
|
3507
3582
|
var rootsByDistribution = /* @__PURE__ */ new Map();
|
|
@@ -3517,7 +3592,7 @@ function swiftObjcRootObjects(id, root, objects) {
|
|
|
3517
3592
|
empty.set(name2, Math.min(empty.get(name2) ?? size, size));
|
|
3518
3593
|
const roots = new Set(
|
|
3519
3594
|
measured.filter(
|
|
3520
|
-
([, sizes]) => [...sizes].some(([name2, size]) => size > (empty.get(name2) ?? 0))
|
|
3595
|
+
([object, sizes]) => object !== "lib/Foundation-NSStringFormatting.o" && object !== "lib/FoundationNetworking-Session.o" && [...sizes].some(([name2, size]) => size > (empty.get(name2) ?? 0))
|
|
3521
3596
|
).map(([object]) => object)
|
|
3522
3597
|
);
|
|
3523
3598
|
rootsByDistribution.set(id, roots);
|
|
@@ -4136,6 +4211,9 @@ function objcSdkIntakeFlags(headers, toolchainBin, minimum) {
|
|
|
4136
4211
|
// the installed icu archive exports its swift_-prefixed names, which the
|
|
4137
4212
|
// unicode headers rename to only off darwin.
|
|
4138
4213
|
"-DU_DISABLE_RENAMING=0",
|
|
4214
|
+
// clang enables blocks in every language for darwin targets, and the sdk
|
|
4215
|
+
// headers declare block types unguarded.
|
|
4216
|
+
"-fblocks",
|
|
4139
4217
|
...WASI_EMULATION_FLAGS,
|
|
4140
4218
|
"-iframework",
|
|
4141
4219
|
import_node_path9.default.join(headers, "System/Library/Frameworks"),
|
|
@@ -4345,16 +4423,1448 @@ async function withSwiftRootLock(root, work, signal, wait = true) {
|
|
|
4345
4423
|
}
|
|
4346
4424
|
|
|
4347
4425
|
// src/swift-shared-sdk.ts
|
|
4348
|
-
var
|
|
4426
|
+
var import_node_child_process7 = require("node:child_process");
|
|
4427
|
+
var import_node_crypto5 = require("node:crypto");
|
|
4428
|
+
var import_node_fs7 = __toESM(require("node:fs"), 1);
|
|
4349
4429
|
var import_node_path11 = __toESM(require("node:path"), 1);
|
|
4350
4430
|
function swiftSharedSdkRoot(moduleRoot, distribution) {
|
|
4351
4431
|
return import_node_path11.default.resolve(moduleRoot, distribution ? "sdk/ios" : "../peachsim/sdk/ios");
|
|
4352
4432
|
}
|
|
4433
|
+
var sdkViews = /* @__PURE__ */ new Map();
|
|
4434
|
+
function swiftSharedSdkViewOptions(moduleRoot, distribution, toolchainBin, sdk) {
|
|
4435
|
+
const frameworks = import_node_path11.default.join(
|
|
4436
|
+
swiftSharedSdkRoot(moduleRoot, distribution),
|
|
4437
|
+
"System/Library/Frameworks"
|
|
4438
|
+
);
|
|
4439
|
+
const key = JSON.stringify([toolchainBin, sdk, frameworks, swiftSdkOptions()]);
|
|
4440
|
+
const cached = sdkViews.get(key);
|
|
4441
|
+
if (cached) return cached;
|
|
4442
|
+
const configuration = (0, import_node_child_process7.execFileSync)(
|
|
4443
|
+
import_node_path11.default.join(toolchainBin, "swift"),
|
|
4444
|
+
[
|
|
4445
|
+
"sdk",
|
|
4446
|
+
"configure",
|
|
4447
|
+
...swiftSdkOptions(),
|
|
4448
|
+
"--show-configuration",
|
|
4449
|
+
sdk,
|
|
4450
|
+
"wasm32-unknown-wasip1"
|
|
4451
|
+
],
|
|
4452
|
+
{ encoding: "utf8", env: swiftEnvironment(), stdio: ["ignore", "pipe", "pipe"] }
|
|
4453
|
+
);
|
|
4454
|
+
const sysroot = /^sdkRootPath: (.+)$/m.exec(configuration)?.[1]?.trim();
|
|
4455
|
+
if (!sysroot || !import_node_path11.default.isAbsolute(sysroot))
|
|
4456
|
+
throw new Error(`swift sdk ${sdk} reports no absolute sdkRootPath`);
|
|
4457
|
+
let bundle = sysroot;
|
|
4458
|
+
while (!bundle.endsWith(".artifactbundle")) {
|
|
4459
|
+
if (import_node_path11.default.dirname(bundle) === bundle)
|
|
4460
|
+
throw new Error(`swift sdk ${sdk} is outside an artifact bundle`);
|
|
4461
|
+
bundle = import_node_path11.default.dirname(bundle);
|
|
4462
|
+
}
|
|
4463
|
+
const view = import_node_path11.default.join(
|
|
4464
|
+
swiftCacheDir(),
|
|
4465
|
+
"swift-sdk-views",
|
|
4466
|
+
(0, import_node_crypto5.createHash)("sha256").update(key).digest("hex").slice(0, 16)
|
|
4467
|
+
);
|
|
4468
|
+
if (!import_node_fs7.default.existsSync(view)) {
|
|
4469
|
+
import_node_fs7.default.mkdirSync(import_node_path11.default.dirname(view), { recursive: true });
|
|
4470
|
+
const staging = import_node_fs7.default.mkdtempSync(`${view}-`);
|
|
4471
|
+
const segments = [
|
|
4472
|
+
import_node_path11.default.basename(bundle),
|
|
4473
|
+
...import_node_path11.default.relative(bundle, import_node_path11.default.join(sysroot, "darwin/System/Library")).split(import_node_path11.default.sep),
|
|
4474
|
+
"Frameworks"
|
|
4475
|
+
];
|
|
4476
|
+
let real = import_node_path11.default.dirname(bundle);
|
|
4477
|
+
let mirror = staging;
|
|
4478
|
+
for (const segment of segments) {
|
|
4479
|
+
for (const entry of (0, import_node_fs7.readdirSync)(real))
|
|
4480
|
+
if (entry !== segment)
|
|
4481
|
+
import_node_fs7.default.symlinkSync(import_node_path11.default.join(real, entry), import_node_path11.default.join(mirror, entry));
|
|
4482
|
+
real = import_node_path11.default.join(real, segment);
|
|
4483
|
+
mirror = import_node_path11.default.join(mirror, segment);
|
|
4484
|
+
if (segment !== "Frameworks") import_node_fs7.default.mkdirSync(mirror);
|
|
4485
|
+
}
|
|
4486
|
+
import_node_fs7.default.symlinkSync(frameworks, mirror);
|
|
4487
|
+
try {
|
|
4488
|
+
import_node_fs7.default.renameSync(staging, view);
|
|
4489
|
+
} catch (error) {
|
|
4490
|
+
import_node_fs7.default.rmSync(staging, { recursive: true, force: true });
|
|
4491
|
+
if (!import_node_fs7.default.existsSync(view)) throw error;
|
|
4492
|
+
}
|
|
4493
|
+
}
|
|
4494
|
+
const options = ["--swift-sdks-path", view];
|
|
4495
|
+
sdkViews.set(key, options);
|
|
4496
|
+
return options;
|
|
4497
|
+
}
|
|
4353
4498
|
function swiftSharedSdkInputFiles(moduleRoot) {
|
|
4354
4499
|
const root = swiftSharedSdkRoot(moduleRoot, false);
|
|
4355
4500
|
return (0, import_node_fs7.readdirSync)(root, { recursive: true, withFileTypes: true }).filter((entry) => entry.isFile()).map((entry) => import_node_path11.default.relative(moduleRoot, import_node_path11.default.join(entry.parentPath, entry.name))).sort();
|
|
4356
4501
|
}
|
|
4357
4502
|
|
|
4503
|
+
// src/swift-wasm-prune.ts
|
|
4504
|
+
var import_node_child_process8 = require("node:child_process");
|
|
4505
|
+
var import_node_crypto6 = require("node:crypto");
|
|
4506
|
+
var import_node_fs8 = __toESM(require("node:fs"), 1);
|
|
4507
|
+
var import_node_os4 = __toESM(require("node:os"), 1);
|
|
4508
|
+
var import_node_path12 = __toESM(require("node:path"), 1);
|
|
4509
|
+
function readULEB(b, o) {
|
|
4510
|
+
let res = 0;
|
|
4511
|
+
let shift = 0;
|
|
4512
|
+
let p = o;
|
|
4513
|
+
while (true) {
|
|
4514
|
+
const byte = b[p++];
|
|
4515
|
+
res |= (byte & 127) << shift;
|
|
4516
|
+
if ((byte & 128) === 0) break;
|
|
4517
|
+
shift += 7;
|
|
4518
|
+
}
|
|
4519
|
+
return [res, p];
|
|
4520
|
+
}
|
|
4521
|
+
function readSLEB(b, o) {
|
|
4522
|
+
let res = 0;
|
|
4523
|
+
let shift = 0;
|
|
4524
|
+
let p = o;
|
|
4525
|
+
let byte = 0;
|
|
4526
|
+
do {
|
|
4527
|
+
byte = b[p++];
|
|
4528
|
+
res |= (byte & 127) << shift;
|
|
4529
|
+
shift += 7;
|
|
4530
|
+
} while (byte & 128);
|
|
4531
|
+
if (shift < 32 && byte & 64) res |= ~0 << shift;
|
|
4532
|
+
return [res, p];
|
|
4533
|
+
}
|
|
4534
|
+
function encodeULEB(val) {
|
|
4535
|
+
const out = [];
|
|
4536
|
+
do {
|
|
4537
|
+
let byte = val & 127;
|
|
4538
|
+
val >>>= 7;
|
|
4539
|
+
if (val !== 0) byte |= 128;
|
|
4540
|
+
out.push(byte);
|
|
4541
|
+
} while (val !== 0);
|
|
4542
|
+
return out;
|
|
4543
|
+
}
|
|
4544
|
+
var HAS_ADDEND = /* @__PURE__ */ new Set([3, 4, 5, 8, 9, 11, 13, 14, 15, 16, 21, 22, 23, 24, 25]);
|
|
4545
|
+
var ROOT_SEG_PREFIXES = [
|
|
4546
|
+
".init_array",
|
|
4547
|
+
"__objc_init_func",
|
|
4548
|
+
"__objc_classes",
|
|
4549
|
+
"__objc_cats",
|
|
4550
|
+
"__objc_class_aliases",
|
|
4551
|
+
"objc_clsrolist",
|
|
4552
|
+
"swift5_protocols",
|
|
4553
|
+
"swift5_protocol_conformances",
|
|
4554
|
+
"swift5_type_metadata",
|
|
4555
|
+
"swift5_type_metadata_2",
|
|
4556
|
+
"swift5_replace",
|
|
4557
|
+
"swift5_replac2",
|
|
4558
|
+
"swift5_accessible_functions",
|
|
4559
|
+
"swift5_entry"
|
|
4560
|
+
];
|
|
4561
|
+
function isRootSegName(name2) {
|
|
4562
|
+
for (const pref of ROOT_SEG_PREFIXES) {
|
|
4563
|
+
if (name2 === pref || name2.startsWith(`${pref}.`)) return true;
|
|
4564
|
+
}
|
|
4565
|
+
return false;
|
|
4566
|
+
}
|
|
4567
|
+
var PARTITIONED_SEGS = /* @__PURE__ */ new Set([
|
|
4568
|
+
".rodata",
|
|
4569
|
+
".data",
|
|
4570
|
+
".data.rel.ro",
|
|
4571
|
+
"swift5_capture",
|
|
4572
|
+
"swift5_fieldmd",
|
|
4573
|
+
"swift5_assocty",
|
|
4574
|
+
"swift5_typeref",
|
|
4575
|
+
"swift5_builtin",
|
|
4576
|
+
"swift5_mpenum"
|
|
4577
|
+
]);
|
|
4578
|
+
var PRUNED_SDK_ARCHIVES = /* @__PURE__ */ new Set([
|
|
4579
|
+
"libFoundation",
|
|
4580
|
+
"lib_FoundationCollections",
|
|
4581
|
+
"libswift_StringProcessing",
|
|
4582
|
+
"libswift_RegexParser",
|
|
4583
|
+
"libswiftObservation",
|
|
4584
|
+
"libswiftSynchronization",
|
|
4585
|
+
"libswiftCxx",
|
|
4586
|
+
"libswiftCxxStdlib",
|
|
4587
|
+
"libswiftWASILibc",
|
|
4588
|
+
"libswift_Builtin_float",
|
|
4589
|
+
"libObjectiveC"
|
|
4590
|
+
]);
|
|
4591
|
+
var OMIT_SDK_LIB_FLAGS = /* @__PURE__ */ new Set([
|
|
4592
|
+
...[...PRUNED_SDK_ARCHIVES].map((a) => `-l${a.slice(3)}`),
|
|
4593
|
+
"-lswiftCore",
|
|
4594
|
+
"-lswift_Concurrency"
|
|
4595
|
+
]);
|
|
4596
|
+
var NEUTRALIZED_SWIFTRT_SECTIONS = /* @__PURE__ */ new Set([
|
|
4597
|
+
"swift5_tests",
|
|
4598
|
+
"swift5_runtime_attributes",
|
|
4599
|
+
"swift5_mpenum",
|
|
4600
|
+
"swift5_capture",
|
|
4601
|
+
"swift5_builtin",
|
|
4602
|
+
"swift5_assocty",
|
|
4603
|
+
"swift5_fieldmd",
|
|
4604
|
+
"swift5_reflstr",
|
|
4605
|
+
"swift5_typeref"
|
|
4606
|
+
]);
|
|
4607
|
+
var parsedObjectCache = /* @__PURE__ */ new Map();
|
|
4608
|
+
function readArMembers(buf) {
|
|
4609
|
+
if (buf.length < 8) return [];
|
|
4610
|
+
const magic = Buffer.from(buf.subarray(0, 8)).toString("ascii");
|
|
4611
|
+
if (magic !== "!<arch>\n") return [];
|
|
4612
|
+
const out = [];
|
|
4613
|
+
let gnuNames = null;
|
|
4614
|
+
let pos = 8;
|
|
4615
|
+
while (pos + 60 <= buf.length) {
|
|
4616
|
+
const rawName = Buffer.from(buf.subarray(pos, pos + 16)).toString("ascii");
|
|
4617
|
+
const sizeStr = Buffer.from(buf.subarray(pos + 48, pos + 58)).toString("ascii").trim();
|
|
4618
|
+
const size = Number.parseInt(sizeStr, 10);
|
|
4619
|
+
pos += 60;
|
|
4620
|
+
if (Number.isNaN(size) || pos + size > buf.length) break;
|
|
4621
|
+
let bodyStart = pos;
|
|
4622
|
+
const bodyEnd = pos + size;
|
|
4623
|
+
let name2 = rawName.trim();
|
|
4624
|
+
if (rawName.startsWith("#1/")) {
|
|
4625
|
+
const nLen = Number.parseInt(rawName.slice(3).trim(), 10);
|
|
4626
|
+
name2 = Buffer.from(buf.subarray(bodyStart, bodyStart + nLen)).toString("utf8").replace(/\0+$/, "");
|
|
4627
|
+
bodyStart += nLen;
|
|
4628
|
+
} else if (rawName.startsWith("//")) {
|
|
4629
|
+
gnuNames = buf.subarray(bodyStart, bodyEnd);
|
|
4630
|
+
pos = bodyEnd + (size & 1);
|
|
4631
|
+
continue;
|
|
4632
|
+
} else if (rawName.startsWith("/") && gnuNames) {
|
|
4633
|
+
const offStr = rawName.slice(1).trim();
|
|
4634
|
+
if (offStr.length > 0 && /^\d+$/.test(offStr)) {
|
|
4635
|
+
const off = Number.parseInt(offStr, 10);
|
|
4636
|
+
let end = off;
|
|
4637
|
+
while (end < gnuNames.length && gnuNames[end] !== 10 && gnuNames[end] !== 47) {
|
|
4638
|
+
end++;
|
|
4639
|
+
}
|
|
4640
|
+
name2 = Buffer.from(gnuNames.subarray(off, end)).toString("utf8");
|
|
4641
|
+
} else {
|
|
4642
|
+
pos = bodyEnd + (size & 1);
|
|
4643
|
+
continue;
|
|
4644
|
+
}
|
|
4645
|
+
} else if (name2.endsWith("/")) {
|
|
4646
|
+
name2 = name2.slice(0, -1);
|
|
4647
|
+
}
|
|
4648
|
+
const bytes = buf.subarray(bodyStart, bodyEnd);
|
|
4649
|
+
if (bytes.length >= 8 && bytes[0] === 0 && bytes[1] === 97 && bytes[2] === 115 && bytes[3] === 109) {
|
|
4650
|
+
out.push({ name: name2, bytes });
|
|
4651
|
+
}
|
|
4652
|
+
pos = bodyEnd + (size & 1);
|
|
4653
|
+
}
|
|
4654
|
+
return out;
|
|
4655
|
+
}
|
|
4656
|
+
function patchSwiftrtObject(src) {
|
|
4657
|
+
const buf = new Uint8Array(src);
|
|
4658
|
+
const neutralizedSyms = /* @__PURE__ */ new Set();
|
|
4659
|
+
let fallbackSymIdx = 2;
|
|
4660
|
+
let pos = 8;
|
|
4661
|
+
while (pos < buf.length) {
|
|
4662
|
+
const id = buf[pos++];
|
|
4663
|
+
const [sz, p] = readULEB(buf, pos);
|
|
4664
|
+
const end = p + sz;
|
|
4665
|
+
if (id === 0) {
|
|
4666
|
+
const [nLen, np] = readULEB(buf, p);
|
|
4667
|
+
const name2 = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
|
|
4668
|
+
const cp = np + nLen;
|
|
4669
|
+
if (name2 === "linking") {
|
|
4670
|
+
let [, lp] = readULEB(buf, cp);
|
|
4671
|
+
while (lp < end) {
|
|
4672
|
+
const subId = buf[lp++];
|
|
4673
|
+
const [subLen, sp] = readULEB(buf, lp);
|
|
4674
|
+
const subEnd = sp + subLen;
|
|
4675
|
+
if (subId === 8) {
|
|
4676
|
+
let [cnt, cur] = readULEB(buf, sp);
|
|
4677
|
+
for (let i = 0; i < cnt; i++) {
|
|
4678
|
+
const kind = buf[cur++];
|
|
4679
|
+
const [fl, c2] = readULEB(buf, cur);
|
|
4680
|
+
cur = c2;
|
|
4681
|
+
const isUndef = (fl & 16) !== 0;
|
|
4682
|
+
const isExplicitName = (fl & 64) !== 0;
|
|
4683
|
+
if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
|
|
4684
|
+
const [, c3] = readULEB(buf, cur);
|
|
4685
|
+
cur = c3;
|
|
4686
|
+
if (!isUndef || isExplicitName) {
|
|
4687
|
+
const [sLen, c4] = readULEB(buf, cur);
|
|
4688
|
+
cur = c4 + sLen;
|
|
4689
|
+
}
|
|
4690
|
+
} else if (kind === 1) {
|
|
4691
|
+
const [sLen, c3] = readULEB(buf, cur);
|
|
4692
|
+
const sName = Buffer.from(buf.subarray(c3, c3 + sLen)).toString("utf8");
|
|
4693
|
+
if (sName === "_ZN12_GLOBAL__N_18sectionsE") fallbackSymIdx = i;
|
|
4694
|
+
for (const prefix of ["__start_", "__stop_"]) {
|
|
4695
|
+
if (sName.startsWith(prefix) && NEUTRALIZED_SWIFTRT_SECTIONS.has(sName.slice(prefix.length))) {
|
|
4696
|
+
buf[c3] = 120;
|
|
4697
|
+
neutralizedSyms.add(i);
|
|
4698
|
+
}
|
|
4699
|
+
}
|
|
4700
|
+
cur = c3 + sLen;
|
|
4701
|
+
if (!isUndef) {
|
|
4702
|
+
const [, c4] = readULEB(buf, cur);
|
|
4703
|
+
const [, c5] = readULEB(buf, c4);
|
|
4704
|
+
const [, c6] = readULEB(buf, c5);
|
|
4705
|
+
cur = c6;
|
|
4706
|
+
}
|
|
4707
|
+
} else if (kind === 3) {
|
|
4708
|
+
const [, c3] = readULEB(buf, cur);
|
|
4709
|
+
cur = c3;
|
|
4710
|
+
}
|
|
4711
|
+
}
|
|
4712
|
+
}
|
|
4713
|
+
lp = subEnd;
|
|
4714
|
+
}
|
|
4715
|
+
}
|
|
4716
|
+
}
|
|
4717
|
+
pos = end;
|
|
4718
|
+
}
|
|
4719
|
+
pos = 8;
|
|
4720
|
+
while (pos < buf.length) {
|
|
4721
|
+
const id = buf[pos++];
|
|
4722
|
+
const [sz, p] = readULEB(buf, pos);
|
|
4723
|
+
const end = p + sz;
|
|
4724
|
+
if (id === 0) {
|
|
4725
|
+
const [nLen, np] = readULEB(buf, p);
|
|
4726
|
+
const name2 = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
|
|
4727
|
+
const cp = np + nLen;
|
|
4728
|
+
if (name2 === "reloc.CODE") {
|
|
4729
|
+
const [, r1] = readULEB(buf, cp);
|
|
4730
|
+
let [cnt, cur] = readULEB(buf, r1);
|
|
4731
|
+
for (let i = 0; i < cnt; i++) {
|
|
4732
|
+
const rType = buf[cur++];
|
|
4733
|
+
const [, c2] = readULEB(buf, cur);
|
|
4734
|
+
const [rs, c3] = readULEB(buf, c2);
|
|
4735
|
+
if (neutralizedSyms.has(rs) && c3 - c2 === 1) {
|
|
4736
|
+
buf[c2] = fallbackSymIdx;
|
|
4737
|
+
}
|
|
4738
|
+
cur = c3;
|
|
4739
|
+
if (HAS_ADDEND.has(rType)) {
|
|
4740
|
+
const [, c4] = readSLEB(buf, cur);
|
|
4741
|
+
cur = c4;
|
|
4742
|
+
}
|
|
4743
|
+
}
|
|
4744
|
+
}
|
|
4745
|
+
}
|
|
4746
|
+
pos = end;
|
|
4747
|
+
}
|
|
4748
|
+
return buf;
|
|
4749
|
+
}
|
|
4750
|
+
function parseWasmObjectBytes(file, buf, isDist) {
|
|
4751
|
+
let pos = 8;
|
|
4752
|
+
let numImportFuncs = 0;
|
|
4753
|
+
const importFuncNames = [];
|
|
4754
|
+
const importGlobalNames = [];
|
|
4755
|
+
const importTableNames = [];
|
|
4756
|
+
const importEventNames = [];
|
|
4757
|
+
let codeStart = 0;
|
|
4758
|
+
const fStarts = [];
|
|
4759
|
+
const fEnds = [];
|
|
4760
|
+
let dataStart = 0;
|
|
4761
|
+
const sStarts = [];
|
|
4762
|
+
const sEnds = [];
|
|
4763
|
+
const sPayloadStarts = [];
|
|
4764
|
+
const segNames = [];
|
|
4765
|
+
const segFlags = [];
|
|
4766
|
+
let symKind = new Uint8Array(0);
|
|
4767
|
+
let symFlags = new Uint32Array(0);
|
|
4768
|
+
let symElemIdx = new Int32Array(0);
|
|
4769
|
+
let symOff = new Int32Array(0);
|
|
4770
|
+
let symSz = new Int32Array(0);
|
|
4771
|
+
const symNames = [];
|
|
4772
|
+
const initFuncs = [];
|
|
4773
|
+
const rawCodeRelocs = [];
|
|
4774
|
+
const rawDataRelocs = [];
|
|
4775
|
+
while (pos < buf.length) {
|
|
4776
|
+
const id = buf[pos++];
|
|
4777
|
+
const [sz, p] = readULEB(buf, pos);
|
|
4778
|
+
const end = p + sz;
|
|
4779
|
+
if (id === 2) {
|
|
4780
|
+
let [cnt, cp] = readULEB(buf, p);
|
|
4781
|
+
for (let i = 0; i < cnt; i++) {
|
|
4782
|
+
const [mLen, m2] = readULEB(buf, cp);
|
|
4783
|
+
cp = m2 + mLen;
|
|
4784
|
+
const [fLen, f2] = readULEB(buf, cp);
|
|
4785
|
+
const fName = Buffer.from(buf.subarray(f2, f2 + fLen)).toString("utf8");
|
|
4786
|
+
cp = f2 + fLen;
|
|
4787
|
+
const kind = buf[cp++];
|
|
4788
|
+
if (kind === 0) {
|
|
4789
|
+
const [, c2] = readULEB(buf, cp);
|
|
4790
|
+
cp = c2;
|
|
4791
|
+
importFuncNames.push(fName);
|
|
4792
|
+
numImportFuncs++;
|
|
4793
|
+
} else if (kind === 1) {
|
|
4794
|
+
cp++;
|
|
4795
|
+
const [fl, c2] = readULEB(buf, cp);
|
|
4796
|
+
cp = c2;
|
|
4797
|
+
const [, c3] = readULEB(buf, cp);
|
|
4798
|
+
cp = c3;
|
|
4799
|
+
if (fl & 1) {
|
|
4800
|
+
const [, c4] = readULEB(buf, cp);
|
|
4801
|
+
cp = c4;
|
|
4802
|
+
}
|
|
4803
|
+
importTableNames.push(fName);
|
|
4804
|
+
} else if (kind === 2) {
|
|
4805
|
+
const [fl, c2] = readULEB(buf, cp);
|
|
4806
|
+
cp = c2;
|
|
4807
|
+
const [, c3] = readULEB(buf, cp);
|
|
4808
|
+
cp = c3;
|
|
4809
|
+
if (fl & 1) {
|
|
4810
|
+
const [, c4] = readULEB(buf, cp);
|
|
4811
|
+
cp = c4;
|
|
4812
|
+
}
|
|
4813
|
+
} else if (kind === 3) {
|
|
4814
|
+
cp += 2;
|
|
4815
|
+
importGlobalNames.push(fName);
|
|
4816
|
+
} else if (kind === 4) {
|
|
4817
|
+
cp++;
|
|
4818
|
+
const [, c2] = readULEB(buf, cp);
|
|
4819
|
+
cp = c2;
|
|
4820
|
+
importEventNames.push(fName);
|
|
4821
|
+
}
|
|
4822
|
+
}
|
|
4823
|
+
} else if (id === 10) {
|
|
4824
|
+
codeStart = p;
|
|
4825
|
+
let [cnt, cp] = readULEB(buf, p);
|
|
4826
|
+
for (let i = 0; i < cnt; i++) {
|
|
4827
|
+
const st = cp - codeStart;
|
|
4828
|
+
const [bLen, b2] = readULEB(buf, cp);
|
|
4829
|
+
cp = b2 + bLen;
|
|
4830
|
+
fStarts.push(st);
|
|
4831
|
+
fEnds.push(cp - codeStart);
|
|
4832
|
+
}
|
|
4833
|
+
} else if (id === 11) {
|
|
4834
|
+
dataStart = p;
|
|
4835
|
+
let [cnt, cp] = readULEB(buf, p);
|
|
4836
|
+
for (let i = 0; i < cnt; i++) {
|
|
4837
|
+
const st = cp - dataStart;
|
|
4838
|
+
const [mode, m2] = readULEB(buf, cp);
|
|
4839
|
+
cp = m2;
|
|
4840
|
+
if (mode === 2) {
|
|
4841
|
+
const [, m3] = readULEB(buf, cp);
|
|
4842
|
+
cp = m3;
|
|
4843
|
+
}
|
|
4844
|
+
if (mode === 0 || mode === 2) {
|
|
4845
|
+
const op = buf[cp++];
|
|
4846
|
+
if (op === 65 || op === 66) {
|
|
4847
|
+
const [, m4] = readSLEB(buf, cp);
|
|
4848
|
+
cp = m4;
|
|
4849
|
+
} else if (op === 35) {
|
|
4850
|
+
const [, m4] = readULEB(buf, cp);
|
|
4851
|
+
cp = m4;
|
|
4852
|
+
}
|
|
4853
|
+
cp++;
|
|
4854
|
+
}
|
|
4855
|
+
const [dLen, d2] = readULEB(buf, cp);
|
|
4856
|
+
sPayloadStarts.push(d2 - dataStart);
|
|
4857
|
+
cp = d2 + dLen;
|
|
4858
|
+
sStarts.push(st);
|
|
4859
|
+
sEnds.push(cp - dataStart);
|
|
4860
|
+
}
|
|
4861
|
+
} else if (id === 0) {
|
|
4862
|
+
const [nLen, np] = readULEB(buf, p);
|
|
4863
|
+
const name2 = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
|
|
4864
|
+
const cp = np + nLen;
|
|
4865
|
+
if (name2 === "linking") {
|
|
4866
|
+
let [, lp] = readULEB(buf, cp);
|
|
4867
|
+
while (lp < end) {
|
|
4868
|
+
const subId = buf[lp++];
|
|
4869
|
+
const [subLen, sp] = readULEB(buf, lp);
|
|
4870
|
+
const subEnd = sp + subLen;
|
|
4871
|
+
if (subId === 5) {
|
|
4872
|
+
const [cnt, p2] = readULEB(buf, sp);
|
|
4873
|
+
let cur = p2;
|
|
4874
|
+
for (let i = 0; i < cnt; i++) {
|
|
4875
|
+
const [sLen, s2] = readULEB(buf, cur);
|
|
4876
|
+
segNames.push(Buffer.from(buf.subarray(s2, s2 + sLen)).toString("utf8"));
|
|
4877
|
+
cur = s2 + sLen;
|
|
4878
|
+
const [, s3] = readULEB(buf, cur);
|
|
4879
|
+
const [fl, s4] = readULEB(buf, s3);
|
|
4880
|
+
segFlags.push(fl);
|
|
4881
|
+
cur = s4;
|
|
4882
|
+
}
|
|
4883
|
+
} else if (subId === 6) {
|
|
4884
|
+
const [cnt, p2] = readULEB(buf, sp);
|
|
4885
|
+
let cur = p2;
|
|
4886
|
+
for (let i = 0; i < cnt; i++) {
|
|
4887
|
+
const [, s2] = readULEB(buf, cur);
|
|
4888
|
+
const [symIdx, s3] = readULEB(buf, s2);
|
|
4889
|
+
initFuncs.push(symIdx);
|
|
4890
|
+
cur = s3;
|
|
4891
|
+
}
|
|
4892
|
+
} else if (subId === 8) {
|
|
4893
|
+
const [cnt, p2] = readULEB(buf, sp);
|
|
4894
|
+
symKind = new Uint8Array(cnt);
|
|
4895
|
+
symFlags = new Uint32Array(cnt);
|
|
4896
|
+
symElemIdx = new Int32Array(cnt).fill(-1);
|
|
4897
|
+
symOff = new Int32Array(cnt).fill(0);
|
|
4898
|
+
symSz = new Int32Array(cnt).fill(0);
|
|
4899
|
+
let cur = p2;
|
|
4900
|
+
for (let i = 0; i < cnt; i++) {
|
|
4901
|
+
const kind = buf[cur++];
|
|
4902
|
+
const [fl, c2] = readULEB(buf, cur);
|
|
4903
|
+
cur = c2;
|
|
4904
|
+
symKind[i] = kind;
|
|
4905
|
+
symFlags[i] = fl;
|
|
4906
|
+
const isUndef = (fl & 16) !== 0;
|
|
4907
|
+
const isExplicitName = (fl & 64) !== 0;
|
|
4908
|
+
if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
|
|
4909
|
+
const [el, c3] = readULEB(buf, cur);
|
|
4910
|
+
cur = c3;
|
|
4911
|
+
if (!isUndef && kind === 0) symElemIdx[i] = el;
|
|
4912
|
+
let sName = "";
|
|
4913
|
+
if (!isUndef || isExplicitName) {
|
|
4914
|
+
const [sLen, c4] = readULEB(buf, cur);
|
|
4915
|
+
sName = Buffer.from(buf.subarray(c4, c4 + sLen)).toString("utf8");
|
|
4916
|
+
cur = c4 + sLen;
|
|
4917
|
+
} else if (kind === 0) {
|
|
4918
|
+
sName = importFuncNames[el] ?? "";
|
|
4919
|
+
} else if (kind === 2) {
|
|
4920
|
+
sName = importGlobalNames[el] ?? "";
|
|
4921
|
+
} else if (kind === 4) {
|
|
4922
|
+
sName = importEventNames[el] ?? "";
|
|
4923
|
+
} else if (kind === 5) {
|
|
4924
|
+
sName = importTableNames[el] ?? "";
|
|
4925
|
+
}
|
|
4926
|
+
symNames.push(sName);
|
|
4927
|
+
} else if (kind === 1) {
|
|
4928
|
+
const [sLen, c3] = readULEB(buf, cur);
|
|
4929
|
+
const sName = Buffer.from(buf.subarray(c3, c3 + sLen)).toString("utf8");
|
|
4930
|
+
cur = c3 + sLen;
|
|
4931
|
+
if (!isUndef) {
|
|
4932
|
+
const [segIdx, c4] = readULEB(buf, cur);
|
|
4933
|
+
const [sOff, c5] = readULEB(buf, c4);
|
|
4934
|
+
const [sSz, c6] = readULEB(buf, c5);
|
|
4935
|
+
cur = c6;
|
|
4936
|
+
symElemIdx[i] = segIdx;
|
|
4937
|
+
symOff[i] = sOff;
|
|
4938
|
+
symSz[i] = sSz;
|
|
4939
|
+
}
|
|
4940
|
+
symNames.push(sName);
|
|
4941
|
+
} else if (kind === 3) {
|
|
4942
|
+
const [, c3] = readULEB(buf, cur);
|
|
4943
|
+
cur = c3;
|
|
4944
|
+
symNames.push("");
|
|
4945
|
+
}
|
|
4946
|
+
}
|
|
4947
|
+
}
|
|
4948
|
+
lp = subEnd;
|
|
4949
|
+
}
|
|
4950
|
+
} else if (name2 === "reloc.CODE" || name2 === "reloc.DATA") {
|
|
4951
|
+
const [, r1] = readULEB(buf, cp);
|
|
4952
|
+
const [cnt, r2] = readULEB(buf, r1);
|
|
4953
|
+
let cur = r2;
|
|
4954
|
+
const target = name2 === "reloc.CODE" ? rawCodeRelocs : rawDataRelocs;
|
|
4955
|
+
for (let i = 0; i < cnt; i++) {
|
|
4956
|
+
const rStart = cur;
|
|
4957
|
+
const rType = buf[cur++];
|
|
4958
|
+
const [ro, c2] = readULEB(buf, cur);
|
|
4959
|
+
const [rs, c3] = readULEB(buf, c2);
|
|
4960
|
+
cur = c3;
|
|
4961
|
+
if (HAS_ADDEND.has(rType)) {
|
|
4962
|
+
const [, c4] = readSLEB(buf, cur);
|
|
4963
|
+
cur = c4;
|
|
4964
|
+
}
|
|
4965
|
+
target.push({ rawBytes: new Uint8Array(buf.subarray(rStart, cur)), ro, rs });
|
|
4966
|
+
}
|
|
4967
|
+
}
|
|
4968
|
+
}
|
|
4969
|
+
pos = end;
|
|
4970
|
+
}
|
|
4971
|
+
const symParentIdx = new Int32Array(symKind.length).fill(-1);
|
|
4972
|
+
const segTopSyms = /* @__PURE__ */ new Map();
|
|
4973
|
+
if (isDist) {
|
|
4974
|
+
const bySeg = /* @__PURE__ */ new Map();
|
|
4975
|
+
for (let i = 0; i < symKind.length; i++) {
|
|
4976
|
+
if (symKind[i] === 1 && symElemIdx[i] >= 0) {
|
|
4977
|
+
const segIdx = symElemIdx[i];
|
|
4978
|
+
if (PARTITIONED_SEGS.has(segNames[segIdx])) {
|
|
4979
|
+
let list = bySeg.get(segIdx);
|
|
4980
|
+
if (!list) {
|
|
4981
|
+
list = [];
|
|
4982
|
+
bySeg.set(segIdx, list);
|
|
4983
|
+
}
|
|
4984
|
+
list.push(i);
|
|
4985
|
+
}
|
|
4986
|
+
}
|
|
4987
|
+
}
|
|
4988
|
+
for (const [segIdx, syms] of bySeg) {
|
|
4989
|
+
const segByteLen = (sEnds[segIdx] ?? 0) - (sPayloadStarts[segIdx] ?? 0);
|
|
4990
|
+
const sorted = [...syms].sort(
|
|
4991
|
+
(a, b) => symOff[a] - symOff[b] || symSz[b] - symSz[a]
|
|
4992
|
+
);
|
|
4993
|
+
const dedupTop = [];
|
|
4994
|
+
for (let k = 0; k < sorted.length; k++) {
|
|
4995
|
+
const i = sorted[k];
|
|
4996
|
+
const off = symOff[i];
|
|
4997
|
+
const sz = symSz[i];
|
|
4998
|
+
const lastTop = dedupTop[dedupTop.length - 1];
|
|
4999
|
+
if (lastTop && off < lastTop.end) {
|
|
5000
|
+
symParentIdx[i] = lastTop.symIdx;
|
|
5001
|
+
continue;
|
|
5002
|
+
}
|
|
5003
|
+
let nextOff = segByteLen;
|
|
5004
|
+
for (let m = k + 1; m < sorted.length; m++) {
|
|
5005
|
+
if (symOff[sorted[m]] > off) {
|
|
5006
|
+
nextOff = symOff[sorted[m]];
|
|
5007
|
+
break;
|
|
5008
|
+
}
|
|
5009
|
+
}
|
|
5010
|
+
const end = sz > 0 ? off + sz : nextOff;
|
|
5011
|
+
symParentIdx[i] = i;
|
|
5012
|
+
dedupTop.push({ symIdx: i, off, end });
|
|
5013
|
+
}
|
|
5014
|
+
segTopSyms.set(segIdx, dedupTop);
|
|
5015
|
+
}
|
|
5016
|
+
}
|
|
5017
|
+
const funcRelocs = Array.from({ length: fEnds.length }, () => []);
|
|
5018
|
+
const codeRelocList = [];
|
|
5019
|
+
for (const r of rawCodeRelocs) {
|
|
5020
|
+
let lo = 0;
|
|
5021
|
+
let hi = fEnds.length - 1;
|
|
5022
|
+
while (lo < hi) {
|
|
5023
|
+
const mid = lo + hi >> 1;
|
|
5024
|
+
if (fEnds[mid] <= r.ro) lo = mid + 1;
|
|
5025
|
+
else hi = mid;
|
|
5026
|
+
}
|
|
5027
|
+
if (fEnds.length > 0) {
|
|
5028
|
+
funcRelocs[lo].push(r.rs);
|
|
5029
|
+
codeRelocList.push({ ...r, funcIdx: lo });
|
|
5030
|
+
}
|
|
5031
|
+
}
|
|
5032
|
+
const segRelocs = Array.from({ length: segNames.length }, () => []);
|
|
5033
|
+
const symDataRelocs = /* @__PURE__ */ new Map();
|
|
5034
|
+
const dataRelocList = [];
|
|
5035
|
+
for (const r of rawDataRelocs) {
|
|
5036
|
+
let lo = 0;
|
|
5037
|
+
let hi = sEnds.length - 1;
|
|
5038
|
+
while (lo < hi) {
|
|
5039
|
+
const mid = lo + hi >> 1;
|
|
5040
|
+
if (sEnds[mid] <= r.ro) lo = mid + 1;
|
|
5041
|
+
else hi = mid;
|
|
5042
|
+
}
|
|
5043
|
+
if (sEnds.length > 0 && lo < segRelocs.length) {
|
|
5044
|
+
const offInSeg = r.ro - (sPayloadStarts[lo] ?? 0);
|
|
5045
|
+
let ownerSymIdx = -1;
|
|
5046
|
+
const topList = segTopSyms.get(lo);
|
|
5047
|
+
if (topList) {
|
|
5048
|
+
const owner = topList.find((t) => offInSeg >= t.off && offInSeg < t.end);
|
|
5049
|
+
if (owner) ownerSymIdx = owner.symIdx;
|
|
5050
|
+
}
|
|
5051
|
+
if (ownerSymIdx !== -1) {
|
|
5052
|
+
let list = symDataRelocs.get(ownerSymIdx);
|
|
5053
|
+
if (!list) {
|
|
5054
|
+
list = [];
|
|
5055
|
+
symDataRelocs.set(ownerSymIdx, list);
|
|
5056
|
+
}
|
|
5057
|
+
list.push(r.rs);
|
|
5058
|
+
} else {
|
|
5059
|
+
segRelocs[lo].push(r.rs);
|
|
5060
|
+
}
|
|
5061
|
+
dataRelocList.push({ ...r, segIdx: lo, offInSeg, ownerSymIdx });
|
|
5062
|
+
}
|
|
5063
|
+
}
|
|
5064
|
+
const typePrefixesInObj = /* @__PURE__ */ new Set();
|
|
5065
|
+
if (isDist) {
|
|
5066
|
+
for (let i = 0; i < symKind.length; i++) {
|
|
5067
|
+
if ((symFlags[i] & 16) === 0 && symNames[i].startsWith("$s") && symNames[i].endsWith("Mn")) {
|
|
5068
|
+
typePrefixesInObj.add(symNames[i].slice(0, -2));
|
|
5069
|
+
}
|
|
5070
|
+
}
|
|
5071
|
+
}
|
|
5072
|
+
const objcRegisterFuncToTypePrefix = /* @__PURE__ */ new Map();
|
|
5073
|
+
const objcClassSymToTypePrefix = /* @__PURE__ */ new Map();
|
|
5074
|
+
if (isDist) {
|
|
5075
|
+
for (const symIdx of initFuncs) {
|
|
5076
|
+
if (symKind[symIdx] === 0 && symElemIdx[symIdx] >= numImportFuncs) {
|
|
5077
|
+
const lf = symElemIdx[symIdx] - numImportFuncs;
|
|
5078
|
+
const fName = symNames[symIdx];
|
|
5079
|
+
if (fName.startsWith(".L.swift.objc.register")) {
|
|
5080
|
+
const relSyms = funcRelocs[lf].map((si) => symNames[si]);
|
|
5081
|
+
const mnSym = relSyms.find((s) => s.startsWith("$s") && s.endsWith("Mn"));
|
|
5082
|
+
const objcSym = relSyms.find((s) => s.startsWith("._OBJC_CLASS_"));
|
|
5083
|
+
if (mnSym) {
|
|
5084
|
+
const pref = mnSym.slice(0, -2);
|
|
5085
|
+
objcRegisterFuncToTypePrefix.set(lf, pref);
|
|
5086
|
+
if (objcSym) objcClassSymToTypePrefix.set(objcSym, pref);
|
|
5087
|
+
}
|
|
5088
|
+
}
|
|
5089
|
+
}
|
|
5090
|
+
}
|
|
5091
|
+
}
|
|
5092
|
+
const rootFuncs = [];
|
|
5093
|
+
const rootSegs = [];
|
|
5094
|
+
for (const symIdx of initFuncs) {
|
|
5095
|
+
if (symKind[symIdx] === 0 && symElemIdx[symIdx] >= numImportFuncs) {
|
|
5096
|
+
const lf = symElemIdx[symIdx] - numImportFuncs;
|
|
5097
|
+
if (!objcRegisterFuncToTypePrefix.has(lf)) {
|
|
5098
|
+
rootFuncs.push(lf);
|
|
5099
|
+
}
|
|
5100
|
+
}
|
|
5101
|
+
}
|
|
5102
|
+
for (let i = 0; i < symKind.length; i++) {
|
|
5103
|
+
const isRootSym = isDist ? (symFlags[i] & 32) !== 0 : (symFlags[i] & 128) !== 0 || (symFlags[i] & 32) !== 0;
|
|
5104
|
+
if (isRootSym && (symFlags[i] & 16) === 0) {
|
|
5105
|
+
if (symKind[i] === 0 && symElemIdx[i] >= numImportFuncs) {
|
|
5106
|
+
rootFuncs.push(symElemIdx[i] - numImportFuncs);
|
|
5107
|
+
} else if (symKind[i] === 1 && symElemIdx[i] >= 0) {
|
|
5108
|
+
rootSegs.push(symElemIdx[i]);
|
|
5109
|
+
}
|
|
5110
|
+
}
|
|
5111
|
+
}
|
|
5112
|
+
for (let i = 0; i < segNames.length; i++) {
|
|
5113
|
+
const sName = segNames[i];
|
|
5114
|
+
if (isDist && (sName === "swift5_type_metadata" || sName === "swift5_protocol_conformances" || sName === "__objc_classes" || sName.startsWith(".init_array"))) {
|
|
5115
|
+
continue;
|
|
5116
|
+
}
|
|
5117
|
+
if (isRootSegName(sName) || !isDist && ((segFlags[i] ?? 0) & 4) !== 0) {
|
|
5118
|
+
rootSegs.push(i);
|
|
5119
|
+
}
|
|
5120
|
+
}
|
|
5121
|
+
return {
|
|
5122
|
+
file,
|
|
5123
|
+
isDist,
|
|
5124
|
+
numImportFuncs,
|
|
5125
|
+
numFuncs: fEnds.length,
|
|
5126
|
+
numSegments: segNames.length,
|
|
5127
|
+
segNames,
|
|
5128
|
+
symKind,
|
|
5129
|
+
symFlags,
|
|
5130
|
+
symElemIdx,
|
|
5131
|
+
symOff,
|
|
5132
|
+
symSz,
|
|
5133
|
+
symParentIdx,
|
|
5134
|
+
symNames,
|
|
5135
|
+
funcRelocs,
|
|
5136
|
+
segRelocs,
|
|
5137
|
+
symDataRelocs,
|
|
5138
|
+
codeRelocList,
|
|
5139
|
+
dataRelocList,
|
|
5140
|
+
initFuncSyms: initFuncs,
|
|
5141
|
+
objcRegisterFuncToTypePrefix,
|
|
5142
|
+
objcClassSymToTypePrefix,
|
|
5143
|
+
typePrefixesInObj,
|
|
5144
|
+
rootFuncs,
|
|
5145
|
+
rootSegs
|
|
5146
|
+
};
|
|
5147
|
+
}
|
|
5148
|
+
function parseWasmObjectCached(file, isDist, useCache) {
|
|
5149
|
+
const key = `${isDist ? "1" : "0"}:${file}`;
|
|
5150
|
+
if (useCache) {
|
|
5151
|
+
const hit = parsedObjectCache.get(key);
|
|
5152
|
+
if (hit) return hit;
|
|
5153
|
+
}
|
|
5154
|
+
const parsed = parseWasmObjectBytes(file, new Uint8Array(import_node_fs8.default.readFileSync(file)), isDist);
|
|
5155
|
+
if (useCache) parsedObjectCache.set(key, parsed);
|
|
5156
|
+
return parsed;
|
|
5157
|
+
}
|
|
5158
|
+
function peachHome2() {
|
|
5159
|
+
const override = process.env.PEACH_HOME;
|
|
5160
|
+
return override ? import_node_path12.default.resolve(override) : import_node_path12.default.join(import_node_os4.default.homedir(), ".peach");
|
|
5161
|
+
}
|
|
5162
|
+
function ensureUnpackedSdkObjects(sdkWasiDir) {
|
|
5163
|
+
const sdkKey = (0, import_node_crypto6.createHash)("sha256").update(sdkWasiDir).digest("hex").slice(0, 16);
|
|
5164
|
+
const outDir = import_node_path12.default.join(peachHome2(), "cache", "swift-builds", `sdk-objs-${sdkKey}`);
|
|
5165
|
+
const stamp = import_node_path12.default.join(outDir, ".complete");
|
|
5166
|
+
if (import_node_fs8.default.existsSync(stamp)) return outDir;
|
|
5167
|
+
const tmpDir = `${outDir}.${process.pid}.${Date.now()}.tmp`;
|
|
5168
|
+
import_node_fs8.default.mkdirSync(tmpDir, { recursive: true });
|
|
5169
|
+
const archives = import_node_fs8.default.readdirSync(sdkWasiDir).filter((f) => f.endsWith(".a")).sort();
|
|
5170
|
+
for (const archive of archives) {
|
|
5171
|
+
const aBase = archive.replace(/\.a$/, "");
|
|
5172
|
+
const members = readArMembers(
|
|
5173
|
+
new Uint8Array(import_node_fs8.default.readFileSync(import_node_path12.default.join(sdkWasiDir, archive)))
|
|
5174
|
+
);
|
|
5175
|
+
const seen = /* @__PURE__ */ new Map();
|
|
5176
|
+
for (const m of members) {
|
|
5177
|
+
const count = (seen.get(m.name) ?? 0) + 1;
|
|
5178
|
+
seen.set(m.name, count);
|
|
5179
|
+
const suffix = count > 1 ? `_${count}` : "";
|
|
5180
|
+
const safeName = m.name.replaceAll("/", "__");
|
|
5181
|
+
const outName = `${aBase}__${safeName}${suffix}`;
|
|
5182
|
+
import_node_fs8.default.writeFileSync(import_node_path12.default.join(tmpDir, outName), m.bytes);
|
|
5183
|
+
}
|
|
5184
|
+
}
|
|
5185
|
+
import_node_fs8.default.writeFileSync(import_node_path12.default.join(tmpDir, ".complete"), "1\n");
|
|
5186
|
+
import_node_fs8.default.mkdirSync(import_node_path12.default.dirname(outDir), { recursive: true });
|
|
5187
|
+
if (import_node_fs8.default.existsSync(stamp)) {
|
|
5188
|
+
import_node_fs8.default.rmSync(tmpDir, { recursive: true, force: true });
|
|
5189
|
+
return outDir;
|
|
5190
|
+
}
|
|
5191
|
+
import_node_fs8.default.rmSync(outDir, { recursive: true, force: true });
|
|
5192
|
+
import_node_fs8.default.renameSync(tmpDir, outDir);
|
|
5193
|
+
return outDir;
|
|
5194
|
+
}
|
|
5195
|
+
function isPrunableSdkFile(file) {
|
|
5196
|
+
const base = import_node_path12.default.basename(file);
|
|
5197
|
+
const aBase = base.split("__")[0];
|
|
5198
|
+
if (PRUNED_SDK_ARCHIVES.has(aBase)) return true;
|
|
5199
|
+
if (base === "libswiftCore__Swift.o" || base === "libswift_Concurrency___Concurrency.o") {
|
|
5200
|
+
return true;
|
|
5201
|
+
}
|
|
5202
|
+
return false;
|
|
5203
|
+
}
|
|
5204
|
+
function getModulePrefix(file) {
|
|
5205
|
+
const base = import_node_path12.default.basename(file);
|
|
5206
|
+
const dbl = base.indexOf("__");
|
|
5207
|
+
if (dbl > 0) return base.slice(0, dbl);
|
|
5208
|
+
const dash = base.indexOf("-");
|
|
5209
|
+
return dash > 0 ? base.slice(0, dash) : base;
|
|
5210
|
+
}
|
|
5211
|
+
function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot) {
|
|
5212
|
+
const rspPath = import_node_path12.default.join(directory, ".peach-link.rsp");
|
|
5213
|
+
if (!import_node_fs8.default.existsSync(rspPath)) return;
|
|
5214
|
+
const origRsp = import_node_fs8.default.readFileSync(rspPath, "utf8");
|
|
5215
|
+
const tokens = Array.from(origRsp.matchAll(/"([^"]+)"|(\S+)/g), (m) => m[1] ?? m[2]);
|
|
5216
|
+
if (!tokens.includes("--start-lib")) return;
|
|
5217
|
+
const sdkFlag = tokens.find(
|
|
5218
|
+
(t) => t.startsWith("-L") && t.endsWith("/swift_static/wasi")
|
|
5219
|
+
);
|
|
5220
|
+
if (!sdkFlag) return;
|
|
5221
|
+
const sdkWasiDir = sdkFlag.slice(2);
|
|
5222
|
+
const sdkObjsDir = ensureUnpackedSdkObjects(sdkWasiDir);
|
|
5223
|
+
const distDir = import_node_path12.default.join(moduleRoot, "lib");
|
|
5224
|
+
const prunedObjsDir = import_node_path12.default.join(directory, ".peach-pruned-objs");
|
|
5225
|
+
import_node_fs8.default.rmSync(prunedObjsDir, { recursive: true, force: true });
|
|
5226
|
+
import_node_fs8.default.mkdirSync(prunedObjsDir, { recursive: true });
|
|
5227
|
+
const distFiles = [];
|
|
5228
|
+
const eagerFiles = [];
|
|
5229
|
+
const extraArchiveObjs = [];
|
|
5230
|
+
let inStartLib = false;
|
|
5231
|
+
let swiftrtOrigPath = "";
|
|
5232
|
+
for (const t of tokens) {
|
|
5233
|
+
if (t === "--start-lib") {
|
|
5234
|
+
inStartLib = true;
|
|
5235
|
+
continue;
|
|
5236
|
+
}
|
|
5237
|
+
if (t === "--end-lib") {
|
|
5238
|
+
inStartLib = false;
|
|
5239
|
+
continue;
|
|
5240
|
+
}
|
|
5241
|
+
if (t.endsWith(".o")) {
|
|
5242
|
+
if (t.startsWith(distDir)) {
|
|
5243
|
+
if (import_node_path12.default.basename(t) !== "Foundation-NSStringFormatting.o") {
|
|
5244
|
+
distFiles.push(t);
|
|
5245
|
+
}
|
|
5246
|
+
if (!inStartLib) eagerFiles.push(t);
|
|
5247
|
+
} else if (!inStartLib) {
|
|
5248
|
+
if (t.endsWith("/swiftrt.o")) {
|
|
5249
|
+
swiftrtOrigPath = t;
|
|
5250
|
+
} else {
|
|
5251
|
+
eagerFiles.push(t);
|
|
5252
|
+
}
|
|
5253
|
+
}
|
|
5254
|
+
} else if (!inStartLib && t.endsWith(".a") && !t.endsWith("libclang_rt.builtins-wasm32.a") && import_node_fs8.default.existsSync(t)) {
|
|
5255
|
+
const members = readArMembers(new Uint8Array(import_node_fs8.default.readFileSync(t)));
|
|
5256
|
+
for (const m of members) {
|
|
5257
|
+
extraArchiveObjs.push(parseWasmObjectBytes(`${t}(${m.name})`, m.bytes, false));
|
|
5258
|
+
}
|
|
5259
|
+
}
|
|
5260
|
+
}
|
|
5261
|
+
let patchedSwiftrtPath = "";
|
|
5262
|
+
if (swiftrtOrigPath && import_node_fs8.default.existsSync(swiftrtOrigPath)) {
|
|
5263
|
+
patchedSwiftrtPath = import_node_path12.default.join(prunedObjsDir, "swiftrt-patched.o");
|
|
5264
|
+
import_node_fs8.default.writeFileSync(
|
|
5265
|
+
patchedSwiftrtPath,
|
|
5266
|
+
patchSwiftrtObject(new Uint8Array(import_node_fs8.default.readFileSync(swiftrtOrigPath)))
|
|
5267
|
+
);
|
|
5268
|
+
eagerFiles.push(patchedSwiftrtPath);
|
|
5269
|
+
}
|
|
5270
|
+
const allSdkObjFiles = import_node_fs8.default.readdirSync(sdkObjsDir).filter((f) => f.endsWith(".o") || f.endsWith(".obj")).sort();
|
|
5271
|
+
const sdkFiles = allSdkObjFiles.map((f) => import_node_path12.default.join(sdkObjsDir, f));
|
|
5272
|
+
const distObjs = /* @__PURE__ */ new Map();
|
|
5273
|
+
const lazyProviders = /* @__PURE__ */ new Map();
|
|
5274
|
+
const registerLazyProvider = (obj) => {
|
|
5275
|
+
for (let i = 0; i < obj.symNames.length; i++) {
|
|
5276
|
+
const fl = obj.symFlags[i];
|
|
5277
|
+
const isUndef = (fl & 16) !== 0;
|
|
5278
|
+
const isLocal = (fl & 3) === 2;
|
|
5279
|
+
if (!isUndef && !isLocal) {
|
|
5280
|
+
const name2 = obj.symNames[i];
|
|
5281
|
+
if (name2) {
|
|
5282
|
+
let list = lazyProviders.get(name2);
|
|
5283
|
+
if (!list) {
|
|
5284
|
+
list = [];
|
|
5285
|
+
lazyProviders.set(name2, list);
|
|
5286
|
+
}
|
|
5287
|
+
list.push(obj);
|
|
5288
|
+
}
|
|
5289
|
+
}
|
|
5290
|
+
}
|
|
5291
|
+
};
|
|
5292
|
+
for (const f of [...distFiles, ...sdkFiles]) {
|
|
5293
|
+
const isSdk = f.startsWith(sdkObjsDir);
|
|
5294
|
+
const isPrunableSwift = !isSdk || isPrunableSdkFile(f);
|
|
5295
|
+
const obj = parseWasmObjectCached(f, isPrunableSwift, true);
|
|
5296
|
+
distObjs.set(f, obj);
|
|
5297
|
+
registerLazyProvider(obj);
|
|
5298
|
+
}
|
|
5299
|
+
for (const obj of extraArchiveObjs) {
|
|
5300
|
+
registerLazyProvider(obj);
|
|
5301
|
+
}
|
|
5302
|
+
const extractedObjs = /* @__PURE__ */ new Set();
|
|
5303
|
+
const definedGlobalSyms = /* @__PURE__ */ new Map();
|
|
5304
|
+
const extractedSymbolDefs = /* @__PURE__ */ new Map();
|
|
5305
|
+
const liveGlobalNames = /* @__PURE__ */ new Set();
|
|
5306
|
+
const liveFuncs = /* @__PURE__ */ new Map();
|
|
5307
|
+
const liveSegs = /* @__PURE__ */ new Map();
|
|
5308
|
+
const liveDataSyms = /* @__PURE__ */ new Map();
|
|
5309
|
+
const liveTypes = /* @__PURE__ */ new Map();
|
|
5310
|
+
const workQueue = [];
|
|
5311
|
+
const pendingUndef = /* @__PURE__ */ new Set();
|
|
5312
|
+
const markFuncLive = (obj, localFuncIdx) => {
|
|
5313
|
+
const arr = liveFuncs.get(obj);
|
|
5314
|
+
if (arr[localFuncIdx]) return;
|
|
5315
|
+
arr[localFuncIdx] = 1;
|
|
5316
|
+
workQueue.push({ kind: "func", obj, idx: localFuncIdx });
|
|
5317
|
+
};
|
|
5318
|
+
const markSegLive = (obj, segIdx) => {
|
|
5319
|
+
const arr = liveSegs.get(obj);
|
|
5320
|
+
if (arr[segIdx]) return;
|
|
5321
|
+
arr[segIdx] = 1;
|
|
5322
|
+
workQueue.push({ kind: "seg", obj, idx: segIdx });
|
|
5323
|
+
};
|
|
5324
|
+
const markDataSymLive = (obj, symIdx) => {
|
|
5325
|
+
const set = liveDataSyms.get(obj);
|
|
5326
|
+
if (set.has(symIdx)) return;
|
|
5327
|
+
set.add(symIdx);
|
|
5328
|
+
workQueue.push({ kind: "datasym", obj, symIdx });
|
|
5329
|
+
};
|
|
5330
|
+
const markTypeLive = (obj, pref) => {
|
|
5331
|
+
const set = liveTypes.get(obj);
|
|
5332
|
+
if (set.has(pref)) return;
|
|
5333
|
+
set.add(pref);
|
|
5334
|
+
const mnName = `${pref}Mn`;
|
|
5335
|
+
for (let i = 0; i < obj.symNames.length; i++) {
|
|
5336
|
+
if (obj.symNames[i] === mnName && (obj.symFlags[i] & 16) === 0) {
|
|
5337
|
+
activateSymbolInObj(obj, i);
|
|
5338
|
+
}
|
|
5339
|
+
}
|
|
5340
|
+
for (const [lf, p] of obj.objcRegisterFuncToTypePrefix) {
|
|
5341
|
+
if (p === pref) {
|
|
5342
|
+
markFuncLive(obj, lf);
|
|
5343
|
+
}
|
|
5344
|
+
}
|
|
5345
|
+
for (let sIdx = 0; sIdx < obj.segNames.length; sIdx++) {
|
|
5346
|
+
if (obj.segNames[sIdx] === "swift5_protocol_conformances") {
|
|
5347
|
+
for (const r of obj.dataRelocList) {
|
|
5348
|
+
if (r.segIdx === sIdx) {
|
|
5349
|
+
const mcName = obj.symNames[r.rs];
|
|
5350
|
+
if (mcName.startsWith(pref)) {
|
|
5351
|
+
activateSymbolInObj(obj, r.rs);
|
|
5352
|
+
}
|
|
5353
|
+
}
|
|
5354
|
+
}
|
|
5355
|
+
}
|
|
5356
|
+
}
|
|
5357
|
+
};
|
|
5358
|
+
const checkTypeTrigger = (obj, rawSymName) => {
|
|
5359
|
+
if (!obj.isDist || !rawSymName) return;
|
|
5360
|
+
const sName = rawSymName.startsWith(".Lgot.") ? rawSymName.slice(6) : rawSymName;
|
|
5361
|
+
const objcPref = obj.objcClassSymToTypePrefix.get(sName);
|
|
5362
|
+
if (objcPref) {
|
|
5363
|
+
markTypeLive(obj, objcPref);
|
|
5364
|
+
return;
|
|
5365
|
+
}
|
|
5366
|
+
if (!sName.startsWith("$s") || sName.endsWith("Tm")) return;
|
|
5367
|
+
for (const suffix of ["Ma", "Mf", "N", "Mn", "ML"]) {
|
|
5368
|
+
if (sName.endsWith(suffix)) {
|
|
5369
|
+
const cand = sName.slice(0, -suffix.length);
|
|
5370
|
+
if (obj.typePrefixesInObj.has(cand)) {
|
|
5371
|
+
markTypeLive(obj, cand);
|
|
5372
|
+
return;
|
|
5373
|
+
}
|
|
5374
|
+
}
|
|
5375
|
+
}
|
|
5376
|
+
if (obj.file.endsWith("libswiftCore__Swift.o") || obj.file.endsWith("libswift_Concurrency___Concurrency.o")) {
|
|
5377
|
+
for (const pref of obj.typePrefixesInObj) {
|
|
5378
|
+
if (sName.startsWith(pref)) {
|
|
5379
|
+
markTypeLive(obj, pref);
|
|
5380
|
+
}
|
|
5381
|
+
}
|
|
5382
|
+
}
|
|
5383
|
+
};
|
|
5384
|
+
const activateGlobalName = (name2) => {
|
|
5385
|
+
if (!name2) return;
|
|
5386
|
+
if (!liveGlobalNames.has(name2)) liveGlobalNames.add(name2);
|
|
5387
|
+
const defs = extractedSymbolDefs.get(name2);
|
|
5388
|
+
if (defs) {
|
|
5389
|
+
for (const d of defs) {
|
|
5390
|
+
activateSymbolInObj(d.obj, d.symIdx);
|
|
5391
|
+
}
|
|
5392
|
+
}
|
|
5393
|
+
};
|
|
5394
|
+
function activateSymbolInObj(obj, symIdx) {
|
|
5395
|
+
const kind = obj.symKind[symIdx];
|
|
5396
|
+
const el = obj.symElemIdx[symIdx];
|
|
5397
|
+
const sName = obj.symNames[symIdx];
|
|
5398
|
+
const fl = obj.symFlags[symIdx];
|
|
5399
|
+
const isUndef = (fl & 16) !== 0;
|
|
5400
|
+
const isLocal = (fl & 3) === 2;
|
|
5401
|
+
checkTypeTrigger(obj, sName);
|
|
5402
|
+
if (!isUndef && !isLocal && sName && !liveGlobalNames.has(sName)) {
|
|
5403
|
+
activateGlobalName(sName);
|
|
5404
|
+
}
|
|
5405
|
+
if (kind === 0 && el >= obj.numImportFuncs) {
|
|
5406
|
+
markFuncLive(obj, el - obj.numImportFuncs);
|
|
5407
|
+
} else if (kind === 1 && el >= 0) {
|
|
5408
|
+
const pIdx = obj.symParentIdx[symIdx];
|
|
5409
|
+
if (pIdx !== -1) {
|
|
5410
|
+
markDataSymLive(obj, pIdx);
|
|
5411
|
+
const parentName = obj.symNames[pIdx];
|
|
5412
|
+
checkTypeTrigger(obj, parentName);
|
|
5413
|
+
}
|
|
5414
|
+
markSegLive(obj, el);
|
|
5415
|
+
}
|
|
5416
|
+
}
|
|
5417
|
+
const extractObject = (obj) => {
|
|
5418
|
+
if (extractedObjs.has(obj)) return;
|
|
5419
|
+
extractedObjs.add(obj);
|
|
5420
|
+
liveFuncs.set(obj, new Uint8Array(obj.numFuncs));
|
|
5421
|
+
liveSegs.set(obj, new Uint8Array(obj.numSegments));
|
|
5422
|
+
liveDataSyms.set(obj, /* @__PURE__ */ new Set());
|
|
5423
|
+
liveTypes.set(obj, /* @__PURE__ */ new Set());
|
|
5424
|
+
for (let i = 0; i < obj.symNames.length; i++) {
|
|
5425
|
+
const fl = obj.symFlags[i];
|
|
5426
|
+
const isUndef = (fl & 16) !== 0;
|
|
5427
|
+
const isLocal = (fl & 3) === 2;
|
|
5428
|
+
const isWeak = (fl & 3) === 1;
|
|
5429
|
+
if (!isUndef && !isLocal) {
|
|
5430
|
+
const name2 = obj.symNames[i];
|
|
5431
|
+
if (name2) {
|
|
5432
|
+
if (!definedGlobalSyms.has(name2) || !isWeak) {
|
|
5433
|
+
definedGlobalSyms.set(name2, { obj, symIdx: i });
|
|
5434
|
+
}
|
|
5435
|
+
let dList = extractedSymbolDefs.get(name2);
|
|
5436
|
+
if (!dList) {
|
|
5437
|
+
dList = [];
|
|
5438
|
+
extractedSymbolDefs.set(name2, dList);
|
|
5439
|
+
}
|
|
5440
|
+
dList.push({ obj, symIdx: i });
|
|
5441
|
+
if (pendingUndef.has(name2) || liveGlobalNames.has(name2)) {
|
|
5442
|
+
pendingUndef.delete(name2);
|
|
5443
|
+
activateSymbolInObj(obj, i);
|
|
5444
|
+
}
|
|
5445
|
+
}
|
|
5446
|
+
}
|
|
5447
|
+
}
|
|
5448
|
+
for (const fIdx of obj.rootFuncs) markFuncLive(obj, fIdx);
|
|
5449
|
+
for (const sIdx of obj.rootSegs) markSegLive(obj, sIdx);
|
|
5450
|
+
if (obj.file.endsWith("libswiftCore__Swift.o")) {
|
|
5451
|
+
for (const pref of obj.typePrefixesInObj) {
|
|
5452
|
+
if (!pref.startsWith("$ss")) {
|
|
5453
|
+
markTypeLive(obj, pref);
|
|
5454
|
+
}
|
|
5455
|
+
}
|
|
5456
|
+
}
|
|
5457
|
+
if (obj.isDist) {
|
|
5458
|
+
for (let sIdx = 0; sIdx < obj.segNames.length; sIdx++) {
|
|
5459
|
+
if (obj.segNames[sIdx] === "swift5_protocol_conformances") {
|
|
5460
|
+
for (const r of obj.dataRelocList) {
|
|
5461
|
+
if (r.segIdx === sIdx) {
|
|
5462
|
+
const mcName = obj.symNames[r.rs];
|
|
5463
|
+
let matchesLocalType = false;
|
|
5464
|
+
for (const pref of obj.typePrefixesInObj) {
|
|
5465
|
+
if (mcName.startsWith(pref)) {
|
|
5466
|
+
matchesLocalType = true;
|
|
5467
|
+
break;
|
|
5468
|
+
}
|
|
5469
|
+
}
|
|
5470
|
+
if (!matchesLocalType) {
|
|
5471
|
+
activateSymbolInObj(obj, r.rs);
|
|
5472
|
+
}
|
|
5473
|
+
}
|
|
5474
|
+
}
|
|
5475
|
+
}
|
|
5476
|
+
}
|
|
5477
|
+
}
|
|
5478
|
+
};
|
|
5479
|
+
for (const f of eagerFiles) {
|
|
5480
|
+
const isDist = f.startsWith(distDir);
|
|
5481
|
+
const obj = distObjs.get(f) ?? parseWasmObjectCached(f, isDist, false);
|
|
5482
|
+
extractObject(obj);
|
|
5483
|
+
if (isDist) {
|
|
5484
|
+
const base = import_node_path12.default.basename(f);
|
|
5485
|
+
if (base.startsWith("PeachFoundation-") || base.startsWith("PeachObjC-") || base.startsWith("PeachICU-") || base.startsWith("Darwin-")) {
|
|
5486
|
+
for (let i = 0; i < obj.symNames.length; i++) {
|
|
5487
|
+
const sName = obj.symNames[i];
|
|
5488
|
+
if ((obj.symFlags[i] & 16) === 0 && sName && !sName.startsWith("$s") && !sName.startsWith(".")) {
|
|
5489
|
+
activateSymbolInObj(obj, i);
|
|
5490
|
+
}
|
|
5491
|
+
}
|
|
5492
|
+
}
|
|
5493
|
+
}
|
|
5494
|
+
}
|
|
5495
|
+
for (const symName of ["_initialize", "__main_argc_argv", "main"]) {
|
|
5496
|
+
const def = definedGlobalSyms.get(symName);
|
|
5497
|
+
if (def) activateSymbolInObj(def.obj, def.symIdx);
|
|
5498
|
+
}
|
|
5499
|
+
while (workQueue.length > 0) {
|
|
5500
|
+
const item = workQueue.pop();
|
|
5501
|
+
const obj = item.obj;
|
|
5502
|
+
let relocs;
|
|
5503
|
+
if (item.kind === "func") {
|
|
5504
|
+
relocs = obj.funcRelocs[item.idx];
|
|
5505
|
+
} else if (item.kind === "seg") {
|
|
5506
|
+
relocs = obj.segRelocs[item.idx];
|
|
5507
|
+
} else {
|
|
5508
|
+
relocs = obj.symDataRelocs.get(item.symIdx) ?? [];
|
|
5509
|
+
}
|
|
5510
|
+
for (const symIdx of relocs) {
|
|
5511
|
+
const fl = obj.symFlags[symIdx];
|
|
5512
|
+
const isUndef = (fl & 16) !== 0;
|
|
5513
|
+
const isLocal = (fl & 3) === 2;
|
|
5514
|
+
const isWeak = (fl & 3) === 1;
|
|
5515
|
+
if (!isUndef) {
|
|
5516
|
+
activateSymbolInObj(obj, symIdx);
|
|
5517
|
+
if (!isLocal) {
|
|
5518
|
+
const name2 = obj.symNames[symIdx];
|
|
5519
|
+
activateGlobalName(name2);
|
|
5520
|
+
}
|
|
5521
|
+
} else {
|
|
5522
|
+
const name2 = obj.symNames[symIdx];
|
|
5523
|
+
if (!name2) continue;
|
|
5524
|
+
let def = definedGlobalSyms.get(name2);
|
|
5525
|
+
if (!def) {
|
|
5526
|
+
const cands = lazyProviders.get(name2);
|
|
5527
|
+
if (cands && cands.length > 0) {
|
|
5528
|
+
const reqMod = getModulePrefix(obj.file);
|
|
5529
|
+
let chosen = cands.find((c) => extractedObjs.has(c));
|
|
5530
|
+
if (!chosen) {
|
|
5531
|
+
const sameMod = cands.filter((c) => getModulePrefix(c.file) === reqMod);
|
|
5532
|
+
const sdkPool = cands.filter((c) => c.file.startsWith(sdkObjsDir));
|
|
5533
|
+
const pool = sameMod.length > 0 ? sameMod : sdkPool.length > 0 ? sdkPool : cands;
|
|
5534
|
+
chosen = pool.reduce(
|
|
5535
|
+
(a, b) => a.rootSegs.length + a.rootFuncs.length <= b.rootSegs.length + b.rootFuncs.length ? a : b
|
|
5536
|
+
);
|
|
5537
|
+
}
|
|
5538
|
+
extractObject(chosen);
|
|
5539
|
+
def = definedGlobalSyms.get(name2);
|
|
5540
|
+
} else if (!isWeak) {
|
|
5541
|
+
pendingUndef.add(name2);
|
|
5542
|
+
}
|
|
5543
|
+
}
|
|
5544
|
+
if (def) {
|
|
5545
|
+
activateGlobalName(name2);
|
|
5546
|
+
}
|
|
5547
|
+
}
|
|
5548
|
+
}
|
|
5549
|
+
}
|
|
5550
|
+
const isSpecialSegRelocLive = (obj, segName, r) => {
|
|
5551
|
+
const sLive = liveSegs.get(obj);
|
|
5552
|
+
const dLive = liveDataSyms.get(obj);
|
|
5553
|
+
const tLive = liveTypes.get(obj);
|
|
5554
|
+
const targetName = obj.symNames[r.rs] ?? "";
|
|
5555
|
+
if (segName === "swift5_type_metadata") {
|
|
5556
|
+
const raw2 = targetName.startsWith(".Lgot.") ? targetName.slice(6) : targetName;
|
|
5557
|
+
if (raw2.endsWith("Mn")) {
|
|
5558
|
+
const pref = raw2.slice(0, -2);
|
|
5559
|
+
if (obj.typePrefixesInObj.has(pref)) return tLive.has(pref);
|
|
5560
|
+
}
|
|
5561
|
+
return true;
|
|
5562
|
+
}
|
|
5563
|
+
if (segName === "swift5_protocol_conformances" || segName === "__objc_classes") {
|
|
5564
|
+
const pIdx = obj.symParentIdx[r.rs];
|
|
5565
|
+
if (pIdx !== -1) return dLive.has(pIdx);
|
|
5566
|
+
const segIdx = obj.symElemIdx[r.rs];
|
|
5567
|
+
return segIdx >= 0 ? sLive[segIdx] === 1 : true;
|
|
5568
|
+
}
|
|
5569
|
+
return true;
|
|
5570
|
+
};
|
|
5571
|
+
const writePrunedObject = (obj, outFile) => {
|
|
5572
|
+
const buf = new Uint8Array(import_node_fs8.default.readFileSync(obj.file));
|
|
5573
|
+
const fLive = liveFuncs.get(obj);
|
|
5574
|
+
const sLive = liveSegs.get(obj);
|
|
5575
|
+
const dLive = liveDataSyms.get(obj);
|
|
5576
|
+
const keptCodeRelocs = obj.codeRelocList.filter((r) => fLive[r.funcIdx] === 1);
|
|
5577
|
+
const firstLiveInSpecialSeg = /* @__PURE__ */ new Map();
|
|
5578
|
+
const deadSpecialSegs = /* @__PURE__ */ new Set();
|
|
5579
|
+
for (let sIdx = 0; sIdx < obj.segNames.length; sIdx++) {
|
|
5580
|
+
const sName = obj.segNames[sIdx];
|
|
5581
|
+
if (sName === "swift5_type_metadata" || sName === "swift5_protocol_conformances" || sName === "__objc_classes") {
|
|
5582
|
+
const segRels = obj.dataRelocList.filter((r) => r.segIdx === sIdx);
|
|
5583
|
+
const liveRels = segRels.filter((r) => isSpecialSegRelocLive(obj, sName, r));
|
|
5584
|
+
if (liveRels.length === 0) {
|
|
5585
|
+
deadSpecialSegs.add(sIdx);
|
|
5586
|
+
} else {
|
|
5587
|
+
const first = liveRels[0];
|
|
5588
|
+
const rType = first.rawBytes[0];
|
|
5589
|
+
const [, afterRoOff] = readULEB(first.rawBytes, 1);
|
|
5590
|
+
firstLiveInSpecialSeg.set(sIdx, {
|
|
5591
|
+
rType,
|
|
5592
|
+
afterRo: first.rawBytes.subarray(afterRoOff)
|
|
5593
|
+
});
|
|
5594
|
+
}
|
|
5595
|
+
}
|
|
5596
|
+
}
|
|
5597
|
+
const keptDataRelocBytes = [];
|
|
5598
|
+
const zeroDataRelocOffsets = [];
|
|
5599
|
+
const usedSyms = /* @__PURE__ */ new Set();
|
|
5600
|
+
for (const r of keptCodeRelocs) usedSyms.add(r.rs);
|
|
5601
|
+
for (const r of obj.dataRelocList) {
|
|
5602
|
+
const sName = obj.segNames[r.segIdx];
|
|
5603
|
+
if (sName === "swift5_type_metadata" || sName === "swift5_protocol_conformances" || sName === "__objc_classes") {
|
|
5604
|
+
if (deadSpecialSegs.has(r.segIdx)) continue;
|
|
5605
|
+
if (isSpecialSegRelocLive(obj, sName, r)) {
|
|
5606
|
+
keptDataRelocBytes.push(r.rawBytes);
|
|
5607
|
+
usedSyms.add(r.rs);
|
|
5608
|
+
} else if (sName === "__objc_classes") {
|
|
5609
|
+
zeroDataRelocOffsets.push(r.ro);
|
|
5610
|
+
} else {
|
|
5611
|
+
const repl = firstLiveInSpecialSeg.get(r.segIdx);
|
|
5612
|
+
const roBytes = encodeULEB(r.ro);
|
|
5613
|
+
const out = new Uint8Array(1 + roBytes.length + repl.afterRo.length);
|
|
5614
|
+
out[0] = repl.rType;
|
|
5615
|
+
out.set(roBytes, 1);
|
|
5616
|
+
out.set(repl.afterRo, 1 + roBytes.length);
|
|
5617
|
+
keptDataRelocBytes.push(out);
|
|
5618
|
+
}
|
|
5619
|
+
} else if (r.ownerSymIdx !== -1) {
|
|
5620
|
+
if (dLive.has(r.ownerSymIdx)) {
|
|
5621
|
+
keptDataRelocBytes.push(r.rawBytes);
|
|
5622
|
+
usedSyms.add(r.rs);
|
|
5623
|
+
}
|
|
5624
|
+
} else if (sLive[r.segIdx] === 1) {
|
|
5625
|
+
keptDataRelocBytes.push(r.rawBytes);
|
|
5626
|
+
usedSyms.add(r.rs);
|
|
5627
|
+
}
|
|
5628
|
+
}
|
|
5629
|
+
const keptInitSyms = obj.initFuncSyms.filter((symIdx) => {
|
|
5630
|
+
if (obj.symKind[symIdx] === 0 && obj.symElemIdx[symIdx] >= obj.numImportFuncs) {
|
|
5631
|
+
return fLive[obj.symElemIdx[symIdx] - obj.numImportFuncs] === 1;
|
|
5632
|
+
}
|
|
5633
|
+
return true;
|
|
5634
|
+
});
|
|
5635
|
+
for (const symIdx of keptInitSyms) usedSyms.add(symIdx);
|
|
5636
|
+
const outChunks = [buf.subarray(0, 8)];
|
|
5637
|
+
let pos = 8;
|
|
5638
|
+
while (pos < buf.length) {
|
|
5639
|
+
const secStart = pos;
|
|
5640
|
+
const id = buf[pos++];
|
|
5641
|
+
const [sz, p] = readULEB(buf, pos);
|
|
5642
|
+
const end = p + sz;
|
|
5643
|
+
if (id === 0) {
|
|
5644
|
+
const [nLen, np] = readULEB(buf, p);
|
|
5645
|
+
const name2 = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
|
|
5646
|
+
const cp = np + nLen;
|
|
5647
|
+
if (name2 === "linking") {
|
|
5648
|
+
const [, lpStart] = readULEB(buf, cp);
|
|
5649
|
+
const subChunks = [buf.subarray(p, lpStart)];
|
|
5650
|
+
let lp = lpStart;
|
|
5651
|
+
while (lp < end) {
|
|
5652
|
+
const subStart = lp;
|
|
5653
|
+
const subId = buf[lp++];
|
|
5654
|
+
const [subLen, sp] = readULEB(buf, lp);
|
|
5655
|
+
const subEnd = sp + subLen;
|
|
5656
|
+
if (subId === 5) {
|
|
5657
|
+
const subCopy = new Uint8Array(buf.subarray(subStart, subEnd));
|
|
5658
|
+
let [cnt, cur] = readULEB(buf, sp);
|
|
5659
|
+
for (let i = 0; i < cnt; i++) {
|
|
5660
|
+
const [sLen, s2] = readULEB(buf, cur);
|
|
5661
|
+
const segName = obj.segNames[i];
|
|
5662
|
+
const isSpecial = segName === "swift5_type_metadata" || segName === "swift5_protocol_conformances" || segName === "__objc_classes";
|
|
5663
|
+
if (deadSpecialSegs.has(i)) {
|
|
5664
|
+
let repl = "";
|
|
5665
|
+
if (segName === "swift5_type_metadata") repl = ".dead_swift5_type_md";
|
|
5666
|
+
else if (segName === "swift5_protocol_conformances")
|
|
5667
|
+
repl = ".dead_swift5_protocol_confor";
|
|
5668
|
+
else if (segName === "__objc_classes") repl = ".dead_objc_cls";
|
|
5669
|
+
if (repl.length === sLen) {
|
|
5670
|
+
subCopy.set(Buffer.from(repl, "utf8"), s2 - subStart);
|
|
5671
|
+
}
|
|
5672
|
+
}
|
|
5673
|
+
cur = s2 + sLen;
|
|
5674
|
+
const [, s3] = readULEB(buf, cur);
|
|
5675
|
+
const [segFl, s4] = readULEB(buf, s3);
|
|
5676
|
+
const sFlLen = s4 - s3;
|
|
5677
|
+
const keepRetain = isSpecial ? !deadSpecialSegs.has(i) : isRootSegName(segName) && !segName.startsWith(".init_array") && sLive[i] === 1;
|
|
5678
|
+
const newSegFl = keepRetain ? segFl | 4 : segFl & ~4;
|
|
5679
|
+
if (sFlLen === 1) {
|
|
5680
|
+
subCopy[s3 - subStart] = newSegFl;
|
|
5681
|
+
} else if (sFlLen === 2) {
|
|
5682
|
+
subCopy[s3 - subStart] = newSegFl & 127 | 128;
|
|
5683
|
+
subCopy[s3 - subStart + 1] = newSegFl >> 7;
|
|
5684
|
+
}
|
|
5685
|
+
cur = s4;
|
|
5686
|
+
}
|
|
5687
|
+
subChunks.push(subCopy);
|
|
5688
|
+
} else if (subId === 6) {
|
|
5689
|
+
let [cnt, cur] = readULEB(buf, sp);
|
|
5690
|
+
const entrySlices = [];
|
|
5691
|
+
for (let i = 0; i < cnt; i++) {
|
|
5692
|
+
const eStart = cur;
|
|
5693
|
+
const [, s2] = readULEB(buf, cur);
|
|
5694
|
+
const [symIdx, s3] = readULEB(buf, s2);
|
|
5695
|
+
cur = s3;
|
|
5696
|
+
if (obj.symKind[symIdx] === 0 && obj.symElemIdx[symIdx] >= obj.numImportFuncs) {
|
|
5697
|
+
if (fLive[obj.symElemIdx[symIdx] - obj.numImportFuncs] === 1) {
|
|
5698
|
+
entrySlices.push(buf.subarray(eStart, cur));
|
|
5699
|
+
}
|
|
5700
|
+
} else {
|
|
5701
|
+
entrySlices.push(buf.subarray(eStart, cur));
|
|
5702
|
+
}
|
|
5703
|
+
}
|
|
5704
|
+
if (entrySlices.length > 0) {
|
|
5705
|
+
const cntBytes = Uint8Array.from(encodeULEB(entrySlices.length));
|
|
5706
|
+
const bodyLen = cntBytes.length + entrySlices.reduce((a, b) => a + b.length, 0);
|
|
5707
|
+
const lenBytes = Uint8Array.from(encodeULEB(bodyLen));
|
|
5708
|
+
subChunks.push(Uint8Array.of(6), lenBytes, cntBytes, ...entrySlices);
|
|
5709
|
+
}
|
|
5710
|
+
} else if (subId === 8) {
|
|
5711
|
+
const subCopy = new Uint8Array(buf.subarray(subStart, subEnd));
|
|
5712
|
+
let [cnt, cur] = readULEB(buf, sp);
|
|
5713
|
+
for (let i = 0; i < cnt; i++) {
|
|
5714
|
+
const kind = buf[cur++];
|
|
5715
|
+
const flOffset = cur - subStart;
|
|
5716
|
+
const [fl, c2] = readULEB(buf, cur);
|
|
5717
|
+
cur = c2;
|
|
5718
|
+
const isUndef = (fl & 16) !== 0;
|
|
5719
|
+
const isExplicitName = (fl & 64) !== 0;
|
|
5720
|
+
const flLen = c2 - (flOffset + subStart);
|
|
5721
|
+
let newFl = fl & 127;
|
|
5722
|
+
if (isUndef && (kind === 0 || kind === 1) && !usedSyms.has(i)) {
|
|
5723
|
+
newFl = (fl & ~3 | 1) & 127;
|
|
5724
|
+
} else if (!isUndef && kind === 0 && obj.symElemIdx[i] >= obj.numImportFuncs && fLive[obj.symElemIdx[i] - obj.numImportFuncs] === 0) {
|
|
5725
|
+
newFl = fl & 64 | 2;
|
|
5726
|
+
}
|
|
5727
|
+
if (flLen === 1) {
|
|
5728
|
+
subCopy[flOffset] = newFl;
|
|
5729
|
+
} else if (flLen === 2) {
|
|
5730
|
+
subCopy[flOffset] = newFl | 128;
|
|
5731
|
+
subCopy[flOffset + 1] = 0;
|
|
5732
|
+
}
|
|
5733
|
+
if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
|
|
5734
|
+
const [, c3] = readULEB(buf, cur);
|
|
5735
|
+
cur = c3;
|
|
5736
|
+
if (!isUndef || isExplicitName) {
|
|
5737
|
+
const [sLen, c4] = readULEB(buf, cur);
|
|
5738
|
+
cur = c4 + sLen;
|
|
5739
|
+
}
|
|
5740
|
+
} else if (kind === 1) {
|
|
5741
|
+
const [sLen, c3] = readULEB(buf, cur);
|
|
5742
|
+
cur = c3 + sLen;
|
|
5743
|
+
if (!isUndef) {
|
|
5744
|
+
const [, c4] = readULEB(buf, cur);
|
|
5745
|
+
const [, c5] = readULEB(buf, c4);
|
|
5746
|
+
const [, c6] = readULEB(buf, c5);
|
|
5747
|
+
cur = c6;
|
|
5748
|
+
}
|
|
5749
|
+
} else if (kind === 3) {
|
|
5750
|
+
const [, c3] = readULEB(buf, cur);
|
|
5751
|
+
cur = c3;
|
|
5752
|
+
}
|
|
5753
|
+
}
|
|
5754
|
+
subChunks.push(subCopy);
|
|
5755
|
+
} else {
|
|
5756
|
+
subChunks.push(buf.subarray(subStart, subEnd));
|
|
5757
|
+
}
|
|
5758
|
+
lp = subEnd;
|
|
5759
|
+
}
|
|
5760
|
+
const totalSubLen = subChunks.reduce((a, b) => a + b.length, 0);
|
|
5761
|
+
outChunks.push(
|
|
5762
|
+
Uint8Array.of(0),
|
|
5763
|
+
Uint8Array.from(encodeULEB(totalSubLen)),
|
|
5764
|
+
...subChunks
|
|
5765
|
+
);
|
|
5766
|
+
} else if (name2 === "reloc.CODE") {
|
|
5767
|
+
const [, r1] = readULEB(buf, cp);
|
|
5768
|
+
const headerSlice = buf.subarray(p, r1);
|
|
5769
|
+
const cntBytes = Uint8Array.from(encodeULEB(keptCodeRelocs.length));
|
|
5770
|
+
const relSlices = keptCodeRelocs.map((r) => r.rawBytes);
|
|
5771
|
+
const totalLen = headerSlice.length + cntBytes.length + relSlices.reduce((a, b) => a + b.length, 0);
|
|
5772
|
+
outChunks.push(
|
|
5773
|
+
Uint8Array.of(0),
|
|
5774
|
+
Uint8Array.from(encodeULEB(totalLen)),
|
|
5775
|
+
headerSlice,
|
|
5776
|
+
cntBytes,
|
|
5777
|
+
...relSlices
|
|
5778
|
+
);
|
|
5779
|
+
} else if (name2 === "reloc.DATA") {
|
|
5780
|
+
const [, r1] = readULEB(buf, cp);
|
|
5781
|
+
const headerSlice = buf.subarray(p, r1);
|
|
5782
|
+
const cntBytes = Uint8Array.from(encodeULEB(keptDataRelocBytes.length));
|
|
5783
|
+
const totalLen = headerSlice.length + cntBytes.length + keptDataRelocBytes.reduce((a, b) => a + b.length, 0);
|
|
5784
|
+
outChunks.push(
|
|
5785
|
+
Uint8Array.of(0),
|
|
5786
|
+
Uint8Array.from(encodeULEB(totalLen)),
|
|
5787
|
+
headerSlice,
|
|
5788
|
+
cntBytes,
|
|
5789
|
+
...keptDataRelocBytes
|
|
5790
|
+
);
|
|
5791
|
+
} else if (name2 === ".swift1_autolink_entries") {
|
|
5792
|
+
} else {
|
|
5793
|
+
outChunks.push(buf.subarray(secStart, end));
|
|
5794
|
+
}
|
|
5795
|
+
} else {
|
|
5796
|
+
if (id === 11 && zeroDataRelocOffsets.length > 0) {
|
|
5797
|
+
for (const ro of zeroDataRelocOffsets) {
|
|
5798
|
+
buf.fill(0, p + ro, p + ro + 4);
|
|
5799
|
+
}
|
|
5800
|
+
}
|
|
5801
|
+
outChunks.push(buf.subarray(secStart, end));
|
|
5802
|
+
}
|
|
5803
|
+
pos = end;
|
|
5804
|
+
}
|
|
5805
|
+
import_node_fs8.default.writeFileSync(outFile, Buffer.concat(outChunks));
|
|
5806
|
+
};
|
|
5807
|
+
const prunableCandidates = [
|
|
5808
|
+
...distFiles,
|
|
5809
|
+
...sdkFiles.filter((f) => isPrunableSdkFile(f))
|
|
5810
|
+
];
|
|
5811
|
+
const reachedPrunableObjs = prunableCandidates.map((f) => distObjs.get(f)).filter((o) => extractedObjs.has(o));
|
|
5812
|
+
const prunedMap = /* @__PURE__ */ new Map();
|
|
5813
|
+
for (const o of reachedPrunableObjs) {
|
|
5814
|
+
const outPath = import_node_path12.default.join(prunedObjsDir, import_node_path12.default.basename(o.file));
|
|
5815
|
+
writePrunedObject(o, outPath);
|
|
5816
|
+
prunedMap.set(o.file, outPath);
|
|
5817
|
+
}
|
|
5818
|
+
const extraCoreConcurrencyObjs = allSdkObjFiles.filter(
|
|
5819
|
+
(f) => f.startsWith("libswiftCore__") && f !== "libswiftCore__Swift.o" || f.startsWith("libswift_Concurrency__") && f !== "libswift_Concurrency___Concurrency.o"
|
|
5820
|
+
).map((f) => import_node_path12.default.join(sdkObjsDir, f));
|
|
5821
|
+
const outTokens = [];
|
|
5822
|
+
const emittedPruned = /* @__PURE__ */ new Set();
|
|
5823
|
+
inStartLib = false;
|
|
5824
|
+
for (const t of tokens) {
|
|
5825
|
+
if (t === "--start-lib") {
|
|
5826
|
+
inStartLib = true;
|
|
5827
|
+
outTokens.push("--start-lib");
|
|
5828
|
+
for (const rf of prunableCandidates) {
|
|
5829
|
+
if (emittedPruned.has(rf)) continue;
|
|
5830
|
+
if (prunedMap.has(rf)) {
|
|
5831
|
+
outTokens.push(prunedMap.get(rf));
|
|
5832
|
+
emittedPruned.add(rf);
|
|
5833
|
+
} else if (rf.startsWith(distDir)) {
|
|
5834
|
+
const m = getModulePrefix(rf);
|
|
5835
|
+
if (m === "PeachICU" || m === "Darwin") {
|
|
5836
|
+
outTokens.push(rf);
|
|
5837
|
+
}
|
|
5838
|
+
}
|
|
5839
|
+
}
|
|
5840
|
+
outTokens.push(...extraCoreConcurrencyObjs);
|
|
5841
|
+
continue;
|
|
5842
|
+
}
|
|
5843
|
+
if (t === "--end-lib") {
|
|
5844
|
+
inStartLib = false;
|
|
5845
|
+
outTokens.push("--end-lib");
|
|
5846
|
+
continue;
|
|
5847
|
+
}
|
|
5848
|
+
if (inStartLib) continue;
|
|
5849
|
+
if (t === swiftrtOrigPath && patchedSwiftrtPath) {
|
|
5850
|
+
outTokens.push(patchedSwiftrtPath);
|
|
5851
|
+
} else if (prunedMap.has(t)) {
|
|
5852
|
+
outTokens.push(prunedMap.get(t));
|
|
5853
|
+
emittedPruned.add(t);
|
|
5854
|
+
} else if (OMIT_SDK_LIB_FLAGS.has(t)) {
|
|
5855
|
+
continue;
|
|
5856
|
+
} else {
|
|
5857
|
+
outTokens.push(t);
|
|
5858
|
+
}
|
|
5859
|
+
}
|
|
5860
|
+
const prunedRspPath = import_node_path12.default.join(directory, ".peach-link.pruned.rsp");
|
|
5861
|
+
import_node_fs8.default.writeFileSync(prunedRspPath, outTokens.map((t) => JSON.stringify(t)).join(" "));
|
|
5862
|
+
(0, import_node_child_process8.execFileSync)(import_node_path12.default.join(toolchainBin, "wasm-ld"), [`@${prunedRspPath}`], {
|
|
5863
|
+
stdio: "pipe"
|
|
5864
|
+
});
|
|
5865
|
+
import_node_fs8.default.rmSync(rspPath, { force: true });
|
|
5866
|
+
}
|
|
5867
|
+
|
|
4358
5868
|
// src/swiftContract.ts
|
|
4359
5869
|
var SWIFT_REMOTE_PACKAGES_DIR = "__packages__";
|
|
4360
5870
|
var SWIFT_LOCAL_PACKAGES_DIR = "__local_packages__";
|
|
@@ -4457,9 +5967,36 @@ function isSwiftResourceBundles(value) {
|
|
|
4457
5967
|
) && new Set(value.map((bundle) => bundle.target)).size === value.length && new Set(value.map((bundle) => bundle.path)).size === value.length;
|
|
4458
5968
|
}
|
|
4459
5969
|
|
|
5970
|
+
// src/wasm-optimize.ts
|
|
5971
|
+
var import_wasm_opt = require("wasm-opt");
|
|
5972
|
+
var FEATURES = [
|
|
5973
|
+
"threads",
|
|
5974
|
+
"bulk-memory",
|
|
5975
|
+
"bulk-memory-opt",
|
|
5976
|
+
"call-indirect-overlong",
|
|
5977
|
+
"exception-handling",
|
|
5978
|
+
"multivalue",
|
|
5979
|
+
"mutable-globals",
|
|
5980
|
+
"nontrapping-float-to-int",
|
|
5981
|
+
"reference-types",
|
|
5982
|
+
"sign-ext"
|
|
5983
|
+
];
|
|
5984
|
+
var WASM_OPTIMIZE_IDENTITY = `wasm-opt ${import_wasm_opt.BINARYEN_VERSION} -Oz ${FEATURES.join(",")}`;
|
|
5985
|
+
async function optimizeWasm(file, output) {
|
|
5986
|
+
const result = await (0, import_wasm_opt.wasmOpt)([
|
|
5987
|
+
"-Oz",
|
|
5988
|
+
...FEATURES.map((feature) => `--enable-${feature}`),
|
|
5989
|
+
file,
|
|
5990
|
+
"-o",
|
|
5991
|
+
output
|
|
5992
|
+
]);
|
|
5993
|
+
if (result.status !== 0)
|
|
5994
|
+
throw new Error(`wasm-opt exited ${result.status}: ${result.stderr}`);
|
|
5995
|
+
}
|
|
5996
|
+
|
|
4460
5997
|
// src/xcode-header-search.ts
|
|
4461
|
-
var
|
|
4462
|
-
var
|
|
5998
|
+
var import_node_fs9 = __toESM(require("node:fs"), 1);
|
|
5999
|
+
var import_node_path13 = __toESM(require("node:path"), 1);
|
|
4463
6000
|
function headerMap(entries) {
|
|
4464
6001
|
const unique = /* @__PURE__ */ new Map();
|
|
4465
6002
|
for (const entry of entries)
|
|
@@ -4502,16 +6039,16 @@ function headerMap(entries) {
|
|
|
4502
6039
|
return Buffer.concat([table, ...strings]);
|
|
4503
6040
|
}
|
|
4504
6041
|
function writeXcodeHeaderSearch(directory, targets) {
|
|
4505
|
-
|
|
6042
|
+
import_node_fs9.default.mkdirSync(directory, { recursive: true });
|
|
4506
6043
|
const productDirectories = /* @__PURE__ */ new Map();
|
|
4507
6044
|
for (const target of targets)
|
|
4508
6045
|
for (const [product, file] of Object.entries(target.productHeaders)) {
|
|
4509
|
-
const listed = productDirectories.get(
|
|
4510
|
-
productDirectories.set(
|
|
4511
|
-
listed.push({ name:
|
|
6046
|
+
const listed = productDirectories.get(import_node_path13.default.dirname(product)) ?? [];
|
|
6047
|
+
productDirectories.set(import_node_path13.default.dirname(product), listed);
|
|
6048
|
+
listed.push({ name: import_node_path13.default.basename(product), file });
|
|
4512
6049
|
}
|
|
4513
|
-
const overlay =
|
|
4514
|
-
|
|
6050
|
+
const overlay = import_node_path13.default.join(directory, "all-product-headers.yaml");
|
|
6051
|
+
import_node_fs9.default.writeFileSync(
|
|
4515
6052
|
overlay,
|
|
4516
6053
|
JSON.stringify({
|
|
4517
6054
|
"case-sensitive": "false",
|
|
@@ -4530,8 +6067,8 @@ function writeXcodeHeaderSearch(directory, targets) {
|
|
|
4530
6067
|
const files = [overlay];
|
|
4531
6068
|
const flags = targets.map((target, index) => {
|
|
4532
6069
|
const maps = target.headerMaps.map((map, order) => {
|
|
4533
|
-
const file =
|
|
4534
|
-
|
|
6070
|
+
const file = import_node_path13.default.join(directory, `${index}-${order}.hmap`);
|
|
6071
|
+
import_node_fs9.default.writeFileSync(file, headerMap(map.entries));
|
|
4535
6072
|
files.push(file);
|
|
4536
6073
|
return { flag: map.flag, file };
|
|
4537
6074
|
});
|
|
@@ -4556,7 +6093,7 @@ async function runCompiler(command, args, options, stream = false, quiet) {
|
|
|
4556
6093
|
detached: true,
|
|
4557
6094
|
stdio: ["ignore", "pipe", "pipe"]
|
|
4558
6095
|
};
|
|
4559
|
-
const child = options.lease ? options.lease.spawn(command, args, launch) : (0,
|
|
6096
|
+
const child = options.lease ? options.lease.spawn(command, args, launch) : (0, import_node_child_process9.spawn)(command, args, launch);
|
|
4560
6097
|
let stopping;
|
|
4561
6098
|
try {
|
|
4562
6099
|
return await new Promise((resolve, reject) => {
|
|
@@ -4637,7 +6174,7 @@ var admittedCores = Number(process.env.TM_EXEC_CPU_CORES);
|
|
|
4637
6174
|
var BUILD_JOBS = String(
|
|
4638
6175
|
Math.min(
|
|
4639
6176
|
4,
|
|
4640
|
-
Math.max(1, Math.floor(
|
|
6177
|
+
Math.max(1, Math.floor(import_node_os5.default.availableParallelism() / 2)),
|
|
4641
6178
|
Number.isInteger(admittedCores) && admittedCores > 0 ? admittedCores : 4
|
|
4642
6179
|
)
|
|
4643
6180
|
);
|
|
@@ -4647,10 +6184,39 @@ function swiftBuilderHopTimeoutMs(compileTimeoutMs) {
|
|
|
4647
6184
|
return (compileTimeoutMs ?? SWIFT_BUILDER_DEFAULT_COMPILE_MS) + SWIFT_BUILDER_TRANSPORT_MARGIN_MS;
|
|
4648
6185
|
}
|
|
4649
6186
|
function swiftDistributionAt(root) {
|
|
4650
|
-
const file =
|
|
4651
|
-
if (!(0,
|
|
4652
|
-
return parseSwiftDistributionManifest(JSON.parse((0,
|
|
6187
|
+
const file = import_node_path14.default.join(root, SWIFT_DISTRIBUTION_MANIFEST);
|
|
6188
|
+
if (!(0, import_node_fs10.existsSync)(file)) return null;
|
|
6189
|
+
return parseSwiftDistributionManifest(JSON.parse((0, import_node_fs10.readFileSync)(file, "utf8")));
|
|
6190
|
+
}
|
|
6191
|
+
function swiftModuleInterface(moduleRoot, name2) {
|
|
6192
|
+
if (swiftDistributionAt(moduleRoot)) {
|
|
6193
|
+
const file = import_node_path14.default.join(moduleRoot, "modules", `${name2}-Swift.h`);
|
|
6194
|
+
if (!(0, import_node_fs10.existsSync)(file)) return null;
|
|
6195
|
+
const header = clangInterfaceHeader((0, import_node_fs10.readFileSync)(file, "utf8"));
|
|
6196
|
+
return { declared: swiftInterfaceDeclarations(header), header };
|
|
6197
|
+
}
|
|
6198
|
+
const sources = import_node_path14.default.join(moduleRoot, "Sources", name2);
|
|
6199
|
+
if (!(0, import_node_fs10.existsSync)(sources)) return null;
|
|
6200
|
+
const declared = /* @__PURE__ */ new Set();
|
|
6201
|
+
for (const file of (0, import_node_fs10.readdirSync)(sources, { recursive: true, encoding: "utf8" }))
|
|
6202
|
+
if (file.endsWith(".swift"))
|
|
6203
|
+
for (const [, objc] of (0, import_node_fs10.readFileSync)(import_node_path14.default.join(sources, file), "utf8").matchAll(
|
|
6204
|
+
/@objc\((\w+)\)\s+(?:\w+\s+)*?(?:protocol|class)\s/g
|
|
6205
|
+
))
|
|
6206
|
+
declared.add(objc);
|
|
6207
|
+
if (declared.size === 0) return null;
|
|
6208
|
+
const built = import_node_path14.default.join(moduleRoot, ".build/host", `${name2}-Swift.h`);
|
|
6209
|
+
return {
|
|
6210
|
+
declared,
|
|
6211
|
+
header: (0, import_node_fs10.existsSync)(built) ? clangInterfaceHeader((0, import_node_fs10.readFileSync)(built, "utf8")) : `// ${name2}-Swift.h is generated when ${name2} builds
|
|
6212
|
+
`
|
|
6213
|
+
};
|
|
4653
6214
|
}
|
|
6215
|
+
var clangInterfaceHeader = (header) => header.replace(/^@import UIKitCore;$/m, "@import UIKit;");
|
|
6216
|
+
var swiftInterfaceDeclarations = (header) => /* @__PURE__ */ new Set([
|
|
6217
|
+
...[...header.matchAll(/^@protocol\s+(\w+)\b(?![^\n]*;\s*$)/gm)].map((m) => m[1]),
|
|
6218
|
+
...[...header.matchAll(/^@interface\s+(\w+)\s*(?=[:<{]|$)/gm)].map((m) => m[1])
|
|
6219
|
+
]);
|
|
4654
6220
|
function swiftModuleSdk(root) {
|
|
4655
6221
|
const pin = swiftDistributionAt(root) ?? swiftSourceSdk(root);
|
|
4656
6222
|
return {
|
|
@@ -4659,12 +6225,21 @@ function swiftModuleSdk(root) {
|
|
|
4659
6225
|
wasmSdkChecksum: pin.wasmSdkChecksum
|
|
4660
6226
|
};
|
|
4661
6227
|
}
|
|
6228
|
+
function swiftCompileSdkOptions(moduleRoot, toolchainBin) {
|
|
6229
|
+
return swiftSharedSdkViewOptions(
|
|
6230
|
+
moduleRoot,
|
|
6231
|
+
swiftDistributionAt(moduleRoot) !== null,
|
|
6232
|
+
toolchainBin,
|
|
6233
|
+
swiftModuleSdk(moduleRoot).wasmSdkId
|
|
6234
|
+
);
|
|
6235
|
+
}
|
|
4662
6236
|
function swiftModuleInputFiles(root) {
|
|
4663
6237
|
if (swiftDistributionAt(root)) return [SWIFT_DISTRIBUTION_MANIFEST];
|
|
4664
6238
|
const files = [
|
|
4665
6239
|
...swiftSharedSdkInputFiles(root),
|
|
4666
6240
|
"../peachsim/src/swift-shared-sdk.ts",
|
|
4667
6241
|
"../../scripts/generate/swift-sdk-module/darwin-mach.json",
|
|
6242
|
+
"../../scripts/generate/swift-sdk-module/darwin-socketvar.json",
|
|
4668
6243
|
"../../scripts/ops/swift-distribution-publish.ts",
|
|
4669
6244
|
"Package.swift",
|
|
4670
6245
|
"scripts/contrast-app-Package.swift",
|
|
@@ -4680,7 +6255,7 @@ function swiftModuleInputFiles(root) {
|
|
|
4680
6255
|
"toolchain.json"
|
|
4681
6256
|
];
|
|
4682
6257
|
const walk = (dir) => {
|
|
4683
|
-
for (const entry of (0,
|
|
6258
|
+
for (const entry of (0, import_node_fs10.readdirSync)(import_node_path14.default.join(root, dir), {
|
|
4684
6259
|
withFileTypes: true
|
|
4685
6260
|
})) {
|
|
4686
6261
|
const relative = `${dir}/${entry.name}`;
|
|
@@ -4698,43 +6273,43 @@ function swiftMacroPlugins(moduleRoot) {
|
|
|
4698
6273
|
const distribution = swiftDistributionAt(moduleRoot);
|
|
4699
6274
|
if (distribution)
|
|
4700
6275
|
return {
|
|
4701
|
-
libraries: distribution.plugins.filter((plugin) =>
|
|
4702
|
-
executables: distribution.plugins.filter((plugin) =>
|
|
6276
|
+
libraries: distribution.plugins.filter((plugin) => import_node_path14.default.basename(plugin) !== "ExpoModulesMacros").map((plugin) => import_node_path14.default.join(moduleRoot, plugin)),
|
|
6277
|
+
executables: distribution.plugins.filter((plugin) => import_node_path14.default.basename(plugin) === "ExpoModulesMacros").map((plugin) => import_node_path14.default.join(moduleRoot, plugin)),
|
|
4703
6278
|
stale: false
|
|
4704
6279
|
};
|
|
4705
|
-
const dir =
|
|
6280
|
+
const dir = import_node_path14.default.join(moduleRoot, ".build/host/RnxPreviewMacros");
|
|
4706
6281
|
const release = JSON.parse(
|
|
4707
|
-
(0,
|
|
6282
|
+
(0, import_node_fs10.readFileSync)(import_node_path14.default.join(moduleRoot, "toolchain.json"), "utf8")
|
|
4708
6283
|
).release;
|
|
4709
|
-
const compilerStamp =
|
|
4710
|
-
const pluginScript =
|
|
4711
|
-
const expoPlugin =
|
|
6284
|
+
const compilerStamp = import_node_path14.default.join(dir, "compiler-release");
|
|
6285
|
+
const pluginScript = import_node_path14.default.join(moduleRoot, "scripts/build-preview-plugin.sh");
|
|
6286
|
+
const expoPlugin = import_node_path14.default.join(dir, "ExpoModulesMacros");
|
|
4712
6287
|
const ext = process.platform === "darwin" ? "dylib" : "so";
|
|
4713
6288
|
const plugins = [
|
|
4714
6289
|
{
|
|
4715
|
-
library:
|
|
4716
|
-
sources: [
|
|
6290
|
+
library: import_node_path14.default.join(dir, `libRnxPreviewMacros.${ext}`),
|
|
6291
|
+
sources: [import_node_path14.default.join(moduleRoot, "Sources/RnxPreviewMacros/PreviewMacro.swift")]
|
|
4717
6292
|
},
|
|
4718
6293
|
{
|
|
4719
|
-
library:
|
|
6294
|
+
library: import_node_path14.default.join(dir, `libFoundationMacros.${ext}`),
|
|
4720
6295
|
sources: [
|
|
4721
|
-
|
|
4722
|
-
|
|
6296
|
+
import_node_path14.default.join(moduleRoot, "Sources/FoundationMacros/PredicateMacro.swift"),
|
|
6297
|
+
import_node_path14.default.join(moduleRoot, "Sources/SwiftMacroSupport/PredicateExpression.swift")
|
|
4723
6298
|
]
|
|
4724
6299
|
},
|
|
4725
6300
|
{
|
|
4726
|
-
library:
|
|
6301
|
+
library: import_node_path14.default.join(dir, `libTipKitMacros.${ext}`),
|
|
4727
6302
|
sources: [
|
|
4728
|
-
|
|
4729
|
-
|
|
6303
|
+
import_node_path14.default.join(moduleRoot, "Sources/TipKitMacros/TipKitMacros.swift"),
|
|
6304
|
+
import_node_path14.default.join(moduleRoot, "Sources/SwiftMacroSupport/PredicateExpression.swift")
|
|
4730
6305
|
]
|
|
4731
6306
|
}
|
|
4732
6307
|
];
|
|
4733
6308
|
return {
|
|
4734
6309
|
libraries: plugins.map(({ library }) => library),
|
|
4735
6310
|
executables: [expoPlugin],
|
|
4736
|
-
stale: !(0,
|
|
4737
|
-
({ library, sources }) => !(0,
|
|
6311
|
+
stale: !(0, import_node_fs10.existsSync)(compilerStamp) || !(0, import_node_fs10.existsSync)(expoPlugin) || (0, import_node_fs10.statSync)(pluginScript).mtimeMs > (0, import_node_fs10.statSync)(expoPlugin).mtimeMs || (0, import_node_fs10.readFileSync)(compilerStamp, "utf8").trim() !== release || plugins.some(
|
|
6312
|
+
({ library, sources }) => !(0, import_node_fs10.existsSync)(library) || sources.some((source) => (0, import_node_fs10.statSync)(source).mtimeMs > (0, import_node_fs10.statSync)(library).mtimeMs)
|
|
4738
6313
|
)
|
|
4739
6314
|
};
|
|
4740
6315
|
}
|
|
@@ -4744,14 +6319,14 @@ async function ensureMacroPlugins(moduleRoot, toolchainBin, release, signal) {
|
|
|
4744
6319
|
await runCompiler(
|
|
4745
6320
|
"sh",
|
|
4746
6321
|
[
|
|
4747
|
-
|
|
6322
|
+
import_node_path14.default.join(moduleRoot, "scripts/build-preview-plugin.sh"),
|
|
4748
6323
|
toolchainBin,
|
|
4749
6324
|
libraries[0]
|
|
4750
6325
|
],
|
|
4751
6326
|
{ signal }
|
|
4752
6327
|
);
|
|
4753
|
-
(0,
|
|
4754
|
-
|
|
6328
|
+
(0, import_node_fs10.writeFileSync)(
|
|
6329
|
+
import_node_path14.default.join(import_node_path14.default.dirname(libraries[0]), "compiler-release"),
|
|
4755
6330
|
`${release}
|
|
4756
6331
|
`
|
|
4757
6332
|
);
|
|
@@ -4765,9 +6340,9 @@ function clearLinkedModuleDigests(root) {
|
|
|
4765
6340
|
}
|
|
4766
6341
|
function swiftModuleDigest(root) {
|
|
4767
6342
|
const files = swiftModuleInputFiles(root);
|
|
4768
|
-
const stampHash = (0,
|
|
6343
|
+
const stampHash = (0, import_node_crypto7.createHash)("sha256");
|
|
4769
6344
|
for (const file of files) {
|
|
4770
|
-
const stat = (0,
|
|
6345
|
+
const stat = (0, import_node_fs10.statSync)(import_node_path14.default.join(root, file), { bigint: true });
|
|
4771
6346
|
stampHash.update(file);
|
|
4772
6347
|
stampHash.update(
|
|
4773
6348
|
`${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}
|
|
@@ -4777,11 +6352,11 @@ function swiftModuleDigest(root) {
|
|
|
4777
6352
|
const stamp = stampHash.digest("hex");
|
|
4778
6353
|
const cached = linkedModuleDigests.get(root);
|
|
4779
6354
|
if (cached?.stamp === stamp) return cached.digest;
|
|
4780
|
-
const hash = (0,
|
|
6355
|
+
const hash = (0, import_node_crypto7.createHash)("sha256");
|
|
4781
6356
|
for (const file of files) {
|
|
4782
|
-
hash.update((0,
|
|
6357
|
+
hash.update((0, import_node_crypto7.createHash)("sha256").update(file).digest());
|
|
4783
6358
|
hash.update(
|
|
4784
|
-
(0,
|
|
6359
|
+
(0, import_node_crypto7.createHash)("sha256").update((0, import_node_fs10.readFileSync)(import_node_path14.default.join(root, file))).digest()
|
|
4785
6360
|
);
|
|
4786
6361
|
}
|
|
4787
6362
|
const digest = hash.digest();
|
|
@@ -4789,7 +6364,7 @@ function swiftModuleDigest(root) {
|
|
|
4789
6364
|
return digest;
|
|
4790
6365
|
}
|
|
4791
6366
|
function swiftProjectBuildKey(moduleRoot, release) {
|
|
4792
|
-
return (0,
|
|
6367
|
+
return (0, import_node_crypto7.createHash)("sha256").update(`${release}\0${swiftModuleSdk(moduleRoot).wasmSdkId}`).update(swiftModuleDigest(moduleRoot)).digest("hex").slice(0, 32);
|
|
4793
6368
|
}
|
|
4794
6369
|
function compileTargets(input) {
|
|
4795
6370
|
const manifest = input.files["Package.swift"];
|
|
@@ -4805,7 +6380,7 @@ function withNativeSourceGlue(input, glue) {
|
|
|
4805
6380
|
...input,
|
|
4806
6381
|
files: {
|
|
4807
6382
|
...input.files,
|
|
4808
|
-
[
|
|
6383
|
+
[import_node_path14.default.posix.join(targetPath, "OneNativeSource.generated.swift")]: glue
|
|
4809
6384
|
},
|
|
4810
6385
|
oneModule: true
|
|
4811
6386
|
};
|
|
@@ -4945,21 +6520,22 @@ function swiftImportNames(contents, available) {
|
|
|
4945
6520
|
function swiftPeachModules(moduleRoot) {
|
|
4946
6521
|
const distribution = swiftDistributionAt(moduleRoot);
|
|
4947
6522
|
return distribution ? distribution.modules : swiftManifestDeclarations(
|
|
4948
|
-
(0,
|
|
6523
|
+
(0, import_node_fs10.readFileSync)(import_node_path14.default.join(moduleRoot, "Package.swift"), "utf8")
|
|
4949
6524
|
).filter((target) => !target.executable && !target.path.startsWith("fixtures/")).map((target) => target.name);
|
|
4950
6525
|
}
|
|
4951
6526
|
var sdkPaths = /* @__PURE__ */ new Map();
|
|
4952
6527
|
function swiftSdkPaths(moduleRoot, toolchainBin) {
|
|
4953
6528
|
const sdk = swiftModuleSdk(moduleRoot).wasmSdkId;
|
|
4954
|
-
const
|
|
6529
|
+
const options = swiftCompileSdkOptions(moduleRoot, toolchainBin);
|
|
6530
|
+
const key = JSON.stringify([toolchainBin, sdk, options]);
|
|
4955
6531
|
const cached = sdkPaths.get(key);
|
|
4956
6532
|
if (cached) return cached;
|
|
4957
|
-
const configuration = (0,
|
|
4958
|
-
|
|
6533
|
+
const configuration = (0, import_node_child_process9.execFileSync)(
|
|
6534
|
+
import_node_path14.default.join(toolchainBin, "swift"),
|
|
4959
6535
|
[
|
|
4960
6536
|
"sdk",
|
|
4961
6537
|
"configure",
|
|
4962
|
-
...
|
|
6538
|
+
...options,
|
|
4963
6539
|
"--show-configuration",
|
|
4964
6540
|
sdk,
|
|
4965
6541
|
"wasm32-unknown-wasip1"
|
|
@@ -4980,30 +6556,30 @@ function swiftSdkPaths(moduleRoot, toolchainBin) {
|
|
|
4980
6556
|
if (!Array.isArray(toolsets) || !toolsets.every((value) => typeof value === "string"))
|
|
4981
6557
|
throw new Error(`swift sdk ${sdk} reports invalid toolset paths`);
|
|
4982
6558
|
for (const toolset of toolsets) {
|
|
4983
|
-
const config = JSON.parse((0,
|
|
6559
|
+
const config = JSON.parse((0, import_node_fs10.readFileSync)(toolset, "utf8"));
|
|
4984
6560
|
if (!config || typeof config !== "object" || !("swiftCompiler" in config)) continue;
|
|
4985
6561
|
const compiler = config.swiftCompiler;
|
|
4986
6562
|
if (!compiler || typeof compiler !== "object" || !("extraCLIOptions" in compiler))
|
|
4987
6563
|
continue;
|
|
4988
|
-
const
|
|
4989
|
-
if (!Array.isArray(
|
|
6564
|
+
const options2 = compiler.extraCLIOptions;
|
|
6565
|
+
if (!Array.isArray(options2) || !options2.every((value) => typeof value === "string"))
|
|
4990
6566
|
throw new Error(
|
|
4991
6567
|
`swift sdk ${sdk} has invalid swift compiler options in ${toolset}`
|
|
4992
6568
|
);
|
|
4993
|
-
for (let index = 0; index <
|
|
4994
|
-
if (
|
|
4995
|
-
const flag =
|
|
6569
|
+
for (let index = 0; index < options2.length; index++) {
|
|
6570
|
+
if (options2[index] === "-Xcc" && typeof options2[index + 1] === "string") {
|
|
6571
|
+
const flag = options2[index + 1];
|
|
4996
6572
|
if (flag !== "-fwasm-exceptions") cFlags.push(flag);
|
|
4997
|
-
if (flag === "-iframeworkwithsysroot" &&
|
|
4998
|
-
cFlags.push(
|
|
4999
|
-
frameworks.push(
|
|
6573
|
+
if (flag === "-iframeworkwithsysroot" && options2[index + 2] === "-Xcc" && typeof options2[index + 3] === "string") {
|
|
6574
|
+
cFlags.push(options2[index + 3]);
|
|
6575
|
+
frameworks.push(import_node_path14.default.join(sysroot, options2[index + 3]));
|
|
5000
6576
|
index += 3;
|
|
5001
6577
|
continue;
|
|
5002
6578
|
}
|
|
5003
6579
|
index += 1;
|
|
5004
6580
|
continue;
|
|
5005
6581
|
}
|
|
5006
|
-
const option =
|
|
6582
|
+
const option = options2[index];
|
|
5007
6583
|
if (option.startsWith("-iframework") || option.startsWith("-F"))
|
|
5008
6584
|
throw new Error(
|
|
5009
6585
|
`swift sdk ${sdk} has an unsupported framework search option ${option}`
|
|
@@ -5013,7 +6589,7 @@ function swiftSdkPaths(moduleRoot, toolchainBin) {
|
|
|
5013
6589
|
}
|
|
5014
6590
|
const paths = {
|
|
5015
6591
|
sysroot,
|
|
5016
|
-
darwin:
|
|
6592
|
+
darwin: import_node_path14.default.join(sysroot, "darwin"),
|
|
5017
6593
|
resources: field("swiftResourcesPath"),
|
|
5018
6594
|
frameworks,
|
|
5019
6595
|
cFlags
|
|
@@ -5029,21 +6605,21 @@ function swiftAvailableModules(moduleRoot, toolchainBin) {
|
|
|
5029
6605
|
if (cached) return cached;
|
|
5030
6606
|
const modules = new Set(swiftPeachModules(moduleRoot));
|
|
5031
6607
|
const { resources, frameworks } = swiftSdkPaths(moduleRoot, toolchainBin);
|
|
5032
|
-
for (const entry of (0,
|
|
6608
|
+
for (const entry of (0, import_node_fs10.readdirSync)(import_node_path14.default.join(resources, "wasi"))) {
|
|
5033
6609
|
if (entry.endsWith(".swiftmodule"))
|
|
5034
6610
|
modules.add(entry.slice(0, -".swiftmodule".length));
|
|
5035
6611
|
}
|
|
5036
|
-
for (const entry of (0,
|
|
5037
|
-
const map =
|
|
5038
|
-
if (!(0,
|
|
5039
|
-
for (const match of (0,
|
|
6612
|
+
for (const entry of (0, import_node_fs10.readdirSync)(resources)) {
|
|
6613
|
+
const map = import_node_path14.default.join(resources, entry, "module.modulemap");
|
|
6614
|
+
if (!(0, import_node_fs10.existsSync)(map)) continue;
|
|
6615
|
+
for (const match of (0, import_node_fs10.readFileSync)(map, "utf8").matchAll(/^module\s+([A-Za-z_]\w*)/gm))
|
|
5040
6616
|
modules.add(match[1]);
|
|
5041
6617
|
}
|
|
5042
6618
|
for (const directory of frameworks) {
|
|
5043
|
-
for (const entry of (0,
|
|
5044
|
-
const map =
|
|
5045
|
-
if (!(0,
|
|
5046
|
-
for (const match of (0,
|
|
6619
|
+
for (const entry of (0, import_node_fs10.readdirSync)(directory)) {
|
|
6620
|
+
const map = import_node_path14.default.join(directory, entry, "Modules/module.modulemap");
|
|
6621
|
+
if (!(0, import_node_fs10.existsSync)(map)) continue;
|
|
6622
|
+
for (const match of (0, import_node_fs10.readFileSync)(map, "utf8").matchAll(
|
|
5047
6623
|
/^framework\s+module\s+([A-Za-z_]\w*)/gm
|
|
5048
6624
|
))
|
|
5049
6625
|
modules.add(match[1]);
|
|
@@ -5094,20 +6670,20 @@ function swiftSystemLibraryExclusions(files, targets, distributionModules) {
|
|
|
5094
6670
|
);
|
|
5095
6671
|
}
|
|
5096
6672
|
function distributionModulesPath(root, moduleRoot, excluded) {
|
|
5097
|
-
const modules =
|
|
6673
|
+
const modules = import_node_path14.default.join(moduleRoot, "modules");
|
|
5098
6674
|
if (!excluded || excluded.size === 0) return modules;
|
|
5099
|
-
const key = (0,
|
|
5100
|
-
const directory =
|
|
5101
|
-
const complete =
|
|
5102
|
-
if (!(0,
|
|
5103
|
-
(0,
|
|
5104
|
-
for (const entry of (0,
|
|
5105
|
-
(0,
|
|
5106
|
-
for (const entry of (0,
|
|
6675
|
+
const key = (0, import_node_crypto7.createHash)("sha256").update([...excluded].sort().join("\0")).digest("hex").slice(0, 16);
|
|
6676
|
+
const directory = import_node_path14.default.join(root, `.peach-modules-${key}`);
|
|
6677
|
+
const complete = import_node_path14.default.join(directory, ".complete");
|
|
6678
|
+
if (!(0, import_node_fs10.existsSync)(complete)) {
|
|
6679
|
+
(0, import_node_fs10.mkdirSync)(directory, { recursive: true });
|
|
6680
|
+
for (const entry of (0, import_node_fs10.readdirSync)(directory))
|
|
6681
|
+
(0, import_node_fs10.rmSync)(import_node_path14.default.join(directory, entry), { recursive: true, force: true });
|
|
6682
|
+
for (const entry of (0, import_node_fs10.readdirSync)(modules)) {
|
|
5107
6683
|
if (excluded.has(entry.replace(/\.swiftmodule$/, ""))) continue;
|
|
5108
|
-
(0,
|
|
6684
|
+
(0, import_node_fs10.symlinkSync)(import_node_path14.default.join(modules, entry), import_node_path14.default.join(directory, entry));
|
|
5109
6685
|
}
|
|
5110
|
-
(0,
|
|
6686
|
+
(0, import_node_fs10.writeFileSync)(complete, "");
|
|
5111
6687
|
}
|
|
5112
6688
|
return directory;
|
|
5113
6689
|
}
|
|
@@ -5152,7 +6728,7 @@ var FOUNDATION_IMPLICIT_FLAGS = FOUNDATION_IMPLICIT_MODULES.map(
|
|
|
5152
6728
|
).join("");
|
|
5153
6729
|
var ONE_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "One"';
|
|
5154
6730
|
var executableLinkFlags = (root) => ` "-Xclang-linker", "-O0",
|
|
5155
|
-
"-Xclang-linker", ${JSON.stringify(`-fuse-ld=${
|
|
6731
|
+
"-Xclang-linker", ${JSON.stringify(`-fuse-ld=${import_node_path14.default.join(root, SWIFT_AUTOLINK_LINKER)}`)},
|
|
5156
6732
|
"-Xlinker", "-z", "-Xlinker", "stack-size=8372224",
|
|
5157
6733
|
"-Xlinker", "--stack-first",
|
|
5158
6734
|
"-Xlinker", "--global-base=8372224",
|
|
@@ -5161,44 +6737,47 @@ var executableLinkFlags = (root) => ` "-Xclang-linker", "-O0",
|
|
|
5161
6737
|
"-Xlinker", "--growable-table",
|
|
5162
6738
|
`;
|
|
5163
6739
|
var REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
|
|
5164
|
-
var MULTI_MANIFEST_VERSION =
|
|
5165
|
-
var compilerSourceDigest = true ? "
|
|
6740
|
+
var MULTI_MANIFEST_VERSION = 51;
|
|
6741
|
+
var compilerSourceDigest = true ? "b895d808e6b9911d7c80744af3eb884b635b96b82b69c6903f1e66ebd7485d6c" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
|
|
5166
6742
|
function swiftArtifactHash(input, release, moduleRoot) {
|
|
5167
|
-
const hash = (0,
|
|
6743
|
+
const hash = (0, import_node_crypto7.createHash)("sha256");
|
|
5168
6744
|
hash.update(`swift-compile
|
|
5169
6745
|
${release}
|
|
5170
6746
|
`);
|
|
5171
6747
|
hash.update(compilerSourceDigest);
|
|
5172
6748
|
if (input.oneModule) hash.update("one-module\n");
|
|
5173
6749
|
hash.update(swiftModuleDigest(moduleRoot));
|
|
5174
|
-
if (input.lazyDistribution)
|
|
6750
|
+
if (input.lazyDistribution)
|
|
6751
|
+
hash.update(`lazy-distribution
|
|
6752
|
+
${WASM_OPTIMIZE_IDENTITY}
|
|
6753
|
+
`);
|
|
5175
6754
|
for (const file of Object.keys(input.files).sort()) {
|
|
5176
|
-
hash.update((0,
|
|
5177
|
-
hash.update((0,
|
|
6755
|
+
hash.update((0, import_node_crypto7.createHash)("sha256").update(file).digest());
|
|
6756
|
+
hash.update((0, import_node_crypto7.createHash)("sha256").update(input.files[file]).digest());
|
|
5178
6757
|
}
|
|
5179
6758
|
for (const file of Object.keys(input.metalSources ?? {}).sort()) {
|
|
5180
6759
|
hash.update("metal-source\n");
|
|
5181
|
-
hash.update((0,
|
|
6760
|
+
hash.update((0, import_node_crypto7.createHash)("sha256").update(file).digest());
|
|
5182
6761
|
hash.update(
|
|
5183
|
-
(0,
|
|
6762
|
+
(0, import_node_crypto7.createHash)("sha256").update(input.metalSources?.[file] ?? "").digest()
|
|
5184
6763
|
);
|
|
5185
6764
|
}
|
|
5186
6765
|
for (const base of Object.keys(input.resources ?? {}).sort()) {
|
|
5187
|
-
hash.update((0,
|
|
6766
|
+
hash.update((0, import_node_crypto7.createHash)("sha256").update(base).digest());
|
|
5188
6767
|
hash.update(
|
|
5189
|
-
(0,
|
|
6768
|
+
(0, import_node_crypto7.createHash)("sha256").update(input.resources?.[base] ?? "").digest()
|
|
5190
6769
|
);
|
|
5191
6770
|
}
|
|
5192
6771
|
for (const name2 of Object.keys(input.images ?? {}).sort()) {
|
|
5193
6772
|
const image = input.images?.[name2];
|
|
5194
6773
|
if (!image) continue;
|
|
5195
|
-
hash.update((0,
|
|
5196
|
-
hash.update((0,
|
|
5197
|
-
hash.update((0,
|
|
6774
|
+
hash.update((0, import_node_crypto7.createHash)("sha256").update(name2).digest());
|
|
6775
|
+
hash.update((0, import_node_crypto7.createHash)("sha256").update(image.file).digest());
|
|
6776
|
+
hash.update((0, import_node_crypto7.createHash)("sha256").update(image.data).digest());
|
|
5198
6777
|
}
|
|
5199
6778
|
for (const file of [...new Set(input.resourcePaths ?? [])].sort()) {
|
|
5200
6779
|
hash.update("resource-path\n");
|
|
5201
|
-
hash.update((0,
|
|
6780
|
+
hash.update((0, import_node_crypto7.createHash)("sha256").update(file).digest());
|
|
5202
6781
|
}
|
|
5203
6782
|
hash.update(
|
|
5204
6783
|
JSON.stringify(
|
|
@@ -5213,18 +6792,18 @@ ${input.defaultLocalization}
|
|
|
5213
6792
|
`);
|
|
5214
6793
|
for (const file of Object.keys(input.packageFiles ?? {}).sort()) {
|
|
5215
6794
|
hash.update(`package-file\0${file}\0`);
|
|
5216
|
-
hash.update((0,
|
|
6795
|
+
hash.update((0, import_node_crypto7.createHash)("sha256").update(input.packageFiles[file]).digest());
|
|
5217
6796
|
}
|
|
5218
6797
|
for (const file of Object.keys(input.projectFiles ?? {}).sort()) {
|
|
5219
6798
|
hash.update(`project-file\0${file}\0`);
|
|
5220
|
-
hash.update((0,
|
|
6799
|
+
hash.update((0, import_node_crypto7.createHash)("sha256").update(input.projectFiles[file]).digest());
|
|
5221
6800
|
}
|
|
5222
6801
|
for (const target of Object.keys(input.libraries ?? {}).sort()) {
|
|
5223
6802
|
hash.update(`library
|
|
5224
6803
|
${target}
|
|
5225
6804
|
`);
|
|
5226
6805
|
hash.update(
|
|
5227
|
-
(0,
|
|
6806
|
+
(0, import_node_crypto7.createHash)("sha256").update(input.libraries?.[target] ?? "").digest()
|
|
5228
6807
|
);
|
|
5229
6808
|
}
|
|
5230
6809
|
const targets = compileTargets(input);
|
|
@@ -5243,17 +6822,17 @@ ${target}
|
|
|
5243
6822
|
return hash.digest("hex");
|
|
5244
6823
|
}
|
|
5245
6824
|
function swiftCrossImportFlags(moduleRoot, distribution) {
|
|
5246
|
-
const overlayRoot =
|
|
6825
|
+
const overlayRoot = import_node_path14.default.join(
|
|
5247
6826
|
moduleRoot,
|
|
5248
6827
|
distribution ? "modules" : "cross-import-overlays"
|
|
5249
6828
|
);
|
|
5250
|
-
return (0,
|
|
6829
|
+
return (0, import_node_fs10.readdirSync)(overlayRoot, { encoding: "utf8", recursive: true }).filter((file) => file.endsWith(".swiftoverlay")).sort((left, right) => left.localeCompare(right)).flatMap((file) => [
|
|
5251
6830
|
"-Xfrontend",
|
|
5252
6831
|
"-swift-module-cross-import",
|
|
5253
6832
|
"-Xfrontend",
|
|
5254
|
-
|
|
6833
|
+
import_node_path14.default.basename(import_node_path14.default.dirname(file), ".swiftcrossimport"),
|
|
5255
6834
|
"-Xfrontend",
|
|
5256
|
-
|
|
6835
|
+
import_node_path14.default.join(overlayRoot, file)
|
|
5257
6836
|
]);
|
|
5258
6837
|
}
|
|
5259
6838
|
function withoutWasmOverlayIsystem(flags) {
|
|
@@ -5299,17 +6878,19 @@ function emitSwiftPackageManifest(args) {
|
|
|
5299
6878
|
(name2) => !object.startsWith(`lib/${name2}-`) || reachedFrameworks.has(name2)
|
|
5300
6879
|
)
|
|
5301
6880
|
);
|
|
5302
|
-
const quoted = (object) => `"${
|
|
6881
|
+
const quoted = (object) => `"${import_node_path14.default.join(moduleRoot, object).replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
|
|
5303
6882
|
const roots = args.lazyDistribution ? swiftObjcRootObjects(distribution.id, moduleRoot, distribution.objects) : null;
|
|
5304
6883
|
const list = (roots ? [
|
|
5305
6884
|
...objects.filter((object) => roots.has(object)).map(quoted),
|
|
5306
6885
|
"-Wl,--start-lib",
|
|
5307
|
-
...objects.filter(
|
|
6886
|
+
...objects.filter(
|
|
6887
|
+
(object) => !roots.has(object) && object !== "lib/Foundation-NSStringFormatting.o"
|
|
6888
|
+
).map(quoted),
|
|
5308
6889
|
"-Wl,--end-lib"
|
|
5309
6890
|
] : objects.map(quoted)).join("\n") + "\n";
|
|
5310
6891
|
distributionLinkPath = distributionLink.path.replace(
|
|
5311
6892
|
/\.rsp$/,
|
|
5312
|
-
`-${(0,
|
|
6893
|
+
`-${(0, import_node_crypto7.createHash)("sha256").update(list).digest("hex").slice(0, 12)}.rsp`
|
|
5313
6894
|
);
|
|
5314
6895
|
distributionLink.files.set(distributionLinkPath, list);
|
|
5315
6896
|
}
|
|
@@ -5323,7 +6904,7 @@ function emitSwiftPackageManifest(args) {
|
|
|
5323
6904
|
const stanza = (target) => {
|
|
5324
6905
|
const native = args.native?.get(target.name);
|
|
5325
6906
|
if (target.systemLibrary || native?.clang?.sources.length === 0)
|
|
5326
|
-
return ` .systemLibrary(name: ${JSON.stringify(target.name)}, path: ${JSON.stringify(native?.clang ?
|
|
6907
|
+
return ` .systemLibrary(name: ${JSON.stringify(target.name)}, path: ${JSON.stringify(native?.clang ? import_node_path14.default.posix.dirname(native.clang.modulemap) : target.path)}),`;
|
|
5327
6908
|
const isolation = target.mainActorIsolation ? " .defaultIsolation(MainActor.self)," : "";
|
|
5328
6909
|
const interoperability = target.cxxInterop ? " .interoperabilityMode(.Cxx)," : "";
|
|
5329
6910
|
const defines = (target.defines ?? []).map((name2) => ` .define(${JSON.stringify(name2)}),`).join("");
|
|
@@ -5364,12 +6945,12 @@ function emitSwiftPackageManifest(args) {
|
|
|
5364
6945
|
].map((flag) => `, ${JSON.stringify(flag)}`).join("");
|
|
5365
6946
|
const header = args.headerDirectory && [...args.native?.values() ?? []].some(
|
|
5366
6947
|
(value) => value.late?.producers.includes(target.name)
|
|
5367
|
-
) ? `, "-emit-objc-header-path", ${JSON.stringify(
|
|
6948
|
+
) ? `, "-emit-objc-header-path", ${JSON.stringify(import_node_path14.default.join(args.headerDirectory, `${target.name}-Swift.h`))}` : "";
|
|
5368
6949
|
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}])]`;
|
|
5369
6950
|
const deps = [
|
|
5370
6951
|
.../* @__PURE__ */ new Set([
|
|
5371
6952
|
...(target.dependencies ?? []).flatMap(
|
|
5372
|
-
(dependency) => dependency.kind === "product" && !(linkedObjects && dependency.package ===
|
|
6953
|
+
(dependency) => dependency.kind === "product" && !(linkedObjects && dependency.package === import_node_path14.default.basename(moduleRoot).toLowerCase()) ? [
|
|
5373
6954
|
`.product(name: ${JSON.stringify(dependency.name)}, package: ${JSON.stringify(dependency.package)})`
|
|
5374
6955
|
] : []
|
|
5375
6956
|
),
|
|
@@ -5440,8 +7021,8 @@ function emitSwiftPackageManifest(args) {
|
|
|
5440
7021
|
` path: ${JSON.stringify(native?.clang ? "." : target.path)},`,
|
|
5441
7022
|
...exclusions.length ? [` exclude: ${JSON.stringify(exclusions)},`] : [],
|
|
5442
7023
|
...native?.clang ? [
|
|
5443
|
-
` sources: ${JSON.stringify(native.clang.sources.map((source) =>
|
|
5444
|
-
` publicHeadersPath: ${JSON.stringify(
|
|
7024
|
+
` sources: ${JSON.stringify(native.clang.sources.map((source) => import_node_path14.default.posix.join(native.path, source)))},`,
|
|
7025
|
+
` publicHeadersPath: ${JSON.stringify(import_node_path14.default.posix.dirname(native.clang.modulemap))},`
|
|
5445
7026
|
] : native?.flags ? [` sources: ${JSON.stringify(native.sources)},`] : [],
|
|
5446
7027
|
...!native?.clang && target.publicHeadersPath !== void 0 ? [` publicHeadersPath: ${JSON.stringify(target.publicHeadersPath)},`] : [],
|
|
5447
7028
|
// the native backend supplies dependency module maps without their
|
|
@@ -5485,8 +7066,8 @@ function emitSwiftPackageManifest(args) {
|
|
|
5485
7066
|
` .target(name: ${JSON.stringify(group.name)},`,
|
|
5486
7067
|
` dependencies: ${JSON.stringify(native.mixed ? [] : [name2])},`,
|
|
5487
7068
|
` path: ${JSON.stringify(native.clang || native.mixed ? "." : native.path)},`,
|
|
5488
|
-
` sources: ${JSON.stringify(native.clang || native.mixed ? group.sources.map((source) =>
|
|
5489
|
-
` publicHeadersPath: ${JSON.stringify(native.clang ?
|
|
7069
|
+
` sources: ${JSON.stringify(native.clang || native.mixed ? group.sources.map((source) => import_node_path14.default.posix.join(native.path, source)) : group.sources)},`,
|
|
7070
|
+
` publicHeadersPath: ${JSON.stringify(native.clang ? import_node_path14.default.posix.dirname(native.clang.modulemap) : native.implementationHeaders ?? "include")},`,
|
|
5490
7071
|
` cSettings: [${macroSettings(owner?.cDefines)} .unsafeFlags(${JSON.stringify([...nativeFlags, ...group.flags])})],`,
|
|
5491
7072
|
` cxxSettings: [${macroSettings(owner?.cxxDefines)} .unsafeFlags(${JSON.stringify(["-fno-cxx-modules", ...cxxFlagsFor(nativeFlags), "-I", native.includeDirectory, "-I", args.headerDirectory, ...group.cxxFlags])})]),`
|
|
5492
7073
|
]) : [];
|
|
@@ -5498,22 +7079,22 @@ function emitSwiftPackageManifest(args) {
|
|
|
5498
7079
|
].join("\n");
|
|
5499
7080
|
}
|
|
5500
7081
|
function syncSwiftTree(base, files) {
|
|
5501
|
-
(0,
|
|
7082
|
+
(0, import_node_fs10.mkdirSync)(base, { recursive: true });
|
|
5502
7083
|
const walk = (dir) => {
|
|
5503
|
-
for (const entry of (0,
|
|
5504
|
-
const full =
|
|
5505
|
-
if (dir === base && (entry.name === ".build" || entry.name.startsWith(".peach-modules-") || entry.name === SWIFT_LINK_STAMP
|
|
7084
|
+
for (const entry of (0, import_node_fs10.readdirSync)(dir, { withFileTypes: true })) {
|
|
7085
|
+
const full = import_node_path14.default.join(dir, entry.name);
|
|
7086
|
+
if (dir === base && (entry.name === ".build" || entry.name.startsWith(".peach-modules-") || entry.name === SWIFT_LINK_STAMP))
|
|
5506
7087
|
continue;
|
|
5507
7088
|
if (entry.isDirectory()) walk(full);
|
|
5508
|
-
else if (!files.has(full)) (0,
|
|
7089
|
+
else if (!files.has(full)) (0, import_node_fs10.rmSync)(full, { force: true });
|
|
5509
7090
|
}
|
|
5510
7091
|
};
|
|
5511
7092
|
walk(base);
|
|
5512
7093
|
for (const [full, contents] of files) {
|
|
5513
|
-
if ((0,
|
|
7094
|
+
if ((0, import_node_fs10.existsSync)(full) && (typeof contents === "string" ? (0, import_node_fs10.readFileSync)(full, "utf8") === contents : (0, import_node_fs10.readFileSync)(full).equals(contents)))
|
|
5514
7095
|
continue;
|
|
5515
|
-
(0,
|
|
5516
|
-
(0,
|
|
7096
|
+
(0, import_node_fs10.mkdirSync)(import_node_path14.default.dirname(full), { recursive: true });
|
|
7097
|
+
(0, import_node_fs10.writeFileSync)(full, contents);
|
|
5517
7098
|
}
|
|
5518
7099
|
}
|
|
5519
7100
|
var DIRECTIVE = /^[ \t]*#(?:if|elseif)\b/;
|
|
@@ -5798,9 +7379,7 @@ var FOUNDATION_OVERLAY_TYPES = /* @__PURE__ */ new Set([
|
|
|
5798
7379
|
"URLUbiquitousSharedItemPermissions",
|
|
5799
7380
|
"URLUbiquitousSharedItemRole",
|
|
5800
7381
|
"UndoManager",
|
|
5801
|
-
"ValueTransformer"
|
|
5802
|
-
"XMLParser",
|
|
5803
|
-
"XMLParserDelegate"
|
|
7382
|
+
"ValueTransformer"
|
|
5804
7383
|
]);
|
|
5805
7384
|
var FOUNDATION_OVERLAY_GLOBALS = /* @__PURE__ */ new Set([
|
|
5806
7385
|
"CFBridgingRetain",
|
|
@@ -6169,7 +7748,6 @@ var FOUNDATION_OVERLAY_GLOBALS = /* @__PURE__ */ new Set([
|
|
|
6169
7748
|
"NSUnicodeStringEncoding",
|
|
6170
7749
|
"NSUserActivityErrorMaximum",
|
|
6171
7750
|
"NSUserActivityErrorMinimum",
|
|
6172
|
-
"NSUserActivityTypeBrowsingWeb",
|
|
6173
7751
|
"NSValidationErrorMaximum",
|
|
6174
7752
|
"NSValidationErrorMinimum",
|
|
6175
7753
|
"NSWindows95OperatingSystem",
|
|
@@ -6511,7 +8089,7 @@ function swiftApplicationEntry(file, source) {
|
|
|
6511
8089
|
else if (source[at] === "}") depth--;
|
|
6512
8090
|
else if (depth === 0 && /^@(?:main|UIApplicationMain)\b/.test(source.slice(at)))
|
|
6513
8091
|
return true;
|
|
6514
|
-
else if (depth === 0 &&
|
|
8092
|
+
else if (depth === 0 && import_node_path14.default.basename(file) === "main.swift" && /^UIApplicationMain\s*\(/.test(source.slice(at)))
|
|
6515
8093
|
return true;
|
|
6516
8094
|
}
|
|
6517
8095
|
return false;
|
|
@@ -6866,59 +8444,60 @@ function swiftCodeScan(source) {
|
|
|
6866
8444
|
return { lineStarts: starts, tokens };
|
|
6867
8445
|
}
|
|
6868
8446
|
function prepareSwiftDependency(source, destination) {
|
|
6869
|
-
(0,
|
|
8447
|
+
(0, import_node_fs10.rmSync)(destination, { recursive: true, force: true });
|
|
6870
8448
|
const origins = {};
|
|
6871
8449
|
const gather = (from) => {
|
|
6872
|
-
for (const entry of (0,
|
|
8450
|
+
for (const entry of (0, import_node_fs10.readdirSync)(from, { withFileTypes: true })) {
|
|
6873
8451
|
if (entry.name === ".git" || entry.name === ".build" || entry.name === ".swiftpm")
|
|
6874
8452
|
continue;
|
|
6875
|
-
const file =
|
|
8453
|
+
const file = import_node_path14.default.join(from, entry.name);
|
|
6876
8454
|
if (entry.isDirectory()) gather(file);
|
|
6877
8455
|
else if (entry.isFile() && entry.name.endsWith(".swift"))
|
|
6878
|
-
origins[
|
|
8456
|
+
origins[import_node_path14.default.relative(source, file)] = (0, import_node_fs10.readFileSync)(file, "utf8");
|
|
6879
8457
|
}
|
|
6880
8458
|
};
|
|
6881
8459
|
gather(source);
|
|
6882
|
-
const manifest =
|
|
6883
|
-
const targets = (0,
|
|
8460
|
+
const manifest = import_node_path14.default.join(source, "Package.swift");
|
|
8461
|
+
const targets = (0, import_node_fs10.existsSync)(manifest) ? swiftManifestTargets((0, import_node_fs10.readFileSync)(manifest, "utf8")) : [];
|
|
6884
8462
|
const compiled = compiledSwiftSources(origins, targets);
|
|
6885
8463
|
const copy = (from, to) => {
|
|
6886
|
-
(0,
|
|
6887
|
-
for (const entry of (0,
|
|
8464
|
+
(0, import_node_fs10.mkdirSync)(to, { recursive: true });
|
|
8465
|
+
for (const entry of (0, import_node_fs10.readdirSync)(from, { withFileTypes: true })) {
|
|
6888
8466
|
if (entry.name === ".git" || entry.name === ".build" || entry.name === ".swiftpm")
|
|
6889
8467
|
continue;
|
|
6890
|
-
const file =
|
|
6891
|
-
const target =
|
|
8468
|
+
const file = import_node_path14.default.join(from, entry.name);
|
|
8469
|
+
const target = import_node_path14.default.join(to, entry.name);
|
|
6892
8470
|
if (entry.isDirectory()) copy(file, target);
|
|
6893
8471
|
else if (entry.isFile() && entry.name.endsWith(".swift"))
|
|
6894
|
-
(0,
|
|
6895
|
-
else (0,
|
|
8472
|
+
(0, import_node_fs10.writeFileSync)(target, compiled.get(import_node_path14.default.relative(source, file)));
|
|
8473
|
+
else (0, import_node_fs10.cpSync)(file, target, { verbatimSymlinks: true });
|
|
6896
8474
|
}
|
|
6897
8475
|
};
|
|
6898
8476
|
copy(source, destination);
|
|
6899
8477
|
}
|
|
6900
8478
|
var HIDDEN_UNITS = "PeachHiddenUnits";
|
|
6901
|
-
function clangImportModuleMapFlags(settings, layoutRoot, written) {
|
|
8479
|
+
function clangImportModuleMapFlags(settings, layoutRoot, written, generated) {
|
|
6902
8480
|
const searched = new Set(settings.headerSearchPaths);
|
|
6903
|
-
const directory =
|
|
8481
|
+
const directory = import_node_path14.default.join(layoutRoot, ".build", "peach-clang-modulemaps");
|
|
6904
8482
|
return (settings.moduleMaps ?? []).flatMap((map) => {
|
|
6905
|
-
const headers =
|
|
6906
|
-
if (!(0,
|
|
6907
|
-
const published =
|
|
6908
|
-
if (searched.has(map.headers) && (0,
|
|
6909
|
-
if (!searched.has(map.headers) && (0,
|
|
8483
|
+
const headers = import_node_path14.default.join(layoutRoot, map.headers);
|
|
8484
|
+
if (!(0, import_node_fs10.existsSync)(headers)) return [];
|
|
8485
|
+
const published = import_node_path14.default.join(headers, "module.modulemap");
|
|
8486
|
+
if (searched.has(map.headers) && (0, import_node_fs10.existsSync)(published)) return [];
|
|
8487
|
+
if (!searched.has(map.headers) && (0, import_node_fs10.existsSync)(published))
|
|
6910
8488
|
return [`-fmodule-map-file=${published}`];
|
|
6911
8489
|
const cached = written.get(headers);
|
|
6912
8490
|
if (cached) return [cached];
|
|
6913
|
-
(0,
|
|
6914
|
-
const output =
|
|
6915
|
-
(0,
|
|
8491
|
+
(0, import_node_fs10.mkdirSync)(directory, { recursive: true });
|
|
8492
|
+
const output = import_node_path14.default.join(directory, `module-${written.size}.modulemap`);
|
|
8493
|
+
(0, import_node_fs10.writeFileSync)(
|
|
6916
8494
|
output,
|
|
6917
8495
|
swiftPackageClangModuleMap(swiftTargetModuleName(map.module), {
|
|
6918
8496
|
kind: "directory",
|
|
6919
8497
|
path: headers
|
|
6920
8498
|
})
|
|
6921
8499
|
);
|
|
8500
|
+
generated.push({ output, module: swiftTargetModuleName(map.module), published });
|
|
6922
8501
|
const flag = `-fmodule-map-file=${output}`;
|
|
6923
8502
|
written.set(headers, flag);
|
|
6924
8503
|
return [flag];
|
|
@@ -6947,14 +8526,19 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
6947
8526
|
const targets = distribution && compileTargets(input).length === 0 ? [
|
|
6948
8527
|
{
|
|
6949
8528
|
name: "App",
|
|
6950
|
-
path:
|
|
8529
|
+
path: import_node_path14.default.relative(layout.root, layout.sources),
|
|
6951
8530
|
executable: true,
|
|
6952
8531
|
languageMode: 5,
|
|
6953
8532
|
mainActorIsolation: false,
|
|
6954
8533
|
resources: false
|
|
6955
8534
|
}
|
|
6956
8535
|
] : compileTargets(input);
|
|
6957
|
-
const distributionExcludes = distribution ?
|
|
8536
|
+
const distributionExcludes = distribution ? /* @__PURE__ */ new Set([
|
|
8537
|
+
...swiftSystemLibraryExclusions(input.files, targets, distribution.modules),
|
|
8538
|
+
...distribution.modules.filter(
|
|
8539
|
+
(name2) => OPTIONAL_FRAMEWORKS.has(name2) && targets.some((target) => target.name === name2)
|
|
8540
|
+
)
|
|
8541
|
+
]) : void 0;
|
|
6958
8542
|
const files = /* @__PURE__ */ new Map();
|
|
6959
8543
|
const native = /* @__PURE__ */ new Map();
|
|
6960
8544
|
const targetFailures = [];
|
|
@@ -6986,18 +8570,18 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
6986
8570
|
clangImportedModules.add(name2);
|
|
6987
8571
|
}
|
|
6988
8572
|
}
|
|
6989
|
-
const headerDirectory =
|
|
8573
|
+
const headerDirectory = import_node_path14.default.join(layout.root, ".build", "peach-cxx-headers");
|
|
6990
8574
|
let checkedToolchain;
|
|
6991
8575
|
const nativeToolchain = () => {
|
|
6992
8576
|
if (checkedToolchain) return checkedToolchain;
|
|
6993
|
-
const pin = distribution ?? JSON.parse((0,
|
|
8577
|
+
const pin = distribution ?? JSON.parse((0, import_node_fs10.readFileSync)(import_node_path14.default.join(moduleRoot, "toolchain.json"), "utf8"));
|
|
6994
8578
|
checkedToolchain = swiftToolchain(pin.release, swiftModuleSdk(moduleRoot));
|
|
6995
8579
|
return checkedToolchain;
|
|
6996
8580
|
};
|
|
6997
8581
|
const deploymentTarget = (name2) => input.nativeTargets?.find((value) => value.name === name2)?.deploymentTarget ?? targets.find((value) => value.name === name2)?.iosDeploymentTarget ?? null;
|
|
6998
8582
|
const targetStagedFiles = /* @__PURE__ */ new Map();
|
|
6999
8583
|
const stageTargetFile = (target, file, contents, options) => {
|
|
7000
|
-
const relative =
|
|
8584
|
+
const relative = import_node_path14.default.relative(layout.root, file).split(import_node_path14.default.sep).join(import_node_path14.default.posix.sep);
|
|
7001
8585
|
const prior = files.has(file) ? files.get(file) : Object.hasOwn(input.files, relative) ? input.files[relative] : void 0;
|
|
7002
8586
|
if (!options?.allowExisting && prior !== void 0)
|
|
7003
8587
|
throw new Error(`target ${target} already contains generated output ${relative}`);
|
|
@@ -7026,7 +8610,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7026
8610
|
targetStagedFiles.delete(target.name);
|
|
7027
8611
|
if (entries.some(([file]) => isSwiftNativeTranslationUnit(file)) && (swift || input.nativeTargets?.some((value) => value.name === target.name))) {
|
|
7028
8612
|
if (!swift) {
|
|
7029
|
-
const unprepared =
|
|
8613
|
+
const unprepared = import_node_path14.default.join(
|
|
7030
8614
|
layout.root,
|
|
7031
8615
|
target.path,
|
|
7032
8616
|
"PeachUnprepared.generated.swift"
|
|
@@ -7041,7 +8625,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7041
8625
|
native.set(target.name, {
|
|
7042
8626
|
mixed: true,
|
|
7043
8627
|
path: target.path,
|
|
7044
|
-
includeDirectory:
|
|
8628
|
+
includeDirectory: import_node_path14.default.join(layout.root, target.path, "include"),
|
|
7045
8629
|
sources: [],
|
|
7046
8630
|
lateSources: [],
|
|
7047
8631
|
exclude: entries.filter(([file]) => !file.endsWith(".swift") && !file.endsWith(".metal")).map(([file]) => file.slice(prefix.length))
|
|
@@ -7050,30 +8634,33 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7050
8634
|
};
|
|
7051
8635
|
for (const settings of input.nativeTargets ?? []) {
|
|
7052
8636
|
for (const file of settings.headers) {
|
|
7053
|
-
const
|
|
8637
|
+
const interfaceModule = /(?:^|\/)(\w+)\.framework\/Headers\/\1-Swift\.h$/.exec(
|
|
8638
|
+
file
|
|
8639
|
+
)?.[1];
|
|
8640
|
+
const contents = interfaceModule && swiftModuleInterface(moduleRoot, interfaceModule)?.header || input.files[file];
|
|
7054
8641
|
if (contents === void 0)
|
|
7055
8642
|
throw new Error(`missing original Objective-C header ${file}`);
|
|
7056
|
-
const destination =
|
|
7057
|
-
(0,
|
|
7058
|
-
(0,
|
|
8643
|
+
const destination = import_node_path14.default.join(layout.root, file);
|
|
8644
|
+
(0, import_node_fs10.mkdirSync)(import_node_path14.default.dirname(destination), { recursive: true });
|
|
8645
|
+
(0, import_node_fs10.writeFileSync)(destination, contents);
|
|
7059
8646
|
files.set(destination, contents);
|
|
7060
8647
|
}
|
|
7061
8648
|
if (!settings.flattensPublicHeaders) continue;
|
|
7062
8649
|
for (const header of settings.publicHeaders) {
|
|
7063
|
-
const destination =
|
|
8650
|
+
const destination = import_node_path14.default.join(headerDirectory, settings.name, import_node_path14.default.basename(header));
|
|
7064
8651
|
if (files.has(destination))
|
|
7065
8652
|
throw new Error(`duplicate product header ${destination}`);
|
|
7066
|
-
const contents = `#import ${JSON.stringify(
|
|
8653
|
+
const contents = `#import ${JSON.stringify(import_node_path14.default.join(layout.root, header))}
|
|
7067
8654
|
`;
|
|
7068
8655
|
files.set(destination, contents);
|
|
7069
|
-
(0,
|
|
7070
|
-
(0,
|
|
8656
|
+
(0, import_node_fs10.mkdirSync)(import_node_path14.default.dirname(destination), { recursive: true });
|
|
8657
|
+
(0, import_node_fs10.writeFileSync)(destination, contents);
|
|
7071
8658
|
}
|
|
7072
8659
|
}
|
|
7073
8660
|
const nativeTargets = input.nativeTargets ?? [];
|
|
7074
|
-
const fromInputRoot = (file) => file.startsWith(`${SWIFT_NATIVE_INPUT_ROOT}/`) ?
|
|
8661
|
+
const fromInputRoot = (file) => file.startsWith(`${SWIFT_NATIVE_INPUT_ROOT}/`) ? import_node_path14.default.join(layout.root, file.slice(SWIFT_NATIVE_INPUT_ROOT.length + 1)) : file;
|
|
7075
8662
|
const headerSearch = writeXcodeHeaderSearch(
|
|
7076
|
-
|
|
8663
|
+
import_node_path14.default.join(layout.root, ".build", "peach-xcode-headers"),
|
|
7077
8664
|
nativeTargets.map((settings) => ({
|
|
7078
8665
|
headerMaps: settings.headerMaps.map((map) => ({
|
|
7079
8666
|
flag: map.flag,
|
|
@@ -7084,16 +8671,17 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7084
8671
|
})),
|
|
7085
8672
|
productHeaders: Object.fromEntries(
|
|
7086
8673
|
Object.entries(settings.productHeaders).map(([product, file]) => [
|
|
7087
|
-
|
|
7088
|
-
|
|
8674
|
+
import_node_path14.default.join(layout.root, product),
|
|
8675
|
+
import_node_path14.default.join(layout.root, file)
|
|
7089
8676
|
])
|
|
7090
8677
|
),
|
|
7091
8678
|
userHeaderSearchPaths: settings.userHeaderSearchPaths.map(
|
|
7092
|
-
(directory) =>
|
|
8679
|
+
(directory) => import_node_path14.default.join(layout.root, directory)
|
|
7093
8680
|
)
|
|
7094
8681
|
}))
|
|
7095
8682
|
);
|
|
7096
8683
|
const importModuleMaps = /* @__PURE__ */ new Map();
|
|
8684
|
+
const generatedModuleMaps = [];
|
|
7097
8685
|
for (const target of targets) {
|
|
7098
8686
|
const prefix = target.path === "." ? "" : `${target.path}/`;
|
|
7099
8687
|
const entries = targetEntries(target);
|
|
@@ -7113,7 +8701,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7113
8701
|
if (producer && targets.some((value) => value.name === producer))
|
|
7114
8702
|
producers2.add(producer);
|
|
7115
8703
|
const local = [
|
|
7116
|
-
|
|
8704
|
+
import_node_path14.default.posix.join(import_node_path14.default.posix.dirname(file), include2),
|
|
7117
8705
|
`${includes}${include2}`
|
|
7118
8706
|
].find((candidate) => input.files[candidate] !== void 0);
|
|
7119
8707
|
if (local) {
|
|
@@ -7147,12 +8735,12 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7147
8735
|
const headers = settings.headers;
|
|
7148
8736
|
const roots2 = settings.bridgingHeader ? [settings.bridgingHeader] : entries.some(([file]) => file.endsWith(".swift")) || importedModules.has(swiftTargetModuleName(target.name)) ? settings.publicHeaders : [];
|
|
7149
8737
|
for (const file of headers) {
|
|
7150
|
-
const destination =
|
|
7151
|
-
(0,
|
|
7152
|
-
(0,
|
|
8738
|
+
const destination = import_node_path14.default.join(layout.root, file);
|
|
8739
|
+
(0, import_node_fs10.mkdirSync)(import_node_path14.default.dirname(destination), { recursive: true });
|
|
8740
|
+
(0, import_node_fs10.writeFileSync)(destination, input.files[file]);
|
|
7153
8741
|
}
|
|
7154
8742
|
const search = [.../* @__PURE__ */ new Set([...settings?.headerSearchPaths ?? []])].flatMap(
|
|
7155
|
-
(dir) => ["-I",
|
|
8743
|
+
(dir) => ["-I", import_node_path14.default.join(layout.root, dir)]
|
|
7156
8744
|
);
|
|
7157
8745
|
const toolchainBin = nativeToolchain();
|
|
7158
8746
|
const stageFlags = (flags2, sdkInclude2) => flags2.map(
|
|
@@ -7164,7 +8752,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7164
8752
|
...search,
|
|
7165
8753
|
...(settings?.frameworkSearchPaths ?? []).flatMap((dir) => [
|
|
7166
8754
|
"-F",
|
|
7167
|
-
|
|
8755
|
+
import_node_path14.default.join(layout.root, dir)
|
|
7168
8756
|
]),
|
|
7169
8757
|
"-I",
|
|
7170
8758
|
headerDirectory
|
|
@@ -7175,13 +8763,13 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7175
8763
|
const flag = settings.flags[index];
|
|
7176
8764
|
if (flag === "-I" || flag === "-iquote") {
|
|
7177
8765
|
const directory = settings.flags[index + 1];
|
|
7178
|
-
if (directory === void 0 || !
|
|
8766
|
+
if (directory === void 0 || !import_node_path14.default.isAbsolute(directory)) {
|
|
7179
8767
|
index++;
|
|
7180
8768
|
continue;
|
|
7181
8769
|
}
|
|
7182
8770
|
}
|
|
7183
8771
|
const joined = /^-(?:I|iquote)(.+)$/.exec(flag);
|
|
7184
|
-
if (joined && !
|
|
8772
|
+
if (joined && !import_node_path14.default.isAbsolute(joined[1])) continue;
|
|
7185
8773
|
kept.push(flag);
|
|
7186
8774
|
}
|
|
7187
8775
|
return [
|
|
@@ -7190,18 +8778,18 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7190
8778
|
...search,
|
|
7191
8779
|
...(settings?.frameworkSearchPaths ?? []).flatMap((dir) => [
|
|
7192
8780
|
"-F",
|
|
7193
|
-
|
|
8781
|
+
import_node_path14.default.join(layout.root, dir)
|
|
7194
8782
|
]),
|
|
7195
8783
|
"-I",
|
|
7196
8784
|
headerDirectory
|
|
7197
8785
|
];
|
|
7198
8786
|
})();
|
|
7199
|
-
const sdkInclude =
|
|
8787
|
+
const sdkInclude = import_node_path14.default.join(
|
|
7200
8788
|
swiftSdkPaths(moduleRoot, toolchainBin).sysroot,
|
|
7201
8789
|
"darwin/usr/include"
|
|
7202
8790
|
);
|
|
7203
8791
|
const flags = stageFlags(originalFlags, sdkInclude);
|
|
7204
|
-
const prefixHeader = settings?.prefixHeader ? ["-include",
|
|
8792
|
+
const prefixHeader = settings?.prefixHeader ? ["-include", import_node_path14.default.join(layout.root, settings.prefixHeader)] : [];
|
|
7205
8793
|
const bundleName = entries.some(([file]) => file.endsWith(".swift")) ? void 0 : swiftObjCResourceBundleName({
|
|
7206
8794
|
target: target.name,
|
|
7207
8795
|
path: target.path,
|
|
@@ -7212,7 +8800,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7212
8800
|
bundles: input.resourceBundles
|
|
7213
8801
|
});
|
|
7214
8802
|
const accessor = bundleName === void 0 ? void 0 : swiftObjCResourceAccessor(bundleName);
|
|
7215
|
-
const accessorHeader =
|
|
8803
|
+
const accessorHeader = import_node_path14.default.join(
|
|
7216
8804
|
layout.root,
|
|
7217
8805
|
target.path,
|
|
7218
8806
|
OBJC_RESOURCE_ACCESSOR_HEADER
|
|
@@ -7223,7 +8811,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7223
8811
|
const nativeUnits = accessor ? [...units, [accessorUnit, accessor.body]] : units;
|
|
7224
8812
|
const unitSource = (file) => {
|
|
7225
8813
|
const relative = file.slice(prefix.length);
|
|
7226
|
-
return relative.split("/").some((part) => part.startsWith(".")) ?
|
|
8814
|
+
return relative.split("/").some((part) => part.startsWith(".")) ? import_node_path14.default.posix.join(HIDDEN_UNITS, relative.replaceAll(/(^|\/)\./g, "$1%2E")) : relative;
|
|
7227
8815
|
};
|
|
7228
8816
|
const accessorFlags = accessor ? ["-include", accessorHeader] : [];
|
|
7229
8817
|
const nativeC = !entries.some(([file]) => file.endsWith(".swift"));
|
|
@@ -7253,20 +8841,20 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7253
8841
|
)
|
|
7254
8842
|
].sort();
|
|
7255
8843
|
const topHeaders = settings.publicHeaders.filter(
|
|
7256
|
-
(file) =>
|
|
8844
|
+
(file) => import_node_path14.default.posix.dirname(file) === headerDir
|
|
7257
8845
|
);
|
|
7258
8846
|
if (input.files[custom] !== void 0) {
|
|
7259
8847
|
swiftpmModuleMap = { path: custom, contents: input.files[custom] };
|
|
7260
8848
|
} else if (input.files[umbrella] !== void 0) {
|
|
7261
8849
|
if (siblingDirs.length > 0)
|
|
7262
8850
|
throw new Error(
|
|
7263
|
-
`target ${target.name} has invalid header layout: umbrella header found at '${
|
|
8851
|
+
`target ${target.name} has invalid header layout: umbrella header found at '${import_node_path14.default.join(layout.root, umbrella)}', but directories exist next to it: ${siblingDirs.map((name2) => import_node_path14.default.join(layout.root, headerDir, name2)).join(", ")}; consider removing them`
|
|
7264
8852
|
);
|
|
7265
8853
|
swiftpmModuleMap = {
|
|
7266
8854
|
path: custom,
|
|
7267
8855
|
contents: swiftPackageClangModuleMap(moduleName, {
|
|
7268
8856
|
kind: "header",
|
|
7269
|
-
path:
|
|
8857
|
+
path: import_node_path14.default.join(layout.root, umbrella)
|
|
7270
8858
|
})
|
|
7271
8859
|
};
|
|
7272
8860
|
} else if (input.files[nestedUmbrella] !== void 0 && siblingDirs.length === 1 && siblingDirs[0] === moduleName && topHeaders.length === 0) {
|
|
@@ -7274,7 +8862,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7274
8862
|
path: custom,
|
|
7275
8863
|
contents: swiftPackageClangModuleMap(moduleName, {
|
|
7276
8864
|
kind: "header",
|
|
7277
|
-
path:
|
|
8865
|
+
path: import_node_path14.default.join(layout.root, nestedUmbrella)
|
|
7278
8866
|
})
|
|
7279
8867
|
};
|
|
7280
8868
|
} else {
|
|
@@ -7282,12 +8870,12 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7282
8870
|
path: custom,
|
|
7283
8871
|
contents: swiftPackageClangModuleMap(moduleName, {
|
|
7284
8872
|
kind: "directory",
|
|
7285
|
-
path:
|
|
8873
|
+
path: import_node_path14.default.join(layout.root, headerDir)
|
|
7286
8874
|
})
|
|
7287
8875
|
};
|
|
7288
8876
|
}
|
|
7289
8877
|
}
|
|
7290
|
-
const modulemap = originalModuleMap?.[0] ?? swiftpmModuleMap?.path ?? packageModuleMap?.[0] ??
|
|
8878
|
+
const modulemap = originalModuleMap?.[0] ?? swiftpmModuleMap?.path ?? packageModuleMap?.[0] ?? import_node_path14.default.posix.join(
|
|
7291
8879
|
".build",
|
|
7292
8880
|
"peach-objc-originals",
|
|
7293
8881
|
target.name,
|
|
@@ -7295,48 +8883,53 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7295
8883
|
);
|
|
7296
8884
|
const moduleContents = originalModuleMap ? input.files[originalModuleMap[1]] : swiftpmModuleMap?.contents ?? packageModuleMap?.[1] ?? swiftObjCModuleMap(
|
|
7297
8885
|
swiftTargetModuleName(target.name),
|
|
7298
|
-
roots2.map((file) =>
|
|
8886
|
+
roots2.map((file) => import_node_path14.default.join(layout.root, file))
|
|
7299
8887
|
);
|
|
7300
8888
|
if (moduleContents === void 0)
|
|
7301
8889
|
throw new Error("missing original module map " + modulemap);
|
|
7302
|
-
stageTargetFile(target.name,
|
|
8890
|
+
stageTargetFile(target.name, import_node_path14.default.join(layout.root, modulemap), moduleContents, {
|
|
7303
8891
|
allowExisting: true
|
|
7304
8892
|
});
|
|
7305
8893
|
const importFlags = [
|
|
7306
8894
|
...swiftClangImporterFlags(stageFlags(importOriginalFlags, sdkInclude)),
|
|
7307
|
-
"-fmodule-map-file=" +
|
|
7308
|
-
...clangImportModuleMapFlags(
|
|
8895
|
+
"-fmodule-map-file=" + import_node_path14.default.join(layout.root, modulemap),
|
|
8896
|
+
...clangImportModuleMapFlags(
|
|
8897
|
+
settings,
|
|
8898
|
+
layout.root,
|
|
8899
|
+
importModuleMaps,
|
|
8900
|
+
generatedModuleMaps
|
|
8901
|
+
)
|
|
7309
8902
|
];
|
|
7310
8903
|
const groups = /* @__PURE__ */ new Map();
|
|
7311
8904
|
for (const [file, contents] of nativeUnits) {
|
|
7312
8905
|
const origin = settings?.sourceDirectories[file];
|
|
7313
8906
|
if (origin) {
|
|
7314
|
-
const original =
|
|
7315
|
-
(0,
|
|
8907
|
+
const original = import_node_path14.default.join(layout.root, origin, import_node_path14.default.posix.basename(file));
|
|
8908
|
+
(0, import_node_fs10.mkdirSync)(import_node_path14.default.dirname(original), { recursive: true });
|
|
7316
8909
|
stageTargetFile(target.name, original, contents, { allowExisting: true });
|
|
7317
8910
|
}
|
|
7318
8911
|
const source = unitSource(file);
|
|
7319
8912
|
if (source !== file.slice(prefix.length))
|
|
7320
8913
|
stageTargetFile(
|
|
7321
8914
|
target.name,
|
|
7322
|
-
|
|
8915
|
+
import_node_path14.default.join(layout.root, target.path, source),
|
|
7323
8916
|
contents,
|
|
7324
8917
|
{
|
|
7325
8918
|
allowExisting: true
|
|
7326
8919
|
}
|
|
7327
8920
|
);
|
|
7328
8921
|
const perFile = [
|
|
7329
|
-
...origin ? ["-iquote",
|
|
8922
|
+
...origin ? ["-iquote", import_node_path14.default.join(layout.root, origin)] : [],
|
|
7330
8923
|
...stageFlags(
|
|
7331
8924
|
settings?.fileFlags[file] ?? [],
|
|
7332
|
-
|
|
8925
|
+
import_node_path14.default.join(
|
|
7333
8926
|
swiftSdkPaths(moduleRoot, toolchainBin).sysroot,
|
|
7334
8927
|
"darwin/usr/include"
|
|
7335
8928
|
)
|
|
7336
8929
|
)
|
|
7337
8930
|
];
|
|
7338
8931
|
const cxx = /\.(?:cc|cpp|cxx|mm)$/.test(file);
|
|
7339
|
-
const identity = (0,
|
|
8932
|
+
const identity = (0, import_node_crypto7.createHash)("sha256").update(JSON.stringify([cxx, perFile, (consumers.get(file)?.size ?? 0) > 0])).digest("hex").slice(0, 12);
|
|
7340
8933
|
const group = groups.get(identity) ?? {
|
|
7341
8934
|
name: `${target.name}${nativeC ? "Native" : "Swift"}Implementation_${identity}`,
|
|
7342
8935
|
sources: [],
|
|
@@ -7347,7 +8940,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7347
8940
|
...accessorFlags,
|
|
7348
8941
|
...stageFlags(
|
|
7349
8942
|
cxx ? settings.cxxFlags : [],
|
|
7350
|
-
|
|
8943
|
+
import_node_path14.default.join(
|
|
7351
8944
|
swiftSdkPaths(moduleRoot, toolchainBin).sysroot,
|
|
7352
8945
|
"darwin/usr/include"
|
|
7353
8946
|
)
|
|
@@ -7362,7 +8955,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7362
8955
|
stageTargetFile(target.name, accessorHeader, accessor.header);
|
|
7363
8956
|
stageTargetFile(
|
|
7364
8957
|
target.name,
|
|
7365
|
-
|
|
8958
|
+
import_node_path14.default.join(layout.root, accessorUnit),
|
|
7366
8959
|
accessor.body
|
|
7367
8960
|
);
|
|
7368
8961
|
}
|
|
@@ -7377,7 +8970,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7377
8970
|
].sort();
|
|
7378
8971
|
native.set(target.name, {
|
|
7379
8972
|
path: target.path,
|
|
7380
|
-
includeDirectory:
|
|
8973
|
+
includeDirectory: import_node_path14.default.dirname(import_node_path14.default.join(layout.root, modulemap)),
|
|
7381
8974
|
importFlags,
|
|
7382
8975
|
sources: nativeUnits.map(([file]) => unitSource(file)),
|
|
7383
8976
|
lateSources: implementations.flatMap((group) => group.sources),
|
|
@@ -7395,15 +8988,15 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7395
8988
|
});
|
|
7396
8989
|
continue;
|
|
7397
8990
|
}
|
|
7398
|
-
const implementationHeaders =
|
|
8991
|
+
const implementationHeaders = import_node_path14.default.posix.join(
|
|
7399
8992
|
".build",
|
|
7400
8993
|
"peach-objc-implementations",
|
|
7401
8994
|
target.name
|
|
7402
8995
|
);
|
|
7403
|
-
const include2 =
|
|
8996
|
+
const include2 = import_node_path14.default.join(layout.root, implementationHeaders);
|
|
7404
8997
|
stageTargetFile(
|
|
7405
8998
|
target.name,
|
|
7406
|
-
|
|
8999
|
+
import_node_path14.default.join(include2, "module.modulemap"),
|
|
7407
9000
|
`module ${target.name}ImplementationDeclarations { export * }
|
|
7408
9001
|
`
|
|
7409
9002
|
);
|
|
@@ -7414,7 +9007,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7414
9007
|
implementationHeaders,
|
|
7415
9008
|
importFlags,
|
|
7416
9009
|
swiftFlags: [
|
|
7417
|
-
...settings.bridgingHeader ? ["-import-objc-header",
|
|
9010
|
+
...settings.bridgingHeader ? ["-import-objc-header", import_node_path14.default.join(layout.root, settings.bridgingHeader)] : roots2.length ? ["-import-underlying-module"] : [],
|
|
7418
9011
|
...importFlags.flatMap((flag) => ["-Xcc", flag])
|
|
7419
9012
|
],
|
|
7420
9013
|
sources: nativeUnits.map(([file]) => unitSource(file)),
|
|
@@ -7444,7 +9037,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7444
9037
|
}
|
|
7445
9038
|
native.set(target.name, {
|
|
7446
9039
|
path: target.path,
|
|
7447
|
-
includeDirectory:
|
|
9040
|
+
includeDirectory: import_node_path14.default.join(layout.root, includes),
|
|
7448
9041
|
sources: units.map(([file]) => file.slice(prefix.length)),
|
|
7449
9042
|
lateSources: late.map(([file]) => file.slice(prefix.length)),
|
|
7450
9043
|
...late.length > 0 ? {
|
|
@@ -7462,7 +9055,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7462
9055
|
([file]) => file.startsWith(includes) && /\.(?:h|hpp|hh|hxx)$/.test(file) && consumers.get(file).size === 0
|
|
7463
9056
|
);
|
|
7464
9057
|
files.set(
|
|
7465
|
-
|
|
9058
|
+
import_node_path14.default.join(layout.root, includes, "module.modulemap"),
|
|
7466
9059
|
[
|
|
7467
9060
|
`module ${target.name} {`,
|
|
7468
9061
|
...roots.map(
|
|
@@ -7474,16 +9067,26 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7474
9067
|
].join("\n")
|
|
7475
9068
|
);
|
|
7476
9069
|
}
|
|
7477
|
-
|
|
9070
|
+
for (const map of generatedModuleMaps)
|
|
9071
|
+
if (files.has(map.published) || Object.hasOwn(
|
|
9072
|
+
input.files,
|
|
9073
|
+
import_node_path14.default.relative(layout.root, map.published).split(import_node_path14.default.sep).join(import_node_path14.default.posix.sep)
|
|
9074
|
+
))
|
|
9075
|
+
(0, import_node_fs10.writeFileSync)(
|
|
9076
|
+
map.output,
|
|
9077
|
+
`extern module ${map.module} ${JSON.stringify(map.published)}
|
|
9078
|
+
`
|
|
9079
|
+
);
|
|
9080
|
+
if (native.size > 0) (0, import_node_fs10.mkdirSync)(headerDirectory, { recursive: true });
|
|
7478
9081
|
const nativeHeaderFlags = [];
|
|
7479
9082
|
for (const name2 of new Set(
|
|
7480
9083
|
[...native.values()].flatMap((value) => value.late?.producers ?? [])
|
|
7481
9084
|
)) {
|
|
7482
9085
|
files.set(
|
|
7483
|
-
|
|
9086
|
+
import_node_path14.default.join(headerDirectory, name2, name2 + "-Swift.h"),
|
|
7484
9087
|
'#include "../' + name2 + '-Swift.h"\n'
|
|
7485
9088
|
);
|
|
7486
|
-
const modulemap =
|
|
9089
|
+
const modulemap = import_node_path14.default.join(
|
|
7487
9090
|
layout.root,
|
|
7488
9091
|
".build",
|
|
7489
9092
|
"peach-objc-swift-headers",
|
|
@@ -7493,19 +9096,19 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7493
9096
|
files.set(
|
|
7494
9097
|
modulemap,
|
|
7495
9098
|
swiftObjCModuleMap(swiftTargetModuleName(name2), [
|
|
7496
|
-
...(input.nativeTargets?.find((target) => target.name === name2)?.publicHeaders ?? []).map((header) =>
|
|
7497
|
-
|
|
9099
|
+
...(input.nativeTargets?.find((target) => target.name === name2)?.publicHeaders ?? []).map((header) => import_node_path14.default.join(layout.root, header)),
|
|
9100
|
+
import_node_path14.default.join(headerDirectory, name2 + "-Swift.h")
|
|
7498
9101
|
])
|
|
7499
9102
|
);
|
|
7500
9103
|
nativeHeaderFlags.push("-fmodule-map-file=" + modulemap);
|
|
7501
9104
|
}
|
|
7502
|
-
const modulePlan = (0,
|
|
9105
|
+
const modulePlan = (0, import_node_crypto7.createHash)("sha256").update(
|
|
7503
9106
|
swiftModuleInputFiles(moduleRoot).join("\n")
|
|
7504
9107
|
);
|
|
7505
9108
|
if (!distribution) {
|
|
7506
|
-
modulePlan.update((0,
|
|
9109
|
+
modulePlan.update((0, import_node_fs10.readFileSync)(import_node_path14.default.join(moduleRoot, "Package.swift")));
|
|
7507
9110
|
}
|
|
7508
|
-
const resourcePlan = (0,
|
|
9111
|
+
const resourcePlan = (0, import_node_crypto7.createHash)("sha256").update(
|
|
7509
9112
|
JSON.stringify(
|
|
7510
9113
|
resourceTargets.filter((target) => target.resources).map((target) => [
|
|
7511
9114
|
target.name,
|
|
@@ -7550,7 +9153,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7550
9153
|
`;
|
|
7551
9154
|
} else if (mains.length === 0) {
|
|
7552
9155
|
const procedural = entries.filter(
|
|
7553
|
-
([file, source]) =>
|
|
9156
|
+
([file, source]) => import_node_path14.default.basename(file) === "main.swift" && swiftApplicationEntry(file, source)
|
|
7554
9157
|
);
|
|
7555
9158
|
const wrapped = procedural.length === 1 ? wrapUIApplicationMainEntry(procedural[0][1]) : null;
|
|
7556
9159
|
if (!wrapped)
|
|
@@ -7579,7 +9182,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7579
9182
|
exclude: []
|
|
7580
9183
|
});
|
|
7581
9184
|
files.set(
|
|
7582
|
-
|
|
9185
|
+
import_node_path14.default.join(layout.root, `PeachApplication/${name2}/Entry.swift`),
|
|
7583
9186
|
`import ${swiftTargetModuleName(target.name)}
|
|
7584
9187
|
@main struct __PeachApplicationEntry { @MainActor static func main() { __peachRunApplication() } }
|
|
7585
9188
|
`
|
|
@@ -7589,7 +9192,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7589
9192
|
const nativeFlags = native.size > 0 ? /* @__PURE__ */ new Map() : void 0;
|
|
7590
9193
|
if (nativeFlags) {
|
|
7591
9194
|
const toolchainBin = nativeToolchain();
|
|
7592
|
-
const headers =
|
|
9195
|
+
const headers = import_node_path14.default.join(swiftSdkPaths(moduleRoot, toolchainBin).sysroot, "darwin");
|
|
7593
9196
|
for (const target of targets) {
|
|
7594
9197
|
const version = deploymentTarget(target.name);
|
|
7595
9198
|
const minimum = iosDeploymentMinimum(version);
|
|
@@ -7620,10 +9223,10 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7620
9223
|
if (targets.length === 0 && !prebuilt) {
|
|
7621
9224
|
for (const [file, contents] of Object.entries(input.files)) {
|
|
7622
9225
|
if (file === "Package.swift") continue;
|
|
7623
|
-
files.set(
|
|
9226
|
+
files.set(import_node_path14.default.join(layout.sources, file), compiled.get(file) ?? contents);
|
|
7624
9227
|
}
|
|
7625
|
-
let manifest = (0,
|
|
7626
|
-
|
|
9228
|
+
let manifest = (0, import_node_fs10.readFileSync)(
|
|
9229
|
+
import_node_path14.default.join(moduleRoot, "scripts/contrast-app-Package.swift"),
|
|
7627
9230
|
"utf8"
|
|
7628
9231
|
).replaceAll("__SOOTSIM_SWIFT_PACKAGE__", moduleRoot);
|
|
7629
9232
|
const reactor = ` ${REACTOR_FLAG}`;
|
|
@@ -7667,25 +9270,25 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7667
9270
|
manifest = manifest.replace(anchor, `${anchor}
|
|
7668
9271
|
${SPRITEKIT_PRODUCT},`);
|
|
7669
9272
|
}
|
|
7670
|
-
files.set(
|
|
9273
|
+
files.set(import_node_path14.default.join(layout.root, "Package.swift"), manifest + moduleFiles);
|
|
7671
9274
|
} else {
|
|
7672
9275
|
const base = layout.multi ? layout.root : layout.sources;
|
|
7673
9276
|
const libraries = /* @__PURE__ */ new Map();
|
|
7674
9277
|
for (const [target, data] of Object.entries(input.libraries ?? {})) {
|
|
7675
9278
|
const bytes = Buffer.from(data, "base64");
|
|
7676
|
-
const digest = (0,
|
|
7677
|
-
const file =
|
|
9279
|
+
const digest = (0, import_node_crypto7.createHash)("sha256").update(bytes).digest("hex");
|
|
9280
|
+
const file = import_node_path14.default.join(layout.root, ".peach-libraries", `lib${target}-${digest}.a`);
|
|
7678
9281
|
files.set(file, bytes);
|
|
7679
9282
|
libraries.set(target, file);
|
|
7680
9283
|
}
|
|
7681
9284
|
for (const [file, contents] of Object.entries(input.files)) {
|
|
7682
9285
|
if (file === "Package.swift") continue;
|
|
7683
|
-
files.set(
|
|
9286
|
+
files.set(import_node_path14.default.join(base, file), compiled.get(file) ?? contents);
|
|
7684
9287
|
}
|
|
7685
9288
|
const manifestTargets = targets.length > 0 ? targets : [
|
|
7686
9289
|
{
|
|
7687
9290
|
name: "App",
|
|
7688
|
-
path:
|
|
9291
|
+
path: import_node_path14.default.relative(layout.root, layout.sources).split(import_node_path14.default.sep).join("/"),
|
|
7689
9292
|
executable: true,
|
|
7690
9293
|
languageMode: 5,
|
|
7691
9294
|
mainActorIsolation: false,
|
|
@@ -7695,11 +9298,11 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7695
9298
|
const reachesFrameworks = !distribution || Object.entries(input.files).some(
|
|
7696
9299
|
([file, source]) => file.endsWith(".swift") && file !== input.entry && file !== "Package.swift" || /\.mm?$/.test(file) || source.includes("dispatch_")
|
|
7697
9300
|
) || [...importedModules].some(
|
|
7698
|
-
(name2) => distribution.modules.includes(name2) && !targets.some((target) => target.name === name2) && !(clangImportedModules.has(name2) && !swiftImportedModules.has(name2) && (0,
|
|
7699
|
-
|
|
9301
|
+
(name2) => distribution.modules.includes(name2) && !targets.some((target) => target.name === name2) && !(clangImportedModules.has(name2) && !swiftImportedModules.has(name2) && (0, import_node_fs10.existsSync)(
|
|
9302
|
+
import_node_path14.default.join(swiftSharedSdkRoot(moduleRoot, true), "usr/include", name2)
|
|
7700
9303
|
))
|
|
7701
9304
|
);
|
|
7702
|
-
const frameworkLink = prebuilt ?
|
|
9305
|
+
const frameworkLink = prebuilt ? import_node_path14.default.join(layout.root, ".peach-framework-objects.rsp") : void 0;
|
|
7703
9306
|
if (prebuilt && frameworkLink) {
|
|
7704
9307
|
files.set(
|
|
7705
9308
|
frameworkLink,
|
|
@@ -7707,7 +9310,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7707
9310
|
);
|
|
7708
9311
|
}
|
|
7709
9312
|
files.set(
|
|
7710
|
-
|
|
9313
|
+
import_node_path14.default.join(layout.root, "Package.swift"),
|
|
7711
9314
|
emitSwiftPackageManifest({
|
|
7712
9315
|
root: layout.root,
|
|
7713
9316
|
targets: manifestTargets,
|
|
@@ -7741,7 +9344,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7741
9344
|
),
|
|
7742
9345
|
...reachesFrameworks ? {
|
|
7743
9346
|
distributionLink: {
|
|
7744
|
-
path:
|
|
9347
|
+
path: import_node_path14.default.join(layout.root, ".peach-distribution-objects.rsp"),
|
|
7745
9348
|
files
|
|
7746
9349
|
},
|
|
7747
9350
|
lazyDistribution: input.lazyDistribution
|
|
@@ -7760,21 +9363,21 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7760
9363
|
);
|
|
7761
9364
|
}
|
|
7762
9365
|
for (const [file, bytes] of Object.entries(input.packageFiles ?? {}))
|
|
7763
|
-
files.set(
|
|
9366
|
+
files.set(import_node_path14.default.join(layout.root, file), Buffer.from(bytes, "base64"));
|
|
7764
9367
|
for (const [file, bytes] of Object.entries(input.projectFiles ?? {})) {
|
|
7765
|
-
const destination =
|
|
9368
|
+
const destination = import_node_path14.default.join(layout.root, file);
|
|
7766
9369
|
if (files.has(destination)) continue;
|
|
7767
9370
|
files.set(destination, Buffer.from(bytes, "base64"));
|
|
7768
9371
|
}
|
|
7769
9372
|
if (input.packageFiles || prebuilt) {
|
|
7770
9373
|
files.set(
|
|
7771
|
-
|
|
9374
|
+
import_node_path14.default.join(layout.root, ".peach-target-toolset.json"),
|
|
7772
9375
|
JSON.stringify({
|
|
7773
9376
|
schemaVersion: "1.0",
|
|
7774
9377
|
swiftCompiler: {
|
|
7775
9378
|
extraCLIOptions: [
|
|
7776
9379
|
"-I",
|
|
7777
|
-
distribution ? distributionModulesPath(layout.root, moduleRoot, distributionExcludes) : prebuilt ? prebuilt.modules :
|
|
9380
|
+
distribution ? distributionModulesPath(layout.root, moduleRoot, distributionExcludes) : prebuilt ? prebuilt.modules : import_node_path14.default.join(layout.root, ".build", WASM_TRIPLE, "release", "Modules"),
|
|
7778
9381
|
...prebuilt?.moduleMaps.flatMap((map) => [
|
|
7779
9382
|
"-Xcc",
|
|
7780
9383
|
`-fmodule-map-file=${map}`
|
|
@@ -7803,9 +9406,9 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7803
9406
|
throw new Error(
|
|
7804
9407
|
`swift resource target ${target.name} has no matching bundle assignment`
|
|
7805
9408
|
);
|
|
7806
|
-
const directory = layout.multi ?
|
|
9409
|
+
const directory = layout.multi ? import_node_path14.default.join(layout.root, target.path) : layout.sources;
|
|
7807
9410
|
files.set(
|
|
7808
|
-
|
|
9411
|
+
import_node_path14.default.join(directory, "ResourceBundleAccessor.generated.swift"),
|
|
7809
9412
|
[
|
|
7810
9413
|
"import Foundation",
|
|
7811
9414
|
"",
|
|
@@ -7822,7 +9425,7 @@ function writeSwiftProject(layout, input, moduleRoot, prebuilt) {
|
|
|
7822
9425
|
}
|
|
7823
9426
|
for (const [file, source] of compiled)
|
|
7824
9427
|
if (!Object.hasOwn(input.files, file))
|
|
7825
|
-
files.set(
|
|
9428
|
+
files.set(import_node_path14.default.join(layout.multi ? layout.root : layout.sources, file), source);
|
|
7826
9429
|
syncSwiftTree(layout.root, files);
|
|
7827
9430
|
const producers = [
|
|
7828
9431
|
.../* @__PURE__ */ new Set([...[...native.values()].flatMap((value) => value.late?.producers ?? [])])
|
|
@@ -7857,24 +9460,17 @@ function outputOf(error) {
|
|
|
7857
9460
|
return error instanceof Error ? error.message : String(error);
|
|
7858
9461
|
}
|
|
7859
9462
|
function builtArtifact(layout) {
|
|
7860
|
-
const binDir =
|
|
7861
|
-
const manifest = (0,
|
|
9463
|
+
const binDir = import_node_path14.default.join(layout.root, ".build", WASM_TRIPLE, "release");
|
|
9464
|
+
const manifest = (0, import_node_fs10.readFileSync)(import_node_path14.default.join(layout.root, "Package.swift"), "utf8");
|
|
7862
9465
|
const executable = swiftManifestTargets(manifest).find((target) => target.executable);
|
|
7863
9466
|
if (executable === void 0) {
|
|
7864
9467
|
throw new Error("swift-compile: the written manifest names no executable target");
|
|
7865
9468
|
}
|
|
7866
|
-
|
|
7867
|
-
if (!(0, import_node_fs9.existsSync)(file)) {
|
|
7868
|
-
const found = (0, import_node_fs9.existsSync)(binDir) ? (0, import_node_fs9.readdirSync)(binDir).filter((name2) => name2.endsWith(".wasm")).sort() : [];
|
|
7869
|
-
throw new Error(
|
|
7870
|
-
`swift-compile: the build produced no ${executable.name}.wasm (found: ${found.join(", ") || "none"})`
|
|
7871
|
-
);
|
|
7872
|
-
}
|
|
7873
|
-
return file;
|
|
9469
|
+
return import_node_path14.default.join(binDir, `${executable.name}.wasm`);
|
|
7874
9470
|
}
|
|
7875
9471
|
function projectDiagnostic(output, layout, files) {
|
|
7876
9472
|
const base = layout.multi ? layout.root : layout.sources;
|
|
7877
|
-
const prefix = `${base}${
|
|
9473
|
+
const prefix = `${base}${import_node_path14.default.sep}`;
|
|
7878
9474
|
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();
|
|
7879
9475
|
}
|
|
7880
9476
|
var ROOT_LOCKS = Symbol.for("peachsim.swiftCompile.rootLocks");
|
|
@@ -7910,13 +9506,13 @@ function serialize(root, work, signal) {
|
|
|
7910
9506
|
function readCompiledArtifact(directory, hash) {
|
|
7911
9507
|
try {
|
|
7912
9508
|
const receipt = JSON.parse(
|
|
7913
|
-
(0,
|
|
9509
|
+
(0, import_node_fs10.readFileSync)(import_node_path14.default.join(directory, "artifact.json"), "utf8")
|
|
7914
9510
|
);
|
|
7915
9511
|
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")
|
|
7916
9512
|
return null;
|
|
7917
|
-
const bytes = (0,
|
|
7918
|
-
const gzip2 = (0,
|
|
7919
|
-
if ((0,
|
|
9513
|
+
const bytes = (0, import_node_fs10.readFileSync)(import_node_path14.default.join(directory, "app.wasm"));
|
|
9514
|
+
const gzip2 = (0, import_node_fs10.readFileSync)(import_node_path14.default.join(directory, "icu.gz"));
|
|
9515
|
+
if ((0, import_node_crypto7.createHash)("sha256").update(bytes).digest("hex") !== receipt.wasm || (0, import_node_crypto7.createHash)("sha256").update(gzip2).digest("hex") !== receipt.icu || bytes.length < 8 || bytes.readUInt32LE(0) !== 1836278016 || bytes.readUInt32LE(4) !== 1)
|
|
7920
9516
|
return null;
|
|
7921
9517
|
return { hash, bytes, icu: { sha256: receipt.icu, gzip: gzip2 } };
|
|
7922
9518
|
} catch (error) {
|
|
@@ -7926,25 +9522,25 @@ function readCompiledArtifact(directory, hash) {
|
|
|
7926
9522
|
}
|
|
7927
9523
|
}
|
|
7928
9524
|
function saveCompiledArtifact(root, artifact) {
|
|
7929
|
-
const directory =
|
|
7930
|
-
(0,
|
|
7931
|
-
const pending = (0,
|
|
9525
|
+
const directory = import_node_path14.default.join(root, "artifact");
|
|
9526
|
+
(0, import_node_fs10.mkdirSync)(directory, { recursive: true });
|
|
9527
|
+
const pending = (0, import_node_fs10.mkdtempSync)(import_node_path14.default.join(root, ".artifact-"));
|
|
7932
9528
|
try {
|
|
7933
|
-
(0,
|
|
7934
|
-
(0,
|
|
7935
|
-
(0,
|
|
7936
|
-
|
|
9529
|
+
(0, import_node_fs10.writeFileSync)(import_node_path14.default.join(pending, "app.wasm"), artifact.bytes);
|
|
9530
|
+
(0, import_node_fs10.writeFileSync)(import_node_path14.default.join(pending, "icu.gz"), artifact.icu.gzip);
|
|
9531
|
+
(0, import_node_fs10.writeFileSync)(
|
|
9532
|
+
import_node_path14.default.join(pending, "artifact.json"),
|
|
7937
9533
|
JSON.stringify({
|
|
7938
9534
|
hash: artifact.hash,
|
|
7939
|
-
wasm: (0,
|
|
9535
|
+
wasm: (0, import_node_crypto7.createHash)("sha256").update(artifact.bytes).digest("hex"),
|
|
7940
9536
|
icu: artifact.icu.sha256
|
|
7941
9537
|
})
|
|
7942
9538
|
);
|
|
7943
9539
|
for (const file of ["app.wasm", "icu.gz", "artifact.json"]) {
|
|
7944
|
-
(0,
|
|
9540
|
+
(0, import_node_fs10.renameSync)(import_node_path14.default.join(pending, file), import_node_path14.default.join(directory, file));
|
|
7945
9541
|
}
|
|
7946
9542
|
} finally {
|
|
7947
|
-
(0,
|
|
9543
|
+
(0, import_node_fs10.rmSync)(pending, { recursive: true, force: true });
|
|
7948
9544
|
}
|
|
7949
9545
|
}
|
|
7950
9546
|
var SHARED_ARTIFACT_BUDGET_BYTES = 4 * 1024 ** 3;
|
|
@@ -7955,29 +9551,29 @@ function vanished(error) {
|
|
|
7955
9551
|
}
|
|
7956
9552
|
function renewSharedArtifact(sharedRoot) {
|
|
7957
9553
|
try {
|
|
7958
|
-
(0,
|
|
9554
|
+
(0, import_node_fs10.utimesSync)(sharedRoot, /* @__PURE__ */ new Date(), /* @__PURE__ */ new Date());
|
|
7959
9555
|
} catch (error) {
|
|
7960
9556
|
if (!vanished(error)) throw error;
|
|
7961
9557
|
}
|
|
7962
9558
|
}
|
|
7963
9559
|
function pruneSharedArtifacts(parent, keep) {
|
|
7964
9560
|
const entries = [];
|
|
7965
|
-
for (const name2 of (0,
|
|
7966
|
-
const directory =
|
|
9561
|
+
for (const name2 of (0, import_node_fs10.readdirSync)(parent)) {
|
|
9562
|
+
const directory = import_node_path14.default.join(parent, name2);
|
|
7967
9563
|
if (name2.startsWith(RETIRED_PREFIX)) {
|
|
7968
|
-
(0,
|
|
9564
|
+
(0, import_node_fs10.rmSync)(directory, { recursive: true, force: true });
|
|
7969
9565
|
continue;
|
|
7970
9566
|
}
|
|
7971
9567
|
try {
|
|
7972
9568
|
let bytes = 0;
|
|
7973
|
-
for (const file of (0,
|
|
9569
|
+
for (const file of (0, import_node_fs10.readdirSync)(import_node_path14.default.join(directory, "artifact"))) {
|
|
7974
9570
|
try {
|
|
7975
|
-
bytes += (0,
|
|
9571
|
+
bytes += (0, import_node_fs10.statSync)(import_node_path14.default.join(directory, "artifact", file)).size;
|
|
7976
9572
|
} catch (error) {
|
|
7977
9573
|
if (!vanished(error)) throw error;
|
|
7978
9574
|
}
|
|
7979
9575
|
}
|
|
7980
|
-
entries.push({ directory, used: (0,
|
|
9576
|
+
entries.push({ directory, used: (0, import_node_fs10.statSync)(directory).mtimeMs, bytes });
|
|
7981
9577
|
} catch (error) {
|
|
7982
9578
|
if (!vanished(error)) throw error;
|
|
7983
9579
|
}
|
|
@@ -7987,25 +9583,25 @@ function pruneSharedArtifacts(parent, keep) {
|
|
|
7987
9583
|
if (total <= SHARED_ARTIFACT_BUDGET_BYTES) break;
|
|
7988
9584
|
if (entry.directory === keep || Date.now() - entry.used < SHARED_ARTIFACT_GRACE_MS)
|
|
7989
9585
|
continue;
|
|
7990
|
-
const retired =
|
|
9586
|
+
const retired = import_node_path14.default.join(
|
|
7991
9587
|
parent,
|
|
7992
|
-
`${RETIRED_PREFIX}${process.pid}-${
|
|
9588
|
+
`${RETIRED_PREFIX}${process.pid}-${import_node_path14.default.basename(entry.directory)}`
|
|
7993
9589
|
);
|
|
7994
9590
|
try {
|
|
7995
|
-
if ((0,
|
|
7996
|
-
(0,
|
|
9591
|
+
if ((0, import_node_fs10.statSync)(entry.directory).mtimeMs !== entry.used) continue;
|
|
9592
|
+
(0, import_node_fs10.renameSync)(entry.directory, retired);
|
|
7997
9593
|
} catch (error) {
|
|
7998
9594
|
if (vanished(error)) continue;
|
|
7999
9595
|
throw error;
|
|
8000
9596
|
}
|
|
8001
|
-
(0,
|
|
9597
|
+
(0, import_node_fs10.rmSync)(retired, { recursive: true, force: true });
|
|
8002
9598
|
total -= entry.bytes;
|
|
8003
9599
|
}
|
|
8004
9600
|
}
|
|
8005
9601
|
function saveSharedArtifact(sharedRoot, artifact) {
|
|
8006
9602
|
saveCompiledArtifact(sharedRoot, artifact);
|
|
8007
9603
|
renewSharedArtifact(sharedRoot);
|
|
8008
|
-
pruneSharedArtifacts(
|
|
9604
|
+
pruneSharedArtifacts(import_node_path14.default.dirname(sharedRoot), sharedRoot);
|
|
8009
9605
|
}
|
|
8010
9606
|
var retainedArtifacts = /* @__PURE__ */ new Map();
|
|
8011
9607
|
function retain(root, artifact) {
|
|
@@ -8033,7 +9629,7 @@ function frameworkLibraryTargets(manifest) {
|
|
|
8033
9629
|
}
|
|
8034
9630
|
function linkedFrameworkTargets(moduleRoot, input) {
|
|
8035
9631
|
const libraries = frameworkLibraryTargets(
|
|
8036
|
-
(0,
|
|
9632
|
+
(0, import_node_fs10.readFileSync)(import_node_path14.default.join(moduleRoot, "Package.swift"), "utf8")
|
|
8037
9633
|
);
|
|
8038
9634
|
const targets = compileTargets(input);
|
|
8039
9635
|
const planning = targets.length > 0 ? targets : [{ name: "App", path: "." }];
|
|
@@ -8074,7 +9670,7 @@ function linkedFrameworkTargets(moduleRoot, input) {
|
|
|
8074
9670
|
return { products: linked, targets: linkedMembers };
|
|
8075
9671
|
}
|
|
8076
9672
|
function writeFrameworkLinkPackage(linkRoot, moduleRoot, products) {
|
|
8077
|
-
const identity =
|
|
9673
|
+
const identity = import_node_path14.default.basename(moduleRoot).toLowerCase();
|
|
8078
9674
|
const swiftString = (value) => `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
8079
9675
|
const dependencies = products.map(
|
|
8080
9676
|
(name2) => ` .product(name: ${swiftString(name2)}, package: ${swiftString(identity)}),`
|
|
@@ -8096,13 +9692,13 @@ ${dependencies}
|
|
|
8096
9692
|
]
|
|
8097
9693
|
)
|
|
8098
9694
|
`;
|
|
8099
|
-
const sourceDir =
|
|
8100
|
-
(0,
|
|
8101
|
-
const manifestPath =
|
|
8102
|
-
if (!(0,
|
|
8103
|
-
(0,
|
|
8104
|
-
const source =
|
|
8105
|
-
if (!(0,
|
|
9695
|
+
const sourceDir = import_node_path14.default.join(linkRoot, "Sources", FRAMEWORK_LINK_TARGET);
|
|
9696
|
+
(0, import_node_fs10.mkdirSync)(sourceDir, { recursive: true });
|
|
9697
|
+
const manifestPath = import_node_path14.default.join(linkRoot, "Package.swift");
|
|
9698
|
+
if (!(0, import_node_fs10.existsSync)(manifestPath) || (0, import_node_fs10.readFileSync)(manifestPath, "utf8") !== manifest)
|
|
9699
|
+
(0, import_node_fs10.writeFileSync)(manifestPath, manifest);
|
|
9700
|
+
const source = import_node_path14.default.join(sourceDir, "Link.swift");
|
|
9701
|
+
if (!(0, import_node_fs10.existsSync)(source)) (0, import_node_fs10.writeFileSync)(source, "");
|
|
8106
9702
|
}
|
|
8107
9703
|
function frameworkLinkClosure(scratch2, roots) {
|
|
8108
9704
|
const suffix = `${WASM_TRIPLE}-release`;
|
|
@@ -8113,7 +9709,7 @@ function frameworkLinkClosure(scratch2, roots) {
|
|
|
8113
9709
|
const moduleMaps = /* @__PURE__ */ new Map();
|
|
8114
9710
|
let pending = null;
|
|
8115
9711
|
let compiling = null;
|
|
8116
|
-
for (const line of (0,
|
|
9712
|
+
for (const line of (0, import_node_fs10.readFileSync)(import_node_path14.default.join(scratch2, "release.yaml"), "utf8").split(
|
|
8117
9713
|
"\n"
|
|
8118
9714
|
)) {
|
|
8119
9715
|
const phony = phonyHeader.exec(line);
|
|
@@ -8172,7 +9768,7 @@ function frameworkLinkClosure(scratch2, roots) {
|
|
|
8172
9768
|
for (const file of own) {
|
|
8173
9769
|
if (seen.has(file)) continue;
|
|
8174
9770
|
seen.add(file);
|
|
8175
|
-
if (!(0,
|
|
9771
|
+
if (!(0, import_node_fs10.existsSync)(file))
|
|
8176
9772
|
throw new Error(`swift-compile: framework object ${file} was not built`);
|
|
8177
9773
|
files.push(file);
|
|
8178
9774
|
}
|
|
@@ -8181,20 +9777,34 @@ function frameworkLinkClosure(scratch2, roots) {
|
|
|
8181
9777
|
files.sort();
|
|
8182
9778
|
return { objects: files, modules, moduleMaps: [...maps].sort() };
|
|
8183
9779
|
}
|
|
8184
|
-
function
|
|
8185
|
-
if (!(0,
|
|
8186
|
-
|
|
9780
|
+
function removeCaseCollidingModuleArtifacts(modulesDir, keep) {
|
|
9781
|
+
if (!(0, import_node_fs10.existsSync)(modulesDir)) return;
|
|
9782
|
+
const folded = new Set([...keep].map((name2) => name2.toLowerCase()));
|
|
9783
|
+
for (const name2 of (0, import_node_fs10.readdirSync)(modulesDir)) {
|
|
8187
9784
|
const dot = name2.indexOf(".");
|
|
8188
9785
|
if (dot <= 0) continue;
|
|
8189
|
-
|
|
8190
|
-
(
|
|
9786
|
+
const module2 = name2.slice(0, dot);
|
|
9787
|
+
if (keep.has(module2) || !folded.has(module2.toLowerCase())) continue;
|
|
9788
|
+
(0, import_node_fs10.rmSync)(import_node_path14.default.join(modulesDir, name2), { recursive: true, force: true });
|
|
8191
9789
|
}
|
|
8192
9790
|
}
|
|
8193
9791
|
async function compileFrameworkProducts(args) {
|
|
8194
|
-
const scratch2 = swiftFrameworkScratch(args.
|
|
8195
|
-
(0,
|
|
9792
|
+
const scratch2 = swiftFrameworkScratch(args.frameworkKey);
|
|
9793
|
+
(0, import_node_fs10.mkdirSync)(scratch2, { recursive: true });
|
|
9794
|
+
const now = /* @__PURE__ */ new Date();
|
|
9795
|
+
(0, import_node_fs10.utimesSync)(scratch2, now, now);
|
|
9796
|
+
return withSwiftRootLock(
|
|
9797
|
+
scratch2,
|
|
9798
|
+
(lease) => buildFrameworkProducts(scratch2, {
|
|
9799
|
+
...args,
|
|
9800
|
+
buildOptions: { ...args.buildOptions, lease }
|
|
9801
|
+
}),
|
|
9802
|
+
args.buildOptions.signal
|
|
9803
|
+
);
|
|
9804
|
+
}
|
|
9805
|
+
async function buildFrameworkProducts(scratch2, args) {
|
|
8196
9806
|
const linkedTargets = linkedFrameworkTargets(args.moduleRoot, args.input);
|
|
8197
|
-
const linkRoot =
|
|
9807
|
+
const linkRoot = import_node_path14.default.join(scratch2, "link");
|
|
8198
9808
|
writeFrameworkLinkPackage(linkRoot, args.moduleRoot, linkedTargets.products);
|
|
8199
9809
|
await runCompiler(
|
|
8200
9810
|
args.swift,
|
|
@@ -8211,7 +9821,7 @@ async function compileFrameworkProducts(args) {
|
|
|
8211
9821
|
scratch2,
|
|
8212
9822
|
"--target",
|
|
8213
9823
|
FRAMEWORK_LINK_TARGET,
|
|
8214
|
-
...
|
|
9824
|
+
...swiftCompileSdkOptions(args.moduleRoot, args.toolchainBin),
|
|
8215
9825
|
"--swift-sdk",
|
|
8216
9826
|
args.sdk,
|
|
8217
9827
|
"-c",
|
|
@@ -8238,47 +9848,78 @@ async function compileFrameworkProducts(args) {
|
|
|
8238
9848
|
args.buildOptions,
|
|
8239
9849
|
SWIFTPM_PROGRESS,
|
|
8240
9850
|
SWIFTPM_NOISE
|
|
8241
|
-
)
|
|
8242
|
-
|
|
9851
|
+
).catch((error) => {
|
|
9852
|
+
throw new Error(outputOf(error), { cause: error });
|
|
9853
|
+
});
|
|
9854
|
+
const release = import_node_path14.default.join(scratch2, WASM_TRIPLE, "release");
|
|
8243
9855
|
const linked = frameworkLinkClosure(scratch2, linkedTargets.targets);
|
|
8244
9856
|
const objects = linked.objects;
|
|
8245
|
-
|
|
8246
|
-
const response =
|
|
8247
|
-
(0,
|
|
9857
|
+
removeCaseCollidingModuleArtifacts(import_node_path14.default.join(release, "Modules"), linked.modules);
|
|
9858
|
+
const response = import_node_path14.default.join(scratch2, "autolink-objects.rsp");
|
|
9859
|
+
(0, import_node_fs10.writeFileSync)(response, objects.map((file) => JSON.stringify(file)).join("\n") + "\n");
|
|
8248
9860
|
const extracted = await runCompiler(
|
|
8249
|
-
|
|
9861
|
+
import_node_path14.default.join(args.toolchainBin, "swift-autolink-extract"),
|
|
8250
9862
|
[`@${response}`, "-o", "-"],
|
|
8251
9863
|
args.buildOptions
|
|
8252
9864
|
);
|
|
8253
|
-
(0,
|
|
9865
|
+
(0, import_node_fs10.rmSync)(response, { force: true });
|
|
8254
9866
|
const link = extracted.split("\n").map((line) => line.trim()).filter((flag, index, all) => flag.length > 0 && all.indexOf(flag) === index);
|
|
8255
9867
|
if (link.includes("-lFoundation"))
|
|
8256
9868
|
objects.push(
|
|
8257
|
-
|
|
9869
|
+
import_node_path14.default.join(
|
|
8258
9870
|
swiftSdkPaths(args.moduleRoot, args.toolchainBin).resources,
|
|
8259
9871
|
"wasi/NSStringFormatting.objc.o"
|
|
8260
9872
|
)
|
|
8261
9873
|
);
|
|
8262
9874
|
return {
|
|
8263
|
-
modules:
|
|
9875
|
+
modules: import_node_path14.default.join(release, "Modules"),
|
|
8264
9876
|
objects,
|
|
8265
9877
|
link,
|
|
8266
9878
|
moduleMaps: linked.moduleMaps
|
|
8267
9879
|
};
|
|
8268
9880
|
}
|
|
8269
9881
|
var SWIFT_LINK_STAMP = ".peach-link-stamp";
|
|
8270
|
-
var
|
|
8271
|
-
function
|
|
8272
|
-
return
|
|
9882
|
+
var SWIFT_FRAMEWORK_SCRATCHES_KEPT = 3;
|
|
9883
|
+
function swiftFrameworksDir() {
|
|
9884
|
+
return import_node_path14.default.join(swiftCacheDir(), "swift-frameworks");
|
|
9885
|
+
}
|
|
9886
|
+
function swiftFrameworkScratch(frameworkKey) {
|
|
9887
|
+
return import_node_path14.default.join(swiftFrameworksDir(), frameworkKey);
|
|
9888
|
+
}
|
|
9889
|
+
function stageFrameworkSource(moduleRoot, frameworkKey) {
|
|
9890
|
+
if (swiftDistributionAt(moduleRoot)) return moduleRoot;
|
|
9891
|
+
const staged = import_node_path14.default.join(swiftFrameworkScratch(frameworkKey), "source");
|
|
9892
|
+
const stagedModule = import_node_path14.default.join(staged, "packages", import_node_path14.default.basename(moduleRoot));
|
|
9893
|
+
if ((0, import_node_fs10.existsSync)(import_node_path14.default.join(staged, ".complete"))) return stagedModule;
|
|
9894
|
+
const partial = `${staged}.${(0, import_node_crypto7.randomUUID)()}`;
|
|
9895
|
+
(0, import_node_fs10.mkdirSync)(partial, { recursive: true });
|
|
9896
|
+
(0, import_node_fs10.cpSync)(moduleRoot, import_node_path14.default.join(partial, "packages", import_node_path14.default.basename(moduleRoot)), {
|
|
9897
|
+
recursive: true,
|
|
9898
|
+
preserveTimestamps: true,
|
|
9899
|
+
filter: (source) => import_node_path14.default.relative(moduleRoot, source) !== ".build"
|
|
9900
|
+
});
|
|
9901
|
+
(0, import_node_fs10.cpSync)(
|
|
9902
|
+
swiftSharedSdkRoot(moduleRoot, false),
|
|
9903
|
+
import_node_path14.default.join(partial, "packages/peachsim/sdk/ios"),
|
|
9904
|
+
{ recursive: true, preserveTimestamps: true }
|
|
9905
|
+
);
|
|
9906
|
+
(0, import_node_fs10.symlinkSync)(
|
|
9907
|
+
(0, import_node_fs10.realpathSync)(import_node_path14.default.join(moduleRoot, "../../node_modules")),
|
|
9908
|
+
import_node_path14.default.join(partial, "node_modules")
|
|
9909
|
+
);
|
|
9910
|
+
(0, import_node_fs10.writeFileSync)(import_node_path14.default.join(partial, ".complete"), "");
|
|
9911
|
+
(0, import_node_fs10.rmSync)(staged, { recursive: true, force: true });
|
|
9912
|
+
(0, import_node_fs10.renameSync)(partial, staged);
|
|
9913
|
+
return stagedModule;
|
|
8273
9914
|
}
|
|
8274
9915
|
function swiftLinkStamp(args) {
|
|
8275
|
-
const hash = (0,
|
|
9916
|
+
const hash = (0, import_node_crypto7.createHash)("sha256");
|
|
8276
9917
|
hash.update(`swift-link/v1
|
|
8277
9918
|
${args.frameworkKey}
|
|
8278
9919
|
`);
|
|
8279
9920
|
if (!args.prebuilt) return hash.digest("hex");
|
|
8280
9921
|
const statOf = (file) => {
|
|
8281
|
-
const stat = (0,
|
|
9922
|
+
const stat = (0, import_node_fs10.statSync)(file, { bigint: true });
|
|
8282
9923
|
return `${stat.size}:${stat.mtimeNs}`;
|
|
8283
9924
|
};
|
|
8284
9925
|
for (const object of args.prebuilt.objects)
|
|
@@ -8295,54 +9936,50 @@ ${args.prebuilt.link.join("\n")}
|
|
|
8295
9936
|
hash.update(`modules
|
|
8296
9937
|
${args.prebuilt.modules}
|
|
8297
9938
|
`);
|
|
8298
|
-
for (const entry of (0,
|
|
9939
|
+
for (const entry of (0, import_node_fs10.readdirSync)(args.prebuilt.modules).sort())
|
|
8299
9940
|
hash.update(`${entry}
|
|
8300
|
-
${statOf(
|
|
9941
|
+
${statOf(import_node_path14.default.join(args.prebuilt.modules, entry))}`);
|
|
8301
9942
|
return hash.digest("hex");
|
|
8302
9943
|
}
|
|
8303
|
-
function
|
|
8304
|
-
const
|
|
8305
|
-
|
|
8306
|
-
|
|
8307
|
-
|
|
8308
|
-
|
|
8309
|
-
|
|
8310
|
-
|
|
8311
|
-
|
|
8312
|
-
|
|
8313
|
-
const scratch2 = swiftFrameworkScratch(root);
|
|
8314
|
-
if (previous === key || !(0, import_node_fs9.existsSync)(scratch2)) return false;
|
|
8315
|
-
(0, import_node_fs9.rmSync)(scratch2, { recursive: true, force: true });
|
|
8316
|
-
return true;
|
|
9944
|
+
async function pruneFrameworkScratches(keep) {
|
|
9945
|
+
const dir = swiftFrameworksDir();
|
|
9946
|
+
const idle = (0, import_node_fs10.readdirSync)(dir).filter((name2) => name2 !== keep).map((name2) => ({ name: name2, modified: (0, import_node_fs10.statSync)(import_node_path14.default.join(dir, name2)).mtimeMs })).sort((left, right) => right.modified - left.modified).slice(SWIFT_FRAMEWORK_SCRATCHES_KEPT - 1);
|
|
9947
|
+
for (const { name: name2 } of idle)
|
|
9948
|
+
await withSwiftRootLock(
|
|
9949
|
+
import_node_path14.default.join(dir, name2),
|
|
9950
|
+
async () => (0, import_node_fs10.rmSync)(import_node_path14.default.join(dir, name2), { recursive: true, force: true }),
|
|
9951
|
+
void 0,
|
|
9952
|
+
false
|
|
9953
|
+
);
|
|
8317
9954
|
}
|
|
8318
9955
|
function retireStaleSwiftLink(root, stamp) {
|
|
8319
|
-
const receipt =
|
|
9956
|
+
const receipt = import_node_path14.default.join(root, SWIFT_LINK_STAMP);
|
|
8320
9957
|
let previous = null;
|
|
8321
9958
|
try {
|
|
8322
|
-
previous = (0,
|
|
9959
|
+
previous = (0, import_node_fs10.readFileSync)(receipt, "utf8").trim();
|
|
8323
9960
|
} catch (error) {
|
|
8324
9961
|
if (!vanished(error)) throw error;
|
|
8325
9962
|
}
|
|
8326
|
-
(0,
|
|
9963
|
+
(0, import_node_fs10.writeFileSync)(receipt, `${stamp}
|
|
8327
9964
|
`);
|
|
8328
|
-
const retired =
|
|
8329
|
-
if (previous === stamp || !(0,
|
|
8330
|
-
(0,
|
|
9965
|
+
const retired = import_node_path14.default.join(root, ".build");
|
|
9966
|
+
if (previous === stamp || !(0, import_node_fs10.existsSync)(retired)) return false;
|
|
9967
|
+
(0, import_node_fs10.rmSync)(retired, { recursive: true, force: true });
|
|
8331
9968
|
return true;
|
|
8332
9969
|
}
|
|
8333
9970
|
function compileSwiftProjectUnit(input, options) {
|
|
8334
9971
|
options.signal?.throwIfAborted();
|
|
8335
|
-
(0,
|
|
8336
|
-
const root = (0,
|
|
8337
|
-
const moduleRoot =
|
|
9972
|
+
(0, import_node_fs10.mkdirSync)(options.buildRoot, { recursive: true });
|
|
9973
|
+
const root = (0, import_node_fs10.realpathSync)(options.buildRoot);
|
|
9974
|
+
const moduleRoot = import_node_path14.default.resolve(options.moduleRoot);
|
|
8338
9975
|
const layout = {
|
|
8339
9976
|
root,
|
|
8340
|
-
sources:
|
|
9977
|
+
sources: import_node_path14.default.join(root, "Sources", "App"),
|
|
8341
9978
|
multi: compileTargets(input).length > 0
|
|
8342
9979
|
};
|
|
8343
9980
|
const hash = swiftArtifactHash(input, options.release, moduleRoot);
|
|
8344
9981
|
const frameworkKey = swiftProjectBuildKey(moduleRoot, options.release);
|
|
8345
|
-
const sharedRoot =
|
|
9982
|
+
const sharedRoot = import_node_path14.default.join(swiftCacheDir(), "swift-projects", hash);
|
|
8346
9983
|
const report = (message) => {
|
|
8347
9984
|
console.error(`[swift-project ${hash.slice(0, 16)}] ${message}`);
|
|
8348
9985
|
options.onStage?.(message);
|
|
@@ -8356,8 +9993,8 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8356
9993
|
report("reusing memory artifact");
|
|
8357
9994
|
return retain(root, retained);
|
|
8358
9995
|
}
|
|
8359
|
-
const cached = readCompiledArtifact(
|
|
8360
|
-
const previous = cached ?? readCompiledArtifact(
|
|
9996
|
+
const cached = readCompiledArtifact(import_node_path14.default.join(sharedRoot, "artifact"), hash);
|
|
9997
|
+
const previous = cached ?? readCompiledArtifact(import_node_path14.default.join(root, "artifact"), hash);
|
|
8361
9998
|
if (previous) {
|
|
8362
9999
|
if (cached) renewSharedArtifact(sharedRoot);
|
|
8363
10000
|
else saveSharedArtifact(sharedRoot, previous);
|
|
@@ -8365,10 +10002,10 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8365
10002
|
return retain(root, previous);
|
|
8366
10003
|
}
|
|
8367
10004
|
if (process.platform === "darwin" && process.env.TM_SESSION && !admittedMacBuilderSlot() && process.env.CI !== "true" && moduleRoot === sourceSwiftCheckout() && !swiftDistributionAt(moduleRoot)) {
|
|
8368
|
-
const requestRoot = (0,
|
|
8369
|
-
const output =
|
|
8370
|
-
const request =
|
|
8371
|
-
(0,
|
|
10005
|
+
const requestRoot = (0, import_node_fs10.mkdtempSync)(`${root}.builder-request-`);
|
|
10006
|
+
const output = import_node_path14.default.join(requestRoot, "output");
|
|
10007
|
+
const request = import_node_path14.default.join(requestRoot, "request.json");
|
|
10008
|
+
(0, import_node_fs10.writeFileSync)(
|
|
8372
10009
|
request,
|
|
8373
10010
|
JSON.stringify({
|
|
8374
10011
|
input,
|
|
@@ -8381,12 +10018,12 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8381
10018
|
})
|
|
8382
10019
|
);
|
|
8383
10020
|
try {
|
|
8384
|
-
const repo =
|
|
10021
|
+
const repo = import_node_path14.default.resolve(moduleRoot, "../..");
|
|
8385
10022
|
report("requesting builder admission or cached result");
|
|
8386
10023
|
await runCompiler(
|
|
8387
10024
|
"bun",
|
|
8388
10025
|
[
|
|
8389
|
-
|
|
10026
|
+
import_node_path14.default.join(repo, "scripts/build/swift-project.ts"),
|
|
8390
10027
|
"--request",
|
|
8391
10028
|
request,
|
|
8392
10029
|
"--output",
|
|
@@ -8414,33 +10051,40 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8414
10051
|
report("builder artifact verified");
|
|
8415
10052
|
return retain(root, artifact);
|
|
8416
10053
|
} finally {
|
|
8417
|
-
(0,
|
|
10054
|
+
(0, import_node_fs10.rmSync)(requestRoot, { recursive: true, force: true });
|
|
8418
10055
|
}
|
|
8419
10056
|
}
|
|
8420
10057
|
return withSwiftRootLock(
|
|
8421
10058
|
root,
|
|
8422
10059
|
async (lease) => {
|
|
8423
|
-
const built = readCompiledArtifact(
|
|
10060
|
+
const built = readCompiledArtifact(import_node_path14.default.join(sharedRoot, "artifact"), hash);
|
|
8424
10061
|
if (built) {
|
|
8425
10062
|
report("reusing verified disk artifact");
|
|
8426
10063
|
return retain(root, built);
|
|
8427
10064
|
}
|
|
8428
|
-
const swift =
|
|
8429
|
-
if (!(0,
|
|
10065
|
+
const swift = import_node_path14.default.join(options.toolchainBin, "swift");
|
|
10066
|
+
if (!(0, import_node_fs10.existsSync)(swift)) {
|
|
8430
10067
|
throw new Error(
|
|
8431
10068
|
`swift-compile: no swift.org toolchain at ${options.toolchainBin}; install ${options.release} and its matching wasm sdk`
|
|
8432
10069
|
);
|
|
8433
10070
|
}
|
|
8434
|
-
|
|
8435
|
-
|
|
10071
|
+
const frameworkRoot = await withSwiftRootLock(
|
|
10072
|
+
swiftFrameworkScratch(frameworkKey),
|
|
10073
|
+
async () => stageFrameworkSource(moduleRoot, frameworkKey),
|
|
10074
|
+
options.signal
|
|
10075
|
+
);
|
|
8436
10076
|
report("preparing compiler plugins");
|
|
8437
|
-
const macroPlugins = await
|
|
8438
|
-
|
|
8439
|
-
|
|
8440
|
-
|
|
10077
|
+
const macroPlugins = await withSwiftRootLock(
|
|
10078
|
+
swiftFrameworkScratch(frameworkKey),
|
|
10079
|
+
async () => ensureMacroPlugins(
|
|
10080
|
+
frameworkRoot,
|
|
10081
|
+
options.toolchainBin,
|
|
10082
|
+
options.release,
|
|
10083
|
+
options.signal
|
|
10084
|
+
),
|
|
8441
10085
|
options.signal
|
|
8442
10086
|
);
|
|
8443
|
-
const sdk = swiftModuleSdk(
|
|
10087
|
+
const sdk = swiftModuleSdk(frameworkRoot).wasmSdkId;
|
|
8444
10088
|
const icu = swiftIcuAsset(options.toolchainBin, sdk);
|
|
8445
10089
|
const buildOptions = {
|
|
8446
10090
|
env: {
|
|
@@ -8448,11 +10092,12 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8448
10092
|
// shipped host plugins resolve against the selected compiler's runtime.
|
|
8449
10093
|
...process.platform === "linux" ? {
|
|
8450
10094
|
LD_LIBRARY_PATH: [
|
|
8451
|
-
|
|
8452
|
-
|
|
10095
|
+
import_node_path14.default.resolve(options.toolchainBin, "../lib/swift/linux"),
|
|
10096
|
+
import_node_path14.default.resolve(options.toolchainBin, "../lib/swift/host"),
|
|
8453
10097
|
process.env.LD_LIBRARY_PATH
|
|
8454
10098
|
].filter(Boolean).join(":")
|
|
8455
|
-
} : {}
|
|
10099
|
+
} : {},
|
|
10100
|
+
...input.lazyDistribution ? { PEACH_DEFER_WASM_LINK: "1" } : {}
|
|
8456
10101
|
},
|
|
8457
10102
|
maxBuffer: 64 * 1024 * 1024,
|
|
8458
10103
|
timeout: options.timeoutMs,
|
|
@@ -8463,8 +10108,8 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8463
10108
|
if (!swiftDistributionAt(moduleRoot)) {
|
|
8464
10109
|
report("compiling framework products");
|
|
8465
10110
|
prebuilt = await compileFrameworkProducts({
|
|
8466
|
-
moduleRoot,
|
|
8467
|
-
|
|
10111
|
+
moduleRoot: frameworkRoot,
|
|
10112
|
+
frameworkKey,
|
|
8468
10113
|
input,
|
|
8469
10114
|
swift,
|
|
8470
10115
|
sdk,
|
|
@@ -8472,6 +10117,7 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8472
10117
|
plugins: macroPlugins,
|
|
8473
10118
|
buildOptions
|
|
8474
10119
|
});
|
|
10120
|
+
await pruneFrameworkScratches(frameworkKey);
|
|
8475
10121
|
}
|
|
8476
10122
|
if (retireStaleSwiftLink(
|
|
8477
10123
|
root,
|
|
@@ -8481,7 +10127,7 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8481
10127
|
})
|
|
8482
10128
|
))
|
|
8483
10129
|
report("framework revision changed; rebuilding the app link");
|
|
8484
|
-
const preparation = writeSwiftProject(layout, input,
|
|
10130
|
+
const preparation = writeSwiftProject(layout, input, frameworkRoot, prebuilt);
|
|
8485
10131
|
writeSwiftAutolinkLinker(root, options.toolchainBin);
|
|
8486
10132
|
const unprepared = preparation.targetFailures.map(
|
|
8487
10133
|
(failure) => `error: target ${failure}`
|
|
@@ -8495,10 +10141,10 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8495
10141
|
BUILD_JOBS,
|
|
8496
10142
|
"--package-path",
|
|
8497
10143
|
root,
|
|
8498
|
-
...
|
|
10144
|
+
...swiftCompileSdkOptions(frameworkRoot, options.toolchainBin),
|
|
8499
10145
|
"--swift-sdk",
|
|
8500
10146
|
sdk,
|
|
8501
|
-
...input.packageFiles || prebuilt ? ["--toolset",
|
|
10147
|
+
...input.packageFiles || prebuilt ? ["--toolset", import_node_path14.default.join(root, ".peach-target-toolset.json")] : [],
|
|
8502
10148
|
"-c",
|
|
8503
10149
|
"release",
|
|
8504
10150
|
"-Xswiftc",
|
|
@@ -8520,6 +10166,12 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8520
10166
|
`${plugin}#ExpoModulesMacros`
|
|
8521
10167
|
])
|
|
8522
10168
|
];
|
|
10169
|
+
const linked = builtArtifact(layout);
|
|
10170
|
+
if (input.lazyDistribution) {
|
|
10171
|
+
(0, import_node_fs10.rmSync)(import_node_path14.default.join(root, ".peach-link.rsp"), { force: true });
|
|
10172
|
+
if ((0, import_node_fs10.existsSync)(linked) && (0, import_node_fs10.statSync)(linked).size <= 8)
|
|
10173
|
+
(0, import_node_fs10.rmSync)(linked, { force: true });
|
|
10174
|
+
}
|
|
8523
10175
|
report("compiling and linking Swift modules");
|
|
8524
10176
|
try {
|
|
8525
10177
|
for (const producer of preparation.headerProducers) {
|
|
@@ -8540,15 +10192,15 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8540
10192
|
);
|
|
8541
10193
|
} catch (error) {
|
|
8542
10194
|
const output = outputOf(error);
|
|
8543
|
-
const moduleCache =
|
|
10195
|
+
const moduleCache = import_node_path14.default.join(
|
|
8544
10196
|
root,
|
|
8545
10197
|
".build",
|
|
8546
10198
|
WASM_TRIPLE,
|
|
8547
10199
|
"release",
|
|
8548
10200
|
"ModuleCache"
|
|
8549
10201
|
);
|
|
8550
|
-
if (output.includes("was compiled with module cache path") && (0,
|
|
8551
|
-
(0,
|
|
10202
|
+
if (output.includes("was compiled with module cache path") && (0, import_node_fs10.existsSync)(moduleCache)) {
|
|
10203
|
+
(0, import_node_fs10.rmSync)(moduleCache, { recursive: true, force: true });
|
|
8552
10204
|
try {
|
|
8553
10205
|
await runCompiler(
|
|
8554
10206
|
swift,
|
|
@@ -8576,9 +10228,21 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8576
10228
|
}
|
|
8577
10229
|
}
|
|
8578
10230
|
if (unprepared.length) throw new Error(unprepared.join("\n"));
|
|
10231
|
+
if (!(0, import_node_fs10.existsSync)(linked)) {
|
|
10232
|
+
const binDir = import_node_path14.default.dirname(linked);
|
|
10233
|
+
const found = (0, import_node_fs10.existsSync)(binDir) ? (0, import_node_fs10.readdirSync)(binDir).filter((name2) => name2.endsWith(".wasm")).sort() : [];
|
|
10234
|
+
throw new Error(
|
|
10235
|
+
`swift-compile: the build produced no ${import_node_path14.default.basename(linked)} (found: ${found.join(", ") || "none"})`
|
|
10236
|
+
);
|
|
10237
|
+
}
|
|
10238
|
+
const optimized = `${linked}.optimized`;
|
|
10239
|
+
if (input.lazyDistribution) {
|
|
10240
|
+
pruneSwiftWasmLink(root, options.toolchainBin, frameworkRoot);
|
|
10241
|
+
await optimizeWasm(linked, optimized);
|
|
10242
|
+
}
|
|
8579
10243
|
const artifact = {
|
|
8580
10244
|
hash,
|
|
8581
|
-
bytes: (0,
|
|
10245
|
+
bytes: (0, import_node_fs10.readFileSync)(input.lazyDistribution ? optimized : linked),
|
|
8582
10246
|
icu: await icu
|
|
8583
10247
|
};
|
|
8584
10248
|
saveCompiledArtifact(root, artifact);
|
|
@@ -8615,12 +10279,14 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
8615
10279
|
swiftCMainEntry,
|
|
8616
10280
|
swiftCPredefines,
|
|
8617
10281
|
swiftCodeMask,
|
|
10282
|
+
swiftCompileSdkOptions,
|
|
8618
10283
|
swiftDistributionAt,
|
|
8619
10284
|
swiftIcuAsset,
|
|
8620
10285
|
swiftImportNames,
|
|
8621
10286
|
swiftMacroPlugins,
|
|
8622
10287
|
swiftModuleDigest,
|
|
8623
10288
|
swiftModuleInputFiles,
|
|
10289
|
+
swiftModuleInterface,
|
|
8624
10290
|
swiftModuleSdk,
|
|
8625
10291
|
swiftPeachModules,
|
|
8626
10292
|
swiftProjectBuildKey,
|