Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/desktop-gpui/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"linux": {
"deb": {
"depends": [
"libc6 (>= 2.39)",
"libva2",
"libva-drm2",
"pulseaudio-utils",
Expand Down
4 changes: 4 additions & 0 deletions apps/web/components/pages/DownloadPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ export const DownloadPage = ({
All versions
</Link>
</div>
<p className="mt-3 text-sm text-gray-10">
Linux downloads require glibc 2.39 or newer, such as Ubuntu 24.04 or
newer. Ubuntu 22.04 is not supported, including with AppImage.
</p>
</div>

{/* Discreet SEO Links */}
Expand Down
53 changes: 53 additions & 0 deletions scripts/finalize-linux-gpui-packages.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
mkdir,
mkdtemp,
open,
readdir,
readFile,
rename,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
83 changes: 79 additions & 4 deletions scripts/finalize-linux-gpui-packages.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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") {
Expand Down Expand Up @@ -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"),
Expand All @@ -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(),
Expand Down Expand Up @@ -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 <stdio.h>\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,
);
}
}
},
);
}
Loading