Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

build(linux): stage native FFmpeg libs for deb bundling in setup

Richie McIlroy6d5befda3764
diff --git a/scripts/setup.js b/scripts/setup.js
index cbdffd941..886b587bd 100644
--- a/scripts/setup.js
+++ b/scripts/setup.js
@@ -202,6 +202,71 @@ async function main() {
"\\",
"/",
)}"\n`;
+ } else if (process.platform === "linux") {
+ const triple = process.env.RUST_TARGET_TRIPLE;
+ if (triple) {
+ cargoConfigContents += FFMPEG_CARGO_ENV;
+
+ const NATIVE_DEPS_VERSION = "v0.25";
+ const NATIVE_DEPS_URL = `https://github.com/spacedriveapp/native-deps/releases/download/${NATIVE_DEPS_VERSION}`;
+ const NATIVE_DEPS_ASSETS = {
+ x86_64: "native-deps-x86_64-linux-gnu.tar.xz",
+ aarch64: "native-deps-aarch64-linux-gnu.tar.xz",
+ };
+
+ const nativeDepsTar = NATIVE_DEPS_ASSETS[arch];
+ if (!nativeDepsTar)
+ throw new Error(`Unsupported Linux arch for native deps: ${arch}`);
+
+ const nativeDepsTarPath = path.join(targetDir, nativeDepsTar);
+ let downloadedNativeDeps = false;
+ if (!(await fileExists(nativeDepsTarPath))) {
+ console.log(`Downloading ${nativeDepsTar}`);
+ const bytes = await fetch(`${NATIVE_DEPS_URL}/${nativeDepsTar}`)
+ .then((r) => r.blob())
+ .then((b) => b.arrayBuffer());
+ await fs.writeFile(nativeDepsTarPath, Buffer.from(bytes));
+ console.log("Downloaded native deps");
+ downloadedNativeDeps = true;
+ } else console.log(`Using cached ${nativeDepsTar}`);
+
+ const nativeDepsDir = path.join(targetDir, "native-deps");
+ const nativeLibDir = path.join(nativeDepsDir, "lib");
+ if (downloadedNativeDeps || !(await fileExists(nativeLibDir))) {
+ await fs
+ .rm(nativeDepsDir, { recursive: true, force: true })
+ .catch(() => {});
+ await fs.mkdir(nativeDepsDir, { recursive: true });
+ await execFile("tar", ["xf", nativeDepsTarPath, "-C", nativeDepsDir]);
+ console.log("Extracted native-deps");
+ } else console.log("Using cached native-deps");
+
+ const debLibDir = path.join(nativeDepsDir, "cap-deb-libs");
+ await fs.rm(debLibDir, { recursive: true, force: true }).catch(() => {});
+ await fs.mkdir(debLibDir, { recursive: true });
+
+ const profileDirs = [];
+ for (const profile of ["debug", "release"]) {
+ profileDirs.push(path.join(targetDir, profile));
+ profileDirs.push(path.join(targetDir, triple, profile));
+ }
+ for (const dir of profileDirs) await fs.mkdir(dir, { recursive: true });
+
+ const sonameLibs = (await fs.readdir(nativeLibDir)).filter((name) =>
+ /\.so\.\d+$/.test(name),
+ );
+ for (const name of sonameLibs) {
+ const realPath = await fs.realpath(path.join(nativeLibDir, name));
+ await fs.copyFile(realPath, path.join(debLibDir, name));
+ for (const dir of profileDirs)
+ await fs.copyFile(realPath, path.join(dir, name));
+ }
+ console.log(
+ `Staged ${sonameLibs.length} FFmpeg shared libraries for Linux bundling`,
+ );
+
+ cargoConfigContents += `\n[target.${triple}]\nrustflags = ["-C", "link-arg=-Wl,-rpath,$ORIGIN", "-C", "link-arg=-Wl,-rpath,$ORIGIN/../lib/cap"]\n`;
+ }
}
await fs.mkdir(path.join(__root, ".cargo"), { recursive: true });