Merge pull request #240 from mitchellh/linux-build

Fix some Linux build issues
This commit is contained in:
Mitchell Hashimoto
2023-08-07 11:10:15 -07:00
committed by GitHub
3 changed files with 30 additions and 22 deletions

View File

@ -644,6 +644,22 @@ fn addDeps(
return static_libs; return static_libs;
} }
// For dynamic linking, we prefer dynamic linking and to search by
// mode first. Mode first will search all paths for a dynamic library
// before falling back to static.
const dynamic_link_opts: std.build.Step.Compile.LinkSystemLibraryOptions = .{
.preferred_link_mode = .Dynamic,
.search_strategy = .mode_first,
};
// On Linux, we need to add a couple common library paths that aren't
// on the standard search list. i.e. GTK is often in /usr/lib/x86_64-linux-gnu
// on x86_64.
if (step.target.isLinux()) {
const triple = try step.target.linuxTriple(b.allocator);
step.addLibraryPath(.{ .path = b.fmt("/usr/lib/{s}", .{triple}) });
}
// If we're building a lib we have some different deps // If we're building a lib we have some different deps
const lib = step.kind == .lib; const lib = step.kind == .lib;
@ -703,14 +719,16 @@ fn addDeps(
// Dynamic link // Dynamic link
if (!static) { if (!static) {
step.addIncludePath(.{ .path = freetype.include_path_self }); step.addIncludePath(.{ .path = freetype.include_path_self });
step.linkSystemLibrary("bzip2"); step.linkSystemLibrary2("bzip2", dynamic_link_opts);
step.linkSystemLibrary("freetype2"); step.linkSystemLibrary2("freetype2", dynamic_link_opts);
step.linkSystemLibrary("harfbuzz"); step.linkSystemLibrary2("harfbuzz", dynamic_link_opts);
step.linkSystemLibrary("libpng"); step.linkSystemLibrary2("libpng", dynamic_link_opts);
step.linkSystemLibrary("pixman-1"); step.linkSystemLibrary2("pixman-1", dynamic_link_opts);
step.linkSystemLibrary("zlib"); step.linkSystemLibrary2("zlib", dynamic_link_opts);
if (font_backend.hasFontconfig()) step.linkSystemLibrary("fontconfig"); if (font_backend.hasFontconfig()) {
step.linkSystemLibrary2("fontconfig", dynamic_link_opts);
}
} }
// Other dependencies, we may dynamically link // Other dependencies, we may dynamically link
@ -800,14 +818,7 @@ fn addDeps(
// When we're targeting flatpak we ALWAYS link GTK so we // When we're targeting flatpak we ALWAYS link GTK so we
// get access to glib for dbus. // get access to glib for dbus.
if (flatpak) { if (flatpak) step.linkSystemLibrary2("gtk4", dynamic_link_opts);
step.linkSystemLibrary("gtk4");
switch (step.target.getCpuArch()) {
.aarch64 => step.addLibraryPath(.{ .path = "/usr/lib/aarch64-linux-gnu" }),
.x86_64 => step.addLibraryPath(.{ .path = "/usr/lib/x86_64-linux-gnu" }),
else => @panic("unsupported flatpak target"),
}
}
switch (app_runtime) { switch (app_runtime) {
.none => {}, .none => {},
@ -834,7 +845,7 @@ fn addDeps(
}; };
try glfw.link(b, step, glfw_opts); try glfw.link(b, step, glfw_opts);
step.linkSystemLibrary("gtk4"); step.linkSystemLibrary2("gtk4", dynamic_link_opts);
}, },
} }
} }

6
flake.lock generated
View File

@ -126,11 +126,11 @@
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"
}, },
"locked": { "locked": {
"lastModified": 1690978078, "lastModified": 1691410097,
"narHash": "sha256-+S9s6sjOGuGCtA9njTdduJ7KjZm2tskxKhwGRKBK/xM=", "narHash": "sha256-HoZ/JwddeysSKNYr7h3AqReCMXPcqgqW/eBVOekxhFM=",
"owner": "mitchellh", "owner": "mitchellh",
"repo": "zig-overlay", "repo": "zig-overlay",
"rev": "c9f51464f2c2c9c75f3d7fdc58c157d252545dec", "rev": "9eda53e9001c54c810e24efe256c28d57a75d20d",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -30,7 +30,6 @@
, harfbuzz , harfbuzz
, libpng , libpng
, libGL , libGL
, libuv
, libX11 , libX11
, libXcursor , libXcursor
, libXext , libXext
@ -51,7 +50,6 @@ let
freetype freetype
harfbuzz harfbuzz
libpng libpng
libuv
zlib zlib
libX11 libX11
@ -105,7 +103,6 @@ in mkShell rec {
freetype freetype
harfbuzz harfbuzz
libpng libpng
libuv
pixman pixman
zlib zlib