Skip to content

Commit 48247dd

Browse files
t3dotggclaude
andauthored
fix(cli): t3 starts on a fresh Ubuntu server without libatomic (pingdotgg#26912)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent b5fc7be commit 48247dd

3 files changed

Lines changed: 100 additions & 9 deletions

File tree

‎.github/workflows/release-desktop.yml‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,15 @@ jobs:
390390
mkdir -p "$target_dir"
391391
cp "native/resource-monitor/target/${{ inputs.rust_target }}/release/${binary_name}" "$target_dir/$binary_name"
392392
393+
- uses: ./.github/actions/setup-apt-mirrors
394+
if: inputs.platform == 'linux'
395+
396+
# The Linux archive ships libatomic.so.1 and points t3's RUNPATH at it.
397+
- name: Install patchelf
398+
if: inputs.cli_archive && inputs.platform == 'linux'
399+
shell: bash
400+
run: command -v patchelf || { sudo apt-get update && sudo apt-get install -y patchelf; }
401+
393402
- name: Build CLI archive
394403
if: inputs.cli_archive
395404
shell: bash
@@ -433,9 +442,6 @@ jobs:
433442
path: release-cli/*
434443
if-no-files-found: error
435444

436-
- uses: ./.github/actions/setup-apt-mirrors
437-
if: inputs.platform == 'linux'
438-
439445
- name: Install Linux desktop build libraries
440446
if: inputs.platform == 'linux'
441447
shell: bash

‎scripts/build-cli-archive.ts‎

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,67 @@ const stageWebClient = Effect.fn("stageWebClient")(function* (source: string, ta
251251
}
252252
});
253253

254+
/** Node links libatomic.so.1, which Ubuntu server and container images lack, so t3 carries its own. */
255+
const bundleLinuxLibatomic = Effect.fn("bundleLinuxLibatomic")(function* (input: {
256+
readonly contentDir: string;
257+
readonly executablePath: string;
258+
}) {
259+
const fs = yield* FileSystem.FileSystem;
260+
const path = yield* Path.Path;
261+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
262+
const ldd = yield* spawner.string(ChildProcess.make("ldd", [input.executablePath]));
263+
const source = /libatomic\.so\.1 => (\/\S+)/.exec(ldd)?.[1];
264+
if (source === undefined) {
265+
return yield* new CliArchiveInputMissingError({
266+
inputPath: "libatomic.so.1",
267+
hint: `ldd did not resolve it for ${input.executablePath}. Install libatomic1 on the build host.`,
268+
});
269+
}
270+
yield* fs.makeDirectory(path.join(input.contentDir, "lib"));
271+
yield* fs.copyFile(source, path.join(input.contentDir, "lib/libatomic.so.1"));
272+
273+
// libatomic is GPL-3.0-or-later WITH GCC-exception-3.1, so its terms and source travel with it.
274+
const owner = yield* spawner.string(
275+
ChildProcess.make("dpkg-query", ["-S", yield* fs.realPath(source)]),
276+
);
277+
// Keep the arch qualifier so a second installed arch cannot add its own line.
278+
const [, qualifiedPkg, pkg] = /^(([^:\s]+)(?::[^:\s]+)?): /.exec(owner) ?? [];
279+
const versions = qualifiedPkg
280+
? yield* spawner.string(
281+
ChildProcess.make("dpkg-query", [
282+
"-W",
283+
"-f=${Version} ${source:Package} ${source:Version}",
284+
qualifiedPkg,
285+
]),
286+
)
287+
: "";
288+
const [version, sourcePackage, sourceVersion] = versions.trim().split(" ");
289+
if (!pkg || !version || !sourcePackage || !sourceVersion) {
290+
return yield* new CliArchiveInputMissingError({
291+
inputPath: `dpkg package for ${source}`,
292+
hint: "The archive copies libatomic's license and source reference from its Ubuntu package.",
293+
});
294+
}
295+
const header = [
296+
`libatomic.so.1 is copied from the Ubuntu package ${pkg} ${version}.`,
297+
`Source: https://launchpad.net/ubuntu/+source/${sourcePackage}/${sourceVersion}`,
298+
"License: GPL-3.0-or-later WITH GCC-exception-3.1. The package copyright file and GPL-3 follow.",
299+
].join("\n");
300+
const copyright = yield* fs.readFileString(`/usr/share/doc/${pkg}/copyright`);
301+
const gpl3 = yield* fs.readFileString("/usr/share/common-licenses/GPL-3");
302+
yield* fs.writeFileString(
303+
path.join(input.contentDir, "lib/libatomic.so.1.LICENSE"),
304+
`${header}\n\n${copyright}\n${gpl3}`,
305+
);
306+
307+
// RUNPATH resolves through symlinks and is not inherited by child processes, unlike LD_LIBRARY_PATH.
308+
yield* runCommand(
309+
ChildProcess.make("patchelf", ["--set-rpath", "$ORIGIN/lib", input.executablePath]),
310+
"patchelf --set-rpath",
311+
);
312+
yield* Effect.log(`[cli-archive] Bundled ${source} as lib/libatomic.so.1.`);
313+
});
314+
254315
const MacSigningConfig = Config.all({
255316
identity: Config.String("T3CODE_CLI_MAC_SIGN_IDENTITY").pipe(Config.option),
256317
appleApiKey: Config.String("APPLE_API_KEY").pipe(Config.option),
@@ -444,11 +505,6 @@ const buildCliArchive = Effect.fn("buildCliArchive")(function* (input: {
444505
builtExecutable,
445506
`Run \`node apps/server/scripts/cli.ts build-exe${targetKey === hostKey ? "" : ` --target ${targetKey}`}\` first.`,
446507
);
447-
// TEMPORARY one-time Node fix. Remove when fixed: https://github.com/nodejs/node/issues/67048
448-
if (input.platform === "linux" && input.arch === "arm64") {
449-
const bytes = yield* fs.readFile(builtExecutable);
450-
yield* Effect.try(() => assertLinuxArm64PageCompatibility(bytes));
451-
}
452508
yield* requireInput(path.join(webClient, "index.html"), "Run `vp run --filter t3 build` first.");
453509
yield* requireInput(
454510
resourceMonitorDir,
@@ -473,6 +529,14 @@ const buildCliArchive = Effect.fn("buildCliArchive")(function* (input: {
473529
});
474530

475531
const executablePath = path.join(contentDir, executableName);
532+
if (input.platform === "linux") {
533+
yield* bundleLinuxLibatomic({ contentDir, executablePath });
534+
}
535+
// TEMPORARY one-time Node fix. Remove when fixed: https://github.com/nodejs/node/issues/67048
536+
if (input.platform === "linux" && input.arch === "arm64") {
537+
const bytes = yield* fs.readFile(executablePath);
538+
yield* Effect.try(() => assertLinuxArm64PageCompatibility(bytes));
539+
}
476540
if (input.platform === "mac") {
477541
yield* signMacArchiveContents({ repoRoot, contentDir, executablePath });
478542
} else if (input.platform === "win") {

‎scripts/smoke-cli-archive.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@ const smokeCliArchive = Effect.fn("smokeCliArchive")(function* (input: {
9797
}
9898
const contentDir = path.join(scratch, root);
9999
const executable = path.join(contentDir, platform === "win32" ? "t3.exe" : "t3");
100-
for (const required of [executable, path.join(contentDir, "client/index.html")]) {
100+
const bundledLibatomic = path.join(contentDir, "lib/libatomic.so.1");
101+
for (const required of [
102+
executable,
103+
path.join(contentDir, "client/index.html"),
104+
...(platform === "linux" ? [bundledLibatomic, `${bundledLibatomic}.LICENSE`] : []),
105+
]) {
101106
if (!(yield* fs.exists(required))) {
102107
return yield* new CliArchiveSmokeError({
103108
step: "checking the archive layout",
@@ -106,6 +111,22 @@ const smokeCliArchive = Effect.fn("smokeCliArchive")(function* (input: {
106111
}
107112
}
108113

114+
// The runner has libatomic installed; fresh Ubuntu servers do not.
115+
if (platform === "linux") {
116+
const ldd = yield* spawner.string(ChildProcess.make("ldd", [executable]));
117+
// Older glibc prints the path as given, newer prints it resolved; compare both resolved.
118+
const loaded = /libatomic\.so\.1 => (\/.*) \(0x[0-9a-f]+\)/.exec(ldd)?.[1];
119+
if (
120+
loaded === undefined ||
121+
(yield* fs.realPath(loaded)) !== (yield* fs.realPath(bundledLibatomic))
122+
) {
123+
return yield* new CliArchiveSmokeError({
124+
step: "checking that t3 loads the bundled libatomic",
125+
detail: ldd,
126+
});
127+
}
128+
}
129+
109130
const version = yield* runExecutable(executable, ["--version"], contentDir);
110131
if (version.exitCode !== 0 || !version.stdout.includes(input.expectVersion)) {
111132
return yield* new CliArchiveSmokeError({

0 commit comments

Comments
 (0)