Skip to content

Commit ce58845

Browse files
authored
fix(desktop): weak-link ScreenCaptureKit so the Computer Use helper loads on macOS 14 and 15 (#9978)
The helper targets macOS 14 but CI builds it with the macOS 26 SDK, which linked the macOS 26 screenshot classes strongly, so dyld refused to load the helper on older macOS and Settings reported it could not connect. The build now weak-links the framework and fails if any ScreenCaptureKit reference is strong.
1 parent c02e06d commit ce58845

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎apps/desktop/scripts/build-native.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ function compileComputerUse(): void {
8989
try {
9090
execFileSync('xcrun', ['lipo', binary, '-verify_arch', 'arm64', 'x86_64'])
9191
execFileSync('codesign', ['--verify', '--strict', bundle])
92+
assertWeakScreenCaptureKit(binary)
9293
return
9394
} catch {
9495
rmSync(bundle, { recursive: true, force: true })
@@ -108,6 +109,11 @@ function compileComputerUse(): void {
108109
'-O',
109110
'-target',
110111
`${arch}-apple-macosx14.0`,
112+
// The macOS 26 screenshot classes do not exist on 14/15; a strong reference stops the helper loading there.
113+
'-Xlinker',
114+
'-weak_framework',
115+
'-Xlinker',
116+
'ScreenCaptureKit',
111117
'native/computer-use/ComputerUse.swift',
112118
'-o',
113119
output,
@@ -118,9 +124,27 @@ function compileComputerUse(): void {
118124
}
119125
execFileSync('xcrun', ['lipo', '-create', ...parts, '-output', binary], { stdio: 'inherit' })
120126
for (const part of parts) rmSync(part)
127+
assertWeakScreenCaptureKit(binary)
121128
execFileSync('codesign', ['--force', '--sign', '-', bundle], { stdio: 'inherit' })
122129
recordNativeBuild('computer-use', outputs)
123130
logger.info('Compiled native macOS Computer Use helper')
124131
}
125132

133+
/**
134+
* The helper targets macOS 14 but uses ScreenCaptureKit classes added later behind `#available`.
135+
* Runners build on the newest macOS, where a strong reference still loads, so this is the only
136+
* place a helper that dyld would refuse on older macOS is caught before it ships.
137+
*/
138+
function assertWeakScreenCaptureKit(binary: string) {
139+
const strong = execFileSync('nm', ['-m', binary], { encoding: 'utf8' })
140+
.split('\n')
141+
.filter(
142+
(line) => line.includes('(undefined) external') && line.includes('(from ScreenCaptureKit)')
143+
)
144+
if (strong.length > 0)
145+
throw new Error(
146+
`The Computer Use helper links ScreenCaptureKit strongly and would not load on macOS 14/15:\n${strong.join('\n')}`
147+
)
148+
}
149+
126150
if (args.includes('--computer-use')) compileComputerUse()

0 commit comments

Comments
 (0)