From 80208255bbc512f8c891003ebfcbb175fc857b3a Mon Sep 17 00:00:00 2001 From: jatmn Date: Tue, 13 Oct 2026 09:52:58 -0700 Subject: [PATCH] fix: declare and validate Linux glibc requirements --- apps/desktop-gpui/tauri.conf.json | 1 + apps/web/components/pages/DownloadPage.tsx | 4 + scripts/finalize-linux-gpui-packages.mjs | 53 ++++++++++++ scripts/finalize-linux-gpui-packages.test.mjs | 83 ++++++++++++++++++- 4 files changed, 137 insertions(+), 4 deletions(-) diff --git a/apps/desktop-gpui/tauri.conf.json b/apps/desktop-gpui/tauri.conf.json index b5f4be441ad..314e0f27dd9 100644 --- a/apps/desktop-gpui/tauri.conf.json +++ b/apps/desktop-gpui/tauri.conf.json @@ -81,6 +81,7 @@ "linux": { "deb": { "depends": [ + "libc6 (>= 2.39)", "libva2", "libva-drm2", "pulseaudio-utils", diff --git a/apps/web/components/pages/DownloadPage.tsx b/apps/web/components/pages/DownloadPage.tsx index 28b7e0201de..2c1e8a58432 100644 --- a/apps/web/components/pages/DownloadPage.tsx +++ b/apps/web/components/pages/DownloadPage.tsx @@ -431,6 +431,10 @@ export const DownloadPage = ({ All versions +

+ Linux downloads require glibc 2.39 or newer, such as Ubuntu 24.04 or + newer. Ubuntu 22.04 is not supported, including with AppImage. +

{/* Discreet SEO Links */} diff --git a/scripts/finalize-linux-gpui-packages.mjs b/scripts/finalize-linux-gpui-packages.mjs index f06dab0e910..f9daf4ffdce 100644 --- a/scripts/finalize-linux-gpui-packages.mjs +++ b/scripts/finalize-linux-gpui-packages.mjs @@ -1,6 +1,7 @@ import { mkdir, mkdtemp, + open, readdir, readFile, rename, @@ -221,6 +222,54 @@ const captured = (env) => ({ stdio: ["ignore", "pipe", "inherit"], }); +async function verifyDebGlibc(root, control, { env, run }) { + const dependencies = /^Depends:(.*(?:\n[ \t].*)*)/m + .exec(control)?.[1] + .replace(/\n[ \t]+/g, " ") + .split(","); + const minimum = dependencies + ?.map((dependency) => + /^\s*libc6\s*\(>=\s*(\d+(?:\.\d+)+)\)\s*$/.exec(dependency), + ) + .find(Boolean)?.[1]; + if (!minimum) { + throw new Error( + "The Cap deb must declare a versioned libc6 (>= version) dependency", + ); + } + async function verifyDirectory(directory) { + for (const entry of await readdir(directory, { withFileTypes: true })) { + const filename = path.join(directory, entry.name); + if (entry.isDirectory()) { + await verifyDirectory(filename); + } else if (entry.isFile()) { + const file = await open(filename, "r"); + const magic = Buffer.alloc(4); + try { + await file.read(magic, 0, 4, 0); + } finally { + await file.close(); + } + if (!magic.equals(Buffer.from([0x7f, 0x45, 0x4c, 0x46]))) continue; + const { stdout } = await run( + "readelf", + ["--wide", "--version-info", filename], + captured(env), + ); + const needs = stdout.split("Version needs section")[1] ?? ""; + for (const match of needs.matchAll(/Name: GLIBC_(\d+(?:\.\d+)+)\b/g)) { + if (match[1].localeCompare(minimum, "en", { numeric: true }) > 0) { + throw new Error( + `${path.relative(root, filename)} requires GLIBC_${match[1]}, exceeding the declared libc6 (>= ${minimum}) dependency`, + ); + } + } + } + } + } + await verifyDirectory(root); +} + async function recompressDebData(uncompressed, output, members, { env, run }) { await mkdir(members); const names = (await run("ar", ["t", uncompressed], captured(env))).stdout @@ -267,6 +316,10 @@ export async function finalizeGpuiDeb( path.join(root, "usr", "lib", "cap"), ); const control = path.join(root, "DEBIAN", "control"); + await verifyDebGlibc(root, await readFile(control, "utf8"), { + env: tools, + run, + }); await writeFile( control, withInstalledSize( diff --git a/scripts/finalize-linux-gpui-packages.test.mjs b/scripts/finalize-linux-gpui-packages.test.mjs index 1fae997d7b0..eabee5c8634 100644 --- a/scripts/finalize-linux-gpui-packages.test.mjs +++ b/scripts/finalize-linux-gpui-packages.test.mjs @@ -250,7 +250,7 @@ for (const [name, listing, expected] of [ await mkdir(path.join(args[2], "DEBIAN"), { recursive: true }); await writeFile( path.join(args[2], "DEBIAN/control"), - "Package: cap\nDepends: libva2, libwebkit2gtk-4.1-0, libgtk-3-0\n", + "Package: cap\nDepends: libc6 (>= 2.39), libva2, libwebkit2gtk-4.1-0, libgtk-3-0\n", ); } else if (command === "dpkg-deb" && args[0] === "--contents") { return { @@ -267,7 +267,7 @@ for (const [name, listing, expected] of [ ]); assert.equal( await readFile(path.join(args[3], "DEBIAN/control"), "utf8"), - "Package: cap\nDepends: libva2\n", + "Package: cap\nDepends: libc6 (>= 2.39), libva2\n", ); await writeFile(args[4], "uncompressed"); } else if (command === "ar" && args[0] === "t") { @@ -448,7 +448,7 @@ test( "Architecture: amd64", "Maintainer: cap", "Installed-Size: 12", - "Depends: libva2, libasound2t64 | libasound2, libwebkit2gtk-4.1-0, libgtk-3-0", + "Depends: libc6 (>= 2.39), libva2, libasound2t64 | libasound2, libwebkit2gtk-4.1-0, libgtk-3-0", "Description: Beautiful screen recordings, owned by you.", "", ].join("\n"), @@ -459,7 +459,7 @@ test( await finalizeGpuiDeb(deb, { unsigned: true }); assert.equal( capture("dpkg-deb", ["--field", deb, "Depends"]).trim(), - "libva2, libasound2t64 | libasound2", + "libc6 (>= 2.39), libva2, libasound2t64 | libasound2", ); assert.equal( capture("dpkg-deb", ["--field", deb, "Package"]).trim(), @@ -602,3 +602,78 @@ test( assert.match(capture("rpm", ["-Kv", rpm]), /Payload SHA256 digest: OK/); }, ); + +for (const payload of ["usr/bin/Cap", "usr/lib/cap/libmedia.so"]) { + test( + `deb finalization checks glibc requirements in ${payload}`, + { + skip: + !available("dpkg-deb") || !available("gcc") || !available("readelf"), + }, + async (t) => { + const root = await workspace(t); + const tree = path.join(root, "tree"); + await mkdir(path.join(tree, "DEBIAN"), { recursive: true }); + await mkdir(path.dirname(path.join(tree, payload)), { recursive: true }); + const source = path.join(root, "payload.c"); + await writeFile( + source, + '#include \nint main(void) { return puts("cap"); }\n', + ); + capture("gcc", [ + ...(payload.endsWith(".so") ? ["-shared", "-fPIC"] : []), + source, + "-o", + path.join(tree, payload), + ]); + const config = JSON.parse( + await readFile( + new URL("../apps/desktop-gpui/tauri.conf.json", import.meta.url), + "utf8", + ), + ); + const declared = config.bundle.linux.deb.depends.find((dependency) => + dependency.startsWith("libc6"), + ); + assert.equal(declared, "libc6 (>= 2.39)"); + const deb = path.join(root, "cap.deb"); + for (const dependency of ["", "libc6", "libc6 (>= 2.0)", declared]) { + await writeFile( + path.join(tree, "DEBIAN/control"), + [ + "Package: cap", + "Version: 0.6.1", + "Architecture: all", + "Maintainer: cap", + ...(dependency ? [`Depends: ${dependency}`] : []), + "Description: glibc packaging fixture", + "", + ].join("\n"), + ); + capture("dpkg-deb", [ + "--root-owner-group", + "-Zgzip", + "--build", + tree, + deb, + ]); + const original = await readFile(deb); + if (dependency !== declared) { + await assert.rejects( + finalizeGpuiDeb(deb, { unsigned: true }), + dependency.includes("2.0") + ? /requires GLIBC_.*exceeding/ + : /versioned libc6/, + ); + assert.deepEqual(await readFile(deb), original); + } else { + await finalizeGpuiDeb(deb, { unsigned: true }); + assert.equal( + capture("dpkg-deb", ["--field", deb, "Depends"]).trim(), + declared, + ); + } + } + }, + ); +}