peachsim 0.1.2412 → 0.1.2422

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.
Files changed (150) hide show
  1. package/README.md +1 -1
  2. package/cli/catalog/content.ts +6 -3
  3. package/cli/catalog/meta.ts +63 -17
  4. package/cli/catalog/routes.ts +4 -0
  5. package/cli/cloud-box-artifact.ts +45 -24
  6. package/cli/cloud-client.ts +6 -2
  7. package/cli/command-registry.ts +3 -1
  8. package/cli/commands/control.ts +74 -55
  9. package/cli/commands/desktop.ts +3 -3
  10. package/cli/commands/electron.ts +7 -5
  11. package/cli/commands/kotlin.ts +8 -1
  12. package/cli/commands/platform.ts +5 -7
  13. package/cli/commands/profile.ts +2 -2
  14. package/cli/commands/settings.ts +90 -0
  15. package/cli/commands/shell-url.ts +18 -10
  16. package/cli/commands/swift.ts +3 -1
  17. package/cli/main.ts +6 -0
  18. package/cli/outbound-endpoints.ts +17 -15
  19. package/cli/settings-flags.ts +115 -0
  20. package/dist-lib/agent-daemon-client.cjs +1 -1
  21. package/dist-lib/agent-events.cjs +1 -1
  22. package/dist-lib/attached-projects.cjs +1 -1
  23. package/dist-lib/auth/shared-session.cjs +1 -1
  24. package/dist-lib/backend-origin.cjs +1 -1
  25. package/dist-lib/beta.cjs +1 -1
  26. package/dist-lib/beta.mjs +1 -1
  27. package/dist-lib/bridge-constants.cjs +1 -1
  28. package/dist-lib/bridge-contract-input.cjs +1 -1
  29. package/dist-lib/bridge-contract-input.mjs +1 -1
  30. package/dist-lib/bridge-contract.cjs +1 -1
  31. package/dist-lib/bridge-contract.mjs +1 -1
  32. package/dist-lib/bundle-channel.cjs +6683 -4510
  33. package/dist-lib/capture-contract.cjs +1 -1
  34. package/dist-lib/capture-contract.mjs +1 -1
  35. package/dist-lib/cloud-contract.cjs +1 -1
  36. package/dist-lib/cloud-contract.mjs +1 -1
  37. package/dist-lib/cloud-test-args.cjs +1 -1
  38. package/dist-lib/cloud-test-args.mjs +1 -1
  39. package/dist-lib/cloud.cjs +1 -1
  40. package/dist-lib/cloud.mjs +1 -1
  41. package/dist-lib/config.cjs +3 -7
  42. package/dist-lib/config.mjs +3 -7
  43. package/dist-lib/detox/index.cjs +4 -4
  44. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  45. package/dist-lib/expo-swift-bundle.cjs +19780 -17646
  46. package/dist-lib/expo-swift-metadata.cjs +1 -1
  47. package/dist-lib/expo-swift-metadata.mjs +1 -1
  48. package/dist-lib/home-paths.cjs +1 -1
  49. package/dist-lib/host/bridge-host.cjs +63968 -62664
  50. package/dist-lib/host/fetch-proxy-handler.cjs +1619 -211
  51. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  52. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  53. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  54. package/dist-lib/host/websocket-proxy.cjs +1 -1
  55. package/dist-lib/index.cjs +2734 -1222
  56. package/dist-lib/jump-to-source-babel.cjs +1 -1
  57. package/dist-lib/jump-to-source-native.cjs +1 -1
  58. package/dist-lib/kotlin-host.cjs +972 -246
  59. package/dist-lib/menu.cjs +1 -1
  60. package/dist-lib/menu.mjs +1 -1
  61. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  62. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  63. package/dist-lib/metro-production-bundle.cjs +1 -1
  64. package/dist-lib/metro-production-bundle.mjs +1 -1
  65. package/dist-lib/metro.cjs +1758 -246
  66. package/dist-lib/native-app-identity-project.cjs +35 -203
  67. package/dist-lib/native-app-identity-project.mjs +264 -413
  68. package/dist-lib/native-app-identity.cjs +1 -1
  69. package/dist-lib/native-app-identity.mjs +1 -1
  70. package/dist-lib/native-firebase-metadata.cjs +1 -1
  71. package/dist-lib/native-firebase-metadata.mjs +1 -1
  72. package/dist-lib/pdfium-raster.cjs +1 -1
  73. package/dist-lib/pdfium-raster.mjs +1 -1
  74. package/dist-lib/plist.cjs +1 -1
  75. package/dist-lib/plist.mjs +1 -1
  76. package/dist-lib/profiles.cjs +1 -1
  77. package/dist-lib/public-brand.cjs +1 -1
  78. package/dist-lib/public-origins-lib-esm.json +32 -25
  79. package/dist-lib/public-origins-lib.json +222 -120
  80. package/dist-lib/react-native-host-modules.cjs +1 -1
  81. package/dist-lib/react-native-host-modules.mjs +1 -1
  82. package/dist-lib/reap-browser.cjs +1 -1
  83. package/dist-lib/scripts/dev-server-scanner.cjs +2 -2
  84. package/dist-lib/sdk.cjs +1 -1
  85. package/dist-lib/sdk.mjs +1 -1
  86. package/dist-lib/skills.cjs +24600 -23060
  87. package/dist-lib/swift-compile.cjs +1396 -1203
  88. package/dist-lib/swift-compile.mjs +1351 -1148
  89. package/dist-lib/swift-package.cjs +1 -1
  90. package/dist-lib/swift-package.mjs +1 -1
  91. package/dist-lib/swift-submit.cjs +1 -1
  92. package/dist-lib/swift-submit.mjs +1 -1
  93. package/dist-lib/swift-toolchain.cjs +1 -199
  94. package/dist-lib/swift.cjs +1 -1
  95. package/dist-lib/vite-swift.cjs +2832 -2588
  96. package/dist-lib/vite.cjs +5254 -3781
  97. package/dist-lib/worklet-executable.cjs +1 -1
  98. package/dist-lib/worklet-executable.mjs +1 -1
  99. package/dist-types/packages/peach-engine/src/config.d.ts +1 -4
  100. package/dist-types/packages/peach-engine/src/engine/native-layout.d.ts +1 -1
  101. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +0 -10
  102. package/dist-types/packages/peach-engine/src/render-worker/compositor-runtime/layer-claims.d.ts +2 -1
  103. package/kotlin/README.md +4 -3
  104. package/kotlin/sdk.tar.gz +0 -0
  105. package/kotlin/toolchain.json +3 -6
  106. package/package.json +1 -1
  107. package/runtime-companion.json +1 -1
  108. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CALayer.h +1 -43
  109. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CALayerContents.h +55 -0
  110. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Modules/module.modulemap +3 -3
  111. package/sdk/ios/usr/include/ObjectiveC.apinotes +0 -24
  112. package/sdk/ios/usr/include/grp.h +93 -0
  113. package/sdk/ios/usr/include/netinet/tcp.h +299 -0
  114. package/sdk/ios/wasm/include/netinet/tcp.h +6 -0
  115. package/sdk/ios/wasm/include/stdlib.h +1 -0
  116. package/sdk/ios/wasm/include/unistd.h +2 -0
  117. package/skills/contrast/SKILL.md +1 -0
  118. package/skills/peach-setup/SKILL.md +11 -1
  119. package/src/android-bridge-dependencies.ts +1 -1
  120. package/src/app-config.ts +7 -0
  121. package/src/binaryen.lock.json +21 -0
  122. package/src/cocoapods-trunk.ts +52 -0
  123. package/src/config.ts +21 -31
  124. package/src/expo-kotlin-bundle.ts +1 -1
  125. package/src/kotlin-host.ts +1 -1
  126. package/src/kotlin-sdk.ts +7 -7
  127. package/src/kotlin-toolchain.ts +28 -24
  128. package/src/kotlinSdkContract.ts +2 -2
  129. package/src/native-bundles.ts +5 -2
  130. package/src/native-static-libraries.ts +85 -5
  131. package/src/podfile-cocoapods.ts +1473 -0
  132. package/src/podspec-cocoapods.ts +331 -106
  133. package/src/podspec-ruby-stdlib.ts +134 -19
  134. package/src/podspec-ruby.ts +199 -46
  135. package/src/settingsContract.ts +74 -0
  136. package/src/swift-compile.ts +185 -108
  137. package/src/swift-compiler-digest.ts +3 -0
  138. package/src/swift-guest-compile.ts +2 -0
  139. package/src/swift-guest-source-inputs.ts +2 -2
  140. package/src/swift-header-compiler.ts +185 -0
  141. package/src/swift-header-dependencies.ts +174 -0
  142. package/src/swift-host.ts +32 -7
  143. package/src/swift-objc-compile.ts +18 -24
  144. package/src/swift-packages.ts +35 -6
  145. package/src/swift-shared-sdk.ts +19 -0
  146. package/src/swift-toolchain.ts +2 -201
  147. package/src/turbo-source.ts +7 -37
  148. package/src/wasm-optimize.ts +4 -27
  149. package/src/xcode-project.ts +6 -1
  150. package/dist-types/packages/peach-engine/src/render-worker/accessibilityHostContract.d.ts +0 -65
