peachsim 0.1.1881 → 0.1.1887
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/cli/commands/control.ts +11 -10
- package/cli/commands/reset.ts +1 -1
- package/cli/native-input.ts +1 -1
- package/cli/outbound-endpoints.ts +1 -1
- package/detox/index.ts +62 -1
- 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 +9079 -4305
- 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 +35 -2
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/expo-swift-bundle.cjs +8609 -3976
- package/dist-lib/expo-swift-metadata.cjs +5 -1
- package/dist-lib/expo-swift-metadata.mjs +5 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +9894 -5149
- package/dist-lib/host/fetch-proxy-handler.cjs +93 -13
- package/dist-lib/host/fetch-proxy-overrides.cjs +10 -2
- package/dist-lib/host/fetch-proxy-overrides.mjs +8 -2
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +538 -120
- 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 +536 -118
- package/dist-lib/native-app-identity-project.cjs +408 -72
- package/dist-lib/native-app-identity-project.mjs +739 -375
- package/dist-lib/native-app-identity.cjs +37 -1
- package/dist-lib/native-app-identity.mjs +36 -1
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/pdfium-raster.cjs +1 -1
- package/dist-lib/pdfium-raster.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 +61 -28
- package/dist-lib/public-origins-lib.json +250 -92
- 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 +1 -1
- package/dist-lib/sdk.mjs +1 -1
- package/dist-lib/skills.cjs +16568 -11674
- package/dist-lib/swift-compile.cjs +6874 -2537
- package/dist-lib/swift-compile.mjs +6207 -1866
- package/dist-lib/swift-package.cjs +20 -3
- package/dist-lib/swift-package.mjs +20 -3
- package/dist-lib/swift-submit.cjs +2 -2
- package/dist-lib/swift-submit.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +19 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +8753 -4124
- package/dist-lib/vite.cjs +93 -13
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +1 -1
- package/dist-types/packages/peach-engine/src/engine/canvaskit-api.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/engine/fontDataContract.d.ts +2 -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-protocol.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +11 -1
- package/dist-types/packages/peach-engine/src/render-worker/shell-tree-wire.d.ts +2 -1
- package/dist-types/packages/peach-globals/src/nodeContract.d.ts +1 -0
- package/dist-types/packages/peach-globals/src/testBridgeContract.d.ts +10 -1
- package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
- package/dist-types/packages/peach-kit/src/ui/popover-placement.d.ts +1 -1
- package/dist-types/packages/sootsim-swift/src/securityHostContract.d.ts +10 -0
- package/package.json +1 -1
- package/runtime-companion.json +1 -1
- package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFHost.h +555 -0
- package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetwork.h +1 -0
- package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes +6 -0
- package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/NSURLProtocol.h +0 -1
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Modules/module.modulemap +6 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIBarButtonItemBadge.h +1 -1
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIBarMinimization.h +1 -1
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIScrollView.h +1 -1
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UISearchTab.h +1 -1
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UITab.h +1 -1
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UITabAccessory.h +2 -2
- package/sdk/ios/usr/include/os/activity.h +534 -0
- package/sdk/ios/usr/include/os.modulemap +15 -0
- package/sdk/ios/wasm/include/fcntl.h +16 -0
- package/sdk/ios/wasm/include/string.h +5 -0
- package/sdk/native-hashes.json +1 -1
- package/src/dns-over-https.ts +61 -9
- package/src/expo-swift-bundle.ts +2 -7
- package/src/expo-swift-host.ts +11 -3
- package/src/host/fetch-proxy-handler.ts +51 -2
- package/src/host/fetch-proxy-overrides.ts +4 -0
- package/src/host/hostname-resolver.ts +9 -5
- package/src/native-app-identity-project.ts +13 -2
- package/src/native-app-identity.ts +47 -0
- package/src/nitro-adapter.lock.json +260 -260
- package/src/nitro-bundle.ts +7 -10
- package/src/nitro-superset.lock.json +4 -4
- package/src/podspec-sources.ts +20 -0
- package/src/storageSnapshotContract.ts +20 -1
- package/src/swift-compile.ts +409 -77
- package/src/swift-compiler-digest.ts +15 -0
- package/src/swift-coverage/xcode-packages.ts +3 -2
- package/src/swift-distribution.lock.json +12 -12
- package/src/swift-guest-archive.ts +153 -0
- package/src/swift-guest-compile.ts +449 -0
- package/src/swift-guest-image-ledger.ts +656 -0
- package/src/swift-guest-link-plan.ts +52 -0
- package/src/swift-guest-link.ts +1414 -0
- package/src/swift-guest-linked-spans.ts +338 -0
- package/src/swift-guest-manifest.ts +141 -0
- package/src/swift-guest-projection-storage.ts +310 -0
- package/src/swift-guest-projection.ts +252 -0
- package/src/swift-guest-runtime-plan.ts +834 -0
- package/src/swift-guest-source-inputs.ts +427 -0
- package/src/swift-guest-source-plan.ts +279 -0
- package/src/swift-host.ts +157 -36
- package/src/swift-icu.ts +60 -18
- package/src/swift-link-roots.ts +27 -50
- package/src/swift-package-manifest.ts +34 -18
- package/src/swift-package.ts +32 -2
- package/src/swift-packages.ts +138 -17
- package/src/swift-runtime-products.ts +73 -0
- package/src/swift-shared-sdk.ts +1 -1
- package/src/swift-submit.ts +15 -3
- package/src/swift-toolchain.ts +18 -0
- package/src/swift-wasm-prune.ts +313 -14
- package/src/swiftContract.ts +83 -0
- package/src/swiftRuntimeProductContract.ts +85 -45
- package/src/turbo-bundle.ts +1 -1
- package/src/turbo-codegen-intake.ts +10 -3
- package/src/turbo-runtime.lock.json +23 -23
- package/src/wasm-optimize.ts +16 -4
- package/src/xcode-project.ts +142 -14
package/src/swift-compile.ts
CHANGED
|
@@ -46,12 +46,14 @@ import {
|
|
|
46
46
|
SWIFT_DISTRIBUTION_OBJC_SELECTORS,
|
|
47
47
|
} from './swift-distribution-contract'
|
|
48
48
|
import { foundationCategoryObjects } from './swift-foundation'
|
|
49
|
+
import { compileGuestLink } from './swift-guest-compile'
|
|
49
50
|
import {
|
|
50
51
|
brotliCompressQ11,
|
|
51
52
|
brotliCompressQ4,
|
|
53
|
+
swiftIcuAddress,
|
|
52
54
|
swiftIcuAsset,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
swiftIcuBundleAsset,
|
|
56
|
+
swiftIcuPacked,
|
|
55
57
|
type SwiftIcuAsset,
|
|
56
58
|
} from './swift-icu'
|
|
57
59
|
import { swiftObjcRootObjects } from './swift-link-roots'
|
|
@@ -115,6 +117,8 @@ import { compileUniformTypeConstants } from './swift-uniform-type-constants'
|
|
|
115
117
|
import { pruneSwiftWasmLink } from './swift-wasm-prune'
|
|
116
118
|
import {
|
|
117
119
|
isSwiftNativeTargets,
|
|
120
|
+
isSwiftSourceLinkGraph,
|
|
121
|
+
type SwiftSourceLinkGraph,
|
|
118
122
|
isSwiftHeaderAliases,
|
|
119
123
|
isSwiftPackageFiles,
|
|
120
124
|
isSwiftProjectFiles,
|
|
@@ -138,9 +142,10 @@ import type { SwiftResourceBundle } from './swiftContract'
|
|
|
138
142
|
export {
|
|
139
143
|
brotliCompressQ11,
|
|
140
144
|
brotliCompressQ4,
|
|
145
|
+
swiftIcuAddress,
|
|
141
146
|
swiftIcuAsset,
|
|
142
|
-
|
|
143
|
-
|
|
147
|
+
swiftIcuBundleAsset,
|
|
148
|
+
swiftIcuPacked,
|
|
144
149
|
type SwiftIcuAsset,
|
|
145
150
|
}
|
|
146
151
|
|
|
@@ -282,6 +287,7 @@ export interface SwiftCompileInput {
|
|
|
282
287
|
projectFiles?: Record<string, string>
|
|
283
288
|
packageGuestImports?: string[]
|
|
284
289
|
nativeTargets?: SwiftNativeTarget[]
|
|
290
|
+
sourceLinkGraph?: SwiftSourceLinkGraph
|
|
285
291
|
headerAliases?: SwiftHeaderAliases
|
|
286
292
|
/** the Xcode app project's development region, for the emitted manifest's default localization. */
|
|
287
293
|
defaultLocalization?: string
|
|
@@ -527,16 +533,21 @@ export function swiftModuleInputFiles(root: string): string[] {
|
|
|
527
533
|
const files: string[] = [
|
|
528
534
|
...swiftSharedSdkInputFiles(root),
|
|
529
535
|
'../peachsim/src/swift-shared-sdk.ts',
|
|
530
|
-
'../peachsim/src/swift-darwin-records.ts',
|
|
531
|
-
'../peachsim/src/swift-uniform-type-constants.ts',
|
|
532
536
|
'../peachsim/src/swift-runtime-products.ts',
|
|
533
537
|
'../peachsim/src/swiftRuntimeProductContract.ts',
|
|
538
|
+
'../peachsim/src/swift-darwin-records.ts',
|
|
539
|
+
'../peachsim/src/swift-uniform-type-constants.ts',
|
|
534
540
|
'../../scripts/generate/swift-sdk-module/darwin-mach.json',
|
|
535
541
|
'../../scripts/generate/swift-sdk-module/darwin-socketvar.json',
|
|
536
542
|
'../../scripts/ops/swift-distribution-publish.ts',
|
|
543
|
+
'../../src/helpers/mapLimit.ts',
|
|
537
544
|
'Package.swift',
|
|
538
545
|
'scripts/contrast-app-Package.swift',
|
|
539
546
|
'scripts/build-distribution.ts',
|
|
547
|
+
'scripts/runtime-product.ts',
|
|
548
|
+
'scripts/runtime-product-scopes.ts',
|
|
549
|
+
'scripts/distribution-runtime-products.ts',
|
|
550
|
+
'scripts/build-helpers.ts',
|
|
540
551
|
'scripts/distribution-clang.ts',
|
|
541
552
|
'runtime/UniformTypeIdentifiersConstants.m',
|
|
542
553
|
'Sources/libxml2/include/module.modulemap',
|
|
@@ -1136,6 +1147,64 @@ export function swiftSdkPaths(
|
|
|
1136
1147
|
|
|
1137
1148
|
const availableModules = new Map<string, Set<string>>()
|
|
1138
1149
|
|
|
1150
|
+
// only frameworks replaced by a Swift module lose their clang submodules.
|
|
1151
|
+
// non-framework clang modules can coexist with a same-name Swift module.
|
|
1152
|
+
function addSwiftOverlayFrameworks(
|
|
1153
|
+
text: string,
|
|
1154
|
+
swiftModules: ReadonlySet<string>,
|
|
1155
|
+
frameworks: Set<string>,
|
|
1156
|
+
): void {
|
|
1157
|
+
const tokens = moduleMapTokens(text)
|
|
1158
|
+
for (let i = 0; i < tokens.length - 2; i++)
|
|
1159
|
+
if (
|
|
1160
|
+
tokens[i] === 'framework' &&
|
|
1161
|
+
tokens[i - 1] !== 'extern' &&
|
|
1162
|
+
tokens[i + 1] === 'module' &&
|
|
1163
|
+
swiftModules.has(tokens[i + 2]!)
|
|
1164
|
+
)
|
|
1165
|
+
frameworks.add(tokens[i + 2]!)
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
const sdkOverlayFrameworks = new Map<string, Set<string>>()
|
|
1169
|
+
|
|
1170
|
+
export function swiftOverlayFrameworks(
|
|
1171
|
+
moduleRoot: string,
|
|
1172
|
+
toolchainBin: string,
|
|
1173
|
+
): ReadonlySet<string> {
|
|
1174
|
+
const key = JSON.stringify([
|
|
1175
|
+
moduleRoot,
|
|
1176
|
+
toolchainBin,
|
|
1177
|
+
swiftModuleSdk(moduleRoot).wasmSdkId,
|
|
1178
|
+
swiftSdkOptions(),
|
|
1179
|
+
])
|
|
1180
|
+
const cached = sdkOverlayFrameworks.get(key)
|
|
1181
|
+
if (cached) return cached
|
|
1182
|
+
const { darwin, resources, frameworks } = swiftSdkPaths(moduleRoot, toolchainBin)
|
|
1183
|
+
const swiftModules = new Set(swiftPeachModules(moduleRoot))
|
|
1184
|
+
const result = new Set<string>()
|
|
1185
|
+
const include = path.join(darwin, 'usr/include')
|
|
1186
|
+
for (const entry of readdirSync(include))
|
|
1187
|
+
if (entry.endsWith('.modulemap'))
|
|
1188
|
+
addSwiftOverlayFrameworks(
|
|
1189
|
+
readFileSync(path.join(include, entry), 'utf8'),
|
|
1190
|
+
swiftModules,
|
|
1191
|
+
result,
|
|
1192
|
+
)
|
|
1193
|
+
for (const entry of readdirSync(resources)) {
|
|
1194
|
+
const map = path.join(resources, entry, 'module.modulemap')
|
|
1195
|
+
if (existsSync(map))
|
|
1196
|
+
addSwiftOverlayFrameworks(readFileSync(map, 'utf8'), swiftModules, result)
|
|
1197
|
+
}
|
|
1198
|
+
for (const directory of frameworks)
|
|
1199
|
+
for (const entry of readdirSync(directory)) {
|
|
1200
|
+
const map = path.join(directory, entry, 'Modules/module.modulemap')
|
|
1201
|
+
if (existsSync(map))
|
|
1202
|
+
addSwiftOverlayFrameworks(readFileSync(map, 'utf8'), swiftModules, result)
|
|
1203
|
+
}
|
|
1204
|
+
sdkOverlayFrameworks.set(key, result)
|
|
1205
|
+
return result
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1139
1208
|
/**
|
|
1140
1209
|
* every module a source compiled against `moduleRoot` can import: Peach's own
|
|
1141
1210
|
* and the wasm SDK's swift modules and top-level clang modules.
|
|
@@ -1149,7 +1218,29 @@ export function swiftAvailableModules(
|
|
|
1149
1218
|
const cached = availableModules.get(key)
|
|
1150
1219
|
if (cached) return cached
|
|
1151
1220
|
const modules = new Set(swiftPeachModules(moduleRoot))
|
|
1152
|
-
const {
|
|
1221
|
+
const { resources, frameworks, sysroot, darwin, cFlags } = swiftSdkPaths(
|
|
1222
|
+
moduleRoot,
|
|
1223
|
+
toolchainBin,
|
|
1224
|
+
)
|
|
1225
|
+
const maps = new Set([
|
|
1226
|
+
path.join(darwin, 'usr/include/module.modulemap'),
|
|
1227
|
+
...cFlags
|
|
1228
|
+
.filter((flag) => flag.startsWith('-fmodule-map-file='))
|
|
1229
|
+
.map((flag) => {
|
|
1230
|
+
const file = flag.slice('-fmodule-map-file='.length)
|
|
1231
|
+
return file.startsWith('=') ? path.join(sysroot, file.slice(1)) : file
|
|
1232
|
+
}),
|
|
1233
|
+
])
|
|
1234
|
+
for (const map of maps) {
|
|
1235
|
+
if (!existsSync(map)) continue
|
|
1236
|
+
const contents = readFileSync(map, 'utf8')
|
|
1237
|
+
for (const match of contents.matchAll(
|
|
1238
|
+
/^(?:explicit\s+)?(?:framework\s+)?module\s+([A-Za-z_]\w*)/gm,
|
|
1239
|
+
))
|
|
1240
|
+
modules.add(match[1]!)
|
|
1241
|
+
for (const match of contents.matchAll(/^\s*extern\s+module\s+\w+\s+"([^"]+)"/gm))
|
|
1242
|
+
maps.add(path.resolve(path.dirname(map), match[1]!))
|
|
1243
|
+
}
|
|
1153
1244
|
for (const entry of readdirSync(path.join(resources, 'wasi'))) {
|
|
1154
1245
|
if (entry.endsWith('.swiftmodule'))
|
|
1155
1246
|
modules.add(entry.slice(0, -'.swiftmodule'.length))
|
|
@@ -1262,15 +1353,18 @@ export function swiftSystemLibraryExclusions(
|
|
|
1262
1353
|
)
|
|
1263
1354
|
}
|
|
1264
1355
|
|
|
1265
|
-
/**
|
|
1266
|
-
function
|
|
1356
|
+
/** prebuilt modules without interfaces owned by the compiling source graph. */
|
|
1357
|
+
function providedModulesPath(
|
|
1267
1358
|
root: string,
|
|
1268
|
-
|
|
1359
|
+
modules: string,
|
|
1269
1360
|
excluded: ReadonlySet<string> | undefined,
|
|
1270
1361
|
): string {
|
|
1271
|
-
const modules = path.join(moduleRoot, 'modules')
|
|
1272
1362
|
if (!excluded || excluded.size === 0) return modules
|
|
1363
|
+
const entries = readdirSync(modules)
|
|
1364
|
+
.filter((entry) => !excluded.has(entry.replace(/\..*$/, '')))
|
|
1365
|
+
.sort()
|
|
1273
1366
|
const key = createHash('sha256')
|
|
1367
|
+
.update(JSON.stringify([modules, entries]))
|
|
1274
1368
|
.update([...excluded].sort().join('\0'))
|
|
1275
1369
|
.digest('hex')
|
|
1276
1370
|
.slice(0, 16)
|
|
@@ -1280,8 +1374,7 @@ function distributionModulesPath(
|
|
|
1280
1374
|
mkdirSync(directory, { recursive: true })
|
|
1281
1375
|
for (const entry of readdirSync(directory))
|
|
1282
1376
|
rmSync(path.join(directory, entry), { recursive: true, force: true })
|
|
1283
|
-
for (const entry of
|
|
1284
|
-
if (excluded.has(entry.replace(/\.swiftmodule$/, ''))) continue
|
|
1377
|
+
for (const entry of entries) {
|
|
1285
1378
|
symlinkSync(path.join(modules, entry), path.join(directory, entry))
|
|
1286
1379
|
}
|
|
1287
1380
|
writeFileSync(complete, '')
|
|
@@ -1291,9 +1384,14 @@ function distributionModulesPath(
|
|
|
1291
1384
|
|
|
1292
1385
|
export function swiftTargetDependencies(
|
|
1293
1386
|
files: Record<string, string>,
|
|
1294
|
-
targets: Pick<
|
|
1387
|
+
targets: Pick<
|
|
1388
|
+
SwiftPackageTarget,
|
|
1389
|
+
'name' | 'path' | 'dependencies' | 'sources' | 'exclude'
|
|
1390
|
+
>[],
|
|
1391
|
+
frameworks: Iterable<string> = OPTIONAL_FRAMEWORKS,
|
|
1295
1392
|
): Map<string, string[]> {
|
|
1296
|
-
const
|
|
1393
|
+
const localNames = new Set(targets.map((target) => target.name))
|
|
1394
|
+
const names = new Set([...frameworks, ...localNames])
|
|
1297
1395
|
const siblings = new Map<string, string[]>()
|
|
1298
1396
|
for (const target of targets) {
|
|
1299
1397
|
const prefix = target.path === '.' ? '' : `${target.path}/`
|
|
@@ -1322,7 +1420,23 @@ export function swiftTargetDependencies(
|
|
|
1322
1420
|
)
|
|
1323
1421
|
for (const [file, contents] of Object.entries(files)) {
|
|
1324
1422
|
if (file === 'Package.swift' || !file.startsWith(prefix)) continue
|
|
1423
|
+
const relative = file.slice(prefix.length)
|
|
1325
1424
|
if (
|
|
1425
|
+
target.sources !== undefined &&
|
|
1426
|
+
!target.sources.some(
|
|
1427
|
+
(source) =>
|
|
1428
|
+
source === '.' || relative === source || relative.startsWith(`${source}/`),
|
|
1429
|
+
)
|
|
1430
|
+
)
|
|
1431
|
+
continue
|
|
1432
|
+
if (
|
|
1433
|
+
target.exclude?.some(
|
|
1434
|
+
(excluded) => relative === excluded || relative.startsWith(`${excluded}/`),
|
|
1435
|
+
)
|
|
1436
|
+
)
|
|
1437
|
+
continue
|
|
1438
|
+
if (
|
|
1439
|
+
target.sources === undefined &&
|
|
1326
1440
|
targets.some(
|
|
1327
1441
|
(candidate) =>
|
|
1328
1442
|
candidate.name !== target.name &&
|
|
@@ -1338,7 +1452,14 @@ export function swiftTargetDependencies(
|
|
|
1338
1452
|
? clangImportNames(contents, ownsHeader)
|
|
1339
1453
|
: []
|
|
1340
1454
|
for (const name of imports) {
|
|
1341
|
-
|
|
1455
|
+
// public umbrella headers may import their own consumers. a declared
|
|
1456
|
+
// package graph owns local edges; imports still select sdk frameworks.
|
|
1457
|
+
if (
|
|
1458
|
+
names.has(name) &&
|
|
1459
|
+
name !== target.name &&
|
|
1460
|
+
!(target.dependencies !== undefined && localNames.has(name))
|
|
1461
|
+
)
|
|
1462
|
+
deps.add(name)
|
|
1342
1463
|
}
|
|
1343
1464
|
}
|
|
1344
1465
|
siblings.set(target.name, [...deps].sort())
|
|
@@ -1386,7 +1507,8 @@ const ONE_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "One
|
|
|
1386
1507
|
// edit pay for an optimizer pass and the artifact depend on the machine, so
|
|
1387
1508
|
// -O0 on the clang link turns that pass off everywhere. the build root's
|
|
1388
1509
|
// linker drops repeated autolink -l flags (writeSwiftAutolinkLinker). the
|
|
1389
|
-
//
|
|
1510
|
+
// icu wraps route icu data opens through Sources/PeachICU, whose host places
|
|
1511
|
+
// each item on first use. the rest is the native main-thread stack budget.
|
|
1390
1512
|
const executableLinkFlags = (root: string) => ` "-Xclang-linker", "-O0",
|
|
1391
1513
|
"-Xclang-linker", ${JSON.stringify(`-fuse-ld=${path.join(root, SWIFT_AUTOLINK_LINKER)}`)},
|
|
1392
1514
|
"-Xlinker", "-z", "-Xlinker", "stack-size=8372224",
|
|
@@ -1395,6 +1517,8 @@ const executableLinkFlags = (root: string) => ` "-Xclang-linker", "-O0"
|
|
|
1395
1517
|
"-Xlinker", "-lsetjmp",
|
|
1396
1518
|
"-Xlinker", "--export-table",
|
|
1397
1519
|
"-Xlinker", "--growable-table",
|
|
1520
|
+
"-Xlinker", "--wrap=swift_udata_open",
|
|
1521
|
+
"-Xlinker", "--wrap=swift_udata_openChoice",
|
|
1398
1522
|
`
|
|
1399
1523
|
// the Darwin module's providers link as an archive does, ahead of the sdk's
|
|
1400
1524
|
// libDarwinRecords.a, which supplies only what remains undefined
|
|
@@ -1404,7 +1528,7 @@ const darwinRecordsRegion = (quoted: readonly string[]): string[] =>
|
|
|
1404
1528
|
const REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n'
|
|
1405
1529
|
|
|
1406
1530
|
/** bump with any change to the emitted multi-target manifest text. */
|
|
1407
|
-
export const MULTI_MANIFEST_VERSION =
|
|
1531
|
+
export const MULTI_MANIFEST_VERSION = 66
|
|
1408
1532
|
const SWIFT_HEADER_PRODUCTS_TARGET = 'PeachHeaderProducts'
|
|
1409
1533
|
|
|
1410
1534
|
// build-cli replaces this in every bundle; source runs read the files directly.
|
|
@@ -1463,6 +1587,7 @@ export function swiftArtifactHash(
|
|
|
1463
1587
|
),
|
|
1464
1588
|
)
|
|
1465
1589
|
hash.update(JSON.stringify(input.nativeTargets ?? []))
|
|
1590
|
+
hash.update(JSON.stringify(input.sourceLinkGraph ?? null))
|
|
1466
1591
|
hash.update(JSON.stringify(input.staticClangTargets ?? []))
|
|
1467
1592
|
hash.update(JSON.stringify(input.headerAliases ?? {}))
|
|
1468
1593
|
hash.update(JSON.stringify(input.packageGuestImports ?? []))
|
|
@@ -1608,8 +1733,8 @@ export function emitSwiftPackageManifest(args: {
|
|
|
1608
1733
|
spriteKit?: boolean
|
|
1609
1734
|
/** link the prebuilt distribution at moduleRoot instead of its sources. */
|
|
1610
1735
|
distribution?: SwiftDistributionManifest
|
|
1611
|
-
/**
|
|
1612
|
-
|
|
1736
|
+
/** prebuilt interfaces owned by local source or system-library targets. */
|
|
1737
|
+
moduleExcludes?: ReadonlySet<string>
|
|
1613
1738
|
/**
|
|
1614
1739
|
* ordered distribution objects, read by the linker without expanding argv.
|
|
1615
1740
|
* absent when no source reaches a distribution framework: the executable
|
|
@@ -1638,11 +1763,13 @@ export function emitSwiftPackageManifest(args: {
|
|
|
1638
1763
|
const linkedObjects = Boolean(distribution || prebuilt)
|
|
1639
1764
|
const cxxFlagsFor = (flags: readonly string[]): readonly string[] =>
|
|
1640
1765
|
args.deferDarwinOverlay ? withoutWasmOverlayIsystem(flags) : flags
|
|
1641
|
-
|
|
1642
|
-
// which requires cryptokit even when an app does not import it directly.
|
|
1643
|
-
const reachedFrameworks = new Set<string>(['CryptoKit'])
|
|
1766
|
+
const reachedFrameworks = new Set<string>()
|
|
1644
1767
|
const reach = (name: string) => {
|
|
1645
|
-
if (
|
|
1768
|
+
if (
|
|
1769
|
+
reachedFrameworks.has(name) ||
|
|
1770
|
+
targets.some((target) => swiftTargetModuleName(target.name) === name)
|
|
1771
|
+
)
|
|
1772
|
+
return
|
|
1646
1773
|
reachedFrameworks.add(name)
|
|
1647
1774
|
for (const dependency of OPTIONAL_FRAMEWORK_DEPENDENCIES[name] ?? [])
|
|
1648
1775
|
reach(dependency)
|
|
@@ -1823,10 +1950,14 @@ export function emitSwiftPackageManifest(args: {
|
|
|
1823
1950
|
// object for autolinks; distribution.link supplies those libraries.
|
|
1824
1951
|
const imports = distribution
|
|
1825
1952
|
? `, "-Isystem", ${JSON.stringify(
|
|
1826
|
-
|
|
1953
|
+
providedModulesPath(
|
|
1954
|
+
args.root,
|
|
1955
|
+
path.join(moduleRoot, 'modules'),
|
|
1956
|
+
args.moduleExcludes,
|
|
1957
|
+
),
|
|
1827
1958
|
)}`
|
|
1828
1959
|
: prebuilt
|
|
1829
|
-
? `, "-Isystem", ${JSON.stringify(prebuilt.modules)}${prebuilt.moduleMaps
|
|
1960
|
+
? `, "-Isystem", ${JSON.stringify(providedModulesPath(args.root, prebuilt.modules, args.moduleExcludes))}${prebuilt.moduleMaps
|
|
1830
1961
|
.map((map) => `, "-Xcc", ${JSON.stringify(`-fmodule-map-file=${map}`)}`)
|
|
1831
1962
|
.join('')}`
|
|
1832
1963
|
: ''
|
|
@@ -2035,7 +2166,9 @@ export function emitSwiftPackageManifest(args: {
|
|
|
2035
2166
|
]
|
|
2036
2167
|
: native?.flags
|
|
2037
2168
|
? [` sources: ${JSON.stringify(native.sources)},`]
|
|
2038
|
-
:
|
|
2169
|
+
: target.sources !== undefined
|
|
2170
|
+
? [` sources: ${JSON.stringify(target.sources)},`]
|
|
2171
|
+
: []),
|
|
2039
2172
|
...(!native?.clang && target.publicHeadersPath !== undefined
|
|
2040
2173
|
? [` publicHeadersPath: ${JSON.stringify(target.publicHeadersPath)},`]
|
|
2041
2174
|
: []),
|
|
@@ -2183,6 +2316,7 @@ const FRAME_INIT = /^override(?=\s+(?:(?:public|open|internal)\s+)?init\s*\(\s*f
|
|
|
2183
2316
|
function compiledSwiftSources(
|
|
2184
2317
|
files: Record<string, string>,
|
|
2185
2318
|
targets: SwiftPackageTarget[],
|
|
2319
|
+
overlayFrameworks: () => ReadonlySet<string>,
|
|
2186
2320
|
): Map<string, string> {
|
|
2187
2321
|
const ordered = [...targets].sort((a, b) => b.path.length - a.path.length)
|
|
2188
2322
|
return new Map(
|
|
@@ -2204,6 +2338,7 @@ function compiledSwiftSources(
|
|
|
2204
2338
|
? source
|
|
2205
2339
|
: swiftSourceAsIOS(
|
|
2206
2340
|
source,
|
|
2341
|
+
overlayFrameworks,
|
|
2207
2342
|
owner?.defines?.includes(SWIFT_XCODE_BUILD_CONDITION) &&
|
|
2208
2343
|
!owner.defines.includes('SWIFT_PACKAGE')
|
|
2209
2344
|
? false
|
|
@@ -2380,8 +2515,6 @@ const FOUNDATION_NETWORKING_TYPES = new Set([
|
|
|
2380
2515
|
'NSURLConnectionDataDelegate',
|
|
2381
2516
|
'NSURLConnectionDelegate',
|
|
2382
2517
|
'NSURLConnectionDownloadDelegate',
|
|
2383
|
-
'URLProtocol',
|
|
2384
|
-
'URLProtocolClient',
|
|
2385
2518
|
])
|
|
2386
2519
|
|
|
2387
2520
|
// Foundation overlay declarations live in the shared guest overlay module.
|
|
@@ -3044,7 +3177,6 @@ const CORE_FOUNDATION_HANDLE_IMPORTS = [
|
|
|
3044
3177
|
|
|
3045
3178
|
// the guest module that owns a name darwin's Foundation declares
|
|
3046
3179
|
export function foundationOwnerOf(name: string): string | undefined {
|
|
3047
|
-
if (name === 'NSErrorPointer') return 'Foundation'
|
|
3048
3180
|
if (
|
|
3049
3181
|
name === 'NSClassFromString' ||
|
|
3050
3182
|
name === 'NSKeyValueChange' ||
|
|
@@ -3063,7 +3195,11 @@ export function foundationOwnerOf(name: string): string | undefined {
|
|
|
3063
3195
|
return undefined
|
|
3064
3196
|
}
|
|
3065
3197
|
|
|
3066
|
-
export function swiftSourceAsIOS(
|
|
3198
|
+
export function swiftSourceAsIOS(
|
|
3199
|
+
source: string,
|
|
3200
|
+
overlayFrameworks: () => ReadonlySet<string>,
|
|
3201
|
+
swiftPackage?: boolean,
|
|
3202
|
+
): string {
|
|
3067
3203
|
const { lineStarts, tokens } = swiftCodeScan(source)
|
|
3068
3204
|
let offset = 0
|
|
3069
3205
|
// equal width, so every token offset still holds
|
|
@@ -3118,16 +3254,18 @@ export function swiftSourceAsIOS(source: string, swiftPackage?: boolean): string
|
|
|
3118
3254
|
}
|
|
3119
3255
|
continue
|
|
3120
3256
|
}
|
|
3121
|
-
//
|
|
3122
|
-
//
|
|
3123
|
-
// submodule brings in the framework's Swift overlay too.
|
|
3257
|
+
// keep Clang submodules the selected SDK actually owns. a framework
|
|
3258
|
+
// replaced by a Swift overlay imports the overlay instead.
|
|
3124
3259
|
const imported =
|
|
3125
3260
|
conditioned[at - 1] === '.'
|
|
3126
3261
|
? null
|
|
3127
3262
|
: /^import[ \t]+([A-Za-z_]\w*)(?:[ \t]*\.[ \t]*[A-Za-z_]\w*)+/.exec(rest)
|
|
3128
3263
|
if (imported) {
|
|
3129
3264
|
out +=
|
|
3130
|
-
conditioned.slice(copied, at) +
|
|
3265
|
+
conditioned.slice(copied, at) +
|
|
3266
|
+
(overlayFrameworks().has(imported[1]!)
|
|
3267
|
+
? `import ${imported[1]}`.padEnd(imported[0].length)
|
|
3268
|
+
: imported[0])
|
|
3131
3269
|
if (imported[1] === 'CoreFoundation') out += `; ${CORE_FOUNDATION_HANDLE_IMPORTS}`
|
|
3132
3270
|
copied = at + imported[0].length
|
|
3133
3271
|
continue
|
|
@@ -3915,9 +4053,14 @@ function swiftCodeScan(source: string): {
|
|
|
3915
4053
|
* source adapted as app sources are, retaining native objective-c syntax.
|
|
3916
4054
|
* its manifests stay as
|
|
3917
4055
|
* published and the upstream tree is never written. */
|
|
3918
|
-
export function prepareSwiftDependency(
|
|
4056
|
+
export function prepareSwiftDependency(
|
|
4057
|
+
source: string,
|
|
4058
|
+
destination: string,
|
|
4059
|
+
overlayFrameworks: () => ReadonlySet<string>,
|
|
4060
|
+
): void {
|
|
3919
4061
|
rmSync(destination, { recursive: true, force: true })
|
|
3920
4062
|
const origins: Record<string, string> = {}
|
|
4063
|
+
const moduleMaps: string[] = []
|
|
3921
4064
|
const gather = (from: string) => {
|
|
3922
4065
|
for (const entry of readdirSync(from, { withFileTypes: true })) {
|
|
3923
4066
|
if (entry.name === '.git' || entry.name === '.build' || entry.name === '.swiftpm')
|
|
@@ -3926,6 +4069,8 @@ export function prepareSwiftDependency(source: string, destination: string): voi
|
|
|
3926
4069
|
if (entry.isDirectory()) gather(file)
|
|
3927
4070
|
else if (entry.isFile() && entry.name.endsWith('.swift'))
|
|
3928
4071
|
origins[path.relative(source, file)] = readFileSync(file, 'utf8')
|
|
4072
|
+
else if (entry.isFile() && entry.name.endsWith('.modulemap'))
|
|
4073
|
+
moduleMaps.push(readFileSync(file, 'utf8'))
|
|
3929
4074
|
}
|
|
3930
4075
|
}
|
|
3931
4076
|
gather(source)
|
|
@@ -3933,7 +4078,26 @@ export function prepareSwiftDependency(source: string, destination: string): voi
|
|
|
3933
4078
|
const targets = existsSync(manifest)
|
|
3934
4079
|
? swiftManifestTargets(readFileSync(manifest, 'utf8'))
|
|
3935
4080
|
: []
|
|
3936
|
-
|
|
4081
|
+
let dependencyOverlays: Set<string> | undefined
|
|
4082
|
+
const compiled = compiledSwiftSources(origins, targets, () => {
|
|
4083
|
+
if (dependencyOverlays) return dependencyOverlays
|
|
4084
|
+
dependencyOverlays = new Set(overlayFrameworks())
|
|
4085
|
+
const sourceFiles = Object.keys(origins)
|
|
4086
|
+
const swiftModules = new Set(
|
|
4087
|
+
targets
|
|
4088
|
+
.filter((target) =>
|
|
4089
|
+
sourceFiles.some(
|
|
4090
|
+
(file) =>
|
|
4091
|
+
file !== 'Package.swift' &&
|
|
4092
|
+
(target.path === '.' || file.startsWith(`${target.path}/`)),
|
|
4093
|
+
),
|
|
4094
|
+
)
|
|
4095
|
+
.map((target) => swiftTargetModuleName(target.name)),
|
|
4096
|
+
)
|
|
4097
|
+
for (const map of moduleMaps)
|
|
4098
|
+
addSwiftOverlayFrameworks(map, swiftModules, dependencyOverlays)
|
|
4099
|
+
return dependencyOverlays
|
|
4100
|
+
})
|
|
3937
4101
|
const copy = (from: string, to: string) => {
|
|
3938
4102
|
mkdirSync(to, { recursive: true })
|
|
3939
4103
|
for (const entry of readdirSync(from, { withFileTypes: true })) {
|
|
@@ -3952,6 +4116,31 @@ export function prepareSwiftDependency(source: string, destination: string): voi
|
|
|
3952
4116
|
|
|
3953
4117
|
// where a mixed native target compiles units whose paths swiftpm would hide.
|
|
3954
4118
|
const HIDDEN_UNITS = 'PeachHiddenUnits'
|
|
4119
|
+
// a package's arch-selected units (KSCrash's KSCPU_arm64.c) wrap their whole
|
|
4120
|
+
// body in one arch guard. the guest is arm64 at 32-bit pointers, as arm64_32
|
|
4121
|
+
// is, and clang defines __arm64__ for that triple, so each such unit compiles
|
|
4122
|
+
// with it defined. a global define would flip headers (setjmp, simd, objc)
|
|
4123
|
+
// for every unit.
|
|
4124
|
+
// whether the unit's only content is one `__arm64__` conditional.
|
|
4125
|
+
function swiftWholeFileArm64Guard(source: string): boolean {
|
|
4126
|
+
const lines = stripCCode(source)
|
|
4127
|
+
.replace(/\\\r?\n/g, '')
|
|
4128
|
+
.split('\n')
|
|
4129
|
+
.map((line) => line.trim())
|
|
4130
|
+
.filter((line) => line !== '')
|
|
4131
|
+
if (
|
|
4132
|
+
!/^#\s*(?:if\s+defined\s*\(\s*__arm64__\s*\)|ifdef\s+__arm64__)$/.test(lines[0] ?? '')
|
|
4133
|
+
)
|
|
4134
|
+
return false
|
|
4135
|
+
let depth = 0
|
|
4136
|
+
for (const [index, line] of lines.entries()) {
|
|
4137
|
+
if (/^#\s*if/.test(line)) depth++
|
|
4138
|
+
else if (/^#\s*endif\b/.test(line)) depth--
|
|
4139
|
+
if (depth === 0 && index !== lines.length - 1) return false
|
|
4140
|
+
if (depth === 0 && /^#\s*(?:else|elif)/.test(line)) return false
|
|
4141
|
+
}
|
|
4142
|
+
return depth === 0 && /^#\s*endif\b/.test(lines.at(-1) ?? '')
|
|
4143
|
+
}
|
|
3955
4144
|
|
|
3956
4145
|
// a clang dependency's module map is written beside its public headers after
|
|
3957
4146
|
// that target's own import. an earlier import already has that directory on
|
|
@@ -4036,10 +4225,18 @@ export function writeSwiftProject(
|
|
|
4036
4225
|
input: SwiftCompileInput,
|
|
4037
4226
|
moduleRoot: string,
|
|
4038
4227
|
prebuilt?: SwiftFrameworkProducts,
|
|
4039
|
-
): SwiftProjectPreparation {
|
|
4228
|
+
): SwiftProjectPreparation & {
|
|
4229
|
+
generatedOwners: Map<string, string>
|
|
4230
|
+
targetToolset: boolean
|
|
4231
|
+
} {
|
|
4040
4232
|
const nativeToolset = needsNativeToolset(input, prebuilt)
|
|
4041
4233
|
if (input.headerAliases !== undefined && !isSwiftHeaderAliases(input.headerAliases))
|
|
4042
4234
|
throw new Error('swift compile input has invalid original header aliases')
|
|
4235
|
+
if (
|
|
4236
|
+
input.sourceLinkGraph !== undefined &&
|
|
4237
|
+
!isSwiftSourceLinkGraph(input.sourceLinkGraph)
|
|
4238
|
+
)
|
|
4239
|
+
throw new Error('swift compile input has invalid source product links')
|
|
4043
4240
|
if (input.nativeTargets !== undefined && !isSwiftNativeTargets(input.nativeTargets))
|
|
4044
4241
|
throw new Error('swift compile input has invalid original clang target inputs')
|
|
4045
4242
|
if (input.packageFiles !== undefined && !isSwiftPackageFiles(input.packageFiles))
|
|
@@ -4084,16 +4281,27 @@ export function writeSwiftProject(
|
|
|
4084
4281
|
},
|
|
4085
4282
|
]
|
|
4086
4283
|
: compileTargets(input)
|
|
4284
|
+
const generatedOwners = new Map(targets.map((target) => [target.name, target.name]))
|
|
4285
|
+
// source owns its module name, including clang targets: a same-name Swift
|
|
4286
|
+
// preview must not hide their original Objective-C interface.
|
|
4287
|
+
const providedModules =
|
|
4288
|
+
distribution?.modules ??
|
|
4289
|
+
(prebuilt
|
|
4290
|
+
? readdirSync(prebuilt.modules)
|
|
4291
|
+
.filter((entry) => entry.endsWith('.swiftmodule'))
|
|
4292
|
+
.map((entry) => entry.slice(0, -'.swiftmodule'.length))
|
|
4293
|
+
: [])
|
|
4087
4294
|
// a local target owns its module, including native React targets from the
|
|
4088
|
-
// installed workspace. the
|
|
4089
|
-
const
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4295
|
+
// installed workspace. the prebuilt interface must not replace its declarations.
|
|
4296
|
+
const moduleExcludes =
|
|
4297
|
+
distribution || prebuilt
|
|
4298
|
+
? new Set([
|
|
4299
|
+
...swiftSystemLibraryExclusions(input.files, targets, providedModules),
|
|
4300
|
+
...providedModules.filter((name) =>
|
|
4301
|
+
targets.some((target) => swiftTargetModuleName(target.name) === name),
|
|
4302
|
+
),
|
|
4303
|
+
])
|
|
4304
|
+
: undefined
|
|
4097
4305
|
const files = new Map<string, string | Buffer>()
|
|
4098
4306
|
const native = new Map<string, SwiftNativeTargetPlan>()
|
|
4099
4307
|
const targetFailures: string[] = []
|
|
@@ -4176,6 +4384,10 @@ export function writeSwiftProject(
|
|
|
4176
4384
|
return Object.entries(input.files).filter(
|
|
4177
4385
|
([file]) =>
|
|
4178
4386
|
file.startsWith(prefix) &&
|
|
4387
|
+
!target.exclude?.some(
|
|
4388
|
+
(excluded) =>
|
|
4389
|
+
file === `${prefix}${excluded}` || file.startsWith(`${prefix}${excluded}/`),
|
|
4390
|
+
) &&
|
|
4179
4391
|
!targets.some(
|
|
4180
4392
|
(candidate) =>
|
|
4181
4393
|
candidate.name !== target.name &&
|
|
@@ -4737,6 +4949,9 @@ export function writeSwiftProject(
|
|
|
4737
4949
|
// before quoted header maps and configured user search paths.
|
|
4738
4950
|
const quoteFlags = origin ? ['-iquote', path.join(layout.root, origin)] : []
|
|
4739
4951
|
const perFile = [
|
|
4952
|
+
...(file.endsWith('.c') && swiftWholeFileArm64Guard(contents)
|
|
4953
|
+
? ['-D__arm64__=1']
|
|
4954
|
+
: []),
|
|
4740
4955
|
...(/\.mm?$/.test(file) ? ['-fobjc-exceptions'] : []),
|
|
4741
4956
|
...stageFlags(
|
|
4742
4957
|
settings?.fileFlags[file] ?? [],
|
|
@@ -5066,6 +5281,7 @@ export function writeSwiftProject(
|
|
|
5066
5281
|
const moduleFiles = `\n// sootsim-swift files ${modulePlan.digest('hex').slice(0, 16)}\n// resource accessors ${resourcePlan}\n`
|
|
5067
5282
|
// view builder literals compile as xcode's design-time lookups, so a save
|
|
5068
5283
|
// that changes only them reloads without compiling (swift-design-time.ts)
|
|
5284
|
+
let projectOverlayFrameworks: Set<string> | undefined
|
|
5069
5285
|
const compiled = compiledSwiftSources(
|
|
5070
5286
|
Object.fromEntries(
|
|
5071
5287
|
Object.entries(input.files).map(([file, contents]) => [
|
|
@@ -5074,6 +5290,24 @@ export function writeSwiftProject(
|
|
|
5074
5290
|
]),
|
|
5075
5291
|
),
|
|
5076
5292
|
targets,
|
|
5293
|
+
() => {
|
|
5294
|
+
if (projectOverlayFrameworks) return projectOverlayFrameworks
|
|
5295
|
+
projectOverlayFrameworks = new Set(
|
|
5296
|
+
swiftOverlayFrameworks(moduleRoot, nativeToolchain()),
|
|
5297
|
+
)
|
|
5298
|
+
const swiftModules = new Set(swiftPeachModules(moduleRoot))
|
|
5299
|
+
const sourceModules = new Set([...swiftTargets].map(swiftTargetModuleName))
|
|
5300
|
+
for (const name of moduleExcludes ?? [])
|
|
5301
|
+
if (!sourceModules.has(name)) {
|
|
5302
|
+
swiftModules.delete(name)
|
|
5303
|
+
projectOverlayFrameworks.delete(name)
|
|
5304
|
+
}
|
|
5305
|
+
for (const name of sourceModules) swiftModules.add(name)
|
|
5306
|
+
for (const [file, contents] of Object.entries(input.files))
|
|
5307
|
+
if (file.endsWith('.modulemap'))
|
|
5308
|
+
addSwiftOverlayFrameworks(contents, swiftModules, projectOverlayFrameworks)
|
|
5309
|
+
return projectOverlayFrameworks
|
|
5310
|
+
},
|
|
5077
5311
|
)
|
|
5078
5312
|
// an application's swift module must precede its native implementations.
|
|
5079
5313
|
// the tiny executable calls the original typed entry after both are linked.
|
|
@@ -5161,6 +5395,7 @@ export function writeSwiftProject(
|
|
|
5161
5395
|
if (targets.some((candidate) => candidate.name === name))
|
|
5162
5396
|
throw new Error(`mixed application executable target conflicts with ${name}`)
|
|
5163
5397
|
target.executable = false
|
|
5398
|
+
generatedOwners.set(name, target.name)
|
|
5164
5399
|
targets.push({
|
|
5165
5400
|
...target,
|
|
5166
5401
|
name,
|
|
@@ -5168,6 +5403,7 @@ export function writeSwiftProject(
|
|
|
5168
5403
|
executable: true,
|
|
5169
5404
|
resources: false,
|
|
5170
5405
|
dependencies: [{ kind: 'target', name: target.name }],
|
|
5406
|
+
sources: ['Entry.swift'],
|
|
5171
5407
|
exclude: [],
|
|
5172
5408
|
})
|
|
5173
5409
|
files.set(
|
|
@@ -5444,7 +5680,7 @@ export function writeSwiftProject(
|
|
|
5444
5680
|
oneModule: input.oneModule,
|
|
5445
5681
|
spriteKit: importsSpriteKit(input.files),
|
|
5446
5682
|
distribution: distribution ?? undefined,
|
|
5447
|
-
|
|
5683
|
+
moduleExcludes,
|
|
5448
5684
|
deferDarwinOverlay:
|
|
5449
5685
|
native.size > 0 &&
|
|
5450
5686
|
toolsetOrdersLibcxxBeforeDarwinOverlay(
|
|
@@ -5483,15 +5719,28 @@ export function writeSwiftProject(
|
|
|
5483
5719
|
if (files.has(destination)) continue
|
|
5484
5720
|
files.set(destination, Buffer.from(bytes, 'base64'))
|
|
5485
5721
|
}
|
|
5486
|
-
|
|
5722
|
+
const targetToolset = nativeToolset || native.size > 0
|
|
5723
|
+
if (targetToolset) {
|
|
5724
|
+
const nativeToolsetFlags = [
|
|
5725
|
+
...headerAliasFlags,
|
|
5726
|
+
...(native.size > 0
|
|
5727
|
+
? [
|
|
5728
|
+
'-fmodule-map-file=' +
|
|
5729
|
+
path.join(
|
|
5730
|
+
swiftSdkPaths(moduleRoot, nativeToolchain()).sysroot,
|
|
5731
|
+
'darwin/wasm/include/module.modulemap',
|
|
5732
|
+
),
|
|
5733
|
+
]
|
|
5734
|
+
: []),
|
|
5735
|
+
]
|
|
5487
5736
|
files.set(
|
|
5488
5737
|
path.join(layout.root, '.peach-target-toolset.json'),
|
|
5489
5738
|
JSON.stringify({
|
|
5490
5739
|
schemaVersion: '1.0',
|
|
5491
|
-
...(
|
|
5740
|
+
...(nativeToolsetFlags.length > 0
|
|
5492
5741
|
? {
|
|
5493
|
-
cCompiler: { extraCLIOptions:
|
|
5494
|
-
cxxCompiler: { extraCLIOptions:
|
|
5742
|
+
cCompiler: { extraCLIOptions: nativeToolsetFlags },
|
|
5743
|
+
cxxCompiler: { extraCLIOptions: nativeToolsetFlags },
|
|
5495
5744
|
}
|
|
5496
5745
|
: {}),
|
|
5497
5746
|
swiftCompiler: {
|
|
@@ -5499,9 +5748,13 @@ export function writeSwiftProject(
|
|
|
5499
5748
|
...headerAliasFlags.flatMap((flag) => ['-Xcc', flag]),
|
|
5500
5749
|
distribution || prebuilt ? '-Isystem' : '-I',
|
|
5501
5750
|
distribution
|
|
5502
|
-
?
|
|
5751
|
+
? providedModulesPath(
|
|
5752
|
+
layout.root,
|
|
5753
|
+
path.join(moduleRoot, 'modules'),
|
|
5754
|
+
moduleExcludes,
|
|
5755
|
+
)
|
|
5503
5756
|
: prebuilt
|
|
5504
|
-
? prebuilt.modules
|
|
5757
|
+
? providedModulesPath(layout.root, prebuilt.modules, moduleExcludes)
|
|
5505
5758
|
: path.join(layout.root, '.build', WASM_TRIPLE, 'release', 'Modules'),
|
|
5506
5759
|
...(prebuilt?.moduleMaps.flatMap((map) => [
|
|
5507
5760
|
'-Xcc',
|
|
@@ -5510,7 +5763,7 @@ export function writeSwiftProject(
|
|
|
5510
5763
|
'-Xfrontend',
|
|
5511
5764
|
'-enable-cross-import-overlays',
|
|
5512
5765
|
...swiftCrossImportFlags(moduleRoot, Boolean(distribution)),
|
|
5513
|
-
...(distribution
|
|
5766
|
+
...(distribution
|
|
5514
5767
|
? FOUNDATION_IMPLICIT_MODULES.flatMap((module) => [
|
|
5515
5768
|
'-Xfrontend',
|
|
5516
5769
|
'-import-module',
|
|
@@ -5557,6 +5810,15 @@ export function writeSwiftProject(
|
|
|
5557
5810
|
const producers = [
|
|
5558
5811
|
...new Set([...[...native.values()].flatMap((value) => value.late?.producers ?? [])]),
|
|
5559
5812
|
]
|
|
5813
|
+
for (const [owner, plan] of native) {
|
|
5814
|
+
if (!plan.late) continue
|
|
5815
|
+
for (const group of plan.groups ?? [{ name: plan.late.name }]) {
|
|
5816
|
+
const prior = generatedOwners.get(group.name)
|
|
5817
|
+
if (prior !== undefined && prior !== owner)
|
|
5818
|
+
throw new Error(`generated target ${group.name} has multiple owners`)
|
|
5819
|
+
generatedOwners.set(group.name, owner)
|
|
5820
|
+
}
|
|
5821
|
+
}
|
|
5560
5822
|
const headerProductTarget =
|
|
5561
5823
|
layout.multi && producers.length > 1 ? SWIFT_HEADER_PRODUCTS_TARGET : undefined
|
|
5562
5824
|
if (headerProductTarget)
|
|
@@ -5600,6 +5862,8 @@ export function writeSwiftProject(
|
|
|
5600
5862
|
nativeHeaderDeclarations,
|
|
5601
5863
|
headerProductTarget,
|
|
5602
5864
|
targetFailures,
|
|
5865
|
+
generatedOwners,
|
|
5866
|
+
targetToolset,
|
|
5603
5867
|
}
|
|
5604
5868
|
}
|
|
5605
5869
|
|
|
@@ -5877,28 +6141,62 @@ function linkedFrameworkTargets(
|
|
|
5877
6141
|
)
|
|
5878
6142
|
const targets = compileTargets(input)
|
|
5879
6143
|
const planning = targets.length > 0 ? targets : [{ name: 'App', path: '.' }]
|
|
5880
|
-
const siblings = swiftTargetDependencies(input.files, planning)
|
|
6144
|
+
const siblings = swiftTargetDependencies(input.files, planning, libraries.keys())
|
|
5881
6145
|
const reached = new Set<string>()
|
|
5882
6146
|
const reach = (name: string) => {
|
|
5883
|
-
if (
|
|
6147
|
+
if (name === 'SwiftUI') return
|
|
6148
|
+
if (
|
|
6149
|
+
reached.has(name) ||
|
|
6150
|
+
planning.some((target) => swiftTargetModuleName(target.name) === name)
|
|
6151
|
+
)
|
|
6152
|
+
return
|
|
5884
6153
|
reached.add(name)
|
|
5885
6154
|
for (const dependency of OPTIONAL_FRAMEWORK_DEPENDENCIES[name] ?? [])
|
|
5886
6155
|
reach(dependency)
|
|
5887
6156
|
}
|
|
5888
6157
|
for (const name of [...siblings.values()].flat())
|
|
5889
|
-
if (
|
|
6158
|
+
if (libraries.has(name) && !planning.some((target) => target.name === name))
|
|
5890
6159
|
reach(name)
|
|
6160
|
+
// SwiftUI is always present; its companion imports activate these modules.
|
|
6161
|
+
// a companion built as another module's dependency activates its overlay too.
|
|
6162
|
+
const manifest = readFileSync(path.join(moduleRoot, 'Package.swift'), 'utf8')
|
|
6163
|
+
const targetDependencies = new Map<string, string[]>()
|
|
6164
|
+
for (const match of manifest.matchAll(
|
|
6165
|
+
/\.target\(\s*name:\s*"([^"]+)"\s*,\s*dependencies:\s*\[([^\]]*)\]/g,
|
|
6166
|
+
))
|
|
6167
|
+
targetDependencies.set(
|
|
6168
|
+
match[1]!,
|
|
6169
|
+
[...match[2]!.matchAll(/"([^"]+)"/g)].map((item) => item[1]!),
|
|
6170
|
+
)
|
|
6171
|
+
const built = new Set<string>()
|
|
6172
|
+
const build = (name: string) => {
|
|
6173
|
+
if (built.has(name)) return
|
|
6174
|
+
built.add(name)
|
|
6175
|
+
for (const dependency of targetDependencies.get(name) ?? []) build(dependency)
|
|
6176
|
+
}
|
|
6177
|
+
for (const name of reached)
|
|
6178
|
+
for (const member of libraries.get(name) ?? []) build(member)
|
|
6179
|
+
const overlays = path.join(moduleRoot, 'cross-import-overlays')
|
|
6180
|
+
for (const directory of readdirSync(overlays)) {
|
|
6181
|
+
const companion = path.basename(directory, '.swiftcrossimport')
|
|
6182
|
+
if (!built.has(companion)) continue
|
|
6183
|
+
const declaration = path.join(overlays, directory, 'SwiftUI.swiftoverlay')
|
|
6184
|
+
for (const match of readFileSync(declaration, 'utf8').matchAll(
|
|
6185
|
+
/^\s*- name: ([A-Za-z_]\w*)\s*$/gm,
|
|
6186
|
+
))
|
|
6187
|
+
reach(match[1]!)
|
|
6188
|
+
}
|
|
5891
6189
|
if (importsSpriteKit(input.files))
|
|
5892
6190
|
for (const name of ['SpriteKit', 'PeachBox2D', 'simd', 'GLKit']) reach(name)
|
|
5893
6191
|
const wanted = [
|
|
5894
|
-
'
|
|
6192
|
+
'PeachApp',
|
|
5895
6193
|
...(input.oneModule ? ['One'] : []),
|
|
5896
6194
|
...(importsSpriteKit(input.files) ? ['SpriteKit'] : []),
|
|
5897
6195
|
...reached,
|
|
5898
6196
|
]
|
|
5899
6197
|
const linked = [...new Set(wanted)].filter((name) => libraries.has(name))
|
|
5900
|
-
if (!linked.includes('
|
|
5901
|
-
throw new Error('swift-compile: the framework package declares no
|
|
6198
|
+
if (!linked.includes('PeachApp'))
|
|
6199
|
+
throw new Error('swift-compile: the framework package declares no PeachApp library')
|
|
5902
6200
|
const members: string[] = []
|
|
5903
6201
|
for (const product of linked) {
|
|
5904
6202
|
const declared = libraries.get(product) ?? []
|
|
@@ -5963,10 +6261,15 @@ ${dependencies}
|
|
|
5963
6261
|
// node. the shell command's inputs name the modules and objects it compiles
|
|
5964
6262
|
// against, which is the dependency closure. automatic products have no
|
|
5965
6263
|
// Objects.LinkFileList.
|
|
5966
|
-
function frameworkLinkClosure(
|
|
6264
|
+
export function frameworkLinkClosure(
|
|
5967
6265
|
scratch: string,
|
|
5968
6266
|
roots: readonly string[],
|
|
5969
|
-
): {
|
|
6267
|
+
): {
|
|
6268
|
+
objects: string[]
|
|
6269
|
+
owners: Map<string, string>
|
|
6270
|
+
modules: Set<string>
|
|
6271
|
+
moduleMaps: string[]
|
|
6272
|
+
} {
|
|
5970
6273
|
const suffix = `${WASM_TRIPLE}-release`
|
|
5971
6274
|
const phonyHeader = new RegExp(`^ "<(.+)-${suffix}\\.module>":\\s*$`)
|
|
5972
6275
|
const shellHeader = new RegExp(`^ "C\\.(.+)-${suffix}\\.module":\\s*$`)
|
|
@@ -6023,6 +6326,7 @@ function frameworkLinkClosure(
|
|
|
6023
6326
|
const stack = [...roots]
|
|
6024
6327
|
const files: string[] = []
|
|
6025
6328
|
const seen = new Set<string>()
|
|
6329
|
+
const owners = new Map<string, string>()
|
|
6026
6330
|
const maps = new Set<string>()
|
|
6027
6331
|
while (stack.length > 0) {
|
|
6028
6332
|
const name = stack.pop()!
|
|
@@ -6033,6 +6337,10 @@ function frameworkLinkClosure(
|
|
|
6033
6337
|
if (!own || own.length === 0)
|
|
6034
6338
|
throw new Error(`swift-compile: ${name} produced no objects`)
|
|
6035
6339
|
for (const file of own) {
|
|
6340
|
+
const owner = owners.get(file)
|
|
6341
|
+
if (owner !== undefined && owner !== name)
|
|
6342
|
+
throw new Error(`swift-compile: framework object ${file} has multiple owners`)
|
|
6343
|
+
owners.set(file, name)
|
|
6036
6344
|
if (seen.has(file)) continue
|
|
6037
6345
|
seen.add(file)
|
|
6038
6346
|
if (!existsSync(file))
|
|
@@ -6042,7 +6350,7 @@ function frameworkLinkClosure(
|
|
|
6042
6350
|
for (const dependency of dependencies.get(name) ?? []) stack.push(dependency)
|
|
6043
6351
|
}
|
|
6044
6352
|
files.sort()
|
|
6045
|
-
return { objects: files, modules, moduleMaps: [...maps].sort() }
|
|
6353
|
+
return { objects: files, owners, modules, moduleMaps: [...maps].sort() }
|
|
6046
6354
|
}
|
|
6047
6355
|
|
|
6048
6356
|
// apps with other optional frameworks share this directory, so only an artifact
|
|
@@ -6066,6 +6374,7 @@ function removeCaseCollidingModuleArtifacts(
|
|
|
6066
6374
|
interface SwiftFrameworkProducts {
|
|
6067
6375
|
modules: string
|
|
6068
6376
|
objects: string[]
|
|
6377
|
+
owners: Map<string, string>
|
|
6069
6378
|
/** the Darwin module's providers, linked as an archive ahead of the sdk's */
|
|
6070
6379
|
providers: string[]
|
|
6071
6380
|
link: string[]
|
|
@@ -6171,6 +6480,7 @@ async function buildFrameworkProducts(
|
|
|
6171
6480
|
})
|
|
6172
6481
|
}
|
|
6173
6482
|
objects.push(object)
|
|
6483
|
+
linked.owners.set(object, 'UniformTypeIdentifiers')
|
|
6174
6484
|
}
|
|
6175
6485
|
// a previous plan of this scratch may have left a fixture module whose name
|
|
6176
6486
|
// differs only by case. the app searches this directory, so that file would
|
|
@@ -6191,13 +6501,14 @@ async function buildFrameworkProducts(
|
|
|
6191
6501
|
// category-only archive members have no symbol reference to pull them in.
|
|
6192
6502
|
// source consumers need the same direct Foundation input as distributions.
|
|
6193
6503
|
if (link.includes('-lFoundation'))
|
|
6194
|
-
for (const name of foundationCategoryObjects)
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
`wasi/${name}.objc.o`,
|
|
6199
|
-
),
|
|
6504
|
+
for (const name of foundationCategoryObjects) {
|
|
6505
|
+
const object = path.join(
|
|
6506
|
+
swiftSdkPaths(args.moduleRoot, args.toolchainBin).resources,
|
|
6507
|
+
`wasi/${name}.objc.o`,
|
|
6200
6508
|
)
|
|
6509
|
+
objects.push(object)
|
|
6510
|
+
linked.owners.set(object, 'Foundation')
|
|
6511
|
+
}
|
|
6201
6512
|
// the providers compile from this revision's source, once per scratch
|
|
6202
6513
|
const providerDir = path.join(scratch, 'darwin-records')
|
|
6203
6514
|
if (!existsSync(path.join(providerDir, '.complete'))) {
|
|
@@ -6214,13 +6525,16 @@ async function buildFrameworkProducts(
|
|
|
6214
6525
|
})
|
|
6215
6526
|
writeFileSync(path.join(providerDir, '.complete'), '')
|
|
6216
6527
|
}
|
|
6528
|
+
const providers = readdirSync(providerDir)
|
|
6529
|
+
.filter((file) => file.endsWith('.o'))
|
|
6530
|
+
.sort()
|
|
6531
|
+
.map((file) => path.join(providerDir, file))
|
|
6532
|
+
for (const provider of providers) linked.owners.set(provider, 'DarwinRecords')
|
|
6217
6533
|
return {
|
|
6218
6534
|
modules: path.join(release, 'Modules'),
|
|
6219
6535
|
objects,
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
.sort()
|
|
6223
|
-
.map((file) => path.join(providerDir, file)),
|
|
6536
|
+
owners: linked.owners,
|
|
6537
|
+
providers,
|
|
6224
6538
|
link,
|
|
6225
6539
|
moduleMaps: linked.moduleMaps,
|
|
6226
6540
|
}
|
|
@@ -6442,6 +6756,9 @@ function compileSwiftProjectOnce(
|
|
|
6442
6756
|
const root = realpathSync(options.buildRoot)
|
|
6443
6757
|
const moduleRoot = path.resolve(options.moduleRoot)
|
|
6444
6758
|
const distribution = swiftDistributionAt(moduleRoot)
|
|
6759
|
+
const guestGraph = distribution ? input.sourceLinkGraph : undefined
|
|
6760
|
+
// the guest link always runs wasm-opt, so its artifact is the optimized one.
|
|
6761
|
+
if (guestGraph && !input.optimize) input = { ...input, optimize: true }
|
|
6445
6762
|
const layout: SwiftProjectLayout = {
|
|
6446
6763
|
root,
|
|
6447
6764
|
sources: path.join(root, 'Sources', 'App'),
|
|
@@ -6681,7 +6998,7 @@ function compileSwiftProjectOnce(
|
|
|
6681
6998
|
...swiftObjCSelectorOptions(frameworkRoot),
|
|
6682
6999
|
'--swift-sdk',
|
|
6683
7000
|
sdk,
|
|
6684
|
-
...(
|
|
7001
|
+
...(preparation.targetToolset
|
|
6685
7002
|
? ['--toolset', path.join(root, '.peach-target-toolset.json')]
|
|
6686
7003
|
: []),
|
|
6687
7004
|
'-c',
|
|
@@ -6864,7 +7181,8 @@ function compileSwiftProjectOnce(
|
|
|
6864
7181
|
)
|
|
6865
7182
|
}
|
|
6866
7183
|
if (options.project) removeProjectLinks(root)
|
|
6867
|
-
|
|
7184
|
+
// the guest link prunes and links the response file itself.
|
|
7185
|
+
if (input.optimize && !guestGraph)
|
|
6868
7186
|
pruneSwiftWasmLink(
|
|
6869
7187
|
root,
|
|
6870
7188
|
options.toolchainBin,
|
|
@@ -6876,7 +7194,21 @@ function compileSwiftProjectOnce(
|
|
|
6876
7194
|
? projectOutputFile(root, linked, options.project)
|
|
6877
7195
|
: linked
|
|
6878
7196
|
const optimized = `${output}.optimized`
|
|
6879
|
-
if (
|
|
7197
|
+
if (guestGraph)
|
|
7198
|
+
await compileGuestLink({
|
|
7199
|
+
graph: guestGraph,
|
|
7200
|
+
buildDirectory: root,
|
|
7201
|
+
releaseDirectory: path.dirname(linked),
|
|
7202
|
+
moduleRoot: frameworkRoot,
|
|
7203
|
+
toolchainBin: options.toolchainBin,
|
|
7204
|
+
sysroot: swiftSdkPaths(frameworkRoot, options.toolchainBin).sysroot,
|
|
7205
|
+
sdk: swiftModuleSdk(frameworkRoot),
|
|
7206
|
+
staticClangTargets: input.staticClangTargets ?? [],
|
|
7207
|
+
generatedOwners: preparation.generatedOwners,
|
|
7208
|
+
output,
|
|
7209
|
+
optimized,
|
|
7210
|
+
})
|
|
7211
|
+
else if (input.optimize) await optimizeWasm(output, optimized)
|
|
6880
7212
|
const artifact = {
|
|
6881
7213
|
hash,
|
|
6882
7214
|
bytes: readFileSync(input.optimize ? optimized : output),
|