Skip to content

Commit 760c475

Browse files
committed
Auto-install ldid for macOS ARM64 stub builds
Automatically install ldid using Homebrew when building stub binaries on macOS ARM64 to fix yao-pkg malformation issue. Changes: - Auto-detect and install ldid if missing - Provide Homebrew installation instructions if brew not found - Streamline the signing process for better UX
1 parent 655babf commit 760c475

File tree

1 file changed

+59
-4
lines changed

1 file changed

+59
-4
lines changed

scripts/build/build-stub.mjs

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ export async function buildStub(options = {}) {
216216
console.log('🔏 Signing macOS ARM64 binary...')
217217
const signResult = await signMacOSBinaryWithLdid(outputPath, quiet)
218218
if (signResult === 'ldid-not-found') {
219-
console.error('⚠️ Warning: ldid not found - binary may be malformed')
220-
console.error(' Install ldid to fix: brew install ldid')
221-
console.error(' Then manually sign: ldid -S ./binaries/stub/socket-macos-arm64')
219+
console.error('⚠️ Warning: Could not install or find ldid')
220+
console.error(' Binary may be malformed without ldid signing')
221+
console.error(' To fix manually: brew install ldid && ldid -S ./binaries/stub/socket-macos-arm64')
222222
} else if (signResult !== 0) {
223223
console.error('⚠️ Warning: Failed to sign with ldid')
224224
} else {
@@ -257,6 +257,55 @@ export async function buildStub(options = {}) {
257257
return 0
258258
}
259259

260+
/**
261+
* Install ldid using Homebrew
262+
*/
263+
async function installLdidViaBrew(quiet = false) {
264+
// First check if brew is available
265+
const brewAvailable = await new Promise((resolve) => {
266+
const child = spawn('which', ['brew'], {
267+
stdio: 'pipe'
268+
})
269+
child.on('exit', (code) => resolve(code === 0))
270+
child.on('error', () => resolve(false))
271+
})
272+
273+
if (!brewAvailable) {
274+
if (!quiet) {
275+
console.error(' Homebrew not found, cannot auto-install ldid')
276+
console.error(' To install Homebrew, run:')
277+
console.error(' /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"')
278+
console.error(' Then re-run this build command')
279+
}
280+
return false
281+
}
282+
283+
// Install ldid using brew
284+
return new Promise((resolve) => {
285+
console.log(' Running: brew install ldid')
286+
const child = spawn('brew', ['install', 'ldid'], {
287+
stdio: quiet ? 'pipe' : 'inherit'
288+
})
289+
290+
child.on('exit', (code) => {
291+
if (code === 0) {
292+
resolve(true)
293+
} else {
294+
if (!quiet) {
295+
console.error(' Failed to install ldid via Homebrew')
296+
}
297+
resolve(false)
298+
}
299+
})
300+
child.on('error', (error) => {
301+
if (!quiet) {
302+
console.error(' Error installing ldid:', error.message)
303+
}
304+
resolve(false)
305+
})
306+
})
307+
}
308+
260309
/**
261310
* Sign macOS ARM64 binary with ldid (fixes yao-pkg malformed binary issue)
262311
*/
@@ -271,7 +320,13 @@ async function signMacOSBinaryWithLdid(binaryPath, quiet = false) {
271320
})
272321

273322
if (!ldidAvailable) {
274-
return 'ldid-not-found'
323+
// Try to install ldid automatically
324+
console.log(' ldid not found, attempting to install via Homebrew...')
325+
const brewInstalled = await installLdidViaBrew(quiet)
326+
if (!brewInstalled) {
327+
return 'ldid-not-found'
328+
}
329+
console.log(' ldid installed successfully')
275330
}
276331

277332
// Remove existing signature first (if any)

0 commit comments

Comments
 (0)