@@ -0,0 +1,185 @@
1
+ import { createHash } from 'node:crypto'
2
+ import {
3
+ chmodSync,
4
+ existsSync,
5
+ mkdirSync,
6
+ mkdtempSync,
7
+ readFileSync,
8
+ renameSync,
9
+ rmSync,
10
+ statSync,
11
+ writeFileSync,
12
+ } from 'node:fs'
13
+ import { createServer } from 'node:http'
14
+ import path from 'node:path'
15
+ import { PEACH_FORKED_SCRIPT_ENV } from './forked-script-contract'
16
+ import { isRecord } from './is-record'
17
+ import { writeBuildFile } from './write-build-file'
18
+
19
+ export const SWIFT_HEADER_COMPILER_WRAPPER = '.build/peach-swiftc'
20
+
21
+ const argument = (value: string) => `'${value.replaceAll("'", `'"'"'`)}'`
22
+
23
+ const client = `const { request } = require('node:http')
24
+ const { spawnSync } = require('node:child_process')
25
+ const { existsSync } = require('node:fs')
26
+ const [socketPath, moduleName, swiftc, receipt, ...args] = process.argv.slice(2)
27
+ const body = JSON.stringify(args)
28
+ const notify = (method) => new Promise((resolve, reject) => {
29
+ const req = request({ socketPath, path: '/' + moduleName, method }, response => {
30
+ let message = ''
31
+ response.setEncoding('utf8').on('data', data => { message += data })
32
+ response.on('end', () => {
33
+ if (response.statusCode === 200 || response.statusCode === 204) resolve(response.statusCode === 200)
34
+ else reject(new Error(message))
35
+ })
36
+ response.on('error', reject)
37
+ })
38
+ req.on('error', reject)
39
+ req.end(body)
40
+ })
41
+ async function compile() {
42
+ if (existsSync(receipt) && await notify('PUT')) return
43
+ const result = spawnSync(swiftc, args, { stdio: 'inherit' })
44
+ if (result.error) throw result.error
45
+ if (result.status !== 0) { process.exitCode = result.status ?? 1; return }
46
+ await notify('POST')
47
+ }
48
+ compile().catch(error => {
49
+ process.stderr.write(String(error) + '\\n')
50
+ process.exitCode = 1
51
+ })
52
+ `
53
+
54
+ function compilerCheckpoint(
55
+ root: string,
56
+ recipe: string,
57
+ args: string[],
58
+ header: string,
59
+ ): string | undefined {
60
+ const value = (flag: string) => {
61
+ const index = args.lastIndexOf(flag)
62
+ return index < 0 ? undefined : args[index + 1]
63
+ }
64
+ const outputMap = value('-output-file-map')
65
+ const module = value('-emit-module-path')
66
+ if (!outputMap || !module || !args.includes('-whole-module-optimization')) return
67
+ const mapText = readFileSync(outputMap, 'utf8')
68
+ const map: unknown = JSON.parse(mapText)
69
+ if (!isRecord(map) || !isRecord(map['']) || typeof map[''].dependencies !== 'string')
70
+ return
71
+ const objects: string[] = []
72
+ for (const [source, outputs] of Object.entries(map)) {
73
+ if (!source) continue
74
+ if (!isRecord(outputs) || typeof outputs.object !== 'string') return
75
+ objects.push(outputs.object)
76
+ }
77
+ if (!objects.length) return
78
+ const outputs = [module, header, map[''].dependencies, ...objects]
79
+ const digest = createHash('sha256')
80
+ .update(recipe)
81
+ .update(JSON.stringify(args))
82
+ .update(mapText)
83
+ for (const flag of args) {
84
+ if (!flag.startsWith('@')) continue
85
+ const response = flag.slice(1)
86
+ if (!path.isAbsolute(response) || !existsSync(response)) return
87
+ digest.update(readFileSync(response))
88
+ }
89
+ for (const file of outputs) {
90
+ if (!file.startsWith(path.join(root, '.build') + path.sep)) return
91
+ const stat = statSync(file, { bigint: true, throwIfNoEntry: false })
92
+ if (!stat?.isFile() || stat.size === 0n) return
93
+ digest.update(JSON.stringify([file, String(stat.size), String(stat.mtimeNs)]))
94
+ }
95
+ return digest.digest('hex')
96
+ }
97
+
98
+ export async function withSwiftHeaderCompiler<T>(
99
+ root: string,
100
+ toolchainBin: string,
101
+ recipe: string,
102
+ producers: ReadonlyMap<string, { header: string; publish: () => void }>,
103
+ build: (compiler: Record<string, string>) => Promise<T>,
104
+ ): Promise<T> {
105
+ const wrapper = path.join(root, SWIFT_HEADER_COMPILER_WRAPPER)
106
+ const script = path.join(root, '.build', 'peach-swift-header.cjs')
107
+ const checkpoints = path.join(root, '.build', 'peach-swift-header-checkpoints')
108
+ mkdirSync(checkpoints, { recursive: true })
109
+ const swiftc = argument(path.join(toolchainBin, 'swiftc'))
110
+ writeBuildFile(script, client)
111
+ writeBuildFile(
112
+ wrapper,
113
+ [
114
+ '#!/bin/sh',
115
+ 'module=; compile=; previous=',
116
+ 'for flag in "$@"; do',
117
+ ' if [ "$previous" = -module-name ]; then module=$flag; fi',
118
+ ' if [ "$flag" = -c ]; then compile=1; fi',
119
+ ' previous=$flag',
120
+ 'done',
121
+ 'case "$compile:$module" in',
122
+ ` ${[...producers.keys()].map((name) => argument(`1:${name}`)).join('|')})`,
123
+ ` ${PEACH_FORKED_SCRIPT_ENV}=1 exec ${argument(process.execPath)} ${argument(script)} "$PEACH_SWIFT_HEADER_SOCKET" "$module" ${swiftc} ${argument(checkpoints)}/"$module" "$@" ;;`,
124
+ 'esac',
125
+ `exec ${swiftc} "$@"`,
126
+ '',
127
+ ].join('\n'),
128
+ )
129
+ chmodSync(wrapper, 0o755)
130
+
131
+ // unix socket paths are shorter than a typical build root on macos.
132
+ const directory = mkdtempSync('/tmp/peach-headers-')
133
+ const socket = path.join(directory, 'compile')
134
+ const server = createServer(async (request, response) => {
135
+ const module = request.url?.slice(1) ?? ''
136
+ const producer = producers.get(module)
137
+ if (!producer) {
138
+ response.writeHead(404).end('unknown Swift header producer')
139
+ return
140
+ }
141
+ try {
142
+ const chunks: Buffer[] = []
143
+ for await (const chunk of request) chunks.push(chunk)
144
+ const args: unknown = JSON.parse(Buffer.concat(chunks).toString())
145
+ if (!Array.isArray(args) || !args.every((arg: unknown) => typeof arg === 'string'))
146
+ throw new Error('invalid Swift compiler arguments')
147
+ const receipt = path.join(checkpoints, module)
148
+ const fingerprint = compilerCheckpoint(root, recipe, args, producer.header)
149
+ if (request.method === 'PUT') {
150
+ if (
151
+ !fingerprint ||
152
+ !existsSync(receipt) ||
153
+ readFileSync(receipt, 'utf8') !== fingerprint
154
+ ) {
155
+ response.writeHead(204).end()
156
+ return
157
+ }
158
+ producer.publish()
159
+ response.end()
160
+ return
161
+ }
162
+ if (request.method !== 'POST')
163
+ throw new Error('invalid Swift compiler checkpoint method')
164
+ producer.publish()
165
+ if (fingerprint) {
166
+ writeFileSync(`${receipt}.partial`, fingerprint)
167
+ renameSync(`${receipt}.partial`, receipt)
168
+ }
169
+ response.end()
170
+ } catch (error) {
171
+ response.writeHead(500).end(String(error))
172
+ }
173
+ })
174
+ try {
175
+ await new Promise<void>((resolve, reject) => {
176
+ server.once('error', reject)
177
+ server.listen(socket, resolve)
178
+ })
179
+ return await build({ SWIFT_EXEC: wrapper, PEACH_SWIFT_HEADER_SOCKET: socket })
180
+ } finally {
181
+ server.close()
182
+ server.closeAllConnections()
183
+ rmSync(directory, { recursive: true, force: true })
184
+ }
185
+ }
@@ -0,0 +1,174 @@
1
+ import path from 'node:path'
2
+ import { moduleMapTokens, type SwiftPackageTarget } from './swift-package'
3
+ import {
4
+ SWIFT_NATIVE_INPUT_ROOT,
5
+ type SwiftHeaderAliases,
6
+ type SwiftNativeTarget,
7
+ } from './swiftContract'
8
+
9
+ export function* nativeHeaderIncludes(source: string): Iterable<string> {
10
+ for (const match of source
11
+ .replace(/\/\*[\s\S]*?\*\//g, '')
12
+ .matchAll(/^\s*#\s*(?:include|import)\s*[<"]([^>"]+)[>"]/gm))
13
+ yield match[1]!
14
+ }
15
+
16
+ export function swiftHeaderDependencies(
17
+ root: string,
18
+ files: ReadonlyMap<string, string | Buffer>,
19
+ targets: readonly SwiftPackageTarget[],
20
+ nativeTargets: readonly SwiftNativeTarget[],
21
+ producers: ReadonlySet<string>,
22
+ aliases: SwiftHeaderAliases,
23
+ ): Map<string, Set<string>> {
24
+ const headers = new Map<string, Set<string>>()
25
+ for (const file of files.keys())
26
+ if (/\.(?:h|hh|hpp|hxx|inc|inl|ipp|def|modulemap)$/.test(file))
27
+ headers.set(file, new Set())
28
+ const byDirectory = new Map<string, Set<string>>()
29
+ for (const target of targets) {
30
+ const directory = path.resolve(root, target.path)
31
+ const owners = byDirectory.get(directory) ?? new Set()
32
+ owners.add(target.name)
33
+ byDirectory.set(directory, owners)
34
+ }
35
+ const settings = new Map(nativeTargets.map((native) => [native.name, native]))
36
+ const physicalHeaders = new Map(
37
+ Object.entries(aliases).map(([alias, file]) => [
38
+ path.resolve(root, alias),
39
+ path.resolve(root, file),
40
+ ]),
41
+ )
42
+ const lookup = new Map(
43
+ targets.map((target) => {
44
+ const native = settings.get(target.name)
45
+ const directory = path.resolve(root, target.path)
46
+ const inputPrefix = `${SWIFT_NATIVE_INPUT_ROOT}/`
47
+ const flags = native?.importerFlags ?? []
48
+ const search = [
49
+ path.resolve(directory, target.publicHeadersPath ?? 'include'),
50
+ ...(native?.userHeaderSearchPaths ?? []).map((file) => path.resolve(root, file)),
51
+ ...(native?.headerSearchPaths ?? []).map((file) => path.resolve(root, file)),
52
+ ...(target.clangSettings ?? []).flatMap((setting) =>
53
+ 'headerSearchPath' in setting
54
+ ? [path.resolve(directory, setting.headerSearchPath)]
55
+ : [],
56
+ ),
57
+ ...flags.flatMap((flag, index) =>
58
+ (flags[index - 1] === '-I' || flags[index - 1] === '-iquote') &&
59
+ flag.startsWith(inputPrefix)
60
+ ? [path.resolve(root, flag.slice(inputPrefix.length))]
61
+ : [],
62
+ ),
63
+ ]
64
+ const mapped = new Map<string, string[]>()
65
+ const map = (include: string, file: string) => {
66
+ const key = include.toLowerCase()
67
+ const files = mapped.get(key) ?? []
68
+ files.push(path.resolve(root, file))
69
+ mapped.set(key, files)
70
+ }
71
+ for (const headerMap of native?.headerMaps ?? []) {
72
+ for (const [alias, file] of headerMap.entries) {
73
+ if (file.startsWith(inputPrefix)) map(alias, file.slice(inputPrefix.length))
74
+ else {
75
+ const product = native?.productHeaders[file]
76
+ if (product) map(alias, product)
77
+ }
78
+ }
79
+ }
80
+ for (const [alias, file] of Object.entries(native?.productHeaders ?? {}))
81
+ map(alias, file)
82
+ if (native?.flattensPublicHeaders)
83
+ for (const file of native.publicHeaders)
84
+ map(`${target.name}/${path.basename(file)}`, file)
85
+ return [target.name, { search, mapped }] as const
86
+ }),
87
+ )
88
+ const headersByTarget = new Map<string, Set<string>>()
89
+ const ownersOf = (file: string): ReadonlySet<string> => {
90
+ for (let directory = path.dirname(file); ; directory = path.dirname(directory)) {
91
+ const owners = byDirectory.get(directory)
92
+ if (owners) return owners
93
+ if (directory === root || !directory.startsWith(root + path.sep)) break
94
+ }
95
+ return new Set()
96
+ }
97
+ const includers = new Map<string, Set<string>>()
98
+ const enqueue: string[] = []
99
+ for (const [file, edges] of headers) {
100
+ const source = files.get(file)!.toString()
101
+ const owners = ownersOf(file)
102
+ for (const owner of owners) {
103
+ const files = headersByTarget.get(owner) ?? new Set()
104
+ files.add(file)
105
+ headersByTarget.set(owner, files)
106
+ }
107
+ const moduleMap = file.endsWith('.modulemap')
108
+ const tokens = moduleMap ? moduleMapTokens(source) : []
109
+ const includes = moduleMap
110
+ ? tokens.flatMap((token, index) =>
111
+ tokens[index - 1] === 'header' &&
112
+ tokens[index - 2] !== 'exclude' &&
113
+ token.startsWith('"')
114
+ ? [token.slice(1, -1)]
115
+ : [],
116
+ )
117
+ : nativeHeaderIncludes(source)
118
+ for (const include of includes) {
119
+ const producer = /(?:^|\/)([^/]+)-Swift\.h$/.exec(include)?.[1]
120
+ if (producer && producers.has(producer)) edges.add(producer)
121
+ const local = path.resolve(path.dirname(file), include)
122
+ const frameworkHeader =
123
+ moduleMap && /\.framework\/Modules\//.test(file)
124
+ ? ['../Headers', '../PrivateHeaders'].map((directory) =>
125
+ path.resolve(path.dirname(file), directory, include),
126
+ )
127
+ : []
128
+ const searchPaths = [...owners].flatMap((owner) => {
129
+ const { search, mapped } = lookup.get(owner)!
130
+ return [
131
+ ...search.map((directory) => path.resolve(directory, include)),
132
+ ...(mapped.get(include.toLowerCase()) ?? []),
133
+ ]
134
+ })
135
+ for (const qualified of [local, ...frameworkHeader, ...searchPaths]) {
136
+ const candidate = physicalHeaders.get(qualified) ?? qualified
137
+ if (!headers.has(candidate)) continue
138
+ const parents = includers.get(candidate) ?? new Set()
139
+ parents.add(file)
140
+ includers.set(candidate, parents)
141
+ }
142
+ }
143
+ if (edges.size) enqueue.push(file)
144
+ }
145
+ for (let index = 0; index < enqueue.length; index++) {
146
+ const file = enqueue[index]!
147
+ for (const parent of includers.get(file) ?? []) {
148
+ const edges = headers.get(parent)!
149
+ const before = edges.size
150
+ for (const producer of headers.get(file)!) edges.add(producer)
151
+ if (edges.size > before) enqueue.push(parent)
152
+ }
153
+ }
154
+ return new Map(
155
+ targets.map((target) => {
156
+ const native = settings.get(target.name)
157
+ const publicHeaders = [
158
+ ...(native?.headers ?? []),
159
+ ...(native?.publicHeaders ?? []),
160
+ ...Object.values(native?.productHeaders ?? {}),
161
+ ...(native?.bridgingHeader ? [native.bridgingHeader] : []),
162
+ ...(native?.prefixHeader ? [native.prefixHeader] : []),
163
+ ].map((file) => path.resolve(root, file))
164
+ return [
165
+ target.name,
166
+ new Set(
167
+ [...(headersByTarget.get(target.name) ?? []), ...publicHeaders]
168
+ .flatMap((file) => [...(headers.get(file) ?? [])])
169
+ .filter((producer) => producer !== target.name),
170
+ ),
171
+ ]
172
+ }),
173
+ )
174
+ }
package/src/swift-host.ts CHANGED
@@ -886,15 +886,22 @@ async function buildXcodeLayout(root: string): Promise<XcodeLayout | null> {
886
886
  )
887
887
  const sourceFrameworks = new Map(
888
888
  packages.sourceFrameworks.map(
889
- ({ packageTarget, project, target, configuration, machOType }) => {
889
+ ({
890
+ packageTarget,
891
+ project,
892
+ target,
893
+ module,
894
+ configuration,
895
+ machOType,
896
+ settings,
897
+ }) => {
890
898
  const framework = readXcodeAppTarget(project, target, configuration, {
891
899
  prepareGeneratedSources: true,
892
900
  frameworkMachOType: machOType,
901
+ frameworkBuildSettings: settings,
893
902
  })
894
- if (framework.moduleName !== target || framework.allSources.length === 0)
895
- throw new Error(
896
- `${project}: ${target} did not produce its declared source module`,
897
- )
903
+ if (framework.moduleName !== module || framework.allSources.length === 0)
904
+ throw new Error(`${project}: ${target} did not produce source module ${module}`)
898
905
  if (
899
906
  framework.linkedProducts.length > 0 ||
900
907
  framework.binaryFrameworks.some(({ path }) => path)
@@ -907,10 +914,28 @@ async function buildXcodeLayout(root: string): Promise<XcodeLayout | null> {
907
914
  ),
908
915
  )
909
916
  const frameworkTargets = [...sourceFrameworks.values()]
917
+ const packageFrameworkSearchPaths = frameworkTargets.flatMap(
918
+ ({ objc }) => objc?.frameworkSearchPaths.slice(0, 1) ?? [],
919
+ )
920
+ const withPackageFrameworks = <T extends XcodeModuleTarget>(target: T): T =>
921
+ target.objc && packageFrameworkSearchPaths.length > 0
922
+ ? {
923
+ ...target,
924
+ objc: {
925
+ ...target.objc,
926
+ frameworkSearchPaths: [
927
+ ...new Set([
928
+ ...target.objc.frameworkSearchPaths,
929
+ ...packageFrameworkSearchPaths,
930
+ ]),
931
+ ],
932
+ },
933
+ }
934
+ : target
910
935
  const app = {
911
- ...appTarget,
936
+ ...withPackageFrameworks(appTarget),
912
937
  frameworks: [
913
- ...appTarget.frameworks,
938
+ ...appTarget.frameworks.map(withPackageFrameworks),
914
939
  ...frameworkTargets.flatMap((framework) => [...framework.frameworks, framework]),
915
940
  ],
916
941
  projectFiles: [
@@ -1334,19 +1334,22 @@ async function prepareXcodeNativeInputs(
1334
1334
  [...sources].map(([file, bytes]) => [file, digest(bytes)]),
1335
1335
  )
1336
1336
  // hoisted: the identity keys the resolved intake flags as data, so a flag
1337
- // change rebuilds even when no input file changed. an unparseable minimum
1338
- // records as a marker here; minimumFor still owns the failure below.
1337
+ // change rebuilds even when no input file changed.
1339
1338
  const headers = path.join(sdk.sysroot, 'darwin')
1339
+ const intake = targets.map(({ deploymentTarget }) => {
1340
+ const minimum = iosDeploymentMinimum(deploymentTarget)
1341
+ return minimum === undefined
1342
+ ? undefined
1343
+ : objcSdkIntakeFlags(headers, toolchain.toolchainBin, minimum)
1344
+ })
1340
1345
  const identity = {
1341
1346
  version: 25,
1342
1347
  ...(purpose === 'dependencies' ? { purpose } : {}),
1343
1348
  importer: STANDIN_SOURCE_DIGEST,
1344
- intake: targets.map((target) => {
1345
- const minimum = iosDeploymentMinimum(target.deploymentTarget)
1346
- return minimum === undefined
1347
- ? [`invalid-minimum:${target.deploymentTarget}`]
1348
- : objcSdkIntakeFlags(headers, toolchain.toolchainBin, minimum)
1349
- }),
1349
+ intake: targets.map(
1350
+ ({ deploymentTarget }, index) =>
1351
+ intake[index] ?? [`invalid-minimum:${deploymentTarget}`],
1352
+ ),
1350
1353
  release: toolchain.release,
1351
1354
  compiler: digest(fs.readFileSync(path.join(toolchain.toolchainBin, 'clang'))),
1352
1355
  sdk: swiftModuleSdk(moduleRoot),
@@ -1552,25 +1555,17 @@ async function prepareXcodeNativeInputs(
1552
1555
  throw new SwiftObjCCompilationError(message, receipt)
1553
1556
  }
1554
1557
  save('compiling')
1555
- const minimumFor = (target: {
1556
- name: string
1557
- deploymentTarget: string | null
1558
- }): number => {
1559
- const minimum = iosDeploymentMinimum(target.deploymentTarget)
1560
- if (minimum === undefined) {
1561
- return finish(
1562
- 'unsupported-deployment-target',
1563
- `${target.name}: Objective-C compilation requires an explicit numeric IPHONEOS_DEPLOYMENT_TARGET; received ${JSON.stringify(target.deploymentTarget)}. Inputs: ${receipt}`,
1564
- )
1565
- }
1566
- return minimum
1567
- }
1568
1558
  if (targets.length === 0)
1569
1559
  return finish(
1570
1560
  'missing-target',
1571
1561
  'Objective-C preparation requires an original implementation target',
1572
1562
  )
1573
- const minimums = targets.map(minimumFor)
1563
+ for (const [index, target] of targets.entries())
1564
+ if (!intake[index])
1565
+ finish(
1566
+ 'unsupported-deployment-target',
1567
+ `${target.name}: Objective-C compilation requires an explicit numeric IPHONEOS_DEPLOYMENT_TARGET; received ${JSON.stringify(target.deploymentTarget)}. Inputs: ${receipt}`,
1568
+ )
1574
1569
  // units compile concurrently under the swift build job cap; the receipt
1575
1570
  // and failure report keep source order.
1576
1571
  const units = targets.flatMap((target, index) =>
@@ -1588,7 +1583,6 @@ async function prepareXcodeNativeInputs(
1588
1583
  swiftBuildJobs(),
1589
1584
  async ({ target, index, unit, file }, position) => {
1590
1585
  if (interrupted) return
1591
- const minimum = minimums[index]!
1592
1586
  const output = path.join(work, `${index}-${unit}.o`)
1593
1587
  const log = path.join(work, `${index}-${unit}.log`)
1594
1588
  const cxx = /\.(mm|cc|cpp|cxx)$/.test(file)
@@ -1637,7 +1631,7 @@ async function prepareXcodeNativeInputs(
1637
1631
  '-mllvm',
1638
1632
  '-wasm-enable-sjlj',
1639
1633
  ...(objc ? [...swiftObjCRuntimeFlags, '-fobjc-exceptions'] : []),
1640
- ...objcSdkIntakeFlags(headers, toolchain.toolchainBin, minimum),
1634
+ ...intake[index]!,
1641
1635
  ...headerSearch.flags[index]!,
1642
1636
  ...target.includes.flatMap((include) => ['-I', staged(include)]),
1643
1637
  ...target.frameworks.flatMap((framework) => ['-F', staged(framework)]),
@@ -102,8 +102,10 @@ export interface SwiftPackages {
102
102
  packageTarget: string
103
103
  project: string
104
104
  target: string
105
+ module: string
105
106
  configuration: string
106
107
  machOType: 'staticlib' | 'mh_dylib'
108
+ settings?: Readonly<Record<string, string>>
107
109
  }[]
108
110
  /** linked products peach cannot compile. */
109
111
  unavailable: Map<string, SwiftPackageGap>
@@ -175,18 +177,43 @@ export const SWIFT_PLACEHOLDER_PACKAGES: ReadonlyMap<string, string> = new Map<
175
177
  const placeholderPackage = (pkg: LoadedPackage) =>
176
178
  SWIFT_PLACEHOLDER_PACKAGES.get(swiftPackageIdentity(pkg.manifest.dir))
177
179
 
178
- // sentry's release script builds the static archive with this xcode target.
179
- const sourceFrameworkRecipes = new Map([
180
+ // each archive is bound to the source revision and xcode target used by its release.
181
+ const sourceFrameworkRecipes = new Map<
182
+ string,
183
+ Omit<SwiftPackages['sourceFrameworks'][number], 'packageTarget'> & { revision: string }
184
+ >([
180
185
  [
181
186
  '438de2c5afb7dde20b640af35dd841961aa2aa4d2719e40c92d48bd2aa5dca56',
182
187
  {
183
188
  revision: 'a49e7c2148ac9e38bd35ef4f13bc9d6ea3ff0b81',
184
189
  project: 'Sentry.xcodeproj',
185
190
  target: 'Sentry',
191
+ module: 'Sentry',
186
192
  configuration: 'Release',
187
193
  machOType: 'staticlib',
188
- } satisfies Omit<SwiftPackages['sourceFrameworks'][number], 'packageTarget'> & {
189
- revision: string
194
+ },
195
+ ],
196
+ [
197
+ '780558374b95d370e8b604097f9ccb2cac328fdd18c4b8542a58ece83d2548d2',
198
+ {
199
+ revision: '5421f94cc859eb65f5ae3866165a053aa634431e',
200
+ project: 'Sentry.xcodeproj',
201
+ target: 'Sentry',
202
+ module: 'Sentry',
203
+ configuration: 'Release',
204
+ machOType: 'staticlib',
205
+ settings: { CARTHAGE: 'YES' },
206
+ },
207
+ ],
208
+ [
209
+ '159842b63ab14ed1615fcace752c57b2633b3d3be6fadd4f643a1c8323b70e48',
210
+ {
211
+ revision: '5561a15a4836efe5d068a366b60599b7b794af70',
212
+ project: 'Simperium.xcodeproj',
213
+ target: 'Simperium_iOS',
214
+ module: 'Simperium',
215
+ configuration: 'Release',
216
+ machOType: 'mh_dylib',
190
217
  },
191
218
  ],
192
219
  ])
@@ -870,13 +897,15 @@ export function resolveSwiftPackages(options: {
870
897
  const recipe = target.checksum
871
898
  ? sourceFrameworkRecipes.get(target.checksum)
872
899
  : undefined
873
- if (recipe && pkg.revision === recipe.revision && name === recipe.target) {
900
+ if (recipe && pkg.revision === recipe.revision && name === recipe.module) {
874
901
  sourceFrameworks.set(key, {
875
902
  packageTarget: path.join(pkg.manifest.dir, '#target', name),
876
903
  project: path.join(pkg.manifest.dir, recipe.project),
877
- target: name,
904
+ target: recipe.target,
905
+ module: recipe.module,
878
906
  configuration: recipe.configuration,
879
907
  machOType: recipe.machOType,
908
+ settings: recipe.settings,
880
909
  })
881
910
  providedTargets.delete(name)
882
911
  return true
@@ -261,6 +261,7 @@ export function swiftSharedSdkViewOptions(
261
261
  .filter((entry) => entry.isFile())
262
262
  .map((entry) => path.join(entry.parentPath, entry.name))
263
263
  .sort()
264
+ const hasDarwinTcp = overlayFiles.includes(path.join(overlay, 'netinet/tcp.h'))
264
265
  const key = JSON.stringify([
265
266
  // bump the recipe when the transformation changes; bundling changes function text.
266
267
  'v25',
@@ -270,6 +271,7 @@ export function swiftSharedSdkViewOptions(
270
271
  frameworks,
271
272
  overlayFiles,
272
273
  swiftSdkOptions(),
274
+ ...(hasDarwinTcp ? ['darwin-tcp-module'] : []),
273
275
  ])
274
276
  const cached = sdkViews.get(key)
275
277
  if (cached && fs.existsSync(cached.manifest)) return touchSdkView(cached.options)
@@ -390,6 +392,23 @@ export function swiftSharedSdkViewOptions(
390
392
  fs.mkdirSync(path.dirname(destination), { recursive: true })
391
393
  fs.symlinkSync(shared, destination)
392
394
  }
395
+ if (hasDarwinTcp) {
396
+ // older sdk maps load musl's incompatible tcphdr into SwiftWASILibc.
397
+ const moduleMap = path.join(
398
+ staging,
399
+ path.relative(realRoot, sysroot),
400
+ 'darwin/wasm/include/module.modulemap',
401
+ )
402
+ const original = fs.readFileSync(moduleMap, 'utf8')
403
+ const updated = original.replace(
404
+ '"../../../include/wasm64-wasip1/netinet/tcp.h"',
405
+ '"netinet/tcp.h"',
406
+ )
407
+ if (updated !== original) {
408
+ fs.unlinkSync(moduleMap)
409
+ fs.writeFileSync(moduleMap, updated)
410
+ }
411
+ }
393
412
  const foundationArchive = path.join(
394
413
  path.dirname(sysroot),
395
414
  'swift.xctoolchain/usr/lib/swift_static/wasi/libFoundation.a',