peachsim 0.1.1716 → 0.1.1728
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 +21 -3
- package/cli/app-bundle-resources.ts +2 -1
- package/cli/app-fonts.ts +4 -4
- package/cli/app-splash.ts +4 -4
- package/cli/app-stubs.ts +17 -0
- package/cli/command-registry.ts +1 -0
- package/cli/commands/control.ts +82 -822
- package/cli/commands/daemon.ts +8 -0
- package/cli/commands/detox.ts +3 -0
- package/cli/commands/doctor.ts +19 -2
- package/cli/commands/inspect/actions.ts +74 -14
- package/cli/commands/inspect/core.ts +5 -1
- package/cli/commands/inspect/settling.ts +5 -2
- package/cli/commands/inspect/wait-ready.ts +6 -0
- package/cli/commands/inspect.ts +48 -45
- package/cli/commands/kotlin.ts +12 -2
- package/cli/commands/package.ts +750 -0
- package/cli/commands/serve.ts +6 -0
- package/cli/commands/shell-url.ts +834 -0
- package/cli/commands/swift.ts +42 -102
- package/cli/commands/test.ts +20 -0
- package/cli/commands/upload.ts +1 -1
- package/cli/device-option.ts +1 -1
- package/cli/main.ts +13 -1
- package/cli/native-input.ts +199 -0
- package/cli/outbound-endpoints.ts +26 -1
- package/cli/packaged-app-launcher.ts +95 -0
- package/cli/scene-video.ts +13 -6
- package/detox/index.ts +187 -23
- 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 +38000 -31658
- 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 +184 -60
- package/dist-lib/dev-bundle-resolution.cjs +14 -13
- package/dist-lib/expo-swift-bundle.cjs +18199 -11834
- package/dist-lib/expo-swift-metadata.cjs +4 -1
- package/dist-lib/expo-swift-metadata.mjs +3 -1
- package/dist-lib/home-paths.cjs +21 -2
- package/dist-lib/host/bridge-host.cjs +26509 -23850
- package/dist-lib/host/fetch-proxy-handler.cjs +221 -222
- 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 +1 -1
- package/dist-lib/index.cjs +876 -389
- 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 +127 -16
- package/dist-lib/menu.cjs +7 -1
- package/dist-lib/menu.mjs +7 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +883 -404
- package/dist-lib/native-app-identity-project.cjs +694 -280
- package/dist-lib/native-app-identity-project.mjs +490 -83
- package/dist-lib/native-app-identity.cjs +13 -2
- package/dist-lib/native-app-identity.mjs +13 -2
- 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 +28 -23
- package/dist-lib/public-origins-lib.json +392 -224
- package/dist-lib/react-native-host-modules.cjs +32 -2
- package/dist-lib/react-native-host-modules.mjs +32 -2
- package/dist-lib/reap-browser.cjs +12 -4
- package/dist-lib/scripts/dev-server-scanner.cjs +15 -8
- package/dist-lib/sdk.cjs +17 -7
- package/dist-lib/sdk.mjs +16 -7
- package/dist-lib/skills.cjs +61838 -47851
- package/dist-lib/swift-compile.cjs +583 -360
- package/dist-lib/swift-compile.mjs +496 -275
- 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 +105 -17
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +4453 -2231
- package/dist-lib/vite.cjs +230 -228
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +1 -1
- package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-cookies.d.ts +17 -8
- package/dist-types/packages/peach-engine/src/engine/canvaskit-renderer.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +7 -5
- package/dist-types/packages/peach-engine/src/engine/memory-counts.d.ts +3 -1
- package/dist-types/packages/peach-engine/src/engine/node.d.ts +1 -11
- package/dist-types/packages/peach-engine/src/engine/types.d.ts +3 -0
- package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +9 -0
- package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +3 -0
- package/dist-types/packages/peach-engine/src/render-worker/native-ui-commandContract.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/render-worker/shell-protocol.d.ts +4 -0
- package/dist-types/packages/peach-engine/src/render-worker/tree-sync-port.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +23 -1
- package/dist-types/packages/peach-engine/src/shell-events.d.ts +1 -0
- package/dist-types/packages/peach-globals/src/audioBridgeContract.d.ts +5 -0
- package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
- package/dist-types/packages/peach-globals/src/keyboardBridgeContract.d.ts +11 -0
- package/dist-types/packages/peach-globals/src/shellBridgeContract.d.ts +1 -0
- package/dist-types/packages/peach-globals/src/testBridgeContract.d.ts +9 -2
- package/package.json +1 -1
- package/runtime-companion.json +1 -1
- package/scripts/dev-server-scanner.ts +12 -25
- package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASFoundation.h +52 -0
- package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASWebAuthenticationSession.h +128 -0
- package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASWebAuthenticationSessionCallback.h +35 -0
- package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/AuthenticationServices.h +3 -0
- package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Modules/module.modulemap +5 -0
- package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFHTTPMessage.h +724 -0
- package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetwork.h +4 -0
- package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetworkDefs.h +27 -0
- package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Modules/module.modulemap +5 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFURL.h +1301 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h +2 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationManager.h +21 -50
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLRegion.h +6 -6
- package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +75 -9
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h +12 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIInterface.h +23 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h +7 -9
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIOrientation.h +14 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIStringDrawing.h +12 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIView.h +14 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIViewAnimating.h +12 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIViewController.h +16 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIWindow.h +2 -0
- package/sdk/ios/usr/include/ConditionalMacros.h +619 -0
- package/sdk/ios/usr/include/module.modulemap +1 -0
- package/sdk/ios/usr/include/objc/objc-sync.h +59 -0
- package/sdk/ios/usr/include/os.modulemap +5 -0
- package/sdk/ios/usr/include/sys/cdefs.h +5 -0
- package/sdk/ios/usr/include/sys/ioccom.h +99 -0
- package/sdk/ios/usr/include/sys/syslog.h +236 -0
- package/sdk/ios/usr/include/syslog.h +24 -0
- package/sdk/ios/wasm/include/fcntl.h +4 -2
- package/sdk/ios/wasm/include/stdio.h +24 -0
- package/sdk/ios/wasm/include/stdlib.h +32 -7
- package/sdk/ios/wasm/include/sys/file.h +7 -0
- package/sdk/ios/wasm/include/sys/ioctl.h +6 -0
- package/sdk/ios/wasm/include/sys/syscall.h +9 -0
- package/sdk/ios/wasm/include/sys/time.h +10 -0
- package/sdk/ios/wasm/include/unistd.h +12 -3
- package/sdk/native-hashes.json +1 -0
- package/skills/contrast/SKILL.md +2 -1
- package/skills/peach-test/SKILL.md +7 -3
- package/src/admitted-mac-build.ts +3 -0
- package/src/android-app-identity.ts +18 -0
- package/src/android-root-module.ts +9 -9
- package/src/appPackageContract.ts +81 -0
- package/src/bridge-contract.ts +50 -0
- package/src/bundle-channel.mjs +21 -4
- package/src/dev-bundle-resolution.ts +7 -27
- package/src/dom-source-reference.ts +15 -0
- package/src/expo-discovery-cache.ts +127 -23
- package/src/expo-manifest-body.ts +33 -0
- package/src/expo-native-workspace.ts +38 -13
- package/src/expo-swift-host.ts +264 -62
- package/src/expoSwiftContract.ts +3 -0
- package/src/generated/swift-c-predefines.json +1 -1
- package/src/home-paths.ts +35 -1
- package/src/host/app-package-handler.ts +47 -0
- package/src/host/bridge-host.ts +3 -0
- package/src/host/staged-host-files.ts +18 -0
- package/src/index.ts +3 -0
- package/src/kotlin-host.ts +21 -18
- package/src/kotlin-instance-source.ts +126 -0
- package/src/menu.ts +7 -0
- package/src/native-app-identity-project.ts +7 -2
- package/src/native-app-identity.ts +11 -0
- package/src/native-firebase-config.ts +24 -1
- package/src/nitro-adapter.lock.json +268 -268
- package/src/nitro-bundle.ts +8 -0
- package/src/nitro-compile.ts +35 -9
- package/src/nitro-dependencies.ts +21 -19
- package/src/nitro-source.ts +4 -0
- package/src/nitroContract.ts +7 -0
- package/src/react-native-bridge-modules.ts +68 -42
- package/src/react-native-host-modules.ts +31 -1
- package/src/reactNativeConfigurationContract.ts +14 -0
- package/src/reap-browser.ts +15 -3
- package/src/sdk.ts +5 -0
- package/src/settingsContract.ts +27 -1
- package/src/sim-client.ts +4 -1
- package/src/storageSnapshotContract.ts +3 -0
- package/src/swift-compile.ts +221 -41
- package/src/swift-coverage/provenance.ts +1 -0
- package/src/swift-coverage/xcode-asset-symbols.ts +922 -0
- package/src/swift-coverage/xcode-assets.ts +89 -131
- package/src/swift-coverage/xcode.ts +1 -1
- package/src/swift-cxx-reachable.ts +2 -1
- package/src/swift-distribution.lock.json +14 -13
- package/src/swift-host.ts +95 -22
- package/src/swift-icu.ts +1 -1
- package/src/swift-link-roots.ts +118 -0
- package/src/swift-objc-compile.ts +144 -22
- package/src/swift-objc-import.ts +6 -0
- package/src/swift-objc-standin.ts +2 -14
- package/src/swift-package-manifest.ts +14 -6
- package/src/swift-packages.ts +75 -11
- package/src/swift-pdf-raster.ts +1 -0
- package/src/swift-root-lock.ts +17 -1
- package/src/swift-source-pods.ts +2 -10
- package/src/swift-standin-emit.ts +592 -57
- package/src/swift-standins.ts +430 -49
- package/src/swift-submit.ts +3 -1
- package/src/swift-toolchain.ts +140 -17
- package/src/turbo-codegen-intake.ts +91 -0
- package/src/vite-plugin-one.ts +13 -9
- package/src/vite-plugin.ts +28 -15
- package/src/xcode-project.ts +223 -22
package/src/swift-host.ts
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
import { compileStringCatalog } from '../../sootsim-swift/src/stringCatalog'
|
|
14
14
|
import { authHeaderValue, resolveCliAuth } from '../cli/auth'
|
|
15
15
|
import { resolveContrastBackendOrigin } from './backend-origin'
|
|
16
|
-
import {
|
|
16
|
+
import { swiftCacheDir } from './home-paths'
|
|
17
17
|
import iosSdk from './ios-sdk-frameworks.json' with { type: 'json' }
|
|
18
18
|
import { type NativeAppIdentity } from './native-app-identity'
|
|
19
19
|
import { readNativeAppIdentityFromXcodeTarget } from './native-app-identity-project'
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
compileTargets,
|
|
25
25
|
missingSwiftModules,
|
|
26
26
|
swiftAvailableModules,
|
|
27
|
+
swiftSystemLibrarySurface,
|
|
27
28
|
swiftImportNames,
|
|
28
29
|
swiftPeachModules,
|
|
29
30
|
withNativeSourceGlue,
|
|
@@ -153,6 +154,7 @@ function swiftPackageId(packagePath: string): string {
|
|
|
153
154
|
|
|
154
155
|
export function nativeSourceDescriptor(packagePath: string): SwiftNativeModules | null {
|
|
155
156
|
packagePath = fs.realpathSync(packagePath)
|
|
157
|
+
if (sourceEntries.has(packagePath)) return null
|
|
156
158
|
const file = path.join(packagePath, NATIVE_DESCRIPTOR)
|
|
157
159
|
if (!fs.existsSync(file)) return null
|
|
158
160
|
const value: unknown = JSON.parse(
|
|
@@ -176,6 +178,7 @@ export function nativeSourceDescriptor(packagePath: string): SwiftNativeModules
|
|
|
176
178
|
|
|
177
179
|
export function nativeSourceFiles(packagePath: string): string[] {
|
|
178
180
|
packagePath = fs.realpathSync(packagePath)
|
|
181
|
+
if (sourceEntries.has(packagePath)) return []
|
|
179
182
|
return [NATIVE_DESCRIPTOR, NATIVE_GLUE]
|
|
180
183
|
.map((name) => path.join(packagePath, name))
|
|
181
184
|
.filter((file) => fs.existsSync(file))
|
|
@@ -223,6 +226,7 @@ export interface SwiftProject {
|
|
|
223
226
|
hosted?: SwiftHostedCompileOptions
|
|
224
227
|
signal?: AbortSignal
|
|
225
228
|
libraries?: Record<string, string>
|
|
229
|
+
lazyDistribution?: boolean
|
|
226
230
|
nativeTargets?: SwiftNativeTarget[]
|
|
227
231
|
nativeFiles?: Record<string, string>
|
|
228
232
|
resourceBundles?: SwiftResourceBundle[]
|
|
@@ -232,6 +236,18 @@ export interface SwiftProject {
|
|
|
232
236
|
// a project is its swiftpm package: the build, the artifact, and the dev
|
|
233
237
|
// server that serves it are shared by every plugin instance in this process.
|
|
234
238
|
const projects = new Map<string, SwiftProject>()
|
|
239
|
+
const sourceEntries = new Map<string, string>()
|
|
240
|
+
|
|
241
|
+
// a loose entry compiles alone through the same manifest-free project compiler.
|
|
242
|
+
export function openSwiftFile(file: string): string {
|
|
243
|
+
file = fs.realpathSync(file)
|
|
244
|
+
const root = path.dirname(file)
|
|
245
|
+
const existing = sourceEntries.get(root)
|
|
246
|
+
if (existing && existing !== file)
|
|
247
|
+
throw new Error(`Swift input ${root} already owns ${existing}`)
|
|
248
|
+
sourceEntries.set(root, file)
|
|
249
|
+
return root
|
|
250
|
+
}
|
|
235
251
|
|
|
236
252
|
export interface SwiftHostedCompileOptions {
|
|
237
253
|
origin: string
|
|
@@ -466,8 +482,9 @@ function swiftPackages(
|
|
|
466
482
|
: [],
|
|
467
483
|
)
|
|
468
484
|
let reached = [...cached.binaries.filter((binary) => binary.reached), ...vendored]
|
|
469
|
-
// a binary artifact,
|
|
470
|
-
// compiling:
|
|
485
|
+
// a binary artifact, a source target whose assembly sources keep it from
|
|
486
|
+
// compiling, or a placeholder package's swift target: each stands in from
|
|
487
|
+
// its public surface.
|
|
471
488
|
const standinArtifact = (binary: SwiftPackageBinary) =>
|
|
472
489
|
binary.publicHeaders === undefined || binary.assemblySources !== undefined
|
|
473
490
|
const artifacts = reached.filter(standinArtifact)
|
|
@@ -512,7 +529,18 @@ function swiftPackages(
|
|
|
512
529
|
cached.standinKey = generation
|
|
513
530
|
}
|
|
514
531
|
}
|
|
515
|
-
|
|
532
|
+
// what only a placeholder imported is no longer linked once it stands in
|
|
533
|
+
const linked = new Set(
|
|
534
|
+
[...cached.packages.binaries.filter((binary) => binary.reached), ...vendored].map(
|
|
535
|
+
(binary) => `${binary.source}\0${binary.target}`,
|
|
536
|
+
),
|
|
537
|
+
)
|
|
538
|
+
return {
|
|
539
|
+
...cached,
|
|
540
|
+
binaries: reached.filter((binary) =>
|
|
541
|
+
linked.has(`${binary.source}\0${binary.target}`),
|
|
542
|
+
),
|
|
543
|
+
}
|
|
516
544
|
}
|
|
517
545
|
|
|
518
546
|
// the app target's sources compile as one executable target under this
|
|
@@ -856,12 +884,7 @@ function buildXcodeLayout(root: string): XcodeLayout | null {
|
|
|
856
884
|
target.remote ? path.posix.join(XCODE_PACKAGES_DIR, posix) : posix,
|
|
857
885
|
'GeneratedAssetSymbols.swift',
|
|
858
886
|
)
|
|
859
|
-
] = generatePackageAssetSymbols(
|
|
860
|
-
catalogs,
|
|
861
|
-
target.packageDir,
|
|
862
|
-
target.iosDeployment,
|
|
863
|
-
`${path.basename(target.packageDir).toLowerCase()}.${target.name}`,
|
|
864
|
-
)
|
|
887
|
+
] = generatePackageAssetSymbols(catalogs, target.packageDir, target.iosDeployment)
|
|
865
888
|
}
|
|
866
889
|
}
|
|
867
890
|
// swiftpm assigns a file to one target: a target directory nested in
|
|
@@ -1132,6 +1155,8 @@ function xcodeManifest(layout: XcodeLayout): string {
|
|
|
1132
1155
|
// a nested package is a separate compile unit; ignored build trees never enter it.
|
|
1133
1156
|
function packageFiles(root: string, includeBuildInputs = true): string[] {
|
|
1134
1157
|
const canonicalRoot = fs.realpathSync(root)
|
|
1158
|
+
const source = sourceEntries.get(canonicalRoot)
|
|
1159
|
+
if (source) return [source]
|
|
1135
1160
|
const xcode = xcodeLayout(canonicalRoot)
|
|
1136
1161
|
if (!xcode) return sourceTreeFiles(canonicalRoot, canonicalRoot)
|
|
1137
1162
|
if (includeBuildInputs) return xcode.files
|
|
@@ -1301,7 +1326,8 @@ export function swiftProjectAppInfo(packagePath: string): {
|
|
|
1301
1326
|
break
|
|
1302
1327
|
}
|
|
1303
1328
|
return {
|
|
1304
|
-
name:
|
|
1329
|
+
name:
|
|
1330
|
+
app?.name ?? path.basename(sourceEntries.get(packagePath) ?? packagePath, '.swift'),
|
|
1305
1331
|
icon,
|
|
1306
1332
|
identity: app ? readNativeAppIdentityFromXcodeTarget(app) : null,
|
|
1307
1333
|
}
|
|
@@ -1612,14 +1638,14 @@ export function buildSwiftBundleFiles(
|
|
|
1612
1638
|
watched.push(relative.split(path.sep).join('/'))
|
|
1613
1639
|
}
|
|
1614
1640
|
}
|
|
1615
|
-
const groups = new Map<string, string
|
|
1641
|
+
const groups = new Map<string, Map<string, string>>()
|
|
1616
1642
|
for (const file of relative) {
|
|
1617
1643
|
const disk = path.join(packagePath, ...file.split('/'))
|
|
1618
1644
|
const key = xcode ? xcodeInputKey(xcode, disk, file) : file
|
|
1619
1645
|
const bundle = swiftResourceBundleForFile(bundles, key)
|
|
1620
1646
|
const bundlePath = bundle?.path ?? '.'
|
|
1621
|
-
const group = groups.get(bundlePath) ??
|
|
1622
|
-
group.
|
|
1647
|
+
const group = groups.get(bundlePath) ?? new Map<string, string>()
|
|
1648
|
+
group.set(file, disk)
|
|
1623
1649
|
groups.set(bundlePath, group)
|
|
1624
1650
|
}
|
|
1625
1651
|
for (const bundle of bundles) {
|
|
@@ -1629,10 +1655,20 @@ export function buildSwiftBundleFiles(
|
|
|
1629
1655
|
Buffer.from(swiftResourceBundleInfoPlist(bundle)),
|
|
1630
1656
|
)
|
|
1631
1657
|
}
|
|
1632
|
-
for (const
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1658
|
+
for (const product of xcode?.app.resourceProducts ?? []) {
|
|
1659
|
+
addFile(`${product.path}/Info.plist`, Buffer.from(product.infoPlist))
|
|
1660
|
+
const group = groups.get(product.path) ?? new Map<string, string>()
|
|
1661
|
+
for (const file of product.resources)
|
|
1662
|
+
group.set(
|
|
1663
|
+
`Resources/${path.relative(packagePath, file).split(path.sep).join('/')}`,
|
|
1664
|
+
file,
|
|
1665
|
+
)
|
|
1666
|
+
groups.set(product.path, group)
|
|
1667
|
+
}
|
|
1668
|
+
for (const [bundlePath, members] of groups) {
|
|
1669
|
+
for (const { base, file } of enumerateBundleResources([...members.keys()])) {
|
|
1670
|
+
const disk = members.get(file)!
|
|
1671
|
+
watched.push(path.relative(packagePath, disk).split(path.sep).join('/'))
|
|
1636
1672
|
const bytes = readPackageFile(packagePath, disk, limits.resourceBytes)
|
|
1637
1673
|
addFile(bundlePath === '.' ? base : `${bundlePath}/${base}`, bytes)
|
|
1638
1674
|
if (base.endsWith('.xcstrings')) {
|
|
@@ -1697,6 +1733,7 @@ export function sourceStamp(
|
|
|
1697
1733
|
hash.update(JSON.stringify(xcodeProjects.get(packagePath)?.behavior ?? {}))
|
|
1698
1734
|
const libraries = projects.get(packagePath)?.libraries
|
|
1699
1735
|
if (libraries) hash.update(JSON.stringify(libraries))
|
|
1736
|
+
if (projects.get(packagePath)?.lazyDistribution) hash.update('lazy-distribution')
|
|
1700
1737
|
hash.update(JSON.stringify(projects.get(packagePath)?.nativeTargets ?? []))
|
|
1701
1738
|
hash.update(JSON.stringify(projects.get(packagePath)?.nativeFiles ?? {}))
|
|
1702
1739
|
hash.update(JSON.stringify(projects.get(packagePath)?.resourceBundles ?? []))
|
|
@@ -1721,6 +1758,7 @@ export function sourceContentStamp(
|
|
|
1721
1758
|
hash.update(JSON.stringify(xcodeProjects.get(packagePath)?.behavior ?? {}))
|
|
1722
1759
|
const libraries = projects.get(packagePath)?.libraries
|
|
1723
1760
|
if (libraries) hash.update(JSON.stringify(libraries))
|
|
1761
|
+
if (projects.get(packagePath)?.lazyDistribution) hash.update('lazy-distribution')
|
|
1724
1762
|
hash.update(JSON.stringify(projects.get(packagePath)?.nativeTargets ?? []))
|
|
1725
1763
|
hash.update(JSON.stringify(projects.get(packagePath)?.nativeFiles ?? {}))
|
|
1726
1764
|
hash.update(JSON.stringify(projects.get(packagePath)?.resourceBundles ?? []))
|
|
@@ -1853,6 +1891,7 @@ interface SwiftPackageSnapshot {
|
|
|
1853
1891
|
packageGuestImports?: string[]
|
|
1854
1892
|
files: Record<string, string>
|
|
1855
1893
|
nativeTargets?: SwiftNativeTarget[]
|
|
1894
|
+
defaultLocalization?: string
|
|
1856
1895
|
entry: string
|
|
1857
1896
|
resourcePaths: string[]
|
|
1858
1897
|
resources: SwiftResourceTable
|
|
@@ -1860,6 +1899,7 @@ interface SwiftPackageSnapshot {
|
|
|
1860
1899
|
native: SwiftNativeModules | null
|
|
1861
1900
|
glue?: string
|
|
1862
1901
|
libraries?: Record<string, string>
|
|
1902
|
+
lazyDistribution?: boolean
|
|
1863
1903
|
}
|
|
1864
1904
|
|
|
1865
1905
|
function packageSnapshot(project: SwiftProject, entry: string): SwiftPackageSnapshot {
|
|
@@ -1937,6 +1977,7 @@ function packageSnapshot(project: SwiftProject, entry: string): SwiftPackageSnap
|
|
|
1937
1977
|
...((project.nativeTargets ?? layout?.nativeTargets)?.length
|
|
1938
1978
|
? { nativeTargets: project.nativeTargets ?? layout?.nativeTargets }
|
|
1939
1979
|
: {}),
|
|
1980
|
+
...(layout ? { defaultLocalization: layout.app.developmentRegion } : {}),
|
|
1940
1981
|
entry: layout
|
|
1941
1982
|
? xcodeInputKey(layout, path.resolve(project.packagePath, entry), entry)
|
|
1942
1983
|
: entry,
|
|
@@ -1959,6 +2000,7 @@ function packageSnapshot(project: SwiftProject, entry: string): SwiftPackageSnap
|
|
|
1959
2000
|
project.resourceBundles,
|
|
1960
2001
|
),
|
|
1961
2002
|
native,
|
|
2003
|
+
...(project.lazyDistribution ? { lazyDistribution: true } : {}),
|
|
1962
2004
|
...(linked.size > 0 || project.libraries
|
|
1963
2005
|
? {
|
|
1964
2006
|
libraries: {
|
|
@@ -1995,6 +2037,9 @@ function snapshotCompileInput(snapshot: SwiftPackageSnapshot): SwiftCompileInput
|
|
|
1995
2037
|
: {}),
|
|
1996
2038
|
...(snapshot.projectFiles ? { projectFiles: snapshot.projectFiles } : {}),
|
|
1997
2039
|
...(snapshot.nativeTargets ? { nativeTargets: snapshot.nativeTargets } : {}),
|
|
2040
|
+
...(snapshot.defaultLocalization
|
|
2041
|
+
? { defaultLocalization: snapshot.defaultLocalization }
|
|
2042
|
+
: {}),
|
|
1998
2043
|
metalSources: snapshot.resources.metalUploads,
|
|
1999
2044
|
resourcePaths: snapshot.resourcePaths,
|
|
2000
2045
|
resourceBundles: snapshot.bundleFiles.bundles,
|
|
@@ -2003,6 +2048,7 @@ function snapshotCompileInput(snapshot: SwiftPackageSnapshot): SwiftCompileInput
|
|
|
2003
2048
|
entry: snapshot.entry,
|
|
2004
2049
|
oneModule: true,
|
|
2005
2050
|
...(snapshot.libraries ? { libraries: snapshot.libraries } : {}),
|
|
2051
|
+
...(snapshot.lazyDistribution ? { lazyDistribution: true } : {}),
|
|
2006
2052
|
}
|
|
2007
2053
|
return snapshot.glue ? withNativeSourceGlue(input, snapshot.glue) : input
|
|
2008
2054
|
}
|
|
@@ -2079,6 +2125,8 @@ async function compile(
|
|
|
2079
2125
|
...swiftAvailableModules(moduleRoot, toolchain.toolchainBin),
|
|
2080
2126
|
// a project without a manifest compiles as the template's one App target
|
|
2081
2127
|
...(targets.length > 0 ? targets : ['App']),
|
|
2128
|
+
// a system target's clang module name need not match its target name
|
|
2129
|
+
...swiftSystemLibrarySurface(input.files, parsed).modules,
|
|
2082
2130
|
...snapshot.nativeModules,
|
|
2083
2131
|
]),
|
|
2084
2132
|
providedByFile,
|
|
@@ -2106,9 +2154,9 @@ async function compile(
|
|
|
2106
2154
|
const buildKeyPath =
|
|
2107
2155
|
expoAt >= 0 && parts.length >= expoAt + 3
|
|
2108
2156
|
? parts.slice(0, scoped ? expoAt + 3 : expoAt + 2).join(path.sep)
|
|
2109
|
-
: resolvedPath
|
|
2157
|
+
: (sourceEntries.get(resolvedPath) ?? resolvedPath)
|
|
2110
2158
|
return path.join(
|
|
2111
|
-
|
|
2159
|
+
swiftCacheDir(),
|
|
2112
2160
|
'swift-builds',
|
|
2113
2161
|
createHash('sha256')
|
|
2114
2162
|
.update(`${moduleRoot}\0${buildKeyPath}`)
|
|
@@ -2488,7 +2536,9 @@ export function swiftPackageWatchFiles(
|
|
|
2488
2536
|
): string[] {
|
|
2489
2537
|
packagePath = fs.realpathSync(packagePath)
|
|
2490
2538
|
return [
|
|
2491
|
-
...(xcodeProjects.has(packagePath)
|
|
2539
|
+
...(xcodeProjects.has(packagePath) || sourceEntries.has(packagePath)
|
|
2540
|
+
? []
|
|
2541
|
+
: [path.join(packagePath, 'Package.swift')]),
|
|
2492
2542
|
...packageFiles(packagePath),
|
|
2493
2543
|
...nativeSourceFiles(packagePath),
|
|
2494
2544
|
...(moduleRoot
|
|
@@ -2674,9 +2724,32 @@ export function serveSwiftPackageAsset(pathname: string, res: ServerResponse): b
|
|
|
2674
2724
|
return true
|
|
2675
2725
|
}
|
|
2676
2726
|
|
|
2727
|
+
// packages retain the exact bytes the foreground host serves, including ICU.
|
|
2728
|
+
export function swiftPackageAssets(packagePath: string, hash: string) {
|
|
2729
|
+
const project = projects.get(fs.realpathSync(packagePath))
|
|
2730
|
+
const artifact = project?.artifacts.find((candidate) => candidate.hash === hash)
|
|
2731
|
+
if (!project || !artifact) throw new Error(`Swift artifact ${hash} was not built`)
|
|
2732
|
+
const assets = new Map<string, { bytes: Buffer; contentType: string }>([
|
|
2733
|
+
[
|
|
2734
|
+
`${ARTIFACT_PATH}${hash}.wasm`,
|
|
2735
|
+
{ bytes: artifact.bytes, contentType: 'application/wasm' },
|
|
2736
|
+
],
|
|
2737
|
+
])
|
|
2738
|
+
for (const [key, resource] of project.resourceFiles)
|
|
2739
|
+
assets.set(`${RESOURCE_PATH}${key}`, resource)
|
|
2740
|
+
if ('sha256' in artifact.icu)
|
|
2741
|
+
assets.set(`${ICU_PATH}${artifact.icu.sha256}`, {
|
|
2742
|
+
bytes: artifact.icu.gzip,
|
|
2743
|
+
contentType: 'application/gzip',
|
|
2744
|
+
})
|
|
2745
|
+
return assets
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2677
2748
|
export function disposeSwiftProject(packagePath: string, signal?: AbortSignal): void {
|
|
2678
2749
|
packagePath = fs.realpathSync(packagePath)
|
|
2679
|
-
|
|
2750
|
+
const project = projects.get(packagePath)
|
|
2751
|
+
if (signal && project && project.signal !== signal) return
|
|
2680
2752
|
projects.delete(packagePath)
|
|
2681
2753
|
xcodeProjects.delete(packagePath)
|
|
2754
|
+
sourceEntries.delete(packagePath)
|
|
2682
2755
|
}
|
package/src/swift-icu.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface SwiftIcuAsset {
|
|
|
22
22
|
/**
|
|
23
23
|
* the blob gzipped, which is how every host stores and serves it: 34 MB
|
|
24
24
|
* raw is 13 MB gzipped, and cloudflare compresses no binary type on its
|
|
25
|
-
* own. the tenant inflates it with
|
|
25
|
+
* own. the tenant inflates it with the shared gzip decoder.
|
|
26
26
|
*/
|
|
27
27
|
gzip: Buffer
|
|
28
28
|
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// which distribution objects a link must keep whole when the rest of the
|
|
2
|
+
// distribution links as an archive. the gnustep ObjC runtime registers an
|
|
3
|
+
// object's classes, protocols and categories from its own initializer, and
|
|
4
|
+
// nothing references that object by symbol, so an archive pass would never
|
|
5
|
+
// load it. every other object is pulled by the symbols the program uses, as
|
|
6
|
+
// SwiftPM links a static Swift library.
|
|
7
|
+
import fs from 'node:fs'
|
|
8
|
+
import path from 'node:path'
|
|
9
|
+
|
|
10
|
+
const OBJC_SEGMENTS = [
|
|
11
|
+
'__objc_classes',
|
|
12
|
+
'__objc_protocols',
|
|
13
|
+
'__objc_cats',
|
|
14
|
+
'__objc_class_aliases',
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
const leb = (bytes: Uint8Array, at: { offset: number }): number => {
|
|
18
|
+
let value = 0
|
|
19
|
+
let scale = 1
|
|
20
|
+
for (;;) {
|
|
21
|
+
const byte = bytes[at.offset++]!
|
|
22
|
+
value += (byte & 0x7f) * scale
|
|
23
|
+
if (!(byte & 0x80)) return value
|
|
24
|
+
scale *= 128
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// data segment name to its summed size in one wasm object. the linking
|
|
29
|
+
// section names each segment and the data section sizes them in the same order.
|
|
30
|
+
function objcSegmentSizes(bytes: Uint8Array): Map<string, number> {
|
|
31
|
+
const at = { offset: 8 }
|
|
32
|
+
const names: string[] = []
|
|
33
|
+
const sizes: number[] = []
|
|
34
|
+
while (at.offset < bytes.length) {
|
|
35
|
+
const id = bytes[at.offset++]!
|
|
36
|
+
const size = leb(bytes, at)
|
|
37
|
+
const end = at.offset + size
|
|
38
|
+
if (id === 0) {
|
|
39
|
+
const length = leb(bytes, at)
|
|
40
|
+
const name = Buffer.from(bytes.subarray(at.offset, at.offset + length)).toString()
|
|
41
|
+
at.offset += length
|
|
42
|
+
if (name === 'linking') {
|
|
43
|
+
leb(bytes, at)
|
|
44
|
+
while (at.offset < end) {
|
|
45
|
+
const kind = bytes[at.offset++]!
|
|
46
|
+
const length = leb(bytes, at)
|
|
47
|
+
const next = at.offset + length
|
|
48
|
+
if (kind === 5) {
|
|
49
|
+
for (let count = leb(bytes, at); count > 0; count--) {
|
|
50
|
+
const nameLength = leb(bytes, at)
|
|
51
|
+
names.push(
|
|
52
|
+
Buffer.from(bytes.subarray(at.offset, at.offset + nameLength)).toString(),
|
|
53
|
+
)
|
|
54
|
+
at.offset += nameLength
|
|
55
|
+
leb(bytes, at)
|
|
56
|
+
leb(bytes, at)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
at.offset = next
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
} else if (id === 11) {
|
|
63
|
+
for (let count = leb(bytes, at); count > 0; count--) {
|
|
64
|
+
const flags = leb(bytes, at)
|
|
65
|
+
if (flags === 2) leb(bytes, at)
|
|
66
|
+
if (flags !== 1) {
|
|
67
|
+
// an active segment's offset is one i32.const expression
|
|
68
|
+
at.offset++
|
|
69
|
+
leb(bytes, at)
|
|
70
|
+
at.offset++
|
|
71
|
+
}
|
|
72
|
+
const length = leb(bytes, at)
|
|
73
|
+
sizes.push(length)
|
|
74
|
+
at.offset += length
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
at.offset = end
|
|
78
|
+
}
|
|
79
|
+
const result = new Map<string, number>()
|
|
80
|
+
names.forEach((name, index) => {
|
|
81
|
+
if (OBJC_SEGMENTS.includes(name))
|
|
82
|
+
result.set(name, (result.get(name) ?? 0) + (sizes[index] ?? 0))
|
|
83
|
+
})
|
|
84
|
+
return result
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const rootsByDistribution = new Map<string, ReadonlySet<string>>()
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* the objects (relative to root) that define an ObjC class, protocol or
|
|
91
|
+
* category. every object carries each section's empty terminator, so a segment
|
|
92
|
+
* holds a definition when it outgrows the smallest one the distribution has.
|
|
93
|
+
*/
|
|
94
|
+
export function swiftObjcRootObjects(
|
|
95
|
+
id: string,
|
|
96
|
+
root: string,
|
|
97
|
+
objects: readonly string[],
|
|
98
|
+
): ReadonlySet<string> {
|
|
99
|
+
const cached = rootsByDistribution.get(id)
|
|
100
|
+
if (cached) return cached
|
|
101
|
+
const measured = objects.map(
|
|
102
|
+
(object) =>
|
|
103
|
+
[object, objcSegmentSizes(fs.readFileSync(path.join(root, object)))] as const,
|
|
104
|
+
)
|
|
105
|
+
const empty = new Map<string, number>()
|
|
106
|
+
for (const [, sizes] of measured)
|
|
107
|
+
for (const [name, size] of sizes)
|
|
108
|
+
empty.set(name, Math.min(empty.get(name) ?? size, size))
|
|
109
|
+
const roots = new Set(
|
|
110
|
+
measured
|
|
111
|
+
.filter(([, sizes]) =>
|
|
112
|
+
[...sizes].some(([name, size]) => size > (empty.get(name) ?? 0)),
|
|
113
|
+
)
|
|
114
|
+
.map(([object]) => object),
|
|
115
|
+
)
|
|
116
|
+
rootsByDistribution.set(id, roots)
|
|
117
|
+
return roots
|
|
118
|
+
}
|