Skip to content

Commit 1a56c45

Browse files
committed
Try pie
1 parent d7c96ef commit 1a56c45

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

build/musl-pie-linker.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
# Linker wrapper for musl builds that need dynamic GTK.
3+
# Replaces -static-pie with -pie to allow dynamic library loading
4+
# while keeping musl libc statically linked.
5+
exec cc $(echo "$@" | sed 's/-static-pie/-pie/g')

build/ui.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { bold, cyan, yellow } from "jsr:@std/fmt@1/colors";
2+
import * as path from "jsr:@std/path@1";
23
import { ensureDeps } from "./deps.ts";
34
import { 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

Comments
 (0)