peachsim 0.1.1653 → 0.1.1655

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 (111) hide show
  1. package/cli/app-stubs.ts +97 -14
  2. package/cli/bridge-diagnostics.ts +10 -7
  3. package/cli/cloud-client.ts +11 -2
  4. package/cli/commands/doctor.ts +20 -10
  5. package/cli/commands/inspect/core.ts +2 -1
  6. package/cli/commands/inspect/shared.ts +2 -0
  7. package/cli/commands/inspect.ts +11 -2
  8. package/cli/output-redaction.ts +22 -6
  9. package/cli/pause-aware-timeout.ts +24 -10
  10. package/cli/ws-bridge.ts +17 -1
  11. package/dist-lib/agent-daemon-client.cjs +1 -1
  12. package/dist-lib/agent-events.cjs +1 -1
  13. package/dist-lib/attached-projects.cjs +1 -1
  14. package/dist-lib/auth/shared-session.cjs +1 -1
  15. package/dist-lib/backend-origin.cjs +1 -1
  16. package/dist-lib/beta.cjs +1 -1
  17. package/dist-lib/beta.mjs +1 -1
  18. package/dist-lib/bridge-constants.cjs +1 -1
  19. package/dist-lib/bridge-contract-input.cjs +1 -1
  20. package/dist-lib/bridge-contract-input.mjs +1 -1
  21. package/dist-lib/bridge-contract.cjs +1 -1
  22. package/dist-lib/bridge-contract.mjs +1 -1
  23. package/dist-lib/bundle-channel.cjs +277 -244
  24. package/dist-lib/capture-contract.cjs +1 -1
  25. package/dist-lib/capture-contract.mjs +1 -1
  26. package/dist-lib/cloud-contract.cjs +1 -1
  27. package/dist-lib/cloud-contract.mjs +1 -1
  28. package/dist-lib/cloud-test-args.cjs +1 -1
  29. package/dist-lib/cloud-test-args.mjs +1 -1
  30. package/dist-lib/cloud.cjs +1 -1
  31. package/dist-lib/cloud.mjs +1 -1
  32. package/dist-lib/config.cjs +1 -1
  33. package/dist-lib/config.mjs +1 -1
  34. package/dist-lib/detox/index.cjs +47 -12
  35. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  36. package/dist-lib/expo-swift-bundle.cjs +276 -243
  37. package/dist-lib/expo-swift-metadata.cjs +1 -1
  38. package/dist-lib/expo-swift-metadata.mjs +1 -1
  39. package/dist-lib/home-paths.cjs +1 -1
  40. package/dist-lib/host/bridge-host.cjs +320 -246
  41. package/dist-lib/host/fetch-proxy-handler.cjs +191 -31
  42. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  43. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  44. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  45. package/dist-lib/host/websocket-proxy.cjs +1 -1
  46. package/dist-lib/index.cjs +633 -373
  47. package/dist-lib/jump-to-source-babel.cjs +1 -1
  48. package/dist-lib/jump-to-source-native.cjs +1 -1
  49. package/dist-lib/kotlin-host.cjs +1 -1
  50. package/dist-lib/menu.cjs +1 -1
  51. package/dist-lib/menu.mjs +1 -1
  52. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  53. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  54. package/dist-lib/metro-production-bundle.cjs +1 -1
  55. package/dist-lib/metro-production-bundle.mjs +1 -1
  56. package/dist-lib/metro.cjs +62 -14
  57. package/dist-lib/native-app-identity-project.cjs +1 -1
  58. package/dist-lib/native-app-identity-project.mjs +1 -1
  59. package/dist-lib/native-app-identity.cjs +1 -1
  60. package/dist-lib/native-app-identity.mjs +1 -1
  61. package/dist-lib/native-firebase-metadata.cjs +1 -1
  62. package/dist-lib/native-firebase-metadata.mjs +1 -1
  63. package/dist-lib/plist.cjs +1 -1
  64. package/dist-lib/plist.mjs +1 -1
  65. package/dist-lib/profiles.cjs +1 -1
  66. package/dist-lib/public-brand.cjs +1 -1
  67. package/dist-lib/public-origins-lib-esm.json +23 -23
  68. package/dist-lib/public-origins-lib.json +62 -54
  69. package/dist-lib/react-native-host-modules.cjs +1 -1
  70. package/dist-lib/react-native-host-modules.mjs +1 -1
  71. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  72. package/dist-lib/sdk.cjs +2 -2
  73. package/dist-lib/sdk.mjs +2 -2
  74. package/dist-lib/skills.cjs +535 -380
  75. package/dist-lib/swift-compile.cjs +258 -197
  76. package/dist-lib/swift-compile.mjs +257 -197
  77. package/dist-lib/swift-package.cjs +1 -1
  78. package/dist-lib/swift-package.mjs +1 -1
  79. package/dist-lib/swift-submit.cjs +1 -1
  80. package/dist-lib/swift-submit.mjs +1 -1
  81. package/dist-lib/swift-toolchain.cjs +1 -1
  82. package/dist-lib/swift.cjs +1 -1
  83. package/dist-lib/vite-swift.cjs +276 -243
  84. package/dist-lib/vite.cjs +385 -200
  85. package/dist-lib/worklet-executable.cjs +1 -1
  86. package/dist-lib/worklet-executable.mjs +1 -1
  87. package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-gesture-handler.d.ts +1 -0
  88. package/dist-types/packages/peach-compat/src/stubs/screen-transition-math.d.ts +10 -7
  89. package/dist-types/packages/peach-engine/src/capture/browser-composite.d.ts +10 -0
  90. package/dist-types/packages/peach-engine/src/cli-companion.d.ts +1 -0
  91. package/dist-types/packages/peach-engine/src/engine/node.d.ts +3 -1
  92. package/dist-types/packages/peach-engine/src/engine/scene-table.d.ts +1 -1
  93. package/dist-types/packages/peach-engine/src/engine/text-first-baseline.d.ts +23 -0
  94. package/dist-types/packages/peach-engine/src/engine/types.d.ts +1 -1
  95. package/dist-types/packages/peach-engine/src/engine/visible-frame.d.ts +1 -0
  96. package/dist-types/packages/peach-engine/src/observability/types.d.ts +1 -0
  97. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +38 -0
  98. package/dist-types/packages/peach-engine/src/rolldown-bundle-inventory.d.ts +9 -0
  99. package/package.json +5 -1
  100. package/runtime-companion.json +1 -1
  101. package/src/bridge-contract.ts +2 -0
  102. package/src/bundleGlobalFooter.ts +9 -0
  103. package/src/host/fetch-proxy-handler.ts +54 -0
  104. package/src/sfSymbolMetricsContract.ts +268 -0
  105. package/src/swift-compile.ts +302 -238
  106. package/src/swift-distribution.lock.json +20 -46
  107. package/src/swift-objc-metadata.ts +21 -7
  108. package/src/swift-objc-sdk.ts +13 -0
  109. package/src/swiftContract.ts +2 -0
  110. package/src/vite-plugin-one.ts +161 -16
  111. package/src/host/lease-owner.test.ts +0 -49
