peachsim 0.1.1881 → 0.1.1886
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/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 +8914 -4264
- 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 +8494 -3955
- 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 +9679 -5057
- 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 +525 -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 +523 -118
- package/dist-lib/native-app-identity-project.cjs +395 -72
- package/dist-lib/native-app-identity-project.mjs +720 -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 +58 -28
- package/dist-lib/public-origins-lib.json +233 -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 +30711 -25956
- package/dist-lib/swift-compile.cjs +6782 -2533
- package/dist-lib/swift-compile.mjs +6112 -1864
- 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 +8640 -4109
- 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-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-superset.lock.json +4 -4
- package/src/storageSnapshotContract.ts +20 -1
- package/src/swift-compile.ts +399 -72
- 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 +125 -17
- 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 +13 -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-runtime.lock.json +23 -23
- package/src/wasm-optimize.ts +16 -4
- package/src/xcode-project.ts +142 -14
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process'
|
|
2
|
+
import { createHash } from 'node:crypto'
|
|
3
|
+
import { readFileSync, realpathSync, writeFileSync } from 'node:fs'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import { libraryArchiveTarget, type GuestSourceArtifact } from './swift-guest-source-plan'
|
|
6
|
+
import { frameworkRuntimeProductId } from './swift-runtime-products'
|
|
7
|
+
import type { SwiftSourceLinkGraph } from './swiftContract'
|
|
8
|
+
import type {
|
|
9
|
+
GuestFrameworkProvider,
|
|
10
|
+
GuestFrameworkRequest,
|
|
11
|
+
SwiftFrameworkProduct,
|
|
12
|
+
SwiftSdkProduct,
|
|
13
|
+
} from './swiftRuntimeProductContract'
|
|
14
|
+
|
|
15
|
+
/** Read Clang's per-translation-unit autolink metadata before Wasm drops it. */
|
|
16
|
+
export function clangIrLinkOptions(ir: string): string[] {
|
|
17
|
+
const list = /^!llvm\.linker\.options = !\{([^\n]*)\}$/m.exec(ir)
|
|
18
|
+
if (!list) {
|
|
19
|
+
if (/^!llvm\.linker\.options\s*=/m.test(ir))
|
|
20
|
+
throw new Error('invalid clang link metadata list')
|
|
21
|
+
return []
|
|
22
|
+
}
|
|
23
|
+
const ids = list[1]!.split(',').map((item) => item.trim())
|
|
24
|
+
if (ids.length === 1 && ids[0] === '') return []
|
|
25
|
+
const result: string[] = []
|
|
26
|
+
for (const id of ids) {
|
|
27
|
+
if (!/^!\d+$/.test(id)) throw new Error(`invalid clang link metadata ${id}`)
|
|
28
|
+
const node = new RegExp(`^${id} = !\\{([^\\n]*)\\}$`, 'm').exec(ir)
|
|
29
|
+
if (!node) throw new Error(`missing clang link metadata ${id}`)
|
|
30
|
+
const parts = node[1]!.split(/,\s*(?=!")/)
|
|
31
|
+
for (const part of parts) {
|
|
32
|
+
const value = /^!"((?:[^"\\]|\\[0-9A-Fa-f]{2})*)"$/.exec(part.trim())
|
|
33
|
+
if (!value) throw new Error(`invalid clang link option ${part}`)
|
|
34
|
+
const decoded = value[1]!.replace(/\\([0-9A-Fa-f]{2})/g, (_, hex: string) =>
|
|
35
|
+
String.fromCharCode(Number.parseInt(hex, 16)),
|
|
36
|
+
)
|
|
37
|
+
const flag = Buffer.from(decoded, 'latin1').toString('utf8')
|
|
38
|
+
if (!flag || flag.includes('\0')) throw new Error('invalid empty clang link option')
|
|
39
|
+
result.push(flag)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return result
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Replay only selected source-owned Clang commands to retain their IR link options. */
|
|
46
|
+
export function sourceGuestClangLinkOptions(options: {
|
|
47
|
+
buildDirectory: string
|
|
48
|
+
directory: string
|
|
49
|
+
toolchainBin: string
|
|
50
|
+
objects: readonly string[]
|
|
51
|
+
}): Map<string, string[]> {
|
|
52
|
+
const wanted = new Set(options.objects.map((file) => path.resolve(file)))
|
|
53
|
+
const commands = new Map<string, { tool: string; args: string[] }>()
|
|
54
|
+
let tool = ''
|
|
55
|
+
let outputs: string[] = []
|
|
56
|
+
for (const line of readFileSync(
|
|
57
|
+
path.join(options.buildDirectory, '.build', 'release.yaml'),
|
|
58
|
+
'utf8',
|
|
59
|
+
).split('\n')) {
|
|
60
|
+
if (line.startsWith(' "') && line.endsWith(':')) {
|
|
61
|
+
tool = ''
|
|
62
|
+
outputs = []
|
|
63
|
+
continue
|
|
64
|
+
}
|
|
65
|
+
if (line.startsWith(' tool: ')) tool = line.slice(10).trim()
|
|
66
|
+
if (line.startsWith(' outputs: ')) {
|
|
67
|
+
const value: unknown = JSON.parse(line.slice(13))
|
|
68
|
+
if (!Array.isArray(value) || !value.every((item) => typeof item === 'string'))
|
|
69
|
+
throw new Error('invalid build command outputs')
|
|
70
|
+
outputs = value
|
|
71
|
+
}
|
|
72
|
+
if (
|
|
73
|
+
!line.startsWith(' args: ') ||
|
|
74
|
+
!outputs.some((file) => wanted.has(path.resolve(file)))
|
|
75
|
+
)
|
|
76
|
+
continue
|
|
77
|
+
const value: unknown = JSON.parse(line.slice(10))
|
|
78
|
+
if (!Array.isArray(value) || !value.every((item) => typeof item === 'string'))
|
|
79
|
+
throw new Error('invalid build command arguments')
|
|
80
|
+
for (const output of outputs) {
|
|
81
|
+
const file = path.resolve(output)
|
|
82
|
+
if (!wanted.has(file)) continue
|
|
83
|
+
if (commands.has(file)) throw new Error(`ambiguous source object producer ${file}`)
|
|
84
|
+
commands.set(file, { tool, args: value })
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const result = new Map<string, string[]>()
|
|
88
|
+
for (const [index, file] of [...wanted].entries()) {
|
|
89
|
+
const command = commands.get(file)
|
|
90
|
+
if (!command) throw new Error(`missing source object producer ${file}`)
|
|
91
|
+
if (command.tool === 'shell') {
|
|
92
|
+
if (
|
|
93
|
+
!command.args.length ||
|
|
94
|
+
realpathSync(command.args[0]!) !==
|
|
95
|
+
realpathSync(path.join(options.toolchainBin, 'swiftc'))
|
|
96
|
+
)
|
|
97
|
+
throw new Error(`unsupported source object producer ${file}`)
|
|
98
|
+
continue
|
|
99
|
+
}
|
|
100
|
+
if (
|
|
101
|
+
command.tool !== 'clang' ||
|
|
102
|
+
!command.args.length ||
|
|
103
|
+
realpathSync(command.args[0]!) !==
|
|
104
|
+
realpathSync(path.join(options.toolchainBin, 'clang'))
|
|
105
|
+
)
|
|
106
|
+
throw new Error(`unsupported source object producer ${file}`)
|
|
107
|
+
const args = command.args.slice(1).filter((arg) => arg !== '-c')
|
|
108
|
+
const output = path.join(options.directory, `clang-link-${index}.ll`)
|
|
109
|
+
for (const flag of ['-o', '-MF']) {
|
|
110
|
+
const index = args.lastIndexOf(flag)
|
|
111
|
+
if (index < 0 || index + 1 >= args.length)
|
|
112
|
+
throw new Error(`missing clang ${flag} for ${file}`)
|
|
113
|
+
args[index + 1] = flag === '-o' ? output : `${output}.d`
|
|
114
|
+
}
|
|
115
|
+
execFileSync(command.args[0]!, [...args, '-S', '-emit-llvm'], { stdio: 'inherit' })
|
|
116
|
+
const flags = clangIrLinkOptions(readFileSync(output, 'utf8'))
|
|
117
|
+
for (let index = 0; index < flags.length; index++) {
|
|
118
|
+
const flag = flags[index]!
|
|
119
|
+
if (flag === '-framework' || flag === '-l' || flag === '--library') {
|
|
120
|
+
const name = flags[++index]
|
|
121
|
+
if (!name || name.startsWith('-'))
|
|
122
|
+
throw new Error(`missing clang link name after ${flag}`)
|
|
123
|
+
} else if (!/^(-l.+|--library=.+)$/.test(flag)) {
|
|
124
|
+
throw new Error(`unsupported clang link option ${flag}`)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
result.set(file, flags)
|
|
128
|
+
}
|
|
129
|
+
return result
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** name actual source objects by original target and producer-relative output. */
|
|
133
|
+
export function sourceGuestInputIdentities(
|
|
134
|
+
graph: SwiftSourceLinkGraph,
|
|
135
|
+
buildDirectory: string,
|
|
136
|
+
objects: readonly GuestSourceArtifact[],
|
|
137
|
+
): Map<string, string> {
|
|
138
|
+
const producers = new Map<string, string | null>()
|
|
139
|
+
for (const target of graph.targets)
|
|
140
|
+
if (target.sourceTarget !== null)
|
|
141
|
+
producers.set(
|
|
142
|
+
target.sourceTarget,
|
|
143
|
+
producers.has(target.sourceTarget) ? null : target.id,
|
|
144
|
+
)
|
|
145
|
+
const identities = new Map<string, string>()
|
|
146
|
+
for (const object of objects) {
|
|
147
|
+
const target = producers.get(object.sourceTarget)
|
|
148
|
+
if (target === null || target === undefined)
|
|
149
|
+
throw new Error(`ambiguous source producer ${object.sourceTarget}`)
|
|
150
|
+
if (object.kind === 'archive') {
|
|
151
|
+
identities.set(
|
|
152
|
+
object.path,
|
|
153
|
+
JSON.stringify([
|
|
154
|
+
'source',
|
|
155
|
+
target,
|
|
156
|
+
`libraries/lib${libraryArchiveTarget(object.path)}.a`,
|
|
157
|
+
]),
|
|
158
|
+
)
|
|
159
|
+
continue
|
|
160
|
+
}
|
|
161
|
+
const relative = path.relative(buildDirectory, object.path).split(path.sep)
|
|
162
|
+
if (!relative[0]?.endsWith('.build') || relative.length < 2)
|
|
163
|
+
throw new Error(`source object is outside its producer ${object.path}`)
|
|
164
|
+
identities.set(object.path, JSON.stringify(['source', target, relative.join('/')]))
|
|
165
|
+
}
|
|
166
|
+
return identities
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** resolve actual per-image autolinks through producer-declared aliases only. */
|
|
170
|
+
export function sourceGuestRuntimeLinks(options: {
|
|
171
|
+
toolchainBin: string
|
|
172
|
+
directory: string
|
|
173
|
+
products: readonly { product: SwiftSdkProduct; root: string }[]
|
|
174
|
+
framework: { readonly product: SwiftFrameworkProduct; readonly root: string }
|
|
175
|
+
sdk: {
|
|
176
|
+
readonly root: string
|
|
177
|
+
readonly wasmSdkId: string
|
|
178
|
+
readonly wasmSdkChecksum: string
|
|
179
|
+
}
|
|
180
|
+
images: readonly {
|
|
181
|
+
id: number
|
|
182
|
+
objects: readonly string[]
|
|
183
|
+
/** source-image linker flags, not another image's or a flattened product's. */
|
|
184
|
+
linkerFlags: readonly string[]
|
|
185
|
+
clangLinkOptions: readonly {
|
|
186
|
+
readonly object: string
|
|
187
|
+
readonly flags: readonly string[]
|
|
188
|
+
}[]
|
|
189
|
+
}[]
|
|
190
|
+
}): {
|
|
191
|
+
links: Map<number, string[]>
|
|
192
|
+
frameworkRequests: Map<number, GuestFrameworkRequest[]>
|
|
193
|
+
} {
|
|
194
|
+
const aliases = new Map<string, string>()
|
|
195
|
+
const artifacts = new Map<string, string | null>()
|
|
196
|
+
const frameworkAliases = new Map<string, GuestFrameworkProvider>()
|
|
197
|
+
const sdkAliases = new Map<
|
|
198
|
+
string,
|
|
199
|
+
{ product: string; moduleMap: string; sha256: string }
|
|
200
|
+
>()
|
|
201
|
+
for (const { product, root } of options.products) {
|
|
202
|
+
for (const alias of product.frameworkAliases) {
|
|
203
|
+
if (product.linkOwnership !== 'image')
|
|
204
|
+
throw new Error(`framework namespace has no image owner ${product.id}`)
|
|
205
|
+
const previous = sdkAliases.get(alias.name)
|
|
206
|
+
if (previous) {
|
|
207
|
+
if (
|
|
208
|
+
previous.product !== product.id ||
|
|
209
|
+
previous.moduleMap !== alias.moduleMap ||
|
|
210
|
+
previous.sha256 !== alias.moduleMapSha256
|
|
211
|
+
)
|
|
212
|
+
throw new Error(`ambiguous declared framework ${alias.name}`)
|
|
213
|
+
continue
|
|
214
|
+
}
|
|
215
|
+
const directory = path.resolve(options.sdk.root)
|
|
216
|
+
const file = path.resolve(directory, alias.moduleMap)
|
|
217
|
+
if (!file.startsWith(directory + path.sep))
|
|
218
|
+
throw new Error(`invalid framework module map ${alias.moduleMap}`)
|
|
219
|
+
if (
|
|
220
|
+
createHash('sha256').update(readFileSync(file)).digest('hex') !==
|
|
221
|
+
alias.moduleMapSha256
|
|
222
|
+
)
|
|
223
|
+
throw new Error(`framework module map changed ${alias.moduleMap}`)
|
|
224
|
+
sdkAliases.set(alias.name, {
|
|
225
|
+
product: product.id,
|
|
226
|
+
moduleMap: alias.moduleMap,
|
|
227
|
+
sha256: alias.moduleMapSha256,
|
|
228
|
+
})
|
|
229
|
+
frameworkAliases.set(alias.name, { kind: 'sdk', product: product.id })
|
|
230
|
+
}
|
|
231
|
+
for (const artifact of product.artifacts) {
|
|
232
|
+
const file = path.resolve(root, artifact.path)
|
|
233
|
+
const prior = artifacts.get(file)
|
|
234
|
+
artifacts.set(file, prior === undefined || prior === product.id ? product.id : null)
|
|
235
|
+
}
|
|
236
|
+
for (const name of product.linkNames) {
|
|
237
|
+
const prior = aliases.get(name)
|
|
238
|
+
if (prior !== undefined && prior !== product.id)
|
|
239
|
+
throw new Error(`ambiguous declared runtime link name ${name}`)
|
|
240
|
+
aliases.set(name, product.id)
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const frameworkId = frameworkRuntimeProductId(options.framework.product)
|
|
244
|
+
const owners = options.products.filter(({ product }) => product.id === frameworkId)
|
|
245
|
+
if (
|
|
246
|
+
owners.length !== 1 ||
|
|
247
|
+
owners[0]!.product.linkOwnership !== 'image' ||
|
|
248
|
+
path.resolve(owners[0]!.root) !== path.resolve(options.framework.root)
|
|
249
|
+
)
|
|
250
|
+
throw new Error(`missing or ambiguous packaged image ${frameworkId}`)
|
|
251
|
+
const targets = new Map(
|
|
252
|
+
options.framework.product.targets.map((target) => [target.name, target]),
|
|
253
|
+
)
|
|
254
|
+
if (targets.size !== options.framework.product.targets.length)
|
|
255
|
+
throw new Error('ambiguous packaged framework target')
|
|
256
|
+
const objectTargets = new Set(
|
|
257
|
+
options.framework.product.objects.map((object) => object.target),
|
|
258
|
+
)
|
|
259
|
+
const closure = (names: readonly string[]) => {
|
|
260
|
+
const linked = new Set<string>()
|
|
261
|
+
const visit = (name: string) => {
|
|
262
|
+
if (linked.has(name)) return
|
|
263
|
+
const target = targets.get(name)
|
|
264
|
+
if (!target) throw new Error(`unknown packaged framework target ${name}`)
|
|
265
|
+
linked.add(name)
|
|
266
|
+
for (const dependency of target.dependencies) visit(dependency)
|
|
267
|
+
}
|
|
268
|
+
for (const name of names) visit(name)
|
|
269
|
+
return [...linked]
|
|
270
|
+
}
|
|
271
|
+
for (const alias of options.framework.product.frameworkAliases) {
|
|
272
|
+
if (frameworkAliases.has(alias.name))
|
|
273
|
+
throw new Error(`ambiguous declared framework ${alias.name}`)
|
|
274
|
+
if (
|
|
275
|
+
alias.wasmSdkId !== options.sdk.wasmSdkId ||
|
|
276
|
+
alias.wasmSdkChecksum !== options.sdk.wasmSdkChecksum
|
|
277
|
+
)
|
|
278
|
+
throw new Error(`framework SDK identity differs for ${alias.name}`)
|
|
279
|
+
if (
|
|
280
|
+
!alias.targets.length ||
|
|
281
|
+
alias.targets.some((target) => !targets.has(target) || !objectTargets.has(target))
|
|
282
|
+
)
|
|
283
|
+
throw new Error(`framework target ownership differs for ${alias.name}`)
|
|
284
|
+
const root = path.resolve(options.framework.root)
|
|
285
|
+
const map = path.resolve(root, alias.moduleMap)
|
|
286
|
+
if (!map.startsWith(root + path.sep))
|
|
287
|
+
throw new Error(`invalid framework module map ${alias.moduleMap}`)
|
|
288
|
+
if (
|
|
289
|
+
createHash('sha256').update(readFileSync(map)).digest('hex') !==
|
|
290
|
+
alias.moduleMapSha256
|
|
291
|
+
)
|
|
292
|
+
throw new Error(`framework module map changed ${alias.moduleMap}`)
|
|
293
|
+
frameworkAliases.set(alias.name, { kind: 'package', targets: closure(alias.targets) })
|
|
294
|
+
}
|
|
295
|
+
// a framework with no Objective-C declarations ships no module map, so it has
|
|
296
|
+
// no alias, but its Swift target in the packaged image is the framework
|
|
297
|
+
for (const name of objectTargets)
|
|
298
|
+
if (!frameworkAliases.has(name) && targets.has(name))
|
|
299
|
+
frameworkAliases.set(name, { kind: 'package', targets: closure([name]) })
|
|
300
|
+
const result = new Map<number, string[]>()
|
|
301
|
+
const frameworkRequests = new Map<number, GuestFrameworkRequest[]>()
|
|
302
|
+
for (const image of options.images) {
|
|
303
|
+
if (result.has(image.id)) throw new Error(`duplicate source image ${image.id}`)
|
|
304
|
+
const response = path.join(options.directory, `image-${image.id}-autolink.rsp`)
|
|
305
|
+
writeFileSync(
|
|
306
|
+
response,
|
|
307
|
+
image.objects.map((file) => JSON.stringify(file)).join('\n') + '\n',
|
|
308
|
+
)
|
|
309
|
+
const autolink = image.objects.length
|
|
310
|
+
? execFileSync(
|
|
311
|
+
path.join(options.toolchainBin, 'swift-autolink-extract'),
|
|
312
|
+
[`@${response}`, '-o', '-'],
|
|
313
|
+
{ encoding: 'utf8' },
|
|
314
|
+
)
|
|
315
|
+
.split('\n')
|
|
316
|
+
.map((line) => line.trim())
|
|
317
|
+
.filter((line) => line.length > 0)
|
|
318
|
+
: []
|
|
319
|
+
const links: string[] = []
|
|
320
|
+
const requests: GuestFrameworkRequest[] = []
|
|
321
|
+
const optionGroups = [
|
|
322
|
+
{ object: null, flags: [...image.linkerFlags, ...autolink] },
|
|
323
|
+
...image.clangLinkOptions,
|
|
324
|
+
]
|
|
325
|
+
for (const { object, flags } of optionGroups) {
|
|
326
|
+
for (let index = 0; index < flags.length; index++) {
|
|
327
|
+
const flag = flags[index]!
|
|
328
|
+
const artifact = artifacts.get(flag)
|
|
329
|
+
if (artifact === null)
|
|
330
|
+
throw new Error(`ambiguous declared runtime artifact ${flag}`)
|
|
331
|
+
if (artifact !== undefined) {
|
|
332
|
+
if (!links.includes(artifact)) links.push(artifact)
|
|
333
|
+
continue
|
|
334
|
+
}
|
|
335
|
+
if (path.isAbsolute(flag) && flag.endsWith('.a'))
|
|
336
|
+
throw new Error(
|
|
337
|
+
`source image ${image.id} has unresolved runtime artifact ${flag}`,
|
|
338
|
+
)
|
|
339
|
+
if (flag === '-framework') {
|
|
340
|
+
const name = flags[++index]
|
|
341
|
+
const provider = name && frameworkAliases.get(name)
|
|
342
|
+
if (!provider)
|
|
343
|
+
throw new Error(
|
|
344
|
+
`source image ${image.id} has unresolved framework linkage ${name}`,
|
|
345
|
+
)
|
|
346
|
+
requests.push({ object, provider })
|
|
347
|
+
continue
|
|
348
|
+
}
|
|
349
|
+
if (
|
|
350
|
+
flag.startsWith('-weak') ||
|
|
351
|
+
flag.startsWith('-reexport') ||
|
|
352
|
+
flag.startsWith('-upward') ||
|
|
353
|
+
flag.startsWith('-lazy') ||
|
|
354
|
+
flag.startsWith('-Wl,')
|
|
355
|
+
)
|
|
356
|
+
throw new Error(
|
|
357
|
+
`source image ${image.id} has unsupported runtime scope flag ${flag}`,
|
|
358
|
+
)
|
|
359
|
+
const name =
|
|
360
|
+
flag === '-l' || flag === '--library'
|
|
361
|
+
? flags[++index]
|
|
362
|
+
: flag.startsWith('-l')
|
|
363
|
+
? flag.slice(2)
|
|
364
|
+
: flag.startsWith('--library=')
|
|
365
|
+
? flag.slice('--library='.length)
|
|
366
|
+
: null
|
|
367
|
+
if (name === null) continue
|
|
368
|
+
const product = name === undefined ? undefined : aliases.get(name)
|
|
369
|
+
if (product === undefined)
|
|
370
|
+
throw new Error(`source image ${image.id} has unresolved runtime link ${name}`)
|
|
371
|
+
if (!links.includes(product)) links.push(product)
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
result.set(image.id, links)
|
|
375
|
+
frameworkRequests.set(image.id, requests)
|
|
376
|
+
}
|
|
377
|
+
return { links: result, frameworkRequests }
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** retain effective option order while replacing only explicitly owned paths. */
|
|
381
|
+
export function logicalGuestLinkOptions(
|
|
382
|
+
args: readonly string[],
|
|
383
|
+
identities: ReadonlyMap<string, string>,
|
|
384
|
+
roots: readonly { path: string; identity: string }[],
|
|
385
|
+
): string[] {
|
|
386
|
+
const orderedRoots = [...roots].sort(
|
|
387
|
+
(left, right) => right.path.length - left.path.length,
|
|
388
|
+
)
|
|
389
|
+
const logicalPath = (file: string) => {
|
|
390
|
+
const direct = identities.get(file)
|
|
391
|
+
if (direct !== undefined) return direct
|
|
392
|
+
if (/\.(?:o|obj|a)$/.test(file))
|
|
393
|
+
throw new Error(`link input has no logical identity ${file}`)
|
|
394
|
+
for (const root of orderedRoots) {
|
|
395
|
+
const relative = path.relative(root.path, file)
|
|
396
|
+
if (
|
|
397
|
+
relative !== '..' &&
|
|
398
|
+
!relative.startsWith(`..${path.sep}`) &&
|
|
399
|
+
!path.isAbsolute(relative)
|
|
400
|
+
)
|
|
401
|
+
return `${root.identity}/${relative.split(path.sep).join('/')}`
|
|
402
|
+
}
|
|
403
|
+
throw new Error(`link option has no logical path identity ${file}`)
|
|
404
|
+
}
|
|
405
|
+
const output: string[] = []
|
|
406
|
+
for (let index = 0; index < args.length; index++) {
|
|
407
|
+
const arg = args[index]!
|
|
408
|
+
if (arg === '-o' || arg === '--output' || arg === '--Map') {
|
|
409
|
+
index++
|
|
410
|
+
continue
|
|
411
|
+
}
|
|
412
|
+
if (arg.startsWith('--output=') || arg.startsWith('--Map=')) continue
|
|
413
|
+
if (arg === '-L' || arg === '--library-path') {
|
|
414
|
+
output.push(arg, logicalPath(args[++index]!))
|
|
415
|
+
continue
|
|
416
|
+
}
|
|
417
|
+
if (arg.startsWith('-L')) output.push(`-L${logicalPath(arg.slice(2))}`)
|
|
418
|
+
else if (arg.startsWith('--library-path='))
|
|
419
|
+
output.push(`--library-path=${logicalPath(arg.slice('--library-path='.length))}`)
|
|
420
|
+
else if (path.isAbsolute(arg)) output.push(logicalPath(arg))
|
|
421
|
+
else if (/^[^=]+=\//.test(arg)) {
|
|
422
|
+
const equals = arg.indexOf('=')
|
|
423
|
+
output.push(arg.slice(0, equals + 1) + logicalPath(arg.slice(equals + 1)))
|
|
424
|
+
} else output.push(identities.get(arg) ?? arg)
|
|
425
|
+
}
|
|
426
|
+
return output
|
|
427
|
+
}
|