fix: stage libffmpeg for Linux AppImage child processes

This commit is contained in:
2026-04-05 10:36:28 -07:00
parent da0087bba6
commit fa89c43f74
6 changed files with 194 additions and 1 deletions

View File

@@ -0,0 +1,41 @@
const fs = require('node:fs/promises');
const path = require('node:path');
const LINUX_FFMPEG_LIBRARY = 'libffmpeg.so';
async function stageLinuxAppImageSharedLibrary(
context,
deps = {
access: (filePath) => fs.access(filePath),
mkdir: (dirPath) => fs.mkdir(dirPath, { recursive: true }),
copyFile: (from, to) => fs.copyFile(from, to),
},
) {
if (context.electronPlatformName !== 'linux') return false;
const sourceLibraryPath = path.join(context.appOutDir, LINUX_FFMPEG_LIBRARY);
try {
await deps.access(sourceLibraryPath);
} catch {
return false;
}
const targetLibraryDir = path.join(context.appOutDir, 'usr', 'lib');
const targetLibraryPath = path.join(targetLibraryDir, LINUX_FFMPEG_LIBRARY);
await deps.mkdir(targetLibraryDir);
await deps.copyFile(sourceLibraryPath, targetLibraryPath);
return true;
}
async function afterPack(context) {
await stageLinuxAppImageSharedLibrary(context);
}
module.exports = {
LINUX_FFMPEG_LIBRARY,
stageLinuxAppImageSharedLibrary,
default: afterPack,
};

View File

@@ -0,0 +1,84 @@
import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import test from 'node:test';
const {
LINUX_FFMPEG_LIBRARY,
stageLinuxAppImageSharedLibrary,
} = require('./electron-builder-after-pack.cjs') as {
LINUX_FFMPEG_LIBRARY: string;
stageLinuxAppImageSharedLibrary: (context: {
appOutDir: string;
electronPlatformName: string;
}) => Promise<boolean>;
};
function createWorkspace(name: string): string {
return fs.mkdtempSync(path.join(os.tmpdir(), `${name}-`));
}
test('stageLinuxAppImageSharedLibrary copies libffmpeg.so into usr/lib for Linux packaging', async () => {
const workspace = createWorkspace('subminer-after-pack-linux');
const appOutDir = path.join(workspace, 'SubMiner-linux-x64');
const sourceLibraryPath = path.join(appOutDir, LINUX_FFMPEG_LIBRARY);
const targetLibraryPath = path.join(appOutDir, 'usr', 'lib', LINUX_FFMPEG_LIBRARY);
fs.mkdirSync(appOutDir, { recursive: true });
fs.writeFileSync(sourceLibraryPath, 'bundled ffmpeg', 'utf8');
try {
const staged = await stageLinuxAppImageSharedLibrary({
appOutDir,
electronPlatformName: 'linux',
});
assert.equal(staged, true);
assert.equal(fs.readFileSync(targetLibraryPath, 'utf8'), 'bundled ffmpeg');
} finally {
fs.rmSync(workspace, { recursive: true, force: true });
}
});
test('stageLinuxAppImageSharedLibrary skips non-Linux packaging contexts', async () => {
const workspace = createWorkspace('subminer-after-pack-non-linux');
const appOutDir = path.join(workspace, 'SubMiner-darwin-arm64');
const sourceLibraryPath = path.join(appOutDir, LINUX_FFMPEG_LIBRARY);
const targetLibraryPath = path.join(appOutDir, 'usr', 'lib', LINUX_FFMPEG_LIBRARY);
fs.mkdirSync(appOutDir, { recursive: true });
fs.writeFileSync(sourceLibraryPath, 'bundled ffmpeg', 'utf8');
try {
const staged = await stageLinuxAppImageSharedLibrary({
appOutDir,
electronPlatformName: 'darwin',
});
assert.equal(staged, false);
assert.equal(fs.existsSync(targetLibraryPath), false);
} finally {
fs.rmSync(workspace, { recursive: true, force: true });
}
});
test('stageLinuxAppImageSharedLibrary no-ops when libffmpeg.so is absent', async () => {
const workspace = createWorkspace('subminer-after-pack-missing-library');
const appOutDir = path.join(workspace, 'SubMiner-linux-x64');
const targetLibraryPath = path.join(appOutDir, 'usr', 'lib', LINUX_FFMPEG_LIBRARY);
fs.mkdirSync(appOutDir, { recursive: true });
try {
const staged = await stageLinuxAppImageSharedLibrary({
appOutDir,
electronPlatformName: 'linux',
});
assert.equal(staged, false);
assert.equal(fs.existsSync(targetLibraryPath), false);
} finally {
fs.rmSync(workspace, { recursive: true, force: true });
}
});