-
Notifications
You must be signed in to change notification settings - Fork 2
fix(build): Fix FFmpeg cross-platform build on macOS for Windows targets #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,21 +18,49 @@ function ffmpegDownloadPlugin() { | |||||
| // 只在生产构建时下载 FFmpeg | ||||||
| if (!isProd) return | ||||||
|
|
||||||
| console.log('Downloading FFmpeg...') | ||||||
| // 根据构建目标决定下载哪个平台 | ||||||
| const targetPlatform = process.env.BUILD_TARGET_PLATFORM || process.platform | ||||||
| const targetArch = process.env.BUILD_TARGET_ARCH || process.arch | ||||||
|
|
||||||
| // 检查是否已存在,避免重复下载 | ||||||
| const ffmpegPath = path.resolve( | ||||||
| 'resources/ffmpeg', | ||||||
| `${targetPlatform}-${targetArch}`, | ||||||
| targetPlatform === 'win32' ? 'ffmpeg.exe' : 'ffmpeg' | ||||||
| ) | ||||||
|
|
||||||
| if (fs.existsSync(ffmpegPath)) { | ||||||
| console.log(`FFmpeg already exists for ${targetPlatform}-${targetArch}`) | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| try { | ||||||
| // 根据构建目标决定下载哪个平台 | ||||||
| const targetPlatform = process.env.BUILD_TARGET_PLATFORM || process.platform | ||||||
| const targetArch = process.env.BUILD_TARGET_ARCH || process.arch | ||||||
| console.log(`Downloading FFmpeg for ${targetPlatform}-${targetArch}...`) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Prefer logger for status messages. - console.log(`Downloading FFmpeg for ${targetPlatform}-${targetArch}...`)
+ logger.info('Downloading FFmpeg', { platform: targetPlatform, arch: targetArch })📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| try { | ||||||
| await new Promise<void>((resolve, reject) => { | ||||||
| const downloadScript = spawn( | ||||||
| 'tsx', | ||||||
| ['scripts/download-ffmpeg.ts', 'platform', targetPlatform, targetArch], | ||||||
| { | ||||||
| stdio: 'inherit' | ||||||
| // 在不同环境中使用不同的命令来确保兼容性 | ||||||
| let command: string | ||||||
| let args: string[] | ||||||
|
|
||||||
| if (process.platform === 'win32') { | ||||||
| // Windows 环境:使用 npm run 调用脚本,更可靠 | ||||||
| command = 'npm' | ||||||
| args = ['run', 'ffmpeg:download'] | ||||||
| } else { | ||||||
| // Unix 环境:直接使用 tsx | ||||||
| command = 'tsx' | ||||||
| args = ['scripts/download-ffmpeg.ts', 'platform', targetPlatform, targetArch] | ||||||
| } | ||||||
|
|
||||||
| const downloadScript = spawn(command, args, { | ||||||
| stdio: 'inherit', | ||||||
| shell: process.platform === 'win32', | ||||||
| env: { | ||||||
| ...process.env, | ||||||
| BUILD_TARGET_PLATFORM: targetPlatform, | ||||||
| BUILD_TARGET_ARCH: targetArch | ||||||
| } | ||||||
| ) | ||||||
| }) | ||||||
|
|
||||||
| downloadScript.on('close', (code) => { | ||||||
| if (code === 0) { | ||||||
|
|
@@ -48,7 +76,8 @@ function ffmpegDownloadPlugin() { | |||||
| }) | ||||||
| }) | ||||||
| } catch (error) { | ||||||
| console.warn('FFmpeg Download failed', error) | ||||||
| console.error('FFmpeg Download failed:', error) | ||||||
| throw new Error(`Failed to download FFmpeg for ${targetPlatform}-${targetArch}: ${error}`) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Use a logger instead of console; early-exit check is good.
Replace console with a build-time logger to meet logging rules. Keep the path computation unchanged.
Add at top:
+import logger from './scripts/build-logger'📝 Committable suggestion
🤖 Prompt for AI Agents