11import { bold , cyan , yellow } from "jsr:@std/fmt@1/colors" ;
2+ import * as path from "jsr:@std/path@1" ;
23import { ensureDeps } from "./deps.ts" ;
34import { exec , getEnvVars , getSysrootEnv } from "./util.ts" ;
45
@@ -13,7 +14,10 @@ async function isMusl(): Promise<boolean> {
1314 } catch {
1415 // Also check for musl by looking at ldd
1516 try {
16- const cmd = new Deno . Command ( "ldd" , { args : [ "--version" ] , stderr : "piped" } ) ;
17+ const cmd = new Deno . Command ( "ldd" , {
18+ args : [ "--version" ] ,
19+ stderr : "piped" ,
20+ } ) ;
1721 const { stderr } = await cmd . output ( ) ;
1822 return new TextDecoder ( ) . decode ( stderr ) . toLowerCase ( ) . includes ( "musl" ) ;
1923 } catch {
@@ -97,13 +101,15 @@ export async function buildUi(target?: string, debug = false) {
97101 Object . assign ( env , getSysrootEnv ( target ) ) ;
98102 }
99103
100- // On musl (Alpine), we need to disable static-pie to allow dynamic GTK linking.
101- // The binary will still be mostly static but can link GTK dynamically .
104+ // On musl (Alpine), use a linker wrapper that replaces - static-pie with -pie
105+ // to allow dynamic GTK linking while keeping musl libc statically linked .
102106 if ( platform === "desktop" && await isMusl ( ) ) {
103- const existingFlags = env . RUSTFLAGS || "" ;
104- // Remove -static-pie and force -Bdynamic before system libs
105- env . RUSTFLAGS =
106- `${ existingFlags } -C link-arg=-Wl,-Bdynamic -C relocation-model=pic` . trim ( ) ;
107+ const linkerPath = path . join (
108+ import . meta. dirname ?? "." ,
109+ "musl-pie-linker.sh" ,
110+ ) ;
111+ env . CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER = linkerPath ;
112+ env . CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER = linkerPath ;
107113 }
108114
109115 await exec ( buildArgs , env ) ;
0 commit comments