@@ -208,6 +208,18 @@ export interface SwiftCompileInput {
208
208
  libraries?: Record<string, string>
209
209
  }
210
210
 
211
+ // the builder hop wraps the compiler's own timeout with admission, transfer and
212
+ // artifact return. both dispatch layers take their deadline from here so the
213
+ // client never kills the hop before the compiler has its full timeout.
214
+ const SWIFT_BUILDER_TRANSPORT_MARGIN_MS = 300_000
215
+ const SWIFT_BUILDER_DEFAULT_COMPILE_MS = 1_800_000
216
+ export function swiftBuilderHopTimeoutMs(compileTimeoutMs: number | undefined): number {
217
+ return (
218
+ (compileTimeoutMs ?? SWIFT_BUILDER_DEFAULT_COMPILE_MS) +
219
+ SWIFT_BUILDER_TRANSPORT_MARGIN_MS
220
+ )
221
+ }
222
+
211
223
  export interface SwiftCompileOptions {
212
224
  buildRoot: string
213
225
  moduleRoot: string
@@ -5960,6 +5972,7 @@ export function writeSwiftProject(
5960
5972
  : compileTargets(input)
5961
5973
  const files = new Map<string, string | Buffer>()
5962
5974
  const native = new Map<string, SwiftNativeTargetPlan>()
5975
+ const targetFailures: string[] = []
5963
5976
  const bySourcePath = [...targets].sort(
5964
5977
  (left, right) => right.path.length - left.path.length,
5965
5978
  )
@@ -6030,223 +6043,254 @@ export function writeSwiftProject(
6030
6043
  entries.some(([file]) => file.endsWith('.swift')) ||
6031
6044
  (settings && units.some(([file]) => /\.mm?$/.test(file)))
6032
6045
  ) {
6033
- if (!settings)
6034
- throw new Error(
6035
- `mixed target ${target.name} requires its original native target settings; SwiftPM does not compile mixed source targets`,
6046
+ const swift = entries.some(([file]) => file.endsWith('.swift'))
6047
+ try {
6048
+ if (!settings)
6049
+ throw new Error(
6050
+ `mixed target ${target.name} requires its original native target settings; SwiftPM does not compile mixed source targets`,
6051
+ )
6052
+ const headers = settings.headers
6053
+ // swift imports a mixed target's objective-c only through its bridging
6054
+ // header or public headers. with neither, xcode gives swift nothing and
6055
+ // the units still consume the generated <Module>-Swift.h.
6056
+ const roots = settings.bridgingHeader
6057
+ ? [settings.bridgingHeader]
6058
+ : settings.publicHeaders
6059
+ for (const file of headers) {
6060
+ const destination = path.join(layout.root, file)
6061
+ mkdirSync(path.dirname(destination), { recursive: true })
6062
+ writeFileSync(destination, input.files[file]!)
6063
+ }
6064
+ const search = [
6065
+ ...new Set([
6066
+ ...(settings?.headerSearchPaths ?? []),
6067
+ ...headers.map((file) => path.posix.dirname(file)),
6068
+ ]),
6069
+ ].flatMap((dir) => ['-I', path.join(layout.root, dir)])
6070
+ const pin: { release: string } =
6071
+ distribution ??
6072
+ JSON.parse(readFileSync(path.join(moduleRoot, 'toolchain.json'), 'utf8'))
6073
+ const release = pin.release
6074
+ const toolchainBin = swiftToolchain(release, swiftModuleSdk(moduleRoot))
6075
+ const sdkHeaders = materializeObjcSdk(
6076
+ path.join(layout.root, '.build', 'peach-objc-sdk'),
6036
6077
  )
6037
- const headers = settings.headers
6038
- const roots = settings.bridgingHeader
6039
- ? [settings.bridgingHeader]
6040
- : settings.publicHeaders
6041
- if (!roots.length)
6042
- throw new Error(`mixed target ${target.name} has no original declaration headers`)
6043
- for (const file of headers) {
6044
- const destination = path.join(layout.root, file)
6045
- mkdirSync(path.dirname(destination), { recursive: true })
6046
- writeFileSync(destination, input.files[file]!)
6047
- }
6048
- const search = [
6049
- ...new Set([
6050
- ...(settings?.headerSearchPaths ?? []),
6051
- ...headers.map((file) => path.posix.dirname(file)),
6052
- ]),
6053
- ].flatMap((dir) => ['-I', path.join(layout.root, dir)])
6054
- const pin: { release: string } =
6055
- distribution ??
6056
- JSON.parse(readFileSync(path.join(moduleRoot, 'toolchain.json'), 'utf8'))
6057
- const release = pin.release
6058
- const toolchainBin = swiftToolchain(release, swiftModuleSdk(moduleRoot))
6059
- const sdkHeaders = materializeObjcSdk(
6060
- path.join(layout.root, '.build', 'peach-objc-sdk'),
6061
- )
6062
- const stageFlags = (flags: readonly string[], sdkInclude: string) =>
6063
- flags.map((flag) =>
6064
- flag
6065
- .replaceAll(SWIFT_NATIVE_INPUT_ROOT, layout.root)
6066
- .replaceAll(SWIFT_NATIVE_SDK_INCLUDE, sdkInclude),
6078
+ const stageFlags = (flags: readonly string[], sdkInclude: string) =>
6079
+ flags.map((flag) =>
6080
+ flag
6081
+ .replaceAll(SWIFT_NATIVE_INPUT_ROOT, layout.root)
6082
+ .replaceAll(SWIFT_NATIVE_SDK_INCLUDE, sdkInclude),
6083
+ )
6084
+ const originalFlags = [
6085
+ ...(settings?.flags ?? []),
6086
+ ...search,
6087
+ ...(settings?.frameworkSearchPaths ?? []).flatMap((dir) => [
6088
+ '-F',
6089
+ path.join(layout.root, dir),
6090
+ ]),
6091
+ '-I',
6092
+ headerDirectory,
6093
+ ]
6094
+ const flags = stageFlags(
6095
+ originalFlags,
6096
+ path.join(swiftSdkPaths(moduleRoot, toolchainBin).sysroot, 'include'),
6067
6097
  )
6068
- const originalFlags = [
6069
- ...(settings?.flags ?? []),
6070
- ...search,
6071
- ...(settings?.frameworkSearchPaths ?? []).flatMap((dir) => [
6072
- '-F',
6073
- path.join(layout.root, dir),
6074
- ]),
6075
- '-I',
6076
- headerDirectory,
6077
- ]
6078
- const flags = stageFlags(
6079
- originalFlags,
6080
- path.join(swiftSdkPaths(moduleRoot, toolchainBin).sysroot, 'include'),
6081
- )
6082
- const prefixHeader = settings?.prefixHeader
6083
- ? ['-include', path.join(layout.root, settings.prefixHeader)]
6084
- : []
6085
- // swiftpm gives a native resource target's units an accessor header and
6086
- // one more unit defining it. the swift accessor below stays for swift.
6087
- const bundleName = entries.some(([file]) => file.endsWith('.swift'))
6088
- ? undefined
6089
- : swiftObjCResourceBundleName({
6090
- target: target.name,
6091
- path: target.path,
6092
- resources:
6093
- resourceTargets.find((candidate) => candidate.name === target.name)
6094
- ?.resources ?? false,
6095
- usesBundleMacro: entries.some(
6096
- ([file, contents]) =>
6097
- /\.(?:c|cc|cpp|cxx|m|mm|h|hpp|hh|hxx)$/.test(file) &&
6098
- /\bSWIFTPM_MODULE_BUNDLE\b/.test(contents),
6099
- ),
6100
- bundles: input.resourceBundles,
6101
- })
6102
- const accessor =
6103
- bundleName === undefined ? undefined : swiftObjCResourceAccessor(bundleName)
6104
- const accessorHeader = path.join(
6105
- layout.root,
6106
- target.path,
6107
- OBJC_RESOURCE_ACCESSOR_HEADER,
6108
- )
6109
- const accessorUnit = `${prefix}${OBJC_RESOURCE_ACCESSOR_BODY}`
6110
- if (
6111
- accessor &&
6112
- (input.files[accessorUnit] !== undefined ||
6113
- input.files[`${prefix}${OBJC_RESOURCE_ACCESSOR_HEADER}`] !== undefined)
6114
- )
6115
- throw new Error(`target ${target.name} already contains its resource accessor`)
6116
- const nativeUnits: [string, string][] = accessor
6117
- ? [...units, [accessorUnit, accessor.body]]
6118
- : units
6119
- const accessorFlags = accessor ? ['-include', accessorHeader] : []
6120
- if (accessor) {
6121
- files.set(accessorHeader, accessor.header)
6122
- files.set(path.join(layout.root, accessorUnit), accessor.body)
6123
- }
6124
- const sourceHeaders = path.join(
6125
- layout.root,
6126
- '.build',
6127
- 'peach-objc-originals',
6128
- target.name,
6129
- )
6130
- mkdirSync(sourceHeaders, { recursive: true })
6131
- const modulemap = path.join(sourceHeaders, 'module.modulemap')
6132
- writeFileSync(
6133
- modulemap,
6134
- `module ${swiftTargetModuleName(target.name)} {\n${roots.map((file) => `header ${JSON.stringify(path.join(layout.root, file))}`).join('\n')}\nexport *\n}\n`,
6135
- )
6136
- const view = objcView(
6137
- { module: swiftTargetModuleName(target.name), headers: sourceHeaders, modulemap },
6138
- toolchainBin,
6139
- path.join(moduleRoot, 'ios-simulator-stdlib'),
6140
- path.join(layout.root, '.build', 'peach-objc-sdk'),
6141
- path.join(layout.root, '.build', 'peach-objc-imports', target.name),
6142
- {
6143
- flags: stageFlags(originalFlags, path.join(sdkHeaders, 'usr/include')),
6144
- target: `arm64-apple-ios${settings?.deploymentTarget ?? '16.0'}-simulator`,
6145
- },
6146
- )
6147
- const defined = new Set<string>()
6148
- const declarations = (node: unknown): void => {
6149
- if (!node || typeof node !== 'object') return
6150
- const name: unknown = Reflect.get(node, 'name')
6098
+ const prefixHeader = settings?.prefixHeader
6099
+ ? ['-include', path.join(layout.root, settings.prefixHeader)]
6100
+ : []
6101
+ // swiftpm gives a native resource target's units an accessor header and
6102
+ // one more unit defining it. the swift accessor below stays for swift.
6103
+ const bundleName = entries.some(([file]) => file.endsWith('.swift'))
6104
+ ? undefined
6105
+ : swiftObjCResourceBundleName({
6106
+ target: target.name,
6107
+ path: target.path,
6108
+ resources:
6109
+ resourceTargets.find((candidate) => candidate.name === target.name)
6110
+ ?.resources ?? false,
6111
+ usesBundleMacro: entries.some(
6112
+ ([file, contents]) =>
6113
+ /\.(?:c|cc|cpp|cxx|m|mm|h|hpp|hh|hxx)$/.test(file) &&
6114
+ /\bSWIFTPM_MODULE_BUNDLE\b/.test(contents),
6115
+ ),
6116
+ bundles: input.resourceBundles,
6117
+ })
6118
+ const accessor =
6119
+ bundleName === undefined ? undefined : swiftObjCResourceAccessor(bundleName)
6120
+ const accessorHeader = path.join(
6121
+ layout.root,
6122
+ target.path,
6123
+ OBJC_RESOURCE_ACCESSOR_HEADER,
6124
+ )
6125
+ const accessorUnit = `${prefix}${OBJC_RESOURCE_ACCESSOR_BODY}`
6151
6126
  if (
6152
- Reflect.get(node, 'kind') === 'ObjCInterfaceDecl' &&
6153
- Reflect.get(node, 'super') &&
6154
- typeof name === 'string'
6127
+ accessor &&
6128
+ (input.files[accessorUnit] !== undefined ||
6129
+ input.files[`${prefix}${OBJC_RESOURCE_ACCESSOR_HEADER}`] !== undefined)
6155
6130
  )
6156
- defined.add(name)
6157
- const children: unknown = Reflect.get(node, 'inner')
6158
- if (Array.isArray(children)) for (const child of children) declarations(child)
6159
- }
6160
- declarations(view.clangAST)
6161
- const foreignTypes = new Map<string, string>()
6162
- for (const graph of view.graphs)
6163
- for (const symbol of graph.symbols) {
6164
- const nativeName = /^c:objc\(cs\)(\w+)$/.exec(symbol.identifier.precise)?.[1]
6165
- if (nativeName && defined.has(nativeName))
6166
- foreignTypes.set(symbol.pathComponents[0]!, nativeName)
6131
+ throw new Error(`target ${target.name} already contains its resource accessor`)
6132
+ const nativeUnits: [string, string][] = accessor
6133
+ ? [...units, [accessorUnit, accessor.body]]
6134
+ : units
6135
+ const accessorFlags = accessor ? ['-include', accessorHeader] : []
6136
+ if (accessor) {
6137
+ files.set(accessorHeader, accessor.header)
6138
+ files.set(path.join(layout.root, accessorUnit), accessor.body)
6167
6139
  }
6168
- imports.set(target.name, {
6169
- view,
6170
- classes: [...foreignTypes.values()],
6171
- headers: roots.map((file) => path.join(layout.root, file)),
6172
- foreignTypes,
6173
- })
6174
- const thunk = 'PeachObjCImports.generated.m'
6175
- const groups = new Map<
6176
- string,
6177
- { name: string; sources: string[]; flags: string[]; cxxFlags: string[] }
6178
- >()
6179
- for (const [file] of nativeUnits) {
6180
- const origin = settings?.sourceDirectories[file]
6181
- if (origin) mkdirSync(path.join(layout.root, origin), { recursive: true })
6182
- const perFile = [
6183
- ...(origin ? ['-iquote', path.join(layout.root, origin)] : []),
6184
- ...stageFlags(
6185
- settings?.fileFlags[file] ?? [],
6186
- path.join(swiftSdkPaths(moduleRoot, toolchainBin).sysroot, 'include'),
6187
- ),
6188
- ]
6189
- const cxx = /\.(?:cc|cpp|cxx|mm)$/.test(file)
6190
- const identity = createHash('sha256')
6191
- .update(JSON.stringify([cxx, perFile]))
6192
- .digest('hex')
6193
- .slice(0, 12)
6194
- const group = groups.get(identity) ?? {
6195
- name: `${target.name}SwiftImplementation_${identity}`,
6196
- sources: [],
6197
- flags: [...flags, ...prefixHeader, ...accessorFlags, ...perFile],
6198
- cxxFlags: [
6199
- ...flags,
6200
- ...prefixHeader,
6201
- ...accessorFlags,
6140
+ if (roots.length) {
6141
+ const sourceHeaders = path.join(
6142
+ layout.root,
6143
+ '.build',
6144
+ 'peach-objc-originals',
6145
+ target.name,
6146
+ )
6147
+ mkdirSync(sourceHeaders, { recursive: true })
6148
+ const modulemap = path.join(sourceHeaders, 'module.modulemap')
6149
+ writeFileSync(
6150
+ modulemap,
6151
+ `module ${swiftTargetModuleName(target.name)} {\n${roots.map((file) => `header ${JSON.stringify(path.join(layout.root, file))}`).join('\n')}\nexport *\n}\n`,
6152
+ )
6153
+ const view = objcView(
6154
+ {
6155
+ module: swiftTargetModuleName(target.name),
6156
+ headers: sourceHeaders,
6157
+ modulemap,
6158
+ },
6159
+ toolchainBin,
6160
+ path.join(moduleRoot, 'ios-simulator-stdlib'),
6161
+ path.join(layout.root, '.build', 'peach-objc-sdk'),
6162
+ path.join(layout.root, '.build', 'peach-objc-imports', target.name),
6163
+ {
6164
+ flags: stageFlags(originalFlags, path.join(sdkHeaders, 'usr/include')),
6165
+ target: `arm64-apple-ios${settings?.deploymentTarget ?? '16.0'}-simulator`,
6166
+ },
6167
+ )
6168
+ const defined = new Set<string>()
6169
+ const declarations = (node: unknown): void => {
6170
+ if (!node || typeof node !== 'object') return
6171
+ const name: unknown = Reflect.get(node, 'name')
6172
+ if (
6173
+ Reflect.get(node, 'kind') === 'ObjCInterfaceDecl' &&
6174
+ Reflect.get(node, 'super') &&
6175
+ typeof name === 'string'
6176
+ )
6177
+ defined.add(name)
6178
+ const children: unknown = Reflect.get(node, 'inner')
6179
+ if (Array.isArray(children)) for (const child of children) declarations(child)
6180
+ }
6181
+ declarations(view.clangAST)
6182
+ const foreignTypes = new Map<string, string>()
6183
+ for (const graph of view.graphs)
6184
+ for (const symbol of graph.symbols) {
6185
+ const nativeName = /^c:objc\(cs\)(\w+)$/.exec(
6186
+ symbol.identifier.precise,
6187
+ )?.[1]
6188
+ if (nativeName && defined.has(nativeName))
6189
+ foreignTypes.set(symbol.pathComponents[0]!, nativeName)
6190
+ }
6191
+ imports.set(target.name, {
6192
+ view,
6193
+ classes: [...foreignTypes.values()],
6194
+ headers: roots.map((file) => path.join(layout.root, file)),
6195
+ foreignTypes,
6196
+ })
6197
+ }
6198
+ const thunks = roots.length ? ['PeachObjCImports.generated.m'] : []
6199
+ const groups = new Map<
6200
+ string,
6201
+ { name: string; sources: string[]; flags: string[]; cxxFlags: string[] }
6202
+ >()
6203
+ for (const [file] of nativeUnits) {
6204
+ const origin = settings?.sourceDirectories[file]
6205
+ if (origin) mkdirSync(path.join(layout.root, origin), { recursive: true })
6206
+ const perFile = [
6207
+ ...(origin ? ['-iquote', path.join(layout.root, origin)] : []),
6202
6208
  ...stageFlags(
6203
- cxx ? settings.cxxFlags : [],
6209
+ settings?.fileFlags[file] ?? [],
6204
6210
  path.join(swiftSdkPaths(moduleRoot, toolchainBin).sysroot, 'include'),
6205
6211
  ),
6206
- ...perFile,
6207
- ],
6212
+ ]
6213
+ const cxx = /\.(?:cc|cpp|cxx|mm)$/.test(file)
6214
+ const identity = createHash('sha256')
6215
+ .update(JSON.stringify([cxx, perFile]))
6216
+ .digest('hex')
6217
+ .slice(0, 12)
6218
+ const group = groups.get(identity) ?? {
6219
+ name: `${target.name}SwiftImplementation_${identity}`,
6220
+ sources: [],
6221
+ flags: [...flags, ...prefixHeader, ...accessorFlags, ...perFile],
6222
+ cxxFlags: [
6223
+ ...flags,
6224
+ ...prefixHeader,
6225
+ ...accessorFlags,
6226
+ ...stageFlags(
6227
+ cxx ? settings.cxxFlags : [],
6228
+ path.join(swiftSdkPaths(moduleRoot, toolchainBin).sysroot, 'include'),
6229
+ ),
6230
+ ...perFile,
6231
+ ],
6232
+ }
6233
+ group.sources.push(file.slice(prefix.length))
6234
+ groups.set(identity, group)
6208
6235
  }
6209
- group.sources.push(file.slice(prefix.length))
6210
- groups.set(identity, group)
6211
- }
6212
- groups.set('imports', {
6213
- name: `${target.name}ObjCImports`,
6214
- sources: [thunk],
6215
- flags: [...flags, '-fobjc-arc'],
6216
- cxxFlags: [...flags, '-fobjc-arc'],
6217
- })
6218
- const include = path.join(layout.root, target.path, 'include')
6219
- files.set(
6220
- path.join(include, 'module.modulemap'),
6221
- `module ${target.name}ImplementationDeclarations { export * }\n`,
6222
- )
6223
- native.set(target.name, {
6224
- mixed: true,
6225
- path: target.path,
6226
- includeDirectory: include,
6227
- sources: nativeUnits.map(([file]) => file.slice(prefix.length)),
6228
- lateSources: [...nativeUnits.map(([file]) => file.slice(prefix.length)), thunk],
6229
- exclude: [
6230
- ...entries
6236
+ if (thunks.length)
6237
+ groups.set('imports', {
6238
+ name: `${target.name}ObjCImports`,
6239
+ sources: thunks,
6240
+ flags: [...flags, '-fobjc-arc'],
6241
+ cxxFlags: [...flags, '-fobjc-arc'],
6242
+ })
6243
+ const include = path.join(layout.root, target.path, 'include')
6244
+ files.set(
6245
+ path.join(include, 'module.modulemap'),
6246
+ `module ${target.name}ImplementationDeclarations { export * }\n`,
6247
+ )
6248
+ native.set(target.name, {
6249
+ mixed: true,
6250
+ path: target.path,
6251
+ includeDirectory: include,
6252
+ sources: nativeUnits.map(([file]) => file.slice(prefix.length)),
6253
+ lateSources: [
6254
+ ...nativeUnits.map(([file]) => file.slice(prefix.length)),
6255
+ ...thunks,
6256
+ ],
6257
+ exclude: [
6258
+ ...entries
6259
+ .filter(([file]) => !file.endsWith('.swift') && !file.endsWith('.metal'))
6260
+ .map(([file]) => file.slice(prefix.length)),
6261
+ ...(accessor
6262
+ ? [OBJC_RESOURCE_ACCESSOR_HEADER, OBJC_RESOURCE_ACCESSOR_BODY]
6263
+ : []),
6264
+ ...thunks,
6265
+ 'include',
6266
+ ],
6267
+ groups: [...groups.values()],
6268
+ late: {
6269
+ name: `${target.name}SwiftImplementation`,
6270
+ producers: [
6271
+ target.name,
6272
+ ...(target.dependencies ?? [])
6273
+ .filter((dependency) => swiftTargets.has(dependency.name))
6274
+ .map((dependency) => dependency.name),
6275
+ ],
6276
+ },
6277
+ })
6278
+ } catch (error) {
6279
+ // a mixed target that fails here still compiles its swift, and its
6280
+ // failure joins the build's diagnostic, so one target hides no other.
6281
+ if (!swift || !(error instanceof Error)) throw error
6282
+ targetFailures.push(`${target.name}: ${error.message}`)
6283
+ native.set(target.name, {
6284
+ mixed: true,
6285
+ path: target.path,
6286
+ includeDirectory: path.join(layout.root, target.path, 'include'),
6287
+ sources: [],
6288
+ lateSources: [],
6289
+ exclude: entries
6231
6290
  .filter(([file]) => !file.endsWith('.swift') && !file.endsWith('.metal'))
6232
6291
  .map(([file]) => file.slice(prefix.length)),
6233
- ...(accessor
6234
- ? [OBJC_RESOURCE_ACCESSOR_HEADER, OBJC_RESOURCE_ACCESSOR_BODY]
6235
- : []),
6236
- thunk,
6237
- 'include',
6238
- ],
6239
- groups: [...groups.values()],
6240
- late: {
6241
- name: `${target.name}SwiftImplementation`,
6242
- producers: [
6243
- target.name,
6244
- ...(target.dependencies ?? [])
6245
- .filter((dependency) => swiftTargets.has(dependency.name))
6246
- .map((dependency) => dependency.name),
6247
- ],
6248
- },
6249
- })
6292
+ })
6293
+ }
6250
6294
  continue
6251
6295
  }
6252
6296
  const includes = `${prefix}include/`
@@ -6438,30 +6482,38 @@ export function writeSwiftProject(
6438
6482
  for (const name of objcProducers) {
6439
6483
  const target = targets.find((value) => value.name === name)!
6440
6484
  const prefix = target.path === '.' ? '' : `${target.path}/`
6441
- const exported = swiftObjCExports({
6442
- module: swiftTargetModuleName(name),
6443
- sources: Object.entries(input.files).filter(
6444
- ([file]) =>
6445
- file.startsWith(prefix) &&
6446
- file.endsWith('.swift') &&
6447
- !targets.some(
6448
- (candidate) =>
6449
- candidate.name !== name &&
6450
- candidate.path !== '.' &&
6451
- candidate.path.startsWith(prefix) &&
6452
- file.startsWith(`${candidate.path}/`),
6453
- ) &&
6454
- !target.exclude?.some(
6455
- (excluded) =>
6456
- file.slice(prefix.length) === excluded ||
6457
- file.slice(prefix.length).startsWith(`${excluded}/`),
6458
- ),
6459
- ),
6460
- mask: swiftCodeMask,
6461
- declarationStart,
6462
- selector: objcSelectorName,
6463
- foreignTypes: imports.get(name)?.foreignTypes,
6464
- })
6485
+ let exported: ReturnType<typeof swiftObjCExports>
6486
+ try {
6487
+ exported = swiftObjCExports({
6488
+ module: swiftTargetModuleName(name),
6489
+ sources: Object.entries(input.files).filter(
6490
+ ([file]) =>
6491
+ file.startsWith(prefix) &&
6492
+ file.endsWith('.swift') &&
6493
+ !targets.some(
6494
+ (candidate) =>
6495
+ candidate.name !== name &&
6496
+ candidate.path !== '.' &&
6497
+ candidate.path.startsWith(prefix) &&
6498
+ file.startsWith(`${candidate.path}/`),
6499
+ ) &&
6500
+ !target.exclude?.some(
6501
+ (excluded) =>
6502
+ file.slice(prefix.length) === excluded ||
6503
+ file.slice(prefix.length).startsWith(`${excluded}/`),
6504
+ ),
6505
+ ),
6506
+ mask: swiftCodeMask,
6507
+ declarationStart,
6508
+ selector: objcSelectorName,
6509
+ foreignTypes: imports.get(name)?.foreignTypes,
6510
+ })
6511
+ } catch (error) {
6512
+ // its objective-c units then fail on the missing header in the same build.
6513
+ if (!(error instanceof Error)) throw error
6514
+ targetFailures.push(`${name}: ${error.message}`)
6515
+ continue
6516
+ }
6465
6517
  const original = imports.get(name)
6466
6518
  if (!exported && !original) continue
6467
6519
  objcModules.add(name)
@@ -6741,6 +6793,7 @@ public func __peachObjcExportRoot() { _objcRegisterPeerClass(NSObject.self, nati
6741
6793
  // building a producer also emits its dependency producers' headers.
6742
6794
  return {
6743
6795
  headerProducers: producers.filter((name) => !included.has(name)),
6796
+ targetFailures,
6744
6797
  ...(rootOwner && objcExports
6745
6798
  ? {
6746
6799
  objcImplementations: {
@@ -7011,7 +7064,10 @@ export function compileSwiftProjectUnit(
7011
7064
  ],
7012
7065
  {
7013
7066
  cwd: repo,
7014
- timeout: options.timeoutMs,
7067
+ timeout:
7068
+ options.timeoutMs === undefined
7069
+ ? undefined
7070
+ : swiftBuilderHopTimeoutMs(options.timeoutMs),
7015
7071
  maxBuffer: 64 * 1024 * 1024,
7016
7072
  signal: options.signal,
7017
7073
  },
@@ -7048,6 +7104,9 @@ export function compileSwiftProjectUnit(
7048
7104
  return retain(root, built)
7049
7105
  }
7050
7106
  const preparation = writeSwiftProject(layout, input, moduleRoot)
7107
+ const unprepared = preparation.targetFailures.map(
7108
+ (failure) => `error: target ${failure}`,
7109
+ )
7051
7110
  const swift = path.join(options.toolchainBin, 'swift')
7052
7111
  if (!existsSync(swift)) {
7053
7112
  throw new Error(
@@ -7227,18 +7286,23 @@ export function compileSwiftProjectUnit(
7227
7286
  )
7228
7287
  } catch (retryError) {
7229
7288
  throw new Error(
7230
- projectDiagnostic(outputOf(retryError), layout, input.files),
7231
- {
7232
- cause: retryError,
7233
- },
7289
+ [
7290
+ ...unprepared,
7291
+ projectDiagnostic(outputOf(retryError), layout, input.files),
7292
+ ].join('\n'),
7293
+ { cause: retryError },
7234
7294
  )
7235
7295
  }
7236
7296
  } else {
7237
- throw new Error(projectDiagnostic(output, layout, input.files), {
7238
- cause: error,
7239
- })
7297
+ throw new Error(
7298
+ [...unprepared, projectDiagnostic(output, layout, input.files)].join(
7299
+ '\n',
7300
+ ),
7301
+ { cause: error },
7302
+ )
7240
7303
  }
7241
7304
  }
7305
+ if (unprepared.length) throw new Error(unprepared.join('\n'))
7242
7306
  const artifact = {
7243
7307
  hash,
7244
7308
  bytes: readFileSync(builtArtifact(layout)),