@@ -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 = / l i b a t o m i c \. s o \. 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+
254315const 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" ) {
0 commit comments